00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <qwidget.h>
00026 #include <qdragobject.h>
00027 #include <qfile.h>
00028
00029 #include <kapplication.h>
00030 #include <kabc/vcardconverter.h>
00031 #include <kaction.h>
00032 #include <kdebug.h>
00033 #include <kgenericfactory.h>
00034 #include <kiconloader.h>
00035 #include <kmessagebox.h>
00036 #include <dcopclient.h>
00037 #include <dcopref.h>
00038 #include <ktempfile.h>
00039
00040 #include <libkcal/calendarlocal.h>
00041 #include <libkcal/icaldrag.h>
00042
00043 #include <libkdepim/maillistdrag.h>
00044 #include <libkdepim/kvcarddrag.h>
00045 #include <libkdepim/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 QStringList& )
00058 : Kontact::Plugin( core, core, "korganizer" ),
00059 mIface( 0 )
00060 {
00061 setInstance( TodoPluginFactory::instance() );
00062 instance()->iconLoader()->addAppDir("kdepim");
00063
00064 insertNewAction( new KAction( i18n( "New To-do..." ), "newtodo",
00065 CTRL+SHIFT+Key_T, this, SLOT( slotNewTodo() ), actionCollection(),
00066 "new_todo" ) );
00067
00068 insertSyncAction( new KAction( i18n( "Synchronize To-do List" ), "reload",
00069 0, this, 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( QWidget *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();
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 QStringList TodoPlugin::invisibleToolbarActions() const
00104 {
00105 QStringList 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", QString("Todo") );
00138 }
00139
00140 bool TodoPlugin::createDCOPInterface( const QString& 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( QMimeSource *mimeSource )
00152 {
00153 return QTextDrag::canDecode( mimeSource ) ||
00154 KPIM::MailListDrag::canDecode( mimeSource );
00155 }
00156
00157 bool TodoPlugin::isRunningStandalone()
00158 {
00159 return mUniqueAppWatcher->isRunningStandalone();
00160 }
00161
00162 void TodoPlugin::processDropEvent( QDropEvent *event )
00163 {
00164 QString text;
00165
00166 KABC::VCardConverter converter;
00167 if ( KVCardDrag::canDecode( event ) && KVCardDrag::decode( event, text ) ) {
00168 KABC::Addressee::List contacts = converter.parseVCards( text );
00169 KABC::Addressee::List::Iterator it;
00170
00171 QStringList attendees;
00172 for ( it = contacts.begin(); it != contacts.end(); ++it ) {
00173 QString email = (*it).fullEmail();
00174 if ( email.isEmpty() )
00175 attendees.append( (*it).realName() + "<>" );
00176 else
00177 attendees.append( email );
00178 }
00179
00180 interface()->openTodoEditor( i18n( "Meeting" ), QString::null, QString::null,
00181 attendees );
00182 return;
00183 }
00184
00185 if ( KCal::ICalDrag::canDecode( event) ) {
00186 KCal::CalendarLocal cal( KPimPrefs::timezone() );
00187 if ( KCal::ICalDrag::decode( event, &cal ) ) {
00188 KCal::Journal::List journals = cal.journals();
00189 if ( !journals.isEmpty() ) {
00190 event->accept();
00191 KCal::Journal *j = journals.first();
00192 interface()->openTodoEditor( i18n("Note: %1").arg( j->summary() ), j->description(), QString() );
00193 return;
00194 }
00195
00196 }
00197 }
00198
00199 if ( QTextDrag::decode( event, text ) ) {
00200 interface()->openTodoEditor( text );
00201 return;
00202 }
00203
00204 KPIM::MailList mails;
00205 if ( KPIM::MailListDrag::decode( event, mails ) ) {
00206 if ( mails.count() != 1 ) {
00207 KMessageBox::sorry( core(),
00208 i18n("Drops of multiple mails are not supported." ) );
00209 } else {
00210 KPIM::MailSummary mail = mails.first();
00211 QString txt = i18n("From: %1\nTo: %2\nSubject: %3").arg( mail.from() )
00212 .arg( mail.to() ).arg( mail.subject() );
00213
00214 KTempFile tf;
00215 tf.setAutoDelete( true );
00216 QString uri = "kmail:" + QString::number( mail.serialNumber() ) + "/" +
00217 mail.messageId();
00218 tf.file()->writeBlock( event->encodedData( "message/rfc822" ) );
00219 tf.close();
00220 interface()->openTodoEditor( i18n("Mail: %1").arg( mail.subject() ), txt,
00221 uri, tf.name(), QStringList(), "message/rfc822" );
00222 }
00223 return;
00224 }
00225
00226 KMessageBox::sorry( core(), i18n("Cannot handle drop events of type '%1'.")
00227 .arg( event->format() ) );
00228 }
00229
00230 #include "todoplugin.moc"