| Date: | 2010-07-28 01:46:32 (13 years 4 months ago) |
|---|---|
| Author: | Maarten ter Huurne |
| Commit: | d1d55a766642bb09b8217e9f530b2e353d7a7e4b |
| Message: | Added MenuSettingStringBase, an abstract base class for
MenuSettingString, MenuSettingFile and MenuSettingDir. This removes a lot of duplicate source code and also decreases the binary size slightly. |
| Files: |
src/Makefile.am (2 diffs) src/menusettingdir.cpp (1 diff) src/menusettingdir.h (1 diff) src/menusettingfile.cpp (2 diffs) src/menusettingfile.h (1 diff) src/menusettingimage.cpp (1 diff) src/menusettingimage.h (1 diff) src/menusettingstring.cpp (2 diffs) src/menusettingstring.h (1 diff) src/menusettingstringbase.cpp (1 diff) src/menusettingstringbase.h (1 diff) |
Change Details
| src/Makefile.am | ||
|---|---|---|
| 6 | 6 | menu.cpp menusettingbool.cpp menusetting.cpp menusettingdir.cpp \ |
| 7 | 7 | menusettingfile.cpp menusettingimage.cpp menusettingint.cpp \ |
| 8 | 8 | menusettingmultistring.cpp menusettingrgba.cpp menusettingstring.cpp \ |
| 9 | menusettingstringbase.cpp \ | |
| 9 | 10 | messagebox.cpp selector.cpp \ |
| 10 | 11 | settingsdialog.cpp sfontplus.cpp surfacecollection.cpp surface.cpp \ |
| 11 | 12 | textdialog.cpp textmanualdialog.cpp touchscreen.cpp translator.cpp \ |
| ... | ... | |
| 18 | 19 | menu.h menusettingbool.h menusettingdir.h \ |
| 19 | 20 | menusettingfile.h menusetting.h menusettingimage.h menusettingint.h \ |
| 20 | 21 | menusettingmultistring.h menusettingrgba.h menusettingstring.h \ |
| 22 | menusettingstringbase.h \ | |
| 21 | 23 | messagebox.h selector.h settingsdialog.h \ |
| 22 | 24 | sfontplus.h surfacecollection.h surface.h textdialog.h textmanualdialog.h \ |
| 23 | 25 | touchscreen.h translator.h utilities.h wallpaperdialog.h \ |
| src/menusettingdir.cpp | ||
|---|---|---|
| 19 | 19 | ***************************************************************************/ |
| 20 | 20 | #include "menusettingdir.h" |
| 21 | 21 | #include "dirdialog.h" |
| 22 | #include "utilities.h" | |
| 23 | 22 | |
| 24 | 23 | using namespace std; |
| 25 | 24 | using namespace fastdelegate; |
| 26 | 25 | |
| 27 | MenuSettingDir::MenuSettingDir(GMenu2X *gmenu2x, const string &name, const string &description, string *value) | |
| 28 | : MenuSetting(gmenu2x,name,description) { | |
| 26 | MenuSettingDir::MenuSettingDir( | |
| 27 | GMenu2X *gmenu2x, const string &name, | |
| 28 | const string &description, string *value) | |
| 29 | : MenuSettingStringBase(gmenu2x, name, description, value) | |
| 30 | { | |
| 29 | 31 | IconButton *btn; |
| 30 | 32 | |
| 31 | _value = value; | |
| 32 | originalValue = *value; | |
| 33 | ||
| 34 | 33 | btn = new IconButton(gmenu2x, "skin:imgs/buttons/x.png", gmenu2x->tr["Clear"]); |
| 35 | 34 | btn->setAction(MakeDelegate(this, &MenuSettingDir::clear)); |
| 36 | 35 | buttonBox.add(btn); |
| 37 | 36 | |
| 38 | 37 | btn = new IconButton(gmenu2x, "skin:imgs/buttons/b.png", gmenu2x->tr["Select a directory"]); |
| 39 | btn->setAction(MakeDelegate(this, &MenuSettingDir::select)); | |
| 38 | btn->setAction(MakeDelegate(this, &MenuSettingDir::edit)); | |
| 40 | 39 | buttonBox.add(btn); |
| 41 | 40 | } |
| 42 | 41 | |
| 43 | void MenuSettingDir::draw(int y) | |
| 44 | { | |
| 45 | MenuSetting::draw(y); | |
| 46 | gmenu2x->s->write( gmenu2x->font, value(), 155, y+gmenu2x->font->getHalfHeight(), SFontHAlignLeft, SFontVAlignMiddle ); | |
| 47 | } | |
| 48 | ||
| 49 | void MenuSettingDir::manageInput() | |
| 50 | { | |
| 51 | if (gmenu2x->input[ACTION_X]) setValue(""); | |
| 52 | if (gmenu2x->input[ACTION_B]) select(); | |
| 53 | } | |
| 54 | ||
| 55 | void MenuSettingDir::clear() | |
| 56 | { | |
| 57 | setValue(""); | |
| 58 | } | |
| 59 | ||
| 60 | void MenuSettingDir::select() | |
| 42 | void MenuSettingDir::edit() | |
| 61 | 43 | { |
| 62 | 44 | DirDialog dd(gmenu2x, description, value()); |
| 63 | 45 | if (dd.exec()) setValue( dd.getPath() ); |
| 64 | 46 | } |
| 65 | ||
| 66 | void MenuSettingDir::setValue(const string &value) | |
| 67 | { | |
| 68 | *_value = value; | |
| 69 | } | |
| 70 | ||
| 71 | const string &MenuSettingDir::value() | |
| 72 | { | |
| 73 | return *_value; | |
| 74 | } | |
| 75 | ||
| 76 | void MenuSettingDir::adjustInput() {} | |
| 77 | ||
| 78 | bool MenuSettingDir::edited() { | |
| 79 | return originalValue != value(); | |
| 80 | } | |
| src/menusettingdir.h | ||
|---|---|---|
| 20 | 20 | #ifndef MENUSETTINGDIR_H |
| 21 | 21 | #define MENUSETTINGDIR_H |
| 22 | 22 | |
| 23 | #include "gmenu2x.h" | |
| 24 | #include "menusetting.h" | |
| 23 | #include "menusettingstringbase.h" | |
| 25 | 24 | |
| 26 | 25 | using std::string; |
| 27 | 26 | |
| 28 | class MenuSettingDir : public MenuSetting { | |
| 29 | private: | |
| 30 | string originalValue; | |
| 31 | string *_value; | |
| 27 | class MenuSettingDir : public MenuSettingStringBase { | |
| 28 | protected: | |
| 29 | virtual void edit(); | |
| 32 | 30 | |
| 33 | void select(); | |
| 34 | void clear(); | |
| 35 | 31 | public: |
| 36 | MenuSettingDir(GMenu2X *gmenu2x, const string &name, const string &description, string *value); | |
| 37 | virtual ~MenuSettingDir() {}; | |
| 38 | ||
| 39 | virtual void draw(int y); | |
| 40 | virtual void manageInput(); | |
| 41 | virtual void adjustInput(); | |
| 42 | virtual bool edited(); | |
| 43 | ||
| 44 | void setValue(const string &value); | |
| 45 | const string &value(); | |
| 32 | MenuSettingDir( | |
| 33 | GMenu2X *gmenu2x, const string &name, | |
| 34 | const string &description, string *value); | |
| 35 | virtual ~MenuSettingDir() {} | |
| 46 | 36 | }; |
| 47 | 37 | |
| 48 | 38 | #endif |
| src/menusettingfile.cpp | ||
|---|---|---|
| 19 | 19 | ***************************************************************************/ |
| 20 | 20 | #include "menusettingfile.h" |
| 21 | 21 | #include "filedialog.h" |
| 22 | #include "utilities.h" | |
| 23 | 22 | |
| 24 | 23 | using namespace std; |
| 25 | 24 | using namespace fastdelegate; |
| 26 | 25 | |
| 27 | MenuSettingFile::MenuSettingFile(GMenu2X *gmenu2x, const string &name, const string &description, string *value, const string &filter_) | |
| 28 | : MenuSetting(gmenu2x, name, description) | |
| 29 | , originalValue(*value) | |
| 30 | , _value(value) | |
| 26 | MenuSettingFile::MenuSettingFile( | |
| 27 | GMenu2X *gmenu2x, const string &name, | |
| 28 | const string &description, string *value, const string &filter_) | |
| 29 | : MenuSettingStringBase(gmenu2x, name, description, value) | |
| 31 | 30 | , filter(filter_) |
| 32 | 31 | { |
| 33 | 32 | IconButton *btn; |
| ... | ... | |
| 37 | 36 | buttonBox.add(btn); |
| 38 | 37 | |
| 39 | 38 | btn = new IconButton(gmenu2x, "skin:imgs/buttons/b.png", gmenu2x->tr["Select a file"]); |
| 40 | btn->setAction(MakeDelegate(this, &MenuSettingFile::select)); | |
| 39 | btn->setAction(MakeDelegate(this, &MenuSettingFile::edit)); | |
| 41 | 40 | buttonBox.add(btn); |
| 42 | 41 | } |
| 43 | 42 | |
| 44 | void MenuSettingFile::draw(int y) | |
| 45 | { | |
| 46 | MenuSetting::draw(y); | |
| 47 | gmenu2x->s->write( gmenu2x->font, value(), 155, y+gmenu2x->font->getHalfHeight(), SFontHAlignLeft, SFontVAlignMiddle ); | |
| 48 | } | |
| 49 | ||
| 50 | void MenuSettingFile::manageInput() | |
| 51 | { | |
| 52 | if (gmenu2x->input[ACTION_X]) clear(); | |
| 53 | if (gmenu2x->input[ACTION_B]) select(); | |
| 54 | } | |
| 55 | ||
| 56 | void MenuSettingFile::clear() | |
| 57 | { | |
| 58 | setValue(""); | |
| 59 | } | |
| 60 | ||
| 61 | void MenuSettingFile::select() | |
| 43 | void MenuSettingFile::edit() | |
| 62 | 44 | { |
| 63 | 45 | FileDialog fd(gmenu2x, description, filter, value()); |
| 64 | 46 | if (fd.exec()) { |
| 65 | 47 | setValue(fd.getPath() + "/" + fd.getFile()); |
| 66 | 48 | } |
| 67 | 49 | } |
| 68 | ||
| 69 | void MenuSettingFile::setValue(const string &value) | |
| 70 | { | |
| 71 | *_value = value; | |
| 72 | } | |
| 73 | ||
| 74 | const string &MenuSettingFile::value() | |
| 75 | { | |
| 76 | return *_value; | |
| 77 | } | |
| 78 | ||
| 79 | void MenuSettingFile::adjustInput() {} | |
| 80 | ||
| 81 | bool MenuSettingFile::edited() { | |
| 82 | return originalValue != value(); | |
| 83 | } | |
| src/menusettingfile.h | ||
|---|---|---|
| 20 | 20 | #ifndef MENUSETTINGFILE_H |
| 21 | 21 | #define MENUSETTINGFILE_H |
| 22 | 22 | |
| 23 | #include "gmenu2x.h" | |
| 24 | #include "menusetting.h" | |
| 23 | #include "menusettingstringbase.h" | |
| 25 | 24 | |
| 26 | 25 | using std::string; |
| 27 | 26 | |
| 28 | class MenuSettingFile : public MenuSetting { | |
| 27 | class MenuSettingFile : public MenuSettingStringBase { | |
| 29 | 28 | protected: |
| 30 | string originalValue; | |
| 31 | string *_value; | |
| 32 | string filter; | |
| 29 | virtual void edit(); | |
| 33 | 30 | |
| 34 | virtual void select(); | |
| 35 | void clear(); | |
| 31 | string filter; | |
| 36 | 32 | |
| 37 | 33 | public: |
| 38 | MenuSettingFile(GMenu2X *gmenu2x, const string &name, | |
| 39 | const string &description, string *value, | |
| 40 | const string &filter = ""); | |
| 34 | MenuSettingFile( | |
| 35 | GMenu2X *gmenu2x, const string &name, | |
| 36 | const string &description, string *value, | |
| 37 | const string &filter = ""); | |
| 41 | 38 | virtual ~MenuSettingFile() {} |
| 42 | ||
| 43 | virtual void draw(int y); | |
| 44 | virtual void manageInput(); | |
| 45 | virtual void adjustInput(); | |
| 46 | virtual bool edited(); | |
| 47 | ||
| 48 | virtual void setValue(const string &value); | |
| 49 | const string &value(); | |
| 50 | 39 | }; |
| 51 | 40 | |
| 52 | 41 | #endif |
| src/menusettingimage.cpp | ||
|---|---|---|
| 28 | 28 | { |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | void MenuSettingImage::select() { | |
| 31 | void MenuSettingImage::edit() { | |
| 32 | 32 | ImageDialog id(gmenu2x, description, filter, value()); |
| 33 | 33 | if (id.exec()) setValue(id.getPath() + "/" + id.getFile()); |
| 34 | 34 | } |
| src/menusettingimage.h | ||
|---|---|---|
| 26 | 26 | |
| 27 | 27 | class MenuSettingImage : public MenuSettingFile { |
| 28 | 28 | protected: |
| 29 | virtual void select(); | |
| 29 | virtual void edit(); | |
| 30 | 30 | |
| 31 | 31 | public: |
| 32 | 32 | MenuSettingImage(GMenu2X *gmenu2x, const string &name, |
| src/menusettingstring.cpp | ||
|---|---|---|
| 19 | 19 | ***************************************************************************/ |
| 20 | 20 | #include "menusettingstring.h" |
| 21 | 21 | #include "inputdialog.h" |
| 22 | #include "utilities.h" | |
| 23 | 22 | |
| 24 | 23 | using namespace std; |
| 25 | 24 | using namespace fastdelegate; |
| 26 | 25 | |
| 27 | MenuSettingString::MenuSettingString(GMenu2X *gmenu2x, const string &name, const string &description, string *value, const string &diagTitle, const string &diagIcon) | |
| 28 | : MenuSetting(gmenu2x, name, description) | |
| 26 | MenuSettingString::MenuSettingString( | |
| 27 | GMenu2X *gmenu2x, const string &name, | |
| 28 | const string &description, string *value, | |
| 29 | const string &diagTitle_, const string &diagIcon_) | |
| 30 | : MenuSettingStringBase(gmenu2x, name, description, value) | |
| 31 | , diagTitle(diagTitle_) | |
| 32 | , diagIcon(diagIcon_) | |
| 29 | 33 | { |
| 30 | 34 | IconButton *btn; |
| 31 | 35 | |
| 32 | _value = value; | |
| 33 | originalValue = *value; | |
| 34 | this->diagTitle = diagTitle; | |
| 35 | this->diagIcon = diagIcon; | |
| 36 | ||
| 37 | 36 | btn = new IconButton(gmenu2x, "skin:imgs/buttons/x.png", gmenu2x->tr["Clear"]); |
| 38 | 37 | btn->setAction(MakeDelegate(this, &MenuSettingString::clear)); |
| 39 | 38 | buttonBox.add(btn); |
| ... | ... | |
| 43 | 42 | buttonBox.add(btn); |
| 44 | 43 | } |
| 45 | 44 | |
| 46 | void MenuSettingString::draw(int y) | |
| 47 | { | |
| 48 | MenuSetting::draw(y); | |
| 49 | gmenu2x->s->write(gmenu2x->font, value(), 155, y+gmenu2x->font->getHalfHeight(), SFontHAlignLeft, SFontVAlignMiddle); | |
| 50 | } | |
| 51 | ||
| 52 | void MenuSettingString::manageInput() | |
| 53 | { | |
| 54 | if (gmenu2x->input[ACTION_X]) | |
| 55 | clear(); | |
| 56 | if (gmenu2x->input[ACTION_B]) | |
| 57 | edit(); | |
| 58 | } | |
| 59 | ||
| 60 | void MenuSettingString::setValue(const string &value) | |
| 61 | { | |
| 62 | *_value = value; | |
| 63 | } | |
| 64 | ||
| 65 | const string &MenuSettingString::value() | |
| 66 | { | |
| 67 | return *_value; | |
| 68 | } | |
| 69 | ||
| 70 | void MenuSettingString::adjustInput() {} | |
| 71 | ||
| 72 | void MenuSettingString::clear() | |
| 73 | { | |
| 74 | setValue(""); | |
| 75 | } | |
| 76 | ||
| 77 | 45 | void MenuSettingString::edit() |
| 78 | 46 | { |
| 79 | InputDialog id(gmenu2x, gmenu2x->input, gmenu2x->ts, | |
| 80 | description, value(), diagTitle, diagIcon); | |
| 47 | InputDialog id( | |
| 48 | gmenu2x, gmenu2x->input, gmenu2x->ts, | |
| 49 | description, value(), diagTitle, diagIcon); | |
| 81 | 50 | if (id.exec()) setValue(id.getInput()); |
| 82 | 51 | } |
| 83 | ||
| 84 | bool MenuSettingString::edited() { | |
| 85 | return originalValue != value(); | |
| 86 | } | |
| src/menusettingstring.h | ||
|---|---|---|
| 20 | 20 | #ifndef MENUSETTINGSTRING_H |
| 21 | 21 | #define MENUSETTINGSTRING_H |
| 22 | 22 | |
| 23 | #include "gmenu2x.h" | |
| 24 | #include "menusetting.h" | |
| 23 | #include "menusettingstringbase.h" | |
| 25 | 24 | |
| 26 | 25 | using std::string; |
| 27 | 26 | |
| 28 | class MenuSettingString : public MenuSetting { | |
| 29 | private: | |
| 30 | string originalValue, diagTitle, diagIcon; | |
| 31 | string *_value; | |
| 27 | class MenuSettingString : public MenuSettingStringBase { | |
| 28 | protected: | |
| 29 | virtual void edit(); | |
| 32 | 30 | |
| 33 | void edit(); | |
| 34 | void clear(); | |
| 31 | string diagTitle, diagIcon; | |
| 35 | 32 | |
| 36 | 33 | public: |
| 37 | MenuSettingString(GMenu2X *gmenu2x, const string &name, const string &description, string *value, const string &diagTitle="", const string &diagIcon=""); | |
| 38 | virtual ~MenuSettingString() {}; | |
| 39 | ||
| 40 | virtual void draw(int y); | |
| 41 | virtual void manageInput(); | |
| 42 | virtual void adjustInput(); | |
| 43 | virtual bool edited(); | |
| 44 | ||
| 45 | void setValue(const string &value); | |
| 46 | const string &value(); | |
| 34 | MenuSettingString(GMenu2X *gmenu2x, const string &name, | |
| 35 | const string &description, string *value, | |
| 36 | const string &diagTitle = "", | |
| 37 | const string &diagIcon = ""); | |
| 38 | virtual ~MenuSettingString() {} | |
| 47 | 39 | }; |
| 48 | 40 | |
| 49 | 41 | #endif |
| src/menusettingstringbase.cpp | ||
|---|---|---|
| 1 | /*************************************************************************** | |
| 2 | * Copyright (C) 2006 by Massimiliano Torromeo * | |
| 3 | * massimiliano.torromeo@gmail.com * | |
| 4 | * * | |
| 5 | * This program is free software; you can redistribute it and/or modify * | |
| 6 | * it under the terms of the GNU General Public License as published by * | |
| 7 | * the Free Software Foundation; either version 2 of the License, or * | |
| 8 | * (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 * | |
| 17 | * Free Software Foundation, Inc., * | |
| 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * | |
| 19 | ***************************************************************************/ | |
| 20 | #include "menusettingstringbase.h" | |
| 21 | ||
| 22 | using namespace std; | |
| 23 | using namespace fastdelegate; | |
| 24 | ||
| 25 | MenuSettingStringBase::MenuSettingStringBase( | |
| 26 | GMenu2X *gmenu2x, const string &name, | |
| 27 | const string &description, string *value) | |
| 28 | : MenuSetting(gmenu2x, name, description) | |
| 29 | , originalValue(*value) | |
| 30 | , _value(value) | |
| 31 | { | |
| 32 | } | |
| 33 | ||
| 34 | MenuSettingStringBase::~MenuSettingStringBase() | |
| 35 | { | |
| 36 | } | |
| 37 | ||
| 38 | void MenuSettingStringBase::draw(int y) | |
| 39 | { | |
| 40 | MenuSetting::draw(y); | |
| 41 | gmenu2x->s->write( | |
| 42 | gmenu2x->font, value(), | |
| 43 | 155, y + gmenu2x->font->getHalfHeight(), | |
| 44 | SFontHAlignLeft, SFontVAlignMiddle); | |
| 45 | } | |
| 46 | ||
| 47 | void MenuSettingStringBase::manageInput() | |
| 48 | { | |
| 49 | if (gmenu2x->input[ACTION_X]) clear(); | |
| 50 | if (gmenu2x->input[ACTION_B]) edit(); | |
| 51 | } | |
| 52 | ||
| 53 | void MenuSettingStringBase::adjustInput() | |
| 54 | { | |
| 55 | } | |
| 56 | ||
| 57 | void MenuSettingStringBase::clear() | |
| 58 | { | |
| 59 | setValue(""); | |
| 60 | } | |
| 61 | ||
| 62 | bool MenuSettingStringBase::edited() | |
| 63 | { | |
| 64 | return originalValue != value(); | |
| 65 | } | |
| src/menusettingstringbase.h | ||
|---|---|---|
| 1 | /*************************************************************************** | |
| 2 | * Copyright (C) 2006 by Massimiliano Torromeo * | |
| 3 | * massimiliano.torromeo@gmail.com * | |
| 4 | * * | |
| 5 | * This program is free software; you can redistribute it and/or modify * | |
| 6 | * it under the terms of the GNU General Public License as published by * | |
| 7 | * the Free Software Foundation; either version 2 of the License, or * | |
| 8 | * (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 * | |
| 17 | * Free Software Foundation, Inc., * | |
| 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * | |
| 19 | ***************************************************************************/ | |
| 20 | #ifndef MENUSETTINGSTRINGBASE_H | |
| 21 | #define MENUSETTINGSTRINGBASE_H | |
| 22 | ||
| 23 | #include "menusetting.h" | |
| 24 | ||
| 25 | using std::string; | |
| 26 | ||
| 27 | class MenuSettingStringBase : public MenuSetting { | |
| 28 | protected: | |
| 29 | string originalValue; | |
| 30 | string *_value; | |
| 31 | ||
| 32 | virtual void edit() = 0; | |
| 33 | void clear(); | |
| 34 | ||
| 35 | public: | |
| 36 | MenuSettingStringBase( | |
| 37 | GMenu2X *gmenu2x, const string &name, | |
| 38 | const string &description, string *value); | |
| 39 | virtual ~MenuSettingStringBase(); | |
| 40 | ||
| 41 | virtual void draw(int y); | |
| 42 | virtual void manageInput(); | |
| 43 | virtual void adjustInput(); | |
| 44 | virtual bool edited(); | |
| 45 | ||
| 46 | void setValue(const string &value) { *_value = value; } | |
| 47 | const string &value() { return *_value; } | |
| 48 | }; | |
| 49 | ||
| 50 | #endif | |
Branches:
install_locations
master
opkrun
packages
