/
updatersettingsdialog.cpp
273 lines (235 loc) · 8.77 KB
/
updatersettingsdialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/** @file updatersettingsdialog.cpp Dialog for configuring automatic updates.
* @ingroup updater
*
* @authors Copyright © 2012-2017 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2013 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/
#include "updater/updatersettingsdialog.h"
#include "updater/updatersettings.h"
#include "updater.h"
#include "clientapp.h"
#include <de/LabelWidget>
#include <de/ChoiceWidget>
#include <de/VariableToggleWidget>
#include <de/GridLayout>
#include <de/SignalAction>
#include <de/Log>
#include <QDesktopServices>
using namespace de;
#if 0
static QString defaultLocationName()
{
#ifdef DENG2_QT_5_0_OR_NEWER
QString name = QStandardPaths::displayName(QStandardPaths::CacheLocation);
#else
QString name = QDesktopServices::displayName(QDesktopServices::CacheLocation);
#endif
if (name.isEmpty())
{
name = "Temporary Files";
}
return name;
}
#endif
DENG2_PIMPL(UpdaterSettingsDialog),
DENG2_OBSERVES(ToggleWidget, Toggle)
{
ToggleWidget *autoCheck;
ChoiceWidget *freqs;
LabelWidget *lastChecked;
ChoiceWidget *channels;
//ChoiceWidget *paths;
ToggleWidget *autoDown;
ToggleWidget *deleteAfter;
bool didApply = false;
Impl(Public *i, Mode mode) : Base(i)
{
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(autoDown = new ToggleWidget);
//area.add(paths = new ChoiceWidget);
area.add(deleteAfter = new ToggleWidget);
// The updater Config is changed when the widget state is modified.
QObject::connect(autoCheck, SIGNAL(stateChangedByUser(ToggleWidget::ToggleState)), thisPublic, SLOT(apply()));
QObject::connect(freqs, SIGNAL(selectionChangedByUser(uint)), thisPublic, SLOT(apply()));
QObject::connect(channels, SIGNAL(selectionChangedByUser(uint)), thisPublic, SLOT(apply()));
QObject::connect(autoDown, SIGNAL(stateChangedByUser(ToggleWidget::ToggleState)), thisPublic, SLOT(apply()));
//QObject::connect(paths, SIGNAL(selectionChangedByUser(uint)), thisPublic, SLOT(apply()));
QObject::connect(deleteAfter, SIGNAL(stateChangedByUser(ToggleWidget::ToggleState)), thisPublic, SLOT(apply()));
LabelWidget *releaseLabel = new LabelWidget;
area.add(releaseLabel);
/*LabelWidget *pathLabel = new LabelWidget;
area.add(pathLabel);*/
autoCheck->setText(tr("Check for Updates:"));
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->margins().setTop("");
lastChecked->setFont("separator.annotation");
lastChecked->setTextColor("altaccent");
releaseLabel->setText("Release Type:");
channels->items()
<< new ChoiceItem(tr("Stable"), UpdaterSettings::Stable)
<< new ChoiceItem(tr("Unstable/Candidate"), UpdaterSettings::Unstable);
/*pathLabel->setText(tr("Download location:"));
paths->items()
<< new ChoiceItem(defaultLocationName(),
UpdaterSettings::defaultDownloadPath().toString());*/
autoDown->setText(tr("Download Automatically"));
deleteAfter->setText(tr("Delete File After Install"));
fetch();
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
<< Const(0) << *autoDown
<< Const(0) << *deleteAfter;
//<< *pathLabel << *paths;
area.setContentSize(layout.width(), layout.height());
self().buttons()
<< new DialogButtonItem(DialogWidget::Default | DialogWidget::Accept, tr("Close"));
if (mode == WithApplyAndCheckButton)
{
self().buttons()
<< new DialogButtonItem(DialogWidget::Action, tr("Check Now"),
new SignalAction(thisPublic, SLOT(applyAndCheckNow())));
}
}
void fetch()
{
UpdaterSettings st;
String ago = st.lastCheckAgo();
if (!ago.isEmpty())
{
lastChecked->setText(tr("Last checked %1.").arg(st.lastCheckAgo()));
}
else
{
lastChecked->setText(tr("Never checked."));
}
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());
autoDown->setActive(st.autoDownload());
deleteAfter->setActive(st.deleteAfterUpdate());
}
void toggleStateChanged(ToggleWidget &toggle)
{
if (&toggle == autoCheck)
{
freqs->enable(autoCheck->isActive());
}
}
void apply()
{
UpdaterSettings st;
st.setOnlyCheckManually(autoCheck->isInactive());
ui::Data::Pos sel = freqs->selected();
if (sel != ui::Data::InvalidPos)
{
st.setFrequency(UpdaterSettings::Frequency(freqs->items().at(sel).data().toInt()));
}
sel = channels->selected();
if (sel != ui::Data::InvalidPos)
{
st.setChannel(UpdaterSettings::Channel(channels->items().at(sel).data().toInt()));
}
//st.setDownloadPath(pathList->itemData(pathList->currentIndex()).toString());
st.setAutoDownload(autoDown->isActive());
st.setDeleteAfterUpdate(deleteAfter->isActive());
}
#if 0
void setDownloadPath(QString const &/*dir*/)
{
paths->setSelected(0);
/*
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));
}*/
}
#endif
};
UpdaterSettingsDialog::UpdaterSettingsDialog(Mode mode, String const &name)
: DialogWidget(name, WithHeading), d(new Impl(this, mode))
{
heading().setText(tr("Updater Settings"));
heading().setImage(style().images().image("updater"));
}
bool UpdaterSettingsDialog::settingsHaveChanged() const
{
return d->didApply;
}
void UpdaterSettingsDialog::apply()
{
d->apply();
d->didApply = true;
}
void UpdaterSettingsDialog::applyAndCheckNow()
{
accept();
ClientApp::updater().checkNow();
}
void UpdaterSettingsDialog::finish(int result)
{
if (result)
{
d->apply();
}
DialogWidget::finish(result);
}
/*
void UpdaterSettingsDialog::pathActivated(int index)
{
QString path = d->pathList->itemData(index).toString();
if (path.isEmpty())
{
QString dir = QFileDialog::getExistingDirectory(this, tr("Download Folder"), QDir::homePath());
if (!dir.isEmpty())
{
d->setDownloadPath(dir);
}
else
{
d->setDownloadPath(UpdaterSettings::defaultDownloadPath());
}
}
}
*/