diff --git a/src/gmenu2x.cpp b/src/gmenu2x.cpp index 3fbc909..59df416 100644 --- a/src/gmenu2x.cpp +++ b/src/gmenu2x.cpp @@ -87,6 +87,7 @@ const char *CARD_ROOT = "/card/"; //Note: Add a trailing /! const int CARD_ROOT_LEN = 5; static GMenu2X *app; +static string gmenu2x_home; using namespace std; using namespace fastdelegate; @@ -121,6 +122,11 @@ static void quit_all(int err) { exit(err); } +const string GMenu2X::getHome(void) +{ + return gmenu2x_home; +} + int main(int /*argc*/, char * /*argv*/[]) { INFO("----\nGMenu2X starting: If you read this message in the logs, check http://gmenu2x.sourceforge.net/page/Troubleshooting for a solution\n----\n"); @@ -128,6 +134,20 @@ int main(int /*argc*/, char * /*argv*/[]) { signal(SIGSEGV,&quit_all); signal(SIGTERM,&quit_all); + char *home = getenv("HOME"); + if (home == NULL) { + ERROR("Unable to find gmenu2x home directory. The $HOME variable is not defined.\n"); + return 1; + } + + gmenu2x_home = (string)home + (string)"/.gmenu2x"; + if (!fileExists(gmenu2x_home) && mkdir(gmenu2x_home.c_str(), 0770) < 0) { + ERROR("Unable to create gmenu2x home directory.\n"); + return 1; + } + + DEBUG("Home path: %s.\n", gmenu2x_home.c_str()); + app = new GMenu2X(); DEBUG("Starting main()\n"); app->main(); diff --git a/src/gmenu2x.h b/src/gmenu2x.h index 013aebd..09dd5b1 100644 --- a/src/gmenu2x.h +++ b/src/gmenu2x.h @@ -155,6 +155,10 @@ public: ~GMenu2X(); void quit(); + /* Returns the home directory of gmenu2x, usually + * ~/.gmenu2x */ + static const string getHome(void); + /* * Variables needed for elements disposition */