[glom] Use Gio::Resource::get_info_global().
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] Use Gio::Resource::get_info_global().
- Date: Sun, 16 Nov 2014 15:34:13 +0000 (UTC)
commit 3ec22eb2d3616d866feab7eee4962001b8270864
Author: Murray Cumming <murrayc murrayc com>
Date: Sun Nov 16 16:33:34 2014 +0100
Use Gio::Resource::get_info_global().
Instead of the C API.
glom/libglom/utils.cc | 14 ++++++++++++++
glom/libglom/utils.h | 7 +++++++
glom/libglom/xsl_utils.cc | 3 ++-
.../print_layouts/print_layout_toolbar_button.cc | 3 ++-
glom/utility_widgets/layouttoolbarbutton.cc | 3 ++-
5 files changed, 27 insertions(+), 3 deletions(-)
---
diff --git a/glom/libglom/utils.cc b/glom/libglom/utils.cc
index 417aefc..3560d53 100644
--- a/glom/libglom/utils.cc
+++ b/glom/libglom/utils.cc
@@ -26,6 +26,7 @@
#include <libglom/data_structure/glomconversions.h>
#include <giomm/file.h>
+#include <giomm/resource.h>
#include <glibmm/convert.h>
#include <glibmm/fileutils.h>
#include <glibmm/miscutils.h>
@@ -1569,4 +1570,17 @@ bool Utils::script_check_for_pygtk2(const Glib::ustring& script)
return true;
}
+bool Utils::get_resource_exists(const std::string& resource_path)
+{
+ try
+ {
+ Gio::Resource::get_info_global(resource_path);
+ return true;
+ }
+ catch (const Gio::ResourceError&)
+ {
+ return false;
+ }
+}
+
} //namespace Glom
diff --git a/glom/libglom/utils.h b/glom/libglom/utils.h
index fbaabff..27d54e0 100644
--- a/glom/libglom/utils.h
+++ b/glom/libglom/utils.h
@@ -248,6 +248,13 @@ Glib::ustring get_temp_directory_uri(const std::string& prefix = std::string());
*/
bool script_check_for_pygtk2(const Glib::ustring& script);
+/**
+ * This is simpler than catching the exception from Gio::Resource::get_info_global().
+ *
+ * @returns true if the GResource exists.
+ */
+bool get_resource_exists(const std::string& resource_path);
+
} //namespace Utils
} //namespace Glom
diff --git a/glom/libglom/xsl_utils.cc b/glom/libglom/xsl_utils.cc
index 739974c..595c92b 100644
--- a/glom/libglom/xsl_utils.cc
+++ b/glom/libglom/xsl_utils.cc
@@ -24,6 +24,7 @@
#include <libglom/connectionpool.h>
#include <libglom/data_structure/layout/report_parts/layoutitem_fieldsummary.h>
#include <libglom/data_structure/glomconversions.h>
+#include <libglom/utils.h>
#include <libxml++/libxml++.h>
#include <libxslt/transform.h>
//#include <libexslt/exslt.h> //For exsltRegisterAll().
@@ -47,7 +48,7 @@ namespace
static std::string get_xslt_filepath(const std::string& xsl_file)
{
const std::string resource_path = "/org/gnome/glom/libglom/data/xslt/" + xsl_file;
- if(!g_resources_get_info(resource_path.c_str(), G_RESOURCE_LOOKUP_FLAGS_NONE, 0, 0, 0))
+ if(!Glom::Utils::get_resource_exists(resource_path))
{
std::cerr << G_STRFUNC << ": xslt resource not found: " << resource_path << std::endl;
}
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 d1653e5..372cf12 100644
--- a/glom/mode_design/print_layouts/print_layout_toolbar_button.cc
+++ b/glom/mode_design/print_layouts/print_layout_toolbar_button.cc
@@ -20,6 +20,7 @@
#include "print_layout_toolbar_button.h"
#include <glom/utils_ui.h>
+#include <libglom/utils.h>
#include <gtkmm/toolpalette.h>
#include <iostream>
@@ -33,7 +34,7 @@ PrintLayoutToolbarButton::PrintLayoutToolbarButton(const std::string& icon_name,
Gtk::Image* image = Gtk::manage (new Gtk::Image());
const std::string resource_path = UiUtils::get_icon_path(icon_name);
- if(!g_resources_get_info(resource_path.c_str(), G_RESOURCE_LOOKUP_FLAGS_NONE, 0, 0, 0))
+ if(!Utils::get_resource_exists(resource_path))
{
std::cerr << G_STRFUNC << ": icon resource not found: " << resource_path << std::endl;
}
diff --git a/glom/utility_widgets/layouttoolbarbutton.cc b/glom/utility_widgets/layouttoolbarbutton.cc
index 44974ce..67ab349 100644
--- a/glom/utility_widgets/layouttoolbarbutton.cc
+++ b/glom/utility_widgets/layouttoolbarbutton.cc
@@ -20,6 +20,7 @@
#include "layouttoolbarbutton.h"
#include <glom/utils_ui.h>
+#include <libglom/utils.h>
#include <iostream>
namespace Glom
@@ -32,7 +33,7 @@ LayoutToolbarButton::LayoutToolbarButton(const std::string& icon_name, LayoutWid
Gtk::Image* image = Gtk::manage (new Gtk::Image());
const std::string resource_path = UiUtils::get_icon_path(icon_name);
- if(!g_resources_get_info(resource_path.c_str(), G_RESOURCE_LOOKUP_FLAGS_NONE, 0, 0, 0))
+ if(!Utils::get_resource_exists(resource_path))
{
std::cerr << G_STRFUNC << ": icon resource not found: " << resource_path << std::endl;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]