TDE personal information management applications
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

814 lines
24 KiB

  1. /*******************************************************************
  2. KNotes -- Notes for the KDE project
  3. Copyright (c) 1997-2006, The KNotes Developers
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  15. *******************************************************************/
  16. #include <tqclipboard.h>
  17. #include <tqptrlist.h>
  18. #include <tqtooltip.h>
  19. #include <kdebug.h>
  20. #include <tdeaction.h>
  21. #include <kxmlguifactory.h>
  22. #include <kxmlguibuilder.h>
  23. #include <ksystemtray.h>
  24. #include <tdelocale.h>
  25. #include <kiconeffect.h>
  26. #include <kstandarddirs.h>
  27. #include <tdepopupmenu.h>
  28. #include <khelpmenu.h>
  29. #include <kfind.h>
  30. #include <kfinddialog.h>
  31. #include <kkeydialog.h>
  32. #include <kglobalaccel.h>
  33. #include <ksimpleconfig.h>
  34. #include <twin.h>
  35. #include <kbufferedsocket.h>
  36. #include <kserversocket.h>
  37. #include <libkcal/journal.h>
  38. #include <libkcal/calendarlocal.h>
  39. #include "knotesapp.h"
  40. #include "knote.h"
  41. #include "knotesalarm.h"
  42. #include "knoteconfigdlg.h"
  43. #include "knotesglobalconfig.h"
  44. #include "knoteslegacy.h"
  45. #include "knotesnetrecv.h"
  46. #include "knotes/resourcemanager.h"
  47. using namespace KNetwork;
  48. class KNotesKeyDialog : public KDialogBase
  49. {
  50. public:
  51. KNotesKeyDialog( TDEGlobalAccel *globals, TQWidget *parent, const char* name = 0 )
  52. : KDialogBase( parent, name, true, i18n("Configure Shortcuts"), Default|Ok|Cancel, Ok )
  53. {
  54. m_keyChooser = new KKeyChooser( globals, this );
  55. setMainWidget( m_keyChooser );
  56. connect( this, TQT_SIGNAL(defaultClicked()), m_keyChooser, TQT_SLOT(allDefault()) );
  57. }
  58. void insert( TDEActionCollection *actions )
  59. {
  60. m_keyChooser->insert( actions, i18n("Note Actions") );
  61. }
  62. void configure()
  63. {
  64. if ( exec() == Accepted )
  65. m_keyChooser->save();
  66. }
  67. private:
  68. KKeyChooser *m_keyChooser;
  69. };
  70. int KNotesApp::KNoteActionList::compareItems( TQPtrCollection::Item s1, TQPtrCollection::Item s2 )
  71. {
  72. if ( ((TDEAction*)s1)->text() == ((TDEAction*)s2)->text() )
  73. return 0;
  74. return ( ((TDEAction*)s1)->text() < ((TDEAction*)s2)->text() ? -1 : 1 );
  75. }
  76. KNotesApp::KNotesApp()
  77. : DCOPObject("KNotesIface"), TQLabel( 0, 0, WType_TopLevel ),
  78. m_alarm( 0 ), m_listener( 0 ), m_find( 0 ), m_findPos( 0 )
  79. {
  80. connect( kapp, TQT_SIGNAL(lastWindowClosed()), kapp, TQT_SLOT(quit()) );
  81. m_noteList.setAutoDelete( true );
  82. m_noteActions.setAutoDelete( true );
  83. // create the dock widget...
  84. KWin::setSystemTrayWindowFor( winId(), tqt_xrootwin() );
  85. TQToolTip::add( this, i18n( "KNotes: Sticky notes for TDE" ) );
  86. setBackgroundMode( X11ParentRelative );
  87. setPixmap( KSystemTray::loadIcon( "knotes" ) );
  88. // set the initial style
  89. KNote::setStyle( KNotesGlobalConfig::style() );
  90. // create the GUI...
  91. new TDEAction( i18n("New Note"), "document-new", 0,
  92. TQT_TQOBJECT(this), TQT_SLOT(newNote()), actionCollection(), "new_note" );
  93. new TDEAction( i18n("New Note From Clipboard"), "edit-paste", 0,
  94. TQT_TQOBJECT(this), TQT_SLOT(newNoteFromClipboard()), actionCollection(), "new_note_clipboard" );
  95. new TDEAction( i18n("Show All Notes"), "knotes", 0,
  96. TQT_TQOBJECT(this), TQT_SLOT(showAllNotes()), actionCollection(), "show_all_notes" );
  97. new TDEAction( i18n("Hide All Notes"), "window-close", 0,
  98. TQT_TQOBJECT(this), TQT_SLOT(hideAllNotes()), actionCollection(), "hide_all_notes" );
  99. new KHelpMenu( this, kapp->aboutData(), false, actionCollection() );
  100. m_findAction = KStdAction::find( TQT_TQOBJECT(this), TQT_SLOT(slotOpenFindDialog()), actionCollection() );
  101. KStdAction::preferences( TQT_TQOBJECT(this), TQT_SLOT(slotPreferences()), actionCollection() );
  102. KStdAction::keyBindings( TQT_TQOBJECT(this), TQT_SLOT(slotConfigureAccels()), actionCollection() );
  103. //FIXME: no shortcut removing!?
  104. KStdAction::quit( TQT_TQOBJECT(this), TQT_SLOT(slotQuit()), actionCollection() )->setShortcut( 0 );
  105. setXMLFile( instance()->instanceName() + "appui.rc" );
  106. m_guiBuilder = new KXMLGUIBuilder( this );
  107. m_guiFactory = new KXMLGUIFactory( m_guiBuilder, TQT_TQOBJECT(this) );
  108. m_guiFactory->addClient( this );
  109. m_context_menu = static_cast<TDEPopupMenu*>(m_guiFactory->container( "knotes_context", this ));
  110. m_note_menu = static_cast<TDEPopupMenu*>(m_guiFactory->container( "notes_menu", this ));
  111. // get the most recent XML UI file
  112. TQString xmlFileName = instance()->instanceName() + "ui.rc";
  113. TQString filter = TQString::fromLatin1( instance()->instanceName() + '/' ) + xmlFileName;
  114. TQStringList fileList = instance()->dirs()->findAllResources( "data", filter ) +
  115. instance()->dirs()->findAllResources( "data", xmlFileName );
  116. TQString doc;
  117. KXMLGUIClient::findMostRecentXMLFile( fileList, doc );
  118. m_noteGUI.setContent( doc );
  119. // create accels for global shortcuts
  120. m_globalAccel = new TDEGlobalAccel( TQT_TQOBJECT(this), "global accel" );
  121. m_globalAccel->insert( "global_new_note", i18n("New Note"), "",
  122. TDEShortcut(), TDEShortcut(),
  123. TQT_TQOBJECT(this), TQT_SLOT(newNote()), true, true );
  124. m_globalAccel->insert( "global_new_note_clipboard", i18n("New Note From Clipboard"), "",
  125. TDEShortcut(), TDEShortcut(),
  126. TQT_TQOBJECT(this), TQT_SLOT(newNoteFromClipboard()), true, true );
  127. m_globalAccel->insert( "global_hide_all_notes", i18n("Hide All Notes"), "",
  128. TDEShortcut(), TDEShortcut(),
  129. TQT_TQOBJECT(this), TQT_SLOT(hideAllNotes()), true, true );
  130. m_globalAccel->insert( "global_show_all_notes", i18n("Show All Notes"), "",
  131. TDEShortcut(), TDEShortcut(),
  132. TQT_TQOBJECT(this), TQT_SLOT(showAllNotes()), true, true );
  133. m_globalAccel->readSettings();
  134. TDEConfig *config = TDEGlobal::config();
  135. config->setGroup( "Global Keybindings" );
  136. m_globalAccel->setEnabled( config->readBoolEntry( "Enabled", true ) );
  137. updateGlobalAccels();
  138. // clean up old config files
  139. KNotesLegacy::cleanUp();
  140. // create the resource manager
  141. m_manager = new KNotesResourceManager();
  142. connect( m_manager, TQT_SIGNAL(sigRegisteredNote( KCal::Journal * )),
  143. this, TQT_SLOT(createNote( KCal::Journal * )) );
  144. connect( m_manager, TQT_SIGNAL(sigDeregisteredNote( KCal::Journal * )),
  145. this, TQT_SLOT(killNote( KCal::Journal * )) );
  146. // read the notes
  147. m_manager->load();
  148. // read the old config files, convert and add them
  149. KCal::CalendarLocal calendar( TQString::fromLatin1( "UTC" ) );
  150. if ( KNotesLegacy::convert( &calendar ) )
  151. {
  152. KCal::Journal::List notes = calendar.journals();
  153. KCal::Journal::List::ConstIterator it;
  154. for ( it = notes.constBegin(); it != notes.constEnd(); ++it )
  155. m_manager->addNewNote( *it );
  156. m_manager->save();
  157. }
  158. // set up the alarm reminder - do it after loading the notes because this
  159. // is used as a check if updateNoteActions has to be called for a new note
  160. m_alarm = new KNotesAlarm( m_manager, TQT_TQOBJECT(this) );
  161. // create the socket and possibly start listening for connections
  162. m_listener = new TDEServerSocket();
  163. m_listener->setResolutionEnabled( true );
  164. connect( m_listener, TQT_SIGNAL(readyAccept()), TQT_SLOT(acceptConnection()) );
  165. updateNetworkListener();
  166. if ( m_noteList.count() == 0 && !kapp->isRestored() )
  167. newNote();
  168. updateNoteActions();
  169. }
  170. void KNotesApp::resizeTrayIcon ()
  171. {
  172. // Honor Free Desktop specifications that allow for arbitrary system tray icon sizes
  173. TQPixmap origpixmap;
  174. TQPixmap scaledpixmap;
  175. TQImage newIcon;
  176. origpixmap = KSystemTray::loadSizedIcon( "knotes", TQWidget::width() );
  177. newIcon = origpixmap;
  178. newIcon = newIcon.smoothScale(TQWidget::width(), TQWidget::height());
  179. scaledpixmap = newIcon;
  180. setPixmap(scaledpixmap);
  181. }
  182. void KNotesApp::resizeEvent ( TQResizeEvent * )
  183. {
  184. // Honor Free Desktop specifications that allow for arbitrary system tray icon sizes
  185. resizeTrayIcon();
  186. }
  187. void KNotesApp::showEvent ( TQShowEvent * )
  188. {
  189. // Honor Free Desktop specifications that allow for arbitrary system tray icon sizes
  190. resizeTrayIcon();
  191. }
  192. KNotesApp::~KNotesApp()
  193. {
  194. saveNotes();
  195. blockSignals( true );
  196. m_noteList.clear();
  197. blockSignals( false );
  198. delete m_listener;
  199. delete m_manager;
  200. delete m_guiBuilder;
  201. }
  202. bool KNotesApp::commitData( TQSessionManager& )
  203. {
  204. saveConfigs();
  205. return true;
  206. }
  207. // -------------------- public DCOP interface -------------------- //
  208. TQString KNotesApp::newNote( const TQString& name, const TQString& text )
  209. {
  210. // create the new note
  211. KCal::Journal *journal = new KCal::Journal();
  212. // new notes have the current date/time as title if none was given
  213. if ( !name.isEmpty() )
  214. journal->setSummary( name );
  215. else
  216. journal->setSummary( TDEGlobal::locale()->formatDateTime( TQDateTime::currentDateTime() ) );
  217. // the body of the note
  218. journal->setDescription( text );
  219. if ( m_manager->addNewNote( journal ) ) {
  220. showNote( journal->uid() );
  221. }
  222. return journal->uid();
  223. }
  224. TQString KNotesApp::newNoteFromClipboard( const TQString& name )
  225. {
  226. const TQString& text = TDEApplication::clipboard()->text();
  227. return newNote( name, text );
  228. }
  229. void KNotesApp::hideAllNotes() const
  230. {
  231. TQDictIterator<KNote> it( m_noteList );
  232. for ( ; *it; ++it )
  233. (*it)->close();
  234. }
  235. void KNotesApp::showAllNotes() const
  236. {
  237. TQDictIterator<KNote> it( m_noteList );
  238. for ( ; *it; ++it )
  239. {
  240. (*it)->show();
  241. }
  242. }
  243. void KNotesApp::showNote( const TQString& id ) const
  244. {
  245. KNote* note = m_noteList[id];
  246. if ( note )
  247. showNote( note );
  248. else
  249. kdWarning(5500) << "showNote: no note with id: " << id << endl;
  250. }
  251. void KNotesApp::hideNote( const TQString& id ) const
  252. {
  253. KNote* note = m_noteList[id];
  254. if ( note )
  255. note->hide();
  256. else
  257. kdWarning(5500) << "hideNote: no note with id: " << id << endl;
  258. }
  259. void KNotesApp::killNote( const TQString& id, bool force )
  260. {
  261. KNote* note = m_noteList[id];
  262. if ( note )
  263. note->slotKill( force );
  264. else
  265. kdWarning(5500) << "killNote: no note with id: " << id << endl;
  266. }
  267. // "bool force = false" doesn't work with dcop
  268. void KNotesApp::killNote( const TQString& id )
  269. {
  270. killNote( id, false );
  271. }
  272. TQMap<TQString,TQString> KNotesApp::notes() const
  273. {
  274. TQMap<TQString,TQString> notes;
  275. TQDictIterator<KNote> it( m_noteList );
  276. for ( ; it.current(); ++it )
  277. notes.insert( it.current()->noteId(), it.current()->name() );
  278. return notes;
  279. }
  280. TQDateTime KNotesApp::getLastModified( const TQString& id ) const
  281. {
  282. KNote* note = m_noteList[id];
  283. TQDateTime d;
  284. if ( note )
  285. d = note->getLastModified();
  286. return d;
  287. }
  288. TQString KNotesApp::name( const TQString& id ) const
  289. {
  290. KNote* note = m_noteList[id];
  291. if ( note )
  292. return note->name();
  293. else
  294. return TQString();
  295. }
  296. TQString KNotesApp::text( const TQString& id ) const
  297. {
  298. KNote* note = m_noteList[id];
  299. if ( note )
  300. return note->text();
  301. else
  302. return TQString();
  303. }
  304. void KNotesApp::setName( const TQString& id, const TQString& newName )
  305. {
  306. KNote* note = m_noteList[id];
  307. if ( note )
  308. note->setName( newName );
  309. else
  310. kdWarning(5500) << "setName: no note with id: " << id << endl;
  311. }
  312. void KNotesApp::setText( const TQString& id, const TQString& newText )
  313. {
  314. KNote* note = m_noteList[id];
  315. if ( note )
  316. note->setText( newText );
  317. else
  318. kdWarning(5500) << "setText: no note with id: " << id << endl;
  319. }
  320. TQString KNotesApp::fgColor( const TQString& id ) const
  321. {
  322. KNote* note = m_noteList[id];
  323. if ( note )
  324. return note->fgColor().name();
  325. else
  326. return TQString();
  327. }
  328. TQString KNotesApp::bgColor( const TQString& id ) const
  329. {
  330. KNote* note = m_noteList[id];
  331. if ( note )
  332. return note->bgColor().name();
  333. else
  334. return TQString();
  335. }
  336. void KNotesApp::setColor( const TQString& id, const TQString& fgColor, const TQString& bgColor )
  337. {
  338. KNote* note = m_noteList[id];
  339. if ( note )
  340. note->setColor( TQColor( fgColor ), TQColor( bgColor ) );
  341. else
  342. kdWarning(5500) << "setColor: no note with id: " << id << endl;
  343. }
  344. int KNotesApp::width( const TQString& id ) const
  345. {
  346. KNote* note = m_noteList[id];
  347. if ( note )
  348. return note->width();
  349. else
  350. return 0;
  351. }
  352. int KNotesApp::height( const TQString& id ) const
  353. {
  354. KNote* note = m_noteList[id];
  355. if ( note )
  356. return note->height();
  357. else
  358. return 0;
  359. }
  360. void KNotesApp::move( const TQString& id, int x, int y ) const
  361. {
  362. KNote* note = m_noteList[id];
  363. if ( note )
  364. return note->move( x, y );
  365. else
  366. kdWarning(5500) << "move: no note with id: " << id << endl;
  367. }
  368. void KNotesApp::resize( const TQString& id, int width, int height ) const
  369. {
  370. KNote* note = m_noteList[id];
  371. if ( note )
  372. return note->resize( width, height );
  373. else
  374. kdWarning(5500) << "resize: no note with id: " << id << endl;
  375. }
  376. void KNotesApp::sync( const TQString& app )
  377. {
  378. TQDictIterator<KNote> it( m_noteList );
  379. for ( ; it.current(); ++it )
  380. it.current()->sync( app );
  381. }
  382. bool KNotesApp::isNew( const TQString& app, const TQString& id ) const
  383. {
  384. KNote* note = m_noteList[id];
  385. if ( note )
  386. return note->isNew( app );
  387. else
  388. return false;
  389. }
  390. bool KNotesApp::isModified( const TQString& app, const TQString& id ) const
  391. {
  392. KNote* note = m_noteList[id];
  393. if ( note )
  394. return note->isModified( app );
  395. else
  396. return false;
  397. }
  398. // ------------------- protected methods ------------------- //
  399. void KNotesApp::mousePressEvent( TQMouseEvent* e )
  400. {
  401. if ( !rect().contains( e->pos() ) )
  402. return;
  403. switch ( e->button() )
  404. {
  405. case Qt::LeftButton:
  406. if ( m_noteList.count() == 1 )
  407. {
  408. TQDictIterator<KNote> it( m_noteList );
  409. showNote( it.toFirst() );
  410. }
  411. else if ( m_note_menu->count() > 0 )
  412. m_note_menu->popup( e->globalPos() );
  413. break;
  414. case Qt::MidButton:
  415. newNote();
  416. break;
  417. case Qt::RightButton:
  418. m_context_menu->popup( e->globalPos() );
  419. default: break;
  420. }
  421. }
  422. // -------------------- protected slots -------------------- //
  423. void KNotesApp::slotShowNote()
  424. {
  425. // tell the WM to give this note focus
  426. showNote( TQString::fromUtf8( TQT_TQOBJECT(const_cast<TQT_BASE_OBJECT_NAME*>(sender()))->name() ) );
  427. }
  428. void KNotesApp::slotWalkThroughNotes()
  429. {
  430. // show next note
  431. TQDictIterator<KNote> it( m_noteList );
  432. KNote *first = it.toFirst();
  433. for ( ; *it; ++it )
  434. if ( (*it)->hasFocus() )
  435. {
  436. if ( ++it )
  437. showNote( *it );
  438. else
  439. showNote( first );
  440. break;
  441. }
  442. }
  443. void KNotesApp::slotOpenFindDialog()
  444. {
  445. KFindDialog findDia( this, "find_dialog" );
  446. findDia.setHasSelection( false );
  447. findDia.setHasCursor( false );
  448. findDia.setSupportsBackwardsFind( false );
  449. if ( (findDia.exec() != TQDialog::Accepted) || findDia.pattern().isEmpty() )
  450. return;
  451. delete m_findPos;
  452. m_findPos = new TQDictIterator<KNote>( m_noteList );
  453. // this could be in an own method if searching without a dialog should be possible
  454. delete m_find;
  455. m_find = new KFind( findDia.pattern(), findDia.options(), this );
  456. slotFindNext();
  457. }
  458. void KNotesApp::slotFindNext()
  459. {
  460. if ( **m_findPos )
  461. {
  462. KNote *note = **m_findPos;
  463. ++*m_findPos;
  464. note->find( m_find->pattern(), m_find->options() );
  465. }
  466. else
  467. {
  468. m_find->displayFinalDialog();
  469. delete m_find;
  470. m_find = 0;
  471. delete m_findPos;
  472. m_findPos = 0;
  473. }
  474. }
  475. void KNotesApp::slotPreferences()
  476. {
  477. // reuse the dialog if possible
  478. if ( KNoteConfigDlg::showDialog( "KNotes Default Settings" ) )
  479. return;
  480. // create a new preferences dialog...
  481. KNoteConfigDlg *dialog = new KNoteConfigDlg( 0, i18n("Settings"), this,
  482. "KNotes Settings" );
  483. connect( dialog, TQT_SIGNAL(settingsChanged()), TQT_TQOBJECT(this), TQT_SLOT(updateNetworkListener()) );
  484. connect( dialog, TQT_SIGNAL(settingsChanged()), TQT_TQOBJECT(this), TQT_SLOT(updateStyle()) );
  485. dialog->show();
  486. }
  487. void KNotesApp::slotConfigureAccels()
  488. {
  489. KNotesKeyDialog keys( m_globalAccel, this );
  490. TQDictIterator<KNote> notes( m_noteList );
  491. if ( !m_noteList.isEmpty() )
  492. keys.insert( (*notes)->actionCollection() );
  493. keys.configure();
  494. m_globalAccel->writeSettings();
  495. updateGlobalAccels();
  496. // update GUI doc for new notes
  497. m_noteGUI.setContent(
  498. KXMLGUIFactory::readConfigFile( instance()->instanceName() + "ui.rc", instance() )
  499. );
  500. if ( m_noteList.isEmpty() )
  501. return;
  502. notes.toFirst();
  503. TQValueList<TDEAction *> list = (*notes)->actionCollection()->actions();
  504. for ( TQValueList<TDEAction *>::iterator it = list.begin(); it != list.end(); ++it )
  505. {
  506. notes.toFirst();
  507. for ( ++notes; *notes; ++notes )
  508. {
  509. TDEAction *toChange = (*notes)->actionCollection()->action( (*it)->name() );
  510. if ( toChange->shortcut() != (*it)->shortcut() )
  511. toChange->setShortcut( (*it)->shortcut() );
  512. }
  513. }
  514. }
  515. void KNotesApp::slotNoteKilled( KCal::Journal *journal )
  516. {
  517. m_noteUidModify="";
  518. m_manager->deleteNote( journal );
  519. saveNotes();
  520. }
  521. void KNotesApp::slotQuit()
  522. {
  523. TQDictIterator<KNote> it( m_noteList );
  524. for ( ; *it; ++it )
  525. if ( (*it)->isModified() )
  526. (*it)->saveData(false);
  527. saveConfigs();
  528. kapp->quit();
  529. }
  530. // -------------------- private methods -------------------- //
  531. void KNotesApp::showNote( KNote* note ) const
  532. {
  533. note->show();
  534. KWin::setCurrentDesktop( KWin::windowInfo( note->winId() ).desktop() );
  535. KWin::forceActiveWindow( note->winId() );
  536. note->setFocus();
  537. }
  538. void KNotesApp::createNote( KCal::Journal *journal )
  539. {
  540. if( journal->uid() == m_noteUidModify)
  541. {
  542. KNote *note = m_noteList[m_noteUidModify];
  543. if ( note )
  544. note->changeJournal(journal);
  545. return;
  546. }
  547. m_noteUidModify = journal->uid();
  548. KNote *newNote = new KNote( m_noteGUI, journal, 0, journal->uid().utf8() );
  549. m_noteList.insert( newNote->noteId(), newNote );
  550. connect( newNote, TQT_SIGNAL(sigRequestNewNote()), TQT_SLOT(newNote()) );
  551. connect( newNote, TQT_SIGNAL(sigShowNextNote()), TQT_SLOT(slotWalkThroughNotes()) );
  552. connect( newNote, TQT_SIGNAL(sigKillNote( KCal::Journal* )),
  553. TQT_SLOT(slotNoteKilled( KCal::Journal* )) );
  554. connect( newNote, TQT_SIGNAL(sigNameChanged()), TQT_SLOT(updateNoteActions()) );
  555. connect( newNote, TQT_SIGNAL(sigDataChanged(const TQString &)), TQT_SLOT(saveNotes(const TQString &)) );
  556. connect( newNote, TQT_SIGNAL(sigColorChanged()), TQT_SLOT(updateNoteActions()) );
  557. connect( newNote, TQT_SIGNAL(sigFindFinished()), TQT_SLOT(slotFindNext()) );
  558. // don't call this during startup for each and every loaded note
  559. if ( m_alarm )
  560. updateNoteActions();
  561. }
  562. void KNotesApp::killNote( KCal::Journal *journal )
  563. {
  564. if(m_noteUidModify == journal->uid())
  565. {
  566. return;
  567. }
  568. // this kills the KNote object
  569. KNote *note = m_noteList.take( journal->uid() );
  570. if ( note )
  571. {
  572. note->deleteWhenIdle();
  573. updateNoteActions();
  574. }
  575. }
  576. void KNotesApp::acceptConnection()
  577. {
  578. // Accept the connection and make KNotesNetworkReceiver do the job
  579. TDEBufferedSocket *s = static_cast<TDEBufferedSocket *>(m_listener->accept());
  580. if ( s )
  581. {
  582. KNotesNetworkReceiver *recv = new KNotesNetworkReceiver( s );
  583. connect( recv, TQT_SIGNAL(sigNoteReceived( const TQString &, const TQString & )),
  584. TQT_TQOBJECT(this), TQT_SLOT(newNote( const TQString &, const TQString & )) );
  585. }
  586. }
  587. void KNotesApp::saveNotes( const TQString & uid )
  588. {
  589. m_noteUidModify = uid;
  590. saveNotes();
  591. }
  592. void KNotesApp::saveNotes()
  593. {
  594. KNotesGlobalConfig::writeConfig();
  595. m_manager->save();
  596. }
  597. void KNotesApp::saveConfigs()
  598. {
  599. TQDictIterator<KNote> it( m_noteList );
  600. for ( ; it.current(); ++it )
  601. it.current()->saveConfig();
  602. }
  603. void KNotesApp::updateNoteActions()
  604. {
  605. unplugActionList( "notes" );
  606. m_noteActions.clear();
  607. for ( TQDictIterator<KNote> it( m_noteList ); it.current(); ++it )
  608. {
  609. TDEAction *action = new TDEAction( it.current()->name().replace("&", "&&"),
  610. TDEShortcut(), TQT_TQOBJECT(this), TQT_SLOT(slotShowNote()),
  611. (TQObject *)0,
  612. it.current()->noteId().utf8() );
  613. TDEIconEffect effect;
  614. TQPixmap icon = effect.apply( kapp->miniIcon(), TDEIconEffect::Colorize, 1,
  615. it.current()->paletteBackgroundColor(), false );
  616. action->setIconSet( icon );
  617. m_noteActions.append( action );
  618. }
  619. if ( m_noteActions.isEmpty() )
  620. {
  621. actionCollection()->action( "hide_all_notes" )->setEnabled( false );
  622. actionCollection()->action( "show_all_notes" )->setEnabled( false );
  623. m_findAction->setEnabled( false );
  624. TDEAction *action = new TDEAction( i18n("No Notes") );
  625. m_noteActions.append( action );
  626. }
  627. else
  628. {
  629. actionCollection()->action( "hide_all_notes" )->setEnabled( true );
  630. actionCollection()->action( "show_all_notes" )->setEnabled( true );
  631. m_findAction->setEnabled( true );
  632. m_noteActions.sort();
  633. }
  634. plugActionList( "notes", m_noteActions );
  635. }
  636. void KNotesApp::updateGlobalAccels()
  637. {
  638. if ( m_globalAccel->isEnabled() )
  639. {
  640. TDEAction *action = actionCollection()->action( "new_note" );
  641. if ( action )
  642. action->setShortcut( m_globalAccel->shortcut( "global_new_note" ) );
  643. action = actionCollection()->action( "new_note_clipboard" );
  644. if ( action )
  645. action->setShortcut( m_globalAccel->shortcut( "global_new_note_clipboard" ) );
  646. action = actionCollection()->action( "hide_all_notes" );
  647. if ( action )
  648. action->setShortcut( m_globalAccel->shortcut( "global_hide_all_notes" ) );
  649. action = actionCollection()->action( "show_all_notes" );
  650. if ( action )
  651. action->setShortcut( m_globalAccel->shortcut( "global_show_all_notes" ) );
  652. m_globalAccel->updateConnections();
  653. }
  654. else
  655. {
  656. TDEAction *action = actionCollection()->action( "new_note" );
  657. if ( action )
  658. action->setShortcut( 0 );
  659. action = actionCollection()->action( "new_note_clipboard" );
  660. if ( action )
  661. action->setShortcut( 0 );
  662. action = actionCollection()->action( "hide_all_notes" );
  663. if ( action )
  664. action->setShortcut( 0 );
  665. action = actionCollection()->action( "show_all_notes" );
  666. if ( action )
  667. action->setShortcut( 0 );
  668. }
  669. }
  670. void KNotesApp::updateNetworkListener()
  671. {
  672. m_listener->close();
  673. if ( KNotesGlobalConfig::receiveNotes() )
  674. {
  675. m_listener->setAddress( TQString::number( KNotesGlobalConfig::port() ) );
  676. m_listener->bind();
  677. m_listener->listen();
  678. }
  679. }
  680. void KNotesApp::updateStyle()
  681. {
  682. KNote::setStyle( KNotesGlobalConfig::style() );
  683. TQDictIterator<KNote> it( m_noteList );
  684. for ( ; it.current(); ++it )
  685. TQApplication::postEvent( *it, new TQEvent( TQEvent::LayoutHint ) );
  686. }
  687. #include "knotesapp.moc"