kaddressbook_plugin.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <qwidget.h>
00025 #include <qdragobject.h>
00026
00027 #include <kaction.h>
00028 #include <kapplication.h>
00029 #include <kdebug.h>
00030 #include <kgenericfactory.h>
00031 #include <kiconloader.h>
00032 #include <kmessagebox.h>
00033 #include <kparts/componentfactory.h>
00034
00035 #include <kaddrbook.h>
00036 #include <kabc/addressbook.h>
00037 #include <kabc/stdaddressbook.h>
00038
00039 #include <dcopclient.h>
00040 #include "kmailIface_stub.h"
00041
00042 #include <libkdepim/maillistdrag.h>
00043
00044 #include "core.h"
00045 #include "kabsummarywidget.h"
00046 #include "plugin.h"
00047
00048 #include "kaddressbook_plugin.h"
00049
00050 typedef KGenericFactory< KAddressbookPlugin, Kontact::Core > KAddressbookPluginFactory;
00051 K_EXPORT_COMPONENT_FACTORY( libkontact_kaddressbookplugin,
00052 KAddressbookPluginFactory( "kontact_kaddressbookplugin" ) )
00053
00054 KAddressbookPlugin::KAddressbookPlugin( Kontact::Core *core, const char *, const QStringList& )
00055 : Kontact::Plugin( core, core, "kaddressbook" ),
00056 mStub( 0 )
00057 {
00058 setInstance( KAddressbookPluginFactory::instance() );
00059
00060 insertNewAction( new KAction( i18n( "New Contact..." ), "identity",
00061 0, this, SLOT( slotNewContact() ), actionCollection(),
00062 "new_contact" ) );
00063 mUniqueAppWatcher = new Kontact::UniqueAppWatcher(
00064 new Kontact::UniqueAppHandlerFactory<KABUniqueAppHandler>(), this );
00065 }
00066
00067 KAddressbookPlugin::~KAddressbookPlugin()
00068 {
00069 }
00070
00071 KParts::Part* KAddressbookPlugin::createPart()
00072 {
00073 KParts::Part * part = loadPart();
00074 if ( !part ) return 0;
00075
00076
00077 mStub = new KAddressBookIface_stub( dcopClient(), "kaddressbook",
00078 "KAddressBookIface" );
00079 return part;
00080 }
00081
00082 QStringList KAddressbookPlugin::configModules() const
00083 {
00084 QStringList modules;
00085 modules << "PIM/kabconfig.desktop" << "PIM/kabldapconfig.desktop";
00086 return modules;
00087 }
00088
00089 QStringList KAddressbookPlugin::invisibleToolbarActions() const
00090 {
00091 return QStringList( "file_new_contact" );
00092 }
00093
00094 KAddressBookIface_stub *KAddressbookPlugin::interface()
00095 {
00096 if ( !mStub ) {
00097 part();
00098 }
00099 Q_ASSERT( mStub );
00100 return mStub;
00101 }
00102
00103 void KAddressbookPlugin::slotNewContact()
00104 {
00105 (void) part();
00106 Q_ASSERT( mStub );
00107 if ( mStub )
00108 mStub->newContact();
00109 }
00110
00111 bool KAddressbookPlugin::createDCOPInterface( const QString& serviceType )
00112 {
00113 if ( serviceType == "DCOP/AddressBook" ) {
00114 Q_ASSERT( mStub );
00115 return true;
00116 }
00117
00118 return false;
00119 }
00120
00121 bool KAddressbookPlugin::isRunningStandalone()
00122 {
00123 return mUniqueAppWatcher->isRunningStandalone();
00124 }
00125
00126 bool KAddressbookPlugin::canDecodeDrag( QMimeSource *mimeSource )
00127 {
00128 return QTextDrag::canDecode( mimeSource ) ||
00129 KPIM::MailListDrag::canDecode( mimeSource );
00130 }
00131
00132 #include <dcopref.h>
00133
00134 void KAddressbookPlugin::processDropEvent( QDropEvent *event )
00135 {
00136 KPIM::MailList mails;
00137 if ( KPIM::MailListDrag::decode( event, mails ) ) {
00138 if ( mails.count() != 1 ) {
00139 KMessageBox::sorry( core(),
00140 i18n( "Drops of multiple mails are not supported." ) );
00141 } else {
00142 KPIM::MailSummary mail = mails.first();
00143
00144 KMailIface_stub kmailIface( "kmail", "KMailIface" );
00145 QString sFrom = kmailIface.getFrom( mail.serialNumber() );
00146
00147 if ( !sFrom.isEmpty() ) {
00148 KAddrBookExternal::addEmail( sFrom, core() );
00149 }
00150 }
00151 return;
00152 }
00153
00154 KMessageBox::sorry( core(), i18n("Cannot handle drop events of type '%1'.")
00155 .arg( event->format() ) );
00156 }
00157
00158 Kontact::Summary *KAddressbookPlugin::createSummaryWidget( QWidget *parentWidget )
00159 {
00160 return new KABSummaryWidget( this, parentWidget );
00161 }
00162
00164
00165 #include "../../../kaddressbook/kaddressbook_options.h"
00166
00167 void KABUniqueAppHandler::loadCommandLineOptions()
00168 {
00169 KCmdLineArgs::addCmdLineOptions( kaddressbook_options );
00170 }
00171
00172 int KABUniqueAppHandler::newInstance()
00173 {
00174 kdDebug(5602) << k_funcinfo << endl;
00175
00176 (void)plugin()->part();
00177 DCOPRef kAB( "kaddressbook", "KAddressBookIface" );
00178 DCOPReply reply = kAB.call( "handleCommandLine" );
00179 if ( reply.isValid() ) {
00180 bool handled = reply;
00181 kdDebug(5602) << k_funcinfo << "handled=" << handled << endl;
00182 if ( !handled )
00183 return Kontact::UniqueAppHandler::newInstance();
00184 }
00185 return 0;
00186 }
00187
00188 #include "kaddressbook_plugin.moc"
00189
00190
This file is part of the documentation for kontact Library Version 3.3.2.