int ContactsHandler::setEntry(const Akonadi::Item &item, QString &newId, QString &errorMessage) { if (!item.hasPayload<KContacts::Addressee>()) { qCCritical(FATCRM_SUGARCRMRESOURCE_LOG) << "item (id=" << item.id() << ", remoteId=" << item.remoteId() << ", mime=" << item.mimeType() << ") is missing Addressee payload"; return SugarJob::InvalidContextError; } QList<KDSoapGenerated::TNS__Name_value> itemList; // if there is an id add it, otherwise skip this field // no id will result in the contact being added if (!item.remoteId().isEmpty()) { KDSoapGenerated::TNS__Name_value field; field.setName(QStringLiteral("id")); field.setValue(item.remoteId()); itemList << field; } // add regular sugar fields const KContacts::Addressee addressee = item.payload<KContacts::Addressee>(); KDSoapGenerated::TNS__Name_value_list valueList = addresseeToNameValueList(addressee, itemList); return mSession->protocol()->setEntry(module(), valueList, newId, errorMessage); }
TaskQueries::TaskResult::Ptr TaskQueries::findChildren(Domain::Task::Ptr task) const { Akonadi::Item item = m_serializer->createItemFromTask(task); if (!m_findChildren.contains(item.id())) { TaskQuery::Ptr query; { TaskQueries *self = const_cast<TaskQueries*>(this); query = self->createTaskQuery(); self->m_findChildren.insert(item.id(), query); } query->setFetchFunction([this, item] (const TaskQuery::AddFunction &add) { ItemFetchJobInterface *job = m_storage->fetchItem(item); Utils::JobHandler::install(job->kjob(), [this, job, add] { if (job->kjob()->error() != KJob::NoError) return; Q_ASSERT(job->items().size() == 1); auto item = job->items()[0]; Q_ASSERT(item.parentCollection().isValid()); ItemFetchJobInterface *job = m_storage->fetchItems(item.parentCollection()); Utils::JobHandler::install(job->kjob(), [this, job, add] { if (job->kjob()->error() != KJob::NoError) return; for (auto item : job->items()) add(item); }); }); }); query->setConvertFunction([this] (const Akonadi::Item &item) { return m_serializer->createTaskFromItem(item); }); query->setUpdateFunction([this] (const Akonadi::Item &item, Domain::Task::Ptr &task) { m_serializer->updateTaskFromItem(task, item); }); query->setPredicateFunction([this, task] (const Akonadi::Item &item) { return m_serializer->isTaskChild(task, item); }); query->setRepresentsFunction([this] (const Akonadi::Item &item, const Domain::Task::Ptr &task) { return m_serializer->representsItem(task, item); }); } return m_findChildren.value(item.id())->result(); }
void shouldAllowToSetId() { // GIVEN Akonadi::Item item = GenTodo().withId(42); // THEN QCOMPARE(item.id(), 42LL); }
int DocumentsHandler::setEntry(const Akonadi::Item &item, QString &newId, QString &errorMessage) { if (!item.hasPayload<SugarDocument>()) { qCCritical(FATCRM_SUGARCRMRESOURCE_LOG) << "item (id=" << item.id() << ", remoteId=" << item.remoteId() << ", mime=" << item.mimeType() << ") is missing Document payload"; return SugarJob::InvalidContextError; } QList<KDSoapGenerated::TNS__Name_value> itemList; // if there is an id add it, otherwise skip this field // no id will result in the email being added if (!item.remoteId().isEmpty()) { KDSoapGenerated::TNS__Name_value field; field.setName(QStringLiteral("id")); field.setValue(item.remoteId()); itemList << field; } const SugarDocument document = item.payload<SugarDocument>(); const SugarDocument::AccessorHash accessors = SugarDocument::accessorHash(); SugarDocument::AccessorHash::const_iterator it = accessors.constBegin(); SugarDocument::AccessorHash::const_iterator endIt = accessors.constEnd(); for (; it != endIt; ++it) { // check if this is a read-only field if (it.key() == QLatin1String("id")) { continue; } const SugarDocument::valueGetter getter = (*it).getter; KDSoapGenerated::TNS__Name_value field; field.setName(sugarFieldFromCrmField(it.key())); field.setValue(KDCRMUtils::encodeXML((document.*getter)())); itemList << field; } // plus custom fields QMap<QString, QString> customFields = document.customFields(); QMap<QString, QString>::const_iterator cit = customFields.constBegin(); const QMap<QString, QString>::const_iterator end = customFields.constEnd(); for ( ; cit != end ; ++cit ) { KDSoapGenerated::TNS__Name_value field; field.setName(customSugarFieldFromCrmField(cit.key())); field.setValue(KDCRMUtils::encodeXML(cit.value())); itemList << field; } KDSoapGenerated::TNS__Name_value_list valueList; valueList.setItems(itemList); return mSession->protocol()->setEntry(module(), valueList, newId, errorMessage); }
void KOEventViewerDialog::showIncidenceContext() { const Akonadi::Item item = mEventViewer->item(); if ( CalendarSupport::hasIncidence( item ) ) { // make sure korganizer is running or the part is shown KToolInvocation::startServiceByDesktopPath( "korganizer" ); OrgKdeKorganizerKorganizerInterface korganizerIface( "org.kde.korganizer", "/Korganizer", QDBusConnection::sessionBus() ); korganizerIface.showIncidenceContext( QString::number( item.id() ) ); } }
QString KJotsLinkDialog::linkUrl() const { if (hrefComboRadioButton->isChecked()){ const QModelIndex index = hrefCombo->view()->currentIndex(); const Akonadi::Collection collection = index.data(Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>(); if (collection.isValid()) { return "kjots://org.kjots.book/" + QString::number(collection.id()); } const Akonadi::Item item = index.data(Akonadi::EntityTreeModel::ItemRole).value<Akonadi::Item>(); Q_ASSERT(item.isValid()); return "kjots://org.kjots.page/" + QString::number(item.id()); } else { return linkUrlLineEdit->text(); } }
bool KolabHelpers::checkForErrors(const Akonadi::Item &item) { if (!Kolab::ErrorHandler::instance().errorOccured()) { Kolab::ErrorHandler::instance().clear(); return false; } QString errorMsg; foreach (const Kolab::ErrorHandler::Err &error, Kolab::ErrorHandler::instance().getErrors()) { errorMsg.append(error.message); errorMsg.append(QLatin1String("\n")); } qCWarning(KOLABRESOURCE_LOG) << "Error on item with id: " << item.id() << " remote id: " << item.remoteId() << ":\n" << errorMsg; Kolab::ErrorHandler::instance().clear(); return true; }
bool SalesforceContactsHandler::setEntry(const Akonadi::Item &item, SforceService *soap) { if (!item.hasPayload<KABC::Addressee>()) { kError() << "item (id=" << item.id() << ", remoteId=" << item.remoteId() << ", mime=" << item.mimeType() << ") is missing Addressee payload"; return false; } ENS__SObject object; object.setType(QLatin1String("Contact")); // if there is an id add it, otherwise skip this field // no id will result in the contact being added if (!item.remoteId().isEmpty()) { object.setId(item.remoteId()); } const KABC::Addressee addressee = item.payload<KABC::Addressee>(); QList<KDSoapValue> valueList; ContactAccessorHash::const_iterator it = mAccessors->constBegin(); ContactAccessorHash::const_iterator endIt = mAccessors->constEnd(); for (; it != endIt; ++it) { // Id is already part of the object, we have the accessor for the query if (it.key() == QLatin1String("Id")) { continue; } if (it->isAvailable) { const QString value = it->getter(addressee); valueList << KDSoapValue(it.key(), value); kDebug() << "Upsert: name=" << it.key() << "value=" << value; } } object.setAny(valueList); TNS__Upsert upsert; upsert.setExternalIDFieldName(QLatin1String("Id")); upsert.setSObjects(QList<ENS__SObject>() << object); soap->asyncUpsert(upsert); return true; }
bool ContactsHandler::setEntry(const Akonadi::Item &item) { if (!item.hasPayload<KABC::Addressee>()) { kError() << "item (id=" << item.id() << ", remoteId=" << item.remoteId() << ", mime=" << item.mimeType() << ") is missing Addressee payload"; return false; } QList<KDSoapGenerated::TNS__Name_value> itemList; // if there is an id add it, otherwise skip this field // no id will result in the contact being added if (!item.remoteId().isEmpty()) { KDSoapGenerated::TNS__Name_value field; field.setName(QLatin1String("id")); field.setValue(item.remoteId()); itemList << field; } const KABC::Addressee addressee = item.payload<KABC::Addressee>(); ContactAccessorHash::const_iterator it = mAccessors->constBegin(); ContactAccessorHash::const_iterator endIt = mAccessors->constEnd(); for (; it != endIt; ++it) { // check if this is a read-only field if ((*it)->getter == 0) { continue; } KDSoapGenerated::TNS__Name_value field; field.setName(it.key()); const QString value = KDCRMUtils::encodeXML((*it)->getter(addressee)); field.setValue(value); itemList << field; } KDSoapGenerated::TNS__Name_value_list valueList; valueList.setItems(itemList); soap()->asyncSet_entry(sessionId(), moduleName(), valueList); return true; }
bool TasksHandler::setEntry( const Akonadi::Item &item ) { if ( !item.hasPayload<KCalCore::Todo::Ptr>() ) { kError() << "item (id=" << item.id() << ", remoteId=" << item.remoteId() << ", mime=" << item.mimeType() << ") is missing Todo payload"; return false; } QList<TNS__Name_value> itemList; // if there is an id add it, otherwise skip this field // no id will result in the contact being added if ( !item.remoteId().isEmpty() ) { TNS__Name_value field; field.setName( QLatin1String( "id" ) ); field.setValue( item.remoteId() ); itemList << field; } const KCalCore::Todo::Ptr todo = item.payload<KCalCore::Todo::Ptr>(); AccessorHash::const_iterator it = mAccessors->constBegin(); AccessorHash::const_iterator endIt = mAccessors->constEnd(); for ( ; it != endIt; ++it ) { // check if this is a read-only field if ( (*it)->getter == 0 ) { continue; } TNS__Name_value field; field.setName(sugarFieldFromCrmField(it.key())); field.setValue(KDCRMUtils::encodeXML((*it)->getter(*todo))); itemList << field; } TNS__Name_value_list valueList; valueList.setItems( itemList ); soap()->asyncSet_entry( sessionId(), moduleName(), valueList ); return true; }
bool ContactWidgetItem::operator= (const Akonadi::Item & item) { return (this->m_item.id() == item.id()); }