00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <qcursor.h>
00026 #include <qfile.h>
00027 #include <qwidget.h>
00028 #include <qdragobject.h>
00029
00030 #include <kapplication.h>
00031 #include <kabc/vcardconverter.h>
00032 #include <kaction.h>
00033 #include <dcopref.h>
00034 #include <kdebug.h>
00035 #include <kgenericfactory.h>
00036 #include <kiconloader.h>
00037 #include <kmessagebox.h>
00038 #include <kstandarddirs.h>
00039 #include <ktempfile.h>
00040
00041 #include <dcopclient.h>
00042
00043 #include <libkdepim/kvcarddrag.h>
00044 #include <libkdepim/maillistdrag.h>
00045
00046 #include "core.h"
00047 #include "summarywidget.h"
00048 #include "korganizerplugin.h"
00049 #include "korg_uniqueapp.h"
00050
00051 typedef KGenericFactory< KOrganizerPlugin, Kontact::Core > KOrganizerPluginFactory;
00052 K_EXPORT_COMPONENT_FACTORY( libkontact_korganizerplugin,
00053 KOrganizerPluginFactory( "kontact_korganizerplugin" ) )
00054
00055 KOrganizerPlugin::KOrganizerPlugin( Kontact::Core *core, const char *, const QStringList& )
00056 : Kontact::Plugin( core, core, "korganizer" ),
00057 mIface( 0 )
00058 {
00059
00060 setInstance( KOrganizerPluginFactory::instance() );
00061 instance()->iconLoader()->addAppDir("kdepim");
00062
00063 insertNewAction( new KAction( i18n( "New Event..." ), "newappointment",
00064 CTRL+SHIFT+Key_E, this, SLOT( slotNewEvent() ), actionCollection(),
00065 "new_event" ) );
00066
00067 insertSyncAction( new KAction( i18n( "Synchronize Calendar" ), "reload",
00068 0, this, SLOT( slotSyncEvents() ), actionCollection(),
00069 "korganizer_sync" ) );
00070
00071 mUniqueAppWatcher = new Kontact::UniqueAppWatcher(
00072 new Kontact::UniqueAppHandlerFactory<KOrganizerUniqueAppHandler>(), this );
00073 }
00074
00075 KOrganizerPlugin::~KOrganizerPlugin()
00076 {
00077 }
00078
00079 Kontact::Summary *KOrganizerPlugin::createSummaryWidget( QWidget *parent )
00080 {
00081 return new SummaryWidget( this, parent );
00082 }
00083
00084 KParts::ReadOnlyPart *KOrganizerPlugin::createPart()
00085 {
00086 KParts::ReadOnlyPart *part = loadPart();
00087
00088 if ( !part )
00089 return 0;
00090
00091 mIface = new KCalendarIface_stub( dcopClient(), "kontact", "CalendarIface" );
00092
00093 return part;
00094 }
00095
00096 QString KOrganizerPlugin::tipFile() const
00097 {
00098 QString file = ::locate("data", "korganizer/tips");
00099 return file;
00100 }
00101
00102 QStringList KOrganizerPlugin::invisibleToolbarActions() const
00103 {
00104 QStringList invisible;
00105 invisible += "new_event";
00106 invisible += "new_todo";
00107 invisible += "new_journal";
00108
00109 invisible += "view_todo";
00110 invisible += "view_journal";
00111 return invisible;
00112 }
00113
00114 void KOrganizerPlugin::select()
00115 {
00116 interface()->showEventView();
00117 }
00118
00119 KCalendarIface_stub *KOrganizerPlugin::interface()
00120 {
00121 if ( !mIface ) {
00122 part();
00123 }
00124 Q_ASSERT( mIface );
00125 return mIface;
00126 }
00127
00128 void KOrganizerPlugin::slotNewEvent()
00129 {
00130 interface()->openEventEditor( "" );
00131 }
00132
00133 void KOrganizerPlugin::slotSyncEvents()
00134 {
00135 DCOPRef ref( "kmail", "KMailICalIface" );
00136 ref.send( "triggerSync", QString("Calendar") );
00137 }
00138
00139 bool KOrganizerPlugin::createDCOPInterface( const QString& serviceType )
00140 {
00141 kdDebug(5602) << k_funcinfo << serviceType << endl;
00142 if ( serviceType == "DCOP/Organizer" || serviceType == "DCOP/Calendar" ) {
00143 if ( part() )
00144 return true;
00145 }
00146
00147 return false;
00148 }
00149
00150 bool KOrganizerPlugin::isRunningStandalone()
00151 {
00152 return mUniqueAppWatcher->isRunningStandalone();
00153 }
00154
00155 bool KOrganizerPlugin::canDecodeDrag( QMimeSource *mimeSource )
00156 {
00157 return QTextDrag::canDecode( mimeSource ) ||
00158 KPIM::MailListDrag::canDecode( mimeSource );
00159 }
00160
00161 void KOrganizerPlugin::processDropEvent( QDropEvent *event )
00162 {
00163 QString text;
00164
00165 KABC::VCardConverter converter;
00166 if ( KVCardDrag::canDecode( event ) && KVCardDrag::decode( event, text ) ) {
00167 KABC::Addressee::List contacts = converter.parseVCards( text );
00168 KABC::Addressee::List::Iterator it;
00169
00170 QStringList attendees;
00171 for ( it = contacts.begin(); it != contacts.end(); ++it ) {
00172 QString email = (*it).fullEmail();
00173 if ( email.isEmpty() )
00174 attendees.append( (*it).realName() + "<>" );
00175 else
00176 attendees.append( email );
00177 }
00178
00179 interface()->openEventEditor( i18n( "Meeting" ), QString::null, QString::null,
00180 attendees );
00181 return;
00182 }
00183
00184 if ( QTextDrag::decode( event, text ) ) {
00185 kdDebug(5602) << "DROP:" << text << endl;
00186 interface()->openEventEditor( text );
00187 return;
00188 }
00189
00190 KPIM::MailList mails;
00191 if ( KPIM::MailListDrag::decode( event, mails ) ) {
00192 if ( mails.count() != 1 ) {
00193 KMessageBox::sorry( core(),
00194 i18n("Drops of multiple mails are not supported." ) );
00195 } else {
00196 KPIM::MailSummary mail = mails.first();
00197 QString txt = i18n("From: %1\nTo: %2\nSubject: %3").arg( mail.from() )
00198 .arg( mail.to() ).arg( mail.subject() );
00199
00200 KTempFile tf;
00201 tf.setAutoDelete( true );
00202 QString uri = QString::fromLatin1("kmail:") + QString::number( mail.serialNumber() );
00203 tf.file()->writeBlock( event->encodedData( "message/rfc822" ) );
00204 tf.close();
00205 interface()->openEventEditor( i18n("Mail: %1").arg( mail.subject() ), txt,
00206 uri, tf.name(), QStringList(), "message/rfc822" );
00207 }
00208 return;
00209 }
00210
00211 KMessageBox::sorry( core(), i18n("Cannot handle drop events of type '%1'.")
00212 .arg( event->format() ) );
00213 }
00214
00215 void KOrganizerPlugin::loadProfile( const QString& directory )
00216 {
00217 DCOPRef ref( "korganizer", "KOrganizerIface" );
00218 ref.send( "loadProfile", directory );
00219 }
00220
00221 void KOrganizerPlugin::saveToProfile( const QString& directory ) const
00222 {
00223 DCOPRef ref( "korganizer", "KOrganizerIface" );
00224 ref.send( "saveToProfile", directory );
00225 }
00226
00227 #include "korganizerplugin.moc"