|
|
|
@ -19,6 +19,7 @@ |
|
|
|
#include <boost/algorithm/string/predicate.hpp> |
|
|
|
#include <boost/algorithm/string/predicate.hpp> |
|
|
|
#include <boost/filesystem.hpp> |
|
|
|
#include <boost/filesystem.hpp> |
|
|
|
#include <boost/locale.hpp> |
|
|
|
#include <boost/locale.hpp> |
|
|
|
|
|
|
|
namespace bf = boost::filesystem; |
|
|
|
|
|
|
|
|
|
|
|
#ifdef __APPLE__ |
|
|
|
#ifdef __APPLE__ |
|
|
|
#undef ENABLE_NLS |
|
|
|
#undef ENABLE_NLS |
|
|
|
@ -26,8 +27,6 @@ |
|
|
|
|
|
|
|
|
|
|
|
namespace bf = boost::filesystem; |
|
|
|
namespace bf = boost::filesystem; |
|
|
|
|
|
|
|
|
|
|
|
#include <string> |
|
|
|
|
|
|
|
using std::string; |
|
|
|
|
|
|
|
#include <iostream> |
|
|
|
#include <iostream> |
|
|
|
using std::cout; |
|
|
|
using std::cout; |
|
|
|
using std::cerr; |
|
|
|
using std::cerr; |
|
|
|
@ -45,7 +44,7 @@ XournalMain::~XournalMain() |
|
|
|
XOJ_RELEASE_TYPE(XournalMain); |
|
|
|
XOJ_RELEASE_TYPE(XournalMain); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//it HAS to be done – otherwise such things like boost::algorithm::to_lower wont work, throwing casting exceptions
|
|
|
|
// it HAS to be done – otherwise such things like boost::algorithm::to_lower wont work, throwing casting exceptions
|
|
|
|
void XournalMain::initLocalisation() |
|
|
|
void XournalMain::initLocalisation() |
|
|
|
{ |
|
|
|
{ |
|
|
|
XOJ_CHECK_TYPE(XournalMain); |
|
|
|
XOJ_CHECK_TYPE(XournalMain); |
|
|
|
@ -60,7 +59,7 @@ void XournalMain::initLocalisation() |
|
|
|
textdomain(GETTEXT_PACKAGE); |
|
|
|
textdomain(GETTEXT_PACKAGE); |
|
|
|
#endif //ENABLE_NLS
|
|
|
|
#endif //ENABLE_NLS
|
|
|
|
|
|
|
|
|
|
|
|
std::locale::global(gen("")); //"" - system default locale
|
|
|
|
std::locale::global(gen("")); // "" - system default locale
|
|
|
|
std::cout.imbue(std::locale()); |
|
|
|
std::cout.imbue(std::locale()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -256,7 +255,10 @@ int XournalMain::run(int argc, char* argv[]) |
|
|
|
// Init GTK Display
|
|
|
|
// Init GTK Display
|
|
|
|
gdk_display_open_default_libgtk_only(); |
|
|
|
gdk_display_open_default_libgtk_only(); |
|
|
|
|
|
|
|
|
|
|
|
GladeSearchpath* gladePath = initPath(argv[0]); |
|
|
|
initSettingsPath(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GladeSearchpath* gladePath = new GladeSearchpath(); |
|
|
|
|
|
|
|
initResourcePath(gladePath); |
|
|
|
|
|
|
|
|
|
|
|
// init singleton
|
|
|
|
// init singleton
|
|
|
|
string colorNameFile = Util::getConfigFile("colornames.ini").string(); |
|
|
|
string colorNameFile = Util::getConfigFile("colornames.ini").string(); |
|
|
|
@ -327,63 +329,92 @@ int XournalMain::run(int argc, char* argv[]) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#define GLADE_UI_PATH "ui" |
|
|
|
void XournalMain::initSettingsPath() |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Path for glade files and Pixmaps, first searches in the home folder, so you can customize glade files |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
GladeSearchpath* XournalMain::initPath(const char* argv0) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
XOJ_CHECK_TYPE(XournalMain); |
|
|
|
XOJ_CHECK_TYPE(XournalMain); |
|
|
|
|
|
|
|
|
|
|
|
GladeSearchpath* gladePath = new GladeSearchpath(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create config directory if not exists
|
|
|
|
// Create config directory if not exists
|
|
|
|
path file = Util::getConfigSubfolder(""); |
|
|
|
path file = Util::getConfigSubfolder(""); |
|
|
|
bf::create_directories(file); |
|
|
|
bf::create_directories(file); |
|
|
|
bf::permissions(file, bf::perms::owner_all); |
|
|
|
bf::permissions(file, bf::perms::owner_all); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Add first home dir to search path, to add custom glade XMLs
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Find a file in a resource folder, and return the resource folder path |
|
|
|
|
|
|
|
* Return an empty string, if the folder was not found |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
string XournalMain::findResourcePath(string searchFile) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
XOJ_CHECK_TYPE(XournalMain); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// First check if the files are available relative to the executable
|
|
|
|
|
|
|
|
// So a "portable" installation will be possible
|
|
|
|
|
|
|
|
path relative1 = searchFile; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (bf::exists(relative1)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
path searchPath = Util::getConfigSubfolder("ui"); |
|
|
|
return relative1.parent_path().string(); |
|
|
|
if (bf::exists(searchPath) && bf::is_directory(searchPath)) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check if we are in the "build" directory, and therefore the resources
|
|
|
|
|
|
|
|
// are installed two folders back
|
|
|
|
|
|
|
|
path relative2 = "../.."; |
|
|
|
|
|
|
|
relative2 /= searchFile; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (bf::exists(relative2)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return relative2.string(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check if the files are in the current working directory
|
|
|
|
|
|
|
|
char buffer[512] = { 0 }; |
|
|
|
|
|
|
|
char* workingDir = getcwd(buffer, sizeof(buffer)); |
|
|
|
|
|
|
|
if (workingDir != NULL) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
path relative3 = workingDir; |
|
|
|
|
|
|
|
relative3 /= searchFile; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (bf::exists(relative3)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
gladePath->addSearchDirectory(searchPath.c_str()); |
|
|
|
return relative3.string(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
gchar* path = g_path_get_dirname(argv0); |
|
|
|
// Not found
|
|
|
|
gchar* searchPath = g_build_filename(path, GLADE_UI_PATH, NULL); |
|
|
|
return ""; |
|
|
|
gladePath->addSearchDirectory(searchPath); |
|
|
|
} |
|
|
|
g_free(searchPath); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
searchPath = g_build_filename(path, "..", GLADE_UI_PATH, NULL); |
|
|
|
void XournalMain::initResourcePath(GladeSearchpath* gladePath) |
|
|
|
gladePath->addSearchDirectory(searchPath); |
|
|
|
{ |
|
|
|
g_free(searchPath); |
|
|
|
XOJ_CHECK_TYPE(XournalMain); |
|
|
|
g_free(path); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char buffer[512] = { 0 }; |
|
|
|
string uiPath = findResourcePath("ui/about.glade"); |
|
|
|
path = getcwd(buffer, sizeof(buffer)); |
|
|
|
|
|
|
|
if (path == NULL) |
|
|
|
if (uiPath != "") |
|
|
|
{ |
|
|
|
{ |
|
|
|
return gladePath; |
|
|
|
gladePath->addSearchDirectory(uiPath); |
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
searchPath = g_build_filename(path, GLADE_UI_PATH, NULL); |
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
gladePath->addSearchDirectory(searchPath); |
|
|
|
|
|
|
|
g_free(searchPath); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
searchPath = g_build_filename(path, "..", GLADE_UI_PATH, NULL); |
|
|
|
// Check at the target installation directory
|
|
|
|
gladePath->addSearchDirectory(searchPath); |
|
|
|
path absolute = PACKAGE_DATA_DIR; |
|
|
|
g_free(searchPath); |
|
|
|
absolute /= PROJECT_PACKAGE; |
|
|
|
|
|
|
|
absolute /= "ui/about.glade"; |
|
|
|
searchPath = g_build_filename(PROJECT_SOURCE_DIR, GLADE_UI_PATH, NULL); |
|
|
|
|
|
|
|
gladePath->addSearchDirectory(searchPath); |
|
|
|
if (bf::exists(absolute)) |
|
|
|
g_free(searchPath); |
|
|
|
{ |
|
|
|
|
|
|
|
gladePath->addSearchDirectory(absolute.parent_path().string()); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
searchPath = g_build_filename(PACKAGE_DATA_DIR, PROJECT_PACKAGE, GLADE_UI_PATH, NULL); |
|
|
|
string msg = _("Missing the needed UI file, could not find them at any location.\nNot relative\nNot in the Working Path\nNot in " PACKAGE_DATA_DIR); |
|
|
|
gladePath->addSearchDirectory(searchPath); |
|
|
|
Util::showErrorToUser(NULL, msg.c_str()); |
|
|
|
g_free(searchPath); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return gladePath; |
|
|
|
exit(12); |
|
|
|
} |
|
|
|
} |
|
|
|
|