diff options
| author | Alex Valavanis <valavanisalex@gmail.com> | 2016-08-09 11:32:55 +0000 |
|---|---|---|
| committer | Alex Valavanis <valavanisalex@gmail.com> | 2016-08-09 11:32:55 +0000 |
| commit | 5198e76ee434bd68985181d26900d71c1675cc63 (patch) | |
| tree | e8ce5a531a26a476da7204521b9ca0dc68336c52 | |
| parent | Merged gsoc work. Created better data structure for selections, replaced SPOb... (diff) | |
| download | inkscape-5198e76ee434bd68985181d26900d71c1675cc63.tar.gz inkscape-5198e76ee434bd68985181d26900d71c1675cc63.zip | |
Move some main functions to Application class
(bzr r15048)
| -rw-r--r-- | src/inkscape.cpp | 105 | ||||
| -rw-r--r-- | src/inkscape.h | 3 | ||||
| -rw-r--r-- | src/main.cpp | 104 |
3 files changed, 116 insertions, 96 deletions
diff --git a/src/inkscape.cpp b/src/inkscape.cpp index a88ef5947..48b921752 100644 --- a/src/inkscape.cpp +++ b/src/inkscape.cpp @@ -22,6 +22,10 @@ #include <map> +#include <glibmm/fileutils.h> + +#include <gtkmm/cssprovider.h> +#include <gtkmm/icontheme.h> #include <gtkmm/messagedialog.h> #include "debug/simple-event.h" #include "debug/event-tracker.h" @@ -57,6 +61,7 @@ #include "inkscape.h" #include "io/sys.h" #include "message-stack.h" +#include "path-prefix.h" #include "resource-manager.h" #include "ui/tools/tool-base.h" #include "ui/dialog/debug.h" @@ -379,6 +384,103 @@ void Application::argv0(char const* argv) _argv0 = g_strdup(argv); } +/** + * \brief Add our icon theme to the search path + */ +void +Application::add_icon_theme() +{ + // Get list of the possible folders containing the theme + auto dataDirs = Glib::get_system_data_dirs(); + dataDirs.insert(dataDirs.begin(), Glib::get_user_data_dir()); + + auto icon_theme = Gtk::IconTheme::get_default(); + + for (auto it : dataDirs) + { + std::vector<Glib::ustring> listing; + listing.push_back(it); + listing.push_back("inkscape"); + listing.push_back("icons"); + auto dir = Glib::build_filename(listing); + icon_theme->append_search_path(dir); + } + + // Add our icon directory to the search path for icon theme lookups. + auto const usericondir = Inkscape::Application::profile_path("icons"); + icon_theme->append_search_path(usericondir); + icon_theme->append_search_path(INKSCAPE_PIXMAPDIR); +#ifdef INKSCAPE_THEMEDIR + icon_theme->append_search_path(INKSCAPE_THEMEDIR); + icon_theme->rescan_if_needed(); +#endif + g_free(usericondir); +} + +/** + * \brief Add our CSS style sheets + */ +void +Application::add_style_sheet() +{ + // Add style sheet (GTK3) + auto const screen = Gdk::Screen::get_default(); + + Glib::ustring inkscape_style = INKSCAPE_UIDIR; + inkscape_style += "/style.css"; + // std::cout << "CSS Stylesheet Inkscape: " << inkscape_style << std::endl; + + if (Glib::file_test(inkscape_style, Glib::FILE_TEST_EXISTS)) { + auto provider = Gtk::CssProvider::create(); + + // From 3.16, throws an error which we must catch. + try { + provider->load_from_path (inkscape_style); + } +#if GTK_CHECK_VERSION(3,16,0) + // Gtk::CssProviderError not defined until 3.16. + catch (const Gtk::CssProviderError& ex) + { + std::cerr << "CSSProviderError::load_from_path(): failed to load: " << inkscape_style + << "\n (" << ex.what() << ")" << std::endl; + } +#else + catch (...) + {} +#endif + + Gtk::StyleContext::add_provider_for_screen (screen, provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + } else { + std::cerr << "sp_main_gui: Cannot find default style file:\n (" << inkscape_style + << ")" << std::endl; + } + + Glib::ustring user_style = Inkscape::Application::profile_path("ui/style.css"); + // std::cout << "CSS Stylesheet User: " << user_style << std::endl; + + if (Glib::file_test(user_style, Glib::FILE_TEST_EXISTS)) { + auto provider2 = Gtk::CssProvider::create(); + + // From 3.16, throws an error which we must catch. + try { + provider2->load_from_path (user_style); + } +#if GTK_CHECK_VERSION(3,16,0) + // Gtk::CssProviderError not defined until 3.16. + catch (const Gtk::CssProviderError& ex) + { + std::cerr << "CSSProviderError::load_from_path(): failed to load: " << user_style + << "\n (" << ex.what() << ")" << std::endl; + } +#else + catch (...) + {} +#endif + + Gtk::StyleContext::add_provider_for_screen (screen, provider2, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + } + +} /* \brief Constructor for the application. * Creates a new Inkscape::Application. * @@ -423,9 +525,12 @@ Application::Application(const char* argv, bool use_gui) : } if (use_gui) { + add_icon_theme(); + add_style_sheet(); load_menus(); Inkscape::DeviceManager::getManager().loadConfig(); } + Inkscape::ResourceManager::getManager(); /* set language for user interface according setting in preferences */ diff --git a/src/inkscape.h b/src/inkscape.h index fe424377c..3f4416f2f 100644 --- a/src/inkscape.h +++ b/src/inkscape.h @@ -205,6 +205,9 @@ private: Application& operator=(Application const&); // no assign Application* operator&() const; // no pointer access + void add_icon_theme(); + void add_style_sheet(); + Inkscape::XML::Document * _menus; std::map<SPDocument *, int> _document_set; std::map<SPDocument *, AppSelectionModel *> _selection_models; diff --git a/src/main.cpp b/src/main.cpp index 28bdf8359..28ae6992f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -46,7 +46,6 @@ #include <libxml/tree.h> -#include <gtkmm/cssprovider.h> #include <gdkmm/screen.h> #include "inkgc/gc-core.h" @@ -101,9 +100,12 @@ #endif // WITH_DBUS #include <glibmm/i18n.h> +#include <glibmm/convert.h> +#include <glibmm/fileutils.h> #include <glibmm/miscutils.h> #include <glibmm/main.h> #include <gtkmm/main.h> +#include <gtkmm/window.h> #ifndef HAVE_BIND_TEXTDOMAIN_CODESET #define bind_textdomain_codeset(p,c) @@ -851,8 +853,8 @@ static int sp_common_main( int argc, char const **argv, GSList **flDest ) // temporarily switch gettext encoding to locale, so that help messages can be output properly - gchar const *charset; - g_get_charset(&charset); + std::string charset; + Glib::get_charset(charset); bind_textdomain_codeset(GETTEXT_PACKAGE, charset); @@ -998,16 +1000,6 @@ snooper(GdkEvent *event, gpointer /*data*/) { gtk_main_do_event (event); } -static std::vector<Glib::ustring> getDirectorySet(const gchar* userDir, const gchar* const * systemDirs) { - std::vector<Glib::ustring> listing; - listing.push_back(userDir); - for ( const char* const* cur = systemDirs; *cur; cur++ ) - { - listing.push_back(*cur); - } - return listing; -} - int sp_main_gui(int argc, char const **argv) { @@ -1017,103 +1009,23 @@ sp_main_gui(int argc, char const **argv) int retVal = sp_common_main( argc, argv, &fl ); g_return_val_if_fail(retVal == 0, 1); - // Add possible icon entry directories - std::vector<Glib::ustring> dataDirs = getDirectorySet( g_get_user_data_dir(), - g_get_system_data_dirs() ); - for (std::vector<Glib::ustring>::iterator it = dataDirs.begin(); it != dataDirs.end(); ++it) - { - std::vector<Glib::ustring> listing; - listing.push_back(*it); - listing.push_back("inkscape"); - listing.push_back("icons"); - Glib::ustring dir = Glib::build_filename(listing); - gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(), dir.c_str()); - } - - // Add our icon directory to the search path for icon theme lookups. - gchar *usericondir = Inkscape::Application::profile_path("icons"); - gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(), usericondir); - gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(), INKSCAPE_PIXMAPDIR); -#ifdef INKSCAPE_THEMEDIR - gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(), INKSCAPE_THEMEDIR); - gtk_icon_theme_rescan_if_needed (gtk_icon_theme_get_default()); -#endif - g_free(usericondir); - - // Add style sheet (GTK3) - Glib::RefPtr<Gdk::Screen> screen = Gdk::Screen::get_default(); - - Glib::ustring inkscape_style = INKSCAPE_UIDIR; - inkscape_style += "/style.css"; - // std::cout << "CSS Stylesheet Inkscape: " << inkscape_style << std::endl; - - if (g_file_test (inkscape_style.c_str(), G_FILE_TEST_EXISTS)) { - Glib::RefPtr<Gtk::CssProvider> provider = Gtk::CssProvider::create(); - - // From 3.16, throws an error which we must catch. - try { - provider->load_from_path (inkscape_style); - } -#if GTK_CHECK_VERSION(3,16,0) - // Gtk::CssProviderError not defined until 3.16. - catch (const Gtk::CssProviderError& ex) - { - std::cerr << "CSSProviderError::load_from_path(): failed to load: " << inkscape_style - << "\n (" << ex.what() << ")" << std::endl; - } -#else - catch (...) - {} -#endif - - Gtk::StyleContext::add_provider_for_screen (screen, provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); - } else { - std::cerr << "sp_main_gui: Cannot find default style file:\n (" << inkscape_style - << ")" << std::endl; - } - - Glib::ustring user_style = Inkscape::Application::profile_path("ui/style.css"); - // std::cout << "CSS Stylesheet User: " << user_style << std::endl; - - if (g_file_test (user_style.c_str(), G_FILE_TEST_EXISTS)) { - Glib::RefPtr<Gtk::CssProvider> provider2 = Gtk::CssProvider::create(); - - // From 3.16, throws an error which we must catch. - try { - provider2->load_from_path (user_style); - } -#if GTK_CHECK_VERSION(3,16,0) - // Gtk::CssProviderError not defined until 3.16. - catch (const Gtk::CssProviderError& ex) - { - std::cerr << "CSSProviderError::load_from_path(): failed to load: " << user_style - << "\n (" << ex.what() << ")" << std::endl; - } -#else - catch (...) - {} -#endif - - Gtk::StyleContext::add_provider_for_screen (screen, provider2, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); - } - gdk_event_handler_set((GdkEventFunc)snooper, NULL, NULL); Inkscape::Debug::log_display_config(); // Set default window icon. Obeys the theme. - gtk_window_set_default_icon_name("inkscape"); + Gtk::Window::set_default_icon_name("inkscape"); // Do things that were previously in inkscape_gtk_stock_init(). sp_icon_get_phys_size(GTK_ICON_SIZE_MENU); Inkscape::UI::Widget::Panel::prep(); - gboolean create_new = TRUE; + bool create_new = true; /// \todo FIXME BROKEN - non-UTF-8 sneaks in here. Inkscape::Application::create(argv[0], true); while (fl) { if (sp_file_open((gchar *)fl->data,NULL)) { - create_new=FALSE; + create_new=false; } fl = g_slist_remove(fl, fl->data); } |
