kontact

kaddressbook_plugin.cpp
1/*
2 This file is part of Kontact.
3
4 Copyright (c) 2001 Matthias Hoelzer-Kluepfel <mhk@kde.org>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
20 As a special exception, permission is given to link this program
21 with any edition of TQt, and distribute the resulting executable,
22 without including the source code for TQt in the source distribution.
23*/
24
25#include <tqwidget.h>
26#include <tqdragobject.h>
27
28#include <tdeaction.h>
29#include <tdeapplication.h>
30#include <kdebug.h>
31#include <kgenericfactory.h>
32#include <kiconloader.h>
33#include <tdemessagebox.h>
34#include <tdeparts/componentfactory.h>
35
36#include <kaddrbook.h>
37#include <tdeabc/addressbook.h>
38#include <tdeabc/stdaddressbook.h>
39
40#include <dcopclient.h>
41#include "kmailIface_stub.h"
42
43#include <libtdepim/maillistdrag.h>
44
45#include "core.h"
46#include "plugin.h"
47
48#include "kaddressbook_plugin.h"
49
50typedef KGenericFactory< KAddressbookPlugin, Kontact::Core > KAddressbookPluginFactory;
51K_EXPORT_COMPONENT_FACTORY( libkontact_kaddressbookplugin,
52 KAddressbookPluginFactory( "kontact_kaddressbookplugin" ) )
53
54KAddressbookPlugin::KAddressbookPlugin( Kontact::Core *core, const char *, const TQStringList& )
55 : Kontact::Plugin( core, core, "kaddressbook" ),
56 mStub( 0 )
57{
58 setInstance( KAddressbookPluginFactory::instance() );
59
60 insertNewAction( new TDEAction( i18n( "New Contact..." ), "identity",
61 CTRL+SHIFT+Key_C, this, TQ_SLOT( slotNewContact() ), actionCollection(),
62 "new_contact" ) );
63
64 insertNewAction( new TDEAction( i18n( "&New Distribution List..." ), "kontact_contacts", 0, this,
65 TQ_SLOT( slotNewDistributionList() ), actionCollection(), "new_distributionlist" ) );
66
67 insertSyncAction( new TDEAction( i18n( "Synchronize Contacts" ), "reload",
68 0, this, TQ_SLOT( slotSyncContacts() ), actionCollection(),
69 "kaddressbook_sync" ) );
70 mUniqueAppWatcher = new Kontact::UniqueAppWatcher(
72}
73
74KAddressbookPlugin::~KAddressbookPlugin()
75{
76}
77
78KParts::ReadOnlyPart* KAddressbookPlugin::createPart()
79{
80 KParts::ReadOnlyPart * part = loadPart();
81 if ( !part ) return 0;
82
83 // Create the stub that allows us to talk to the part
84 mStub = new KAddressBookIface_stub( dcopClient(), "kaddressbook",
85 "KAddressBookIface" );
86 return part;
87}
88
89TQStringList KAddressbookPlugin::configModules() const
90{
91 TQStringList modules;
92 modules << "PIM/tdeabconfig.desktop" << "PIM/kabldapconfig.desktop";
93 return modules;
94}
95
97{
98 return TQStringList( "file_new_contact" );
99}
100
101KAddressBookIface_stub *KAddressbookPlugin::interface()
102{
103 if ( !mStub ) {
104 part();
105 }
106 Q_ASSERT( mStub );
107 return mStub;
108}
109
110void KAddressbookPlugin::slotNewContact()
111{
112 interface()->newContact();
113}
114
115
116void KAddressbookPlugin::slotNewDistributionList()
117{
118 interface()->newDistributionList();
119}
120
121void KAddressbookPlugin::slotSyncContacts()
122{
123 DCOPRef ref( "kaddressbook", "KAddressBookIface" );
124 ref.send( "syncAllResources" );
125}
126
127bool KAddressbookPlugin::createDCOPInterface( const TQString& serviceType )
128{
129 if ( serviceType == "DCOP/AddressBook" ) {
130 Q_ASSERT( mStub );
131 return true;
132 }
133
134 return false;
135}
136
138{
139}
140
142{
143 return mUniqueAppWatcher->isRunningStandalone();
144}
145
146bool KAddressbookPlugin::canDecodeDrag( TQMimeSource *mimeSource )
147{
148 return KPIM::MailListDrag::canDecode( mimeSource );
149}
150
151#include <dcopref.h>
152
153void KAddressbookPlugin::processDropEvent( TQDropEvent *event )
154{
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." ) );
160 } else {
161 KPIM::MailSummary mail = mails.first();
162
163 KMailIface_stub kmailIface( "kmail", "KMailIface" );
164 TQString sFrom = kmailIface.getFrom( mail.serialNumber() );
165
166 if ( !sFrom.isEmpty() ) {
167 KAddrBookExternal::addEmail( sFrom, core() );
168 }
169 }
170 return;
171 }
172
173 KMessageBox::sorry( core(), i18n( "Cannot handle drop events of type '%1'." )
174 .arg( event->format() ) );
175}
176
177
178void KAddressbookPlugin::loadProfile( const TQString& directory )
179{
180 DCOPRef ref( "kaddressbook", "KAddressBookIface" );
181 ref.send( "loadProfile", directory );
182}
183
184void KAddressbookPlugin::saveToProfile( const TQString& directory ) const
185{
186 DCOPRef ref( "kaddressbook", "KAddressBookIface" );
187 ref.send( "saveToProfile", directory );
188}
189
191
192#include "../../../kaddressbook/kaddressbook_options.h"
193
195{
196 TDECmdLineArgs::addCmdLineOptions( kaddressbook_options );
197}
198
200{
201 kdDebug(5602) << k_funcinfo << endl;
202 // Ensure part is loaded
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;
209 if ( !handled ) // no args -> simply bring kaddressbook plugin to front
211 }
212 return 0;
213}
214
215#include "kaddressbook_plugin.moc"
KParts::ReadOnlyPart * part()
You can use this method if you need to access the current part.
Definition plugin.cpp:145
DCOPClient * dcopClient() const
Retrieve the current DCOP Client for the plugin.
Definition plugin.cpp:163
virtual TQStringList invisibleToolbarActions() const
Returns a list of action name which shall be hidden in the main toolbar.
Definition plugin.h:233
virtual bool isRunningStandalone()
Reimplement this method and return whether a standalone application is still running This is only req...
Definition plugin.h:131
virtual KParts::ReadOnlyPart * createPart()=0
Reimplement and return the part here.
virtual void configUpdated()
This function is called whenever the config dialog has been closed successfully.
Definition plugin.cpp:205
Used by UniqueAppWatcher below, to create the above UniqueAppHandler object when necessary.
virtual void loadCommandLineOptions()=0
This must be reimplemented so that app-specific command line options can be parsed.
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,...