/[svn]/gigedit/trunk/src/gigedit/gigedit.cpp
ViewVC logotype

Diff of /gigedit/trunk/src/gigedit/gigedit.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3021 by persson, Sun Oct 23 07:24:40 2016 UTC revision 3364 by schoenebeck, Tue Nov 14 18:07:25 2017 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2007-2015 Andreas Persson   * Copyright (C) 2007-2017 Andreas Persson
3   *   *
4   * This program is free software; you can redistribute it and/or   * This program is free software; you can redistribute it and/or
5   * modify it under the terms of the GNU General Public License as   * modify it under the terms of the GNU General Public License as
# Line 17  Line 17 
17   * 02110-1301 USA.   * 02110-1301 USA.
18   */   */
19    
20  #include <glibmmconfig.h>  #include "compat.h"
21  // threads.h must be included first to be able to build with  // threads.h must be included first to be able to build with
22  // G_DISABLE_DEPRECATED  // G_DISABLE_DEPRECATED
23  #if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION == 31 && GLIBMM_MICRO_VERSION >= 2) || \  #if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION == 31 && GLIBMM_MICRO_VERSION >= 2) || \
# Line 27  Line 27 
27    
28  #include "gigedit.h"  #include "gigedit.h"
29    
 #include <gtkmmconfig.h>  
30  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
31  #include <gdkmm/region.h>  #include <gdkmm/region.h>
32  #endif  #endif
33  #include <glibmm/dispatcher.h>  #include <glibmm/dispatcher.h>
34  #include <glibmm/main.h>  #include <glibmm/main.h>
35    #include <glibmm/miscutils.h>
36  #include <gtkmm/main.h>  #include <gtkmm/main.h>
37    
38    #ifdef WIN32
39    #include <gtkmm/icontheme.h>
40    #endif
41    
42  #if defined(__APPLE__)  #if defined(__APPLE__)
43  # include <CoreFoundation/CoreFoundation.h>  # include <CoreFoundation/CoreFoundation.h>
44  # include "MacHelper.h"  # include "MacHelper.h"
# Line 47  Line 51 
51  #ifdef __APPLE__  #ifdef __APPLE__
52  #include <dlfcn.h>  #include <dlfcn.h>
53  #include <glibmm/fileutils.h>  #include <glibmm/fileutils.h>
 #include <glibmm/miscutils.h>  
