• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kmail

  • sources
  • kde-4.14
  • kdepim
  • kmail
  • configuredialog
  • configureagents
configureagentlistview.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2015 Montel Laurent <montel@kde.org>
3 
4  This program is free software; you can redistribute it and/or modify it
5  under the terms of the GNU General Public License, version 2, as
6  published by the Free Software Foundation.
7 
8  This program is distributed in the hope that it will be useful, but
9  WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License along
14  with this program; if not, write to the Free Software Foundation, Inc.,
15  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #include "configureagentlistview.h"
19 #include "configureagentlistdelegate.h"
20 #include "configureagentlistmodel.h"
21 
22 #include <QDBusInterface>
23 #include <KDebug>
24 #include <QSortFilterProxyModel>
25 
26 ConfigureAgentListView::ConfigureAgentListView(QWidget *parent)
27  : QListView(parent)
28 {
29  ConfigureAgentListDelegate *configureListDelegate = new ConfigureAgentListDelegate(this, this);
30  connect(configureListDelegate, SIGNAL(requestConfiguration(QModelIndex)), this, SLOT(slotConfigureAgent(QModelIndex)));
31  connect(this, SIGNAL(clicked(QModelIndex)), this, SLOT(slotAgentClicked(QModelIndex)));
32  ConfigureAgentListModel *configureAgentListModel = new ConfigureAgentListModel(this);
33 
34  QSortFilterProxyModel* proxyModel = new QSortFilterProxyModel(this);
35  proxyModel->setSourceModel(configureAgentListModel);
36  proxyModel->setSortRole(Qt::DisplayRole);
37 
38  setModel(proxyModel);
39  setItemDelegate(configureListDelegate);
40  connect(configureAgentListModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SIGNAL(agentChanged()));
41 
42 }
43 
44 ConfigureAgentListView::~ConfigureAgentListView()
45 {
46 
47 }
48 
49 void ConfigureAgentListView::setAgentItems(const QVector<ConfigureAgentItem> &lst)
50 {
51  Q_FOREACH(const ConfigureAgentItem &agentItem, lst) {
52  model()->insertRow(0);
53  const QModelIndex index = model()->index(0, 0);
54  model()->setData(index, agentItem.agentName(), Qt::DisplayRole);
55  model()->setData(index, agentItem.checked(), Qt::CheckStateRole);
56  model()->setData(index, agentItem.description(), ConfigureAgentListModel::DescriptionRole);
57  model()->setData(index, agentItem.failed(), ConfigureAgentListModel::FailedRole);
58  model()->setData(index, agentItem.interfaceName(), ConfigureAgentListModel::InterfaceNameRole);
59  model()->setData(index, agentItem.path(), ConfigureAgentListModel::PathRole);
60  }
61  model()->sort(Qt::DisplayRole);
62 }
63 
64 void ConfigureAgentListView::slotConfigureAgent(const QModelIndex &index)
65 {
66  const QAbstractItemModel* model = index.model();
67  const QString interfaceName = model->data(index, ConfigureAgentListModel::InterfaceNameRole).toString();
68  const QString path = model->data(index, ConfigureAgentListModel::PathRole).toString();
69  if (!interfaceName.isEmpty() && !path.isEmpty()) {
70  QDBusInterface interface( QLatin1String("org.freedesktop.Akonadi.Agent.") + interfaceName, path );
71  if (interface.isValid()) {
72  interface.call(QLatin1String("showConfigureDialog"), (qlonglong)winId());
73  } else {
74  kDebug()<<" interface does not exist ";
75  }
76 
77  }
78 }
79 
80 void ConfigureAgentListView::changeAgentActiveState(const QString &interfaceName, const QString &path, bool enable)
81 {
82  if (!interfaceName.isEmpty() && !path.isEmpty()) {
83  QDBusInterface interface( QLatin1String("org.freedesktop.Akonadi.Agent.") + interfaceName, path );
84  if (interface.isValid()) {
85  interface.call(QLatin1String("setEnableAgent"), enable);
86  } else {
87  kDebug()<<interfaceName << "does not exist ";
88  }
89  }
90 }
91 
92 void ConfigureAgentListView::slotAgentClicked(const QModelIndex &index)
93 {
94  const QAbstractItemModel* model = index.model();
95  const QString description = model->data(index, ConfigureAgentListModel::DescriptionRole).toString();
96  Q_EMIT descriptionChanged(description);
97 }
98 
99 void ConfigureAgentListView::save()
100 {
101  const QAbstractItemModel *agentListModel = model();
102  const int rowCount = agentListModel->rowCount();
103  if (rowCount > 0) {
104  for (int i = 0; i < rowCount; ++i) {
105  const QModelIndex index = agentListModel->index(i, 0);
106  const QString interfaceName = agentListModel->data(index, ConfigureAgentListModel::InterfaceNameRole).toString();
107  const QString path = agentListModel->data(index, ConfigureAgentListModel::PathRole).toString();
108  const bool checked = agentListModel->data(index, Qt::CheckStateRole).toBool();
109  changeAgentActiveState(interfaceName, path, checked);
110  }
111  }
112 }
113 
114 void ConfigureAgentListView::resetToDefault()
115 {
116  QAbstractItemModel *agentListModel = model();
117  const int rowCount = agentListModel->rowCount();
118  if (rowCount > 0) {
119  for (int i = 0; i < rowCount; ++i) {
120  const QModelIndex index = agentListModel->index(i, 0);
121  agentListModel->setData(index, true, Qt::CheckStateRole);
122  }
123  }
124 }
QAbstractItemModel::insertRow
bool insertRow(int row, const QModelIndex &parent)
QModelIndex
QSortFilterProxyModel::setSortRole
void setSortRole(int role)
QWidget
QAbstractItemModel::rowCount
virtual int rowCount(const QModelIndex &parent) const =0
QListView::dataChanged
virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
QAbstractItemModel::index
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const =0
QSortFilterProxyModel::setSourceModel
virtual void setSourceModel(QAbstractItemModel *sourceModel)
QAbstractItemView::setModel
virtual void setModel(QAbstractItemModel *model)
ConfigureAgentItem::agentName
QString agentName() const
Definition: configureagentitem.cpp:33
ConfigureAgentListView::~ConfigureAgentListView
~ConfigureAgentListView()
Definition: configureagentlistview.cpp:44
ConfigureAgentItem::description
QString description() const
Definition: configureagentitem.cpp:43
ConfigureAgentListView::agentChanged
void agentChanged()
QAbstractItemModel::sort
virtual void sort(int column, Qt::SortOrder order)
QListView
ConfigureAgentListView::setAgentItems
void setAgentItems(const QVector< ConfigureAgentItem > &lst)
Definition: configureagentlistview.cpp:49
ConfigureAgentListModel::InterfaceNameRole
Definition: configureagentlistmodel.h:36
ConfigureAgentListModel::PathRole
Definition: configureagentlistmodel.h:35
ConfigureAgentItem
Definition: configureagentitem.h:23
ConfigureAgentListView::resetToDefault
void resetToDefault()
Definition: configureagentlistview.cpp:114
ConfigureAgentListModel::FailedRole
Definition: configureagentlistmodel.h:37
QString::isEmpty
bool isEmpty() const
QAbstractItemView::setItemDelegate
void setItemDelegate(QAbstractItemDelegate *delegate)
ConfigureAgentListModel::DescriptionRole
Definition: configureagentlistmodel.h:34
ConfigureAgentListView::descriptionChanged
void descriptionChanged(const QString &desc)
configureagentlistmodel.h
QAbstractItemModel::data
virtual QVariant data(const QModelIndex &index, int role) const =0
QWidget::winId
WId winId() const
QString
configureagentlistview.h
QDBusInterface
QSortFilterProxyModel
configureagentlistdelegate.h
ConfigureAgentItem::interfaceName
QString interfaceName() const
Definition: configureagentitem.cpp:63
ConfigureAgentListView::save
void save()
Definition: configureagentlistview.cpp:99
QModelIndex::model
const QAbstractItemModel * model() const
QVector< ConfigureAgentItem >
QLatin1String
ConfigureAgentItem::checked
bool checked() const
Definition: configureagentitem.cpp:73
ConfigureAgentListModel
Definition: configureagentlistmodel.h:27
ConfigureAgentItem::path
QString path() const
Definition: configureagentitem.cpp:53
QVariant::toBool
bool toBool() const
QAbstractItemModel
QAbstractItemModel::setData
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
QAbstractItemView::clicked
void clicked(const QModelIndex &index)
QAbstractItemView::model
QAbstractItemModel * model() const
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QVariant::toString
QString toString() const
ConfigureAgentListDelegate
Definition: configureagentlistdelegate.h:25
ConfigureAgentItem::failed
bool failed() const
Definition: configureagentitem.cpp:83
ConfigureAgentListView::ConfigureAgentListView
ConfigureAgentListView(QWidget *parent=0)
Definition: configureagentlistview.cpp:26
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:34:32 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kmail

Skip menu "kmail"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



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