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

akonadi

  • akonadi
subscriptiondialog.cpp
1 /*
2  Copyright (c) 2007 Volker Krause <vkrause@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 "subscriptiondialog_p.h"
21 
22 #include "control.h"
23 #include "recursivecollectionfilterproxymodel.h"
24 #include "subscriptionjob_p.h"
25 #include "subscriptionmodel_p.h"
26 
27 #include <kdebug.h>
28 
29 #include <QBoxLayout>
30 
31 #include <klocale.h>
32 
33 #ifndef KDEPIM_MOBILE_UI
34 #include <klineedit.h>
35 #include <KPushButton>
36 #include <krecursivefilterproxymodel.h>
37 #include <QHeaderView>
38 #include <QLabel>
39 #include <QTreeView>
40 #include <QCheckBox>
41 #include <QItemSelectionModel>
42 #else
43 #include <kdescendantsproxymodel.h>
44 #include <QListView>
45 #include <QSortFilterProxyModel>
46 
47 class CheckableFilterProxyModel : public QSortFilterProxyModel
48 {
49 public:
50  CheckableFilterProxyModel( QObject *parent = 0 )
51  : QSortFilterProxyModel( parent ) { }
52 
53 protected:
54  /*reimp*/ bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const
55  {
56  QModelIndex sourceIndex = sourceModel()->index( sourceRow, 0, sourceParent );
57  return sourceModel()->flags( sourceIndex ) & Qt::ItemIsUserCheckable;
58  }
59 };
60 #endif
61 
62 using namespace Akonadi;
63 
67 class SubscriptionDialog::Private
68 {
69  public:
70  Private( SubscriptionDialog *parent ) : q( parent ) {}
71 
72  void done()
73  {
74  SubscriptionJob *job = new SubscriptionJob( q );
75  job->subscribe( model->subscribed() );
76  job->unsubscribe( model->unsubscribed() );
77  connect( job, SIGNAL(result(KJob*)), q, SLOT(subscriptionResult(KJob*)) );
78  }
79 
80  void subscriptionResult( KJob *job )
81  {
82  if ( job->error() ) {
83  // TODO
84  kWarning() << job->errorString();
85  }
86  q->deleteLater();
87  }
88 
89  void modelLoaded()
90  {
91  collectionView->setEnabled( true );
92 #ifndef KDEPIM_MOBILE_UI
93  collectionView->expandAll();
94 #endif
95  q->enableButtonOk( true );
96  }
97  void slotSetPattern(const QString &text)
98  {
99  filterRecursiveCollectionFilter->setSearchPattern( text );
100  }
101  void slotSetIncludeCheckedOnly(bool checked)
102  {
103  filterRecursiveCollectionFilter->setIncludeCheckedOnly( checked );
104  }
105 
106  void slotUnSubscribe();
107  void slotSubscribe();
108 
109  SubscriptionDialog* q;
110 #ifndef KDEPIM_MOBILE_UI
111  QTreeView *collectionView;
112  KPushButton *subscribe;
113  KPushButton *unSubscribe;
114 #else
115  QListView *collectionView;
116 #endif
117  SubscriptionModel* model;
118  RecursiveCollectionFilterProxyModel *filterRecursiveCollectionFilter;
119 
120 };
121 
122 
123 void SubscriptionDialog::Private::slotSubscribe()
124 {
125 #ifndef KDEPIM_MOBILE_UI
126  QModelIndexList list = collectionView->selectionModel()->selectedIndexes();
127  foreach (const QModelIndex& index, list) {
128  model->setData(index, Qt::Checked, Qt::CheckStateRole);
129  }
130  collectionView->setFocus();
131 #endif
132 }
133 
134 void SubscriptionDialog::Private::slotUnSubscribe()
135 {
136 #ifndef KDEPIM_MOBILE_UI
137  QModelIndexList list = collectionView->selectionModel()->selectedIndexes();
138  foreach (const QModelIndex& index, list) {
139  model->setData(index, Qt::Unchecked, Qt::CheckStateRole);
140  }
141  collectionView->setFocus();
142 #endif
143 }
144 
145 
146 SubscriptionDialog::SubscriptionDialog(QWidget * parent) :
147  KDialog( parent ),
148  d( new Private( this ) )
149 {
150  init( QStringList() );
151 }
152 
153 SubscriptionDialog::SubscriptionDialog(const QStringList& mimetypes, QWidget * parent) :
154  KDialog( parent ),
155  d( new Private( this ) )
156 {
157  init( mimetypes );
158 }
159 
160 void SubscriptionDialog::showHiddenCollection(bool showHidden)
161 {
162  d->model->showHiddenCollection(showHidden);
163 }
164 
165 void SubscriptionDialog::init( const QStringList &mimetypes )
166 {
167  enableButtonOk( false );
168  setCaption( i18n( "Local Subscriptions" ) );
169  QWidget *mainWidget = new QWidget( this );
170  QVBoxLayout *mainLayout = new QVBoxLayout;
171  mainWidget->setLayout( mainLayout );
172  setMainWidget( mainWidget );
173 
174  d->model = new SubscriptionModel( this );
175 
176 #ifndef KDEPIM_MOBILE_UI
177  d->filterRecursiveCollectionFilter
178  = new Akonadi::RecursiveCollectionFilterProxyModel( this );
179  d->filterRecursiveCollectionFilter->setDynamicSortFilter( true );
180  d->filterRecursiveCollectionFilter->setSourceModel( d->model );
181  d->filterRecursiveCollectionFilter->setFilterCaseSensitivity( Qt::CaseInsensitive );
182  if ( !mimetypes.isEmpty() ) {
183  d->filterRecursiveCollectionFilter->addContentMimeTypeInclusionFilters( mimetypes );
184  }
185 
186 
187  d->collectionView = new QTreeView( mainWidget );
188  d->collectionView->setEditTriggers( QAbstractItemView::NoEditTriggers );
189  d->collectionView->header()->hide();
190  d->collectionView->setModel( d->filterRecursiveCollectionFilter );
191  d->collectionView->setSelectionMode(QAbstractItemView::ExtendedSelection);
192 
193  QHBoxLayout *filterBarLayout = new QHBoxLayout;
194 
195  filterBarLayout->addWidget( new QLabel( i18n( "Search:" ) ) );
196 
197  KLineEdit *lineEdit = new KLineEdit( mainWidget );
198  lineEdit->setClearButtonShown(true);
199  lineEdit->setFocus();
200  connect( lineEdit, SIGNAL(textChanged(QString)),
201  this, SLOT(slotSetPattern(QString)) );
202  filterBarLayout->addWidget( lineEdit );
203  QCheckBox *checkBox = new QCheckBox( i18n("Subscribed only"), mainWidget );
204  connect( checkBox, SIGNAL(clicked(bool)),
205  this, SLOT(slotSetIncludeCheckedOnly(bool)) );
206  filterBarLayout->addWidget( checkBox );
207 
208 
209  QHBoxLayout *hboxLayout = new QHBoxLayout;
210  hboxLayout->addWidget( d->collectionView );
211 
212 
213  QVBoxLayout *subscribeButtonLayout = new QVBoxLayout;
214  d->subscribe = new KPushButton(i18n("Subscribe"));
215  subscribeButtonLayout->addWidget(d->subscribe);
216  connect(d->subscribe,SIGNAL(clicked()),this,SLOT(slotSubscribe()));
217 
218  d->unSubscribe = new KPushButton(i18n("Unsubscribe"));
219  subscribeButtonLayout->addWidget(d->unSubscribe);
220  connect(d->unSubscribe,SIGNAL(clicked()),this,SLOT(slotUnSubscribe()));
221  subscribeButtonLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Minimum, QSizePolicy::Expanding ) );
222 
223 
224  hboxLayout->addLayout(subscribeButtonLayout);
225 
226  mainLayout->addLayout(filterBarLayout);
227  mainLayout->addLayout(hboxLayout);
228 
229 
230 #else
231 
232  d->filterRecursiveCollectionFilter
233  = new Akonadi::RecursiveCollectionFilterProxyModel( this );
234  if ( !mimetypes.isEmpty() )
235  d->filterRecursiveCollectionFilter->addContentMimeTypeInclusionFilters( mimetypes );
236 
237  d->filterRecursiveCollectionFilter->setSourceModel( d->model );
238 
239  KDescendantsProxyModel *flatModel = new KDescendantsProxyModel( this );
240  flatModel->setDisplayAncestorData( true );
241  flatModel->setAncestorSeparator( QLatin1String( "/" ) );
242  flatModel->setSourceModel( d->filterRecursiveCollectionFilter );
243 
244  CheckableFilterProxyModel *checkableModel = new CheckableFilterProxyModel( this );
245  checkableModel->setSourceModel( flatModel );
246 
247  d->collectionView = new QListView( mainWidget );
248 
249  d->collectionView->setModel( checkableModel );
250  mainLayout->addWidget( d->collectionView );
251 #endif
252 
253  connect( d->model, SIGNAL(loaded()), SLOT(modelLoaded()) );
254  connect( this, SIGNAL(okClicked()), SLOT(done()) );
255  connect( this, SIGNAL(cancelClicked()), SLOT(deleteLater()) );
256  Control::widgetNeedsAkonadi( mainWidget );
257 }
258 
259 SubscriptionDialog::~ SubscriptionDialog()
260 {
261  delete d;
262 }
263 
264 
265 #include "moc_subscriptiondialog_p.cpp"
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:27:43 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