From 84135b93a20e6c9fe652849959d3ff90474c99bb Mon Sep 17 00:00:00 2001 From: Murray Cumming Date: Fri, 1 Feb 2008 23:24:08 +0000 Subject: Use convert_return_gchar_ptr_to_ustring() because it releases the gchar* 2008-02-02 Murray Cumming * gio/giomm/contenttype.cc: * gio/giomm/contenttype.h: Use convert_return_gchar_ptr_to_ustring() because it releases the gchar* and checks for NULL. Removed the ontent_type_guess() that takes a basic_string because I doubt anybody would use that. Added one that takes a gchar* and size, and one that takes a std::string (for when the data is a string). svn path=/trunk/; revision=552 --- gio/giomm/contenttype.cc | 56 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 17 deletions(-) (limited to 'gio/giomm/contenttype.cc') diff --git a/gio/giomm/contenttype.cc b/gio/giomm/contenttype.cc index c840acd6..dc268cef 100644 --- a/gio/giomm/contenttype.cc +++ b/gio/giomm/contenttype.cc @@ -23,55 +23,77 @@ namespace Gio { -bool content_type_equals(const Glib::ustring& type1, - const Glib::ustring& type2) +bool content_type_equals(const Glib::ustring& type1, const Glib::ustring& type2) { - return g_content_type_equals(type1.c_str(), type2.c_str()); + return g_content_type_equals(type1.c_str(), type2.c_str()); } -bool content_type_is_a(const Glib::ustring& type, - const Glib::ustring& supertype) +bool content_type_is_a(const Glib::ustring& type, const Glib::ustring& supertype) { - return g_content_type_is_a(type.c_str(), supertype.c_str()); + return g_content_type_is_a(type.c_str(), supertype.c_str()); } bool content_type_is_unknown(const Glib::ustring& type) { - return g_content_type_is_unknown(type.c_str()); + return g_content_type_is_unknown(type.c_str()); } Glib::ustring content_type_get_description(const Glib::ustring& type) { - return Glib::ustring(g_content_type_get_description(type.c_str())); + return Glib::convert_return_gchar_ptr_to_ustring(g_content_type_get_description(type.c_str())); } Glib::ustring content_type_get_mime_type(const Glib::ustring& type) { - return Glib::ustring(g_content_type_get_mime_type(type.c_str())); + return Glib::convert_return_gchar_ptr_to_ustring(g_content_type_get_mime_type(type.c_str())); } Glib::RefPtr content_type_get_icon(const Glib::ustring& type) { - return Glib::wrap(g_content_type_get_icon(type.c_str())); + //TODO: Does g_content_type_get_icon() return a reference? + //It currently has no implementation so it's hard to know. murrayc. + return Glib::wrap(g_content_type_get_icon(type.c_str())); } bool content_type_can_be_executable(const Glib::ustring& type) { - return g_content_type_can_be_executable(type.c_str()); + return g_content_type_can_be_executable(type.c_str()); } Glib::ustring content_type_guess(const std::string& filename, - const std::basic_string& data, - bool& result_uncertain) + const std::basic_string& data, bool& result_uncertain) { - return Glib::ustring(g_content_type_guess(filename.c_str(), data.c_str(), - data.size(), reinterpret_cast(&result_uncertain))); + gboolean c_result_uncertain = FALSE; + gchar* cresult = g_content_type_guess(filename.c_str(), data.c_str(), + data.size(), &c_result_uncertain); + result_uncertain = c_result_uncertain; + return Glib::convert_return_gchar_ptr_to_ustring(cresult); } -Glib::ListHandle content_types_get_registered(void) +Glib::ustring content_type_guess(const std::string& filename, + const guchar* data, gsize data_size, bool& result_uncertain) +{ + gboolean c_result_uncertain = FALSE; + gchar* cresult = g_content_type_guess(filename.c_str(), data, + data_size, &c_result_uncertain); + result_uncertain = c_result_uncertain; + return Glib::convert_return_gchar_ptr_to_ustring(cresult); +} + +Glib::ustring content_type_guess(const std::string& filename, + const std::string& data, bool& result_uncertain) +{ + gboolean c_result_uncertain = FALSE; + gchar* cresult = g_content_type_guess(filename.c_str(), (const guchar*)data.c_str(), + data.size(), &c_result_uncertain); + result_uncertain = c_result_uncertain; + return Glib::convert_return_gchar_ptr_to_ustring(cresult); +} + +Glib::ListHandle content_types_get_registered() { return Glib::ListHandle(g_content_types_get_registered(), - Glib::OWNERSHIP_DEEP); + Glib::OWNERSHIP_DEEP); } } // namespace Gio -- cgit v1.2.1