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

akonadi

  • sources
  • kde-4.14
  • kdepimlibs
  • akonadi
collectionrequester.cpp
1 /*
2  Copyright 2008 Ingo Klöcker <kloecker@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 "collectionrequester.h"
21 #include "collectiondialog.h"
22 #include "entitydisplayattribute.h"
23 #include "collectionfetchjob.h"
24 #include "collectionfetchscope.h"
25 
26 #include <klineedit.h>
27 #include <klocalizedstring.h>
28 #include <kpushbutton.h>
29 #include <kicon.h>
30 #include <kstandardshortcut.h>
31 
32 #include <QtCore/QEvent>
33 #include <QAction>
34 
35 using namespace Akonadi;
36 
37 class CollectionRequester::Private
38 {
39 public:
40  Private(CollectionRequester *parent)
41  : q(parent)
42  , edit(0)
43  , button(0)
44  , collectionDialog(0)
45  {
46  }
47 
48  ~Private()
49  {
50  }
51 
52  void fetchCollection(const Collection &collection);
53 
54  void init();
55 
56  // slots
57  void _k_slotOpenDialog();
58  void _k_collectionReceived(KJob *job);
59  void _k_collectionsNamesReceived(KJob *job);
60 
61  CollectionRequester *q;
62  Collection collection;
63  KLineEdit *edit;
64  KPushButton *button;
65  CollectionDialog *collectionDialog;
66 };
67 
68 void CollectionRequester::Private::fetchCollection(const Collection &collection)
69 {
70  CollectionFetchJob *job = new CollectionFetchJob(collection, Akonadi::CollectionFetchJob::Base, q);
71  job->setProperty("OriginalCollectionId", collection.id());
72  job->fetchScope().setAncestorRetrieval(CollectionFetchScope::All);
73  connect(job, SIGNAL(finished(KJob*)),
74  q, SLOT(_k_collectionReceived(KJob*)));
75 }
76 
77 void CollectionRequester::Private::_k_collectionReceived(KJob *job)
78 {
79  CollectionFetchJob *fetch = qobject_cast<CollectionFetchJob*>(job);
80  Collection::List chain;
81  if (fetch->collections().size() == 1) {
82  Collection currentCollection = fetch->collections().first();
83  while (currentCollection.isValid()) {
84  chain << currentCollection;
85  currentCollection = Collection(currentCollection.parentCollection());
86  }
87 
88  CollectionFetchJob *namesFetch = new CollectionFetchJob(chain, CollectionFetchJob::Base, q);
89  namesFetch->setProperty("OriginalCollectionId", job->property("OriginalCollectionId"));
90  namesFetch->fetchScope().setAncestorRetrieval(CollectionFetchScope::Parent);
91  connect(namesFetch, SIGNAL(finished(KJob*)),
92  q, SLOT(_k_collectionsNamesReceived(KJob*)));
93  } else {
94  _k_collectionsNamesReceived(job);
95  }
96 }
97 
98 void CollectionRequester::Private::_k_collectionsNamesReceived(KJob *job)
99 {
100  CollectionFetchJob *fetch = qobject_cast<CollectionFetchJob*>(job);
101  const qint64 originalId = fetch->property("OriginalCollectionId").toLongLong();
102 
103  QMap<qint64, Collection> names;
104  Q_FOREACH (const Collection &collection, fetch->collections()) {
105  names.insert(collection.id(), collection);
106  }
107 
108  QStringList namesList;
109  Collection currentCollection = names.take(originalId);
110  while (currentCollection.isValid()) {
111  namesList.prepend(currentCollection.displayName());
112  currentCollection = names.take(currentCollection.parent());
113  }
114  edit->setText(namesList.join(QLatin1String( "/")));
115 }
116 
117 void CollectionRequester::Private::init()
118 {
119  q->setMargin(0);
120 
121  edit = new KLineEdit(q);
122  edit->setReadOnly(true);
123  edit->setClickMessage(i18n("No Folder"));
124  edit->setClearButtonShown(false);
125  edit->setFocusPolicy(Qt::NoFocus);
126 
127  button = new KPushButton(q);
128  button->setIcon(KIcon(QLatin1String("document-open")));
129  const int buttonSize = edit->sizeHint().height();
130  button->setFixedSize(buttonSize, buttonSize);
131  button->setToolTip(i18n("Open collection dialog"));
132 
133  q->setSpacing(-1);
134 
135  edit->installEventFilter(q);
136  q->setFocusProxy(button);
137  q->setFocusPolicy(Qt::StrongFocus);
138 
139  q->connect(button, SIGNAL(clicked()), q, SLOT(_k_slotOpenDialog()));
140 
141  QAction *openAction = new QAction(q);
142  openAction->setShortcut(KStandardShortcut::Open);
143  q->connect(openAction, SIGNAL(triggered(bool)), q, SLOT(_k_slotOpenDialog()));
144 
145  collectionDialog = new CollectionDialog(q);
146  collectionDialog->setWindowIcon(KIcon(QLatin1String("akonadi")));
147  collectionDialog->setCaption(i18n("Select a collection"));
148  collectionDialog->setSelectionMode(QAbstractItemView::SingleSelection);
149  collectionDialog->changeCollectionDialogOptions(CollectionDialog::KeepTreeExpanded);
150 }
151 
152 void CollectionRequester::Private::_k_slotOpenDialog()
153 {
154  CollectionDialog *dlg = collectionDialog;
155 
156  if (dlg->exec() != QDialog::Accepted) {
157  return;
158  }
159 
160  const Akonadi::Collection collection = dlg->selectedCollection();
161  q->setCollection(collection);
162  emit q->collectionChanged(collection);
163 }
164 
165 CollectionRequester::CollectionRequester(QWidget *parent)
166  : KHBox(parent)
167  , d(new Private(this))
168 {
169  d->init();
170 }
171 
172 CollectionRequester::CollectionRequester(const Akonadi::Collection &collection, QWidget *parent)
173  : KHBox(parent)
174  , d(new Private(this))
175 {
176  d->init();
177  setCollection(collection);
178 }
179 
180 CollectionRequester::~CollectionRequester()
181 {
182  delete d;
183 }
184 
185 Collection CollectionRequester::collection() const
186 {
187  return d->collection;
188 }
189 
190 void CollectionRequester::setCollection(const Collection &collection)
191 {
192  d->collection = collection;
193  QString name;
194  if (collection.isValid()) {
195  name = collection.displayName();
196  }
197 
198  d->edit->setText(name);
199  emit collectionChanged(collection);
200  d->fetchCollection(collection);
201 }
202 
203 void CollectionRequester::setMimeTypeFilter(const QStringList &mimeTypes)
204 {
205  if (d->collectionDialog) {
206  d->collectionDialog->setMimeTypeFilter(mimeTypes);
207  }
208 }
209 
210 QStringList CollectionRequester::mimeTypeFilter() const
211 {
212  if (d->collectionDialog) {
213  return d->collectionDialog->mimeTypeFilter();
214  } else {
215  return QStringList();
216  }
217 }
218 
219 void CollectionRequester::setAccessRightsFilter(Collection::Rights rights)
220 {
221  if (d->collectionDialog) {
222  d->collectionDialog->setAccessRightsFilter(rights);
223  }
224 }
225 
226 Collection::Rights CollectionRequester::accessRightsFilter() const
227 {
228  if (d->collectionDialog) {
229  return d->collectionDialog->accessRightsFilter();
230  } else {
231  return Akonadi::Collection::ReadOnly;
232  }
233 }
234 
235 void CollectionRequester::changeCollectionDialogOptions(CollectionDialog::CollectionDialogOptions options)
236 {
237  if (d->collectionDialog) {
238  d->collectionDialog->changeCollectionDialogOptions(options);
239  }
240 }
241 
242 void CollectionRequester::setContentMimeTypes(const QStringList &mimetypes)
243 {
244  if (d->collectionDialog) {
245  d->collectionDialog->setContentMimeTypes(mimetypes);
246  }
247 }
248 
249 void CollectionRequester::changeEvent(QEvent *event)
250 {
251  if (event->type() == QEvent::WindowTitleChange) {
252  if (d->collectionDialog) {
253  d->collectionDialog->setCaption(windowTitle());
254  }
255  } else if (event->type() == QEvent::EnabledChange) {
256  if (d->collectionDialog) {
257  d->collectionDialog->setEnabled(true);
258  }
259  }
260  KHBox::changeEvent(event);
261 }
262 
263 #include "moc_collectionrequester.cpp"
Akonadi::CollectionDialog::selectedCollection
Akonadi::Collection selectedCollection() const
Returns the selected collection if the selection mode is QAbstractItemView::SingleSelection.
Definition: collectiondialog_desktop.cpp:309
QEvent
QWidget
QEvent::type
Type type() const
Akonadi::CollectionFetchScope::setAncestorRetrieval
void setAncestorRetrieval(AncestorRetrieval ancestorDepth)
Sets how many levels of ancestor collections should be included in the retrieval. ...
Definition: collectionfetchscope.cpp:138
Akonadi::CollectionFetchJob::collections
Collection::List collections() const
Returns the list of fetched collection.
Definition: collectionfetchjob.cpp:169
Akonadi::Collection::displayName
QString displayName() const
Returns the display name (EntityDisplayAttribute::displayName()) if set, and Collection::name() other...
Definition: collection.cpp:86
Akonadi::CollectionRequester::collection
Akonadi::Collection collection() const
Returns the currently chosen collection, or an empty collection if none none was chosen.
Definition: collectionrequester.cpp:185
Akonadi::CollectionRequester::mimeTypeFilter
QStringList mimeTypeFilter() const
Returns the mime types any of which the selected collection shall support.
Definition: collectionrequester.cpp:210
Akonadi::CollectionDialog
A collection selection dialog.
Definition: collectiondialog.h:67
Akonadi::CollectionRequester::setMimeTypeFilter
void setMimeTypeFilter(const QStringList &mimeTypes)
Sets the mime types any of which the selected collection shall support.
Definition: collectionrequester.cpp:203
Akonadi::CollectionRequester::collectionChanged
void collectionChanged(const Akonadi::Collection &collection)
This signal is emitted when the selected collection has changed.
Akonadi::CollectionFetchJob::fetchScope
CollectionFetchScope & fetchScope()
Returns the collection fetch scope.
Definition: collectionfetchjob.cpp:439
Akonadi::Collection
Represents a collection of PIM items.
Definition: collection.h:75
QMap
Akonadi::CollectionFetchJob
Job that fetches collections from the Akonadi storage.
Definition: collectionfetchjob.h:53
QStringList::join
QString join(const QString &separator) const
Akonadi::CollectionFetchScope::Parent
Only retrieve the immediate parent collection.
Definition: collectionfetchscope.h:76
Akonadi::CollectionRequester
A widget to request an Akonadi collection from the user.
Definition: collectionrequester.h:58
QList::size
int size() const
Akonadi::CollectionFetchJob::Base
Only fetch the base collection.
Definition: collectionfetchjob.h:62
Akonadi::CollectionRequester::setAccessRightsFilter
void setAccessRightsFilter(Collection::Rights rights)
Sets the access rights that the listed collections shall match with.
Definition: collectionrequester.cpp:219
Akonadi::Collection::ReadOnly
Can only read items or subcollection of this collection.
Definition: collection.h:87
Akonadi::CollectionRequester::setCollection
void setCollection(const Akonadi::Collection &collection)
Sets the collection of the requester.
Definition: collectionrequester.cpp:190
Akonadi::CollectionFetchScope::All
Retrieve all ancestors, up to Collection::root()
Definition: collectionfetchscope.h:77
Akonadi::CollectionRequester::accessRightsFilter
Collection::Rights accessRightsFilter() const
Returns the access rights that the listed collections shall match with.
Definition: collectionrequester.cpp:226
QList::first
T & first()
QString
QList
Akonadi::Entity::id
Id id() const
Returns the unique identifier of the entity.
Definition: entity.cpp:72
QStringList
QAction::setShortcut
void setShortcut(const QKeySequence &shortcut)
Akonadi::CollectionRequester::CollectionRequester
CollectionRequester(QWidget *parent=0)
Creates a collection requester.
Definition: collectionrequester.cpp:165
QLatin1String
QAction
Akonadi::CollectionRequester::changeCollectionDialogOptions
void changeCollectionDialogOptions(CollectionDialog::CollectionDialogOptions options)
Definition: collectionrequester.cpp:235
QList::prepend
void prepend(const T &value)
QMap::insert
iterator insert(const Key &key, const T &value)
Akonadi::CollectionRequester::~CollectionRequester
~CollectionRequester()
Destroys the collection requester.
Definition: collectionrequester.cpp:180
Akonadi::Collection::parent
AKONADI_DEPRECATED Id parent() const
Returns the identifier of the parent collection.
Definition: collection.cpp:129
Akonadi::Entity::isValid
bool isValid() const
Returns whether the entity is valid.
Definition: entity.cpp:97
QMap::take
T take(const Key &key)
Akonadi::CollectionRequester::setContentMimeTypes
void setContentMimeTypes(const QStringList &mimetypes)
Allow to specify collection content mimetype when we create new one.
Definition: collectionrequester.cpp:242
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:38:02 by doxygen 1.8.7 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 API Reference

Skip menu "kdepimlibs 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

Search



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