bool ResourceLocal::load() { mCalendar.load(mURL.path()); KCal::Journal::List notes = mCalendar.journals(); KCal::Journal::List::ConstIterator it; for(it = notes.begin(); it != notes.end(); ++it) manager()->registerNote(this, *it); return true; }
bool ResourceLocal::load() { mCalendar.load( mURL.toLocalFile() ); KCal::Journal::List notes = mCalendar.journals(); KCal::Journal::List::ConstIterator it; for ( it = notes.constBegin(); it != notes.constEnd(); ++it ) { manager()->registerNote( this, *it ); } return true; }
KCal::Alarm::List ResourceLocal::alarms(const QDateTime &from, const QDateTime &to) { KCal::Alarm::List alarms; KCal::Journal::List notes = mCalendar.journals(); KCal::Journal::List::ConstIterator note; for(note = notes.begin(); note != notes.end(); ++note) { QDateTime preTime = from.addSecs(-1); KCal::Alarm::List::ConstIterator it; for(it = (*note)->alarms().begin(); it != (*note)->alarms().end(); ++it) { if((*it)->enabled()) { QDateTime dt = (*it)->nextRepetition(preTime); if(dt.isValid() && dt <= to) alarms.append(*it); } } } return alarms; }
KNotesApp::KNotesApp() : QWidget(), m_alarm( 0 ), m_listener( 0 ), m_publisher( 0 ), m_find( 0 ), m_findPos( 0 ) { new KNotesAdaptor( this ); QDBusConnection::sessionBus().registerObject( "/KNotes" , this ); kapp->setQuitOnLastWindowClosed( false ); // create the dock widget... m_tray = new KStatusNotifierItem(0); m_tray->setToolTipTitle( i18n( "KNotes: Sticky notes for KDE" ) ); m_tray->setIconByName( "knotes" ); m_tray->setToolTipIconByName( "knotes" ); m_tray->setStatus( KStatusNotifierItem::Active ); m_tray->setCategory( KStatusNotifierItem::ApplicationStatus ); m_tray->setStandardActionsEnabled(false); connect( m_tray, SIGNAL(activateRequested(bool,QPoint)), this, SLOT(slotActivateRequested(bool,QPoint)) ); connect( m_tray, SIGNAL(secondaryActivateRequested(QPoint)), this, SLOT(slotSecondaryActivateRequested(QPoint)) ); // set the initial style #ifdef __GNUC__ #warning FIXME #endif // KNote::setStyle( KNotesGlobalConfig::style() ); // create the GUI... KAction *action = new KAction( KIcon( "document-new" ), i18n( "New Note" ), this ); actionCollection()->addAction( "new_note", action ); action->setGlobalShortcut( KShortcut( Qt::ALT + Qt::SHIFT + Qt::Key_N )); connect( action, SIGNAL(triggered()), SLOT(newNote()) ); action = new KAction( KIcon( "edit-paste" ), i18n( "New Note From Clipboard" ), this ); actionCollection()->addAction( "new_note_clipboard", action ); action->setGlobalShortcut( KShortcut( Qt::ALT + Qt::SHIFT + Qt::Key_C )); connect( action, SIGNAL(triggered()), SLOT(newNoteFromClipboard()) ); action = new KAction( KIcon( "knotes" ), i18n( "Show All Notes" ), this ); actionCollection()->addAction( "show_all_notes", action ); action->setGlobalShortcut( KShortcut( Qt::ALT + Qt::SHIFT + Qt::Key_S )); connect( action, SIGNAL(triggered()), SLOT(showAllNotes()) ); action = new KAction( KIcon( "window-close" ), i18n( "Hide All Notes" ), this ); actionCollection()->addAction( "hide_all_notes", action ); action->setGlobalShortcut( KShortcut( Qt::ALT + Qt::SHIFT + Qt::Key_H )); connect( action, SIGNAL(triggered()), SLOT(hideAllNotes()) ); new KHelpMenu( this, KGlobal::mainComponent().aboutData(), false, actionCollection() ); m_findAction = KStandardAction::find( this, SLOT(slotOpenFindDialog()), actionCollection() ); KStandardAction::preferences( this, SLOT(slotPreferences()), actionCollection() ); KStandardAction::keyBindings( this, SLOT(slotConfigureAccels()), actionCollection() ); //FIXME: no shortcut removing!? KStandardAction::quit( this, SLOT(slotQuit()), actionCollection() )->setShortcut( 0 ); setXMLFile( componentData().componentName() + "appui.rc" ); m_guiBuilder = new KXMLGUIBuilder( this ); m_guiFactory = new KXMLGUIFactory( m_guiBuilder, this ); m_guiFactory->addClient( this ); m_contextMenu = static_cast<KMenu *>( m_guiFactory->container( "knotes_context", this ) ); m_noteMenu = static_cast<KMenu *>( m_guiFactory->container( "notes_menu", this ) ); m_tray->setContextMenu( m_contextMenu ); // get the most recent XML UI file QString xmlFileName = componentData().componentName() + "ui.rc"; QString filter = componentData().componentName() + '/' + xmlFileName; const QStringList fileList = componentData().dirs()->findAllResources( "data", filter ) + componentData().dirs()->findAllResources( "data", xmlFileName ); QString doc; KXMLGUIClient::findMostRecentXMLFile( fileList, doc ); m_noteGUI.setContent( doc ); KConfigGroup config( KGlobal::config(), "Global Keybindings" ); // clean up old config files KNotesLegacy::cleanUp(); // create the resource manager m_manager = new KNotesResourceManager(); connect( m_manager, SIGNAL(sigRegisteredNote(KCal::Journal*)), this, SLOT(createNote(KCal::Journal*)) ); connect( m_manager, SIGNAL(sigDeregisteredNote(KCal::Journal*)), this, SLOT(killNote(KCal::Journal*)) ); // read the notes m_manager->load(); // read the old config files, convert and add them KCal::CalendarLocal calendar( QString::fromLatin1( "UTC" ) ); if ( KNotesLegacy::convert( &calendar ) ) { KCal::Journal::List notes = calendar.journals(); KCal::Journal::List::ConstIterator it; for ( it = notes.constBegin(); it != notes.constEnd(); ++it ) { m_manager->addNewNote( *it ); } m_manager->save(); } // set up the alarm reminder - do it after loading the notes because this // is used as a check if updateNoteActions has to be called for a new note m_alarm = new KNotesAlarm( m_manager, this ); updateNetworkListener(); if ( m_notes.size() == 0 && !kapp->isSessionRestored() ) { newNote(); } updateNoteActions(); }
KNotesApp::KNotesApp() : DCOPObject("KNotesIface"), QLabel( 0, 0, WType_TopLevel ), m_alarm( 0 ), m_listener( 0 ), m_find( 0 ), m_findPos( 0 ) { connect( kapp, SIGNAL(lastWindowClosed()), kapp, SLOT(quit()) ); m_noteList.setAutoDelete( true ); m_noteActions.setAutoDelete( true ); // create the dock widget... KWin::setSystemTrayWindowFor( winId(), qt_xrootwin() ); QToolTip::add( this, i18n( "KNotes: Sticky notes for KDE" ) ); setBackgroundMode( X11ParentRelative ); setPixmap( KSystemTray::loadIcon( "knotes" ) ); // set the initial style KNote::setStyle( KNotesGlobalConfig::style() ); // create the GUI... new KAction( i18n("New Note"), "filenew", 0, this, SLOT(newNote()), actionCollection(), "new_note" ); new KAction( i18n("New Note From Clipboard"), "editpaste", 0, this, SLOT(newNoteFromClipboard()), actionCollection(), "new_note_clipboard" ); new KAction( i18n("Show All Notes"), "knotes", 0, this, SLOT(showAllNotes()), actionCollection(), "show_all_notes" ); new KAction( i18n("Hide All Notes"), "fileclose", 0, this, SLOT(hideAllNotes()), actionCollection(), "hide_all_notes" ); new KHelpMenu( this, kapp->aboutData(), false, actionCollection() ); KStdAction::find( this, SLOT(slotOpenFindDialog()), actionCollection() ); KStdAction::preferences( this, SLOT(slotPreferences()), actionCollection() ); KStdAction::keyBindings( this, SLOT(slotConfigureAccels()), actionCollection() ); //FIXME: no shortcut removing!? KStdAction::quit( this, SLOT(slotQuit()), actionCollection() )->setShortcut( 0 ); setXMLFile( instance()->instanceName() + "appui.rc" ); m_guiBuilder = new KXMLGUIBuilder( this ); m_guiFactory = new KXMLGUIFactory( m_guiBuilder, this ); m_guiFactory->addClient( this ); m_context_menu = static_cast<KPopupMenu*>(m_guiFactory->container( "knotes_context", this )); m_note_menu = static_cast<KPopupMenu*>(m_guiFactory->container( "notes_menu", this )); // get the most recent XML UI file QString xmlFileName = instance()->instanceName() + "ui.rc"; QString filter = QString::fromLatin1( instance()->instanceName() + '/' ) + xmlFileName; QStringList fileList = instance()->dirs()->findAllResources( "data", filter ) + instance()->dirs()->findAllResources( "data", xmlFileName ); QString doc; KXMLGUIClient::findMostRecentXMLFile( fileList, doc ); m_noteGUI.setContent( doc ); // create accels for global shortcuts m_globalAccel = new KGlobalAccel( this, "global accel" ); m_globalAccel->insert( "global_new_note", i18n("New Note"), "", ALT+SHIFT+Key_N, ALT+SHIFT+Key_N , this, SLOT(newNote()), true, true ); m_globalAccel->insert( "global_new_note_clipboard", i18n("New Note From Clipboard"), "", ALT+SHIFT+Key_C, ALT+SHIFT+Key_C, this, SLOT(newNoteFromClipboard()), true, true ); m_globalAccel->insert( "global_hide_all_notes", i18n("Hide All Notes"), "", ALT+SHIFT+Key_H, ALT+SHIFT+Key_H , this, SLOT(hideAllNotes()), true, true ); m_globalAccel->insert( "global_show_all_notes", i18n("Show All Notes"), "", ALT+SHIFT+Key_S, ALT+SHIFT+Key_S, this, SLOT(showAllNotes()), true, true ); m_globalAccel->readSettings(); KConfig *config = KGlobal::config(); config->setGroup( "Global Keybindings" ); m_globalAccel->setEnabled( config->readBoolEntry( "Enabled", true ) ); updateGlobalAccels(); // clean up old config files KNotesLegacy::cleanUp(); // create the resource manager m_manager = new KNotesResourceManager(); connect( m_manager, SIGNAL(sigRegisteredNote( KCal::Journal * )), this, SLOT(createNote( KCal::Journal * )) ); connect( m_manager, SIGNAL(sigDeregisteredNote( KCal::Journal * )), this, SLOT(killNote( KCal::Journal * )) ); // read the notes m_manager->load(); // read the old config files, convert and add them KCal::CalendarLocal calendar( QString::fromLatin1( "UTC" ) ); if ( KNotesLegacy::convert( &calendar ) ) { KCal::Journal::List notes = calendar.journals(); KCal::Journal::List::ConstIterator it; for ( it = notes.begin(); it != notes.end(); ++it ) m_manager->addNewNote( *it ); m_manager->save(); } // set up the alarm reminder - do it after loading the notes because this // is used as a check if updateNoteActions has to be called for a new note m_alarm = new KNotesAlarm( m_manager, this ); // create the socket and possibly start listening for connections m_listener = new KServerSocket(); m_listener->setResolutionEnabled( true ); connect( m_listener, SIGNAL(readyAccept()), SLOT(acceptConnection()) ); updateNetworkListener(); if ( m_noteList.count() == 0 && !kapp->isRestored() ) newNote(); updateNoteActions(); }