kontact
kaddressbook_plugin.cpp00001
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 <qwidget.h>
00026 #include <qdragobject.h>
00027
00028 #include <kaction.h>
00029 #include <kapplication.h>
00030 #include <kdebug.h>
00031 #include <kgenericfactory.h>
00032 #include <kiconloader.h>
00033 #include <kmessagebox.h>
00034 #include <kparts/componentfactory.h>
00035
00036 #include <kaddrbook.h>
00037 #include <kabc/addressbook.h>
00038 #include <kabc/stdaddressbook.h>
00039
00040 #include <dcopclient.h>
00041 #include "kmailIface_stub.h"
00042
00043 #include <libkdepim/maillistdrag.h>
00044
00045 #include "core.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 CTRL+SHIFT+Key_C, 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::ReadOnlyPart* KAddressbookPlugin::createPart()
00072 {
00073 KParts::ReadOnlyPart * 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 interface()->newContact();
00106 }
00107
00108 bool KAddressbookPlugin::createDCOPInterface( const QString& serviceType )
00109 {
00110 if ( serviceType == "DCOP/AddressBook" ) {
00111 Q_ASSERT( mStub );
00112 return true;
00113 }
00114
00115 return false;
00116 }
00117
00118 void KAddressbookPlugin::configUpdated()
00119 {
00120 }
00121
00122 bool KAddressbookPlugin::isRunningStandalone()
00123 {
00124 return mUniqueAppWatcher->isRunningStandalone();
00125 }
00126
00127 bool KAddressbookPlugin::canDecodeDrag( QMimeSource *mimeSource )
00128 {
00129 return QTextDrag::canDecode( mimeSource ) ||
00130 KPIM::MailListDrag::canDecode( mimeSource );
00131 }
00132
00133 #include <dcopref.h>
00134
00135 void KAddressbookPlugin::processDropEvent( QDropEvent *event )
00136 {
00137 KPIM::MailList mails;
00138 if ( KPIM::MailListDrag::decode( event, mails ) ) {
00139 if ( mails.count() != 1 ) {
00140 KMessageBox::sorry( core(),
00141 i18n( "Drops of multiple mails are not supported." ) );
00142 } else {
00143 KPIM::MailSummary mail = mails.first();
00144
00145 KMailIface_stub kmailIface( "kmail", "KMailIface" );
00146 QString sFrom = kmailIface.getFrom( mail.serialNumber() );
00147
00148 if ( !sFrom.isEmpty() ) {
00149 KAddrBookExternal::addEmail( sFrom, core() );
00150 }
00151 }
00152 return;
00153 }
00154
00155 KMessageBox::sorry( core(), i18n( "Cannot handle drop events of type '%1'." )
00156 .arg( event->format() ) );
00157 }
00158
00160
00161 #include "../../../kaddressbook/kaddressbook_options.h"
00162
00163 void KABUniqueAppHandler::loadCommandLineOptions()
00164 {
00165 KCmdLineArgs::addCmdLineOptions( kaddressbook_options );
00166 }
00167
00168 int KABUniqueAppHandler::newInstance()
00169 {
00170 kdDebug(5602) << k_funcinfo << endl;
00171
00172 (void)plugin()->part();
00173 DCOPRef kAB( "kaddressbook", "KAddressBookIface" );
00174 DCOPReply reply = kAB.call( "handleCommandLine" );
00175 if ( reply.isValid() ) {
00176 bool handled = reply;
00177 kdDebug(5602) << k_funcinfo << "handled=" << handled << endl;
00178 if ( !handled )
00179 return Kontact::UniqueAppHandler::newInstance();
00180 }
00181 return 0;
00182 }
00183
00184 #include "kaddressbook_plugin.moc"
00185
00186
|