22 #include <libgtkcrnmm_config.h>
40 using namespace GtkCRN;
48 bool Main::init_done(
false);
50 Main::Main(
int &argc,
char **&argv):
51 #ifdef CRN_USING_GTKMM3
52 Gtk::Application(argc, argv)
54 Gtk::
Main(argc, argv),
55 iconfac(Gtk::IconFactory::create())
61 if (!Glib::thread_supported())
68 char *loc = getenv(
"LANG");
69 CRNdout << GETTEXT_PACKAGE <<
" LANG environment var: " << (loc ==
nullptr ?
"none" : loc) << std::endl;
71 #if !defined(CRN_USING_GLIB_INTL) && !defined(CRN_USING_LIBINTL)
72 loc = setlocale(LC_ALL,
"C");
74 loc = setlocale(LC_ALL,
"");
77 CRNdout << GETTEXT_PACKAGE <<
" setlocale failed" << std::endl;
79 CRNdout << GETTEXT_PACKAGE <<
" locale = " << loc << std::endl;
81 CRNdout << GETTEXT_PACKAGE <<
" gettext package = " << GETTEXT_PACKAGE << std::endl;
83 CRNdout <<
"setting path to " << Config::GetLocalePath().CStr() << std::endl;
86 CRNdout << GETTEXT_PACKAGE <<
" no bound path. should be " << Config::GetLocalePath().CStr() << std::endl;
88 CRNdout << GETTEXT_PACKAGE <<
" path = " << loc << std::endl;
91 CRNdout << GETTEXT_PACKAGE <<
" no bound codeset. should be " <<
"UTF-8" << std::endl;
93 CRNdout << GETTEXT_PACKAGE <<
" Codeset = " << loc << std::endl;
96 CRNdout << GETTEXT_PACKAGE <<
" textdomain failed" << std::endl;
98 CRNdout << GETTEXT_PACKAGE <<
" text domain = " << loc << std::endl;
100 CRNdout <<
_(
"Using default language.") << std::endl;
105 #ifdef CRN_USING_GTKMM3
109 struct {
const char *file;
const char *name;} iconlist[] =
111 {
"addblock.png",
"gtk-crn-add-block"},
112 {
"addview.png",
"gtk-crn-add-view"},
113 {
"block.png",
"gtk-crn-block"},
114 {
"document.png",
"gtk-crn-document"},
115 {
"eraser.png",
"gtk-crn-eraser"},
116 {
"even.png",
"gtk-crn-even"},
117 {
"eye.png",
"gtk-crn-eye"},
118 {
"filter.png",
"gtk-crn-filter"},
119 {
"find.png",
"gtk-crn-find"},
120 {
"find_from_file.png",
"gtk-crn-find-from-file"},
121 {
"findpencil.png",
"gtk-crn-findpencil"},
122 {
"image.png",
"gtk-crn-image"},
123 {
"inkpen.png",
"gtk-crn-inkpen"},
124 {
"invert.png",
"gtk-crn-invert"},
125 {
"key.png",
"gtk-crn-key"},
126 {
"keyboard.png",
"gtk-crn-keyboard"},
127 {
"lens.png",
"gtk-crn-lens"},
128 {
"line05.png",
"gtk-crn-line-0.5"},
129 {
"line1.png",
"gtk-crn-line-1"},
130 {
"line2.png",
"gtk-crn-line-2"},
131 {
"line3.png",
"gtk-crn-line-3"},
132 {
"log.png",
"gtk-crn-log"},
133 {
"merge.png",
"gtk-crn-merge"},
134 {
"mouse.png",
"gtk-crn-mouse"},
135 {
"odd.png",
"gtk-crn-odd"},
136 {
"paintbrush.png",
"gtk-crn-paintbrush"},
137 {
"pencil.png",
"gtk-crn-pencil"},
138 {
"remblock.png",
"gtk-crn-delete-block"},
139 {
"remview.png",
"gtk-crn-delete-view"},
140 {
"rotate_180.png",
"gtk-crn-rotate-180"},
141 {
"rotate_left.png",
"gtk-crn-rotate-left"},
142 {
"rotate_right.png",
"gtk-crn-rotate-right"},
143 {
"script.png",
"gtk-crn-script"},
144 {
"size_plus.png",
"gtk-crn-size-plus"},
145 {
"size_minus.png",
"gtk-crn-size-minus"},
146 {
"square1.png",
"gtk-crn-square-1"},
147 {
"square2.png",
"gtk-crn-square-2"},
148 {
"square3.png",
"gtk-crn-square-3"},
149 {
"square4.png",
"gtk-crn-square-4"},
150 {
"view.png",
"gtk-crn-view"},
151 {
"rgb.png",
"gtk-crn-rgb"},
152 {
"gray.png",
"gtk-crn-gray"},
153 {
"bw.png",
"gtk-crn-bw"},
154 {
"cmyk.png",
"gtk-crn-cmyk"},
155 {
"twopages.png",
"gtk-crn-two-pages"},
156 {
"paragraph.png",
"gtk-crn-paragraph"},
159 for (
size_t tmp = 0; tmp <
sizeof(iconlist) / (2 *
sizeof(
const char*)); tmp++)
163 Glib::RefPtr<Gdk::Pixbuf> pb = Gdk::Pixbuf::create_from_file((basedir + iconlist[tmp].file).CStr());
166 icons.push_back(Gtk::IconSet(pb));
167 iconfac->add(Gtk::StockID(iconlist[tmp].name), icons.back());
172 CRNError(
"libgtkcrnmm: Missing file: " + basedir + iconlist[tmp].file);
175 Glib::RefPtr<Gdk::Pixbuf> pb(Gdk::Pixbuf::create_from_inline(
sizeof(logo64), logo64));
178 icons.push_back(Gtk::IconSet(pb));
179 iconfac->add(Gtk::StockID(
"corenum-logo"), icons.back());
181 pb = Gdk::Pixbuf::create_from_inline(
sizeof(icon64), icon64);
184 icons.push_back(Gtk::IconSet(pb));
185 iconfac->add(Gtk::StockID(
"corenum-icon"), icons.back());
187 pb = Gdk::Pixbuf::create_from_inline(
sizeof(icon64circle), icon64circle);
190 icons.push_back(Gtk::IconSet(pb));
191 iconfac->add(Gtk::StockID(
"corenum-icon-circle"), icons.back());
193 iconfac->add_default();
194 Gtk::IconTheme::get_default()->append_search_path(Config::GetStaticDataPath().CStr());
200 #ifdef CRN_USING_GTKMM3
213 catch (std::exception &ex)
215 CRNdout << ex.what() << std::endl;
219 CRNdout <<
"unknown error" << std::endl;
221 #ifdef CRN_USING_GTKMM3
227 static void gtkcrnmmterminate()
235 const char *exname =
typeid(ex).name();
238 char *ret = abi::__cxa_demangle(exname,
nullptr,
nullptr, &status);
244 std::cerr <<
"Unhandled <" << exname <<
">: " << std::endl;
248 std::cerr <<
"what: " << ex.
what() << std::endl;
249 std::cerr <<
"context: " << ex.
GetContext().c_str() << std::endl;
251 catch (
const Glib::Exception &ex)
253 const char *exname =
typeid(ex).name();
256 char *ret = abi::__cxa_demangle(exname,
nullptr,
nullptr, &status);
262 std::cerr <<
"Unhandled <" << exname <<
">: " << std::endl;
266 std::cerr <<
"what: " << ex.what().c_str() << std::endl;
268 catch (
const std::exception &ex)
270 const char *exname =
typeid(ex).name();
273 char *ret = abi::__cxa_demangle(exname,
nullptr,
nullptr, &status);
279 std::cerr <<
"Unhandled <" << exname <<
">: " << std::endl;
283 std::cerr <<
"what: " << ex.what() << std::endl;
287 std::cerr <<
"Unexpected exception!" << std::endl;
295 Glib::add_exception_handler(sigc::ptr_fun(gtkcrnmmterminate));
static void SetDefaultExceptionHandler()
Sets the default exception handler to print message and context to the standard error.
const std::string & GetMessage() const noexcept
String containing a description of the exception.
void run_thread_safe()
Launches the application.
static char Separator() noexcept
Local directory separator.
char * CRNbindtextdomain(const char *, const char *)
const std::string & GetContext() const noexcept
String containing the call stack at the moment of throw.
A convenience class for file paths.
static void SetDefaultHandler()
Sets the default exception handler to print message and context to the standard error.
char * CRNtextdomain(const char *)
virtual const char * what() const noexceptoverride
String containing a description of the exception.
char * CRNbind_textdomain_codeset(const char *, const char *)
Base class for exceptions.