--- gigedit/trunk/src/gigedit/gigedit.cpp 2009/05/10 09:35:56 1898 +++ gigedit/trunk/src/gigedit/gigedit.cpp 2013/09/15 17:06:45 2471 @@ -19,12 +19,20 @@ #include "gigedit.h" -#include +#include #include +#include + #include "mainwindow.h" #include "global.h" +#ifdef __APPLE__ +#include +#include +#include +#endif + namespace { // State for a gigedit thread. @@ -48,22 +56,26 @@ class Cond { private: bool pred; - Glib::Mutex mutex; - Glib::Cond cond; + Glib::Threads::Mutex mutex; + Glib::Threads::Cond cond; public: Cond() : pred(false) { } void signal() { - Glib::Mutex::Lock lock(mutex); + Glib::Threads::Mutex::Lock lock(mutex); pred = true; cond.signal(); } void wait() { - Glib::Mutex::Lock lock(mutex); + Glib::Threads::Mutex::Lock lock(mutex); while (!pred) cond.wait(mutex); } }; +#ifdef OLD_THREADS static Glib::StaticMutex mutex; +#else + static Glib::Threads::Mutex mutex; +#endif static Glib::Dispatcher* dispatcher; static GigEditState* current; @@ -83,6 +95,10 @@ HINSTANCE gigedit_dll_handle = 0; #endif +#ifdef __APPLE__ +std::string gigedit_localedir; +#endif + void init_app() { static bool process_initialized = false; if (!process_initialized) { @@ -90,6 +106,45 @@ << std::flush; setlocale(LC_ALL, ""); +#ifdef __APPLE__ + // Look for pango.modules, gdk-pixbuf.loaders and locale files + // under the same dir as the gigedit dylib is installed in. + Dl_info info; + if (dladdr((void*)&init_app, &info)) { + std::string libdir = Glib::path_get_dirname(info.dli_fname); + + if (Glib::getenv("PANGO_SYSCONFDIR") == "" && + Glib::file_test(Glib::build_filename(libdir, + "pango/pango.modules"), + Glib::FILE_TEST_EXISTS)) { + Glib::setenv("PANGO_SYSCONFDIR", libdir, true); + } + if (Glib::getenv("GDK_PIXBUF_MODULE_FILE") == "") { + std::string module_file = + Glib::build_filename(libdir, + "gtk-2.0/gdk-pixbuf.loaders"); + if (Glib::file_test(module_file, Glib::FILE_TEST_EXISTS)) { + Glib::setenv("GDK_PIXBUF_MODULE_FILE", module_file, true); + } + } +#if HAVE_GETTEXT + std::string localedir = Glib::build_filename(libdir, "locale"); + if (Glib::file_test(localedir, Glib::FILE_TEST_EXISTS)) { + gigedit_localedir = localedir; + bindtextdomain(GETTEXT_PACKAGE, gigedit_localedir.c_str()); + } else { + bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); + } +#endif + } + + // The gtk file dialog stores its recent files state in + // ~/.local/share + g_mkdir_with_parents( + Glib::build_filename(Glib::get_home_dir(), + ".local/share").c_str(), 0777); +#endif + #if HAVE_GETTEXT #ifdef WIN32 @@ -106,16 +161,17 @@ g_free(temp); bindtextdomain(GETTEXT_PACKAGE, localedir); g_free(localedir); -#else +#elif !defined(__APPLE__) bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); #endif bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); textdomain(GETTEXT_PACKAGE); #endif // HAVE_GETTEXT +#ifdef OLD_THREADS // make sure thread_init() is called once and ONLY once per process if (!Glib::thread_supported()) Glib::thread_init(); - +#endif process_initialized = true; } } @@ -172,6 +228,16 @@ init_app(); Gtk::Main kit(argc, argv); + +#if HAVE_GETTEXT && defined(__APPLE__) + // Gtk::Main binds the gtk locale to a possible non-existent + // directory. If we have bundled gtk locale files, we rebind here, + // after the Gtk::Main constructor. + if (!gigedit_localedir.empty()) { + bindtextdomain("gtk20", gigedit_localedir.c_str()); + } +#endif + MainWindow window; connect_signals(this, &window); if (argc >= 2) window.load_file(argv[1]); @@ -249,7 +315,11 @@ return keyboard_key_released_signal; } +#ifdef OLD_THREADS Glib::StaticMutex GigEditState::mutex = GLIBMM_STATIC_MUTEX_INIT; +#else +Glib::Threads::Mutex GigEditState::mutex; +#endif Glib::Dispatcher* GigEditState::dispatcher = 0; GigEditState* GigEditState::current = 0; @@ -280,6 +350,11 @@ const char* argv_c[] = { "gigedit" }; char** argv = const_cast(argv_c); Gtk::Main main_loop(argc, argv); +#if HAVE_GETTEXT && defined(__APPLE__) + if (!gigedit_localedir.empty()) { + bindtextdomain("gtk20", gigedit_localedir.c_str()); + } +#endif dispatcher = new Glib::Dispatcher(); dispatcher->connect(sigc::ptr_fun(&GigEditState::open_window_static)); @@ -294,10 +369,16 @@ static bool main_loop_started = false; if (!main_loop_started) { Cond initialized; +#ifdef OLD_THREADS Glib::Thread::create( sigc::bind(sigc::ptr_fun(&GigEditState::main_loop_run), &initialized), false); +#else + Glib::Threads::Thread::create( + sigc::bind(sigc::ptr_fun(&GigEditState::main_loop_run), + &initialized)); +#endif initialized.wait(); main_loop_started = true; }