Use configured resolution for login/outgame/ingame
[ryzomcore.git] / ryzom / tools / client / ryzom_installer / src / uninstalldialog.cpp
blobe346d7a004712b486156a46099f6e7f50632a99f
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "stdpch.h"
18 #include "uninstalldialog.h"
19 #include "configfile.h"
20 #include "utils.h"
22 #include "nel/misc/system_info.h"
23 #include "nel/misc/common.h"
25 #ifdef DEBUG_NEW
26 #define new DEBUG_NEW
27 #endif
29 CUninstallDialog::CUninstallDialog(QWidget *parent):QDialog(parent), m_installerIndex(-1)
31 setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
33 setupUi(this);
35 CConfigFile *config = CConfigFile::getInstance();
37 int serverCount = config->getServersCount();
39 QStandardItemModel *model = new QStandardItemModel(0, 2, this);
41 QStringList columns;
42 columns << tr("Component");
43 columns << tr("Size");
45 model->setHorizontalHeaderLabels(columns);
47 QStandardItem *item = NULL;
49 // clients
50 for (int row = 0; row < serverCount; ++row)
52 const CServer &server = config->getServer(row);
54 if (QFile::exists(server.getDirectory()))
56 m_serversIndices[server.id] = model->rowCount();
58 item = new QStandardItem(tr("Client for %1").arg(server.name));
59 item->setCheckable(true);
60 model->appendRow(item);
64 int profilesCount = config->getProfilesCount();
66 // profiles
67 for (int row = 0; row < profilesCount; ++row)
69 const CProfile &profile = config->getProfile(row);
71 m_profilesIndices[profile.id] = model->rowCount();
73 item = new QStandardItem(tr("Profile #%1: %2").arg(profile.id).arg(profile.name));
74 item->setCheckable(true);
75 model->appendRow(item);
79 // installer
80 m_installerIndex = model->rowCount();
82 item = new QStandardItem(tr("Installer"));
83 item->setCheckable(true);
84 model->appendRow(item);
86 // downloaded files
87 m_downloadedFilesIndex = model->rowCount();
89 item = new QStandardItem(tr("Downloaded Files"));
90 item->setCheckable(true);
91 model->appendRow(item);
93 componentsTreeView->setModel(model);
94 componentsTreeView->resizeColumnToContents(0);
96 // resize layout depending on content and constraints
97 adjustSize();
99 // fix height because to left bitmap
100 setFixedHeight(height());
102 // click signals
103 connect(uninstallButton, SIGNAL(clicked()), SLOT(accept()));
104 connect(cancelButton, SIGNAL(clicked()), SLOT(reject()));
105 connect(model, SIGNAL(itemChanged(QStandardItem *)), SLOT(onItemChanged(QStandardItem *)));
107 // semi-hack to not update UI on another thread
108 connect(this, SIGNAL(updateSize(int, QString)), SLOT(onUpdateSize(int, QString)));
109 connect(this, SIGNAL(updateLayout()), SLOT(onUpdateLayout()));
112 CUninstallDialog::~CUninstallDialog()
116 void CUninstallDialog::showEvent(QShowEvent *event)
118 QDialog::showEvent(event);
120 // update size of all components sizes in a thread to not block interface
121 QtConcurrent::run(this, &CUninstallDialog::updateSizes);
124 void CUninstallDialog::setSelectedComponents(const SComponents &components)
126 QStandardItemModel *model = qobject_cast<QStandardItemModel*>(componentsTreeView->model());
127 if (model == NULL) return;
129 QStandardItem *item = NULL;
131 // servers
132 IDIndicesMap::const_iterator it = m_serversIndices.begin(), iend = m_serversIndices.end();
134 while (it != iend)
136 item = model->item(it.value());
138 if (item) item->setCheckState(components.servers.indexOf(it.key()) > -1 ? Qt::Checked : Qt::Unchecked);
140 ++it;
143 // profiles
144 it = m_profilesIndices.begin(), iend = m_profilesIndices.end();
146 while (it != iend)
148 item = model->item(it.value());
150 if (item) item->setCheckState(components.profiles.indexOf(it.key()) > -1 ? Qt::Checked : Qt::Unchecked);
152 ++it;
155 // installer
156 item = model->item(m_installerIndex);
157 if (item) item->setCheckState(components.installer ? Qt::Checked : Qt::Unchecked);
159 // downloaded files
160 item = model->item(m_downloadedFilesIndex);
161 if (item) item->setCheckState(components.downloadedFiles ? Qt::Checked : Qt::Unchecked);
164 SComponents CUninstallDialog::getSelectedCompenents() const
166 SComponents res;
168 QStandardItemModel *model = qobject_cast<QStandardItemModel*>(componentsTreeView->model());
169 if (model == NULL) return res;
171 QStandardItem *item = NULL;
173 // servers
174 IDIndicesMap::const_iterator it = m_serversIndices.begin(), iend = m_serversIndices.end();
176 while (it != iend)
178 item = model->item(it.value());
180 if (item && item->checkState() == Qt::Checked) res.servers << it.key();
182 ++it;
185 // profiles
186 it = m_profilesIndices.begin(), iend = m_profilesIndices.end();
188 while (it != iend)
190 item = model->item(it.value());
192 if (item && item->checkState() == Qt::Checked) res.profiles << it.key();
194 ++it;
197 // installer
198 item = model->item(m_installerIndex);
199 res.installer = item && item->checkState() == Qt::Checked;
201 // downloaded files
202 item = model->item(m_downloadedFilesIndex);
203 res.downloadedFiles = item && item->checkState() == Qt::Checked;
205 return res;
208 void CUninstallDialog::accept()
210 QDialog::accept();
213 void CUninstallDialog::onItemChanged(QStandardItem * /* item */)
215 updateButtons();
218 void CUninstallDialog::onUpdateSize(int row, const QString &text)
220 QStandardItemModel *model = qobject_cast<QStandardItemModel*>(componentsTreeView->model());
221 if (model == NULL) return;
223 // set size for a component
224 QStandardItem *item = new QStandardItem(text);
225 model->setItem(row, 1, item);
228 void CUninstallDialog::onUpdateLayout()
230 componentsTreeView->resizeColumnToContents(1);
232 updateButtons();
235 void CUninstallDialog::updateSizes()
237 CConfigFile *config = CConfigFile::getInstance();
239 // clients
240 IDIndicesMap::const_iterator it = m_serversIndices.begin(), iend = m_serversIndices.end();
242 while(it != iend)
244 const CServer &server = config->getServer(it.key());
246 qint64 bytes = getDirectorySize(server.getDirectory(), true);
248 emit updateSize(it.value(), qBytesToHumanReadable(bytes));
250 ++it;
253 // profiles
254 it = m_profilesIndices.begin(), iend = m_profilesIndices.end();
256 while (it != iend)
258 const CProfile &profile = config->getProfile(it.key());
260 // wrong profile
261 if (profile.id.isEmpty()) continue;
263 qint64 bytes = getDirectorySize(profile.getDirectory(), true);
265 emit updateSize(it.value(), qBytesToHumanReadable(bytes));
267 ++it;
270 // downloaded files
271 qint64 bytes = 0;
273 QDir dir(config->getInstallationDirectory());
275 QStringList filters;
277 filters << "*.log";
278 filters << "*.7z";
279 filters << "*.bnp";
280 filters << "*.zip";
281 filters << "*.part";
283 QFileInfoList downloadedFiles = dir.entryInfoList(filters, QDir::Files);
285 foreach(const QFileInfo &info, downloadedFiles)
287 bytes += info.size();
290 emit updateSize(m_downloadedFilesIndex, qBytesToHumanReadable(bytes));
292 emit updateLayout();
295 void CUninstallDialog::updateButtons()
297 QStandardItemModel *model = qobject_cast<QStandardItemModel*>(componentsTreeView->model());
298 if (model == NULL) return;
300 int checkedCount = 0;
302 for (int i = 0; i < model->rowCount(); ++i)
304 if (model->item(i)->checkState() == Qt::Checked) ++checkedCount;
307 // Uninstall button should be enabled only if at least one component is checked
308 uninstallButton->setEnabled(checkedCount > 0);