diff --git a/doomsday/client/include/ui/widgets/taskbarwidget.h b/doomsday/client/include/ui/widgets/taskbarwidget.h index c23de369ae..a92f27864e 100644 --- a/doomsday/client/include/ui/widgets/taskbarwidget.h +++ b/doomsday/client/include/ui/widgets/taskbarwidget.h @@ -59,6 +59,7 @@ public slots: void openMainMenu(); void unloadGame(); void showAbout(); + void showUpdaterSettings(); signals: void opened(); diff --git a/doomsday/client/src/ui/widgets/taskbarwidget.cpp b/doomsday/client/src/ui/widgets/taskbarwidget.cpp index eae607f076..a24869b468 100644 --- a/doomsday/client/src/ui/widgets/taskbarwidget.cpp +++ b/doomsday/client/src/ui/widgets/taskbarwidget.cpp @@ -38,7 +38,7 @@ #include #include -#include "../../updater/versioninfo.h" +#include "versioninfo.h" #include "dd_main.h" using namespace de; @@ -47,6 +47,7 @@ using namespace ui; static TimeDelta OPEN_CLOSE_SPAN = 0.2; static uint POS_PANEL = 0; static uint POS_UNLOAD = 3; +static uint POS_UPDATER_SETTINGS = 6; DENG2_PIMPL(TaskBarWidget), public IGameChangeObserver @@ -492,3 +493,16 @@ void TaskBarWidget::showAbout() about->setDeleteAfterDismissed(true); about->exec(root()); } + +void TaskBarWidget::showUpdaterSettings() +{ + UpdaterSettingsDialog *dlg = new UpdaterSettingsDialog; + dlg->setDeleteAfterDismissed(true); + if(d->mainMenu->isOpen()) + { + dlg->setAnchorAndOpeningDirection(d->mainMenu->menu().organizer(). + itemWidget(POS_UPDATER_SETTINGS)->hitRule(), + ui::Left); + } + dlg->exec(root()); +} diff --git a/doomsday/client/src/updater/updateavailabledialog.cpp b/doomsday/client/src/updater/updateavailabledialog.cpp index 6f8f98b697..cc9631e6dc 100644 --- a/doomsday/client/src/updater/updateavailabledialog.cpp +++ b/doomsday/client/src/updater/updateavailabledialog.cpp @@ -256,6 +256,7 @@ void UpdateAvailableDialog::showWhatsNew() void UpdateAvailableDialog::editSettings() { + /* UpdaterSettingsDialog st(this); if(st.exec()) { @@ -265,7 +266,7 @@ void UpdateAvailableDialog::editSettings() // Rerun the check. emit checkAgain(); - } + }*/ } void UpdateAvailableDialog::recenterDialog() diff --git a/doomsday/client/src/updater/updater.cpp b/doomsday/client/src/updater/updater.cpp index 413a5ddc62..c0d7fb2fbb 100644 --- a/doomsday/client/src/updater/updater.cpp +++ b/doomsday/client/src/updater/updater.cpp @@ -132,7 +132,7 @@ DENG2_PIMPL(Updater) DownloadDialog* download; bool alwaysShowNotification; UpdateAvailableDialog* availableDlg; - UpdaterSettingsDialog* settingsDlg; + //UpdaterSettingsDialog* settingsDlg; bool backToFullscreen; bool savingSuggested; @@ -146,7 +146,7 @@ DENG2_PIMPL(Updater) network(0), download(0), availableDlg(0), - settingsDlg(0), + //settingsDlg(0), backToFullscreen(false), savingSuggested(false) { @@ -172,7 +172,7 @@ DENG2_PIMPL(Updater) ~Instance() { - if(settingsDlg) delete settingsDlg; + //if(settingsDlg) delete settingsDlg; // Delete the ongoing download. if(download) delete download; @@ -240,6 +240,7 @@ DENG2_PIMPL(Updater) void showSettingsNonModal() { + /* if(!settingsDlg) { settingsDlg = new UpdaterSettingsDialog(&ClientWindow::main()); @@ -250,6 +251,7 @@ DENG2_PIMPL(Updater) settingsDlg->fetch(); } settingsDlg->open(); + */ } void queryLatestVersion(bool notifyAlways) diff --git a/doomsday/client/src/updater/updatersettings.cpp b/doomsday/client/src/updater/updatersettings.cpp index ea472fdb83..1d14146ac2 100644 --- a/doomsday/client/src/updater/updatersettings.cpp +++ b/doomsday/client/src/updater/updatersettings.cpp @@ -199,19 +199,29 @@ de::String UpdaterSettings::lastCheckAgo() const if(delta < 60.0) { t = delta.asMilliSeconds() / 1000; - return de::String("%1 second%2 ago").arg(t).arg(t != 1? "s" : ""); + return de::String(QObject::tr("%1 %2 ago")).arg(t). + arg(t != 1? QObject::tr("seconds") : QObject::tr("second")); } t = delta.asMinutes(); if(t <= 60) { - return de::String("%1 minute%2 ago").arg(t).arg(t != 1? "s" : ""); + return de::String(QObject::tr("%1 %2 ago")).arg(t). + arg(t != 1? QObject::tr("minutes") : QObject::tr("minute")); } t = delta.asHours(); if(t <= 24) { - return de::String("%1 hour%2 ago").arg(t).arg(t != 1? "s" : ""); + return de::String(QObject::tr("%1 %2 ago")).arg(t). + arg(t != 1? QObject::tr("hours") : QObject::tr("hour")); + } + + t = delta.asDays(); + if(t <= 7) + { + return de::String(QObject::tr("%1 %2 ago")).arg(t). + arg(t != 1? QObject::tr("days") : QObject::tr("day")); } return de::String("on " + when.asText(de::Time::FriendlyFormat)); diff --git a/doomsday/client/src/updater/updatersettingsdialog.cpp b/doomsday/client/src/updater/updatersettingsdialog.cpp index e10bcda024..3e3a8af0fa 100644 --- a/doomsday/client/src/updater/updatersettingsdialog.cpp +++ b/doomsday/client/src/updater/updatersettingsdialog.cpp @@ -1,4 +1,4 @@ -/** @file updatersettingsdialog.cpp Dialog for configuring automatic updates. +/** @file updatersettingsdialog.cpp Dialog for configuring automatic updates. * @ingroup updater * * @authors Copyright © 2012-2013 Jaakko Keränen @@ -19,19 +19,14 @@ * 02110-1301 USA */ -#include "updatersettingsdialog.h" -#include "updatersettings.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "updater/updatersettingsdialog.h" +#include "updater/updatersettings.h" +#include "ui/widgets/labelwidget.h" +#include "ui/widgets/choicewidget.h" +#include "ui/widgets/variabletogglewidget.h" +#include "ui/widgets/gridlayout.h" #include -#include +#include using namespace de; @@ -49,70 +44,79 @@ static QString defaultLocationName() return name; } -DENG2_PIMPL(UpdaterSettingsDialog) +DENG2_PIMPL(UpdaterSettingsDialog), +DENG2_OBSERVES(ToggleWidget, Toggle) { - QCheckBox* autoCheck; - QComboBox* freqList; - QLabel* lastChecked; - QComboBox* channelList; - QComboBox* pathList; - QCheckBox* deleteAfter; - - Instance(Public &i) : Base(i) + ToggleWidget *autoCheck; + ChoiceWidget *freqs; + LabelWidget *lastChecked; + ChoiceWidget *channels; + ChoiceWidget *paths; + ToggleWidget *deleteAfter; + + Instance(Public *i) : Base(i) { - // As a modal dialog it is implicitly clear that this belongs to - // Doomsday, so we don't need to have the name in the window title. - self.setWindowTitle(tr("Updater Settings")); + ScrollAreaWidget &area = self.area(); + + // Create the widgets. + area.add(autoCheck = new ToggleWidget); + area.add(freqs = new ChoiceWidget); + area.add(lastChecked = new LabelWidget); + area.add(channels = new ChoiceWidget); + area.add(paths = new ChoiceWidget); + area.add(deleteAfter = new ToggleWidget); - QVBoxLayout* mainLayout = new QVBoxLayout; - self.setLayout(mainLayout); + LabelWidget *releaseLabel = new LabelWidget; + area.add(releaseLabel); - QFormLayout* form = new QFormLayout; - mainLayout->addLayout(form); + LabelWidget *pathLabel = new LabelWidget; + area.add(pathLabel); - freqList = new QComboBox; - freqList->addItem(tr("At startup"), UpdaterSettings::AtStartup); - freqList->addItem(tr("Daily"), UpdaterSettings::Daily); - freqList->addItem(tr("Biweekly"), UpdaterSettings::Biweekly); - freqList->addItem(tr("Weekly"), UpdaterSettings::Weekly); - freqList->addItem(tr("Monthly"), UpdaterSettings::Monthly); + autoCheck->setText(tr("Check for updates:")); - autoCheck = new QCheckBox(tr("&Check for updates:")); - form->addRow(autoCheck, freqList); - QLayoutItem* item = form->itemAt(0, QFormLayout::LabelRole); - item->setAlignment(Qt::AlignVCenter); + freqs->items() + << new ChoiceItem(tr("At startup"), UpdaterSettings::AtStartup) + << new ChoiceItem(tr("Daily"), UpdaterSettings::Daily) + << new ChoiceItem(tr("Biweekly"), UpdaterSettings::Biweekly) + << new ChoiceItem(tr("Weekly"), UpdaterSettings::Weekly) + << new ChoiceItem(tr("Monthly"), UpdaterSettings::Monthly); - lastChecked = new QLabel; - form->addRow(new QWidget, lastChecked); + lastChecked->setMargin(ui::Up, ""); - channelList = new QComboBox; - channelList->addItem(tr("Stable"), UpdaterSettings::Stable); - channelList->addItem(tr("Unstable/Candidate"), UpdaterSettings::Unstable); - form->addRow(tr("&Release type:"), channelList); + releaseLabel->setText("Release type:"); - pathList = new QComboBox; - pathList->addItem(defaultLocationName(), - UpdaterSettings::defaultDownloadPath().toString()); - pathList->addItem(tr("Select folder..."), ""); - form->addRow(tr("&Download location:"), pathList); + channels->items() + << new ChoiceItem(tr("Stable"), UpdaterSettings::Stable) + << new ChoiceItem(tr("Unstable/Candidate"), UpdaterSettings::Unstable); - deleteAfter = new QCheckBox(tr("D&elete file after install")); - form->addRow(new QWidget, deleteAfter); + pathLabel->setText(tr("Download location:")); - QDialogButtonBox* bbox = new QDialogButtonBox; - mainLayout->addWidget(bbox); + paths->items() + << new ChoiceItem(defaultLocationName(), + UpdaterSettings::defaultDownloadPath().toString()); - // Buttons. - QPushButton* ok = bbox->addButton(QDialogButtonBox::Ok); - QPushButton* cancel = bbox->addButton(QDialogButtonBox::Cancel); + deleteAfter->setText(tr("Delete file after install")); fetch(); - // Connections. - QObject::connect(autoCheck, SIGNAL(toggled(bool)), &self, SLOT(autoCheckToggled(bool))); - QObject::connect(pathList, SIGNAL(activated(int)), &self, SLOT(pathActivated(int))); - QObject::connect(ok, SIGNAL(clicked()), &self, SLOT(accept())); - QObject::connect(cancel, SIGNAL(clicked()), &self, SLOT(reject())); + autoCheck->audienceForToggle += this; + + // Place the widgets into a grid. + GridLayout layout(area.contentRule().left(), area.contentRule().top()); + layout.setGridSize(2, 0); + layout.setColumnAlignment(0, ui::AlignRight); // Labels aligned to the right. + + layout << *autoCheck << *freqs + << Const(0) << *lastChecked + << *releaseLabel << *channels + << *pathLabel << *paths + << Const(0) << *deleteAfter; + + area.setContentSize(layout.width(), layout.height()); + + self.buttons().items() + << new DialogButtonItem(DialogWidget::Default | DialogWidget::Accept) + << new DialogButtonItem(DialogWidget::Reject); } void fetch() @@ -122,42 +126,52 @@ DENG2_PIMPL(UpdaterSettingsDialog) String ago = st.lastCheckAgo(); if(!ago.isEmpty()) { - lastChecked->setText(tr("Last checked %1.") - .arg(st.lastCheckAgo())); + lastChecked->setText(_E(D)_E(t) + tr("Last checked %1.").arg(st.lastCheckAgo())); } else { - lastChecked->setText(tr("Never checked.")); + lastChecked->setText(_E(D)_E(t) + tr("Never checked.")); } - autoCheck->setChecked(!st.onlyCheckManually()); - freqList->setEnabled(!st.onlyCheckManually()); - freqList->setCurrentIndex(freqList->findData(st.frequency())); - channelList->setCurrentIndex(channelList->findData(st.channel())); + autoCheck->setActive(!st.onlyCheckManually()); + freqs->enable(!st.onlyCheckManually()); + freqs->setSelected(freqs->items().findData(st.frequency())); + channels->setSelected(channels->items().findData(st.channel())); setDownloadPath(st.downloadPath()); - deleteAfter->setChecked(st.deleteAfterUpdate()); + deleteAfter->setActive(st.deleteAfterUpdate()); + } + + void toggleStateChanged(ToggleWidget &toggle) + { + if(&toggle == autoCheck) + { + freqs->enable(autoCheck->isActive()); + } } void apply() { UpdaterSettings st; - st.setOnlyCheckManually(!autoCheck->isChecked()); - int sel = freqList->currentIndex(); - if(sel >= 0) + + st.setOnlyCheckManually(autoCheck->isInactive()); + ui::Context::Pos sel = freqs->selected(); + if(sel != ui::Context::InvalidPos) { - st.setFrequency(UpdaterSettings::Frequency(freqList->itemData(sel).toInt())); + st.setFrequency(UpdaterSettings::Frequency(freqs->items().at(sel).data().toInt())); } - sel = channelList->currentIndex(); - if(sel >= 0) + sel = channels->selected(); + if(sel != ui::Context::InvalidPos) { - st.setChannel(UpdaterSettings::Channel(channelList->itemData(sel).toInt())); + st.setChannel(UpdaterSettings::Channel(channels->items().at(sel).data().toInt())); } - st.setDownloadPath(pathList->itemData(pathList->currentIndex()).toString()); - st.setDeleteAfterUpdate(deleteAfter->isChecked()); + //st.setDownloadPath(pathList->itemData(pathList->currentIndex()).toString()); + st.setDeleteAfterUpdate(deleteAfter->isActive()); } - void setDownloadPath(const QString& dir) + void setDownloadPath(QString const &/*dir*/) { + paths->setSelected(0); + /* if(dir != UpdaterSettings::defaultDownloadPath()) { // Remove extra items. @@ -171,35 +185,25 @@ DENG2_PIMPL(UpdaterSettingsDialog) else { pathList->setCurrentIndex(pathList->findData(dir)); - } + }*/ } }; -UpdaterSettingsDialog::UpdaterSettingsDialog(QWidget *parent) - : UpdaterDialog(parent), d(new Instance(*this)) +UpdaterSettingsDialog::UpdaterSettingsDialog(String const &name) + : DialogWidget(name), d(new Instance(this)) {} -void UpdaterSettingsDialog::fetch() -{ - d->fetch(); -} - -void UpdaterSettingsDialog::accept() -{ - d->apply(); - QDialog::accept(); -} - -void UpdaterSettingsDialog::reject() +void UpdaterSettingsDialog::finish(int result) { - QDialog::reject(); -} + if(result) + { + d->apply(); + } -void UpdaterSettingsDialog::autoCheckToggled(bool set) -{ - d->freqList->setEnabled(set); + DialogWidget::finish(result); } +/* void UpdaterSettingsDialog::pathActivated(int index) { QString path = d->pathList->itemData(index).toString(); @@ -216,3 +220,4 @@ void UpdaterSettingsDialog::pathActivated(int index) } } } +*/