1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-25 17:53:07 +02:00

Use unique_ptr to make ownership of MenuSettings explicit

This commit is contained in:
Maarten ter Huurne 2014-08-16 16:57:45 +02:00
parent 8a1bb5694f
commit faf2495727
3 changed files with 103 additions and 42 deletions

View File

@ -706,15 +706,36 @@ void GMenu2X::showSettings() {
encodings.push_back("PAL"); encodings.push_back("PAL");
SettingsDialog sd(this, input, ts, tr["Settings"]); SettingsDialog sd(this, input, ts, tr["Settings"]);
sd.addSetting(new MenuSettingMultiString(this, ts, tr["Language"], tr["Set the language used by GMenu2X"], &lang, &translations)); sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingMultiString(
sd.addSetting(new MenuSettingBool(this, ts, tr["Save last selection"], tr["Save the last selected link and section on exit"], &confInt["saveSelection"])); this, ts, tr["Language"],
tr["Set the language used by GMenu2X"],
&lang, &translations)));
sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingBool(
this, ts, tr["Save last selection"],
tr["Save the last selected link and section on exit"],
&confInt["saveSelection"])));
#ifdef ENABLE_CPUFREQ #ifdef ENABLE_CPUFREQ
sd.addSetting(new MenuSettingInt(this, ts, tr["Clock for GMenu2X"], tr["Set the cpu working frequency when running GMenu2X"], &confInt["menuClock"], cpuFreqMin, cpuFreqSafeMax, cpuFreqMultiple)); sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingInt(
sd.addSetting(new MenuSettingInt(this, ts, tr["Maximum overclock"], tr["Set the maximum overclock for launching links"], &confInt["maxClock"], cpuFreqMin, cpuFreqMax, cpuFreqMultiple)); this, ts, tr["Clock for GMenu2X"],
tr["Set the cpu working frequency when running GMenu2X"],
&confInt["menuClock"], cpuFreqMin, cpuFreqSafeMax, cpuFreqMultiple)));
sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingInt(
this, ts, tr["Maximum overclock"],
tr["Set the maximum overclock for launching links"],
&confInt["maxClock"], cpuFreqMin, cpuFreqMax, cpuFreqMultiple)));
#endif #endif
sd.addSetting(new MenuSettingBool(this, ts, tr["Output logs"], tr["Logs the output of the links. Use the Log Viewer to read them."], &confInt["outputLogs"])); sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingBool(
sd.addSetting(new MenuSettingInt(this, ts, tr["Screen Timeout"], tr["Set screen's backlight timeout in seconds"], &confInt["backlightTimeout"], 0, 120)); this, ts, tr["Output logs"],
sd.addSetting(new MenuSettingInt(this, ts, tr["Button repeat rate"], tr["Set button repetitions per second"], &confInt["buttonRepeatRate"], 0, 20)); tr["Logs the output of the links. Use the Log Viewer to read them."],
&confInt["outputLogs"])));
sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingInt(
this, ts, tr["Screen Timeout"],
tr["Set screen's backlight timeout in seconds"],
&confInt["backlightTimeout"], 0, 120)));
sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingInt(
this, ts, tr["Button repeat rate"],
tr["Set button repetitions per second"],
&confInt["buttonRepeatRate"], 0, 20)));
if (sd.exec() && sd.edited()) { if (sd.exec() && sd.edited()) {
#ifdef ENABLE_CPUFREQ #ifdef ENABLE_CPUFREQ
@ -745,13 +766,34 @@ void GMenu2X::skinMenu() {
string curSkin = confStr["skin"]; string curSkin = confStr["skin"];
SettingsDialog sd(this, input, ts, tr["Skin"]); SettingsDialog sd(this, input, ts, tr["Skin"]);
sd.addSetting(new MenuSettingMultiString(this, ts, tr["Skin"], tr["Set the skin used by GMenu2X"], &confStr["skin"], &fl_sk.getDirectories())); sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingMultiString(
sd.addSetting(new MenuSettingRGBA(this, ts, tr["Top Bar"], tr["Color of the top bar"], &skinConfColors[COLOR_TOP_BAR_BG])); this, ts, tr["Skin"],
sd.addSetting(new MenuSettingRGBA(this, ts, tr["Bottom Bar"], tr["Color of the bottom bar"], &skinConfColors[COLOR_BOTTOM_BAR_BG])); tr["Set the skin used by GMenu2X"],
sd.addSetting(new MenuSettingRGBA(this, ts, tr["Selection"], tr["Color of the selection and other interface details"], &skinConfColors[COLOR_SELECTION_BG])); &confStr["skin"], &fl_sk.getDirectories())));
sd.addSetting(new MenuSettingRGBA(this, ts, tr["Message Box"], tr["Background color of the message box"], &skinConfColors[COLOR_MESSAGE_BOX_BG])); sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingRGBA(
sd.addSetting(new MenuSettingRGBA(this, ts, tr["Message Box Border"], tr["Border color of the message box"], &skinConfColors[COLOR_MESSAGE_BOX_BORDER])); this, ts, tr["Top Bar"],
sd.addSetting(new MenuSettingRGBA(this, ts, tr["Message Box Selection"], tr["Color of the selection of the message box"], &skinConfColors[COLOR_MESSAGE_BOX_SELECTION])); tr["Color of the top bar"],
&skinConfColors[COLOR_TOP_BAR_BG])));
sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingRGBA(
this, ts, tr["Bottom Bar"],
tr["Color of the bottom bar"],
&skinConfColors[COLOR_BOTTOM_BAR_BG])));
sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingRGBA(
this, ts, tr["Selection"],
tr["Color of the selection and other interface details"],
&skinConfColors[COLOR_SELECTION_BG])));
sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingRGBA(
this, ts, tr["Message Box"],
tr["Background color of the message box"],
&skinConfColors[COLOR_MESSAGE_BOX_BG])));
sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingRGBA(
this, ts, tr["Message Box Border"],
tr["Border color of the message box"],
&skinConfColors[COLOR_MESSAGE_BOX_BORDER])));
sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingRGBA(
this, ts, tr["Message Box Selection"],
tr["Color of the selection of the message box"],
&skinConfColors[COLOR_MESSAGE_BOX_SELECTION])));
if (sd.exec() && sd.edited()) { if (sd.exec() && sd.edited()) {
if (curSkin != confStr["skin"]) { if (curSkin != confStr["skin"]) {
@ -889,26 +931,52 @@ void GMenu2X::editLink() {
SettingsDialog sd(this, input, ts, diagTitle, diagIcon); SettingsDialog sd(this, input, ts, diagTitle, diagIcon);
if (!linkApp->isOpk()) { if (!linkApp->isOpk()) {
sd.addSetting(new MenuSettingString(this, ts, tr["Title"], tr["Link title"], &linkTitle, diagTitle, diagIcon)); sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingString(
sd.addSetting(new MenuSettingString(this, ts, tr["Description"], tr["Link description"], &linkDescription, diagTitle, diagIcon)); this, ts, tr["Title"],
sd.addSetting(new MenuSettingMultiString(this, ts, tr["Section"], tr["The section this link belongs to"], &newSection, &menu->getSections())); tr["Link title"],
sd.addSetting(new MenuSettingImage(this, ts, tr["Icon"], &linkTitle, diagTitle, diagIcon)));
tr.translate("Select an icon for this link", sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingString(
linkTitle.c_str(), NULL), &linkIcon, "png")); this, ts, tr["Description"],
sd.addSetting(new MenuSettingFile(this, ts, tr["Manual"], tr["Link description"],
tr["Select a manual or README file"], &linkDescription, diagTitle, diagIcon)));
&linkManual, "man.png,txt")); sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingMultiString(
this, ts, tr["Section"],
tr["The section this link belongs to"],
&newSection, &menu->getSections())));
sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingImage(
this, ts, tr["Icon"],
tr.translate("Select an icon for this link", linkTitle.c_str(), NULL),
&linkIcon, "png")));
sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingFile(
this, ts, tr["Manual"],
tr["Select a manual or README file"],
&linkManual, "man.png,txt")));
} }
if (!linkApp->isOpk() || !linkApp->getSelectorDir().empty()) { if (!linkApp->isOpk() || !linkApp->getSelectorDir().empty()) {
sd.addSetting(new MenuSettingDir(this, ts, tr["Selector Directory"], tr["Directory to scan for the selector"], &linkSelDir)); sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingDir(
sd.addSetting(new MenuSettingBool(this, ts, tr["Selector Browser"], tr["Allow the selector to change directory"], &linkSelBrowser)); this, ts, tr["Selector Directory"],
tr["Directory to scan for the selector"],
&linkSelDir)));
sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingBool(
this, ts, tr["Selector Browser"],
tr["Allow the selector to change directory"],
&linkSelBrowser)));
} }
#ifdef ENABLE_CPUFREQ #ifdef ENABLE_CPUFREQ
sd.addSetting(new MenuSettingInt(this, ts, tr["Clock frequency"], tr["CPU clock frequency for this link"], &linkClock, cpuFreqMin, confInt["maxClock"], cpuFreqMultiple)); sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingInt(
this, ts, tr["Clock frequency"],
tr["CPU clock frequency for this link"],
&linkClock, cpuFreqMin, confInt["maxClock"], cpuFreqMultiple)));
#endif #endif
if (!linkApp->isOpk()) { if (!linkApp->isOpk()) {
sd.addSetting(new MenuSettingString(this, ts, tr["Selector Filter"], tr["Selector filter (Separate values with a comma)"], &linkSelFilter, diagTitle, diagIcon)); sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingString(
sd.addSetting(new MenuSettingBool(this, ts, tr["Display Console"], tr["Must be enabled for console-based applications"], &linkApp->consoleApp)); this, ts, tr["Selector Filter"],
tr["Selector filter (Separate values with a comma)"],
&linkSelFilter, diagTitle, diagIcon)));
sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingBool(
this, ts, tr["Display Console"],
tr["Must be enabled for console-based applications"],
&linkApp->consoleApp)));
} }
if (sd.exec() && sd.edited()) { if (sd.exec() && sd.edited()) {

View File

@ -42,13 +42,6 @@ SettingsDialog::SettingsDialog(
} }
} }
SettingsDialog::~SettingsDialog() {
for (vector<MenuSetting *>::iterator it = settings.begin();
it != settings.end(); ++it) {
delete *it;
}
}
bool SettingsDialog::exec() { bool SettingsDialog::exec() {
OffscreenSurface bg(*gmenu2x->bg); OffscreenSurface bg(*gmenu2x->bg);
bg.convertToDisplayFormat(); bg.convertToDisplayFormat();
@ -151,10 +144,6 @@ bool SettingsDialog::exec() {
return true; return true;
} }
void SettingsDialog::addSetting(MenuSetting *set) {
settings.push_back(set);
}
bool SettingsDialog::edited() { bool SettingsDialog::edited() {
for (uint i=0; i < settings.size(); i++) { for (uint i=0; i < settings.size(); i++) {
if (settings[i]->edited()) return true; if (settings[i]->edited()) return true;

View File

@ -23,6 +23,8 @@
#include "dialog.h" #include "dialog.h"
#include <algorithm>
#include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
@ -34,18 +36,20 @@ class SettingsDialog : protected Dialog {
private: private:
InputManager &inputMgr; InputManager &inputMgr;
Touchscreen &ts; Touchscreen &ts;
std::vector<MenuSetting *> settings; std::vector<std::unique_ptr<MenuSetting>> settings;
std::string text, icon; std::string text, icon;
public: public:
SettingsDialog(GMenu2X *gmenu2x, InputManager &inputMgr, Touchscreen &ts, SettingsDialog(GMenu2X *gmenu2x, InputManager &inputMgr, Touchscreen &ts,
const std::string &text, const std::string &text,
const std::string &icon = "skin:sections/settings.png"); const std::string &icon = "skin:sections/settings.png");
~SettingsDialog();
void addSetting(std::unique_ptr<MenuSetting> setting) {
settings.push_back(std::move(setting));
}
bool edited(); bool edited();
bool exec(); bool exec();
void addSetting(MenuSetting* set);
}; };
#endif // SETTINGSDIALOG_H #endif // SETTINGSDIALOG_H