summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleix Pol <aleixpol@kde.org>2015-09-21 16:20:33 (GMT)
committerAleix Pol <aleixpol@kde.org>2015-09-21 16:20:33 (GMT)
commitcaa3c95cd177ebc749565fffdd8a28ec66dea999 (patch)
treeb8c64eb5e445d1b1e4fc88c9bb9ba4f112051cfc
parent882f2fe88465295a23bfafad67d330e82c0880a4 (diff)
Make it possible to figure out the total updates and the ones that have been checked
-rw-r--r--libmuon/UpdateModel/UpdateItem.cpp13
-rw-r--r--libmuon/UpdateModel/UpdateItem.h2
-rw-r--r--libmuon/UpdateModel/UpdateModel.cpp15
-rw-r--r--libmuon/UpdateModel/UpdateModel.h10
4 files changed, 40 insertions, 0 deletions
diff --git a/libmuon/UpdateModel/UpdateItem.cpp b/libmuon/UpdateModel/UpdateItem.cpp
index bf4e90f..f213485 100644
--- a/libmuon/UpdateModel/UpdateItem.cpp
+++ b/libmuon/UpdateModel/UpdateItem.cpp
@@ -215,3 +215,16 @@ UpdateItem::ItemType UpdateItem::type() const
{
return m_type;
}
+
+int UpdateItem::checkedItems() const
+{
+ if (m_app)
+ return checked()!=Qt::Unchecked ? 1 : 0;
+ else {
+ int ret = 0;
+ foreach(UpdateItem* item, children()) {
+ ret += item->checkedItems();
+ }
+ return ret;
+ }
+}
diff --git a/libmuon/UpdateModel/UpdateItem.h b/libmuon/UpdateModel/UpdateItem.h
index bee3125..0f5492a 100644
--- a/libmuon/UpdateModel/UpdateItem.h
+++ b/libmuon/UpdateModel/UpdateItem.h
@@ -66,6 +66,8 @@ public:
Qt::CheckState checked() const;
ItemType type() const;
+ int checkedItems() const;
+
private:
AbstractResource *m_app;
diff --git a/libmuon/UpdateModel/UpdateModel.cpp b/libmuon/UpdateModel/UpdateModel.cpp
index f0651b5..9222ea8 100644
--- a/libmuon/UpdateModel/UpdateModel.cpp
+++ b/libmuon/UpdateModel/UpdateModel.cpp
@@ -39,6 +39,7 @@
UpdateModel::UpdateModel(QObject *parent)
: QAbstractItemModel(parent)
, m_updates(nullptr)
+ , m_updatesCount(0)
{
m_rootItem = new UpdateItem();
@@ -251,6 +252,8 @@ bool UpdateModel::setData(const QModelIndex &idx, const QVariant &value, int rol
emit dataChanged(index(0,0, idx), index(item->childCount()-1, 0, idx));
}
+ Q_EMIT toUpdateChanged();
+
return true;
}
@@ -306,6 +309,8 @@ void UpdateModel::setResources(const QList< AbstractResource* >& resources)
}
endResetModel();
+ m_updatesCount = resources.count();
+
Q_EMIT hasUpdatesChanged(!resources.isEmpty());
}
@@ -318,3 +323,13 @@ ResourcesUpdatesModel* UpdateModel::backend() const
{
return m_updates;
}
+
+int UpdateModel::totalUpdatesCount() const
+{
+ return m_updatesCount;
+}
+
+int UpdateModel::toUpdateCount() const
+{
+ return m_rootItem->checkedItems();
+}
diff --git a/libmuon/UpdateModel/UpdateModel.h b/libmuon/UpdateModel/UpdateModel.h
index 4af9cbc..da61606 100644
--- a/libmuon/UpdateModel/UpdateModel.h
+++ b/libmuon/UpdateModel/UpdateModel.h
@@ -33,6 +33,8 @@ class MUONCOMMON_EXPORT UpdateModel : public QAbstractItemModel
Q_OBJECT
Q_PROPERTY(ResourcesUpdatesModel* backend READ backend WRITE setBackend)
Q_PROPERTY(bool hasUpdates READ hasUpdates NOTIFY hasUpdatesChanged)
+ Q_PROPERTY(int toUpdateCount READ toUpdateCount NOTIFY toUpdateChanged)
+ Q_PROPERTY(int totalUpdatesCount READ totalUpdatesCount NOTIFY hasUpdatesChanged)
public:
enum Roles {
@@ -62,6 +64,12 @@ public:
bool hasUpdates() const;
+ ///all upgradeable packages
+ int totalUpdatesCount() const;
+
+ ///packages marked to upgrade
+ int toUpdateCount() const;
+
enum Columns {
NameColumn = 0,
VersionColumn,
@@ -74,6 +82,7 @@ public Q_SLOTS:
Q_SIGNALS:
void hasUpdatesChanged(bool hasUpdates);
+ void toUpdateChanged();
private:
void activityChanged();
@@ -81,6 +90,7 @@ private:
void addResource(AbstractResource* res);
UpdateItem *m_rootItem;
ResourcesUpdatesModel* m_updates;
+ int m_updatesCount;
};
#endif // UPDATEMODEL_H