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
#include <qdragobject.h>
00026
00027
#include <kapplication.h>
00028
#include <kabc/vcardconverter.h>
00029
#include <kaction.h>
00030
#include <kdebug.h>
00031
#include <kgenericfactory.h>
00032
#include <kiconloader.h>
00033
#include <kmessagebox.h>
00034
#include <kstandarddirs.h>
00035
00036
#include <dcopclient.h>
00037
00038
#include <libkdepim/kvcarddrag.h>
00039
#include <libkdepim/maillistdrag.h>
00040
00041
#include "core.h"
00042
#include "summarywidget.h"
00043
#include "korganizerplugin.h"
00044
#include "korg_uniqueapp.h"
00045
00046
typedef KGenericFactory< KOrganizerPlugin, Kontact::Core > KOrganizerPluginFactory;
00047 K_EXPORT_COMPONENT_FACTORY( libkontact_korganizerplugin,
00048 KOrganizerPluginFactory(
"kontact_korganizerplugin" ) )
00049
00050 KOrganizerPlugin::KOrganizerPlugin( Kontact::
Core *core, const
char *, const
QStringList& )
00051 : Kontact::Plugin( core, core, "korganizer" ),
00052 mIface( 0 )
00053 {
00054 setInstance( KOrganizerPluginFactory::instance() );
00055
00056 instance()->iconLoader()->addAppDir(
"korganizer" );
00057
QPixmap pm = instance()->iconLoader()->loadIcon(
"appointment", KIcon::Toolbar );
00058
00059 insertNewAction(
new KAction( i18n(
"New Event..." ), pm,
00060 0,
this, SLOT( slotNewEvent() ), actionCollection(),
00061
"new_event" ) );
00062
00063 mUniqueAppWatcher =
new Kontact::UniqueAppWatcher(
00064
new Kontact::UniqueAppHandlerFactory<KOrganizerUniqueAppHandler>(),
this );
00065 }
00066
00067 KOrganizerPlugin::~KOrganizerPlugin()
00068 {
00069 }
00070
00071
Kontact::Summary *KOrganizerPlugin::createSummaryWidget(
QWidget *parent )
00072 {
00073
return new SummaryWidget(
this, parent );
00074 }
00075
00076 KParts::Part *KOrganizerPlugin::createPart()
00077 {
00078 KParts::Part *part = loadPart();
00079
00080
if ( !part )
00081
return 0;
00082
00083 mIface =
new KCalendarIface_stub( dcopClient(),
"kontact",
"CalendarIface" );
00084
00085
return part;
00086 }
00087
00088
QString KOrganizerPlugin::tipFile()
const
00089
{
00090
QString file = ::locate(
"data",
"korganizer/tips");
00091
return file;
00092 }
00093
00094
QStringList KOrganizerPlugin::invisibleToolbarActions()
const
00095
{
00096
return QStringList(
"new_event" );
00097 }
00098
00099
void KOrganizerPlugin::select()
00100 {
00101 interface()->showEventView();
00102 }
00103
00104 KCalendarIface_stub *KOrganizerPlugin::interface()
00105 {
00106
if ( !mIface ) {
00107 part();
00108 }
00109 Q_ASSERT( mIface );
00110
return mIface;
00111 }
00112
00113
void KOrganizerPlugin::slotNewEvent()
00114 {
00115 interface()->openEventEditor(
"" );
00116 }
00117
00118
bool KOrganizerPlugin::createDCOPInterface(
const QString& serviceType )
00119 {
00120 kdDebug(5602) << k_funcinfo << serviceType << endl;
00121
if ( serviceType ==
"DCOP/Organizer" || serviceType ==
"DCOP/Calendar" ) {
00122
if ( part() )
00123
return true;
00124 }
00125
00126
return false;
00127 }
00128
00129
bool KOrganizerPlugin::isRunningStandalone()
00130 {
00131
return mUniqueAppWatcher->isRunningStandalone();
00132 }
00133
00134
bool KOrganizerPlugin::canDecodeDrag(
QMimeSource *mimeSource )
00135 {
00136
return QTextDrag::canDecode( mimeSource ) ||
00137 KPIM::MailListDrag::canDecode( mimeSource );
00138 }
00139
00140
void KOrganizerPlugin::processDropEvent(
QDropEvent *event )
00141 {
00142
QString text;
00143
00144 KABC::VCardConverter converter;
00145
if ( KVCardDrag::canDecode( event ) && KVCardDrag::decode( event, text ) ) {
00146 KABC::Addressee::List contacts = converter.parseVCards( text );
00147 KABC::Addressee::List::Iterator it;
00148
00149
QStringList attendees;
00150
for ( it = contacts.begin(); it != contacts.end(); ++it ) {
00151
QString email = (*it).fullEmail();
00152
if ( email.isEmpty() )
00153 attendees.append( (*it).realName() +
"<>" );
00154
else
00155 attendees.append( email );
00156 }
00157
00158 interface()->openEventEditor( i18n(
"Meeting" ), QString::null, QString::null,
00159 attendees );
00160
return;
00161 }
00162
00163
if ( QTextDrag::decode( event, text ) ) {
00164 kdDebug(5602) <<
"DROP:" << text << endl;
00165 interface()->openEventEditor( text );
00166
return;
00167 }
00168
00169 KPIM::MailList mails;
00170
if ( KPIM::MailListDrag::decode( event, mails ) ) {
00171
if ( mails.count() != 1 ) {
00172 KMessageBox::sorry( core(),
00173 i18n(
"Drops of multiple mails are not supported." ) );
00174 }
else {
00175 KPIM::MailSummary mail = mails.first();
00176
QString txt = i18n(
"From: %1\nTo: %2\nSubject: %3").arg( mail.from() )
00177 .arg( mail.to() ).arg( mail.subject() );
00178
QString uri =
"kmail:" + QString::number( mail.serialNumber() ) +
"/" +
00179 mail.messageId();
00180 interface()->openEventEditor( i18n(
"Mail: %1").arg( mail.subject() ), txt,
00181 uri );
00182 }
00183
return;
00184 }
00185
00186 KMessageBox::sorry( core(), i18n(
"Cannot handle drop events of type '%1'.")
00187 .arg( event->format() ) );
00188 }
00189
00190
#include "korganizerplugin.moc"