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);
    }
  }
}
Exemple #2
0
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());
}
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::onMailBoxesReceived(const QList< KIMAP::MailBoxDescriptor > &descriptors,
        const QList< QList<QByteArray> > &flags)
{
    QStringList contentTypes;
    contentTypes << KMime::Message::mimeType() << Akonadi::Collection::mimeType();

    if (!descriptors.isEmpty()) {
        // This is still not optimal way of getting the separator, but it's better
        // than guessing every time from RID of parent collection
        setSeparatorCharacter(descriptors.first().separator);
    }

    for (int i = 0; i < descriptors.size(); ++i) {
        KIMAP::MailBoxDescriptor descriptor = descriptors[i];

        // skip phantom mailboxes contained in LSUB but not LIST
        if (isSubscriptionEnabled() && !m_fullReportedCollections.contains(descriptor.name)) {
            qCDebug(IMAPRESOURCE_LOG) << "Got phantom mailbox: " << descriptor.name;
            continue;
        }

        const QString separator = descriptor.separator;
        Q_ASSERT(separator.size() == 1);   // that's what the spec says

        const QString boxName = descriptor.name.endsWith(separator)
                                ? descriptor.name.left(descriptor.name.size() - 1)
                                : descriptor.name;

        const QStringList pathParts = boxName.split(separator);

        QString parentPath;
        QString currentPath;

        const int pathPartsSize(pathParts.size());
        for (int j = 0; j < pathPartsSize; ++j) {
            const bool isDummy = j != pathPartsSize - 1;
            const QString pathPart = pathParts.at(j);
            currentPath += separator + pathPart;

            if (m_reportedCollections.contains(currentPath)) {
                if (m_dummyCollections.contains(currentPath) && !isDummy) {
                    qCDebug(IMAPRESOURCE_LOG) << "Received the real collection for a dummy one : " << currentPath;

                    //set the correct attributes for the collection, eg. noselect needs to be removed
                    Akonadi::Collection c = m_reportedCollections.value(currentPath);
                    c.setContentMimeTypes(contentTypes);
                    c.setRights(Akonadi::Collection::AllRights);
                    c.removeAttribute<NoSelectAttribute>();

                    m_dummyCollections.remove(currentPath);
                    m_reportedCollections.remove(currentPath);
                    m_reportedCollections.insert(currentPath, c);

                }
                parentPath = currentPath;
                continue;
            }

            const QList<QByteArray> currentFlags = isDummy ? (QList<QByteArray>() << "\\noselect") : flags[i];

            Akonadi::Collection c;
            c.setName(pathPart);
            c.setRemoteId(separator + pathPart);
            const Akonadi::Collection parentCollection = m_reportedCollections.value(parentPath);
            c.setParentCollection(parentCollection);
            c.setContentMimeTypes(contentTypes);

            // If the folder is the Inbox, make some special settings.
            if (currentPath.compare(separator + QLatin1String("INBOX"), Qt::CaseInsensitive) == 0) {
                Akonadi::EntityDisplayAttribute *attr = c.attribute<Akonadi::EntityDisplayAttribute>(Akonadi::Collection::AddIfMissing);
                attr->setDisplayName(i18n("Inbox"));
                attr->setIconName(QStringLiteral("mail-folder-inbox"));
                setIdleCollection(c);
            }

            // If the folder is the user top-level folder, mark it as well, even although it is not officially noted in the RFC
            if (currentPath == (separator + QLatin1String("user")) && currentFlags.contains("\\noselect")) {
                Akonadi::EntityDisplayAttribute *attr = c.attribute<Akonadi::EntityDisplayAttribute>(Akonadi::Collection::AddIfMissing);
                attr->setDisplayName(i18n("Shared Folders"));
                attr->setIconName(QStringLiteral("x-mail-distribution-list"));
            }

            // If this folder is a noselect folder, make some special settings.
            if (currentFlags.contains("\\noselect")) {
                qCDebug(IMAPRESOURCE_LOG) << "Dummy collection created: " << currentPath;
                c.addAttribute(new NoSelectAttribute(true));
                c.setContentMimeTypes(QStringList() << Akonadi::Collection::mimeType());
                c.setRights(Akonadi::Collection::ReadOnly);
            } else {
                // remove the noselect attribute explicitly, in case we had set it before (eg. for non-subscribed non-leaf folders)
                c.removeAttribute<NoSelectAttribute>();
            }

            // If this folder is a noinferiors folder, it is not allowed to create subfolders inside.
            if (currentFlags.contains("\\noinferiors")) {
                //qCDebug(IMAPRESOURCE_LOG) << "Noinferiors: " << currentPath;
                c.addAttribute(new NoInferiorsAttribute(true));
                c.setRights(c.rights() & ~Akonadi::Collection::CanCreateCollection);
            }

            m_reportedCollections.insert(currentPath, c);

            if (isDummy) {
                m_dummyCollections.insert(currentPath, c);
            }

            parentPath = currentPath;
        }
    }
}
void ActionListEditor::updateActions()
{
    const QItemSelectionModel * const itemSelectionModel = currentPage()->selectionModel();
    const QModelIndex index = itemSelectionModel->currentIndex();
    int type = index.data(Zanshin::ItemTypeRole).toInt();

    Akonadi::Collection collection;
    if ( type==Zanshin::Collection ) {
        collection = index.data(Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
    } else if (type==Zanshin::Context) {
        collection = Akonadi::StorageSettings::instance().defaultTaskCollection();
    } else if (type==Zanshin::Topic) {
        collection = Akonadi::StorageSettings::instance().defaultNoteCollection();
    } else if (type==Zanshin::StandardTodo) {
        QModelIndex parent = index;
        int parentType = type;
        while (parent.isValid() && parentType==Zanshin::StandardTodo) {
            parent = parent.sibling(parent.row()-1, parent.column());
            parentType = parent.data(Zanshin::ItemTypeRole).toInt();
        }

        if (parentType!=Zanshin::ProjectTodo) {
            collection = Akonadi::StorageSettings::instance().defaultTaskCollection();
        } else {
            collection = index.data(Akonadi::EntityTreeModel::ParentCollectionRole).value<Akonadi::Collection>();
        }
    } else {
        // We use ParentCollectionRole instead of Akonadi::Item::parentCollection() because the
        // information about the rights is not valid on retrieved items.
        collection = index.data(Akonadi::EntityTreeModel::ParentCollectionRole).value<Akonadi::Collection>();
    }

    m_add->setEnabled(index.isValid()
                  && (collection.rights() & Akonadi::Collection::CanCreateItem)
                  && (type==Zanshin::ProjectTodo
                   || type==Zanshin::Context
                   || type==Zanshin::Topic
                   || type==Zanshin::Inbox
                   || type==Zanshin::StandardTodo));

    currentPage()->setActionEditEnabled(m_add->isEnabled());

    m_remove->setEnabled(index.isValid()
                     && (collection.rights() & Akonadi::Collection::CanDeleteItem)
                     && ((type==Zanshin::StandardTodo)
                       || type==Zanshin::ProjectTodo
                       || type==Zanshin::Context
                       || type==Zanshin::Topic));

    m_move->setEnabled(index.isValid()
                   && (collection.rights() & Akonadi::Collection::CanDeleteItem)
                   && (type==Zanshin::StandardTodo
                    || type==Zanshin::Context
                    || type==Zanshin::Topic
                    || type==Zanshin::ProjectTodo));

    m_promote->setEnabled(index.isValid()
                       && (collection.rights() & Akonadi::Collection::CanChangeItem)
                       && type==Zanshin::StandardTodo
                       && itemSelectionModel->selectedRows().size() == 1);

    m_dissociate->setEnabled(index.isValid()
                          && (collection.rights() & Akonadi::Collection::CanDeleteItem)
                          && type==Zanshin::StandardTodo);
}