mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2025-04-21 12:27:27 +03:00
Merge branch 'install_locations'
Conflicts: configure.in
This commit is contained in:
@@ -65,10 +65,12 @@ void FileLister::setFilter(const string &filter)
|
||||
this->filter = filter;
|
||||
}
|
||||
|
||||
void FileLister::browse()
|
||||
void FileLister::browse(bool clean)
|
||||
{
|
||||
directories.clear();
|
||||
files.clear();
|
||||
if (clean) {
|
||||
directories.clear();
|
||||
files.clear();
|
||||
}
|
||||
|
||||
if (showDirectories || showFiles) {
|
||||
DIR *dirp;
|
||||
@@ -86,8 +88,8 @@ void FileLister::browse()
|
||||
|
||||
while ((dptr = readdir(dirp))) {
|
||||
file = dptr->d_name;
|
||||
file_lowercase = file;
|
||||
std::transform(file_lowercase.begin(), file_lowercase.end(), file_lowercase.begin(), ::tolower);
|
||||
file_lowercase = file;
|
||||
std::transform(file_lowercase.begin(), file_lowercase.end(), file_lowercase.begin(), ::tolower);
|
||||
|
||||
if (file[0] == '.' && file != "..")
|
||||
continue;
|
||||
@@ -104,10 +106,18 @@ void FileLister::browse()
|
||||
if (S_ISDIR(st.st_mode)) {
|
||||
if (!showDirectories)
|
||||
continue;
|
||||
|
||||
if (std::find(directories.begin(), directories.end(), file) != directories.end())
|
||||
continue;
|
||||
|
||||
directories.push_back(file);
|
||||
} else {
|
||||
if (!showFiles)
|
||||
continue;
|
||||
|
||||
if (std::find(files.begin(), files.end(), file) != files.end())
|
||||
continue;
|
||||
|
||||
for (vector<string>::iterator it = vfilter.begin(); it != vfilter.end(); ++it) {
|
||||
if (it->length() <= file.length()) {
|
||||
if (file_lowercase.compare(file.length() - it->length(), it->length(), *it) == 0) {
|
||||
|
||||
@@ -36,7 +36,7 @@ private:
|
||||
|
||||
public:
|
||||
FileLister(const string &startPath = "/boot/local", bool showDirectories = true, bool showFiles = true);
|
||||
void browse();
|
||||
void browse(bool clean = true);
|
||||
|
||||
unsigned int size();
|
||||
unsigned int dirCount();
|
||||
|
||||
@@ -86,6 +86,7 @@ const char *CARD_ROOT = "/card/"; //Note: Add a trailing /!
|
||||
const int CARD_ROOT_LEN = 5;
|
||||
|
||||
static GMenu2X *app;
|
||||
static string gmenu2x_home;
|
||||
|
||||
using namespace std;
|
||||
using namespace fastdelegate;
|
||||
@@ -120,6 +121,11 @@ static void quit_all(int err) {
|
||||
exit(err);
|
||||
}
|
||||
|
||||
const string GMenu2X::getHome(void)
|
||||
{
|
||||
return gmenu2x_home;
|
||||
}
|
||||
|
||||
int main(int /*argc*/, char * /*argv*/[]) {
|
||||
INFO("----\nGMenu2X starting: If you read this message in the logs, check http://gmenu2x.sourceforge.net/page/Troubleshooting for a solution\n----\n");
|
||||
|
||||
@@ -127,6 +133,20 @@ int main(int /*argc*/, char * /*argv*/[]) {
|
||||
signal(SIGSEGV,&quit_all);
|
||||
signal(SIGTERM,&quit_all);
|
||||
|
||||
char *home = getenv("HOME");
|
||||
if (home == NULL) {
|
||||
ERROR("Unable to find gmenu2x home directory. The $HOME variable is not defined.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
gmenu2x_home = (string)home + (string)"/.gmenu2x";
|
||||
if (!fileExists(gmenu2x_home) && mkdir(gmenu2x_home.c_str(), 0770) < 0) {
|
||||
ERROR("Unable to create gmenu2x home directory.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
DEBUG("Home path: %s.\n", gmenu2x_home.c_str());
|
||||
|
||||
app = new GMenu2X();
|
||||
DEBUG("Starting main()\n");
|
||||
app->main();
|
||||
@@ -286,19 +306,23 @@ GMenu2X::GMenu2X() {
|
||||
initMenu();
|
||||
|
||||
if (!fileExists(confStr["wallpaper"])) {
|
||||
DEBUG("Searching wallpaper\n");
|
||||
|
||||
FileLister fl("skins/"+confStr["skin"]+"/wallpapers",false,true);
|
||||
fl.setFilter(".png,.jpg,.jpeg,.bmp");
|
||||
fl.browse();
|
||||
if (fl.getFiles().size()<=0 && confStr["skin"] != "Default")
|
||||
fl.setPath("skins/Default/wallpapers",true);
|
||||
if (fl.getFiles().size()>0)
|
||||
confStr["wallpaper"] = fl.getPath()+fl.getFiles()[0];
|
||||
DEBUG("No wallpaper defined; we will take the default one.\n");
|
||||
confStr["wallpaper"] = DEFAULT_WALLPAPER_PATH;
|
||||
}
|
||||
|
||||
initBG();
|
||||
input.init(path+"input.conf");
|
||||
|
||||
/* If a user-specified input.conf file exists, we load it;
|
||||
* otherwise, we load the default one. */
|
||||
const char *input_file = (getHome() + "/input.conf").c_str();
|
||||
if (fileExists(input_file)) {
|
||||
DEBUG("Loading user-specific input.conf file: %s.\n", input_file);
|
||||
} else {
|
||||
input_file = GMENU2X_SYSTEM_DIR "/input.conf";
|
||||
DEBUG("Loading system input.conf file: %s.\n", input_file);
|
||||
}
|
||||
|
||||
input.init(input_file);
|
||||
PowerSaver::getInstance()->setScreenTimeout( confInt["backlightTimeout"] );
|
||||
setInputSpeed();
|
||||
initServices();
|
||||
@@ -441,7 +465,7 @@ void GMenu2X::initMenu() {
|
||||
menu->addActionLink(i,"USB Nand",MakeDelegate(this,&GMenu2X::activateNandUsb),tr["Activate Usb on Nand"],"skin:icons/usb.png");
|
||||
//menu->addActionLink(i,"USB Root",MakeDelegate(this,&GMenu2X::activateRootUsb),tr["Activate Usb on the root of the Gp2x Filesystem"],"skin:icons/usb.png");*/
|
||||
#endif
|
||||
if (fileExists(path+"log.txt"))
|
||||
if (fileExists(getHome()+"/log.txt"))
|
||||
menu->addActionLink(i,tr["Log Viewer"],MakeDelegate(this,&GMenu2X::viewLog),tr["Displays last launched program's output"],"skin:icons/ebook.png");
|
||||
menu->addActionLink(i,tr["About"],MakeDelegate(this,&GMenu2X::about),tr["Info about GMenu2X"],"skin:icons/about.png");
|
||||
}
|
||||
@@ -507,7 +531,7 @@ and all the anonymous donors...\n\
|
||||
}
|
||||
|
||||
void GMenu2X::viewLog() {
|
||||
string logfile = path+"log.txt";
|
||||
string logfile = getHome()+"/log.txt";
|
||||
if (fileExists(logfile)) {
|
||||
ifstream inf(logfile.c_str(), ios_base::in);
|
||||
if (inf.is_open()) {
|
||||
@@ -536,7 +560,7 @@ void GMenu2X::viewLog() {
|
||||
}
|
||||
|
||||
void GMenu2X::readConfig() {
|
||||
string conffile = path+"gmenu2x.conf";
|
||||
string conffile = getHome() + "/gmenu2x.conf";
|
||||
if (fileExists(conffile)) {
|
||||
ifstream inf(conffile.c_str(), ios_base::in);
|
||||
if (inf.is_open()) {
|
||||
@@ -573,7 +597,7 @@ void GMenu2X::readConfig() {
|
||||
|
||||
void GMenu2X::writeConfig() {
|
||||
ledOn();
|
||||
string conffile = path+"gmenu2x.conf";
|
||||
string conffile = getHome() + "/gmenu2x.conf";
|
||||
ofstream inf(conffile.c_str());
|
||||
if (inf.is_open()) {
|
||||
ConfStrHash::iterator endS = confStr.end();
|
||||
@@ -642,7 +666,15 @@ void GMenu2X::writeConfigOpen2x() {
|
||||
|
||||
void GMenu2X::writeSkinConfig() {
|
||||
ledOn();
|
||||
string conffile = path+"skins/"+confStr["skin"]+"/skin.conf";
|
||||
|
||||
string conffile = getHome() + "/skins/";
|
||||
if (!fileExists(conffile))
|
||||
mkdir(conffile.c_str(), 0770);
|
||||
conffile = conffile + confStr["skin"];
|
||||
if (!fileExists(conffile))
|
||||
mkdir(conffile.c_str(), 0770);
|
||||
conffile = conffile + "/skin.conf";
|
||||
|
||||
ofstream inf(conffile.c_str());
|
||||
if (inf.is_open()) {
|
||||
ConfStrHash::iterator endS = skinConfStr.end();
|
||||
@@ -1104,8 +1136,11 @@ void GMenu2X::options() {
|
||||
int prevbacklight = confInt["backlight"];
|
||||
bool showRootFolder = fileExists(CARD_ROOT);
|
||||
|
||||
FileLister fl_tr("translations");
|
||||
FileLister fl_tr(getHome() + "/translations");
|
||||
fl_tr.browse();
|
||||
fl_tr.setPath(GMENU2X_SYSTEM_DIR "/translations", false);
|
||||
fl_tr.browse(false);
|
||||
|
||||
fl_tr.insertFile("English");
|
||||
string lang = tr.lang();
|
||||
|
||||
@@ -1172,9 +1207,12 @@ void GMenu2X::settingsOpen2x() {
|
||||
}
|
||||
|
||||
void GMenu2X::skinMenu() {
|
||||
FileLister fl_sk("skins",true,false);
|
||||
FileLister fl_sk(getHome() + "/skins", true, false);
|
||||
fl_sk.addExclude("..");
|
||||
fl_sk.browse();
|
||||
fl_sk.setPath(GMENU2X_SYSTEM_DIR "/skins", false);
|
||||
fl_sk.browse(false);
|
||||
|
||||
string curSkin = confStr["skin"];
|
||||
|
||||
SettingsDialog sd(this, input, ts, tr["Skin"]);
|
||||
@@ -1224,8 +1262,12 @@ void GMenu2X::setSkin(const string &skin, bool setWallpaper) {
|
||||
skinConfColors[COLOR_MESSAGE_BOX_BORDER] = (RGBAColor){80,80,80,255};
|
||||
skinConfColors[COLOR_MESSAGE_BOX_SELECTION] = (RGBAColor){160,160,160,255};
|
||||
|
||||
//load skin settings
|
||||
string skinconfname = "skins/"+skin+"/skin.conf";
|
||||
/* Load skin settings from user directory if present,
|
||||
* or from the system directory. */
|
||||
string skinconfname = getHome() + "/skins/" + skin + "/skin.conf";
|
||||
if (!fileExists(skinconfname))
|
||||
skinconfname = GMENU2X_SYSTEM_DIR "/skins/" + skin + "/skin.conf";
|
||||
|
||||
if (fileExists(skinconfname)) {
|
||||
ifstream skinconf(skinconfname.c_str(), ios_base::in);
|
||||
if (skinconf.is_open()) {
|
||||
@@ -1597,19 +1639,22 @@ void GMenu2X::renameSection() {
|
||||
&& find(menu->getSections().begin(),menu->getSections().end(), id.getInput())
|
||||
== menu->getSections().end()) {
|
||||
//section directory doesn't exists
|
||||
string newsectiondir = "sections/" + id.getInput();
|
||||
string sectiondir = "sections/" + menu->selSection();
|
||||
string newsectiondir = getHome() + "/sections/" + id.getInput();
|
||||
string sectiondir = getHome() + "/sections/" + menu->selSection();
|
||||
ledOn();
|
||||
if (rename(sectiondir.c_str(), "tmpsection")==0 && rename("tmpsection", newsectiondir.c_str())==0) {
|
||||
string oldpng = sectiondir+".png", newpng = newsectiondir+".png";
|
||||
string oldicon = sc.getSkinFilePath(oldpng), newicon = sc.getSkinFilePath(newpng);
|
||||
|
||||
if (!rename(sectiondir.c_str(), newsectiondir.c_str())) {
|
||||
string oldpng = menu->selSection() + ".png";
|
||||
string newpng = id.getInput() + ".png";
|
||||
string oldicon = sc.getSkinFilePath(oldpng);
|
||||
string newicon = sc.getSkinFilePath(newpng);
|
||||
|
||||
if (!oldicon.empty() && newicon.empty()) {
|
||||
newicon = oldicon;
|
||||
newicon.replace(newicon.find(oldpng), oldpng.length(), newpng);
|
||||
|
||||
if (!fileExists(newicon)) {
|
||||
rename(oldicon.c_str(), "tmpsectionicon");
|
||||
rename("tmpsectionicon", newicon.c_str());
|
||||
rename(oldicon.c_str(), newicon.c_str());
|
||||
sc.move("skin:"+oldpng, "skin:"+newpng);
|
||||
}
|
||||
}
|
||||
@@ -1627,7 +1672,7 @@ void GMenu2X::deleteSection() {
|
||||
mb.setButton(CLEAR, tr["No"]);
|
||||
if (mb.exec() == ACCEPT) {
|
||||
ledOn();
|
||||
if (rmtree(path+"sections/"+menu->selSection())) {
|
||||
if (rmtree(getHome() + "/sections/" + menu->selSection())) {
|
||||
menu->deleteSelectedSection();
|
||||
sync();
|
||||
}
|
||||
|
||||
@@ -37,6 +37,15 @@
|
||||
#include <vector>
|
||||
#include <tr1/unordered_map>
|
||||
|
||||
#ifndef GMENU2X_SYSTEM_DIR
|
||||
#define GMENU2X_SYSTEM_DIR "/usr/share/gmenu2x"
|
||||
#endif
|
||||
|
||||
#ifndef DEFAULT_WALLPAPER_PATH
|
||||
#define DEFAULT_WALLPAPER_PATH \
|
||||
GMENU2X_SYSTEM_DIR "/skins/Default/wallpapers/default.png"
|
||||
#endif
|
||||
|
||||
const int MAX_VOLUME_SCALE_FACTOR = 200;
|
||||
// Default values - going to add settings adjustment, saving, loading and such
|
||||
const int VOLUME_SCALER_MUTE = 0;
|
||||
@@ -153,6 +162,10 @@ public:
|
||||
~GMenu2X();
|
||||
void quit();
|
||||
|
||||
/* Returns the home directory of gmenu2x, usually
|
||||
* ~/.gmenu2x */
|
||||
static const string getHome(void);
|
||||
|
||||
/*
|
||||
* Variables needed for elements disposition
|
||||
*/
|
||||
|
||||
@@ -484,7 +484,7 @@ void LinkApp::launch(const string &selectedFile, const string &selectedDir) {
|
||||
} // else, well.. we are no worse off :)
|
||||
|
||||
if (params!="") command += " " + params;
|
||||
if (gmenu2x->confInt["outputLogs"]) command += " &> " + cmdclean(gmenu2x->getExePath()) + "/log.txt";
|
||||
if (gmenu2x->confInt["outputLogs"]) command += " &> " + cmdclean(gmenu2x->getHome()) + "/log.txt";
|
||||
if (wrapper) command += "; sync & cd "+cmdclean(gmenu2x->getExePath())+"; exec ./gmenu2x";
|
||||
if (dontleave) {
|
||||
system(command.c_str());
|
||||
|
||||
112
src/menu.cpp
112
src/menu.cpp
@@ -39,26 +39,9 @@ Menu::Menu(GMenu2X *gmenu2x) {
|
||||
this->gmenu2x = gmenu2x;
|
||||
iFirstDispSection = 0;
|
||||
|
||||
DIR *dirp;
|
||||
struct stat st;
|
||||
struct dirent *dptr;
|
||||
string filepath;
|
||||
readSections(GMENU2X_SYSTEM_DIR "/sections");
|
||||
readSections(GMenu2X::getHome() + "/sections");
|
||||
|
||||
if ((dirp = opendir("sections")) == NULL) return;
|
||||
|
||||
while ((dptr = readdir(dirp))) {
|
||||
if (dptr->d_name[0]=='.') continue;
|
||||
filepath = (string)"sections/"+dptr->d_name;
|
||||
int statRet = stat(filepath.c_str(), &st);
|
||||
if (!S_ISDIR(st.st_mode)) continue;
|
||||
if (statRet != -1) {
|
||||
sections.push_back((string)dptr->d_name);
|
||||
linklist ll;
|
||||
links.push_back(ll);
|
||||
}
|
||||
}
|
||||
|
||||
closedir(dirp);
|
||||
sort(sections.begin(),sections.end(),case_less());
|
||||
setSectionIndex(0);
|
||||
readLinks();
|
||||
@@ -72,6 +55,34 @@ uint Menu::firstDispRow() {
|
||||
return iFirstDispRow;
|
||||
}
|
||||
|
||||
void Menu::readSections(std::string parentDir)
|
||||
{
|
||||
DIR *dirp;
|
||||
struct stat st;
|
||||
struct dirent *dptr;
|
||||
|
||||
dirp = opendir(parentDir.c_str());
|
||||
if (!dirp) return;
|
||||
|
||||
while ((dptr = readdir(dirp))) {
|
||||
int statret;
|
||||
if (dptr->d_name[0]=='.') continue;
|
||||
|
||||
string filepath = parentDir + "/" + dptr->d_name;
|
||||
statret = stat(filepath.c_str(), &st);
|
||||
if (!S_ISDIR(st.st_mode)) continue;
|
||||
if (statret != -1) {
|
||||
if (find(sections.begin(), sections.end(), (string)dptr->d_name) == sections.end()) {
|
||||
sections.push_back((string)dptr->d_name);
|
||||
linklist ll;
|
||||
links.push_back(ll);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
closedir(dirp);
|
||||
}
|
||||
|
||||
void Menu::loadIcons() {
|
||||
//reload section icons
|
||||
for (uint i=0; i<sections.size(); i++) {
|
||||
@@ -154,11 +165,6 @@ void Menu::setSectionIndex(int i) {
|
||||
iFirstDispRow = 0;
|
||||
}
|
||||
|
||||
string Menu::sectionPath(int section) {
|
||||
if (section<0 || section>(int)sections.size()) section = iSection;
|
||||
return "sections/"+sections[section]+"/";
|
||||
}
|
||||
|
||||
/*====================================
|
||||
LINKS MANAGEMENT
|
||||
====================================*/
|
||||
@@ -198,14 +204,18 @@ bool Menu::addLink(string path, string file, string section) {
|
||||
title = title.substr(0, pos);
|
||||
}
|
||||
|
||||
string linkpath = "sections/"+section+"/"+title;
|
||||
string linkpath = GMenu2X::getHome()+"/sections/"+section;
|
||||
if (!fileExists(linkpath))
|
||||
mkdir(linkpath.c_str(), 0755);
|
||||
|
||||
linkpath += "/" + title;
|
||||
int x=2;
|
||||
while (fileExists(linkpath)) {
|
||||
stringstream ss;
|
||||
linkpath = "";
|
||||
ss << x;
|
||||
ss >> linkpath;
|
||||
linkpath = "sections/"+section+"/"+title+linkpath;
|
||||
linkpath = GMenu2X::getHome()+"/sections/"+section+"/"+title+linkpath;
|
||||
x++;
|
||||
}
|
||||
|
||||
@@ -284,8 +294,12 @@ bool Menu::addLink(string path, string file, string section) {
|
||||
}
|
||||
|
||||
bool Menu::addSection(const string §ionName) {
|
||||
string sectiondir = "sections/"+sectionName;
|
||||
if (mkdir(sectiondir.c_str(),0777)==0) {
|
||||
string sectiondir = GMenu2X::getHome() + "/sections";
|
||||
if (!fileExists(sectiondir))
|
||||
mkdir(sectiondir.c_str(), 0755);
|
||||
|
||||
sectiondir = sectiondir + "/" + sectionName;
|
||||
if (mkdir(sectiondir.c_str(), 0755) == 0) {
|
||||
sections.push_back(sectionName);
|
||||
linklist ll;
|
||||
links.push_back(ll);
|
||||
@@ -394,32 +408,44 @@ void Menu::setLinkIndex(int i) {
|
||||
iLink = i;
|
||||
}
|
||||
|
||||
void Menu::readLinksOfSection(std::string path, std::vector<std::string> &linkfiles)
|
||||
{
|
||||
DIR *dirp;
|
||||
struct stat st;
|
||||
struct dirent *dptr;
|
||||
|
||||
if ((dirp = opendir(path.c_str())) == NULL) return;
|
||||
|
||||
while ((dptr = readdir(dirp))) {
|
||||
if (dptr->d_name[0] == '.') continue;
|
||||
string filepath = path + "/" + dptr->d_name;
|
||||
int statret = stat(filepath.c_str(), &st);
|
||||
if (S_ISDIR(st.st_mode)) continue;
|
||||
if (statret != -1)
|
||||
linkfiles.push_back(filepath);
|
||||
}
|
||||
|
||||
closedir(dirp);
|
||||
}
|
||||
|
||||
void Menu::readLinks() {
|
||||
vector<string> linkfiles;
|
||||
|
||||
iLink = 0;
|
||||
iFirstDispRow = 0;
|
||||
|
||||
DIR *dirp;
|
||||
struct stat st;
|
||||
struct dirent *dptr;
|
||||
string filepath;
|
||||
|
||||
for (uint i=0; i<links.size(); i++) {
|
||||
links[i].clear();
|
||||
linkfiles.clear();
|
||||
|
||||
if ((dirp = opendir(sectionPath(i).c_str())) == NULL) continue;
|
||||
int correct = (i>sections.size() ? iSection : i);
|
||||
|
||||
while ((dptr = readdir(dirp))) {
|
||||
if (dptr->d_name[0]=='.') continue;
|
||||
filepath = sectionPath(i)+dptr->d_name;
|
||||
int statRet = stat(filepath.c_str(), &st);
|
||||
if (S_ISDIR(st.st_mode)) continue;
|
||||
if (statRet != -1) {
|
||||
linkfiles.push_back(filepath);
|
||||
}
|
||||
}
|
||||
readLinksOfSection(GMENU2X_SYSTEM_DIR "/sections/"
|
||||
+ sections[correct], linkfiles);
|
||||
|
||||
readLinksOfSection(GMenu2X::getHome() + "/sections/"
|
||||
+ sections[correct], linkfiles);
|
||||
|
||||
sort(linkfiles.begin(), linkfiles.end(),case_less());
|
||||
for (uint x=0; x<linkfiles.size(); x++) {
|
||||
@@ -430,8 +456,6 @@ void Menu::readLinks() {
|
||||
else
|
||||
free(link);
|
||||
}
|
||||
|
||||
closedir(dirp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,12 @@ private:
|
||||
void readLinks();
|
||||
void freeLinks();
|
||||
|
||||
// Load all the sections of the given "sections" directory.
|
||||
void readSections(std::string parentDir);
|
||||
|
||||
// Load all the links on the given section directory.
|
||||
void readLinksOfSection(std::string path, std::vector<std::string> &linkfiles);
|
||||
|
||||
public:
|
||||
Menu(GMenu2X *gmenu2x);
|
||||
~Menu();
|
||||
@@ -80,8 +86,6 @@ public:
|
||||
void linkDown();
|
||||
void setLinkIndex(int i);
|
||||
|
||||
string sectionPath(int section = -1);
|
||||
|
||||
const vector<string> &getSections() { return sections; }
|
||||
void renameSection(int index, const string &name);
|
||||
};
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "imageio.h"
|
||||
#include "utilities.h"
|
||||
#include "debug.h"
|
||||
#include "surfacecollection.h"
|
||||
|
||||
#include <SDL_gfxPrimitives.h>
|
||||
|
||||
@@ -54,13 +55,10 @@ Surface *Surface::emptySurface(int width, int height) {
|
||||
|
||||
Surface *Surface::loadImage(const string &img, const string &skin) {
|
||||
string skinpath;
|
||||
if (!skin.empty() && !img.empty() && img[0]!='/') {
|
||||
skinpath = "skins/"+skin+"/"+img;
|
||||
if (!fileExists(skinpath))
|
||||
skinpath = "skins/Default/"+img;
|
||||
} else {
|
||||
skinpath = img;
|
||||
}
|
||||
if (!skin.empty() && !img.empty() && img[0]!='/')
|
||||
skinpath = SurfaceCollection::getSkinFilePath(skin, img);
|
||||
else
|
||||
skinpath = img;
|
||||
|
||||
SDL_Surface *raw = loadPNG(skinpath);
|
||||
if (!raw) {
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "surface.h"
|
||||
#include "utilities.h"
|
||||
#include "debug.h"
|
||||
#include "gmenu2x.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
@@ -39,16 +40,39 @@ void SurfaceCollection::setSkin(const string &skin) {
|
||||
this->skin = skin;
|
||||
}
|
||||
|
||||
string SurfaceCollection::getSkinFilePath(const string &file) {
|
||||
string prefix = "/usr/share/gmenu2x/";
|
||||
if (fileExists("skins/"+skin+"/"+file))
|
||||
return "skins/"+skin+"/"+file;
|
||||
else if (fileExists("skins/Default/"+file))
|
||||
return "skins/Default/"+file;
|
||||
else if (fileExists(prefix+"skins/Default/"+file))
|
||||
return prefix+"skins/Default/"+file;
|
||||
else
|
||||
return "";
|
||||
/* Returns the location of a skin directory,
|
||||
* from its name given as a parameter. */
|
||||
string SurfaceCollection::getSkinPath(const string &skin)
|
||||
{
|
||||
string path = GMenu2X::getHome() + "/skins/" + skin;
|
||||
if (fileExists(path))
|
||||
return path;
|
||||
|
||||
path = GMENU2X_SYSTEM_DIR "/skins/" + skin;
|
||||
if (fileExists(path))
|
||||
return path;
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
string SurfaceCollection::getSkinFilePath(const string &file)
|
||||
{
|
||||
return SurfaceCollection::getSkinFilePath(skin, file);
|
||||
}
|
||||
|
||||
string SurfaceCollection::getSkinFilePath(const string &skin, const string &file)
|
||||
{
|
||||
/* We first search the skin file on the user-specific directory. */
|
||||
string path = GMenu2X::getHome() + "/skins/" + skin + "/" + file;
|
||||
if (fileExists(path))
|
||||
return path;
|
||||
|
||||
/* If not found, we search that skin file on the system directory. */
|
||||
path = GMENU2X_SYSTEM_DIR "/skins/" + skin + "/" + file;
|
||||
if (fileExists(path))
|
||||
return path;
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
void SurfaceCollection::debug() {
|
||||
|
||||
@@ -39,6 +39,8 @@ public:
|
||||
|
||||
void setSkin(const std::string &skin);
|
||||
std::string getSkinFilePath(const std::string &file);
|
||||
static std::string getSkinFilePath(const std::string &skin, const std::string &file);
|
||||
static std::string getSkinPath(const std::string &skin);
|
||||
|
||||
bool defaultAlpha;
|
||||
void debug();
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "translator.h"
|
||||
#include "debug.h"
|
||||
#include "gmenu2x.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -44,7 +45,10 @@ void Translator::setLang(const string &lang) {
|
||||
translations.clear();
|
||||
|
||||
string line;
|
||||
ifstream infile (string("translations/"+lang).c_str(), ios_base::in);
|
||||
ifstream infile ((GMenu2X::getHome() + "/translations/" + lang).c_str(), ios_base::in);
|
||||
if (!infile.is_open())
|
||||
infile.open((string(GMENU2X_SYSTEM_DIR "/translations/") + lang).c_str(), ios_base::in);
|
||||
|
||||
if (infile.is_open()) {
|
||||
while (getline(infile, line, '\n')) {
|
||||
line = trim(line);
|
||||
|
||||
@@ -35,19 +35,37 @@ bool WallpaperDialog::exec()
|
||||
{
|
||||
bool close = false, result = true;
|
||||
|
||||
FileLister fl("skins/"+gmenu2x->confStr["skin"]+"/wallpapers");
|
||||
FileLister fl;
|
||||
fl.setFilter(".png,.jpg,.jpeg,.bmp");
|
||||
vector<string> wallpapers;
|
||||
if (fileExists("skins/"+gmenu2x->confStr["skin"]+"/wallpapers")) {
|
||||
fl.browse();
|
||||
wallpapers = fl.getFiles();
|
||||
|
||||
string filepath = GMenu2X::getHome() + "/skins/"
|
||||
+ gmenu2x->confStr["skin"] + "/wallpapers";
|
||||
if (fileExists(filepath))
|
||||
fl.setPath(filepath, true);
|
||||
|
||||
filepath = GMENU2X_SYSTEM_DIR "/skins/"
|
||||
+ gmenu2x->confStr["skin"] + "/wallpapers";
|
||||
if (fileExists(filepath)) {
|
||||
fl.setPath(filepath, false);
|
||||
fl.browse(false);
|
||||
}
|
||||
|
||||
if (gmenu2x->confStr["skin"] != "Default") {
|
||||
fl.setPath("skins/Default/wallpapers",true);
|
||||
for (uint i=0; i<fl.getFiles().size(); i++)
|
||||
wallpapers.push_back(fl.getFiles()[i]);
|
||||
filepath = GMenu2X::getHome() + "/skins/Default/wallpapers";
|
||||
if (fileExists(filepath)) {
|
||||
fl.setPath(filepath, false);
|
||||
fl.browse(false);
|
||||
}
|
||||
|
||||
filepath = GMENU2X_SYSTEM_DIR "/skins/Default/wallpapers";
|
||||
if (fileExists(filepath)) {
|
||||
fl.setPath(filepath, false);
|
||||
fl.browse(false);
|
||||
}
|
||||
}
|
||||
|
||||
vector<string> wallpapers = fl.getFiles();
|
||||
|
||||
DEBUG("Wallpapers: %i\n", wallpapers.size());
|
||||
|
||||
uint i, selected = 0, firstElement = 0, iY;
|
||||
@@ -57,10 +75,7 @@ bool WallpaperDialog::exec()
|
||||
if (selected<firstElement) firstElement=selected;
|
||||
|
||||
//Wallpaper
|
||||
if (selected<wallpapers.size()-fl.getFiles().size())
|
||||
gmenu2x->sc["skins/"+gmenu2x->confStr["skin"]+"/wallpapers/"+wallpapers[selected]]->blit(gmenu2x->s,0,0);
|
||||
else
|
||||
gmenu2x->sc["skins/Default/wallpapers/"+wallpapers[selected]]->blit(gmenu2x->s,0,0);
|
||||
gmenu2x->sc[((string)"skin:wallpapers/" + wallpapers[selected]).c_str()]->blit(gmenu2x->s, 0, 0);
|
||||
|
||||
gmenu2x->drawTopBar(gmenu2x->s);
|
||||
gmenu2x->drawBottomBar(gmenu2x->s);
|
||||
@@ -111,22 +126,16 @@ bool WallpaperDialog::exec()
|
||||
break;
|
||||
case ACCEPT:
|
||||
close = true;
|
||||
if (wallpapers.size() > 0) {
|
||||
if (selected < wallpapers.size() - fl.getFiles().size())
|
||||
wallpaper = "skins/" + gmenu2x->confStr["skin"] + "/wallpapers/" + wallpapers[selected];
|
||||
else
|
||||
wallpaper = "skins/Default/wallpapers/" + wallpapers[selected];
|
||||
} else result = false;
|
||||
if (wallpapers.size() > 0)
|
||||
wallpaper = gmenu2x->sc.getSkinFilePath("wallpapers/" + wallpapers[selected]);
|
||||
else result = false;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (uint i=0; i<wallpapers.size(); i++)
|
||||
if (i<wallpapers.size()-fl.getFiles().size())
|
||||
gmenu2x->sc.del("skins/"+gmenu2x->confStr["skin"]+"/wallpapers/"+wallpapers[i]);
|
||||
else
|
||||
gmenu2x->sc.del("skins/Default/wallpapers/"+wallpapers[i]);
|
||||
gmenu2x->sc.del("skin:wallpapers/" + wallpapers[i]);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user