20#include "collectionrequester.h"
21#include "collectiondialog.h"
22#include "entitydisplayattribute.h"
23#include "collectionfetchjob.h"
24#include "collectionfetchscope.h"
27#include <klocalizedstring.h>
28#include <kpushbutton.h>
30#include <kstandardshortcut.h>
32#include <QtCore/QEvent>
37class CollectionRequester::Private
52 void fetchCollection(
const Collection &collection);
57 void _k_slotOpenDialog();
58 void _k_collectionReceived(KJob *job);
59 void _k_collectionsNamesReceived(KJob *job);
62 Collection collection;
65 CollectionDialog *collectionDialog;
68void CollectionRequester::Private::fetchCollection(
const Collection &collection)
71 job->setProperty(
"OriginalCollectionId", collection.id());
73 connect(job, SIGNAL(finished(KJob*)),
74 q, SLOT(_k_collectionReceived(KJob*)));
77void CollectionRequester::Private::_k_collectionReceived(KJob *job)
79 CollectionFetchJob *fetch = qobject_cast<CollectionFetchJob*>(job);
82 Collection currentCollection = fetch->
collections().first();
83 while (currentCollection.
isValid()) {
84 chain << currentCollection;
85 currentCollection = Collection(currentCollection.parentCollection());
89 namesFetch->setProperty(
"OriginalCollectionId", job->property(
"OriginalCollectionId"));
91 connect(namesFetch, SIGNAL(finished(KJob*)),
92 q, SLOT(_k_collectionsNamesReceived(KJob*)));
94 _k_collectionsNamesReceived(job);
98void CollectionRequester::Private::_k_collectionsNamesReceived(KJob *job)
100 CollectionFetchJob *fetch = qobject_cast<CollectionFetchJob*>(job);
101 const qint64 originalId = fetch->property(
"OriginalCollectionId").toLongLong();
103 QMap<qint64, Collection> names;
108 QStringList namesList;
109 Collection currentCollection = names.take(originalId);
110 while (currentCollection.
isValid()) {
111 namesList.prepend(currentCollection.
displayName());
112 currentCollection = names.take(currentCollection.
parent());
114 edit->setText(namesList.join(QLatin1String(
"/")));
117void CollectionRequester::Private::init()
121 edit =
new KLineEdit(q);
122 edit->setReadOnly(
true);
123 edit->setClickMessage(i18n(
"No Folder"));
124 edit->setClearButtonShown(
false);
125 edit->setFocusPolicy(Qt::NoFocus);
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"));
135 edit->installEventFilter(q);
136 q->setFocusProxy(button);
137 q->setFocusPolicy(Qt::StrongFocus);
139 q->connect(button, SIGNAL(clicked()), q, SLOT(_k_slotOpenDialog()));
141 QAction *openAction =
new QAction(q);
142 openAction->setShortcut(KStandardShortcut::Open);
143 q->connect(openAction, SIGNAL(triggered(
bool)), q, SLOT(_k_slotOpenDialog()));
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);
152void CollectionRequester::Private::_k_slotOpenDialog()
154 CollectionDialog *dlg = collectionDialog;
156 if (dlg->exec() != QDialog::Accepted) {
167 , d(new Private(this))
174 , d(new Private(this))
187 return d->collection;
198 d->edit->setText(name);
205 if (d->collectionDialog) {
206 d->collectionDialog->setMimeTypeFilter(mimeTypes);
212 if (d->collectionDialog) {
213 return d->collectionDialog->mimeTypeFilter();
215 return QStringList();
221 if (d->collectionDialog) {
222 d->collectionDialog->setAccessRightsFilter(rights);
228 if (d->collectionDialog) {
229 return d->collectionDialog->accessRightsFilter();
237 if (d->collectionDialog) {
238 d->collectionDialog->changeCollectionDialogOptions(options);
244 if (d->collectionDialog) {
245 d->collectionDialog->setContentMimeTypes(mimetypes);
249void CollectionRequester::changeEvent(QEvent *event)
251 if (event->type() == QEvent::WindowTitleChange) {
252 if (d->collectionDialog) {
253 d->collectionDialog->setCaption(windowTitle());
255 }
else if (event->type() == QEvent::EnabledChange) {
256 if (d->collectionDialog) {
257 d->collectionDialog->setEnabled(
true);
260 KHBox::changeEvent(event);
263#include "moc_collectionrequester.cpp"
Akonadi::Collection selectedCollection() const
Returns the selected collection if the selection mode is QAbstractItemView::SingleSelection.
CollectionFetchScope & fetchScope()
Returns the collection fetch scope.
@ Base
Only fetch the base collection.
Collection::List collections() const
Returns the list of fetched collection.
void setAncestorRetrieval(AncestorRetrieval ancestorDepth)
Sets how many levels of ancestor collections should be included in the retrieval.
@ Parent
Only retrieve the immediate parent collection.
@ All
Retrieve all ancestors, up to Collection::root()
void setContentMimeTypes(const QStringList &mimetypes)
Allow to specify collection content mimetype when we create new one.
void collectionChanged(const Akonadi::Collection &collection)
This signal is emitted when the selected collection has changed.
void setCollection(const Akonadi::Collection &collection)
Sets the collection of the requester.
Akonadi::Collection collection() const
Returns the currently chosen collection, or an empty collection if none none was chosen.
QStringList mimeTypeFilter() const
Returns the mime types any of which the selected collection shall support.
Collection::Rights accessRightsFilter() const
Returns the access rights that the listed collections shall match with.
void changeCollectionDialogOptions(CollectionDialog::CollectionDialogOptions options)
~CollectionRequester()
Destroys the collection requester.
void setMimeTypeFilter(const QStringList &mimeTypes)
Sets the mime types any of which the selected collection shall support.
void setAccessRightsFilter(Collection::Rights rights)
Sets the access rights that the listed collections shall match with.
CollectionRequester(QWidget *parent=0)
Creates a collection requester.
Represents a collection of PIM items.
QString displayName() const
Returns the display name (EntityDisplayAttribute::displayName()) if set, and Collection::name() other...
QList< Collection > List
Describes a list of collections.
@ ReadOnly
Can only read items or subcollection of this collection.
AKONADI_DEPRECATED Id parent() const
Returns the identifier of the parent collection.
bool isValid() const
Returns whether the entity is valid.
FreeBusyManager::Singleton.