示例#1
0
QString MoveCollectionTask::mailBoxForCollections(const Akonadi::Collection &parent, const Akonadi::Collection &child) const
{
    const QString parentMailbox = mailBoxForCollection(parent);
    if (parentMailbox.isEmpty()) {
        return child.remoteId().mid(1); //Strip separator on toplevel mailboxes
    }
    return parentMailbox + child.remoteId();
}
示例#2
0
void CalendarResource::itemAdded(const Akonadi::Item &item, const Akonadi::Collection &collection)
{
    if ((!collection.contentMimeTypes().contains(KCalCore::Event::eventMimeType()) &&
            !collection.contentMimeTypes().contains(KCalCore::Todo::todoMimeType())) ||
            (!canPerformTask<KCalCore::Event::Ptr>(item, KCalCore::Event::eventMimeType()) &&
             !canPerformTask<KCalCore::Todo::Ptr>(item, KCalCore::Todo::todoMimeType()))) {
        return;
    }

    if (collection.parentCollection() == Akonadi::Collection::root()) {
        cancelTask(i18n("The top-level collection cannot contain any tasks or events"));
        return;
    }

    KGAPI2::Job *job = Q_NULLPTR;
    if (item.hasPayload<KCalCore::Event::Ptr>()) {
        KCalCore::Event::Ptr event = item.payload<KCalCore::Event::Ptr>();
        EventPtr kevent(new Event(*event));
        kevent->setUid(QLatin1String(""));

        job = new EventCreateJob(kevent, collection.remoteId(), account(),  this);

    } else if (item.hasPayload<KCalCore::Todo::Ptr>()) {
        KCalCore::Todo::Ptr todo = item.payload<KCalCore::Todo::Ptr>();
        TaskPtr ktodo(new Task(*todo));
        ktodo->setUid(QLatin1String(""));

        if (!ktodo->relatedTo(KCalCore::Incidence::RelTypeParent).isEmpty()) {
            Akonadi::Item parentItem;
            parentItem.setGid(ktodo->relatedTo(KCalCore::Incidence::RelTypeParent));

            ItemFetchJob *fetchJob = new ItemFetchJob(parentItem, this);
            fetchJob->setProperty(ITEM_PROPERTY, QVariant::fromValue(item));
            fetchJob->setProperty(TASK_PROPERTY, QVariant::fromValue(ktodo));

            connect(fetchJob, &ItemFetchJob::finished, this, &CalendarResource::slotTaskAddedSearchFinished);
            return;
        } else {
            job = new TaskCreateJob(ktodo, collection.remoteId(), account(), this);
        }
    } else {
        cancelTask(i18n("Invalid payload type"));
        return;
    }

    job->setProperty(ITEM_PROPERTY, QVariant::fromValue(item));
    connect(job, &EventCreateJob::finished, this, &CalendarResource::slotCreateJobFinished);
}
示例#3
0
void MapiResource::error(const Akonadi::Collection &collection, const QString &body)
{
    static QString prefix = QString::fromAscii("Error %1(%2): %3");
    QString message = prefix.arg(collection.remoteId()).arg(collection.name()).arg(body);

    error(message);
}
void CollectionInternalsPage::load(const Akonadi::Collection & col)
{
  ui.idLabel->setText( QString::number( col.id() ) );
  ui.ridEdit->setText( col.remoteId() );
  ui.rrevEdit->setText( col.remoteRevision() );
  ui.resourceLabel->setText( col.resource() );
  ui.contentTypes->setItems( col.contentMimeTypes() );
  ui.virtCheck->setChecked( col.isVirtual() );
}
示例#5
0
void CalendarResource::retrieveItems(const Akonadi::Collection &collection)
{
    if (!canPerformTask()) {
        return;
    }

    // https://bugs.kde.org/show_bug.cgi?id=308122: we can only request changes in
    // max. last 25 days, otherwise we get an error.
    int lastSyncDelta = -1;
    if (!collection.remoteRevision().isEmpty()) {
        lastSyncDelta = QDateTime::currentDateTimeUtc().toTime_t() - collection.remoteRevision().toUInt();
    }

    KGAPI2::Job *job = Q_NULLPTR;
    if (collection.contentMimeTypes().contains(KCalCore::Event::eventMimeType())) {
        EventFetchJob *fetchJob = new EventFetchJob(collection.remoteId(), account(), this);
        if (lastSyncDelta > -1 && lastSyncDelta < 25 * 24 * 3600) {
            fetchJob->setFetchOnlyUpdated(collection.remoteRevision().toULongLong());
        }
        if (!Settings::self()->eventsSince().isEmpty()) {
            const QDate date = QDate::fromString(Settings::self()->eventsSince(), Qt::ISODate);
            fetchJob->setTimeMin(QDateTime(date).toTime_t());
        }
        job = fetchJob;
    } else if (collection.contentMimeTypes().contains(KCalCore::Todo::todoMimeType())) {
        TaskFetchJob *fetchJob = new TaskFetchJob(collection.remoteId(), account(), this);
        if (lastSyncDelta > -1 && lastSyncDelta < 25 * 25 * 3600) {
            fetchJob->setFetchOnlyUpdated(collection.remoteRevision().toULongLong());
        }
        job = fetchJob;
    } else {
        itemsRetrieved(Item::List());
        return;
    }

    job->setProperty(COLLECTION_PROPERTY, QVariant::fromValue(collection));
    connect(job, &KGAPI2::Job::progress, this, &CalendarResource::emitPercent);
    connect(job, &KGAPI2::Job::finished, this, &CalendarResource::slotItemsRetrieved);
}
示例#6
0
void SugarCRMResource::itemAdded(const Akonadi::Item &item, const Akonadi::Collection &collection)
{
    // find the handler for the module represented by the given collection and let it
    // perform the respective "set entry" operation
    ModuleHandler *handler = mModuleHandlers->value(collection.remoteId());
    if (handler) {
        status(Running);

        CreateEntryJob *job = new CreateEntryJob(item, mSession, this);
        Q_ASSERT(!mCurrentJob);
        mCurrentJob = job;
        job->setModule(handler);
        connect(job, SIGNAL(result(KJob*)), this, SLOT(createEntryResult(KJob*)));
        job->start();
    } else {
示例#7
0
const QChar ResourceTask::separatorCharacter() const
{
    const QChar separator = m_resource->separatorCharacter();
    if (!separator.isNull()) {
        return separator;
    } else {
        //If we request the separator before first folder listing, then try to guess
        //the separator:
        //If we create a toplevel folder, assume the separator to be '/'. This is not perfect, but detecting the right
        //IMAP separator is not straightforward for toplevel folders, and fixes bug 292418 and maybe other, where
        //subfolders end up with remote id's starting with "i" (the first letter of imap:// ...)

        QString remoteId;
        // We don't always have parent collection set (for example for CollectionChangeTask),
        // in such cases however we can use current collection's remoteId to get the separator
        const Akonadi::Collection parent = parentCollection();
        if (parent.isValid()) {
            remoteId = parent.remoteId();
        } else {
            remoteId = collection().remoteId();
        }
        return ((remoteId != rootRemoteId()) && !remoteId.isEmpty()) ? remoteId.at(0) : QLatin1Char('/');
    }
}