kaddressbook_plugin.cpp
00001 /* 00002 This file is part of Kontact. 00003 00004 Copyright (c) 2001 Matthias Hoelzer-Kluepfel <mhk@kde.org> 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 00020 As a special exception, permission is given to link this program 00021 with any edition of TQt, and distribute the resulting executable, 00022 without including the source code for TQt in the source distribution. 00023 */ 00024 00025 #include <tqwidget.h> 00026 #include <tqdragobject.h> 00027 00028 #include <tdeaction.h> 00029 #include <tdeapplication.h> 00030 #include <kdebug.h> 00031 #include <kgenericfactory.h> 00032 #include <kiconloader.h> 00033 #include <tdemessagebox.h> 00034 #include <tdeparts/componentfactory.h> 00035 00036 #include <kaddrbook.h> 00037 #include <tdeabc/addressbook.h> 00038 #include <tdeabc/stdaddressbook.h> 00039 00040 #include <dcopclient.h> 00041 #include "kmailIface_stub.h" 00042 00043 #include <libtdepim/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 TQStringList& ) 00055 : Kontact::Plugin( core, TQT_TQOBJECT(core), "kaddressbook" ), 00056 mStub( 0 ) 00057 { 00058 setInstance( KAddressbookPluginFactory::instance() ); 00059 00060 insertNewAction( new TDEAction( i18n( "New Contact..." ), "identity", 00061 CTRL+SHIFT+Key_C, this, TQT_SLOT( slotNewContact() ), actionCollection(), 00062 "new_contact" ) ); 00063 00064 insertNewAction( new TDEAction( i18n( "&New Distribution List..." ), "kontact_contacts", 0, this, 00065 TQT_SLOT( slotNewDistributionList() ), actionCollection(), "new_distributionlist" ) ); 00066 00067 insertSyncAction( new TDEAction( i18n( "Synchronize Contacts" ), "reload", 00068 0, this, TQT_SLOT( slotSyncContacts() ), actionCollection(), 00069 "kaddressbook_sync" ) ); 00070 mUniqueAppWatcher = new Kontact::UniqueAppWatcher( 00071 new Kontact::UniqueAppHandlerFactory<KABUniqueAppHandler>(), this ); 00072 } 00073 00074 KAddressbookPlugin::~KAddressbookPlugin() 00075 { 00076 } 00077 00078 KParts::ReadOnlyPart* KAddressbookPlugin::createPart() 00079 { 00080 KParts::ReadOnlyPart * part = loadPart(); 00081 if ( !part ) return 0; 00082 00083 // Create the stub that allows us to talk to the part 00084 mStub = new KAddressBookIface_stub( dcopClient(), "kaddressbook", 00085 "KAddressBookIface" ); 00086 return part; 00087 } 00088 00089 TQStringList KAddressbookPlugin::configModules() const 00090 { 00091 TQStringList modules; 00092 modules << "PIM/tdeabconfig.desktop" << "PIM/kabldapconfig.desktop"; 00093 return modules; 00094 } 00095 00096 TQStringList KAddressbookPlugin::invisibleToolbarActions() const 00097 { 00098 return TQStringList( "file_new_contact" ); 00099 } 00100 00101 KAddressBookIface_stub *KAddressbookPlugin::interface() 00102 { 00103 if ( !mStub ) { 00104 part(); 00105 } 00106 Q_ASSERT( mStub ); 00107 return mStub; 00108 } 00109 00110 void KAddressbookPlugin::slotNewContact() 00111 { 00112 interface()->newContact(); 00113 } 00114 00115 00116 void KAddressbookPlugin::slotNewDistributionList() 00117 { 00118 interface()->newDistributionList(); 00119 } 00120 00121 void KAddressbookPlugin::slotSyncContacts() 00122 { 00123 DCOPRef ref( "kaddressbook", "KAddressBookIface" ); 00124 ref.send( "syncAllResources" ); 00125 } 00126 00127 bool KAddressbookPlugin::createDCOPInterface( const TQString& serviceType ) 00128 { 00129 if ( serviceType == "DCOP/AddressBook" ) { 00130 Q_ASSERT( mStub ); 00131 return true; 00132 } 00133 00134 return false; 00135 } 00136 00137 void KAddressbookPlugin::configUpdated() 00138 { 00139 } 00140 00141 bool KAddressbookPlugin::isRunningStandalone() 00142 { 00143 return mUniqueAppWatcher->isRunningStandalone(); 00144 } 00145 00146 bool KAddressbookPlugin::canDecodeDrag( TQMimeSource *mimeSource ) 00147 { 00148 return KPIM::MailListDrag::canDecode( mimeSource ); 00149 } 00150 00151 #include <dcopref.h> 00152 00153 void KAddressbookPlugin::processDropEvent( TQDropEvent *event ) 00154 { 00155 KPIM::MailList mails; 00156 if ( KPIM::MailListDrag::decode( event, mails ) ) { 00157 if ( mails.count() != 1 ) { 00158 KMessageBox::sorry( core(), 00159 i18n( "Drops of multiple mails are not supported." ) ); 00160 } else { 00161 KPIM::MailSummary mail = mails.first(); 00162 00163 KMailIface_stub kmailIface( "kmail", "KMailIface" ); 00164 TQString sFrom = kmailIface.getFrom( mail.serialNumber() ); 00165 00166 if ( !sFrom.isEmpty() ) { 00167 KAddrBookExternal::addEmail( sFrom, core() ); 00168 } 00169 } 00170 return; 00171 } 00172 00173 KMessageBox::sorry( core(), i18n( "Cannot handle drop events of type '%1'." ) 00174 .arg( event->format() ) ); 00175 } 00176 00177 00178 void KAddressbookPlugin::loadProfile( const TQString& directory ) 00179 { 00180 DCOPRef ref( "kaddressbook", "KAddressBookIface" ); 00181 ref.send( "loadProfile", directory ); 00182 } 00183 00184 void KAddressbookPlugin::saveToProfile( const TQString& directory ) const 00185 { 00186 DCOPRef ref( "kaddressbook", "KAddressBookIface" ); 00187 ref.send( "saveToProfile", directory ); 00188 } 00189 00191 00192 #include "../../../kaddressbook/kaddressbook_options.h" 00193 00194 void KABUniqueAppHandler::loadCommandLineOptions() 00195 { 00196 TDECmdLineArgs::addCmdLineOptions( kaddressbook_options ); 00197 } 00198 00199 int KABUniqueAppHandler::newInstance() 00200 { 00201 kdDebug(5602) << k_funcinfo << endl; 00202 // Ensure part is loaded 00203 (void)plugin()->part(); 00204 DCOPRef kAB( "kaddressbook", "KAddressBookIface" ); 00205 DCOPReply reply = kAB.call( "handleCommandLine" ); 00206 if ( reply.isValid() ) { 00207 bool handled = reply; 00208 kdDebug(5602) << k_funcinfo << "handled=" << handled << endl; 00209 if ( !handled ) // no args -> simply bring kaddressbook plugin to front 00210 return Kontact::UniqueAppHandler::newInstance(); 00211 } 00212 return 0; 00213 } 00214 00215 #include "kaddressbook_plugin.moc" 00216 00217 // vim: sw=2 sts=2 tw=80 et