kontact

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 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 <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   instance()->iconLoader()->addAppDir("kdepim");
00056 
00057   insertNewAction( new KAction( i18n( "New To-do..." ), "newtodo",
00058                    CTRL+SHIFT+Key_T, this, SLOT( slotNewTodo() ), actionCollection(),
00059                    "new_todo" ) );
00060 
00061   mUniqueAppWatcher = new Kontact::UniqueAppWatcher(
00062       new Kontact::UniqueAppHandlerFactory<KOrganizerUniqueAppHandler>(), this );
00063 }
00064 
00065 TodoPlugin::~TodoPlugin()
00066 {
00067 }
00068 
00069 Kontact::Summary *TodoPlugin::createSummaryWidget( QWidget *parent )
00070 {
00071   return new TodoSummaryWidget( this, parent );
00072 }
00073 
00074 KParts::ReadOnlyPart *TodoPlugin::createPart()
00075 {
00076   KParts::ReadOnlyPart *part = loadPart();
00077 
00078   if ( !part )
00079     return 0;
00080 
00081   dcopClient(); // ensure that we register to DCOP as "korganizer"
00082   mIface = new KCalendarIface_stub( dcopClient(), "kontact", "CalendarIface" );
00083 
00084   return part;
00085 }
00086 
00087 void TodoPlugin::select()
00088 {
00089   interface()->showTodoView();
00090 }
00091 
00092 QStringList TodoPlugin::invisibleToolbarActions() const
00093 {
00094   QStringList invisible;
00095   invisible += "new_event";
00096   invisible += "new_todo";
00097   invisible += "new_journal";
00098 
00099   invisible += "view_day";
00100   invisible += "view_list";
00101   invisible += "view_workweek";
00102   invisible += "view_week";
00103   invisible += "view_nextx";
00104   invisible += "view_month";
00105   invisible += "view_journal";
00106   return invisible;
00107 }
00108 
00109 KCalendarIface_stub *TodoPlugin::interface()
00110 {
00111   if ( !mIface ) {
00112     part();
00113   }
00114   Q_ASSERT( mIface );
00115   return mIface;
00116 }
00117 
00118 void TodoPlugin::slotNewTodo()
00119 {
00120   interface()->openTodoEditor( "" );
00121 }
00122 
00123 bool TodoPlugin::createDCOPInterface( const QString& serviceType )
00124 {
00125   kdDebug(5602) << k_funcinfo << serviceType << endl;
00126   if ( serviceType == "DCOP/Organizer" || serviceType == "DCOP/Calendar" ) {
00127     if ( part() )
00128       return true;
00129   }
00130 
00131   return false;
00132 }
00133 
00134 bool TodoPlugin::canDecodeDrag( QMimeSource *mimeSource )
00135 {
00136   return QTextDrag::canDecode( mimeSource ) ||
00137          KPIM::MailListDrag::canDecode( mimeSource );
00138 }
00139 
00140 bool TodoPlugin::isRunningStandalone()
00141 {
00142   return mUniqueAppWatcher->isRunningStandalone();
00143 }
00144 
00145 void TodoPlugin::processDropEvent( QDropEvent *event )
00146 {
00147   QString text;
00148 
00149   KABC::VCardConverter converter;
00150   if ( KVCardDrag::canDecode( event ) && KVCardDrag::decode( event, text ) ) {
00151     KABC::Addressee::List contacts = converter.parseVCards( text );
00152     KABC::Addressee::List::Iterator it;
00153 
00154     QStringList attendees;
00155     for ( it = contacts.begin(); it != contacts.end(); ++it ) {
00156       QString email = (*it).fullEmail();
00157       if ( email.isEmpty() )
00158         attendees.append( (*it).realName() + "<>" );
00159       else
00160         attendees.append( email );
00161     }
00162 
00163     interface()->openTodoEditor( i18n( "Meeting" ), QString::null, QString::null,
00164                                  attendees );
00165     return;
00166   }
00167 
00168   if ( QTextDrag::decode( event, text ) ) {
00169     interface()->openTodoEditor( text );
00170     return;
00171   }
00172 
00173   KPIM::MailList mails;
00174   if ( KPIM::MailListDrag::decode( event, mails ) ) {
00175     if ( mails.count() != 1 ) {
00176       KMessageBox::sorry( core(),
00177                           i18n("Drops of multiple mails are not supported." ) );
00178     } else {
00179       KPIM::MailSummary mail = mails.first();
00180       QString txt = i18n("From: %1\nTo: %2\nSubject: %3").arg( mail.from() )
00181                     .arg( mail.to() ).arg( mail.subject() );
00182       QString uri = "kmail:" + QString::number( mail.serialNumber() ) + "/" +
00183                     mail.messageId();
00184       interface()->openTodoEditor( i18n("Mail: %1").arg( mail.subject() ), txt,
00185                                    uri );
00186     }
00187     return;
00188   }
00189 
00190   KMessageBox::sorry( core(), i18n("Cannot handle drop events of type '%1'.")
00191                               .arg( event->format() ) );
00192 }
00193 
00194 #include "todoplugin.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys