From 7c9364780b63ca83c1e7e53858cbc002cb5f193d Mon Sep 17 00:00:00 2001 From: Ayla Date: Fri, 17 Sep 2010 22:31:09 +0200 Subject: [PATCH] Replaced every message output by calls to the log macros. --- src/cpu.cpp | 11 +++++---- src/filelister.cpp | 5 ++-- src/gmenu2x.cpp | 48 +++++++++++++++++++-------------------- src/inputmanager.cpp | 13 ++++++----- src/linkapp.cpp | 10 ++++---- src/menu.cpp | 33 ++++++++++++--------------- src/selector.cpp | 9 ++++---- src/sfontplus.cpp | 4 ++-- src/surface.cpp | 5 ++-- src/surfacecollection.cpp | 13 ++++------- src/translator.cpp | 6 ++--- src/utilities.cpp | 5 ++-- src/wallpaperdialog.cpp | 8 ++++--- 13 files changed, 85 insertions(+), 85 deletions(-) diff --git a/src/cpu.cpp b/src/cpu.cpp index 4facea5..c30f17a 100644 --- a/src/cpu.cpp +++ b/src/cpu.cpp @@ -1,11 +1,14 @@ -#include "cpu.h" - #include #include #include #include #include +#include + +#include "cpu.h" +#include "debug.h" + #define SYSFS_CPUFREQ_DIR "/sys/devices/system/cpu/cpu0/cpufreq" #define SYSFS_CPUFREQ_MAX SYSFS_CPUFREQ_DIR "/scaling_max_freq" #define SYSFS_CPUFREQ_SET SYSFS_CPUFREQ_DIR "/scaling_setspeed" @@ -14,11 +17,11 @@ void writeStringToFile(const char *path, const char *content) { int fd = open(path, O_RDWR); if (fd == -1) { - fprintf(stderr, "Failed to open \"%s\": %s\n", path, strerror(errno)); + WARNING("Failed to open '%s': %s\n", path, strerror(errno)); } else { ssize_t written = write(fd, content, strlen(content)); if (written == -1) { - fprintf(stderr, "Error writing \"%s\": %s\n", path, strerror(errno)); + WARNING("Error writing '%s': %s\n", path, strerror(errno)); } close(fd); } diff --git a/src/filelister.cpp b/src/filelister.cpp index a323a3e..657b97c 100644 --- a/src/filelister.cpp +++ b/src/filelister.cpp @@ -29,6 +29,7 @@ #include "filelister.h" #include "utilities.h" +#include "debug.h" using namespace std; @@ -72,7 +73,7 @@ void FileLister::browse() if (showDirectories || showFiles) { DIR *dirp; if ((dirp = opendir(path.c_str())) == NULL) { - cout << "Error: opendir(" << path << ")" << endl; + ERROR("Error: opendir(%s)\n", path.c_str()); return; } @@ -92,7 +93,7 @@ void FileLister::browse() filepath = path + file; int statRet = stat(filepath.c_str(), &st); if (statRet == -1) { - cout << "\033[0;34mGMENU2X:\033[0;31m stat failed on '" << filepath << "' with error '" << strerror(errno) << "'\033[0m" << endl; + ERROR("Stat failed on '%s' with error '%s'\n", filepath.c_str(), strerror(errno)); continue; } if (find(excludes.begin(), excludes.end(), file) != excludes.end()) diff --git a/src/gmenu2x.cpp b/src/gmenu2x.cpp index 7769de6..03916ff 100644 --- a/src/gmenu2x.cpp +++ b/src/gmenu2x.cpp @@ -69,6 +69,8 @@ #include "menusettingimage.h" #include "menusettingdir.h" +#include "debug.h" + #include #ifdef TARGET_PANDORA @@ -112,17 +114,15 @@ static const char *colorToString(enum color c) return colorNames[c]; } -int main(int /*argc*/, char */*argv*/[]) { - cout << "----" << endl; - cout << "GMenu2X starting: If you read this message in the logs, check http://gmenu2x.sourceforge.net/page/Troubleshooting for a solution" << endl; - cout << "----" << endl; +int main(int /*argc*/, char * /*argv*/[]) { + INFO("----\nGMenu2X starting: If you read this message in the logs, check http://gmenu2x.sourceforge.net/page/Troubleshooting for a solution\n----\n"); signal(SIGINT,&exit); GMenu2X app; -#ifdef DEBUG - cout << "Starting main()" << endl; -#endif + + DEBUG("Starting main()\n"); app.main(); + return 0; } @@ -264,7 +264,7 @@ GMenu2X::GMenu2X() { //Screen if( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_JOYSTICK)<0 ) { - cout << "\033[0;34mGMENU2X:\033[0;31m Could not initialize SDL:\033[0m " << SDL_GetError() << endl; + ERROR("Could not initialize SDL: %s\n", SDL_GetError()); quit(); } @@ -288,9 +288,8 @@ GMenu2X::GMenu2X() { initMenu(); if (!fileExists(confStr["wallpaper"])) { -#ifdef DEBUG - cout << "Searching wallpaper" << endl; -#endif + DEBUG("Searching wallpaper\n"); + FileLister fl("skins/"+confStr["skin"]+"/wallpapers",false,true); fl.setFilter(".png,.jpg,.jpeg,.bmp"); fl.browse(); @@ -403,7 +402,7 @@ void GMenu2X::initFont() { string fontFile = sc.getSkinFilePath("imgs/font.png"); if (fontFile.empty()) { - cout << "Font png not found!" << endl; + ERROR("Font png not found!\n"); quit(); exit(-1); } @@ -795,7 +794,7 @@ void GMenu2X::main() { uint sectionsCoordX = 24; SDL_Rect re = {0,0,0,0}; bool helpDisplayed = false; -#ifdef DEBUG +#ifdef WITH_DEBUG //framerate long tickFPS = SDL_GetTicks(); int drawn_frames = 0; @@ -913,7 +912,7 @@ void GMenu2X::main() { } -#ifdef DEBUG +#ifdef WITH_DEBUG //framerate drawn_frames++; if (tickNow-tickFPS>=1000) { @@ -1031,7 +1030,7 @@ void GMenu2X::explorer() { //if execution continues then something went wrong and as we already called SDL_Quit we cannot continue //try relaunching gmenu2x - fprintf(stderr, "Error executing selected application, re-launching gmenu2x\n"); + ERROR("Error executing selected application, re-launching gmenu2x\n"); chdir(getExePath().c_str()); execlp("./gmenu2x", "./gmenu2x", NULL); } @@ -1167,7 +1166,7 @@ void GMenu2X::setSkin(const string &skin, bool setWallpaper) { string line; while (getline(skinconf, line, '\n')) { line = trim(line); - cout << "skinconf: " << line << endl; + DEBUG("skinconf: '%s'\n", line.c_str()); string::size_type pos = line.find("="); string name = trim(line.substr(0,pos)); string value = trim(line.substr(pos+1,line.length())); @@ -1460,9 +1459,8 @@ void GMenu2X::editLink() { //G menu->selLinkApp()->setBacklight(linkBacklight); -#ifdef DEBUG - cout << "New Section: " << newSection << endl; -#endif + INFO("New Section: '%s'\n", newSection.c_str()); + //if section changed move file and update link->file if (oldSection!=newSection) { vector::const_iterator newSectionIndex = find(menu->getSections().begin(),menu->getSections().end(),newSection); @@ -1477,9 +1475,9 @@ void GMenu2X::editLink() { } rename(menu->selLinkApp()->getFile().c_str(),newFileName.c_str()); menu->selLinkApp()->renameFile(newFileName); -#ifdef DEBUG - cout << "New section index: " << newSectionIndex - menu->getSections().begin() << endl; -#endif + + INFO("New section index: %i.\n", newSectionIndex - menu->getSections().begin()); + menu->linkChangeSection(menu->selLinkIndex(), menu->selSectionIndex(), newSectionIndex - menu->getSections().begin()); } menu->selLinkApp()->save(); @@ -1816,7 +1814,7 @@ int GMenu2X::getVolume() { if(mixer) { if (ioctl(mixer, SOUND_MIXER_READ_VOLUME, &basevolume) == -1) { - fprintf(stderr, "Failed opening mixer for read - VOLUME\n"); + ERROR("Failed opening mixer for read - VOLUME\n"); } close(mixer); if(basevolume != -1) @@ -1833,7 +1831,7 @@ void GMenu2X::setVolume(int vol) { if(mixer) { if (ioctl(mixer, SOUND_MIXER_WRITE_VOLUME, &oss_volume) == -1) { - fprintf(stderr, "Failed opening mixer for write - VOLUME\n"); + ERROR("Failed opening mixer for write - VOLUME\n"); } close(mixer); } @@ -1887,7 +1885,7 @@ string GMenu2X::getDiskFree() { ((unsigned long long)b.f_blocks * b.f_frsize) / 1048576; ss << free << "/" << total << "MB"; ss >> df; - } else cout << "\033[0;34mGMENU2X:\033[0;31m statvfs failed with error '" << strerror(errno) << "'\033[0m" << endl; + } else WARNING("statvfs failed with error '%s'.\n", strerror(errno)); return df; } diff --git a/src/inputmanager.cpp b/src/inputmanager.cpp index 58014f7..21be83a 100644 --- a/src/inputmanager.cpp +++ b/src/inputmanager.cpp @@ -21,8 +21,10 @@ #include #include #include + #include "inputmanager.h" #include "utilities.h" +#include "debug.h" using namespace std; @@ -41,14 +43,13 @@ void InputManager::init(const string &conffile) { for (int x=0; x #include + #include "linkapp.h" #include "menu.h" #include "selector.h" #include "textmanualdialog.h" +#include "debug.h" using namespace std; @@ -100,7 +102,7 @@ LinkApp::LinkApp(GMenu2X *gmenu2x_, InputManager &inputMgr_, } else if (name == "selectoraliases") { setAliasFile( value ); } else { - cout << "Unrecognized option: " << name << endl; + WARNING("Unrecognized option: '%s'\n", name.c_str()); break; } } @@ -252,7 +254,7 @@ bool LinkApp::save() { sync(); return true; } else - cout << "\033[0;34mGMENU2X:\033[0;31m Error while opening the file '" << file << "' for write\033[0m" << endl; + ERROR("Error while opening the file '%s' for write.\n", file.c_str()); return false; } @@ -436,9 +438,7 @@ void LinkApp::launch(const string &selectedFile, const string &selectedDir) { if (volume()>=0) gmenu2x->setVolume(volume()); -#ifdef DEBUG - cout << "\033[0;34mGMENU2X:\033[0m Executing '" << title << "' (" << exec << " " << params << ")" << endl; -#endif + INFO("Executing '%s' (%s %s)\n", title.c_str(), exec.c_str(), params.c_str()); //check if we have to quit string command = cmdclean(exec); diff --git a/src/menu.cpp b/src/menu.cpp index fdbd4e2..18f911b 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -31,6 +31,7 @@ #include "menu.h" #include "filelister.h" #include "utilities.h" +#include "debug.h" using namespace std; @@ -207,9 +208,8 @@ bool Menu::addLink(string path, string file, string section) { linkpath = "sections/"+section+"/"+title+linkpath; x++; } -#ifdef DEBUG - cout << "\033[0;34mGMENU2X:\033[0m Adding link: " << linkpath << endl; -#endif + + INFO("Adding link: '%s'\n", linkpath.c_str()); if (path[path.length()-1]!='/') path += "/"; //search for a manual @@ -241,9 +241,8 @@ bool Menu::addLink(string path, string file, string section) { } } } -#ifdef DEBUG - cout << "\033[0;34mGMENU2X:\033[0m Manual: " << manual << endl; -#endif + + INFO("Manual: '%s'\n", manual.c_str()); string shorttitle=title, description="", exec=path+file, icon=""; @@ -266,17 +265,17 @@ bool Menu::addLink(string path, string file, string section) { sync(); int isection = find(sections.begin(),sections.end(),section) - sections.begin(); if (isection>=0 && isection<(int)sections.size()) { -#ifdef DEBUG - cout << "\033[0;34mGMENU2X:\033[0m Section: " << sections[isection] << "(" << isection << ")" << endl; -#endif + + INFO("Section: '%s(%i)'\n", sections[isection].c_str(), isection); + LinkApp* link = new LinkApp(gmenu2x, gmenu2x->input, linkpath.c_str()); link->setSize(gmenu2x->skinConfInt["linkWidth"],gmenu2x->skinConfInt["linkHeight"]); links[isection].push_back( link ); } } else { -#ifdef DEBUG - cout << "\033[0;34mGMENU2X:\033[0;31m Error while opening the file '" << linkpath << "' for write\033[0m" << endl; -#endif + + ERROR("Error while opening the file '%s' for write.\n", linkpath.c_str()); + return false; } @@ -295,9 +294,8 @@ bool Menu::addSection(const string §ionName) { } void Menu::deleteSelectedLink() { -#ifdef DEBUG - cout << "\033[0;34mGMENU2X:\033[0m Deleting link " << selLink()->getTitle() << endl; -#endif + INFO("Deleting link '%s'\n", selLink()->getTitle().c_str()); + if (selLinkApp()!=NULL) unlink(selLinkApp()->getFile().c_str()); gmenu2x->sc.del(selLink()->getIconPath()); @@ -306,9 +304,8 @@ void Menu::deleteSelectedLink() { } void Menu::deleteSelectedSection() { -#ifdef DEBUG - cout << "\033[0;34mGMENU2X:\033[0m Deleting section " << selSection() << endl; -#endif + INFO("Deleting section '%s'\n", selSection().c_str()); + gmenu2x->sc.del("sections/"+selSection()+".png"); links.erase( links.begin()+selSectionIndex() ); sections.erase( sections.begin()+selSectionIndex() ); diff --git a/src/selector.cpp b/src/selector.cpp index 13488fb..b49cdb2 100644 --- a/src/selector.cpp +++ b/src/selector.cpp @@ -32,6 +32,7 @@ #include "selector.h" #include "filelister.h" #include "gmenu2x.h" +#include "debug.h" using namespace std; @@ -157,7 +158,7 @@ int Selector::exec(int startSelection) { result = false; } else { dir = dir.substr(0,p+1); - cout << dir << endl; + INFO("%s\n", dir.c_str()); selected = 0; firstElement = 0; prepare(&fl,&screens,&titles); @@ -204,9 +205,9 @@ void Selector::prepare(FileLister *fl, vector *screens, vector * titles->at(i) = getAlias(noext); if (titles->at(i)=="") titles->at(i) = noext; -#ifdef DEBUG - cout << "\033[0;34mGMENU2X:\033[0m Searching for screen " << screendir << noext << ".png" << endl; -#endif + + DEBUG("Searching for screen '%s%s.png'\n", screendir.c_str(), noext.c_str()); + if (fileExists(screendir+noext+".png")) screens->at(i) = screendir+noext+".png"; else if (fileExists(screendir+noext+".jpg")) diff --git a/src/sfontplus.cpp b/src/sfontplus.cpp index 0235e05..765ec99 100644 --- a/src/sfontplus.cpp +++ b/src/sfontplus.cpp @@ -76,11 +76,11 @@ void SFontPlus::initFont(SDL_Surface *font, const string &characters) { if (font==NULL) return; surface = font; Uint32 pink = SDL_MapRGB(surface->format, 255,0,255); -#ifdef _DEBUG +#ifdef DEBUG bool utf8 = false; for (uint x=0; x128; - if (utf8) printf("%d\n", (unsigned char)characters[x]); + if (utf8) DEBUG("%d\n", (unsigned char)characters[x]); } #endif diff --git a/src/surface.cpp b/src/surface.cpp index 0e5d8f6..4947f67 100644 --- a/src/surface.cpp +++ b/src/surface.cpp @@ -25,6 +25,7 @@ using namespace std; #include "surface.h" #include "utilities.h" +#include "debug.h" RGBAColor strtorgba(const string &strColor) { RGBAColor c = {0,0,0,255}; @@ -131,14 +132,14 @@ void Surface::load(const string &img, bool alpha, const string &skin) { raw = SDL_DisplayFormat(buf); SDL_FreeSurface(buf); } else { - cout << "Couldn't load surface " << img << endl; + ERROR("Couldn't load surface '%s'\n", img.c_str()); } } void Surface::lock() { if ( SDL_MUSTLOCK(raw) && !locked ) { if ( SDL_LockSurface(raw) < 0 ) { - fprintf(stderr, "Can't lock surface: %s\n", SDL_GetError()); + ERROR("Can't lock surface: '%s'\n", SDL_GetError()); SDL_Quit(); } locked = true; diff --git a/src/surfacecollection.cpp b/src/surfacecollection.cpp index cdb2f16..bcd8a51 100644 --- a/src/surfacecollection.cpp +++ b/src/surfacecollection.cpp @@ -21,8 +21,8 @@ #include "surfacecollection.h" #include "surface.h" #include "utilities.h" +#include "debug.h" -using std::cout; using std::endl; using std::string; @@ -52,7 +52,7 @@ string SurfaceCollection::getSkinFilePath(const string &file) { void SurfaceCollection::debug() { SurfaceHash::iterator end = surfaces.end(); for(SurfaceHash::iterator curr = surfaces.begin(); curr != end; curr++){ - cout << "key: " << curr->first << endl; + DEBUG("key: %i\n", curr->first); } } @@ -67,9 +67,8 @@ Surface *SurfaceCollection::add(Surface *s, const string &path) { } Surface *SurfaceCollection::add(const string &path, bool alpha) { -#ifdef DEBUG - cout << "Adding surface: " << path << endl; -#endif + DEBUG("Adding surface: '%s'\n", path.c_str()); + if (exists(path)) del(path); string filePath = path; @@ -85,9 +84,7 @@ Surface *SurfaceCollection::add(const string &path, bool alpha) { } Surface *SurfaceCollection::addSkinRes(const string &path, bool alpha) { -#ifdef DEBUG - cout << "Adding skin surface: " << path << endl; -#endif + DEBUG("Adding skin surface: '%s'\n", path.c_str()); if (path.empty()) return NULL; if (exists(path)) del(path); diff --git a/src/translator.cpp b/src/translator.cpp index 2b9de96..d1c5553 100644 --- a/src/translator.cpp +++ b/src/translator.cpp @@ -24,6 +24,7 @@ #include #include "translator.h" +#include "debug.h" using namespace std; @@ -66,9 +67,8 @@ string Translator::translate(const string &term,const char *replacestr,...) { if (i != translations.end()) { result = i->second; } - #ifdef DEBUG - else cout << "Untranslated string: " << term << endl; - #endif + + else WARNING("Untranslated string: '%s'\n", term.c_str()); } va_list arglist; diff --git a/src/utilities.cpp b/src/utilities.cpp index 88f3bf9..69e0387 100644 --- a/src/utilities.cpp +++ b/src/utilities.cpp @@ -29,6 +29,7 @@ #include #include "utilities.h" +#include "debug.h" using namespace std; @@ -73,9 +74,7 @@ bool rmtree(string path) { struct dirent *dptr; string filepath; -#ifdef DEBUG - cout << "RMTREE: " << path << endl; -#endif + DEBUG("RMTREE: '%s'\n", path.c_str()); if ((dirp = opendir(path.c_str())) == NULL) return false; if (path[path.length()-1]!='/') path += "/"; diff --git a/src/wallpaperdialog.cpp b/src/wallpaperdialog.cpp index 2311d40..7f98e08 100644 --- a/src/wallpaperdialog.cpp +++ b/src/wallpaperdialog.cpp @@ -18,8 +18,11 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include + #include "wallpaperdialog.h" #include "filelister.h" +#include "debug.h" using namespace std; @@ -44,9 +47,8 @@ bool WallpaperDialog::exec() for (uint i=0; i