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() );
}
Ejemplo n.º 2
0
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);
        }
    }
}
Ejemplo n.º 3
0
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);
    }
}
Ejemplo n.º 4
0
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;
}
Ejemplo n.º 5
0
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;
}
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();
    }
}
Ejemplo n.º 7
0
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;
        }
    }
}
Ejemplo n.º 8
0
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;
}
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;
}
Ejemplo n.º 10
0
void CreateCommand::onTargetFetched(KJob *job)
{
  if (job->error()!=0)
  {
    emit error(ki18nc("@info:shell",
                      "Cannot fetch parent collection '%1', %2")
               .subs(mParentCollection)
               .subs(job->errorString()).toString());
    emit finished(RuntimeError);
    return;
  }

  Q_ASSERT(job==mResolveJob);
  Akonadi::Collection parentCollection = mResolveJob->collection();
  Q_ASSERT(parentCollection.isValid());

  // Warning for bug 319513
  if ((mNewCollectionName=="cur") || (mNewCollectionName=="new") || (mNewCollectionName=="tmp"))
  {
    QString parentResource = parentCollection.resource();
    if (parentResource.startsWith(QLatin1String("akonadi_maildir_resource")))
    {
      ErrorReporter::warning(i18n("Creating a maildir folder named '%1' may not work",
                                  mNewCollectionName));
    }
  }

  Akonadi::Collection newCollection;
  newCollection.setParentCollection(parentCollection);
  newCollection.setName(mNewCollectionName);
  newCollection.setContentMimeTypes(parentCollection.contentMimeTypes());
  if (!mDryRun)
  {
    CollectionCreateJob *createJob = new CollectionCreateJob(newCollection);
    connect(createJob, SIGNAL(result(KJob *)), this, SLOT(onCollectionCreated(KJob *)));
  }
Ejemplo n.º 11
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('/');
    }
}
void AggregationComboBox::readStorageModelConfig(const Akonadi::Collection &col, bool &isPrivateSetting)
{
    if (col.isValid()) {
        readStorageModelConfig(QString::number(col.id()), isPrivateSetting);
    }
}
void ImportMailPage::collectionChanged(const Akonadi::Collection& collection)
{
  ui->importMails->setEnabled( collection.isValid() );
}
Ejemplo n.º 14
0
void MBoxImportWidget::collectionChanged(const Akonadi::Collection &collection)
{
    ui->importMails->setEnabled(collection.isValid());
}