[gtkmm] RecentInfo: Correct get_application_info() so it can actually be used.



commit 6fcf354bd04eb85d465ca6479890aaffe1c93248
Author: Daniel Elstner <danielk openismus com>
Date:   Tue Aug 25 12:51:42 2009 +0200

    RecentInfo: Correct get_application_info() so it can actually be used.
    
    * gtk/src/recentinfo.[hg|ccg]: get_application_info(): Correct the
    app_exec parameter to a Glib::ustring& instead of a
    Glib::StringArrayHandle& app_exec. This method could not have been
    used before without crashing so this is not a real ABI break.
    equal(): Reimplement with _WRAP_METHOD() instead of hand-coding.
    get_applications(), get_length(): Make the implementations more robust
    by using the length parameter.
    
    Bug #590381

 ChangeLog              |   21 ++++++++++++-
 gtk/src/recentinfo.ccg |   34 +++++++++++++++------
 gtk/src/recentinfo.hg  |   77 ++++++++++++++++++++++++++++--------------------
 3 files changed, 89 insertions(+), 43 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 9a0853b..137ddb5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,23 @@
-2009-08-25  Murray Cumming  <murrayc murrayc-desktop>
+2009-08-25  Daniel Elstner  <danielk openismus com>
+
+	RecentInfo: Correct get_application_info() so it can actually be used.
+
+	* gtk/src/recentinfo.[hg|ccg]: get_application_info(): Correct the 
+	app_exec parameter to a Glib::ustring& instead of a 
+	Glib::StringArrayHandle& app_exec. This method could not have been 
+	used before without crashing so this is not a real ABI break.
+	equal(): Reimplement with _WRAP_METHOD() instead of hand-coding.
+	get_applications(), get_length(): Make the implementations more robust 
+	by using the length parameter.
+
+	Bug #590381
+
+The proper prototype would have been something much simpler:
+
+  bool get_application_info(const Glib::ustring& app_name,
+                            std::string& app_exec
+
+2009-08-25  Murray Cumming  <murrayc murrayc com>
 
 	Regenerated C documentation XML and wrapped some new API.
 
diff --git a/gtk/src/recentinfo.ccg b/gtk/src/recentinfo.ccg
index 2ceca8d..a536c6f 100644
--- a/gtk/src/recentinfo.ccg
+++ b/gtk/src/recentinfo.ccg
@@ -20,12 +20,6 @@
 namespace Gtk
 {
 
-bool RecentInfo::equal(const RecentInfo& other) const
-{
-  return (static_cast<bool>(gtk_recent_info_match(const_cast<GtkRecentInfo*>(this->gobj()),
-                                                  const_cast<GtkRecentInfo*>(other.gobj()))));
-}
-
 RecentInfo::operator bool() const
 {
   return gobj() != 0;
@@ -33,14 +27,34 @@ RecentInfo::operator bool() const
 
 Glib::StringArrayHandle RecentInfo::get_applications() const
 {
-  //We pass 0 for the length output argument, because we don't need it, because the returned array is null-terminated.
-  return Glib::StringArrayHandle(gtk_recent_info_get_applications(const_cast<GtkRecentInfo*>(this->gobj()), 0));
+  gsize length = 0;
+  char** const applications =
+    gtk_recent_info_get_applications(const_cast<GtkRecentInfo*>(gobj()), &length);
+
+  return Glib::StringArrayHandle(applications, length, Glib::OWNERSHIP_DEEP);
+}
+
+bool RecentInfo::get_application_info(const Glib::ustring& app_name, std::string& app_exec,
+                                      guint& count, time_t& time_) const
+{
+  const char* app_exec_cstr = 0;
+  const int found = gtk_recent_info_get_application_info(
+      const_cast<GtkRecentInfo*>(gobj()), app_name.c_str(), &app_exec_cstr, &count, &time_);
+
+  if (app_exec_cstr)
+    app_exec = app_exec_cstr;
+  else
+    app_exec.erase();
+
+  return (found != 0);
 }
 
 Glib::StringArrayHandle RecentInfo::get_groups() const
 {
-  //We pass 0 for the length output argument, because we don't need it, because the returned array is null-terminated.
-  return Glib::StringArrayHandle(gtk_recent_info_get_groups(const_cast<GtkRecentInfo*>(this->gobj()), 0));
+  gsize length = 0;
+  char** const groups = gtk_recent_info_get_groups(const_cast<GtkRecentInfo*>(gobj()), &length);
+
+  return Glib::StringArrayHandle(groups, length, Glib::OWNERSHIP_DEEP);
 }
 
 RecentInfoTraits::CppType RecentInfoTraits::to_cpp_type(const CType& obj)
diff --git a/gtk/src/recentinfo.hg b/gtk/src/recentinfo.hg
index b444bca..8d36ca6 100644
--- a/gtk/src/recentinfo.hg
+++ b/gtk/src/recentinfo.hg
@@ -16,19 +16,21 @@
  */
 
 #include <gdkmm/pixbuf.h>
-
-#include <time.h>
+#include <ctime>
 
 _DEFS(gtkmm,gtk)
 
 #ifndef DOXYGEN_SHOULD_SKIP_THIS
+extern "C"
+{
 typedef struct _GtkRecentInfo GtkRecentInfo;
-#endif //DOXYGEN_SHOULD_SKIP_THIS
+void gtk_recent_info_unref(GtkRecentInfo* info);
+}
+#endif /* !DOXYGEN_SHOULD_SKIP_THIS */
 
 namespace Gtk
 {
 
-
 /** Contains informations found when looking up an entry of the
  * recently used files list.
  *
@@ -42,48 +44,59 @@ class RecentInfo
   _IGNORE(gtk_recent_info_ref, gtk_recent_info_unref)
 public:
 
-  bool equal(const RecentInfo& other) const;
+
+//TODO: Deprecate this? Why? Document the deprecation.
+//#ifndef DOXYGEN_SHOULD_SKIP_THIS
+//# if (!defined(GTKMM_DISABLE_DEPRECATED) || defined(GTKMM_COMPILATION))
   /// Tests whether the RecentInfo is valid.
   operator bool() const;
+//# endif
+//#endif
 
   _WRAP_METHOD(Glib::ustring get_uri() const, gtk_recent_info_get_uri)
   _WRAP_METHOD(Glib::ustring get_display_name() const, gtk_recent_info_get_display_name)
   _WRAP_METHOD(Glib::ustring get_description() const, gtk_recent_info_get_description)
   _WRAP_METHOD(Glib::ustring get_mime_type() const, gtk_recent_info_get_mime_type)
-  
+
   _WRAP_METHOD(time_t get_added() const, gtk_recent_info_get_added)
   _WRAP_METHOD(time_t get_modified() const, gtk_recent_info_get_modified)
   _WRAP_METHOD(time_t get_visited() const, gtk_recent_info_get_visited)
-  
+
   _WRAP_METHOD(bool get_private_hint() const, gtk_recent_info_get_private_hint)
 
-  _WRAP_METHOD(bool get_application_info(const Glib::ustring& app_name, Glib::StringArrayHandle& app_exec, guint& count, time_t& time) const, gtk_recent_info_get_application_info)
+  _WRAP_METHOD_DOCS_ONLY(gtk_recent_info_get_application_info)
+  bool get_application_info(const Glib::ustring& app_name, std::string& app_exec,
+                            guint& count, time_t& time_) const;
+
+  _WRAP_METHOD_DOCS_ONLY(gtk_recent_info_get_applications)
   Glib::StringArrayHandle get_applications() const;
-  _IGNORE(gtk_recent_info_get_applications)
-  //_WRAP_METHOD(Glib::StringArrayHandle get_applications(unsigned& length) const, gtk_recent_info_get_applications)
+
   _WRAP_METHOD(Glib::ustring last_application() const, gtk_recent_info_last_application)
-  _WRAP_METHOD(bool has_application(const Glib::ustring& app_name) const, gtk_recent_info_has_application)
-  
+  _WRAP_METHOD(bool has_application(const Glib::ustring& app_name) const,
+               gtk_recent_info_has_application)
+
+  _WRAP_METHOD_DOCS_ONLY(gtk_recent_info_get_groups)
   Glib::StringArrayHandle get_groups() const;
-  _IGNORE(gtk_recent_info_get_groups)
-  //_WRAP_METHOD(Glib::StringArrayHandle get_groups(unsigned& length) const, gtk_recent_info_get_groups)
+
   _WRAP_METHOD(bool has_group(const Glib::ustring& group) const, gtk_recent_info_has_group)
-  
-  _WRAP_METHOD(Glib::RefPtr<Gdk::Pixbuf> get_icon(int size), gtk_recent_info_get_icon, refreturn)
-  _WRAP_METHOD(Glib::RefPtr<const Gdk::Pixbuf> get_icon(int size) const, gtk_recent_info_get_icon, refreturn)
-  
+
+  _WRAP_METHOD(Glib::RefPtr<Gdk::Pixbuf> get_icon(int size),
+               gtk_recent_info_get_icon, refreturn)
+  _WRAP_METHOD(Glib::RefPtr<const Gdk::Pixbuf> get_icon(int size) const,
+               gtk_recent_info_get_icon, refreturn, constversion)
+
   _WRAP_METHOD(Glib::ustring get_short_name() const, gtk_recent_info_get_short_name)
   _WRAP_METHOD(Glib::ustring get_uri_display() const, gtk_recent_info_get_uri_display)
-  
+
   _WRAP_METHOD(int get_age() const, gtk_recent_info_get_age)
   _WRAP_METHOD(bool is_local() const, gtk_recent_info_is_local)
   _WRAP_METHOD(bool exists() const, gtk_recent_info_exists)
-
-  _IGNORE(gtk_recent_info_match)
-  //_WRAP_METHOD(bool match(const RecentInfo& b) const, gtk_recent_info_match)
+#m4begin
+_CONVERSION(`const RecentInfo&',`GtkRecentInfo*', `const_cast<GtkRecentInfo*>(($3).gobj())')
+#m4end
+  _WRAP_METHOD(bool equal(const RecentInfo& b) const, gtk_recent_info_match)
 };
 
-
 #ifndef DOXYGEN_SHOULD_SKIP_THIS
 
 struct RecentInfoTraits
@@ -92,14 +105,15 @@ struct RecentInfoTraits
   typedef const GtkRecentInfo* CType;
   typedef GtkRecentInfo* CTypeNonConst;
 
-  static CType to_c_type(const CppType& obj) { return Glib::unwrap(obj); }
-  static CType to_c_type(const CType& obj) { return obj; }
-  static CppType to_cpp_type(const CType& obj); //Implemented in the .cpp file
-  static void release_c_type(const CType& /* obj */) { /* gtk_recent_info_unref(const_cast<CTypeNonConst>(obj)); */}
+  static inline CType to_c_type(const CppType& obj) { return Glib::unwrap(obj); }
+  static inline CType to_c_type(const CType& obj) { return obj; }
+  static CppType to_cpp_type(const CType& obj);
+  static inline void release_c_type(const CType& obj)
+    { gtk_recent_info_unref(const_cast<CTypeNonConst>(obj)); }
 };
-#endif
+#endif /* !DOXYGEN_SHOULD_SKIP_THIS */
 
-//TODO: We normally put these inside the class:
+// TODO: These are almost impossible to use without RefPtr<>::operator*()
 
 /** @relates Gtk::RecentInfo */
 inline bool operator==(const RecentInfo& lhs, const RecentInfo& rhs)
@@ -116,8 +130,8 @@ namespace Glib
 
 // This is needed so Glib::RefPtr<Gtk::RecentInfo> can be used with
 // Glib::Value and Gtk::TreeModelColumn:
-template<>
-class Value<Glib::RefPtr<Gtk::RecentInfo> >: public ValueBase_Boxed
+template <>
+class Value< Glib::RefPtr<Gtk::RecentInfo> > : public ValueBase_Boxed
 {
 public:
   typedef Glib::RefPtr<Gtk::RecentInfo> CppType;
@@ -130,4 +144,3 @@ public:
 };
 
 } // namespace Glib
-



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