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 <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();
00086 Q_ASSERT( mStub );
00087
if ( mStub ) {
00088
if ( attach.isValid() )
00089 mStub->openComposer(
"",
"",
"",
"",
"",
false, KURL(), attach );
00090
else
00091 mStub->newMessage();
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
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
00161
if ( !handled )
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"