26 #include "calendarinterface.h"
32 #include <KABC/VCardDrag>
34 #include <KCalCore/MemoryCalendar>
36 #include <KCalUtils/ICalDrag>
38 #include <KontactInterface/Core>
41 #include <KActionCollection>
44 #include <KIconLoader>
46 #include <KMessageBox>
47 #include <KSystemTimeZone>
48 #include <KTemporaryFile>
55 : KontactInterface::Plugin( core, core, "korganizer", "todo" ), mIface( 0 )
57 setComponentData( KontactPluginFactory::componentData() );
58 KIconLoader::global()->addAppDir( QLatin1String(
"korganizer") );
59 KIconLoader::global()->addAppDir( QLatin1String(
"kdepim") );
62 new KAction( KIcon( QLatin1String(
"task-new") ),
63 i18nc(
"@action:inmenu",
"New To-do..." ),
this );
64 actionCollection()->addAction( QLatin1String(
"new_todo"), action );
65 action->setShortcut( QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_T ) );
67 i18nc(
"@info:status",
"Create a new to-do" ) );
69 i18nc(
"@info:whatsthis",
70 "You will be presented with a dialog where you can create a new to-do item." ) );
71 connect( action, SIGNAL(triggered(
bool)), SLOT(slotNewTodo()) );
72 insertNewAction( action );
75 new KAction( KIcon( QLatin1String(
"view-refresh") ),
76 i18nc(
"@action:inmenu",
"Sync To-do List" ),
this );
77 syncAction->setHelpText(
78 i18nc(
"@info:status",
"Synchronize groupware to-do list" ) );
79 syncAction->setWhatsThis(
80 i18nc(
"@info:whatsthis",
81 "Choose this option to synchronize your groupware to-do list." ) );
82 connect( syncAction, SIGNAL(triggered(
bool)), SLOT(slotSyncTodos()) );
83 insertSyncAction( syncAction );
85 mUniqueAppWatcher =
new KontactInterface::UniqueAppWatcher(
86 new KontactInterface::UniqueAppHandlerFactory<KOrganizerUniqueAppHandler>(),
this );
100 KParts::ReadOnlyPart *part = loadPart();
106 mIface =
new OrgKdeKorganizerCalendarInterface(
107 QLatin1String(
"org.kde.korganizer"), QLatin1String(
"/Calendar"), QDBusConnection::sessionBus(),
this );
119 QStringList invisible;
120 invisible += QLatin1String(
"new_event");
121 invisible += QLatin1String(
"new_todo");
122 invisible += QLatin1String(
"new_journal");
124 invisible += QLatin1String(
"view_whatsnext");
125 invisible += QLatin1String(
"view_day");
126 invisible += QLatin1String(
"view_nextx");
127 invisible += QLatin1String(
"view_month");
128 invisible += QLatin1String(
"view_workweek");
129 invisible += QLatin1String(
"view_week");
130 invisible += QLatin1String(
"view_list");
131 invisible += QLatin1String(
"view_todo");
132 invisible += QLatin1String(
"view_journal");
133 invisible += QLatin1String(
"view_timeline");
134 invisible += QLatin1String(
"view_timespent");
148 void TodoPlugin::slotNewTodo()
150 interface()->openTodoEditor( QString() );
153 void TodoPlugin::slotSyncTodos()
156 QDBusMessage message =
157 QDBusMessage::createMethodCall(
"org.kde.kmail",
"/Groupware",
158 "org.kde.kmail.groupware",
160 message << QString(
"Todo" );
161 QDBusConnection::sessionBus().send( message );
163 kWarning() <<
"TodoPlugin::slotSyncTodos : need to port to Akonadi";
169 if ( serviceType == QLatin1String(
"DBUS/Organizer") || serviceType == QLatin1String(
"DBUS/Calendar") ) {
180 mimeData->hasText() ||
188 return mUniqueAppWatcher->isRunningStandalone();
196 KABC::Addressee::List contacts;
200 KABC::Addressee::List::ConstIterator it;
202 QStringList attendees;
203 KABC::Addressee::List::ConstIterator end(contacts.constEnd());
204 for ( it = contacts.constBegin(); it != end; ++it ) {
205 const QString email = (*it).fullEmail();
206 if ( email.isEmpty() ) {
207 attendees.append( (*it).realName() + QLatin1String(
"<>") );
209 attendees.append( email );
213 interface()->openTodoEditor( i18nc(
"@item",
"Meeting" ),
214 QString(), QStringList(), attendees );
219 KCalCore::MemoryCalendar::Ptr cal(
new KCalCore::MemoryCalendar( KSystemTimeZones::local() ) );
221 KCalCore::Incidence::List incidences = cal->incidences();
222 Q_ASSERT( incidences.count() );
223 if ( !incidences.isEmpty() ) {
225 KCalCore::Incidence::Ptr i = incidences.first();
227 if ( i->type() == KCalCore::Incidence::TypeJournal ) {
228 summary = i18nc(
"@item",
"Note: %1", i->summary() );
230 summary = i->summary();
232 interface()->openTodoEditor( summary, i->description(), QStringList() );
239 if ( md->hasText() ) {
240 const QString
text = md->text();
248 if ( mails.count() != 1 ) {
251 i18nc(
"@info",
"Dropping multiple mails is not supported." ) );
254 QString txt = i18nc(
"@item",
"From: %1\nTo: %2\nSubject: %3",
256 QString uri = QLatin1String(
"kmail:" ) +
257 QString::number( mail.
serialNumber() ) + QLatin1Char(
'/') +
260 tf.setAutoRemove(
true );
261 tf.write( event->encodedData(
"message/rfc822" ) );
263 i18nc(
"@item",
"Mail: %1", mail.
subject() ),
264 txt, uri, tf.fileName(), QStringList(), QLatin1String(
"message/rfc822") );
270 kWarning() << QString::fromLatin1(
"Cannot handle drop events of type '%1'." ).arg( QLatin1String(event->format()) );
273 #include "todoplugin.moc"
OrgKdeKorganizerCalendarInterface * interface()
virtual QByteArray text(quint32 serialNumber) const =0
virtual KontactInterface::Summary * createSummaryWidget(QWidget *parent)
static MailList fromMimeData(const QMimeData *md)
QString messageId() const
static bool canDecode(const QMimeData *md)
QStringList invisibleToolbarActions() const
bool canDecodeMimeData(const QMimeData *) const
void processDropEvent(QDropEvent *)
quint32 serialNumber() const
bool isRunningStandalone() const
bool createDBUSInterface(const QString &serviceType)
KParts::ReadOnlyPart * createPart()