27 |
|
|
28 |
#include "global.h" |
#include "global.h" |
29 |
|
|
30 |
|
#ifdef __APPLE__ |
31 |
|
#include <dlfcn.h> |
32 |
|
#include <glibmm/fileutils.h> |
33 |
|
#include <glibmm/miscutils.h> |
34 |
|
#endif |
35 |
|
|
36 |
namespace { |
namespace { |
37 |
|
|
38 |
// State for a gigedit thread. |
// State for a gigedit thread. |
95 |
HINSTANCE gigedit_dll_handle = 0; |
HINSTANCE gigedit_dll_handle = 0; |
96 |
#endif |
#endif |
97 |
|
|
98 |
|
#ifdef __APPLE__ |
99 |
|
std::string gigedit_localedir; |
100 |
|
#endif |
101 |
|
|
102 |
void init_app() { |
void init_app() { |
103 |
static bool process_initialized = false; |
static bool process_initialized = false; |
104 |
if (!process_initialized) { |
if (!process_initialized) { |
106 |
<< std::flush; |
<< std::flush; |
107 |
setlocale(LC_ALL, ""); |
setlocale(LC_ALL, ""); |
108 |
|
|
109 |
|
#ifdef __APPLE__ |
110 |
|
// Look for pango.modules, gdk-pixbuf.loaders and locale files |
111 |
|
// under the same dir as the gigedit dylib is installed in. |
112 |
|
Dl_info info; |
113 |
|
if (dladdr((void*)&init_app, &info)) { |
114 |
|
std::string libdir = Glib::path_get_dirname(info.dli_fname); |
115 |
|
|
116 |
|
if (Glib::getenv("PANGO_SYSCONFDIR") == "" && |
117 |
|
Glib::file_test(Glib::build_filename(libdir, |
118 |
|
"pango/pango.modules"), |
119 |
|
Glib::FILE_TEST_EXISTS)) { |
120 |
|
Glib::setenv("PANGO_SYSCONFDIR", libdir, true); |
121 |
|
} |
122 |
|
if (Glib::getenv("GDK_PIXBUF_MODULE_FILE") == "") { |
123 |
|
std::string module_file = |
124 |
|
Glib::build_filename(libdir, |
125 |
|
"gtk-2.0/gdk-pixbuf.loaders"); |
126 |
|
if (Glib::file_test(module_file, Glib::FILE_TEST_EXISTS)) { |
127 |
|
Glib::setenv("GDK_PIXBUF_MODULE_FILE", module_file, true); |
128 |
|
} |
129 |
|
} |
130 |
|
#if HAVE_GETTEXT |
131 |
|
std::string localedir = Glib::build_filename(libdir, "locale"); |
132 |
|
if (Glib::file_test(localedir, Glib::FILE_TEST_EXISTS)) { |
133 |
|
gigedit_localedir = localedir; |
134 |
|
bindtextdomain(GETTEXT_PACKAGE, gigedit_localedir.c_str()); |
135 |
|
} else { |
136 |
|
bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); |
137 |
|
} |
138 |
|
#endif |
139 |
|
} |
140 |
|
|
141 |
|
// The gtk file dialog stores its recent files state in |
142 |
|
// ~/.local/share |
143 |
|
g_mkdir_with_parents( |
144 |
|
Glib::build_filename(Glib::get_home_dir(), |
145 |
|
".local/share").c_str(), 0777); |
146 |
|
#endif |
147 |
|
|
148 |
#if HAVE_GETTEXT |
#if HAVE_GETTEXT |
149 |
|
|
150 |
#ifdef WIN32 |
#ifdef WIN32 |
161 |
g_free(temp); |
g_free(temp); |
162 |
bindtextdomain(GETTEXT_PACKAGE, localedir); |
bindtextdomain(GETTEXT_PACKAGE, localedir); |
163 |
g_free(localedir); |
g_free(localedir); |
164 |
#else |
#elif !defined(__APPLE__) |
165 |
bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); |
bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); |
166 |
#endif |
#endif |
167 |
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); |
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); |
228 |
init_app(); |
init_app(); |
229 |
|
|
230 |
Gtk::Main kit(argc, argv); |
Gtk::Main kit(argc, argv); |
231 |
|
|
232 |
|
#ifdef __APPLE__ |
233 |
|
// Gtk::Main binds the gtk locale to a possible non-existent |
234 |
|
// directory. If we have bundled gtk locale files, we rebind here, |
235 |
|
// after the Gtk::Main constructor. |
236 |
|
if (!gigedit_localedir.empty()) { |
237 |
|
bindtextdomain("gtk20", gigedit_localedir.c_str()); |
238 |
|
} |
239 |
|
#endif |
240 |
|
|
241 |
MainWindow window; |
MainWindow window; |
242 |
connect_signals(this, &window); |
connect_signals(this, &window); |
243 |
if (argc >= 2) window.load_file(argv[1]); |
if (argc >= 2) window.load_file(argv[1]); |
350 |
const char* argv_c[] = { "gigedit" }; |
const char* argv_c[] = { "gigedit" }; |
351 |
char** argv = const_cast<char**>(argv_c); |
char** argv = const_cast<char**>(argv_c); |
352 |
Gtk::Main main_loop(argc, argv); |
Gtk::Main main_loop(argc, argv); |
353 |
|
#ifdef __APPLE__ |
354 |
|
if (!gigedit_localedir.empty()) { |
355 |
|
bindtextdomain("gtk20", gigedit_localedir.c_str()); |
356 |
|
} |
357 |
|
#endif |
358 |
|
|
359 |
dispatcher = new Glib::Dispatcher(); |
dispatcher = new Glib::Dispatcher(); |
360 |
dispatcher->connect(sigc::ptr_fun(&GigEditState::open_window_static)); |
dispatcher->connect(sigc::ptr_fun(&GigEditState::open_window_static)); |
369 |
static bool main_loop_started = false; |
static bool main_loop_started = false; |
370 |
if (!main_loop_started) { |
if (!main_loop_started) { |
371 |
Cond initialized; |
Cond initialized; |
372 |
Glib::Threads::Thread::create( |
#ifdef OLD_THREADS |
373 |
|
Glib::Thread::create( |
374 |
sigc::bind(sigc::ptr_fun(&GigEditState::main_loop_run), |
sigc::bind(sigc::ptr_fun(&GigEditState::main_loop_run), |
375 |
&initialized), |
&initialized), |
376 |
false); |
false); |
377 |
|
#else |
378 |
|
Glib::Threads::Thread::create( |
379 |
|
sigc::bind(sigc::ptr_fun(&GigEditState::main_loop_run), |
380 |
|
&initialized)); |
381 |
|
#endif |
382 |
initialized.wait(); |
initialized.wait(); |
383 |
main_loop_started = true; |
main_loop_started = true; |
384 |
} |
} |