From 40a26e1a9cc74364dc7f7ee51a8c24e903606a95 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sun, 2 May 2010 14:29:09 +0200 Subject: [PATCH] pass strings by reference where possible --- src/asfont.cpp | 2 +- src/asfont.h | 2 +- src/dirdialog.cpp | 2 +- src/dirdialog.h | 2 +- src/filedialog.cpp | 4 +-- src/filedialog.h | 6 ++-- src/filelister.cpp | 13 +++---- src/filelister.h | 10 +++--- src/gmenu2x.cpp | 16 ++++----- src/gmenu2x.h | 18 +++++----- src/iconbutton.cpp | 10 +++--- src/iconbutton.h | 10 +++--- src/imagedialog.cpp | 11 +++--- src/imagedialog.h | 2 +- src/inputdialog.cpp | 2 +- src/inputdialog.h | 2 +- src/inputmanager.cpp | 2 +- src/inputmanager.h | 2 +- src/link.cpp | 30 +++++++++------- src/link.h | 18 +++++----- src/linkapp.cpp | 66 ++++++++++++++++++---------------- src/linkapp.h | 46 ++++++++++++------------ src/listview.cpp | 2 +- src/listview.h | 2 +- src/listviewitem.cpp | 2 +- src/listviewitem.h | 2 +- src/menu.cpp | 8 ++--- src/menu.h | 6 ++-- src/menusetting.cpp | 2 +- src/menusetting.h | 2 +- src/menusettingbool.cpp | 4 +-- src/menusettingbool.h | 4 +-- src/menusettingdir.cpp | 6 ++-- src/menusettingdir.h | 6 ++-- src/menusettingfile.cpp | 6 ++-- src/menusettingfile.h | 6 ++-- src/menusettingimage.cpp | 11 +++--- src/menusettingimage.h | 4 +-- src/menusettingint.cpp | 2 +- src/menusettingint.h | 2 +- src/menusettingmultistring.cpp | 2 +- src/menusettingmultistring.h | 2 +- src/menusettingrgba.cpp | 2 +- src/menusettingrgba.h | 2 +- src/menusettingstring.cpp | 6 ++-- src/menusettingstring.h | 6 ++-- src/messagebox.cpp | 2 +- src/messagebox.h | 2 +- src/selector.cpp | 4 +-- src/selector.h | 4 +-- src/selectordetector.cpp | 4 +-- src/selectordetector.h | 8 ++--- src/settingsdialog.cpp | 2 +- src/settingsdialog.h | 2 +- src/sfontplus.cpp | 10 +++--- src/sfontplus.h | 10 +++--- src/surface.cpp | 15 ++++---- src/surface.h | 10 +++--- src/surfacecollection.cpp | 22 ++++++------ src/surfacecollection.h | 22 ++++++------ src/textdialog.cpp | 2 +- src/textdialog.h | 2 +- src/textmanualdialog.cpp | 2 +- src/textmanualdialog.h | 2 +- src/translator.cpp | 10 +++--- src/translator.h | 10 +++--- src/utilities.cpp | 14 ++++---- src/utilities.h | 14 ++++---- 68 files changed, 279 insertions(+), 267 deletions(-) diff --git a/src/asfont.cpp b/src/asfont.cpp index e6cfdbb..40b3169 100644 --- a/src/asfont.cpp +++ b/src/asfont.cpp @@ -18,7 +18,7 @@ ASFont::ASFont(Surface* font) { halfLineHeight = getLineHeight()/2; } -ASFont::ASFont(string font) { +ASFont::ASFont(const string &font) { this->font.initFont(font); halfHeight = getHeight()/2; halfLineHeight = getLineHeight()/2; diff --git a/src/asfont.h b/src/asfont.h index b28efcb..2ac318f 100644 --- a/src/asfont.h +++ b/src/asfont.h @@ -24,7 +24,7 @@ class ASFont { public: ASFont(SDL_Surface* font); ASFont(Surface* font); - ASFont(string font); + ASFont(const string &font); ~ASFont(); bool utf8Code(unsigned char c); diff --git a/src/dirdialog.cpp b/src/dirdialog.cpp index c495a74..4558cbd 100644 --- a/src/dirdialog.cpp +++ b/src/dirdialog.cpp @@ -33,7 +33,7 @@ using namespace std; using namespace fastdelegate; -DirDialog::DirDialog(GMenu2X *gmenu2x, string text, string dir) { +DirDialog::DirDialog(GMenu2X *gmenu2x, const string &text, const string &dir) { this->gmenu2x = gmenu2x; this->text = text; selRow = 0; diff --git a/src/dirdialog.h b/src/dirdialog.h index 42fd927..ff12fe9 100644 --- a/src/dirdialog.h +++ b/src/dirdialog.h @@ -56,7 +56,7 @@ private: public: string path; - DirDialog(GMenu2X *gmenu2x, string text, string dir=""); + DirDialog(GMenu2X *gmenu2x, const string &text, const string &dir=""); bool exec(); }; diff --git a/src/filedialog.cpp b/src/filedialog.cpp index 99abde9..e9c47ce 100644 --- a/src/filedialog.cpp +++ b/src/filedialog.cpp @@ -30,7 +30,7 @@ using namespace std; -FileDialog::FileDialog(GMenu2X *gmenu2x, string text, string filter, string file) { +FileDialog::FileDialog(GMenu2X *gmenu2x, const string &text, const string &filter, const string &file) { this->gmenu2x = gmenu2x; this->text = text; this->filter = filter; @@ -176,7 +176,7 @@ bool FileDialog::exec() { return result; } -void FileDialog::setPath(string path) { +void FileDialog::setPath(const string &path) { path_v = path; fl.setPath(path); selected = 0; diff --git a/src/filedialog.h b/src/filedialog.h index 605d742..7c495c8 100644 --- a/src/filedialog.h +++ b/src/filedialog.h @@ -51,11 +51,11 @@ protected: public: string file; - FileDialog(GMenu2X *gmenu2x, string text, string filter="", string file=""); + FileDialog(GMenu2X *gmenu2x, const string &text, const string &filter="", const string &file=""); virtual ~FileDialog() {}; - virtual string path() { return path_v; }; - virtual void setPath(string path); + virtual const string &path() { return path_v; }; + virtual void setPath(const string &path); inline virtual void beforeFileList(); inline virtual void onChangeDir(); diff --git a/src/filelister.cpp b/src/filelister.cpp index 1b43c25..3a87c33 100644 --- a/src/filelister.cpp +++ b/src/filelister.cpp @@ -30,26 +30,27 @@ using namespace std; -FileLister::FileLister(string startPath, bool showDirectories, bool showFiles) { +FileLister::FileLister(const string &startPath, bool showDirectories, bool showFiles) { this->showDirectories = showDirectories; this->showFiles = showFiles; setPath(startPath,false); } -string FileLister::getPath() { +const string &FileLister::getPath() { return path; } -void FileLister::setPath(string path, bool doBrowse) { - if (path[path.length()-1]!='/') path += "/"; +void FileLister::setPath(const string &path, bool doBrowse) { this->path = path; + if (this->path[path.length()-1]!='/') + this->path += "/"; if (doBrowse) browse(); } -string FileLister::getFilter() { +const string &FileLister::getFilter() { return filter; } -void FileLister::setFilter(string filter) { +void FileLister::setFilter(const string &filter) { this->filter = filter; } diff --git a/src/filelister.h b/src/filelister.h index 2f61ea8..9455f88 100644 --- a/src/filelister.h +++ b/src/filelister.h @@ -33,7 +33,7 @@ private: bool showDirectories, showFiles; public: - FileLister(string startPath = "/boot/local", bool showDirectories = true, bool showFiles = true); + FileLister(const string &startPath = "/boot/local", bool showDirectories = true, bool showFiles = true); void browse(); vector directories, files, exclude; @@ -45,10 +45,10 @@ public: bool isFile(uint); bool isDirectory(uint); - string getPath(); - void setPath(string path, bool doBrowse=true); - string getFilter(); - void setFilter(string filter); + const string &getPath(); + void setPath(const string &path, bool doBrowse=true); + const string &getFilter(); + void setFilter(const string &filter); }; #endif /*FILELISTER_H_*/ diff --git a/src/gmenu2x.cpp b/src/gmenu2x.cpp index d668a13..f878e09 100644 --- a/src/gmenu2x.cpp +++ b/src/gmenu2x.cpp @@ -695,7 +695,7 @@ void GMenu2X::readTmp() { } } -void GMenu2X::writeTmp(int selelem, string selectordir) { +void GMenu2X::writeTmp(int selelem, const string &selectordir) { string conffile = "/tmp/gmenu2x.tmp"; ofstream inf(conffile.c_str()); if (inf.is_open()) { @@ -1122,7 +1122,7 @@ void GMenu2X::toggleTvOut() { #endif } -void GMenu2X::setSkin(string skin, bool setWallpaper) { +void GMenu2X::setSkin(const string &skin, bool setWallpaper) { confStr["skin"] = skin; //Clear previous skin settings @@ -1847,7 +1847,7 @@ int GMenu2X::getVolumeScaler() { return currentscalefactor; } -string GMenu2X::getExePath() { +const string &GMenu2X::getExePath() { if (path.empty()) { char buf[255]; int l = readlink("/proc/self/exe",buf,255); @@ -1882,7 +1882,7 @@ int GMenu2X::drawButton(IconButton *btn, int x, int y) { return x+btn->getRect().w+6; } -int GMenu2X::drawButton(Surface *s, string btn, string text, int x, int y) { +int GMenu2X::drawButton(Surface *s, const string &btn, const string &text, int x, int y) { if (y<0) y = resY+y; SDL_Rect re = {x, y-7, 0, 16}; if (sc.skinRes("imgs/buttons/"+btn+".png") != NULL) { @@ -1894,7 +1894,7 @@ int GMenu2X::drawButton(Surface *s, string btn, string text, int x, int y) { return x+re.w+6; } -int GMenu2X::drawButtonRight(Surface *s, string btn, string text, int x, int y) { +int GMenu2X::drawButtonRight(Surface *s, const string &btn, const string &text, int x, int y) { if (y<0) y = resY+y; if (sc.skinRes("imgs/buttons/"+btn+".png") != NULL) { x -= 16; @@ -1923,7 +1923,7 @@ void GMenu2X::drawScrollBar(uint pagesize, uint totalsize, uint pagepos, uint to s->box(resX-6, by, 3, bs, skinConfColors["selectionBg"]); } -void GMenu2X::drawTitleIcon(string icon, bool skinRes, Surface *s) { +void GMenu2X::drawTitleIcon(const string &icon, bool skinRes, Surface *s) { if (s==NULL) s = this->s; Surface *i = NULL; @@ -1940,12 +1940,12 @@ void GMenu2X::drawTitleIcon(string icon, bool skinRes, Surface *s) { i->blit(s,4,(skinConfInt["topBarHeight"]-32)/2); } -void GMenu2X::writeTitle(string title, Surface *s) { +void GMenu2X::writeTitle(const string &title, Surface *s) { if (s==NULL) s = this->s; s->write(font,title,40, skinConfInt["topBarHeight"]/4, SFontHAlignLeft, SFontVAlignMiddle); } -void GMenu2X::writeSubTitle(string subtitle, Surface *s) { +void GMenu2X::writeSubTitle(const string &subtitle, Surface *s) { if (s==NULL) s = this->s; s->write(font,subtitle,40, skinConfInt["topBarHeight"]/4*3, SFontHAlignLeft, SFontVAlignMiddle); } diff --git a/src/gmenu2x.h b/src/gmenu2x.h index 8c0d46c..443fd06 100644 --- a/src/gmenu2x.h +++ b/src/gmenu2x.h @@ -85,7 +85,7 @@ private: */ unsigned short getBatteryLevel(); FILE* batteryHandle, *backlightHandle, *usbHandle, *acHandle; - void browsePath(string path, vector* directories, vector* files); + void browsePath(const string &path, vector* directories, vector* files); /*! Starts the scanning of the nand and sd filesystems, searching for dge and gpu files and creating the links in 2 dedicated sections. */ @@ -146,7 +146,7 @@ public: @see path @return String containing the parent directory */ - string getExePath(); + const string &getExePath(); InputManager input; Touchscreen ts; @@ -158,7 +158,7 @@ public: //Configuration settings bool useSelectionPng; - void setSkin(string skin, bool setWallpaper = true); + void setSkin(const string &skin, bool setWallpaper = true); //firmware type and version string fwType, fwVersion; //gp2x type @@ -212,7 +212,7 @@ public: void writeConfig(); void writeConfigOpen2x(); void writeSkinConfig(); - void writeTmp(int selelem=-1, string selectordir=""); + void writeTmp(int selelem=-1, const string &selectordir=""); void ledOn(); void ledOff(); @@ -226,13 +226,13 @@ public: void initBG(); int drawButton(IconButton *btn, int x=5, int y=-10); - int drawButton(Surface *s, string btn, string text, int x=5, int y=-10); - int drawButtonRight(Surface *s, string btn, string text, int x=5, int y=-10); + int drawButton(Surface *s, const string &btn, const string &text, int x=5, int y=-10); + int drawButtonRight(Surface *s, const string &btn, const string &text, int x=5, int y=-10); void drawScrollBar(uint pagesize, uint totalsize, uint pagepos, uint top, uint height); - void drawTitleIcon(string icon, bool skinRes=true, Surface *s=NULL); - void writeTitle(string title, Surface *s=NULL); - void writeSubTitle(string subtitle, Surface *s=NULL); + void drawTitleIcon(const string &icon, bool skinRes=true, Surface *s=NULL); + void writeTitle(const string &title, Surface *s=NULL); + void writeSubTitle(const string &subtitle, Surface *s=NULL); void drawTopBar(Surface *s=NULL); void drawBottomBar(Surface *s=NULL); diff --git a/src/iconbutton.cpp b/src/iconbutton.cpp index bca0050..93aa6da 100644 --- a/src/iconbutton.cpp +++ b/src/iconbutton.cpp @@ -4,7 +4,7 @@ using namespace std; using namespace fastdelegate; -IconButton::IconButton(GMenu2X *gmenu2x, string icon, string label) : Button(gmenu2x) { +IconButton::IconButton(GMenu2X *gmenu2x, const string &icon, const string &label) : Button(gmenu2x) { this->gmenu2x = gmenu2x; this->icon = icon; labelPosition = IconButton::DISP_RIGHT; @@ -93,11 +93,11 @@ void IconButton::recalcSize() { setSize(w, h); } -string IconButton::getLabel() { +const string &IconButton::getLabel() { return label; } -void IconButton::setLabel(string label) { +void IconButton::setLabel(const string &label) { this->label = label; } @@ -107,11 +107,11 @@ void IconButton::setLabelPosition(int pos, int margin) { recalcSize(); } -string IconButton::getIcon() { +const string &IconButton::getIcon() { return icon; } -void IconButton::setIcon(string icon) { +void IconButton::setIcon(const string &icon) { this->icon = icon; recalcSize(); } diff --git a/src/iconbutton.h b/src/iconbutton.h index 7397c1b..9c4a465 100644 --- a/src/iconbutton.h +++ b/src/iconbutton.h @@ -22,7 +22,7 @@ public: static const int DISP_TOP = 2; static const int DISP_BOTTOM = 3; - IconButton(GMenu2X *gmenu2x, string icon, string label=""); + IconButton(GMenu2X *gmenu2x, const string &icon, const string &label=""); virtual ~IconButton() {}; virtual void paint(); @@ -30,12 +30,12 @@ public: void setPosition(int x, int y); - string getLabel(); - void setLabel(string label); + const string &getLabel(); + void setLabel(const string &label); void setLabelPosition(int pos, int margin); - string getIcon(); - void setIcon(string icon); + const string &getIcon(); + void setIcon(const string &icon); void setAction(ButtonAction action); }; diff --git a/src/imagedialog.cpp b/src/imagedialog.cpp index 4bfdd31..0959be9 100644 --- a/src/imagedialog.cpp +++ b/src/imagedialog.cpp @@ -31,20 +31,19 @@ using namespace std; -ImageDialog::ImageDialog(GMenu2X *gmenu2x, string text, string filter, string file) : FileDialog(gmenu2x, text, filter, file) { +ImageDialog::ImageDialog(GMenu2X *gmenu2x, const string &text, const string &filter, const string &file) : FileDialog(gmenu2x, text, filter, file) { this->gmenu2x = gmenu2x; this->text = text; this->filter = filter; - this->file = ""; setPath("/card"); title = "Image Browser"; if (!file.empty()) { - file = strreplace(file,"skin:",gmenu2x->getExePath()+"skins/"+gmenu2x->confStr["skin"]+"/"); - string::size_type pos = file.rfind("/"); + this->file = strreplace(file,"skin:",gmenu2x->getExePath()+"skins/"+gmenu2x->confStr["skin"]+"/"); + string::size_type pos = this->file.rfind("/"); if (pos != string::npos) { - setPath( file.substr(0, pos) ); + setPath( this->file.substr(0, pos) ); cout << "ib: " << path() << endl; - this->file = file.substr(pos+1,file.length()); + this->file = this->file.substr(pos+1,file.length()); } } selRow = 0; diff --git a/src/imagedialog.h b/src/imagedialog.h index 2d0652a..3044ac7 100644 --- a/src/imagedialog.h +++ b/src/imagedialog.h @@ -31,7 +31,7 @@ class ImageDialog : public FileDialog { protected: SurfaceCollection previews; public: - ImageDialog(GMenu2X *gmenu2x, string text, string filter="", string file=""); + ImageDialog(GMenu2X *gmenu2x, const string &text, const string &filter="", const string &file=""); virtual ~ImageDialog(); inline virtual void beforeFileList(); inline virtual void onChangeDir(); diff --git a/src/inputdialog.cpp b/src/inputdialog.cpp index c802207..8708acd 100644 --- a/src/inputdialog.cpp +++ b/src/inputdialog.cpp @@ -26,7 +26,7 @@ using namespace std; using namespace fastdelegate; -InputDialog::InputDialog(GMenu2X *gmenu2x, string text, string startvalue, string title, string icon) { +InputDialog::InputDialog(GMenu2X *gmenu2x, const string &text, const string &startvalue, const string &title, const string &icon) { this->gmenu2x = gmenu2x; if (title=="") { this->title = text; diff --git a/src/inputdialog.h b/src/inputdialog.h index 2cdb060..a1236d1 100644 --- a/src/inputdialog.h +++ b/src/inputdialog.h @@ -67,7 +67,7 @@ private: void setKeyboard(int); public: - InputDialog(GMenu2X *gmenu2x, string text, string startvalue="", string title="", string icon=""); + InputDialog(GMenu2X *gmenu2x, const string &text, const string &startvalue="", const string &title="", const string &icon=""); string input; bool exec(); diff --git a/src/inputmanager.cpp b/src/inputmanager.cpp index 93e2529..704b409 100644 --- a/src/inputmanager.cpp +++ b/src/inputmanager.cpp @@ -34,7 +34,7 @@ InputManager::~InputManager() { SDL_JoystickClose(joysticks[x]); } -void InputManager::init(string conffile) { +void InputManager::init(const string &conffile) { SDL_JoystickEventState(SDL_IGNORE); int numJoy = SDL_NumJoysticks(); diff --git a/src/inputmanager.h b/src/inputmanager.h index 5a00885..9e65614 100644 --- a/src/inputmanager.h +++ b/src/inputmanager.h @@ -72,7 +72,7 @@ public: InputManager(); ~InputManager(); - void init(string conffile = "input.conf"); + void init(const string &conffile = "input.conf"); vector joysticks; vector actions; diff --git a/src/link.cpp b/src/link.cpp index c5b352f..0945be9 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -57,59 +57,63 @@ void Link::updateSurfaces() iconSurface = gmenu2x->sc[getIconPath()]; } -string Link::getTitle() { +const string &Link::getTitle() { return title; } -void Link::setTitle(string title) { +void Link::setTitle(const string &title) { this->title = title; edited = true; } -string Link::getDescription() { +const string &Link::getDescription() { return description; } -void Link::setDescription(string description) { +void Link::setDescription(const string &description) { this->description = description; edited = true; } -string Link::getIcon() { +const string &Link::getIcon() { return icon; } -void Link::setIcon(string icon) { +void Link::setIcon(const string &icon) { string skinpath = gmenu2x->getExePath()+"skins/"+gmenu2x->confStr["skin"]; + if (icon.substr(0,skinpath.length()) == skinpath) { string tempIcon = icon.substr(skinpath.length(), icon.length()); string::size_type pos = tempIcon.find("/"); if (pos != string::npos) - icon = "skin:"+tempIcon.substr(pos+1,icon.length()); + this->icon = "skin:"+tempIcon.substr(pos+1,icon.length()); + else + this->icon = icon; + } else { + this->icon = icon; } - iconPath = strreplace(icon,"skin:",skinpath+"/"); + iconPath = strreplace(this->icon,"skin:",skinpath+"/"); if (iconPath.empty() || !fileExists(iconPath)) { - iconPath = strreplace(icon,"skin:",gmenu2x->getExePath()+"skins/Default/"); + iconPath = strreplace(this->icon,"skin:",gmenu2x->getExePath()+"skins/Default/"); if (!fileExists(iconPath)) searchIcon(); } - this->icon = icon; edited = true; updateSurfaces(); } -string Link::searchIcon() { +const string &Link::searchIcon() { iconPath = gmenu2x->sc.getSkinFilePath("icons/generic.png"); return iconPath; } -string Link::getIconPath() { +const string &Link::getIconPath() { if (iconPath.empty()) searchIcon(); return iconPath; } -void Link::setIconPath(string icon) { +void Link::setIconPath(const string &icon) { if (fileExists(icon)) iconPath = icon; else diff --git a/src/link.h b/src/link.h index 0f5695d..a73fea5 100644 --- a/src/link.h +++ b/src/link.h @@ -59,15 +59,15 @@ public: void setSize(int w, int h); void setPosition(int x, int y); - string getTitle(); - void setTitle(string title); - string getDescription(); - void setDescription(string description); - string getIcon(); - void setIcon(string icon); - virtual string searchIcon(); - string getIconPath(); - void setIconPath(string icon); + const string &getTitle(); + void setTitle(const string &title); + const string &getDescription(); + void setDescription(const string &description); + const string &getIcon(); + void setIcon(const string &icon); + virtual const string &searchIcon(); + const string &getIconPath(); + void setIconPath(const string &icon); virtual void run(); }; diff --git a/src/linkapp.cpp b/src/linkapp.cpp index 88d27e1..192a0c1 100644 --- a/src/linkapp.cpp +++ b/src/linkapp.cpp @@ -109,7 +109,7 @@ LinkApp::LinkApp(GMenu2X *gmenu2x, const char* linkfile) edited = false; } -string LinkApp::searchIcon() { +const string &LinkApp::searchIcon() { string execicon = exec; string::size_type pos = exec.rfind("."); if (pos != string::npos) execicon = exec.substr(0,pos); @@ -133,7 +133,7 @@ int LinkApp::clock() { return iclock; } -string LinkApp::clockStr(int maxClock) { +const string &LinkApp::clockStr(int maxClock) { if (iclock>maxClock) setClock(maxClock); return sclock; } @@ -152,7 +152,7 @@ int LinkApp::volume() { return ivolume; } -string LinkApp::volumeStr() { +const string &LinkApp::volumeStr() { return svolume; } @@ -174,7 +174,7 @@ int LinkApp::backlight() return ibacklight; } -string LinkApp::backlightStr() +const string &LinkApp::backlightStr() { return sbacklight; } @@ -194,7 +194,7 @@ int LinkApp::gamma() { return igamma; } -string LinkApp::gammaStr() { +const string &LinkApp::gammaStr() { return sgamma; } @@ -372,7 +372,7 @@ void LinkApp::showManual() { } } -void LinkApp::selector(int startSelection, string selectorDir) { +void LinkApp::selector(int startSelection, const string &selectorDir) { //Run selector interface Selector sel(gmenu2x, this, selectorDir); int selection = sel.exec(startSelection); @@ -382,7 +382,7 @@ void LinkApp::selector(int startSelection, string selectorDir) { } } -void LinkApp::launch(string selectedFile, string selectedDir) { +void LinkApp::launch(const string &selectedFile, const string &selectedDir) { drawRun(); save(); #ifndef TARGET_GP2X @@ -405,23 +405,27 @@ void LinkApp::launch(string selectedFile, string selectedDir) { //selectedFile if (selectedFile!="") { string selectedFileExtension; + string selectedFileName; + string dir; string::size_type i = selectedFile.rfind("."); if (i != string::npos) { selectedFileExtension = selectedFile.substr(i,selectedFile.length()); - selectedFile = selectedFile.substr(0,i); + selectedFileName = selectedFile.substr(0,i); } if (selectedDir=="") - selectedDir = getSelectorDir(); + dir = getSelectorDir(); + else + dir = selectedDir; if (params=="") { - params = cmdclean(selectedDir+selectedFile+selectedFileExtension); + params = cmdclean(dir+selectedFile); } else { string origParams = params; - params = strreplace(params,"[selFullPath]",cmdclean(selectedDir+selectedFile+selectedFileExtension)); - params = strreplace(params,"[selPath]",cmdclean(selectedDir)); - params = strreplace(params,"[selFile]",cmdclean(selectedFile)); + params = strreplace(params,"[selFullPath]",cmdclean(dir+selectedFile)); + params = strreplace(params,"[selPath]",cmdclean(dir)); + params = strreplace(params,"[selFile]",cmdclean(selectedFileName)); params = strreplace(params,"[selExt]",cmdclean(selectedFileExtension)); - if (params == origParams) params += " " + cmdclean(selectedDir+selectedFile+selectedFileExtension); + if (params == origParams) params += " " + cmdclean(dir+selectedFile); } } @@ -480,49 +484,49 @@ void LinkApp::launch(string selectedFile, string selectedDir) { chdir(gmenu2x->getExePath().c_str()); } -string LinkApp::getExec() { +const string &LinkApp::getExec() { return exec; } -void LinkApp::setExec(string exec) { +void LinkApp::setExec(const string &exec) { this->exec = exec; edited = true; } -string LinkApp::getParams() { +const string &LinkApp::getParams() { return params; } -void LinkApp::setParams(string params) { +void LinkApp::setParams(const string ¶ms) { this->params = params; edited = true; } -string LinkApp::getWorkdir() { +const string &LinkApp::getWorkdir() { return workdir; } -void LinkApp::setWorkdir(string workdir) { +void LinkApp::setWorkdir(const string &workdir) { this->workdir = workdir; edited = true; } -string LinkApp::getManual() { +const string &LinkApp::getManual() { return manual; } -void LinkApp::setManual(string manual) { +void LinkApp::setManual(const string &manual) { this->manual = manual; edited = true; } -string LinkApp::getSelectorDir() { +const string &LinkApp::getSelectorDir() { return selectordir; } -void LinkApp::setSelectorDir(string selectordir) { - if (selectordir!="" && selectordir[selectordir.length()-1]!='/') selectordir += "/"; +void LinkApp::setSelectorDir(const string &selectordir) { this->selectordir = selectordir; + if (this->selectordir!="" && this->selectordir[this->selectordir.length()-1]!='/') this->selectordir += "/"; edited = true; } @@ -544,29 +548,29 @@ void LinkApp::setUseRamTimings(bool value) { edited = true; } -string LinkApp::getSelectorFilter() { +const string &LinkApp::getSelectorFilter() { return selectorfilter; } -void LinkApp::setSelectorFilter(string selectorfilter) { +void LinkApp::setSelectorFilter(const string &selectorfilter) { this->selectorfilter = selectorfilter; edited = true; } -string LinkApp::getSelectorScreens() { +const string &LinkApp::getSelectorScreens() { return selectorscreens; } -void LinkApp::setSelectorScreens(string selectorscreens) { +void LinkApp::setSelectorScreens(const string &selectorscreens) { this->selectorscreens = selectorscreens; edited = true; } -string LinkApp::getAliasFile() { +const string &LinkApp::getAliasFile() { return aliasfile; } -void LinkApp::setAliasFile(string aliasfile) { +void LinkApp::setAliasFile(const string &aliasfile) { if (fileExists(aliasfile)) { this->aliasfile = aliasfile; edited = true; diff --git a/src/linkapp.h b/src/linkapp.h index 37a0b1d..fe67731 100644 --- a/src/linkapp.h +++ b/src/linkapp.h @@ -52,46 +52,46 @@ private: public: LinkApp(GMenu2X *gmenu2x, const char* linkfile); - virtual string searchIcon(); + virtual const string &searchIcon(); - string getExec(); - void setExec(string exec); - string getParams(); - void setParams(string params); - string getWorkdir(); - void setWorkdir(string workdir); - string getManual(); - void setManual(string manual); - string getSelectorDir(); - void setSelectorDir(string selectordir); + const string &getExec(); + void setExec(const string &exec); + const string &getParams(); + void setParams(const string ¶ms); + const string &getWorkdir(); + void setWorkdir(const string &workdir); + const string &getManual(); + void setManual(const string &manual); + const string &getSelectorDir(); + void setSelectorDir(const string &selectordir); bool getSelectorBrowser(); void setSelectorBrowser(bool value); bool getUseRamTimings(); void setUseRamTimings(bool value); - string getSelectorScreens(); - void setSelectorScreens(string selectorscreens); - string getSelectorFilter(); - void setSelectorFilter(string selectorfilter); - string getAliasFile(); - void setAliasFile(string aliasfile); + const string &getSelectorScreens(); + void setSelectorScreens(const string &selectorscreens); + const string &getSelectorFilter(); + void setSelectorFilter(const string &selectorfilter); + const string &getAliasFile(); + void setAliasFile(const string &aliasfile); string file; int clock(); - string clockStr(int maxClock); + const string &clockStr(int maxClock); void setClock(int mhz); int volume(); - string volumeStr(); + const string &volumeStr(); void setVolume(int vol); //G int gamma(); - string gammaStr(); + const string &gammaStr(); void setGamma(int gamma); int backlight(); - string backlightStr(); + const string &backlightStr(); void setBacklight(int val); // /G @@ -101,8 +101,8 @@ public: bool save(); void run(); void showManual(); - void selector(int startSelection=0, string selectorDir=""); - void launch(string selectedFile="", string selectedDir=""); + void selector(int startSelection=0, const string &selectorDir=""); + void launch(const string &selectedFile="", const string &selectedDir=""); bool targetExists(); }; diff --git a/src/listview.cpp b/src/listview.cpp index a295ca9..8d612ea 100644 --- a/src/listview.cpp +++ b/src/listview.cpp @@ -13,7 +13,7 @@ ListViewItem * ListView::add(ListViewItem *item) { return item; } -ListViewItem * ListView::add(string text) { +ListViewItem * ListView::add(const string &text) { ListViewItem *item = new ListViewItem(this,text); return add(item); } diff --git a/src/listview.h b/src/listview.h index e8dd6e1..13c740a 100644 --- a/src/listview.h +++ b/src/listview.h @@ -41,7 +41,7 @@ public: GMenu2X *gmenu2x; ListViewItem *add(ListViewItem *item); - ListViewItem *add(string text); + ListViewItem *add(const string &text); void del(ListViewItem *item); void del(int itemIndex); void clear(); diff --git a/src/listviewitem.cpp b/src/listviewitem.cpp index 59ed829..6e2ac18 100644 --- a/src/listviewitem.cpp +++ b/src/listviewitem.cpp @@ -1,7 +1,7 @@ #include "listview.h" #include "listviewitem.h" -ListViewItem::ListViewItem(ListView * parent, string text) { +ListViewItem::ListViewItem(ListView * parent, const string &text) { this->parent = parent; rect.h = 16; rect.w = parent->getWidth(); diff --git a/src/listviewitem.h b/src/listviewitem.h index 7c03e08..a52d2b8 100644 --- a/src/listviewitem.h +++ b/src/listviewitem.h @@ -32,7 +32,7 @@ protected: SDL_Rect rect; public: - ListViewItem(ListView *parent, string text); + ListViewItem(ListView *parent, const string &text); virtual ~ListViewItem(); string text; diff --git a/src/menu.cpp b/src/menu.cpp index 7a3f631..1b7f25d 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -133,7 +133,7 @@ int Menu::selSectionIndex() { return iSection; } -string Menu::selSection() { +const string &Menu::selSection() { return sections[iSection]; } @@ -161,7 +161,7 @@ string Menu::sectionPath(int section) { /*==================================== LINKS MANAGEMENT ====================================*/ -bool Menu::addActionLink(uint section, string title, LinkRunAction action, string description, string icon) { +bool Menu::addActionLink(uint section, const string &title, const LinkRunAction &action, const string &description, const string &icon) { if (section>=sections.size()) return false; LinkAction *linkact = new LinkAction(gmenu2x,action); @@ -183,7 +183,6 @@ bool Menu::addLink(string path, string file, string section) { if (!addSection(section)) return false; } - if (path[path.length()-1]!='/') path += "/"; //if the extension is not equal to gpu or dge then enable the wrapepr by default bool wrapper = false, pxml = false; @@ -213,6 +212,7 @@ bool Menu::addLink(string path, string file, string section) { cout << "\033[0;34mGMENU2X:\033[0m Adding link: " << linkpath << endl; #endif + if (path[path.length()-1]!='/') path += "/"; //search for a manual pos = file.rfind("."); string exename = path+file.substr(0,pos); @@ -306,7 +306,7 @@ bool Menu::addLink(string path, string file, string section) { return true; } -bool Menu::addSection(string sectionName) { +bool Menu::addSection(const string §ionName) { string sectiondir = "sections/"+sectionName; if (mkdir(sectiondir.c_str(),0777)==0) { sections.push_back(sectionName); diff --git a/src/menu.h b/src/menu.h index a832b41..48a3281 100644 --- a/src/menu.h +++ b/src/menu.h @@ -54,16 +54,16 @@ public: linklist *sectionLinks(int i = -1); int selSectionIndex(); - string selSection(); + const string &selSection(); void decSectionIndex(); void incSectionIndex(); void setSectionIndex(int i); uint firstDispSection(); uint firstDispRow(); - bool addActionLink(uint section, string title, LinkRunAction action, string description="", string icon=""); + bool addActionLink(uint section, const string &title, const LinkRunAction &action, const string &description="", const string &icon=""); bool addLink(string path, string file, string section=""); - bool addSection(string sectionName); + bool addSection(const string §ionName); void deleteSelectedLink(); void deleteSelectedSection(); diff --git a/src/menusetting.cpp b/src/menusetting.cpp index 4f5fc97..dde4213 100644 --- a/src/menusetting.cpp +++ b/src/menusetting.cpp @@ -19,7 +19,7 @@ ***************************************************************************/ #include "menusetting.h" -MenuSetting::MenuSetting(GMenu2X *gmenu2x, string name, string description) { +MenuSetting::MenuSetting(GMenu2X *gmenu2x, const string &name, const string &description) { this->gmenu2x = gmenu2x; this->name = name; this->description = description; diff --git a/src/menusetting.h b/src/menusetting.h index 6f83341..415472e 100644 --- a/src/menusetting.h +++ b/src/menusetting.h @@ -38,7 +38,7 @@ private: GMenu2X *gmenu2x; public: - MenuSetting(GMenu2X *gmenu2x, string name, string description); + MenuSetting(GMenu2X *gmenu2x, const string &name, const string &description); virtual ~MenuSetting() {}; virtual void draw(int y); diff --git a/src/menusettingbool.cpp b/src/menusettingbool.cpp index 4a4e54a..7d9e134 100644 --- a/src/menusettingbool.cpp +++ b/src/menusettingbool.cpp @@ -24,7 +24,7 @@ using namespace std; using namespace fastdelegate; -MenuSettingBool::MenuSettingBool(GMenu2X *gmenu2x, string name, string description, int *value) +MenuSettingBool::MenuSettingBool(GMenu2X *gmenu2x, const string &name, const string &description, int *value) : MenuSetting(gmenu2x,name,description) { this->gmenu2x = gmenu2x; _ivalue = value; @@ -36,7 +36,7 @@ MenuSettingBool::MenuSettingBool(GMenu2X *gmenu2x, string name, string descripti btnToggle->setAction(MakeDelegate(this, &MenuSettingBool::toggle)); } -MenuSettingBool::MenuSettingBool(GMenu2X *gmenu2x, string name, string description, bool *value) +MenuSettingBool::MenuSettingBool(GMenu2X *gmenu2x, const string &name, const string &description, bool *value) : MenuSetting(gmenu2x,name,description) { this->gmenu2x = gmenu2x; _value = value; diff --git a/src/menusettingbool.h b/src/menusettingbool.h index 9373a7d..e6af68b 100644 --- a/src/menusettingbool.h +++ b/src/menusettingbool.h @@ -38,8 +38,8 @@ private: void toggle(); public: - MenuSettingBool(GMenu2X *gmenu2x, string name, string description, bool *value); - MenuSettingBool(GMenu2X *gmenu2x, string name, string description, int *value); + MenuSettingBool(GMenu2X *gmenu2x, const string &name, const string &description, bool *value); + MenuSettingBool(GMenu2X *gmenu2x, const string &name, const string &description, int *value); virtual ~MenuSettingBool() {}; virtual void draw(int y); diff --git a/src/menusettingdir.cpp b/src/menusettingdir.cpp index a98dc18..893d553 100644 --- a/src/menusettingdir.cpp +++ b/src/menusettingdir.cpp @@ -24,7 +24,7 @@ using namespace std; using namespace fastdelegate; -MenuSettingDir::MenuSettingDir(GMenu2X *gmenu2x, string name, string description, string *value) +MenuSettingDir::MenuSettingDir(GMenu2X *gmenu2x, const string &name, const string &description, string *value) : MenuSetting(gmenu2x,name,description) { this->gmenu2x = gmenu2x; _value = value; @@ -61,11 +61,11 @@ void MenuSettingDir::select() { if (dd.exec()) setValue( dd.path ); } -void MenuSettingDir::setValue(string value) { +void MenuSettingDir::setValue(const string &value) { *_value = value; } -string MenuSettingDir::value() { +const string &MenuSettingDir::value() { return *_value; } diff --git a/src/menusettingdir.h b/src/menusettingdir.h index e5c4c3a..794b839 100644 --- a/src/menusettingdir.h +++ b/src/menusettingdir.h @@ -36,7 +36,7 @@ private: void clear(); public: - MenuSettingDir(GMenu2X *gmenu2x, string name, string description, string *value); + MenuSettingDir(GMenu2X *gmenu2x, const string &name, const string &description, string *value); virtual ~MenuSettingDir() {}; virtual void draw(int y); @@ -46,8 +46,8 @@ public: virtual void drawSelected(int y); virtual bool edited(); - void setValue(string value); - string value(); + void setValue(const string &value); + const string &value(); }; #endif diff --git a/src/menusettingfile.cpp b/src/menusettingfile.cpp index 5317226..de6cd0a 100644 --- a/src/menusettingfile.cpp +++ b/src/menusettingfile.cpp @@ -24,7 +24,7 @@ using namespace std; using namespace fastdelegate; -MenuSettingFile::MenuSettingFile(GMenu2X *gmenu2x, string name, string description, string *value, string filter) +MenuSettingFile::MenuSettingFile(GMenu2X *gmenu2x, const string &name, const string &description, string *value, const string &filter) : MenuSetting(gmenu2x,name,description) { this->gmenu2x = gmenu2x; this->filter = filter; @@ -62,11 +62,11 @@ void MenuSettingFile::select() { if (fd.exec()) setValue( fd.path()+"/"+fd.file ); } -void MenuSettingFile::setValue(string value) { +void MenuSettingFile::setValue(const string &value) { *_value = value; } -string MenuSettingFile::value() { +const string &MenuSettingFile::value() { return *_value; } diff --git a/src/menusettingfile.h b/src/menusettingfile.h index 811a101..fdea210 100644 --- a/src/menusettingfile.h +++ b/src/menusettingfile.h @@ -37,7 +37,7 @@ protected: void clear(); public: - MenuSettingFile(GMenu2X *gmenu2x, string name, string description, string *value, string filter=""); + MenuSettingFile(GMenu2X *gmenu2x, const string &name, const string &description, string *value, const string &filter=""); virtual ~MenuSettingFile() {}; virtual void draw(int y); @@ -47,8 +47,8 @@ public: virtual void drawSelected(int y); virtual bool edited(); - virtual void setValue(string value); - string value(); + virtual void setValue(const string &value); + const string &value(); }; #endif diff --git a/src/menusettingimage.cpp b/src/menusettingimage.cpp index 6726e76..b51686f 100644 --- a/src/menusettingimage.cpp +++ b/src/menusettingimage.cpp @@ -23,7 +23,7 @@ using namespace std; -MenuSettingImage::MenuSettingImage(GMenu2X *gmenu2x, string name, string description, string *value, string filter) +MenuSettingImage::MenuSettingImage(GMenu2X *gmenu2x, const string &name, const string &description, string *value, const string &filter) : MenuSettingFile(gmenu2x,name,description,value,filter) { this->gmenu2x = gmenu2x; this->filter = filter; @@ -39,7 +39,7 @@ void MenuSettingImage::manageInput() { } } -void MenuSettingImage::setValue(string value) { +void MenuSettingImage::setValue(const string &value) { string skinpath = gmenu2x->getExePath()+"skins/"+gmenu2x->confStr["skin"]; bool inSkinDir = value.substr(0,skinpath.length()) == skinpath; if (!inSkinDir && gmenu2x->confStr["skin"] != "Default") { @@ -50,7 +50,10 @@ void MenuSettingImage::setValue(string value) { 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()); + *_value = "skin:"+tempIcon.substr(pos+1,value.length()); + else + *_value = value; + } else { + *_value = value; } - *_value = value; } diff --git a/src/menusettingimage.h b/src/menusettingimage.h index 11ed068..d5ebeb3 100644 --- a/src/menusettingimage.h +++ b/src/menusettingimage.h @@ -27,11 +27,11 @@ using std::string; class MenuSettingImage : public MenuSettingFile { public: - MenuSettingImage(GMenu2X *gmenu2x, string name, string description, string *value, string filter=""); + MenuSettingImage(GMenu2X *gmenu2x, const string &name, const string &description, string *value, const string &filter=""); virtual ~MenuSettingImage() {}; virtual void manageInput(); - virtual void setValue(string value); + virtual void setValue(const string &value); }; #endif diff --git a/src/menusettingint.cpp b/src/menusettingint.cpp index b72112d..3d0378c 100644 --- a/src/menusettingint.cpp +++ b/src/menusettingint.cpp @@ -24,7 +24,7 @@ using namespace std; using namespace fastdelegate; -MenuSettingInt::MenuSettingInt(GMenu2X *gmenu2x, string name, string description, int *value, int min, int max) +MenuSettingInt::MenuSettingInt(GMenu2X *gmenu2x, const string &name, const string &description, int *value, int min, int max) : MenuSetting(gmenu2x,name,description) { this->gmenu2x = gmenu2x; _value = value; diff --git a/src/menusettingint.h b/src/menusettingint.h index 57158ff..986e189 100644 --- a/src/menusettingint.h +++ b/src/menusettingint.h @@ -39,7 +39,7 @@ private: void dec(); public: - MenuSettingInt(GMenu2X *gmenu2x, string name, string description, int *value, int min, int max); + MenuSettingInt(GMenu2X *gmenu2x, const string &name, const string &description, int *value, int min, int max); virtual ~MenuSettingInt() {}; virtual void draw(int y); diff --git a/src/menusettingmultistring.cpp b/src/menusettingmultistring.cpp index 220c886..e6837d2 100644 --- a/src/menusettingmultistring.cpp +++ b/src/menusettingmultistring.cpp @@ -23,7 +23,7 @@ using namespace std; using namespace fastdelegate; -MenuSettingMultiString::MenuSettingMultiString(GMenu2X *gmenu2x, string name, string description, string *value, vector *choices) +MenuSettingMultiString::MenuSettingMultiString(GMenu2X *gmenu2x, const string &name, const string &description, string *value, vector *choices) : MenuSetting(gmenu2x,name,description) { this->gmenu2x = gmenu2x; this->choices = choices; diff --git a/src/menusettingmultistring.h b/src/menusettingmultistring.h index e90df47..5c0e29a 100644 --- a/src/menusettingmultistring.h +++ b/src/menusettingmultistring.h @@ -39,7 +39,7 @@ private: void setSel(int); public: - MenuSettingMultiString(GMenu2X *gmenu2x, string name, string description, string *value, vector *choices); + MenuSettingMultiString(GMenu2X *gmenu2x, const string &name, const string &description, string *value, vector *choices); virtual ~MenuSettingMultiString() {}; virtual void draw(int y); diff --git a/src/menusettingrgba.cpp b/src/menusettingrgba.cpp index 98fc459..00185ae 100644 --- a/src/menusettingrgba.cpp +++ b/src/menusettingrgba.cpp @@ -23,7 +23,7 @@ using namespace std; using namespace fastdelegate; -MenuSettingRGBA::MenuSettingRGBA(GMenu2X *gmenu2x, string name, string description, RGBAColor *value) +MenuSettingRGBA::MenuSettingRGBA(GMenu2X *gmenu2x, const string &name, const string &description, RGBAColor *value) : MenuSetting(gmenu2x,name,description) { selPart = 0; this->gmenu2x = gmenu2x; diff --git a/src/menusettingrgba.h b/src/menusettingrgba.h index f5b0d0a..ad34c28 100644 --- a/src/menusettingrgba.h +++ b/src/menusettingrgba.h @@ -42,7 +42,7 @@ private: void rightComponent(); public: - MenuSettingRGBA(GMenu2X *gmenu2x, string name, string description, RGBAColor *value); + MenuSettingRGBA(GMenu2X *gmenu2x, const string &name, const string &description, RGBAColor *value); virtual ~MenuSettingRGBA() {}; virtual void draw(int y); diff --git a/src/menusettingstring.cpp b/src/menusettingstring.cpp index 3886370..1614386 100644 --- a/src/menusettingstring.cpp +++ b/src/menusettingstring.cpp @@ -24,7 +24,7 @@ using namespace std; using namespace fastdelegate; -MenuSettingString::MenuSettingString(GMenu2X *gmenu2x, string name, string description, string *value, string diagTitle, string diagIcon) +MenuSettingString::MenuSettingString(GMenu2X *gmenu2x, const string &name, const string &description, string *value, const string &diagTitle, const string &diagIcon) : MenuSetting(gmenu2x,name,description) { this->gmenu2x = gmenu2x; _value = value; @@ -53,11 +53,11 @@ void MenuSettingString::manageInput() { if ( gmenu2x->input[ACTION_B] ) edit(); } -void MenuSettingString::setValue(string value) { +void MenuSettingString::setValue(const string &value) { *_value = value; } -string MenuSettingString::value() { +const string &MenuSettingString::value() { return *_value; } diff --git a/src/menusettingstring.h b/src/menusettingstring.h index 4b45395..84af9a1 100644 --- a/src/menusettingstring.h +++ b/src/menusettingstring.h @@ -36,7 +36,7 @@ private: void clear(); public: - MenuSettingString(GMenu2X *gmenu2x, string name, string description, string *value, string diagTitle="", string diagIcon=""); + MenuSettingString(GMenu2X *gmenu2x, const string &name, const string &description, string *value, const string &diagTitle="", const string &diagIcon=""); virtual ~MenuSettingString() {}; virtual void draw(int y); @@ -46,8 +46,8 @@ public: virtual void drawSelected(int y); virtual bool edited(); - void setValue(string value); - string value(); + void setValue(const string &value); + const string &value(); }; #endif diff --git a/src/messagebox.cpp b/src/messagebox.cpp index 43c9f8a..75a2195 100644 --- a/src/messagebox.cpp +++ b/src/messagebox.cpp @@ -25,7 +25,7 @@ using namespace std; -MessageBox::MessageBox(GMenu2X *gmenu2x, string text, string icon) { +MessageBox::MessageBox(GMenu2X *gmenu2x, const string &text, const string &icon) { this->gmenu2x = gmenu2x; this->text = text; this->icon = icon; diff --git a/src/messagebox.h b/src/messagebox.h index 3bfe17d..23e8483 100644 --- a/src/messagebox.h +++ b/src/messagebox.h @@ -38,7 +38,7 @@ private: GMenu2X *gmenu2x; public: - MessageBox(GMenu2X *gmenu2x, string text, string icon=""); + MessageBox(GMenu2X *gmenu2x, const string &text, const string &icon=""); vector buttons; vector buttonLabels; vector buttonPositions; diff --git a/src/selector.cpp b/src/selector.cpp index 0bc8d17..6d55aa1 100644 --- a/src/selector.cpp +++ b/src/selector.cpp @@ -33,7 +33,7 @@ using namespace std; -Selector::Selector(GMenu2X *gmenu2x, LinkApp *link, string selectorDir) { +Selector::Selector(GMenu2X *gmenu2x, LinkApp *link, const string &selectorDir) { this->gmenu2x = gmenu2x; this->link = link; loadAliases(); @@ -235,7 +235,7 @@ void Selector::loadAliases() { } } -string Selector::getAlias(string key) { +string Selector::getAlias(const string &key) { hash_map::iterator i = aliases.find(key); if (i == aliases.end()) return ""; diff --git a/src/selector.h b/src/selector.h index c9a5fa4..d00e9c2 100644 --- a/src/selector.h +++ b/src/selector.h @@ -41,13 +41,13 @@ private: hash_map aliases; void loadAliases(); - string getAlias(string key); + string getAlias(const string &key); void prepare(FileLister *fl, vector *screens, vector *titles); void freeScreenshots(vector *screens); public: string file, dir; - Selector(GMenu2X *gmenu2x, LinkApp *link, string selectorDir=""); + Selector(GMenu2X *gmenu2x, LinkApp *link, const string &selectorDir=""); int exec(int startSelection=0); }; diff --git a/src/selectordetector.cpp b/src/selectordetector.cpp index 9ce639d..7930b81 100644 --- a/src/selectordetector.cpp +++ b/src/selectordetector.cpp @@ -11,7 +11,7 @@ SelectorDetector::SelectorDetector() { useSelectorBackground = false; } -SelectorDetector::SelectorDetector(string config) { +SelectorDetector::SelectorDetector(const string &config) { useSelectorBackground = false; readSelectorConfig(config); } @@ -20,7 +20,7 @@ SelectorDetector::~SelectorDetector() { //dtor } -bool SelectorDetector::readSelectorConfig(string config) { +bool SelectorDetector::readSelectorConfig(const string &config) { if (fileExists(config)) { ifstream inf(config.c_str(), ios_base::in); if (inf.is_open()) { diff --git a/src/selectordetector.h b/src/selectordetector.h index 7c279c5..41b66a8 100644 --- a/src/selectordetector.h +++ b/src/selectordetector.h @@ -37,10 +37,10 @@ class SelectorDetector { public: SelectorDetector(); - SelectorDetector(string config); + SelectorDetector(const string &config); ~SelectorDetector(); - bool readSelectorConfig(string config); + bool readSelectorConfig(const string &config); string getApplication(){return application;} string getFilePath(){return filePath;} @@ -51,8 +51,8 @@ class SelectorDetector string application; string filePath; string filters; - //bool isSelectorGPE(string gpe); - //string getSelectorConfig(string gpe); // Looks in the GPE for the location of the selectorconfig + //bool isSelectorGPE(const string &gpe); + //string getSelectorConfig(const string &gpe); // Looks in the GPE for the location of the selectorconfig }; #endif // SELECTORDETECTOR_H diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index 51d0df6..ec53b60 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -25,7 +25,7 @@ using namespace std; -SettingsDialog::SettingsDialog(GMenu2X *gmenu2x, string text, string icon) { +SettingsDialog::SettingsDialog(GMenu2X *gmenu2x, const string &text, const string &icon) { this->gmenu2x = gmenu2x; this->text = text; diff --git a/src/settingsdialog.h b/src/settingsdialog.h index 0123efa..2de39b6 100644 --- a/src/settingsdialog.h +++ b/src/settingsdialog.h @@ -40,7 +40,7 @@ private: GMenu2X *gmenu2x; public: - SettingsDialog(GMenu2X *gmenu2x, string text, string icon="skin:sections/settings.png"); + SettingsDialog(GMenu2X *gmenu2x, const string &text, const string &icon="skin:sections/settings.png"); ~SettingsDialog(); bool edited(); diff --git a/src/sfontplus.cpp b/src/sfontplus.cpp index 2747e07..e084a9d 100644 --- a/src/sfontplus.cpp +++ b/src/sfontplus.cpp @@ -46,7 +46,7 @@ SFontPlus::SFontPlus(SDL_Surface* font) { initFont(font); } -SFontPlus::SFontPlus(string font) { +SFontPlus::SFontPlus(const string &font) { surface = NULL; initFont(font); } @@ -60,7 +60,7 @@ bool SFontPlus::utf8Code(unsigned char c) { //return c>=194; } -void SFontPlus::initFont(string font, string characters) { +void SFontPlus::initFont(const string &font, const string &characters) { SDL_Surface *buf = IMG_Load(font.c_str()); if (buf!=NULL) { initFont( SDL_DisplayFormatAlpha(buf), characters ); @@ -68,7 +68,7 @@ void SFontPlus::initFont(string font, string characters) { } } -void SFontPlus::initFont(SDL_Surface *font, string characters) { +void SFontPlus::initFont(SDL_Surface *font, const string &characters) { freeFont(); this->characters = characters; if (font==NULL) return; @@ -126,7 +126,7 @@ void SFontPlus::freeFont() { } } -void SFontPlus::write(SDL_Surface *s, string text, int x, int y) { +void SFontPlus::write(SDL_Surface *s, const string &text, int x, int y) { if (text.empty()) return; string::size_type pos; @@ -161,7 +161,7 @@ void SFontPlus::write(SDL_Surface *s, string text, int x, int y) { } } -uint SFontPlus::getTextWidth(string text) { +uint SFontPlus::getTextWidth(const string &text) { string::size_type pos; int width = 0; diff --git a/src/sfontplus.h b/src/sfontplus.h index 9c9d7fb..cfa2e9e 100644 --- a/src/sfontplus.h +++ b/src/sfontplus.h @@ -24,18 +24,18 @@ private: public: SFontPlus(); SFontPlus(SDL_Surface *font); - SFontPlus(string font); + SFontPlus(const string &font); ~SFontPlus(); bool utf8Code(unsigned char c); - void initFont(SDL_Surface *font, string characters = SFONTPLUS_CHARSET); - void initFont(string font, string characters = SFONTPLUS_CHARSET); + void initFont(SDL_Surface *font, const string &characters = SFONTPLUS_CHARSET); + void initFont(const string &font, const string &characters = SFONTPLUS_CHARSET); void freeFont(); - void write(SDL_Surface *s, string text, int x, int y); + void write(SDL_Surface *s, const string &text, int x, int y); - uint getTextWidth(string text); + uint getTextWidth(const string &text); uint getHeight(); uint getLineHeight(); }; diff --git a/src/surface.cpp b/src/surface.cpp index edbc735..0e5d8f6 100644 --- a/src/surface.cpp +++ b/src/surface.cpp @@ -26,7 +26,7 @@ using namespace std; #include "surface.h" #include "utilities.h" -RGBAColor strtorgba(string strColor) { +RGBAColor strtorgba(const string &strColor) { RGBAColor c = {0,0,0,255}; c.r = constrain( strtol( strColor.substr(0,2).c_str(), NULL, 16 ), 0, 255 ); c.g = constrain( strtol( strColor.substr(2,2).c_str(), NULL, 16 ), 0, 255 ); @@ -40,7 +40,7 @@ Surface::Surface() { dblbuffer = NULL; } -Surface::Surface(string img, bool alpha, string skin) { +Surface::Surface(const string &img, bool alpha, const string &skin) { raw = NULL; dblbuffer = NULL; load(img, alpha, skin); @@ -48,7 +48,7 @@ Surface::Surface(string img, bool alpha, string skin) { halfH = raw->h/2; } -Surface::Surface(string img, string skin, bool alpha) { +Surface::Surface(const string &img, const string &skin, bool alpha) { raw = NULL; dblbuffer = NULL; load(img, alpha, skin); @@ -111,7 +111,7 @@ SDL_PixelFormat *Surface::format() { return raw->format; } -void Surface::load(string img, bool alpha, string skin) { +void Surface::load(const string &img, bool alpha, const string &skin) { free(); string skinpath; @@ -119,10 +119,11 @@ void Surface::load(string img, bool alpha, string skin) { skinpath = "skins/"+skin+"/"+img; if (!fileExists(skinpath)) skinpath = "skins/Default/"+img; - img = skinpath; + } else { + skinpath = img; } - SDL_Surface *buf = IMG_Load(img.c_str()); + SDL_Surface *buf = IMG_Load(skinpath.c_str()); if (buf!=NULL) { if (alpha) raw = SDL_DisplayFormatAlpha(buf); @@ -264,7 +265,7 @@ void Surface::blendAdd(Surface *target, int x, int y) { */ } -void Surface::write(ASFont *font, string text, int x, int y, const unsigned short halign, const unsigned short valign) { +void Surface::write(ASFont *font, const string &text, int x, int y, const unsigned short halign, const unsigned short valign) { font->write(this,text,x,y,halign,valign); } diff --git a/src/surface.h b/src/surface.h index 83dad91..e0f3478 100644 --- a/src/surface.h +++ b/src/surface.h @@ -32,7 +32,7 @@ struct RGBAColor { unsigned short r,g,b,a; }; -RGBAColor strtorgba(string strColor); +RGBAColor strtorgba(const string &strColor); /** Wrapper around SDL_Surface @@ -46,8 +46,8 @@ private: public: Surface(); - Surface(string img, string skin="", bool alpha=true); - Surface(string img, bool alpha, string skin=""); + Surface(const string &img, const string &skin="", bool alpha=true); + Surface(const string &img, bool alpha, const string &skin=""); Surface(SDL_Surface *s, SDL_PixelFormat *fmt = NULL, Uint32 flags = 0); Surface(Surface *s); Surface(int w, int h, Uint32 flags = SDL_HWSURFACE|SDL_SRCALPHA); @@ -58,7 +58,7 @@ public: SDL_Surface *raw; void free(); - void load(string img, bool alpha=true, string skin=""); + void load(const string &img, bool alpha=true, const string &skin=""); void lock(); void unlock(); void flip(); @@ -83,7 +83,7 @@ public: bool blitRight(Surface *destination, int x, int y, int w=0, int h=0, int a=-1); bool blitRight(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1); - void write(ASFont *font, string text, int x, int y, const unsigned short halign=0, const unsigned short valign=0); + void write(ASFont *font, const string &text, int x, int y, const unsigned short halign=0, const unsigned short valign=0); int box(Sint16, Sint16, Sint16, Sint16, Uint8, Uint8, Uint8, Uint8); int box(Sint16, Sint16, Sint16, Sint16, Uint8, Uint8, Uint8); diff --git a/src/surfacecollection.cpp b/src/surfacecollection.cpp index 4e2a465..06c7ac5 100644 --- a/src/surfacecollection.cpp +++ b/src/surfacecollection.cpp @@ -22,7 +22,7 @@ using namespace std; -SurfaceCollection::SurfaceCollection(bool defaultAlpha, string skin) { +SurfaceCollection::SurfaceCollection(bool defaultAlpha, const string &skin) { surfaces.set_empty_key(" "); surfaces.set_deleted_key(""); this->defaultAlpha = defaultAlpha; @@ -31,11 +31,11 @@ SurfaceCollection::SurfaceCollection(bool defaultAlpha, string skin) { SurfaceCollection::~SurfaceCollection() {} -void SurfaceCollection::setSkin(string skin) { +void SurfaceCollection::setSkin(const string &skin) { this->skin = skin; } -string SurfaceCollection::getSkinFilePath(string file) { +string SurfaceCollection::getSkinFilePath(const string &file) { string prefix = "/usr/share/gmenu2x/"; if (fileExists("skins/"+skin+"/"+file)) return "skins/"+skin+"/"+file; @@ -54,17 +54,17 @@ void SurfaceCollection::debug() { } } -bool SurfaceCollection::exists(string path) { +bool SurfaceCollection::exists(const string &path) { return surfaces.find(path) != surfaces.end(); } -Surface *SurfaceCollection::add(Surface *s, string path) { +Surface *SurfaceCollection::add(Surface *s, const string &path) { if (exists(path)) del(path); surfaces[path] = s; return s; } -Surface *SurfaceCollection::add(string path, bool alpha) { +Surface *SurfaceCollection::add(const string &path, bool alpha) { #ifdef DEBUG cout << "Adding surface: " << path << endl; #endif @@ -82,7 +82,7 @@ Surface *SurfaceCollection::add(string path, bool alpha) { return s; } -Surface *SurfaceCollection::addSkinRes(string path, bool alpha) { +Surface *SurfaceCollection::addSkinRes(const string &path, bool alpha) { #ifdef DEBUG cout << "Adding skin surface: " << path << endl; #endif @@ -99,7 +99,7 @@ Surface *SurfaceCollection::addSkinRes(string path, bool alpha) { return s; } -void SurfaceCollection::del(string path) { +void SurfaceCollection::del(const string &path) { SurfaceHash::iterator i = surfaces.find(path); if (i != surfaces.end()) { free(i->second); @@ -115,13 +115,13 @@ void SurfaceCollection::clear() { } } -void SurfaceCollection::move(string from, string to) { +void SurfaceCollection::move(const string &from, const string &to) { del(to); surfaces[to] = surfaces[from]; surfaces.erase(from); } -Surface *SurfaceCollection::operator[](string key) { +Surface *SurfaceCollection::operator[](const string &key) { SurfaceHash::iterator i = surfaces.find(key); if (i == surfaces.end()) return add(key, defaultAlpha); @@ -129,7 +129,7 @@ Surface *SurfaceCollection::operator[](string key) { return i->second; } -Surface *SurfaceCollection::skinRes(string key) { +Surface *SurfaceCollection::skinRes(const string &key) { if (key.empty()) return NULL; SurfaceHash::iterator i = surfaces.find(key); diff --git a/src/surfacecollection.h b/src/surfacecollection.h index e5106ea..4b55df6 100644 --- a/src/surfacecollection.h +++ b/src/surfacecollection.h @@ -39,25 +39,25 @@ private: string skin; public: - SurfaceCollection(bool defaultAlpha=true, string skin="default"); + SurfaceCollection(bool defaultAlpha=true, const string &skin="default"); ~SurfaceCollection(); - void setSkin(string skin); - string getSkinFilePath(string file); + void setSkin(const string &skin); + string getSkinFilePath(const string &file); bool defaultAlpha; void debug(); - Surface *add(Surface *s, string path); - Surface *add(string path, bool alpha=true); - Surface *addSkinRes(string path, bool alpha=true); - void del(string path); + Surface *add(Surface *s, const string &path); + Surface *add(const string &path, bool alpha=true); + Surface *addSkinRes(const string &path, bool alpha=true); + void del(const string &path); void clear(); - void move(string from, string to); - bool exists(string path); + void move(const string &from, const string &to); + bool exists(const string &path); - Surface *operator[](string); - Surface *skinRes(string); + Surface *operator[](const string &); + Surface *skinRes(const string &); }; #endif diff --git a/src/textdialog.cpp b/src/textdialog.cpp index 038078d..2090ef7 100644 --- a/src/textdialog.cpp +++ b/src/textdialog.cpp @@ -22,7 +22,7 @@ using namespace std; -TextDialog::TextDialog(GMenu2X *gmenu2x, string title, string description, string icon, vector *text) { +TextDialog::TextDialog(GMenu2X *gmenu2x, const string &title, const string &description, const string &icon, vector *text) { this->gmenu2x = gmenu2x; this->text = text; this->title = title; diff --git a/src/textdialog.h b/src/textdialog.h index 8d062a4..5187013 100644 --- a/src/textdialog.h +++ b/src/textdialog.h @@ -37,7 +37,7 @@ protected: void drawText(vector *text, uint firstRow, uint rowsPerPage); public: - TextDialog(GMenu2X *gmenu2x, string title, string description, string icon, vector *text); + TextDialog(GMenu2X *gmenu2x, const string &title, const string &description, const string &icon, vector *text); void exec(); }; diff --git a/src/textmanualdialog.cpp b/src/textmanualdialog.cpp index f7361ae..02efb69 100644 --- a/src/textmanualdialog.cpp +++ b/src/textmanualdialog.cpp @@ -23,7 +23,7 @@ using namespace std; -TextManualDialog::TextManualDialog(GMenu2X *gmenu2x, string title, string icon, vector *text) +TextManualDialog::TextManualDialog(GMenu2X *gmenu2x, const string &title, const string &icon, vector *text) : TextDialog(gmenu2x,title,"",icon,text) { this->gmenu2x = gmenu2x; diff --git a/src/textmanualdialog.h b/src/textmanualdialog.h index bb7c711..98ea8f7 100644 --- a/src/textmanualdialog.h +++ b/src/textmanualdialog.h @@ -38,7 +38,7 @@ private: vector pages; public: - TextManualDialog(GMenu2X *gmenu2x, string title, string icon, vector *text); + TextManualDialog(GMenu2X *gmenu2x, const string &title, const string &icon, vector *text); void exec(); }; diff --git a/src/translator.cpp b/src/translator.cpp index d65e4f4..fb718b8 100644 --- a/src/translator.cpp +++ b/src/translator.cpp @@ -26,7 +26,7 @@ using namespace std; -Translator::Translator(string lang) { +Translator::Translator(const string &lang) { _lang = ""; if (!lang.empty()) setLang(lang); @@ -34,11 +34,11 @@ Translator::Translator(string lang) { Translator::~Translator() {} -bool Translator::exists(string term) { +bool Translator::exists(const string &term) { return translations.find(term) != translations.end(); } -void Translator::setLang(string lang) { +void Translator::setLang(const string &lang) { translations.clear(); string line; @@ -57,7 +57,7 @@ void Translator::setLang(string lang) { } } -string Translator::translate(string term,const char *replacestr,...) { +string Translator::translate(const string &term,const char *replacestr,...) { string result = term; if (!_lang.empty()) { @@ -87,7 +87,7 @@ string Translator::translate(string term,const char *replacestr,...) { return result; } -string Translator::operator[](string term) { +string Translator::operator[](const string &term) { return translate(term); } diff --git a/src/translator.h b/src/translator.h index 7d0a8c0..53a4b5d 100644 --- a/src/translator.h +++ b/src/translator.h @@ -33,14 +33,14 @@ private: hash_map translations; public: - Translator(string lang=""); + Translator(const string &lang=""); ~Translator(); string lang(); - void setLang(string lang); - bool exists(string term); - string translate(string term,const char *replacestr=NULL,...); - string operator[](string term); + void setLang(const string &lang); + bool exists(const string &term); + string translate(const string &term,const char *replacestr=NULL,...); + string operator[](const string &term); }; #endif diff --git a/src/utilities.cpp b/src/utilities.cpp index 77630d7..7d9bd88 100644 --- a/src/utilities.cpp +++ b/src/utilities.cpp @@ -28,7 +28,7 @@ using namespace std; -bool case_less::operator()(string const &left, string const &right) const { +bool case_less::operator()(const string &left, const string &right) const { return strcasecmp(left.c_str(), right.c_str()) < 0; } @@ -43,18 +43,18 @@ string trim(const string& s) { return string(s, b, e - b + 1); } -void string_copy(string s, char **cs) { +void string_copy(const string &s, char **cs) { *cs = (char*)malloc(s.length()); strcpy(*cs, s.c_str()); } -char * string_copy(string s) { +char * string_copy(const string &s) { char *cs = NULL; string_copy(s, &cs); return cs; } -bool fileExists(string file) { +bool fileExists(const string &file) { fstream fin; fin.open(file.c_str() ,ios::in); bool exists = fin.is_open(); @@ -115,10 +115,10 @@ int evalIntConf (int *val, int def, int imin, int imax) { return *val; } -string evalStrConf (string val, string def) { +const string &evalStrConf (const string &val, const string &def) { return val.empty() ? def : val; } -string evalStrConf (string *val, string def) { +const string &evalStrConf (string *val, const string &def) { *val = evalStrConf(*val, def); return *val; } @@ -158,7 +158,7 @@ bool split (vector &vec, const string &str, const string &delim, bool de return true; } -string strreplace (string orig, string search, string replace) { +string strreplace (string orig, const string &search, const string &replace) { string::size_type pos = orig.find( search, 0 ); while (pos != string::npos) { orig.replace(pos,search.length(),replace); diff --git a/src/utilities.h b/src/utilities.h index 486dfcb..a7abd4d 100644 --- a/src/utilities.h +++ b/src/utilities.h @@ -49,17 +49,17 @@ struct eqstr { class case_less { public: - bool operator()(string const &left, string const &right) const; + bool operator()(const string &left, const string &right) const; }; string trim(const string& s); -string strreplace (string orig, string search, string replace); +string strreplace (string orig, const string &search, const string &replace); string cmdclean (string cmdline); -char *string_copy(string); -void string_copy(string, char **); +char *string_copy(const string &); +void string_copy(const string &, char **); -bool fileExists(string file); +bool fileExists(const string &file); bool rmtree(string path); int max (int a, int b); @@ -68,8 +68,8 @@ int constrain (int x, int imin, int imax); int evalIntConf (int val, int def, int imin, int imax); int evalIntConf (int *val, int def, int imin, int imax); -string evalStrConf (string val, string def); -string evalStrConf (string *val, string def); +const string &evalStrConf (const string &val, const string &def); +const string &evalStrConf (string *val, const string &def); bool split (vector &vec, const string &str, const string &delim, bool destructive=true);