Skip to content

Commit

Permalink
Updater: Fully functional updater settings dialog
Browse files Browse the repository at this point in the history
The settings can be viewed and changed in the dialog.
  • Loading branch information
skyjake committed May 27, 2012
1 parent 35b3caf commit 8f50889
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 25 deletions.
12 changes: 6 additions & 6 deletions doomsday/engine/portable/src/updater/updatersettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@
#define STK_DELETE "updater/delete"
#define STK_DOWNLOAD_PATH "updater/downloadPath"

static de::String defaultDownloadPath()
{
return QDesktopServices::storageLocation(QDesktopServices::TempLocation);
}

UpdaterSettings::UpdaterSettings()
{}

Expand Down Expand Up @@ -61,7 +56,7 @@ void UpdaterSettings::setFrequency(UpdaterSettings::Frequency freq)
QSettings().setValue(STK_FREQUENCY, int(freq));
}

void UpdaterSettings::channel(UpdaterSettings::Channel channel)
void UpdaterSettings::setChannel(UpdaterSettings::Channel channel)
{
QSettings().setValue(STK_CHANNEL, int(channel));
}
Expand Down Expand Up @@ -90,3 +85,8 @@ void UpdaterSettings::useDefaultDownloadPath()
{
setDownloadPath(defaultDownloadPath());
}

de::String UpdaterSettings::defaultDownloadPath()
{
return QDesktopServices::storageLocation(QDesktopServices::TempLocation);
}
4 changes: 3 additions & 1 deletion doomsday/engine/portable/src/updater/updatersettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ class UpdaterSettings
de::String downloadPath() const;

void setFrequency(Frequency freq);
void channel(Channel channel);
void setChannel(Channel channel);
void setLastCheckTime(const de::Time& time);
void setOnlyCheckManually(bool onlyManually);
void setDeleteAfterUpdate(bool deleteAfter);
void setDownloadPath(de::String downloadPath);
void useDefaultDownloadPath();

static de::String defaultDownloadPath();
};

#endif // LIBDENG_UPDATERSETTINGS_H
63 changes: 45 additions & 18 deletions doomsday/engine/portable/src/updater/updatersettingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ struct UpdaterSettingsDialog::Instance
QFormLayout* form = new QFormLayout;
mainLayout->addLayout(form);

/*
bool deleteAfterUpdate() const;
bool isDefaultDownloadPath() const;
de::String downloadPath() const;
*/
neverCheck = new QCheckBox("Never check for updates automatically");
form->addRow(neverCheck);

Expand All @@ -49,7 +44,7 @@ struct UpdaterSettingsDialog::Instance

pathList = new QComboBox;
pathList->addItem(QDesktopServices::displayName(QDesktopServices::TempLocation),
QDesktopServices::storageLocation(QDesktopServices::TempLocation));
UpdaterSettings::defaultDownloadPath());
pathList->addItem("Select folder...", "");
form->addRow("Download location:", pathList);

Expand All @@ -60,7 +55,6 @@ struct UpdaterSettingsDialog::Instance
mainLayout->addWidget(bbox);

// Buttons.
//QPushButton* apply = bbox->addButton(QDialogButtonBox::Apply);
QPushButton* ok = bbox->addButton(QDialogButtonBox::Ok);
QPushButton* cancel = bbox->addButton(QDialogButtonBox::Cancel);

Expand All @@ -69,26 +63,54 @@ struct UpdaterSettingsDialog::Instance
// Connections.
QObject::connect(neverCheck, SIGNAL(toggled(bool)), self, SLOT(neverCheckToggled(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()));
}

~Instance()
{

}

void fetch()
{
neverCheck->setChecked(UpdaterSettings().onlyCheckManually());
freqList->setEnabled(!UpdaterSettings().onlyCheckManually());
freqList->setCurrentIndex(freqList->findData(UpdaterSettings().frequency()));
channelList->setCurrentIndex(channelList->findData(UpdaterSettings().channel()));
setDownloadPath(UpdaterSettings().downloadPath());
deleteAfter->setChecked(UpdaterSettings().deleteAfterUpdate());
}

void apply()
{
UpdaterSettings st;
st.setOnlyCheckManually(neverCheck->isChecked());
int sel = freqList->currentIndex();
if(sel >= 0)
{
st.setFrequency(UpdaterSettings::Frequency(freqList->itemData(sel).toInt()));
}
sel = channelList->currentIndex();
if(sel >= 0)
{
st.setChannel(UpdaterSettings::Channel(channelList->itemData(sel).toInt()));
}
st.setDownloadPath(pathList->itemData(pathList->currentIndex()).toString());
st.setDeleteAfterUpdate(deleteAfter->isChecked());
}

void setDownloadPath(const QString& dir)
{
if(dir != UpdaterSettings::defaultDownloadPath())
{
// Remove extra items.
while(pathList->count() > 2)
{
pathList->removeItem(0);
}
pathList->insertItem(0, QDir(dir).dirName(), dir);
pathList->setCurrentIndex(0);
}
else
{
pathList->setCurrentIndex(pathList->findData(dir));
}
}
};

Expand All @@ -103,6 +125,12 @@ UpdaterSettingsDialog::~UpdaterSettingsDialog()
delete d;
}

void UpdaterSettingsDialog::accept()
{
d->apply();
QDialog::accept();
}

void UpdaterSettingsDialog::neverCheckToggled(bool set)
{
d->freqList->setEnabled(!set);
Expand All @@ -116,12 +144,11 @@ void UpdaterSettingsDialog::pathActivated(int index)
QString dir = QFileDialog::getExistingDirectory(this, "Download Folder", QDir::homePath());
if(!dir.isEmpty())
{
// Remove extra items.
while(d->pathList->count() > 2)
d->pathList->removeItem(0);

d->pathList->insertItem(0, QDir(dir).dirName(), dir);
d->pathList->setCurrentIndex(0);
d->setDownloadPath(dir);
}
else
{
d->setDownloadPath(UpdaterSettings::defaultDownloadPath());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class UpdaterSettingsDialog : public QDialog
signals:

public slots:
void accept();
void neverCheckToggled(bool);
void pathActivated(int index);

Expand Down

0 comments on commit 8f50889

Please sign in to comment.