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 TQDateTime KNotesApp::getLastModified( const TQString& id ) const 00346 { 00347 KNote* note = m_noteList[id]; 00348 TQDateTime d; 00349 if ( note ) 00350 d = note->getLastModified(); 00351 return d; 00352 } 00353 00354 TQString KNotesApp::name( const TQString& id ) const 00355 { 00356 KNote* note = m_noteList[id]; 00357 if ( note ) 00358 return note->name(); 00359 else 00360 return TQString(); 00361 } 00362 00363 TQString KNotesApp::text( const TQString& id ) const 00364 { 00365 KNote* note = m_noteList[id]; 00366 if ( note ) 00367 return note->text(); 00368 else 00369 return TQString(); 00370 } 00371 00372 void KNotesApp::setName( const TQString& id, const TQString& newName ) 00373 { 00374 KNote* note = m_noteList[id]; 00375 if ( note ) 00376 note->setName( newName ); 00377 else 00378 kdWarning(5500) << "setName: no note with id: " << id << endl; 00379 } 00380 00381 void KNotesApp::setText( const TQString& id, const TQString& newText ) 00382 { 00383 KNote* note = m_noteList[id]; 00384 if ( note ) 00385 note->setText( newText ); 00386 else 00387 kdWarning(5500) << "setText: no note with id: " << id << endl; 00388 } 00389 00390 TQString KNotesApp::fgColor( const TQString& id ) const 00391 { 00392 KNote* note = m_noteList[id]; 00393 if ( note ) 00394 return note->fgColor().name(); 00395 else 00396 return TQString(); 00397 } 00398 00399 TQString KNotesApp::bgColor( const TQString& id ) const 00400 { 00401 KNote* note = m_noteList[id]; 00402 if ( note ) 00403 return note->bgColor().name(); 00404 else 00405 return TQString(); 00406 } 00407 00408 void KNotesApp::setColor( const TQString& id, const TQString& fgColor, const TQString& bgColor ) 00409 { 00410 KNote* note = m_noteList[id]; 00411 if ( note ) 00412 note->setColor( TQColor( fgColor ), TQColor( bgColor ) ); 00413 else 00414 kdWarning(5500) << "setColor: no note with id: " << id << endl; 00415 } 00416 00417 int KNotesApp::width( const TQString& id ) const 00418 { 00419 KNote* note = m_noteList[id]; 00420 if ( note ) 00421 return note->width(); 00422 else 00423 return 0; 00424 } 00425 00426 int KNotesApp::height( const TQString& id ) const 00427 { 00428 KNote* note = m_noteList[id]; 00429 if ( note ) 00430 return note->height(); 00431 else 00432 return 0; 00433 } 00434 00435 void KNotesApp::move( const TQString& id, int x, int y ) const 00436 { 00437 KNote* note = m_noteList[id]; 00438 if ( note ) 00439 return note->move( x, y ); 00440 else 00441 kdWarning(5500) << "move: no note with id: " << id << endl; 00442 } 00443 00444 void KNotesApp::resize( const TQString& id, int width, int height ) const 00445 { 00446 KNote* note = m_noteList[id]; 00447 if ( note ) 00448 return note->resize( width, height ); 00449 else 00450 kdWarning(5500) << "resize: no note with id: " << id << endl; 00451 } 00452 00453 void KNotesApp::sync( const TQString& app ) 00454 { 00455 TQDictIterator<KNote> it( m_noteList ); 00456 00457 for ( ; it.current(); ++it ) 00458 it.current()->sync( app ); 00459 } 00460 00461 bool KNotesApp::isNew( const TQString& app, const TQString& id ) const 00462 { 00463 KNote* note = m_noteList[id]; 00464 if ( note ) 00465 return note->isNew( app ); 00466 else 00467 return false; 00468 } 00469 00470 bool KNotesApp::isModified( const TQString& app, const TQString& id ) const 00471 { 00472 KNote* note = m_noteList[id]; 00473 if ( note ) 00474 return note->isModified( app ); 00475 else 00476 return false; 00477 } 00478 00479 00480 // ------------------- protected methods ------------------- // 00481 00482 void KNotesApp::mousePressEvent( TQMouseEvent* e ) 00483 { 00484 if ( !rect().contains( e->pos() ) ) 00485 return; 00486 00487 switch ( e->button() ) 00488 { 00489 case Qt::LeftButton: 00490 if ( m_noteList.count() == 1 ) 00491 { 00492 TQDictIterator<KNote> it( m_noteList ); 00493 showNote( it.toFirst() ); 00494 } 00495 else if ( m_note_menu->count() > 0 ) 00496 m_note_menu->popup( e->globalPos() ); 00497 break; 00498 case Qt::MidButton: 00499 newNote(); 00500 break; 00501 case Qt::RightButton: 00502 m_context_menu->popup( e->globalPos() ); 00503 default: break; 00504 } 00505 } 00506 00507 // -------------------- protected slots -------------------- // 00508 00509 void KNotesApp::slotShowNote() 00510 { 00511 // tell the WM to give this note focus 00512 showNote( TQString::fromUtf8( TQT_TQOBJECT(const_cast<TQT_BASE_OBJECT_NAME*>(sender()))->name() ) ); 00513 } 00514 00515 void KNotesApp::slotWalkThroughNotes() 00516 { 00517 // show next note 00518 TQDictIterator<KNote> it( m_noteList ); 00519 KNote *first = it.toFirst(); 00520 for ( ; *it; ++it ) 00521 if ( (*it)->hasFocus() ) 00522 { 00523 if ( ++it ) 00524 showNote( *it ); 00525 else 00526 showNote( first ); 00527 break; 00528 } 00529 } 00530 00531 void KNotesApp::slotOpenFindDialog() 00532 { 00533 KFindDialog findDia( this, "find_dialog" ); 00534 findDia.setHasSelection( false ); 00535 findDia.setHasCursor( false ); 00536 findDia.setSupportsBackwardsFind( false ); 00537 00538 if ( (findDia.exec() != TQDialog::Accepted) || findDia.pattern().isEmpty() ) 00539 return; 00540 00541 delete m_findPos; 00542 m_findPos = new TQDictIterator<KNote>( m_noteList ); 00543 00544 // this could be in an own method if searching without a dialog should be possible 00545 delete m_find; 00546 m_find = new KFind( findDia.pattern(), findDia.options(), this ); 00547 00548 slotFindNext(); 00549 } 00550 00551 void KNotesApp::slotFindNext() 00552 { 00553 if ( **m_findPos ) 00554 { 00555 KNote *note = **m_findPos; 00556 ++*m_findPos; 00557 note->find( m_find->pattern(), m_find->options() ); 00558 } 00559 else 00560 { 00561 m_find->displayFinalDialog(); 00562 delete m_find; 00563 m_find = 0; 00564 delete m_findPos; 00565 m_findPos = 0; 00566 } 00567 } 00568 00569 void KNotesApp::slotPreferences() 00570 { 00571 // reuse the dialog if possible 00572 if ( KNoteConfigDlg::showDialog( "KNotes Default Settings" ) ) 00573 return; 00574 00575 // create a new preferences dialog... 00576 KNoteConfigDlg *dialog = new KNoteConfigDlg( 0, i18n("Settings"), this, 00577 "KNotes Settings" ); 00578 connect( dialog, TQT_SIGNAL(settingsChanged()), TQT_TQOBJECT(this), TQT_SLOT(updateNetworkListener()) ); 00579 connect( dialog, TQT_SIGNAL(settingsChanged()), TQT_TQOBJECT(this), TQT_SLOT(updateStyle()) ); 00580 dialog->show(); 00581 } 00582 00583 void KNotesApp::slotConfigureAccels() 00584 { 00585 KNotesKeyDialog keys( m_globalAccel, this ); 00586 TQDictIterator<KNote> notes( m_noteList ); 00587 if ( !m_noteList.isEmpty() ) 00588 keys.insert( (*notes)->actionCollection() ); 00589 keys.configure(); 00590 00591 m_globalAccel->writeSettings(); 00592 updateGlobalAccels(); 00593 00594 // update GUI doc for new notes 00595 m_noteGUI.setContent( 00596 KXMLGUIFactory::readConfigFile( instance()->instanceName() + "ui.rc", instance() ) 00597 ); 00598 00599 if ( m_noteList.isEmpty() ) 00600 return; 00601 00602 notes.toFirst(); 00603 TQValueList<TDEAction *> list = (*notes)->actionCollection()->actions(); 00604 for ( TQValueList<TDEAction *>::iterator it = list.begin(); it != list.end(); ++it ) 00605 { 00606 notes.toFirst(); 00607 for ( ++notes; *notes; ++notes ) 00608 { 00609 TDEAction *toChange = (*notes)->actionCollection()->action( (*it)->name() ); 00610 if ( toChange->shortcut() != (*it)->shortcut() ) 00611 toChange->setShortcut( (*it)->shortcut() ); 00612 } 00613 } 00614 } 00615 00616 void KNotesApp::slotNoteKilled( KCal::Journal *journal ) 00617 { 00618 m_noteUidModify=""; 00619 m_manager->deleteNote( journal ); 00620 saveNotes(); 00621 } 00622 00623 void KNotesApp::slotQuit() 00624 { 00625 TQDictIterator<KNote> it( m_noteList ); 00626 00627 for ( ; *it; ++it ) 00628 if ( (*it)->isModified() ) 00629 (*it)->saveData(false); 00630 00631 saveConfigs(); 00632 kapp->quit(); 00633 } 00634 00635 00636 // -------------------- private methods -------------------- // 00637 00638 void KNotesApp::showNote( KNote* note ) const 00639 { 00640 note->show(); 00641 KWin::setCurrentDesktop( KWin::windowInfo( note->winId() ).desktop() ); 00642 KWin::forceActiveWindow( note->winId() ); 00643 note->setFocus(); 00644 } 00645 00646 void KNotesApp::createNote( KCal::Journal *journal ) 00647 { 00648 if( journal->uid() == m_noteUidModify) 00649 { 00650 KNote *note = m_noteList[m_noteUidModify]; 00651 if ( note ) 00652 note->changeJournal(journal); 00653 00654 return; 00655 } 00656 m_noteUidModify = journal->uid(); 00657 KNote *newNote = new KNote( m_noteGUI, journal, 0, journal->uid().utf8() ); 00658 m_noteList.insert( newNote->noteId(), newNote ); 00659 00660 connect( newNote, TQT_SIGNAL(sigRequestNewNote()), TQT_SLOT(newNote()) ); 00661 connect( newNote, TQT_SIGNAL(sigShowNextNote()), TQT_SLOT(slotWalkThroughNotes()) ); 00662 connect( newNote, TQT_SIGNAL(sigKillNote( KCal::Journal* )), 00663 TQT_SLOT(slotNoteKilled( KCal::Journal* )) ); 00664 connect( newNote, TQT_SIGNAL(sigNameChanged()), TQT_SLOT(updateNoteActions()) ); 00665 connect( newNote, TQT_SIGNAL(sigDataChanged(const TQString &)), TQT_SLOT(saveNotes(const TQString &)) ); 00666 connect( newNote, TQT_SIGNAL(sigColorChanged()), TQT_SLOT(updateNoteActions()) ); 00667 connect( newNote, TQT_SIGNAL(sigFindFinished()), TQT_SLOT(slotFindNext()) ); 00668 00669 // don't call this during startup for each and every loaded note 00670 if ( m_alarm ) 00671 updateNoteActions(); 00672 } 00673 00674 void KNotesApp::killNote( KCal::Journal *journal ) 00675 { 00676 if(m_noteUidModify == journal->uid()) 00677 { 00678 return; 00679 } 00680 // this kills the KNote object 00681 KNote *note = m_noteList.take( journal->uid() ); 00682 if ( note ) 00683 { 00684 note->deleteWhenIdle(); 00685 updateNoteActions(); 00686 } 00687 } 00688 00689 void KNotesApp::acceptConnection() 00690 { 00691 // Accept the connection and make KNotesNetworkReceiver do the job 00692 TDEBufferedSocket *s = static_cast<TDEBufferedSocket *>(m_listener->accept()); 00693 if ( s ) 00694 { 00695 KNotesNetworkReceiver *recv = new KNotesNetworkReceiver( s ); 00696 connect( recv, TQT_SIGNAL(sigNoteReceived( const TQString &, const TQString & )), 00697 TQT_TQOBJECT(this), TQT_SLOT(newNote( const TQString &, const TQString & )) ); 00698 } 00699 } 00700 00701 void KNotesApp::saveNotes( const TQString & uid ) 00702 { 00703 m_noteUidModify = uid; 00704 saveNotes(); 00705 } 00706 00707 void KNotesApp::saveNotes() 00708 { 00709 KNotesGlobalConfig::writeConfig(); 00710 m_manager->save(); 00711 } 00712 00713 void KNotesApp::saveConfigs() 00714 { 00715 TQDictIterator<KNote> it( m_noteList ); 00716 for ( ; it.current(); ++it ) 00717 it.current()->saveConfig(); 00718 } 00719 00720 void KNotesApp::updateNoteActions() 00721 { 00722 unplugActionList( "notes" ); 00723 m_noteActions.clear(); 00724 00725 for ( TQDictIterator<KNote> it( m_noteList ); it.current(); ++it ) 00726 { 00727 TDEAction *action = new TDEAction( it.current()->name().replace("&", "&&"), 00728 TDEShortcut(), TQT_TQOBJECT(this), TQT_SLOT(slotShowNote()), 00729 (TQObject *)0, 00730 it.current()->noteId().utf8() ); 00731 TDEIconEffect effect; 00732 TQPixmap icon = effect.apply( kapp->miniIcon(), TDEIconEffect::Colorize, 1, 00733 it.current()->paletteBackgroundColor(), false ); 00734 action->setIconSet( icon ); 00735 m_noteActions.append( action ); 00736 } 00737 00738 if ( m_noteActions.isEmpty() ) 00739 { 00740 actionCollection()->action( "hide_all_notes" )->setEnabled( false ); 00741 actionCollection()->action( "show_all_notes" )->setEnabled( false ); 00742 m_findAction->setEnabled( false ); 00743 TDEAction *action = new TDEAction( i18n("No Notes") ); 00744 m_noteActions.append( action ); 00745 } 00746 else 00747 { 00748 actionCollection()->action( "hide_all_notes" )->setEnabled( true ); 00749 actionCollection()->action( "show_all_notes" )->setEnabled( true ); 00750 m_findAction->setEnabled( true ); 00751 m_noteActions.sort(); 00752 } 00753 plugActionList( "notes", m_noteActions ); 00754 } 00755 00756 void KNotesApp::updateGlobalAccels() 00757 { 00758 if ( m_globalAccel->isEnabled() ) 00759 { 00760 TDEAction *action = actionCollection()->action( "new_note" ); 00761 if ( action ) 00762 action->setShortcut( m_globalAccel->shortcut( "global_new_note" ) ); 00763 action = actionCollection()->action( "new_note_clipboard" ); 00764 if ( action ) 00765 action->setShortcut( m_globalAccel->shortcut( "global_new_note_clipboard" ) ); 00766 action = actionCollection()->action( "hide_all_notes" ); 00767 if ( action ) 00768 action->setShortcut( m_globalAccel->shortcut( "global_hide_all_notes" ) ); 00769 action = actionCollection()->action( "show_all_notes" ); 00770 if ( action ) 00771 action->setShortcut( m_globalAccel->shortcut( "global_show_all_notes" ) ); 00772 00773 m_globalAccel->updateConnections(); 00774 } 00775 else 00776 { 00777 TDEAction *action = actionCollection()->action( "new_note" ); 00778 if ( action ) 00779 action->setShortcut( 0 ); 00780 action = actionCollection()->action( "new_note_clipboard" ); 00781 if ( action ) 00782 action->setShortcut( 0 ); 00783 action = actionCollection()->action( "hide_all_notes" ); 00784 if ( action ) 00785 action->setShortcut( 0 ); 00786 action = actionCollection()->action( "show_all_notes" ); 00787 if ( action ) 00788 action->setShortcut( 0 ); 00789 } 00790 } 00791 00792 void KNotesApp::updateNetworkListener() 00793 { 00794 m_listener->close(); 00795 00796 if ( KNotesGlobalConfig::receiveNotes() ) 00797 { 00798 m_listener->setAddress( TQString::number( KNotesGlobalConfig::port() ) ); 00799 m_listener->bind(); 00800 m_listener->listen(); 00801 } 00802 } 00803 00804 void KNotesApp::updateStyle() 00805 { 00806 KNote::setStyle( KNotesGlobalConfig::style() ); 00807 00808 TQDictIterator<KNote> it( m_noteList ); 00809 for ( ; it.current(); ++it ) 00810 TQApplication::postEvent( *it, new TQEvent( TQEvent::LayoutHint ) ); 00811 } 00812 00813 #include "knotesapp.moc"
