23 #include "gui/wadseekerinterface.h" 24 #include "ui_wadseekerinterface.h" 26 #include "configuration/doomseekerconfig.h" 27 #include "gui/helpers/taskbarbutton.h" 28 #include "gui/helpers/taskbarprogress.h" 29 #include "serverapi/server.h" 30 #include "application.h" 31 #include "mainwindow.h" 34 #include <QMessageBox> 36 const int WadseekerInterface::UPDATE_INTERVAL_MS = 500;
39 DClass<WadseekerInterface> :
public Ui::WadseekerInterface
42 bool bCompletedSuccessfully;
57 WadseekerInterface::WadseekerInterface(ServerPtr server, QWidget* parent)
63 d->lblTop->setText(tr(
"Downloading WADs for server \"%1\"").arg(server->name()));
64 setCustomSite(server->webSite());
67 WadseekerInterface::~WadseekerInterface()
69 currentInstance = NULL;
72 void WadseekerInterface::abortService(
const QString &service)
74 message(tr(
"Aborting service: %1").arg(service), WadseekerLib::Notice);
75 wadseeker.skipService(service);
78 void WadseekerInterface::abortSite(
const QUrl &url)
80 message(tr(
"Aborting site: %1").arg(url.toString()), WadseekerLib::Notice);
81 wadseeker.skipSiteSeek(url);
84 void WadseekerInterface::accept()
88 if (d->bCompletedSuccessfully)
90 done(QDialog::Accepted);
95 if (d->leWadName->text().isEmpty())
100 startSeeking(d->leWadName->text().split(
',', QString::SkipEmptyParts));
104 void WadseekerInterface::allDone(
bool bSuccess)
107 d->bCompletedSuccessfully = bSuccess;
108 QApplication::alert(
this);
111 displayMessage(tr(
"All done. Success."), WadseekerLib::NoticeImportant,
false);
113 if (isAutomatic() && !d->preventGame)
115 if (isActiveWindow())
117 done(QDialog::Accepted);
121 d->btnStartGame->show();
127 QStringList failures = unsuccessfulWads();
129 foreach (
const QString& failure, failures)
131 d->twWads->setFileFailed(failure);
134 displayMessage(tr(
"All done. Fail."), WadseekerLib::CriticalError,
false);
138 void WadseekerInterface::connectWadseekerObject()
141 this->connect(&wadseeker, SIGNAL( allDone(
bool) ),
142 SLOT( allDone(
bool) ) );
143 this->connect(&wadseeker, SIGNAL( message(
const QString&, WadseekerLib::MessageType) ),
144 SLOT( message(
const QString&, WadseekerLib::MessageType) ) );
145 this->connect(&wadseeker, SIGNAL( seekStarted(
const QStringList&) ),
146 SLOT( seekStarted(
const QStringList&) ) );
147 this->connect(&wadseeker, SIGNAL( fileInstalled(
const QString&) ),
148 SLOT( fileDownloadSuccessful(
const QString&) ) );
149 this->connect(&wadseeker, SIGNAL( siteFinished(
const QUrl&) ),
150 SLOT( siteFinished(
const QUrl&) ) );
151 this->connect(&wadseeker, SIGNAL( siteProgress(
const QUrl&, qint64, qint64) ),
152 SLOT( siteProgress(
const QUrl&, qint64, qint64) ) );
153 this->connect(&wadseeker, SIGNAL( siteRedirect(
const QUrl&,
const QUrl&) ),
154 SLOT( siteRedirect(
const QUrl&,
const QUrl&) ) );
155 this->connect(&wadseeker, SIGNAL( siteStarted(
const QUrl&) ),
156 SLOT( siteStarted(
const QUrl&) ) );
157 this->connect(&wadseeker, SIGNAL( serviceStarted(QString) ),
158 SLOT( serviceStarted(QString) ) );
159 this->connect(&wadseeker, SIGNAL( serviceFinished(QString) ),
160 SLOT( serviceFinished(QString) ) );
163 d->twWads->connect(&wadseeker, SIGNAL( fileDownloadFinished(
const QString&) ),
164 SLOT( setFileDownloadFinished(
const QString&) ) );
165 d->twWads->connect(&wadseeker, SIGNAL( fileDownloadProgress(
const QString&, qint64, qint64) ),
166 SLOT( setFileProgress(
const QString&, qint64, qint64) ) );
167 d->twWads->connect(&wadseeker, SIGNAL( fileDownloadStarted(
const QString&,
const QUrl&) ),
168 SLOT( setFileUrl(
const QString&,
const QUrl&) ) );
171 void WadseekerInterface::construct()
174 d->preventGame =
false;
175 d->bCompletedSuccessfully =
false;
179 d->taskbarProgress = d->taskbarButton->progress();
180 d->taskbarProgress->setMaximum(d->pbOverallProgress->maximum());
186 this->setWindowIcon(QIcon(
":/icon.png"));
187 d->btnStartGame->hide();
188 this->connect(&updateTimer, SIGNAL(timeout()), SLOT(registerUpdateRequest()));
190 connectWadseekerObject();
193 this->connect(d->twWads, SIGNAL( rightMouseClick(
const QModelIndex&,
const QPoint&) ),
194 SLOT( wadsTableRightClicked(
const QModelIndex&,
const QPoint&) ) );
199 QStringList urlList = gConfig.wadseeker.searchURLs;
200 if (gConfig.wadseeker.bAlwaysUseDefaultSites)
202 for (
int i = 0; !Wadseeker::defaultSites[i].isEmpty(); ++i)
204 urlList << Wadseeker::defaultSites[i];
208 wadseeker.setPrimarySites(urlList);
210 updateTimer.setSingleShot(
false);
211 updateTimer.start(UPDATE_INTERVAL_MS);
216 if (!isInstantiated())
219 return currentInstance;
226 if (!isInstantiated())
229 return currentInstance;
237 if (interface != NULL)
239 interface->setupAutomatic();
240 interface->d->preventGame =
true;
245 void WadseekerInterface::displayMessage(
const QString& message, WadseekerLib::MessageType type,
bool bPrependErrorsWithMessageType)
247 QString strProcessedMessage;
249 bool bPrependWithNewline =
false;
250 QString wrapHtmlLeft =
"<div style=\"%1\">";
251 QString wrapHtmlRight =
"</div>";
256 case WadseekerLib::CriticalError:
257 htmlStyle = QString(
"color: %1; font-weight: bold;").arg(colorHtmlMessageFatalError);
258 bPrependWithNewline =
true;
260 if (bPrependErrorsWithMessageType)
262 strProcessedMessage = tr(
"CRITICAL ERROR: %1").arg(message);
266 strProcessedMessage = message;
272 case WadseekerLib::Error:
273 htmlStyle = QString(
"color: %1;").arg(colorHtmlMessageError);
275 if (bPrependErrorsWithMessageType)
277 strProcessedMessage = tr(
"Error: %1").arg(message);
281 strProcessedMessage = message;
285 case WadseekerLib::Notice:
286 htmlStyle = QString(
"color: %1;").arg(colorHtmlMessageNotice);
288 strProcessedMessage = message;
291 case WadseekerLib::NoticeImportant:
292 htmlStyle = QString(
"color: %1; font-weight: bold;").arg(colorHtmlMessageNotice);
293 bPrependWithNewline =
true;
295 strProcessedMessage = message;
299 if (bPrependWithNewline && !d->teWadseekerOutput->toPlainText().isEmpty())
301 strProcessedMessage =
"<br>" + strProcessedMessage;
304 wrapHtmlLeft = wrapHtmlLeft.arg(htmlStyle);
306 strProcessedMessage = wrapHtmlLeft + strProcessedMessage + wrapHtmlRight;
308 d->teWadseekerOutput->append(strProcessedMessage);
311 void WadseekerInterface::fileDownloadSuccessful(
const QString& filename)
313 successfulWads << filename;
314 d->twWads->setFileSuccessful(filename);
317 void WadseekerInterface::initMessageColors()
319 colorHtmlMessageNotice = gConfig.wadseeker.colorMessageNotice;
320 colorHtmlMessageError = gConfig.wadseeker.colorMessageError;
321 colorHtmlMessageFatalError = gConfig.wadseeker.colorMessageCriticalError;
324 bool WadseekerInterface::isInstantiated()
326 return currentInstance != NULL;
329 void WadseekerInterface::message(
const QString& message, WadseekerLib::MessageType type)
331 displayMessage(message, type,
true);
334 void WadseekerInterface::registerUpdateRequest()
340 void WadseekerInterface::reject()
349 this->done(Rejected);
354 void WadseekerInterface::resetTitleToDefault()
356 setWindowTitle(tr(
"Wadseeker"));
359 void WadseekerInterface::seekStarted(
const QStringList& filenames)
361 d->teWadseekerOutput->clear();
362 d->pbOverallProgress->setValue(0);
363 d->taskbarProgress->setValue(0);
364 displayMessage(
"Seek started on filenames: " + filenames.join(
", "), WadseekerLib::Notice,
false);
366 seekedWads = filenames;
367 successfulWads.clear();
368 d->twSites->setRowCount(0);
369 d->twWads->setRowCount(0);
370 setStateDownloading();
372 foreach (
const QString& name, filenames)
374 d->twWads->addFile(name);
378 void WadseekerInterface::setStateDownloading()
380 d->btnClose->setText(tr(
"Abort"));
381 d->btnDownload->setEnabled(
false);
382 d->taskbarProgress->show();
386 void WadseekerInterface::setStateWaiting()
388 d->btnClose->setText(tr(
"Close"));
389 d->btnDownload->setEnabled(
true);
390 d->taskbarProgress->hide();
394 void WadseekerInterface::setupAutomatic()
398 d->btnDownload->hide();
399 d->leWadName->hide();
410 d->leWadName->setText(wads.join(
", "));
414 void WadseekerInterface::setupIdgames()
416 QString idgamesUrl = Wadseeker::defaultIdgamesUrl();
417 bool useIdgames =
true;
419 useIdgames = gConfig.wadseeker.bSearchInIdgames;
420 idgamesUrl = gConfig.wadseeker.idgamesURL;
422 wadseeker.setIdgamesEnabled(useIdgames);
423 wadseeker.setIdgamesUrl(idgamesUrl);
424 wadseeker.setWadArchiveEnabled(gConfig.wadseeker.bSearchInWadArchive);
427 void WadseekerInterface::showEvent(QShowEvent* event)
431 #if QT_VERSION >= 0x050000 432 d->taskbarButton->setWindow(windowHandle());
438 startSeeking(seekedWads);
443 void WadseekerInterface::serviceStarted(
const QString &service)
445 d->twSites->addService(service);
448 void WadseekerInterface::serviceFinished(
const QString &service)
450 d->twSites->removeService(service);
453 void WadseekerInterface::siteFinished(
const QUrl& site)
455 d->twSites->removeUrl(site);
456 displayMessage(
"Site finished: " + site.toString(), WadseekerLib::Notice,
false);
459 void WadseekerInterface::siteProgress(
const QUrl& site, qint64 bytes, qint64 total)
461 d->twSites->setUrlProgress(site, bytes, total);
464 void WadseekerInterface::siteRedirect(
const QUrl& oldUrl,
const QUrl& newUrl)
466 d->twSites->removeUrl(oldUrl);
467 d->twSites->addUrl(newUrl);
468 displayMessage(
"Site redirect: " + oldUrl.toString() +
" -> " + newUrl.toString(), WadseekerLib::Notice,
false);
471 void WadseekerInterface::siteStarted(
const QUrl& site)
473 d->twSites->addUrl(site);
474 displayMessage(
"Site started: " + site.toString(), WadseekerLib::Notice,
false);
477 void WadseekerInterface::startSeeking(
const QStringList& seekedFilesList)
479 if (seekedFilesList.isEmpty())
483 d->bCompletedSuccessfully =
false;
487 QStringList seekedFilesListFormatted;
488 foreach (QString filenameFormatted, seekedFilesList)
490 filenameFormatted = filenameFormatted.trimmed();
492 seekedFilesListFormatted << filenameFormatted;
497 wadseeker.setTargetDirectory(gConfig.wadseeker.targetDirectory);
498 wadseeker.setCustomSite(customSite);
499 wadseeker.setMaximumConcurrentSeeks(gConfig.wadseeker.maxConcurrentSiteDownloads);
500 wadseeker.setMaximumConcurrentDownloads(gConfig.wadseeker.maxConcurrentWadDownloads);
501 wadseeker.startSeek(seekedFilesListFormatted);
504 void WadseekerInterface::updateProgressBar()
506 double totalPercentage = d->twWads->totalDonePercentage();
507 unsigned progressBarValue = (unsigned)(totalPercentage * 100.0);
509 d->pbOverallProgress->setValue(progressBarValue);
510 d->taskbarProgress->setValue(progressBarValue);
513 void WadseekerInterface::updateTitle()
519 double totalPercentage = d->twWads->totalDonePercentage();
520 if (totalPercentage < 0.0)
522 totalPercentage = 0.0;
525 setWindowTitle(tr(
"[%1%] Wadseeker").arg(totalPercentage, 6,
'f', 2));
531 resetTitleToDefault();
536 QStringList WadseekerInterface::unsuccessfulWads()
const 538 QStringList allWads = seekedWads;
540 foreach (
const QString& success, successfulWads)
542 allWads.removeAll(success);
548 void WadseekerInterface::wadsTableRightClicked(
const QModelIndex& index,
const QPoint& cursorPosition)
553 QString fileName = d->twWads->fileNameAtRow(index.row());
554 if (!wadseeker.isDownloadingFile(fileName))
556 menu->actionSkipCurrentSite->setEnabled(
false);
559 QAction* pResult = menu->exec();
561 if (pResult == menu->actionSkipCurrentSite)
563 QString wadName = d->twWads->fileNameAtRow(index.row());
564 d->twWads->setFileUrl(fileName, QUrl());
566 wadseeker.skipFileCurrentUrl(wadName);
568 else if (pResult != NULL)
570 QMessageBox::warning(
this, tr(
"Context menu error"), tr(
"Unknown action selected."));
Platform-agnostic wrapper for QWinTaskbarProgress.
void setWads(const QStringList &wads)
Sets WADs to seek.
Wadseeker dialog box, only one instance is allowed.