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