* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
*
* Author: Alexander Larsson <alexl@redhat.com>
*/
* The encoding of the returned string is proprietary to #GIcon except
* in the following two cases
*
- * <itemizedlist>
- * <listitem><para>
- * If @icon is a #GFileIcon, the returned string is a native path
- * (such as <literal>/path/to/my icon.png</literal>) without escaping
- * if the #GFile for @icon is a native file. If the file is not
- * native, the returned string is the result of g_file_get_uri()
- * (such as <literal>sftp://path/to/my%20icon.png</literal>).
- * </para></listitem>
- * <listitem><para>
- * If @icon is a #GThemedIcon with exactly one name, the encoding is
- * simply the name (such as <literal>network-server</literal>).
- * </para></listitem>
- * </itemizedlist>
+ * - If @icon is a #GFileIcon, the returned string is a native path
+ * (such as `/path/to/my icon.png`) without escaping
+ * if the #GFile for @icon is a native file. If the file is not
+ * native, the returned string is the result of g_file_get_uri()
+ * (such as `sftp://path/to/my%20icon.png`).
+ *
+ * - If @icon is a #GThemedIcon with exactly one name, the encoding is
+ * simply the name (such as `network-server`).
*
* Virtual: to_tokens
- * Returns: An allocated NUL-terminated UTF8 string or %NULL if @icon can't
- * be serialized. Use g_free() to free.
+ * Returns: (nullable): An allocated NUL-terminated UTF8 string or
+ * %NULL if @icon can't be serialized. Use g_free() to free.
*
* Since: 2.20
*/
int num_tokens;
int i;
+ icon = NULL;
+ klass = NULL;
+
num_tokens = g_strv_length (tokens);
- g_return_val_if_fail (num_tokens >= 1, NULL);
+ if (num_tokens < 1)
+ {
+ g_set_error (error,
+ G_IO_ERROR,
+ G_IO_ERROR_INVALID_ARGUMENT,
+ _("Wrong number of tokens (%d)"),
+ num_tokens);
+ goto out;
+ }
typename = tokens[0];
version_str = strchr (typename, '.');
type = g_type_from_name (tokens[0]);
- g_return_val_if_fail (type != 0, NULL);
- g_return_val_if_fail (g_type_is_a (type, G_TYPE_ICON), NULL);
+ if (type == 0)
+ {
+ g_set_error (error,
+ G_IO_ERROR,
+ G_IO_ERROR_INVALID_ARGUMENT,
+ _("No type for class name %s"),
+ tokens[0]);
+ goto out;
+ }
+
+ if (!g_type_is_a (type, G_TYPE_ICON))
+ {
+ g_set_error (error,
+ G_IO_ERROR,
+ G_IO_ERROR_INVALID_ARGUMENT,
+ _("Type %s does not implement the GIcon interface"),
+ tokens[0]);
+ goto out;
+ }
klass = g_type_class_ref (type);
- g_return_val_if_fail (klass, NULL);
+ if (klass == NULL)
+ {
+ g_set_error (error,
+ G_IO_ERROR,
+ G_IO_ERROR_INVALID_ARGUMENT,
+ _("Type %s is not classed"),
+ tokens[0]);
+ goto out;
+ }
version = 0;
if (version_str)
{
version = strtol (version_str, &endp, 10);
- g_return_val_if_fail (endp && *endp, NULL);
+ if (endp == NULL || *endp != '\0')
+ {
+ g_set_error (error,
+ G_IO_ERROR,
+ G_IO_ERROR_INVALID_ARGUMENT,
+ _("Malformed version number: %s"),
+ version_str);
+ goto out;
+ }
}
icon_iface = g_type_interface_peek (klass, G_TYPE_ICON);
g_assert (icon_iface != NULL);
- g_return_val_if_fail (icon_iface->from_tokens, NULL);
+ if (icon_iface->from_tokens == NULL)
+ {
+ g_set_error (error,
+ G_IO_ERROR,
+ G_IO_ERROR_INVALID_ARGUMENT,
+ _("Type %s does not implement from_tokens() on the GIcon interface"),
+ tokens[0]);
+ goto out;
+ }
for (i = 1; i < num_tokens; i++)
{
icon = icon_iface->from_tokens (tokens + 1, num_tokens - 1, version, error);
- g_type_class_unref (klass);
+ out:
+ if (klass != NULL)
+ g_type_class_unref (klass);
return icon;
}
g_set_error_literal (error,
G_IO_ERROR,
G_IO_ERROR_INVALID_ARGUMENT,
- "Can't handle the supplied version of the icon encoding");
+ _("Can't handle the supplied version of the icon encoding"));
return icon;
}