00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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();
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();
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
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
00199 if ( !handled )
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"