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

knotes

  • sources
  • kde-4.14
  • kdepim
  • knotes
  • apps
knotesapp.cpp
Go to the documentation of this file.
1 /*******************************************************************
2  KNotes -- Notes for the KDE project
3 
4  Copyright (c) 1997-2013, The KNotes Developers
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  as published by the Free Software Foundation; either version 2
9  of the License, or (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
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 *******************************************************************/
20 
21 #include "configdialog/knoteconfigdialog.h"
22 
23 #include "dialog/knoteselectednotesdialog.h"
24 #include "utils/knoteutils.h"
25 
26 #include "noteshared/akonadi/notesakonaditreemodel.h"
27 #include "noteshared/akonadi/noteschangerecorder.h"
28 #include "noteshared/attributes/notelockattribute.h"
29 #include "noteshared/attributes/notedisplayattribute.h"
30 #include "noteshared/attributes/notealarmattribute.h"
31 #include "noteshared/attributes/showfoldernotesattribute.h"
32 #include "noteshared/resources/localresourcecreator.h"
33 #include "noteshared/job/createnewnotejob.h"
34 #include "noteshared/attributes/notealarmattribute.h"
35 #include "noteshared/attributes/notedisplayattribute.h"
36 #include "noteshared/attributes/notelockattribute.h"
37 
38 #include "apps/knotesakonaditray.h"
39 #include "dialog/selectednotefolderdialog.h"
40 
41 #include "notesharedglobalconfig.h"
42 #include "notes/knote.h"
43 #include "knotesadaptor.h"
44 #include "knotesapp.h"
45 #include "print/knoteprinter.h"
46 #include "print/knoteprintobject.h"
47 #include "knotesglobalconfig.h"
48 #include "dialog/knoteskeydialog.h"
49 #include "dialog/knotedeleteselectednotesdialog.h"
50 #include "print/knoteprintselectednotesdialog.h"
51 #include "finddialog/knotefinddialog.h"
52 
53 #include <KMime/KMimeMessage>
54 #include <Akonadi/Notes/NoteUtils>
55 #include <Akonadi/ItemCreateJob>
56 #include <Akonadi/ItemDeleteJob>
57 #include <Akonadi/EntityDisplayAttribute>
58 #include <Akonadi/ItemFetchJob>
59 #include <Akonadi/ItemFetchScope>
60 
61 #include <akonadi/control.h>
62 #include <Akonadi/ChangeRecorder>
63 #include <Akonadi/Collection>
64 #include <Akonadi/EntityTreeModel>
65 #include <Akonadi/Session>
66 #include <KMime/KMimeMessage>
67 #include <KActionCollection>
68 
69 #include <KMessageBox>
70 #include <kaction.h>
71 #include <kdebug.h>
72 #include <khelpmenu.h>
73 #include <kicon.h>
74 #include <kiconeffect.h>
75 #include <klocale.h>
76 #include <kmenu.h>
77 #include <kshortcutsdialog.h>
78 #include <ksocketfactory.h>
79 #include <kstandardaction.h>
80 #include <kstandarddirs.h>
81 #include <ksystemtrayicon.h>
82 #include <kwindowsystem.h>
83 #include <kxmlguibuilder.h>
84 #include <kxmlguifactory.h>
85 #include <KFileDialog>
86 
87 #include <kiconloader.h>
88 
89 #include <QPixmap>
90 #include <QClipboard>
91 #include <QDBusConnection>
92 #include <QTcpServer>
93 
94 #include <dnssd/publicservice.h>
95 
96 static bool qActionLessThan( const QAction *a1, const QAction *a2 )
97 {
98  return ( a1->text() < a2->text() );
99 }
100 
101 
102 KNotesApp::KNotesApp()
103  : QWidget(),
104  m_publisher( 0 ),
105  mDebugBaloo(false)
106 {
107  Akonadi::Control::widgetNeedsAkonadi(this);
108  KNoteUtils::migrateToAkonadi();
109 
110  if (!qgetenv("KDEPIM_BALOO_DEBUG").isEmpty()) {
111  mDebugBaloo = true;
112  }
113 
114  if (KNotesGlobalConfig::self()->autoCreateResourceOnStart()) {
115  NoteShared::LocalResourceCreator *creator = new NoteShared::LocalResourceCreator( this );
116  creator->createIfMissing();
117  }
118 
119  new KNotesAdaptor( this );
120  QDBusConnection::sessionBus().registerObject( QLatin1String("/KNotes") , this );
121  kapp->setQuitOnLastWindowClosed( false );
122  // create the GUI...
123  KAction *action = new KAction( KIcon( QLatin1String("document-new") ),
124  i18n( "New Note" ), this );
125  actionCollection()->addAction( QLatin1String("new_note"), action );
126  action->setGlobalShortcut( KShortcut( Qt::ALT + Qt::SHIFT + Qt::Key_N ));
127  connect( action, SIGNAL(triggered()), SLOT(newNote()) );
128 
129  action = new KAction( KIcon( QLatin1String("edit-paste") ),
130  i18n( "New Note From Clipboard" ), this );
131  actionCollection()->addAction( QLatin1String("new_note_clipboard"), action );
132  action->setGlobalShortcut( KShortcut( Qt::ALT + Qt::SHIFT + Qt::Key_C ));
133  connect( action, SIGNAL(triggered()), SLOT(newNoteFromClipboard()) );
134 
135  action = new KAction( KIcon( QLatin1String("document-open") ),
136  i18n( "New Note From Text File..." ), this );
137  actionCollection()->addAction( QLatin1String("new_note_from_text_file"), action );
138  connect( action, SIGNAL(triggered()), SLOT(newNoteFromTextFile()) );
139 
140 
141  action = new KAction( KIcon(QLatin1String( "knotes") ), i18n( "Show All Notes" ), this );
142  actionCollection()->addAction( QLatin1String("show_all_notes"), action );
143  action->setGlobalShortcut( KShortcut( Qt::ALT + Qt::SHIFT + Qt::Key_S ));
144  connect( action, SIGNAL(triggered()), SLOT(showAllNotes()) );
145 
146  action = new KAction( KIcon( QLatin1String("window-close") ),
147  i18n( "Hide All Notes" ), this );
148  actionCollection()->addAction( QLatin1String("hide_all_notes"), action );
149  action->setGlobalShortcut( KShortcut( Qt::ALT + Qt::SHIFT + Qt::Key_H ));
150  connect( action, SIGNAL(triggered()), SLOT(hideAllNotes()) );
151 
152  action = new KAction( KIcon( QLatin1String("document-print") ),
153  i18nc( "@action:inmenu", "Print Selected Notes..." ), this );
154  actionCollection()->addAction( QLatin1String("print_selected_notes"), action );
155  connect( action, SIGNAL(triggered()), SLOT(slotPrintSelectedNotes()) );
156 
157  action = new KAction( KIcon( QLatin1String("edit-delete") ),
158  i18nc( "@action:inmenu", "Delete Selected Notes..." ), this );
159  actionCollection()->addAction( QLatin1String("delete_selected_notes"), action );
160  connect( action, SIGNAL(triggered()), SLOT(slotDeleteSelectedNotes()) );
161 
162  KAction *act = KStandardAction::find( this, SLOT(slotOpenFindDialog()), actionCollection());
163  //REmove shortcut here.
164  act->setShortcut(0);
165 
166 
167 
168  new KHelpMenu( this, KGlobal::mainComponent().aboutData(), false,
169  actionCollection() );
170 
171  KStandardAction::preferences( this, SLOT(slotPreferences()),
172  actionCollection() );
173  KStandardAction::keyBindings( this, SLOT(slotConfigureAccels()),
174  actionCollection() );
175  //FIXME: no shortcut removing!?
176  KStandardAction::quit( this, SLOT(slotQuit()),
177  actionCollection() )->setShortcut( 0 );
178  setXMLFile( componentData().componentName() + QLatin1String("appui.rc") );
179 
180  m_guiBuilder = new KXMLGUIBuilder( this );
181  m_guiFactory = new KXMLGUIFactory( m_guiBuilder, this );
182  m_guiFactory->addClient( this );
183 
184  KMenu *contextMenu = static_cast<KMenu *>( m_guiFactory->container(
185  QLatin1String("knotes_context"),
186  this ) );
187  m_noteMenu = static_cast<KMenu *>( m_guiFactory->container(
188  QLatin1String("notes_menu"), this ) );
189 
190  // get the most recent XML UI file
191  QString xmlFileName = componentData().componentName() + QLatin1String("ui.rc");
192  QString filter = componentData().componentName() + QLatin1Char('/') + xmlFileName;
193  const QStringList fileList =
194  componentData().dirs()->findAllResources( "data", filter ) +
195  componentData().dirs()->findAllResources( "data", xmlFileName );
196 
197  QString doc;
198  KXMLGUIClient::findMostRecentXMLFile( fileList, doc );
199  m_noteGUI.setContent( doc );
200  // set up the alarm reminder - do it after loading the notes because this
201  // is used as a check if updateNoteActions has to be called for a new note
202  updateNetworkListener();
203 
204  Akonadi::Session *session = new Akonadi::Session( "KNotes Session", this );
205  mNoteRecorder = new NoteShared::NotesChangeRecorder(this);
206  mNoteRecorder->changeRecorder()->setSession(session);
207  mTray = new KNotesAkonadiTray(0);
208  connect( mTray, SIGNAL(activateRequested(bool,QPoint)), this, SLOT(slotActivateRequested(bool,QPoint)) );
209  connect( mTray, SIGNAL(secondaryActivateRequested(QPoint)), this, SLOT(slotSecondaryActivateRequested(QPoint)) );
210 
211  mTray->setContextMenu( contextMenu );
212  mNoteTreeModel = new NoteShared::NotesAkonadiTreeModel(mNoteRecorder->changeRecorder(), this);
213 
214  connect( mNoteTreeModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
215  SLOT(slotRowInserted(QModelIndex,int,int)));
216 
217  connect( mNoteRecorder->changeRecorder(), SIGNAL(itemChanged(Akonadi::Item,QSet<QByteArray>)), SLOT(slotItemChanged(Akonadi::Item,QSet<QByteArray>)));
218  connect( mNoteRecorder->changeRecorder(), SIGNAL(itemRemoved(Akonadi::Item)), SLOT(slotItemRemoved(Akonadi::Item)) );
219  connect( mNoteRecorder->changeRecorder(), SIGNAL(collectionChanged(Akonadi::Collection,QSet<QByteArray>)), SLOT(slotCollectionChanged(Akonadi::Collection,QSet<QByteArray>)) );
220  updateNoteActions();
221 }
222 
223 KNotesApp::~KNotesApp()
224 {
225  qDeleteAll( m_noteActions );
226  m_noteActions.clear();
227  saveNotes();
228  delete m_guiBuilder;
229  delete mTray;
230  qDeleteAll(mNotes);
231  mNotes.clear();
232  delete m_publisher;
233  m_publisher=0;
234 }
235 
236 void KNotesApp::slotDeleteSelectedNotes()
237 {
238  QPointer<KNoteDeleteSelectedNotesDialog> dlg = new KNoteDeleteSelectedNotesDialog(this);
239  Akonadi::Item::List lst;
240  QHashIterator<Akonadi::Item::Id, KNote*> i(mNotes);
241  while (i.hasNext()) {
242  i.next();
243  Akonadi::Item item = i.value()->item();
244  if (!item.hasAttribute<NoteShared::NoteLockAttribute>()) {
245  lst.append(item);
246  }
247  }
248  dlg->setNotes(lst);
249  if (dlg->exec()) {
250  Akonadi::Item::List lst = dlg->selectedNotes();
251  if (!lst.isEmpty()) {
252  Akonadi::ItemDeleteJob *deleteJob = new Akonadi::ItemDeleteJob(lst, this);
253  connect( deleteJob, SIGNAL(result(KJob*)), SLOT(slotNoteDeleteFinished(KJob*)) );
254  }
255  }
256  delete dlg;
257 }
258 
259 void KNotesApp::slotItemRemoved(const Akonadi::Item &item)
260 {
261  qDebug()<<" note removed"<<item.id();
262  if (mNotes.contains(item.id())) {
263  delete mNotes.find(item.id()).value();
264  mNotes.remove(item.id());
265  updateNoteActions();
266  updateSystray();
267  }
268 }
269 
270 void KNotesApp::slotItemChanged(const Akonadi::Item &item, const QSet<QByteArray> &set)
271 {
272  if (mNotes.contains(item.id())) {
273  qDebug()<<" item changed "<<item.id()<<" info "<<set.toList();
274  KNote *note = mNotes.value(item.id());
275  note->setChangeItem(item, set);
276  }
277 }
278 
279 void KNotesApp::slotRowInserted(const QModelIndex &parent, int start, int end)
280 {
281  bool needUpdate = false;
282  for ( int i = start; i <= end; ++i) {
283  if ( mNoteTreeModel->hasIndex( i, 0, parent ) ) {
284  const QModelIndex child = mNoteTreeModel->index( i, 0, parent );
285  Akonadi::Item item =
286  mNoteTreeModel->data( child, Akonadi::EntityTreeModel::ItemRole ).value<Akonadi::Item>();
287  Akonadi::Collection parentCollection = mNoteTreeModel->data( child, Akonadi::EntityTreeModel::ParentCollectionRole).value<Akonadi::Collection>();
288  if (parentCollection.hasAttribute<NoteShared::ShowFolderNotesAttribute>()) {
289  createNote(item);
290  needUpdate = true;
291  }
292  }
293  }
294  if (needUpdate) {
295  updateNoteActions();
296  updateSystray();
297  }
298 }
299 
300 void KNotesApp::createNote(const Akonadi::Item &item)
301 {
302  if ( item.hasPayload<KMime::Message::Ptr>() ) {
303  //TODO add AllowDebugBaloo
304  KNote *note = new KNote(m_noteGUI,item, mDebugBaloo);
305  mNotes.insert(item.id(), note);
306  connect( note, SIGNAL(sigShowNextNote()),
307  SLOT(slotWalkThroughNotes()) ) ;
308  connect( note, SIGNAL(sigRequestNewNote()),
309  SLOT(newNote()) );
310  connect( note, SIGNAL(sigNameChanged(QString)),
311  SLOT(updateNoteActions()) );
312  connect( note, SIGNAL(sigColorChanged()),
313  SLOT(updateNoteActions()) );
314  connect( note, SIGNAL(sigKillNote(Akonadi::Item::Id)),
315  SLOT(slotNoteKilled(Akonadi::Item::Id)) );
316  }
317 }
318 
319 void KNotesApp::updateSystray()
320 {
321  if (KNotesGlobalConfig::self()->systemTrayShowNotes()) {
322  mTray->updateNumberOfNotes(mNotes.count());
323  }
324 }
325 
326 void KNotesApp::newNote(const QString &name, const QString &text)
327 {
328  NoteShared::CreateNewNoteJob *job = new NoteShared::CreateNewNoteJob(this, this);
329  job->setRichText(KNotesGlobalConfig::self()->richText());
330  job->setNote(name, text);
331  job->start();
332 }
333 
334 void KNotesApp::showNote(const Akonadi::Entity::Id &id ) const
335 {
336  if (mNotes.contains(id)) {
337  KNote *note = mNotes.value(id);
338  showNote( note );
339  } else {
340  kWarning( 5500 ) << "hideNote: no note with id:" << id;
341  }
342 }
343 
344 void KNotesApp::showNote( KNote *note ) const
345 {
346  note->show();
347 #ifdef Q_WS_X11
348  if ( !note->isDesktopAssigned() ) {
349  note->toDesktop( KWindowSystem::currentDesktop() );
350  } else {
351  KWindowSystem::setCurrentDesktop(
352  KWindowSystem::windowInfo( note->winId(), NET::WMDesktop ).desktop() );
353  }
354  KWindowSystem::forceActiveWindow( note->winId() );
355 #endif
356  note->setFocus();
357 }
358 
359 
360 void KNotesApp::hideNote( const Akonadi::Item::Id &id ) const
361 {
362  if (mNotes.contains(id)) {
363  KNote *note = mNotes.value(id);
364  note->hide();
365  } else {
366  kWarning( 5500 ) << "hideNote: no note with id:" << id;
367  }
368 }
369 
370 
371 void KNotesApp::hideAllNotes() const
372 {
373  QHashIterator<Akonadi::Item::Id, KNote*> i(mNotes);
374  while (i.hasNext()) {
375  i.next();
376  i.value()->slotClose();
377  }
378 }
379 
380 void KNotesApp::showAllNotes() const
381 {
382  QHashIterator<Akonadi::Item::Id, KNote*> i(mNotes);
383  while (i.hasNext()) {
384  i.next();
385  // workaround to BUG 149116
386  i.value()->hide();
387 
388  i.value()->show();
389  }
390 }
391 
392 
393 void KNotesApp::newNoteFromClipboard( const QString &name )
394 {
395  const QString &text = KApplication::clipboard()->text();
396  newNote( name, text );
397 }
398 
399 void KNotesApp::newNoteFromTextFile()
400 {
401  QString text;
402  const QString filename = KFileDialog::getOpenFileName( KUrl(),
403  QLatin1String("*.txt"),
404  this,
405  i18n("Select Text File") );
406  if (!filename.isEmpty()) {
407  QFile f(filename);
408  if (f.open(QIODevice::ReadOnly|QIODevice::Text)) {
409  text = QString::fromUtf8(f.readAll());
410  } else {
411  KMessageBox::error(this, i18n("Error during open text file: %1", f.errorString()), i18n("Open Text File"));
412  return;
413  }
414  newNote( i18n("Note from file '%1'",filename), text);
415  }
416 }
417 
418 void KNotesApp::updateNetworkListener()
419 {
420  delete m_publisher;
421  m_publisher=0;
422 
423  if ( NoteShared::NoteSharedGlobalConfig::receiveNotes() ) {
424  // create the socket and start listening for connections
425  m_publisher=new DNSSD::PublicService(NoteShared::NoteSharedGlobalConfig::senderID(), QLatin1String("_knotes._tcp"), NoteShared::NoteSharedGlobalConfig::port());
426  m_publisher->publishAsync();
427  }
428 }
429 
430 QString KNotesApp::name( const Akonadi::Item::Id &id ) const
431 {
432  if (mNotes.contains(id)) {
433  return mNotes.value(id)->name();
434  }
435  return QString();
436 }
437 
438 QString KNotesApp::text( const Akonadi::Item::Id &id ) const
439 {
440  if (mNotes.contains(id)) {
441  return mNotes.value(id)->text();
442  }
443  return QString();
444 }
445 
446 void KNotesApp::setName( const Akonadi::Item::Id &id, const QString &newName )
447 {
448  if (mNotes.contains(id)) {
449  mNotes.value(id)->setName(newName);
450  } else {
451  kWarning( 5500 ) << "setName: no note with id:" << id;
452  }
453 }
454 
455 void KNotesApp::setText( const Akonadi::Item::Id &id, const QString &newText )
456 {
457  if (mNotes.contains(id)) {
458  mNotes.value(id)->setText( newText );
459  } else {
460  kWarning( 5500 ) << "setText: no note with id:" << id;
461  }
462 }
463 
464 void KNotesApp::updateNoteActions()
465 {
466  unplugActionList( QLatin1String("notes") );
467  m_noteActions.clear();
468 
469  QHashIterator<Akonadi::Item::Id, KNote*> i(mNotes);
470  while (i.hasNext()) {
471  i.next();
472  KNote *note = i.value();
473  QString replaceText;
474  QString realName = note->name();
475  if ( realName.count() > 50 ) {
476  replaceText = realName.left(50) + QLatin1String("...");
477  } else {
478  replaceText = realName;
479  }
480 
481 
482  KAction *action = new KAction( replaceText.replace( QLatin1String("&"), QLatin1String("&&") ), this );
483  action->setToolTip(realName);
484  action->setObjectName(QString::number(note->noteId()));
485  connect( action, SIGNAL(triggered(bool)), SLOT(slotShowNote()) );
486  KIconEffect effect;
487  QPixmap icon =
488  effect.apply( qApp->windowIcon().pixmap( IconSize( KIconLoader::Small ),
489  IconSize( KIconLoader::Small ) ),
490  KIconEffect::Colorize,
491  1,
492  note->palette().color( note->backgroundRole() ),
493  false );
494 
495  action->setIcon( icon );
496  m_noteActions.append( action );
497  }
498 
499  if ( m_noteActions.isEmpty() ) {
500  actionCollection()->action( QLatin1String("hide_all_notes") )->setEnabled( false );
501  actionCollection()->action( QLatin1String("show_all_notes") )->setEnabled( false );
502  actionCollection()->action( QLatin1String("print_selected_notes") )->setEnabled( false );
503  actionCollection()->action( QLatin1String("edit_find") )->setEnabled( false );
504  KAction *action = new KAction( i18n( "No Notes" ), this );
505  action->setEnabled(false);
506  m_noteActions.append( action );
507  } else {
508  qSort( m_noteActions.begin(), m_noteActions.end(), qActionLessThan );
509  actionCollection()->action( QLatin1String("hide_all_notes") )->setEnabled( true );
510  actionCollection()->action( QLatin1String("show_all_notes") )->setEnabled( true );
511  actionCollection()->action( QLatin1String("print_selected_notes") )->setEnabled( true );
512  actionCollection()->action( QLatin1String("edit_find") )->setEnabled( true );
513  }
514  plugActionList( QLatin1String("notes"), m_noteActions );
515 }
516 
517 
518 void KNotesApp::slotActivateRequested( bool, const QPoint&)
519 {
520  if ( mNotes.size() == 1 ) {
521  showNote( mNotes.begin().value() );
522  } else {
523  m_noteMenu->popup( QCursor::pos ());
524  }
525 }
526 
527 void KNotesApp::slotSecondaryActivateRequested( const QPoint & )
528 {
529  newNote();
530 }
531 
532 void KNotesApp::slotShowNote()
533 {
534  // tell the WM to give this note focus
535  showNote( sender()->objectName().toLongLong() );
536 }
537 
538 void KNotesApp::slotWalkThroughNotes()
539 {
540  QHashIterator<Akonadi::Item::Id, KNote*> i(mNotes);
541  while (i.hasNext()) {
542  i.next();
543  KNote *note = i.value();
544  if ( note->hasFocus() ) {
545  if ( i.value() != mNotes.end().value() ) {
546  showNote( i.value() );
547  } else {
548  showNote( mNotes.begin().value() );
549  }
550  break;
551  }
552  }
553 }
554 
555 void KNotesApp::slotPreferences()
556 {
557  // create a new preferences dialog...
558  KNoteConfigDialog *dialog = new KNoteConfigDialog( i18n( "Settings" ), this);
559  connect( dialog, SIGNAL(configCommitted()), this, SLOT(slotConfigUpdated()));
560  dialog->show();
561 }
562 
563 void KNotesApp::slotConfigUpdated()
564 {
565  updateNetworkListener();
566  KNoteUtils::updateConfiguration();
567  //Force update if we disable or enable show number in systray
568  mTray->updateNumberOfNotes(mNotes.count());
569 }
570 
571 void KNotesApp::slotCollectionChanged(const Akonadi::Collection &col, const QSet<QByteArray> &set)
572 {
573  if (set.contains("showfoldernotesattribute")) {
574  //qDebug()<<" collection Changed "<<set<<" col "<<col;
575  if (col.hasAttribute<NoteShared::ShowFolderNotesAttribute>()) {
576  fetchNotesFromCollection(col);
577  } else {
578  QHashIterator<Akonadi::Item::Id, KNote*> i(mNotes);
579  while (i.hasNext()) {
580  i.next();
581  Akonadi::Item item = i.value()->item();
582  if (item.parentCollection() == col) {
583  slotItemRemoved(item);
584  }
585  }
586  }
587  }
588 }
589 
590 void KNotesApp::slotConfigureAccels()
591 {
592  QPointer<KNotesKeyDialog> keys = new KNotesKeyDialog( actionCollection(), this );
593 
594  KActionCollection *actionCollection = 0;
595  if ( !mNotes.isEmpty() ) {
596  actionCollection = mNotes.begin().value()->actionCollection();
597  keys->insert( actionCollection );
598  }
599  if (keys->exec()) {
600  keys->save();
601 
602  // update GUI doc for new notes
603  m_noteGUI.setContent(
604  KXMLGUIFactory::readConfigFile( componentData().componentName() + QLatin1String("ui.rc"),
605  componentData() )
606  );
607 
608 
609  if ( actionCollection ) {
610  QHashIterator<Akonadi::Item::Id, KNote*> i(mNotes);
611  while (i.hasNext()) {
612  i.next();
613  foreach ( QAction *action, actionCollection->actions() ) {
614  QAction *toChange = i.value()->actionCollection()->action( action->objectName() );
615  if ( toChange ) {
616  toChange->setShortcuts( action->shortcuts() );
617  }
618  }
619 
620  }
621  }
622  }
623  delete keys;
624 }
625 
626 void KNotesApp::slotNoteKilled( Akonadi::Item::Id id)
627 {
628  Akonadi::ItemDeleteJob *deleteJob = new Akonadi::ItemDeleteJob(Akonadi::Item(id), this);
629  connect( deleteJob, SIGNAL(result(KJob*)), SLOT(slotNoteDeleteFinished(KJob*)) );
630 }
631 
632 void KNotesApp::slotNoteDeleteFinished(KJob* job)
633 {
634  if (job->error()) {
635  kWarning() << job->errorString();
636  return;
637  }
638 }
639 
640 void KNotesApp::slotPrintSelectedNotes()
641 {
642  QPointer<KNotePrintSelectedNotesDialog> dlg = new KNotePrintSelectedNotesDialog(this);
643  dlg->setNotes(mNotes);
644  if (dlg->exec()) {
645  const QList<KNotePrintObject *> lst = dlg->selectedNotes();
646  if (!lst.isEmpty()) {
647  const QString selectedTheme = dlg->selectedTheme();
648  KNotePrinter printer;
649  printer.printNotes( lst, selectedTheme, dlg->preview() );
650  qDeleteAll(lst);
651  }
652  }
653  delete dlg;
654 }
655 
656 void KNotesApp::saveNotes(bool force, bool sync)
657 {
658  KNotesGlobalConfig::self()->writeConfig();
659  QHashIterator<Akonadi::Item::Id, KNote*> i(mNotes);
660  while (i.hasNext()) {
661  i.next();
662  i.value()->saveNote(force, sync);
663  }
664 }
665 
666 void KNotesApp::slotQuit()
667 {
668  saveNotes(true, true);
669  kapp->quit();
670 }
671 
672 bool KNotesApp::commitData( QSessionManager & )
673 {
674  saveNotes(true, true);
675  return true;
676 }
677 
678 void KNotesApp::slotSelectNote(Akonadi::Item::Id id)
679 {
680  showNote(id);
681 }
682 
683 void KNotesApp::slotOpenFindDialog()
684 {
685  if (!mFindDialog) {
686  mFindDialog = new KNoteFindDialog(this);
687  connect(mFindDialog, SIGNAL(noteSelected(Akonadi::Item::Id)), this, SLOT(slotSelectNote(Akonadi::Item::Id)));
688  }
689  QHash<Akonadi::Item::Id , Akonadi::Item> lst;
690 
691  QHashIterator<Akonadi::Item::Id, KNote*> i(mNotes);
692  while (i.hasNext()) {
693  i.next();
694  lst.insert(i.key(), i.value()->item());
695  }
696  mFindDialog->setExistingNotes(lst);
697  mFindDialog->show();
698 }
699 
700 void KNotesApp::fetchNotesFromCollection(const Akonadi::Collection &col)
701 {
702  Akonadi::ItemFetchJob *job = new Akonadi::ItemFetchJob( col );
703  job->fetchScope().fetchFullPayload(true);
704  job->fetchScope().fetchAttribute<NoteShared::NoteLockAttribute>();
705  job->fetchScope().fetchAttribute<NoteShared::NoteDisplayAttribute>();
706  job->fetchScope().fetchAttribute<NoteShared::NoteAlarmAttribute>();
707  job->fetchScope().setAncestorRetrieval(Akonadi::ItemFetchScope::Parent);
708  connect( job, SIGNAL(result(KJob*)), SLOT(slotItemFetchFinished(KJob*)) );
709 }
710 
711 void KNotesApp::slotItemFetchFinished(KJob *job)
712 {
713  if ( job->error() ) {
714  qDebug() << "Error occurred during item fetch:"<<job->errorString();
715  return;
716  }
717 
718  Akonadi::ItemFetchJob *fetchJob = qobject_cast<Akonadi::ItemFetchJob*>( job );
719 
720  const Akonadi::Item::List items = fetchJob->items();
721  foreach ( const Akonadi::Item &item, items ) {
722  createNote(item);
723  }
724  if (!items.isEmpty()) {
725  updateNoteActions();
726  updateSystray();
727  }
728 }
QObject::child
QObject * child(const char *objName, const char *inheritsClass, bool recursiveSearch) const
QAction::text
text
KNotesApp::~KNotesApp
~KNotesApp()
Definition: knotesapp.cpp:223
QList::clear
void clear()
QModelIndex
KNotesApp::showAllNotes
void showAllNotes() const
Definition: knotesapp.cpp:380
KNoteFindDialog
Definition: knotefinddialog.h:57
QWidget
QWidget::palette
palette
QHash::insert
iterator insert(const Key &key, const T &value)
KNotePrinter::printNotes
void printNotes(const QList< KNotePrintObject * > lst, const QString &themePath, bool preview)
Definition: knoteprinter.cpp:125
QSessionManager
QObject::sender
QObject * sender() const
QHashIterator::hasNext
bool hasNext() const
KNotesApp::setText
void setText(const Akonadi::Item::Id &id, const QString &newText)
Definition: knotesapp.cpp:455
KNoteDeleteSelectedNotesDialog
Definition: knotedeleteselectednotesdialog.h:28
QHash::size
int size() const
KNote
Definition: knote.h:48
knotesapp.h
QPointer
QDBusConnection::registerObject
bool registerObject(const QString &path, QObject *object, QFlags< QDBusConnection::RegisterOption > options)
QAction::shortcuts
QList< QKeySequence > shortcuts() const
KNote::isDesktopAssigned
bool isDesktopAssigned() const
Definition: knote.cpp:276
QDBusConnection::sessionBus
QDBusConnection sessionBus()
QWidget::icon
const QPixmap * icon() const
QWidget::hasFocus
bool hasFocus() const
QPoint
QHash::count
int count(const Key &key) const
KNotesApp::text
QString text(const Akonadi::Item::Id &id) const
Definition: knotesapp.cpp:438
QFile
knoteconfigdialog.h
KNotesApp::hideAllNotes
void hideAllNotes() const
Definition: knotesapp.cpp:371
QObject::name
const char * name() const
QString::number
QString number(int n, int base)
knote.h
QList::append
void append(const T &value)
QAction::setShortcuts
void setShortcuts(const QList< QKeySequence > &shortcuts)
QString::fromUtf8
QString fromUtf8(const char *str, int size)
knoteprintobject.h
QHash< Akonadi::Item::Id, Akonadi::Item >
knoteselectednotesdialog.h
QWidget::setFocus
void setFocus()
knoteskeydialog.h
QWidget::backgroundRole
QPalette::ColorRole backgroundRole() const
QList::isEmpty
bool isEmpty() const
knotefinddialog.h
QObject::objectName
QString objectName() const
QHashIterator
QString::isEmpty
bool isEmpty() const
knoteprinter.h
knotesakonaditray.h
QHash::begin
iterator begin()
knoteprintselectednotesdialog.h
KNote::name
QString name() const
Definition: knote.cpp:241
knoteutils.h
QSet
KNotesApp::newNoteFromClipboard
void newNoteFromClipboard(const QString &name=QString())
Definition: knotesapp.cpp:393
QWidget::winId
WId winId() const
QString
QList
QWidget::hide
void hide()
KNotesApp::showNote
void showNote(const Akonadi::Item::Id &id) const
QHash::remove
int remove(const Key &key)
QStringList
KNoteUtils::migrateToAkonadi
KNOTES_EXPORT void migrateToAkonadi()
Definition: knoteutils.cpp:60
KNote::setChangeItem
void setChangeItem(const Akonadi::Item &item, const QSet< QByteArray > &set=QSet< QByteArray >())
Definition: knote.cpp:139
QPixmap
QHash::clear
void clear()
QList::end
iterator end()
QHash::value
const T value(const Key &key) const
QHash::find
iterator find(const Key &key)
QHashIterator::next
Item next()
QLatin1Char
QSet::contains
bool contains(const T &value) const
KNotesApp::commitData
bool commitData(QSessionManager &)
Definition: knotesapp.cpp:672
KNotesApp::hideNote
void hideNote(const Akonadi::Item::Id &id) const
Definition: knotesapp.cpp:360
QString::replace
QString & replace(int position, int n, QChar after)
knotedeleteselectednotesdialog.h
QCursor::pos
QPoint pos()
QLatin1String
KNote::noteId
Akonadi::Item::Id noteId() const
Definition: knote.cpp:236
QHash::isEmpty
bool isEmpty() const
KNotePrinter
Definition: knoteprinter.h:34
QString::count
int count() const
QAction
KNoteUtils::updateConfiguration
KNOTES_EXPORT void updateConfiguration()
Definition: knoteutils.cpp:31
KNotesApp::newNote
void newNote(const QString &name=QString(), const QString &text=QString())
Definition: knotesapp.cpp:326
QString::left
QString left(int n) const
QSet::toList
QList< T > toList() const
QHash::contains
bool contains(const Key &key) const
QWidget::show
void show()
QHash::end
iterator end()
QHashIterator::value
const T & value() const
KNote::toDesktop
void toDesktop(int desktop)
Definition: knote.cpp:978
KNotesApp::setName
void setName(const Akonadi::Item::Id &id, const QString &newName)
Definition: knotesapp.cpp:446
qActionLessThan
static bool qActionLessThan(const QAction *a1, const QAction *a2)
Definition: knotesapp.cpp:96
KNotesApp::KNotesApp
KNotesApp()
Definition: knotesapp.cpp:102
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
KNotesAkonadiTray::updateNumberOfNotes
void updateNumberOfNotes(int number)
Definition: knotesakonaditray.cpp:54
QList::begin
iterator begin()
KNotePrintSelectedNotesDialog
Definition: knoteprintselectednotesdialog.h:27
KNotesKeyDialog
Definition: knoteskeydialog.h:24
KNoteConfigDialog
Definition: knoteconfigdialog.h:32
QDomDocument::setContent
bool setContent(const QByteArray &data, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn)
KNotesAkonadiTray
Definition: knotesakonaditray.h:23
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:32:28 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

knotes

Skip menu "knotes"
  • Main Page
  • Namespace List
  • Namespace Members
  • 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