[glibmm/glibmm-2-68] Gio::AppInfo::get_all(): Use a local TypeTraits in ListHandler
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm/glibmm-2-68] Gio::AppInfo::get_all(): Use a local TypeTraits in ListHandler
- Date: Thu, 29 Jul 2021 13:56:28 +0000 (UTC)
commit 58cbf4e0b4808fc75149fc1c9e6cf1e03018b32d
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date: Thu Jul 29 15:53:07 2021 +0200
Gio::AppInfo::get_all(): Use a local TypeTraits in ListHandler
Applies also to get_all_for_type().
Add and use struct TypeTraits_AppInfo, local in gio/src/appinfo.ccg
and appinfo.cc. It calls Glib::wrap(GAppInfo*, bool) which uses
Glib::wrap_auto_interface(). The partial specialization in
containerhandle_shared.h calls Glib::wrap_auto(), which is not acceptable
if the GAppInfo object does not already have a wrapper, and its class type
has not been wrapped in a C++ class (e.g. GWin32AppInfo or GOsxAppInfo).
Fixes #94
gio/src/appinfo.ccg | 29 +++++++++++++++++++++++++++++
gio/src/appinfo.hg | 2 +-
2 files changed, 30 insertions(+), 1 deletion(-)
---
diff --git a/gio/src/appinfo.ccg b/gio/src/appinfo.ccg
index 5c4a7170..b75af725 100644
--- a/gio/src/appinfo.ccg
+++ b/gio/src/appinfo.ccg
@@ -19,6 +19,35 @@
#include <giomm/slot_async.h>
#include <gio/gio.h>
+namespace
+{
+/* Special type traits for pointers to the GAppInfo interface.
+ * The partial specialization in glibmm/glib/glibmm/containerhandle_shared.h
+ * is not well suited for interfaces which do not already have a wrapper.
+ * Its to_cpp_type() calls Glib::wrap_auto() instead id Glib::wrap_auto_interface().
+ * These type traits are used by Glib::ListHandler<>::list_to_vector() in
+ * Gio::AppInfo::get_all() and Gio::AppInfo::get_all_for_type().
+ * https://gitlab.gnome.org/GNOME/glibmm/-/issues/94
+ */
+struct TypeTraits_AppInfo
+{
+ using T = Gio::AppInfo;
+ using CppType = Glib::RefPtr<T>;
+ using CType = typename T::BaseObjectType*;
+ using CTypeNonConst = typename T::BaseObjectType*;
+
+ static CType to_c_type(const CppType& ptr) { return Glib::unwrap(ptr); }
+ static CType to_c_type(CType ptr) { return ptr; }
+ static CppType to_cpp_type(CType ptr) { return Glib::wrap(ptr, true); }
+
+ static void release_c_type(CType ptr)
+ {
+ GLIBMM_DEBUG_UNREFERENCE(nullptr, ptr);
+ g_object_unref(ptr);
+ }
+};
+} // anonymous namespace
+
namespace Gio
{
diff --git a/gio/src/appinfo.hg b/gio/src/appinfo.hg
index ed7a6dc0..06d8d515 100644
--- a/gio/src/appinfo.hg
+++ b/gio/src/appinfo.hg
@@ -220,7 +220,7 @@ public:
_WRAP_METHOD(bool set_as_last_used_for_type(const std::string& content_type),
g_app_info_set_as_last_used_for_type, errthrow)
-#m4
_CONVERSION(`GList*',`std::vector<Glib::RefPtr<AppInfo>>',`Glib::ListHandler<Glib::RefPtr<AppInfo>>::list_to_vector($3,
Glib::OWNERSHIP_DEEP)')
+#m4 _CONVERSION(`GList*',`std::vector<Glib::RefPtr<AppInfo>>',`Glib::ListHandler<Glib::RefPtr<AppInfo>,
TypeTraits_AppInfo>::list_to_vector($3, Glib::OWNERSHIP_DEEP)')
_WRAP_METHOD(static std::vector<Glib::RefPtr<AppInfo>> get_all(), g_app_info_get_all)
_WRAP_METHOD(static std::vector<Glib::RefPtr<AppInfo>> get_all_for_type(const std::string& content_type),
g_app_info_get_all_for_type)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]