Skip to content
This repository has been archived by the owner on Nov 17, 2020. It is now read-only.

Commit

Permalink
appinfo: add g_app_info_set_as_last_used_for_type()
Browse files Browse the repository at this point in the history
This commit also changes (maintaining compatibility) the way
user-specified default applications are stored (as in, those for which
g_app_info_set_as_default_for_type() has been called.

We now store the default application for a content type in a new group
in the mimeapps.list keyfile, and "Added Associations" tracks only the
applications that have been added by the user, following a
most-recently-used first order.

This is useful in GtkAppChooser-like widgets to pre-select the last used
application when constructing a widget.

https://bugzilla.gnome.org/show_bug.cgi?id=636311
  • Loading branch information
cosimoc committed Dec 20, 2010
1 parent 01ba7bd commit 678bcad
Show file tree
Hide file tree
Showing 6 changed files with 314 additions and 64 deletions.
1 change: 1 addition & 0 deletions docs/reference/gio/gio-sections.txt
Expand Up @@ -1256,6 +1256,7 @@ g_app_info_delete
g_app_info_reset_type_associations
g_app_info_set_as_default_for_type
g_app_info_set_as_default_for_extension
g_app_info_set_as_last_used_for_type
g_app_info_add_supports_type
g_app_info_can_remove_supports_type
g_app_info_remove_supports_type
Expand Down
27 changes: 27 additions & 0 deletions gio/gappinfo.c
Expand Up @@ -308,6 +308,33 @@ g_app_info_set_as_default_for_type (GAppInfo *appinfo,
return (* iface->set_as_default_for_type) (appinfo, content_type, error);
}

/**
* g_app_info_set_as_last_used_for_type:
* @appinfo: a #GAppInfo.
* @content_type: the content type.
* @error: a #GError.
*
* Sets the application as the last used application for a given type.
* This will make the application appear as first in the list returned by
* #g_app_info_get_recommended_for_type, regardless of the default application
* for that content type.
*
* Returns: %TRUE on success, %FALSE on error.
**/
gboolean
g_app_info_set_as_last_used_for_type (GAppInfo *appinfo,
const char *content_type,
GError **error)
{
GAppInfoIface *iface;

g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
g_return_val_if_fail (content_type != NULL, FALSE);

iface = G_APP_INFO_GET_IFACE (appinfo);

return (* iface->set_as_last_used_for_type) (appinfo, content_type, error);
}

/**
* g_app_info_set_as_default_for_extension:
Expand Down
7 changes: 7 additions & 0 deletions gio/gappinfo.h
Expand Up @@ -128,6 +128,9 @@ struct _GAppInfoIface
gboolean (* do_delete) (GAppInfo *appinfo);
const char * (* get_commandline) (GAppInfo *appinfo);
const char * (* get_display_name) (GAppInfo *appinfo);
gboolean (* set_as_last_used_for_type) (GAppInfo *appinfo,
const char *content_type,
GError **error);
};

GType g_app_info_get_type (void) G_GNUC_CONST;
Expand Down Expand Up @@ -173,6 +176,10 @@ gboolean g_app_info_remove_supports_type (GAppInfo *appin
gboolean g_app_info_can_delete (GAppInfo *appinfo);
gboolean g_app_info_delete (GAppInfo *appinfo);

gboolean g_app_info_set_as_last_used_for_type (GAppInfo *appinfo,
const char *content_type,
GError **error);

GList * g_app_info_get_all (void);
GList * g_app_info_get_all_for_type (const char *content_type);
GList * g_app_info_get_recommended_for_type (const gchar *content_type);
Expand Down

0 comments on commit 678bcad

Please sign in to comment.