cfgautoupdates.cpp
1 //------------------------------------------------------------------------------
2 // cfgautoupdates.cpp
3 //------------------------------------------------------------------------------
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301, USA.
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2012 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #include "cfgautoupdates.h"
24 #include "ui_cfgautoupdates.h"
25 
26 #include "configuration/doomseekerconfig.h"
27 #include "updater/updatechannel.h"
28 #include "log.h"
29 #include <cassert>
30 
31 DClass<CFGAutoUpdates> : public Ui::CFGAutoUpdates
32 {
33 };
34 
35 DPointered(CFGAutoUpdates)
36 
37 CFGAutoUpdates::CFGAutoUpdates(QWidget *parent)
38 : ConfigurationBaseBox(parent)
39 {
40  d->setupUi(this);
41 }
42 
43 CFGAutoUpdates::~CFGAutoUpdates()
44 {
45 }
46 
47 void CFGAutoUpdates::initUpdateChannels()
48 {
49  QList<UpdateChannel> channels = UpdateChannel::allChannels();
50  foreach (const UpdateChannel& channel, channels)
51  {
52  d->cboUpdateChannel->addItem(channel.translatedName(),
53  channel.name());
54  }
55 }
56 
57 void CFGAutoUpdates::onUpdateChannelChange(int index)
58 {
59  // Update description field.
60  QString name = d->cboUpdateChannel->itemData(index).toString();
61  UpdateChannel channel = UpdateChannel::fromName(name);
62  d->pteChannelDescription->setPlainText(channel.translatedDescription());
63 }
64 
66 {
67  initUpdateChannels();
68 
69  switch (gConfig.autoUpdates.updateMode)
70  {
72  d->rbDisabled->setChecked(true);
73  break;
74  default:
76  d->rbNotifyButDontInstall->setChecked(true);
77  break;
79  d->rbInstallAutomatically->setChecked(true);
80  break;
81  }
82  QString channelName = gConfig.autoUpdates.updateChannelName;
83  int channelIdx = d->cboUpdateChannel->findData(channelName);
84  if (channelIdx < 0)
85  {
86  // Default to "stable" if user tampered with the INI file.
87  channelIdx = d->cboUpdateChannel->findData(UpdateChannel::mkStable().name());
88  }
89  d->cboUpdateChannel->setCurrentIndex(channelIdx);
90 }
91 
93 {
94  if (d->rbDisabled->isChecked())
95  {
96  gConfig.autoUpdates.updateMode = DoomseekerConfig::AutoUpdates::UM_Disabled;
97  }
98  else if (d->rbNotifyButDontInstall->isChecked())
99  {
100  gConfig.autoUpdates.updateMode = DoomseekerConfig::AutoUpdates::UM_NotifyOnly;
101  }
102  else if (d->rbInstallAutomatically->isChecked())
103  {
104  gConfig.autoUpdates.updateMode = DoomseekerConfig::AutoUpdates::UM_FullAuto;
105  }
106  else
107  {
108  assert(false && "CFGAutoUpdates::saveSettings() - No radio button is checked.");
109  }
110  gConfig.autoUpdates.updateChannelName = d->cboUpdateChannel->itemData(
111  d->cboUpdateChannel->currentIndex()).toString();
112 }
void saveSettings()
Reimplement this to write settings to config from widgets.
static UpdateChannel fromName(const QString &name)
Creates object from its internal name.
static QList< UpdateChannel > allChannels()
List of all available channels.
QString name() const
Reimplement this to return a list-displayable name for this ConfigurationBaseBox. ...
void readSettings()
Reimplement this to read settings from config into widgets.
static UpdateChannel mkStable()
Creates "stable" channel object.
Base class for configuration pages.
User is only notified of the update and decides if it should be installed.