23 #include "freedoomdialog.h" 25 #include "ui_freedoomdialog.h" 26 #include "configuration/doomseekerconfig.h" 27 #include "pathfinder/filesearchpath.h" 28 #include "pathfinder/pathfinder.h" 29 #include "fileutils.h" 30 #include <wadseeker/entities/modset.h> 31 #include <wadseeker/freedoom.h> 32 #include <wadseeker/modinstall.h> 36 #include <QMessageBox> 38 DClass<FreedoomDialog> :
public Ui::FreedoomDialog
42 ModInstall *modInstall;
52 d->freedoom =
new Freedoom(
this);
53 this->connect(d->freedoom, SIGNAL(finished()), SLOT(applyFreedoomVersionInfo()));
55 d->modInstall =
new ModInstall(
this);
56 this->connect(d->modInstall, SIGNAL(finished()), SLOT(onModInstallFinished()));
57 this->connect(d->modInstall, SIGNAL(fileDownloadProgress(QString, qint64, qint64)),
58 SLOT(showFileDownloadProgress(QString, qint64, qint64)));
60 d->btnInstall->setEnabled(
false);
66 FreedoomDialog::~FreedoomDialog()
70 void FreedoomDialog::accept()
72 ModSet modSet = selectedModFiles();
75 QMessageBox::critical(
this, tr(
"Install Freedoom"),
76 tr(
"Select at least one file."));
80 showStatus(tr(
"Downloading & installing ..."));
81 d->targetDir = d->cboInstallPath->currentText();
82 d->modInstall->install(d->targetDir, modSet);
85 void FreedoomDialog::onModInstallFinished()
87 if (!d->modInstall->isError())
94 showError(d->modInstall->error());
98 void FreedoomDialog::updateConfig()
100 gConfig.doomseeker.enableFreedoomInstallation(d->targetDir);
101 gConfig.saveToFile();
104 void FreedoomDialog::fetchInfo()
108 showStatus(tr(
"Downloading Freedoom version info ..."));
109 d->freedoom->requestModSet();
112 void FreedoomDialog::resetProgressBar()
114 d->progressBar->setFormat(tr(
"Working ..."));
115 d->progressBar->show();
116 d->progressBar->setMaximum(0);
117 d->progressBar->setValue(0);
120 void FreedoomDialog::applyFreedoomVersionInfo()
122 if (!d->freedoom->isError())
124 showModInfo(d->freedoom->modSet());
128 showError(tr(
"Error: %1").arg(d->freedoom->error()));
132 void FreedoomDialog::showModInfo(
const ModSet &modSet)
135 d->workInProgressArea->hide();
137 d->wadsTable->setSortingEnabled(
false);
138 d->wadsTable->clearContents();
139 while (d->wadsTable->rowCount() > 0)
141 d->wadsTable->removeRow(d->wadsTable->rowCount() - 1);
143 foreach (
const ModFile &file, modSet.modFiles())
147 d->wadsTable->setSortingEnabled(
true);
148 d->btnInstall->setEnabled(
true);
151 void FreedoomDialog::insertModFile(
const ModFile &file)
154 QString location = pathFinder.
findFile(file.fileName());
156 QString status = tr(
"OK");
157 bool needsInstall =
false;
158 if (location.isEmpty())
161 status = tr(
"Missing");
165 QString md5 = FileUtils::md5(location).toHex();
166 if (md5.compare(file.md5(), Qt::CaseInsensitive) != 0)
168 status = tr(
"Different");
172 if (file.fileName().compare(
"freedm.wad", Qt::CaseInsensitive) == 0)
174 needsInstall =
false;
177 d->wadsTable->insertRow(d->wadsTable->rowCount());
178 int row = d->wadsTable->rowCount() - 1;
179 d->wadsTable->setItem(row, ColName,
new QTableWidgetItem(file.fileName()));
180 d->wadsTable->setItem(row, ColStatus,
new QTableWidgetItem(status));
182 QCheckBox *checkBox =
new QCheckBox();
183 checkBox->setChecked(needsInstall);
184 d->wadsTable->setCellWidget(row, ColInstall, checkBox);
186 QString tooltip = tr(
"<p>File: %1<br>Version: %2<br>" 187 "Description: %3<br>Location: %4</p>")
188 .arg(file.name(), file.version(), file.description(), location);
190 for (
int col = 0; col < d->wadsTable->columnCount(); ++col)
192 QTableWidgetItem *item = d->wadsTable->item(row, col);
195 item->setToolTip(tooltip);
200 void FreedoomDialog::showError(
const QString &text)
202 d->btnRetry->setVisible(
true);
204 d->progressBar->hide();
207 void FreedoomDialog::showStatus(
const QString &text)
210 d->workInProgressArea->show();
211 d->btnInstall->setEnabled(
false);
212 d->lblWorkInProgress->setText(text);
215 ModSet FreedoomDialog::selectedModFiles()
const 218 for (
int row = 0; row < d->wadsTable->rowCount(); ++row)
220 QCheckBox *checkbox =
static_cast<QCheckBox*
>(d->wadsTable->cellWidget(row, ColInstall));
221 if (checkbox->isChecked())
223 QString fileName = d->wadsTable->item(row, ColName)->text();
224 modSet.addModFile(d->freedoom->modSet().findFileName(fileName));
230 void FreedoomDialog::setupInstallPaths()
232 QCompleter *completer =
new QCompleter(
this);
233 completer->setModel(
new QDirModel(completer));
234 d->cboInstallPath->setCompleter(completer);
236 foreach (
const FileSearchPath &path, gConfig.combinedWadseekPaths())
238 d->cboInstallPath->addItem(path.path());
240 #if QT_VERSION >= 0x050000 241 d->cboInstallPath->setCurrentText(gConfig.wadseeker.targetDirectory);
246 const int item = d->cboInstallPath->findText(gConfig.wadseeker.targetDirectory);
248 d->cboInstallPath->setCurrentIndex(item);
250 d->cboInstallPath->setEditText(gConfig.wadseeker.targetDirectory);
254 void FreedoomDialog::setupWadsTable()
256 QHeaderView *header = d->wadsTable->horizontalHeader();
257 #if QT_VERSION >= 0x050000 258 header->setSectionResizeMode(ColName, QHeaderView::Stretch);
259 header->setSectionResizeMode(ColStatus, QHeaderView::ResizeToContents);
260 header->setSectionResizeMode(ColInstall, QHeaderView::ResizeToContents);
262 header->setResizeMode(ColName, QHeaderView::Stretch);
263 header->setResizeMode(ColStatus, QHeaderView::ResizeToContents);
264 header->setResizeMode(ColInstall, QHeaderView::ResizeToContents);
266 d->wadsTable->setColumnWidth(ColName, 150);
269 void FreedoomDialog::showFileDownloadProgress(
const QString &file,
270 qint64 current, qint64 total)
272 d->progressBar->setFormat(tr(
"%1 %p%").arg(file));
273 d->progressBar->setMaximum(total);
274 d->progressBar->setValue(current);
Performs a case-insensitive (OS independent) file searches.
QString findFile(const QString &fileName) const
Performs a search for a single file.