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 +++++++++++++++++++++++++++------------ gio/giomm/contenttype.h | 69 ++++++++++++++++++++++++++++-------------------- 2 files changed, 80 insertions(+), 45 deletions(-) (limited to 'gio/giomm') 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 diff --git a/gio/giomm/contenttype.h b/gio/giomm/contenttype.h index ec7a7cba..5f5b56be 100644 --- a/gio/giomm/contenttype.h +++ b/gio/giomm/contenttype.h @@ -29,23 +29,23 @@ namespace Gio /** * Compares two content types for equality. - - * @param type1 a content type string. - * @param type2 a content type string. + * + * @param type1 A content type string. + * @param type2 A content type string. * * @return true if the two strings are identical or equivalent, false otherwise. - **/ + */ bool content_type_equals(const Glib::ustring& type1, const Glib::ustring& type2); /** - * Determines if @type is a subset of @supertype. + * Determines if @a type is a subset of @a supertype. + * + * @param type A content type string. + * @param supertype A string. * - * @param type a content type string. - * @param supertype a string. - * @return true if @type is a kind of @supertype, false otherwise. - **/ + */ bool content_type_is_a(const Glib::ustring& type, const Glib::ustring& supertype); @@ -54,37 +54,37 @@ bool content_type_is_a(const Glib::ustring& type, * On unix this is the "application/octet-stream" mimetype, * while on win32 it is "*". * - * @param type a content type string. + * @param type A content type string. * * @return true if the type is the unknown type. - **/ + */ bool content_type_is_unknown(const Glib::ustring& type); /** * Gets the human readable description of the content type. * - * @param type a content type string. + * @param type A content type string. * * @return a short description of the content type @type. - **/ + */ Glib::ustring content_type_get_description(const Glib::ustring& type); /** * Gets the mime-type for the content type. If one is registered * - * @param type a content type string. + * @param type A content type string. * * @return the registered mime-type for the given @type, or NULL if unknown. - **/ + */ Glib::ustring content_type_get_mime_type(const Glib::ustring& type); /** - * @param type a content type string. + * @param type A content type string. * * Gets the icon for a content type. * * @return Icon corresponding to the content type. - **/ + */ Glib::RefPtr content_type_get_icon(const Glib::ustring& type); /** @@ -94,24 +94,37 @@ Glib::RefPtr content_type_get_icon(const Glib::ustring& type); * @param type a content type string. * * @return true if the file type corresponds to a type that can be executable, - * true otherwise. - **/ + * false otherwise. + */ bool content_type_can_be_executable(const Glib::ustring& type); /** * Guesses the content type based on example data. If the function is uncertain, - * @result_uncertain will be set to true + * @a result_uncertain will be set to true * * @param filename a string. - * @param data a stream of data. - * @param data_size the size of @data. - * @param result_uncertain a flag indicating the certainty of the result. + * @param data A stream of data. + * @param data_size The size of @data. + * @param result_uncertain A flag indicating the certainty of the result. + * @return A string indicating a guessed content type for the + * given data. + */ +Glib::ustring content_type_guess(const std::string& filename, + const guchar* data, gsize data_size, + bool& result_uncertain); + +/** + * Guesses the content type based on example data. If the function is uncertain, + * @a result_uncertain will be set to true * - * Returns: a string indicating a guessed content type for the + * @param filename a string. + * @param data A stream of data. + * @param result_uncertain A flag indicating the certainty of the result. + * @return A string indicating a guessed content type for the * given data. - **/ + */ Glib::ustring content_type_guess(const std::string& filename, - const std::basic_string& data, + const std::string& data, bool& result_uncertain); /** @@ -119,8 +132,8 @@ Glib::ustring content_type_guess(const std::string& filename, * known to the system. * * @return List of the registered content types. - **/ -Glib::ListHandle content_types_get_registered(void); + */ +Glib::ListHandle content_types_get_registered(); } // namespace Gio #endif // _GIOMM_CONTENTTYPE_H -- cgit v1.2.1