From bd4fcfd99696761d893b42fd1eff263e2f26bace Mon Sep 17 00:00:00 2001 From: kervala Date: Sat, 4 Jun 2016 19:57:50 +0200 Subject: [PATCH] Changed: Implement components selection for uninstaller --- .../tools/client/ryzom_installer/src/main.cpp | 31 +++---- .../client/ryzom_installer/src/mainwindow.cpp | 30 +++++-- .../client/ryzom_installer/src/operation.h | 13 +++ .../ryzom_installer/src/operationdialog.cpp | 66 +++++++++++++++ .../ryzom_installer/src/operationdialog.h | 5 ++ .../src/uninstallwizarddialog.cpp | 83 +++++++++++++------ .../src/uninstallwizarddialog.h | 5 +- 7 files changed, 181 insertions(+), 52 deletions(-) diff --git a/code/ryzom/tools/client/ryzom_installer/src/main.cpp b/code/ryzom/tools/client/ryzom_installer/src/main.cpp index ea4b87918..55388fa7e 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/main.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/main.cpp @@ -107,14 +107,12 @@ int main(int argc, char *argv[]) if (parser.isSet(uninstallOption)) { - QVector selectedServers; - QVector selectedProfiles; - bool selectedInstaller = true; + SUninstallComponents components; // add all servers by default for (int i = 0; i < config.getServersCount(); ++i) { - selectedServers << i; + components.servers << i; } // show uninstall wizard dialog if not in silent mode @@ -122,25 +120,22 @@ int main(int argc, char *argv[]) { CUninstallWizardDialog dialog; - if (dialog.exec()) - { - selectedServers = dialog.getSelectedServers(); - selectedProfiles = dialog.getSelectedProfiles(); - selectedInstaller = dialog.isInstallerSelected(); - } + dialog.setSelectedComponents(components); + + // TODO: check real return codes from Uninstallers + if (!dialog.exec()) return 1; + + components = dialog.getSelectedCompenents(); } - { - COperationDialog dialog; + COperationDialog dialog; - dialog.setOperation(COperationDialog::OperationUninstall); + dialog.setOperation(COperationDialog::OperationUninstall); + dialog.setUninstallComponents(components); - // TODO: set all components to uninstall + // TODO: set all components to uninstall - if (dialog.exec()) return 0; - } - - return 1; + return dialog.exec() ? 0 : 1; } if (step == CConfigFile::ShowMigrateWizard) diff --git a/code/ryzom/tools/client/ryzom_installer/src/mainwindow.cpp b/code/ryzom/tools/client/ryzom_installer/src/mainwindow.cpp index d28aaf5fc..34b8303b9 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/mainwindow.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/mainwindow.cpp @@ -129,15 +129,33 @@ void CMainWindow::onProfiles() void CMainWindow::onUninstall() { - CUninstallWizardDialog dialog(this); + CConfigFile *config = CConfigFile::getInstance(); + + SUninstallComponents components; + + // add all servers by default + for (int i = 0; i < config->getServersCount(); ++i) + { + components.servers << i; + } + + { + CUninstallWizardDialog dialog(this); + + dialog.setSelectedComponents(components); + + if (!dialog.exec()) return; + + components = dialog.getSelectedCompenents(); + } + + COperationDialog dialog; + + dialog.setOperation(COperationDialog::OperationUninstall); + dialog.setUninstallComponents(components); if (dialog.exec()) { - COperationDialog dialog(&dialog); - - dialog.setOperation(COperationDialog::OperationUninstall); - - dialog.exec(); } } diff --git a/code/ryzom/tools/client/ryzom_installer/src/operation.h b/code/ryzom/tools/client/ryzom_installer/src/operation.h index 121761e57..344e9e8ba 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/operation.h +++ b/code/ryzom/tools/client/ryzom_installer/src/operation.h @@ -33,4 +33,17 @@ public: virtual bool operationShouldStop() =0; }; +struct SUninstallComponents +{ + SUninstallComponents() + { + installer = true; + } + + QVector servers; + QVector profiles; + + bool installer; +}; + #endif diff --git a/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp b/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp index df5cd7d8c..ef05f1ce8 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp @@ -89,6 +89,11 @@ void COperationDialog::setOperation(Operation operation) m_operation = operation; } +void COperationDialog::setUninstallComponents(const SUninstallComponents &components) +{ + m_components = components; +} + void COperationDialog::processNextStep() { switch (m_operation) @@ -202,6 +207,25 @@ void COperationDialog::processInstallNextStep() void COperationDialog::processUninstallNextStep() { + CConfigFile *config = CConfigFile::getInstance(); + + if (!m_components.servers.isEmpty()) + { + QtConcurrent::run(this, &COperationDialog::deleteComponentsServers); + } + else if (!m_components.profiles.isEmpty()) + { + QtConcurrent::run(this, &COperationDialog::deleteComponentsProfiles); + } + else if (m_components.installer) + { + QtConcurrent::run(this, &COperationDialog::deleteComponentsInstaller); + } + else + { + // done + accept(); + } } void COperationDialog::showEvent(QShowEvent *e) @@ -644,6 +668,48 @@ bool COperationDialog::createAddRemoveEntry() return true; } +void COperationDialog::deleteComponentsServers() +{ + m_currentOperation = QApplication::tr("Delete client files"); + m_currentOperationProgressFormat = QApplication::tr("Deleting %1..."); + +// connect(m_downloader, SIGNAL(downloadPrepare()), SLOT(onProgressPrepare())); +// connect(m_downloader, SIGNAL(downloadInit(qint64, qint64)), SLOT(onProgressInit(qint64, qint64))); +// connect(m_downloader, SIGNAL(downloadStart()), SLOT(onProgressStart())); +// connect(m_downloader, SIGNAL(downloadStop()), SLOT(onProgressStop())); +// connect(m_downloader, SIGNAL(downloadProgress(qint64, QString)), SLOT(onProgressProgress(qint64, QString))); + + + CConfigFile *config = CConfigFile::getInstance(); + + foreach(int serverIndex, m_components.servers) + { + const CServer &server = config->getServer(serverIndex); + + QString path = config->getInstallationDirectory() + "/" + server.id; + + QDir dir(path); + + if (!dir.exists() || !dir.removeRecursively()) + { + emit onProgressFail(tr("Uninstall to delete files for client %1").arg(server.name)); + } + } + + emit onProgressSuccess(m_components.servers.size()); + emit done(); +} + +void COperationDialog::deleteComponentsProfiles() +{ + emit done(); +} + +void COperationDialog::deleteComponentsInstaller() +{ + emit done(); +} + void COperationDialog::operationPrepare() { emit prepare(); diff --git a/code/ryzom/tools/client/ryzom_installer/src/operationdialog.h b/code/ryzom/tools/client/ryzom_installer/src/operationdialog.h index 6876933a6..61105742d 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/operationdialog.h +++ b/code/ryzom/tools/client/ryzom_installer/src/operationdialog.h @@ -47,6 +47,7 @@ public: }; void setOperation(Operation operation); + void setUninstallComponents(const SUninstallComponents &components); public slots: void onAbortClicked(); @@ -106,6 +107,9 @@ protected: bool createDefaultProfile(); bool createDefaultShortcuts(); bool createAddRemoveEntry(); + void deleteComponentsServers(); + void deleteComponentsProfiles(); + void deleteComponentsInstaller(); // from CFilesCopier virtual void operationPrepare(); @@ -128,6 +132,7 @@ protected: bool m_aborting; Operation m_operation; + SUninstallComponents m_components; }; #endif diff --git a/code/ryzom/tools/client/ryzom_installer/src/uninstallwizarddialog.cpp b/code/ryzom/tools/client/ryzom_installer/src/uninstallwizarddialog.cpp index 7c5bdfab0..fbaf44853 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/uninstallwizarddialog.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/uninstallwizarddialog.cpp @@ -44,6 +44,8 @@ CUninstallWizardDialog::CUninstallWizardDialog(QWidget *parent):QDialog(parent), model->setHorizontalHeaderLabels(columns); + QStandardItem *item = NULL; + // clients for (int row = 0; row < serverCount; ++row) { @@ -53,9 +55,8 @@ CUninstallWizardDialog::CUninstallWizardDialog(QWidget *parent):QDialog(parent), { m_serversIndices[row] = model->rowCount(); - QStandardItem *item = new QStandardItem(tr("Client for %1").arg(server.name)); + item = new QStandardItem(tr("Client for %1").arg(server.name)); item->setCheckable(true); - item->setCheckState(Qt::Checked); model->appendRow(item); } } @@ -69,7 +70,7 @@ CUninstallWizardDialog::CUninstallWizardDialog(QWidget *parent):QDialog(parent), const CProfile &profile = config->getProfile(row); - QStandardItem *item = new QStandardItem(tr("Profile #%1: %2").arg(profile.id).arg(profile.name)); + item = new QStandardItem(tr("Profile #%1: %2").arg(profile.id).arg(profile.name)); item->setCheckable(true); model->appendRow(item); @@ -77,9 +78,8 @@ CUninstallWizardDialog::CUninstallWizardDialog(QWidget *parent):QDialog(parent), m_installerIndex = model->rowCount(); - QStandardItem *item = new QStandardItem(tr("Ryzom Installer")); + item = new QStandardItem(tr("Ryzom Installer")); item->setCheckable(true); - item->setCheckState(Qt::Checked); model->appendRow(item); componentsTreeView->setModel(model); @@ -100,58 +100,89 @@ CUninstallWizardDialog::~CUninstallWizardDialog() { } -QVector CUninstallWizardDialog::getSelectedServers() const +void CUninstallWizardDialog::showEvent(QShowEvent *event) { - QVector res; + QDialog::showEvent(event); + QtConcurrent::run(this, &CUninstallWizardDialog::updateSizes); +} + +void CUninstallWizardDialog::setSelectedComponents(const SUninstallComponents &components) +{ QStandardItemModel *model = qobject_cast(componentsTreeView->model()); - if (model == NULL) return res; + if (model == NULL) return; + QStandardItem *item = NULL; + + // servers QMap::const_iterator it = m_serversIndices.begin(), iend = m_serversIndices.end(); while (it != iend) { - QStandardItem *item = model->item(m_installerIndex); + item = model->item(it.value()); - if (item && item->checkState() == Qt::Checked) res << it.value(); + if (item) item->setCheckState(components.servers.indexOf(it.key()) > -1 ? Qt::Checked : Qt::Unchecked); ++it; } - return res; + // profiles + it = m_profilesIndices.begin(), iend = m_profilesIndices.end(); + + while (it != iend) + { + item = model->item(it.value()); + + if (item) item->setCheckState(components.profiles.indexOf(it.key()) > -1 ? Qt::Checked : Qt::Unchecked); + + ++it; + } + + // installer + item = model->item(m_installerIndex); + if (item) item->setCheckState(components.installer ? Qt::Checked : Qt::Unchecked); } -QVector CUninstallWizardDialog::getSelectedProfiles() const +SUninstallComponents CUninstallWizardDialog::getSelectedCompenents() const { - QVector res; + SUninstallComponents res; QStandardItemModel *model = qobject_cast(componentsTreeView->model()); if (model == NULL) return res; - QMap::const_iterator it = m_profilesIndices.begin(), iend = m_profilesIndices.end(); + QStandardItem *item = NULL; + + // servers + QMap::const_iterator it = m_serversIndices.begin(), iend = m_serversIndices.end(); while (it != iend) { - QStandardItem *item = model->item(m_installerIndex); + item = model->item(it.value()); - if (item && item->checkState() == Qt::Checked) res << it.value(); + if (item && item->checkState() == Qt::Checked) res.servers << it.key(); ++it; } + // profiles + it = m_profilesIndices.begin(), iend = m_profilesIndices.end(); + + while (it != iend) + { + item = model->item(it.value()); + + if (item && item->checkState() == Qt::Checked) res.profiles << it.key(); + + ++it; + } + + // installer + item = model->item(m_installerIndex); + res.installer = item && item->checkState() == Qt::Checked; + return res; } -bool CUninstallWizardDialog::isInstallerSelected() const -{ - QStandardItemModel *model = qobject_cast(componentsTreeView->model()); - if (model == NULL) return false; - - QStandardItem *item = model->item(m_installerIndex); - - return item && item->checkState() == Qt::Checked; -} - void CUninstallWizardDialog::accept() { QDialog::accept(); diff --git a/code/ryzom/tools/client/ryzom_installer/src/uninstallwizarddialog.h b/code/ryzom/tools/client/ryzom_installer/src/uninstallwizarddialog.h index c5f911b33..a65598f1e 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/uninstallwizarddialog.h +++ b/code/ryzom/tools/client/ryzom_installer/src/uninstallwizarddialog.h @@ -18,6 +18,7 @@ #define UNINSTALLWIZARDDIALOG_H #include "ui_uninstallwizard.h" +#include "operation.h" /** * Wizard displayed at first launch, that asks user to choose source and destination directories. @@ -33,8 +34,8 @@ public: CUninstallWizardDialog(QWidget *parent = NULL); virtual ~CUninstallWizardDialog(); - QVector getSelectedServers() const; - QVector getSelectedProfiles() const; + void setSelectedComponents(const SUninstallComponents &components); + SUninstallComponents getSelectedCompenents() const; bool isInstallerSelected() const;