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

akonadi

  • 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  Akonadi::CollectionFetchJob *job = new Akonadi::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->edit->setText( collection.displayName() );
201  d->fetchCollection( collection );
202 }
203 
204 void CollectionRequester::setMimeTypeFilter( const QStringList &mimeTypes )
205 {
206  if ( d->collectionDialog ) {
207  d->collectionDialog->setMimeTypeFilter( mimeTypes );
208  }
209 }
210 
211 QStringList CollectionRequester::mimeTypeFilter() const
212 {
213  if ( d->collectionDialog ) {
214  return d->collectionDialog->mimeTypeFilter();
215  } else {
216  return QStringList();
217  }
218 }
219 
220 void CollectionRequester::setAccessRightsFilter( Collection::Rights rights )
221 {
222  if ( d->collectionDialog ) {
223  d->collectionDialog->setAccessRightsFilter( rights );
224  }
225 }
226 
227 Collection::Rights CollectionRequester::accessRightsFilter() const
228 {
229  if ( d->collectionDialog ) {
230  return d->collectionDialog->accessRightsFilter();
231  } else {
232  return Akonadi::Collection::ReadOnly;
233  }
234 }
235 
236 void CollectionRequester::changeCollectionDialogOptions( CollectionDialog::CollectionDialogOptions options )
237 {
238  if ( d->collectionDialog ) {
239  d->collectionDialog->changeCollectionDialogOptions( options );
240  }
241 }
242 
243 #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:282
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:179
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:211
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:204
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:441
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:220
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:227
Akonadi::Entity::id
Id id() const
Returns the unique identifier of the entity.
Definition: entity.cpp:72
Akonadi::CollectionRequester::CollectionRequester
CollectionRequester(QWidget *parent=0)
Creates a collection requester.
Definition: collectionrequester.cpp:165
Akonadi::CollectionRequester::changeCollectionDialogOptions
void changeCollectionDialogOptions(CollectionDialog::CollectionDialogOptions options)
Definition: collectionrequester.cpp:236
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
Akonadi::Collection::List
QList< Collection > List
Describes a list of collections.
Definition: collection.h:81
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Mon Jul 21 2014 08:03:51 by doxygen 1.8.6 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.13.3 API Reference

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