26 #include <tqdragobject.h>
28 #include <tdeaction.h>
29 #include <tdeapplication.h>
31 #include <kgenericfactory.h>
32 #include <kiconloader.h>
33 #include <tdemessagebox.h>
34 #include <tdeparts/componentfactory.h>
36 #include <kaddrbook.h>
37 #include <tdeabc/addressbook.h>
38 #include <tdeabc/stdaddressbook.h>
40 #include <dcopclient.h>
41 #include "kmailIface_stub.h"
43 #include <libtdepim/maillistdrag.h>
48 #include "kaddressbook_plugin.h"
50 typedef KGenericFactory< KAddressbookPlugin, Kontact::Core > KAddressbookPluginFactory;
51 K_EXPORT_COMPONENT_FACTORY( libkontact_kaddressbookplugin,
52 KAddressbookPluginFactory(
"kontact_kaddressbookplugin" ) )
54 KAddressbookPlugin::KAddressbookPlugin( Kontact::Core *core, const
char *, const TQStringList& )
55 : Kontact::Plugin( core, core, "kaddressbook" ),
58 setInstance( KAddressbookPluginFactory::instance() );
60 insertNewAction(
new TDEAction( i18n(
"New Contact..." ),
"identity",
61 CTRL+SHIFT+Key_C,
this, TQ_SLOT( slotNewContact() ), actionCollection(),
64 insertNewAction(
new TDEAction( i18n(
"&New Distribution List..." ),
"kontact_contacts", 0,
this,
65 TQ_SLOT( slotNewDistributionList() ), actionCollection(),
"new_distributionlist" ) );
67 insertSyncAction(
new TDEAction( i18n(
"Synchronize Contacts" ),
"reload",
68 0,
this, TQ_SLOT( slotSyncContacts() ), actionCollection(),
69 "kaddressbook_sync" ) );
74 KAddressbookPlugin::~KAddressbookPlugin()
78 KParts::ReadOnlyPart* KAddressbookPlugin::createPart()
80 KParts::ReadOnlyPart * part = loadPart();
81 if ( !part )
return 0;
84 mStub =
new KAddressBookIface_stub( dcopClient(),
"kaddressbook",
85 "KAddressBookIface" );
89 TQStringList KAddressbookPlugin::configModules()
const
92 modules <<
"PIM/tdeabconfig.desktop" <<
"PIM/kabldapconfig.desktop";
96 TQStringList KAddressbookPlugin::invisibleToolbarActions()
const
98 return TQStringList(
"file_new_contact" );
101 KAddressBookIface_stub *KAddressbookPlugin::interface()
110 void KAddressbookPlugin::slotNewContact()
112 interface()->newContact();
116 void KAddressbookPlugin::slotNewDistributionList()
118 interface()->newDistributionList();
121 void KAddressbookPlugin::slotSyncContacts()
123 DCOPRef ref(
"kaddressbook",
"KAddressBookIface" );
124 ref.send(
"syncAllResources" );
127 bool KAddressbookPlugin::createDCOPInterface(
const TQString& serviceType )
129 if ( serviceType ==
"DCOP/AddressBook" ) {
137 void KAddressbookPlugin::configUpdated()
141 bool KAddressbookPlugin::isRunningStandalone()
143 return mUniqueAppWatcher->isRunningStandalone();
146 bool KAddressbookPlugin::canDecodeDrag( TQMimeSource *mimeSource )
148 return KPIM::MailListDrag::canDecode( mimeSource );
153 void KAddressbookPlugin::processDropEvent( TQDropEvent *event )
155 KPIM::MailList mails;
156 if ( KPIM::MailListDrag::decode( event, mails ) ) {
157 if ( mails.count() != 1 ) {
158 KMessageBox::sorry( core(),
159 i18n(
"Drops of multiple mails are not supported." ) );
161 KPIM::MailSummary mail = mails.first();
163 KMailIface_stub kmailIface(
"kmail",
"KMailIface" );
164 TQString sFrom = kmailIface.getFrom( mail.serialNumber() );
166 if ( !sFrom.isEmpty() ) {
167 KAddrBookExternal::addEmail( sFrom, core() );
173 KMessageBox::sorry( core(), i18n(
"Cannot handle drop events of type '%1'." )
174 .arg( event->format() ) );
178 void KAddressbookPlugin::loadProfile(
const TQString& directory )
180 DCOPRef ref(
"kaddressbook",
"KAddressBookIface" );
181 ref.send(
"loadProfile", directory );
184 void KAddressbookPlugin::saveToProfile(
const TQString& directory )
const
186 DCOPRef ref(
"kaddressbook",
"KAddressBookIface" );
187 ref.send(
"saveToProfile", directory );
192 #include "../../../kaddressbook/kaddressbook_options.h"
194 void KABUniqueAppHandler::loadCommandLineOptions()
196 TDECmdLineArgs::addCmdLineOptions( kaddressbook_options );
199 int KABUniqueAppHandler::newInstance()
201 kdDebug(5602) << k_funcinfo << endl;
203 (void)plugin()->part();
204 DCOPRef kAB(
"kaddressbook",
"KAddressBookIface" );
205 DCOPReply reply = kAB.call(
"handleCommandLine" );
206 if ( reply.isValid() ) {
207 bool handled = reply;
208 kdDebug(5602) << k_funcinfo <<
"handled=" << handled << endl;
215 #include "kaddressbook_plugin.moc"
Used by UniqueAppWatcher below, to create the above UniqueAppHandler object when necessary.
virtual int newInstance()
We can't use k_dcop and dcopidl here, because the data passed to newInstance can't be expressed in te...
If the standalone application is running by itself, we need to watch for when the user closes it,...