• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 API Reference
  • KDE Home
  • Contact Us
 

akonadi

  • akonadi
collectiondialog_mobile.cpp
1/*
2 Copyright 2010 Tobias Koenig <tokoe@kde.org>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19
20#include "collectiondialog_mobile_p.h"
21#include "asyncselectionhandler_p.h"
22#include "collectiondialog.h"
23
24#include <qplatformdefs.h>
25
26#include <kdescendantsproxymodel.h>
27
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>
34
35#include <KLocalizedString>
36#include <KInputDialog>
37#include <KUrl>
38#include <KMessageBox>
39#include <KStandardDirs>
40
41#include <QDeclarativeView>
42
43using namespace Akonadi;
44
45CollectionDialog::Private::Private(QAbstractItemModel *customModel, CollectionDialog *parent, CollectionDialogOptions options)
46 : QObject(parent)
47 , mParent(parent)
48 , mSelectionMode(QAbstractItemView::SingleSelection)
49 , mOkButtonEnabled(false)
50 , mCancelButtonEnabled(true)
51 , mCreateButtonEnabled(false)
52{
53 // setup GUI
54 mView = new QDeclarativeView(mParent);
55 mView->setResizeMode(QDeclarativeView::SizeRootObjectToView);
56
57 mParent->setMainWidget(mView);
58 mParent->setButtons(KDialog::None);
59
60 changeCollectionDialogOptions(options);
61
62 QAbstractItemModel *baseModel;
63
64 if (customModel) {
65 baseModel = customModel;
66 } else {
67 mMonitor = new Akonadi::ChangeRecorder(mParent);
68 mMonitor->fetchCollection(true);
69 mMonitor->setCollectionMonitored(Akonadi::Collection::root());
70
71 mModel = new EntityTreeModel(mMonitor, mParent);
72 mModel->setItemPopulationStrategy(EntityTreeModel::NoItemPopulation);
73
74 baseModel = mModel;
75 }
76
77 KDescendantsProxyModel *proxyModel = new KDescendantsProxyModel(parent);
78 proxyModel->setDisplayAncestorData(true);
79 proxyModel->setSourceModel(baseModel);
80
81 mMimeTypeFilterModel = new CollectionFilterProxyModel(parent);
82 mMimeTypeFilterModel->setSourceModel(proxyModel);
83
84 mRightsFilterModel = new EntityRightsFilterModel(parent);
85 mRightsFilterModel->setSourceModel(mMimeTypeFilterModel);
86
87 mFilterModel = new QSortFilterProxyModel(parent);
88 mFilterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
89 mFilterModel->setSourceModel(mRightsFilterModel);
90
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)));
96
97 mSelectionHandler = new AsyncSelectionHandler(mFilterModel, mParent);
98 mParent->connect(mSelectionHandler, SIGNAL(collectionAvailable(QModelIndex)),
99 SLOT(slotCollectionAvailable(QModelIndex)));
100
101 foreach (const QString &importPath, KGlobal::dirs()->findDirs("module", QLatin1String("imports"))) {
102 mView->engine()->addImportPath(importPath);
103 }
104
105 mView->rootContext()->setContextProperty(QLatin1String("dialogController"), this);
106 mView->rootContext()->setContextProperty(QLatin1String("collectionModel"), mFilterModel);
107
108 // QUICKHACK: since we have no KDE integration plugin available in kdelibs, we have to do the translation in C++ space
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('&')));
112
113 mView->setSource(KUrl::fromLocalFile(KStandardDirs::locate("data", QLatin1String("akonadi-kde/qml/CollectionDialogMobile.qml"))));
114
115#if defined (Q_WS_MAEMO_5) || defined (MEEGO_EDITION_HARMATTAN)
116 mParent->setWindowState(Qt::WindowFullScreen);
117#else
118 // on the desktop start with a nice size
119 mParent->resize(800, 480);
120#endif
121}
122
123CollectionDialog::Private::~Private()
124{
125}
126
127void CollectionDialog::Private::slotDoubleClicked()
128{
129}
130
131void CollectionDialog::Private::slotCollectionAvailable(const QModelIndex &index)
132{
133 mSelectionModel->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect);
134}
135
136void CollectionDialog::Private::slotFilterFixedString(const QString &filter)
137{
138}
139
140void CollectionDialog::Private::slotSelectionChanged()
141{
142 mOkButtonEnabled = mSelectionModel->hasSelection();
143 if (mAllowToCreateNewChildCollection) {
144 const Akonadi::Collection parentCollection = mParent->selectedCollection();
145 const bool canCreateChildCollections = canCreateCollection(parentCollection);
146 const bool isVirtual = parentCollection.isVirtual();
147
148 mCreateButtonEnabled = (canCreateChildCollections && !isVirtual);
149 if (parentCollection.isValid()) {
150 const bool canCreateItems = (parentCollection.rights() & Akonadi::Collection::CanCreateItem);
151 mOkButtonEnabled = canCreateItems;
152 }
153 }
154
155 emit buttonStatusChanged();
156}
157
158void CollectionDialog::Private::changeCollectionDialogOptions(CollectionDialogOptions options)
159{
160 mAllowToCreateNewChildCollection = (options & AllowToCreateNewChildCollection);
161 emit buttonStatusChanged();
162}
163
164bool CollectionDialog::Private::canCreateCollection(const Akonadi::Collection &parentCollection) const
165{
166 if (!parentCollection.isValid()) {
167 return false;
168 }
169
170 if ((parentCollection.rights() & Akonadi::Collection::CanCreateCollection)) {
171 const QStringList dialogMimeTypeFilter = mParent->mimeTypeFilter();
172 const QStringList parentCollectionMimeTypes = parentCollection.contentMimeTypes();
173 Q_FOREACH (const QString &mimetype, dialogMimeTypeFilter) {
174 if (parentCollectionMimeTypes.contains(mimetype)) {
175 return true;
176 }
177 }
178 return true;
179 }
180 return false;
181}
182
183void CollectionDialog::Private::slotAddChildCollection()
184{
185 const Akonadi::Collection parentCollection = mParent->selectedCollection();
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()) {
191 return;
192 }
193
194 Akonadi::Collection collection;
195 collection.setName(name);
196 collection.setParentCollection(parentCollection);
197 Akonadi::CollectionCreateJob *job = new Akonadi::CollectionCreateJob(collection);
198 connect(job, SIGNAL(result(KJob*)), mParent, SLOT(slotCollectionCreationResult(KJob*)));
199 }
200}
201
202void CollectionDialog::Private::slotCollectionCreationResult(KJob *job)
203{
204 if (job->error()) {
205 KMessageBox::error(mParent, i18n("Could not create folder: %1", job->errorString()),
206 i18n("Folder creation failed"));
207 }
208}
209
210void CollectionDialog::Private::setDescriptionText(const QString &text)
211{
212 mDescriptionText = text;
213 emit descriptionTextChanged();
214}
215
216QString CollectionDialog::Private::descriptionText() const
217{
218 return mDescriptionText;
219}
220
221bool CollectionDialog::Private::okButtonEnabled() const
222{
223 return mOkButtonEnabled;
224}
225
226bool CollectionDialog::Private::cancelButtonEnabled() const
227{
228 return mCancelButtonEnabled;
229}
230
231bool CollectionDialog::Private::createButtonEnabled() const
232{
233 return mCreateButtonEnabled;
234}
235
236bool CollectionDialog::Private::createButtonVisible() const
237{
238 return mAllowToCreateNewChildCollection;
239}
240
241void CollectionDialog::Private::okClicked()
242{
243 mParent->accept();
244}
245
246void CollectionDialog::Private::cancelClicked()
247{
248 mParent->reject();
249}
250
251void CollectionDialog::Private::createClicked()
252{
253 slotAddChildCollection();
254}
255
256void CollectionDialog::Private::setCurrentIndex(int row)
257{
258 const QModelIndex index = mSelectionModel->model()->index(row, 0);
259 mSelectionModel->select(index, QItemSelectionModel::ClearAndSelect);
260}
261
262void CollectionDialog::Private::setFilterText(const QString &text)
263{
264 mFilterModel->setFilterFixedString(text);
265}
266
267void CollectionDialog::Private::selectionChanged(const QItemSelection &selection, const QItemSelection &)
268{
269 if (selection.isEmpty()) {
270 return;
271 }
272
273 emit selectionChanged(selection.indexes().first().row());
274}
275
276CollectionDialog::CollectionDialog(QWidget *parent)
277 : KDialog(parent, Qt::Window)
278 , d(new Private(0, this, CollectionDialog::None))
279{
280}
281
282CollectionDialog::CollectionDialog(QAbstractItemModel *model, QWidget *parent)
283 : KDialog(parent, Qt::Window)
284 , d(new Private(model, this, CollectionDialog::None))
285{
286}
287
288CollectionDialog::CollectionDialog(CollectionDialogOptions options, QAbstractItemModel *model, QWidget *parent)
289 : KDialog(parent, Qt::Window)
290 , d(new Private(model, this, options))
291{
292}
293
294CollectionDialog::~CollectionDialog()
295{
296}
297
298Akonadi::Collection CollectionDialog::selectedCollection() const
299{
300 if (!d->mSelectionModel->hasSelection()) {
301 return Akonadi::Collection();
302 }
303
304 return d->mSelectionModel->selectedRows().first().data(Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
305}
306
307Akonadi::Collection::List CollectionDialog::selectedCollections() const
308{
309 if (!d->mSelectionModel->hasSelection()) {
310 return Akonadi::Collection::List();
311 }
312
313 return (Akonadi::Collection::List() << d->mSelectionModel->selectedRows().first().data(Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>());
314}
315
316void CollectionDialog::setMimeTypeFilter(const QStringList &mimeTypes)
317{
318 d->mMimeTypeFilterModel->clearFilters();
319 d->mMimeTypeFilterModel->addMimeTypeFilters(mimeTypes);
320}
321
322QStringList CollectionDialog::mimeTypeFilter() const
323{
324 return d->mMimeTypeFilterModel->mimeTypes();
325}
326
327void CollectionDialog::setAccessRightsFilter(Collection::Rights rights)
328{
329 d->mRightsFilterModel->setAccessRights(rights);
330}
331
332Akonadi::Collection::Rights CollectionDialog::accessRightsFilter() const
333{
334 return d->mRightsFilterModel->accessRights();
335}
336
337void CollectionDialog::setDescription(const QString &text)
338{
339 d->setDescriptionText(text);
340}
341
342void CollectionDialog::setDefaultCollection(const Collection &collection)
343{
344 d->mSelectionHandler->waitForCollection(collection);
345}
346
347void CollectionDialog::setSelectionMode(QAbstractItemView::SelectionMode mode)
348{
349 d->mSelectionMode = mode;
350}
351
352QAbstractItemView::SelectionMode CollectionDialog::selectionMode() const
353{
354 return d->mSelectionMode;
355}
356
357void CollectionDialog::changeCollectionDialogOptions(CollectionDialogOptions options)
358{
359 d->changeCollectionDialogOptions(options);
360}
361
362#include "moc_collectiondialog.cpp"
363#include "moc_collectiondialog_mobile_p.cpp"
Akonadi::AsyncSelectionHandler
Definition: asyncselectionhandler_p.h:43
Akonadi::ChangeRecorder
Records and replays change notification.
Definition: changerecorder.h:48
Akonadi::CollectionCreateJob
Job that creates a new collection in the Akonadi storage.
Definition: collectioncreatejob.h:53
Akonadi::CollectionDialog
A collection selection dialog.
Definition: collectiondialog.h:68
Akonadi::CollectionDialog::CollectionDialog
CollectionDialog(QWidget *parent=0)
Creates a new collection dialog.
Definition: collectiondialog_desktop.cpp:286
Akonadi::CollectionDialog::selectedCollection
Akonadi::Collection selectedCollection() const
Returns the selected collection if the selection mode is QAbstractItemView::SingleSelection.
Definition: collectiondialog_desktop.cpp:309
Akonadi::CollectionDialog::changeCollectionDialogOptions
void changeCollectionDialogOptions(CollectionDialogOptions options)
Change collection dialog options.
Definition: collectiondialog_desktop.cpp:393
Akonadi::CollectionDialog::selectionMode
QAbstractItemView::SelectionMode selectionMode() const
Returns the selection mode.
Definition: collectiondialog_desktop.cpp:388
Akonadi::CollectionDialog::setDefaultCollection
void setDefaultCollection(const Collection &collection)
Sets the collection that shall be selected by default.
Definition: collectiondialog_desktop.cpp:378
Akonadi::CollectionDialog::setSelectionMode
void setSelectionMode(QAbstractItemView::SelectionMode mode)
Sets the selection mode.
Definition: collectiondialog_desktop.cpp:383
Akonadi::CollectionDialog::setAccessRightsFilter
void setAccessRightsFilter(Collection::Rights rights)
Sets the access rights that the listed collections shall match with.
Definition: collectiondialog_desktop.cpp:359
Akonadi::CollectionDialog::~CollectionDialog
~CollectionDialog()
Destroys the collection dialog.
Definition: collectiondialog_desktop.cpp:304
Akonadi::CollectionDialog::mimeTypeFilter
QStringList mimeTypeFilter() const
Returns the mime types any of which the selected collection(s) shall support.
Definition: collectiondialog_desktop.cpp:354
Akonadi::CollectionDialog::setMimeTypeFilter
void setMimeTypeFilter(const QStringList &mimeTypes)
Sets the mime types any of which the selected collection(s) shall support.
Definition: collectiondialog_desktop.cpp:338
Akonadi::CollectionDialog::setDescription
void setDescription(const QString &text)
Sets the text that will be shown in the dialog.
Definition: collectiondialog_desktop.cpp:372
Akonadi::CollectionDialog::accessRightsFilter
Collection::Rights accessRightsFilter() const
Sets the access rights that the listed collections shall match with.
Definition: collectiondialog_desktop.cpp:367
Akonadi::CollectionDialog::selectedCollections
Akonadi::Collection::List selectedCollections() const
Returns the list of selected collections.
Definition: collectiondialog_desktop.cpp:321
Akonadi::CollectionFilterProxyModel
A proxy model that filters collections by mime type.
Definition: collectionfilterproxymodel.h:55
Akonadi::Collection
Represents a collection of PIM items.
Definition: collection.h:76
Akonadi::Collection::contentMimeTypes
QStringList contentMimeTypes() const
Returns a list of possible content mimetypes, e.g.
Definition: collection.cpp:115
Akonadi::Collection::root
static Collection root()
Returns the root collection.
Definition: collection.cpp:192
Akonadi::Collection::rights
Rights rights() const
Returns the rights the user has on the collection.
Definition: collection.cpp:99
Akonadi::Collection::List
QList< Collection > List
Describes a list of collections.
Definition: collection.h:81
Akonadi::Collection::CanCreateItem
@ CanCreateItem
Can create new items in this collection.
Definition: collection.h:89
Akonadi::Collection::CanCreateCollection
@ CanCreateCollection
Can create new subcollections in this collection.
Definition: collection.h:92
Akonadi::Collection::isVirtual
bool isVirtual() const
Returns whether the collection is virtual, for example a search collection.
Definition: collection.cpp:261
Akonadi::EntityRightsFilterModel
A proxy model that filters entities by access rights.
Definition: entityrightsfiltermodel.h:61
Akonadi::EntityTreeModel
A model for collections and items together.
Definition: entitytreemodel.h:319
Akonadi::EntityTreeModel::NoItemPopulation
@ NoItemPopulation
Do not include items in the model.
Definition: entitytreemodel.h:409
Akonadi::EntityTreeModel::CollectionRole
@ CollectionRole
The collection.
Definition: entitytreemodel.h:336
Akonadi::Entity::isValid
bool isValid() const
Returns whether the entity is valid.
Definition: entity.cpp:97
Akonadi
FreeBusyManager::Singleton.
Definition: actionstatemanager_p.h:28
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jul 21 2022 00:00:00 by doxygen 1.9.5 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Modules
  • Related Pages

kdepimlibs-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal