summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleix Pol <aleixpol@kde.org>2015-09-04 16:29:51 (GMT)
committerAleix Pol <aleixpol@kde.org>2015-09-09 22:15:19 (GMT)
commit3f455d7183acba9c28f6ec0dc4d6a4e72a0e01ae (patch)
tree29d714691d0c497e1b5138ada219999236092c30
parent7c5f0737624f136256721bd9febe0473664d6224 (diff)
Move the UpdateModel into libmuon
This way it can be re-used by Discover as well.
-rw-r--r--libmuon/CMakeLists.txt2
-rw-r--r--libmuon/UpdateModel/UpdateItem.cpp (renamed from updater/UpdateModel/UpdateItem.cpp)1
-rw-r--r--libmuon/UpdateModel/UpdateItem.h (renamed from updater/UpdateModel/UpdateItem.h)3
-rw-r--r--libmuon/UpdateModel/UpdateModel.cpp (renamed from updater/UpdateModel/UpdateModel.cpp)42
-rw-r--r--libmuon/UpdateModel/UpdateModel.h (renamed from updater/UpdateModel/UpdateModel.h)18
-rw-r--r--updater/CMakeLists.txt4
-rw-r--r--updater/UpdateDelegate.cpp (renamed from updater/UpdateModel/UpdateDelegate.cpp)27
-rw-r--r--updater/UpdateDelegate.h (renamed from updater/UpdateModel/UpdateDelegate.h)2
-rw-r--r--updater/UpdaterWidget.cpp10
9 files changed, 63 insertions, 46 deletions
diff --git a/libmuon/CMakeLists.txt b/libmuon/CMakeLists.txt
index 3c8c15e..dcfb533 100644
--- a/libmuon/CMakeLists.txt
+++ b/libmuon/CMakeLists.txt
@@ -17,6 +17,8 @@ set(muon_LIB_SRCS
Transaction/Transaction.cpp
Transaction/TransactionListener.cpp
Transaction/TransactionModel.cpp
+ UpdateModel/UpdateItem.cpp
+ UpdateModel/UpdateModel.cpp
resources/ResourcesModel.cpp
resources/ResourcesProxyModel.cpp
resources/PackageState.cpp
diff --git a/updater/UpdateModel/UpdateItem.cpp b/libmuon/UpdateModel/UpdateItem.cpp
index bc87243..bf4e90f 100644
--- a/updater/UpdateModel/UpdateItem.cpp
+++ b/libmuon/UpdateModel/UpdateItem.cpp
@@ -25,6 +25,7 @@
#include <QtCore/QStringBuilder>
#include <KLocalizedString>
+#include <QDebug>
UpdateItem::UpdateItem()
: m_app(nullptr)
diff --git a/updater/UpdateModel/UpdateItem.h b/libmuon/UpdateModel/UpdateItem.h
index 7faa703..bee3125 100644
--- a/updater/UpdateModel/UpdateItem.h
+++ b/libmuon/UpdateModel/UpdateItem.h
@@ -24,11 +24,12 @@
// Qt includes
#include <QtCore/QList>
#include <QtCore/QString>
+#include "libMuonCommon_export.h"
#include <QIcon>
class AbstractResource;
-class UpdateItem
+class MUONCOMMON_EXPORT UpdateItem
{
public:
enum class ItemType : quint8 {
diff --git a/updater/UpdateModel/UpdateModel.cpp b/libmuon/UpdateModel/UpdateModel.cpp
index d1e291f..1fd82e8 100644
--- a/updater/UpdateModel/UpdateModel.cpp
+++ b/libmuon/UpdateModel/UpdateModel.cpp
@@ -23,6 +23,7 @@
// Qt includes
#include <QFont>
#include <QApplication>
+#include <QDebug>
// KDE includes
#include <KIconLoader>
@@ -33,15 +34,16 @@
#include "UpdateItem.h"
#include <resources/AbstractResource.h>
#include <resources/ResourcesUpdatesModel.h>
-
-#define ICON_SIZE KIconLoader::SizeSmallMedium
-
+#include <resources/ResourcesModel.h>
UpdateModel::UpdateModel(QObject *parent)
: QAbstractItemModel(parent)
, m_updates(nullptr)
{
m_rootItem = new UpdateItem();
+
+ connect(ResourcesModel::global(), &ResourcesModel::fetchingChanged, this, &UpdateModel::activityChanged);
+ connect(ResourcesModel::global(), &ResourcesModel::updatesCountChanged, this, &UpdateModel::activityChanged);
}
UpdateModel::~UpdateModel()
@@ -49,6 +51,34 @@ UpdateModel::~UpdateModel()
delete m_rootItem;
}
+QHash<int,QByteArray> UpdateModel::roleNames() const
+{
+ return QAbstractItemModel::roleNames().unite({ { Qt::CheckStateRole, "checked"} } );
+}
+
+void UpdateModel::setBackend(ResourcesUpdatesModel* updates)
+{
+ if (m_updates) {
+ disconnect(m_updates, nullptr, this, nullptr);
+ }
+
+ m_updates = updates;
+
+ connect(m_updates, &ResourcesUpdatesModel::progressingChanged, this, &UpdateModel::activityChanged);
+
+ activityChanged();
+}
+
+void UpdateModel::activityChanged()
+{
+ if(ResourcesModel::global()->isFetching()) {
+ setResources(QList<AbstractResource*>());
+ } else if(!m_updates->isProgressing() && m_updates->hasUpdates()) {
+ m_updates->prepare();
+ setResources(m_updates->toUpdate());
+ }
+}
+
QVariant UpdateModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid()) {
@@ -71,7 +101,7 @@ QVariant UpdateModel::data(const QModelIndex &index, int role) const
break;
case Qt::DecorationRole:
if (column == NameColumn) {
- return item->icon().pixmap(ICON_SIZE, ICON_SIZE);
+ return item->icon();
}
break;
case Qt::FontRole: {
@@ -269,7 +299,7 @@ void UpdateModel::setResources(const QList< AbstractResource* >& resources)
endResetModel();
}
-void UpdateModel::setBackend(ResourcesUpdatesModel* updates)
+ResourcesUpdatesModel* UpdateModel::backend() const
{
- m_updates = updates;
+ return m_updates;
}
diff --git a/updater/UpdateModel/UpdateModel.h b/libmuon/UpdateModel/UpdateModel.h
index 9828887..434eba9 100644
--- a/updater/UpdateModel/UpdateModel.h
+++ b/libmuon/UpdateModel/UpdateModel.h
@@ -22,18 +22,16 @@
#define UPDATEMODEL_H
#include <QtCore/QAbstractItemModel>
+#include "libMuonCommon_export.h"
class ResourcesUpdatesModel;
class AbstractResource;
class UpdateItem;
-namespace QApt {
- class Package;
-}
-
-class UpdateModel : public QAbstractItemModel
+class MUONCOMMON_EXPORT UpdateModel : public QAbstractItemModel
{
Q_OBJECT
+ Q_PROPERTY(ResourcesUpdatesModel* backend READ backend WRITE setBackend)
public:
explicit UpdateModel(QObject *parent = nullptr);
~UpdateModel();
@@ -53,20 +51,24 @@ public:
UpdateItem *itemFromIndex(const QModelIndex &index) const;
void checkResources(const QList< AbstractResource* >& resource, bool checked);
+ QHash<int,QByteArray> roleNames() const override;
enum Columns {
NameColumn = 0,
VersionColumn,
SizeColumn
};
+ ResourcesUpdatesModel* backend() const;
+
+public Q_SLOTS:
+ void setBackend(ResourcesUpdatesModel* updates);
private:
+ void activityChanged();
+
void addResource(AbstractResource* res);
UpdateItem *m_rootItem;
ResourcesUpdatesModel* m_updates;
-
-public Q_SLOTS:
- void setBackend(ResourcesUpdatesModel* updates);
};
#endif // UPDATEMODEL_H
diff --git a/updater/CMakeLists.txt b/updater/CMakeLists.txt
index cff1abd..1a361a7 100644
--- a/updater/CMakeLists.txt
+++ b/updater/CMakeLists.txt
@@ -7,9 +7,7 @@ set(muon_updater_SRCS
ProgressWidget.cpp
UpdaterWidget.cpp
KActionMessageWidget.cpp
- UpdateModel/UpdateItem.cpp
- UpdateModel/UpdateModel.cpp
- UpdateModel/UpdateDelegate.cpp)
+ UpdateDelegate.cpp)
ki18n_wrap_ui(muon_updater_SRCS ProgressWidget.ui
UpdaterCentralWidget.ui
diff --git a/updater/UpdateModel/UpdateDelegate.cpp b/updater/UpdateDelegate.cpp
index dbe1960..5d4db41 100644
--- a/updater/UpdateModel/UpdateDelegate.cpp
+++ b/updater/UpdateDelegate.cpp
@@ -36,27 +36,6 @@ UpdateDelegate::UpdateDelegate(QObject *parent)
{
}
-QSize UpdateDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
-{
- Q_UNUSED(index);
-
- QSize size;
- QFontMetrics metric = QFontMetrics(option.font);
-
- size.setWidth(metric.width(index.data(Qt::DisplayRole).toString()));
- size.setHeight(ICON_SIZE + SPACING);
-
- if (index.column() == 0) {
- const QStyle *style = QApplication::style();
- QRect rect = style->subElementRect(QStyle::SE_CheckBoxIndicator, &option);
- // Adds the icon size AND the checkbox size
- // [ x ] (icon) Text
- size.rwidth() += 4 * SPACING + ICON_SIZE + rect.width();
- }
-
- return size;
-}
-
bool UpdateDelegate::editorEvent(QEvent *event,
QAbstractItemModel *model,
const QStyleOptionViewItem &option,
@@ -104,3 +83,9 @@ bool UpdateDelegate::editorEvent(QEvent *event,
}
return false;
}
+
+void UpdateDelegate::initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const
+{
+ QStyledItemDelegate::initStyleOption(option, index);
+ option->decorationSize = QSize(ICON_SIZE, ICON_SIZE);
+}
diff --git a/updater/UpdateModel/UpdateDelegate.h b/updater/UpdateDelegate.h
index cc02246..14357b2 100644
--- a/updater/UpdateModel/UpdateDelegate.h
+++ b/updater/UpdateDelegate.h
@@ -30,7 +30,7 @@ public:
explicit UpdateDelegate(QObject *parent = nullptr);
protected:
- QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
+ void initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const override;
bool editorEvent(QEvent *event,
QAbstractItemModel *model,
const QStyleOptionViewItem &option,
diff --git a/updater/UpdaterWidget.cpp b/updater/UpdaterWidget.cpp
index e4a2cdf..2e716c0 100644
--- a/updater/UpdaterWidget.cpp
+++ b/updater/UpdaterWidget.cpp
@@ -48,11 +48,11 @@
#include <resources/AbstractBackendUpdater.h>
#include <resources/ResourcesUpdatesModel.h>
#include <resources/ResourcesModel.h>
+#include <UpdateModel/UpdateModel.h>
+#include <UpdateModel/UpdateItem.h>
// Own includes
-#include "UpdateModel/UpdateModel.h"
-#include "UpdateModel/UpdateItem.h"
-#include "UpdateModel/UpdateDelegate.h"
+#include "UpdateDelegate.h"
#include "ChangelogWidget.h"
#include "ui_UpdaterWidgetNoUpdates.h"
@@ -61,6 +61,7 @@ UpdaterWidget::UpdaterWidget(ResourcesUpdatesModel* updates, QWidget *parent) :
{
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding);
m_updateModel = new UpdateModel(this);
+ m_updateModel->setBackend(updates);
// First page (update view)
QWidget *page1 = new QWidget(this);
@@ -139,7 +140,6 @@ UpdaterWidget::~UpdaterWidget()
void UpdaterWidget::activityChanged()
{
if(ResourcesModel::global()->isFetching()) {
- m_updateModel->setResources(QList<AbstractResource*>());
m_busyWidget->start();
setEnabled(false);
setCurrentIndex(0);
@@ -163,8 +163,6 @@ void UpdaterWidget::populateUpdateModel()
if (!m_updatesBackends->hasUpdates()) {
return;
}
- m_updatesBackends->prepare();
- m_updateModel->setResources(m_updatesBackends->toUpdate());
m_updateView->expand(m_updateModel->index(0,0)); // Expand apps category
m_updateView->resizeColumnToContents(0);