kontact Library API Documentation

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., 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 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 <libkcal/vcaldrag.h> 00037 #include <libkcal/icaldrag.h> 00038 #include <libkcal/calendarlocal.h> 00039 00040 #include "core.h" 00041 #include "summarywidget.h" 00042 00043 #include "kmail_plugin.h" 00044 00045 using namespace KCal; 00046 00047 typedef KGenericFactory<KMailPlugin, Kontact::Core> KMailPluginFactory; 00048 K_EXPORT_COMPONENT_FACTORY( libkontact_kmailplugin, 00049 KMailPluginFactory( "kontact_kmailplugin" ) ) 00050 00051 KMailPlugin::KMailPlugin(Kontact::Core *core, const char *, const QStringList& ) 00052 : Kontact::Plugin( core, core, "kmail" ), 00053 mStub( 0 ) 00054 { 00055 setInstance( KMailPluginFactory::instance() ); 00056 00057 insertNewAction( new KAction( i18n( "New Mail..." ), "mail_new", 00058 0, this, SLOT( slotNewMail() ), actionCollection(), 00059 "new_mail" ) ); 00060 00061 mUniqueAppWatcher = new Kontact::UniqueAppWatcher( 00062 new Kontact::UniqueAppHandlerFactory<KMailUniqueAppHandler>(), this ); 00063 } 00064 00065 bool KMailPlugin::canDecodeDrag( QMimeSource *qms ) 00066 { 00067 return ( ICalDrag::canDecode( qms ) || VCalDrag::canDecode( qms )); 00068 } 00069 00070 void KMailPlugin::processDropEvent( QDropEvent * de ) 00071 { 00072 CalendarLocal cal; 00073 00074 if ( !VCalDrag::decode( de, &cal ) && 00075 !ICalDrag::decode( de, &cal ) ) 00076 return; 00077 00078 KTempFile tmp( locateLocal( "tmp", "incidences-" ), ".ics" ); 00079 cal.save(tmp.name()); 00080 openComposer( KURL::fromPathOrURL( tmp.name() ) ); 00081 } 00082 00083 void KMailPlugin::openComposer( const KURL& attach ) 00084 { 00085 (void) part(); // ensure part is loaded 00086 Q_ASSERT( mStub ); 00087 if ( mStub ) { 00088 if ( attach.isValid() ) 00089 mStub->openComposer( "", "", "", "", "", false, KURL(), attach ); 00090 else 00091 mStub->openComposer( "", "", "", "", "", false ); 00092 } 00093 } 00094 00095 void KMailPlugin::slotNewMail() 00096 { 00097 openComposer( KURL() ); 00098 } 00099 00100 KMailPlugin::~KMailPlugin() 00101 { 00102 } 00103 00104 bool KMailPlugin::createDCOPInterface( const QString& serviceType ) 00105 { 00106 if ( serviceType == "DCOP/ResourceBackend/IMAP" ) { 00107 if ( part() ) 00108 return true; 00109 } 00110 00111 return false; 00112 } 00113 00114 QString KMailPlugin::tipFile() const 00115 { 00116 QString file = ::locate("data", "kmail/tips"); 00117 return file; 00118 } 00119 00120 KParts::Part* KMailPlugin::createPart() 00121 { 00122 KParts::Part *part = loadPart(); 00123 if ( !part ) return 0; 00124 00125 mStub = new KMailIface_stub( dcopClient(), "kmail", "KMailIface" ); 00126 return part; 00127 } 00128 00129 QStringList KMailPlugin::invisibleToolbarActions() const 00130 { 00131 return QStringList( "new_message" ); 00132 } 00133 00134 bool KMailPlugin::isRunningStandalone() 00135 { 00136 return mUniqueAppWatcher->isRunningStandalone(); 00137 } 00138 00139 Kontact::Summary *KMailPlugin::createSummaryWidget( QWidget *parent ) 00140 { 00141 return new SummaryWidget( this, parent ); 00142 } 00143 00145 00146 #include "../../../kmail/kmail_options.h" 00147 void KMailUniqueAppHandler::loadCommandLineOptions() 00148 { 00149 KCmdLineArgs::addCmdLineOptions( kmail_options ); 00150 } 00151 00152 int KMailUniqueAppHandler::newInstance() 00153 { 00154 // Ensure part is loaded 00155 (void)plugin()->part(); 00156 DCOPRef kmail( "kmail", "KMailIface" ); 00157 DCOPReply reply = kmail.call( "handleCommandLine", false ); 00158 if ( reply.isValid() ) { 00159 bool handled = reply; 00160 //kdDebug(5602) << k_funcinfo << "handled=" << handled << endl; 00161 if ( !handled ) // no args -> simply bring kmail plugin to front 00162 return Kontact::UniqueAppHandler::newInstance(); 00163 } 00164 return 0; 00165 } 00166 00167 bool KMailPlugin::queryClose() const { 00168 KMailIface_stub stub( kapp->dcopClient(), "kmail", "KMailIface" ); 00169 bool canClose=stub.canQueryClose(); 00170 return canClose; 00171 } 00172 00173 #include "kmail_plugin.moc"
KDE Logo
This file is part of the documentation for kontact Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Aug 27 12:53:44 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003