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 <tdestandarddirs.h>
33#include <tdepopupmenu.h>
34#include <khelpmenu.h>
35#include <kfind.h>
36#include <kfinddialog.h>
37#include <kkeydialog.h>
38#include <tdeglobalaccel.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
57using namespace KNetwork;
58
59
60class KNotesKeyDialog : public KDialogBase
61{
62public:
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, TQ_SIGNAL(defaultClicked()), m_keyChooser, TQ_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
82private:
83 KKeyChooser *m_keyChooser;
84};
85
86
87int 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
95KNotesApp::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( tdeApp, TQ_SIGNAL(lastWindowClosed()), tdeApp, TQ_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 this, TQ_SLOT(newNote()), actionCollection(), "new_note" );
116 new TDEAction( i18n("New Note From Clipboard"), "edit-paste", 0,
117 this, TQ_SLOT(newNoteFromClipboard()), actionCollection(), "new_note_clipboard" );
118 new TDEAction( i18n("Show All Notes"), "knotes", 0,
119 this, TQ_SLOT(showAllNotes()), actionCollection(), "show_all_notes" );
120 new TDEAction( i18n("Hide All Notes"), "window-close", 0,
121 this, TQ_SLOT(hideAllNotes()), actionCollection(), "hide_all_notes" );
122 new KHelpMenu( this, tdeApp->aboutData(), false, actionCollection() );
123
124 m_findAction = KStdAction::find( this, TQ_SLOT(slotOpenFindDialog()), actionCollection() );
125 KStdAction::preferences( this, TQ_SLOT(slotPreferences()), actionCollection() );
126 KStdAction::keyBindings( this, TQ_SLOT(slotConfigureAccels()), actionCollection() );
127 //FIXME: no shortcut removing!?
128 KStdAction::quit( this, TQ_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, 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( this, "global accel" );
151 m_globalAccel->insert( "global_new_note", i18n("New Note"), "",
152 TDEShortcut(), TDEShortcut(),
153 this, TQ_SLOT(newNote()), true, true );
154 m_globalAccel->insert( "global_new_note_clipboard", i18n("New Note From Clipboard"), "",
155 TDEShortcut(), TDEShortcut(),
156 this, TQ_SLOT(newNoteFromClipboard()), true, true );
157 m_globalAccel->insert( "global_hide_all_notes", i18n("Hide All Notes"), "",
158 TDEShortcut(), TDEShortcut(),
159 this, TQ_SLOT(hideAllNotes()), true, true );
160 m_globalAccel->insert( "global_show_all_notes", i18n("Show All Notes"), "",
161 TDEShortcut(), TDEShortcut(),
162 this, TQ_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, TQ_SIGNAL(sigRegisteredNote( KCal::Journal * )),
178 this, TQ_SLOT(createNote( KCal::Journal * )) );
179 connect( m_manager, TQ_SIGNAL(sigDeregisteredNote( KCal::Journal * )),
180 this, TQ_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, 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, TQ_SIGNAL(readyAccept()), TQ_SLOT(acceptConnection()) );
205 updateNetworkListener();
206
207 if ( m_noteList.count() == 0 && !tdeApp->isRestored() )
208 newNote();
209
210 updateNoteActions();
211}
212
213void 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
226void KNotesApp::resizeEvent ( TQResizeEvent * )
227{
228 // Honor Free Desktop specifications that allow for arbitrary system tray icon sizes
229 resizeTrayIcon();
230}
231
232void KNotesApp::showEvent ( TQShowEvent * )
233{
234 // Honor Free Desktop specifications that allow for arbitrary system tray icon sizes
235 resizeTrayIcon();
236}
237
238KNotesApp::~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
251bool KNotesApp::commitData( TQSessionManager& )
252{
253 saveConfigs();
254 return true;
255}
256
257// -------------------- public DCOP interface -------------------- //
258
259TQString 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
279TQString KNotesApp::newNoteFromClipboard( const TQString& name )
280{
281 const TQString& text = TDEApplication::clipboard()->text();
282 return newNote( name, text );
283}
284
285void KNotesApp::hideAllNotes() const
286{
287 TQDictIterator<KNote> it( m_noteList );
288 for ( ; *it; ++it )
289 (*it)->close();
290}
291
292void KNotesApp::showAllNotes() const
293{
294 TQDictIterator<KNote> it( m_noteList );
295 for ( ; *it; ++it )
296 {
297 (*it)->show();
298 }
299}
300
301void 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
310void 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
319void 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
329void KNotesApp::killNote( const TQString& id )
330{
331 killNote( id, false );
332}
333
334TQMap<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
345TQDateTime KNotesApp::getLastModified( const TQString& id ) const
346{
347 KNote* note = m_noteList[id];
348 TQDateTime d;
349 if ( note )
350 d = note->getLastModified();
351 return d;
352}
353
354TQString KNotesApp::name( const TQString& id ) const
355{
356 KNote* note = m_noteList[id];
357 if ( note )
358 return note->name();
359 else
360 return TQString();
361}
362
363TQString KNotesApp::text( const TQString& id ) const
364{
365 KNote* note = m_noteList[id];
366 if ( note )
367 return note->text();
368 else
369 return TQString();
370}
371
372void KNotesApp::setName( const TQString& id, const TQString& newName )
373{
374 KNote* note = m_noteList[id];
375 if ( note )
376 note->setName( newName );
377 else
378 kdWarning(5500) << "setName: no note with id: " << id << endl;
379}
380
381void KNotesApp::setText( const TQString& id, const TQString& newText )
382{
383 KNote* note = m_noteList[id];
384 if ( note )
385 note->setText( newText );
386 else
387 kdWarning(5500) << "setText: no note with id: " << id << endl;
388}
389
390TQString KNotesApp::fgColor( const TQString& id ) const
391{
392 KNote* note = m_noteList[id];
393 if ( note )
394 return note->fgColor().name();
395 else
396 return TQString();
397}
398
399TQString KNotesApp::bgColor( const TQString& id ) const
400{
401 KNote* note = m_noteList[id];
402 if ( note )
403 return note->bgColor().name();
404 else
405 return TQString();
406}
407
408void KNotesApp::setColor( const TQString& id, const TQString& fgColor, const TQString& bgColor )
409{
410 KNote* note = m_noteList[id];
411 if ( note )
412 note->setColor( TQColor( fgColor ), TQColor( bgColor ) );
413 else
414 kdWarning(5500) << "setColor: no note with id: " << id << endl;
415}
416
417int KNotesApp::width( const TQString& id ) const
418{
419 KNote* note = m_noteList[id];
420 if ( note )
421 return note->width();
422 else
423 return 0;
424}
425
426int KNotesApp::height( const TQString& id ) const
427{
428 KNote* note = m_noteList[id];
429 if ( note )
430 return note->height();
431 else
432 return 0;
433}
434
435void KNotesApp::move( const TQString& id, int x, int y ) const
436{
437 KNote* note = m_noteList[id];
438 if ( note )
439 return note->move( x, y );
440 else
441 kdWarning(5500) << "move: no note with id: " << id << endl;
442}
443
444void KNotesApp::resize( const TQString& id, int width, int height ) const
445{
446 KNote* note = m_noteList[id];
447 if ( note )
448 return note->resize( width, height );
449 else
450 kdWarning(5500) << "resize: no note with id: " << id << endl;
451}
452
453void KNotesApp::sync( const TQString& app )
454{
455 TQDictIterator<KNote> it( m_noteList );
456
457 for ( ; it.current(); ++it )
458 it.current()->sync( app );
459}
460
461bool KNotesApp::isNew( const TQString& app, const TQString& id ) const
462{
463 KNote* note = m_noteList[id];
464 if ( note )
465 return note->isNew( app );
466 else
467 return false;
468}
469
470bool KNotesApp::isModified( const TQString& app, const TQString& id ) const
471{
472 KNote* note = m_noteList[id];
473 if ( note )
474 return note->isModified( app );
475 else
476 return false;
477}
478
479
480// ------------------- protected methods ------------------- //
481
482void KNotesApp::mousePressEvent( TQMouseEvent* e )
483{
484 if ( !rect().contains( e->pos() ) )
485 return;
486
487 switch ( e->button() )
488 {
489 case TQt::LeftButton:
490 if ( m_noteList.count() == 1 )
491 {
492 TQDictIterator<KNote> it( m_noteList );
493 showNote( it.toFirst() );
494 }
495 else if ( m_note_menu->count() > 0 )
496 m_note_menu->popup( e->globalPos() );
497 break;
498 case TQt::MidButton:
499 newNote();
500 break;
501 case TQt::RightButton:
502 m_context_menu->popup( e->globalPos() );
503 default: break;
504 }
505}
506
507// -------------------- protected slots -------------------- //
508
509void KNotesApp::slotShowNote()
510{
511 // tell the WM to give this note focus
512 showNote( TQString::fromUtf8( sender()->name() ) );
513}
514
515void KNotesApp::slotWalkThroughNotes()
516{
517 // show next note
518 TQDictIterator<KNote> it( m_noteList );
519 KNote *first = it.toFirst();
520 for ( ; *it; ++it )
521 if ( (*it)->hasFocus() )
522 {
523 if ( ++it )
524 showNote( *it );
525 else
526 showNote( first );
527 break;
528 }
529}
530
531void KNotesApp::slotOpenFindDialog()
532{
533 KFindDialog findDia( this, "find_dialog" );
534 findDia.setHasSelection( false );
535 findDia.setHasCursor( false );
536 findDia.setSupportsBackwardsFind( false );
537
538 if ( (findDia.exec() != TQDialog::Accepted) || findDia.pattern().isEmpty() )
539 return;
540
541 delete m_findPos;
542 m_findPos = new TQDictIterator<KNote>( m_noteList );
543
544 // this could be in an own method if searching without a dialog should be possible
545 delete m_find;
546 m_find = new KFind( findDia.pattern(), findDia.options(), this );
547
548 slotFindNext();
549}
550
551void KNotesApp::slotFindNext()
552{
553 if ( **m_findPos )
554 {
555 KNote *note = **m_findPos;
556 ++*m_findPos;
557 note->find( m_find->pattern(), m_find->options() );
558 }
559 else
560 {
561 m_find->displayFinalDialog();
562 delete m_find;
563 m_find = 0;
564 delete m_findPos;
565 m_findPos = 0;
566 }
567}
568
569void KNotesApp::slotPreferences()
570{
571 // reuse the dialog if possible
572 if ( KNoteConfigDlg::showDialog( "KNotes Default Settings" ) )
573 return;
574
575 // create a new preferences dialog...
576 KNoteConfigDlg *dialog = new KNoteConfigDlg( 0, i18n("Settings"), this,
577 "KNotes Settings" );
578 connect( dialog, TQ_SIGNAL(settingsChanged()), this, TQ_SLOT(updateNetworkListener()) );
579 connect( dialog, TQ_SIGNAL(settingsChanged()), this, TQ_SLOT(updateStyle()) );
580 dialog->show();
581}
582
583void KNotesApp::slotConfigureAccels()
584{
585 KNotesKeyDialog keys( m_globalAccel, this );
586 TQDictIterator<KNote> notes( m_noteList );
587 if ( !m_noteList.isEmpty() )
588 keys.insert( (*notes)->actionCollection() );
589 keys.configure();
590
591 m_globalAccel->writeSettings();
592 updateGlobalAccels();
593
594 // update GUI doc for new notes
595 m_noteGUI.setContent(
596 KXMLGUIFactory::readConfigFile( instance()->instanceName() + "ui.rc", instance() )
597 );
598
599 if ( m_noteList.isEmpty() )
600 return;
601
602 notes.toFirst();
603 TQValueList<TDEAction *> list = (*notes)->actionCollection()->actions();
604 for ( TQValueList<TDEAction *>::iterator it = list.begin(); it != list.end(); ++it )
605 {
606 notes.toFirst();
607 for ( ++notes; *notes; ++notes )
608 {
609 TDEAction *toChange = (*notes)->actionCollection()->action( (*it)->name() );
610 if ( toChange->shortcut() != (*it)->shortcut() )
611 toChange->setShortcut( (*it)->shortcut() );
612 }
613 }
614}
615
616void KNotesApp::slotNoteKilled( KCal::Journal *journal )
617{
618 m_noteUidModify="";
619 m_manager->deleteNote( journal );
620 saveNotes();
621}
622
623void KNotesApp::slotQuit()
624{
625 TQDictIterator<KNote> it( m_noteList );
626
627 for ( ; *it; ++it )
628 if ( (*it)->isModified() )
629 (*it)->saveData(false);
630
631 saveConfigs();
632 tdeApp->quit();
633}
634
635
636// -------------------- private methods -------------------- //
637
638void KNotesApp::showNote( KNote* note ) const
639{
640 note->show();
641 KWin::setCurrentDesktop( KWin::windowInfo( note->winId() ).desktop() );
642 KWin::forceActiveWindow( note->winId() );
643 note->setFocus();
644}
645
646void KNotesApp::createNote( KCal::Journal *journal )
647{
648 if( journal->uid() == m_noteUidModify)
649 {
650 KNote *note = m_noteList[m_noteUidModify];
651 if ( note )
652 note->changeJournal(journal);
653
654 return;
655 }
656 m_noteUidModify = journal->uid();
657 KNote *newNote = new KNote( m_noteGUI, journal, 0, journal->uid().utf8() );
658 m_noteList.insert( newNote->noteId(), newNote );
659
660 connect( newNote, TQ_SIGNAL(sigRequestNewNote()), TQ_SLOT(newNote()) );
661 connect( newNote, TQ_SIGNAL(sigShowNextNote()), TQ_SLOT(slotWalkThroughNotes()) );
662 connect( newNote, TQ_SIGNAL(sigKillNote( KCal::Journal* )),
663 TQ_SLOT(slotNoteKilled( KCal::Journal* )) );
664 connect( newNote, TQ_SIGNAL(sigNameChanged()), TQ_SLOT(updateNoteActions()) );
665 connect( newNote, TQ_SIGNAL(sigDataChanged(const TQString &)), TQ_SLOT(saveNotes(const TQString &)) );
666 connect( newNote, TQ_SIGNAL(sigColorChanged()), TQ_SLOT(updateNoteActions()) );
667 connect( newNote, TQ_SIGNAL(sigFindFinished()), TQ_SLOT(slotFindNext()) );
668
669 // don't call this during startup for each and every loaded note
670 if ( m_alarm )
671 updateNoteActions();
672}
673
674void KNotesApp::killNote( KCal::Journal *journal )
675{
676 if(m_noteUidModify == journal->uid())
677 {
678 return;
679 }
680 // this kills the KNote object
681 KNote *note = m_noteList.take( journal->uid() );
682 if ( note )
683 {
684 note->deleteWhenIdle();
685 updateNoteActions();
686 }
687}
688
689void KNotesApp::acceptConnection()
690{
691 // Accept the connection and make KNotesNetworkReceiver do the job
692 TDEBufferedSocket *s = static_cast<TDEBufferedSocket *>(m_listener->accept());
693 if ( s )
694 {
695 KNotesNetworkReceiver *recv = new KNotesNetworkReceiver( s );
696 connect( recv, TQ_SIGNAL(sigNoteReceived( const TQString &, const TQString & )),
697 this, TQ_SLOT(newNote( const TQString &, const TQString & )) );
698 }
699}
700
701void KNotesApp::saveNotes( const TQString & uid )
702{
703 m_noteUidModify = uid;
704 saveNotes();
705}
706
707void KNotesApp::saveNotes()
708{
709 KNotesGlobalConfig::writeConfig();
710 m_manager->save();
711}
712
713void KNotesApp::saveConfigs()
714{
715 TQDictIterator<KNote> it( m_noteList );
716 for ( ; it.current(); ++it )
717 it.current()->saveConfig();
718}
719
720void KNotesApp::updateNoteActions()
721{
722 unplugActionList( "notes" );
723 m_noteActions.clear();
724
725 for ( TQDictIterator<KNote> it( m_noteList ); it.current(); ++it )
726 {
727 TDEAction *action = new TDEAction( it.current()->name().replace("&", "&&"),
728 TDEShortcut(), this, TQ_SLOT(slotShowNote()),
729 (TQObject *)0,
730 it.current()->noteId().utf8() );
731 TDEIconEffect effect;
732 TQPixmap icon = effect.apply( tdeApp->miniIcon(), TDEIconEffect::Colorize, 1,
733 it.current()->paletteBackgroundColor(), false );
734 action->setIconSet( icon );
735 m_noteActions.append( action );
736 }
737
738 if ( m_noteActions.isEmpty() )
739 {
740 actionCollection()->action( "hide_all_notes" )->setEnabled( false );
741 actionCollection()->action( "show_all_notes" )->setEnabled( false );
742 m_findAction->setEnabled( false );
743 TDEAction *action = new TDEAction( i18n("No Notes") );
744 m_noteActions.append( action );
745 }
746 else
747 {
748 actionCollection()->action( "hide_all_notes" )->setEnabled( true );
749 actionCollection()->action( "show_all_notes" )->setEnabled( true );
750 m_findAction->setEnabled( true );
751 m_noteActions.sort();
752 }
753 plugActionList( "notes", m_noteActions );
754}
755
756void KNotesApp::updateGlobalAccels()
757{
758 if ( m_globalAccel->isEnabled() )
759 {
760 TDEAction *action = actionCollection()->action( "new_note" );
761 if ( action )
762 action->setShortcut( m_globalAccel->shortcut( "global_new_note" ) );
763 action = actionCollection()->action( "new_note_clipboard" );
764 if ( action )
765 action->setShortcut( m_globalAccel->shortcut( "global_new_note_clipboard" ) );
766 action = actionCollection()->action( "hide_all_notes" );
767 if ( action )
768 action->setShortcut( m_globalAccel->shortcut( "global_hide_all_notes" ) );
769 action = actionCollection()->action( "show_all_notes" );
770 if ( action )
771 action->setShortcut( m_globalAccel->shortcut( "global_show_all_notes" ) );
772
773 m_globalAccel->updateConnections();
774 }
775 else
776 {
777 TDEAction *action = actionCollection()->action( "new_note" );
778 if ( action )
779 action->setShortcut( 0 );
780 action = actionCollection()->action( "new_note_clipboard" );
781 if ( action )
782 action->setShortcut( 0 );
783 action = actionCollection()->action( "hide_all_notes" );
784 if ( action )
785 action->setShortcut( 0 );
786 action = actionCollection()->action( "show_all_notes" );
787 if ( action )
788 action->setShortcut( 0 );
789 }
790}
791
792void KNotesApp::updateNetworkListener()
793{
794 m_listener->close();
795
796 if ( KNotesGlobalConfig::receiveNotes() )
797 {
798 m_listener->setAddress( TQString::number( KNotesGlobalConfig::port() ) );
799 m_listener->bind();
800 m_listener->listen();
801 }
802}
803
804void KNotesApp::updateStyle()
805{
806 KNote::setStyle( KNotesGlobalConfig::style() );
807
808 TQDictIterator<KNote> it( m_noteList );
809 for ( ; it.current(); ++it )
810 TQApplication::postEvent( *it, new TQEvent( TQEvent::LayoutHint ) );
811}
812
813#include "knotesapp.moc"