| Date: | 2010-07-28 00:54:00 (13 years 4 months ago) |
|---|---|
| Author: | Maarten ter Huurne |
| Commit: | 9d05af288172d0f3664d36888b03a3428ea3d895 |
| Message: | Removed duplicate code between MenuSettingFile and its
MenuSettingImage subclass. Also performed some cosmetic fixes. |
| Files: |
src/menusettingfile.cpp (3 diffs) src/menusettingfile.h (1 diff) src/menusettingimage.cpp (1 diff) src/menusettingimage.h (1 diff) |
Change Details
| src/menusettingfile.cpp | ||
|---|---|---|
| 24 | 24 | using namespace std; |
| 25 | 25 | using namespace fastdelegate; |
| 26 | 26 | |
| 27 | MenuSettingFile::MenuSettingFile(GMenu2X *gmenu2x, const string &name, const string &description, string *value, const string &filter) | |
| 28 | : MenuSetting(gmenu2x,name,description) | |
| 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) | |
| 31 | , filter(filter_) | |
| 29 | 32 | { |
| 30 | 33 | IconButton *btn; |
| 31 | 34 | |
| 32 | this->filter = filter; | |
| 33 | _value = value; | |
| 34 | originalValue = *value; | |
| 35 | ||
| 36 | 35 | btn = new IconButton(gmenu2x, "skin:imgs/buttons/x.png", gmenu2x->tr["Clear"]); |
| 37 | 36 | btn->setAction(MakeDelegate(this, &MenuSettingFile::clear)); |
| 38 | 37 | buttonBox.add(btn); |
| ... | ... | |
| 50 | 49 | |
| 51 | 50 | void MenuSettingFile::manageInput() |
| 52 | 51 | { |
| 53 | if (gmenu2x->input[ACTION_X]) | |
| 54 | setValue(""); | |
| 55 | if (gmenu2x->input[ACTION_B]) | |
| 56 | select(); | |
| 52 | if (gmenu2x->input[ACTION_X]) clear(); | |
| 53 | if (gmenu2x->input[ACTION_B]) select(); | |
| 57 | 54 | } |
| 58 | 55 | |
| 59 | 56 | void MenuSettingFile::clear() |
| ... | ... | |
| 64 | 61 | void MenuSettingFile::select() |
| 65 | 62 | { |
| 66 | 63 | FileDialog fd(gmenu2x, description, filter, value()); |
| 67 | if (fd.exec()) | |
| 68 | setValue(fd.getPath()+"/"+fd.getFile()); | |
| 64 | if (fd.exec()) { | |
| 65 | setValue(fd.getPath() + "/" + fd.getFile()); | |
| 66 | } | |
| 69 | 67 | } |
| 70 | 68 | |
| 71 | 69 | void MenuSettingFile::setValue(const string &value) |
| src/menusettingfile.h | ||
|---|---|---|
| 31 | 31 | string *_value; |
| 32 | 32 | string filter; |
| 33 | 33 | |
| 34 | void select(); | |
| 34 | virtual void select(); | |
| 35 | 35 | void clear(); |
| 36 | 36 | |
| 37 | 37 | public: |
| 38 | MenuSettingFile(GMenu2X *gmenu2x, const string &name, const string &description, string *value, const string &filter=""); | |
| 39 | virtual ~MenuSettingFile() {}; | |
| 38 | MenuSettingFile(GMenu2X *gmenu2x, const string &name, | |
| 39 | const string &description, string *value, | |
| 40 | const string &filter = ""); | |
| 41 | virtual ~MenuSettingFile() {} | |
| 40 | 42 | |
| 41 | 43 | virtual void draw(int y); |
| 42 | 44 | virtual void manageInput(); |
| src/menusettingimage.cpp | ||
|---|---|---|
| 24 | 24 | using namespace std; |
| 25 | 25 | |
| 26 | 26 | MenuSettingImage::MenuSettingImage(GMenu2X *gmenu2x, const string &name, const string &description, string *value, const string &filter) |
| 27 | : MenuSettingFile(gmenu2x,name,description,value,filter) { | |
| 28 | this->filter = filter; | |
| 29 | _value = value; | |
| 30 | originalValue = *value; | |
| 27 | : MenuSettingFile(gmenu2x, name, description, value, filter) | |
| 28 | { | |
| 31 | 29 | } |
| 32 | 30 | |
| 33 | void MenuSettingImage::manageInput() { | |
| 34 | if ( gmenu2x->input[ACTION_X] ) setValue(""); | |
| 35 | if ( gmenu2x->input[ACTION_B] ) { | |
| 36 | ImageDialog id(gmenu2x, description, filter, value()); | |
| 37 | if (id.exec()) setValue( id.getPath()+"/"+id.getFile() ); | |
| 38 | } | |
| 31 | void MenuSettingImage::select() { | |
| 32 | ImageDialog id(gmenu2x, description, filter, value()); | |
| 33 | if (id.exec()) setValue(id.getPath() + "/" + id.getFile()); | |
| 39 | 34 | } |
| 40 | 35 | |
| 41 | 36 | void MenuSettingImage::setValue(const string &value) { |
| 42 | string skinpath = gmenu2x->getExePath()+"skins/"+gmenu2x->confStr["skin"]; | |
| 43 | bool inSkinDir = value.substr(0,skinpath.length()) == skinpath; | |
| 37 | string skinpath(gmenu2x->getExePath() + "skins/" + gmenu2x->confStr["skin"]); | |
| 38 | bool inSkinDir = value.substr(0, skinpath.length()) == skinpath; | |
| 44 | 39 | if (!inSkinDir && gmenu2x->confStr["skin"] != "Default") { |
| 45 | skinpath = gmenu2x->getExePath()+"skins/Default"; | |
| 46 | inSkinDir = value.substr(0,skinpath.length()) == skinpath; | |
| 40 | skinpath = gmenu2x->getExePath() + "skins/Default"; | |
| 41 | inSkinDir = value.substr(0, skinpath.length()) == skinpath; | |
| 47 | 42 | } |
| 48 | 43 | if (inSkinDir) { |
| 49 | 44 | string tempIcon = value.substr(skinpath.length(), value.length()); |
| 50 | 45 | string::size_type pos = tempIcon.find("/"); |
| 51 | if (pos != string::npos) | |
| 52 | *_value = "skin:"+tempIcon.substr(pos+1,value.length()); | |
| 53 | else | |
| 46 | if (pos != string::npos) { | |
| 47 | *_value = "skin:" + tempIcon.substr(pos + 1, value.length()); | |
| 48 | } else { | |
| 54 | 49 | *_value = value; |
| 50 | } | |
| 55 | 51 | } else { |
| 56 | 52 | *_value = value; |
| 57 | 53 | } |
| src/menusettingimage.h | ||
|---|---|---|
| 20 | 20 | #ifndef MENUSETTINGIMAGE_H |
| 21 | 21 | #define MENUSETTINGIMAGE_H |
| 22 | 22 | |
| 23 | #include "gmenu2x.h" | |
| 24 | 23 | #include "menusettingfile.h" |
| 25 | 24 | |
| 26 | 25 | using std::string; |
| 27 | 26 | |
| 28 | 27 | class MenuSettingImage : public MenuSettingFile { |
| 28 | protected: | |
| 29 | virtual void select(); | |
| 30 | ||
| 29 | 31 | public: |
| 30 | MenuSettingImage(GMenu2X *gmenu2x, const string &name, const string &description, string *value, const string &filter=""); | |
| 31 | virtual ~MenuSettingImage() {}; | |
| 32 | MenuSettingImage(GMenu2X *gmenu2x, const string &name, | |
| 33 | const string &description, string *value, | |
| 34 | const string &filter = ""); | |
| 35 | virtual ~MenuSettingImage() {} | |
| 32 | 36 | |
| 33 | virtual void manageInput(); | |
| 34 | 37 | virtual void setValue(const string &value); |
| 35 | 38 | }; |
| 36 | 39 | |
Branches:
install_locations
master
opkrun
packages
