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     m_findAction = 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.constBegin(); it != notes.constEnd(); ++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     if ( m_manager->addNewNote( journal ) ) {
00249         showNote( journal->uid() );
00250     }
00251     return journal->uid();
00252 }
00253 
00254 QString KNotesApp::newNoteFromClipboard( const QString& name )
00255 {
00256     const QString& text = KApplication::clipboard()->text();
00257     return newNote( name, text );
00258 }
00259 
00260 void KNotesApp::hideAllNotes() const
00261 {
00262     QDictIterator<KNote> it( m_noteList );
00263     for ( ; *it; ++it )
00264         (*it)->close();
00265 }
00266 
00267 void KNotesApp::showAllNotes() const
00268 {
00269     QDictIterator<KNote> it( m_noteList );
00270     for ( ; *it; ++it )
00271     {
00272         (*it)->show();
00273     }
00274 }
00275 
00276 void KNotesApp::showNote( const QString& id ) const
00277 {
00278     KNote* note = m_noteList[id];
00279     if ( note )
00280         showNote( note );
00281     else
00282         kdWarning(5500) << "showNote: no note with id: " << id << endl;
00283 }
00284 
00285 void KNotesApp::hideNote( const QString& id ) const
00286 {
00287     KNote* note = m_noteList[id];
00288     if ( note )
00289         note->hide();
00290     else
00291         kdWarning(5500) << "hideNote: no note with id: " << id << endl;
00292 }
00293 
00294 void KNotesApp::killNote( const QString& id, bool force )
00295 {
00296     KNote* note = m_noteList[id];
00297     if ( note )
00298         note->slotKill( force );
00299     else
00300         kdWarning(5500) << "killNote: no note with id: " << id << endl;
00301 }
00302 
00303 // "bool force = false" doesn't work with dcop
00304 void KNotesApp::killNote( const QString& id )
00305 {
00306     killNote( id, false );
00307 }
00308 
00309 QMap<QString,QString> KNotesApp::notes() const
00310 {
00311     QMap<QString,QString> notes;
00312     QDictIterator<KNote> it( m_noteList );
00313 
00314     for ( ; it.current(); ++it )
00315         notes.insert( it.current()->noteId(), it.current()->name() );
00316 
00317     return notes;
00318 }
00319 
00320 QString KNotesApp::name( const QString& id ) const
00321 {
00322     KNote* note = m_noteList[id];
00323     if ( note )
00324         return note->name();
00325     else
00326         return QString::null;
00327 }
00328 
00329 QString KNotesApp::text( const QString& id ) const
00330 {
00331     KNote* note = m_noteList[id];
00332     if ( note )
00333         return note->text();
00334     else
00335         return QString::null;
00336 }
00337 
00338 void KNotesApp::setName( const QString& id, const QString& newName )
00339 {
00340     KNote* note = m_noteList[id];
00341     if ( note )
00342         note->setName( newName );
00343     else
00344         kdWarning(5500) << "setName: no note with id: " << id << endl;
00345 }
00346 
00347 void KNotesApp::setText( const QString& id, const QString& newText )
00348 {
00349     KNote* note = m_noteList[id];
00350     if ( note )
00351         note->setText( newText );
00352     else
00353         kdWarning(5500) << "setText: no note with id: " << id << endl;
00354 }
00355 
00356 QString KNotesApp::fgColor( const QString& id ) const
00357 {
00358     KNote* note = m_noteList[id];
00359     if ( note )
00360         return note->fgColor().name();
00361     else
00362         return QString::null;
00363 }
00364 
00365 QString KNotesApp::bgColor( const QString& id ) const
00366 {
00367     KNote* note = m_noteList[id];
00368     if ( note )
00369         return note->bgColor().name();
00370     else
00371         return QString::null;
00372 }
00373 
00374 void KNotesApp::setColor( const QString& id, const QString& fgColor, const QString& bgColor )
00375 {
00376     KNote* note = m_noteList[id];
00377     if ( note )
00378         note->setColor( QColor( fgColor ), QColor( bgColor ) );
00379     else
00380         kdWarning(5500) << "setColor: no note with id: " << id << endl;
00381 }
00382 
00383 int KNotesApp::width( const QString& id ) const
00384 {
00385     KNote* note = m_noteList[id];
00386     if ( note )
00387         return note->width();
00388     else
00389         return 0;
00390 }
00391 
00392 int KNotesApp::height( const QString& id ) const
00393 {
00394     KNote* note = m_noteList[id];
00395     if ( note )
00396         return note->height();
00397     else
00398         return 0;
00399 }
00400 
00401 void KNotesApp::move( const QString& id, int x, int y ) const
00402 {
00403     KNote* note = m_noteList[id];
00404     if ( note )
00405         return note->move( x, y );
00406     else
00407         kdWarning(5500) << "move: no note with id: " << id << endl;
00408 }
00409 
00410 void KNotesApp::resize( const QString& id, int width, int height ) const
00411 {
00412     KNote* note = m_noteList[id];
00413     if ( note )
00414         return note->resize( width, height );
00415     else
00416         kdWarning(5500) << "resize: no note with id: " << id << endl;
00417 }
00418 
00419 void KNotesApp::sync( const QString& app )
00420 {
00421     QDictIterator<KNote> it( m_noteList );
00422 
00423     for ( ; it.current(); ++it )
00424         it.current()->sync( app );
00425 }
00426 
00427 bool KNotesApp::isNew( const QString& app, const QString& id ) const
00428 {
00429     KNote* note = m_noteList[id];
00430     if ( note )
00431         return note->isNew( app );
00432     else
00433         return false;
00434 }
00435 
00436 bool KNotesApp::isModified( const QString& app, const QString& id ) const
00437 {
00438     KNote* note = m_noteList[id];
00439     if ( note )
00440         return note->isModified( app );
00441     else
00442         return false;
00443 }
00444 
00445 
00446 // ------------------- protected methods ------------------- //
00447 
00448 void KNotesApp::mousePressEvent( QMouseEvent* e )
00449 {
00450     if ( !rect().contains( e->pos() ) )
00451         return;
00452 
00453     switch ( e->button() )
00454     {
00455     case LeftButton:
00456         if ( m_noteList.count() == 1 )
00457         {
00458             QDictIterator<KNote> it( m_noteList );
00459             showNote( it.toFirst() );
00460         }
00461         else if ( m_note_menu->count() > 0 )
00462             m_note_menu->popup( e->globalPos() );
00463         break;
00464     case MidButton:
00465         newNote();
00466         break;
00467     case RightButton:
00468         m_context_menu->popup( e->globalPos() );
00469     default: break;
00470     }
00471 }
00472 
00473 // -------------------- protected slots -------------------- //
00474 
00475 void KNotesApp::slotShowNote()
00476 {
00477     // tell the WM to give this note focus
00478     showNote( QString::fromUtf8( sender()->name() ) );
00479 }
00480 
00481 void KNotesApp::slotWalkThroughNotes()
00482 {
00483     // show next note
00484     QDictIterator<KNote> it( m_noteList );
00485     KNote *first = it.toFirst();
00486     for ( ; *it; ++it )
00487         if ( (*it)->hasFocus() )
00488         {
00489             if ( ++it )
00490                 showNote( *it );
00491             else
00492                 showNote( first );
00493             break;
00494         }
00495 }
00496 
00497 void KNotesApp::slotOpenFindDialog()
00498 {
00499     KFindDialog findDia( this, "find_dialog" );
00500     findDia.setHasSelection( false );
00501     findDia.setHasCursor( false );
00502     findDia.setSupportsBackwardsFind( false );
00503 
00504     if ( (findDia.exec() != QDialog::Accepted) || findDia.pattern().isEmpty() )
00505         return;
00506 
00507     delete m_findPos;
00508     m_findPos = new QDictIterator<KNote>( m_noteList );
00509 
00510     // this could be in an own method if searching without a dialog should be possible
00511     delete m_find;
00512     m_find = new KFind( findDia.pattern(), findDia.options(), this );
00513 
00514     slotFindNext();
00515 }
00516 
00517 void KNotesApp::slotFindNext()
00518 {
00519     if ( **m_findPos )
00520     {
00521         KNote *note = **m_findPos;
00522         ++*m_findPos;
00523         note->find( m_find->pattern(), m_find->options() );
00524     }
00525     else
00526     {
00527         m_find->displayFinalDialog();
00528         delete m_find;
00529         m_find = 0;
00530         delete m_findPos;
00531         m_findPos = 0;
00532     }
00533 }
00534 
00535 void KNotesApp::slotPreferences()
00536 {
00537     // reuse the dialog if possible
00538     if ( KNoteConfigDlg::showDialog( "KNotes Default Settings" ) )
00539         return;
00540 
00541     // create a new preferences dialog...
00542     KNoteConfigDlg *dialog = new KNoteConfigDlg( 0, i18n("Settings"), this,
00543                                                  "KNotes Settings" );
00544     connect( dialog, SIGNAL(settingsChanged()), this, SLOT(updateNetworkListener()) );
00545     connect( dialog, SIGNAL(settingsChanged()), this, SLOT(updateStyle()) );
00546     dialog->show();
00547 }
00548 
00549 void KNotesApp::slotConfigureAccels()
00550 {
00551     KNotesKeyDialog keys( m_globalAccel, this );
00552     QDictIterator<KNote> notes( m_noteList );
00553     if ( !m_noteList.isEmpty() )
00554         keys.insert( (*notes)->actionCollection() );
00555     keys.configure();
00556 
00557     m_globalAccel->writeSettings();
00558     updateGlobalAccels();
00559 
00560     // update GUI doc for new notes
00561     m_noteGUI.setContent(
00562         KXMLGUIFactory::readConfigFile( instance()->instanceName() + "ui.rc", instance() )
00563     );
00564 
00565     if ( m_noteList.isEmpty() )
00566         return;
00567 
00568     notes.toFirst();
00569     QValueList<KAction *> list = (*notes)->actionCollection()->actions();
00570     for ( QValueList<KAction *>::iterator it = list.begin(); it != list.end(); ++it )
00571     {
00572         notes.toFirst();
00573         for ( ++notes; *notes; ++notes )
00574         {
00575             KAction *toChange = (*notes)->actionCollection()->action( (*it)->name() );
00576             if ( toChange->shortcut() != (*it)->shortcut() )
00577                 toChange->setShortcut( (*it)->shortcut() );
00578         }
00579     }
00580 }
00581 
00582 void KNotesApp::slotNoteKilled( KCal::Journal *journal )
00583 {
00584     m_noteUidModify="";
00585     m_manager->deleteNote( journal );
00586     saveNotes();
00587 }
00588 
00589 void KNotesApp::slotQuit()
00590 {
00591     QDictIterator<KNote> it( m_noteList );
00592 
00593     for ( ; *it; ++it )
00594         if ( (*it)->isModified() )
00595             (*it)->saveData(false);
00596 
00597     saveConfigs();
00598     kapp->quit();
00599 }
00600 
00601 
00602 // -------------------- private methods -------------------- //
00603 
00604 void KNotesApp::showNote( KNote* note ) const
00605 {
00606     note->show();
00607     KWin::setCurrentDesktop( KWin::windowInfo( note->winId() ).desktop() );
00608     KWin::forceActiveWindow( note->winId() );
00609     note->setFocus();
00610 }
00611 
00612 void KNotesApp::createNote( KCal::Journal *journal )
00613 {
00614   if( journal->uid() == m_noteUidModify)
00615   {
00616          KNote *note = m_noteList[m_noteUidModify];
00617          if ( note )
00618                  note->changeJournal(journal);
00619 
00620          return;
00621   }
00622   m_noteUidModify = journal->uid();
00623     KNote *newNote = new KNote( m_noteGUI, journal, 0, journal->uid().utf8() );
00624     m_noteList.insert( newNote->noteId(), newNote );
00625 
00626     connect( newNote, SIGNAL(sigRequestNewNote()), SLOT(newNote()) );
00627     connect( newNote, SIGNAL(sigShowNextNote()), SLOT(slotWalkThroughNotes()) );
00628     connect( newNote, SIGNAL(sigKillNote( KCal::Journal* )),
00629                         SLOT(slotNoteKilled( KCal::Journal* )) );
00630     connect( newNote, SIGNAL(sigNameChanged()), SLOT(updateNoteActions()) );
00631     connect( newNote, SIGNAL(sigDataChanged(const QString &)), SLOT(saveNotes(const QString &)) );
00632     connect( newNote, SIGNAL(sigColorChanged()), SLOT(updateNoteActions()) );
00633     connect( newNote, SIGNAL(sigFindFinished()), SLOT(slotFindNext()) );
00634 
00635     // don't call this during startup for each and every loaded note
00636     if ( m_alarm )
00637         updateNoteActions();
00638 }
00639 
00640 void KNotesApp::killNote( KCal::Journal *journal )
00641 {
00642   if(m_noteUidModify == journal->uid())
00643   {
00644          return;
00645   }
00646     // this kills the KNote object
00647     KNote *note = m_noteList.take( journal->uid() );
00648     if ( note )
00649     {
00650         note->deleteWhenIdle();
00651         updateNoteActions();
00652     }
00653 }
00654 
00655 void KNotesApp::acceptConnection()
00656 {
00657     // Accept the connection and make KNotesNetworkReceiver do the job
00658     KBufferedSocket *s = static_cast<KBufferedSocket *>(m_listener->accept());
00659     if ( s )
00660     {
00661         KNotesNetworkReceiver *recv = new KNotesNetworkReceiver( s );
00662         connect( recv, SIGNAL(sigNoteReceived( const QString &, const QString & )),
00663                  this, SLOT(newNote( const QString &, const QString & )) );
00664     }
00665 }
00666 
00667 void KNotesApp::saveNotes( const QString & uid )
00668 {
00669   m_noteUidModify = uid;
00670   saveNotes();
00671 }
00672 
00673 void KNotesApp::saveNotes()
00674 {
00675     KNotesGlobalConfig::writeConfig();
00676     m_manager->save();
00677 }
00678 
00679 void KNotesApp::saveConfigs()
00680 {
00681     QDictIterator<KNote> it( m_noteList );
00682     for ( ; it.current(); ++it )
00683         it.current()->saveConfig();
00684 }
00685 
00686 void KNotesApp::updateNoteActions()
00687 {
00688     unplugActionList( "notes" );
00689     m_noteActions.clear();
00690 
00691     for ( QDictIterator<KNote> it( m_noteList ); it.current(); ++it )
00692     {
00693         KAction *action = new KAction( it.current()->name().replace("&", "&&"),
00694                                        KShortcut(), this, SLOT(slotShowNote()),
00695                                        (QObject *)0,
00696                                        it.current()->noteId().utf8() );
00697         KIconEffect effect;
00698         QPixmap icon = effect.apply( kapp->miniIcon(), KIconEffect::Colorize, 1,
00699                                      it.current()->paletteBackgroundColor(), false );
00700         action->setIconSet( icon );
00701         m_noteActions.append( action );
00702     }
00703 
00704     if ( m_noteActions.isEmpty() )
00705     {
00706         actionCollection()->action( "hide_all_notes" )->setEnabled( false );
00707         actionCollection()->action( "show_all_notes" )->setEnabled( false );
00708         m_findAction->setEnabled( false );
00709         KAction *action = new KAction( i18n("No Notes") );
00710         m_noteActions.append( action );
00711     }
00712     else
00713     {
00714         actionCollection()->action( "hide_all_notes" )->setEnabled( true );
00715         actionCollection()->action( "show_all_notes" )->setEnabled( true );
00716         m_findAction->setEnabled( true );
00717         m_noteActions.sort();
00718     }
00719     plugActionList( "notes", m_noteActions );
00720 }
00721 
00722 void KNotesApp::updateGlobalAccels()
00723 {
00724     if ( m_globalAccel->isEnabled() )
00725     {
00726         KAction *action = actionCollection()->action( "new_note" );
00727         if ( action )
00728             action->setShortcut( m_globalAccel->shortcut( "global_new_note" ) );
00729         action = actionCollection()->action( "new_note_clipboard" );
00730         if ( action )
00731             action->setShortcut( m_globalAccel->shortcut( "global_new_note_clipboard" ) );
00732         action = actionCollection()->action( "hide_all_notes" );
00733         if ( action )
00734             action->setShortcut( m_globalAccel->shortcut( "global_hide_all_notes" ) );
00735         action = actionCollection()->action( "show_all_notes" );
00736         if ( action )
00737             action->setShortcut( m_globalAccel->shortcut( "global_show_all_notes" ) );
00738 
00739         m_globalAccel->updateConnections();
00740     }
00741     else
00742     {
00743         KAction *action = actionCollection()->action( "new_note" );
00744         if ( action )
00745             action->setShortcut( 0 );
00746         action = actionCollection()->action( "new_note_clipboard" );
00747         if ( action )
00748             action->setShortcut( 0 );
00749         action = actionCollection()->action( "hide_all_notes" );
00750         if ( action )
00751             action->setShortcut( 0 );
00752         action = actionCollection()->action( "show_all_notes" );
00753         if ( action )
00754             action->setShortcut( 0 );
00755     }
00756 }
00757 
00758 void KNotesApp::updateNetworkListener()
00759 {
00760     m_listener->close();
00761 
00762     if ( KNotesGlobalConfig::receiveNotes() )
00763     {
00764         m_listener->setAddress( QString::number( KNotesGlobalConfig::port() ) );
00765         m_listener->bind();
00766         m_listener->listen();
00767     }
00768 }
00769 
00770 void KNotesApp::updateStyle()
00771 {
00772     KNote::setStyle( KNotesGlobalConfig::style() );
00773 
00774     QDictIterator<KNote> it( m_noteList );
00775     for ( ; it.current(); ++it )
00776         QApplication::postEvent( *it, new QEvent( QEvent::LayoutHint ) );
00777 }
00778 
00779 #include "knotesapp.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys