Skip to content

Commit

Permalink
UPDATES: Got rid of hardcoded update intervals list
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Apr 3, 2016
1 parent 0df4c56 commit b44a98c
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 11 deletions.
5 changes: 5 additions & 0 deletions common/module.mk
Expand Up @@ -56,5 +56,10 @@ MODULE_OBJS += \
recorderfile.o
endif

ifdef USE_UPDATES
MODULE_OBJS += \
updates.o
endif

# Include common rules
include $(srcdir)/rules.mk
56 changes: 56 additions & 0 deletions common/updates.cpp
@@ -0,0 +1,56 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* 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 Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/

#include "common/system.h"
#include "common/updates.h"
#include "common/translation.h"

namespace Common {

static const int updateIntervals[] = {
UpdateManager::kUpdateIntervalNotSupported,
UpdateManager::kUpdateIntervalOneDay,
UpdateManager::kUpdateIntervalOneWeek,
UpdateManager::kUpdateIntervalOneMonth,
-1
};

const int *UpdateManager::getUpdateIntervals() {
return updateIntervals;
}

const char *UpdateManager::updateIntervalToString(int interval) {
switch (interval) {
case kUpdateIntervalNotSupported:
return _("Never");
case kUpdateIntervalOneDay:
return _("Daily");
case kUpdateIntervalOneWeek:
return _("Weekly");
case kUpdateIntervalOneMonth:
return _("Monthly");
default:
return _("<Bad value>");
}
}

} // End of namespace Common
9 changes: 6 additions & 3 deletions common/updates.h
Expand Up @@ -20,8 +20,8 @@
*
*/

#ifndef BACKENDS_UPDATES_ABSTRACT_H
#define BACKENDS_UPDATES_ABSTRACT_H
#ifndef COMMON_UPDATES_H
#define COMMON_UPDATES_H

#if defined(USE_UPDATES)

Expand Down Expand Up @@ -93,10 +93,13 @@ class UpdateManager {
* @return the update check interval.
*/
virtual int getUpdateCheckInterval() { return kUpdateIntervalNotSupported; }

static const int *getUpdateIntervals();
static const char *updateIntervalToString(int interval);
};

} // End of namespace Common

#endif

#endif // BACKENDS_UPDATES_ABSTRACT_H
#endif // COMMON_UPDATES_H
10 changes: 6 additions & 4 deletions gui/options.cpp
Expand Up @@ -1234,10 +1234,12 @@ GlobalOptionsDialog::GlobalOptionsDialog()
_updatesPopUpDesc = new StaticTextWidget(tab, "GlobalOptions_Misc.UpdatesPopupDesc", _("Update check:"), _("How often to check ScummVM updates"));
_updatesPopUp = new PopUpWidget(tab, "GlobalOptions_Misc.UpdatesPopup");

_updatesPopUp->appendEntry(_("Never"), Common::UpdateManager::kUpdateIntervalNotSupported);
_updatesPopUp->appendEntry(_("Daily"), Common::UpdateManager::kUpdateIntervalOneDay);
_updatesPopUp->appendEntry(_("Weekly"), Common::UpdateManager::kUpdateIntervalOneWeek);
_updatesPopUp->appendEntry(_("Monthly"), Common::UpdateManager::kUpdateIntervalOneMonth);
const int *vals = Common::UpdateManager::getUpdateIntervals();

while (*vals != -1) {
_updatesPopUp->appendEntry(Common::UpdateManager::updateIntervalToString(*vals), *vals);
vals++;
}

if (ConfMan.hasKey("updates_check"))
_updatesPopUp->setSelectedTag(ConfMan.getInt("updates_check"));
Expand Down
10 changes: 6 additions & 4 deletions gui/updates-dialog.cpp
Expand Up @@ -95,10 +95,12 @@ UpdatesDialog::UpdatesDialog() : Dialog(30, 20, 260, 124) {

_updatesPopUp = new PopUpWidget(this, 10, y, _w - 20, g_gui.xmlEval()->getVar("Globals.PopUp.Height", kLineHeight));

_updatesPopUp->appendEntry(_("Never"), Common::UpdateManager::kUpdateIntervalNotSupported);
_updatesPopUp->appendEntry(_("Daily"), Common::UpdateManager::kUpdateIntervalOneDay);
_updatesPopUp->appendEntry(_("Weekly"), Common::UpdateManager::kUpdateIntervalOneWeek);
_updatesPopUp->appendEntry(_("Monthly"), Common::UpdateManager::kUpdateIntervalOneMonth);
const int *vals = Common::UpdateManager::getUpdateIntervals();

while (*vals != -1) {
_updatesPopUp->appendEntry(Common::UpdateManager::updateIntervalToString(*vals), *vals);
vals++;
}

_updatesPopUp->setSelectedTag(Common::UpdateManager::kUpdateIntervalOneWeek);

Expand Down

0 comments on commit b44a98c

Please sign in to comment.