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

kontact

  • sources
  • kde-4.12
  • 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/resource/resourcemanager.h"
24 #include "summarywidget.h"
25 #include "migrations/knoteslegacy.h"
26 #include "knotes/knotesglobalconfig.h"
27 
28 #include "kdepim-version.h"
29 
30 #include <libkdepim/misc/maillistdrag.h>
31 using namespace KPIM;
32 
33 #include <KABC/VCardDrag>
34 #include <KCal/CalendarLocal>
35 #include <KCal/ICalDrag>
36 
37 #include <KontactInterface/Core>
38 
39 #include <KAboutData>
40 #include <KCmdLineArgs>
41 #include <KAction>
42 #include <KActionCollection>
43 #include <KDebug>
44 #include <KIcon>
45 #include <KLocale>
46 #include <KMessageBox>
47 #include <KSystemTimeZones>
48 
49 #include <QDBusConnection>
50 #include <QDBusMessage>
51 #include <QDropEvent>
52 
53 EXPORT_KONTACT_PLUGIN( KNotesPlugin, knotes )
54 
55 KNotesPlugin::KNotesPlugin( KontactInterface::Core *core, const QVariantList & )
56  : KontactInterface::Plugin( core, core, "knotes" ),
57  mAboutData( 0 ),
58  mNotesSummary( 0 )
59 {
60  const bool needConvert = (KNotesGlobalConfig::self()->notesVersion()<1);
61  if ( needConvert ) {
62  // clean up old config files
63  KNotesLegacy::cleanUp();
64  }
65 
66  mCalendar = new CalendarLocal( QString::fromLatin1( "UTC" ) );
67 
68  mManager = new KNotesResourceManager();
69  setComponentData( KontactPluginFactory::componentData() );
70 
71  KAction *action =
72  new KAction( KIcon( QLatin1String("knotes") ),
73  i18nc( "@action:inmenu", "New Popup Note..." ), this );
74  actionCollection()->addAction( QLatin1String("new_note"), action );
75  connect( action, SIGNAL(triggered(bool)), SLOT(slotNewNote()) );
76  action->setShortcut( QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_N ) );
77  action->setHelpText(
78  i18nc( "@info:status", "Create new popup note" ) );
79  action->setWhatsThis(
80  i18nc( "@info:whatsthis",
81  "You will be presented with a dialog where you can create a new popup note." ) );
82  insertNewAction( action );
83 
84  mUniqueAppWatcher = new KontactInterface::UniqueAppWatcher(
85  new KontactInterface::UniqueAppHandlerFactory<KNotesUniqueAppHandler>(), this );
86 
87  QObject::connect( mManager, SIGNAL(sigRegisteredNote(KCal::Journal*)),
88  this, SLOT(addNote(KCal::Journal*)) );
89  QObject::connect( mManager, SIGNAL(sigDeregisteredNote(KCal::Journal*)),
90  this, SLOT(removeNote(KCal::Journal*)) );
91 }
92 
93 KNotesPlugin::~KNotesPlugin()
94 {
95  delete mManager;
96 }
97 
98 bool KNotesPlugin::isRunningStandalone() const
99 {
100  return mUniqueAppWatcher->isRunningStandalone();
101 }
102 
103 QString KNotesPlugin::tipFile() const
104 {
105  // TODO: tips file
106  //QString file = KStandardDirs::locate("data", "knotes/tips");
107  QString file;
108  return file;
109 }
110 
111 KParts::ReadOnlyPart *KNotesPlugin::createPart()
112 {
113  return new KNotesPart( mManager, this );
114 }
115 
116 KontactInterface::Summary *KNotesPlugin::createSummaryWidget( QWidget *parentWidget )
117 {
118  mNotesSummary = new KNotesSummaryWidget( mCalendar, this, parentWidget );
119  return mNotesSummary;
120 }
121 
122 const KAboutData *KNotesPlugin::aboutData() const
123 {
124  if ( !mAboutData ) {
125  mAboutData =
126  new KAboutData( "knotes", 0,
127  ki18nc( "@title", "KNotes" ),
128  KDEPIM_VERSION,
129  ki18nc( "@title", "Popup Notes" ),
130  KAboutData::License_GPL_V2,
131  ki18nc( "@info:credit", "Copyright © 2003–2013 Kontact authors" ) );
132 
133  mAboutData->addAuthor( ki18nc( "@info:credit", "Michael Brade" ),
134  ki18nc( "@info:credit", "Current Maintainer" ),
135  "brade@kde.org" );
136  mAboutData->addAuthor( ki18nc( "@info:credit", "Tobias Koenig" ),
137  ki18nc( "@info:credit", "Developer" ),
138  "tokoe@kde.org" );
139  mAboutData->addAuthor( ki18nc( "@info:credit", "Laurent Montel" ),
140  ki18nc( "@info:credit", "Developer" ),
141  "montel@kde.org" );
142  }
143 
144  return mAboutData;
145 }
146 
147 bool KNotesPlugin::canDecodeMimeData( const QMimeData *mimeData ) const
148 {
149  return
150  mimeData->hasText() ||
151  MailList::canDecode( mimeData ) ||
152  KABC::VCardDrag::canDecode( mimeData ) ||
153  ICalDrag::canDecode( mimeData );
154 }
155 
156 void KNotesPlugin::processDropEvent( QDropEvent *event )
157 {
158  const QMimeData *md = event->mimeData();
159 
160  if ( KABC::VCardDrag::canDecode( md ) ) {
161  KABC::Addressee::List contacts;
162 
163  KABC::VCardDrag::fromMimeData( md, contacts );
164 
165  KABC::Addressee::List::ConstIterator it;
166 
167  QStringList attendees;
168  KABC::Addressee::List::ConstIterator end(contacts.constEnd());
169  for ( it = contacts.constBegin(); it != end; ++it ) {
170  const QString email = (*it).fullEmail();
171  if ( email.isEmpty() ) {
172  attendees.append( (*it).realName() + QLatin1String("<>") );
173  } else {
174  attendees.append( email );
175  }
176  }
177  event->accept();
178  static_cast<KNotesPart *>( part() )->newNote(
179  i18nc( "@item", "Meeting" ), attendees.join( QLatin1String(", ") ) );
180  return;
181  }
182 
183  if ( ICalDrag::canDecode( event->mimeData() ) ) {
184  CalendarLocal cal( KSystemTimeZones::local() );
185  if ( ICalDrag::fromMimeData( event->mimeData(), &cal ) ) {
186  Journal::List journals = cal.journals();
187  if ( !journals.isEmpty() ) {
188  event->accept();
189  Journal *j = journals.first();
190  static_cast<KNotesPart *>( part() )->
191  newNote( i18nc( "@item", "Note: %1", j->summary() ), j->description() );
192  return;
193  }
194  // else fall through to text decoding
195  }
196  }
197 
198  if ( md->hasText() ) {
199  static_cast<KNotesPart *>( part() )->newNote(
200  i18nc( "@item", "New Note" ), md->text() );
201  return;
202  }
203 
204  if ( MailList::canDecode( md ) ) {
205  MailList mails = MailList::fromMimeData( md );
206  event->accept();
207  if ( mails.count() != 1 ) {
208  KMessageBox::sorry(
209  core(),
210  i18nc( "@info", "Dropping multiple mails is not supported." ) );
211  } else {
212  MailSummary mail = mails.first();
213  QString txt = i18nc( "@item", "From: %1\nTo: %2\nSubject: %3",
214  mail.from(), mail.to(), mail.subject() );
215  static_cast<KNotesPart *>( part() )->newNote(
216  i18nc( "@item", "Mail: %1", mail.subject() ), txt );
217  }
218  return;
219  }
220 
221  kWarning() << QString::fromLatin1( "Cannot handle drop events of type '%1'." ).arg( QLatin1String(event->format()) );
222 }
223 
224 // private slots
225 
226 void KNotesPlugin::slotNewNote()
227 {
228  if ( part() ) {
229  static_cast<KNotesPart *>( part() )->newNote();
230  }
231 }
232 
233 void KNotesPlugin::addNote( KCal::Journal *j )
234 {
235  mCalendar->addJournal( j );
236  if (mNotesSummary)
237  mNotesSummary->updateSummary(true);
238 }
239 
240 void KNotesPlugin::removeNote( KCal::Journal *j )
241 {
242  mCalendar->deleteJournal( j );
243  if (mNotesSummary)
244  mNotesSummary->updateSummary(true);
245 }
246 
247 void KNotesUniqueAppHandler::loadCommandLineOptions()
248 {
249  KCmdLineArgs::addCmdLineOptions( KCmdLineOptions() );
250 }
251 
252 int KNotesUniqueAppHandler::newInstance()
253 {
254  kDebug() ;
255  // Ensure part is loaded
256  (void)plugin()->part();
257  return KontactInterface::UniqueAppHandler::newInstance();
258 }
259 
260 
261 
262 
263 #include "knotes_plugin.moc"
KNotesPlugin::aboutData
const KAboutData * aboutData() const
Definition: knotes_plugin.cpp:122
KNotesPlugin::createSummaryWidget
virtual KontactInterface::Summary * createSummaryWidget(QWidget *parentWidget)
Definition: knotes_plugin.cpp:116
QWidget
KNotesSummaryWidget
Definition: knotes/summarywidget.h:40
KPIM::MailSummary::from
QString from() const
KNotesUniqueAppHandler::newInstance
virtual int newInstance()
Definition: knotes_plugin.cpp:252
KNotesPart
Definition: knotes_part.h:48
fromMimeData
static MailList fromMimeData(const QMimeData *md)
KNotesPlugin::~KNotesPlugin
~KNotesPlugin()
Definition: knotes_plugin.cpp:93
knotes_plugin.h
KNotesPlugin::isRunningStandalone
bool isRunningStandalone() const
Definition: knotes_plugin.cpp:98
maillistdrag.h
KNotesPlugin
Definition: knotes_plugin.h:47
KNotesPlugin::processDropEvent
void processDropEvent(QDropEvent *)
Definition: knotes_plugin.cpp:156
knotes_part.h
KPIM::MailSummary::to
QString to() const
KPIM::MailSummary::subject
QString subject() const
KNotesPlugin::canDecodeMimeData
bool canDecodeMimeData(const QMimeData *data) const
Definition: knotes_plugin.cpp:147
QMimeData
KPIM::MailList::canDecode
static bool canDecode(const QMimeData *md)
KNotesPlugin::tipFile
QString tipFile() const
Definition: knotes_plugin.cpp:103
KNotesPlugin::createPart
KParts::ReadOnlyPart * createPart()
Definition: knotes_plugin.cpp:111
KPIM::MailSummary
KPIM::MailList
KNotesUniqueAppHandler::loadCommandLineOptions
virtual void loadCommandLineOptions()
Definition: knotes_plugin.cpp:247
summarywidget.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:30 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

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