| src/filelister.cpp |
| 30 | 30 | |
| 31 | 31 | using namespace std; |
| 32 | 32 | |
| 33 | | FileLister::FileLister(string startPath, bool showDirectories, bool showFiles) { |
| 33 | FileLister::FileLister(const string &startPath, bool showDirectories, bool showFiles) { |
| 34 | 34 | this->showDirectories = showDirectories; |
| 35 | 35 | this->showFiles = showFiles; |
| 36 | 36 | setPath(startPath,false); |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | | string FileLister::getPath() { |
| 39 | const string &FileLister::getPath() { |
| 40 | 40 | return path; |
| 41 | 41 | } |
| 42 | | void FileLister::setPath(string path, bool doBrowse) { |
| 43 | | if (path[path.length()-1]!='/') path += "/"; |
| 42 | void FileLister::setPath(const string &path, bool doBrowse) { |
| 44 | 43 | this->path = path; |
| 44 | if (this->path[path.length()-1]!='/') |
| 45 | this->path += "/"; |
| 45 | 46 | if (doBrowse) |
| 46 | 47 | browse(); |
| 47 | 48 | } |
| 48 | 49 | |
| 49 | | string FileLister::getFilter() { |
| 50 | const string &FileLister::getFilter() { |
| 50 | 51 | return filter; |
| 51 | 52 | } |
| 52 | | void FileLister::setFilter(string filter) { |
| 53 | void FileLister::setFilter(const string &filter) { |
| 53 | 54 | this->filter = filter; |
| 54 | 55 | } |
| 55 | 56 | |
| src/gmenu2x.cpp |
| 695 | 695 | } |
| 696 | 696 | } |
| 697 | 697 | |
| 698 | | void GMenu2X::writeTmp(int selelem, string selectordir) { |
| 698 | void GMenu2X::writeTmp(int selelem, const string &selectordir) { |
| 699 | 699 | string conffile = "/tmp/gmenu2x.tmp"; |
| 700 | 700 | ofstream inf(conffile.c_str()); |
| 701 | 701 | if (inf.is_open()) { |
| ... | ... | |
| 1122 | 1122 | #endif |
| 1123 | 1123 | } |
| 1124 | 1124 | |
| 1125 | | void GMenu2X::setSkin(string skin, bool setWallpaper) { |
| 1125 | void GMenu2X::setSkin(const string &skin, bool setWallpaper) { |
| 1126 | 1126 | confStr["skin"] = skin; |
| 1127 | 1127 | |
| 1128 | 1128 | //Clear previous skin settings |
| ... | ... | |
| 1847 | 1847 | return currentscalefactor; |
| 1848 | 1848 | } |
| 1849 | 1849 | |
| 1850 | | string GMenu2X::getExePath() { |
| 1850 | const string &GMenu2X::getExePath() { |
| 1851 | 1851 | if (path.empty()) { |
| 1852 | 1852 | char buf[255]; |
| 1853 | 1853 | int l = readlink("/proc/self/exe",buf,255); |
| ... | ... | |
| 1882 | 1882 | return x+btn->getRect().w+6; |
| 1883 | 1883 | } |
| 1884 | 1884 | |
| 1885 | | int GMenu2X::drawButton(Surface *s, string btn, string text, int x, int y) { |
| 1885 | int GMenu2X::drawButton(Surface *s, const string &btn, const string &text, int x, int y) { |
| 1886 | 1886 | if (y<0) y = resY+y; |
| 1887 | 1887 | SDL_Rect re = {x, y-7, 0, 16}; |
| 1888 | 1888 | if (sc.skinRes("imgs/buttons/"+btn+".png") != NULL) { |
| ... | ... | |
| 1894 | 1894 | return x+re.w+6; |
| 1895 | 1895 | } |
| 1896 | 1896 | |
| 1897 | | int GMenu2X::drawButtonRight(Surface *s, string btn, string text, int x, int y) { |
| 1897 | int GMenu2X::drawButtonRight(Surface *s, const string &btn, const string &text, int x, int y) { |
| 1898 | 1898 | if (y<0) y = resY+y; |
| 1899 | 1899 | if (sc.skinRes("imgs/buttons/"+btn+".png") != NULL) { |
| 1900 | 1900 | x -= 16; |
| ... | ... | |
| 1923 | 1923 | s->box(resX-6, by, 3, bs, skinConfColors["selectionBg"]); |
| 1924 | 1924 | } |
| 1925 | 1925 | |
| 1926 | | void GMenu2X::drawTitleIcon(string icon, bool skinRes, Surface *s) { |
| 1926 | void GMenu2X::drawTitleIcon(const string &icon, bool skinRes, Surface *s) { |
| 1927 | 1927 | if (s==NULL) s = this->s; |
| 1928 | 1928 | |
| 1929 | 1929 | Surface *i = NULL; |
| ... | ... | |
| 1940 | 1940 | i->blit(s,4,(skinConfInt["topBarHeight"]-32)/2); |
| 1941 | 1941 | } |
| 1942 | 1942 | |
| 1943 | | void GMenu2X::writeTitle(string title, Surface *s) { |
| 1943 | void GMenu2X::writeTitle(const string &title, Surface *s) { |
| 1944 | 1944 | if (s==NULL) s = this->s; |
| 1945 | 1945 | s->write(font,title,40, skinConfInt["topBarHeight"]/4, SFontHAlignLeft, SFontVAlignMiddle); |
| 1946 | 1946 | } |
| 1947 | 1947 | |
| 1948 | | void GMenu2X::writeSubTitle(string subtitle, Surface *s) { |
| 1948 | void GMenu2X::writeSubTitle(const string &subtitle, Surface *s) { |
| 1949 | 1949 | if (s==NULL) s = this->s; |
| 1950 | 1950 | s->write(font,subtitle,40, skinConfInt["topBarHeight"]/4*3, SFontHAlignLeft, SFontVAlignMiddle); |
| 1951 | 1951 | } |
| src/gmenu2x.h |
| 85 | 85 | */ |
| 86 | 86 | unsigned short getBatteryLevel(); |
| 87 | 87 | FILE* batteryHandle, *backlightHandle, *usbHandle, *acHandle; |
| 88 | | void browsePath(string path, vector<string>* directories, vector<string>* files); |
| 88 | void browsePath(const string &path, vector<string>* directories, vector<string>* files); |
| 89 | 89 | /*! |
| 90 | 90 | Starts the scanning of the nand and sd filesystems, searching for dge and gpu files and creating the links in 2 dedicated sections. |
| 91 | 91 | */ |
| ... | ... | |
| 146 | 146 | @see path |
| 147 | 147 | @return String containing the parent directory |
| 148 | 148 | */ |
| 149 | | string getExePath(); |
| 149 | const string &getExePath(); |
| 150 | 150 | |
| 151 | 151 | InputManager input; |
| 152 | 152 | Touchscreen ts; |
| ... | ... | |
| 158 | 158 | |
| 159 | 159 | //Configuration settings |
| 160 | 160 | bool useSelectionPng; |
| 161 | | void setSkin(string skin, bool setWallpaper = true); |
| 161 | void setSkin(const string &skin, bool setWallpaper = true); |
| 162 | 162 | //firmware type and version |
| 163 | 163 | string fwType, fwVersion; |
| 164 | 164 | //gp2x type |
| ... | ... | |
| 212 | 212 | void writeConfig(); |
| 213 | 213 | void writeConfigOpen2x(); |
| 214 | 214 | void writeSkinConfig(); |
| 215 | | void writeTmp(int selelem=-1, string selectordir=""); |
| 215 | void writeTmp(int selelem=-1, const string &selectordir=""); |
| 216 | 216 | |
| 217 | 217 | void ledOn(); |
| 218 | 218 | void ledOff(); |
| ... | ... | |
| 226 | 226 | |
| 227 | 227 | void initBG(); |
| 228 | 228 | int drawButton(IconButton *btn, int x=5, int y=-10); |
| 229 | | int drawButton(Surface *s, string btn, string text, int x=5, int y=-10); |
| 230 | | int drawButtonRight(Surface *s, string btn, string text, int x=5, int y=-10); |
| 229 | int drawButton(Surface *s, const string &btn, const string &text, int x=5, int y=-10); |
| 230 | int drawButtonRight(Surface *s, const string &btn, const string &text, int x=5, int y=-10); |
| 231 | 231 | void drawScrollBar(uint pagesize, uint totalsize, uint pagepos, uint top, uint height); |
| 232 | 232 | |
| 233 | | void drawTitleIcon(string icon, bool skinRes=true, Surface *s=NULL); |
| 234 | | void writeTitle(string title, Surface *s=NULL); |
| 235 | | void writeSubTitle(string subtitle, Surface *s=NULL); |
| 233 | void drawTitleIcon(const string &icon, bool skinRes=true, Surface *s=NULL); |
| 234 | void writeTitle(const string &title, Surface *s=NULL); |
| 235 | void writeSubTitle(const string &subtitle, Surface *s=NULL); |
| 236 | 236 | void drawTopBar(Surface *s=NULL); |
| 237 | 237 | void drawBottomBar(Surface *s=NULL); |
| 238 | 238 | |
| src/imagedialog.cpp |
| 31 | 31 | |
| 32 | 32 | using namespace std; |
| 33 | 33 | |
| 34 | | ImageDialog::ImageDialog(GMenu2X *gmenu2x, string text, string filter, string file) : FileDialog(gmenu2x, text, filter, file) { |
| 34 | ImageDialog::ImageDialog(GMenu2X *gmenu2x, const string &text, const string &filter, const string &file) : FileDialog(gmenu2x, text, filter, file) { |
| 35 | 35 | this->gmenu2x = gmenu2x; |
| 36 | 36 | this->text = text; |
| 37 | 37 | this->filter = filter; |
| 38 | | this->file = ""; |
| 39 | 38 | setPath("/card"); |
| 40 | 39 | title = "Image Browser"; |
| 41 | 40 | if (!file.empty()) { |
| 42 | | file = strreplace(file,"skin:",gmenu2x->getExePath()+"skins/"+gmenu2x->confStr["skin"]+"/"); |
| 43 | | string::size_type pos = file.rfind("/"); |
| 41 | this->file = strreplace(file,"skin:",gmenu2x->getExePath()+"skins/"+gmenu2x->confStr["skin"]+"/"); |
| 42 | string::size_type pos = this->file.rfind("/"); |
| 44 | 43 | if (pos != string::npos) { |
| 45 | | setPath( file.substr(0, pos) ); |
| 44 | setPath( this->file.substr(0, pos) ); |
| 46 | 45 | cout << "ib: " << path() << endl; |
| 47 | | this->file = file.substr(pos+1,file.length()); |
| 46 | this->file = this->file.substr(pos+1,file.length()); |
| 48 | 47 | } |
| 49 | 48 | } |
| 50 | 49 | selRow = 0; |
| src/link.cpp |
| 57 | 57 | iconSurface = gmenu2x->sc[getIconPath()]; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | | string Link::getTitle() { |
| 60 | const string &Link::getTitle() { |
| 61 | 61 | return title; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | | void Link::setTitle(string title) { |
| 64 | void Link::setTitle(const string &title) { |
| 65 | 65 | this->title = title; |
| 66 | 66 | edited = true; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | | string Link::getDescription() { |
| 69 | const string &Link::getDescription() { |
| 70 | 70 | return description; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | | void Link::setDescription(string description) { |
| 73 | void Link::setDescription(const string &description) { |
| 74 | 74 | this->description = description; |
| 75 | 75 | edited = true; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | | string Link::getIcon() { |
| 78 | const string &Link::getIcon() { |
| 79 | 79 | return icon; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | | void Link::setIcon(string icon) { |
| 82 | void Link::setIcon(const string &icon) { |
| 83 | 83 | string skinpath = gmenu2x->getExePath()+"skins/"+gmenu2x->confStr["skin"]; |
| 84 | |
| 84 | 85 | if (icon.substr(0,skinpath.length()) == skinpath) { |
| 85 | 86 | string tempIcon = icon.substr(skinpath.length(), icon.length()); |
| 86 | 87 | string::size_type pos = tempIcon.find("/"); |
| 87 | 88 | if (pos != string::npos) |
| 88 | | icon = "skin:"+tempIcon.substr(pos+1,icon.length()); |
| 89 | this->icon = "skin:"+tempIcon.substr(pos+1,icon.length()); |
| 90 | else |
| 91 | this->icon = icon; |
| 92 | } else { |
| 93 | this->icon = icon; |
| 89 | 94 | } |
| 90 | 95 | |
| 91 | | iconPath = strreplace(icon,"skin:",skinpath+"/"); |
| 96 | iconPath = strreplace(this->icon,"skin:",skinpath+"/"); |
| 92 | 97 | if (iconPath.empty() || !fileExists(iconPath)) { |
| 93 | | iconPath = strreplace(icon,"skin:",gmenu2x->getExePath()+"skins/Default/"); |
| 98 | iconPath = strreplace(this->icon,"skin:",gmenu2x->getExePath()+"skins/Default/"); |
| 94 | 99 | if (!fileExists(iconPath)) searchIcon(); |
| 95 | 100 | } |
| 96 | 101 | |
| 97 | | this->icon = icon; |
| 98 | 102 | edited = true; |
| 99 | 103 | updateSurfaces(); |
| 100 | 104 | } |
| 101 | 105 | |
| 102 | | string Link::searchIcon() { |
| 106 | const string &Link::searchIcon() { |
| 103 | 107 | iconPath = gmenu2x->sc.getSkinFilePath("icons/generic.png"); |
| 104 | 108 | return iconPath; |
| 105 | 109 | } |
| 106 | 110 | |
| 107 | | string Link::getIconPath() { |
| 111 | const string &Link::getIconPath() { |
| 108 | 112 | if (iconPath.empty()) searchIcon(); |
| 109 | 113 | return iconPath; |
| 110 | 114 | } |
| 111 | 115 | |
| 112 | | void Link::setIconPath(string icon) { |
| 116 | void Link::setIconPath(const string &icon) { |
| 113 | 117 | if (fileExists(icon)) |
| 114 | 118 | iconPath = icon; |
| 115 | 119 | else |
| src/linkapp.cpp |
| 109 | 109 | edited = false; |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | | string LinkApp::searchIcon() { |
| 112 | const string &LinkApp::searchIcon() { |
| 113 | 113 | string execicon = exec; |
| 114 | 114 | string::size_type pos = exec.rfind("."); |
| 115 | 115 | if (pos != string::npos) execicon = exec.substr(0,pos); |
| ... | ... | |
| 133 | 133 | return iclock; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | | string LinkApp::clockStr(int maxClock) { |
| 136 | const string &LinkApp::clockStr(int maxClock) { |
| 137 | 137 | if (iclock>maxClock) setClock(maxClock); |
| 138 | 138 | return sclock; |
| 139 | 139 | } |
| ... | ... | |
| 152 | 152 | return ivolume; |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | | string LinkApp::volumeStr() { |
| 155 | const string &LinkApp::volumeStr() { |
| 156 | 156 | return svolume; |
| 157 | 157 | } |
| 158 | 158 | |
| ... | ... | |
| 174 | 174 | return ibacklight; |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | | string LinkApp::backlightStr() |
| 177 | const string &LinkApp::backlightStr() |
| 178 | 178 | { |
| 179 | 179 | return sbacklight; |
| 180 | 180 | } |
| ... | ... | |
| 194 | 194 | return igamma; |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | | string LinkApp::gammaStr() { |
| 197 | const string &LinkApp::gammaStr() { |
| 198 | 198 | return sgamma; |
| 199 | 199 | } |
| 200 | 200 | |
| ... | ... | |
| 372 | 372 | } |
| 373 | 373 | } |
| 374 | 374 | |
| 375 | | void LinkApp::selector(int startSelection, string selectorDir) { |
| 375 | void LinkApp::selector(int startSelection, const string &selectorDir) { |
| 376 | 376 | //Run selector interface |
| 377 | 377 | Selector sel(gmenu2x, this, selectorDir); |
| 378 | 378 | int selection = sel.exec(startSelection); |
| ... | ... | |
| 382 | 382 | } |
| 383 | 383 | } |
| 384 | 384 | |
| 385 | | void LinkApp::launch(string selectedFile, string selectedDir) { |
| 385 | void LinkApp::launch(const string &selectedFile, const string &selectedDir) { |
| 386 | 386 | drawRun(); |
| 387 | 387 | save(); |
| 388 | 388 | #ifndef TARGET_GP2X |
| ... | ... | |
| 405 | 405 | //selectedFile |
| 406 | 406 | if (selectedFile!="") { |
| 407 | 407 | string selectedFileExtension; |
| 408 | string selectedFileName; |
| 409 | string dir; |
| 408 | 410 | string::size_type i = selectedFile.rfind("."); |
| 409 | 411 | if (i != string::npos) { |
| 410 | 412 | selectedFileExtension = selectedFile.substr(i,selectedFile.length()); |
| 411 | | selectedFile = selectedFile.substr(0,i); |
| 413 | selectedFileName = selectedFile.substr(0,i); |
| 412 | 414 | } |
| 413 | 415 | |
| 414 | 416 | if (selectedDir=="") |
| 415 | | selectedDir = getSelectorDir(); |
| 417 | dir = getSelectorDir(); |
| 418 | else |
| 419 | dir = selectedDir; |
| 416 | 420 | if (params=="") { |
| 417 | | params = cmdclean(selectedDir+selectedFile+selectedFileExtension); |
| 421 | params = cmdclean(dir+selectedFile); |
| 418 | 422 | } else { |
| 419 | 423 | string origParams = params; |
| 420 | | params = strreplace(params,"[selFullPath]",cmdclean(selectedDir+selectedFile+selectedFileExtension)); |
| 421 | | params = strreplace(params,"[selPath]",cmdclean(selectedDir)); |
| 422 | | params = strreplace(params,"[selFile]",cmdclean(selectedFile)); |
| 424 | params = strreplace(params,"[selFullPath]",cmdclean(dir+selectedFile)); |
| 425 | params = strreplace(params,"[selPath]",cmdclean(dir)); |
| 426 | params = strreplace(params,"[selFile]",cmdclean(selectedFileName)); |
| 423 | 427 | params = strreplace(params,"[selExt]",cmdclean(selectedFileExtension)); |
| 424 | | if (params == origParams) params += " " + cmdclean(selectedDir+selectedFile+selectedFileExtension); |
| 428 | if (params == origParams) params += " " + cmdclean(dir+selectedFile); |
| 425 | 429 | } |
| 426 | 430 | } |
| 427 | 431 | |
| ... | ... | |
| 480 | 484 | chdir(gmenu2x->getExePath().c_str()); |
| 481 | 485 | } |
| 482 | 486 | |
| 483 | | string LinkApp::getExec() { |
| 487 | const string &LinkApp::getExec() { |
| 484 | 488 | return exec; |
| 485 | 489 | } |
| 486 | 490 | |
| 487 | | void LinkApp::setExec(string exec) { |
| 491 | void LinkApp::setExec(const string &exec) { |
| 488 | 492 | this->exec = exec; |
| 489 | 493 | edited = true; |
| 490 | 494 | } |
| 491 | 495 | |
| 492 | | string LinkApp::getParams() { |
| 496 | const string &LinkApp::getParams() { |
| 493 | 497 | return params; |
| 494 | 498 | } |
| 495 | 499 | |
| 496 | | void LinkApp::setParams(string params) { |
| 500 | void LinkApp::setParams(const string ¶ms) { |
| 497 | 501 | this->params = params; |
| 498 | 502 | edited = true; |
| 499 | 503 | } |
| 500 | 504 | |
| 501 | | string LinkApp::getWorkdir() { |
| 505 | const string &LinkApp::getWorkdir() { |
| 502 | 506 | return workdir; |
| 503 | 507 | } |
| 504 | 508 | |
| 505 | | void LinkApp::setWorkdir(string workdir) { |
| 509 | void LinkApp::setWorkdir(const string &workdir) { |
| 506 | 510 | this->workdir = workdir; |
| 507 | 511 | edited = true; |
| 508 | 512 | } |
| 509 | 513 | |
| 510 | | string LinkApp::getManual() { |
| 514 | const string &LinkApp::getManual() { |
| 511 | 515 | return manual; |
| 512 | 516 | } |
| 513 | 517 | |
| 514 | | void LinkApp::setManual(string manual) { |
| 518 | void LinkApp::setManual(const string &manual) { |
| 515 | 519 | this->manual = manual; |
| 516 | 520 | edited = true; |
| 517 | 521 | } |
| 518 | 522 | |
| 519 | | string LinkApp::getSelectorDir() { |
| 523 | const string &LinkApp::getSelectorDir() { |
| 520 | 524 | return selectordir; |
| 521 | 525 | } |
| 522 | 526 | |
| 523 | | void LinkApp::setSelectorDir(string selectordir) { |
| 524 | | if (selectordir!="" && selectordir[selectordir.length()-1]!='/') selectordir += "/"; |
| 527 | void LinkApp::setSelectorDir(const string &selectordir) { |
| 525 | 528 | this->selectordir = selectordir; |
| 529 | if (this->selectordir!="" && this->selectordir[this->selectordir.length()-1]!='/') this->selectordir += "/"; |
| 526 | 530 | edited = true; |
| 527 | 531 | } |
| 528 | 532 | |
| ... | ... | |
| 544 | 548 | edited = true; |
| 545 | 549 | } |
| 546 | 550 | |
| 547 | | string LinkApp::getSelectorFilter() { |
| 551 | const string &LinkApp::getSelectorFilter() { |
| 548 | 552 | return selectorfilter; |
| 549 | 553 | } |
| 550 | 554 | |
| 551 | | void LinkApp::setSelectorFilter(string selectorfilter) { |
| 555 | void LinkApp::setSelectorFilter(const string &selectorfilter) { |
| 552 | 556 | this->selectorfilter = selectorfilter; |
| 553 | 557 | edited = true; |
| 554 | 558 | } |
| 555 | 559 | |
| 556 | | string LinkApp::getSelectorScreens() { |
| 560 | const string &LinkApp::getSelectorScreens() { |
| 557 | 561 | return selectorscreens; |
| 558 | 562 | } |
| 559 | 563 | |
| 560 | | void LinkApp::setSelectorScreens(string selectorscreens) { |
| 564 | void LinkApp::setSelectorScreens(const string &selectorscreens) { |
| 561 | 565 | this->selectorscreens = selectorscreens; |
| 562 | 566 | edited = true; |
| 563 | 567 | } |
| 564 | 568 | |
| 565 | | string LinkApp::getAliasFile() { |
| 569 | const string &LinkApp::getAliasFile() { |
| 566 | 570 | return aliasfile; |
| 567 | 571 | } |
| 568 | 572 | |
| 569 | | void LinkApp::setAliasFile(string aliasfile) { |
| 573 | void LinkApp::setAliasFile(const string &aliasfile) { |
| 570 | 574 | if (fileExists(aliasfile)) { |
| 571 | 575 | this->aliasfile = aliasfile; |
| 572 | 576 | edited = true; |
| src/linkapp.h |
| 52 | 52 | |
| 53 | 53 | public: |
| 54 | 54 | LinkApp(GMenu2X *gmenu2x, const char* linkfile); |
| 55 | | virtual string searchIcon(); |
| 56 | | |
| 57 | | string getExec(); |
| 58 | | void setExec(string exec); |
| 59 | | string getParams(); |
| 60 | | void setParams(string params); |
| 61 | | string getWorkdir(); |
| 62 | | void setWorkdir(string workdir); |
| 63 | | string getManual(); |
| 64 | | void setManual(string manual); |
| 65 | | string getSelectorDir(); |
| 66 | | void setSelectorDir(string selectordir); |
| 55 | virtual const string &searchIcon(); |
| 56 | |
| 57 | const string &getExec(); |
| 58 | void setExec(const string &exec); |
| 59 | const string &getParams(); |
| 60 | void setParams(const string ¶ms); |
| 61 | const string &getWorkdir(); |
| 62 | void setWorkdir(const string &workdir); |
| 63 | const string &getManual(); |
| 64 | void setManual(const string &manual); |
| 65 | const string &getSelectorDir(); |
| 66 | void setSelectorDir(const string &selectordir); |
| 67 | 67 | bool getSelectorBrowser(); |
| 68 | 68 | void setSelectorBrowser(bool value); |
| 69 | 69 | bool getUseRamTimings(); |
| 70 | 70 | void setUseRamTimings(bool value); |
| 71 | | string getSelectorScreens(); |
| 72 | | void setSelectorScreens(string selectorscreens); |
| 73 | | string getSelectorFilter(); |
| 74 | | void setSelectorFilter(string selectorfilter); |
| 75 | | string getAliasFile(); |
| 76 | | void setAliasFile(string aliasfile); |
| 71 | const string &getSelectorScreens(); |
| 72 | void setSelectorScreens(const string &selectorscreens); |
| 73 | const string &getSelectorFilter(); |
| 74 | void setSelectorFilter(const string &selectorfilter); |
| 75 | const string &getAliasFile(); |
| 76 | void setAliasFile(const string &aliasfile); |
| 77 | 77 | |
| 78 | 78 | string file; |
| 79 | 79 | |
| 80 | 80 | int clock(); |
| 81 | | string clockStr(int maxClock); |
| 81 | const string &clockStr(int maxClock); |
| 82 | 82 | void setClock(int mhz); |
| 83 | 83 | |
| 84 | 84 | int volume(); |
| 85 | | string volumeStr(); |
| 85 | const string &volumeStr(); |
| 86 | 86 | void setVolume(int vol); |
| 87 | 87 | |
| 88 | 88 | //G |
| 89 | 89 | int gamma(); |
| 90 | | string gammaStr(); |
| 90 | const string &gammaStr(); |
| 91 | 91 | void setGamma(int gamma); |
| 92 | 92 | |
| 93 | 93 | int backlight(); |
| 94 | | string backlightStr(); |
| 94 | const string &backlightStr(); |
| 95 | 95 | void setBacklight(int val); |
| 96 | 96 | // /G |
| 97 | 97 | |
| ... | ... | |
| 101 | 101 | bool save(); |
| 102 | 102 | void run(); |
| 103 | 103 | void showManual(); |
| 104 | | void selector(int startSelection=0, string selectorDir=""); |
| 105 | | void launch(string selectedFile="", string selectedDir=""); |
| 104 | void selector(int startSelection=0, const string &selectorDir=""); |
| 105 | void launch(const string &selectedFile="", const string &selectedDir=""); |
| 106 | 106 | bool targetExists(); |
| 107 | 107 | }; |
| 108 | 108 | |
| src/menu.cpp |
| 133 | 133 | return iSection; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | | string Menu::selSection() { |
| 136 | const string &Menu::selSection() { |
| 137 | 137 | return sections[iSection]; |
| 138 | 138 | } |
| 139 | 139 | |
| ... | ... | |
| 161 | 161 | /*==================================== |
| 162 | 162 | LINKS MANAGEMENT |
| 163 | 163 | ====================================*/ |
| 164 | | bool Menu::addActionLink(uint section, string title, LinkRunAction action, string description, string icon) { |
| 164 | bool Menu::addActionLink(uint section, const string &title, const LinkRunAction &action, const string &description, const string &icon) { |
| 165 | 165 | if (section>=sections.size()) return false; |
| 166 | 166 | |
| 167 | 167 | LinkAction *linkact = new LinkAction(gmenu2x,action); |
| ... | ... | |
| 183 | 183 | if (!addSection(section)) |
| 184 | 184 | return false; |
| 185 | 185 | } |
| 186 | | if (path[path.length()-1]!='/') path += "/"; |
| 187 | 186 | |
| 188 | 187 | //if the extension is not equal to gpu or dge then enable the wrapepr by default |
| 189 | 188 | bool wrapper = false, pxml = false; |
| ... | ... | |
| 213 | 212 | cout << "\033[0;34mGMENU2X:\033[0m Adding link: " << linkpath << endl; |
| 214 | 213 | #endif |
| 215 | 214 | |
| 215 | if (path[path.length()-1]!='/') path += "/"; |
| 216 | 216 | //search for a manual |
| 217 | 217 | pos = file.rfind("."); |
| 218 | 218 | string exename = path+file.substr(0,pos); |
| ... | ... | |
| 306 | 306 | return true; |
| 307 | 307 | } |
| 308 | 308 | |
| 309 | | bool Menu::addSection(string sectionName) { |
| 309 | bool Menu::addSection(const string §ionName) { |
| 310 | 310 | string sectiondir = "sections/"+sectionName; |
| 311 | 311 | if (mkdir(sectiondir.c_str(),0777)==0) { |
| 312 | 312 | sections.push_back(sectionName); |
| src/menusettingimage.cpp |
| 23 | 23 | |
| 24 | 24 | using namespace std; |
| 25 | 25 | |
| 26 | | MenuSettingImage::MenuSettingImage(GMenu2X *gmenu2x, string name, string description, string *value, string filter) |
| 26 | MenuSettingImage::MenuSettingImage(GMenu2X *gmenu2x, const string &name, const string &description, string *value, const string &filter) |
| 27 | 27 | : MenuSettingFile(gmenu2x,name,description,value,filter) { |
| 28 | 28 | this->gmenu2x = gmenu2x; |
| 29 | 29 | this->filter = filter; |
| ... | ... | |
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | | void MenuSettingImage::setValue(string value) { |
| 42 | void MenuSettingImage::setValue(const string &value) { |
| 43 | 43 | string skinpath = gmenu2x->getExePath()+"skins/"+gmenu2x->confStr["skin"]; |
| 44 | 44 | bool inSkinDir = value.substr(0,skinpath.length()) == skinpath; |
| 45 | 45 | if (!inSkinDir && gmenu2x->confStr["skin"] != "Default") { |
| ... | ... | |
| 50 | 50 | string tempIcon = value.substr(skinpath.length(), value.length()); |
| 51 | 51 | string::size_type pos = tempIcon.find("/"); |
| 52 | 52 | if (pos != string::npos) |
| 53 | | value = "skin:"+tempIcon.substr(pos+1,value.length()); |
| 53 | *_value = "skin:"+tempIcon.substr(pos+1,value.length()); |
| 54 | else |
| 55 | *_value = value; |
| 56 | } else { |
| 57 | *_value = value; |
| 54 | 58 | } |
| 55 | | *_value = value; |
| 56 | 59 | } |
| src/sfontplus.cpp |
| 46 | 46 | initFont(font); |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | | SFontPlus::SFontPlus(string font) { |
| 49 | SFontPlus::SFontPlus(const string &font) { |
| 50 | 50 | surface = NULL; |
| 51 | 51 | initFont(font); |
| 52 | 52 | } |
| ... | ... | |
| 60 | 60 | //return c>=194; |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | | void SFontPlus::initFont(string font, string characters) { |
| 63 | void SFontPlus::initFont(const string &font, const string &characters) { |
| 64 | 64 | SDL_Surface *buf = IMG_Load(font.c_str()); |
| 65 | 65 | if (buf!=NULL) { |
| 66 | 66 | initFont( SDL_DisplayFormatAlpha(buf), characters ); |
| ... | ... | |
| 68 | 68 | } |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | | void SFontPlus::initFont(SDL_Surface *font, string characters) { |
| 71 | void SFontPlus::initFont(SDL_Surface *font, const string &characters) { |
| 72 | 72 | freeFont(); |
| 73 | 73 | this->characters = characters; |
| 74 | 74 | if (font==NULL) return; |
| ... | ... | |
| 126 | 126 | } |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | | void SFontPlus::write(SDL_Surface *s, string text, int x, int y) { |
| 129 | void SFontPlus::write(SDL_Surface *s, const string &text, int x, int y) { |
| 130 | 130 | if (text.empty()) return; |
| 131 | 131 | |
| 132 | 132 | string::size_type pos; |
| ... | ... | |
| 161 | 161 | } |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | | uint SFontPlus::getTextWidth(string text) { |
| 164 | uint SFontPlus::getTextWidth(const string &text) { |
| 165 | 165 | string::size_type pos; |
| 166 | 166 | int width = 0; |
| 167 | 167 | |
| src/surface.cpp |
| 26 | 26 | #include "surface.h" |
| 27 | 27 | #include "utilities.h" |
| 28 | 28 | |
| 29 | | RGBAColor strtorgba(string strColor) { |
| 29 | RGBAColor strtorgba(const string &strColor) { |
| 30 | 30 | RGBAColor c = {0,0,0,255}; |
| 31 | 31 | c.r = constrain( strtol( strColor.substr(0,2).c_str(), NULL, 16 ), 0, 255 ); |
| 32 | 32 | c.g = constrain( strtol( strColor.substr(2,2).c_str(), NULL, 16 ), 0, 255 ); |
| ... | ... | |
| 40 | 40 | dblbuffer = NULL; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | | Surface::Surface(string img, bool alpha, string skin) { |
| 43 | Surface::Surface(const string &img, bool alpha, const string &skin) { |
| 44 | 44 | raw = NULL; |
| 45 | 45 | dblbuffer = NULL; |
| 46 | 46 | load(img, alpha, skin); |
| ... | ... | |
| 48 | 48 | halfH = raw->h/2; |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | | Surface::Surface(string img, string skin, bool alpha) { |
| 51 | Surface::Surface(const string &img, const string &skin, bool alpha) { |
| 52 | 52 | raw = NULL; |
| 53 | 53 | dblbuffer = NULL; |
| 54 | 54 | load(img, alpha, skin); |
| ... | ... | |
| 111 | 111 | return raw->format; |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | | void Surface::load(string img, bool alpha, string skin) { |
| 114 | void Surface::load(const string &img, bool alpha, const string &skin) { |
| 115 | 115 | free(); |
| 116 | 116 | |
| 117 | 117 | string skinpath; |
| ... | ... | |
| 119 | 119 | skinpath = "skins/"+skin+"/"+img; |
| 120 | 120 | if (!fileExists(skinpath)) |
| 121 | 121 | skinpath = "skins/Default/"+img; |
| 122 | | img = skinpath; |
| 122 | } else { |
| 123 | skinpath = img; |
| 123 | 124 | } |
| 124 | 125 | |
| 125 | | SDL_Surface *buf = IMG_Load(img.c_str()); |
| 126 | SDL_Surface *buf = IMG_Load(skinpath.c_str()); |
| 126 | 127 | if (buf!=NULL) { |
| 127 | 128 | if (alpha) |
| 128 | 129 | raw = SDL_DisplayFormatAlpha(buf); |
| ... | ... | |
| 264 | 265 | */ |
| 265 | 266 | } |
| 266 | 267 | |
| 267 | | void Surface::write(ASFont *font, string text, int x, int y, const unsigned short halign, const unsigned short valign) { |
| 268 | void Surface::write(ASFont *font, const string &text, int x, int y, const unsigned short halign, const unsigned short valign) { |
| 268 | 269 | font->write(this,text,x,y,halign,valign); |
| 269 | 270 | } |
| 270 | 271 | |
| src/surface.h |
| 32 | 32 | unsigned short r,g,b,a; |
| 33 | 33 | }; |
| 34 | 34 | |
| 35 | | RGBAColor strtorgba(string strColor); |
| 35 | RGBAColor strtorgba(const string &strColor); |
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | 38 | Wrapper around SDL_Surface |
| ... | ... | |
| 46 | 46 | |
| 47 | 47 | public: |
| 48 | 48 | Surface(); |
| 49 | | Surface(string img, string skin="", bool alpha=true); |
| 50 | | Surface(string img, bool alpha, string skin=""); |
| 49 | Surface(const string &img, const string &skin="", bool alpha=true); |
| 50 | Surface(const string &img, bool alpha, const string &skin=""); |
| 51 | 51 | Surface(SDL_Surface *s, SDL_PixelFormat *fmt = NULL, Uint32 flags = 0); |
| 52 | 52 | Surface(Surface *s); |
| 53 | 53 | Surface(int w, int h, Uint32 flags = SDL_HWSURFACE|SDL_SRCALPHA); |
| ... | ... | |
| 58 | 58 | SDL_Surface *raw; |
| 59 | 59 | |
| 60 | 60 | void free(); |
| 61 | | void load(string img, bool alpha=true, string skin=""); |
| 61 | void load(const string &img, bool alpha=true, const string &skin=""); |
| 62 | 62 | void lock(); |
| 63 | 63 | void unlock(); |
| 64 | 64 | void flip(); |
| ... | ... | |
| 83 | 83 | bool blitRight(Surface *destination, int x, int y, int w=0, int h=0, int a=-1); |
| 84 | 84 | bool blitRight(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1); |
| 85 | 85 | |
| 86 | | void write(ASFont *font, string text, int x, int y, const unsigned short halign=0, const unsigned short valign=0); |
| 86 | void write(ASFont *font, const string &text, int x, int y, const unsigned short halign=0, const unsigned short valign=0); |
| 87 | 87 | |
| 88 | 88 | int box(Sint16, Sint16, Sint16, Sint16, Uint8, Uint8, Uint8, Uint8); |
| 89 | 89 | int box(Sint16, Sint16, Sint16, Sint16, Uint8, Uint8, Uint8); |
| src/surfacecollection.cpp |
| 22 | 22 | |
| 23 | 23 | using namespace std; |
| 24 | 24 | |
| 25 | | SurfaceCollection::SurfaceCollection(bool defaultAlpha, string skin) { |
| 25 | SurfaceCollection::SurfaceCollection(bool defaultAlpha, const string &skin) { |
| 26 | 26 | surfaces.set_empty_key(" "); |
| 27 | 27 | surfaces.set_deleted_key(""); |
| 28 | 28 | this->defaultAlpha = defaultAlpha; |
| ... | ... | |
| 31 | 31 | |
| 32 | 32 | SurfaceCollection::~SurfaceCollection() {} |
| 33 | 33 | |
| 34 | | void SurfaceCollection::setSkin(string skin) { |
| 34 | void SurfaceCollection::setSkin(const string &skin) { |
| 35 | 35 | this->skin = skin; |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | | string SurfaceCollection::getSkinFilePath(string file) { |
| 38 | string SurfaceCollection::getSkinFilePath(const string &file) { |
| 39 | 39 | string prefix = "/usr/share/gmenu2x/"; |
| 40 | 40 | if (fileExists("skins/"+skin+"/"+file)) |
| 41 | 41 | return "skins/"+skin+"/"+file; |
| ... | ... | |
| 54 | 54 | } |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | | bool SurfaceCollection::exists(string path) { |
| 57 | bool SurfaceCollection::exists(const string &path) { |
| 58 | 58 | return surfaces.find(path) != surfaces.end(); |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | | Surface *SurfaceCollection::add(Surface *s, string path) { |
| 61 | Surface *SurfaceCollection::add(Surface *s, const string &path) { |
| 62 | 62 | if (exists(path)) del(path); |
| 63 | 63 | surfaces[path] = s; |
| 64 | 64 | return s; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | | Surface *SurfaceCollection::add(string path, bool alpha) { |
| 67 | Surface *SurfaceCollection::add(const string &path, bool alpha) { |
| 68 | 68 | #ifdef DEBUG |
| 69 | 69 | cout << "Adding surface: " << path << endl; |
| 70 | 70 | #endif |
| ... | ... | |
| 82 | 82 | return s; |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | | Surface *SurfaceCollection::addSkinRes(string path, bool alpha) { |
| 85 | Surface *SurfaceCollection::addSkinRes(const string &path, bool alpha) { |
| 86 | 86 | #ifdef DEBUG |
| 87 | 87 | cout << "Adding skin surface: " << path << endl; |
| 88 | 88 | #endif |
| ... | ... | |
| 99 | 99 | return s; |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | | void SurfaceCollection::del(string path) { |
| 102 | void SurfaceCollection::del(const string &path) { |
| 103 | 103 | SurfaceHash::iterator i = surfaces.find(path); |
| 104 | 104 | if (i != surfaces.end()) { |
| 105 | 105 | free(i->second); |
| ... | ... | |
| 115 | 115 | } |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | | void SurfaceCollection::move(string from, string to) { |
| 118 | void SurfaceCollection::move(const string &from, const string &to) { |
| 119 | 119 | del(to); |
| 120 | 120 | surfaces[to] = surfaces[from]; |
| 121 | 121 | surfaces.erase(from); |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | | Surface *SurfaceCollection::operator[](string key) { |
| 124 | Surface *SurfaceCollection::operator[](const string &key) { |
| 125 | 125 | SurfaceHash::iterator i = surfaces.find(key); |
| 126 | 126 | if (i == surfaces.end()) |
| 127 | 127 | return add(key, defaultAlpha); |
| ... | ... | |
| 129 | 129 | return i->second; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | | Surface *SurfaceCollection::skinRes(string key) { |
| 132 | Surface *SurfaceCollection::skinRes(const string &key) { |
| 133 | 133 | if (key.empty()) return NULL; |
| 134 | 134 | |
| 135 | 135 | SurfaceHash::iterator i = surfaces.find(key); |
| src/surfacecollection.h |
| 39 | 39 | string skin; |
| 40 | 40 | |
| 41 | 41 | public: |
| 42 | | SurfaceCollection(bool defaultAlpha=true, string skin="default"); |
| 42 | SurfaceCollection(bool defaultAlpha=true, const string &skin="default"); |
| 43 | 43 | ~SurfaceCollection(); |
| 44 | 44 | |
| 45 | | void setSkin(string skin); |
| 46 | | string getSkinFilePath(string file); |
| 45 | void setSkin(const string &skin); |
| 46 | string getSkinFilePath(const string &file); |
| 47 | 47 | |
| 48 | 48 | bool defaultAlpha; |
| 49 | 49 | void debug(); |
| 50 | 50 | |
| 51 | | Surface *add(Surface *s, string path); |
| 52 | | Surface *add(string path, bool alpha=true); |
| 53 | | Surface *addSkinRes(string path, bool alpha=true); |
| 54 | | void del(string path); |
| 51 | Surface *add(Surface *s, const string &path); |
| 52 | Surface *add(const string &path, bool alpha=true); |
| 53 | Surface *addSkinRes(const string &path, bool alpha=true); |
| 54 | void del(const string &path); |
| 55 | 55 | void clear(); |
| 56 | | void move(string from, string to); |
| 57 | | bool exists(string path); |
| 56 | void move(const string &from, const string &to); |
| 57 | bool exists(const string &path); |
| 58 | 58 | |
| 59 | | Surface *operator[](string); |
| 60 | | Surface *skinRes(string); |
| 59 | Surface *operator[](const string &); |
| 60 | Surface *skinRes(const string &); |
| 61 | 61 | }; |
| 62 | 62 | |
| 63 | 63 | #endif |
| src/utilities.cpp |
| 28 | 28 | |
| 29 | 29 | using namespace std; |
| 30 | 30 | |
| 31 | | bool case_less::operator()(string const &left, string const &right) const { |
| 31 | bool case_less::operator()(const string &left, const string &right) const { |
| 32 | 32 | return strcasecmp(left.c_str(), right.c_str()) < 0; |
| 33 | 33 | } |
| 34 | 34 | |
| ... | ... | |
| 43 | 43 | return string(s, b, e - b + 1); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | | void string_copy(string s, char **cs) { |
| 46 | void string_copy(const string &s, char **cs) { |
| 47 | 47 | *cs = (char*)malloc(s.length()); |
| 48 | 48 | strcpy(*cs, s.c_str()); |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | | char * string_copy(string s) { |
| 51 | char * string_copy(const string &s) { |
| 52 | 52 | char *cs = NULL; |
| 53 | 53 | string_copy(s, &cs); |
| 54 | 54 | return cs; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | | bool fileExists(string file) { |
| 57 | bool fileExists(const string &file) { |
| 58 | 58 | fstream fin; |
| 59 | 59 | fin.open(file.c_str() ,ios::in); |
| 60 | 60 | bool exists = fin.is_open(); |
| ... | ... | |
| 115 | 115 | return *val; |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | | string evalStrConf (string val, string def) { |
| 118 | const string &evalStrConf (const string &val, const string &def) { |
| 119 | 119 | return val.empty() ? def : val; |
| 120 | 120 | } |
| 121 | | string evalStrConf (string *val, string def) { |
| 121 | const string &evalStrConf (string *val, const string &def) { |
| 122 | 122 | *val = evalStrConf(*val, def); |
| 123 | 123 | return *val; |
| 124 | 124 | } |
| ... | ... | |
| 158 | 158 | return true; |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | | string strreplace (string orig, string search, string replace) { |
| 161 | string strreplace (string orig, const string &search, const string &replace) { |
| 162 | 162 | string::size_type pos = orig.find( search, 0 ); |
| 163 | 163 | while (pos != string::npos) { |
| 164 | 164 | orig.replace(pos,search.length(),replace); |
| src/utilities.h |
| 49 | 49 | |
| 50 | 50 | class case_less { |
| 51 | 51 | public: |
| 52 | | bool operator()(string const &left, string const &right) const; |
| 52 | bool operator()(const string &left, const string &right) const; |
| 53 | 53 | }; |
| 54 | 54 | |
| 55 | 55 | string trim(const string& s); |
| 56 | | string strreplace (string orig, string search, string replace); |
| 56 | string strreplace (string orig, const string &search, const string &replace); |
| 57 | 57 | string cmdclean (string cmdline); |
| 58 | 58 | |
| 59 | | char *string_copy(string); |
| 60 | | void string_copy(string, char **); |
| 59 | char *string_copy(const string &); |
| 60 | void string_copy(const string &, char **); |
| 61 | 61 | |
| 62 | | bool fileExists(string file); |
| 62 | bool fileExists(const string &file); |
| 63 | 63 | bool rmtree(string path); |
| 64 | 64 | |
| 65 | 65 | int max (int a, int b); |
| ... | ... | |
| 68 | 68 | |
| 69 | 69 | int evalIntConf (int val, int def, int imin, int imax); |
| 70 | 70 | int evalIntConf (int *val, int def, int imin, int imax); |
| 71 | | string evalStrConf (string val, string def); |
| 72 | | string evalStrConf (string *val, string def); |
| 71 | const string &evalStrConf (const string &val, const string &def); |
| 72 | const string &evalStrConf (string *val, const string &def); |
| 73 | 73 | |
| 74 | 74 | bool split (vector<string> &vec, const string &str, const string &delim, bool destructive=true); |
| 75 | 75 | |