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