From 80c58c124caf17f670d8efc120f5ae4bfd9aa09f Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Tue, 14 May 2013 01:13:41 +0200 Subject: added liveview watchlet menu (API break) --- libsowatch/watchletplugininterface.h | 9 +++++---- libsowatch/watchletsmodel.cpp | 15 ++++++++++++++- libsowatch/watchletsmodel.h | 11 +++++++++-- libsowatch/watchserver.cpp | 1 + 4 files changed, 29 insertions(+), 7 deletions(-) (limited to 'libsowatch') diff --git a/libsowatch/watchletplugininterface.h b/libsowatch/watchletplugininterface.h index ed90467..4c135b3 100644 --- a/libsowatch/watchletplugininterface.h +++ b/libsowatch/watchletplugininterface.h @@ -22,17 +22,18 @@ public: struct WatchletInfo { QString name; QUrl icon; - bool hidden; + QUrl phoneIcon; + bool visible; QUrl configQmlUrl; - inline WatchletInfo() : - hidden(false) + inline WatchletInfo() : visible(false) { + } }; virtual QStringList watchlets() = 0; - virtual WatchletInfo describeWatchlet(const QString& id) = 0; + virtual WatchletInfo describeWatchlet(const QString& id, const QString& watchModel) = 0; virtual Watchlet* getWatchlet(const QString& id, ConfigKey *settings, Watch *watch) = 0; }; diff --git a/libsowatch/watchletsmodel.cpp b/libsowatch/watchletsmodel.cpp index 9e06928..5989872 100644 --- a/libsowatch/watchletsmodel.cpp +++ b/libsowatch/watchletsmodel.cpp @@ -11,10 +11,21 @@ WatchletsModel::WatchletsModel(QObject *parent) : { QHash roles = roleNames(); roles[TitleRole] = QByteArray("title"); + roles[IconRole] = QByteArray("icon"); roles[ObjectRole] = QByteArray("object"); setRoleNames(roles); } +QString WatchletsModel::watchModel() const +{ + return _watchModel; +} + +void WatchletsModel::setWatchModel(const QString &s) +{ + _watchModel = s; +} + int WatchletsModel::rowCount(const QModelIndex &parent) const { return parent.isValid() ? 0 : _list.count(); @@ -35,6 +46,8 @@ QVariant WatchletsModel::data(const QModelIndex &index, int role) const switch (role) { case Qt::DisplayRole: return QVariant::fromValue(info.name); + case IconRole: + return QVariant::fromValue(info.icon); case ObjectRole: return QVariant::fromValue(const_cast(watchlet)); } @@ -109,7 +122,7 @@ WatchletsModel::WatchletInfo WatchletsModel::getInfoForWatchlet(const Watchlet * QString id = w->id(); WatchletPluginInterface *plugin = Registry::registry()->getWatchletPlugin(id); if (plugin) { - return plugin->describeWatchlet(id); + return plugin->describeWatchlet(id, _watchModel); } else { return WatchletInfo(); } diff --git a/libsowatch/watchletsmodel.h b/libsowatch/watchletsmodel.h index cdb6be4..3bbabf9 100644 --- a/libsowatch/watchletsmodel.h +++ b/libsowatch/watchletsmodel.h @@ -12,15 +12,20 @@ namespace sowatch class WatchletsModel : public QAbstractListModel { Q_OBJECT + Q_PROPERTY(QString watchModel READ watchModel WRITE setWatchModel NOTIFY watchModelChanged) public: explicit WatchletsModel(QObject *parent = 0); enum DataRoles { ObjectRole = Qt::UserRole, - TitleRole = Qt::DisplayRole + TitleRole = Qt::DisplayRole, + IconRole = Qt::DecorationRole }; + QString watchModel() const; + void setWatchModel(const QString& s); + int rowCount(const QModelIndex &parent) const; QVariant data(const QModelIndex &index, int role) const; @@ -35,14 +40,16 @@ public: void remove(int position); signals: + void watchModelChanged(); void modelChanged(); protected: typedef WatchletPluginInterface::WatchletInfo WatchletInfo; - static WatchletInfo getInfoForWatchlet(const Watchlet *w); + WatchletInfo getInfoForWatchlet(const Watchlet *w); private: + QString _watchModel; QList _list; QList _info; diff --git a/libsowatch/watchserver.cpp b/libsowatch/watchserver.cpp index eaea040..da93730 100644 --- a/libsowatch/watchserver.cpp +++ b/libsowatch/watchserver.cpp @@ -30,6 +30,7 @@ WatchServer::WatchServer(Watch* watch, QObject* parent) : _syncTimeTimer->setSingleShot(true); _syncTimeTimer->setInterval(24 * 3600 * 1000); // Once a day + _watchlets->setWatchModel(_watch->model()); _watch->setWatchletsModel(_watchlets); } -- cgit v1.2.3