[glom] Use toolpallete and about icons from a GResource instead of installing.



commit f79223fa7ebbb0cfc12c6a47366136de478d57cb
Author: Murray Cumming <murrayc murrayc com>
Date:   Tue Oct 22 11:13:40 2013 +0200

    Use toolpallete and about icons from a GResource instead of installing.
    
    * Makefile.am:
    * Makefile_glom.am: Put the ToolPalette and AboutDialog icons in
      a GResource instead of installing them. Some icons still need
      to be installed as icons for the application and the mime type.
    * icons/16x16/*.png: Move the toolpalette icons to icons/ as these
      were the only size ever used anyway.
    * glom/utils_ui.cc: get_icon_path(): Make this return the resource
      path instead of a file path.
    * glom/appwindow.cc: Load the about dialog icon from a resource
      instead of the filesystem.
    * glom/mode_design/print_layotus/print_layout_toolbar_button.cc:
    * glom/utility_widgets/layouttoolbarbutton.cc: Constructor:
      Load the icon from a resource instead of from the filesystem.

 Makefile.am                                        |   29 ++++++++++---------
 Makefile_glom.am                                   |   13 +++++++--
 glom/appwindow.cc                                  |   21 +++++++++++++-
 .../print_layouts/print_layout_toolbar_button.cc   |   14 +++++++++-
 glom/utility_widgets/layouttoolbarbutton.cc        |   14 +++++++++-
 glom/utils_ui.cc                                   |   10 +------
 icons/{16x16 => }/glom-button.png                  |  Bin 220 -> 220 bytes
 icons/{16x16 => }/glom-field.png                   |  Bin 128 -> 128 bytes
 icons/{16x16 => }/glom-group.png                   |  Bin 137 -> 137 bytes
 icons/glom-icons.gresource.xml                     |   22 +++++++++++++++
 icons/{16x16 => }/glom-image.png                   |  Bin 367 -> 367 bytes
 icons/{16x16 => }/glom-line-horizontal.png         |  Bin 610 -> 610 bytes
 icons/{16x16 => }/glom-line-vertical.png           |  Bin 615 -> 615 bytes
 icons/{16x16 => }/glom-notebook.png                |  Bin 166 -> 166 bytes
 icons/{16x16 => }/glom-related-records.png         |  Bin 221 -> 221 bytes
 icons/{16x16 => }/glom-text.png                    |  Bin 113 -> 113 bytes
 16 files changed, 93 insertions(+), 30 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 23e8d96..2980a2b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -190,9 +190,6 @@ appicon32dir = $(iconthemedir)/32x32/apps
 appicon48dir = $(iconthemedir)/48x48/apps
 appiconscdir = $(iconthemedir)/scalable/apps
 
-glom_defines += \
--DGLOM_ICONPATH=\""$(appicon24dir)/glom.png"\"
-
 dist_appicon16_DATA = icons/16x16/glom.png
 dist_appicon22_DATA = icons/22x22/glom.png
 dist_appicon24_DATA = icons/24x24/glom.png
@@ -202,17 +199,21 @@ dist_appiconsc_DATA = icons/scalable/glom.svg
 
 noinst_icons = icons/16x16/glom.svg icons/22x22/glom.svg icons/32x32/glom.svg icons/win32/glom.ico
 
-pixmapdir = $(pkgdatadir)/pixmaps
-dist_pixmap_DATA =                             \
-       icons/16x16/glom-button.png             \
-       icons/16x16/glom-field.png              \
-       icons/16x16/glom-group.png              \
-       icons/16x16/glom-image.png              \
-       icons/16x16/glom-line-horizontal.png    \
-       icons/16x16/glom-line-vertical.png      \
-       icons/16x16/glom-notebook.png           \
-       icons/16x16/glom-related-records.png    \
-       icons/16x16/glom-text.png
+# These icons are used for toolpalette buttons, and an about dialog:
+icons_for_resources = \
+       icons/glom-button.png           \
+       icons/glom-field.png            \
+       icons/glom-group.png            \
+       icons/glom-image.png            \
+       icons/glom-line-horizontal.png  \
+       icons/glom-line-vertical.png    \
+       icons/glom-notebook.png         \
+       icons/glom-related-records.png  \
+       icons/glom-text.png \
+       icons/48x48/glom.png
+
+EXTRA_DIST += $(icons_for_resources)
+
 
 desktopdir = $(datadir)/applications
 
diff --git a/Makefile_glom.am b/Makefile_glom.am
index 4eae916..9da5182 100644
--- a/Makefile_glom.am
+++ b/Makefile_glom.am
@@ -36,15 +36,22 @@ ui/glom-ui-resources.c: $(glom_ui_resource_file) $(shell $(GLIB_COMPILE_RESOURCE
        $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate-source 
$(glom_ui_resource_file)
 
 # Generate the GResource source file for example .glom files:
-# TODO: Do not use all .glade files in the client-only build.
 glom_examples_resource_file = examples/glom-examples.gresource.xml
 BUILT_SOURCES += examples/glom-examples-resources.c
 examples/glom-examples-resources.c: $(glom_examples_resource_file) $(shell $(GLIB_COMPILE_RESOURCES) 
--generate-dependencies $(glom_examples_resource_file))
        $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate-source 
$(glom_examples_resource_file)
 
+# Generate the GResource source file for icon files:
+glom_icons_resource_file = icons/glom-icons.gresource.xml
+BUILT_SOURCES += icons/glom-icons-resources.c
+icons/glom-icons-resources.c: $(glom_icons_resource_file) $(shell $(GLIB_COMPILE_RESOURCES) 
--generate-dependencies $(glom_icons_resource_file))
+       $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate-source 
$(glom_icons_resource_file)
+
 EXTRA_DIST = \
-       $(glom_ui_resource_file)\
-       $(glom_examples_resource_file)
+       $(glom_ui_resource_file) \
+       $(glom_examples_resource_file) \
+       $(glom_icons_resource_file)
+
 
 glom_eggspreadtable_files =  \
   glom/utility_widgets/eggspreadtable/eggmarshalers.c \
diff --git a/glom/appwindow.cc b/glom/appwindow.cc
index aa2b22d..56316a4 100644
--- a/glom/appwindow.cc
+++ b/glom/appwindow.cc
@@ -464,11 +464,28 @@ void AppWindow::on_menu_help_about()
     vecAuthors.push_back("Murray Cumming <murrayc murrayc com>");
     m_pAbout->set_authors(vecAuthors);
     
-    Glib::RefPtr<Gdk::Pixbuf> logo = Gdk::Pixbuf::create_from_file(GLOM_ICONPATH);
+    //For some reason this use of the resource:// syntax does not work:
+    const char* about_icon_name = "48x48/glom.png";
+    //const Glib::ustring glom_icon_path = "resource://" + Utils::get_icon_path(about_icon_name);
+    //Glib::RefPtr<Gdk::Pixbuf> logo = Gdk::Pixbuf::create_from_file(glom_icon_path);
+
+    const Glib::ustring glom_icon_path = Utils::get_icon_path(about_icon_name);
+
+    //TODO: Use this, instead of the C API, when we can depend on gtkmm 3.12, with a try/catch:
+    //Glib::RefPtr<Gdk::Pixbuf> logo = Gdk::Pixbuf::create_from_resource(glom_icon_path);
+    GError* gerror = 0;
+    Glib::RefPtr<Gdk::Pixbuf> logo =
+      Glib::wrap(gdk_pixbuf_new_from_resource(glom_icon_path.c_str(), &gerror));
+    if(gerror)
+    {
+      std::cerr << G_STRFUNC << ": Could not load icon from resource path=" << glom_icon_path << std::endl;
+      g_clear_error(&gerror);
+    }
+
     if(logo)
       m_pAbout->set_logo(logo);
     else
-      std::cout << G_STRFUNC << ": Could not load icon from path=" << GLOM_ICONPATH << std::endl;
+      std::cout << G_STRFUNC << ": Could not load icon from resource path=" << glom_icon_path << std::endl;
 
     m_pAbout->signal_hide().connect( sigc::mem_fun(*this, &AppWindow::on_about_close) );
     m_bAboutShown = true;
diff --git a/glom/mode_design/print_layouts/print_layout_toolbar_button.cc 
b/glom/mode_design/print_layouts/print_layout_toolbar_button.cc
index 4eb652c..3c52280 100644
--- a/glom/mode_design/print_layouts/print_layout_toolbar_button.cc
+++ b/glom/mode_design/print_layouts/print_layout_toolbar_button.cc
@@ -28,8 +28,20 @@ namespace Glom
 
 PrintLayoutToolbarButton::PrintLayoutToolbarButton(const std::string& icon_name, enumItems type,
                                          const Glib::ustring& title, const Glib::ustring& tooltip)
-: Gtk::ToolButton( *(Gtk::manage (new Gtk::Image(Utils::get_icon_path(icon_name)))) )
+: Gtk::ToolButton()
 {
+  Gtk::Image* image = Gtk::manage (new Gtk::Image());
+
+  const std::string resource_path = Utils::get_icon_path(icon_name);
+  if(!g_resources_get_info(resource_path.c_str(), G_RESOURCE_LOOKUP_FLAGS_NONE, 0, 0, 0))
+  {
+    std::cerr << G_STRFUNC << ": icon resource not found: " << resource_path << std::endl;
+  }
+
+  image->set_from_resource(resource_path);
+  set_icon_widget(*image);
+
+
   m_type = type;
   g_object_set_data(G_OBJECT(gobj()), "glom-type", GINT_TO_POINTER(type));
 
diff --git a/glom/utility_widgets/layouttoolbarbutton.cc b/glom/utility_widgets/layouttoolbarbutton.cc
index 2af45fd..653f66b 100644
--- a/glom/utility_widgets/layouttoolbarbutton.cc
+++ b/glom/utility_widgets/layouttoolbarbutton.cc
@@ -20,14 +20,26 @@
 
 #include "layouttoolbarbutton.h"
 #include <glom/utils_ui.h>
+#include <iostream>
 
 namespace Glom
 {
 
 LayoutToolbarButton::LayoutToolbarButton(const std::string& icon_name, LayoutWidgetBase::enumType type,
                                          const Glib::ustring& title, const Glib::ustring& tooltip)
-: Gtk::ToolButton( *(Gtk::manage (new Gtk::Image(Utils::get_icon_path(icon_name)))) )
+: Gtk::ToolButton()
 {
+  Gtk::Image* image = Gtk::manage (new Gtk::Image());
+
+  const std::string resource_path = Utils::get_icon_path(icon_name);
+  if(!g_resources_get_info(resource_path.c_str(), G_RESOURCE_LOOKUP_FLAGS_NONE, 0, 0, 0))
+  {
+    std::cerr << G_STRFUNC << ": icon resource not found: " << resource_path << std::endl;
+  }
+
+  image->set_from_resource(resource_path);
+  set_icon_widget(*image);
+
   m_type = type;
   g_object_set_data(G_OBJECT(gobj()), "glom-type", GINT_TO_POINTER(type));
 
diff --git a/glom/utils_ui.cc b/glom/utils_ui.cc
index b981004..909b5d7 100644
--- a/glom/utils_ui.cc
+++ b/glom/utils_ui.cc
@@ -522,15 +522,7 @@ void Utils::show_report_in_browser(const std::string& filepath, Gtk::Window* par
 
 std::string Utils::get_icon_path(const Glib::ustring& filename)
 {
-#ifdef G_OS_WIN32
-  gchar* basepath = g_win32_get_package_installation_directory_of_module(0);
-  const std::string result = Glib::build_filename(Glib::build_filename(basepath,
-      "share" G_DIR_SEPARATOR_S "glom" G_DIR_SEPARATOR_S "pixmaps"), filename);
-  g_free(basepath);
-  return result;
-#else
-  return Glib::build_filename(GLOM_PKGDATADIR G_DIR_SEPARATOR_S "pixmaps", filename);
-#endif
+  return  "/org/gnome/glom/icons/" + filename;
 }
 
 bool Utils::script_check_for_pygtk2_with_warning(const Glib::ustring& script, Gtk::Window* parent_window)
diff --git a/icons/glom-icons.gresource.xml b/icons/glom-icons.gresource.xml
new file mode 100644
index 0000000..1eedf8d
--- /dev/null
+++ b/icons/glom-icons.gresource.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/gnome/glom">
+    <file>icons/glom-button.png</file>
+    <file>icons/glom-field.png</file>
+    <file>icons/glom-group.png</file>
+    <file>icons/glom-image.png</file>
+    <file>icons/glom-line-horizontal.png</file>
+    <file>icons/glom-line-vertical.png</file>
+    <file>icons/glom-notebook.png</file>
+    <file>icons/glom-related-records.png</file>
+    <file>icons/glom-text.png</file>
+    <file>icons/48x48/glom.png</file>
+  </gresource>
+</gresources>
+
+
+
+
+ 
+
+


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]