• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.9.4 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 <QtGui/QBoxLayout>
30 
31 #include <klocale.h>
32 
33 #ifndef KDEPIM_MOBILE_UI
34 #include <klineedit.h>
35 #include <krecursivefilterproxymodel.h>
36 #include <QtGui/QHeaderView>
37 #include <QtGui/QLabel>
38 #include <QtGui/QTreeView>
39 #include <QtGui/QCheckBox>
40 #else
41 #include <kdescendantsproxymodel.h>
42 #include <QtGui/QListView>
43 #include <QtGui/QSortFilterProxyModel>
44 
45 class CheckableFilterProxyModel : public QSortFilterProxyModel
46 {
47 public:
48  CheckableFilterProxyModel( QObject *parent = 0 )
49  : QSortFilterProxyModel( parent ) { }
50 
51 protected:
52  /*reimp*/ bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const
53  {
54  QModelIndex sourceIndex = sourceModel()->index( sourceRow, 0, sourceParent );
55  return sourceModel()->flags( sourceIndex ) & Qt::ItemIsUserCheckable;
56  }
57 };
58 #endif
59 
60 using namespace Akonadi;
61 
65 class SubscriptionDialog::Private
66 {
67  public:
68  Private( SubscriptionDialog *parent ) : q( parent ) {}
69 
70  void done()
71  {
72  SubscriptionJob *job = new SubscriptionJob( q );
73  job->subscribe( model->subscribed() );
74  job->unsubscribe( model->unsubscribed() );
75  connect( job, SIGNAL(result(KJob*)), q, SLOT(subscriptionResult(KJob*)) );
76  }
77 
78  void subscriptionResult( KJob *job )
79  {
80  if ( job->error() ) {
81  // TODO
82  kWarning() << job->errorString();
83  }
84  q->deleteLater();
85  }
86 
87  void modelLoaded()
88  {
89  collectionView->setEnabled( true );
90 #ifndef KDEPIM_MOBILE_UI
91  collectionView->expandAll();
92 #endif
93  q->enableButtonOk( true );
94  }
95  void slotSetPattern(const QString &text)
96  {
97  filterRecursiveCollectionFilter->setSearchPattern( text );
98  }
99  void slotSetIncludeCheckedOnly(bool checked)
100  {
101  filterRecursiveCollectionFilter->setIncludeCheckedOnly( checked );
102  }
103 
104  SubscriptionDialog* q;
105 #ifndef KDEPIM_MOBILE_UI
106  QTreeView *collectionView;
107 #else
108  QListView *collectionView;
109 #endif
110  SubscriptionModel* model;
111  RecursiveCollectionFilterProxyModel *filterRecursiveCollectionFilter;
112 
113 };
114 
115 SubscriptionDialog::SubscriptionDialog(QWidget * parent) :
116  KDialog( parent ),
117  d( new Private( this ) )
118 {
119  init( QStringList() );
120 }
121 
122 SubscriptionDialog::SubscriptionDialog(const QStringList& mimetypes, QWidget * parent) :
123  KDialog( parent ),
124  d( new Private( this ) )
125 {
126  init( mimetypes );
127 }
128 
129 void SubscriptionDialog::showHiddenCollection(bool showHidden)
130 {
131  d->model->showHiddenCollection(showHidden);
132 }
133 
134 void SubscriptionDialog::init( const QStringList &mimetypes )
135 {
136  enableButtonOk( false );
137  setCaption( i18n( "Local Subscriptions" ) );
138  QWidget *mainWidget = new QWidget( this );
139  QVBoxLayout *mainLayout = new QVBoxLayout;
140  mainWidget->setLayout( mainLayout );
141  setMainWidget( mainWidget );
142 
143  d->model = new SubscriptionModel( this );
144 
145 #ifndef KDEPIM_MOBILE_UI
146  d->filterRecursiveCollectionFilter
147  = new Akonadi::RecursiveCollectionFilterProxyModel( this );
148  d->filterRecursiveCollectionFilter->setDynamicSortFilter( true );
149  d->filterRecursiveCollectionFilter->setSourceModel( d->model );
150  d->filterRecursiveCollectionFilter->setFilterCaseSensitivity( Qt::CaseInsensitive );
151  if ( !mimetypes.isEmpty() ) {
152  d->filterRecursiveCollectionFilter->addContentMimeTypeInclusionFilters( mimetypes );
153  }
154 
155  d->collectionView = new QTreeView( mainWidget );
156  d->collectionView->setEditTriggers( QAbstractItemView::NoEditTriggers );
157  d->collectionView->header()->hide();
158  d->collectionView->setModel( d->filterRecursiveCollectionFilter );
159 
160 
161  QHBoxLayout *filterBarLayout = new QHBoxLayout;
162 
163  filterBarLayout->addWidget( new QLabel( i18n( "Search:" ) ) );
164 
165  KLineEdit *lineEdit = new KLineEdit( mainWidget );
166  lineEdit->setClearButtonShown(true);
167  lineEdit->setFocus();
168  connect( lineEdit, SIGNAL(textChanged(QString)),
169  this, SLOT(slotSetPattern(QString)) );
170  filterBarLayout->addWidget( lineEdit );
171  QCheckBox *checkBox = new QCheckBox( i18n("Subscribed only"), mainWidget );
172  connect( checkBox, SIGNAL(clicked(bool)),
173  this, SLOT(slotSetIncludeCheckedOnly(bool)) );
174  filterBarLayout->addWidget( checkBox );
175 
176  mainLayout->addLayout( filterBarLayout );
177  mainLayout->addWidget( d->collectionView );
178 #else
179 
180  d->filterRecursiveCollectionFilter
181  = new Akonadi::RecursiveCollectionFilterProxyModel( this );
182  if ( !mimetypes.isEmpty() )
183  d->filterRecursiveCollectionFilter->addContentMimeTypeInclusionFilters( mimetypes );
184 
185  d->filterRecursiveCollectionFilter->setSourceModel( d->model );
186 
187  KDescendantsProxyModel *flatModel = new KDescendantsProxyModel( this );
188  flatModel->setDisplayAncestorData( true );
189  flatModel->setAncestorSeparator( QLatin1String( "/" ) );
190  flatModel->setSourceModel( d->filterRecursiveCollectionFilter );
191 
192  CheckableFilterProxyModel *checkableModel = new CheckableFilterProxyModel( this );
193  checkableModel->setSourceModel( flatModel );
194 
195  d->collectionView = new QListView( mainWidget );
196 
197  d->collectionView->setModel( checkableModel );
198  mainLayout->addWidget( d->collectionView );
199 #endif
200 
201  connect( d->model, SIGNAL(loaded()), SLOT(modelLoaded()) );
202  connect( this, SIGNAL(okClicked()), SLOT(done()) );
203  connect( this, SIGNAL(cancelClicked()), SLOT(deleteLater()) );
204  Control::widgetNeedsAkonadi( mainWidget );
205 }
206 
207 SubscriptionDialog::~ SubscriptionDialog()
208 {
209  delete d;
210 }
211 
212 
213 #include "subscriptiondialog_p.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Tue Dec 11 2012 12:14:35 by doxygen 1.8.1.2 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.9.4 API Reference

Skip menu "kdepimlibs-4.9.4 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • 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