1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-22 17:41:52 +02:00

Removed duplicate code between MenuSettingFile and its MenuSettingImage subclass.

Also performed some cosmetic fixes.
This commit is contained in:
Maarten ter Huurne 2010-07-28 00:54:00 +02:00
parent ac30153cfc
commit 9d05af2881
4 changed files with 36 additions and 37 deletions

View File

@ -24,15 +24,14 @@
using namespace std;
using namespace fastdelegate;
MenuSettingFile::MenuSettingFile(GMenu2X *gmenu2x, const string &name, const string &description, string *value, const string &filter)
: MenuSetting(gmenu2x,name,description)
MenuSettingFile::MenuSettingFile(GMenu2X *gmenu2x, const string &name, const string &description, string *value, const string &filter_)
: MenuSetting(gmenu2x, name, description)
, originalValue(*value)
, _value(value)
, filter(filter_)
{
IconButton *btn;
this->filter = filter;
_value = value;
originalValue = *value;
btn = new IconButton(gmenu2x, "skin:imgs/buttons/x.png", gmenu2x->tr["Clear"]);
btn->setAction(MakeDelegate(this, &MenuSettingFile::clear));
buttonBox.add(btn);
@ -50,10 +49,8 @@ void MenuSettingFile::draw(int y)
void MenuSettingFile::manageInput()
{
if (gmenu2x->input[ACTION_X])
setValue("");
if (gmenu2x->input[ACTION_B])
select();
if (gmenu2x->input[ACTION_X]) clear();
if (gmenu2x->input[ACTION_B]) select();
}
void MenuSettingFile::clear()
@ -64,8 +61,9 @@ void MenuSettingFile::clear()
void MenuSettingFile::select()
{
FileDialog fd(gmenu2x, description, filter, value());
if (fd.exec())
setValue(fd.getPath()+"/"+fd.getFile());
if (fd.exec()) {
setValue(fd.getPath() + "/" + fd.getFile());
}
}
void MenuSettingFile::setValue(const string &value)

View File

@ -31,12 +31,14 @@ protected:
string *_value;
string filter;
void select();
virtual void select();
void clear();
public:
MenuSettingFile(GMenu2X *gmenu2x, const string &name, const string &description, string *value, const string &filter="");
virtual ~MenuSettingFile() {};
MenuSettingFile(GMenu2X *gmenu2x, const string &name,
const string &description, string *value,
const string &filter = "");
virtual ~MenuSettingFile() {}
virtual void draw(int y);
virtual void manageInput();

View File

@ -24,34 +24,30 @@
using namespace std;
MenuSettingImage::MenuSettingImage(GMenu2X *gmenu2x, const string &name, const string &description, string *value, const string &filter)
: MenuSettingFile(gmenu2x,name,description,value,filter) {
this->filter = filter;
_value = value;
originalValue = *value;
: MenuSettingFile(gmenu2x, name, description, value, filter)
{
}
void MenuSettingImage::manageInput() {
if ( gmenu2x->input[ACTION_X] ) setValue("");
if ( gmenu2x->input[ACTION_B] ) {
void MenuSettingImage::select() {
ImageDialog id(gmenu2x, description, filter, value());
if (id.exec()) setValue( id.getPath()+"/"+id.getFile() );
}
if (id.exec()) setValue(id.getPath() + "/" + id.getFile());
}
void MenuSettingImage::setValue(const string &value) {
string skinpath = gmenu2x->getExePath()+"skins/"+gmenu2x->confStr["skin"];
bool inSkinDir = value.substr(0,skinpath.length()) == skinpath;
string skinpath(gmenu2x->getExePath() + "skins/" + gmenu2x->confStr["skin"]);
bool inSkinDir = value.substr(0, skinpath.length()) == skinpath;
if (!inSkinDir && gmenu2x->confStr["skin"] != "Default") {
skinpath = gmenu2x->getExePath()+"skins/Default";
inSkinDir = value.substr(0,skinpath.length()) == skinpath;
skinpath = gmenu2x->getExePath() + "skins/Default";
inSkinDir = value.substr(0, skinpath.length()) == skinpath;
}
if (inSkinDir) {
string tempIcon = value.substr(skinpath.length(), value.length());
string::size_type pos = tempIcon.find("/");
if (pos != string::npos)
*_value = "skin:"+tempIcon.substr(pos+1,value.length());
else
if (pos != string::npos) {
*_value = "skin:" + tempIcon.substr(pos + 1, value.length());
} else {
*_value = value;
}
} else {
*_value = value;
}

View File

@ -20,17 +20,20 @@
#ifndef MENUSETTINGIMAGE_H
#define MENUSETTINGIMAGE_H
#include "gmenu2x.h"
#include "menusettingfile.h"
using std::string;
class MenuSettingImage : public MenuSettingFile {
public:
MenuSettingImage(GMenu2X *gmenu2x, const string &name, const string &description, string *value, const string &filter="");
virtual ~MenuSettingImage() {};
protected:
virtual void select();
public:
MenuSettingImage(GMenu2X *gmenu2x, const string &name,
const string &description, string *value,
const string &filter = "");
virtual ~MenuSettingImage() {}
virtual void manageInput();
virtual void setValue(const string &value);
};