• 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
korganizerplugin.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Kontact.
3 
4  Copyright (c) 2001 Matthias Hoelzer-Kluepfel <mhk@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 "korganizerplugin.h"
26 #include "apptsummarywidget.h"
27 #include "calendarinterface.h"
28 #include "korg_uniqueapp.h"
29 
30 #include <libkdepim/misc/maillistdrag.h>
31 
32 #include <KABC/VCardDrag>
33 
34 #include <KCalCore/Incidence>
35 #include <KCalCore/MemoryCalendar>
36 
37 #include <KCalUtils/ICalDrag>
38 
39 #include <KontactInterface/Core>
40 
41 #include <KAction>
42 #include <KActionCollection>
43 #include <KDebug>
44 #include <KIcon>
45 #include <KIconLoader>
46 #include <KLocalizedString>
47 #include <KMessageBox>
48 #include <KStandardDirs>
49 #include <KSystemTimeZone>
50 #include <KTemporaryFile>
51 
52 #include <QDropEvent>
53 
54 EXPORT_KONTACT_PLUGIN( KOrganizerPlugin, korganizer )
55 
56 KOrganizerPlugin::KOrganizerPlugin( KontactInterface::Core *core, const QVariantList & )
57  : KontactInterface::Plugin( core, core, "korganizer", "calendar" ), mIface( 0 )
58 {
59  setComponentData( KontactPluginFactory::componentData() );
60  KIconLoader::global()->addAppDir( QLatin1String("korganizer") );
61  KIconLoader::global()->addAppDir( QLatin1String("kdepim") );
62 
63  KAction *action =
64  new KAction( KIcon( QLatin1String("appointment-new") ),
65  i18nc( "@action:inmenu", "New Event..." ), this );
66  actionCollection()->addAction( QLatin1String("new_event"), action );
67  action->setShortcut( QKeySequence( Qt::CTRL + Qt::SHIFT+Qt::Key_E ) );
68  action->setHelpText(
69  i18nc( "@info:status", "Create a new event" ) );
70  action->setWhatsThis(
71  i18nc( "@info:whatsthis",
72  "You will be presented with a dialog where you can create a new event item." ) );
73  connect( action, SIGNAL(triggered(bool)), SLOT(slotNewEvent()) );
74  insertNewAction( action );
75 
76  KAction *syncAction =
77  new KAction( KIcon( QLatin1String("view-refresh") ),
78  i18nc( "@action:inmenu", "Sync Calendar" ), this );
79  actionCollection()->addAction( QLatin1String("korganizer_sync"), syncAction );
80  syncAction->setHelpText(
81  i18nc( "@info:status", "Synchronize groupware calendar" ) );
82  syncAction->setWhatsThis(
83  i18nc( "@info:whatsthis",
84  "Choose this option to synchronize your groupware events." ) );
85  connect( syncAction, SIGNAL(triggered(bool)), SLOT(slotSyncEvents()) );
86  insertSyncAction( syncAction );
87 
88  mUniqueAppWatcher = new KontactInterface::UniqueAppWatcher(
89  new KontactInterface::UniqueAppHandlerFactory<KOrganizerUniqueAppHandler>(), this );
90 }
91 
92 KOrganizerPlugin::~KOrganizerPlugin()
93 {
94 }
95 
96 KontactInterface::Summary *KOrganizerPlugin::createSummaryWidget( QWidget *parent )
97 {
98  return new ApptSummaryWidget( this, parent );
99 }
100 
101 KParts::ReadOnlyPart *KOrganizerPlugin::createPart()
102 {
103  KParts::ReadOnlyPart *part = loadPart();
104 
105  if ( !part ) {
106  return 0;
107  }
108 
109  mIface = new OrgKdeKorganizerCalendarInterface(
110  QLatin1String("org.kde.korganizer"), QLatin1String("/Calendar"), QDBusConnection::sessionBus(), this );
111 
112  return part;
113 }
114 
115 QString KOrganizerPlugin::tipFile() const
116 {
117  QString file = KStandardDirs::locate( "data", QLatin1String("korganizer/tips") );
118  return file;
119 }
120 
121 QStringList KOrganizerPlugin::invisibleToolbarActions() const
122 {
123  QStringList invisible;
124  invisible += QLatin1String("new_event");
125  invisible += QLatin1String("new_todo");
126  invisible += QLatin1String("new_journal");
127 
128  invisible += QLatin1String("view_todo");
129  invisible += QLatin1String("view_journal");
130  return invisible;
131 }
132 
133 void KOrganizerPlugin::select()
134 {
135  interface()->showEventView();
136 }
137 
138 OrgKdeKorganizerCalendarInterface *KOrganizerPlugin::interface()
139 {
140  if ( !mIface ) {
141  part();
142  }
143  Q_ASSERT( mIface );
144  return mIface;
145 }
146 
147 void KOrganizerPlugin::slotNewEvent()
148 {
149  interface()->openEventEditor( QString() );
150 }
151 
152 void KOrganizerPlugin::slotSyncEvents()
153 {
154 #if 0
155  QDBusMessage message =
156  QDBusMessage::createMethodCall( "org.kde.kmail", "/Groupware",
157  "org.kde.kmail.groupware",
158  "triggerSync" );
159  message << QString( "Calendar" );
160  QDBusConnection::sessionBus().send( message );
161 #else
162  kWarning() << " KOrganizerPlugin::slotSyncEvents : need to port to Akonadi";
163 #endif
164 }
165 
166 bool KOrganizerPlugin::createDBUSInterface( const QString &serviceType )
167 {
168  if ( serviceType == QLatin1String("DBUS/Organizer") || serviceType == QLatin1String("DBUS/Calendar") ) {
169  if ( part() ) {
170  return true;
171  }
172  }
173  return false;
174 }
175 
176 bool KOrganizerPlugin::isRunningStandalone() const
177 {
178  return mUniqueAppWatcher->isRunningStandalone();
179 }
180 
181 bool KOrganizerPlugin::canDecodeMimeData( const QMimeData *mimeData ) const
182 {
183  return mimeData->hasText() ||
184  KPIM::MailList::canDecode( mimeData ) ||
185  KABC::VCardDrag::canDecode( mimeData );
186 }
187 
188 void KOrganizerPlugin::processDropEvent( QDropEvent *event )
189 {
190  const QMimeData *md = event->mimeData();
191  if ( KABC::VCardDrag::canDecode( md ) ) {
192  KABC::Addressee::List contacts;
193 
194  KABC::VCardDrag::fromMimeData( md, contacts );
195 
196  KABC::Addressee::List::ConstIterator it;
197 
198  KABC::Addressee::List::ConstIterator end(contacts.constEnd());
199  QStringList attendees;
200  for ( it = contacts.constBegin(); it != end; ++it ) {
201  QString email = (*it).fullEmail();
202  if ( email.isEmpty() ) {
203  attendees.append( (*it).realName() + QLatin1String("<>") );
204  } else {
205  attendees.append( email );
206  }
207  }
208 
209  interface()->openEventEditor( i18nc( "@item", "Meeting" ),
210  QString(), QStringList(), attendees );
211  return;
212  }
213 
214  if ( KCalUtils::ICalDrag::canDecode( event->mimeData() ) ) {
215  KCalCore::MemoryCalendar::Ptr cal(
216  new KCalCore::MemoryCalendar( KSystemTimeZones::local() ) );
217  if ( KCalUtils::ICalDrag::fromMimeData( event->mimeData(), cal ) ) {
218  KCalCore::Incidence::List incidences = cal->incidences();
219  Q_ASSERT( incidences.count() );
220  if ( !incidences.isEmpty() ) {
221  event->accept();
222  KCalCore::Incidence::Ptr i = incidences.first();
223  QString summary;
224  if ( i->type() == KCalCore::Incidence::TypeJournal ) {
225  summary = i18nc( "@item", "Note: %1", i->summary() );
226  } else {
227  summary = i->summary();
228  }
229  interface()->openEventEditor( summary, i->description(), QStringList() );
230  return;
231  }
232  // else fall through to text decoding
233  }
234  }
235 
236  if ( md->hasText() ) {
237  const QString text = md->text();
238  kDebug() << "DROP:" << text;
239  interface()->openEventEditor( text );
240  return;
241  }
242 
243  if ( KPIM::MailList::canDecode( md ) ) {
244  KPIM::MailList mails = KPIM::MailList::fromMimeData( md );
245  event->accept();
246  if ( mails.count() != 1 ) {
247  KMessageBox::sorry(
248  core(),
249  i18nc( "@info", "Dropping multiple mails is not supported." ) );
250  } else {
251  KPIM::MailSummary mail = mails.first();
252  QString txt = i18nc( "@item", "From: %1\nTo: %2\nSubject: %3",
253  mail.from(), mail.to(), mail.subject() );
254 
255  KTemporaryFile tf;
256  tf.setAutoRemove( true );
257  tf.open();
258  QString uri = QLatin1String( "kmail:" ) + QString::number( mail.serialNumber() );
259  tf.write( event->encodedData( "message/rfc822" ) );
260  interface()->openEventEditor(
261  i18nc( "@item", "Mail: %1", mail.subject() ), txt,
262  uri, tf.fileName(), QStringList(), QLatin1String("message/rfc822") );
263  tf.close();
264  }
265  return;
266  }
267 
268  kWarning() << QString::fromLatin1( "Cannot handle drop events of type '%1'." ).arg( QLatin1String(event->format()) );
269 }
270 
QWidget
QString::append
QString & append(QChar ch)
QDropEvent::mimeData
const QMimeData * mimeData() const
KOrganizerPlugin::createSummaryWidget
virtual KontactInterface::Summary * createSummaryWidget(QWidget *parent)
Definition: korganizerplugin.cpp:96
KOrganizerPlugin::isRunningStandalone
bool isRunningStandalone() const
Definition: korganizerplugin.cpp:176
text
virtual QByteArray text(quint32 serialNumber) const =0
KOrganizerPlugin
Definition: korganizerplugin.h:36
QDropEvent::format
virtual const char * format(int n) const
KOrganizerPlugin::~KOrganizerPlugin
~KOrganizerPlugin()
Definition: korganizerplugin.cpp:92
QDBusConnection::sessionBus
QDBusConnection sessionBus()
QMimeData::hasText
bool hasText() const
KPIM::MailSummary::from
QString from() const
QMimeData
ApptSummaryWidget
Definition: apptsummarywidget.h:44
QString::number
QString number(int n, int base)
QList::count
int count(const T &value) const
fromMimeData
static MailList fromMimeData(const QMimeData *md)
QMimeData::text
QString text() const
maillistdrag.h
QDropEvent
QString::isEmpty
bool isEmpty() const
QDBusConnection::send
bool send(const QDBusMessage &message) const
apptsummarywidget.h
KOrganizerPlugin::tipFile
QString tipFile() const
Definition: korganizerplugin.cpp:115
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
KOrganizerPlugin::invisibleToolbarActions
QStringList invisibleToolbarActions() const
Definition: korganizerplugin.cpp:121
korganizerplugin.h
KOrganizerPlugin::createPart
KParts::ReadOnlyPart * createPart()
Definition: korganizerplugin.cpp:101
KPIM::MailSummary
KOrganizerPlugin::select
void select()
Definition: korganizerplugin.cpp:133
QDBusMessage
QLatin1String
QKeySequence
KOrganizerPlugin::createDBUSInterface
bool createDBUSInterface(const QString &serviceType)
Definition: korganizerplugin.cpp:166
KPIM::MailList
korg_uniqueapp.h
QString::fromLatin1
QString fromLatin1(const char *str, int size)
KOrganizerPlugin::interface
OrgKdeKorganizerCalendarInterface * interface()
Definition: korganizerplugin.cpp:138
KPIM::MailSummary::serialNumber
quint32 serialNumber() const
KOrganizerPlugin::canDecodeMimeData
bool canDecodeMimeData(const QMimeData *) const
Definition: korganizerplugin.cpp:181
KOrganizerPlugin::processDropEvent
void processDropEvent(QDropEvent *)
Definition: korganizerplugin.cpp:188
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)
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