• 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
  • knotes
knotes_plugin.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Kontact
3  Copyright (c) 2002 Daniel Molkentin <molkentin@kde.org>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #include "knotes_plugin.h"
22 #include "knotes_part.h"
23 #include "knotes/apps/knotes_options.h"
24 #include "knotes/utils/knoteutils.h"
25 #include "summarywidget.h"
26 #include "knotes/knotesglobalconfig.h"
27 #include <KCalUtils/ICalDrag>
28 #include <KCalUtils/VCalDrag>
29 #include <KCalCore/FileStorage>
30 
31 
32 #include "kdepim-version.h"
33 
34 #include <libkdepim/misc/maillistdrag.h>
35 using namespace KPIM;
36 using namespace KCalUtils;
37 using namespace KCalCore;
38 
39 #include <KABC/VCardDrag>
40 
41 #include <KontactInterface/Core>
42 
43 #include <KAboutData>
44 #include <KCmdLineArgs>
45 #include <KAction>
46 #include <KActionCollection>
47 #include <KDebug>
48 #include <KIcon>
49 #include <KLocalizedString>
50 #include <KMessageBox>
51 #include <KSystemTimeZones>
52 #include <KTemporaryFile>
53 
54 #include <QDBusConnection>
55 #include <QDBusMessage>
56 #include <QDropEvent>
57 
58 EXPORT_KONTACT_PLUGIN( KNotesPlugin, knotes )
59 
60 KNotesPlugin::KNotesPlugin( KontactInterface::Core *core, const QVariantList & )
61  : KontactInterface::Plugin( core, core, "knotes" ),
62  mAboutData( 0 )
63 {
64  KNoteUtils::migrateToAkonadi();
65  setComponentData( KontactPluginFactory::componentData() );
66 
67  KAction *action =
68  new KAction( KIcon( QLatin1String("knotes") ),
69  i18nc( "@action:inmenu", "New Popup Note..." ), this );
70  actionCollection()->addAction( QLatin1String("new_note"), action );
71  connect( action, SIGNAL(triggered(bool)), SLOT(slotNewNote()) );
72  action->setShortcut( QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_N ) );
73  action->setHelpText(
74  i18nc( "@info:status", "Create new popup note" ) );
75  action->setWhatsThis(
76  i18nc( "@info:whatsthis",
77  "You will be presented with a dialog where you can create a new popup note." ) );
78  insertNewAction( action );
79 
80  mUniqueAppWatcher = new KontactInterface::UniqueAppWatcher(
81  new KontactInterface::UniqueAppHandlerFactory<KNotesUniqueAppHandler>(), this );
82 
83 }
84 
85 KNotesPlugin::~KNotesPlugin()
86 {
87 }
88 
89 bool KNotesPlugin::isRunningStandalone() const
90 {
91  return mUniqueAppWatcher->isRunningStandalone();
92 }
93 
94 QString KNotesPlugin::tipFile() const
95 {
96  // TODO: tips file
97  //QString file = KStandardDirs::locate("data", "knotes/tips");
98  QString file;
99  return file;
100 }
101 
102 KParts::ReadOnlyPart *KNotesPlugin::createPart()
103 {
104  return new KNotesPart( this );
105 }
106 
107 KontactInterface::Summary *KNotesPlugin::createSummaryWidget( QWidget *parentWidget )
108 {
109  return new KNotesSummaryWidget( this, parentWidget );
110 }
111 
112 const KAboutData *KNotesPlugin::aboutData() const
113 {
114  if ( !mAboutData ) {
115  mAboutData =
116  new KAboutData( "knotes", 0,
117  ki18nc( "@title", "KNotes" ),
118  KDEPIM_VERSION,
119  ki18nc( "@title", "Popup Notes" ),
120  KAboutData::License_GPL_V2,
121  ki18nc( "@info:credit", "Copyright © 2003–2014 Kontact authors" ) );
122 
123  mAboutData->addAuthor( ki18nc( "@info:credit", "Laurent Montel" ),
124  ki18nc( "@info:credit", "Current Maintainer" ),
125  "montel@kde.org" );
126 
127  mAboutData->addAuthor( ki18nc( "@info:credit", "Michael Brade" ),
128  ki18nc( "@info:credit", "Previous Maintainer" ),
129  "brade@kde.org" );
130  mAboutData->addAuthor( ki18nc( "@info:credit", "Tobias Koenig" ),
131  ki18nc( "@info:credit", "Developer" ),
132  "tokoe@kde.org" );
133  }
134 
135  return mAboutData;
136 }
137 
138 bool KNotesPlugin::canDecodeMimeData( const QMimeData *mimeData ) const
139 {
140  return
141  mimeData->hasText() ||
142  MailList::canDecode( mimeData ) ||
143  KABC::VCardDrag::canDecode( mimeData ) ||
144  ICalDrag::canDecode( mimeData );
145 }
146 
147 void KNotesPlugin::processDropEvent( QDropEvent *event )
148 {
149  const QMimeData *md = event->mimeData();
150 
151  if ( KABC::VCardDrag::canDecode( md ) ) {
152  KABC::Addressee::List contacts;
153 
154  KABC::VCardDrag::fromMimeData( md, contacts );
155 
156  KABC::Addressee::List::ConstIterator it;
157 
158  QStringList attendees;
159  KABC::Addressee::List::ConstIterator end(contacts.constEnd());
160  for ( it = contacts.constBegin(); it != end; ++it ) {
161  const QString email = (*it).fullEmail();
162  if ( email.isEmpty() ) {
163  attendees.append( (*it).realName() + QLatin1String("<>") );
164  } else {
165  attendees.append( email );
166  }
167  }
168  event->accept();
169  static_cast<KNotesPart *>( part() )->newNote(
170  i18nc( "@item", "Meeting" ), attendees.join( QLatin1String(", ") ) );
171  return;
172  }
173 
174  if ( KCalUtils::ICalDrag::canDecode( md ) ) {
175  KCalCore::MemoryCalendar::Ptr cal( new KCalCore::MemoryCalendar( KSystemTimeZones::local() ) );
176  if ( KCalUtils::ICalDrag::fromMimeData( md, cal ) ) {
177  KCalCore::Incidence::List incidences = cal->incidences();
178  Q_ASSERT( incidences.count() );
179  if ( !incidences.isEmpty() ) {
180  event->accept();
181  KCalCore::Incidence::Ptr i = incidences.first();
182  QString summary;
183  if ( i->type() == KCalCore::Incidence::TypeJournal ) {
184  summary = i18nc( "@item", "Note: %1", i->summary() );
185  } else {
186  summary = i->summary();
187  }
188  static_cast<KNotesPart *>( part() )->
189  newNote( i18nc( "@item", "Note: %1", summary ), i->description() );
190  return;
191  }
192  }
193  }
194  if ( md->hasText() ) {
195  static_cast<KNotesPart *>( part() )->newNote(
196  i18nc( "@item", "New Note" ), md->text() );
197  return;
198  }
199 
200  if ( MailList::canDecode( md ) ) {
201  MailList mails = MailList::fromMimeData( md );
202  event->accept();
203  if ( mails.count() != 1 ) {
204  KMessageBox::sorry(
205  core(),
206  i18nc( "@info", "Dropping multiple mails is not supported." ) );
207  } else {
208  MailSummary mail = mails.first();
209  const QString txt = i18nc( "@item", "From: %1\nTo: %2\nSubject: %3",
210  mail.from(), mail.to(), mail.subject() );
211  static_cast<KNotesPart *>( part() )->newNote(
212  i18nc( "@item", "Mail: %1", mail.subject() ), txt );
213  }
214  return;
215  }
216 
217  kWarning() << QString::fromLatin1( "Cannot handle drop events of type '%1'." ).arg( QLatin1String(event->format()) );
218 }
219 
220 void KNotesPlugin::shortcutChanged()
221 {
222  if ( part() ) {
223  static_cast<KNotesPart *>( part() )->updateClickMessage();
224  }
225 }
226 
227 // private slots
228 
229 void KNotesPlugin::slotNewNote()
230 {
231  if ( part() ) {
232  static_cast<KNotesPart *>( part() )->newNote();
233  core()->selectPlugin( this );
234  }
235 }
236 
237 void KNotesUniqueAppHandler::loadCommandLineOptions()
238 {
239  KCmdLineArgs::addCmdLineOptions( knotesOptions() );
240 }
241 
242 int KNotesUniqueAppHandler::newInstance()
243 {
244  kDebug() ;
245  // Ensure part is loaded
246  (void)plugin()->part();
247  return KontactInterface::UniqueAppHandler::newInstance();
248 }
QWidget
KNotesPlugin::aboutData
const KAboutData * aboutData() const
Definition: knotes_plugin.cpp:112
KNotesPlugin::createSummaryWidget
virtual KontactInterface::Summary * createSummaryWidget(QWidget *parentWidget)
Definition: knotes_plugin.cpp:107
QDropEvent::format
virtual const char * format(int n) const
KNotesSummaryWidget
Definition: knotes/summarywidget.h:52
QStringList::join
QString join(const QString &separator) const
QMimeData::hasText
bool hasText() const
KPIM::MailSummary::from
QString from() const
KNotesUniqueAppHandler::newInstance
virtual int newInstance()
Definition: knotes_plugin.cpp:242
QMimeData
KNotesPart
Definition: knotes_part.h:54
QList::count
int count(const T &value) const
fromMimeData
static MailList fromMimeData(const QMimeData *md)
QList::append
void append(const T &value)
KNotesPlugin::~KNotesPlugin
~KNotesPlugin()
Definition: knotes_plugin.cpp:85
knotes_plugin.h
QMimeData::text
QString text() const
KNotesPlugin::isRunningStandalone
bool isRunningStandalone() const
Definition: knotes_plugin.cpp:89
maillistdrag.h
KNotesPlugin::shortcutChanged
void shortcutChanged()
Definition: knotes_plugin.cpp:220
QDropEvent
KNotesPlugin
Definition: knotes_plugin.h:40
KNotesPlugin::processDropEvent
void processDropEvent(QDropEvent *)
Definition: knotes_plugin.cpp:147
QString::isEmpty
bool isEmpty() const
knotes_part.h
KPIM::MailSummary::to
QString to() const
KPIM::MailSummary::subject
QString subject() const
QList::first
T & first()
KNotesPlugin::canDecodeMimeData
bool canDecodeMimeData(const QMimeData *data) const
Definition: knotes_plugin.cpp:138
QString
KPIM::MailList::canDecode
static bool canDecode(const QMimeData *md)
QStringList
KNotesPlugin::tipFile
QString tipFile() const
Definition: knotes_plugin.cpp:94
KNotesPlugin::createPart
KParts::ReadOnlyPart * createPart()
Definition: knotes_plugin.cpp:102
KPIM::MailSummary
QLatin1String
QKeySequence
KPIM::MailList
QString::fromLatin1
QString fromLatin1(const char *str, int size)
KNotesUniqueAppHandler::loadCommandLineOptions
virtual void loadCommandLineOptions()
Definition: knotes_plugin.cpp:237
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
summarywidget.h
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