• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kontact

  • sources
  • kde-4.14
  • kdepim
  • kontact
  • plugins
  • korganizer
todoplugin.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Kontact.
3 
4  Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License along
17  with this program; if not, write to the Free Software Foundation, Inc.,
18  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20  As a special exception, permission is given to link this program
21  with any edition of Qt, and distribute the resulting executable,
22  without including the source code for Qt in the source distribution.
23 */
24 
25 #include "todoplugin.h"
26 #include "calendarinterface.h"
27 #include "korg_uniqueapp.h"
28 #include "todosummarywidget.h"
29 
30 #include <libkdepim/misc/maillistdrag.h>
31 
32 #include <KABC/VCardDrag>
33 
34 #include <KCalCore/MemoryCalendar>
35 
36 #include <KCalUtils/ICalDrag>
37 
38 #include <KontactInterface/Core>
39 
40 #include <KAction>
41 #include <KActionCollection>
42 #include <KDebug>
43 #include <KIcon>
44 #include <KIconLoader>
45 #include <KLocalizedString>
46 #include <KMessageBox>
47 #include <KSystemTimeZone>
48 #include <KTemporaryFile>
49 
50 #include <QDropEvent>
51 
52 EXPORT_KONTACT_PLUGIN( TodoPlugin, todo )
53 
54 TodoPlugin::TodoPlugin( KontactInterface::Core *core, const QVariantList & )
55  : KontactInterface::Plugin( core, core, "korganizer", "todo" ), mIface( 0 )
56 {
57  setComponentData( KontactPluginFactory::componentData() );
58  KIconLoader::global()->addAppDir( QLatin1String("korganizer") );
59  KIconLoader::global()->addAppDir( QLatin1String("kdepim") );
60 
61  KAction *action =
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 ) );
66  action->setHelpText(
67  i18nc( "@info:status", "Create a new to-do" ) );
68  action->setWhatsThis(
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 );
73 
74  KAction *syncAction =
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 );
84 
85  mUniqueAppWatcher = new KontactInterface::UniqueAppWatcher(
86  new KontactInterface::UniqueAppHandlerFactory<KOrganizerUniqueAppHandler>(), this );
87 }
88 
89 TodoPlugin::~TodoPlugin()
90 {
91 }
92 
93 KontactInterface::Summary *TodoPlugin::createSummaryWidget( QWidget *parent )
94 {
95  return new TodoSummaryWidget( this, parent );
96 }
97 
98 KParts::ReadOnlyPart *TodoPlugin::createPart()
99 {
100  KParts::ReadOnlyPart *part = loadPart();
101 
102  if ( !part ) {
103  return 0;
104  }
105 
106  mIface = new OrgKdeKorganizerCalendarInterface(
107  QLatin1String("org.kde.korganizer"), QLatin1String("/Calendar"), QDBusConnection::sessionBus(), this );
108 
109  return part;
110 }
111 
112 void TodoPlugin::select()
113 {
114  interface()->showTodoView();
115 }
116 
117 QStringList TodoPlugin::invisibleToolbarActions() const
118 {
119  QStringList invisible;
120  invisible += QLatin1String("new_event");
121  invisible += QLatin1String("new_todo");
122  invisible += QLatin1String("new_journal");
123 
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");
135 
136  return invisible;
137 }
138 
139 OrgKdeKorganizerCalendarInterface *TodoPlugin::interface()
140 {
141  if ( !mIface ) {
142  part();
143  }
144  Q_ASSERT( mIface );
145  return mIface;
146 }
147 
148 void TodoPlugin::slotNewTodo()
149 {
150  interface()->openTodoEditor( QString() );
151 }
152 
153 void TodoPlugin::slotSyncTodos()
154 {
155 #if 0
156  QDBusMessage message =
157  QDBusMessage::createMethodCall( "org.kde.kmail", "/Groupware",
158  "org.kde.kmail.groupware",
159  "triggerSync" );
160  message << QString( "Todo" );
161  QDBusConnection::sessionBus().send( message );
162 #else
163  kWarning() << "TodoPlugin::slotSyncTodos : need to port to Akonadi";
164 #endif
165 }
166 
167 bool TodoPlugin::createDBUSInterface( const QString &serviceType )
168 {
169  if ( serviceType == QLatin1String("DBUS/Organizer") || serviceType == QLatin1String("DBUS/Calendar") ) {
170  if ( part() ) {
171  return true;
172  }
173  }
174  return false;
175 }
176 
177 bool TodoPlugin::canDecodeMimeData( const QMimeData *mimeData ) const
178 {
179  return
180  mimeData->hasText() ||
181  KPIM::MailList::canDecode( mimeData ) ||
182  KABC::VCardDrag::canDecode( mimeData ) ||
183  KCalUtils::ICalDrag::canDecode( mimeData );
184 }
185 
186 bool TodoPlugin::isRunningStandalone() const
187 {
188  return mUniqueAppWatcher->isRunningStandalone();
189 }
190 
191 void TodoPlugin::processDropEvent( QDropEvent *event )
192 {
193  const QMimeData *md = event->mimeData();
194 
195  if ( KABC::VCardDrag::canDecode( md ) ) {
196  KABC::Addressee::List contacts;
197 
198  KABC::VCardDrag::fromMimeData( md, contacts );
199 
200  KABC::Addressee::List::ConstIterator it;
201 
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("<>") );
208  } else {
209  attendees.append( email );
210  }
211  }
212 
213  interface()->openTodoEditor( i18nc( "@item", "Meeting" ),
214  QString(), QStringList(), attendees );
215  return;
216  }
217 
218  if ( KCalUtils::ICalDrag::canDecode( event->mimeData() ) ) {
219  KCalCore::MemoryCalendar::Ptr cal( new KCalCore::MemoryCalendar( KSystemTimeZones::local() ) );
220  if ( KCalUtils::ICalDrag::fromMimeData( event->mimeData(), cal ) ) {
221  KCalCore::Incidence::List incidences = cal->incidences();
222  Q_ASSERT( incidences.count() );
223  if ( !incidences.isEmpty() ) {
224  event->accept();
225  KCalCore::Incidence::Ptr i = incidences.first();
226  QString summary;
227  if ( i->type() == KCalCore::Incidence::TypeJournal ) {
228  summary = i18nc( "@item", "Note: %1", i->summary() );
229  } else {
230  summary = i->summary();
231  }
232  interface()->openTodoEditor( summary, i->description(), QStringList() );
233  return;
234  }
235  // else fall through to text decoding
236  }
237  }
238 
239  if ( md->hasText() ) {
240  const QString text = md->text();
241  interface()->openTodoEditor( text );
242  return;
243  }
244 
245  if ( KPIM::MailList::canDecode( md ) ) {
246  KPIM::MailList mails = KPIM::MailList::fromMimeData( md );
247  event->accept();
248  if ( mails.count() != 1 ) {
249  KMessageBox::sorry(
250  core(),
251  i18nc( "@info", "Dropping multiple mails is not supported." ) );
252  } else {
253  KPIM::MailSummary mail = mails.first();
254  QString txt = i18nc( "@item", "From: %1\nTo: %2\nSubject: %3",
255  mail.from(), mail.to(), mail.subject() );
256  QString uri = QLatin1String( "kmail:" ) +
257  QString::number( mail.serialNumber() ) + QLatin1Char('/') +
258  mail.messageId();
259  KTemporaryFile tf;
260  tf.setAutoRemove( true );
261  tf.write( event->encodedData( "message/rfc822" ) );
262  interface()->openTodoEditor(
263  i18nc( "@item", "Mail: %1", mail.subject() ),
264  txt, uri, tf.fileName(), QStringList(), QLatin1String("message/rfc822") );
265  tf.close();
266  }
267  return;
268  }
269 
270  kWarning() << QString::fromLatin1("Cannot handle drop events of type '%1'." ).arg( QLatin1String(event->format()) );
271 }
272 
todoplugin.h
QWidget
TodoPlugin::interface
OrgKdeKorganizerCalendarInterface * interface()
Definition: todoplugin.cpp:139
QDropEvent::mimeData
const QMimeData * mimeData() const
text
virtual QByteArray text(quint32 serialNumber) const =0
todosummarywidget.h
QDropEvent::format
virtual const char * format(int n) const
QDBusConnection::sessionBus
QDBusConnection sessionBus()
TodoPlugin::createSummaryWidget
virtual KontactInterface::Summary * createSummaryWidget(QWidget *parent)
Definition: todoplugin.cpp:93
QMimeData::hasText
bool hasText() const
KPIM::MailSummary::from
QString from() const
TodoSummaryWidget
Definition: todosummarywidget.h:45
QMimeData
TodoPlugin::~TodoPlugin
~TodoPlugin()
Definition: todoplugin.cpp:89
QString::number
QString number(int n, int base)
QList::count
int count(const T &value) const
fromMimeData
static MailList fromMimeData(const QMimeData *md)
QList::append
void append(const T &value)
KPIM::MailSummary::messageId
QString messageId() const
QMimeData::text
QString text() const
maillistdrag.h
QDropEvent
QString::isEmpty
bool isEmpty() const
QDBusConnection::send
bool send(const QDBusMessage &message) const
KPIM::MailSummary::to
QString to() const
KPIM::MailSummary::subject
QString subject() const
QList::first
T & first()
QString
KPIM::MailList::canDecode
static bool canDecode(const QMimeData *md)
QStringList
QDropEvent::encodedData
virtual QByteArray encodedData(const char *format) const
QLatin1Char
TodoPlugin::invisibleToolbarActions
QStringList invisibleToolbarActions() const
Definition: todoplugin.cpp:117
KPIM::MailSummary
QDBusMessage
QLatin1String
QKeySequence
KPIM::MailList
TodoPlugin
Definition: todoplugin.h:35
korg_uniqueapp.h
QString::fromLatin1
QString fromLatin1(const char *str, int size)
TodoPlugin::canDecodeMimeData
bool canDecodeMimeData(const QMimeData *) const
Definition: todoplugin.cpp:177
TodoPlugin::processDropEvent
void processDropEvent(QDropEvent *)
Definition: todoplugin.cpp:191
KPIM::MailSummary::serialNumber
quint32 serialNumber() const
TodoPlugin::isRunningStandalone
bool isRunningStandalone() const
Definition: todoplugin.cpp:186
TodoPlugin::createDBUSInterface
bool createDBUSInterface(const QString &serviceType)
Definition: todoplugin.cpp:167
TodoPlugin::createPart
KParts::ReadOnlyPart * createPart()
Definition: todoplugin.cpp:98
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QDBusMessage::createMethodCall
QDBusMessage createMethodCall(const QString &service, const QString &path, const QString &interface, const QString &method)
TodoPlugin::select
void select()
Definition: todoplugin.cpp:112
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:34:11 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kontact

Skip menu "kontact"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal