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 <tqclipboard.h>
00022 #include <tqptrlist.h>
00023 #include <tqtooltip.h>
00024 
00025 #include <kdebug.h>
00026 #include <tdeaction.h>
00027 #include <kxmlguifactory.h>
00028 #include <kxmlguibuilder.h>
00029 #include <ksystemtray.h>
00030 #include <tdelocale.h>
00031 #include <kiconeffect.h>
00032 #include <kstandarddirs.h>
00033 #include <tdepopupmenu.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 <twin.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( TDEGlobalAccel *globals, TQWidget *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, TQT_SIGNAL(defaultClicked()), m_keyChooser, TQT_SLOT(allDefault()) );
00069     }
00070 
00071     void insert( TDEActionCollection *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( TQPtrCollection::Item s1, TQPtrCollection::Item s2 )
00088 {
00089     if ( ((TDEAction*)s1)->text() == ((TDEAction*)s2)->text() )
00090         return 0;
00091     return ( ((TDEAction*)s1)->text() < ((TDEAction*)s2)->text() ? -1 : 1 );
00092 }
00093 
00094 
00095 KNotesApp::KNotesApp()
00096     : DCOPObject("KNotesIface"), TQLabel( 0, 0, WType_TopLevel ),
00097       m_alarm( 0 ), m_listener( 0 ), m_find( 0 ), m_findPos( 0 )
00098 {
00099     connect( kapp, TQT_SIGNAL(lastWindowClosed()), kapp, TQT_SLOT(quit()) );
00100 
00101     m_noteList.setAutoDelete( true );
00102     m_noteActions.setAutoDelete( true );
00103 
00104     // create the dock widget...
00105     KWin::setSystemTrayWindowFor( winId(), tqt_xrootwin() );
00106     TQToolTip::add( this, i18n( "KNotes: Sticky notes for TDE" ) );
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 TDEAction( i18n("New Note"), "document-new", 0,
00115         TQT_TQOBJECT(this), TQT_SLOT(newNote()), actionCollection(), "new_note" );
00116     new TDEAction( i18n("New Note From Clipboard"), "edit-paste", 0,
00117         TQT_TQOBJECT(this), TQT_SLOT(newNoteFromClipboard()), actionCollection(), "new_note_clipboard" );
00118     new TDEAction( i18n("Show All Notes"), "knotes", 0,
00119         TQT_TQOBJECT(this), TQT_SLOT(showAllNotes()), actionCollection(), "show_all_notes" );
00120     new TDEAction( i18n("Hide All Notes"), "window-close", 0,
00121         TQT_TQOBJECT(this), TQT_SLOT(hideAllNotes()), actionCollection(), "hide_all_notes" );
00122     new KHelpMenu( this, kapp->aboutData(), false, actionCollection() );
00123 
00124     m_findAction = KStdAction::find( TQT_TQOBJECT(this), TQT_SLOT(slotOpenFindDialog()), actionCollection() );
00125     KStdAction::preferences( TQT_TQOBJECT(this), TQT_SLOT(slotPreferences()), actionCollection() );
00126     KStdAction::keyBindings( TQT_TQOBJECT(this), TQT_SLOT(slotConfigureAccels()), actionCollection() );
00127     //FIXME: no shortcut removing!?
00128     KStdAction::quit( TQT_TQOBJECT(this), TQT_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, TQT_TQOBJECT(this) );
00134     m_guiFactory->addClient( this );
00135 
00136     m_context_menu = static_cast<TDEPopupMenu*>(m_guiFactory->container( "knotes_context", this ));
00137     m_note_menu = static_cast<TDEPopupMenu*>(m_guiFactory->container( "notes_menu", this ));
00138 
00139     // get the most recent XML UI file
00140     TQString xmlFileName = instance()->instanceName() + "ui.rc";
00141     TQString filter = TQString::fromLatin1( instance()->instanceName() + '/' ) + xmlFileName;
00142     TQStringList fileList = instance()->dirs()->findAllResources( "data", filter ) +
00143                            instance()->dirs()->findAllResources( "data", xmlFileName );
00144 
00145     TQString doc;
00146     KXMLGUIClient::findMostRecentXMLFile( fileList, doc );
00147     m_noteGUI.setContent( doc );
00148 
00149     // create accels for global shortcuts
00150     m_globalAccel = new TDEGlobalAccel( TQT_TQOBJECT(this), "global accel" );
00151     m_globalAccel->insert( "global_new_note", i18n("New Note"), "",
00152                            ALT+SHIFT+Key_N, ALT+SHIFT+Key_N ,
00153                            TQT_TQOBJECT(this), TQT_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                            TQT_TQOBJECT(this), TQT_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                            TQT_TQOBJECT(this), TQT_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                            TQT_TQOBJECT(this), TQT_SLOT(showAllNotes()), true, true );
00163 
00164     m_globalAccel->readSettings();
00165 
00166     TDEConfig *config = TDEGlobal::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, TQT_SIGNAL(sigRegisteredNote( KCal::Journal * )),
00178              this,      TQT_SLOT(createNote( KCal::Journal * )) );
00179     connect( m_manager, TQT_SIGNAL(sigDeregisteredNote( KCal::Journal * )),
00180              this,      TQT_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( TQString::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, TQT_TQOBJECT(this) );
00200 
00201     // create the socket and possibly start listening for connections
00202     m_listener = new TDEServerSocket();
00203     m_listener->setResolutionEnabled( true );
00204     connect( m_listener, TQT_SIGNAL(readyAccept()), TQT_SLOT(acceptConnection()) );
00205     updateNetworkListener();
00206 
00207     if ( m_noteList.count() == 0 && !kapp->isRestored() )
00208         newNote();
00209 
00210     updateNoteActions();
00211 }
00212 
00213 void KNotesApp::resizeTrayIcon ()
00214 {
00215     // Honor Free Desktop specifications that allow for arbitrary system tray icon sizes
00216     TQPixmap origpixmap;
00217     TQPixmap scaledpixmap;
00218     TQImage newIcon;
00219     origpixmap = KSystemTray::loadSizedIcon( "knotes", TQWidget::width() );
00220     newIcon = origpixmap;
00221     newIcon = newIcon.smoothScale(TQWidget::width(), TQWidget::height());
00222     scaledpixmap = newIcon;
00223     setPixmap(scaledpixmap);
00224 }
00225 
00226 void KNotesApp::resizeEvent ( TQResizeEvent * )
00227 {
00228     // Honor Free Desktop specifications that allow for arbitrary system tray icon sizes
00229     resizeTrayIcon();
00230 }
00231 
00232 void KNotesApp::showEvent ( TQShowEvent * )
00233 {
00234     // Honor Free Desktop specifications that allow for arbitrary system tray icon sizes
00235     resizeTrayIcon();
00236 }
00237 
00238 KNotesApp::~KNotesApp()
00239 {
00240     saveNotes();
00241 
00242     blockSignals( true );
00243     m_noteList.clear();
00244     blockSignals( false );
00245 
00246     delete m_listener;
00247     delete m_manager;
00248     delete m_guiBuilder;
00249 }
00250 
00251 bool KNotesApp::commitData( TQSessionManager& )
00252 {
00253     saveConfigs();
00254     return true;
00255 }
00256 
00257 // -------------------- public DCOP interface -------------------- //
00258 
00259 TQString KNotesApp::newNote( const TQString& name, const TQString& text )
00260 {
00261     // create the new note
00262     KCal::Journal *journal = new KCal::Journal();
00263 
00264     // new notes have the current date/time as title if none was given
00265     if ( !name.isEmpty() )
00266         journal->setSummary( name );
00267     else
00268         journal->setSummary( TDEGlobal::locale()->formatDateTime( TQDateTime::currentDateTime() ) );
00269 
00270     // the body of the note
00271     journal->setDescription( text );
00272 
00273     if ( m_manager->addNewNote( journal ) ) {
00274         showNote( journal->uid() );
00275     }
00276     return journal->uid();
00277 }
00278 
00279 TQString KNotesApp::newNoteFromClipboard( const TQString& name )
00280 {
00281     const TQString& text = TDEApplication::clipboard()->text();
00282     return newNote( name, text );
00283 }
00284 
00285 void KNotesApp::hideAllNotes() const
00286 {
00287     TQDictIterator<KNote> it( m_noteList );
00288     for ( ; *it; ++it )
00289         (*it)->close();
00290 }
00291 
00292 void KNotesApp::showAllNotes() const
00293 {
00294     TQDictIterator<KNote> it( m_noteList );
00295     for ( ; *it; ++it )
00296     {
00297         (*it)->show();
00298     }
00299 }
00300 
00301 void KNotesApp::showNote( const TQString& id ) const
00302 {
00303     KNote* note = m_noteList[id];
00304     if ( note )
00305         showNote( note );
00306     else
00307         kdWarning(5500) << "showNote: no note with id: " << id << endl;
00308 }
00309 
00310 void KNotesApp::hideNote( const TQString& id ) const
00311 {
00312     KNote* note = m_noteList[id];
00313     if ( note )
00314         note->hide();
00315     else
00316         kdWarning(5500) << "hideNote: no note with id: " << id << endl;
00317 }
00318 
00319 void KNotesApp::killNote( const TQString& id, bool force )
00320 {
00321     KNote* note = m_noteList[id];
00322     if ( note )
00323         note->slotKill( force );
00324     else
00325         kdWarning(5500) << "killNote: no note with id: " << id << endl;
00326 }
00327 
00328 // "bool force = false" doesn't work with dcop
00329 void KNotesApp::killNote( const TQString& id )
00330 {
00331     killNote( id, false );
00332 }
00333 
00334 TQMap<TQString,TQString> KNotesApp::notes() const
00335 {
00336     TQMap<TQString,TQString> notes;
00337     TQDictIterator<KNote> it( m_noteList );
00338 
00339     for ( ; it.current(); ++it )
00340         notes.insert( it.current()->noteId(), it.current()->name() );
00341 
00342     return notes;
00343 }
00344 
00345 TQString KNotesApp::name( const TQString& id ) const
00346 {
00347     KNote* note = m_noteList[id];
00348     if ( note )
00349         return note->name();
00350     else
00351         return TQString();
00352 }
00353 
00354 TQString KNotesApp::text( const TQString& id ) const
00355 {
00356     KNote* note = m_noteList[id];
00357     if ( note )
00358         return note->text();
00359     else
00360         return TQString();
00361 }
00362 
00363 void KNotesApp::setName( const TQString& id, const TQString& newName )
00364 {
00365     KNote* note = m_noteList[id];
00366     if ( note )
00367         note->setName( newName );
00368     else
00369         kdWarning(5500) << "setName: no note with id: " << id << endl;
00370 }
00371 
00372 void KNotesApp::setText( const TQString& id, const TQString& newText )
00373 {
00374     KNote* note = m_noteList[id];
00375     if ( note )
00376         note->setText( newText );
00377     else
00378         kdWarning(5500) << "setText: no note with id: " << id << endl;
00379 }
00380 
00381 TQString KNotesApp::fgColor( const TQString& id ) const
00382 {
00383     KNote* note = m_noteList[id];
00384     if ( note )
00385         return note->fgColor().name();
00386     else
00387         return TQString();
00388 }
00389 
00390 TQString KNotesApp::bgColor( const TQString& id ) const
00391 {
00392     KNote* note = m_noteList[id];
00393     if ( note )
00394         return note->bgColor().name();
00395     else
00396         return TQString();
00397 }
00398 
00399 void KNotesApp::setColor( const TQString& id, const TQString& fgColor, const TQString& bgColor )
00400 {
00401     KNote* note = m_noteList[id];
00402     if ( note )
00403         note->setColor( TQColor( fgColor ), TQColor( bgColor ) );
00404     else
00405         kdWarning(5500) << "setColor: no note with id: " << id << endl;
00406 }
00407 
00408 int KNotesApp::width( const TQString& id ) const
00409 {
00410     KNote* note = m_noteList[id];
00411     if ( note )
00412         return note->width();
00413     else
00414         return 0;
00415 }
00416 
00417 int KNotesApp::height( const TQString& id ) const
00418 {
00419     KNote* note = m_noteList[id];
00420     if ( note )
00421         return note->height();
00422     else
00423         return 0;
00424 }
00425 
00426 void KNotesApp::move( const TQString& id, int x, int y ) const
00427 {
00428     KNote* note = m_noteList[id];
00429     if ( note )
00430         return note->move( x, y );
00431     else
00432         kdWarning(5500) << "move: no note with id: " << id << endl;
00433 }
00434 
00435 void KNotesApp::resize( const TQString& id, int width, int height ) const
00436 {
00437     KNote* note = m_noteList[id];
00438     if ( note )
00439         return note->resize( width, height );
00440     else
00441         kdWarning(5500) << "resize: no note with id: " << id << endl;
00442 }
00443 
00444 void KNotesApp::sync( const TQString& app )
00445 {
00446     TQDictIterator<KNote> it( m_noteList );
00447 
00448     for ( ; it.current(); ++it )
00449         it.current()->sync( app );
00450 }
00451 
00452 bool KNotesApp::isNew( const TQString& app, const TQString& id ) const
00453 {
00454     KNote* note = m_noteList[id];
00455     if ( note )
00456         return note->isNew( app );
00457     else
00458         return false;
00459 }
00460 
00461 bool KNotesApp::isModified( const TQString& app, const TQString& id ) const
00462 {
00463     KNote* note = m_noteList[id];
00464     if ( note )
00465         return note->isModified( app );
00466     else
00467         return false;
00468 }
00469 
00470 
00471 // ------------------- protected methods ------------------- //
00472 
00473 void KNotesApp::mousePressEvent( TQMouseEvent* e )
00474 {
00475     if ( !rect().contains( e->pos() ) )
00476         return;
00477 
00478     switch ( e->button() )
00479     {
00480     case Qt::LeftButton:
00481         if ( m_noteList.count() == 1 )
00482         {
00483             TQDictIterator<KNote> it( m_noteList );
00484             showNote( it.toFirst() );
00485         }
00486         else if ( m_note_menu->count() > 0 )
00487             m_note_menu->popup( e->globalPos() );
00488         break;
00489     case Qt::MidButton:
00490         newNote();
00491         break;
00492     case Qt::RightButton:
00493         m_context_menu->popup( e->globalPos() );
00494     default: break;
00495     }
00496 }
00497 
00498 // -------------------- protected slots -------------------- //
00499 
00500 void KNotesApp::slotShowNote()
00501 {
00502     // tell the WM to give this note focus
00503     showNote( TQString::fromUtf8( TQT_TQOBJECT(const_cast<TQT_BASE_OBJECT_NAME*>(sender()))->name() ) );
00504 }
00505 
00506 void KNotesApp::slotWalkThroughNotes()
00507 {
00508     // show next note
00509     TQDictIterator<KNote> it( m_noteList );
00510     KNote *first = it.toFirst();
00511     for ( ; *it; ++it )
00512         if ( (*it)->hasFocus() )
00513         {
00514             if ( ++it )
00515                 showNote( *it );
00516             else
00517                 showNote( first );
00518             break;
00519         }
00520 }
00521 
00522 void KNotesApp::slotOpenFindDialog()
00523 {
00524     KFindDialog findDia( this, "find_dialog" );
00525     findDia.setHasSelection( false );
00526     findDia.setHasCursor( false );
00527     findDia.setSupportsBackwardsFind( false );
00528 
00529     if ( (findDia.exec() != TQDialog::Accepted) || findDia.pattern().isEmpty() )
00530         return;
00531 
00532     delete m_findPos;
00533     m_findPos = new TQDictIterator<KNote>( m_noteList );
00534 
00535     // this could be in an own method if searching without a dialog should be possible
00536     delete m_find;
00537     m_find = new KFind( findDia.pattern(), findDia.options(), this );
00538 
00539     slotFindNext();
00540 }
00541 
00542 void KNotesApp::slotFindNext()
00543 {
00544     if ( **m_findPos )
00545     {
00546         KNote *note = **m_findPos;
00547         ++*m_findPos;
00548         note->find( m_find->pattern(), m_find->options() );
00549     }
00550     else
00551     {
00552         m_find->displayFinalDialog();
00553         delete m_find;
00554         m_find = 0;
00555         delete m_findPos;
00556         m_findPos = 0;
00557     }
00558 }
00559 
00560 void KNotesApp::slotPreferences()
00561 {
00562     // reuse the dialog if possible
00563     if ( KNoteConfigDlg::showDialog( "KNotes Default Settings" ) )
00564         return;
00565 
00566     // create a new preferences dialog...
00567     KNoteConfigDlg *dialog = new KNoteConfigDlg( 0, i18n("Settings"), this,
00568                                                  "KNotes Settings" );
00569     connect( dialog, TQT_SIGNAL(settingsChanged()), TQT_TQOBJECT(this), TQT_SLOT(updateNetworkListener()) );
00570     connect( dialog, TQT_SIGNAL(settingsChanged()), TQT_TQOBJECT(this), TQT_SLOT(updateStyle()) );
00571     dialog->show();
00572 }
00573 
00574 void KNotesApp::slotConfigureAccels()
00575 {
00576     KNotesKeyDialog keys( m_globalAccel, this );
00577     TQDictIterator<KNote> notes( m_noteList );
00578     if ( !m_noteList.isEmpty() )
00579         keys.insert( (*notes)->actionCollection() );
00580     keys.configure();
00581 
00582     m_globalAccel->writeSettings();
00583     updateGlobalAccels();
00584 
00585     // update GUI doc for new notes
00586     m_noteGUI.setContent(
00587         KXMLGUIFactory::readConfigFile( instance()->instanceName() + "ui.rc", instance() )
00588     );
00589 
00590     if ( m_noteList.isEmpty() )
00591         return;
00592 
00593     notes.toFirst();
00594     TQValueList<TDEAction *> list = (*notes)->actionCollection()->actions();
00595     for ( TQValueList<TDEAction *>::iterator it = list.begin(); it != list.end(); ++it )
00596     {
00597         notes.toFirst();
00598         for ( ++notes; *notes; ++notes )
00599         {
00600             TDEAction *toChange = (*notes)->actionCollection()->action( (*it)->name() );
00601             if ( toChange->shortcut() != (*it)->shortcut() )
00602                 toChange->setShortcut( (*it)->shortcut() );
00603         }
00604     }
00605 }
00606 
00607 void KNotesApp::slotNoteKilled( KCal::Journal *journal )
00608 {
00609     m_noteUidModify="";
00610     m_manager->deleteNote( journal );
00611     saveNotes();
00612 }
00613 
00614 void KNotesApp::slotQuit()
00615 {
00616     TQDictIterator<KNote> it( m_noteList );
00617 
00618     for ( ; *it; ++it )
00619         if ( (*it)->isModified() )
00620             (*it)->saveData(false);
00621 
00622     saveConfigs();
00623     kapp->quit();
00624 }
00625 
00626 
00627 // -------------------- private methods -------------------- //
00628 
00629 void KNotesApp::showNote( KNote* note ) const
00630 {
00631     note->show();
00632     KWin::setCurrentDesktop( KWin::windowInfo( note->winId() ).desktop() );
00633     KWin::forceActiveWindow( note->winId() );
00634     note->setFocus();
00635 }
00636 
00637 void KNotesApp::createNote( KCal::Journal *journal )
00638 {
00639   if( journal->uid() == m_noteUidModify)
00640   {
00641          KNote *note = m_noteList[m_noteUidModify];
00642          if ( note )
00643                  note->changeJournal(journal);
00644 
00645          return;
00646   }
00647   m_noteUidModify = journal->uid();
00648     KNote *newNote = new KNote( m_noteGUI, journal, 0, journal->uid().utf8() );
00649     m_noteList.insert( newNote->noteId(), newNote );
00650 
00651     connect( newNote, TQT_SIGNAL(sigRequestNewNote()), TQT_SLOT(newNote()) );
00652     connect( newNote, TQT_SIGNAL(sigShowNextNote()), TQT_SLOT(slotWalkThroughNotes()) );
00653     connect( newNote, TQT_SIGNAL(sigKillNote( KCal::Journal* )),
00654                         TQT_SLOT(slotNoteKilled( KCal::Journal* )) );
00655     connect( newNote, TQT_SIGNAL(sigNameChanged()), TQT_SLOT(updateNoteActions()) );
00656     connect( newNote, TQT_SIGNAL(sigDataChanged(const TQString &)), TQT_SLOT(saveNotes(const TQString &)) );
00657     connect( newNote, TQT_SIGNAL(sigColorChanged()), TQT_SLOT(updateNoteActions()) );
00658     connect( newNote, TQT_SIGNAL(sigFindFinished()), TQT_SLOT(slotFindNext()) );
00659 
00660     // don't call this during startup for each and every loaded note
00661     if ( m_alarm )
00662         updateNoteActions();
00663 }
00664 
00665 void KNotesApp::killNote( KCal::Journal *journal )
00666 {
00667   if(m_noteUidModify == journal->uid())
00668   {
00669          return;
00670   }
00671     // this kills the KNote object
00672     KNote *note = m_noteList.take( journal->uid() );
00673     if ( note )
00674     {
00675         note->deleteWhenIdle();
00676         updateNoteActions();
00677     }
00678 }
00679 
00680 void KNotesApp::acceptConnection()
00681 {
00682     // Accept the connection and make KNotesNetworkReceiver do the job
00683     TDEBufferedSocket *s = static_cast<TDEBufferedSocket *>(m_listener->accept());
00684     if ( s )
00685     {
00686         KNotesNetworkReceiver *recv = new KNotesNetworkReceiver( s );
00687         connect( recv, TQT_SIGNAL(sigNoteReceived( const TQString &, const TQString & )),
00688                  TQT_TQOBJECT(this), TQT_SLOT(newNote( const TQString &, const TQString & )) );
00689     }
00690 }
00691 
00692 void KNotesApp::saveNotes( const TQString & uid )
00693 {
00694   m_noteUidModify = uid;
00695   saveNotes();
00696 }
00697 
00698 void KNotesApp::saveNotes()
00699 {
00700     KNotesGlobalConfig::writeConfig();
00701     m_manager->save();
00702 }
00703 
00704 void KNotesApp::saveConfigs()
00705 {
00706     TQDictIterator<KNote> it( m_noteList );
00707     for ( ; it.current(); ++it )
00708         it.current()->saveConfig();
00709 }
00710 
00711 void KNotesApp::updateNoteActions()
00712 {
00713     unplugActionList( "notes" );
00714     m_noteActions.clear();
00715 
00716     for ( TQDictIterator<KNote> it( m_noteList ); it.current(); ++it )
00717     {
00718         TDEAction *action = new TDEAction( it.current()->name().replace("&", "&&"),
00719                                        TDEShortcut(), TQT_TQOBJECT(this), TQT_SLOT(slotShowNote()),
00720                                        (TQObject *)0,
00721                                        it.current()->noteId().utf8() );
00722         TDEIconEffect effect;
00723         TQPixmap icon = effect.apply( kapp->miniIcon(), TDEIconEffect::Colorize, 1,
00724                                      it.current()->paletteBackgroundColor(), false );
00725         action->setIconSet( icon );
00726         m_noteActions.append( action );
00727     }
00728 
00729     if ( m_noteActions.isEmpty() )
00730     {
00731         actionCollection()->action( "hide_all_notes" )->setEnabled( false );
00732         actionCollection()->action( "show_all_notes" )->setEnabled( false );
00733         m_findAction->setEnabled( false );
00734         TDEAction *action = new TDEAction( i18n("No Notes") );
00735         m_noteActions.append( action );
00736     }
00737     else
00738     {
00739         actionCollection()->action( "hide_all_notes" )->setEnabled( true );
00740         actionCollection()->action( "show_all_notes" )->setEnabled( true );
00741         m_findAction->setEnabled( true );
00742         m_noteActions.sort();
00743     }
00744     plugActionList( "notes", m_noteActions );
00745 }
00746 
00747 void KNotesApp::updateGlobalAccels()
00748 {
00749     if ( m_globalAccel->isEnabled() )
00750     {
00751         TDEAction *action = actionCollection()->action( "new_note" );
00752         if ( action )
00753             action->setShortcut( m_globalAccel->shortcut( "global_new_note" ) );
00754         action = actionCollection()->action( "new_note_clipboard" );
00755         if ( action )
00756             action->setShortcut( m_globalAccel->shortcut( "global_new_note_clipboard" ) );
00757         action = actionCollection()->action( "hide_all_notes" );
00758         if ( action )
00759             action->setShortcut( m_globalAccel->shortcut( "global_hide_all_notes" ) );
00760         action = actionCollection()->action( "show_all_notes" );
00761         if ( action )
00762             action->setShortcut( m_globalAccel->shortcut( "global_show_all_notes" ) );
00763 
00764         m_globalAccel->updateConnections();
00765     }
00766     else
00767     {
00768         TDEAction *action = actionCollection()->action( "new_note" );
00769         if ( action )
00770             action->setShortcut( 0 );
00771         action = actionCollection()->action( "new_note_clipboard" );
00772         if ( action )
00773             action->setShortcut( 0 );
00774         action = actionCollection()->action( "hide_all_notes" );
00775         if ( action )
00776             action->setShortcut( 0 );
00777         action = actionCollection()->action( "show_all_notes" );
00778         if ( action )
00779             action->setShortcut( 0 );
00780     }
00781 }
00782 
00783 void KNotesApp::updateNetworkListener()
00784 {
00785     m_listener->close();
00786 
00787     if ( KNotesGlobalConfig::receiveNotes() )
00788     {
00789         m_listener->setAddress( TQString::number( KNotesGlobalConfig::port() ) );
00790         m_listener->bind();
00791         m_listener->listen();
00792     }
00793 }
00794 
00795 void KNotesApp::updateStyle()
00796 {
00797     KNote::setStyle( KNotesGlobalConfig::style() );
00798 
00799     TQDictIterator<KNote> it( m_noteList );
00800     for ( ; it.current(); ++it )
00801         TQApplication::postEvent( *it, new TQEvent( TQEvent::LayoutHint ) );
00802 }
00803 
00804 #include "knotesapp.moc"