20 #include "subscriptiondialog_p.h"
23 #include "recursivecollectionfilterproxymodel.h"
24 #include "subscriptionjob_p.h"
25 #include "subscriptionmodel_p.h"
31 #include <klocalizedstring.h>
33 #ifndef KDEPIM_MOBILE_UI
34 #include <klineedit.h>
35 #include <KPushButton>
36 #include <krecursivefilterproxymodel.h>
37 #include <QHeaderView>
41 #include <QItemSelectionModel>
43 #include <kdescendantsproxymodel.h>
45 #include <QSortFilterProxyModel>
47 class CheckableFilterProxyModel :
public QSortFilterProxyModel
50 CheckableFilterProxyModel( QObject *parent = 0 )
51 : QSortFilterProxyModel( parent ) { }
54 bool filterAcceptsRow(
int sourceRow,
const QModelIndex &sourceParent )
const
56 QModelIndex sourceIndex = sourceModel()->index( sourceRow, 0, sourceParent );
57 return sourceModel()->flags( sourceIndex ) & Qt::ItemIsUserCheckable;
62 using namespace Akonadi;
67 class SubscriptionDialog::Private
77 connect( job, SIGNAL(result(KJob*)), q, SLOT(subscriptionResult(KJob*)) );
80 void subscriptionResult( KJob *job )
84 kWarning() << job->errorString();
91 collectionView->setEnabled(
true );
92 #ifndef KDEPIM_MOBILE_UI
93 collectionView->expandAll();
95 q->enableButtonOk(
true );
97 void slotSetPattern(
const QString &text)
99 filterRecursiveCollectionFilter->setSearchPattern( text );
101 void slotSetIncludeCheckedOnly(
bool checked)
103 filterRecursiveCollectionFilter->setIncludeCheckedOnly( checked );
108 KConfigGroup group( KGlobal::config(),
"SubscriptionDialog" );
109 group.writeEntry(
"Size", q->size() );
114 KConfigGroup group( KGlobal::config(),
"SubscriptionDialog" );
115 const QSize sizeDialog = group.readEntry(
"Size", QSize(300,200) );
116 if ( sizeDialog.isValid() ) {
117 q->resize( sizeDialog );
121 void slotUnSubscribe();
122 void slotSubscribe();
125 #ifndef KDEPIM_MOBILE_UI
126 QTreeView *collectionView;
127 KPushButton *subscribe;
128 KPushButton *unSubscribe;
130 QListView *collectionView;
137 void SubscriptionDialog::Private::slotSubscribe()
139 #ifndef KDEPIM_MOBILE_UI
140 QModelIndexList list = collectionView->selectionModel()->selectedIndexes();
141 foreach (
const QModelIndex& index, list) {
142 model->setData(index, Qt::Checked, Qt::CheckStateRole);
144 collectionView->setFocus();
148 void SubscriptionDialog::Private::slotUnSubscribe()
150 #ifndef KDEPIM_MOBILE_UI
151 QModelIndexList list = collectionView->selectionModel()->selectedIndexes();
152 foreach (
const QModelIndex& index, list) {
153 model->setData(index, Qt::Unchecked, Qt::CheckStateRole);
155 collectionView->setFocus();
161 d( new Private( this ) )
163 init( QStringList() );
168 d( new Private( this ) )
175 d->model->showHiddenCollection(showHidden);
178 void SubscriptionDialog::init(
const QStringList &mimetypes )
180 enableButtonOk(
false );
181 setCaption( i18n(
"Local Subscriptions" ) );
182 QWidget *mainWidget =
new QWidget(
this );
183 QVBoxLayout *mainLayout =
new QVBoxLayout;
184 mainWidget->setLayout( mainLayout );
185 setMainWidget( mainWidget );
189 #ifndef KDEPIM_MOBILE_UI
190 d->filterRecursiveCollectionFilter
192 d->filterRecursiveCollectionFilter->setDynamicSortFilter(
true );
193 d->filterRecursiveCollectionFilter->setSourceModel( d->model );
194 d->filterRecursiveCollectionFilter->setFilterCaseSensitivity( Qt::CaseInsensitive );
195 if ( !mimetypes.isEmpty() ) {
196 d->filterRecursiveCollectionFilter->addContentMimeTypeInclusionFilters( mimetypes );
199 d->collectionView =
new QTreeView( mainWidget );
200 d->collectionView->setEditTriggers( QAbstractItemView::NoEditTriggers );
201 d->collectionView->header()->hide();
202 d->collectionView->setModel( d->filterRecursiveCollectionFilter );
203 d->collectionView->setSelectionMode(QAbstractItemView::ExtendedSelection);
205 QHBoxLayout *filterBarLayout =
new QHBoxLayout;
207 filterBarLayout->addWidget(
new QLabel( i18n(
"Search:" ) ) );
209 KLineEdit *lineEdit =
new KLineEdit( mainWidget );
210 lineEdit->setClearButtonShown(
true);
211 lineEdit->setFocus();
212 connect( lineEdit, SIGNAL(textChanged(QString)),
213 this, SLOT(slotSetPattern(QString)) );
214 filterBarLayout->addWidget( lineEdit );
215 QCheckBox *checkBox =
new QCheckBox( i18n(
"Subscribed only"), mainWidget );
216 connect( checkBox, SIGNAL(clicked(
bool)),
217 this, SLOT(slotSetIncludeCheckedOnly(
bool)) );
218 filterBarLayout->addWidget( checkBox );
220 QHBoxLayout *hboxLayout =
new QHBoxLayout;
221 hboxLayout->addWidget( d->collectionView );
223 QVBoxLayout *subscribeButtonLayout =
new QVBoxLayout;
224 d->subscribe =
new KPushButton(i18n(
"Subscribe"));
225 subscribeButtonLayout->addWidget(d->subscribe);
226 connect(d->subscribe,SIGNAL(clicked()),
this,SLOT(slotSubscribe()));
228 d->unSubscribe =
new KPushButton(i18n(
"Unsubscribe"));
229 subscribeButtonLayout->addWidget(d->unSubscribe);
230 connect(d->unSubscribe,SIGNAL(clicked()),
this,SLOT(slotUnSubscribe()));
231 subscribeButtonLayout->addItem(
new QSpacerItem( 5, 5, QSizePolicy::Minimum, QSizePolicy::Expanding ) );
233 hboxLayout->addLayout(subscribeButtonLayout);
235 mainLayout->addLayout(filterBarLayout);
236 mainLayout->addLayout(hboxLayout);
240 d->filterRecursiveCollectionFilter
242 if ( !mimetypes.isEmpty() )
243 d->filterRecursiveCollectionFilter->addContentMimeTypeInclusionFilters( mimetypes );
245 d->filterRecursiveCollectionFilter->setSourceModel( d->model );
247 KDescendantsProxyModel *flatModel =
new KDescendantsProxyModel(
this );
248 flatModel->setDisplayAncestorData(
true );
249 flatModel->setAncestorSeparator( QLatin1String(
"/" ) );
250 flatModel->setSourceModel( d->filterRecursiveCollectionFilter );
252 CheckableFilterProxyModel *checkableModel =
new CheckableFilterProxyModel(
this );
253 checkableModel->setSourceModel( flatModel );
255 d->collectionView =
new QListView( mainWidget );
257 d->collectionView->setModel( checkableModel );
258 mainLayout->addWidget( d->collectionView );
261 connect( d->model, SIGNAL(loaded()), SLOT(modelLoaded()) );
262 connect(
this, SIGNAL(okClicked()), SLOT(done()) );
263 connect(
this, SIGNAL(cancelClicked()), SLOT(deleteLater()) );
274 #include "moc_subscriptiondialog_p.cpp"
void subscribe(const Collection::List &collections)
Subscribes to the given list of collections.
~SubscriptionDialog()
Destroys the subscription dialog.
void showHiddenCollection(bool showHidden)
static void widgetNeedsAkonadi(QWidget *widget)
Disable the given widget when Akonadi is not operational and show an error overlay (given enough spac...
A model to filter out collections of non-matching content types.
SubscriptionDialog(QWidget *parent=0)
Creates a new subscription dialog.
Job to manipulate the local subscription state of a set of collections.
void unsubscribe(const Collection::List &collections)
Unsubscribes from the given list of collections.