info: Use g_auto for variables
https://bugzilla.gnome.org/show_bug.cgi?id=788158
This commit is contained in:
parent
a2b20a65cb
commit
1e62c99f41
6 changed files with 121 additions and 211 deletions
|
@ -77,8 +77,8 @@ static void
|
|||
default_app_changed (GtkAppChooserButton *button,
|
||||
CcInfoDefaultAppsPanel *self)
|
||||
{
|
||||
GAppInfo *info;
|
||||
GError *error = NULL;
|
||||
g_autoptr(GAppInfo) info = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
DefaultAppData *app_data;
|
||||
int i;
|
||||
|
||||
|
@ -89,8 +89,6 @@ default_app_changed (GtkAppChooserButton *button,
|
|||
{
|
||||
g_warning ("Failed to set '%s' as the default application for '%s': %s",
|
||||
g_app_info_get_name (info), app_data->content_type, error->message);
|
||||
g_error_free (error);
|
||||
error = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -101,22 +99,23 @@ default_app_changed (GtkAppChooserButton *button,
|
|||
if (app_data->extra_type_filter)
|
||||
{
|
||||
const char *const *mime_types;
|
||||
GPatternSpec *pattern;
|
||||
g_autoptr(GPatternSpec) pattern = NULL;
|
||||
|
||||
pattern = g_pattern_spec_new (app_data->extra_type_filter);
|
||||
mime_types = g_app_info_get_supported_types (info);
|
||||
|
||||
for (i = 0; mime_types && mime_types[i]; i++)
|
||||
{
|
||||
g_autoptr(GError) local_error = NULL;
|
||||
|
||||
if (!g_pattern_match_string (pattern, mime_types[i]))
|
||||
continue;
|
||||
|
||||
if (g_app_info_set_as_default_for_type (info, mime_types[i], &error) == FALSE)
|
||||
if (g_app_info_set_as_default_for_type (info, mime_types[i], &local_error) == FALSE)
|
||||
{
|
||||
g_warning ("Failed to set '%s' as the default application for secondary "
|
||||
"content type '%s': %s",
|
||||
g_app_info_get_name (info), mime_types[i], error->message);
|
||||
g_error_free (error);
|
||||
g_app_info_get_name (info), mime_types[i], local_error->message);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -124,11 +123,7 @@ default_app_changed (GtkAppChooserButton *button,
|
|||
g_app_info_get_name (info), mime_types[i]);
|
||||
}
|
||||
}
|
||||
|
||||
g_pattern_spec_free (pattern);
|
||||
}
|
||||
|
||||
g_object_unref (info);
|
||||
}
|
||||
|
||||
#define OFFSET(x) (G_STRUCT_OFFSET (CcInfoDefaultAppsPanel, x))
|
||||
|
|
|
@ -108,6 +108,18 @@ typedef struct
|
|||
char **current;
|
||||
} VersionData;
|
||||
|
||||
static void
|
||||
version_data_free (VersionData *data)
|
||||
{
|
||||
g_free (data->major);
|
||||
g_free (data->minor);
|
||||
g_free (data->micro);
|
||||
g_free (data->distributor);
|
||||
g_free (data->date);
|
||||
g_free (data);
|
||||
}
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (VersionData, version_data_free);
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (CcInfoOverviewPanel, cc_info_overview_panel, CC_TYPE_PANEL)
|
||||
|
||||
|
@ -153,7 +165,13 @@ version_text_handler (GMarkupParseContext *ctx,
|
|||
{
|
||||
VersionData *data = user_data;
|
||||
if (data->current != NULL)
|
||||
*data->current = g_strstrip (g_strdup (text));
|
||||
{
|
||||
g_autofree char *stripped = NULL;
|
||||
|
||||
stripped = g_strstrip (g_strdup (text));
|
||||
g_free (*data->current);
|
||||
*data->current = g_strdup (stripped);
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -168,16 +186,12 @@ load_gnome_version (char **version,
|
|||
NULL,
|
||||
NULL,
|
||||
};
|
||||
GError *error;
|
||||
GMarkupParseContext *ctx;
|
||||
char *contents;
|
||||
gsize length;
|
||||
VersionData *data;
|
||||
gboolean ret;
|
||||
g_autoptr(GError) error = NULL;
|
||||
g_autoptr(GMarkupParseContext) ctx = NULL;
|
||||
g_autofree char *contents = NULL;
|
||||
gsize length;
|
||||
g_autoptr(VersionData) data = NULL;
|
||||
|
||||
ret = FALSE;
|
||||
|
||||
error = NULL;
|
||||
if (!g_file_get_contents (DATADIR "/gnome/gnome-version.xml",
|
||||
&contents,
|
||||
&length,
|
||||
|
@ -200,19 +214,10 @@ load_gnome_version (char **version,
|
|||
if (date != NULL)
|
||||
*date = g_strdup (data->date);
|
||||
|
||||
ret = TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
g_markup_parse_context_free (ctx);
|
||||
g_free (data->major);
|
||||
g_free (data->minor);
|
||||
g_free (data->micro);
|
||||
g_free (data->distributor);
|
||||
g_free (data->date);
|
||||
g_free (data);
|
||||
g_free (contents);
|
||||
|
||||
return ret;
|
||||
return FALSE;
|
||||
};
|
||||
|
||||
static void
|
||||
|
@ -225,10 +230,10 @@ graphics_data_free (GraphicsData *gdata)
|
|||
static char *
|
||||
get_renderer_from_session (void)
|
||||
{
|
||||
GDBusProxy *session_proxy;
|
||||
GVariant *renderer_variant;
|
||||
g_autoptr(GDBusProxy) session_proxy = NULL;
|
||||
g_autoptr(GVariant) renderer_variant = NULL;
|
||||
char *renderer;
|
||||
GError *error = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
session_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
|
||||
G_DBUS_PROXY_FLAGS_NONE,
|
||||
|
@ -241,12 +246,10 @@ get_renderer_from_session (void)
|
|||
{
|
||||
g_warning ("Unable to connect to create a proxy for org.gnome.SessionManager: %s",
|
||||
error->message);
|
||||
g_error_free (error);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
renderer_variant = g_dbus_proxy_get_cached_property (session_proxy, "Renderer");
|
||||
g_object_unref (session_proxy);
|
||||
|
||||
if (!renderer_variant)
|
||||
{
|
||||
|
@ -255,7 +258,6 @@ get_renderer_from_session (void)
|
|||
}
|
||||
|
||||
renderer = info_cleanup (g_variant_get_string (renderer_variant, NULL));
|
||||
g_variant_unref (renderer_variant);
|
||||
|
||||
return renderer;
|
||||
}
|
||||
|
@ -265,10 +267,9 @@ get_renderer_from_helper (gboolean discrete_gpu)
|
|||
{
|
||||
int status;
|
||||
char *argv[] = { GNOME_SESSION_DIR "/gnome-session-check-accelerated", NULL };
|
||||
char **envp = NULL;
|
||||
char *renderer = NULL;
|
||||
char *ret = NULL;
|
||||
GError *error = NULL;
|
||||
g_auto(GStrv) envp = NULL;
|
||||
g_autofree char *renderer = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
if (discrete_gpu)
|
||||
{
|
||||
|
@ -281,31 +282,25 @@ get_renderer_from_helper (gboolean discrete_gpu)
|
|||
g_debug ("Failed to get %s GPU: %s",
|
||||
discrete_gpu ? "discrete" : "integrated",
|
||||
error->message);
|
||||
g_error_free (error);
|
||||
goto out;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!g_spawn_check_exit_status (status, NULL))
|
||||
goto out;
|
||||
return NULL;
|
||||
|
||||
if (renderer == NULL || *renderer == '\0')
|
||||
goto out;
|
||||
return NULL;
|
||||
|
||||
ret = info_cleanup (renderer);
|
||||
|
||||
out:
|
||||
g_free (renderer);
|
||||
g_strfreev (envp);
|
||||
return ret;
|
||||
return info_cleanup (renderer);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
has_dual_gpu (void)
|
||||
{
|
||||
GDBusProxy *switcheroo_proxy;
|
||||
GVariant *dualgpu_variant;
|
||||
g_autoptr(GDBusProxy) switcheroo_proxy = NULL;
|
||||
g_autoptr(GVariant) dualgpu_variant = NULL;
|
||||
gboolean ret;
|
||||
GError *error = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
switcheroo_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
|
||||
G_DBUS_PROXY_FLAGS_NONE,
|
||||
|
@ -318,12 +313,10 @@ has_dual_gpu (void)
|
|||
{
|
||||
g_debug ("Unable to connect to create a proxy for net.hadess.SwitcherooControl: %s",
|
||||
error->message);
|
||||
g_error_free (error);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
dualgpu_variant = g_dbus_proxy_get_cached_property (switcheroo_proxy, "HasDualGpu");
|
||||
g_object_unref (switcheroo_proxy);
|
||||
|
||||
if (!dualgpu_variant)
|
||||
{
|
||||
|
@ -332,7 +325,6 @@ has_dual_gpu (void)
|
|||
}
|
||||
|
||||
ret = g_variant_get_boolean (dualgpu_variant);
|
||||
g_variant_unref (dualgpu_variant);
|
||||
|
||||
if (ret)
|
||||
g_debug ("Dual-GPU machine detected");
|
||||
|
@ -361,8 +353,8 @@ get_graphics_data (void)
|
|||
|
||||
if (x11_or_wayland)
|
||||
{
|
||||
char *discrete_renderer = NULL;
|
||||
char *renderer;
|
||||
g_autofree char *discrete_renderer = NULL;
|
||||
g_autofree char *renderer = NULL;
|
||||
|
||||
renderer = get_renderer_from_session ();
|
||||
if (!renderer)
|
||||
|
@ -375,8 +367,6 @@ get_graphics_data (void)
|
|||
result->hardware_string = g_strdup_printf ("%s / %s",
|
||||
renderer,
|
||||
discrete_renderer);
|
||||
g_free (renderer);
|
||||
g_free (discrete_renderer);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -390,32 +380,31 @@ static GHashTable*
|
|||
get_os_info (void)
|
||||
{
|
||||
GHashTable *hashtable;
|
||||
gchar *buffer;
|
||||
g_autofree gchar *buffer = NULL;
|
||||
|
||||
hashtable = NULL;
|
||||
|
||||
if (g_file_get_contents ("/etc/os-release", &buffer, NULL, NULL))
|
||||
{
|
||||
gchar **lines;
|
||||
g_auto(GStrv) lines = NULL;
|
||||
gint i;
|
||||
|
||||
lines = g_strsplit (buffer, "\n", -1);
|
||||
|
||||
for (i = 0; lines[i] != NULL; i++)
|
||||
{
|
||||
gchar *delimiter, *key, *value;
|
||||
gchar *delimiter;
|
||||
|
||||
/* Initialize the hash table if needed */
|
||||
if (!hashtable)
|
||||
hashtable = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
|
||||
|
||||
delimiter = strstr (lines[i], "=");
|
||||
value = NULL;
|
||||
key = NULL;
|
||||
|
||||
if (delimiter != NULL)
|
||||
{
|
||||
gint size;
|
||||
gchar *key, *value;
|
||||
|
||||
key = g_strndup (lines[i], delimiter - lines[i]);
|
||||
|
||||
|
@ -437,9 +426,6 @@ get_os_info (void)
|
|||
g_hash_table_insert (hashtable, key, value);
|
||||
}
|
||||
}
|
||||
|
||||
g_strfreev (lines);
|
||||
g_free (buffer);
|
||||
}
|
||||
|
||||
return hashtable;
|
||||
|
@ -505,30 +491,24 @@ query_done (GFile *file,
|
|||
CcInfoOverviewPanel *self)
|
||||
{
|
||||
CcInfoOverviewPanelPrivate *priv;
|
||||
GFileInfo *info;
|
||||
GError *error = NULL;
|
||||
g_autoptr(GFileInfo) info = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
info = g_file_query_filesystem_info_finish (file, res, &error);
|
||||
if (info != NULL)
|
||||
{
|
||||
priv = cc_info_overview_panel_get_instance_private (self);
|
||||
priv->total_bytes += g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE);
|
||||
g_object_unref (info);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
||||
{
|
||||
g_error_free (error);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
char *path;
|
||||
g_autofree char *path = NULL;
|
||||
path = g_file_get_path (file);
|
||||
g_warning ("Failed to get filesystem free space for '%s': %s", path, error->message);
|
||||
g_free (path);
|
||||
g_error_free (error);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -540,16 +520,15 @@ static void
|
|||
get_primary_disc_info_start (CcInfoOverviewPanel *self)
|
||||
{
|
||||
GUnixMountEntry *mount;
|
||||
GFile *file;
|
||||
g_autoptr(GFile) file = NULL;
|
||||
CcInfoOverviewPanelPrivate *priv = cc_info_overview_panel_get_instance_private (self);
|
||||
|
||||
if (priv->primary_mounts == NULL)
|
||||
{
|
||||
char *size;
|
||||
g_autofree char *size = NULL;
|
||||
|
||||
size = g_format_size (priv->total_bytes);
|
||||
gtk_label_set_text (GTK_LABEL (priv->disk_label), size);
|
||||
g_free (size);
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -565,7 +544,6 @@ get_primary_disc_info_start (CcInfoOverviewPanel *self)
|
|||
priv->cancellable,
|
||||
(GAsyncReadyCallback) query_done,
|
||||
self);
|
||||
g_object_unref (file);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -618,9 +596,8 @@ get_primary_disc_info (CcInfoOverviewPanel *self)
|
|||
static char *
|
||||
get_cpu_info (const glibtop_sysinfo *info)
|
||||
{
|
||||
GHashTable *counts;
|
||||
GString *cpu;
|
||||
char *ret;
|
||||
g_autoptr(GHashTable) counts = NULL;
|
||||
g_autoptr(GString) cpu = NULL;
|
||||
GHashTableIter iter;
|
||||
gpointer key, value;
|
||||
int i;
|
||||
|
@ -657,8 +634,8 @@ get_cpu_info (const glibtop_sysinfo *info)
|
|||
g_hash_table_iter_init (&iter, counts);
|
||||
while (g_hash_table_iter_next (&iter, &key, &value))
|
||||
{
|
||||
char *cleanedup;
|
||||
int count;
|
||||
g_autofree char *cleanedup = NULL;
|
||||
int count;
|
||||
|
||||
count = GPOINTER_TO_INT (value);
|
||||
cleanedup = info_cleanup ((const char *) key);
|
||||
|
@ -666,14 +643,9 @@ get_cpu_info (const glibtop_sysinfo *info)
|
|||
g_string_append_printf (cpu, "%s \303\227 %d ", cleanedup, count);
|
||||
else
|
||||
g_string_append_printf (cpu, "%s ", cleanedup);
|
||||
g_free (cleanedup);
|
||||
}
|
||||
|
||||
g_hash_table_destroy (counts);
|
||||
|
||||
ret = g_string_free (cpu, FALSE);
|
||||
|
||||
return ret;
|
||||
return g_strdup (cpu->str);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -743,13 +715,10 @@ set_virtualization_label (CcInfoOverviewPanel *self,
|
|||
static void
|
||||
info_overview_panel_setup_virt (CcInfoOverviewPanel *self)
|
||||
{
|
||||
GError *error = NULL;
|
||||
GDBusProxy *systemd_proxy;
|
||||
GVariant *variant;
|
||||
g_autoptr(GError) error = NULL;
|
||||
g_autoptr(GDBusProxy) systemd_proxy = NULL;
|
||||
g_autoptr(GVariant) variant = NULL;
|
||||
GVariant *inner;
|
||||
char *str;
|
||||
|
||||
str = NULL;
|
||||
|
||||
systemd_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
|
||||
G_DBUS_PROXY_FLAGS_NONE,
|
||||
|
@ -763,8 +732,8 @@ info_overview_panel_setup_virt (CcInfoOverviewPanel *self)
|
|||
if (systemd_proxy == NULL)
|
||||
{
|
||||
g_debug ("systemd not available, bailing: %s", error->message);
|
||||
g_error_free (error);
|
||||
goto bail;
|
||||
set_virtualization_label (self, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
variant = g_dbus_proxy_call_sync (systemd_proxy,
|
||||
|
@ -777,20 +746,12 @@ info_overview_panel_setup_virt (CcInfoOverviewPanel *self)
|
|||
if (variant == NULL)
|
||||
{
|
||||
g_debug ("Failed to get property '%s': %s", "Virtualization", error->message);
|
||||
g_error_free (error);
|
||||
g_object_unref (systemd_proxy);
|
||||
goto bail;
|
||||
set_virtualization_label (self, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
g_variant_get (variant, "(v)", &inner);
|
||||
str = g_variant_dup_string (inner, NULL);
|
||||
g_variant_unref (variant);
|
||||
|
||||
g_object_unref (systemd_proxy);
|
||||
|
||||
bail:
|
||||
set_virtualization_label (self, str);
|
||||
g_free (str);
|
||||
set_virtualization_label (self, g_variant_get_string (inner, NULL));
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -799,7 +760,10 @@ info_overview_panel_setup_overview (CcInfoOverviewPanel *self)
|
|||
gboolean res;
|
||||
glibtop_mem mem;
|
||||
const glibtop_sysinfo *info;
|
||||
char *text;
|
||||
g_autofree char *memory_text = NULL;
|
||||
g_autofree char *cpu_text = NULL;
|
||||
g_autofree char *os_type_text = NULL;
|
||||
g_autofree char *os_name_text = NULL;
|
||||
CcInfoOverviewPanelPrivate *priv = cc_info_overview_panel_get_instance_private (self);
|
||||
|
||||
res = load_gnome_version (&priv->gnome_version,
|
||||
|
@ -807,29 +771,25 @@ info_overview_panel_setup_overview (CcInfoOverviewPanel *self)
|
|||
&priv->gnome_date);
|
||||
if (res)
|
||||
{
|
||||
g_autofree gchar *text = NULL;
|
||||
text = g_strdup_printf (_("Version %s"), priv->gnome_version);
|
||||
gtk_label_set_text (GTK_LABEL (priv->version_label), text);
|
||||
g_free (text);
|
||||
}
|
||||
|
||||
glibtop_get_mem (&mem);
|
||||
text = g_format_size_full (mem.total, G_FORMAT_SIZE_IEC_UNITS);
|
||||
gtk_label_set_text (GTK_LABEL (priv->memory_label), text ? text : "");
|
||||
g_free (text);
|
||||
memory_text = g_format_size_full (mem.total, G_FORMAT_SIZE_IEC_UNITS);
|
||||
gtk_label_set_text (GTK_LABEL (priv->memory_label), memory_text ? memory_text : "");
|
||||
|
||||
info = glibtop_get_sysinfo ();
|
||||
|
||||
text = get_cpu_info (info);
|
||||
gtk_label_set_markup (GTK_LABEL (priv->processor_label), text ? text : "");
|
||||
g_free (text);
|
||||
cpu_text = get_cpu_info (info);
|
||||
gtk_label_set_markup (GTK_LABEL (priv->processor_label), cpu_text ? cpu_text : "");
|
||||
|
||||
text = get_os_type ();
|
||||
gtk_label_set_text (GTK_LABEL (priv->os_type_label), text ? text : "");
|
||||
g_free (text);
|
||||
os_type_text = get_os_type ();
|
||||
gtk_label_set_text (GTK_LABEL (priv->os_type_label), os_type_text ? os_type_text : "");
|
||||
|
||||
text = get_os_name ();
|
||||
gtk_label_set_text (GTK_LABEL (priv->os_name_label), text ? text : "");
|
||||
g_free (text);
|
||||
os_name_text = get_os_name ();
|
||||
gtk_label_set_text (GTK_LABEL (priv->os_name_label), os_name_text ? os_name_text : "");
|
||||
|
||||
get_primary_disc_info (self);
|
||||
|
||||
|
@ -852,9 +812,9 @@ static void
|
|||
on_updates_button_clicked (GtkWidget *widget,
|
||||
CcInfoOverviewPanel *self)
|
||||
{
|
||||
GError *error = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
gboolean ret;
|
||||
gchar **argv;
|
||||
g_auto(GStrv) argv = NULL;
|
||||
|
||||
argv = g_new0 (gchar *, 3);
|
||||
if (does_gnome_software_exist ())
|
||||
|
@ -868,11 +828,7 @@ on_updates_button_clicked (GtkWidget *widget,
|
|||
}
|
||||
ret = g_spawn_async (NULL, argv, NULL, 0, NULL, NULL, NULL, &error);
|
||||
if (!ret)
|
||||
{
|
||||
g_warning ("Failed to spawn %s: %s", argv[0], error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
g_strfreev (argv);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -155,9 +155,9 @@ autorun_get_preferences (CcInfoRemovableMediaPanel *self,
|
|||
gboolean *pref_ignore,
|
||||
gboolean *pref_open_folder)
|
||||
{
|
||||
char **x_content_start_app;
|
||||
char **x_content_ignore;
|
||||
char **x_content_open_folder;
|
||||
g_auto(GStrv) x_content_start_app = NULL;
|
||||
g_auto(GStrv) x_content_ignore = NULL;
|
||||
g_auto(GStrv) x_content_open_folder = NULL;
|
||||
|
||||
g_return_if_fail (pref_start_app != NULL);
|
||||
g_return_if_fail (pref_ignore != NULL);
|
||||
|
@ -181,9 +181,6 @@ autorun_get_preferences (CcInfoRemovableMediaPanel *self,
|
|||
if (x_content_open_folder != NULL) {
|
||||
*pref_open_folder = media_panel_g_strv_find (x_content_open_folder, x_content_type) != -1;
|
||||
}
|
||||
g_strfreev (x_content_ignore);
|
||||
g_strfreev (x_content_start_app);
|
||||
g_strfreev (x_content_open_folder);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -193,9 +190,9 @@ autorun_set_preferences (CcInfoRemovableMediaPanel *self,
|
|||
gboolean pref_ignore,
|
||||
gboolean pref_open_folder)
|
||||
{
|
||||
char **x_content_start_app;
|
||||
char **x_content_ignore;
|
||||
char **x_content_open_folder;
|
||||
g_auto(GStrv) x_content_start_app = NULL;
|
||||
g_auto(GStrv) x_content_ignore = NULL;
|
||||
g_auto(GStrv) x_content_open_folder = NULL;
|
||||
|
||||
g_assert (x_content_type != NULL);
|
||||
|
||||
|
@ -227,10 +224,6 @@ autorun_set_preferences (CcInfoRemovableMediaPanel *self,
|
|||
g_settings_set_strv (self->media_settings,
|
||||
PREF_MEDIA_AUTORUN_X_CONTENT_OPEN_FOLDER, (const gchar * const*) x_content_open_folder);
|
||||
|
||||
g_strfreev (x_content_open_folder);
|
||||
g_strfreev (x_content_ignore);
|
||||
g_strfreev (x_content_start_app);
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -239,7 +232,7 @@ custom_item_activated_cb (GtkAppChooserButton *button,
|
|||
gpointer user_data)
|
||||
{
|
||||
CcInfoRemovableMediaPanel *self = user_data;
|
||||
gchar *content_type;
|
||||
g_autofree gchar *content_type = NULL;
|
||||
|
||||
content_type = gtk_app_chooser_get_content_type (GTK_APP_CHOOSER (button));
|
||||
|
||||
|
@ -253,8 +246,6 @@ custom_item_activated_cb (GtkAppChooserButton *button,
|
|||
autorun_set_preferences (self, content_type,
|
||||
FALSE, TRUE, FALSE);
|
||||
}
|
||||
|
||||
g_free (content_type);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -262,8 +253,8 @@ combo_box_changed_cb (GtkComboBox *combo_box,
|
|||
gpointer user_data)
|
||||
{
|
||||
CcInfoRemovableMediaPanel *self = user_data;
|
||||
GAppInfo *info;
|
||||
gchar *content_type;
|
||||
g_autoptr(GAppInfo) info = NULL;
|
||||
g_autofree gchar *content_type = NULL;
|
||||
|
||||
info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (combo_box));
|
||||
|
||||
|
@ -274,9 +265,6 @@ combo_box_changed_cb (GtkComboBox *combo_box,
|
|||
autorun_set_preferences (self, content_type,
|
||||
TRUE, FALSE, FALSE);
|
||||
g_app_info_set_as_default_for_type (info, content_type, NULL);
|
||||
|
||||
g_object_unref (info);
|
||||
g_free (content_type);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -289,8 +277,8 @@ prepare_combo_box (CcInfoRemovableMediaPanel *self,
|
|||
gboolean pref_start_app;
|
||||
gboolean pref_ignore;
|
||||
gboolean pref_open_folder;
|
||||
GAppInfo *info;
|
||||
gchar *content_type;
|
||||
g_autoptr(GAppInfo) info = NULL;
|
||||
g_autofree gchar *content_type = NULL;
|
||||
|
||||
content_type = gtk_app_chooser_get_content_type (GTK_APP_CHOOSER (app_chooser));
|
||||
|
||||
|
@ -304,7 +292,6 @@ prepare_combo_box (CcInfoRemovableMediaPanel *self,
|
|||
/* append the separator only if we have >= 1 apps in the chooser */
|
||||
if (info != NULL) {
|
||||
gtk_app_chooser_button_append_separator (app_chooser);
|
||||
g_object_unref (info);
|
||||
}
|
||||
|
||||
gtk_app_chooser_button_append_custom_item (app_chooser, CUSTOM_ITEM_ASK,
|
||||
|
@ -336,8 +323,6 @@ prepare_combo_box (CcInfoRemovableMediaPanel *self,
|
|||
G_CALLBACK (combo_box_changed_cb), self);
|
||||
g_signal_connect (app_chooser, "custom-item-activated",
|
||||
G_CALLBACK (custom_item_activated_cb), self);
|
||||
|
||||
g_free (content_type);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -346,12 +331,10 @@ other_type_combo_box_changed (GtkComboBox *combo_box,
|
|||
{
|
||||
GtkTreeIter iter;
|
||||
GtkTreeModel *model;
|
||||
char *x_content_type;
|
||||
g_autofree gchar *x_content_type = NULL;
|
||||
GtkWidget *action_container;
|
||||
GtkWidget *action_label;
|
||||
|
||||
x_content_type = NULL;
|
||||
|
||||
if (!gtk_combo_box_get_active_iter (combo_box, &iter)) {
|
||||
return;
|
||||
}
|
||||
|
@ -379,8 +362,6 @@ other_type_combo_box_changed (GtkComboBox *combo_box,
|
|||
action_label = self->media_other_action_label;
|
||||
|
||||
gtk_label_set_mnemonic_widget (GTK_LABEL (action_label), self->other_application_combo);
|
||||
|
||||
g_free (x_content_type);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -490,7 +471,7 @@ info_panel_setup_media (CcInfoRemovableMediaPanel *self)
|
|||
|
||||
for (l = content_types; l != NULL; l = l->next) {
|
||||
char *content_type = l->data;
|
||||
char *description = NULL;
|
||||
g_autofree char *description = NULL;
|
||||
|
||||
if (!g_str_has_prefix (content_type, "x-content/"))
|
||||
continue;
|
||||
|
@ -524,7 +505,6 @@ info_panel_setup_media (CcInfoRemovableMediaPanel *self)
|
|||
0, description,
|
||||
1, content_type,
|
||||
-1);
|
||||
g_free (description);
|
||||
skip:
|
||||
;
|
||||
}
|
||||
|
|
|
@ -121,17 +121,15 @@ gboolean
|
|||
gsd_is_removable_mount (GUnixMountEntry *mount)
|
||||
{
|
||||
const char *mount_path;
|
||||
char *path;
|
||||
g_autofree gchar *path = NULL;
|
||||
|
||||
mount_path = g_unix_mount_get_mount_path (mount);
|
||||
if (mount_path == NULL)
|
||||
return FALSE;
|
||||
|
||||
path = g_strdup_printf ("/run/media/%s", g_get_user_name ());
|
||||
if (g_str_has_prefix (mount_path, path)) {
|
||||
g_free (path);
|
||||
if (g_str_has_prefix (mount_path, path))
|
||||
return TRUE;
|
||||
}
|
||||
g_free (path);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
|
|
@ -32,7 +32,8 @@ typedef struct
|
|||
static char *
|
||||
prettify_info (const char *info)
|
||||
{
|
||||
char *pretty;
|
||||
g_autofree char *escaped = NULL;
|
||||
g_autofree gchar *pretty = NULL;
|
||||
int i;
|
||||
static const ReplaceStrings rs[] = {
|
||||
{ "Mesa DRI ", ""},
|
||||
|
@ -49,22 +50,19 @@ prettify_info (const char *info)
|
|||
if (*info == '\0')
|
||||
return NULL;
|
||||
|
||||
pretty = g_markup_escape_text (info, -1);
|
||||
pretty = g_strchug (g_strchomp (pretty));
|
||||
escaped = g_markup_escape_text (info, -1);
|
||||
pretty = g_strdup (g_strstrip (escaped));
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (rs); i++)
|
||||
{
|
||||
GError *error;
|
||||
GRegex *re;
|
||||
char *new;
|
||||
|
||||
error = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
g_autoptr(GRegex) re = NULL;
|
||||
g_autofree gchar *new = NULL;
|
||||
|
||||
re = g_regex_new (rs[i].regex, 0, 0, &error);
|
||||
if (re == NULL)
|
||||
{
|
||||
g_warning ("Error building regex: %s", error->message);
|
||||
g_error_free (error);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -76,38 +74,33 @@ prettify_info (const char *info)
|
|||
0,
|
||||
&error);
|
||||
|
||||
g_regex_unref (re);
|
||||
|
||||
if (error != NULL)
|
||||
{
|
||||
g_warning ("Error replacing %s: %s", rs[i].regex, error->message);
|
||||
g_error_free (error);
|
||||
continue;
|
||||
}
|
||||
|
||||
g_free (pretty);
|
||||
pretty = new;
|
||||
pretty = g_steal_pointer (&new);
|
||||
}
|
||||
|
||||
return pretty;
|
||||
return g_steal_pointer (&pretty);
|
||||
}
|
||||
|
||||
static char *
|
||||
remove_duplicate_whitespace (const char *old)
|
||||
{
|
||||
char *new;
|
||||
GRegex *re;
|
||||
GError *error;
|
||||
g_autofree gchar *new = NULL;
|
||||
g_autoptr(GRegex) re = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
if (old == NULL)
|
||||
return NULL;
|
||||
|
||||
error = NULL;
|
||||
re = g_regex_new ("[ \t\n\r]+", G_REGEX_MULTILINE, 0, &error);
|
||||
if (re == NULL)
|
||||
{
|
||||
g_warning ("Error building regex: %s", error->message);
|
||||
g_error_free (error);
|
||||
return g_strdup (old);
|
||||
}
|
||||
new = g_regex_replace (re,
|
||||
|
@ -117,25 +110,20 @@ remove_duplicate_whitespace (const char *old)
|
|||
" ",
|
||||
0,
|
||||
&error);
|
||||
g_regex_unref (re);
|
||||
if (new == NULL)
|
||||
{
|
||||
g_warning ("Error replacing string: %s", error->message);
|
||||
g_error_free (error);
|
||||
return g_strdup (old);
|
||||
}
|
||||
|
||||
return new;
|
||||
return g_steal_pointer (&new);
|
||||
}
|
||||
|
||||
char *
|
||||
info_cleanup (const char *input)
|
||||
{
|
||||
char *pretty, *ret;
|
||||
g_autofree char *pretty;
|
||||
|
||||
pretty = prettify_info (input);
|
||||
ret = remove_duplicate_whitespace (pretty);
|
||||
g_free (pretty);
|
||||
|
||||
return ret;
|
||||
return remove_duplicate_whitespace (pretty);
|
||||
}
|
||||
|
|
|
@ -27,10 +27,9 @@
|
|||
static void
|
||||
test_info (void)
|
||||
{
|
||||
char *contents;
|
||||
char *result;
|
||||
g_autofree gchar *contents = NULL;
|
||||
guint i;
|
||||
char **lines;
|
||||
g_auto(GStrv) lines = NULL;
|
||||
|
||||
if (g_file_get_contents (TEST_SRCDIR "/info-cleanup-test.txt", &contents, NULL, NULL) == FALSE) {
|
||||
g_warning ("Failed to load '%s'", TEST_SRCDIR "/info-cleanup-test.txt");
|
||||
|
@ -46,8 +45,9 @@ test_info (void)
|
|||
}
|
||||
|
||||
for (i = 0; lines[i] != NULL; i++) {
|
||||
char *utf8;
|
||||
char **items;
|
||||
g_auto(GStrv) items = NULL;
|
||||
g_autofree gchar *utf8 = NULL;
|
||||
g_autofree gchar *result = NULL;
|
||||
|
||||
if (*lines[i] == '#')
|
||||
continue;
|
||||
|
@ -65,14 +65,7 @@ test_info (void)
|
|||
g_debug ("Result for '%s' matches '%s'",
|
||||
utf8, result);
|
||||
}
|
||||
g_free (result);
|
||||
g_free (utf8);
|
||||
|
||||
g_strfreev (items);
|
||||
}
|
||||
|
||||
g_strfreev (lines);
|
||||
g_free (contents);
|
||||
}
|
||||
|
||||
int main (int argc, char **argv)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue