kmail_plugin.cpp
1 /*
2  This file is part of Kontact.
3  Copyright (c) 2003 Kontact Developer
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 
19  As a special exception, permission is given to link this program
20  with any edition of TQt, and distribute the resulting executable,
21  without including the source code for TQt in the source distribution.
22 */
23 
24 #include <tqwidget.h>
25 
26 #include <tdeaction.h>
27 #include <tdeapplication.h>
28 #include <kdebug.h>
29 #include <kgenericfactory.h>
30 #include <kiconloader.h>
31 #include <tdeparts/componentfactory.h>
32 #include <kstandarddirs.h>
33 #include <dcopclient.h>
34 #include <tdetempfile.h>
35 
36 #include <tdeabc/addressee.h>
37 
38 #include <libkcal/vcaldrag.h>
39 #include <libkcal/icaldrag.h>
40 #include <libkcal/calendarlocal.h>
41 
42 #include <libtdepim/kvcarddrag.h>
43 
44 #include <kmail/kmail_part.h>
45 #include <kmail/kmkernel.h>
46 
47 #include "core.h"
48 #include "summarywidget.h"
49 
50 #include "kmail_plugin.h"
51 
52 using namespace KCal;
53 
54 typedef KGenericFactory<KMailPlugin, Kontact::Core> KMailPluginFactory;
55 K_EXPORT_COMPONENT_FACTORY( libkontact_kmailplugin,
56  KMailPluginFactory( "kontact_kmailplugin" ) )
57 
58 KMailPlugin::KMailPlugin(Kontact::Core *core, const char *, const TQStringList& )
59  : Kontact::Plugin( core, core, "kmail" ),
60  mStub( 0 )
61 {
62  setInstance( KMailPluginFactory::instance() );
63 
64  insertNewAction( new TDEAction( i18n( "New Message..." ), "mail-message-new",
65  CTRL+SHIFT+Key_M, this, TQ_SLOT( slotNewMail() ), actionCollection(),
66  "new_mail" ) );
67 
68  insertSyncAction( new TDEAction( i18n( "Synchronize Mail" ), "reload",
69  0, this, TQ_SLOT( slotSyncFolders() ), actionCollection(),
70  "sync_mail" ) );
71 
72  mUniqueAppWatcher = new Kontact::UniqueAppWatcher(
74 }
75 
76 bool KMailPlugin::canDecodeDrag( TQMimeSource *qms )
77 {
78  return ( ICalDrag::canDecode( qms ) ||
79  VCalDrag::canDecode( qms ) ||
80  KVCardDrag::canDecode( qms ) );
81 }
82 
83 void KMailPlugin::processDropEvent( TQDropEvent * de )
84 {
85  kdDebug() << k_funcinfo << endl;
86  CalendarLocal cal( TQString::fromLatin1("UTC") );
87  TDEABC::Addressee::List list;
88 
89  if ( VCalDrag::decode( de, &cal ) || ICalDrag::decode( de, &cal ) ) {
90  KTempFile tmp( locateLocal( "tmp", "incidences-" ), ".ics" );
91  cal.save( tmp.name() );
92  openComposer( KURL::fromPathOrURL( tmp.name() ) );
93  }
94  else if ( KVCardDrag::decode( de, list ) ) {
95  TDEABC::Addressee::List::Iterator it;
96  TQStringList to;
97  for ( it = list.begin(); it != list.end(); ++it ) {
98  to.append( ( *it ).fullEmail() );
99  }
100  openComposer( to.join(", ") );
101  }
102 
103 }
104 
105 void KMailPlugin::openComposer( const KURL& attach )
106 {
107  (void) part(); // ensure part is loaded
108  Q_ASSERT( mStub );
109  if ( mStub ) {
110  if ( attach.isValid() )
111  mStub->newMessage( "", "", "", false, true, KURL(), attach );
112  else
113  mStub->newMessage( "", "", "", false, true, KURL(), KURL() );
114  }
115 }
116 
117 void KMailPlugin::openComposer( const TQString& to )
118 {
119  (void) part(); // ensure part is loaded
120  Q_ASSERT( mStub );
121  if ( mStub ) {
122  mStub->newMessage( to, "", "", false, true, KURL(), KURL() );
123  }
124 }
125 
126 void KMailPlugin::slotNewMail()
127 {
128  openComposer( TQString() );
129 }
130 
131 void KMailPlugin::slotSyncFolders()
132 {
133  DCOPRef ref( "kmail", "KMailIface" );
134  ref.send( "checkMail" );
135 }
136 
137 KMailPlugin::~KMailPlugin()
138 {
139 }
140 
141 bool KMailPlugin::createDCOPInterface( const TQString& serviceType )
142 {
143  if ( serviceType == "DCOP/ResourceBackend/IMAP" ) {
144  if ( part() )
145  return true;
146  }
147 
148  return false;
149 }
150 
151 TQString KMailPlugin::tipFile() const
152 {
153  TQString file = ::locate("data", "kmail/tips");
154  return file;
155 }
156 
157 KParts::ReadOnlyPart* KMailPlugin::createPart()
158 {
159  KParts::ReadOnlyPart *part = loadPart();
160  if ( !part ) return 0;
161 
162  mStub = new KMailIface_stub( dcopClient(), "kmail", "KMailIface" );
163 
164  return part;
165 }
166 
167 TQStringList KMailPlugin::invisibleToolbarActions() const
168 {
169  return TQStringList( "new_message" );
170 }
171 
172 bool KMailPlugin::isRunningStandalone()
173 {
174  return mUniqueAppWatcher->isRunningStandalone();
175 }
176 
177 Kontact::Summary *KMailPlugin::createSummaryWidget( TQWidget *parent )
178 {
179  return new SummaryWidget( this, parent );
180 }
181 
183 
184 #include "../../../kmail/kmail_options.h"
185 void KMailUniqueAppHandler::loadCommandLineOptions()
186 {
187  TDECmdLineArgs::addCmdLineOptions( kmail_options );
188 }
189 
190 int KMailUniqueAppHandler::newInstance()
191 {
192  // Ensure part is loaded
193  (void)plugin()->part();
194  DCOPRef kmail( "kmail", "KMailIface" );
195  DCOPReply reply = kmail.call( "handleCommandLine", false );
196  if ( reply.isValid() ) {
197  bool handled = reply;
198  //kdDebug(5602) << k_funcinfo << "handled=" << handled << endl;
199  if ( !handled ) // no args -> simply bring kmail plugin to front
201  }
202  return 0;
203 }
204 
205 bool KMailPlugin::queryClose() const {
206  KMailIface_stub stub( kapp->dcopClient(), "kmail", "KMailIface" );
207  bool canClose=stub.canQueryClose();
208  return canClose;
209 }
210 
211 void KMailPlugin::loadProfile( const TQString& profileDirectory ) {
212  DCOPRef ref( "kmail", "KMailIface" );
213  ref.send( "loadProfile", profileDirectory );
214 }
215 
216 void KMailPlugin::saveToProfile( const TQString& profileDirectory ) {
217  DCOPRef ref( "kmail", "KMailIface" );
218  ref.send( "saveToProfile", profileDirectory );
219 }
220 
221 #include "kmail_plugin.moc"
static bool canDecode(TQMimeSource *)
static bool decode(TQMimeSource *e, Calendar *cal)
static bool canDecode(TQMimeSource *)
static bool decode(TQMimeSource *e, Calendar *cal)
Summary widget for display in the Summary View plugin.
Definition: summary.h:37
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,...