mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-10 09:19:01 +00:00
Added: Uninstall Wizard Dialog used in Add/Remove programs under Windows
This commit is contained in:
parent
605661eeb8
commit
482865ca74
3 changed files with 400 additions and 0 deletions
|
@ -0,0 +1,217 @@
|
|||
// 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);
|
||||
|
||||
// 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();
|
||||
|
||||
QStandardItem *item = new QStandardItem(tr("Client for %1").arg(server.name));
|
||||
item->setCheckable(true);
|
||||
item->setCheckState(Qt::Checked);
|
||||
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);
|
||||
|
||||
QStandardItem *item = new QStandardItem(tr("Profile #%1: %2").arg(profile.id).arg(profile.name));
|
||||
item->setCheckable(true);
|
||||
model->appendRow(item);
|
||||
|
||||
}
|
||||
|
||||
m_installerIndex = model->rowCount();
|
||||
|
||||
QStandardItem *item = new QStandardItem(tr("Ryzom Installer"));
|
||||
item->setCheckable(true);
|
||||
item->setCheckState(Qt::Checked);
|
||||
model->appendRow(item);
|
||||
|
||||
componentsTreeView->setModel(model);
|
||||
componentsTreeView->resizeColumnToContents(0);
|
||||
|
||||
connect(uninstallButton, SIGNAL(clicked()), SLOT(accept()));
|
||||
connect(quitButton, SIGNAL(clicked()), SLOT(reject()));
|
||||
connect(model, SIGNAL(itemChanged(QStandardItem *)), SLOT(onItemChanged(QStandardItem *)));
|
||||
|
||||
adjustSize();
|
||||
|
||||
QtConcurrent::run(this, &CUninstallWizardDialog::updateSizes);
|
||||
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
CUninstallWizardDialog::~CUninstallWizardDialog()
|
||||
{
|
||||
}
|
||||
|
||||
QVector<int> CUninstallWizardDialog::getSelectedServers() const
|
||||
{
|
||||
QVector<int> res;
|
||||
|
||||
QStandardItemModel *model = qobject_cast<QStandardItemModel*>(componentsTreeView->model());
|
||||
if (model == NULL) return res;
|
||||
|
||||
QMap<int, int>::const_iterator it = m_serversIndices.begin(), iend = m_serversIndices.end();
|
||||
|
||||
while (it != iend)
|
||||
{
|
||||
QStandardItem *item = model->item(m_installerIndex);
|
||||
|
||||
if (item && item->checkState() == Qt::Checked) res << it.value();
|
||||
|
||||
++it;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
QVector<int> CUninstallWizardDialog::getSelectedProfiles() const
|
||||
{
|
||||
QVector<int> 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();
|
||||
|
||||
while (it != iend)
|
||||
{
|
||||
QStandardItem *item = model->item(m_installerIndex);
|
||||
|
||||
if (item && item->checkState() == Qt::Checked) res << it.value();
|
||||
|
||||
++it;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
void CUninstallWizardDialog::onItemChanged(QStandardItem * /* item */)
|
||||
{
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
void CUninstallWizardDialog::updateSizes()
|
||||
{
|
||||
QStandardItemModel *model = qobject_cast<QStandardItemModel*>(componentsTreeView->model());
|
||||
|
||||
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);
|
||||
|
||||
QStandardItem *item = new QStandardItem(qBytesToHumanReadable(bytes));
|
||||
model->setItem(it.value(), 1, item);
|
||||
|
||||
++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);
|
||||
|
||||
QStandardItem *item = new QStandardItem(qBytesToHumanReadable(bytes));
|
||||
model->setItem(it.value(), 1, item);
|
||||
|
||||
++it;
|
||||
}
|
||||
|
||||
componentsTreeView->resizeColumnToContents(1);
|
||||
}
|
||||
|
||||
void CUninstallWizardDialog::updateButtons()
|
||||
{
|
||||
QStandardItemModel *model = qobject_cast<QStandardItemModel*>(componentsTreeView->model());
|
||||
|
||||
int checkedCount = 0;
|
||||
|
||||
// Uninstall button should be enabled only if at least one component is selected
|
||||
for (int i = 0; i < model->rowCount(); ++i)
|
||||
{
|
||||
if (model->item(i)->checkState() == Qt::Checked) ++checkedCount;
|
||||
}
|
||||
|
||||
uninstallButton->setEnabled(checkedCount > 0);
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
// 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/>.
|
||||
|
||||
#ifndef UNINSTALLWIZARDDIALOG_H
|
||||
#define UNINSTALLWIZARDDIALOG_H
|
||||
|
||||
#include "ui_uninstallwizard.h"
|
||||
|
||||
/**
|
||||
* Wizard displayed at first launch, that asks user to choose source and destination directories.
|
||||
*
|
||||
* \author Cedric 'Kervala' OCHS
|
||||
* \date 2016
|
||||
*/
|
||||
class CUninstallWizardDialog : public QDialog, public Ui::UninstallWizardDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CUninstallWizardDialog(QWidget *parent = NULL);
|
||||
virtual ~CUninstallWizardDialog();
|
||||
|
||||
QVector<int> getSelectedServers() const;
|
||||
QVector<int> getSelectedProfiles() const;
|
||||
|
||||
bool isInstallerSelected() const;
|
||||
|
||||
private slots:
|
||||
void accept();
|
||||
void onItemChanged(QStandardItem *item);
|
||||
|
||||
private:
|
||||
void updateSizes();
|
||||
void updateButtons();
|
||||
|
||||
// key is original ID, value is row index
|
||||
QMap<int, int> m_serversIndices;
|
||||
QMap<int, int> m_profilesIndices;
|
||||
|
||||
int m_installerIndex;
|
||||
};
|
||||
|
||||
#endif
|
127
code/ryzom/tools/client/ryzom_installer/ui/uninstallwizard.ui
Normal file
127
code/ryzom/tools/client/ryzom_installer/ui/uninstallwizard.ui
Normal file
|
@ -0,0 +1,127 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>UninstallWizardDialog</class>
|
||||
<widget class="QDialog" name="UninstallWizardDialog">
|
||||
<property name="windowModality">
|
||||
<enum>Qt::ApplicationModal</enum>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>415</width>
|
||||
<height>365</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Ryzom Installer</string>
|
||||
</property>
|
||||
<property name="modal">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="dialogLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="mainLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="headerBitmap">
|
||||
<property name="pixmap">
|
||||
<pixmap resource="../res/resources.qrc">:/images/background.png</pixmap>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="contentLayout" stretch="0,0,0,0">
|
||||
<item>
|
||||
<widget class="QLabel" name="messageLabel">
|
||||
<property name="text">
|
||||
<string>You're about to uninstall some or all components of Ryzom. Please check each component you want to remove (warning, it can't be reverted).</string>
|
||||
</property>
|
||||
<property name="textFormat">
|
||||
<enum>Qt::PlainText</enum>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignJustify|Qt::AlignTop</set>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="componentsSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="componentsLabel">
|
||||
<property name="text">
|
||||
<string>Components to remove</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTreeView" name="componentsTreeView">
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::NoSelection</enum>
|
||||
</property>
|
||||
<property name="rootIsDecorated">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="uniformRowHeights">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="buttonsLayout" stretch="1,0,0">
|
||||
<item>
|
||||
<spacer name="buttonsSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="uninstallButton">
|
||||
<property name="text">
|
||||
<string>Uninstall</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="quitButton">
|
||||
<property name="text">
|
||||
<string>Quit</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../res/resources.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
Loading…
Reference in a new issue