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 <qcursor.h>
00026 #include <qfile.h>
00027 #include <qwidget.h>
00028 #include <qdragobject.h>
00029 
00030 #include <kapplication.h>
00031 #include <kabc/vcardconverter.h>
00032 #include <kaction.h>
00033 #include <dcopref.h>
00034 #include <kdebug.h>
00035 #include <kgenericfactory.h>
00036 #include <kiconloader.h>
00037 #include <kmessagebox.h>
00038 #include <kstandarddirs.h>
00039 #include <ktempfile.h>
00040 
00041 #include <dcopclient.h>
00042 
00043 #include <libkdepim/kvcarddrag.h>
00044 #include <libkdepim/maillistdrag.h>
00045 
00046 #include "core.h"
00047 #include "summarywidget.h"
00048 #include "korganizerplugin.h"
00049 #include "korg_uniqueapp.h"
00050 
00051 typedef KGenericFactory< KOrganizerPlugin, Kontact::Core > KOrganizerPluginFactory;
00052 K_EXPORT_COMPONENT_FACTORY( libkontact_korganizerplugin,
00053                             KOrganizerPluginFactory( "kontact_korganizerplugin" ) )
00054 
00055 KOrganizerPlugin::KOrganizerPlugin( Kontact::Core *core, const char *, const QStringList& )
00056   : Kontact::Plugin( core, core, "korganizer" ),
00057     mIface( 0 )
00058 {
00059 
00060   setInstance( KOrganizerPluginFactory::instance() );
00061   instance()->iconLoader()->addAppDir("kdepim");
00062 
00063   insertNewAction( new KAction( i18n( "New Event..." ), "newappointment",
00064                    CTRL+SHIFT+Key_E, this, SLOT( slotNewEvent() ), actionCollection(),
00065                    "new_event" ) );
00066 
00067   insertSyncAction( new KAction( i18n( "Synchronize Calendar" ), "reload",
00068                    0, this, SLOT( slotSyncEvents() ), actionCollection(),
00069                    "korganizer_sync" ) );
00070 
00071   mUniqueAppWatcher = new Kontact::UniqueAppWatcher(
00072       new Kontact::UniqueAppHandlerFactory<KOrganizerUniqueAppHandler>(), this );
00073 }
00074 
00075 KOrganizerPlugin::~KOrganizerPlugin()
00076 {
00077 }
00078 
00079 Kontact::Summary *KOrganizerPlugin::createSummaryWidget( QWidget *parent )
00080 {
00081   return new SummaryWidget( this, parent );
00082 }
00083 
00084 KParts::ReadOnlyPart *KOrganizerPlugin::createPart()
00085 {
00086   KParts::ReadOnlyPart *part = loadPart();
00087 
00088   if ( !part )
00089     return 0;
00090 
00091   mIface = new KCalendarIface_stub( dcopClient(), "kontact", "CalendarIface" );
00092 
00093   return part;
00094 }
00095 
00096 QString KOrganizerPlugin::tipFile() const
00097 {
00098   QString file = ::locate("data", "korganizer/tips");
00099   return file;
00100 }
00101 
00102 QStringList KOrganizerPlugin::invisibleToolbarActions() const
00103 {
00104   QStringList invisible;
00105   invisible += "new_event";
00106   invisible += "new_todo";
00107   invisible += "new_journal";
00108 
00109   invisible += "view_todo";
00110   invisible += "view_journal";
00111   return invisible;
00112 }
00113 
00114 void KOrganizerPlugin::select()
00115 {
00116   interface()->showEventView();
00117 }
00118 
00119 KCalendarIface_stub *KOrganizerPlugin::interface()
00120 {
00121   if ( !mIface ) {
00122     part();
00123   }
00124   Q_ASSERT( mIface );
00125   return mIface;
00126 }
00127 
00128 void KOrganizerPlugin::slotNewEvent()
00129 {
00130   interface()->openEventEditor( "" );
00131 }
00132 
00133 void KOrganizerPlugin::slotSyncEvents()
00134 {
00135   DCOPRef ref( "kmail", "KMailICalIface" );
00136   ref.send( "triggerSync", QString("Calendar") );
00137 }
00138 
00139 bool KOrganizerPlugin::createDCOPInterface( const QString& serviceType )
00140 {
00141   kdDebug(5602) << k_funcinfo << serviceType << endl;
00142   if ( serviceType == "DCOP/Organizer" || serviceType == "DCOP/Calendar" ) {
00143     if ( part() )
00144       return true;
00145   }
00146 
00147   return false;
00148 }
00149 
00150 bool KOrganizerPlugin::isRunningStandalone()
00151 {
00152   return mUniqueAppWatcher->isRunningStandalone();
00153 }
00154 
00155 bool KOrganizerPlugin::canDecodeDrag( QMimeSource *mimeSource )
00156 {
00157   return QTextDrag::canDecode( mimeSource ) ||
00158          KPIM::MailListDrag::canDecode( mimeSource );
00159 }
00160 
00161 void KOrganizerPlugin::processDropEvent( QDropEvent *event )
00162 {
00163   QString text;
00164 
00165   KABC::VCardConverter converter;
00166   if ( KVCardDrag::canDecode( event ) && KVCardDrag::decode( event, text ) ) {
00167     KABC::Addressee::List contacts = converter.parseVCards( text );
00168     KABC::Addressee::List::Iterator it;
00169 
00170     QStringList attendees;
00171     for ( it = contacts.begin(); it != contacts.end(); ++it ) {
00172       QString email = (*it).fullEmail();
00173       if ( email.isEmpty() )
00174         attendees.append( (*it).realName() + "<>" );
00175       else
00176         attendees.append( email );
00177     }
00178 
00179     interface()->openEventEditor( i18n( "Meeting" ), QString::null, QString::null,
00180                                   attendees );
00181     return;
00182   }
00183 
00184   if ( QTextDrag::decode( event, text ) ) {
00185     kdDebug(5602) << "DROP:" << text << endl;
00186     interface()->openEventEditor( text );
00187     return;
00188   }
00189 
00190   KPIM::MailList mails;
00191   if ( KPIM::MailListDrag::decode( event, mails ) ) {
00192     if ( mails.count() != 1 ) {
00193       KMessageBox::sorry( core(),
00194                           i18n("Drops of multiple mails are not supported." ) );
00195     } else {
00196       KPIM::MailSummary mail = mails.first();
00197       QString txt = i18n("From: %1\nTo: %2\nSubject: %3").arg( mail.from() )
00198                     .arg( mail.to() ).arg( mail.subject() );
00199 
00200       KTempFile tf;
00201       tf.setAutoDelete( true );
00202       QString uri = QString::fromLatin1("kmail:") + QString::number( mail.serialNumber() );
00203       tf.file()->writeBlock( event->encodedData( "message/rfc822" ) );
00204       tf.close();
00205       interface()->openEventEditor( i18n("Mail: %1").arg( mail.subject() ), txt,
00206                                     uri, tf.name(), QStringList(), "message/rfc822" );
00207     }
00208     return;
00209   }
00210 
00211   KMessageBox::sorry( core(), i18n("Cannot handle drop events of type '%1'.")
00212                               .arg( event->format() ) );
00213 }
00214 
00215 void KOrganizerPlugin::loadProfile( const QString& directory )
00216 {
00217   DCOPRef ref( "korganizer", "KOrganizerIface" );
00218   ref.send( "loadProfile", directory );
00219 }
00220 
00221 void KOrganizerPlugin::saveToProfile( const QString& directory ) const
00222 {
00223   DCOPRef ref( "korganizer", "KOrganizerIface" );
00224   ref.send( "saveToProfile", directory );
00225 }
00226 
00227 #include "korganizerplugin.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys