knotes

knotesapp.cpp

00001 /*******************************************************************
00002  KNotes -- Notes for the KDE project
00003 
00004  Copyright (c) 1997-2006, The KNotes Developers
00005 
00006  This program is free software; you can redistribute it and/or
00007  modify it under the terms of the GNU General Public License
00008  as published by the Free Software Foundation; either version 2
00009  of the License, or (at your option) any later version.
00010 
00011  This program is distributed in the hope that it will be useful,
00012  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  GNU General Public License for more details.
00015 
00016  You should have received a copy of the GNU General Public License
00017  along with this program; if not, write to the Free Software
00018  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019 *******************************************************************/
00020 
00021 #include <qclipboard.h>
00022 #include <qptrlist.h>
00023 #include <qtooltip.h>
00024 
00025 #include <kdebug.h>
00026 #include <kaction.h>
00027 #include <kxmlguifactory.h>
00028 #include <kxmlguibuilder.h>
00029 #include <ksystemtray.h>
00030 #include <klocale.h>
00031 #include <kiconeffect.h>
00032 #include <kstandarddirs.h>
00033 #include <kpopupmenu.h>
00034 #include <khelpmenu.h>
00035 #include <kfind.h>
00036 #include <kfinddialog.h>
00037 #include <kkeydialog.h>
00038 #include <kglobalaccel.h>
00039 #include <ksimpleconfig.h>
00040 #include <kwin.h>
00041 #include <kbufferedsocket.h>
00042 #include <kserversocket.h>
00043 
00044 #include <libkcal/journal.h>
00045 #include <libkcal/calendarlocal.h>
00046 
00047 #include "knotesapp.h"
00048 #include "knote.h"
00049 #include "knotesalarm.h"
00050 #include "knoteconfigdlg.h"
00051 #include "knotesglobalconfig.h"
00052 #include "knoteslegacy.h"
00053 #include "knotesnetrecv.h"
00054 
00055 #include "knotes/resourcemanager.h"
00056 
00057 using namespace KNetwork;
00058 
00059 
00060 class KNotesKeyDialog : public KDialogBase
00061 {
00062 public:
00063     KNotesKeyDialog( KGlobalAccel *globals, QWidget *parent, const char* name = 0 )
00064         : KDialogBase( parent, name, true, i18n("Configure Shortcuts"), Default|Ok|Cancel, Ok )
00065     {
00066         m_keyChooser = new KKeyChooser( globals, this );
00067         setMainWidget( m_keyChooser );
00068         connect( this, SIGNAL(defaultClicked()), m_keyChooser, SLOT(allDefault()) );
00069     }
00070 
00071     void insert( KActionCollection *actions )
00072     {
00073         m_keyChooser->insert( actions, i18n("Note Actions") );
00074     }
00075 
00076     void configure()
00077     {
00078         if ( exec() == Accepted )
00079             m_keyChooser->save();
00080     }
00081 
00082 private:
00083     KKeyChooser *m_keyChooser;
00084 };
00085 
00086 
00087 int KNotesApp::KNoteActionList::compareItems( QPtrCollection::Item s1, QPtrCollection::Item s2 )
00088 {
00089     if ( ((KAction*)s1)->text() == ((KAction*)s2)->text() )
00090         return 0;
00091     return ( ((KAction*)s1)->text() < ((KAction*)s2)->text() ? -1 : 1 );
00092 }
00093 
00094 
00095 KNotesApp::KNotesApp()
00096     : DCOPObject("KNotesIface"), QLabel( 0, 0, WType_TopLevel ),
00097       m_alarm( 0 ), m_listener( 0 ), m_find( 0 ), m_findPos( 0 )
00098 {
00099     connect( kapp, SIGNAL(lastWindowClosed()), kapp, SLOT(quit()) );
00100 
00101     m_noteList.setAutoDelete( true );
00102     m_noteActions.setAutoDelete( true );
00103 
00104     // create the dock widget...
00105     KWin::setSystemTrayWindowFor( winId(), qt_xrootwin() );
00106     QToolTip::add( this, i18n( "KNotes: Sticky notes for KDE" ) );
00107     setBackgroundMode( X11ParentRelative );
00108     setPixmap( KSystemTray::loadIcon( "knotes" ) );
00109 
00110     // set the initial style
00111     KNote::setStyle( KNotesGlobalConfig::style() );
00112 
00113     // create the GUI...
00114     new KAction( i18n("New Note"), "filenew", 0,
00115         this, SLOT(newNote()), actionCollection(), "new_note" );
00116     new KAction( i18n("New Note From Clipboard"), "editpaste", 0,
00117         this, SLOT(newNoteFromClipboard()), actionCollection(), "new_note_clipboard" );
00118     new KAction( i18n("Show All Notes"), "knotes", 0,
00119         this, SLOT(showAllNotes()), actionCollection(), "show_all_notes" );
00120     new KAction( i18n("Hide All Notes"), "fileclose", 0,
00121         this, SLOT(hideAllNotes()), actionCollection(), "hide_all_notes" );
00122     new KHelpMenu( this, kapp->aboutData(), false, actionCollection() );
00123 
00124     KStdAction::find( this, SLOT(slotOpenFindDialog()), actionCollection() );
00125     KStdAction::preferences( this, SLOT(slotPreferences()), actionCollection() );
00126     KStdAction::keyBindings( this, SLOT(slotConfigureAccels()), actionCollection() );
00127     //FIXME: no shortcut removing!?
00128     KStdAction::quit( this, SLOT(slotQuit()), actionCollection() )->setShortcut( 0 );
00129 
00130     setXMLFile( instance()->instanceName() + "appui.rc" );
00131 
00132     m_guiBuilder = new KXMLGUIBuilder( this );
00133     m_guiFactory = new KXMLGUIFactory( m_guiBuilder, this );
00134     m_guiFactory->addClient( this );
00135 
00136     m_context_menu = static_cast<KPopupMenu*>(m_guiFactory->container( "knotes_context", this ));
00137     m_note_menu = static_cast<KPopupMenu*>(m_guiFactory->container( "notes_menu", this ));
00138 
00139     // get the most recent XML UI file
00140     QString xmlFileName = instance()->instanceName() + "ui.rc";
00141     QString filter = QString::fromLatin1( instance()->instanceName() + '/' ) + xmlFileName;
00142     QStringList fileList = instance()->dirs()->findAllResources( "data", filter ) +
00143                            instance()->dirs()->findAllResources( "data", xmlFileName );
00144 
00145     QString doc;
00146     KXMLGUIClient::findMostRecentXMLFile( fileList, doc );
00147     m_noteGUI.setContent( doc );
00148 
00149     // create accels for global shortcuts
00150     m_globalAccel = new KGlobalAccel( this, "global accel" );
00151     m_globalAccel->insert( "global_new_note", i18n("New Note"), "",
00152                            ALT+SHIFT+Key_N, ALT+SHIFT+Key_N ,
00153                            this, SLOT(newNote()), true, true );
00154     m_globalAccel->insert( "global_new_note_clipboard", i18n("New Note From Clipboard"), "",
00155                            ALT+SHIFT+Key_C, ALT+SHIFT+Key_C,
00156                            this, SLOT(newNoteFromClipboard()), true, true );
00157     m_globalAccel->insert( "global_hide_all_notes", i18n("Hide All Notes"), "",
00158                            ALT+SHIFT+Key_H, ALT+SHIFT+Key_H ,
00159                            this, SLOT(hideAllNotes()), true, true );
00160     m_globalAccel->insert( "global_show_all_notes", i18n("Show All Notes"), "",
00161                            ALT+SHIFT+Key_S, ALT+SHIFT+Key_S,
00162                            this, SLOT(showAllNotes()), true, true );
00163 
00164     m_globalAccel->readSettings();
00165 
00166     KConfig *config = KGlobal::config();
00167     config->setGroup( "Global Keybindings" );
00168     m_globalAccel->setEnabled( config->readBoolEntry( "Enabled", true ) );
00169 
00170     updateGlobalAccels();
00171 
00172     // clean up old config files
00173     KNotesLegacy::cleanUp();
00174 
00175     // create the resource manager
00176     m_manager = new KNotesResourceManager();
00177     connect( m_manager, SIGNAL(sigRegisteredNote( KCal::Journal * )),
00178              this,      SLOT(createNote( KCal::Journal * )) );
00179     connect( m_manager, SIGNAL(sigDeregisteredNote( KCal::Journal * )),
00180              this,      SLOT(killNote( KCal::Journal * )) );
00181 
00182     // read the notes
00183     m_manager->load();
00184 
00185     // read the old config files, convert and add them
00186     KCal::CalendarLocal calendar( QString::fromLatin1( "UTC" ) );
00187     if ( KNotesLegacy::convert( &calendar ) )
00188     {
00189         KCal::Journal::List notes = calendar.journals();
00190         KCal::Journal::List::ConstIterator it;
00191         for ( it = notes.begin(); it != notes.end(); ++it )
00192             m_manager->addNewNote( *it );
00193 
00194         m_manager->save();
00195     }
00196 
00197     // set up the alarm reminder - do it after loading the notes because this
00198     // is used as a check if updateNoteActions has to be called for a new note
00199     m_alarm = new KNotesAlarm( m_manager, this );
00200 
00201     // create the socket and possibly start listening for connections
00202     m_listener = new KServerSocket();
00203     m_listener->setResolutionEnabled( true );
00204     connect( m_listener, SIGNAL(readyAccept()), SLOT(acceptConnection()) );
00205     updateNetworkListener();
00206 
00207     if ( m_noteList.count() == 0 && !kapp->isRestored() )
00208         newNote();
00209 
00210     updateNoteActions();
00211 }
00212 
00213 KNotesApp::~KNotesApp()
00214 {
00215     saveNotes();
00216 
00217     blockSignals( true );
00218     m_noteList.clear();
00219     blockSignals( false );
00220 
00221     delete m_listener;
00222     delete m_manager;
00223     delete m_guiBuilder;
00224 }
00225 
00226 bool KNotesApp::commitData( QSessionManager& )
00227 {
00228     saveConfigs();
00229     return true;
00230 }
00231 
00232 // -------------------- public DCOP interface -------------------- //
00233 
00234 QString KNotesApp::newNote( const QString& name, const QString& text )
00235 {
00236     // create the new note
00237     KCal::Journal *journal = new KCal::Journal();
00238 
00239     // new notes have the current date/time as title if none was given
00240     if ( !name.isEmpty() )
00241         journal->setSummary( name );
00242     else
00243         journal->setSummary( KGlobal::locale()->formatDateTime( QDateTime::currentDateTime() ) );
00244 
00245     // the body of the note
00246     journal->setDescription( text );
00247 
00248     m_manager->addNewNote( journal );
00249 
00250     showNote( journal->uid() );
00251 
00252     return journal->uid();
00253 }
00254 
00255 QString KNotesApp::newNoteFromClipboard( const QString& name )
00256 {
00257     const QString& text = KApplication::clipboard()->text();
00258     return newNote( name, text );
00259 }
00260 
00261 void KNotesApp::hideAllNotes() const
00262 {
00263     QDictIterator<KNote> it( m_noteList );
00264     for ( ; *it; ++it )
00265         (*it)->close();
00266 }
00267 
00268 void KNotesApp::showAllNotes() const
00269 {
00270     QDictIterator<KNote> it( m_noteList );
00271     for ( ; *it; ++it )
00272     {
00273         (*it)->show();
00274         (*it)->setFocus();
00275     }
00276 }
00277 
00278 void KNotesApp::showNote( const QString& id ) const
00279 {
00280     KNote* note = m_noteList[id];
00281     if ( note )
00282         showNote( note );
00283     else
00284         kdWarning(5500) << "showNote: no note with id: " << id << endl;
00285 }
00286 
00287 void KNotesApp::hideNote( const QString& id ) const
00288 {
00289     KNote* note = m_noteList[id];
00290     if ( note )
00291         note->hide();
00292     else
00293         kdWarning(5500) << "hideNote: no note with id: " << id << endl;
00294 }
00295 
00296 void KNotesApp::killNote( const QString& id, bool force )
00297 {
00298     KNote* note = m_noteList[id];
00299     if ( note )
00300         note->slotKill( force );
00301     else
00302         kdWarning(5500) << "killNote: no note with id: " << id << endl;
00303 }
00304 
00305 // "bool force = false" doesn't work with dcop
00306 void KNotesApp::killNote( const QString& id )
00307 {
00308     killNote( id, false );
00309 }
00310 
00311 QMap<QString,QString> KNotesApp::notes() const
00312 {
00313     QMap<QString,QString> notes;
00314     QDictIterator<KNote> it( m_noteList );
00315 
00316     for ( ; it.current(); ++it )
00317         notes.insert( it.current()->noteId(), it.current()->name() );
00318 
00319     return notes;
00320 }
00321 
00322 QString KNotesApp::name( const QString& id ) const
00323 {
00324     KNote* note = m_noteList[id];
00325     if ( note )
00326         return note->name();
00327     else
00328         return QString::null;
00329 }
00330 
00331 QString KNotesApp::text( const QString& id ) const
00332 {
00333     KNote* note = m_noteList[id];
00334     if ( note )
00335         return note->text();
00336     else
00337         return QString::null;
00338 }
00339 
00340 void KNotesApp::setName( const QString& id, const QString& newName )
00341 {
00342     KNote* note = m_noteList[id];
00343     if ( note )
00344         note->setName( newName );
00345     else
00346         kdWarning(5500) << "setName: no note with id: " << id << endl;
00347 }
00348 
00349 void KNotesApp::setText( const QString& id, const QString& newText )
00350 {
00351     KNote* note = m_noteList[id];
00352     if ( note )
00353         note->setText( newText );
00354     else
00355         kdWarning(5500) << "setText: no note with id: " << id << endl;
00356 }
00357 
00358 QString KNotesApp::fgColor( const QString& id ) const
00359 {
00360     KNote* note = m_noteList[id];
00361     if ( note )
00362         return note->fgColor().name();
00363     else
00364         return QString::null;
00365 }
00366 
00367 QString KNotesApp::bgColor( const QString& id ) const
00368 {
00369     KNote* note = m_noteList[id];
00370     if ( note )
00371         return note->bgColor().name();
00372     else
00373         return QString::null;
00374 }
00375 
00376 void KNotesApp::setColor( const QString& id, const QString& fgColor, const QString& bgColor )
00377 {
00378     KNote* note = m_noteList[id];
00379     if ( note )
00380         note->setColor( QColor( fgColor ), QColor( bgColor ) );
00381     else
00382         kdWarning(5500) << "setColor: no note with id: " << id << endl;
00383 }
00384 
00385 int KNotesApp::width( const QString& id ) const
00386 {
00387     KNote* note = m_noteList[id];
00388     if ( note )
00389         return note->width();
00390     else
00391         return 0;
00392 }
00393 
00394 int KNotesApp::height( const QString& id ) const
00395 {
00396     KNote* note = m_noteList[id];
00397     if ( note )
00398         return note->height();
00399     else
00400         return 0;
00401 }
00402 
00403 void KNotesApp::move( const QString& id, int x, int y ) const
00404 {
00405     KNote* note = m_noteList[id];
00406     if ( note )
00407         return note->move( x, y );
00408     else
00409         kdWarning(5500) << "move: no note with id: " << id << endl;
00410 }
00411 
00412 void KNotesApp::resize( const QString& id, int width, int height ) const
00413 {
00414     KNote* note = m_noteList[id];
00415     if ( note )
00416         return note->resize( width, height );
00417     else
00418         kdWarning(5500) << "resize: no note with id: " << id << endl;
00419 }
00420 
00421 void KNotesApp::sync( const QString& app )
00422 {
00423     QDictIterator<KNote> it( m_noteList );
00424 
00425     for ( ; it.current(); ++it )
00426         it.current()->sync( app );
00427 }
00428 
00429 bool KNotesApp::isNew( const QString& app, const QString& id ) const
00430 {
00431     KNote* note = m_noteList[id];
00432     if ( note )
00433         return note->isNew( app );
00434     else
00435         return false;
00436 }
00437 
00438 bool KNotesApp::isModified( const QString& app, const QString& id ) const
00439 {
00440     KNote* note = m_noteList[id];
00441     if ( note )
00442         return note->isModified( app );
00443     else
00444         return false;
00445 }
00446 
00447 
00448 // ------------------- protected methods ------------------- //
00449 
00450 void KNotesApp::mousePressEvent( QMouseEvent* e )
00451 {
00452     if ( !rect().contains( e->pos() ) )
00453         return;
00454 
00455     switch ( e->button() )
00456     {
00457     case LeftButton:
00458         if ( m_noteList.count() == 1 )
00459         {
00460             QDictIterator<KNote> it( m_noteList );
00461             showNote( it.toFirst() );
00462         }
00463         else if ( m_note_menu->count() > 0 )
00464             m_note_menu->popup( e->globalPos() );
00465         break;
00466     case MidButton:
00467         newNote();
00468         break;
00469     case RightButton:
00470         m_context_menu->popup( e->globalPos() );
00471     default: break;
00472     }
00473 }
00474 
00475 // -------------------- protected slots -------------------- //
00476 
00477 void KNotesApp::slotShowNote()
00478 {
00479     // tell the WM to give this note focus
00480     showNote( QString::fromUtf8( sender()->name() ) );
00481 }
00482 
00483 void KNotesApp::slotWalkThroughNotes()
00484 {
00485     // show next note
00486     QDictIterator<KNote> it( m_noteList );
00487     KNote *first = it.toFirst();
00488     for ( ; *it; ++it )
00489         if ( (*it)->hasFocus() )
00490         {
00491             if ( ++it )
00492                 showNote( *it );
00493             else
00494                 showNote( first );
00495             break;
00496         }
00497 }
00498 
00499 void KNotesApp::slotOpenFindDialog()
00500 {
00501     KFindDialog findDia( this, "find_dialog" );
00502     findDia.setHasSelection( false );
00503     findDia.setHasCursor( false );
00504     findDia.setSupportsBackwardsFind( false );
00505 
00506     if ( findDia.exec() != QDialog::Accepted )
00507         return;
00508 
00509     delete m_findPos;
00510     m_findPos = new QDictIterator<KNote>( m_noteList );
00511 
00512     // this could be in an own method if searching without a dialog should be possible
00513     delete m_find;
00514     m_find = new KFind( findDia.pattern(), findDia.options(), this );
00515 
00516     slotFindNext();
00517 }
00518 
00519 void KNotesApp::slotFindNext()
00520 {
00521     if ( **m_findPos )
00522     {
00523         KNote *note = **m_findPos;
00524         ++*m_findPos;
00525         note->find( m_find->pattern(), m_find->options() );
00526     }
00527     else
00528     {
00529         m_find->displayFinalDialog();
00530         delete m_find;
00531         m_find = 0;
00532         delete m_findPos;
00533         m_findPos = 0;
00534     }
00535 }
00536 
00537 void KNotesApp::slotPreferences()
00538 {
00539     // reuse the dialog if possible
00540     if ( KNoteConfigDlg::showDialog( "KNotes Default Settings" ) )
00541         return;
00542 
00543     // create a new preferences dialog...
00544     KNoteConfigDlg *dialog = new KNoteConfigDlg( 0, i18n("Settings"), this,
00545                                                  "KNotes Settings" );
00546     connect( dialog, SIGNAL(settingsChanged()), this, SLOT(updateNetworkListener()) );
00547     connect( dialog, SIGNAL(settingsChanged()), this, SLOT(updateStyle()) );
00548     dialog->show();
00549 }
00550 
00551 void KNotesApp::slotConfigureAccels()
00552 {
00553     KNotesKeyDialog keys( m_globalAccel, this );
00554     QDictIterator<KNote> notes( m_noteList );
00555     if ( !m_noteList.isEmpty() )
00556         keys.insert( (*notes)->actionCollection() );
00557     keys.configure();
00558 
00559     m_globalAccel->writeSettings();
00560     updateGlobalAccels();
00561 
00562     // update GUI doc for new notes
00563     m_noteGUI.setContent(
00564         KXMLGUIFactory::readConfigFile( instance()->instanceName() + "ui.rc", instance() )
00565     );
00566 
00567     if ( m_noteList.isEmpty() )
00568         return;
00569 
00570     notes.toFirst();
00571     QValueList<KAction *> list = (*notes)->actionCollection()->actions();
00572     for ( QValueList<KAction *>::iterator it = list.begin(); it != list.end(); ++it )
00573     {
00574         notes.toFirst();
00575         for ( ++notes; *notes; ++notes )
00576         {
00577             KAction *toChange = (*notes)->actionCollection()->action( (*it)->name() );
00578             if ( toChange->shortcut() != (*it)->shortcut() )
00579                 toChange->setShortcut( (*it)->shortcut() );
00580         }
00581     }
00582 }
00583 
00584 void KNotesApp::slotNoteKilled( KCal::Journal *journal )
00585 {
00586     m_manager->deleteNote( journal );
00587     saveNotes();
00588 }
00589 
00590 void KNotesApp::slotQuit()
00591 {
00592     QDictIterator<KNote> it( m_noteList );
00593 
00594     for ( ; *it; ++it )
00595         if ( (*it)->isModified() )
00596             (*it)->saveData();
00597 
00598     saveConfigs();
00599     kapp->quit();
00600 }
00601 
00602 
00603 // -------------------- private methods -------------------- //
00604 
00605 void KNotesApp::showNote( KNote* note ) const
00606 {
00607     note->show();
00608     KWin::setCurrentDesktop( KWin::windowInfo( note->winId() ).desktop() );
00609     KWin::forceActiveWindow( note->winId() );
00610     note->setFocus();
00611 }
00612 
00613 void KNotesApp::createNote( KCal::Journal *journal )
00614 {
00615     KNote *newNote = new KNote( m_noteGUI, journal, 0, journal->uid().utf8() );
00616     m_noteList.insert( newNote->noteId(), newNote );
00617 
00618     connect( newNote, SIGNAL(sigRequestNewNote()), SLOT(newNote()) );
00619     connect( newNote, SIGNAL(sigShowNextNote()), SLOT(slotWalkThroughNotes()) );
00620     connect( newNote, SIGNAL(sigKillNote( KCal::Journal* )),
00621                         SLOT(slotNoteKilled( KCal::Journal* )) );
00622     connect( newNote, SIGNAL(sigNameChanged()), SLOT(updateNoteActions()) );
00623     connect( newNote, SIGNAL(sigDataChanged()), SLOT(saveNotes()) );
00624     connect( newNote, SIGNAL(sigColorChanged()), SLOT(updateNoteActions()) );
00625     connect( newNote, SIGNAL(sigFindFinished()), SLOT(slotFindNext()) );
00626 
00627     // don't call this during startup for each and every loaded note
00628     if ( m_alarm )
00629         updateNoteActions();
00630 }
00631 
00632 void KNotesApp::killNote( KCal::Journal *journal )
00633 {
00634     // this kills the KNote object
00635     m_noteList.remove( journal->uid() );
00636     updateNoteActions();
00637 }
00638 
00639 void KNotesApp::acceptConnection()
00640 {
00641     // Accept the connection and make KNotesNetworkReceiver do the job
00642     KBufferedSocket *s = static_cast<KBufferedSocket *>(m_listener->accept());
00643     if ( s )
00644     {
00645         KNotesNetworkReceiver *recv = new KNotesNetworkReceiver( s );
00646         connect( recv, SIGNAL(sigNoteReceived( const QString &, const QString & )),
00647                  this, SLOT(newNote( const QString &, const QString & )) );
00648     }
00649 }
00650 
00651 void KNotesApp::saveNotes()
00652 {
00653     KNotesGlobalConfig::writeConfig();
00654     m_manager->save();
00655 }
00656 
00657 void KNotesApp::saveConfigs()
00658 {
00659     QDictIterator<KNote> it( m_noteList );
00660     for ( ; it.current(); ++it )
00661         it.current()->saveConfig();
00662 }
00663 
00664 void KNotesApp::updateNoteActions()
00665 {
00666     unplugActionList( "notes" );
00667     m_noteActions.clear();
00668 
00669     for ( QDictIterator<KNote> it( m_noteList ); it.current(); ++it )
00670     {
00671         KAction *action = new KAction( it.current()->name().replace("&", "&&"),
00672                                        KShortcut(), this, SLOT(slotShowNote()),
00673                                        (QObject *)0,
00674                                        it.current()->noteId().utf8() );
00675         KIconEffect effect;
00676         QPixmap icon = effect.apply( kapp->miniIcon(), KIconEffect::Colorize, 1,
00677                                      it.current()->paletteBackgroundColor(), false );
00678         action->setIconSet( icon );
00679         m_noteActions.append( action );
00680     }
00681 
00682     m_noteActions.sort();
00683 
00684     if ( m_noteActions.isEmpty() )
00685     {
00686         KAction *action = new KAction( i18n("No Notes") );
00687         m_noteActions.append( action );
00688     }
00689 
00690     plugActionList( "notes", m_noteActions );
00691 }
00692 
00693 void KNotesApp::updateGlobalAccels()
00694 {
00695     if ( m_globalAccel->isEnabled() )
00696     {
00697         KAction *action = actionCollection()->action( "new_note" );
00698         if ( action )
00699             action->setShortcut( m_globalAccel->shortcut( "global_new_note" ) );
00700         action = actionCollection()->action( "new_note_clipboard" );
00701         if ( action )
00702             action->setShortcut( m_globalAccel->shortcut( "global_new_note_clipboard" ) );
00703         action = actionCollection()->action( "hide_all_notes" );
00704         if ( action )
00705             action->setShortcut( m_globalAccel->shortcut( "global_hide_all_notes" ) );
00706         action = actionCollection()->action( "show_all_notes" );
00707         if ( action )
00708             action->setShortcut( m_globalAccel->shortcut( "global_show_all_notes" ) );
00709 
00710         m_globalAccel->updateConnections();
00711     }
00712     else
00713     {
00714         KAction *action = actionCollection()->action( "new_note" );
00715         if ( action )
00716             action->setShortcut( 0 );
00717         action = actionCollection()->action( "new_note_clipboard" );
00718         if ( action )
00719             action->setShortcut( 0 );
00720         action = actionCollection()->action( "hide_all_notes" );
00721         if ( action )
00722             action->setShortcut( 0 );
00723         action = actionCollection()->action( "show_all_notes" );
00724         if ( action )
00725             action->setShortcut( 0 );
00726     }
00727 }
00728 
00729 void KNotesApp::updateNetworkListener()
00730 {
00731     m_listener->close();
00732 
00733     if ( KNotesGlobalConfig::receiveNotes() )
00734     {
00735         m_listener->setAddress( QString::number( KNotesGlobalConfig::port() ) );
00736         m_listener->bind();
00737         m_listener->listen();
00738     }
00739 }
00740 
00741 void KNotesApp::updateStyle()
00742 {
00743     KNote::setStyle( KNotesGlobalConfig::style() );
00744 
00745     QDictIterator<KNote> it( m_noteList );
00746     for ( ; it.current(); ++it )
00747         QApplication::postEvent( *it, new QEvent( QEvent::LayoutHint ) );
00748 }
00749 
00750 #include "knotesapp.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys