kontact
kaddressbook_plugin.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "kaddressbook_plugin.h"
00026 #include "coreinterface.h"
00027 #include "kmailinterface.h"
00028
00029 #include <kaddrbookexternal.h>
00030
00031 #include <kontactinterfaces/core.h>
00032 #include <kontactinterfaces/plugin.h>
00033 #include <libkdepim/maillistdrag.h>
00034
00035 #include <kabc/addressbook.h>
00036 #include <kabc/stdaddressbook.h>
00037
00038 #include <kaction.h>
00039 #include <kactioncollection.h>
00040 #include <kdebug.h>
00041 #include <kgenericfactory.h>
00042 #include <kicon.h>
00043 #include <kiconloader.h>
00044 #include <kmessagebox.h>
00045 #include <kparts/componentfactory.h>
00046
00047 #include <QDropEvent>
00048
00049 EXPORT_KONTACT_PLUGIN( KAddressbookPlugin, kaddressbook )
00050
00051 KAddressbookPlugin::KAddressbookPlugin( Kontact::Core *core, const QVariantList & )
00052 : Kontact::Plugin( core, core, "kaddressbook" ),
00053 m_interface( 0 )
00054 {
00055 setComponentData( KontactPluginFactory::componentData() );
00056
00057 KAction *action = new KAction( KIcon( "contact-new" ),
00058 i18n( "New Contact..." ), this );
00059 actionCollection()->addAction( "new_contact", action );
00060 connect( action, SIGNAL(triggered(bool)), SLOT(slotNewContact()) );
00061 action->setShortcut( QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_C ) );
00062 insertNewAction( action );
00063
00064 action = new KAction( KIcon( "view-pim-contacts" ),
00065 i18n( "New Distribution List..." ), this );
00066 actionCollection()->addAction( "new_distributionlist", action );
00067 connect( action, SIGNAL(triggered(bool)), SLOT(slotNewDistributionList()) );
00068 insertNewAction( action );
00069
00070 KAction *syncAction = new KAction( KIcon( "view-refresh" ),
00071 i18n( "Synchronize Contacts" ), this );
00072 actionCollection()->addAction( "kaddressbook_sync", syncAction );
00073 connect( action, SIGNAL(triggered(bool)), SLOT(slotSyncContacts()) );
00074
00075 mUniqueAppWatcher = new Kontact::UniqueAppWatcher(
00076 new Kontact::UniqueAppHandlerFactory<KABUniqueAppHandler>(), this );
00077 }
00078
00079 KAddressbookPlugin::~KAddressbookPlugin()
00080 {
00081 }
00082
00083 QString KAddressbookPlugin::tipFile() const
00084 {
00085
00086
00087 QString file;
00088 return file;
00089 }
00090
00091 KParts::ReadOnlyPart *KAddressbookPlugin::createPart()
00092 {
00093 KParts::ReadOnlyPart *part = loadPart();
00094 if ( !part ) {
00095 return 0;
00096 }
00097
00098
00099 m_interface = new OrgKdeKAddressbookCoreInterface(
00100 "org.kde.kaddressbook", "/KAddressBook", QDBusConnection::sessionBus() );
00101 return part;
00102 }
00103
00104 QStringList KAddressbookPlugin::configModules() const
00105 {
00106 QStringList modules;
00107 modules << "PIM/kabconfig.desktop" << "PIM/kabldapconfig.desktop";
00108 return modules;
00109 }
00110
00111 QStringList KAddressbookPlugin::invisibleToolbarActions() const
00112 {
00113 return QStringList( "file_new_contact" );
00114 }
00115
00116 OrgKdeKAddressbookCoreInterface *KAddressbookPlugin::interface()
00117 {
00118 if ( !m_interface ) {
00119 part();
00120 }
00121 Q_ASSERT( m_interface );
00122 return m_interface;
00123 }
00124
00125 void KAddressbookPlugin::slotNewContact()
00126 {
00127 interface()->newContact();
00128 }
00129
00130 void KAddressbookPlugin::slotNewDistributionList()
00131 {
00132 interface()->newDistributionList();
00133 }
00134
00135 void KAddressbookPlugin::slotSyncContacts()
00136 {
00137 QDBusMessage message =
00138 QDBusMessage::createMethodCall( "org.kde.kmail", "/Groupware",
00139 "org.kde.kmail.groupware",
00140 "triggerSync" );
00141 message << QString( "Contact" );
00142 QDBusConnection::sessionBus().send( message );
00143 }
00144
00145 bool KAddressbookPlugin::createDBUSInterface( const QString &serviceType )
00146 {
00147 if ( serviceType == "DBUS/AddressBook" ) {
00148 Q_ASSERT( m_interface );
00149 return true;
00150 }
00151 return false;
00152 }
00153
00154 void KAddressbookPlugin::configUpdated()
00155 {
00156 }
00157
00158 bool KAddressbookPlugin::isRunningStandalone()
00159 {
00160 return mUniqueAppWatcher->isRunningStandalone();
00161 }
00162
00163 bool KAddressbookPlugin::canDecodeMimeData( const QMimeData * mimeData )
00164 {
00165 return KPIM::MailList::canDecode( mimeData );
00166 }
00167
00168 void KAddressbookPlugin::processDropEvent( QDropEvent *event )
00169 {
00170 const QMimeData *md = event->mimeData();
00171 if ( KPIM::MailList::canDecode( md ) ) {
00172 event->accept();
00173 KPIM::MailList mails = KPIM::MailList::fromMimeData( md );
00174 if ( mails.count() != 1 ) {
00175 KMessageBox::sorry( core(),
00176 i18n( "Dropping multiple mails is not supported." ) );
00177 } else {
00178 KPIM::MailSummary mail = mails.first();
00179 org::kde::kmail::kmail kmail(
00180 "org.kde.kmail", "/KMail", QDBusConnection::sessionBus() );
00181 QString sFrom = kmail.getFrom( mail.serialNumber() );
00182 if ( !sFrom.isEmpty() ) {
00183 KPIM::KAddrBookExternal::addEmail( sFrom, core() );
00184 }
00185 }
00186 return;
00187 }
00188
00189 kWarning() << QString( "Cannot handle drop events of type '%1'." ).arg( event->format() );
00190 }
00191
00193
00194 #include "../../../kaddressbook/kaddressbook_options.h"
00195
00196 void KABUniqueAppHandler::loadCommandLineOptions()
00197 {
00198 KCmdLineArgs::addCmdLineOptions( kaddressbook_options() );
00199 }
00200
00201 int KABUniqueAppHandler::newInstance()
00202 {
00203 kDebug() ;
00204
00205 (void)plugin()->part();
00206
00207 org::kde::KAddressbook::Core kaddressbook(
00208 "org.kde.kaddressbook", "/KAddressBook", QDBusConnection::sessionBus() );
00209 QDBusReply<bool> reply = kaddressbook.handleCommandLine();
00210 if ( reply.isValid() ) {
00211 bool handled = reply;
00212 kDebug() << "handled=" << handled;
00213 if ( !handled ) {
00214 return Kontact::UniqueAppHandler::newInstance();
00215 }
00216 }
00217
00218 return 0;
00219 }
00220
00221 #include "kaddressbook_plugin.moc"
00222
00223