Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 3
0
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();
}