todoplugin.cpp
1/*
2 This file is part of Kontact.
3
4 Copyright (c) 2003 Cornelius Schumacher <schumacher@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#include <tqfile.h>
28
29#include <tdeapplication.h>
30#include <tdeabc/vcardconverter.h>
31#include <tdeaction.h>
32#include <kdebug.h>
33#include <kgenericfactory.h>
34#include <kiconloader.h>
35#include <tdemessagebox.h>
36#include <dcopclient.h>
37#include <dcopref.h>
38#include <tdetempfile.h>
39
40#include <libkcal/calendarlocal.h>
41#include <libkcal/icaldrag.h>
42
43#include <libtdepim/maillistdrag.h>
44#include <libtdepim/kvcarddrag.h>
45#include <libtdepim/kpimprefs.h>
46
47#include "core.h"
48
49#include "todoplugin.h"
50#include "todosummarywidget.h"
51#include "korg_uniqueapp.h"
52
53typedef KGenericFactory< TodoPlugin, Kontact::Core > TodoPluginFactory;
54K_EXPORT_COMPONENT_FACTORY( libkontact_todoplugin,
55 TodoPluginFactory( "kontact_todoplugin" ) )
56
57TodoPlugin::TodoPlugin( Kontact::Core *core, const char *, const TQStringList& )
58 : Kontact::Plugin( core, core, "korganizer" ),
59 mIface( 0 )
60{
61 setInstance( TodoPluginFactory::instance() );
62 instance()->iconLoader()->addAppDir("tdepim");
63
64 insertNewAction( new TDEAction( i18n( "New To-do..." ), "newtodo",
65 CTRL+SHIFT+Key_T, this, TQ_SLOT( slotNewTodo() ), actionCollection(),
66 "new_todo" ) );
67
68 insertSyncAction( new TDEAction( i18n( "Synchronize To-do List" ), "reload",
69 0, this, TQ_SLOT( slotSyncTodos() ), actionCollection(),
70 "todo_sync" ) );
71
72 mUniqueAppWatcher = new Kontact::UniqueAppWatcher(
74}
75
76TodoPlugin::~TodoPlugin()
77{
78}
79
80Kontact::Summary *TodoPlugin::createSummaryWidget( TQWidget *parent )
81{
82 return new TodoSummaryWidget( this, parent );
83}
84
85KParts::ReadOnlyPart *TodoPlugin::createPart()
86{
87 KParts::ReadOnlyPart *part = loadPart();
88
89 if ( !part )
90 return 0;
91
92 dcopClient(); // ensure that we register to DCOP as "korganizer"
93 mIface = new KCalendarIface_stub( dcopClient(), "kontact", "CalendarIface" );
94
95 return part;
96}
97
98void TodoPlugin::select()
99{
100 interface()->showTodoView();
101}
102
103TQStringList TodoPlugin::invisibleToolbarActions() const
104{
105 TQStringList invisible;
106 invisible += "new_event";
107 invisible += "new_todo";
108 invisible += "new_journal";
109
110 invisible += "view_day";
111 invisible += "view_list";
112 invisible += "view_workweek";
113 invisible += "view_week";
114 invisible += "view_nextx";
115 invisible += "view_month";
116 invisible += "view_journal";
117 return invisible;
118}
119
120KCalendarIface_stub *TodoPlugin::interface()
121{
122 if ( !mIface ) {
123 part();
124 }
125 Q_ASSERT( mIface );
126 return mIface;
127}
128
129void TodoPlugin::slotNewTodo()
130{
131 interface()->openTodoEditor( "" );
132}
133
134void TodoPlugin::slotSyncTodos()
135{
136 DCOPRef ref( "kmail", "KMailICalIface" );
137 ref.send( "triggerSync", TQString("Todo") );
138}
139
140bool TodoPlugin::createDCOPInterface( const TQString& serviceType )
141{
142 kdDebug(5602) << k_funcinfo << serviceType << endl;
143 if ( serviceType == "DCOP/Organizer" || serviceType == "DCOP/Calendar" ) {
144 if ( part() )
145 return true;
146 }
147
148 return false;
149}
150
151bool TodoPlugin::canDecodeDrag( TQMimeSource *mimeSource )
152{
153 return TQTextDrag::canDecode( mimeSource ) ||
154 KPIM::MailListDrag::canDecode( mimeSource );
155}
156
157bool TodoPlugin::isRunningStandalone()
158{
159 return mUniqueAppWatcher->isRunningStandalone();
160}
161
162void TodoPlugin::processDropEvent( TQDropEvent *event )
163{
164 TDEABC::Addressee::List list;
165 if ( KVCardDrag::decode( event, list ) ) {
166 TQStringList attendees;
167 TDEABC::Addressee::List::Iterator it;
168 for ( it = list.begin(); it != list.end(); ++it ) {
169 TQString email = (*it).fullEmail();
170 if ( email.isEmpty() ) {
171 attendees.append( (*it).realName() + "<>" );
172 } else {
173 attendees.append( email );
174 }
175 }
176 interface()->openTodoEditor( i18n( "Meeting" ), TQString(), TQString(),
177 attendees );
178 return;
179 }
180
181 if ( KCal::ICalDrag::canDecode( event) ) {
182 KCal::CalendarLocal cal( KPimPrefs::timezone() );
183 if ( KCal::ICalDrag::decode( event, &cal ) ) {
184 KCal::Incidence::List incidences = cal.incidences();
185 if ( !incidences.isEmpty() ) {
186 event->accept();
187 KCal::Incidence *i = incidences.first();
188 TQString summary;
189 if ( dynamic_cast<KCal::Journal*>( i ) )
190 summary = i18n( "Note: %1" ).arg( i->summary() );
191 else
192 summary = i->summary();
193 interface()->openTodoEditor( summary, i->description(), TQString() );
194 return;
195 }
196 // else fall through to text decoding
197 }
198 }
199
200 TQString text;
201 if ( TQTextDrag::decode( event, text ) ) {
202 interface()->openTodoEditor( text );
203 return;
204 }
205
206 KPIM::MailList mails;
207 if ( KPIM::MailListDrag::decode( event, mails ) ) {
208 if ( mails.count() != 1 ) {
209 KMessageBox::sorry( core(),
210 i18n("Drops of multiple mails are not supported." ) );
211 } else {
212 KPIM::MailSummary mail = mails.first();
213 TQString txt = i18n("From: %1\nTo: %2\nSubject: %3").arg( mail.from() )
214 .arg( mail.to() ).arg( mail.subject() );
215
216 KTempFile tf;
217 tf.setAutoDelete( true );
218 TQString uri = "kmail:" + TQString::number( mail.serialNumber() ) + "/" +
219 mail.messageId();
220 tf.file()->writeBlock( event->encodedData( "message/rfc822" ) );
221 tf.close();
222 interface()->openTodoEditor( i18n("Mail: %1").arg( mail.subject() ),
223 txt, uri, tf.name(), TQStringList(), "message/rfc822", false );
224 }
225 return;
226 }
227
228 KMessageBox::sorry( core(), i18n("Cannot handle drop events of type '%1'.")
229 .arg( event->format() ) );
230}
231
232#include "todoplugin.moc"
static bool canDecode(TQMimeSource *)
static bool decode(TQMimeSource *e, Calendar *cal)
TQString description() const
TQString summary() const
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.
If the standalone application is running by itself, we need to watch for when the user closes it,...