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 "pathfinder/wadpathfinder.h" 30 #include "fileutils.h" 31 #include <wadseeker/entities/modset.h> 32 #include <wadseeker/freedoom.h> 33 #include <wadseeker/modinstall.h> 37 #include <QMessageBox> 39 DClass<FreedoomDialog> :
public Ui::FreedoomDialog
43 ModInstall *modInstall;
53 d->freedoom =
new Freedoom(
this);
54 this->connect(d->freedoom, SIGNAL(finished()), SLOT(applyFreedoomVersionInfo()));
56 d->modInstall =
new ModInstall(
this);
57 this->connect(d->modInstall, SIGNAL(finished()), SLOT(onModInstallFinished()));
58 this->connect(d->modInstall, SIGNAL(fileDownloadProgress(QString, qint64, qint64)),
59 SLOT(showFileDownloadProgress(QString, qint64, qint64)));
61 d->btnInstall->setEnabled(
false);
67 FreedoomDialog::~FreedoomDialog()
71 void FreedoomDialog::accept()
73 ModSet modSet = selectedModFiles();
76 QMessageBox::critical(
this, tr(
"Install Freedoom"),
77 tr(
"Select at least one file."));
81 showStatus(tr(
"Downloading & installing ..."));
82 d->targetDir = d->cboInstallPath->currentText();
83 d->modInstall->install(d->targetDir, modSet);
86 void FreedoomDialog::onModInstallFinished()
88 if (!d->modInstall->isError())
95 showError(d->modInstall->error());
99 void FreedoomDialog::updateConfig()
101 gConfig.doomseeker.enableFreedoomInstallation(d->targetDir);
102 gConfig.saveToFile();
105 void FreedoomDialog::fetchInfo()
109 showStatus(tr(
"Downloading Freedoom version info ..."));
110 d->freedoom->requestModSet();
113 void FreedoomDialog::resetProgressBar()
115 d->progressBar->setFormat(tr(
"Working ..."));
116 d->progressBar->show();
117 d->progressBar->setMaximum(0);
118 d->progressBar->setValue(0);
121 void FreedoomDialog::applyFreedoomVersionInfo()
123 if (!d->freedoom->isError())
125 showModInfo(d->freedoom->modSet());
129 showError(tr(
"Error: %1").arg(d->freedoom->error()));
133 void FreedoomDialog::showModInfo(
const ModSet &modSet)
136 d->workInProgressArea->hide();
138 d->wadsTable->setSortingEnabled(
false);
139 d->wadsTable->clearContents();
140 while (d->wadsTable->rowCount() > 0)
142 d->wadsTable->removeRow(d->wadsTable->rowCount() - 1);
144 foreach (
const ModFile &file, modSet.modFiles())
148 d->wadsTable->setSortingEnabled(
true);
149 d->btnInstall->setEnabled(
true);
152 void FreedoomDialog::insertModFile(
const ModFile &file)
156 QString location = pathFinder.find(file.fileName()).path();
158 QString status = tr(
"OK");
159 bool needsInstall =
false;
160 if (location.isEmpty())
163 status = tr(
"Missing");
167 QString md5 = FileUtils::md5(location).toHex();
168 if (md5.compare(file.md5(), Qt::CaseInsensitive) != 0)
170 status = tr(
"Different");
174 if (file.fileName().compare(
"freedm.wad", Qt::CaseInsensitive) == 0)
176 needsInstall =
false;
179 d->wadsTable->insertRow(d->wadsTable->rowCount());
180 int row = d->wadsTable->rowCount() - 1;
181 d->wadsTable->setItem(row, ColName,
new QTableWidgetItem(file.fileName()));
182 d->wadsTable->setItem(row, ColStatus,
new QTableWidgetItem(status));
184 QCheckBox *checkBox =
new QCheckBox();
185 checkBox->setChecked(needsInstall);
186 d->wadsTable->setCellWidget(row, ColInstall, checkBox);
188 QString tooltip = tr(
"<p>File: %1<br>Version: %2<br>" 189 "Description: %3<br>Location: %4</p>")
190 .arg(file.name(), file.version(), file.description(), location);
192 for (
int col = 0; col < d->wadsTable->columnCount(); ++col)
194 QTableWidgetItem *item = d->wadsTable->item(row, col);
197 item->setToolTip(tooltip);
202 void FreedoomDialog::showError(
const QString &text)
204 d->btnRetry->setVisible(
true);
206 d->progressBar->hide();
209 void FreedoomDialog::showStatus(
const QString &text)
212 d->workInProgressArea->show();
213 d->btnInstall->setEnabled(
false);
214 d->lblWorkInProgress->setText(text);
217 ModSet FreedoomDialog::selectedModFiles()
const 220 for (
int row = 0; row < d->wadsTable->rowCount(); ++row)
222 QCheckBox *checkbox =
static_cast<QCheckBox*
>(d->wadsTable->cellWidget(row, ColInstall));
223 if (checkbox->isChecked())
225 QString fileName = d->wadsTable->item(row, ColName)->text();
226 modSet.addModFile(d->freedoom->modSet().findFileName(fileName));
232 void FreedoomDialog::setupInstallPaths()
234 QCompleter *completer =
new QCompleter(
this);
235 completer->setModel(
new QDirModel(completer));
236 d->cboInstallPath->setCompleter(completer);
238 foreach (
const FileSearchPath &path, gConfig.combinedWadseekPaths())
240 d->cboInstallPath->addItem(path.path());
242 #if QT_VERSION >= 0x050000 243 d->cboInstallPath->setCurrentText(gConfig.wadseeker.targetDirectory);
248 const int item = d->cboInstallPath->findText(gConfig.wadseeker.targetDirectory);
250 d->cboInstallPath->setCurrentIndex(item);
252 d->cboInstallPath->setEditText(gConfig.wadseeker.targetDirectory);
256 void FreedoomDialog::setupWadsTable()
258 QHeaderView *header = d->wadsTable->horizontalHeader();
259 #if QT_VERSION >= 0x050000 260 header->setSectionResizeMode(ColName, QHeaderView::Stretch);
261 header->setSectionResizeMode(ColStatus, QHeaderView::ResizeToContents);
262 header->setSectionResizeMode(ColInstall, QHeaderView::ResizeToContents);
264 header->setResizeMode(ColName, QHeaderView::Stretch);
265 header->setResizeMode(ColStatus, QHeaderView::ResizeToContents);
266 header->setResizeMode(ColInstall, QHeaderView::ResizeToContents);
268 d->wadsTable->setColumnWidth(ColName, 150);
271 void FreedoomDialog::showFileDownloadProgress(
const QString &file,
272 qint64 current, qint64 total)
274 d->progressBar->setFormat(tr(
"%1 %p%").arg(file));
275 d->progressBar->setMaximum(total);
276 d->progressBar->setValue(current);
Performs a case-insensitive (OS independent) file searches.
void setAllowAliases(bool allowed)
Can disable WAD aliasing for contexts where only specific WADs should be found.
Wrapper for PathFinder that specializes in findings WADs.