kontact Library API Documentation

korganizerplugin.cpp

00001 /*
00002     This file is part of Kontact.
00003     Copyright (c) 2003 Kontact Developer
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 
00019     As a special exception, permission is given to link this program
00020     with any edition of Qt, and distribute the resulting executable,
00021     without including the source code for Qt in the source distribution.
00022 */
00023 
00024 #include <qwidget.h>
00025 #include <qdragobject.h>
00026 
00027 #include <kapplication.h>
00028 #include <kaction.h>
00029 #include <kdebug.h>
00030 #include <kgenericfactory.h>
00031 #include <kiconloader.h>
00032 #include <kmessagebox.h>
00033 #include <kstandarddirs.h>
00034 
00035 #include <dcopclient.h>
00036 
00037 #include <libkdepim/maillistdrag.h>
00038 
00039 #include "core.h"
00040 #include "summarywidget.h"
00041 #include "korganizerplugin.h"
00042 #include "korg_uniqueapp.h"
00043 
00044 typedef KGenericFactory< KOrganizerPlugin, Kontact::Core > KOrganizerPluginFactory;
00045 K_EXPORT_COMPONENT_FACTORY( libkontact_korganizerplugin,
00046                             KOrganizerPluginFactory( "kontact_korganizerplugin" ) )
00047 
00048 KOrganizerPlugin::KOrganizerPlugin( Kontact::Core *core, const char *, const QStringList& )
00049   : Kontact::Plugin( core, core, "korganizer" ),
00050     mIface( 0 )
00051 {
00052   setInstance( KOrganizerPluginFactory::instance() );
00053 
00054   instance()->iconLoader()->addAppDir( "korganizer" );
00055   QPixmap pm = instance()->iconLoader()->loadIcon( "appointment", KIcon::Toolbar );
00056 
00057   insertNewAction( new KAction( i18n( "New Event" ), pm,
00058                    0, this, SLOT( slotNewEvent() ), actionCollection(),
00059                    "new_event" ) );
00060 
00061   mUniqueAppWatcher = new Kontact::UniqueAppWatcher(
00062       new Kontact::UniqueAppHandlerFactory<KOrganizerUniqueAppHandler>(), this );
00063 }
00064 
00065 KOrganizerPlugin::~KOrganizerPlugin()
00066 {
00067 }
00068 
00069 Kontact::Summary *KOrganizerPlugin::createSummaryWidget( QWidget *parent )
00070 {
00071   return new SummaryWidget( this, parent );
00072 }
00073 
00074 KParts::Part *KOrganizerPlugin::createPart()
00075 {
00076   KParts::Part *part = loadPart();
00077 
00078   if ( !part )
00079     return 0;
00080 
00081   mIface = new KCalendarIface_stub( dcopClient(), "kontact", "CalendarIface" );
00082 
00083   return part;
00084 }
00085 
00086 QString KOrganizerPlugin::tipFile() const
00087 {
00088   QString file = ::locate("data", "korganizer/tips");
00089   return file;
00090 }
00091 
00092 QStringList KOrganizerPlugin::invisibleToolbarActions() const
00093 {
00094   return QStringList( "new_event" );
00095 }
00096 
00097 void KOrganizerPlugin::select()
00098 {
00099   interface()->showEventView();
00100 }
00101 
00102 KCalendarIface_stub *KOrganizerPlugin::interface()
00103 {
00104   if ( !mIface ) {
00105     part();
00106   }
00107   Q_ASSERT( mIface );
00108   return mIface;
00109 }
00110 
00111 void KOrganizerPlugin::slotNewEvent()
00112 {
00113   interface()->openEventEditor( "" );
00114 }
00115 
00116 bool KOrganizerPlugin::createDCOPInterface( const QString& serviceType )
00117 {
00118   kdDebug(5602) << k_funcinfo << serviceType << endl;
00119   if ( serviceType == "DCOP/Organizer" || serviceType == "DCOP/Calendar" ) {
00120     if ( part() )
00121       return true;
00122   }
00123 
00124   return false;
00125 }
00126 
00127 bool KOrganizerPlugin::isRunningStandalone()
00128 {
00129   return mUniqueAppWatcher->isRunningStandalone();
00130 }
00131 
00132 bool KOrganizerPlugin::canDecodeDrag( QMimeSource *mimeSource )
00133 {
00134   return QTextDrag::canDecode( mimeSource ) ||
00135          KPIM::MailListDrag::canDecode( mimeSource );
00136 }
00137 
00138 void KOrganizerPlugin::processDropEvent( QDropEvent *event )
00139 {
00140   QString text;
00141   if ( QTextDrag::decode( event, text ) ) {
00142     kdDebug() << "DROP:" << text << endl;
00143     interface()->openEventEditor( text );
00144     return;
00145   }
00146 
00147   KPIM::MailList mails;
00148   if ( KPIM::MailListDrag::decode( event, mails ) ) {
00149     if ( mails.count() != 1 ) {
00150       KMessageBox::sorry( core(),
00151                           i18n("Drops of multiple mails aren't supported." ) );
00152     } else {
00153       KPIM::MailSummary mail = mails.first();
00154       QString txt = i18n("From: %1\nTo: %2\nSubject: %3").arg( mail.from() )
00155                     .arg( mail.to() ).arg( mail.subject() );
00156       QString uri = "kmail:" + QString::number( mail.serialNumber() ) + "/" +
00157                     mail.messageId();
00158       interface()->openEventEditor( i18n("Mail: %1").arg( mail.subject() ), txt,
00159                                     uri );
00160     }
00161     return;
00162   }
00163 
00164   KMessageBox::sorry( core(), i18n("Can't handle drop events of type '%1'.")
00165                               .arg( event->format() ) );
00166 }
00167 
00168 #include "korganizerplugin.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 Sat May 1 11:39:00 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003