Exemplo n.º 1
0
void CalendarDemo::buildMenu()
{
    // Build Options menu
#if defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6) || defined(Q_OS_WINCE)
    // These platforms need their menu items added directly to the menu bar.
    QMenuBar *optionsMenu = menuBar();
#else
    QMenu *optionsMenu = new QMenu("&Options", this);
    #if !(defined(Q_OS_SYMBIAN) || defined(Q_WS_SIMULATOR))
    // We add the options menu to the softkey manually later
    menuBar()->addMenu(optionsMenu);
    #endif
#endif
    // Add editing options in the menu for Symbian (other platforms get buttons)
    QOrganizerManager defaultManager;
    QStringList supportedItemTypes = defaultManager.supportedItemTypes();
    if (supportedItemTypes.contains(QOrganizerItemType::TypeEvent)) {
        QAction* addEventAction = optionsMenu->addAction("Add E&vent");
        connect(addEventAction, SIGNAL(triggered(bool)), this, SLOT(addNewEvent()));
    }
Exemplo n.º 2
0
QDateTime TimeZone::convert(const QDateTime& dateTime) const
{
    Q_ASSERT(isValid());
    QOrganizerManager* manager = getManager();
    int offset = 100000; // impossible value
    QDateTime latestPhase;
    foreach(const TimeZonePhase& phase, mPhases) {
        QOrganizerEvent event;
        event.setStartDateTime(phase.startDateTime());
        event.setRecurrenceRules(QSet<QOrganizerRecurrenceRule>() << phase.recurrenceRule());
        event.setRecurrenceDates(phase.recurrenceDates());
        QList<QOrganizerItem> occurrences =
            manager->itemOccurrences(event, phase.startDateTime(), dateTime, 500);
        if (!occurrences.isEmpty()) {
            QDateTime phaseStart(static_cast<QOrganizerEventOccurrence>(occurrences.last()).startDateTime());
            if (phaseStart > latestPhase) {
                latestPhase = phaseStart;
                offset = phase.utcOffset();
            }
        }
    }
void snippets()
{
    //! [Instantiating the default manager for the platform]
    QOrganizerManager defaultManager;
    //! [Instantiating the default manager for the platform]

    //! [Instantiating a specific manager]
    QOrganizerManager specificManager("KCal");
    //! [Instantiating a specific manager]

    // XXX TODO: use rrule instead of rdates.
    QDateTime startDateTime = QDateTime::currentDateTime();
    QDate firstOccDate = startDateTime.date().addDays(7);
    QDate secondOccDate = startDateTime.date().addDays(14);
    QDate thirdOccDate = startDateTime.date().addDays(21);
    QDateTime endDateTime = startDateTime.addDays(28);
    QSet<QDate> rDates;
    rDates << firstOccDate << secondOccDate << thirdOccDate;

    //! [Creating a recurrent event]
    QOrganizerEvent marshmallowMeeting;
    marshmallowMeeting.setRecurrenceDates(rDates);
    marshmallowMeeting.setPriority(QOrganizerItemPriority::HighPriority);
    marshmallowMeeting.setLocation("Meeting Room 8");
    marshmallowMeeting.setDescription("A meeting every wednesday to discuss the vitally important topic of marshmallows");
    marshmallowMeeting.setDisplayLabel("Marshmallow Conference");
    if (!defaultManager.saveItem(&marshmallowMeeting))
        qDebug() << "Failed to save the recurrent event; error:" << defaultManager.error();
    //! [Creating a recurrent event]

    //! [Retrieving occurrences of a particular recurrent event within a time period]
    QList<QOrganizerItem> instances = defaultManager.itemOccurrences(marshmallowMeeting, startDateTime, endDateTime);
    //! [Retrieving occurrences of a particular recurrent event within a time period]
    qDebug() << "dumping retrieved instances:";
    foreach(const QOrganizerItem& currInst, instances)
    {
        dumpItem(currInst);
        qDebug() << "....................";
    }
Exemplo n.º 4
0
void CalendarThreadWrapper::addToCalendar()
{
    const QString viaStation = m_result->viaStation();
    QSettings settings(FAHRPLAN_SETTINGS_NAMESPACE, "fahrplan2");
    QString calendarEntryTitle;
    QString calendarEntryDesc;

    if (viaStation.isEmpty())
        calendarEntryTitle = tr("%1 to %2").arg(m_result->departureStation(),
                                                m_result->arrivalStation());
    else
        calendarEntryTitle = tr("%1 via %3 to %2").arg(m_result->departureStation(),
                                                       m_result->arrivalStation(),
                                                       viaStation);

    if (!m_result->info().isEmpty())
        calendarEntryDesc.append(m_result->info()).append("\n");

    const bool compactFormat = settings.value("compactCalendarEntries", false).toBool();
    for (int i=0; i < m_result->itemcount(); i++) {
        JourneyDetailResultItem *item = m_result->getItem(i);

        if (!compactFormat && !item->train().isEmpty())
            calendarEntryDesc.append("--- ").append(item->train()).append(" ---\n");

        calendarEntryDesc.append(formatStation(item->departureDateTime(),
                                               item->departureStation(),
                                               item->departureInfo()));
        calendarEntryDesc.append("\n");

        if (compactFormat && !item->train().isEmpty())
            calendarEntryDesc.append("--- ").append(item->train()).append(" ---\n");

        calendarEntryDesc.append(formatStation(item->arrivalDateTime(),
                                               item->arrivalStation(),
                                               item->arrivalInfo()));
        calendarEntryDesc.append("\n");

        if (!item->info().isEmpty()) {
            calendarEntryDesc.append(item->info()).append("\n");
        }

        if (!compactFormat)
            calendarEntryDesc.append("\n");
    }

    if (!compactFormat)
        calendarEntryDesc.append(
            tr("-- \nAdded by Fahrplan. Please, re-check the information before your journey."));

#ifdef BUILD_FOR_BLACKBERRY

    CalendarService service;

    QPair<AccountId, FolderId> folder;

    settings.beginGroup("Calendar");
    folder.first = settings.value("AccountId", -1).toInt();
    if (folder.first >= 0)
        folder.second = settings.value("FolderId", -1).toInt();

    if ((folder.first < 0) || (folder.second < 0))
        folder = service.defaultCalendarFolder();

    CalendarEvent event;
    event.setAccountId(folder.first);
    event.setFolderId(folder.second);
    event.setSubject(calendarEntryTitle);
    event.setStartTime(m_result->departureDateTime());
    event.setEndTime(m_result->arrivalDateTime());
    event.setBody(calendarEntryDesc);
    event.setReminder(-1);

    emit addCalendarEntryComplete(service.createEvent(event) == Result::Success);

#elif defined(BUILD_FOR_HARMATTAN) || defined(BUILD_FOR_MAEMO_5) || defined(BUILD_FOR_SYMBIAN)

    QOrganizerManager defaultManager;
    QOrganizerEvent event;
    event.setDisplayLabel(calendarEntryTitle);
    event.setStartDateTime(m_result->departureDateTime());
    event.setEndDateTime(m_result->arrivalDateTime());
    event.setDescription(calendarEntryDesc);

    QString id = settings.value("Calendar/CollectionId").toString();
    if (!id.isEmpty()) {
        QOrganizerCollectionId collectionId = QOrganizerCollectionId::fromString(id);
        if (!collectionId.isNull())
            event.setCollectionId(collectionId);
    }

    emit addCalendarEntryComplete(defaultManager.saveItem(&event));
#else
    emit addCalendarEntryComplete(false);
#endif

    QThread::currentThread()->exit(0);

    // Move back to GUI thread so the deleteLater() callback works (it requires
    // an event loop which is still alive)
    moveToThread(QCoreApplication::instance()->thread());
}
Exemplo n.º 5
0
QTM_USE_NAMESPACE

TodoEditPage::TodoEditPage(QWidget *parent)
    :QWidget(parent),
    m_manager(0),
    m_subjectEdit(0),
    m_startTimeEdit(0),
    m_dueTimeEdit(0),
    m_priorityEdit(0),
    m_statusEdit(0),
    m_alarmComboBox(0)
{
    // Create widgets
    QLabel *subjectLabel = new QLabel("Subject:", this);
    m_subjectEdit = new QLineEdit(this);
    QLabel *startTimeLabel = new QLabel("Start time:", this);
    m_startTimeEdit = new QDateTimeEdit(this);
    m_startTimeEdit->setDisplayFormat(QString("yyyy-MM-dd hh:mm:ss AP"));
    QLabel *dueTimeLabel = new QLabel("Due time:", this);
    m_dueTimeEdit = new QDateTimeEdit(this);
    m_dueTimeEdit->setDisplayFormat(QString("yyyy-MM-dd hh:mm:ss AP"));
    QLabel *priorityLabel = new QLabel("Priority:", this);
    m_priorityEdit = new QComboBox(this);
    QLabel *statusLabel = new QLabel("Status:", this);
    m_statusEdit = new QComboBox(this);
    QLabel *alarmLabel = new QLabel("Alarm:", this);
    m_alarmComboBox = new QComboBox(this);
    QLabel *calendarLabel = new QLabel("Calendar:", this);

    QStringList alarmList;
    alarmList  << "None"
                << "0 minutes before"
                << "5 minutes before"
                << "15 minutes before"
                << "30 minutes before"
                << "1 hour before";
    m_alarmComboBox->addItems(alarmList);
    connect(m_alarmComboBox, SIGNAL(currentIndexChanged(const QString)), this,
                        SLOT(handleAlarmIndexChanged(const QString)));

    m_calendarComboBox = new QComboBox(this);
    // the calendar names are not know here, fill the combo box later...

#ifndef Q_OS_SYMBIAN
    // Add push buttons for non-Symbian platforms as they do not support soft keys
    QHBoxLayout* hbLayout = new QHBoxLayout();
    QPushButton *okButton = new QPushButton("Save", this);
    connect(okButton,SIGNAL(clicked()),this,SLOT(saveClicked()));
    hbLayout->addWidget(okButton);
    QPushButton *cancelButton = new QPushButton("Cancel", this);
    connect(cancelButton,SIGNAL(clicked()),this,SLOT(cancelClicked()));
    hbLayout->addWidget(cancelButton);
#endif

    // check to see whether we support alarms.
    QOrganizerManager defaultManager;
    QStringList supportedDefinitionNames = defaultManager.detailDefinitions(QOrganizerItemType::TypeTodo).keys();

    QVBoxLayout *scrollAreaLayout = new QVBoxLayout();
    scrollAreaLayout->addWidget(subjectLabel);
    scrollAreaLayout->addWidget(m_subjectEdit);
    scrollAreaLayout->addWidget(startTimeLabel);
    scrollAreaLayout->addWidget(m_startTimeEdit);
    scrollAreaLayout->addWidget(dueTimeLabel);
    scrollAreaLayout->addWidget(m_dueTimeEdit);
    scrollAreaLayout->addWidget(priorityLabel);
    scrollAreaLayout->addWidget(m_priorityEdit);
    scrollAreaLayout->addWidget(statusLabel);
    scrollAreaLayout->addWidget(m_statusEdit);
    if (supportedDefinitionNames.contains(QOrganizerItemVisualReminder::DefinitionName)) {
        scrollAreaLayout->addWidget(alarmLabel);
        scrollAreaLayout->addWidget(m_alarmComboBox);
    }
    scrollAreaLayout->addWidget(calendarLabel);
    scrollAreaLayout->addWidget(m_calendarComboBox);
    scrollAreaLayout->addStretch();
#ifndef Q_OS_SYMBIAN
    scrollAreaLayout->addLayout(hbLayout);
#endif

    QScrollArea *scrollArea = new QScrollArea(this);
    scrollArea->setWidgetResizable(true);
    QWidget *formContainer = new QWidget(scrollArea);
    formContainer->setLayout(scrollAreaLayout);
    scrollArea->setWidget(formContainer);

    QVBoxLayout *mainLayout = new QVBoxLayout();
    mainLayout->addWidget(scrollArea);
    setLayout(mainLayout);

    // Add softkeys
    QAction* cancelSoftKey = new QAction("Cancel", this);
    cancelSoftKey->setSoftKeyRole(QAction::NegativeSoftKey);
    addAction(cancelSoftKey);
    connect(cancelSoftKey, SIGNAL(triggered(bool)), this, SLOT(cancelClicked()));
    
    QAction* saveSoftKey = new QAction("Save", this);
    saveSoftKey->setSoftKeyRole(QAction::PositiveSoftKey);
    addAction(saveSoftKey);
    connect(saveSoftKey, SIGNAL(triggered(bool)), this, SLOT(saveClicked()));
    
    // Fill priority combo
    m_priorityEdit->addItem("Unknown", QVariant(QOrganizerItemPriority::UnknownPriority));
    m_priorityEdit->addItem("Highest", QVariant(QOrganizerItemPriority::HighestPriority));
    m_priorityEdit->addItem("Extremely high", QVariant(QOrganizerItemPriority::ExtremelyHighPriority));
    m_priorityEdit->addItem("Very high", QVariant(QOrganizerItemPriority::VeryHighPriority));
    m_priorityEdit->addItem("High", QVariant(QOrganizerItemPriority::HighPriority));
    m_priorityEdit->addItem("Medium", QVariant(QOrganizerItemPriority::MediumPriority));
    m_priorityEdit->addItem("Low", QVariant(QOrganizerItemPriority::LowPriority));
    m_priorityEdit->addItem("Very low", QVariant(QOrganizerItemPriority::VeryLowPriority));
    m_priorityEdit->addItem("Extremely low", QVariant(QOrganizerItemPriority::ExtremelyLowPriority));
    m_priorityEdit->addItem("Lowest", QVariant(QOrganizerItemPriority::LowestPriority));

    // Fill status combo
    m_statusEdit->addItem("Not started", QVariant(QOrganizerTodoProgress::StatusNotStarted));
    m_statusEdit->addItem("In progress", QVariant(QOrganizerTodoProgress::StatusInProgress));
    m_statusEdit->addItem("Complete", QVariant(QOrganizerTodoProgress::StatusComplete));
}
Exemplo n.º 6
0
void FahrplanCalendarManager::getCalendarsList()
{
    settings->beginGroup("Calendar");
#ifdef BUILD_FOR_BLACKBERRY
    int accountId = settings->value("AccountId", -1).toInt();
    int folderId = settings->value("FolderId", -1).toInt();

    bb::pim::calendar::CalendarService service;
    bb::pim::account::AccountService accservice;
    QList<bb::pim::calendar::CalendarFolder> folders = service.folders();
    foreach (const bb::pim::calendar::CalendarFolder &folder, folders) {
        if (!folder.isVisible() || folder.isReadOnly())
            continue;

        QString account;
        if (folder.accountId() == 1)
            account = tr("Local Calendar");
        else
            account = accservice.account(folder.accountId()).displayName();

        //: Calendar name (Account name)
        m_calendars << CalendarInfo(tr("%1 (%2)", "Calendar name (Account name)")
                                    .arg(folder.name()).arg(account)
                                    , folder.accountId(), folder.id());
        if ((folder.id() == folderId) && (folder.accountId() == accountId)) {
            m_selectedIndex = m_calendars.count() - 1;
            emit selectedIndexChanged();
        }
    }
#elif defined(BUILD_FOR_SAILFISHOS)

#elif !defined(BUILD_FOR_DESKTOP) && !defined(BUILD_FOR_UBUNTU)
    QString id = settings->value("CollectionId").toString();
    QOrganizerCollectionId collectionId = QOrganizerCollectionId::fromString(id);

    QOrganizerManager manager;
    QList<QOrganizerCollection> collections = manager.collections();
    foreach (const QOrganizerCollection &collection, collections) {
        // TODO: Find out ??? where possible.
        // Hidden/disabled calendar:
        // - IsVisible on Harmattan;
        // - Enabled on Symbian;
        // - ??? on Ubuntu Touch.
        // Read only calendar:
        // - IsReadOnly on Harmattan;
        // - ??? on Symbian;
        // - ??? on Ubuntu Touch.
        // Calendar doesn't store events (stores only notes, todos, etc.):
        // - EventsAllowed on Harmattan;
        // - ??? on Symbian;
        // - ??? on Ubuntu Touch.
        // ??? temporary calendar ???:
        // - IsRunTimeOnly on Harmattan;
        // - ??? on Symbian;
        // - ??? on Ubuntu Touch.
        if (
#ifdef BUILD_FOR_HARMATTAN
                collection.metaData("IsReadOnly").toBool()
                || !collection.metaData("IsVisible").toBool()
                || !collection.metaData("EventsAllowed").toBool()
                || collection.metaData("IsRunTimeOnly").toBool()
#elif defined(BUILD_FOR_SYMBIAN)
                !collection.metaData("Enabled").toBool()
#else
                // Show all calendars by default on
                // unknown/unsupported platforms.
                false
#endif
                )
            continue;

        m_calendars << CalendarInfo(normalizeCalendarName(collection.metaData(QOrganizerCollection::KeyName).toString()), collection.id().toString());
        if (collection.id() == collectionId)
            m_selectedIndex = m_calendars.count() - 1;
    }
#endif
    settings->endGroup();
}
Exemplo n.º 7
0
void CalendarThreadWrapper::addToCalendar()
{
#if defined(MEEGO_EDITION_HARMATTAN) || defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)

    QString desc;
    const QString viaStation = m_result->viaStation();
    if (viaStation.isEmpty())
        desc.append(tr("%1 to %2").arg(m_result->departureStation()).arg(m_result->arrivalStation()) + "\n");
    else
        desc.append(tr("%1 via %3 to %2").arg(m_result->departureStation()).arg(m_result->arrivalStation()).arg(viaStation) + "\n");

    if (!m_result->info().isEmpty()) {
        desc.append(m_result->info() + "\n");
    }

    for (int i=0; i < m_result->itemcount(); i++) {
        JourneyDetailResultItem *item = m_result->getItem(i);

        if (!item->train().isEmpty()) {
            desc.append(item->train() + "\n");
        }
        desc.append(item->departureDateTime().date().toString() + " " + item->departureDateTime().time().toString("HH:mm") + " " + item->departureStation());
        if (!item->departureInfo().isEmpty()) {
            desc.append(" - " + item->departureInfo());
        }
        desc.append("\n");
        desc.append(item->arrivalDateTime().date().toString() + " " + item->arrivalDateTime().time().toString("HH:mm") + " " + item->arrivalStation());
        if (!item->arrivalInfo().isEmpty()) {
            desc.append(" - " + item->arrivalInfo());
        }
        desc.append("\n");
        if (!item->info().isEmpty()) {
            desc.append(item->info() + "\n");
        }
        desc.append("--\n");
    }

    desc.append(tr("\n(added by fahrplan app, please recheck informations before travel.)"));


    QOrganizerManager defaultManager;
    QOrganizerEvent event;

    if (viaStation.isEmpty())
        event.setDisplayLabel(tr("Journey: %1 to %2").arg(m_result->departureStation()).arg(m_result->arrivalStation()));
    else
        event.setDisplayLabel(tr("Journey: %1 via %3 to %2").arg(m_result->departureStation()).arg(m_result->arrivalStation()).arg(viaStation));
    event.setDescription(desc);
    event.setStartDateTime(m_result->departureDateTime());
    event.setEndDateTime(m_result->arrivalDateTime());

    emit addCalendarEntryComplete(defaultManager.saveItem(&event));

#else

    emit addCalendarEntryComplete(false);

#endif

    QThread::currentThread()->exit(0);

    // Move back to GUI thread so the deleteLater() callback works (it requires
    // an event loop which is still alive)
    moveToThread(QCoreApplication::instance()->thread());
}
void CalendarCollections::refresh()
{
    QOrganizerManager organizerManager;
    mCollections = organizerManager.collections();
}