void KJotsLinkDialog::setLinkUrl(const QString &linkUrl) { Akonadi::Item item = Akonadi::Item::fromUrl(KUrl(linkUrl)); Akonadi::Collection collection = Akonadi::Collection::fromUrl(KUrl(linkUrl)); if (!item.isValid() && !collection.isValid()) { linkUrlLineEdit->setText(linkUrl); linkUrlLineEditRadioButton->setChecked(true); return; } QModelIndex idx; if (collection.isValid()) { idx = Akonadi::EntityTreeModel::modelIndexForCollection( m_descendantsProxyModel, collection ); } else if (item.isValid()) { const QModelIndexList list = Akonadi::EntityTreeModel::modelIndexesForItem( m_descendantsProxyModel, item ); if (list.isEmpty()) return; idx = list.first(); } if (!idx.isValid()) return; hrefComboRadioButton->setChecked(true); hrefCombo->view()->setCurrentIndex( idx ); hrefCombo->setCurrentIndex( idx.row() ); }
inline bool qCompare(const Akonadi::Collection &left, const Akonadi::Collection &right, const char *actual, const char *expected, const char *file, int line) { return zCompareHelper((left == right) && (left.displayName() == right.displayName()), left, right, actual, expected, file, line); }
void CollectionInternalsPage::save(Akonadi::Collection & col) { col.setRemoteId( ui.ridEdit->text() ); col.setRemoteRevision( ui.rrevEdit->text() ); col.setContentMimeTypes( ui.contentTypes->items() ); col.setVirtual( ui.virtCheck->isChecked() ); }
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 CheckIndexingManager::initializeCollectionList(QAbstractItemModel *model, const QModelIndex &parentIndex) { const int rowCount = model->rowCount(parentIndex); for (int row = 0; row < rowCount; ++row) { const QModelIndex index = model->index(row, 0, parentIndex); const Akonadi::Collection collection = model->data( index, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>(); if (!collection.isValid() || MailCommon::Util::isVirtualCollection(collection)) { continue; } if (collection.hasAttribute<Akonadi::EntityHiddenAttribute>()) { continue; } if (PimCommon::Util::isImapResource(collection.resource()) && !collection.cachePolicy().localParts().contains(QLatin1String("RFC822"))) { continue; } if (!mCollectionsIndexed.contains(collection.id())) { mListCollection.append(collection); } if (model->rowCount(index) > 0) { initializeCollectionList(model, index); } } }
void RecentCollectionAction::fillRecentCollection() { delete mRecentAction->menu(); if ( mListRecentCollection.isEmpty() ) { mRecentAction->setEnabled( false ); return; } QMenu* popup = new QMenu; mRecentAction->setMenu( popup ); const int numberOfRecentCollection(mListRecentCollection.count()); for ( int i=0; i < numberOfRecentCollection; ++i ) { const QModelIndex index = Akonadi::EntityTreeModel::modelIndexForCollection( mModel, Akonadi::Collection( mListRecentCollection.at( i ).toLongLong() ) ); const Akonadi::Collection collection = mModel->data( index, Akonadi::CollectionModel::CollectionRole ).value<Akonadi::Collection>(); if ( index.isValid() ) { const bool canCreateNewItems = (collection.rights() & Collection::CanCreateItem); QAction *action = popup->addAction( actionName( index ) ); const QIcon icon = mModel->data( index, Qt::DecorationRole ).value<QIcon>(); action->setIcon( icon ); action->setData( QVariant::fromValue<QModelIndex>( index ) ); action->setEnabled(canCreateNewItems); } } }
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(); }
static Akonadi::Collection detatchCollection(const Akonadi::Collection &collection) { //HACK: Attributes are accessed via a const function, and the implicitly shared private pointer thus doesn't detach. //We force a detach to avoid surprises. (RetrieveItemsTask used to write back the collection changes, even though the task was canceled) //Once this is fixed this function can go away. Akonadi::Collection col = collection; col.setId(col.id()); return col; }
void VirtualResource::reset() { Q_ASSERT(mRootCollection.isValid()); Akonadi::Collection col = mRootCollection; CollectionDeleteJob *d = new CollectionDeleteJob(mRootCollection, mSession); EXEC(d); col.setId(-1); createRootCollection(col); }
Akonadi::Item::Id KMail::Util::putRepliesInSameFolder( const Akonadi::Item& item ) { Akonadi::Collection parentCollection = item.parentCollection(); if ( parentCollection.isValid() ) { const QSharedPointer<FolderCollection> fd = FolderCollection::forCollection( parentCollection, false ); if( fd->putRepliesInSameFolder() ) { return parentCollection.id(); } } return -1; }
void XXPortManager::slotImport( const QString &identifier ) { const XXPort *xxport = mFactory.createXXPort( identifier, mParentWidget ); if( !xxport ) { return; } const KABC::Addressee::List contacts = xxport->importContacts(); delete xxport; if ( contacts.isEmpty() ) { // nothing to import return; } const QStringList mimeTypes( KABC::Addressee::mimeType() ); QPointer<Akonadi::CollectionDialog> dlg = new Akonadi::CollectionDialog( mParentWidget ); dlg->setMimeTypeFilter( mimeTypes ); dlg->setAccessRightsFilter( Akonadi::Collection::CanCreateItem ); dlg->setCaption( i18n( "Select Address Book" ) ); dlg->setDescription( i18n( "Select the address book the imported contact(s) shall be saved in:" ) ); dlg->setDefaultCollection( mDefaultAddressBook ); if ( !dlg->exec() || !dlg ) { delete dlg; return; } const Akonadi::Collection collection = dlg->selectedCollection(); delete dlg; if ( !mImportProgressDialog ) { mImportProgressDialog = new KProgressDialog( mParentWidget, i18n( "Import Contacts" ) ); mImportProgressDialog->setLabelText( i18np( "Importing one contact to %2", "Importing %1 contacts to %2", contacts.count(), collection.name() ) ); mImportProgressDialog->setAllowCancel( false ); mImportProgressDialog->setAutoClose( true ); mImportProgressDialog->progressBar()->setRange( 1, contacts.count() ); } mImportProgressDialog->show(); for ( int i = 0; i < contacts.count(); ++i ) { Akonadi::Item item; item.setPayload<KABC::Addressee>( contacts.at( i ) ); item.setMimeType( KABC::Addressee::mimeType() ); Akonadi::ItemCreateJob *job = new Akonadi::ItemCreateJob( item, collection ); connect( job, SIGNAL(result(KJob*)), SLOT(slotImportJobDone(KJob*)) ); } }
Akonadi::Collection TasksHandler::handlerCollection() const { Akonadi::Collection taskCollection; taskCollection.setContentMimeTypes( QStringList() << KCalCore::Todo::todoMimeType() ); taskCollection.setName( i18nc( "@item folder name", "Tasks" ) ); taskCollection.setRights( Akonadi::Collection::CanChangeItem | Akonadi::Collection::CanCreateItem | Akonadi::Collection::CanDeleteItem ); return taskCollection; }
Akonadi::Collection SalesforceContactsHandler::collection() const { Akonadi::Collection contactCollection; contactCollection.setRemoteId(moduleName()); contactCollection.setContentMimeTypes(QStringList() << KABC::Addressee::mimeType()); contactCollection.setName(i18nc("@item folder name", "Contacts")); contactCollection.setRights(Akonadi::Collection::CanChangeItem | Akonadi::Collection::CanCreateItem | Akonadi::Collection::CanDeleteItem); return contactCollection; }
Akonadi::Collection DocumentsHandler::handlerCollection() const { Akonadi::Collection documentCollection; documentCollection.setRemoteId(moduleToName(module())); documentCollection.setContentMimeTypes(QStringList() << SugarDocument::mimeType()); documentCollection.setName(i18nc("@item folder name", "Documents")); documentCollection.setRights(Akonadi::Collection::CanChangeItem | Akonadi::Collection::CanCreateItem | Akonadi::Collection::CanDeleteItem); return documentCollection; }
void FolderArchiveManager::slotCollectionRemoved(const Akonadi::Collection &collection) { KConfig config(FolderArchive::FolderArchiveUtil::configFileName()); mFolderArchiveCache->clearCacheWithContainsCollection(collection.id()); Q_FOREACH (FolderArchiveAccountInfo *info, mListAccountInfo) { if (info->archiveTopLevel() == collection.id()) { info->setArchiveTopLevel(-1); KConfigGroup group = config.group(FolderArchive::FolderArchiveUtil::groupConfigPattern() + info->instanceName()); info->writeConfig(group); } } load(); }
KMime::Types::Mailbox::List KMail::Util::mailingListsFromMessage( const Akonadi::Item& item ) { KMime::Types::Mailbox::List addresses; // determine the mailing list posting address Akonadi::Collection parentCollection = item.parentCollection(); if ( parentCollection.isValid() ) { const QSharedPointer<FolderCollection> fd = FolderCollection::forCollection( parentCollection, false ); if ( fd->isMailingListEnabled() && !fd->mailingListPostAddress().isEmpty() ) { addresses << MessageCore::StringUtil::mailboxFromUnicodeString( fd->mailingListPostAddress() ); } } return addresses; }
void EmptyTrashCommand::execute() { if (!mFolder.isValid() && !mModel) { emitResult(Failed); return; } if (!mFolder.isValid()) { //expunge all const QString title = i18n("Empty Trash"); const QString text = i18n("Are you sure you want to empty the trash folders of all accounts?"); if (KMessageBox::warningContinueCancel(nullptr, text, title, KStandardGuiItem::cont(), KStandardGuiItem::cancel(), QStringLiteral("confirm_empty_trash")) != KMessageBox::Continue) { emitResult(OK); return; } Akonadi::Collection trash = trashCollectionFolder(); QVector<Akonadi::Collection> trashFolder; trashFolder << trash; const Akonadi::AgentInstance::List lst = agentInstances(); for (const Akonadi::AgentInstance &type : lst) { if (type.identifier().contains(IMAP_RESOURCE_IDENTIFIER)) { if (type.status() == Akonadi::AgentInstance::Broken) { continue; } OrgKdeAkonadiImapSettingsInterface *iface = Util::createImapSettingsInterface(type.identifier()); if (iface->isValid()) { const int trashImap = iface->trashCollection(); if (trashImap != trash.id()) { trashFolder << Akonadi::Collection(trashImap); } } delete iface; } } mNumberOfTrashToEmpty = trashFolder.count(); for (int i = 0; i < mNumberOfTrashToEmpty; ++i) { expunge(trashFolder.at(i)); } } else { if (folderIsTrash(mFolder)) { mNumberOfTrashToEmpty++; expunge(mFolder); } else { emitResult(OK); } } }
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(); } }
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); }
void CollectionGeneralPage::load(const Akonadi::Collection &collection) { init(collection); mNameEdit->setEnabled(collection.rights() & Collection::CanChangeCollection); const QString displayName = collection.displayName(); mNameEdit->setText(displayName); mBlockAlarmsCheckBox->setChecked(collection.hasAttribute<BlockAlarmsAttribute>() && collection.attribute<BlockAlarmsAttribute>()->isEverythingBlocked()); QString iconName; if (collection.hasAttribute<EntityDisplayAttribute>()) { iconName = collection.attribute<EntityDisplayAttribute>()->iconName(); } if (iconName.isEmpty()) { const QStringList mimeTypes = collection.contentMimeTypes(); if (collection.contentMimeTypes().count() > 1 || collection.contentMimeTypes().contains(KCalCore::Event::eventMimeType())) { mIconButton->setIcon(QIcon::fromTheme(QStringLiteral("view-pim-calendar"))); } else if (collection.contentMimeTypes().contains(KCalCore::Todo::todoMimeType())) { mIconButton->setIcon(QIcon::fromTheme(QStringLiteral("view-pim-tasks"))); } else if (collection.contentMimeTypes().contains(KCalCore::Journal::journalMimeType())) { mIconButton->setIcon(QIcon::fromTheme(QStringLiteral("view-pim-journal"))); } else if (mimeTypes.isEmpty()) { mIconButton->setIcon(QIcon::fromTheme(QStringLiteral("folder-grey"))); } else { mIconButton->setIcon(QIcon::fromTheme(QStringLiteral("folder"))); } } else { mIconButton->setIcon(iconName); } mIconCheckBox->setChecked(!iconName.isEmpty()); }
void EmptyTrashCommand::expunge(const Akonadi::Collection &col) { if (col.isValid()) { Akonadi::ItemFetchJob *job = new Akonadi::ItemFetchJob(col, this); connect(job, &Akonadi::ItemFetchJob::result, this, &EmptyTrashCommand::slotExpungeJob); } else { qCDebug(AKONADIMIME_LOG) << " Try to expunge an invalid collection :" << col; emitResult(Failed); } }
bool CollectionFilterModel::filterAcceptsRow(int row, const QModelIndex &parent) const { bool accepted = true; const QModelIndex index = sourceModel()->index(row, 0, parent); const Akonadi::Collection collection = index.data(Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>(); if (!collection.isValid()) { return false; } if (!mContentMimeTypes.isEmpty()) { QSet<QString> contentMimeTypes = collection.contentMimeTypes().toSet(); accepted = accepted && !(contentMimeTypes.intersect(mContentMimeTypes).isEmpty()); } if (mRights != Akonadi::Collection::ReadOnly) { accepted = accepted && (collection.rights() & mRights); } return accepted; }
void RetrieveCollectionsTask::doStart(KIMAP::Session *session) { Akonadi::Collection root; root.setName(resourceName()); root.setRemoteId(rootRemoteId()); root.setContentMimeTypes(QStringList(Akonadi::Collection::mimeType())); root.setParentCollection(Akonadi::Collection::root()); root.addAttribute(new NoSelectAttribute(true)); Akonadi::CachePolicy policy; policy.setInheritFromParent(false); policy.setSyncOnDemand(true); QStringList localParts; localParts << QLatin1String(Akonadi::MessagePart::Envelope) << QLatin1String(Akonadi::MessagePart::Header); int cacheTimeout = 60; if (isDisconnectedModeEnabled()) { // For disconnected mode we also cache the body // and we keep all data indifinitely localParts << QLatin1String(Akonadi::MessagePart::Body); cacheTimeout = -1; } policy.setLocalParts(localParts); policy.setCacheTimeout(cacheTimeout); policy.setIntervalCheckTime(intervalCheckTime()); root.setCachePolicy(policy); m_reportedCollections.insert(QString(), root); // this is ugly, but the result of LSUB is unfortunately not a sub-set of LIST // it also contains subscribed but currently not available (eg. deleted) mailboxes // so we need to use both and exclude mailboxes in LSUB but not in LIST if (isSubscriptionEnabled()) { KIMAP::ListJob *fullListJob = new KIMAP::ListJob(session); fullListJob->setIncludeUnsubscribed(true); fullListJob->setQueriedNamespaces(serverNamespaces()); connect(fullListJob, &KIMAP::ListJob::mailBoxesReceived, this, &RetrieveCollectionsTask::onFullMailBoxesReceived); connect(fullListJob, &KIMAP::ListJob::result, this, &RetrieveCollectionsTask::onFullMailBoxesReceiveDone); fullListJob->start(); } KIMAP::ListJob *listJob = new KIMAP::ListJob(session); listJob->setIncludeUnsubscribed(!isSubscriptionEnabled()); listJob->setQueriedNamespaces(serverNamespaces()); connect(listJob, &KIMAP::ListJob::mailBoxesReceived, this, &RetrieveCollectionsTask::onMailBoxesReceived); connect(listJob, &KIMAP::ListJob::result, this, &RetrieveCollectionsTask::onMailBoxesReceiveDone); listJob->start(); }
/** Set by event ID and optional resource ID, in the format "[rid:]eid". */ EventId::EventId(const QString& resourceEventId) { bool resourceOk = false; QRegExp rx(QStringLiteral("^\\w+:")); if (rx.indexIn(resourceEventId) == 0) { // A resource ID has been supplied, so use it int n = rx.matchedLength(); Akonadi::Collection c = CollectionControlModel::collectionForResource(resourceEventId.left(n - 1)); { first = c.id(); second = resourceEventId.mid(n); resourceOk = true; } } if (!resourceOk) { // Only an event ID has been supplied (or the syntax was invalid) first = -1; second = resourceEventId; } }
bool DateRangeFilterProxyModel::filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const { const Akonadi::Collection collection = sourceModel()->index( source_row, 0, source_parent ).data( Akonadi::EntityTreeModel::CollectionRole ).value<Akonadi::Collection>(); if ( collection.isValid() ) { return true; } if ( d->mEnd.isValid() ) { const QModelIndex idx = sourceModel()->index( source_row, d->mStartColumn, source_parent ); const QVariant v = idx.data( filterRole() ); const QDateTime start = v.toDateTime(); if ( start.isValid() && start > d->mEnd.dateTime() ) { return false; } } const bool recurs = sourceModel()->index( source_row, 0, source_parent ).data( CalendarModel::RecursRole ).toBool(); if ( recurs ) {// that's fuzzy and might return events not actually recurring in the range return true; } if ( d->mStart.isValid() ) { const QModelIndex idx = sourceModel()->index( source_row, d->mEndColumn, source_parent ); const QVariant v = idx.data( filterRole() ); const QDateTime end = v.toDateTime(); if ( end.isValid() && end < d->mStart.dateTime() ) { return false; } } return true; }
Akonadi::Collection VirtualResource::createCollection(const Akonadi::Collection &collection) { // kDebug() << collection.name() << collection.parentCollection().remoteId(); // kDebug() << "contentMimeTypes: " << collection.contentMimeTypes(); Q_ASSERT(!collection.name().isEmpty()); Collection col = collection; if (!col.parentCollection().isValid()) { col.setParentCollection(mRootCollection); } CollectionCreateJob *create = new CollectionCreateJob(col, mSession); EXEC(create); return create->collection(); }
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() ); }
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 {
void ResourceScheduler::collectionRemoved(const Akonadi::Collection &collection) { if (!collection.isValid()) { // should not happen, but you never know... return; } TaskList &queue = queueForTaskType(SyncCollection); for (QList<Task>::iterator it = queue.begin(); it != queue.end();) { if ((*it).type == SyncCollection && (*it).collection == collection) { it = queue.erase(it); qCDebug(AKONADIAGENTBASE_LOG) << " erasing"; } else { ++it; } } }
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('/'); } }