summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkh1 <karsten.heimrich@nokia.com>2012-04-23 17:27:46 +0200
committerKarsten Heimrich <karsten.heimrich@nokia.com>2012-04-25 14:23:56 +0200
commit3eb3be2e042a6c93007f8bf4a1b6079b4961d919 (patch)
tree98d9b55d91bdfe65718e5dc9506e9a75e9a0df72
parentc6821e8dc0b1c4724f158d4714b7b25e60bd6638 (diff)
Move the models inside core engine.
Improves the situation for qml based installer. Change-Id: Ia7198f0720a1268c7918517228c13255cccce4ea Reviewed-by: Niels Weber <niels.2.weber@nokia.com> Reviewed-by: Tim Jenssen <tim.jenssen@nokia.com>
-rw-r--r--src/libs/installer/componentmodel.cpp76
-rw-r--r--src/libs/installer/componentmodel.h7
-rw-r--r--src/libs/installer/packagemanagercore.cpp46
-rw-r--r--src/libs/installer/packagemanagercore.h7
-rw-r--r--src/libs/installer/packagemanagercore_p.cpp8
-rw-r--r--src/libs/installer/packagemanagercore_p.h14
-rw-r--r--src/libs/installer/packagemanagergui.cpp55
7 files changed, 124 insertions, 89 deletions
diff --git a/src/libs/installer/componentmodel.cpp b/src/libs/installer/componentmodel.cpp
index ec61ee84e..42e381c0d 100644
--- a/src/libs/installer/componentmodel.cpp
+++ b/src/libs/installer/componentmodel.cpp
@@ -229,44 +229,6 @@ Qt::ItemFlags ComponentModel::flags(const QModelIndex &index) const
}
/*!
- Set's the passed \a rootComponents to be list of currently shown components. The model is repopulated and
- the individual component checked state is used to show the check mark in front of the visual component
- representation. The modelAboutToBeReset() and modelReset() signals are emitted.
-*/
-void ComponentModel::setRootComponents(QList<Component*> rootComponents)
-{
- beginResetModel();
-
- m_indexByNameCache.clear();
- m_rootComponentList.clear();
- m_initialCheckedSet.clear();
- m_currentCheckedSet.clear();
-
- m_rootIndex = 0;
- m_rootComponentList = rootComponents;
-
- endResetModel();
-}
-
-/*!
- Appends the passed \a rootComponents to the currently shown list of components. The model is repopulated
- and the individual component checked state is used to show the check mark in front of the visual component
- representation. Already changed check states on the previous model are preserved. The modelAboutToBeReset()
- and modelReset() signals are emitted.
-*/
-void ComponentModel::appendRootComponents(QList<Component*> rootComponents)
-{
- beginResetModel();
-
- m_indexByNameCache.clear();
-
- m_rootIndex = m_rootComponentList.count() - 1;
- m_rootComponentList += rootComponents;
-
- endResetModel();
-}
-
-/*!
Returns a pointer to the PackageManagerCore this model belongs to.
*/
PackageManagerCore *ComponentModel::packageManagerCore() const
@@ -363,6 +325,44 @@ void ComponentModel::selectDefault()
emit defaultCheckStateChanged(m_initialCheckedSet != m_currentCheckedSet);
}
+/*!
+ Set's the passed \a rootComponents to be list of currently shown components. The model is repopulated and
+ the individual component checked state is used to show the check mark in front of the visual component
+ representation. The modelAboutToBeReset() and modelReset() signals are emitted.
+*/
+void ComponentModel::setRootComponents(QList<QInstaller::Component*> rootComponents)
+{
+ beginResetModel();
+
+ m_indexByNameCache.clear();
+ m_rootComponentList.clear();
+ m_initialCheckedSet.clear();
+ m_currentCheckedSet.clear();
+
+ m_rootIndex = 0;
+ m_rootComponentList = rootComponents;
+
+ endResetModel();
+}
+
+/*!
+ Appends the passed \a rootComponents to the currently shown list of components. The model is repopulated
+ and the individual component checked state is used to show the check mark in front of the visual component
+ representation. Already changed check states on the previous model are preserved. The modelAboutToBeReset()
+ and modelReset() signals are emitted.
+*/
+void ComponentModel::appendRootComponents(QList<QInstaller::Component*> rootComponents)
+{
+ beginResetModel();
+
+ m_indexByNameCache.clear();
+
+ m_rootIndex = m_rootComponentList.count() - 1;
+ m_rootComponentList += rootComponents;
+
+ endResetModel();
+}
+
// -- private slots
void ComponentModel::slotModelReset()
diff --git a/src/libs/installer/componentmodel.h b/src/libs/installer/componentmodel.h
index 6dd6b634a..d51c25edf 100644
--- a/src/libs/installer/componentmodel.h
+++ b/src/libs/installer/componentmodel.h
@@ -67,10 +67,6 @@ public:
int role = Qt::EditRole);
Qt::ItemFlags flags(const QModelIndex &index) const;
-
- void setRootComponents(QList<Component*> rootComponents);
- void appendRootComponents(QList<Component*> rootComponents);
-
PackageManagerCore *packageManagerCore() const;
bool defaultCheckState() const;
@@ -85,6 +81,9 @@ public Q_SLOTS:
void deselectAll();
void selectDefault();
+ void setRootComponents(QList<QInstaller::Component*> rootComponents);
+ void appendRootComponents(QList<QInstaller::Component*> rootComponents);
+
Q_SIGNALS:
void defaultCheckStateChanged(bool changed);
void checkStateChanged(const QModelIndex &index);
diff --git a/src/libs/installer/packagemanagercore.cpp b/src/libs/installer/packagemanagercore.cpp
index c81987f39..52713f50f 100644
--- a/src/libs/installer/packagemanagercore.cpp
+++ b/src/libs/installer/packagemanagercore.cpp
@@ -34,6 +34,7 @@
#include "adminauthorization.h"
#include "binaryformat.h"
#include "component.h"
+#include "componentmodel.h"
#include "downloadarchivesjob.h"
#include "errors.h"
#include "fsengineclient.h"
@@ -48,6 +49,7 @@
#include "settings.h"
#include "utils.h"
+#include <QtCore/QMutex>
#include <QtCore/QSettings>
#include <QtCore/QTemporaryFile>
@@ -66,6 +68,7 @@
using namespace QInstaller;
+static QMutex sModelMutex;
static QFont sVirtualComponentsFont;
static bool sNoForceInstallation = false;
@@ -614,6 +617,7 @@ bool PackageManagerCore::fetchLocalPackagesTree()
emit finishAllComponentsReset();
d->setStatus(Success);
+ emit setRootComponents(d->m_rootComponents);
return true;
}
@@ -1029,6 +1033,26 @@ QList<Component*> PackageManagerCore::dependencies(const Component *component, Q
return result;
}
+ComponentModel *PackageManagerCore::defaultComponentModel() const
+{
+ QMutexLocker _(&sModelMutex);
+ if (!d->m_defaultModel) {
+ d->m_defaultModel = componentModel(const_cast<PackageManagerCore*> (this),
+ QLatin1String("AllComponentsModel"));
+ }
+ return d->m_defaultModel;
+}
+
+ComponentModel *PackageManagerCore::updaterComponentModel() const
+{
+ QMutexLocker _(&sModelMutex);
+ if (!d->m_updaterModel) {
+ d->m_updaterModel = componentModel(const_cast<PackageManagerCore*> (this),
+ QLatin1String("UpdaterComponentsModel"));
+ }
+ return d->m_updaterModel;
+}
+
Settings &PackageManagerCore::settings() const
{
return d->m_settings;
@@ -1669,6 +1693,7 @@ bool PackageManagerCore::fetchAllPackages(const PackagesList &remotes, const Loc
return false;
emit finishAllComponentsReset();
+ emit setRootComponents(d->m_rootComponents);
return true;
}
@@ -1813,6 +1838,7 @@ bool PackageManagerCore::fetchUpdaterPackages(const PackagesList &remotes, const
}
emit finishUpdaterComponentsReset();
+ emit setRootComponents(d->m_updaterComponents);
return true;
}
@@ -1874,3 +1900,23 @@ void PackageManagerCore::setCreateLocalRepositoryFromBinary(bool create)
return;
d->m_createLocalRepositoryFromBinary = create;
}
+
+ComponentModel *PackageManagerCore::componentModel(PackageManagerCore *core, const QString &objectName) const
+{
+ ComponentModel *model = new ComponentModel(4, core);
+
+ model->setObjectName(objectName);
+ model->setHeaderData(ComponentModelHelper::NameColumn, Qt::Horizontal,
+ ComponentModel::tr("Component Name"));
+ model->setHeaderData(ComponentModelHelper::InstalledVersionColumn, Qt::Horizontal,
+ ComponentModel::tr("Installed Version"));
+ model->setHeaderData(ComponentModelHelper::NewVersionColumn, Qt::Horizontal,
+ ComponentModel::tr("New Version"));
+ model->setHeaderData(ComponentModelHelper::UncompressedSizeColumn, Qt::Horizontal,
+ ComponentModel::tr("Size"));
+ connect(this, SIGNAL(setRootComponents(QList<QInstaller::Component*>)), model,
+ SLOT(setRootComponents(QList<QInstaller::Component*>)), Qt::QueuedConnection);
+ connect(model, SIGNAL(defaultCheckStateChanged(bool)), this, SLOT(componentsToInstallNeedsRecalculation()));
+
+ return model;
+}
diff --git a/src/libs/installer/packagemanagercore.h b/src/libs/installer/packagemanagercore.h
index 6714f3170..a8fa65eab 100644
--- a/src/libs/installer/packagemanagercore.h
+++ b/src/libs/installer/packagemanagercore.h
@@ -47,6 +47,7 @@ namespace KDUpdater {
namespace QInstaller {
class Component;
+class ComponentModel;
class PackageManagerCorePrivate;
class Settings;
@@ -183,6 +184,9 @@ public:
QList<Component*> dependees(const Component *component) const;
QList<Component*> dependencies(const Component *component, QStringList &missingComponents) const;
+ ComponentModel *defaultComponentModel() const;
+ ComponentModel *updaterComponentModel() const;
+
// convenience
Q_INVOKABLE bool isInstaller() const;
Q_INVOKABLE bool isOfflineOnly() const;
@@ -248,6 +252,7 @@ Q_SIGNALS:
void finishButtonClicked();
void metaJobInfoMessage(const QString &message);
+ void setRootComponents(const QList<QInstaller::Component*> &components);
void startAllComponentsReset();
void finishAllComponentsReset();
@@ -292,6 +297,8 @@ private:
void updateDisplayVersions(const QString &displayKey);
QString findDisplayVersion(const QString &componentName, const QHash<QString, QInstaller::Component*> &components,
const QString& versionKey, QHash<QString, bool> &visited);
+ ComponentModel *componentModel(PackageManagerCore *core, const QString &objectName) const;
+
private:
PackageManagerCorePrivate *const d;
friend class PackageManagerCorePrivate;
diff --git a/src/libs/installer/packagemanagercore_p.cpp b/src/libs/installer/packagemanagercore_p.cpp
index da0e4adac..72a29e1bc 100644
--- a/src/libs/installer/packagemanagercore_p.cpp
+++ b/src/libs/installer/packagemanagercore_p.cpp
@@ -34,6 +34,7 @@
#include "adminauthorization.h"
#include "binaryformat.h"
#include "component.h"
+#include "componentmodel.h"
#include "errors.h"
#include "fileutils.h"
#include "fsengineclient.h"
@@ -168,6 +169,8 @@ PackageManagerCorePrivate::PackageManagerCorePrivate(PackageManagerCore *core)
, m_componentsToInstallCalculated(false)
, m_proxyFactory(0)
, m_createLocalRepositoryFromBinary(false)
+ , m_defaultModel(0)
+ , m_updaterModel(0)
{
}
@@ -191,6 +194,8 @@ PackageManagerCorePrivate::PackageManagerCorePrivate(PackageManagerCore *core, q
, m_componentsToInstallCalculated(false)
, m_proxyFactory(0)
, m_createLocalRepositoryFromBinary(false)
+ , m_defaultModel(0)
+ , m_updaterModel(0)
{
connect(this, SIGNAL(installationStarted()), m_core, SIGNAL(installationStarted()));
connect(this, SIGNAL(installationFinished()), m_core, SIGNAL(installationFinished()));
@@ -214,6 +219,9 @@ PackageManagerCorePrivate::~PackageManagerCorePrivate()
delete m_updateFinder;
delete m_proxyFactory;
+
+ delete m_defaultModel;
+ delete m_updaterModel;
}
/*!
diff --git a/src/libs/installer/packagemanagercore_p.h b/src/libs/installer/packagemanagercore_p.h
index 1a585cf96..b8ec335a0 100644
--- a/src/libs/installer/packagemanagercore_p.h
+++ b/src/libs/installer/packagemanagercore_p.h
@@ -58,6 +58,7 @@ namespace QInstaller {
struct BinaryLayout;
class Component;
+class ComponentModel;
class TempDirDeleter;
class PackageManagerCorePrivate : public QObject
@@ -182,12 +183,12 @@ public:
QHash<QString, bool> m_sharedFlags;
QString m_installerBaseBinaryUnreplaced;
- QList<Component*> m_rootComponents;
- QList<Component*> m_rootDependencyReplacements;
+ QList<QInstaller::Component*> m_rootComponents;
+ QList<QInstaller::Component*> m_rootDependencyReplacements;
- QList<Component*> m_updaterComponents;
- QList<Component*> m_updaterComponentsDeps;
- QList<Component*> m_updaterDependencyReplacements;
+ QList<QInstaller::Component*> m_updaterComponents;
+ QList<QInstaller::Component*> m_updaterComponentsDeps;
+ QList<QInstaller::Component*> m_updaterDependencyReplacements;
OperationList m_ownedOperations;
OperationList m_performedOperationsOld;
@@ -248,6 +249,9 @@ private:
FileDownloaderProxyFactory *m_proxyFactory;
bool m_createLocalRepositoryFromBinary;
+ ComponentModel *m_defaultModel;
+ ComponentModel *m_updaterModel;
+
private:
// remove once we deprecate isSelected, setSelected etc...
void resetComponentsToUserCheckedState();
diff --git a/src/libs/installer/packagemanagergui.cpp b/src/libs/installer/packagemanagergui.cpp
index 367e16363..ad71596bd 100644
--- a/src/libs/installer/packagemanagergui.cpp
+++ b/src/libs/installer/packagemanagergui.cpp
@@ -954,27 +954,14 @@ public:
: q(qq)
, m_core(core)
, m_treeView(new QTreeView(q))
- , m_allModel(new ComponentModel(4, m_core))
- , m_updaterModel(new ComponentModel(4, m_core))
+ , m_allModel(m_core->defaultComponentModel())
+ , m_updaterModel(m_core->updaterComponentModel())
+ , m_currentModel(m_allModel)
{
m_treeView->setObjectName(QLatin1String("ComponentsTreeView"));
- m_allModel->setObjectName(QLatin1String("AllComponentsModel"));
- m_updaterModel->setObjectName(QLatin1String("UpdaterComponentsModel"));
-
- int i = 0;
- m_currentModel = m_allModel;
- ComponentModel *list[] = { m_allModel, m_updaterModel, 0 };
- while (ComponentModel *model = list[i++]) {
- connect(model, SIGNAL(defaultCheckStateChanged(bool)), q, SLOT(setModified(bool)));
- connect(model, SIGNAL(defaultCheckStateChanged(bool)), m_core,
- SLOT(componentsToInstallNeedsRecalculation()));
-
- model->setHeaderData(ComponentModelHelper::NameColumn, Qt::Horizontal, ComponentSelectionPage::tr("Component Name"));
- model->setHeaderData(ComponentModelHelper::InstalledVersionColumn, Qt::Horizontal,
- ComponentSelectionPage::tr("Installed Version"));
- model->setHeaderData(ComponentModelHelper::NewVersionColumn, Qt::Horizontal, ComponentSelectionPage::tr("New Version"));
- model->setHeaderData(ComponentModelHelper::UncompressedSizeColumn, Qt::Horizontal, ComponentSelectionPage::tr("Size"));
- }
+
+ connect(m_allModel, SIGNAL(defaultCheckStateChanged(bool)), q, SLOT(setModified(bool)));
+ connect(m_updaterModel, SIGNAL(defaultCheckStateChanged(bool)), q, SLOT(setModified(bool)));
QHBoxLayout *hlayout = new QHBoxLayout;
hlayout->addWidget(m_treeView, 3);
@@ -1034,11 +1021,6 @@ public:
hlayout->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::MinimumExpanding,
QSizePolicy::MinimumExpanding));
layout->addLayout(hlayout);
-
- connect(m_core, SIGNAL(finishAllComponentsReset()), this, SLOT(allComponentsChanged()),
- Qt::QueuedConnection);
- connect(m_core, SIGNAL(finishUpdaterComponentsReset()), this, SLOT(updaterComponentsChanged()),
- Qt::QueuedConnection);
}
void updateTreeView()
@@ -1102,44 +1084,33 @@ public slots:
}
}
+ // TODO: all *select* function ignore the fact that components can be selected inside the tree view as
+ // well, which will result in e.g. a disabled button state as long as "ALL" components not
+ // unchecked again.
void selectAll()
{
m_currentModel->selectAll();
- m_checkAll->setEnabled(!m_currentModel->hasCheckedComponents());
- m_uncheckAll->setEnabled(m_currentModel->hasCheckedComponents());
+ m_checkAll->setEnabled(false);
+ m_uncheckAll->setEnabled(true);
}
void deselectAll()
{
m_currentModel->deselectAll();
- m_checkAll->setEnabled(m_currentModel->hasCheckedComponents());
- m_uncheckAll->setEnabled(!m_currentModel->hasCheckedComponents());
+ m_checkAll->setEnabled(true);
+ m_uncheckAll->setEnabled(false);
}
void selectDefault()
{
m_currentModel->selectDefault();
- // Do not apply special magic here to keep the enabled/ disabled state in sync with the checked
- // components. We would need to implement the counter in the model, which has an unnecessary impact
- // on the complexity and amount of code compared to what we gain in functionality.
m_checkAll->setEnabled(true);
m_uncheckAll->setEnabled(true);
}
-private slots:
- void allComponentsChanged()
- {
- m_allModel->setRootComponents(m_core->rootComponents());
- }
-
- void updaterComponentsChanged()
- {
- m_updaterModel->setRootComponents(m_core->updaterComponents());
- }
-
public:
ComponentSelectionPage *q;
PackageManagerCore *m_core;