Changed: Implement components selection for uninstaller

This commit is contained in:
kervala 2016-06-04 19:57:50 +02:00
parent 7c89930d46
commit bd4fcfd996
7 changed files with 181 additions and 52 deletions

View file

@ -107,14 +107,12 @@ int main(int argc, char *argv[])
if (parser.isSet(uninstallOption))
{
QVector<int> selectedServers;
QVector<int> 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;
dialog.setOperation(COperationDialog::OperationUninstall);
dialog.setUninstallComponents(components);
// TODO: set all components to uninstall
if (dialog.exec()) return 0;
}
return 1;
return dialog.exec() ? 0 : 1;
}
if (step == CConfigFile::ShowMigrateWizard)

View file

@ -129,15 +129,33 @@ void CMainWindow::onProfiles()
void CMainWindow::onUninstall()
{
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();
}
}

View file

@ -33,4 +33,17 @@ public:
virtual bool operationShouldStop() =0;
};
struct SUninstallComponents
{
SUninstallComponents()
{
installer = true;
}
QVector<int> servers;
QVector<int> profiles;
bool installer;
};
#endif

View file

@ -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();

View file

@ -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

View file

@ -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<int> CUninstallWizardDialog::getSelectedServers() const
void CUninstallWizardDialog::showEvent(QShowEvent *event)
{
QVector<int> res;
QDialog::showEvent(event);
QtConcurrent::run(this, &CUninstallWizardDialog::updateSizes);
}
void CUninstallWizardDialog::setSelectedComponents(const SUninstallComponents &components)
{
QStandardItemModel *model = qobject_cast<QStandardItemModel*>(componentsTreeView->model());
if (model == NULL) return res;
if (model == NULL) return;
QStandardItem *item = NULL;
// servers
QMap<int, int>::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<int> CUninstallWizardDialog::getSelectedProfiles() const
SUninstallComponents CUninstallWizardDialog::getSelectedCompenents() const
{
QVector<int> res;
SUninstallComponents res;
QStandardItemModel *model = qobject_cast<QStandardItemModel*>(componentsTreeView->model());
if (model == NULL) return res;
QMap<int, int>::const_iterator it = m_profilesIndices.begin(), iend = m_profilesIndices.end();
QStandardItem *item = NULL;
// servers
QMap<int, int>::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<QStandardItemModel*>(componentsTreeView->model());
if (model == NULL) return false;
QStandardItem *item = model->item(m_installerIndex);
return item && item->checkState() == Qt::Checked;
}
void CUninstallWizardDialog::accept()
{
QDialog::accept();

View file

@ -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<int> getSelectedServers() const;
QVector<int> getSelectedProfiles() const;
void setSelectedComponents(const SUninstallComponents &components);
SUninstallComponents getSelectedCompenents() const;
bool isInstallerSelected() const;