• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.10.5 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 
23 #include <klineedit.h>
24 #include <klocale.h>
25 #include <kpushbutton.h>
26 #include <kstandardshortcut.h>
27 
28 #include <QtCore/QEvent>
29 #include <QAction>
30 #include <QApplication>
31 
32 using namespace Akonadi;
33 
34 class CollectionRequester::Private
35 {
36  public:
37  Private( CollectionRequester *parent )
38  : q( parent ),
39  edit( 0 ),
40  button( 0 ),
41  collectionDialog( 0 )
42  {
43  }
44 
45  ~Private()
46  {
47  }
48 
49  void init();
50 
51  // slots
52  void _k_slotOpenDialog();
53 
54  CollectionRequester *q;
55  Collection collection;
56  KLineEdit *edit;
57  KPushButton *button;
58  CollectionDialog *collectionDialog;
59 };
60 
61 
62 void CollectionRequester::Private::init()
63 {
64  q->setMargin( 0 );
65 
66  edit = new KLineEdit( q );
67  edit->setReadOnly( true );
68  edit->setClickMessage( i18n( "No Folder" ) );
69  edit->setClearButtonShown( false );
70  edit->setFocusPolicy( Qt::NoFocus );
71 
72  button = new KPushButton( q );
73  button->setIcon( KIcon( QLatin1String( "document-open" ) ) );
74  const int buttonSize = edit->sizeHint().height();
75  button->setFixedSize( buttonSize, buttonSize );
76  button->setToolTip( i18n( "Open collection dialog" ) );
77 
78  q->setSpacing( -1 );
79 
80  edit->installEventFilter( q );
81  q->setFocusProxy( button );
82  q->setFocusPolicy( Qt::StrongFocus );
83 
84  q->connect( button, SIGNAL(clicked()), q, SLOT(_k_slotOpenDialog()) );
85 
86  QAction *openAction = new QAction( q );
87  openAction->setShortcut( KStandardShortcut::Open );
88  q->connect( openAction, SIGNAL(triggered(bool)), q, SLOT(_k_slotOpenDialog()) );
89 
90  collectionDialog = new CollectionDialog( q );
91  collectionDialog->setCaption( i18n( "Select a collection" ) );
92  collectionDialog->setSelectionMode( QAbstractItemView::SingleSelection );
93 }
94 
95 void CollectionRequester::Private::_k_slotOpenDialog()
96 {
97  CollectionDialog *dlg = collectionDialog;
98 
99  if ( dlg->exec() != QDialog::Accepted ) {
100  return;
101  }
102 
103  const Akonadi::Collection collection = dlg->selectedCollection();
104  q->setCollection( collection );
105  emit q->collectionChanged( collection );
106 }
107 
108 CollectionRequester::CollectionRequester( QWidget *parent )
109  : KHBox( parent ),
110  d( new Private( this ) )
111 {
112  d->init();
113 }
114 
115 
116 CollectionRequester::CollectionRequester( const Akonadi::Collection &collection, QWidget *parent )
117  : KHBox( parent ),
118  d( new Private( this ) )
119 {
120  d->init();
121  setCollection( collection );
122 }
123 
124 
125 CollectionRequester::~CollectionRequester()
126 {
127  delete d;
128 }
129 
130 
131 Collection CollectionRequester::collection() const
132 {
133  return d->collection;
134 }
135 
136 
137 void CollectionRequester::setCollection( const Collection& collection )
138 {
139  d->collection = collection;
140  d->edit->setText( collection.isValid() ? collection.name() : QString() );
141  emit collectionChanged( collection );
142 }
143 
144 void CollectionRequester::setMimeTypeFilter( const QStringList &mimeTypes )
145 {
146  if ( d->collectionDialog ) {
147  d->collectionDialog->setMimeTypeFilter( mimeTypes );
148  }
149 }
150 
151 QStringList CollectionRequester::mimeTypeFilter() const
152 {
153  if ( d->collectionDialog ) {
154  return d->collectionDialog->mimeTypeFilter();
155  } else {
156  return QStringList();
157  }
158 }
159 
160 void CollectionRequester::setAccessRightsFilter( Collection::Rights rights )
161 {
162  if ( d->collectionDialog ) {
163  d->collectionDialog->setAccessRightsFilter( rights );
164  }
165 }
166 
167 Collection::Rights CollectionRequester::accessRightsFilter() const
168 {
169  if ( d->collectionDialog ) {
170  return d->collectionDialog->accessRightsFilter();
171  } else {
172  return Akonadi::Collection::ReadOnly;
173  }
174 }
175 
176 void CollectionRequester::changeCollectionDialogOptions( CollectionDialog::CollectionDialogOptions options )
177 {
178  if ( d->collectionDialog ) {
179  d->collectionDialog->changeCollectionDialogOptions( options );
180  }
181 }
182 
183 #include "moc_collectionrequester.cpp"
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:27:33 by doxygen 1.8.3.1 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.10.5 API Reference

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