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

akonadi

  • sources
  • kde-4.12
  • 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 #include <QApplication>
35 
36 using namespace Akonadi;
37 
38 class CollectionRequester::Private
39 {
40  public:
41  Private( CollectionRequester *parent )
42  : q( parent ),
43  edit( 0 ),
44  button( 0 ),
45  collectionDialog( 0 )
46  {
47  }
48 
49  ~Private()
50  {
51  }
52 
53  QString fetchCollection(const Collection &collection);
54 
55  void init();
56 
57  // slots
58  void _k_slotOpenDialog();
59 
60  CollectionRequester *q;
61  Collection collection;
62  KLineEdit *edit;
63  KPushButton *button;
64  CollectionDialog *collectionDialog;
65 };
66 
67 QString CollectionRequester::Private::fetchCollection(const Collection &collection)
68 {
69  QString result;
70  Akonadi::CollectionFetchJob *job = new Akonadi::CollectionFetchJob( collection, Akonadi::CollectionFetchJob::Base, q );
71  job->fetchScope().setAncestorRetrieval( Akonadi::CollectionFetchScope::Parent );
72  if (job->exec()) {
73  if (job->collections().size() == 1) {
74  Akonadi::Collection col = job->collections().at(0);
75  if (col != Akonadi::Collection::root()) {
76  const QString tmp = fetchCollection(Akonadi::Collection(col.parent()));
77  if (tmp.isEmpty()) {
78  result = col.displayName();
79  } else {
80  result = fetchCollection(Akonadi::Collection(col.parent())) + QLatin1Char('/') + col.displayName();
81  }
82  }
83  }
84  }
85  return result;
86 }
87 
88 void CollectionRequester::Private::init()
89 {
90  q->setMargin( 0 );
91 
92  edit = new KLineEdit( q );
93  edit->setReadOnly( true );
94  edit->setClickMessage( i18n( "No Folder" ) );
95  edit->setClearButtonShown( false );
96  edit->setFocusPolicy( Qt::NoFocus );
97 
98  button = new KPushButton( q );
99  button->setIcon( KIcon( QLatin1String( "document-open" ) ) );
100  const int buttonSize = edit->sizeHint().height();
101  button->setFixedSize( buttonSize, buttonSize );
102  button->setToolTip( i18n( "Open collection dialog" ) );
103 
104  q->setSpacing( -1 );
105 
106  edit->installEventFilter( q );
107  q->setFocusProxy( button );
108  q->setFocusPolicy( Qt::StrongFocus );
109 
110  q->connect( button, SIGNAL(clicked()), q, SLOT(_k_slotOpenDialog()) );
111 
112  QAction *openAction = new QAction( q );
113  openAction->setShortcut( KStandardShortcut::Open );
114  q->connect( openAction, SIGNAL(triggered(bool)), q, SLOT(_k_slotOpenDialog()) );
115 
116  collectionDialog = new CollectionDialog( q );
117  collectionDialog->setWindowIcon( KIcon( QLatin1String( "akonadi" ) ) );
118  collectionDialog->setCaption( i18n( "Select a collection" ) );
119  collectionDialog->setSelectionMode( QAbstractItemView::SingleSelection );
120  collectionDialog->changeCollectionDialogOptions(CollectionDialog::KeepTreeExpanded);
121 }
122 
123 void CollectionRequester::Private::_k_slotOpenDialog()
124 {
125  CollectionDialog *dlg = collectionDialog;
126 
127  if ( dlg->exec() != QDialog::Accepted ) {
128  return;
129  }
130 
131  const Akonadi::Collection collection = dlg->selectedCollection();
132  q->setCollection( collection );
133  emit q->collectionChanged( collection );
134 }
135 
136 CollectionRequester::CollectionRequester( QWidget *parent )
137  : KHBox( parent ),
138  d( new Private( this ) )
139 {
140  d->init();
141 }
142 
143 CollectionRequester::CollectionRequester( const Akonadi::Collection &collection, QWidget *parent )
144  : KHBox( parent ),
145  d( new Private( this ) )
146 {
147  d->init();
148  setCollection( collection );
149 }
150 
151 CollectionRequester::~CollectionRequester()
152 {
153  delete d;
154 }
155 
156 Collection CollectionRequester::collection() const
157 {
158  return d->collection;
159 }
160 
161 void CollectionRequester::setCollection( const Collection& collection )
162 {
163  d->collection = collection;
164  QString name;
165  if ( collection.isValid() ) {
166  name = collection.displayName();
167  }
168 
169  d->edit->setText( name );
170  emit collectionChanged( collection );
171  const QString result = d->fetchCollection(collection);
172  d->edit->setText( result );
173 }
174 
175 void CollectionRequester::setMimeTypeFilter( const QStringList &mimeTypes )
176 {
177  if ( d->collectionDialog ) {
178  d->collectionDialog->setMimeTypeFilter( mimeTypes );
179  }
180 }
181 
182 QStringList CollectionRequester::mimeTypeFilter() const
183 {
184  if ( d->collectionDialog ) {
185  return d->collectionDialog->mimeTypeFilter();
186  } else {
187  return QStringList();
188  }
189 }
190 
191 void CollectionRequester::setAccessRightsFilter( Collection::Rights rights )
192 {
193  if ( d->collectionDialog ) {
194  d->collectionDialog->setAccessRightsFilter( rights );
195  }
196 }
197 
198 Collection::Rights CollectionRequester::accessRightsFilter() const
199 {
200  if ( d->collectionDialog ) {
201  return d->collectionDialog->accessRightsFilter();
202  } else {
203  return Akonadi::Collection::ReadOnly;
204  }
205 }
206 
207 void CollectionRequester::changeCollectionDialogOptions( CollectionDialog::CollectionDialogOptions options )
208 {
209  if ( d->collectionDialog ) {
210  d->collectionDialog->changeCollectionDialogOptions( options );
211  }
212 }
213 
214 #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:256
Akonadi::CollectionFetchScope::setAncestorRetrieval
void setAncestorRetrieval(AncestorRetrieval ancestorDepth)
Sets how many levels of ancestor collections should be included in the retrieval. ...
Definition: collectionfetchscope.cpp:134
Akonadi::CollectionFetchJob::collections
Collection::List collections() const
Returns the list of fetched collection.
Definition: collectionfetchjob.cpp:175
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:156
Akonadi::CollectionRequester::mimeTypeFilter
QStringList mimeTypeFilter() const
Returns the mime types any of which the selected collection shall support.
Definition: collectionrequester.cpp:182
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:175
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:437
Akonadi::Collection
Represents a collection of PIM items.
Definition: collection.h:75
Akonadi::CollectionFetchJob
Job that fetches collections from the Akonadi storage.
Definition: collectionfetchjob.h:53
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
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:191
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:161
Akonadi::CollectionRequester::accessRightsFilter
Collection::Rights accessRightsFilter() const
Returns the access rights that the listed collections shall match with.
Definition: collectionrequester.cpp:198
Akonadi::Collection::root
static Collection root()
Returns the root collection.
Definition: collection.cpp:192
Akonadi::CollectionRequester::CollectionRequester
CollectionRequester(QWidget *parent=0)
Creates a collection requester.
Definition: collectionrequester.cpp:136
Akonadi::CollectionRequester::changeCollectionDialogOptions
void changeCollectionDialogOptions(CollectionDialog::CollectionDialogOptions options)
Definition: collectionrequester.cpp:207
Akonadi::CollectionRequester::~CollectionRequester
~CollectionRequester()
Destroys the collection requester.
Definition: collectionrequester.cpp:151
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
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:26 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
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

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