knotes

knotesapp.cpp
1 /*******************************************************************
2  KNotes -- Notes for the KDE project
3 
4  Copyright (c) 1997-2006, 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 <tqclipboard.h>
22 #include <tqptrlist.h>
23 #include <tqtooltip.h>
24 
25 #include <kdebug.h>
26 #include <tdeaction.h>
27 #include <kxmlguifactory.h>
28 #include <kxmlguibuilder.h>
29 #include <ksystemtray.h>
30 #include <tdelocale.h>
31 #include <kiconeffect.h>
32 #include <kstandarddirs.h>
33 #include <tdepopupmenu.h>
34 #include <khelpmenu.h>
35 #include <kfind.h>
36 #include <kfinddialog.h>
37 #include <kkeydialog.h>
38 #include <kglobalaccel.h>
39 #include <ksimpleconfig.h>
40 #include <twin.h>
41 #include <kbufferedsocket.h>
42 #include <kserversocket.h>
43 
44 #include <libkcal/journal.h>
45 #include <libkcal/calendarlocal.h>
46 
47 #include "knotesapp.h"
48 #include "knote.h"
49 #include "knotesalarm.h"
50 #include "knoteconfigdlg.h"
51 #include "knotesglobalconfig.h"
52 #include "knoteslegacy.h"
53 #include "knotesnetrecv.h"
54 
55 #include "knotes/resourcemanager.h"
56 
57 using namespace KNetwork;
58 
59 
60 class KNotesKeyDialog : public KDialogBase
61 {
62 public:
63  KNotesKeyDialog( TDEGlobalAccel *globals, TQWidget *parent, const char* name = 0 )
64  : KDialogBase( parent, name, true, i18n("Configure Shortcuts"), Default|Ok|Cancel, Ok )
65  {
66  m_keyChooser = new KKeyChooser( globals, this );
67  setMainWidget( m_keyChooser );
68  connect( this, TQT_SIGNAL(defaultClicked()), m_keyChooser, TQT_SLOT(allDefault()) );
69  }
70 
71  void insert( TDEActionCollection *actions )
72  {
73  m_keyChooser->insert( actions, i18n("Note Actions") );
74  }
75 
76  void configure()
77  {
78  if ( exec() == Accepted )
79  m_keyChooser->save();
80  }
81 
82 private:
83  KKeyChooser *m_keyChooser;
84 };
85 
86 
87 int KNotesApp::KNoteActionList::compareItems( TQPtrCollection::Item s1, TQPtrCollection::Item s2 )
88 {
89  if ( ((TDEAction*)s1)->text() == ((TDEAction*)s2)->text() )
90  return 0;
91  return ( ((TDEAction*)s1)->text() < ((TDEAction*)s2)->text() ? -1 : 1 );
92 }
93 
94 
95 KNotesApp::KNotesApp()
96  : DCOPObject("KNotesIface"), TQLabel( 0, 0, WType_TopLevel ),
97  m_alarm( 0 ), m_listener( 0 ), m_find( 0 ), m_findPos( 0 )
98 {
99  connect( kapp, TQT_SIGNAL(lastWindowClosed()), kapp, TQT_SLOT(quit()) );
100 
101  m_noteList.setAutoDelete( true );
102  m_noteActions.setAutoDelete( true );
103 
104  // create the dock widget...
105  KWin::setSystemTrayWindowFor( winId(), tqt_xrootwin() );
106  TQToolTip::add( this, i18n( "KNotes: Sticky notes for TDE" ) );
107  setBackgroundMode( X11ParentRelative );
108  setPixmap( KSystemTray::loadIcon( "knotes" ) );
109 
110  // set the initial style
111  KNote::setStyle( KNotesGlobalConfig::style() );
112 
113  // create the GUI...
114  new TDEAction( i18n("New Note"), "document-new", 0,
115  TQT_TQOBJECT(this), TQT_SLOT(newNote()), actionCollection(), "new_note" );
116  new TDEAction( i18n("New Note From Clipboard"), "edit-paste", 0,
117  TQT_TQOBJECT(this), TQT_SLOT(newNoteFromClipboard()), actionCollection(), "new_note_clipboard" );
118  new TDEAction( i18n("Show All Notes"), "knotes", 0,
119  TQT_TQOBJECT(this), TQT_SLOT(showAllNotes()), actionCollection(), "show_all_notes" );
120  new TDEAction( i18n("Hide All Notes"), "window-close", 0,
121  TQT_TQOBJECT(this), TQT_SLOT(hideAllNotes()), actionCollection(), "hide_all_notes" );
122  new KHelpMenu( this, kapp->aboutData(), false, actionCollection() );
123 
124  m_findAction = KStdAction::find( TQT_TQOBJECT(this), TQT_SLOT(slotOpenFindDialog()), actionCollection() );
125  KStdAction::preferences( TQT_TQOBJECT(this), TQT_SLOT(slotPreferences()), actionCollection() );
126  KStdAction::keyBindings( TQT_TQOBJECT(this), TQT_SLOT(slotConfigureAccels()), actionCollection() );
127  //FIXME: no shortcut removing!?
128  KStdAction::quit( TQT_TQOBJECT(this), TQT_SLOT(slotQuit()), actionCollection() )->setShortcut( 0 );
129 
130  setXMLFile( instance()->instanceName() + "appui.rc" );
131 
132  m_guiBuilder = new KXMLGUIBuilder( this );
133  m_guiFactory = new KXMLGUIFactory( m_guiBuilder, TQT_TQOBJECT(this) );
134  m_guiFactory->addClient( this );
135 
136  m_context_menu = static_cast<TDEPopupMenu*>(m_guiFactory->container( "knotes_context", this ));
137  m_note_menu = static_cast<TDEPopupMenu*>(m_guiFactory->container( "notes_menu", this ));
138 
139  // get the most recent XML UI file
140  TQString xmlFileName = instance()->instanceName() + "ui.rc";
141  TQString filter = TQString::fromLatin1( instance()->instanceName() + '/' ) + xmlFileName;
142  TQStringList fileList = instance()->dirs()->findAllResources( "data", filter ) +
143  instance()->dirs()->findAllResources( "data", xmlFileName );
144 
145  TQString doc;
146  KXMLGUIClient::findMostRecentXMLFile( fileList, doc );
147  m_noteGUI.setContent( doc );
148 
149  // create accels for global shortcuts
150  m_globalAccel = new TDEGlobalAccel( TQT_TQOBJECT(this), "global accel" );
151  m_globalAccel->insert( "global_new_note", i18n("New Note"), "",
152  TDEShortcut(), TDEShortcut(),
153  TQT_TQOBJECT(this), TQT_SLOT(newNote()), true, true );
154  m_globalAccel->insert( "global_new_note_clipboard", i18n("New Note From Clipboard"), "",
155  TDEShortcut(), TDEShortcut(),
156  TQT_TQOBJECT(this), TQT_SLOT(newNoteFromClipboard()), true, true );
157  m_globalAccel->insert( "global_hide_all_notes", i18n("Hide All Notes"), "",
158  TDEShortcut(), TDEShortcut(),
159  TQT_TQOBJECT(this), TQT_SLOT(hideAllNotes()), true, true );
160  m_globalAccel->insert( "global_show_all_notes", i18n("Show All Notes"), "",
161  TDEShortcut(), TDEShortcut(),
162  TQT_TQOBJECT(this), TQT_SLOT(showAllNotes()), true, true );
163 
164  m_globalAccel->readSettings();
165 
166  TDEConfig *config = TDEGlobal::config();
167  config->setGroup( "Global Keybindings" );
168  m_globalAccel->setEnabled( config->readBoolEntry( "Enabled", true ) );
169 
170  updateGlobalAccels();
171 
172  // clean up old config files
173  KNotesLegacy::cleanUp();
174 
175  // create the resource manager
176  m_manager = new KNotesResourceManager();
177  connect( m_manager, TQT_SIGNAL(sigRegisteredNote( KCal::Journal * )),
178  this, TQT_SLOT(createNote( KCal::Journal * )) );
179  connect( m_manager, TQT_SIGNAL(sigDeregisteredNote( KCal::Journal * )),
180  this, TQT_SLOT(killNote( KCal::Journal * )) );
181 
182  // read the notes
183  m_manager->load();
184 
185  // read the old config files, convert and add them
186  KCal::CalendarLocal calendar( TQString::fromLatin1( "UTC" ) );
187  if ( KNotesLegacy::convert( &calendar ) )
188  {
189  KCal::Journal::List notes = calendar.journals();
190  KCal::Journal::List::ConstIterator it;
191  for ( it = notes.constBegin(); it != notes.constEnd(); ++it )
192  m_manager->addNewNote( *it );
193 
194  m_manager->save();
195  }
196 
197  // set up the alarm reminder - do it after loading the notes because this
198  // is used as a check if updateNoteActions has to be called for a new note
199  m_alarm = new KNotesAlarm( m_manager, TQT_TQOBJECT(this) );
200 
201  // create the socket and possibly start listening for connections
202  m_listener = new TDEServerSocket();
203  m_listener->setResolutionEnabled( true );
204  connect( m_listener, TQT_SIGNAL(readyAccept()), TQT_SLOT(acceptConnection()) );
205  updateNetworkListener();
206 
207  if ( m_noteList.count() == 0 && !kapp->isRestored() )
208  newNote();
209 
210  updateNoteActions();
211 }
212 
213 void KNotesApp::resizeTrayIcon ()
214 {
215  // Honor Free Desktop specifications that allow for arbitrary system tray icon sizes
216  TQPixmap origpixmap;
217  TQPixmap scaledpixmap;
218  TQImage newIcon;
219  origpixmap = KSystemTray::loadSizedIcon( "knotes", TQWidget::width() );
220  newIcon = origpixmap;
221  newIcon = newIcon.smoothScale(TQWidget::width(), TQWidget::height());
222  scaledpixmap = newIcon;
223  setPixmap(scaledpixmap);
224 }
225 
226 void KNotesApp::resizeEvent ( TQResizeEvent * )
227 {
228  // Honor Free Desktop specifications that allow for arbitrary system tray icon sizes
229  resizeTrayIcon();
230 }
231 
232 void KNotesApp::showEvent ( TQShowEvent * )
233 {
234  // Honor Free Desktop specifications that allow for arbitrary system tray icon sizes
235  resizeTrayIcon();
236 }
237 
238 KNotesApp::~KNotesApp()
239 {
240  saveNotes();
241 
242  blockSignals( true );
243  m_noteList.clear();
244  blockSignals( false );
245 
246  delete m_listener;
247  delete m_manager;
248  delete m_guiBuilder;
249 }
250 
251 bool KNotesApp::commitData( TQSessionManager& )
252 {
253  saveConfigs();
254  return true;
255 }
256 
257 // -------------------- public DCOP interface -------------------- //
258 
259 TQString KNotesApp::newNote( const TQString& name, const TQString& text )
260 {
261  // create the new note
262  KCal::Journal *journal = new KCal::Journal();
263 
264  // new notes have the current date/time as title if none was given
265  if ( !name.isEmpty() )
266  journal->setSummary( name );
267  else
268  journal->setSummary( TDEGlobal::locale()->formatDateTime( TQDateTime::currentDateTime() ) );
269 
270  // the body of the note
271  journal->setDescription( text );
272 
273  if ( m_manager->addNewNote( journal ) ) {
274  showNote( journal->uid() );
275  }
276  return journal->uid();
277 }
278 
279 TQString KNotesApp::newNoteFromClipboard( const TQString& name )
280 {
281  const TQString& text = TDEApplication::clipboard()->text();
282  return newNote( name, text );
283 }
284 
285 void KNotesApp::hideAllNotes() const
286 {
287  TQDictIterator<KNote> it( m_noteList );
288  for ( ; *it; ++it )
289  (*it)->close();
290 }
291 
292 void KNotesApp::showAllNotes() const
293 {
294  TQDictIterator<KNote> it( m_noteList );
295  for ( ; *it; ++it )
296  {
297  (*it)->show();
298  }
299 }
300 
301 void KNotesApp::showNote( const TQString& id ) const
302 {
303  KNote* note = m_noteList[id];
304  if ( note )
305  showNote( note );
306  else
307  kdWarning(5500) << "showNote: no note with id: " << id << endl;
308 }
309 
310 void KNotesApp::hideNote( const TQString& id ) const
311 {
312  KNote* note = m_noteList[id];
313  if ( note )
314  note->hide();
315  else
316  kdWarning(5500) << "hideNote: no note with id: " << id << endl;
317 }
318 
319 void KNotesApp::killNote( const TQString& id, bool force )
320 {
321  KNote* note = m_noteList[id];
322  if ( note )
323  note->slotKill( force );
324  else
325  kdWarning(5500) << "killNote: no note with id: " << id << endl;
326 }
327 
328 // "bool force = false" doesn't work with dcop
329 void KNotesApp::killNote( const TQString& id )
330 {
331  killNote( id, false );
332 }
333 
334 TQMap<TQString,TQString> KNotesApp::notes() const
335 {
336  TQMap<TQString,TQString> notes;
337  TQDictIterator<KNote> it( m_noteList );
338 
339  for ( ; it.current(); ++it )
340  notes.insert( it.current()->noteId(), it.current()->name() );
341 
342  return notes;
343 }
344 
345 TQString KNotesApp::name( const TQString& id ) const
346 {
347  KNote* note = m_noteList[id];
348  if ( note )
349  return note->name();
350  else
351  return TQString();
352 }
353 
354 TQString KNotesApp::text( const TQString& id ) const
355 {
356  KNote* note = m_noteList[id];
357  if ( note )
358  return note->text();
359  else
360  return TQString();
361 }
362 
363 void KNotesApp::setName( const TQString& id, const TQString& newName )
364 {
365  KNote* note = m_noteList[id];
366  if ( note )
367  note->setName( newName );
368  else
369  kdWarning(5500) << "setName: no note with id: " << id << endl;
370 }
371 
372 void KNotesApp::setText( const TQString& id, const TQString& newText )
373 {
374  KNote* note = m_noteList[id];
375  if ( note )
376  note->setText( newText );
377  else
378  kdWarning(5500) << "setText: no note with id: " << id << endl;
379 }
380 
381 TQString KNotesApp::fgColor( const TQString& id ) const
382 {
383  KNote* note = m_noteList[id];
384  if ( note )
385  return note->fgColor().name();
386  else
387  return TQString();
388 }
389 
390 TQString KNotesApp::bgColor( const TQString& id ) const
391 {
392  KNote* note = m_noteList[id];
393  if ( note )
394  return note->bgColor().name();
395  else
396  return TQString();
397 }
398 
399 void KNotesApp::setColor( const TQString& id, const TQString& fgColor, const TQString& bgColor )
400 {
401  KNote* note = m_noteList[id];
402  if ( note )
403  note->setColor( TQColor( fgColor ), TQColor( bgColor ) );
404  else
405  kdWarning(5500) << "setColor: no note with id: " << id << endl;
406 }
407 
408 int KNotesApp::width( const TQString& id ) const
409 {
410  KNote* note = m_noteList[id];
411  if ( note )
412  return note->width();
413  else
414  return 0;
415 }
416 
417 int KNotesApp::height( const TQString& id ) const
418 {
419  KNote* note = m_noteList[id];
420  if ( note )
421  return note->height();
422  else
423  return 0;
424 }
425 
426 void KNotesApp::move( const TQString& id, int x, int y ) const
427 {
428  KNote* note = m_noteList[id];
429  if ( note )
430  return note->move( x, y );
431  else
432  kdWarning(5500) << "move: no note with id: " << id << endl;
433 }
434 
435 void KNotesApp::resize( const TQString& id, int width, int height ) const
436 {
437  KNote* note = m_noteList[id];
438  if ( note )
439  return note->resize( width, height );
440  else
441  kdWarning(5500) << "resize: no note with id: " << id << endl;
442 }
443 
444 void KNotesApp::sync( const TQString& app )
445 {
446  TQDictIterator<KNote> it( m_noteList );
447 
448  for ( ; it.current(); ++it )
449  it.current()->sync( app );
450 }
451 
452 bool KNotesApp::isNew( const TQString& app, const TQString& id ) const
453 {
454  KNote* note = m_noteList[id];
455  if ( note )
456  return note->isNew( app );
457  else
458  return false;
459 }
460 
461 bool KNotesApp::isModified( const TQString& app, const TQString& id ) const
462 {
463  KNote* note = m_noteList[id];
464  if ( note )
465  return note->isModified( app );
466  else
467  return false;
468 }
469 
470 
471 // ------------------- protected methods ------------------- //
472 
473 void KNotesApp::mousePressEvent( TQMouseEvent* e )
474 {
475  if ( !rect().contains( e->pos() ) )
476  return;
477 
478  switch ( e->button() )
479  {
480  case Qt::LeftButton:
481  if ( m_noteList.count() == 1 )
482  {
483  TQDictIterator<KNote> it( m_noteList );
484  showNote( it.toFirst() );
485  }
486  else if ( m_note_menu->count() > 0 )
487  m_note_menu->popup( e->globalPos() );
488  break;
489  case Qt::MidButton:
490  newNote();
491  break;
492  case Qt::RightButton:
493  m_context_menu->popup( e->globalPos() );
494  default: break;
495  }
496 }
497 
498 // -------------------- protected slots -------------------- //
499 
500 void KNotesApp::slotShowNote()
501 {
502  // tell the WM to give this note focus
503  showNote( TQString::fromUtf8( TQT_TQOBJECT(const_cast<TQT_BASE_OBJECT_NAME*>(sender()))->name() ) );
504 }
505 
506 void KNotesApp::slotWalkThroughNotes()
507 {
508  // show next note
509  TQDictIterator<KNote> it( m_noteList );
510  KNote *first = it.toFirst();
511  for ( ; *it; ++it )
512  if ( (*it)->hasFocus() )
513  {
514  if ( ++it )
515  showNote( *it );
516  else
517  showNote( first );
518  break;
519  }
520 }
521 
522 void KNotesApp::slotOpenFindDialog()
523 {
524  KFindDialog findDia( this, "find_dialog" );
525  findDia.setHasSelection( false );
526  findDia.setHasCursor( false );
527  findDia.setSupportsBackwardsFind( false );
528 
529  if ( (findDia.exec() != TQDialog::Accepted) || findDia.pattern().isEmpty() )
530  return;
531 
532  delete m_findPos;
533  m_findPos = new TQDictIterator<KNote>( m_noteList );
534 
535  // this could be in an own method if searching without a dialog should be possible
536  delete m_find;
537  m_find = new KFind( findDia.pattern(), findDia.options(), this );
538 
539  slotFindNext();
540 }
541 
542 void KNotesApp::slotFindNext()
543 {
544  if ( **m_findPos )
545  {
546  KNote *note = **m_findPos;
547  ++*m_findPos;
548  note->find( m_find->pattern(), m_find->options() );
549  }
550  else
551  {
552  m_find->displayFinalDialog();
553  delete m_find;
554  m_find = 0;
555  delete m_findPos;
556  m_findPos = 0;
557  }
558 }
559 
560 void KNotesApp::slotPreferences()
561 {
562  // reuse the dialog if possible
563  if ( KNoteConfigDlg::showDialog( "KNotes Default Settings" ) )
564  return;
565 
566  // create a new preferences dialog...
567  KNoteConfigDlg *dialog = new KNoteConfigDlg( 0, i18n("Settings"), this,
568  "KNotes Settings" );
569  connect( dialog, TQT_SIGNAL(settingsChanged()), TQT_TQOBJECT(this), TQT_SLOT(updateNetworkListener()) );
570  connect( dialog, TQT_SIGNAL(settingsChanged()), TQT_TQOBJECT(this), TQT_SLOT(updateStyle()) );
571  dialog->show();
572 }
573 
574 void KNotesApp::slotConfigureAccels()
575 {
576  KNotesKeyDialog keys( m_globalAccel, this );
577  TQDictIterator<KNote> notes( m_noteList );
578  if ( !m_noteList.isEmpty() )
579  keys.insert( (*notes)->actionCollection() );
580  keys.configure();
581 
582  m_globalAccel->writeSettings();
583  updateGlobalAccels();
584 
585  // update GUI doc for new notes
586  m_noteGUI.setContent(
587  KXMLGUIFactory::readConfigFile( instance()->instanceName() + "ui.rc", instance() )
588  );
589 
590  if ( m_noteList.isEmpty() )
591  return;
592 
593  notes.toFirst();
594  TQValueList<TDEAction *> list = (*notes)->actionCollection()->actions();
595  for ( TQValueList<TDEAction *>::iterator it = list.begin(); it != list.end(); ++it )
596  {
597  notes.toFirst();
598  for ( ++notes; *notes; ++notes )
599  {
600  TDEAction *toChange = (*notes)->actionCollection()->action( (*it)->name() );
601  if ( toChange->shortcut() != (*it)->shortcut() )
602  toChange->setShortcut( (*it)->shortcut() );
603  }
604  }
605 }
606 
607 void KNotesApp::slotNoteKilled( KCal::Journal *journal )
608 {
609  m_noteUidModify="";
610  m_manager->deleteNote( journal );
611  saveNotes();
612 }
613 
614 void KNotesApp::slotQuit()
615 {
616  TQDictIterator<KNote> it( m_noteList );
617 
618  for ( ; *it; ++it )
619  if ( (*it)->isModified() )
620  (*it)->saveData(false);
621 
622  saveConfigs();
623  kapp->quit();
624 }
625 
626 
627 // -------------------- private methods -------------------- //
628 
629 void KNotesApp::showNote( KNote* note ) const
630 {
631  note->show();
632  KWin::setCurrentDesktop( KWin::windowInfo( note->winId() ).desktop() );
633  KWin::forceActiveWindow( note->winId() );
634  note->setFocus();
635 }
636 
637 void KNotesApp::createNote( KCal::Journal *journal )
638 {
639  if( journal->uid() == m_noteUidModify)
640  {
641  KNote *note = m_noteList[m_noteUidModify];
642  if ( note )
643  note->changeJournal(journal);
644 
645  return;
646  }
647  m_noteUidModify = journal->uid();
648  KNote *newNote = new KNote( m_noteGUI, journal, 0, journal->uid().utf8() );
649  m_noteList.insert( newNote->noteId(), newNote );
650 
651  connect( newNote, TQT_SIGNAL(sigRequestNewNote()), TQT_SLOT(newNote()) );
652  connect( newNote, TQT_SIGNAL(sigShowNextNote()), TQT_SLOT(slotWalkThroughNotes()) );
653  connect( newNote, TQT_SIGNAL(sigKillNote( KCal::Journal* )),
654  TQT_SLOT(slotNoteKilled( KCal::Journal* )) );
655  connect( newNote, TQT_SIGNAL(sigNameChanged()), TQT_SLOT(updateNoteActions()) );
656  connect( newNote, TQT_SIGNAL(sigDataChanged(const TQString &)), TQT_SLOT(saveNotes(const TQString &)) );
657  connect( newNote, TQT_SIGNAL(sigColorChanged()), TQT_SLOT(updateNoteActions()) );
658  connect( newNote, TQT_SIGNAL(sigFindFinished()), TQT_SLOT(slotFindNext()) );
659 
660  // don't call this during startup for each and every loaded note
661  if ( m_alarm )
662  updateNoteActions();
663 }
664 
665 void KNotesApp::killNote( KCal::Journal *journal )
666 {
667  if(m_noteUidModify == journal->uid())
668  {
669  return;
670  }
671  // this kills the KNote object
672  KNote *note = m_noteList.take( journal->uid() );
673  if ( note )
674  {
675  note->deleteWhenIdle();
676  updateNoteActions();
677  }
678 }
679 
680 void KNotesApp::acceptConnection()
681 {
682  // Accept the connection and make KNotesNetworkReceiver do the job
683  TDEBufferedSocket *s = static_cast<TDEBufferedSocket *>(m_listener->accept());
684  if ( s )
685  {
686  KNotesNetworkReceiver *recv = new KNotesNetworkReceiver( s );
687  connect( recv, TQT_SIGNAL(sigNoteReceived( const TQString &, const TQString & )),
688  TQT_TQOBJECT(this), TQT_SLOT(newNote( const TQString &, const TQString & )) );
689  }
690 }
691 
692 void KNotesApp::saveNotes( const TQString & uid )
693 {
694  m_noteUidModify = uid;
695  saveNotes();
696 }
697 
698 void KNotesApp::saveNotes()
699 {
700  KNotesGlobalConfig::writeConfig();
701  m_manager->save();
702 }
703 
704 void KNotesApp::saveConfigs()
705 {
706  TQDictIterator<KNote> it( m_noteList );
707  for ( ; it.current(); ++it )
708  it.current()->saveConfig();
709 }
710 
711 void KNotesApp::updateNoteActions()
712 {
713  unplugActionList( "notes" );
714  m_noteActions.clear();
715 
716  for ( TQDictIterator<KNote> it( m_noteList ); it.current(); ++it )
717  {
718  TDEAction *action = new TDEAction( it.current()->name().replace("&", "&&"),
719  TDEShortcut(), TQT_TQOBJECT(this), TQT_SLOT(slotShowNote()),
720  (TQObject *)0,
721  it.current()->noteId().utf8() );
722  TDEIconEffect effect;
723  TQPixmap icon = effect.apply( kapp->miniIcon(), TDEIconEffect::Colorize, 1,
724  it.current()->paletteBackgroundColor(), false );
725  action->setIconSet( icon );
726  m_noteActions.append( action );
727  }
728 
729  if ( m_noteActions.isEmpty() )
730  {
731  actionCollection()->action( "hide_all_notes" )->setEnabled( false );
732  actionCollection()->action( "show_all_notes" )->setEnabled( false );
733  m_findAction->setEnabled( false );
734  TDEAction *action = new TDEAction( i18n("No Notes") );
735  m_noteActions.append( action );
736  }
737  else
738  {
739  actionCollection()->action( "hide_all_notes" )->setEnabled( true );
740  actionCollection()->action( "show_all_notes" )->setEnabled( true );
741  m_findAction->setEnabled( true );
742  m_noteActions.sort();
743  }
744  plugActionList( "notes", m_noteActions );
745 }
746 
747 void KNotesApp::updateGlobalAccels()
748 {
749  if ( m_globalAccel->isEnabled() )
750  {
751  TDEAction *action = actionCollection()->action( "new_note" );
752  if ( action )
753  action->setShortcut( m_globalAccel->shortcut( "global_new_note" ) );
754  action = actionCollection()->action( "new_note_clipboard" );
755  if ( action )
756  action->setShortcut( m_globalAccel->shortcut( "global_new_note_clipboard" ) );
757  action = actionCollection()->action( "hide_all_notes" );
758  if ( action )
759  action->setShortcut( m_globalAccel->shortcut( "global_hide_all_notes" ) );
760  action = actionCollection()->action( "show_all_notes" );
761  if ( action )
762  action->setShortcut( m_globalAccel->shortcut( "global_show_all_notes" ) );
763 
764  m_globalAccel->updateConnections();
765  }
766  else
767  {
768  TDEAction *action = actionCollection()->action( "new_note" );
769  if ( action )
770  action->setShortcut( 0 );
771  action = actionCollection()->action( "new_note_clipboard" );
772  if ( action )
773  action->setShortcut( 0 );
774  action = actionCollection()->action( "hide_all_notes" );
775  if ( action )
776  action->setShortcut( 0 );
777  action = actionCollection()->action( "show_all_notes" );
778  if ( action )
779  action->setShortcut( 0 );
780  }
781 }
782 
783 void KNotesApp::updateNetworkListener()
784 {
785  m_listener->close();
786 
787  if ( KNotesGlobalConfig::receiveNotes() )
788  {
789  m_listener->setAddress( TQString::number( KNotesGlobalConfig::port() ) );
790  m_listener->bind();
791  m_listener->listen();
792  }
793 }
794 
795 void KNotesApp::updateStyle()
796 {
797  KNote::setStyle( KNotesGlobalConfig::style() );
798 
799  TQDictIterator<KNote> it( m_noteList );
800  for ( ; it.current(); ++it )
801  TQApplication::postEvent( *it, new TQEvent( TQEvent::LayoutHint ) );
802 }
803 
804 #include "knotesapp.moc"