bool QOrganizerSimulatorEngine::saveCollection(QOrganizerCollection *collection, QOrganizerManager::Error *error) { Connection *con = Connection::instance(); if (!con->mNotifySimulator) return QOrganizerItemMemoryEngine::saveCollection(collection, error); // translate local id -> remote id QOrganizerCollection remoteCollection = *collection; con->translateCollectionIds(&remoteCollection, con->mLocalToRemote); bool newCollection = remoteCollection.id().isNull(); // save remotely QLocalSocket *sendSocket = con->sendSocket(); Simulator::SaveOrganizerCollectionReply reply = RemoteMetacall<Simulator::SaveOrganizerCollectionReply>::call( sendSocket, TimeoutSync, "requestSaveOrganizerCollection", remoteCollection); *error = reply.error; // if it failed, stop if (reply.error != QOrganizerManager::NoError) return false; // save locally if (!QOrganizerItemMemoryEngine::saveCollection(collection, error)) return false; // it's already saved remotely - revert? if (newCollection) { con->mRemoteToLocal.collections.insert(reply.savedCollection.id(), collection->id()); con->mLocalToRemote.collections.insert(collection->id(), reply.savedCollection.id()); } return true; }
/*! Streams the \a collection to the given debug stream \a dbg, and returns the stream. \since 1.1 */ QDebug operator<<(QDebug dbg, const QOrganizerCollection& collection) { dbg.nospace() << "QOrganizerCollection(id=" << collection.id(); QVariantMap metadata = collection.metaData(); QVariantMap::const_iterator it; for (it = metadata.constBegin(); it != metadata.constEnd(); ++it) { dbg.nospace() << ", " << it.key() << '=' << it.value(); } dbg.nospace() << ')'; return dbg.maybeSpace(); }
/*! Returns the hash value for \a key. \since 1.1 */ uint qHash(const QOrganizerCollection &key) { uint hash = qHash(key.id()); QVariantMap metadata = key.metaData(); QVariantMap::const_iterator it; for (it = metadata.constBegin(); it != metadata.constEnd(); ++it) { hash += qHash(it.key()) + QT_PREPEND_NAMESPACE(qHash)(it.value().toString()); } return hash; }
foreach(QOrganizerCollection collection, m_collections) { // We currently have no way of stringifying ids // QString visibleName = "Calendar id = " + QString::number(collection.id().localId()); QString visibleName = "Calendar " + QString::number(counter); if (!calendarNameMetadataKey.isNull()) visibleName = collection.metaData(calendarNameMetadataKey).toString(); m_calendarComboBox->addItem(visibleName); if (collection.id() == todo.collectionId()) todoCalendarIndex = counter; ++counter; }
void AddCalendarPage::calendarChanged(QOrganizerManager *manager, QOrganizerCollection& calendar) { m_manager = manager; m_collection = calendar; window()->setWindowTitle(!calendar.id().isNull() ? "Edit calendar" : "Add calendar"); #if defined(Q_WS_MAEMO_5) // Maemo5 calendar features QVariant calendarName = calendar.metaData("Name"); if (calendarName.canConvert(QVariant::String)) m_nameEdit->setText(calendarName.toString()); QVariant colorList = calendar.metaData("Available colors"); QStringList availableColors; if (colorList.canConvert(QVariant::StringList)) availableColors = colorList.toStringList(); int index = 0; foreach(QString color, availableColors) { m_colorComboBox->addItem(color); if (calendar.metaData("Color").toString() == color) m_colorComboBox->setCurrentIndex(index); ++index; }
void AddCalendarPage::calendarChanged(QOrganizerManager *manager, QOrganizerCollection& calendar) { m_manager = manager; m_collection = calendar; window()->setWindowTitle(!calendar.id().isNull() ? "Edit calendar" : "Add calendar"); }
void tst_QOrganizerCollection::datastream() { // collection datastreaming QByteArray buffer; QOrganizerCollection collectionIn; collectionIn.setMetaData("key", "value"); QOrganizerCollection collectionOut; QOrganizerCollectionId originalId; // first, stream an item with a complete id { QDataStream stream1(&buffer, QIODevice::WriteOnly); QOrganizerManager om("memory"); QVERIFY(om.saveCollection(&collectionIn)); // fill in its ID originalId = collectionIn.id(); stream1 << collectionIn; QVERIFY(buffer.size() > 0); QDataStream stream2(buffer); stream2 >> collectionOut; QCOMPARE(collectionOut, collectionIn); // can use QCOMPARE for collections, since no detail keys. } // second, stream an item with an id with the mgr uri set, local id null { QDataStream stream1(&buffer, QIODevice::WriteOnly); collectionIn.setId(QOrganizerCollectionId()); stream1 << collectionIn; QVERIFY(buffer.size() > 0); QDataStream stream2(buffer); stream2 >> collectionOut; QCOMPARE(collectionOut, collectionIn); // can use QCOMPARE for collections, since no detail keys. } /* TODO: Review tests // third, stream an item with an id with the mgr uri null, local id set { QDataStream stream1(&buffer, QIODevice::WriteOnly); QOrganizerCollectionId modifiedId = originalId; modifiedId.setManagerUri(QString()); // this will clear the local id! modifiedId.setId(originalId.localId()); // so reset it and make sure nothing bad happens. collectionIn.setId(modifiedId); stream1 << collectionIn; QVERIFY(buffer.size() > 0); QDataStream stream2(buffer); stream2 >> collectionOut; QVERIFY(collectionOut.metaData() == collectionIn.metaData()); QVERIFY(collectionOut.id() != collectionIn.id()); // no manager uri of input :. won't be serialized. }*/ // fourth, stream an item with a null id { QDataStream stream1(&buffer, QIODevice::WriteOnly); collectionIn.setId(QOrganizerCollectionId()); stream1 << collectionIn; QVERIFY(buffer.size() > 0); QDataStream stream2(buffer); stream2 >> collectionOut; QVERIFY(collectionOut.metaData() == collectionIn.metaData()); QVERIFY(collectionOut.id() == collectionIn.id()); // should both be null ids. } // id datastreaming buffer.clear(); QOrganizerCollectionId inputId; QOrganizerCollectionId outputId; // first, stream the whole id (mgr uri set, local id set) { inputId = originalId; QString serializedId = inputId.toString(); outputId = QOrganizerCollectionId::fromString(serializedId); QCOMPARE(inputId, outputId); inputId = originalId; buffer.clear(); QDataStream stream1(&buffer, QIODevice::WriteOnly); stream1 << inputId; QVERIFY(buffer.size() > 0); QDataStream stream2(buffer); stream2 >> outputId; QCOMPARE(inputId, outputId); } /* TODO: review test // second, stream a partial id (mgr uri null, local id set) { inputId.setManagerUri(QString()); inputId.setId(originalId.localId()); buffer.clear(); QDataStream stream1(&buffer, QIODevice::WriteOnly); stream1 << inputId; QVERIFY(buffer.size() > 0); QDataStream stream2(buffer); stream2 >> outputId; // because the manager uri is null, we cannot stream it in. QVERIFY(outputId.isNull()); QVERIFY(!inputId.isNull()); } // third, stream a partial id (mgr uri set, local id null). { inputId.setManagerUri(originalId.managerUri()); inputId.setId(QOrganizerCollectionId()); buffer.clear(); QDataStream stream1(&buffer, QIODevice::WriteOnly); stream1 << inputId; QVERIFY(buffer.size() > 0); QDataStream stream2(buffer); stream2 >> outputId; QCOMPARE(inputId, outputId); }*/ // fourth, stream a null id { inputId = QOrganizerCollectionId(); QString serializedId = inputId.toString(); outputId = QOrganizerCollectionId::fromString(serializedId); QCOMPARE(inputId, outputId); inputId = QOrganizerCollectionId(); buffer.clear(); QDataStream stream1(&buffer, QIODevice::WriteOnly); stream1 << inputId; QVERIFY(buffer.size() > 0); QDataStream stream2(buffer); stream2 >> outputId; QCOMPARE(inputId, outputId); } /* TODO: review test // fifth, stream an id after changing it's manager uri. { inputId.setManagerUri(originalId.managerUri()); inputId.setId(originalId.localId()); inputId.setManagerUri("test manager uri"); // should clear the local id. QVERIFY(inputId.localId() == QOrganizerCollectionId()); buffer.clear(); QDataStream stream1(&buffer, QIODevice::WriteOnly); stream1 << inputId; QVERIFY(buffer.size() > 0); QDataStream stream2(buffer); stream2 >> outputId; QCOMPARE(inputId, outputId); } // sixth, stream an id after changing it's manager uri and resetting the local id. // this should cause great problems, because the manager doesn't exist so it shouldn't // be able to deserialize. Make sure it's handled gracefully. { inputId.setManagerUri(originalId.managerUri()); inputId.setManagerUri("test manager uri"); // should clear the local id. inputId.setId(originalId.localId()); buffer.clear(); QDataStream stream1(&buffer, QIODevice::WriteOnly); stream1 << inputId; QVERIFY(buffer.size() > 0); QDataStream stream2(buffer); stream2 >> outputId; QVERIFY(outputId.isNull()); } */ }