54  #endif  #endif
55    
56  //TODO: (hopefully) just a temporary nasty hack for launching gigedit on the main thread on Mac (see comments below in this file for details)  //TODO: (hopefully) just a temporary nasty hack for launching gigedit on the main thread on Mac (see comments below in this file for details)
# Line 123  private: Line 126  private:
126    
127  #ifdef WIN32  #ifdef WIN32
128  HINSTANCE gigedit_dll_handle = 0;  HINSTANCE gigedit_dll_handle = 0;
129    std::string gigedit_datadir;
130    bool gigedit_installdir_is_parent = false;
131  #endif  #endif
132    
133  #ifdef __APPLE__  #ifdef __APPLE__
# Line 141  void init_app() { Line 146  void init_app() {
146          // under the same dir as the gigedit dylib is installed in.          // under the same dir as the gigedit dylib is installed in.
147          Dl_info info;          Dl_info info;
148          if (dladdr((void*)&init_app, &info)) {          if (dladdr((void*)&init_app, &info)) {
149    #ifdef CONFIG_FORCE_GTK_LIBDIR
150                std::string libdir = CONFIG_FORCE_GTK_LIBDIR;
151    #else
152              std::string libdir = Glib::path_get_dirname(info.dli_fname);              std::string libdir = Glib::path_get_dirname(info.dli_fname);
153    #endif
154    
155              if (Glib::getenv("PANGO_SYSCONFDIR") == "" &&              if (Glib::getenv("PANGO_SYSCONFDIR") == "" &&
156                  Glib::file_test(Glib::build_filename(libdir,                  Glib::file_test(Glib::build_filename(libdir,
# Line 176  void init_app() { Line 185  void init_app() {
185                                   ".local/share").c_str(), 0777);                                   ".local/share").c_str(), 0777);
186  #endif // __APPLE__  #endif // __APPLE__
187    
188  //FIXME: for some reason AC GETTEXT check fails on the Mac cross compiler?  #ifdef WIN32
189  #if (HAVE_GETTEXT || defined(__APPLE__))          // Find the data directory: the linuxsampler installer puts
190            // the binaries in sub directories "32" and "64", so the share
191            // directory is located in the parent of the directory of the
192            // binaries.
193    
194    #ifdef WIN32    #if GLIB_CHECK_VERSION(2, 16, 0)
     #if GLIB_CHECK_VERSION(2, 16, 0)  
195          gchar* root =          gchar* root =
196              g_win32_get_package_installation_directory_of_module(gigedit_dll_handle);              g_win32_get_package_installation_directory_of_module(gigedit_dll_handle);
197      #else    #else
198          gchar* root =          gchar* root =
199              g_win32_get_package_installation_directory(NULL, NULL);              g_win32_get_package_installation_directory(NULL, NULL);
200      #endif    #endif
201          gchar* temp = g_build_filename(root, "/share/locale", NULL);          std::string installdir(root);
202          g_free(root);          g_free(root);
203          gchar* localedir = g_win32_locale_filename_from_utf8(temp);          std::string basename = Glib::path_get_basename(installdir);
204          g_free(temp);          if (basename == "32" || basename == "64") {
205                installdir = Glib::path_get_dirname(installdir);
206                gigedit_installdir_is_parent = true;
207            }
208            gigedit_datadir = Glib::build_filename(installdir, "share");
209    
210            // the file dialogs need glib-2.0/schemas/gschemas.compiled
211            if (gigedit_installdir_is_parent) {
212                Glib::setenv("GSETTINGS_SCHEMA_DIR",
213                             Glib::build_filename(gigedit_datadir,
214                                                  "glib-2.0/schemas"));
215            }
216    #endif
217    
218    //FIXME: for some reason AC GETTEXT check fails on the Mac cross compiler?
219    #if (HAVE_GETTEXT || defined(__APPLE__))
220      #ifdef WIN32
221            std::string temp = Glib::build_filename(gigedit_datadir, "locale");
222            gchar* localedir = g_win32_locale_filename_from_utf8(temp.c_str());
223          bindtextdomain(GETTEXT_PACKAGE, localedir);          bindtextdomain(GETTEXT_PACKAGE, localedir);
224          g_free(localedir);          g_free(localedir);
225    #elif !defined(__APPLE__)    #elif !defined(__APPLE__)
# Line 208  void init_app() { Line 237  void init_app() {
237      }      }
238  }  }
239    
240    void init_app_after_gtk_init() {
241    //FIXME: for some reason AC GETTEXT check fails on the Mac cross compiler?
242    #if (/*HAVE_GETTEXT &&*/ defined(__APPLE__))
243        // Gtk::Main binds the gtk locale to a possible non-existent
244        // directory. If we have bundled gtk locale files, we rebind here,
245        // after the Gtk::Main constructor.
246        if (!gigedit_localedir.empty()) {
247            bindtextdomain("gtk20", gigedit_localedir.c_str());
248        }
249    #endif
250    
251    #ifdef WIN32
252        if (gigedit_installdir_is_parent) {
253            std::string icon_dir = Glib::build_filename(gigedit_datadir, "icons");
254            Gtk::IconTheme::get_default()->append_search_path(icon_dir);
255        }
256    #endif
257    }
258    
259  void connect_signals(GigEdit* gigedit, MainWindow* mainwindow) {  void connect_signals(GigEdit* gigedit, MainWindow* mainwindow) {
260      // the signals of the "GigEdit" class are actually just proxies, that      // the signals of the "GigEdit" class are actually just proxies, that
261      // is they simply forward the signals of the internal classes to the      // is they simply forward the signals of the internal classes to the
# Line 268  GigEdit::GigEdit() { Line 316  GigEdit::GigEdit() {
316  int GigEdit::run(int argc, char* argv[]) {  int GigEdit::run(int argc, char* argv[]) {
317      init_app();      init_app();
318    
319    #if GTKMM_MAJOR_VERSION < 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION < 89 || (GTKMM_MINOR_VERSION == 89 && GTKMM_MICRO_VERSION < 4))) // GTKMM < 3.89.4
320      Gtk::Main kit(argc, argv);      Gtk::Main kit(argc, argv);
321    #else
322  //FIXME: for some reason AC GETTEXT check fails on the Mac cross compiler?      Glib::RefPtr<Gtk::Application> app =
323  #if (/*HAVE_GETTEXT &&*/ defined(__APPLE__))          Gtk::Application::create("org.linuxsampler.gigedit");
     // 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());  
     }  
324  #endif  #endif
325        init_app_after_gtk_init();
326    
327      MainWindow window;      MainWindow window;
328      connect_signals(this, &window);      connect_signals(this, &window);
329      if (argc >= 2) window.load_file(argv[1]);      if (argc >= 2) window.load_file(argv[1]);
330    #if GTKMM_MAJOR_VERSION < 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION < 89 || (GTKMM_MINOR_VERSION == 89 && GTKMM_MICRO_VERSION < 4))) // GTKMM < 3.89.4
331      kit.run(window);      kit.run(window);
332    #else
333        app->run(window, argc, argv);
334    #endif
335        
336      return 0;      return 0;
337  }  }
338    
# Line 399  void GigEditState::main_loop_run(Cond* i Line 448  void GigEditState::main_loop_run(Cond* i
448      int argc = 1;      int argc = 1;
449      const char* argv_c[] = { "gigedit" };      const char* argv_c[] = { "gigedit" };
450      char** argv = const_cast<char**>(argv_c);      char** argv = const_cast<char**>(argv_c);
451    #if GTKMM_MAJOR_VERSION < 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION < 89 || (GTKMM_MINOR_VERSION == 89 && GTKMM_MICRO_VERSION < 4))) // GTKMM < 3.89.4
452      Gtk::Main main_loop(argc, argv);      Gtk::Main main_loop(argc, argv);
 //FIXME: for some reason AC GETTEXT check fails on the Mac cross compiler?  
 #if (/*HAVE_GETTEXT &&*/ defined(__APPLE__))  
     if (!gigedit_localedir.empty()) {  
         bindtextdomain("gtk20", gigedit_localedir.c_str());  
     }  
453  #endif  #endif
454        init_app_after_gtk_init();
455    
456      dispatcher = new Glib::Dispatcher();      dispatcher = new Glib::Dispatcher();
457      dispatcher->connect(sigc::ptr_fun(&GigEditState::open_window_static));      dispatcher->connect(sigc::ptr_fun(&GigEditState::open_window_static));
458      initialized->signal();      initialized->signal();
459    
460    #if GTKMM_MAJOR_VERSION < 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION < 89 || (GTKMM_MINOR_VERSION == 89 && GTKMM_MICRO_VERSION < 4))) // GTKMM < 3.89.4
461      main_loop.run();      main_loop.run();
462    #else
463        Gtk::Main::run();
464    #endif
465  }  }
466    
467  #if defined(__APPLE__)  #if defined(__APPLE__)

Legend:
Removed from v.3021  
changed lines
  Added in v.3364

  ViewVC Help
Powered by ViewVC