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 #include <libkdepim/kpimprefs.h>
00046
00047 #include <libkcal/calendarlocal.h>
00048 #include <libkcal/icaldrag.h>
00049
00050 #include "core.h"
00051 #include "summarywidget.h"
00052 #include "korganizerplugin.h"
00053 #include "korg_uniqueapp.h"
00054
00055 typedef KGenericFactory< KOrganizerPlugin, Kontact::Core > KOrganizerPluginFactory;
00056 K_EXPORT_COMPONENT_FACTORY( libkontact_korganizerplugin,
00057 KOrganizerPluginFactory( "kontact_korganizerplugin" ) )
00058
00059 KOrganizerPlugin::KOrganizerPlugin( Kontact::Core *core, const char *, const QStringList& )
00060 : Kontact::Plugin( core, core, "korganizer" ),
00061 mIface( 0 )
00062 {
00063
00064 setInstance( KOrganizerPluginFactory::instance() );
00065 instance()->iconLoader()->addAppDir("kdepim");
00066
00067 insertNewAction( new KAction( i18n( "New Event..." ), "newappointment",
00068 CTRL+SHIFT+Key_E, this, SLOT( slotNewEvent() ), actionCollection(),
00069 "new_event" ) );
00070
00071 insertSyncAction( new KAction( i18n( "Synchronize Calendar" ), "reload",
00072 0, this, SLOT( slotSyncEvents() ), actionCollection(),
00073 "korganizer_sync" ) );
00074
00075 mUniqueAppWatcher = new Kontact::UniqueAppWatcher(
00076 new Kontact::UniqueAppHandlerFactory<KOrganizerUniqueAppHandler>(), this );
00077 }
00078
00079 KOrganizerPlugin::~KOrganizerPlugin()
00080 {
00081 }
00082
00083 Kontact::Summary *KOrganizerPlugin::createSummaryWidget( QWidget *parent )
00084 {
00085 return new SummaryWidget( this, parent );
00086 }
00087
00088 KParts::ReadOnlyPart *KOrganizerPlugin::createPart()
00089 {
00090 KParts::ReadOnlyPart *part = loadPart();
00091
00092 if ( !part )
00093 return 0;
00094
00095 mIface = new KCalendarIface_stub( dcopClient(), "kontact", "CalendarIface" );
00096
00097 return part;
00098 }
00099
00100 QString KOrganizerPlugin::tipFile() const
00101 {
00102 QString file = ::locate("data", "korganizer/tips");
00103 return file;
00104 }
00105
00106 QStringList KOrganizerPlugin::invisibleToolbarActions() const
00107 {
00108 QStringList invisible;
00109 invisible += "new_event";
00110 invisible += "new_todo";
00111 invisible += "new_journal";
00112
00113 invisible += "view_todo";
00114 invisible += "view_journal";
00115 return invisible;
00116 }
00117
00118 void KOrganizerPlugin::select()
00119 {
00120 interface()->showEventView();
00121 }
00122
00123 KCalendarIface_stub *KOrganizerPlugin::interface()
00124 {
00125 if ( !mIface ) {
00126 part();
00127 }
00128 Q_ASSERT( mIface );
00129 return mIface;
00130 }
00131
00132 void KOrganizerPlugin::slotNewEvent()
00133 {
00134 interface()->openEventEditor( "" );
00135 }
00136
00137 void KOrganizerPlugin::slotSyncEvents()
00138 {
00139 DCOPRef ref( "kmail", "KMailICalIface" );
00140 ref.send( "triggerSync", QString("Calendar") );
00141 }
00142
00143 bool KOrganizerPlugin::createDCOPInterface( const QString& serviceType )
00144 {
00145 kdDebug(5602) << k_funcinfo << serviceType << endl;
00146 if ( serviceType == "DCOP/Organizer" || serviceType == "DCOP/Calendar" ) {
00147 if ( part() )
00148 return true;
00149 }
00150
00151 return false;
00152 }
00153
00154 bool KOrganizerPlugin::isRunningStandalone()
00155 {
00156 return mUniqueAppWatcher->isRunningStandalone();
00157 }
00158
00159 bool KOrganizerPlugin::canDecodeDrag( QMimeSource *mimeSource )
00160 {
00161 return QTextDrag::canDecode( mimeSource ) ||
00162 KPIM::MailListDrag::canDecode( mimeSource );
00163 }
00164
00165 void KOrganizerPlugin::processDropEvent( QDropEvent *event )
00166 {
00167 QString text;
00168
00169 KABC::VCardConverter converter;
00170 if ( KVCardDrag::canDecode( event ) && KVCardDrag::decode( event, text ) ) {
00171 KABC::Addressee::List contacts = converter.parseVCards( text );
00172 KABC::Addressee::List::Iterator it;
00173
00174 QStringList attendees;
00175 for ( it = contacts.begin(); it != contacts.end(); ++it ) {
00176 QString email = (*it).fullEmail();
00177 if ( email.isEmpty() )
00178 attendees.append( (*it).realName() + "<>" );
00179 else
00180 attendees.append( email );
00181 }
00182
00183 interface()->openEventEditor( i18n( "Meeting" ), QString::null, QString::null,
00184 attendees );
00185 return;
00186 }
00187
00188 if ( KCal::ICalDrag::canDecode( event) ) {
00189 KCal::CalendarLocal cal( KPimPrefs::timezone() );
00190 if ( KCal::ICalDrag::decode( event, &cal ) ) {
00191 KCal::Incidence::List incidences = cal.incidences();
00192 if ( !incidences.isEmpty() ) {
00193 event->accept();
00194 KCal::Incidence *i = incidences.first();
00195 QString summary;
00196 if ( dynamic_cast<KCal::Journal*>( i ) )
00197 summary = i18n( "Note: %1" ).arg( i->summary() );
00198 else
00199 summary = i->summary();
00200 interface()->openEventEditor( summary, i->description(), QString() );
00201 return;
00202 }
00203
00204 }
00205 }
00206
00207 if ( QTextDrag::decode( event, text ) ) {
00208 kdDebug(5602) << "DROP:" << text << endl;
00209 interface()->openEventEditor( text );
00210 return;
00211 }
00212
00213 KPIM::MailList mails;
00214 if ( KPIM::MailListDrag::decode( event, mails ) ) {
00215 if ( mails.count() != 1 ) {
00216 KMessageBox::sorry( core(),
00217 i18n("Drops of multiple mails are not supported." ) );
00218 } else {
00219 KPIM::MailSummary mail = mails.first();
00220 QString txt = i18n("From: %1\nTo: %2\nSubject: %3").arg( mail.from() )
00221 .arg( mail.to() ).arg( mail.subject() );
00222
00223 KTempFile tf;
00224 tf.setAutoDelete( true );
00225 QString uri = QString::fromLatin1("kmail:") + QString::number( mail.serialNumber() );
00226 tf.file()->writeBlock( event->encodedData( "message/rfc822" ) );
00227 tf.close();
00228 interface()->openEventEditor( i18n("Mail: %1").arg( mail.subject() ), txt,
00229 uri, tf.name(), QStringList(), "message/rfc822" );
00230 }
00231 return;
00232 }
00233
00234 KMessageBox::sorry( core(), i18n("Cannot handle drop events of type '%1'.")
00235 .arg( event->format() ) );
00236 }
00237
00238 void KOrganizerPlugin::loadProfile( const QString& directory )
00239 {
00240 DCOPRef ref( "korganizer", "KOrganizerIface" );
00241 ref.send( "loadProfile", directory );
00242 }
00243
00244 void KOrganizerPlugin::saveToProfile( const QString& directory ) const
00245 {
00246 DCOPRef ref( "korganizer", "KOrganizerIface" );
00247 ref.send( "saveToProfile", directory );
00248 }
00249
00250 #include "korganizerplugin.moc"