todoplugin.cpp
00001 /* 00002 This file is part of Kontact. 00003 00004 Copyright (c) 2003 Cornelius Schumacher <schumacher@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 #include <tqfile.h> 00028 00029 #include <tdeapplication.h> 00030 #include <tdeabc/vcardconverter.h> 00031 #include <tdeaction.h> 00032 #include <kdebug.h> 00033 #include <kgenericfactory.h> 00034 #include <kiconloader.h> 00035 #include <tdemessagebox.h> 00036 #include <dcopclient.h> 00037 #include <dcopref.h> 00038 #include <tdetempfile.h> 00039 00040 #include <libkcal/calendarlocal.h> 00041 #include <libkcal/icaldrag.h> 00042 00043 #include <libtdepim/maillistdrag.h> 00044 #include <libtdepim/kvcarddrag.h> 00045 #include <libtdepim/kpimprefs.h> 00046 00047 #include "core.h" 00048 00049 #include "todoplugin.h" 00050 #include "todosummarywidget.h" 00051 #include "korg_uniqueapp.h" 00052 00053 typedef KGenericFactory< TodoPlugin, Kontact::Core > TodoPluginFactory; 00054 K_EXPORT_COMPONENT_FACTORY( libkontact_todoplugin, 00055 TodoPluginFactory( "kontact_todoplugin" ) ) 00056 00057 TodoPlugin::TodoPlugin( Kontact::Core *core, const char *, const TQStringList& ) 00058 : Kontact::Plugin( core, TQT_TQOBJECT(core), "korganizer" ), 00059 mIface( 0 ) 00060 { 00061 setInstance( TodoPluginFactory::instance() ); 00062 instance()->iconLoader()->addAppDir("tdepim"); 00063 00064 insertNewAction( new TDEAction( i18n( "New To-do..." ), "newtodo", 00065 CTRL+SHIFT+Key_T, this, TQT_SLOT( slotNewTodo() ), actionCollection(), 00066 "new_todo" ) ); 00067 00068 insertSyncAction( new TDEAction( i18n( "Synchronize To-do List" ), "reload", 00069 0, this, TQT_SLOT( slotSyncTodos() ), actionCollection(), 00070 "todo_sync" ) ); 00071 00072 mUniqueAppWatcher = new Kontact::UniqueAppWatcher( 00073 new Kontact::UniqueAppHandlerFactory<KOrganizerUniqueAppHandler>(), this ); 00074 } 00075 00076 TodoPlugin::~TodoPlugin() 00077 { 00078 } 00079 00080 Kontact::Summary *TodoPlugin::createSummaryWidget( TQWidget *parent ) 00081 { 00082 return new TodoSummaryWidget( this, parent ); 00083 } 00084 00085 KParts::ReadOnlyPart *TodoPlugin::createPart() 00086 { 00087 KParts::ReadOnlyPart *part = loadPart(); 00088 00089 if ( !part ) 00090 return 0; 00091 00092 dcopClient(); // ensure that we register to DCOP as "korganizer" 00093 mIface = new KCalendarIface_stub( dcopClient(), "kontact", "CalendarIface" ); 00094 00095 return part; 00096 } 00097 00098 void TodoPlugin::select() 00099 { 00100 interface()->showTodoView(); 00101 } 00102 00103 TQStringList TodoPlugin::invisibleToolbarActions() const 00104 { 00105 TQStringList invisible; 00106 invisible += "new_event"; 00107 invisible += "new_todo"; 00108 invisible += "new_journal"; 00109 00110 invisible += "view_day"; 00111 invisible += "view_list"; 00112 invisible += "view_workweek"; 00113 invisible += "view_week"; 00114 invisible += "view_nextx"; 00115 invisible += "view_month"; 00116 invisible += "view_journal"; 00117 return invisible; 00118 } 00119 00120 KCalendarIface_stub *TodoPlugin::interface() 00121 { 00122 if ( !mIface ) { 00123 part(); 00124 } 00125 Q_ASSERT( mIface ); 00126 return mIface; 00127 } 00128 00129 void TodoPlugin::slotNewTodo() 00130 { 00131 interface()->openTodoEditor( "" ); 00132 } 00133 00134 void TodoPlugin::slotSyncTodos() 00135 { 00136 DCOPRef ref( "kmail", "KMailICalIface" ); 00137 ref.send( "triggerSync", TQString("Todo") ); 00138 } 00139 00140 bool TodoPlugin::createDCOPInterface( const TQString& serviceType ) 00141 { 00142 kdDebug(5602) << k_funcinfo << serviceType << endl; 00143 if ( serviceType == "DCOP/Organizer" || serviceType == "DCOP/Calendar" ) { 00144 if ( part() ) 00145 return true; 00146 } 00147 00148 return false; 00149 } 00150 00151 bool TodoPlugin::canDecodeDrag( TQMimeSource *mimeSource ) 00152 { 00153 return TQTextDrag::canDecode( mimeSource ) || 00154 KPIM::MailListDrag::canDecode( mimeSource ); 00155 } 00156 00157 bool TodoPlugin::isRunningStandalone() 00158 { 00159 return mUniqueAppWatcher->isRunningStandalone(); 00160 } 00161 00162 void TodoPlugin::processDropEvent( TQDropEvent *event ) 00163 { 00164 TDEABC::Addressee::List list; 00165 if ( KVCardDrag::decode( event, list ) ) { 00166 TQStringList attendees; 00167 TDEABC::Addressee::List::Iterator it; 00168 for ( it = list.begin(); it != list.end(); ++it ) { 00169 TQString email = (*it).fullEmail(); 00170 if ( email.isEmpty() ) { 00171 attendees.append( (*it).realName() + "<>" ); 00172 } else { 00173 attendees.append( email ); 00174 } 00175 } 00176 interface()->openTodoEditor( i18n( "Meeting" ), TQString(), TQString(), 00177 attendees ); 00178 return; 00179 } 00180 00181 if ( KCal::ICalDrag::canDecode( event) ) { 00182 KCal::CalendarLocal cal( KPimPrefs::timezone() ); 00183 if ( KCal::ICalDrag::decode( event, &cal ) ) { 00184 KCal::Incidence::List incidences = cal.incidences(); 00185 if ( !incidences.isEmpty() ) { 00186 event->accept(); 00187 KCal::Incidence *i = incidences.first(); 00188 TQString summary; 00189 if ( dynamic_cast<KCal::Journal*>( i ) ) 00190 summary = i18n( "Note: %1" ).arg( i->summary() ); 00191 else 00192 summary = i->summary(); 00193 interface()->openTodoEditor( summary, i->description(), TQString() ); 00194 return; 00195 } 00196 // else fall through to text decoding 00197 } 00198 } 00199 00200 TQString text; 00201 if ( TQTextDrag::decode( event, text ) ) { 00202 interface()->openTodoEditor( text ); 00203 return; 00204 } 00205 00206 KPIM::MailList mails; 00207 if ( KPIM::MailListDrag::decode( event, mails ) ) { 00208 if ( mails.count() != 1 ) { 00209 KMessageBox::sorry( core(), 00210 i18n("Drops of multiple mails are not supported." ) ); 00211 } else { 00212 KPIM::MailSummary mail = mails.first(); 00213 TQString txt = i18n("From: %1\nTo: %2\nSubject: %3").arg( mail.from() ) 00214 .arg( mail.to() ).arg( mail.subject() ); 00215 00216 KTempFile tf; 00217 tf.setAutoDelete( true ); 00218 TQString uri = "kmail:" + TQString::number( mail.serialNumber() ) + "/" + 00219 mail.messageId(); 00220 tf.file()->writeBlock( event->encodedData( "message/rfc822" ) ); 00221 tf.close(); 00222 interface()->openTodoEditor( i18n("Mail: %1").arg( mail.subject() ), 00223 txt, uri, tf.name(), TQStringList(), "message/rfc822", false ); 00224 } 00225 return; 00226 } 00227 00228 KMessageBox::sorry( core(), i18n("Cannot handle drop events of type '%1'.") 00229 .arg( event->format() ) ); 00230 } 00231 00232 #include "todoplugin.moc"