summaryrefslogtreecommitdiff
path: root/sowatchui
diff options
context:
space:
mode:
authorJavier S. Pedro <maemo@javispedro.com>2012-08-10 14:02:07 +0200
committerJavier S. Pedro <maemo@javispedro.com>2012-08-10 14:02:07 +0200
commitb9082fda48bb026fc4e6148efeba9aabf608373a (patch)
treef4f2c498adc8009d082aecc7df2458c2bcf99c15 /sowatchui
parent3ca0764c683f8c6498b80f8d8410eca96cc9a793 (diff)
downloadsowatch-b9082fda48bb026fc4e6148efeba9aabf608373a.tar.gz
sowatch-b9082fda48bb026fc4e6148efeba9aabf608373a.zip
NotificationProviders UI
Diffstat (limited to 'sowatchui')
-rw-r--r--sowatchui/main.cpp2
-rw-r--r--sowatchui/providersmodel.cc105
-rw-r--r--sowatchui/providersmodel.h44
-rw-r--r--sowatchui/qml/WatchPage.qml29
-rw-r--r--sowatchui/sowatchui.pro6
5 files changed, 169 insertions, 17 deletions
diff --git a/sowatchui/main.cpp b/sowatchui/main.cpp
index af2a0c0..5e116ac 100644
--- a/sowatchui/main.cpp
+++ b/sowatchui/main.cpp
@@ -6,6 +6,7 @@
#include "watchesmodel.h"
#include "watchscannermodel.h"
+#include "providersmodel.h"
static sowatch::Registry *registry;
static WatchesModel *watches;
@@ -24,6 +25,7 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
qmlRegisterType<sowatch::ConfigKey>();
qmlRegisterType<sowatch::GConfKey>("com.javispedro.sowatch", 1, 0, "GConfKey");
+ qmlRegisterType<ProvidersModel>("com.javispedro.sowatch", 1, 0, "ProvidersModel");
viewer->rootContext()->setContextProperty("watches", watches);
viewer->rootContext()->setContextProperty("watchScanner", watchScanner);
diff --git a/sowatchui/providersmodel.cc b/sowatchui/providersmodel.cc
new file mode 100644
index 0000000..68ce21b
--- /dev/null
+++ b/sowatchui/providersmodel.cc
@@ -0,0 +1,105 @@
+#include <QtDebug>
+
+#include "providersmodel.h"
+
+using namespace sowatch;
+
+ProvidersModel::ProvidersModel(QObject *parent) :
+ QAbstractListModel(parent),
+ _config(0)
+{
+ QHash<int, QByteArray> roles = roleNames();
+ roles[Qt::DisplayRole] = QByteArray("title");
+ roles[NameRole] = QByteArray("name");
+ roles[EnabledRole] = QByteArray("enabled");
+ setRoleNames(roles);
+}
+
+QString ProvidersModel::configKey() const
+{
+ if (_config) {
+ return _config->key();
+ } else {
+ return QString();
+ }
+}
+
+void ProvidersModel::setConfigKey(const QString &configKey)
+{
+ QString oldConfigKey = this->configKey();
+ if (_config) {
+ delete _config;
+ _config = 0;
+ }
+ if (!configKey.isEmpty()) {
+ _config = new GConfKey(configKey, this);
+ connect(_config, SIGNAL(changed()), SLOT(reload()));
+ }
+ if (this->configKey() != oldConfigKey) {
+ reload();
+ emit configKeyChanged();
+ }
+}
+
+int ProvidersModel::rowCount(const QModelIndex &parent) const
+{
+ return _all_list.count();
+}
+
+QVariant ProvidersModel::data(const QModelIndex &index, int role) const
+{
+ switch (role) {
+ case Qt::DisplayRole:
+ return QVariant::fromValue(_info_list[index.row()].name);
+ case NameRole:
+ return QVariant::fromValue(_all_list[index.row()]);
+ case EnabledRole:
+ return QVariant::fromValue(_enabled.contains(_all_list[index.row()]));
+ }
+ return QVariant();
+}
+
+bool ProvidersModel::setData(const QModelIndex &index, const QVariant &value, int role)
+{
+ switch (role) {
+ case EnabledRole:
+ setProviderEnabled(_all_list[index.row()], value.toBool());
+ return true;
+ }
+ return false;
+}
+
+void ProvidersModel::setProviderEnabled(const QString &id, bool enabled)
+{
+ if (enabled) {
+ _enabled.insert(id);
+ } else {
+ _enabled.remove(id);
+ }
+ _config->set(QVariant::fromValue(QStringList(_enabled.toList())));
+}
+
+void ProvidersModel::reload()
+{
+ Registry *registry = Registry::registry();
+ beginResetModel();
+ _all_list.clear();
+ _info_list.clear();
+ _enabled.clear();
+
+ _all_list = registry->allNotificationProviders();
+ _info_list.reserve(_all_list.size());
+ foreach (const QString& s, _all_list) {
+ NotificationPluginInterface *plugin = registry->getNotificationPlugin(s);
+ if (plugin) {
+ _info_list.append(plugin->describeProvider(s));
+ } else {
+ NotificationPluginInterface::NotificationProviderInfo info;
+ info.name = s;
+ _info_list.append(info);
+ }
+ }
+
+ _enabled = _config->value().toStringList().toSet();
+ endResetModel();
+}
diff --git a/sowatchui/providersmodel.h b/sowatchui/providersmodel.h
new file mode 100644
index 0000000..9cf6ec6
--- /dev/null
+++ b/sowatchui/providersmodel.h
@@ -0,0 +1,44 @@
+#ifndef PROVIDERSMODEL_H
+#define PROVIDERSMODEL_H
+
+#include <QtCore/QAbstractListModel>
+
+#include <sowatch.h>
+
+class ProvidersModel : public QAbstractListModel
+{
+ Q_OBJECT
+ Q_PROPERTY(QString configKey READ configKey WRITE setConfigKey NOTIFY configKeyChanged)
+
+public:
+ explicit ProvidersModel(QObject *parent = 0);
+
+ enum DataRoles {
+ NameRole = Qt::UserRole,
+ EnabledRole
+ };
+
+ QString configKey() const;
+ void setConfigKey(const QString& configKey);
+
+ int rowCount(const QModelIndex &parent) const;
+ QVariant data(const QModelIndex &index, int role) const;
+ bool setData(const QModelIndex &index, const QVariant &value, int role);
+
+public slots:
+ void setProviderEnabled(const QString& id, bool enabled);
+
+signals:
+ void configKeyChanged();
+
+private slots:
+ void reload();
+
+private:
+ sowatch::ConfigKey *_config;
+ QStringList _all_list;
+ QList<sowatch::NotificationPluginInterface::NotificationProviderInfo> _info_list;
+ QSet<QString> _enabled;
+};
+
+#endif // PROVIDERSMODEL_H
diff --git a/sowatchui/qml/WatchPage.qml b/sowatchui/qml/WatchPage.qml
index 59bb5c4..21c4543 100644
--- a/sowatchui/qml/WatchPage.qml
+++ b/sowatchui/qml/WatchPage.qml
@@ -73,38 +73,37 @@ Page {
GroupHeader {
width: parent.width
- text: "Watchlets"
+ text: "Notification sources"
visible: configQmlLoader.status === Loader.Ready
}
ListView {
- id: watchletsListView
+ id: providersListView
interactive: false
width: parent.width
height: UiConstants.ListItemHeightDefault * count
- model: ListModel {
- ListElement {
- title: "Test"
- }
+ model: ProvidersModel {
+ id: providersModel
+ configKey: watchPage.configKey + "/providers"
}
delegate: ListDelegate {
-
+ CheckBox {
+ anchors.verticalCenter: parent.verticalCenter
+ anchors.right: parent.right
+ checked: model.enabled
+ onCheckedChanged: providersModel.setProviderEnabled(model.name, checked);
+ }
}
}
- Button {
- anchors.horizontalCenter: parent.horizontalCenter
- text: qsTr("Add watchlet")
- }
-
GroupHeader {
width: parent.width
- text: "Notification sources"
+ text: "Watchlets"
visible: configQmlLoader.status === Loader.Ready
}
ListView {
- id: providersListView
+ id: watchletsListView
interactive: false
width: parent.width
height: UiConstants.ListItemHeightDefault * count
@@ -120,7 +119,7 @@ Page {
Button {
anchors.horizontalCenter: parent.horizontalCenter
- text: qsTr("Add notification source")
+ text: qsTr("Add new watchlet")
}
}
}
diff --git a/sowatchui/sowatchui.pro b/sowatchui/sowatchui.pro
index c0589fc..fa965d3 100644
--- a/sowatchui/sowatchui.pro
+++ b/sowatchui/sowatchui.pro
@@ -37,11 +37,13 @@ DEPENDPATH += $$PWD/../libsowatch
# Source files
SOURCES += main.cpp \
watchesmodel.cpp daemonproxy.cpp \
- watchscannermodel.cpp
+ watchscannermodel.cpp \
+ providersmodel.cc
HEADERS += \
watchesmodel.h daemonproxy.h \
- watchscannermodel.h
+ watchscannermodel.h \
+ providersmodel.h
OTHER_FILES += qml/main.qml \
qml/MainPage.qml \