kontact Library API Documentation

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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00019 00020 As a special exception, permission is given to link this program 00021 with any edition of Qt, and distribute the resulting executable, 00022 without including the source code for Qt in the source distribution. 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 * /*parent*/ ) 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(); // ensure that we register to DCOP as "korganizer" 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"
KDE Logo
This file is part of the documentation for kontact Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:58:15 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003