Root/src/menusettingimage.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 "menusettingimage.h"
21#include "imagedialog.h"
22#include "utilities.h"
23
24using std::string;
25
26MenuSettingImage::MenuSettingImage(GMenu2X *gmenu2x, const string &name, const string &description, string *value, const string &filter)
27    : MenuSettingFile(gmenu2x, name, description, value, filter)
28{
29}
30
31void MenuSettingImage::edit() {
32    ImageDialog id(gmenu2x, description, filter, value());
33    if (id.exec()) setValue(id.getPath() + "/" + id.getFile());
34}
35
36void MenuSettingImage::setValue(const string &value) {
37    string skinpath(gmenu2x->getExePath() + "skins/" + gmenu2x->confStr["skin"]);
38    bool inSkinDir = value.substr(0, skinpath.length()) == skinpath;
39    if (!inSkinDir && gmenu2x->confStr["skin"] != "Default") {
40        skinpath = gmenu2x->getExePath() + "skins/Default";
41        inSkinDir = value.substr(0, skinpath.length()) == skinpath;
42    }
43    if (inSkinDir) {
44        string tempIcon = value.substr(skinpath.length(), value.length());
45        string::size_type pos = tempIcon.find("/");
46        if (pos != string::npos) {
47            *_value = "skin:" + tempIcon.substr(pos + 1, value.length());
48        } else {
49            *_value = value;
50        }
51    } else {
52        *_value = value;
53    }
54}
55

Archive Download this file



interactive