todoplugin.cpp
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
00028 #include <kapplication.h>
00029 #include <kaction.h>
00030 #include <kdebug.h>
00031 #include <kgenericfactory.h>
00032 #include <kiconloader.h>
00033 #include <kmessagebox.h>
00034 #include <dcopclient.h>
00035
00036 #include <libkdepim/maillistdrag.h>
00037
00038 #include "core.h"
00039
00040 #include "todoplugin.h"
00041 #include "korg_uniqueapp.h"
00042
00043 typedef KGenericFactory< TodoPlugin, Kontact::Core > TodoPluginFactory;
00044 K_EXPORT_COMPONENT_FACTORY( libkontact_todoplugin,
00045 TodoPluginFactory( "kontact_todoplugin" ) )
00046
00047 TodoPlugin::TodoPlugin( Kontact::Core *core, const char *, const QStringList& )
00048 : Kontact::Plugin( core, core, "korganizer" ),
00049 mIface( 0 )
00050 {
00051 setInstance( TodoPluginFactory::instance() );
00052
00053 instance()->iconLoader()->addAppDir( "korganizer" );
00054 QPixmap pm = instance()->iconLoader()->loadIcon( "newtodo", KIcon::Toolbar );
00055 insertNewAction( new KAction( i18n( "New Todo" ), pm,
00056 0, this, SLOT( slotNewTodo() ), actionCollection(),
00057 "new_todo" ) );
00058
00059 mUniqueAppWatcher = new Kontact::UniqueAppWatcher(
00060 new Kontact::UniqueAppHandlerFactory<KOrganizerUniqueAppHandler>(), this );
00061 }
00062
00063 TodoPlugin::~TodoPlugin()
00064 {
00065 }
00066
00067 Kontact::Summary *TodoPlugin::createSummaryWidget( QWidget * )
00068 {
00069 return 0;
00070 }
00071
00072 KParts::Part *TodoPlugin::createPart()
00073 {
00074 KParts::Part *part = loadPart();
00075
00076 if ( !part )
00077 return 0;
00078
00079 dcopClient();
00080 mIface = new KCalendarIface_stub( dcopClient(), "kontact", "CalendarIface" );
00081
00082 return part;
00083 }
00084
00085 void TodoPlugin::select()
00086 {
00087 interface()->showTodoView();
00088 }
00089
00090 QStringList TodoPlugin::invisibleToolbarActions() const
00091 {
00092 return QStringList( "new_todo" );
00093 }
00094
00095 KCalendarIface_stub *TodoPlugin::interface()
00096 {
00097 if ( !mIface ) {
00098 part();
00099 }
00100 Q_ASSERT( mIface );
00101 return mIface;
00102 }
00103
00104 void TodoPlugin::slotNewTodo()
00105 {
00106 interface()->openTodoEditor( "" );
00107 }
00108
00109 bool TodoPlugin::createDCOPInterface( const QString& serviceType )
00110 {
00111 kdDebug(5602) << k_funcinfo << serviceType << endl;
00112 if ( serviceType == "DCOP/Organizer" || serviceType == "DCOP/Calendar" ) {
00113 if ( part() )
00114 return true;
00115 }
00116
00117 return false;
00118 }
00119
00120 bool TodoPlugin::canDecodeDrag( QMimeSource *mimeSource )
00121 {
00122 return QTextDrag::canDecode( mimeSource ) ||
00123 KPIM::MailListDrag::canDecode( mimeSource );
00124 }
00125
00126 bool TodoPlugin::isRunningStandalone()
00127 {
00128 return mUniqueAppWatcher->isRunningStandalone();
00129 }
00130
00131 void TodoPlugin::processDropEvent( QDropEvent *event )
00132 {
00133 QString text;
00134 if ( QTextDrag::decode( event, text ) ) {
00135 interface()->openTodoEditor( text );
00136 return;
00137 }
00138
00139 KPIM::MailList mails;
00140 if ( KPIM::MailListDrag::decode( event, mails ) ) {
00141 if ( mails.count() != 1 ) {
00142 KMessageBox::sorry( core(),
00143 i18n("Drops of multiple mails aren't supported." ) );
00144 } else {
00145 KPIM::MailSummary mail = mails.first();
00146 QString txt = i18n("From: %1\nTo: %2\nSubject: %3").arg( mail.from() )
00147 .arg( mail.to() ).arg( mail.subject() );
00148 QString uri = "kmail:" + QString::number( mail.serialNumber() ) + "/" +
00149 mail.messageId();
00150 interface()->openTodoEditor( i18n("Mail: %1").arg( mail.subject() ), txt,
00151 uri );
00152 }
00153 return;
00154 }
00155
00156 KMessageBox::sorry( core(), i18n("Can't handle drop events of type '%1'.")
00157 .arg( event->format() ) );
00158 }
00159
00160 #include "todoplugin.moc"
This file is part of the documentation for kontact Library Version 3.2.2.