20#include "collectiondialog_mobile_p.h"
21#include "asyncselectionhandler_p.h"
22#include "collectiondialog.h"
24#include <qplatformdefs.h>
26#include <kdescendantsproxymodel.h>
28#include <akonadi/changerecorder.h>
29#include <akonadi/collectioncreatejob.h>
30#include <akonadi/collectionfilterproxymodel.h>
31#include <akonadi/collectionutils_p.h>
32#include <akonadi/entityrightsfiltermodel.h>
33#include <akonadi/entitytreemodel.h>
35#include <KLocalizedString>
36#include <KInputDialog>
39#include <KStandardDirs>
41#include <QDeclarativeView>
45CollectionDialog::Private::Private(QAbstractItemModel *customModel,
CollectionDialog *parent, CollectionDialogOptions options)
48 , mSelectionMode(QAbstractItemView::SingleSelection)
49 , mOkButtonEnabled(false)
50 , mCancelButtonEnabled(true)
51 , mCreateButtonEnabled(false)
54 mView =
new QDeclarativeView(mParent);
55 mView->setResizeMode(QDeclarativeView::SizeRootObjectToView);
57 mParent->setMainWidget(mView);
58 mParent->setButtons(KDialog::None);
60 changeCollectionDialogOptions(options);
62 QAbstractItemModel *baseModel;
65 baseModel = customModel;
68 mMonitor->fetchCollection(
true);
77 KDescendantsProxyModel *proxyModel =
new KDescendantsProxyModel(parent);
78 proxyModel->setDisplayAncestorData(
true);
79 proxyModel->setSourceModel(baseModel);
82 mMimeTypeFilterModel->setSourceModel(proxyModel);
85 mRightsFilterModel->setSourceModel(mMimeTypeFilterModel);
87 mFilterModel =
new QSortFilterProxyModel(parent);
88 mFilterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
89 mFilterModel->setSourceModel(mRightsFilterModel);
91 mSelectionModel =
new QItemSelectionModel(mFilterModel);
92 mParent->connect(mSelectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
93 SLOT(slotSelectionChanged()));
94 mParent->connect(mSelectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
95 this, SLOT(selectionChanged(QItemSelection,QItemSelection)));
98 mParent->connect(mSelectionHandler, SIGNAL(collectionAvailable(QModelIndex)),
99 SLOT(slotCollectionAvailable(QModelIndex)));
101 foreach (
const QString &importPath, KGlobal::dirs()->findDirs(
"module", QLatin1String(
"imports"))) {
102 mView->engine()->addImportPath(importPath);
105 mView->rootContext()->setContextProperty(QLatin1String(
"dialogController"),
this);
106 mView->rootContext()->setContextProperty(QLatin1String(
"collectionModel"), mFilterModel);
109 mView->rootContext()->setContextProperty(QLatin1String(
"okButtonText"), KStandardGuiItem::ok().text().remove(QLatin1Char(
'&')));
110 mView->rootContext()->setContextProperty(QLatin1String(
"cancelButtonText"), KStandardGuiItem::cancel().text().remove(QLatin1Char(
'&')));
111 mView->rootContext()->setContextProperty(QLatin1String(
"createButtonText"), i18n(
"&New Subfolder...").remove(QLatin1Char(
'&')));
113 mView->setSource(KUrl::fromLocalFile(KStandardDirs::locate(
"data", QLatin1String(
"akonadi-kde/qml/CollectionDialogMobile.qml"))));
115#if defined (Q_WS_MAEMO_5) || defined (MEEGO_EDITION_HARMATTAN)
116 mParent->setWindowState(Qt::WindowFullScreen);
119 mParent->resize(800, 480);
123CollectionDialog::Private::~Private()
127void CollectionDialog::Private::slotDoubleClicked()
131void CollectionDialog::Private::slotCollectionAvailable(
const QModelIndex &index)
133 mSelectionModel->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect);
136void CollectionDialog::Private::slotFilterFixedString(
const QString &filter)
140void CollectionDialog::Private::slotSelectionChanged()
142 mOkButtonEnabled = mSelectionModel->hasSelection();
143 if (mAllowToCreateNewChildCollection) {
145 const bool canCreateChildCollections = canCreateCollection(parentCollection);
146 const bool isVirtual = parentCollection.
isVirtual();
148 mCreateButtonEnabled = (canCreateChildCollections && !isVirtual);
149 if (parentCollection.
isValid()) {
151 mOkButtonEnabled = canCreateItems;
155 emit buttonStatusChanged();
158void CollectionDialog::Private::changeCollectionDialogOptions(CollectionDialogOptions options)
160 mAllowToCreateNewChildCollection = (options & AllowToCreateNewChildCollection);
161 emit buttonStatusChanged();
164bool CollectionDialog::Private::canCreateCollection(
const Akonadi::Collection &parentCollection)
const
166 if (!parentCollection.
isValid()) {
171 const QStringList dialogMimeTypeFilter = mParent->mimeTypeFilter();
172 const QStringList parentCollectionMimeTypes = parentCollection.
contentMimeTypes();
173 Q_FOREACH (
const QString &mimetype, dialogMimeTypeFilter) {
174 if (parentCollectionMimeTypes.contains(mimetype)) {
183void CollectionDialog::Private::slotAddChildCollection()
186 if (canCreateCollection(parentCollection)) {
187 const QString name = KInputDialog::getText(i18nc(
"@title:window",
"New Folder"),
188 i18nc(
"@label:textbox, name of a thing",
"Name"),
189 QString(), 0, mParent);
190 if (name.isEmpty()) {
195 collection.setName(name);
196 collection.setParentCollection(parentCollection);
198 connect(job, SIGNAL(result(KJob*)), mParent, SLOT(slotCollectionCreationResult(KJob*)));
202void CollectionDialog::Private::slotCollectionCreationResult(KJob *job)
205 KMessageBox::error(mParent, i18n(
"Could not create folder: %1", job->errorString()),
206 i18n(
"Folder creation failed"));
210void CollectionDialog::Private::setDescriptionText(
const QString &text)
212 mDescriptionText = text;
213 emit descriptionTextChanged();
216QString CollectionDialog::Private::descriptionText()
const
218 return mDescriptionText;
221bool CollectionDialog::Private::okButtonEnabled()
const
223 return mOkButtonEnabled;
226bool CollectionDialog::Private::cancelButtonEnabled()
const
228 return mCancelButtonEnabled;
231bool CollectionDialog::Private::createButtonEnabled()
const
233 return mCreateButtonEnabled;
236bool CollectionDialog::Private::createButtonVisible()
const
238 return mAllowToCreateNewChildCollection;
241void CollectionDialog::Private::okClicked()
246void CollectionDialog::Private::cancelClicked()
251void CollectionDialog::Private::createClicked()
253 slotAddChildCollection();
256void CollectionDialog::Private::setCurrentIndex(
int row)
258 const QModelIndex index = mSelectionModel->model()->index(row, 0);
259 mSelectionModel->select(index, QItemSelectionModel::ClearAndSelect);
262void CollectionDialog::Private::setFilterText(
const QString &text)
264 mFilterModel->setFilterFixedString(text);
267void CollectionDialog::Private::selectionChanged(
const QItemSelection &selection,
const QItemSelection &)
269 if (selection.isEmpty()) {
273 emit selectionChanged(selection.indexes().first().row());
277 : KDialog(parent, Qt::Window)
283 : KDialog(parent, Qt::Window)
289 : KDialog(parent, Qt::Window)
290 , d(new Private(model, this, options))
300 if (!d->mSelectionModel->hasSelection()) {
309 if (!d->mSelectionModel->hasSelection()) {
318 d->mMimeTypeFilterModel->clearFilters();
319 d->mMimeTypeFilterModel->addMimeTypeFilters(mimeTypes);
324 return d->mMimeTypeFilterModel->mimeTypes();
329 d->mRightsFilterModel->setAccessRights(rights);
334 return d->mRightsFilterModel->accessRights();
339 d->setDescriptionText(text);
344 d->mSelectionHandler->waitForCollection(collection);
349 d->mSelectionMode = mode;
354 return d->mSelectionMode;
359 d->changeCollectionDialogOptions(options);
362#include "moc_collectiondialog.cpp"
363#include "moc_collectiondialog_mobile_p.cpp"
Records and replays change notification.
Job that creates a new collection in the Akonadi storage.
A collection selection dialog.
CollectionDialog(QWidget *parent=0)
Creates a new collection dialog.
Akonadi::Collection selectedCollection() const
Returns the selected collection if the selection mode is QAbstractItemView::SingleSelection.
void changeCollectionDialogOptions(CollectionDialogOptions options)
Change collection dialog options.
QAbstractItemView::SelectionMode selectionMode() const
Returns the selection mode.
void setDefaultCollection(const Collection &collection)
Sets the collection that shall be selected by default.
void setSelectionMode(QAbstractItemView::SelectionMode mode)
Sets the selection mode.
void setAccessRightsFilter(Collection::Rights rights)
Sets the access rights that the listed collections shall match with.
~CollectionDialog()
Destroys the collection dialog.
QStringList mimeTypeFilter() const
Returns the mime types any of which the selected collection(s) shall support.
void setMimeTypeFilter(const QStringList &mimeTypes)
Sets the mime types any of which the selected collection(s) shall support.
void setDescription(const QString &text)
Sets the text that will be shown in the dialog.
Collection::Rights accessRightsFilter() const
Sets the access rights that the listed collections shall match with.
Akonadi::Collection::List selectedCollections() const
Returns the list of selected collections.
A proxy model that filters collections by mime type.
Represents a collection of PIM items.
QStringList contentMimeTypes() const
Returns a list of possible content mimetypes, e.g.
static Collection root()
Returns the root collection.
Rights rights() const
Returns the rights the user has on the collection.
QList< Collection > List
Describes a list of collections.
@ CanCreateItem
Can create new items in this collection.
@ CanCreateCollection
Can create new subcollections in this collection.
bool isVirtual() const
Returns whether the collection is virtual, for example a search collection.
A proxy model that filters entities by access rights.
A model for collections and items together.
@ NoItemPopulation
Do not include items in the model.
@ CollectionRole
The collection.
bool isValid() const
Returns whether the entity is valid.
FreeBusyManager::Singleton.