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 <kaction.h>
27 #include <kxmlguifactory.h>
28 #include <kxmlguibuilder.h>
29 #include <ksystemtray.h>
30 #include <klocale.h>
31 #include <kiconeffect.h>
32 #include <kstandarddirs.h>
33 #include <kpopupmenu.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 <kwin.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( KGlobalAccel *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( KActionCollection *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 ( ((KAction*)s1)->text() == ((KAction*)s2)->text() )
90  return 0;
91  return ( ((KAction*)s1)->text() < ((KAction*)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(), qt_xrootwin() );
106  TQToolTip::add( this, i18n( "KNotes: Sticky notes for KDE" ) );
107  setBackgroundMode( X11ParentRelative );
108  setPixmap( KSystemTray::loadSizedIcon( "knotes", TQWidget::width() ) );
109 
110  // set the initial style
111  KNote::setStyle( KNotesGlobalConfig::style() );
112 
113  // create the GUI...
114  new KAction( i18n("New Note"), "filenew", 0,
115  TQT_TQOBJECT(this), TQT_SLOT(newNote()), actionCollection(), "new_note" );
116  new KAction( i18n("New Note From Clipboard"), "editpaste", 0,
117  TQT_TQOBJECT(this), TQT_SLOT(newNoteFromClipboard()), actionCollection(), "new_note_clipboard" );
118  new KAction( i18n("Show All Notes"), "knotes", 0,
119  TQT_TQOBJECT(this), TQT_SLOT(showAllNotes()), actionCollection(), "show_all_notes" );
120  new KAction( i18n("Hide All Notes"), "fileclose", 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<KPopupMenu*>(m_guiFactory->container( "knotes_context", this ));
137  m_note_menu = static_cast<KPopupMenu*>(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 KGlobalAccel( TQT_TQOBJECT(this), "global accel" );
151  m_globalAccel->insert( "global_new_note", i18n("New Note"), "",
152  ALT+SHIFT+Key_N, ALT+SHIFT+Key_N ,
153  TQT_TQOBJECT(this), TQT_SLOT(newNote()), true, true );
154  m_globalAccel->insert( "global_new_note_clipboard", i18n("New Note From Clipboard"), "",
155  ALT+SHIFT+Key_C, ALT+SHIFT+Key_C,
156  TQT_TQOBJECT(this), TQT_SLOT(newNoteFromClipboard()), true, true );
157  m_globalAccel->insert( "global_hide_all_notes", i18n("Hide All Notes"), "",
158  ALT+SHIFT+Key_H, ALT+SHIFT+Key_H ,
159  TQT_TQOBJECT(this), TQT_SLOT(hideAllNotes()), true, true );
160  m_globalAccel->insert( "global_show_all_notes", i18n("Show All Notes"), "",
161  ALT+SHIFT+Key_S, ALT+SHIFT+Key_S,
162  TQT_TQOBJECT(this), TQT_SLOT(showAllNotes()), true, true );
163 
164  m_globalAccel->readSettings();
165 
166  KConfig *config = KGlobal::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 KServerSocket();
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::resizeEvent ( TQResizeEvent * )
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 KNotesApp::~KNotesApp()
227 {
228  saveNotes();
229 
230  blockSignals( true );
231  m_noteList.clear();
232  blockSignals( false );
233 
234  delete m_listener;
235  delete m_manager;
236  delete m_guiBuilder;
237 }
238 
239 bool KNotesApp::commitData( TQSessionManager& )
240 {
241  saveConfigs();
242  return true;
243 }
244 
245 // -------------------- public DCOP interface -------------------- //
246 
247 TQString KNotesApp::newNote( const TQString& name, const TQString& text )
248 {
249  // create the new note
250  KCal::Journal *journal = new KCal::Journal();
251 
252  // new notes have the current date/time as title if none was given
253  if ( !name.isEmpty() )
254  journal->setSummary( name );
255  else
256  journal->setSummary( KGlobal::locale()->formatDateTime( TQDateTime::currentDateTime() ) );
257 
258  // the body of the note
259  journal->setDescription( text );
260 
261  if ( m_manager->addNewNote( journal ) ) {
262  showNote( journal->uid() );
263  }
264  return journal->uid();
265 }
266 
267 TQString KNotesApp::newNoteFromClipboard( const TQString& name )
268 {
269  const TQString& text = KApplication::clipboard()->text();
270  return newNote( name, text );
271 }
272 
273 void KNotesApp::hideAllNotes() const
274 {
275  TQDictIterator<KNote> it( m_noteList );
276  for ( ; *it; ++it )
277  (*it)->close();
278 }
279 
280 void KNotesApp::showAllNotes() const
281 {
282  TQDictIterator<KNote> it( m_noteList );
283  for ( ; *it; ++it )
284  {
285  (*it)->show();
286  }
287 }
288 
289 void KNotesApp::showNote( const TQString& id ) const
290 {
291  KNote* note = m_noteList[id];
292  if ( note )
293  showNote( note );
294  else
295  kdWarning(5500) << "showNote: no note with id: " << id << endl;
296 }
297 
298 void KNotesApp::hideNote( const TQString& id ) const
299 {
300  KNote* note = m_noteList[id];
301  if ( note )
302  note->hide();
303  else
304  kdWarning(5500) << "hideNote: no note with id: " << id << endl;
305 }
306 
307 void KNotesApp::killNote( const TQString& id, bool force )
308 {
309  KNote* note = m_noteList[id];
310  if ( note )
311  note->slotKill( force );
312  else
313  kdWarning(5500) << "killNote: no note with id: " << id << endl;
314 }
315 
316 // "bool force = false" doesn't work with dcop
317 void KNotesApp::killNote( const TQString& id )
318 {
319  killNote( id, false );
320 }
321 
322 TQMap<TQString,TQString> KNotesApp::notes() const
323 {
324  TQMap<TQString,TQString> notes;
325  TQDictIterator<KNote> it( m_noteList );
326 
327  for ( ; it.current(); ++it )
328  notes.insert( it.current()->noteId(), it.current()->name() );
329 
330  return notes;
331 }
332 
333 TQString KNotesApp::name( const TQString& id ) const
334 {
335  KNote* note = m_noteList[id];
336  if ( note )
337  return note->name();
338  else
339  return TQString();
340 }
341 
342 TQString KNotesApp::text( const TQString& id ) const
343 {
344  KNote* note = m_noteList[id];
345  if ( note )
346  return note->text();
347  else
348  return TQString();
349 }
350 
351 void KNotesApp::setName( const TQString& id, const TQString& newName )
352 {
353  KNote* note = m_noteList[id];
354  if ( note )
355  note->setName( newName );
356  else
357  kdWarning(5500) << "setName: no note with id: " << id << endl;
358 }
359 
360 void KNotesApp::setText( const TQString& id, const TQString& newText )
361 {
362  KNote* note = m_noteList[id];
363  if ( note )
364  note->setText( newText );
365  else
366  kdWarning(5500) << "setText: no note with id: " << id << endl;
367 }
368 
369 TQString KNotesApp::fgColor( const TQString& id ) const
370 {
371  KNote* note = m_noteList[id];
372  if ( note )
373  return note->fgColor().name();
374  else
375  return TQString();
376 }
377 
378 TQString KNotesApp::bgColor( const TQString& id ) const
379 {
380  KNote* note = m_noteList[id];
381  if ( note )
382  return note->bgColor().name();
383  else
384  return TQString();
385 }
386 
387 void KNotesApp::setColor( const TQString& id, const TQString& fgColor, const TQString& bgColor )
388 {
389  KNote* note = m_noteList[id];
390  if ( note )
391  note->setColor( TQColor( fgColor ), TQColor( bgColor ) );
392  else
393  kdWarning(5500) << "setColor: no note with id: " << id << endl;
394 }
395 
396 int KNotesApp::width( const TQString& id ) const
397 {
398  KNote* note = m_noteList[id];
399  if ( note )
400  return note->width();
401  else
402  return 0;
403 }
404 
405 int KNotesApp::height( const TQString& id ) const
406 {
407  KNote* note = m_noteList[id];
408  if ( note )
409  return note->height();
410  else
411  return 0;
412 }
413 
414 void KNotesApp::move( const TQString& id, int x, int y ) const
415 {
416  KNote* note = m_noteList[id];
417  if ( note )
418  return note->move( x, y );
419  else
420  kdWarning(5500) << "move: no note with id: " << id << endl;
421 }
422 
423 void KNotesApp::resize( const TQString& id, int width, int height ) const
424 {
425  KNote* note = m_noteList[id];
426  if ( note )
427  return note->resize( width, height );
428  else
429  kdWarning(5500) << "resize: no note with id: " << id << endl;
430 }
431 
432 void KNotesApp::sync( const TQString& app )
433 {
434  TQDictIterator<KNote> it( m_noteList );
435 
436  for ( ; it.current(); ++it )
437  it.current()->sync( app );
438 }
439 
440 bool KNotesApp::isNew( const TQString& app, const TQString& id ) const
441 {
442  KNote* note = m_noteList[id];
443  if ( note )
444  return note->isNew( app );
445  else
446  return false;
447 }
448 
449 bool KNotesApp::isModified( const TQString& app, const TQString& id ) const
450 {
451  KNote* note = m_noteList[id];
452  if ( note )
453  return note->isModified( app );
454  else
455  return false;
456 }
457 
458 
459 // ------------------- protected methods ------------------- //
460 
461 void KNotesApp::mousePressEvent( TQMouseEvent* e )
462 {
463  if ( !rect().contains( e->pos() ) )
464  return;
465 
466  switch ( e->button() )
467  {
468  case Qt::LeftButton:
469  if ( m_noteList.count() == 1 )
470  {
471  TQDictIterator<KNote> it( m_noteList );
472  showNote( it.toFirst() );
473  }
474  else if ( m_note_menu->count() > 0 )
475  m_note_menu->popup( e->globalPos() );
476  break;
477  case Qt::MidButton:
478  newNote();
479  break;
480  case Qt::RightButton:
481  m_context_menu->popup( e->globalPos() );
482  default: break;
483  }
484 }
485 
486 // -------------------- protected slots -------------------- //
487 
488 void KNotesApp::slotShowNote()
489 {
490  // tell the WM to give this note focus
491  showNote( TQString::fromUtf8( TQT_TQOBJECT(const_cast<TQT_BASE_OBJECT_NAME*>(sender()))->name() ) );
492 }
493 
494 void KNotesApp::slotWalkThroughNotes()
495 {
496  // show next note
497  TQDictIterator<KNote> it( m_noteList );
498  KNote *first = it.toFirst();
499  for ( ; *it; ++it )
500  if ( (*it)->hasFocus() )
501  {
502  if ( ++it )
503  showNote( *it );
504  else
505  showNote( first );
506  break;
507  }
508 }
509 
510 void KNotesApp::slotOpenFindDialog()
511 {
512  KFindDialog findDia( this, "find_dialog" );
513  findDia.setHasSelection( false );
514  findDia.setHasCursor( false );
515  findDia.setSupportsBackwardsFind( false );
516 
517  if ( (findDia.exec() != TQDialog::Accepted) || findDia.pattern().isEmpty() )
518  return;
519 
520  delete m_findPos;
521  m_findPos = new TQDictIterator<KNote>( m_noteList );
522 
523  // this could be in an own method if searching without a dialog should be possible
524  delete m_find;
525  m_find = new KFind( findDia.pattern(), findDia.options(), this );
526 
527  slotFindNext();
528 }
529 
530 void KNotesApp::slotFindNext()
531 {
532  if ( **m_findPos )
533  {
534  KNote *note = **m_findPos;
535  ++*m_findPos;
536  note->find( m_find->pattern(), m_find->options() );
537  }
538  else
539  {
540  m_find->displayFinalDialog();
541  delete m_find;
542  m_find = 0;
543  delete m_findPos;
544  m_findPos = 0;
545  }
546 }
547 
548 void KNotesApp::slotPreferences()
549 {
550  // reuse the dialog if possible
551  if ( KNoteConfigDlg::showDialog( "KNotes Default Settings" ) )
552  return;
553 
554  // create a new preferences dialog...
555  KNoteConfigDlg *dialog = new KNoteConfigDlg( 0, i18n("Settings"), this,
556  "KNotes Settings" );
557  connect( dialog, TQT_SIGNAL(settingsChanged()), TQT_TQOBJECT(this), TQT_SLOT(updateNetworkListener()) );
558  connect( dialog, TQT_SIGNAL(settingsChanged()), TQT_TQOBJECT(this), TQT_SLOT(updateStyle()) );
559  dialog->show();
560 }
561 
562 void KNotesApp::slotConfigureAccels()
563 {
564  KNotesKeyDialog keys( m_globalAccel, this );
565  TQDictIterator<KNote> notes( m_noteList );
566  if ( !m_noteList.isEmpty() )
567  keys.insert( (*notes)->actionCollection() );
568  keys.configure();
569 
570  m_globalAccel->writeSettings();
571  updateGlobalAccels();
572 
573  // update GUI doc for new notes
574  m_noteGUI.setContent(
575  KXMLGUIFactory::readConfigFile( instance()->instanceName() + "ui.rc", instance() )
576  );
577 
578  if ( m_noteList.isEmpty() )
579  return;
580 
581  notes.toFirst();
582  TQValueList<KAction *> list = (*notes)->actionCollection()->actions();
583  for ( TQValueList<KAction *>::iterator it = list.begin(); it != list.end(); ++it )
584  {
585  notes.toFirst();
586  for ( ++notes; *notes; ++notes )
587  {
588  KAction *toChange = (*notes)->actionCollection()->action( (*it)->name() );
589  if ( toChange->shortcut() != (*it)->shortcut() )
590  toChange->setShortcut( (*it)->shortcut() );
591  }
592  }
593 }
594 
595 void KNotesApp::slotNoteKilled( KCal::Journal *journal )
596 {
597  m_noteUidModify="";
598  m_manager->deleteNote( journal );
599  saveNotes();
600 }
601 
602 void KNotesApp::slotQuit()
603 {
604  TQDictIterator<KNote> it( m_noteList );
605 
606  for ( ; *it; ++it )
607  if ( (*it)->isModified() )
608  (*it)->saveData(false);
609 
610  saveConfigs();
611  kapp->quit();
612 }
613 
614 
615 // -------------------- private methods -------------------- //
616 
617 void KNotesApp::showNote( KNote* note ) const
618 {
619  note->show();
620  KWin::setCurrentDesktop( KWin::windowInfo( note->winId() ).desktop() );
621  KWin::forceActiveWindow( note->winId() );
622  note->setFocus();
623 }
624 
625 void KNotesApp::createNote( KCal::Journal *journal )
626 {
627  if( journal->uid() == m_noteUidModify)
628  {
629  KNote *note = m_noteList[m_noteUidModify];
630  if ( note )
631  note->changeJournal(journal);
632 
633  return;
634  }
635  m_noteUidModify = journal->uid();
636  KNote *newNote = new KNote( m_noteGUI, journal, 0, journal->uid().utf8() );
637  m_noteList.insert( newNote->noteId(), newNote );
638 
639  connect( newNote, TQT_SIGNAL(sigRequestNewNote()), TQT_SLOT(newNote()) );
640  connect( newNote, TQT_SIGNAL(sigShowNextNote()), TQT_SLOT(slotWalkThroughNotes()) );
641  connect( newNote, TQT_SIGNAL(sigKillNote( KCal::Journal* )),
642  TQT_SLOT(slotNoteKilled( KCal::Journal* )) );
643  connect( newNote, TQT_SIGNAL(sigNameChanged()), TQT_SLOT(updateNoteActions()) );
644  connect( newNote, TQT_SIGNAL(sigDataChanged(const TQString &)), TQT_SLOT(saveNotes(const TQString &)) );
645  connect( newNote, TQT_SIGNAL(sigColorChanged()), TQT_SLOT(updateNoteActions()) );
646  connect( newNote, TQT_SIGNAL(sigFindFinished()), TQT_SLOT(slotFindNext()) );
647 
648  // don't call this during startup for each and every loaded note
649  if ( m_alarm )
650  updateNoteActions();
651 }
652 
653 void KNotesApp::killNote( KCal::Journal *journal )
654 {
655  if(m_noteUidModify == journal->uid())
656  {
657  return;
658  }
659  // this kills the KNote object
660  KNote *note = m_noteList.take( journal->uid() );
661  if ( note )
662  {
663  note->deleteWhenIdle();
664  updateNoteActions();
665  }
666 }
667 
668 void KNotesApp::acceptConnection()
669 {
670  // Accept the connection and make KNotesNetworkReceiver do the job
671  KBufferedSocket *s = static_cast<KBufferedSocket *>(m_listener->accept());
672  if ( s )
673  {
674  KNotesNetworkReceiver *recv = new KNotesNetworkReceiver( s );
675  connect( recv, TQT_SIGNAL(sigNoteReceived( const TQString &, const TQString & )),
676  TQT_TQOBJECT(this), TQT_SLOT(newNote( const TQString &, const TQString & )) );
677  }
678 }
679 
680 void KNotesApp::saveNotes( const TQString & uid )
681 {
682  m_noteUidModify = uid;
683  saveNotes();
684 }
685 
686 void KNotesApp::saveNotes()
687 {
688  KNotesGlobalConfig::writeConfig();
689  m_manager->save();
690 }
691 
692 void KNotesApp::saveConfigs()
693 {
694  TQDictIterator<KNote> it( m_noteList );
695  for ( ; it.current(); ++it )
696  it.current()->saveConfig();
697 }
698 
699 void KNotesApp::updateNoteActions()
700 {
701  unplugActionList( "notes" );
702  m_noteActions.clear();
703 
704  for ( TQDictIterator<KNote> it( m_noteList ); it.current(); ++it )
705  {
706  KAction *action = new KAction( it.current()->name().replace("&", "&&"),
707  KShortcut(), TQT_TQOBJECT(this), TQT_SLOT(slotShowNote()),
708  (TQObject *)0,
709  it.current()->noteId().utf8() );
710  KIconEffect effect;
711  TQPixmap icon = effect.apply( kapp->miniIcon(), KIconEffect::Colorize, 1,
712  it.current()->paletteBackgroundColor(), false );
713  action->setIconSet( icon );
714  m_noteActions.append( action );
715  }
716 
717  if ( m_noteActions.isEmpty() )
718  {
719  actionCollection()->action( "hide_all_notes" )->setEnabled( false );
720  actionCollection()->action( "show_all_notes" )->setEnabled( false );
721  m_findAction->setEnabled( false );
722  KAction *action = new KAction( i18n("No Notes") );
723  m_noteActions.append( action );
724  }
725  else
726  {
727  actionCollection()->action( "hide_all_notes" )->setEnabled( true );
728  actionCollection()->action( "show_all_notes" )->setEnabled( true );
729  m_findAction->setEnabled( true );
730  m_noteActions.sort();
731  }
732  plugActionList( "notes", m_noteActions );
733 }
734 
735 void KNotesApp::updateGlobalAccels()
736 {
737  if ( m_globalAccel->isEnabled() )
738  {
739  KAction *action = actionCollection()->action( "new_note" );
740  if ( action )
741  action->setShortcut( m_globalAccel->shortcut( "global_new_note" ) );
742  action = actionCollection()->action( "new_note_clipboard" );
743  if ( action )
744  action->setShortcut( m_globalAccel->shortcut( "global_new_note_clipboard" ) );
745  action = actionCollection()->action( "hide_all_notes" );
746  if ( action )
747  action->setShortcut( m_globalAccel->shortcut( "global_hide_all_notes" ) );
748  action = actionCollection()->action( "show_all_notes" );
749  if ( action )
750  action->setShortcut( m_globalAccel->shortcut( "global_show_all_notes" ) );
751 
752  m_globalAccel->updateConnections();
753  }
754  else
755  {
756  KAction *action = actionCollection()->action( "new_note" );
757  if ( action )
758  action->setShortcut( 0 );
759  action = actionCollection()->action( "new_note_clipboard" );
760  if ( action )
761  action->setShortcut( 0 );
762  action = actionCollection()->action( "hide_all_notes" );
763  if ( action )
764  action->setShortcut( 0 );
765  action = actionCollection()->action( "show_all_notes" );
766  if ( action )
767  action->setShortcut( 0 );
768  }
769 }
770 
771 void KNotesApp::updateNetworkListener()
772 {
773  m_listener->close();
774 
775  if ( KNotesGlobalConfig::receiveNotes() )
776  {
777  m_listener->setAddress( TQString::number( KNotesGlobalConfig::port() ) );
778  m_listener->bind();
779  m_listener->listen();
780  }
781 }
782 
783 void KNotesApp::updateStyle()
784 {
785  KNote::setStyle( KNotesGlobalConfig::style() );
786 
787  TQDictIterator<KNote> it( m_noteList );
788  for ( ; it.current(); ++it )
789  TQApplication::postEvent( *it, new TQEvent( TQEvent::LayoutHint ) );
790 }
791 
792 #include "knotesapp.moc"