kontact

korganizerplugin.cpp

00001 /*
00002     This file is part of Kontact.
00003 
00004     Copyright (c) 2001 Matthias Hoelzer-Kluepfel <mhk@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 <kstandarddirs.h>
00036 
00037 #include <dcopclient.h>
00038 
00039 #include <libkdepim/kvcarddrag.h>
00040 #include <libkdepim/maillistdrag.h>
00041 
00042 #include "core.h"
00043 #include "summarywidget.h"
00044 #include "korganizerplugin.h"
00045 #include "korg_uniqueapp.h"
00046 
00047 typedef KGenericFactory< KOrganizerPlugin, Kontact::Core > KOrganizerPluginFactory;
00048 K_EXPORT_COMPONENT_FACTORY( libkontact_korganizerplugin,
00049                             KOrganizerPluginFactory( "kontact_korganizerplugin" ) )
00050 
00051 KOrganizerPlugin::KOrganizerPlugin( Kontact::Core *core, const char *, const QStringList& )
00052   : Kontact::Plugin( core, core, "korganizer" ),
00053     mIface( 0 )
00054 {
00055 
00056   setInstance( KOrganizerPluginFactory::instance() );
00057   instance()->iconLoader()->addAppDir("kdepim");
00058 
00059   insertNewAction( new KAction( i18n( "New Event..." ), "newappointment",
00060                    CTRL+SHIFT+Key_E, this, SLOT( slotNewEvent() ), actionCollection(),
00061                    "new_event" ) );
00062 
00063   mUniqueAppWatcher = new Kontact::UniqueAppWatcher(
00064       new Kontact::UniqueAppHandlerFactory<KOrganizerUniqueAppHandler>(), this );
00065 }
00066 
00067 KOrganizerPlugin::~KOrganizerPlugin()
00068 {
00069 }
00070 
00071 Kontact::Summary *KOrganizerPlugin::createSummaryWidget( QWidget *parent )
00072 {
00073   return new SummaryWidget( this, parent );
00074 }
00075 
00076 KParts::ReadOnlyPart *KOrganizerPlugin::createPart()
00077 {
00078   KParts::ReadOnlyPart *part = loadPart();
00079 
00080   if ( !part )
00081     return 0;
00082 
00083   mIface = new KCalendarIface_stub( dcopClient(), "kontact", "CalendarIface" );
00084 
00085   return part;
00086 }
00087 
00088 QString KOrganizerPlugin::tipFile() const
00089 {
00090   QString file = ::locate("data", "korganizer/tips");
00091   return file;
00092 }
00093 
00094 QStringList KOrganizerPlugin::invisibleToolbarActions() const
00095 {
00096   QStringList invisible;
00097   invisible += "new_event";
00098   invisible += "new_todo";
00099   invisible += "new_journal";
00100 
00101   invisible += "view_todo";
00102   invisible += "view_journal";
00103   return invisible;
00104 }
00105 
00106 void KOrganizerPlugin::select()
00107 {
00108   interface()->showEventView();
00109 }
00110 
00111 KCalendarIface_stub *KOrganizerPlugin::interface()
00112 {
00113   if ( !mIface ) {
00114     part();
00115   }
00116   Q_ASSERT( mIface );
00117   return mIface;
00118 }
00119 
00120 void KOrganizerPlugin::slotNewEvent()
00121 {
00122   interface()->openEventEditor( "" );
00123 }
00124 
00125 bool KOrganizerPlugin::createDCOPInterface( const QString& serviceType )
00126 {
00127   kdDebug(5602) << k_funcinfo << serviceType << endl;
00128   if ( serviceType == "DCOP/Organizer" || serviceType == "DCOP/Calendar" ) {
00129     if ( part() )
00130       return true;
00131   }
00132 
00133   return false;
00134 }
00135 
00136 bool KOrganizerPlugin::isRunningStandalone()
00137 {
00138   return mUniqueAppWatcher->isRunningStandalone();
00139 }
00140 
00141 bool KOrganizerPlugin::canDecodeDrag( QMimeSource *mimeSource )
00142 {
00143   return QTextDrag::canDecode( mimeSource ) ||
00144          KPIM::MailListDrag::canDecode( mimeSource );
00145 }
00146 
00147 void KOrganizerPlugin::processDropEvent( QDropEvent *event )
00148 {
00149   QString text;
00150 
00151   KABC::VCardConverter converter;
00152   if ( KVCardDrag::canDecode( event ) && KVCardDrag::decode( event, text ) ) {
00153     KABC::Addressee::List contacts = converter.parseVCards( text );
00154     KABC::Addressee::List::Iterator it;
00155 
00156     QStringList attendees;
00157     for ( it = contacts.begin(); it != contacts.end(); ++it ) {
00158       QString email = (*it).fullEmail();
00159       if ( email.isEmpty() )
00160         attendees.append( (*it).realName() + "<>" );
00161       else
00162         attendees.append( email );
00163     }
00164 
00165     interface()->openEventEditor( i18n( "Meeting" ), QString::null, QString::null,
00166                                   attendees );
00167     return;
00168   }
00169 
00170   if ( QTextDrag::decode( event, text ) ) {
00171     kdDebug(5602) << "DROP:" << text << endl;
00172     interface()->openEventEditor( text );
00173     return;
00174   }
00175 
00176   KPIM::MailList mails;
00177   if ( KPIM::MailListDrag::decode( event, mails ) ) {
00178     if ( mails.count() != 1 ) {
00179       KMessageBox::sorry( core(),
00180                           i18n("Drops of multiple mails are not supported." ) );
00181     } else {
00182       KPIM::MailSummary mail = mails.first();
00183       QString txt = i18n("From: %1\nTo: %2\nSubject: %3").arg( mail.from() )
00184                     .arg( mail.to() ).arg( mail.subject() );
00185       QString uri = "kmail:" + QString::number( mail.serialNumber() );
00186       interface()->openEventEditor( i18n("Mail: %1").arg( mail.subject() ), txt,
00187                                     uri );
00188     }
00189     return;
00190   }
00191 
00192   KMessageBox::sorry( core(), i18n("Cannot handle drop events of type '%1'.")
00193                               .arg( event->format() ) );
00194 }
00195 
00196 #include "korganizerplugin.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys