MapApplication.cpp 1.17 KB
Newer Older
1
#include "MapApplication.hpp"
Martin Kröning's avatar
Martin Kröning committed
2
#include <glibmm/i18n.h>
3
4
5
6
7
#include <glibmm/refptr.h>
#include <gtkmm/application.h>
#include <gtkmm/window.h>
#include <vector>

Martin Kröning's avatar
Martin Kröning committed
8
9
10
11
12
13
14
15
16
17
18
19
20
void MapApplication::initGettext() {
#ifdef G_OS_WIN32
  gchar *win32_dir = g_win32_get_package_installation_directory_of_module(NULL);
  bindtextdomain("pi2-view",
                 g_build_filename(win32_dir, "share", "locale", NULL));
  g_free(win32_dir);
#endif /* G_OS_WIN32 */

  bind_textdomain_codeset("pi2-view", "UTF-8");
}

Glib::RefPtr<Gtk::Application> MapApplication::application = []() {
  initGettext();
Martin Kröning's avatar
Martin Kröning committed
21
  return Gtk::Application::create("de.rwth_aachen.git.pi2.view");
Martin Kröning's avatar
Martin Kröning committed
22
}();
23
24
25
26
27
std::thread MapApplication::thread;

void MapApplication::addWindow(Gtk::Window &window) {
  if (application->get_windows().empty()) {
    thread = std::thread([&window]() {
Martin Kröning's avatar
Martin Kröning committed
28
      application = Gtk::Application::create("de.rwth_aachen.git.pi2.view");
29
30
31
32
33
34
35
36
37
38
39
40
41
42
      application->run(window);
    });
  } else {
    application->add_window(window);
    window.show();
  }
}

void MapApplication::removeWindow(Gtk::Window &window) {
  application->remove_window(window);
  if (thread.joinable() && application->get_windows().empty()) {
    thread.join();
  }
}