appinfo: Add properties

Give GAppInfo a bunch of readonly properties, and
support them in GDesktopAppInfo. This makes app infos
more convenient to work with in GTK4, and in general.
This commit is contained in:
Matthias Clasen 2020-07-25 14:40:34 -04:00
parent 060fda09eb
commit 6e707d2aa5
2 changed files with 214 additions and 2 deletions

View File

@ -108,8 +108,144 @@ G_DEFINE_INTERFACE (GAppInfo, g_app_info, G_TYPE_OBJECT)
static void
g_app_info_default_init (GAppInfoInterface *iface)
{
}
/**
* GAppInfo:id:
*
* The ID of an application -- a string that identifies the application.
*
* The exact format of the ID is platform dependent. For instance,
* on Unix this is the desktop file id from the xdg menu specification.
*
* May be %NULL, depending on how the GAppInfo has been constructed.
*/
g_object_interface_install_property (iface,
g_param_spec_string ("id", "ID", "ID",
NULL,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
/**
* GAppInfo:name:
*
* The name of the application.
*/
g_object_interface_install_property (iface,
g_param_spec_string ("name", "Name", "Name",
NULL,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
/**
* GAppInfo:display-name:
*
* The display name of the application.
*
* This string is meant to be displayed to the user; it is often more
* descriptive than #GAppInfo:name.
*/
g_object_interface_install_property (iface,
g_param_spec_string ("display-name", "Display Name", "Display Name",
NULL,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
/**
* GAppInfo:description:
*
* A human-readable description of the application.
*/
g_object_interface_install_property (iface,
g_param_spec_string ("description", "Description", "Description",
NULL,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
/**
* GAppInfo:executable:
*
* The executable's name for the application.
*/
g_object_interface_install_property (iface,
g_param_spec_string ("executable", "Executable", "Executable",
NULL,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
/**
* GAppInfo:commandline:
*
* The commandline with which the application will be launched.
*/
g_object_interface_install_property (iface,
g_param_spec_string ("commandline", "Commandline", "Commandline",
NULL,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
/**
* GAppInfo:icon:
*
* The icon for the application.
*
* May be %NULL
*/
g_object_interface_install_property (iface,
g_param_spec_object ("icon", "Icon", "Icon",
G_TYPE_ICON,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
/**
* GAppInfo:supports-uris:
*
* %TRUE if the application supports reading files and directories
* from URIs when launched. See g_app_info_launch_uris().
*/
g_object_interface_install_property (iface,
g_param_spec_boolean ("supports-uris", "Supports URIs", "Supports URIs",
FALSE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
/**
* GAppInfo:supports-files:
*
* %TRUE if the application supports files as arguments when launched.
* See g_app_info_launch_uris().
*/
g_object_interface_install_property (iface,
g_param_spec_boolean ("supports-files", "Supports files", "Supports files",
FALSE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
/**
* GAppInfo:should-show:
*
* %TRUE if the application should be shown in menus that list
* available applications.
*/
g_object_interface_install_property (iface,
g_param_spec_boolean ("should-show", "Should show", "Should show",
FALSE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
/**
* GAppInfo:supported-types:
*
* The list of content types that the application claims to support.
* Note that this property does not take into account associations
* added with g_app_info_add_supports_type().
*
* May be %NULL.
*/
g_object_interface_install_property (iface,
g_param_spec_boxed ("supported-types", "Supported types", "Supported types",
G_TYPE_STRV,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
/**
* GAppInfo:can-delete:
*
* %TRUE if it makes sense to call g_app_info_delete() for this
* GAppInfo.
*/
g_object_interface_install_property (iface,
g_param_spec_boolean ("can-delete", "Can delete", "Can delete",
FALSE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
}
/**
* g_app_info_dup:

View File

@ -81,7 +81,20 @@
enum {
PROP_0,
PROP_FILENAME
PROP_FILENAME,
PROP_ID,
PROP_NAME,
PROP_DISPLAY_NAME,
PROP_DESCRIPTION,
PROP_EXECUTABLE,
PROP_COMMANDLINE,
PROP_ICON,
PROP_SUPPORTS_URIS,
PROP_SUPPORTS_FILES,
PROP_SHOULD_SHOW,
PROP_SUPPORTED_TYPES,
PROP_CAN_DELETE,
NUM_PROPERTIES
};
static void g_desktop_app_info_iface_init (GAppInfoIface *iface);
@ -1657,12 +1670,62 @@ g_desktop_app_info_get_property (GObject *object,
GParamSpec *pspec)
{
GDesktopAppInfo *self = G_DESKTOP_APP_INFO (object);
GAppInfo *app_info = G_APP_INFO (self);
switch (prop_id)
{
case PROP_FILENAME:
g_value_set_string (value, self->filename);
break;
case PROP_ID:
g_value_set_string (value, g_app_info_get_id (app_info));
break;
case PROP_NAME:
g_value_set_string (value, g_app_info_get_name (app_info));
break;
case PROP_DISPLAY_NAME:
g_value_set_string (value, g_app_info_get_display_name (app_info));
break;
case PROP_DESCRIPTION:
g_value_set_string (value, g_app_info_get_description (app_info));
break;
case PROP_EXECUTABLE:
g_value_set_string (value, g_app_info_get_executable (app_info));
break;
case PROP_COMMANDLINE:
g_value_set_string (value, g_app_info_get_commandline (app_info));
break;
case PROP_ICON:
g_value_set_object (value, g_app_info_get_icon (app_info));
break;
case PROP_SUPPORTS_URIS:
g_value_set_boolean (value, g_app_info_supports_uris (app_info));
break;
case PROP_SUPPORTS_FILES:
g_value_set_boolean (value, g_app_info_supports_uris (app_info));
break;
case PROP_SHOULD_SHOW:
g_value_set_boolean (value, g_app_info_should_show (app_info));
break;
case PROP_SUPPORTED_TYPES:
g_value_set_boxed (value, g_app_info_get_supported_types (app_info));
break;
case PROP_CAN_DELETE:
g_value_set_boolean (value, g_app_info_can_delete (app_info));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -1687,6 +1750,19 @@ g_desktop_app_info_class_init (GDesktopAppInfoClass *klass)
PROP_FILENAME,
g_param_spec_string ("filename", "Filename", "", NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_override_property (gobject_class, PROP_ID, "id");
g_object_class_override_property (gobject_class, PROP_NAME, "name");
g_object_class_override_property (gobject_class, PROP_DISPLAY_NAME, "display-name");
g_object_class_override_property (gobject_class, PROP_DESCRIPTION, "description");
g_object_class_override_property (gobject_class, PROP_EXECUTABLE, "executable");
g_object_class_override_property (gobject_class, PROP_COMMANDLINE, "commandline");
g_object_class_override_property (gobject_class, PROP_ICON, "icon");
g_object_class_override_property (gobject_class, PROP_SUPPORTS_URIS, "supports-uris");
g_object_class_override_property (gobject_class, PROP_SUPPORTS_FILES, "supports-files");
g_object_class_override_property (gobject_class, PROP_SHOULD_SHOW, "should-show");
g_object_class_override_property (gobject_class, PROP_SUPPORTED_TYPES, "supported-types");
g_object_class_override_property (gobject_class, PROP_CAN_DELETE, "can-delete");
}
static void