2010-02-04 13:33:47 +02:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2006 by Massimiliano Torromeo *
|
|
|
|
* massimiliano.torromeo@gmail.com *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the *
|
|
|
|
* Free Software Foundation, Inc., *
|
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
|
|
***************************************************************************/
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2010-12-26 18:58:22 +02:00
|
|
|
#include <sys/ioctl.h>
|
2011-02-22 00:54:07 +02:00
|
|
|
#include <signal.h>
|
2010-02-04 13:33:47 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
#include <sstream>
|
2010-09-17 23:31:09 +03:00
|
|
|
|
2010-02-04 13:33:47 +02:00
|
|
|
#include "linkapp.h"
|
|
|
|
#include "menu.h"
|
|
|
|
#include "selector.h"
|
|
|
|
#include "textmanualdialog.h"
|
2010-09-17 23:31:09 +03:00
|
|
|
#include "debug.h"
|
2010-02-04 13:33:47 +02:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2010-07-28 00:22:46 +03:00
|
|
|
LinkApp::LinkApp(GMenu2X *gmenu2x_, InputManager &inputMgr_,
|
|
|
|
const char* linkfile)
|
2010-07-27 23:12:28 +03:00
|
|
|
: Link(gmenu2x_)
|
2010-07-28 00:22:46 +03:00
|
|
|
, inputMgr(inputMgr_)
|
2010-07-27 23:12:28 +03:00
|
|
|
{
|
2010-02-04 13:33:47 +02:00
|
|
|
manual = "";
|
|
|
|
file = linkfile;
|
|
|
|
wrapper = false;
|
|
|
|
dontleave = false;
|
|
|
|
setClock(336);
|
|
|
|
setVolume(-1);
|
|
|
|
//G
|
|
|
|
//setGamma(0);
|
2010-10-13 23:15:55 +03:00
|
|
|
setBacklight(-1);
|
2010-02-04 13:33:47 +02:00
|
|
|
selectordir = "";
|
|
|
|
selectorfilter = "";
|
|
|
|
icon = iconPath = "";
|
|
|
|
selectorbrowser = false;
|
|
|
|
useRamTimings = false;
|
|
|
|
|
|
|
|
string line;
|
|
|
|
ifstream infile (linkfile, ios_base::in);
|
|
|
|
while (getline(infile, line, '\n')) {
|
|
|
|
line = trim(line);
|
|
|
|
if (line=="") continue;
|
|
|
|
if (line[0]=='#') continue;
|
|
|
|
|
|
|
|
string::size_type position = line.find("=");
|
|
|
|
string name = trim(line.substr(0,position));
|
|
|
|
string value = trim(line.substr(position+1));
|
|
|
|
if (name == "title") {
|
|
|
|
title = value;
|
|
|
|
} else if (name == "description") {
|
|
|
|
description = value;
|
|
|
|
} else if (name == "icon") {
|
|
|
|
setIcon(value);
|
|
|
|
} else if (name == "exec") {
|
|
|
|
exec = value;
|
|
|
|
} else if (name == "params") {
|
|
|
|
params = value;
|
|
|
|
} else if (name == "workdir") {
|
|
|
|
workdir = value;
|
|
|
|
} else if (name == "manual") {
|
|
|
|
manual = value;
|
|
|
|
} else if (name == "wrapper") {
|
|
|
|
if (value=="true") wrapper = true;
|
|
|
|
} else if (name == "dontleave") {
|
|
|
|
if (value=="true") dontleave = true;
|
|
|
|
} else if (name == "clock") {
|
|
|
|
setClock( atoi(value.c_str()) );
|
|
|
|
//G
|
|
|
|
} else if (name == "gamma") {
|
|
|
|
setGamma( atoi(value.c_str()) );
|
|
|
|
} else if (name == "backlight") {
|
|
|
|
setBacklight( atoi(value.c_str()) );
|
|
|
|
} else if (name == "volume") {
|
|
|
|
setVolume( atoi(value.c_str()) );
|
|
|
|
} else if (name == "selectordir") {
|
|
|
|
setSelectorDir( value );
|
|
|
|
} else if (name == "selectorbrowser") {
|
|
|
|
if (value=="true") selectorbrowser = true;
|
|
|
|
} else if (name == "useramtimings") {
|
|
|
|
if (value=="true") useRamTimings = true;
|
|
|
|
} else if (name == "selectorfilter") {
|
|
|
|
setSelectorFilter( value );
|
|
|
|
} else if (name == "selectorscreens") {
|
|
|
|
setSelectorScreens( value );
|
|
|
|
} else if (name == "selectoraliases") {
|
|
|
|
setAliasFile( value );
|
|
|
|
} else {
|
2010-09-17 23:31:09 +03:00
|
|
|
WARNING("Unrecognized option: '%s'\n", name.c_str());
|
2010-02-04 13:33:47 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
infile.close();
|
|
|
|
|
|
|
|
if (iconPath.empty()) searchIcon();
|
|
|
|
|
|
|
|
edited = false;
|
|
|
|
}
|
|
|
|
|
2010-05-02 15:29:09 +03:00
|
|
|
const string &LinkApp::searchIcon() {
|
2010-02-04 13:33:47 +02:00
|
|
|
string execicon = exec;
|
|
|
|
string::size_type pos = exec.rfind(".");
|
|
|
|
if (pos != string::npos) execicon = exec.substr(0,pos);
|
|
|
|
execicon += ".png";
|
|
|
|
string exectitle = execicon;
|
|
|
|
pos = execicon.rfind("/");
|
|
|
|
if (pos != string::npos)
|
|
|
|
string exectitle = execicon.substr(pos+1,execicon.length());
|
|
|
|
|
|
|
|
if (!gmenu2x->sc.getSkinFilePath("icons/"+exectitle).empty())
|
|
|
|
iconPath = gmenu2x->sc.getSkinFilePath("icons/"+exectitle);
|
|
|
|
else if (fileExists(execicon))
|
|
|
|
iconPath = execicon;
|
|
|
|
else
|
|
|
|
iconPath = gmenu2x->sc.getSkinFilePath("icons/generic.png");
|
|
|
|
|
|
|
|
return iconPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
int LinkApp::clock() {
|
|
|
|
return iclock;
|
|
|
|
}
|
|
|
|
|
2010-05-02 15:29:09 +03:00
|
|
|
const string &LinkApp::clockStr(int maxClock) {
|
2010-02-04 13:33:47 +02:00
|
|
|
if (iclock>maxClock) setClock(maxClock);
|
|
|
|
return sclock;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LinkApp::setClock(int mhz) {
|
|
|
|
iclock = constrain(mhz,200,430);
|
|
|
|
stringstream ss;
|
|
|
|
sclock = "";
|
|
|
|
ss << iclock << "Mhz";
|
|
|
|
ss >> sclock;
|
|
|
|
|
|
|
|
edited = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int LinkApp::volume() {
|
|
|
|
return ivolume;
|
|
|
|
}
|
|
|
|
|
2010-05-02 15:29:09 +03:00
|
|
|
const string &LinkApp::volumeStr() {
|
2010-02-04 13:33:47 +02:00
|
|
|
return svolume;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LinkApp::setVolume(int vol) {
|
|
|
|
ivolume = constrain(vol,-1,100);
|
|
|
|
stringstream ss;
|
|
|
|
svolume = "";
|
|
|
|
if (ivolume<0)
|
|
|
|
ss << gmenu2x->confInt["globalVolume"];
|
|
|
|
else
|
|
|
|
ss << ivolume;
|
|
|
|
ss >> svolume;
|
|
|
|
|
|
|
|
edited = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int LinkApp::backlight()
|
|
|
|
{
|
|
|
|
return ibacklight;
|
|
|
|
}
|
|
|
|
|
2010-05-02 15:29:09 +03:00
|
|
|
const string &LinkApp::backlightStr()
|
2010-02-04 13:33:47 +02:00
|
|
|
{
|
|
|
|
return sbacklight;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LinkApp::setBacklight(int val)
|
|
|
|
{
|
2010-10-13 23:15:55 +03:00
|
|
|
ibacklight = constrain(val,-1,100);
|
2010-02-04 13:33:47 +02:00
|
|
|
stringstream ss;
|
|
|
|
sbacklight = "";
|
|
|
|
ss << ibacklight;
|
|
|
|
ss >> sbacklight;
|
|
|
|
|
|
|
|
edited = true;
|
|
|
|
}
|
|
|
|
//G
|
|
|
|
int LinkApp::gamma() {
|
|
|
|
return igamma;
|
|
|
|
}
|
|
|
|
|
2010-05-02 15:29:09 +03:00
|
|
|
const string &LinkApp::gammaStr() {
|
2010-02-04 13:33:47 +02:00
|
|
|
return sgamma;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LinkApp::setGamma(int gamma) {
|
|
|
|
igamma = constrain(gamma,0,100);
|
|
|
|
stringstream ss;
|
|
|
|
sgamma = "";
|
|
|
|
ss << igamma;
|
|
|
|
ss >> sgamma;
|
|
|
|
|
|
|
|
edited = true;
|
|
|
|
}
|
|
|
|
// /G
|
|
|
|
|
|
|
|
bool LinkApp::targetExists() {
|
|
|
|
#ifndef TARGET_GP2X
|
|
|
|
return true; //For displaying elements during testing on pc
|
|
|
|
#endif
|
|
|
|
|
|
|
|
string target = exec;
|
|
|
|
if (!exec.empty() && exec[0]!='/' && !workdir.empty())
|
|
|
|
target = workdir + "/" + exec;
|
|
|
|
|
|
|
|
return fileExists(target);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LinkApp::save() {
|
|
|
|
if (!edited) return false;
|
|
|
|
|
|
|
|
ofstream f(file.c_str());
|
|
|
|
if (f.is_open()) {
|
|
|
|
if (title!="" ) f << "title=" << title << endl;
|
|
|
|
if (description!="" ) f << "description=" << description << endl;
|
|
|
|
if (icon!="" ) f << "icon=" << icon << endl;
|
|
|
|
if (exec!="" ) f << "exec=" << exec << endl;
|
|
|
|
if (params!="" ) f << "params=" << params << endl;
|
|
|
|
if (workdir!="" ) f << "workdir=" << workdir << endl;
|
|
|
|
if (manual!="" ) f << "manual=" << manual << endl;
|
|
|
|
if (iclock!=0 ) f << "clock=" << iclock << endl;
|
|
|
|
if (useRamTimings ) f << "useramtimings=true" << endl;
|
|
|
|
if (ivolume>0 ) f << "volume=" << ivolume << endl;
|
|
|
|
//G
|
|
|
|
if (igamma!=0 ) f << "gamma=" << igamma << endl;
|
2010-06-18 04:12:58 +03:00
|
|
|
if (ibacklight!=0 ) f << "backlight=" << ibacklight << endl;
|
2010-02-04 13:33:47 +02:00
|
|
|
if (selectordir!="" ) f << "selectordir=" << selectordir << endl;
|
|
|
|
if (selectorbrowser ) f << "selectorbrowser=true" << endl;
|
|
|
|
if (selectorfilter!="" ) f << "selectorfilter=" << selectorfilter << endl;
|
|
|
|
if (selectorscreens!="") f << "selectorscreens=" << selectorscreens << endl;
|
|
|
|
if (aliasfile!="" ) f << "selectoraliases=" << aliasfile << endl;
|
|
|
|
if (wrapper ) f << "wrapper=true" << endl;
|
|
|
|
if (dontleave ) f << "dontleave=true" << endl;
|
|
|
|
f.close();
|
|
|
|
sync();
|
|
|
|
return true;
|
|
|
|
} else
|
2010-09-17 23:31:09 +03:00
|
|
|
ERROR("Error while opening the file '%s' for write.\n", file.c_str());
|
2010-02-04 13:33:47 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LinkApp::drawRun() {
|
|
|
|
//Darkened background
|
|
|
|
gmenu2x->s->box(0, 0, gmenu2x->resX, gmenu2x->resY, 0,0,0,150);
|
|
|
|
|
|
|
|
string text = gmenu2x->tr.translate("Launching $1",getTitle().c_str(),NULL);
|
|
|
|
int textW = gmenu2x->font->getTextWidth(text);
|
|
|
|
int boxW = 62+textW;
|
|
|
|
int halfBoxW = boxW/2;
|
|
|
|
|
|
|
|
//outer box
|
2010-05-02 20:53:06 +03:00
|
|
|
gmenu2x->s->box(gmenu2x->halfX-2-halfBoxW, gmenu2x->halfY-23, halfBoxW*2+5, 47, gmenu2x->skinConfColors[COLOR_MESSAGE_BOX_BG]);
|
2010-02-04 13:33:47 +02:00
|
|
|
//inner rectangle
|
2010-05-02 20:53:06 +03:00
|
|
|
gmenu2x->s->rectangle(gmenu2x->halfX-halfBoxW, gmenu2x->halfY-21, boxW, 42, gmenu2x->skinConfColors[COLOR_MESSAGE_BOX_BORDER]);
|
2010-02-04 13:33:47 +02:00
|
|
|
|
|
|
|
int x = gmenu2x->halfX+10-halfBoxW;
|
|
|
|
/*if (getIcon()!="")
|
|
|
|
gmenu2x->sc[getIcon()]->blit(gmenu2x->s,x,104);
|
|
|
|
else
|
|
|
|
gmenu2x->sc["icons/generic.png"]->blit(gmenu2x->s,x,104);*/
|
|
|
|
gmenu2x->sc[getIconPath()]->blit(gmenu2x->s,x,gmenu2x->halfY-16);
|
2011-05-09 06:17:25 +03:00
|
|
|
gmenu2x->s->write( gmenu2x->font, text, x+42, gmenu2x->halfY+1, ASFont::HAlignLeft, ASFont::VAlignMiddle );
|
2010-02-04 13:33:47 +02:00
|
|
|
gmenu2x->s->flip();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LinkApp::run() {
|
|
|
|
if (selectordir!="")
|
|
|
|
selector();
|
|
|
|
else
|
|
|
|
launch();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LinkApp::showManual() {
|
|
|
|
if (manual=="" || !fileExists(manual)) return;
|
|
|
|
|
|
|
|
// Png manuals
|
|
|
|
string ext8 = manual.substr(manual.size()-8,8);
|
|
|
|
if (ext8==".man.png" || ext8==".man.bmp" || ext8==".man.jpg" || manual.substr(manual.size()-9,9)==".man.jpeg") {
|
|
|
|
//Raise the clock to speed-up the loading of the manual
|
|
|
|
gmenu2x->setClock(336);
|
|
|
|
|
|
|
|
Surface pngman(manual);
|
2011-06-02 08:13:59 +03:00
|
|
|
// Note: Copy constructor converts to display format.
|
|
|
|
Surface bg(Surface(gmenu2x->confStr["wallpaper"]));
|
2010-02-04 13:33:47 +02:00
|
|
|
stringstream ss;
|
|
|
|
string pageStatus;
|
|
|
|
|
|
|
|
bool close = false, repaint = true;
|
|
|
|
int page=0, pagecount=pngman.raw->w/320;
|
|
|
|
|
|
|
|
ss << pagecount;
|
|
|
|
string spagecount;
|
|
|
|
ss >> spagecount;
|
|
|
|
|
|
|
|
//Lower the clock
|
|
|
|
gmenu2x->setClock(gmenu2x->confInt["menuClock"]);
|
|
|
|
|
|
|
|
while (!close) {
|
|
|
|
if (repaint) {
|
|
|
|
bg.blit(gmenu2x->s, 0, 0);
|
|
|
|
pngman.blit(gmenu2x->s, -page*320, 0);
|
|
|
|
|
|
|
|
gmenu2x->drawBottomBar();
|
|
|
|
gmenu2x->drawButton(gmenu2x->s, "x", gmenu2x->tr["Exit"],
|
|
|
|
gmenu2x->drawButton(gmenu2x->s, "right", gmenu2x->tr["Change page"],
|
|
|
|
gmenu2x->drawButton(gmenu2x->s, "left", "", 5)-10));
|
|
|
|
|
|
|
|
ss.clear();
|
|
|
|
ss << page+1;
|
|
|
|
ss >> pageStatus;
|
|
|
|
pageStatus = gmenu2x->tr["Page"]+": "+pageStatus+"/"+spagecount;
|
2011-05-09 06:17:25 +03:00
|
|
|
gmenu2x->s->write(gmenu2x->font, pageStatus, 310, 230, ASFont::HAlignRight, ASFont::VAlignMiddle);
|
2010-02-04 13:33:47 +02:00
|
|
|
|
|
|
|
gmenu2x->s->flip();
|
|
|
|
repaint = false;
|
|
|
|
}
|
|
|
|
|
2010-09-17 23:34:26 +03:00
|
|
|
switch(inputMgr.waitForPressedButton()) {
|
|
|
|
case MANUAL:
|
|
|
|
case CLEAR:
|
|
|
|
case SETTINGS:
|
|
|
|
close = true;
|
|
|
|
break;
|
|
|
|
case LEFT:
|
|
|
|
if (page > 0) {
|
|
|
|
page--;
|
|
|
|
repaint = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case RIGHT:
|
|
|
|
if (page < pagecount-1) {
|
|
|
|
page++;
|
|
|
|
repaint=true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-02-04 13:33:47 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Txt manuals
|
|
|
|
if (manual.substr(manual.size()-8,8)==".man.txt") {
|
|
|
|
vector<string> txtman;
|
|
|
|
|
|
|
|
string line;
|
|
|
|
ifstream infile(manual.c_str(), ios_base::in);
|
|
|
|
if (infile.is_open()) {
|
|
|
|
gmenu2x->setClock(336);
|
|
|
|
while (getline(infile, line, '\n')) txtman.push_back(line);
|
|
|
|
infile.close();
|
|
|
|
|
|
|
|
TextManualDialog tmd(gmenu2x, getTitle(), getIconPath(), &txtman);
|
|
|
|
gmenu2x->setClock(gmenu2x->confInt["menuClock"]);
|
|
|
|
tmd.exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Readmes
|
|
|
|
vector<string> readme;
|
|
|
|
|
|
|
|
string line;
|
|
|
|
ifstream infile(manual.c_str(), ios_base::in);
|
|
|
|
if (infile.is_open()) {
|
|
|
|
gmenu2x->setClock(336);
|
|
|
|
while (getline(infile, line, '\n')) readme.push_back(line);
|
|
|
|
infile.close();
|
|
|
|
|
|
|
|
TextDialog td(gmenu2x, getTitle(), "ReadMe", getIconPath(), &readme);
|
|
|
|
gmenu2x->setClock(gmenu2x->confInt["menuClock"]);
|
|
|
|
td.exec();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-02 15:29:09 +03:00
|
|
|
void LinkApp::selector(int startSelection, const string &selectorDir) {
|
2010-02-04 13:33:47 +02:00
|
|
|
//Run selector interface
|
|
|
|
Selector sel(gmenu2x, this, selectorDir);
|
|
|
|
int selection = sel.exec(startSelection);
|
|
|
|
if (selection!=-1) {
|
2010-07-26 06:47:46 +03:00
|
|
|
gmenu2x->writeTmp(selection, sel.getDir());
|
|
|
|
launch(sel.getFile(), sel.getDir());
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-02 15:29:09 +03:00
|
|
|
void LinkApp::launch(const string &selectedFile, const string &selectedDir) {
|
2010-02-04 13:33:47 +02:00
|
|
|
drawRun();
|
|
|
|
save();
|
|
|
|
#ifndef TARGET_GP2X
|
|
|
|
//delay for testing
|
|
|
|
SDL_Delay(1000);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//Set correct working directory
|
|
|
|
string wd = workdir;
|
|
|
|
if (wd=="") {
|
|
|
|
string::size_type pos = exec.rfind("/");
|
|
|
|
if (pos!=string::npos)
|
|
|
|
wd = exec.substr(0,pos);
|
|
|
|
}
|
|
|
|
if (!wd.empty()) {
|
|
|
|
if (wd[0]!='/') wd = gmenu2x->getExePath() + wd;
|
|
|
|
chdir(wd.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
//selectedFile
|
|
|
|
if (selectedFile!="") {
|
|
|
|
string selectedFileExtension;
|
2010-05-02 15:29:09 +03:00
|
|
|
string selectedFileName;
|
|
|
|
string dir;
|
2010-02-04 13:33:47 +02:00
|
|
|
string::size_type i = selectedFile.rfind(".");
|
|
|
|
if (i != string::npos) {
|
|
|
|
selectedFileExtension = selectedFile.substr(i,selectedFile.length());
|
2010-05-02 15:29:09 +03:00
|
|
|
selectedFileName = selectedFile.substr(0,i);
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (selectedDir=="")
|
2010-05-02 15:29:09 +03:00
|
|
|
dir = getSelectorDir();
|
|
|
|
else
|
|
|
|
dir = selectedDir;
|
2010-02-04 13:33:47 +02:00
|
|
|
if (params=="") {
|
2010-05-02 15:29:09 +03:00
|
|
|
params = cmdclean(dir+selectedFile);
|
2010-02-04 13:33:47 +02:00
|
|
|
} else {
|
|
|
|
string origParams = params;
|
2010-05-02 15:29:09 +03:00
|
|
|
params = strreplace(params,"[selFullPath]",cmdclean(dir+selectedFile));
|
|
|
|
params = strreplace(params,"[selPath]",cmdclean(dir));
|
|
|
|
params = strreplace(params,"[selFile]",cmdclean(selectedFileName));
|
2010-02-04 13:33:47 +02:00
|
|
|
params = strreplace(params,"[selExt]",cmdclean(selectedFileExtension));
|
2010-05-02 15:29:09 +03:00
|
|
|
if (params == origParams) params += " " + cmdclean(dir+selectedFile);
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (useRamTimings)
|
|
|
|
gmenu2x->applyRamTimings();
|
|
|
|
if (volume()>=0)
|
|
|
|
gmenu2x->setVolume(volume());
|
|
|
|
|
2010-09-17 23:31:09 +03:00
|
|
|
INFO("Executing '%s' (%s %s)\n", title.c_str(), exec.c_str(), params.c_str());
|
2010-02-04 13:33:47 +02:00
|
|
|
|
|
|
|
//check if we have to quit
|
|
|
|
string command = cmdclean(exec);
|
|
|
|
|
|
|
|
// Check to see if permissions are desirable
|
|
|
|
struct stat fstat;
|
|
|
|
if( stat( command.c_str(), &fstat ) == 0 ) {
|
|
|
|
struct stat newstat = fstat;
|
|
|
|
if( S_IRUSR != ( fstat.st_mode & S_IRUSR ) )
|
|
|
|
newstat.st_mode |= S_IRUSR;
|
|
|
|
if( S_IXUSR != ( fstat.st_mode & S_IXUSR ) )
|
|
|
|
newstat.st_mode |= S_IXUSR;
|
|
|
|
if( fstat.st_mode != newstat.st_mode )
|
|
|
|
chmod( command.c_str(), newstat.st_mode );
|
|
|
|
} // else, well.. we are no worse off :)
|
|
|
|
|
|
|
|
if (params!="") command += " " + params;
|
|
|
|
if (gmenu2x->confInt["outputLogs"]) command += " &> " + cmdclean(gmenu2x->getExePath()) + "/log.txt";
|
|
|
|
if (wrapper) command += "; sync & cd "+cmdclean(gmenu2x->getExePath())+"; exec ./gmenu2x";
|
|
|
|
if (dontleave) {
|
|
|
|
system(command.c_str());
|
|
|
|
} else {
|
|
|
|
if (gmenu2x->confInt["saveSelection"] && (gmenu2x->confInt["section"]!=gmenu2x->menu->selSectionIndex() || gmenu2x->confInt["link"]!=gmenu2x->menu->selLinkIndex()))
|
|
|
|
gmenu2x->writeConfig();
|
|
|
|
if (gmenu2x->fwType == "open2x" && gmenu2x->savedVolumeMode != gmenu2x->volumeMode)
|
|
|
|
gmenu2x->writeConfigOpen2x();
|
|
|
|
if (selectedFile=="")
|
|
|
|
gmenu2x->writeTmp();
|
|
|
|
gmenu2x->quit();
|
|
|
|
if (clock()!=gmenu2x->confInt["menuClock"])
|
|
|
|
gmenu2x->setClock(clock());
|
|
|
|
//if (gamma()!=0 && gamma()!=gmenu2x->confInt["gamma"])
|
|
|
|
// gmenu2x->setGamma(gamma());
|
|
|
|
if((backlight() != 0) && (backlight() != gmenu2x->confInt["backlight"]))
|
|
|
|
gmenu2x->setBacklight(backlight());
|
|
|
|
|
2010-12-26 18:58:22 +02:00
|
|
|
/* Make the terminal we're connected to (via stdin/stdout) our
|
|
|
|
contolling terminal again. Else many console programs are
|
|
|
|
not going to work correctly. Actually this would not be
|
|
|
|
necessary, if SDL correctly restored terminal state after
|
|
|
|
SDL_Quit(). */
|
|
|
|
int pid = setsid();
|
2011-01-05 16:11:54 +02:00
|
|
|
ioctl(1, TIOCSCTTY, STDOUT_FILENO);
|
2010-12-26 18:58:22 +02:00
|
|
|
|
2011-02-22 00:54:07 +02:00
|
|
|
int pgid = tcgetpgrp(STDOUT_FILENO);
|
|
|
|
signal(SIGTTOU, SIG_IGN);
|
|
|
|
tcsetpgrp(STDOUT_FILENO, pgid);
|
|
|
|
|
2010-02-04 13:33:47 +02:00
|
|
|
execlp("/bin/sh","/bin/sh","-c",command.c_str(),NULL);
|
|
|
|
//if execution continues then something went wrong and as we already called SDL_Quit we cannot continue
|
|
|
|
//try relaunching gmenu2x
|
|
|
|
chdir(gmenu2x->getExePath().c_str());
|
|
|
|
execlp("./gmenu2x", "./gmenu2x", NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
chdir(gmenu2x->getExePath().c_str());
|
|
|
|
}
|
|
|
|
|
2010-05-02 15:29:09 +03:00
|
|
|
const string &LinkApp::getExec() {
|
2010-02-04 13:33:47 +02:00
|
|
|
return exec;
|
|
|
|
}
|
|
|
|
|
2010-05-02 15:29:09 +03:00
|
|
|
void LinkApp::setExec(const string &exec) {
|
2010-02-04 13:33:47 +02:00
|
|
|
this->exec = exec;
|
|
|
|
edited = true;
|
|
|
|
}
|
|
|
|
|
2010-05-02 15:29:09 +03:00
|
|
|
const string &LinkApp::getParams() {
|
2010-02-04 13:33:47 +02:00
|
|
|
return params;
|
|
|
|
}
|
|
|
|
|
2010-05-02 15:29:09 +03:00
|
|
|
void LinkApp::setParams(const string ¶ms) {
|
2010-02-04 13:33:47 +02:00
|
|
|
this->params = params;
|
|
|
|
edited = true;
|
|
|
|
}
|
|
|
|
|
2010-05-02 15:29:09 +03:00
|
|
|
const string &LinkApp::getWorkdir() {
|
2010-02-04 13:33:47 +02:00
|
|
|
return workdir;
|
|
|
|
}
|
|
|
|
|
2010-05-02 15:29:09 +03:00
|
|
|
void LinkApp::setWorkdir(const string &workdir) {
|
2010-02-04 13:33:47 +02:00
|
|
|
this->workdir = workdir;
|
|
|
|
edited = true;
|
|
|
|
}
|
|
|
|
|
2010-05-02 15:29:09 +03:00
|
|
|
const string &LinkApp::getManual() {
|
2010-02-04 13:33:47 +02:00
|
|
|
return manual;
|
|
|
|
}
|
|
|
|
|
2010-05-02 15:29:09 +03:00
|
|
|
void LinkApp::setManual(const string &manual) {
|
2010-02-04 13:33:47 +02:00
|
|
|
this->manual = manual;
|
|
|
|
edited = true;
|
|
|
|
}
|
|
|
|
|
2010-05-02 15:29:09 +03:00
|
|
|
const string &LinkApp::getSelectorDir() {
|
2010-02-04 13:33:47 +02:00
|
|
|
return selectordir;
|
|
|
|
}
|
|
|
|
|
2010-05-02 15:29:09 +03:00
|
|
|
void LinkApp::setSelectorDir(const string &selectordir) {
|
2010-02-04 13:33:47 +02:00
|
|
|
this->selectordir = selectordir;
|
2010-05-02 15:29:09 +03:00
|
|
|
if (this->selectordir!="" && this->selectordir[this->selectordir.length()-1]!='/') this->selectordir += "/";
|
2010-02-04 13:33:47 +02:00
|
|
|
edited = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LinkApp::getSelectorBrowser() {
|
|
|
|
return selectorbrowser;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LinkApp::setSelectorBrowser(bool value) {
|
|
|
|
selectorbrowser = value;
|
|
|
|
edited = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LinkApp::getUseRamTimings() {
|
|
|
|
return useRamTimings;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LinkApp::setUseRamTimings(bool value) {
|
|
|
|
useRamTimings = value;
|
|
|
|
edited = true;
|
|
|
|
}
|
|
|
|
|
2010-05-02 15:29:09 +03:00
|
|
|
const string &LinkApp::getSelectorFilter() {
|
2010-02-04 13:33:47 +02:00
|
|
|
return selectorfilter;
|
|
|
|
}
|
|
|
|
|
2010-05-02 15:29:09 +03:00
|
|
|
void LinkApp::setSelectorFilter(const string &selectorfilter) {
|
2010-02-04 13:33:47 +02:00
|
|
|
this->selectorfilter = selectorfilter;
|
|
|
|
edited = true;
|
|
|
|
}
|
|
|
|
|
2010-05-02 15:29:09 +03:00
|
|
|
const string &LinkApp::getSelectorScreens() {
|
2010-02-04 13:33:47 +02:00
|
|
|
return selectorscreens;
|
|
|
|
}
|
|
|
|
|
2010-05-02 15:29:09 +03:00
|
|
|
void LinkApp::setSelectorScreens(const string &selectorscreens) {
|
2010-02-04 13:33:47 +02:00
|
|
|
this->selectorscreens = selectorscreens;
|
|
|
|
edited = true;
|
|
|
|
}
|
|
|
|
|
2010-05-02 15:29:09 +03:00
|
|
|
const string &LinkApp::getAliasFile() {
|
2010-02-04 13:33:47 +02:00
|
|
|
return aliasfile;
|
|
|
|
}
|
|
|
|
|
2010-05-02 15:29:09 +03:00
|
|
|
void LinkApp::setAliasFile(const string &aliasfile) {
|
2010-02-04 13:33:47 +02:00
|
|
|
if (fileExists(aliasfile)) {
|
|
|
|
this->aliasfile = aliasfile;
|
|
|
|
edited = true;
|
|
|
|
}
|
|
|
|
}
|
2010-07-27 22:26:02 +03:00
|
|
|
|
|
|
|
void LinkApp::renameFile(const string &name) {
|
|
|
|
file = name;
|
|
|
|
}
|