summaryrefslogtreecommitdiff
path: root/sowatchui/watchesmodel.cc
diff options
context:
space:
mode:
authorJavier S. Pedro <maemo@javispedro.com>2012-08-09 04:03:20 +0200
committerJavier S. Pedro <maemo@javispedro.com>2012-08-09 04:03:20 +0200
commit406332eb6b3199d19388f359d04c9f184e6082b5 (patch)
tree0560e8dabcd715cdf1932b7ac6105df5d20025e5 /sowatchui/watchesmodel.cc
parent3aa62b0543d978c1a01c5cf05a898fd8d805c44b (diff)
downloadsowatch-406332eb6b3199d19388f359d04c9f184e6082b5.tar.gz
sowatch-406332eb6b3199d19388f359d04c9f184e6082b5.zip
watch status UI
Diffstat (limited to 'sowatchui/watchesmodel.cc')
-rw-r--r--sowatchui/watchesmodel.cc136
1 files changed, 0 insertions, 136 deletions
diff --git a/sowatchui/watchesmodel.cc b/sowatchui/watchesmodel.cc
deleted file mode 100644
index d12e7db..0000000
--- a/sowatchui/watchesmodel.cc
+++ /dev/null
@@ -1,136 +0,0 @@
-#include <QtDebug>
-
-#include "watchesmodel.h"
-
-using namespace sowatch;
-
-WatchesModel::WatchesModel(QObject *parent) :
- QAbstractListModel(parent),
- _config(new GConfKey("/apps/sowatch", this)),
- _active_watches(_config->getSubkey("active-watches", this))
-{
- QHash<int, QByteArray> roles = roleNames();
- roles[Qt::DisplayRole] = QByteArray("title");
- roles[Qt::StatusTipRole] = QByteArray("subtitle");
- roles[ObjectRole] = QByteArray("object");
- setRoleNames(roles);
-
- connect(_config, SIGNAL(changed()),
- this, SLOT(handleConfigChanged()));
- connect(_config, SIGNAL(subkeyChanged(QString)),
- this, SLOT(handleSubkeyChanged(QString)));
- qDebug() << "connects";
-
- reload();
-}
-
-WatchesModel::~WatchesModel()
-{
-}
-
-int WatchesModel::rowCount(const QModelIndex &parent) const
-{
- return _list.count();
-}
-
-QVariant WatchesModel::data(const QModelIndex &index, int role) const
-{
- qDebug() << "Asked for data" << index.row() << index.column() << role;
- ConfigKey *config = _list[index.row()];
- switch (role) {
- case Qt::DisplayRole:
- return config->value("name");
- case Qt::StatusTipRole:
- return QVariant(tr("Configured"));
- }
- return QVariant();
-}
-
-bool WatchesModel::removeRows(int row, int count, const QModelIndex &parent)
-{
-
-}
-
-void WatchesModel::addFoundWatch(const QVariantMap &info)
-{
- QStringList existing = _config->dirs();
- QString base = "watch%1";
- QString name = base.arg("");
- int num = 1;
-
- while (existing.contains(name)) {
- num++;
- name = base.arg(num);
- }
-
- ConfigKey* newkey = _config->getSubkey(name);
- foreach (const QString& key, info.keys()) {
- newkey->set(key, info[key]);
- }
-
- // Now add to active watches
- QStringList active = _active_watches->value().toStringList();
- active << name;
- _active_watches->set(active);
-}
-
-void WatchesModel::reload()
-{
- QStringList dirs = _config->dirs();
-
- beginResetModel();
- foreach (ConfigKey* conf, _list) {
- conf->deleteLater();
- }
- _list.clear();
- foreach (const QString& s, dirs) {
- _list.append(_config->getSubkey(s, this));
- }
- endResetModel();
-
- qDebug() << "Found" << _list.count() << "configured watches";
-}
-
-void WatchesModel::handleConfigChanged()
-{
- qDebug() << "Key changed";
-}
-
-void WatchesModel::handleSubkeyChanged(const QString &subkey)
-{
- QRegExp nameexp("^([^/]+)/name");
- if (nameexp.exactMatch(subkey)) {
- qDebug() << "Name key changed:" << subkey;
- QString id = nameexp.cap(1);
- int i = findRowByWatchId(id);
- if (i != -1) {
- if (_config->value(subkey).isNull()) {
- beginRemoveRows(QModelIndex(), i, i);
- _list[i]->deleteLater();
- _list.removeAt(i);
- qDebug() << "Removing" << i;
- endRemoveRows();
- } else {
- emit dataChanged(createIndex(i, 0), createIndex(i, 0));
- qDebug() << "Changing" << i;
- }
- } else {
- i = _list.size();
- qDebug() << "Inserting" << i;
- beginInsertRows(QModelIndex(), i, i);
- _list.append(_config->getSubkey(id, this));
- endInsertRows();
- }
- }
-}
-
-int WatchesModel::findRowByWatchId(const QString &id)
-{
- QString pattern(_config->key() + "/" + id);
- for (int i = 0; i < _list.size(); i++) {
- if (_list[i]->key().endsWith("/" + id)) {
- return i;
- }
- }
- return -1;
-}