void TodoEditPage::todoChanged(QOrganizerManager *manager, const QOrganizerTodo &todo) { m_manager = manager; m_organizerTodo = todo; m_subjectEdit->setText(todo.displayLabel()); m_startTimeEdit->setDateTime(todo.startDateTime()); m_dueTimeEdit->setDateTime(todo.dueDateTime()); int index = m_priorityEdit->findData(QVariant(todo.priority())); m_priorityEdit->setCurrentIndex(index); index = m_priorityEdit->findData(QVariant(todo.status())); m_statusEdit->setCurrentIndex(index); // set calendar selection m_calendarComboBox->clear(); // resolve metadata field that contains calendar name (if any) QString calendarNameMetadataKey; m_collections = m_manager->collections(); if (!m_collections.isEmpty()) { QOrganizerCollection firstCollection = m_collections[0]; QVariantMap metadata = firstCollection.metaData(); QList<QString> metaDataKeys = metadata.keys(); foreach(QString key, metaDataKeys) { if (key.indexOf("name", 0, Qt::CaseInsensitive) != -1) { calendarNameMetadataKey = key; break; } } }
//! [4] void Window::deleteTodo() { QList<QListWidgetItem *> items = listWidget->selectedItems(); if (!items.isEmpty()) { QVariant variant = items.at(0)->data(Qt::UserRole); if (variant.canConvert<QOrganizerTodo>()) { QOrganizerTodo theTodo = variant.value<QOrganizerTodo>(); manager->removeItem(theTodo.id()); refreshList(); } } }
//! [1] void Window::editNewTodo() { QOrganizerTodo newTodo; newTodo.setPriority(QOrganizerItemPriority::HighPriority); newTodo.setStatus(QOrganizerTodoProgress::StatusNotStarted); QDateTime currentDateTime(calendarWidget->selectedDate(), QTime::currentTime()); newTodo.setStartDateTime(currentDateTime); newTodo.setDueDateTime(currentDateTime.addSecs(60*60)); todoEditor->editTodo(newTodo); stackedWidget->setCurrentWidget(todoEditor); }
void tst_QOrganizerItemDetails::type() { QOrganizerItem oi; QOrganizerItemType t1, t2; QOrganizerEvent e; QOrganizerNote n; QOrganizerTodo t; QOrganizerJournal j; QOrganizerEventOccurrence eo; QOrganizerTodoOccurrence to; QVERIFY(e.type() == QOrganizerItemType::TypeEvent); QVERIFY(n.type() == QOrganizerItemType::TypeNote); QVERIFY(t.type() == QOrganizerItemType::TypeTodo); QVERIFY(j.type() == QOrganizerItemType::TypeJournal); QVERIFY(eo.type() == QOrganizerItemType::TypeEventOccurrence); QVERIFY(to.type() == QOrganizerItemType::TypeTodoOccurrence); // test property set t1.setType(QOrganizerItemType::TypeEvent); QCOMPARE(t1.type(), QOrganizerItemType::TypeEvent); QCOMPARE(static_cast<QOrganizerItemType::ItemType>(t1.value(QOrganizerItemType::FieldType).toInt()), QOrganizerItemType::TypeEvent); // test property add QVERIFY(oi.saveDetail(&t1)); QCOMPARE(oi.details(QOrganizerItemDetail::TypeItemType).count(), 1); QCOMPARE(QOrganizerItemType(oi.details(QOrganizerItemDetail::TypeItemType).value(0)).type(), t1.type()); // test property update t1.setType(QOrganizerItemType::TypeTodo); QVERIFY(oi.saveDetail(&t1)); QCOMPARE(static_cast<QOrganizerItemType::ItemType>(oi.details(QOrganizerItemDetail::TypeItemType).value(0).value(QOrganizerItemType::FieldType).toInt()), QOrganizerItemType::TypeTodo); // test property remove QVERIFY(!oi.removeDetail(&t1)); // cannot remove type QCOMPARE(oi.details(QOrganizerItemDetail::TypeItemType).count(), 1); t2.setType(QOrganizerItemType::TypeNote); QVERIFY(oi.saveDetail(&t2)); // overwrites t1 QCOMPARE(oi.details(QOrganizerItemDetail::TypeItemType).count(), 1); QVERIFY(!oi.removeDetail(&t2)); // cannot remove type - "succeeds" but count remains unchanged QCOMPARE(oi.details(QOrganizerItemDetail::TypeItemType).count(), 1); QVERIFY(!oi.removeDetail(&t2)); QCOMPARE(oi.details(QOrganizerItemDetail::TypeItemType).count(), 1); }
void tst_QOrganizerItemDetails::todoProgress() { QOrganizerTodoProgress p; QOrganizerTodo t; QVERIFY(p.status() == QOrganizerTodoProgress::StatusNotStarted); QVERIFY(p.isEmpty()); p.setStatus(QOrganizerTodoProgress::StatusInProgress); QVERIFY(!p.isEmpty()); QVERIFY(p.status() == QOrganizerTodoProgress::StatusInProgress); p.setPercentageComplete(50); QVERIFY(p.percentageComplete() == 50); p.setPercentageComplete(200); // this should fail QVERIFY(p.percentageComplete() == 50); // value should remain unchanged. p.setFinishedDateTime(QDateTime(QDate(2010, 10, 13))); QVERIFY(p.finishedDateTime() == QDateTime(QDate(2010, 10, 13))); QVERIFY(p.status() != QOrganizerTodoProgress::StatusComplete); // XXX TODO: should this be automatic? p.setPercentageComplete(100); QVERIFY(p.percentageComplete() == 100); QVERIFY(p.status() != QOrganizerTodoProgress::StatusComplete); // XXX TODO: should this be automatic? // add QVERIFY(t.saveDetail(&p)); QVERIFY(t.details(QOrganizerItemDetail::TypeTodoProgress).size() == 1); QVERIFY(t.detail(QOrganizerItemDetail::TypeTodoProgress) == p); // update p.setStatus(QOrganizerTodoProgress::StatusComplete); QVERIFY(p.status() == QOrganizerTodoProgress::StatusComplete); QVERIFY(t.detail(QOrganizerItemDetail::TypeTodoProgress) != p); QVERIFY(t.saveDetail(&p)); QVERIFY(t.details(QOrganizerItemDetail::TypeTodoProgress).size() == 1); // update, not add another QVERIFY(t.detail(QOrganizerItemDetail::TypeTodoProgress) == p); // remove QVERIFY(t.removeDetail(&p)); QVERIFY(t.details(QOrganizerItemDetail::TypeTodoProgress).size() == 0); }
//! [5] void Window::refreshList() { listWidget->clear(); QOrganizerItemSortOrder sortOrder; sortOrder.setDetailDefinitionName(QOrganizerTodoTime::DefinitionName, QOrganizerTodoTime::FieldDueDateTime); QList<QOrganizerItem> items = manager->items(QOrganizerItemFilter(), QList<QOrganizerItemSortOrder>() << sortOrder); //! [5] if (items.isEmpty()) { new QListWidgetItem("<No Todos>", listWidget); } //! [6] foreach(QOrganizerItem item, items) { if (item.type() == QOrganizerItemType::TypeTodo) { QOrganizerTodo todo = static_cast<QOrganizerTodo>(item); if (todo.startDateTime() > QDateTime(calendarWidget->selectedDate(), QTime(23,59)) || todo.dueDateTime() < QDateTime(calendarWidget->selectedDate(), QTime(0, 0))) continue; QString display = todo.startDateTime().toString("yy/MM/dd hh:mm") + "-" + todo.dueDateTime().toString("yy/MM/dd hh:mm") + " - "+ todo.displayLabel(); QListWidgetItem *listItem = new QListWidgetItem(display, listWidget); listItem->setData(Qt::UserRole, QVariant::fromValue(todo)); } } }
void TodoEditPage::todoChanged(QOrganizerManager *manager, const QOrganizerTodo &todo) { m_manager = manager; m_organizerTodo = todo; m_subjectEdit->setText(todo.displayLabel()); m_startTimeEdit->setDateTime(todo.startDateTime()); m_dueTimeEdit->setDateTime(todo.dueDateTime()); int index = m_priorityEdit->findData(QVariant(todo.priority())); m_priorityEdit->setCurrentIndex(index); index = m_priorityEdit->findData(QVariant(todo.status())); m_statusEdit->setCurrentIndex(index); // set calendar selection m_calendarComboBox->clear(); // resolve metadata field that contains calendar name (if any) m_collections = m_manager->collections(); int counter = 0; int todoCalendarIndex = -1; foreach(QOrganizerCollection collection, m_collections) { // We currently have no way of stringifying ids // QString visibleName = "Calendar id = " + QString::number(collection.id().localId()); QString visibleName = collection.metaData(QOrganizerCollection::KeyName).toString(); if (visibleName.isEmpty()) visibleName = "Calendar " + QString::number(index); m_calendarComboBox->addItem(visibleName); if (collection.id() == todo.collectionId()) todoCalendarIndex = counter; ++counter; }
QOrganizerTodo OrganizerItemTransform::convertCTodoToQTodo(CTodo *ctodo) { QOrganizerTodo retn; // Priority int tempint = ctodo->getPriority(); if (tempint != -1) retn.setPriority(static_cast<QOrganizerItemPriority::Priority>(tempint)); // Date start QDateTime tempdt = QDateTime::fromTime_t(ctodo->getDateStart()); if (!tempdt.isNull()) retn.setStartDateTime(tempdt); // Due tempdt = QDateTime::fromTime_t(ctodo->getDue()); if (!tempdt.isNull()) retn.setDueDateTime(tempdt); // Completed time tempdt = QDateTime::fromTime_t(ctodo->getCompleted()); if (!tempdt.isNull()) retn.setFinishedDateTime(tempdt); // Percent complete tempint = ctodo->getPercentComplete(); if (tempint != -1) retn.setProgressPercentage(tempint); // Status retn.setStatus(static_cast<QOrganizerTodoProgress::Status>(ctodo->getStatus())); // Location geo coordinates QOrganizerItemLocation loc = retn.detail<QOrganizerItemLocation>(); if(addGeoToQOIL(QString::fromStdString(ctodo->getGeo()), &loc)) retn.saveDetail(&loc); return retn; }
void tst_QOrganizerItemDetails::todoTime() { QOrganizerTodoTime r; QOrganizerTodo t; QVERIFY(r.isEmpty()); QVERIFY(!r.isAllDay()); r.setStartDateTime(QDateTime(QDate(2010, 10, 13))); QVERIFY(r.startDateTime() == QDateTime(QDate(2010, 10, 13))); QVERIFY(!r.isAllDay()); r.setAllDay(true); QVERIFY(r.isAllDay()); r.setDueDateTime(QDateTime(QDate(2010, 10, 14))); QVERIFY(r.dueDateTime() == QDateTime(QDate(2010, 10, 14))); // add QOrganizerTodoTime r2; r2.setStartDateTime(QDateTime(QDate(2010, 10, 23))); r2.setDueDateTime(QDateTime(QDate(2010, 10, 24))); QVERIFY(t.saveDetail(&r)); QVERIFY(t.details<QOrganizerTodoTime>().size() == 1); QVERIFY(t.detail<QOrganizerTodoTime>() == r); QVERIFY(t.saveDetail(&r2)); // note that we don't enforce uniqueness in organizeritem; that's done by the manager! QVERIFY(t.details<QOrganizerTodoTime>().size() == 2); QVERIFY(t.removeDetail(&r2)); QVERIFY(t.details<QOrganizerTodoTime>().size() == 1); QVERIFY(t.detail<QOrganizerTodoTime>() == r); // update r.setAllDay(false); QVERIFY(t.detail<QOrganizerTodoTime>() != r); QVERIFY(t.saveDetail(&r)); QVERIFY(t.detail<QOrganizerTodoTime>() == r); QVERIFY(t.details<QOrganizerTodoTime>().size() == 1); // remove QVERIFY(t.removeDetail(&r)); QVERIFY(t.details<QOrganizerTodoTime>().size() == 0); }
void tst_QVersitOrganizerExporter::testExport_data() { QTest::addColumn<QList<QOrganizerItem> >("items"); QTest::addColumn<QVersitDocument>("expectedDocument"); { QVersitDocument document(QVersitDocument::ICalendar20Type); document.setComponentType(QLatin1String("VCALENDAR")); QVersitDocument nested(QVersitDocument::ICalendar20Type); nested.setComponentType(QLatin1String("VEVENT")); QVersitProperty property; property.setName(QLatin1String("SUMMARY")); property.setValue(QLatin1String("Bastille Day Party")); nested.addProperty(property); property.setName(QLatin1String("DTSTART")); property.setValue(QLatin1String("19970714T170000Z")); nested.addProperty(property); property.setName(QLatin1String("DTEND")); property.setValue(QLatin1String("19970715T035959Z")); nested.addProperty(property); document.addSubDocument(nested); nested.clear(); nested.setType(QVersitDocument::ICalendar20Type); nested.setComponentType(QLatin1String("VTODO")); property.setName(QLatin1String("SUMMARY")); property.setValue(QLatin1String("Take out the garbage")); nested.addProperty(property); property.setName(QLatin1String("DTSTART")); property.setValue(QLatin1String("20100609T080000")); nested.addProperty(property); property.setName(QLatin1String("DUE")); property.setValue(QLatin1String("20100610T080000")); nested.addProperty(property); document.addSubDocument(nested); nested.clear(); nested.setType(QVersitDocument::ICalendar20Type); nested.setComponentType(QLatin1String("VJOURNAL")); property.setName(QLatin1String("SUMMARY")); property.setValue(QLatin1String("Trip to Thailand")); nested.addProperty(property); property.setName(QLatin1String("DTSTART")); property.setValue(QLatin1String("20100615T112300")); nested.addProperty(property); document.addSubDocument(nested); QOrganizerEvent event; event.setDisplayLabel(QLatin1String("Bastille Day Party")); event.setStartDateTime(QDateTime(QDate(1997, 7, 14), QTime(17, 0, 0), Qt::UTC)); event.setEndDateTime(QDateTime(QDate(1997, 7, 15), QTime(3, 59, 59), Qt::UTC)); QOrganizerTodo todo; todo.setDisplayLabel(QLatin1String("Take out the garbage")); todo.setStartDateTime(QDateTime(QDate(2010, 6, 9), QTime(8, 0, 0))); todo.setDueDateTime(QDateTime(QDate(2010, 6, 10), QTime(8, 0, 0))); QOrganizerJournal journal; journal.setDisplayLabel(QLatin1String("Trip to Thailand")); journal.setDateTime(QDateTime(QDate(2010, 6, 15), QTime(11, 23, 0))); QList<QOrganizerItem> items; items << static_cast<QOrganizerItem>(event); items << static_cast<QOrganizerItem>(todo); items << static_cast<QOrganizerItem>(journal); QTest::newRow("sample event, todo and journal") << items << document; } { QVersitDocument document(QVersitDocument::ICalendar20Type); document.setComponentType(QLatin1String("VCALENDAR")); QVersitDocument nested(QVersitDocument::ICalendar20Type); nested.setComponentType(QLatin1String("VEVENT")); QVersitProperty property; property.setName(QLatin1String("UID")); property.setValue(QLatin1String("1234")); nested.addProperty(property); property.setName(QLatin1String("RECURRENCE-ID")); property.setValue(QLatin1String("20100608")); nested.addProperty(property); document.addSubDocument(nested); // An event occurrence with OriginalDate and Guid set QOrganizerEventOccurrence event; event.setGuid(QLatin1String("1234")); event.setOriginalDate(QDate(2010, 6, 8)); QList<QOrganizerItem> items; items << static_cast<QOrganizerItem>(event); QTest::newRow("event occurrence exception") << items << document; } }