cfgautoupdates.cpp
1 //------------------------------------------------------------------------------
2 // cfgautoupdates.cpp
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library 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 GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; 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 : ConfigPage(parent)
39 {
40  d->setupUi(this);
41  // Hide if not supported on target platform.
42  #ifndef WITH_AUTOUPDATES
43  d->programUpdateArea->hide();
44  #endif
45  layout()->setAlignment(Qt::AlignTop);
46 }
47 
48 CFGAutoUpdates::~CFGAutoUpdates()
49 {
50 }
51 
52 void CFGAutoUpdates::initUpdateChannels()
53 {
54  QList<UpdateChannel> channels = UpdateChannel::allChannels();
55  foreach (const UpdateChannel& channel, channels)
56  {
57  d->cboUpdateChannel->addItem(channel.translatedName(),
58  channel.name());
59  }
60 }
61 
62 void CFGAutoUpdates::onUpdateChannelChange(int index)
63 {
64  // Update description field.
65  QString name = d->cboUpdateChannel->itemData(index).toString();
66  UpdateChannel channel = UpdateChannel::fromName(name);
67  d->pteChannelDescription->setPlainText(channel.translatedDescription());
68 }
69 
71 {
72  initUpdateChannels();
73 
74  switch (gConfig.autoUpdates.updateMode)
75  {
77  d->rbDisabled->setChecked(true);
78  break;
79  default:
81  d->rbNotifyButDontInstall->setChecked(true);
82  break;
84  d->rbInstallAutomatically->setChecked(true);
85  break;
86  }
87  QString channelName = gConfig.autoUpdates.updateChannelName;
88  int channelIdx = d->cboUpdateChannel->findData(channelName);
89  if (channelIdx < 0)
90  {
91  // Default to "stable" if user tampered with the INI file.
92  channelIdx = d->cboUpdateChannel->findData(UpdateChannel::mkStable().name());
93  }
94  d->cboUpdateChannel->setCurrentIndex(channelIdx);
95  d->cbIp2cAutoUpdate->setChecked(gConfig.doomseeker.bIP2CountryAutoUpdate);
96 }
97 
99 {
100  if (d->rbDisabled->isChecked())
101  {
102  gConfig.autoUpdates.updateMode = DoomseekerConfig::AutoUpdates::UM_Disabled;
103  }
104  else if (d->rbNotifyButDontInstall->isChecked())
105  {
106  gConfig.autoUpdates.updateMode = DoomseekerConfig::AutoUpdates::UM_NotifyOnly;
107  }
108  else if (d->rbInstallAutomatically->isChecked())
109  {
110  gConfig.autoUpdates.updateMode = DoomseekerConfig::AutoUpdates::UM_FullAuto;
111  }
112  else
113  {
114  assert(false && "CFGAutoUpdates::saveSettings() - No radio button is checked.");
115  }
116  gConfig.autoUpdates.updateChannelName = d->cboUpdateChannel->itemData(
117  d->cboUpdateChannel->currentIndex()).toString();
118  gConfig.doomseeker.bIP2CountryAutoUpdate = d->cbIp2cAutoUpdate->isChecked();
119 }
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 ConfigPage.
void readSettings()
Reimplement this to read settings from config into widgets.
static UpdateChannel mkStable()
Creates "stable" channel object.
User is only notified of the update and decides if it should be installed.
Base class for configuration pages.
Definition: configpage.h:44