• 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_part.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the KDE project
3 
4  Copyright (C) 2002-2003 Daniel Molkentin <molkentin@kde.org>
5  Copyright (C) 2004-2006 Michael Brade <brade@kde.org>
6  Copyright (C) 2013 Laurent Montel <montel@kde.org>
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public
10  License as published by the Free Software Foundation; either
11  version 2 of the License, or (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; see the file COPYING. If not, write to
20  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  Boston, MA 02110-1301, USA.
22 */
23 
24 #include "knotes_part.h"
25 #include "knoteseditdialog.h"
26 #include "knotesadaptor.h"
27 #include "knotesiconview.h"
28 #include "knoteswidget.h"
29 #include "knotesselectdeletenotesdialog.h"
30 #include "knotetip.h"
31 #include "knotes/configdialog/knoteconfigdialog.h"
32 #include "knotes/network/knotesnetrecv.h"
33 #include "knotes/print/knoteprinter.h"
34 #include "knotes/print/knoteprintobject.h"
35 #include "knotes/print/knoteprintselectthemedialog.h"
36 #include "knotes/resource/resourcemanager.h"
37 #include "knotes/knoteedit.h"
38 #include "knotes/knotesglobalconfig.h"
39 #include "knotes/configdialog/knotesimpleconfigdialog.h"
40 #include "utils/knoteutils.h"
41 #include "alarms/knotealarmdialog.h"
42 #include "alarms/knotesalarm.h"
43 #include <KCal/Journal>
44 using namespace KCal;
45 
46 #include <KActionCollection>
47 #include <KAction>
48 #include <KInputDialog>
49 #include <KMessageBox>
50 #include <KXMLGUIFactory>
51 #include <KPrintPreview>
52 #include <ksocketfactory.h>
53 #include <KApplication>
54 #include <KFileDialog>
55 #include <KToggleAction>
56 
57 #include <QApplication>
58 #include <QClipboard>
59 #include <QTcpServer>
60 #include <QMenu>
61 #include <QPointer>
62 #include <QCheckBox>
63 
64 #include <dnssd/publicservice.h>
65 
66 KNotesPart::KNotesPart( KNotesResourceManager *manager, QObject *parent )
67  : KParts::ReadOnlyPart( parent ),
68  mNotesWidget( new KNotesWidget(this) ),
69  mNoteTip( new KNoteTip( mNotesWidget->notesView() ) ),
70  mManager( manager ),
71  mListener(0),
72  mPublisher(0),
73  mAlarm(0),
74  mNotePrintPreview(0)
75 {
76  (void) new KNotesAdaptor( this );
77  QDBusConnection::sessionBus().registerObject( QLatin1String("/KNotes"), this );
78 
79  setComponentData( KComponentData( "knotes" ) );
80 
81  // create the actions
82  mNewNote = new KAction( KIcon( QLatin1String("knotes") ),
83  i18nc( "@action:inmenu create new popup note", "&New" ), this );
84  actionCollection()->addAction( QLatin1String("file_new"), mNewNote );
85  connect( mNewNote, SIGNAL(triggered(bool)), SLOT(newNote()) );
86  mNewNote->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_N ) );
87  mNewNote->setHelpText(
88  i18nc( "@info:status", "Create a new popup note" ) );
89  mNewNote->setWhatsThis(
90  i18nc( "@info:whatsthis",
91  "You will be presented with a dialog where you can add a new popup note." ) );
92 
93  mNoteEdit = new KAction( KIcon( QLatin1String("document-edit") ),
94  i18nc( "@action:inmenu", "Edit..." ), this );
95  actionCollection()->addAction( QLatin1String("edit_note"), mNoteEdit );
96  connect( mNoteEdit, SIGNAL(triggered(bool)), SLOT(editNote()) );
97  mNoteEdit->setHelpText(
98  i18nc( "@info:status", "Edit popup note" ) );
99  mNoteEdit->setWhatsThis(
100  i18nc( "@info:whatsthis",
101  "You will be presented with a dialog where you can modify an existing popup note." ) );
102 
103  mNoteRename = new KAction( KIcon( QLatin1String("edit-rename") ),
104  i18nc( "@action:inmenu", "Rename..." ), this );
105  actionCollection()->addAction( QLatin1String("edit_rename"), mNoteRename );
106  connect( mNoteRename, SIGNAL(triggered(bool)), SLOT(renameNote()) );
107  mNoteRename->setHelpText(
108  i18nc( "@info:status", "Rename popup note" ) );
109  mNoteRename->setWhatsThis(
110  i18nc( "@info:whatsthis",
111  "You will be presented with a dialog where you can rename an existing popup note." ) );
112 
113  mNoteDelete = new KAction( KIcon( QLatin1String("edit-delete") ),
114  i18nc( "@action:inmenu", "Delete" ), this );
115  actionCollection()->addAction( QLatin1String("edit_delete"), mNoteDelete );
116  connect( mNoteDelete, SIGNAL(triggered(bool)), SLOT(killSelectedNotes()) );
117  mNoteDelete->setShortcut( QKeySequence( Qt::Key_Delete ) );
118  mNoteDelete->setHelpText(
119  i18nc( "@info:status", "Delete popup note" ) );
120  mNoteDelete->setWhatsThis(
121  i18nc( "@info:whatsthis",
122  "You will be prompted if you really want to permanently remove "
123  "the selected popup note." ) );
124 
125  mNotePrint = new KAction( KIcon( QLatin1String("document-print") ),
126  i18nc( "@action:inmenu", "Print Selected Notes..." ), this );
127  actionCollection()->addAction( QLatin1String("print_note"), mNotePrint );
128  connect( mNotePrint, SIGNAL(triggered(bool)), SLOT(slotPrintSelectedNotes()) );
129  mNotePrint->setHelpText(
130  i18nc( "@info:status", "Print popup note" ) );
131  mNotePrint->setWhatsThis(
132  i18nc( "@info:whatsthis",
133  "You will be prompted to print the selected popup note." ) );
134 
135  if(KPrintPreview::isAvailable()) {
136 
137  mNotePrintPreview = new KAction( KIcon( QLatin1String("document-print-preview") ),i18nc( "@action:inmenu", "Print Preview Selected Notes..." ), this );
138  actionCollection()->addAction( QLatin1String("print_preview_note"), mNotePrintPreview );
139 
140  connect( mNotePrintPreview, SIGNAL(triggered(bool)), SLOT(slotPrintPreviewSelectedNotes()) );
141  }
142 
143  mNoteConfigure = new KAction( KIcon( QLatin1String("configure") ), i18n( "Note settings..." ), this );
144  actionCollection()->addAction( QLatin1String("configure_note"), mNoteConfigure );
145  connect( mNoteConfigure, SIGNAL(triggered(bool)), SLOT(slotNotePreferences()) );
146 
147  KAction *act = new KAction( KIcon( QLatin1String("configure") ), i18n( "Preferences KNotes..." ), this );
148  actionCollection()->addAction( QLatin1String("knotes_configure"), act );
149  connect( act, SIGNAL(triggered(bool)), SLOT(slotPreferences()) );
150 
151  mNoteSendMail = new KAction( KIcon( QLatin1String("mail-send") ), i18n( "Mail..." ), this );
152  actionCollection()->addAction( QLatin1String("mail_note"), mNoteSendMail );
153  connect( mNoteSendMail, SIGNAL(triggered(bool)), SLOT(slotMail()) );
154 
155  mNoteSendNetwork = new KAction( KIcon( QLatin1String("network-wired") ), i18n( "Send..." ), this );
156  actionCollection()->addAction( QLatin1String("send_note"), mNoteSendNetwork );
157  connect( mNoteSendNetwork, SIGNAL(triggered(bool)), SLOT(slotSendToNetwork()) );
158 
159  mNoteSetAlarm = new KAction( KIcon( QLatin1String("knotes_alarm") ), i18n( "Set Alarm..." ), this );
160  actionCollection()->addAction( QLatin1String("set_alarm"), mNoteSetAlarm );
161  connect( mNoteSetAlarm, SIGNAL(triggered(bool)), SLOT(slotSetAlarm()) );
162 
163  act = new KAction( KIcon( QLatin1String("edit-paste") ),
164  i18n( "New Note From Clipboard" ), this );
165  actionCollection()->addAction( QLatin1String("new_note_clipboard"), act );
166  connect( act, SIGNAL(triggered()), SLOT(slotNewNoteFromClipboard()) );
167 
168 
169  mSaveAs = new KAction( KIcon( QLatin1String("document-save-as") ), i18n( "Save As..." ), this );
170  actionCollection()->addAction( QLatin1String("save_note"), mSaveAs );
171  connect( mSaveAs, SIGNAL(triggered(bool)), SLOT(slotSaveAs()) );
172 
173  mReadOnly = new KToggleAction( KIcon( QLatin1String("object-locked") ), i18n( "Lock" ), this );
174  actionCollection()->addAction( QLatin1String("lock_note"), mReadOnly );
175  connect( mReadOnly, SIGNAL(triggered(bool)), SLOT(slotUpdateReadOnly()) );
176  mReadOnly->setCheckedState( KGuiItem( i18n( "Unlock" ), QLatin1String("object-unlocked") ) );
177 
178 
179  // TODO icons: s/editdelete/knotes_delete/ or the other way round in knotes
180 
181  // set the view up
182 
183  connect( mNotesWidget->notesView(), SIGNAL(executed(QListWidgetItem*)),
184  this, SLOT(editNote(QListWidgetItem*)) );
185 
186  connect( mNotesWidget->notesView(), SIGNAL(entered(QModelIndex)),
187  this, SLOT(requestToolTip(QModelIndex)));
188 
189  connect( mNotesWidget->notesView(), SIGNAL(viewportEntered()),
190  this, SLOT(hideToolTip()));
191 
192  connect( mNotesWidget->notesView(), SIGNAL(itemSelectionChanged()),
193  this, SLOT(slotOnCurrentChanged()) );
194 
195  slotOnCurrentChanged();
196 
197  setWidget( mNotesWidget );
198  setXMLFile( QLatin1String("knotes_part.rc") );
199 
200  // connect the resource manager
201  connect( mManager, SIGNAL(sigRegisteredNote(KCal::Journal*)),
202  this, SLOT(createNote(KCal::Journal*)) );
203  connect( mManager, SIGNAL(sigDeregisteredNote(KCal::Journal*)),
204  this, SLOT(killNote(KCal::Journal*)) );
205  mManager->load();
206  mAlarm = new KNotesAlarm( mManager, this );
207  updateNetworkListener();
208 }
209 
210 KNotesPart::~KNotesPart()
211 {
212  delete mListener;
213  mListener=0;
214  delete mPublisher;
215  mPublisher=0;
216  delete mNoteTip;
217  mNoteTip = 0;
218 }
219 
220 QStringList KNotesPart::notesList() const
221 {
222  QStringList notes;
223 
224  QHashIterator<QString, KNotesIconViewItem*> i(mNoteList);
225  while ( i.hasNext() ) {
226  i.next();
227  notes.append(i.value()->journal()->uid());
228  }
229  return notes;
230 }
231 
232 void KNotesPart::requestToolTip( const QModelIndex &index )
233 {
234  const QRect m_itemRect = mNotesWidget->notesView()->visualRect( index );
235  mNoteTip->setNote(
236  static_cast<KNotesIconViewItem *>( mNotesWidget->notesView()->itemAt( m_itemRect.topLeft() ) ) );
237 }
238 
239 void KNotesPart::hideToolTip()
240 {
241  mNoteTip->setNote( 0 );
242 }
243 
244 void KNotesPart::slotPrintPreviewSelectedNotes()
245 {
246  printSelectedNotes(true);
247 }
248 
249 void KNotesPart::slotPrintSelectedNotes()
250 {
251  printSelectedNotes(false);
252 }
253 
254 void KNotesPart::printSelectedNotes(bool preview)
255 {
256  QList<QListWidgetItem *> lst = mNotesWidget->notesView()->selectedItems();
257  if ( lst.isEmpty() ) {
258  KMessageBox::information(
259  mNotesWidget,
260  i18nc( "@info",
261  "To print notes, first select the notes to print from the list." ),
262  i18nc( "@title:window", "Print Popup Notes" ) );
263  return;
264  }
265 
266  KNotesGlobalConfig *globalConfig = KNotesGlobalConfig::self();
267  QString printingTheme = globalConfig->theme();
268  if (printingTheme.isEmpty()) {
269  QPointer<KNotePrintSelectThemeDialog> dlg = new KNotePrintSelectThemeDialog(widget());
270  if (dlg->exec()) {
271  printingTheme = dlg->selectedTheme();
272  }
273  delete dlg;
274  }
275  if (!printingTheme.isEmpty()) {
276 
277  QList<KNotePrintObject *> listPrintObj;
278  foreach ( QListWidgetItem *item, lst ) {
279  listPrintObj.append(new KNotePrintObject(static_cast<KNotesIconViewItem *>( item )->journal()));
280  }
281  KNotePrinter printer;
282  printer.printNotes( listPrintObj, printingTheme, preview );
283  qDeleteAll(listPrintObj);
284  }
285 }
286 
287 bool KNotesPart::openFile()
288 {
289  return false;
290 }
291 
292 // public KNotes D-Bus interface implementation
293 
294 QString KNotesPart::newNote( const QString &name, const QString &text )
295 {
296  // create the new note
297  Journal *journal = new Journal();
298 
299  // new notes have the current date/time as title if none was given
300  if ( !name.isEmpty() ) {
301  journal->setSummary( name );
302  } else {
303  journal->setSummary( KGlobal::locale()->formatDateTime( QDateTime::currentDateTime() ) );
304  }
305 
306  // the body of the note
307  journal->setDescription( text );
308 
309  // Edit the new note if text is empty
310  if ( text.isNull() ) {
311  QPointer<KNoteEditDialog> dlg = new KNoteEditDialog( false, widget() );
312 
313  dlg->setTitle( journal->summary() );
314  dlg->setText( journal->description() );
315 
316 
317  const QString property = journal->customProperty("KNotes", "RichText");
318  if ( !property.isNull() ) {
319  dlg->setAcceptRichText( property == QLatin1String("true") ? true : false );
320  } else {
321  KNotesGlobalConfig *globalConfig = KNotesGlobalConfig::self();
322  dlg->setAcceptRichText( globalConfig->richText());
323  }
324 
325 
326  dlg->noteEdit()->setFocus();
327  if ( dlg->exec() == QDialog::Accepted ) {
328  journal->setSummary( dlg->title() );
329  journal->setDescription( dlg->text() );
330  delete dlg;
331  } else {
332  delete dlg;
333  delete journal;
334  return QString();
335  }
336  }
337 
338  mManager->addNewNote( journal );
339 
340  KNotesIconViewItem *note = mNoteList.value( journal->uid() );
341  mNotesWidget->notesView()->scrollToItem( note );
342  mNotesWidget->notesView()->setCurrentItem( note );
343  mManager->save();
344  return journal->uid();
345 }
346 
347 QString KNotesPart::newNoteFromClipboard( const QString &name )
348 {
349  const QString &text = QApplication::clipboard()->text();
350  return newNote( name, text );
351 }
352 
353 void KNotesPart::killNote( const QString &id )
354 {
355  killNote( id, false );
356 }
357 
358 void KNotesPart::killNote( const QString &id, bool force )
359 {
360  KNotesIconViewItem *note = mNoteList.value( id );
361 
362  if ( note &&
363  ( (!force && KMessageBox::warningContinueCancelList(
364  mNotesWidget,
365  i18nc( "@info", "Do you really want to delete this note?" ),
366  QStringList( mNoteList.value( id )->text() ),
367  i18nc( "@title:window", "Confirm Delete" ),
368  KStandardGuiItem::del() ) == KMessageBox::Continue )
369  || force ) ) {
370  KNoteUtils::removeNote(mNoteList.value( id )->journal(), 0);
371  mManager->deleteNote( mNoteList.value( id )->journal() );
372  mManager->save();
373  }
374 }
375 
376 QString KNotesPart::name( const QString &id ) const
377 {
378  KNotesIconViewItem *note = mNoteList.value( id );
379  if ( note ) {
380  return note->text();
381  } else {
382  return QString();
383  }
384 }
385 
386 QString KNotesPart::text( const QString &id ) const
387 {
388  KNotesIconViewItem *note = mNoteList.value( id );
389  if ( note ) {
390  return note->journal()->description();
391  } else {
392  return QString();
393  }
394 }
395 
396 void KNotesPart::setName( const QString &id, const QString &newName )
397 {
398  KNotesIconViewItem *note = mNoteList.value( id );
399  if ( note ) {
400  note->setIconText( newName );
401  mManager->save();
402  }
403 }
404 
405 void KNotesPart::setText( const QString &id, const QString &newText )
406 {
407  KNotesIconViewItem *note = mNoteList.value( id );
408  if ( note ) {
409  note->journal()->setDescription( newText );
410  mManager->save();
411  }
412 }
413 
414 QMap<QString, QString> KNotesPart::notes() const
415 {
416  QMap<QString, QString> notes;
417 
418  QHashIterator<QString, KNotesIconViewItem*> i(mNoteList);
419  while ( i.hasNext() ) {
420  i.next();
421  notes.insert( i.value()->journal()->uid(), i.value()->journal()->summary() );
422  }
423  return notes;
424 }
425 
426 // private stuff
427 
428 void KNotesPart::killSelectedNotes()
429 {
430  QList<QListWidgetItem *> lst = mNotesWidget->notesView()->selectedItems();
431  if ( lst.isEmpty() ) {
432  return;
433  }
434  QList<KNotesIconViewItem*> items;
435 
436  foreach ( QListWidgetItem *item, lst ) {
437  KNotesIconViewItem *knivi = static_cast<KNotesIconViewItem *>( item );
438  items.append( knivi );
439  }
440 
441  if (items.isEmpty())
442  return;
443 
444  QPointer<KNotesSelectDeleteNotesDialog> dlg = new KNotesSelectDeleteNotesDialog(items, widget());
445  if (dlg->exec()) {
446  QListIterator<KNotesIconViewItem*> kniviIt( items );
447  while ( kniviIt.hasNext() ) {
448  KNotesIconViewItem *iconViewIcon = kniviIt.next();
449  if (!iconViewIcon->readOnly()) {
450  Journal *journal = iconViewIcon->journal();
451  KNoteUtils::removeNote(journal, 0);
452  mManager->deleteNote( journal );
453  }
454  }
455  mManager->save();
456  }
457 
458  delete dlg;
459 }
460 
461 void KNotesPart::popupRMB( QListWidgetItem *item, const QPoint &pos, const QPoint &globalPos )
462 {
463  Q_UNUSED( item );
464 
465  QMenu *contextMenu = new QMenu(widget());
466  if ( mNotesWidget->notesView()->itemAt ( pos ) ) {
467  contextMenu->addAction(mNewNote);
468  const bool uniqueNoteSelected = (mNotesWidget->notesView()->selectedItems().count() == 1);
469  const bool readOnly = uniqueNoteSelected ? static_cast<KNotesIconViewItem *>(mNotesWidget->notesView()->selectedItems().at(0))->readOnly() : false;
470  if (uniqueNoteSelected) {
471  if (!readOnly) {
472  contextMenu->addSeparator();
473  contextMenu->addAction(mNoteSetAlarm);
474  }
475  contextMenu->addSeparator();
476  contextMenu->addAction(mSaveAs);
477  contextMenu->addSeparator();
478  contextMenu->addAction(mNoteEdit);
479  contextMenu->addAction(mReadOnly);
480  if (!readOnly)
481  contextMenu->addAction(mNoteRename);
482  contextMenu->addSeparator();
483  contextMenu->addAction(mNoteSendMail);
484  contextMenu->addSeparator();
485  contextMenu->addAction(mNoteSendNetwork);
486  }
487  contextMenu->addSeparator();
488  contextMenu->addAction(mNotePrint);
489  contextMenu->addAction(mNotePrintPreview);
490 
491  if (!readOnly) {
492  contextMenu->addSeparator();
493  contextMenu->addAction(mNoteConfigure);
494  contextMenu->addSeparator();
495  contextMenu->addAction(mNoteDelete);
496  }
497  } else {
498  contextMenu->addAction(mNewNote);
499  }
500 
501  contextMenu->exec( mNotesWidget->notesView()->mapFromParent( globalPos ) );
502  delete contextMenu;
503 }
504 
505 // TODO: also with takeItem, clear(),
506 
507 // create and kill the icon view item corresponding to the note, edit the note
508 
509 void KNotesPart::createNote( KCal::Journal *journal )
510 {
511  mNoteList.insert( journal->uid(), new KNotesIconViewItem( mNotesWidget->notesView(), journal ) );
512 }
513 
514 void KNotesPart::killNote( KCal::Journal *journal )
515 {
516  KNotesIconViewItem *item = mNoteList.take( journal->uid() );
517  delete item;
518 }
519 
520 void KNotesPart::editNote( QListWidgetItem *item )
521 {
522  KNotesIconViewItem * knotesItem = static_cast<KNotesIconViewItem *>( item );
523  QPointer<KNoteEditDialog> dlg = new KNoteEditDialog( knotesItem->readOnly(), widget() );
524  Journal *journal = knotesItem->journal();
525  dlg->setTitle( journal->summary() );
526  dlg->setText( journal->description() );
527 
528  const QString property = journal->customProperty("KNotes", "RichText");
529  if ( !property.isNull() ) {
530  dlg->setAcceptRichText( property == QLatin1String("true") ? true : false );
531  } else {
532  KNotesGlobalConfig *globalConfig = KNotesGlobalConfig::self();
533  dlg->setAcceptRichText( globalConfig->richText());
534  }
535  dlg->setTabSize(knotesItem->tabSize());
536  dlg->setAutoIndentMode(knotesItem->autoIndent());
537  dlg->setTextFont(knotesItem->textFont());
538 
539  dlg->noteEdit()->setFocus();
540  if ( dlg->exec() == QDialog::Accepted ) {
541  static_cast<KNotesIconViewItem *>( item )->setIconText( dlg->title() );
542  journal->setDescription( dlg->text() );
543  mManager->save();
544  }
545  delete dlg;
546 }
547 
548 void KNotesPart::editNote()
549 {
550  QListWidgetItem *item = mNotesWidget->notesView()->currentItem();
551  if ( item ) {
552  editNote( item );
553  }
554 }
555 
556 void KNotesPart::renameNote()
557 {
558  KNotesIconViewItem *knoteItem = static_cast<KNotesIconViewItem *>(mNotesWidget->notesView()->currentItem());
559 
560  const QString oldName = knoteItem->realName();
561  bool ok = false;
562  const QString newName =
563  KInputDialog::getText( i18nc( "@title:window", "Rename Popup Note" ),
564  i18nc( "@label:textbox", "New Name:" ),
565  oldName, &ok, mNotesWidget );
566  if ( ok && ( newName != oldName ) ) {
567  knoteItem->setIconText( newName );
568  mManager->save();
569  }
570 }
571 
572 void KNotesPart::slotOnCurrentChanged( )
573 {
574  const bool uniqueNoteSelected = (mNotesWidget->notesView()->selectedItems().count() == 1);
575  const bool enabled(mNotesWidget->notesView()->currentItem());
576  mNoteRename->setEnabled( enabled && uniqueNoteSelected);
577  mNoteEdit->setEnabled( enabled && uniqueNoteSelected);
578  mNoteConfigure->setEnabled( uniqueNoteSelected );
579  mNoteSendMail->setEnabled(uniqueNoteSelected);
580  mNoteSendNetwork->setEnabled(uniqueNoteSelected);
581  mNoteSetAlarm->setEnabled(uniqueNoteSelected);
582  mSaveAs->setEnabled(uniqueNoteSelected);
583  mReadOnly->setEnabled(uniqueNoteSelected);
584  if (uniqueNoteSelected) {
585  const bool readOnly = static_cast<KNotesIconViewItem *>(mNotesWidget->notesView()->selectedItems().at(0))->readOnly();
586  mReadOnly->setChecked(readOnly);
587  mNoteEdit->setText(readOnly ? i18n("Show Note...") : i18nc( "@action:inmenu", "Edit..." ));
588  } else {
589  mNoteEdit->setText(i18nc( "@action:inmenu", "Edit..." ));
590  }
591 }
592 
593 void KNotesPart::slotNotePreferences()
594 {
595  if (!mNotesWidget->notesView()->currentItem())
596  return;
597 
598  KNotesIconViewItem *knoteItem = static_cast<KNotesIconViewItem *>(mNotesWidget->notesView()->currentItem());
599  const QString name = knoteItem->realName();
600  QPointer<KNoteSimpleConfigDialog> dialog = new KNoteSimpleConfigDialog( knoteItem->config(), name, widget(), knoteItem->journal()->uid() );
601  connect( dialog, SIGNAL(settingsChanged(QString)) , this,
602  SLOT(slotApplyConfig()) );
603  dialog->exec();
604  delete dialog;
605 }
606 
607 void KNotesPart::slotApplyConfig()
608 {
609  KNotesIconViewItem *knoteItem = static_cast<KNotesIconViewItem *>(mNotesWidget->notesView()->currentItem());
610  knoteItem->updateSettings();
611  mManager->save();
612 }
613 
614 void KNotesPart::slotPreferences()
615 {
616  // create a new preferences dialog...
617  KNoteConfigDialog *dialog = new KNoteConfigDialog( i18n( "Settings" ), widget());
618  connect( dialog, SIGNAL(configWrote()), this, SLOT(slotConfigUpdated()));
619  dialog->show();
620 }
621 
622 void KNotesPart::slotConfigUpdated()
623 {
624  updateNetworkListener();
625 }
626 
627 void KNotesPart::slotMail()
628 {
629  if (!mNotesWidget->notesView()->currentItem())
630  return;
631  KNotesIconViewItem *knoteItem = static_cast<KNotesIconViewItem *>(mNotesWidget->notesView()->currentItem());
632  KNoteUtils::sendMail(widget(),knoteItem->realName(), knoteItem->journal()->description());
633 }
634 
635 void KNotesPart::slotSendToNetwork()
636 {
637  if (!mNotesWidget->notesView()->currentItem())
638  return;
639  KNotesIconViewItem *knoteItem = static_cast<KNotesIconViewItem *>(mNotesWidget->notesView()->currentItem());
640  KNoteUtils::sendToNetwork(widget(),knoteItem->realName(), knoteItem->journal()->description());
641 }
642 
643 void KNotesPart::updateNetworkListener()
644 {
645  delete mListener;
646  mListener=0;
647  delete mPublisher;
648  mPublisher=0;
649 
650  if ( KNotesGlobalConfig::receiveNotes() ) {
651  // create the socket and start listening for connections
652  mListener = KSocketFactory::listen( QLatin1String("knotes") , QHostAddress::Any,
653  KNotesGlobalConfig::port() );
654  connect( mListener, SIGNAL(newConnection()), SLOT(slotAcceptConnection()) );
655  mPublisher=new DNSSD::PublicService(KNotesGlobalConfig::senderID(), QLatin1String("_knotes._tcp"), KNotesGlobalConfig::port());
656  mPublisher->publishAsync();
657  }
658 }
659 
660 void KNotesPart::slotAcceptConnection()
661 {
662  // Accept the connection and make KNotesNetworkReceiver do the job
663  QTcpSocket *s = mListener->nextPendingConnection();
664 
665  if ( s ) {
666  KNotesNetworkReceiver *recv = new KNotesNetworkReceiver( s );
667  connect( recv,SIGNAL(sigNoteReceived(QString,QString)), SLOT(newNote(QString,QString)) );
668  }
669 }
670 
671 void KNotesPart::slotSetAlarm()
672 {
673  if (!mNotesWidget->notesView()->currentItem())
674  return;
675  KNotesIconViewItem *knoteItem = static_cast<KNotesIconViewItem *>(mNotesWidget->notesView()->currentItem());
676 
677  QPointer<KNoteAlarmDialog> dlg = new KNoteAlarmDialog( knoteItem->realName(), widget() );
678  dlg->setIncidence( knoteItem->journal() );
679  if ( dlg->exec() ) {
680  mManager->save();
681  }
682  delete dlg;
683 }
684 
685 void KNotesPart::slotNewNoteFromClipboard()
686 {
687  const QString &text = KApplication::clipboard()->text();
688  newNote( QString(), text );
689 }
690 
691 void KNotesPart::slotSaveAs()
692 {
693  if (!mNotesWidget->notesView()->currentItem())
694  return;
695  KNotesIconViewItem *knoteItem = static_cast<KNotesIconViewItem *>(mNotesWidget->notesView()->currentItem());
696 
697  KUrl url;
698  QCheckBox *convert = 0;
699 
700  if ( knoteItem->isRichText() ) {
701  convert = new QCheckBox( 0 );
702  convert->setText( i18n( "Save note as plain text" ) );
703  }
704  QPointer<KFileDialog> dlg = new KFileDialog( url, QString(), widget(), convert );
705  dlg->setOperationMode( KFileDialog::Saving );
706  dlg->setCaption( i18n( "Save As" ) );
707  if( !dlg->exec() ) {
708  delete dlg;
709  return;
710  }
711 
712  const QString fileName = dlg->selectedFile();
713  const bool htmlFormatAndSaveAsHtml = (convert && !convert->isChecked());
714  delete dlg;
715  if ( fileName.isEmpty() ) {
716  return;
717  }
718 
719  QFile file( fileName );
720  if ( file.exists() &&
721  KMessageBox::warningContinueCancel( widget(),
722  i18n( "<qt>A file named <b>%1</b> already exists.<br />"
723  "Are you sure you want to overwrite it?</qt>",
724  QFileInfo( file ).fileName() ) ) != KMessageBox::Continue ) {
725  return;
726  }
727 
728  if ( file.open( QIODevice::WriteOnly ) ) {
729  QTextStream stream( &file );
730  QTextDocument doc;
731  doc.setHtml(knoteItem->journal()->description());
732  if ( htmlFormatAndSaveAsHtml ) {
733  stream << doc.toHtml();
734  } else {
735  stream << knoteItem->realName() + QLatin1Char('\n');
736  stream << doc.toPlainText();
737  }
738  }
739 }
740 
741 void KNotesPart::slotUpdateReadOnly()
742 {
743  if (!mNotesWidget->notesView()->currentItem())
744  return;
745  KNotesIconViewItem *knoteItem = static_cast<KNotesIconViewItem *>(mNotesWidget->notesView()->currentItem());
746 
747  const bool readOnly = mReadOnly->isChecked();
748 
749  mNoteEdit->setText(readOnly ? i18n("Show Note...") : i18nc( "@action:inmenu", "Edit..." ));
750 
751  knoteItem->setReadOnly( readOnly );
752 }
753 
754 #include "knotes_part.moc"
KNotesPart::setName
void setName(const QString &id, const QString &newName)
Definition: knotes_part.cpp:396
KNotesIconViewItem::autoIndent
bool autoIndent() const
Definition: knotesiconview.cpp:131
KNotesPart::openFile
bool openFile()
Definition: knotes_part.cpp:287
KNotesPart::notes
QMap< QString, QString > notes() const
Definition: knotes_part.cpp:414
KNotesPart::setText
void setText(const QString &id, const QString &newText)
Definition: knotes_part.cpp:405
KNotesPart::newNoteFromClipboard
QString newNoteFromClipboard(const QString &name=QString())
Definition: knotes_part.cpp:347
text
virtual QByteArray text(quint32 serialNumber) const =0
KNotesIconViewItem::journal
Journal * journal() const
Definition: knotesiconview.cpp:86
KNotesWidget::notesView
KNotesIconView * notesView() const
Definition: knoteswidget.cpp:41
KNotesIconViewItem::updateSettings
void updateSettings()
Definition: knotesiconview.cpp:74
KNoteTip
Definition: knotetip.h:43
QObject
KNotesPart::notesList
QStringList notesList() const
Definition: knotes_part.cpp:220
KNotesWidget
Definition: knoteswidget.h:25
KNotesPart::name
QString name(const QString &id) const
Definition: knotes_part.cpp:376
KNotesPart::text
QString text(const QString &id) const
Definition: knotes_part.cpp:386
KNotesIconViewItem::setIconText
void setIconText(const QString &text)
Definition: knotesiconview.cpp:101
knoteswidget.h
knotetip.h
KNotesIconViewItem::isRichText
bool isRichText() const
Definition: knotesiconview.cpp:141
KNotesSelectDeleteNotesDialog
Definition: knotesselectdeletenotesdialog.h:35
knotes_part.h
KNotesIconViewItem::realName
QString realName() const
Definition: knotesiconview.cpp:96
KNotesIconViewItem::config
KNoteConfig * config()
Definition: knotesiconview.cpp:91
KNotesPart::newNote
QString newNote(const QString &name=QString(), const QString &text=QString())
Definition: knotes_part.cpp:294
KNoteTip::setNote
void setNote(KNotesIconViewItem *item)
Definition: knotetip.cpp:75
QListWidgetItem
KNotesIconViewItem::readOnly
bool readOnly() const
Definition: knotesiconview.cpp:115
KNotesPart::killNote
void killNote(const QString &id)
Definition: knotes_part.cpp:353
KNotesPart::~KNotesPart
~KNotesPart()
Definition: knotes_part.cpp:210
KNotesIconViewItem::textFont
QFont textFont() const
Definition: knotesiconview.cpp:136
QMenu
knotesiconview.h
KNotesIconViewItem
Definition: knotesiconview.h:37
KNotesPart::popupRMB
void popupRMB(QListWidgetItem *item, const QPoint &pos, const QPoint &globalPos)
Definition: knotes_part.cpp:461
knoteseditdialog.h
KNotesIconViewItem::setReadOnly
void setReadOnly(bool b)
Definition: knotesiconview.cpp:120
KNoteEditDialog
Definition: knoteseditdialog.h:28
KNotesPart::KNotesPart
KNotesPart(KNotesResourceManager *manager, QObject *parent=0)
Definition: knotes_part.cpp:66
knotesselectdeletenotesdialog.h
KNotesIconViewItem::tabSize
int tabSize() const
Definition: knotesiconview.cpp:126
QList
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