2016-05-29 18:27:26 +00:00
|
|
|
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
|
|
|
|
// Copyright (C) 2010 Winch Gate Property Limited
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as
|
|
|
|
// published by the Free Software Foundation, either version 3 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
#include "stdpch.h"
|
|
|
|
#include "uninstallwizarddialog.h"
|
|
|
|
#include "configfile.h"
|
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
#include "nel/misc/system_info.h"
|
|
|
|
#include "nel/misc/common.h"
|
|
|
|
|
|
|
|
#ifdef DEBUG_NEW
|
|
|
|
#define new DEBUG_NEW
|
|
|
|
#endif
|
|
|
|
|
|
|
|
CUninstallWizardDialog::CUninstallWizardDialog(QWidget *parent):QDialog(parent), m_installerIndex(-1)
|
|
|
|
{
|
|
|
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
|
|
|
|
|
|
|
setupUi(this);
|
|
|
|
|
|
|
|
CConfigFile *config = CConfigFile::getInstance();
|
|
|
|
|
|
|
|
int serverCount = config->getServersCount();
|
|
|
|
|
|
|
|
QStandardItemModel *model = new QStandardItemModel(0, 2, this);
|
|
|
|
|
|
|
|
QStringList columns;
|
|
|
|
columns << tr("Component");
|
|
|
|
columns << tr("Size");
|
|
|
|
|
|
|
|
model->setHorizontalHeaderLabels(columns);
|
|
|
|
|
2016-06-04 17:57:50 +00:00
|
|
|
QStandardItem *item = NULL;
|
|
|
|
|
2016-05-29 18:27:26 +00:00
|
|
|
// clients
|
|
|
|
for (int row = 0; row < serverCount; ++row)
|
|
|
|
{
|
|
|
|
const CServer &server = config->getServer(row);
|
|
|
|
|
|
|
|
if (QFile::exists(config->getInstallationDirectory() + "/" + server.id))
|
|
|
|
{
|
|
|
|
m_serversIndices[row] = model->rowCount();
|
|
|
|
|
2016-06-04 17:57:50 +00:00
|
|
|
item = new QStandardItem(tr("Client for %1").arg(server.name));
|
2016-05-29 18:27:26 +00:00
|
|
|
item->setCheckable(true);
|
|
|
|
model->appendRow(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int profilesCount = config->getProfilesCount();
|
|
|
|
|
|
|
|
// profiles
|
|
|
|
for (int row = 0; row < profilesCount; ++row)
|
|
|
|
{
|
|
|
|
m_profilesIndices[row] = model->rowCount();
|
|
|
|
|
|
|
|
const CProfile &profile = config->getProfile(row);
|
|
|
|
|
2016-06-04 17:57:50 +00:00
|
|
|
item = new QStandardItem(tr("Profile #%1: %2").arg(profile.id).arg(profile.name));
|
2016-05-29 18:27:26 +00:00
|
|
|
item->setCheckable(true);
|
|
|
|
model->appendRow(item);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-06-12 13:10:37 +00:00
|
|
|
// installer
|
2016-05-29 18:27:26 +00:00
|
|
|
m_installerIndex = model->rowCount();
|
|
|
|
|
2016-06-04 17:57:50 +00:00
|
|
|
item = new QStandardItem(tr("Ryzom Installer"));
|
2016-05-29 18:27:26 +00:00
|
|
|
item->setCheckable(true);
|
|
|
|
model->appendRow(item);
|
|
|
|
|
|
|
|
componentsTreeView->setModel(model);
|
|
|
|
componentsTreeView->resizeColumnToContents(0);
|
|
|
|
|
2016-06-12 13:10:37 +00:00
|
|
|
// resize layout depending on content and constraints
|
2016-06-04 17:58:50 +00:00
|
|
|
adjustSize();
|
|
|
|
|
2016-06-12 13:11:04 +00:00
|
|
|
// fix height because to left bitmap
|
|
|
|
setFixedHeight(height());
|
|
|
|
|
2016-06-04 17:58:50 +00:00
|
|
|
// click signals
|
2016-05-29 18:27:26 +00:00
|
|
|
connect(uninstallButton, SIGNAL(clicked()), SLOT(accept()));
|
|
|
|
connect(quitButton, SIGNAL(clicked()), SLOT(reject()));
|
|
|
|
connect(model, SIGNAL(itemChanged(QStandardItem *)), SLOT(onItemChanged(QStandardItem *)));
|
|
|
|
|
2016-06-04 17:58:50 +00:00
|
|
|
// semi-hack to not update UI on another thread
|
|
|
|
connect(this, SIGNAL(updateSize(int, QString)), SLOT(onUpdateSize(int, QString)));
|
|
|
|
connect(this, SIGNAL(updateLayout()), SLOT(onUpdateLayout()));
|
2016-05-29 18:27:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CUninstallWizardDialog::~CUninstallWizardDialog()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-06-04 17:57:50 +00:00
|
|
|
void CUninstallWizardDialog::showEvent(QShowEvent *event)
|
2016-05-29 18:27:26 +00:00
|
|
|
{
|
2016-06-04 17:57:50 +00:00
|
|
|
QDialog::showEvent(event);
|
|
|
|
|
2016-06-12 13:10:37 +00:00
|
|
|
// update size of all components sizes in a thread to not block interface
|
2016-06-04 17:57:50 +00:00
|
|
|
QtConcurrent::run(this, &CUninstallWizardDialog::updateSizes);
|
|
|
|
}
|
2016-05-29 18:27:26 +00:00
|
|
|
|
2016-06-04 17:57:50 +00:00
|
|
|
void CUninstallWizardDialog::setSelectedComponents(const SUninstallComponents &components)
|
|
|
|
{
|
2016-05-29 18:27:26 +00:00
|
|
|
QStandardItemModel *model = qobject_cast<QStandardItemModel*>(componentsTreeView->model());
|
2016-06-04 17:57:50 +00:00
|
|
|
if (model == NULL) return;
|
2016-05-29 18:27:26 +00:00
|
|
|
|
2016-06-04 17:57:50 +00:00
|
|
|
QStandardItem *item = NULL;
|
|
|
|
|
|
|
|
// servers
|
2016-05-29 18:27:26 +00:00
|
|
|
QMap<int, int>::const_iterator it = m_serversIndices.begin(), iend = m_serversIndices.end();
|
|
|
|
|
|
|
|
while (it != iend)
|
|
|
|
{
|
2016-06-04 17:57:50 +00:00
|
|
|
item = model->item(it.value());
|
2016-05-29 18:27:26 +00:00
|
|
|
|
2016-06-04 17:57:50 +00:00
|
|
|
if (item) item->setCheckState(components.servers.indexOf(it.key()) > -1 ? Qt::Checked : Qt::Unchecked);
|
2016-05-29 18:27:26 +00:00
|
|
|
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
|
2016-06-04 17:57:50 +00:00
|
|
|
// 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);
|
2016-05-29 18:27:26 +00:00
|
|
|
}
|
|
|
|
|
2016-06-04 17:57:50 +00:00
|
|
|
SUninstallComponents CUninstallWizardDialog::getSelectedCompenents() const
|
2016-05-29 18:27:26 +00:00
|
|
|
{
|
2016-06-04 17:57:50 +00:00
|
|
|
SUninstallComponents res;
|
2016-05-29 18:27:26 +00:00
|
|
|
|
|
|
|
QStandardItemModel *model = qobject_cast<QStandardItemModel*>(componentsTreeView->model());
|
|
|
|
if (model == NULL) return res;
|
|
|
|
|
2016-06-04 17:57:50 +00:00
|
|
|
QStandardItem *item = NULL;
|
|
|
|
|
|
|
|
// servers
|
|
|
|
QMap<int, int>::const_iterator it = m_serversIndices.begin(), iend = m_serversIndices.end();
|
2016-05-29 18:27:26 +00:00
|
|
|
|
|
|
|
while (it != iend)
|
|
|
|
{
|
2016-06-04 17:57:50 +00:00
|
|
|
item = model->item(it.value());
|
2016-05-29 18:27:26 +00:00
|
|
|
|
2016-06-04 17:57:50 +00:00
|
|
|
if (item && item->checkState() == Qt::Checked) res.servers << it.key();
|
2016-05-29 18:27:26 +00:00
|
|
|
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
|
2016-06-04 17:57:50 +00:00
|
|
|
// profiles
|
|
|
|
it = m_profilesIndices.begin(), iend = m_profilesIndices.end();
|
2016-05-29 18:27:26 +00:00
|
|
|
|
2016-06-04 17:57:50 +00:00
|
|
|
while (it != iend)
|
|
|
|
{
|
|
|
|
item = model->item(it.value());
|
2016-05-29 18:27:26 +00:00
|
|
|
|
2016-06-04 17:57:50 +00:00
|
|
|
if (item && item->checkState() == Qt::Checked) res.profiles << it.key();
|
2016-05-29 18:27:26 +00:00
|
|
|
|
2016-06-04 17:57:50 +00:00
|
|
|
++it;
|
|
|
|
}
|
|
|
|
|
|
|
|
// installer
|
|
|
|
item = model->item(m_installerIndex);
|
|
|
|
res.installer = item && item->checkState() == Qt::Checked;
|
|
|
|
|
|
|
|
return res;
|
2016-05-29 18:27:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CUninstallWizardDialog::accept()
|
|
|
|
{
|
|
|
|
QDialog::accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CUninstallWizardDialog::onItemChanged(QStandardItem * /* item */)
|
|
|
|
{
|
|
|
|
updateButtons();
|
|
|
|
}
|
|
|
|
|
2016-06-04 17:58:50 +00:00
|
|
|
void CUninstallWizardDialog::onUpdateSize(int row, const QString &text)
|
2016-05-29 18:27:26 +00:00
|
|
|
{
|
|
|
|
QStandardItemModel *model = qobject_cast<QStandardItemModel*>(componentsTreeView->model());
|
2016-06-04 17:58:50 +00:00
|
|
|
if (model == NULL) return;
|
|
|
|
|
2016-06-12 13:10:37 +00:00
|
|
|
// set size for a component
|
2016-06-04 17:58:50 +00:00
|
|
|
QStandardItem *item = new QStandardItem(text);
|
|
|
|
model->setItem(row, 1, item);
|
|
|
|
}
|
2016-05-29 18:27:26 +00:00
|
|
|
|
2016-06-04 17:58:50 +00:00
|
|
|
void CUninstallWizardDialog::onUpdateLayout()
|
|
|
|
{
|
|
|
|
componentsTreeView->resizeColumnToContents(1);
|
|
|
|
|
|
|
|
updateButtons();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CUninstallWizardDialog::updateSizes()
|
|
|
|
{
|
2016-05-29 18:27:26 +00:00
|
|
|
CConfigFile *config = CConfigFile::getInstance();
|
|
|
|
|
|
|
|
// clients
|
|
|
|
QMap<int, int>::const_iterator it = m_serversIndices.begin(), iend = m_serversIndices.end();
|
|
|
|
|
|
|
|
while(it != iend)
|
|
|
|
{
|
|
|
|
const CServer &server = config->getServer(it.key());
|
|
|
|
|
|
|
|
qint64 bytes = getDirectorySize(config->getInstallationDirectory() + "/" + server.id);
|
|
|
|
|
2016-06-04 17:58:50 +00:00
|
|
|
emit updateSize(it.value(), qBytesToHumanReadable(bytes));
|
2016-05-29 18:27:26 +00:00
|
|
|
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
|
|
|
|
// profiles
|
|
|
|
it = m_profilesIndices.begin(), iend = m_profilesIndices.end();
|
|
|
|
|
|
|
|
while (it != iend)
|
|
|
|
{
|
|
|
|
const CProfile &profile = config->getProfile(it.key());
|
|
|
|
|
|
|
|
qint64 bytes = getDirectorySize(config->getProfileDirectory() + "/" + profile.id);
|
|
|
|
|
2016-06-04 17:58:50 +00:00
|
|
|
emit updateSize(it.value(), qBytesToHumanReadable(bytes));
|
2016-05-29 18:27:26 +00:00
|
|
|
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
|
2016-06-04 17:58:50 +00:00
|
|
|
emit updateLayout();
|
2016-05-29 18:27:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CUninstallWizardDialog::updateButtons()
|
|
|
|
{
|
|
|
|
QStandardItemModel *model = qobject_cast<QStandardItemModel*>(componentsTreeView->model());
|
|
|
|
|
|
|
|
int checkedCount = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < model->rowCount(); ++i)
|
|
|
|
{
|
|
|
|
if (model->item(i)->checkState() == Qt::Checked) ++checkedCount;
|
|
|
|
}
|
|
|
|
|
2016-06-12 13:10:37 +00:00
|
|
|
// Uninstall button should be enabled only if at least one component is checked
|
2016-05-29 18:27:26 +00:00
|
|
|
uninstallButton->setEnabled(checkedCount > 0);
|
|
|
|
}
|