kontact

kmail_plugin.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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 
00026 #include <kaction.h>
00027 #include <kapplication.h>
00028 #include <kdebug.h>
00029 #include <kgenericfactory.h>
00030 #include <kiconloader.h>
00031 #include <kparts/componentfactory.h>
00032 #include <kstandarddirs.h>
00033 #include <dcopclient.h>
00034 #include <ktempfile.h>
00035 
00036 #include <kabc/addressee.h>
00037 
00038 #include <libkcal/vcaldrag.h>
00039 #include <libkcal/icaldrag.h>
00040 #include <libkcal/calendarlocal.h>
00041 
00042 #include <libkdepim/kvcarddrag.h>
00043 
00044 #include <kmail/kmail_part.h>
00045 #include <kmail/kmkernel.h>
00046 
00047 #include "core.h"
00048 #include "summarywidget.h"
00049 
00050 #include "kmail_plugin.h"
00051 
00052 using namespace KCal;
00053 
00054 typedef KGenericFactory<KMailPlugin, Kontact::Core> KMailPluginFactory;
00055 K_EXPORT_COMPONENT_FACTORY( libkontact_kmailplugin,
00056                             KMailPluginFactory( "kontact_kmailplugin" ) )
00057 
00058 KMailPlugin::KMailPlugin(Kontact::Core *core, const char *, const QStringList& )
00059   : Kontact::Plugin( core, core, "kmail" ),
00060     mStub( 0 )
00061 {
00062   setInstance( KMailPluginFactory::instance() );
00063 
00064   insertNewAction( new KAction( i18n( "New Message..." ), "mail_new",
00065                    CTRL+SHIFT+Key_M, this, SLOT( slotNewMail() ), actionCollection(),
00066                    "new_mail" ) );
00067 
00068   insertSyncAction( new KAction( i18n( "Synchronize Mail" ), "reload",
00069                    0, this, SLOT( slotSyncFolders() ), actionCollection(),
00070                    "sync_mail" ) );
00071 
00072   mUniqueAppWatcher = new Kontact::UniqueAppWatcher(
00073       new Kontact::UniqueAppHandlerFactory<KMailUniqueAppHandler>(), this );
00074 }
00075 
00076 bool KMailPlugin::canDecodeDrag( QMimeSource *qms )
00077 {
00078   return ( ICalDrag::canDecode( qms ) ||
00079            VCalDrag::canDecode( qms ) ||
00080            KVCardDrag::canDecode( qms ) );
00081 }
00082 
00083 void KMailPlugin::processDropEvent( QDropEvent * de )
00084 {
00085   kdDebug() << k_funcinfo << endl;
00086   CalendarLocal cal( QString::fromLatin1("UTC") );
00087   KABC::Addressee::List list;
00088 
00089   if ( VCalDrag::decode( de, &cal ) || ICalDrag::decode( de, &cal ) ) {
00090     KTempFile tmp( locateLocal( "tmp", "incidences-" ), ".ics" );
00091     cal.save( tmp.name() );
00092     openComposer( KURL::fromPathOrURL( tmp.name() ) );
00093   }
00094   else if ( KVCardDrag::decode( de, list ) ) {
00095     KABC::Addressee::List::Iterator it;
00096     QStringList to;
00097     for ( it = list.begin(); it != list.end(); ++it ) {
00098       to.append( ( *it ).fullEmail() );
00099     }
00100     openComposer( to.join(", ") );
00101   }
00102 
00103 }
00104 
00105 void KMailPlugin::openComposer( const KURL& attach )
00106 {
00107   (void) part(); // ensure part is loaded
00108   Q_ASSERT( mStub );
00109   if ( mStub ) {
00110     if ( attach.isValid() )
00111       mStub->newMessage( "", "", "", false, true, KURL(), attach );
00112     else
00113       mStub->newMessage( "", "", "", false, true, KURL(), KURL() );
00114   }
00115 }
00116 
00117 void KMailPlugin::openComposer( const QString& to )
00118 {
00119   (void) part(); // ensure part is loaded
00120   Q_ASSERT( mStub );
00121   if ( mStub ) {
00122     mStub->newMessage( to, "", "", false, true, KURL(), KURL() );
00123   }
00124 }
00125 
00126 void KMailPlugin::slotNewMail()
00127 {
00128   openComposer( QString::null );
00129 }
00130 
00131 void KMailPlugin::slotSyncFolders()
00132 {
00133   DCOPRef ref( "kmail", "KMailIface" );
00134   ref.send( "checkMail" );
00135 }
00136 
00137 KMailPlugin::~KMailPlugin()
00138 {
00139 }
00140 
00141 bool KMailPlugin::createDCOPInterface( const QString& serviceType )
00142 {
00143   if ( serviceType == "DCOP/ResourceBackend/IMAP" ) {
00144     if ( part() )
00145       return true;
00146   }
00147 
00148   return false;
00149 }
00150 
00151 QString KMailPlugin::tipFile() const
00152 {
00153   QString file = ::locate("data", "kmail/tips");
00154   return file;
00155 }
00156 
00157 KParts::ReadOnlyPart* KMailPlugin::createPart()
00158 {
00159   KParts::ReadOnlyPart *part = loadPart();
00160   if ( !part ) return 0;
00161 
00162   mStub = new KMailIface_stub( dcopClient(), "kmail", "KMailIface" );
00163 
00164   return part;
00165 }
00166 
00167 QStringList KMailPlugin::invisibleToolbarActions() const
00168 {
00169   return QStringList( "new_message" );
00170 }
00171 
00172 bool KMailPlugin::isRunningStandalone()
00173 {
00174   return mUniqueAppWatcher->isRunningStandalone();
00175 }
00176 
00177 Kontact::Summary *KMailPlugin::createSummaryWidget( QWidget *parent )
00178 {
00179   return new SummaryWidget( this, parent );
00180 }
00181 
00183 
00184 #include "../../../kmail/kmail_options.h"
00185 void KMailUniqueAppHandler::loadCommandLineOptions()
00186 {
00187     KCmdLineArgs::addCmdLineOptions( kmail_options );
00188 }
00189 
00190 int KMailUniqueAppHandler::newInstance()
00191 {
00192     // Ensure part is loaded
00193     (void)plugin()->part();
00194     DCOPRef kmail( "kmail", "KMailIface" );
00195     DCOPReply reply = kmail.call( "handleCommandLine", false );
00196     if ( reply.isValid() ) {
00197         bool handled = reply;
00198         //kdDebug(5602) << k_funcinfo << "handled=" << handled << endl;
00199         if ( !handled ) // no args -> simply bring kmail plugin to front
00200             return Kontact::UniqueAppHandler::newInstance();
00201     }
00202     return 0;
00203 }
00204 
00205 bool KMailPlugin::queryClose() const {
00206   KMailIface_stub stub( kapp->dcopClient(), "kmail", "KMailIface" );
00207   bool canClose=stub.canQueryClose();
00208   return canClose;
00209 }
00210 
00211 void KMailPlugin::loadProfile( const QString& profileDirectory ) {
00212   DCOPRef ref( "kmail", "KMailIface" );
00213   ref.send( "loadProfile", profileDirectory );
00214 }
00215 
00216 void KMailPlugin::saveToProfile( const QString& profileDirectory ) {
00217   DCOPRef ref( "kmail", "KMailIface" );
00218   ref.send( "saveToProfile", profileDirectory );
00219 }
00220 
00221 #include "kmail_plugin.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys