sharing: Use g_auto for variables
This commit is contained in:
parent
9a7850a7aa
commit
a30f660db9
6 changed files with 137 additions and 220 deletions
|
@ -28,7 +28,7 @@
|
|||
static GKeyFile*
|
||||
cc_media_sharing_open_key_file (void)
|
||||
{
|
||||
gchar *path;
|
||||
g_autofree gchar *path = NULL;
|
||||
GKeyFile *file;
|
||||
|
||||
file = g_key_file_new ();
|
||||
|
@ -39,22 +39,20 @@ cc_media_sharing_open_key_file (void)
|
|||
G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS,
|
||||
NULL))
|
||||
{
|
||||
g_free (path);
|
||||
path = g_build_filename (SYSCONFDIR, "rygel.conf", NULL);
|
||||
g_key_file_load_from_file (file, path,
|
||||
g_autofree gchar *sysconf_path = NULL;
|
||||
sysconf_path = g_build_filename (SYSCONFDIR, "rygel.conf", NULL);
|
||||
g_key_file_load_from_file (file, sysconf_path,
|
||||
G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS,
|
||||
NULL);
|
||||
}
|
||||
|
||||
g_free (path);
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
void
|
||||
cc_media_sharing_get_preferences (gchar ***folders)
|
||||
{
|
||||
GKeyFile *file;
|
||||
g_autoptr(GKeyFile) file = NULL;
|
||||
|
||||
file = cc_media_sharing_open_key_file ();
|
||||
|
||||
|
@ -62,7 +60,8 @@ cc_media_sharing_get_preferences (gchar ***folders)
|
|||
{
|
||||
gsize length;
|
||||
GPtrArray *array;
|
||||
char **str_list, **orig_list;
|
||||
GStrv str_list;
|
||||
g_auto(GStrv) orig_list = NULL;
|
||||
|
||||
str_list = g_key_file_get_string_list (file, "MediaExport", "uris",
|
||||
&length, NULL);
|
||||
|
@ -91,20 +90,17 @@ cc_media_sharing_get_preferences (gchar ***folders)
|
|||
g_ptr_array_add (array, NULL);
|
||||
|
||||
*folders = (char **) g_ptr_array_free (array, FALSE);
|
||||
g_strfreev (orig_list);
|
||||
}
|
||||
|
||||
g_key_file_free (file);
|
||||
}
|
||||
|
||||
void
|
||||
cc_media_sharing_set_preferences (gchar **folders)
|
||||
{
|
||||
GKeyFile *file;
|
||||
g_autoptr(GKeyFile) file = NULL;
|
||||
gchar **str_list;
|
||||
gchar *path;
|
||||
g_autofree gchar *path = NULL;
|
||||
gsize length;
|
||||
gchar *data;
|
||||
g_autofree gchar *data = NULL;
|
||||
|
||||
file = cc_media_sharing_open_key_file ();
|
||||
|
||||
|
@ -146,8 +142,4 @@ cc_media_sharing_set_preferences (gchar **folders)
|
|||
path = g_build_filename (g_get_user_config_dir (), "rygel.conf", NULL);
|
||||
|
||||
g_file_set_contents (path, data, -1, NULL);
|
||||
|
||||
g_free (path);
|
||||
|
||||
g_key_file_free (file);
|
||||
}
|
||||
|
|
|
@ -30,19 +30,19 @@ static const gchar *service_list[] = { SSHD_SERVICE, NULL };
|
|||
static gint
|
||||
enable_ssh_service ()
|
||||
{
|
||||
GDBusConnection *connection;
|
||||
GError *error = NULL;
|
||||
GVariant *temp_variant;
|
||||
g_autoptr(GDBusConnection) connection = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
g_autoptr(GVariant) start_result = NULL;
|
||||
g_autoptr(GVariant) enable_result = NULL;
|
||||
|
||||
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
|
||||
if (!connection)
|
||||
{
|
||||
g_critical ("Error connecting to D-Bus system bus: %s", error->message);
|
||||
g_clear_error (&error);
|
||||
return 1;
|
||||
}
|
||||
|
||||
temp_variant = g_dbus_connection_call_sync (connection,
|
||||
start_result = g_dbus_connection_call_sync (connection,
|
||||
"org.freedesktop.systemd1",
|
||||
"/org/freedesktop/systemd1",
|
||||
"org.freedesktop.systemd1.Manager",
|
||||
|
@ -56,98 +56,86 @@ enable_ssh_service ()
|
|||
NULL,
|
||||
&error);
|
||||
|
||||
if (!temp_variant)
|
||||
if (!start_result)
|
||||
{
|
||||
g_critical ("Error starting " SSHD_SERVICE ": %s", error->message);
|
||||
g_clear_error (&error);
|
||||
return 1;
|
||||
}
|
||||
|
||||
g_variant_unref (temp_variant);
|
||||
enable_result = g_dbus_connection_call_sync (connection,
|
||||
"org.freedesktop.systemd1",
|
||||
"/org/freedesktop/systemd1",
|
||||
"org.freedesktop.systemd1.Manager",
|
||||
"EnableUnitFiles",
|
||||
g_variant_new ("(^asbb)",
|
||||
service_list,
|
||||
FALSE, FALSE),
|
||||
(GVariantType *) "(ba(sss))",
|
||||
G_DBUS_CALL_FLAGS_NONE,
|
||||
-1,
|
||||
NULL,
|
||||
&error);
|
||||
|
||||
temp_variant = g_dbus_connection_call_sync (connection,
|
||||
"org.freedesktop.systemd1",
|
||||
"/org/freedesktop/systemd1",
|
||||
"org.freedesktop.systemd1.Manager",
|
||||
"EnableUnitFiles",
|
||||
g_variant_new ("(^asbb)",
|
||||
service_list,
|
||||
FALSE, FALSE),
|
||||
(GVariantType *) "(ba(sss))",
|
||||
G_DBUS_CALL_FLAGS_NONE,
|
||||
-1,
|
||||
NULL,
|
||||
&error);
|
||||
|
||||
if (!temp_variant)
|
||||
if (!enable_result)
|
||||
{
|
||||
g_critical ("Error enabling " SSHD_SERVICE ": %s", error->message);
|
||||
g_clear_error (&error);
|
||||
return 1;
|
||||
}
|
||||
|
||||
g_variant_unref (temp_variant);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static gint
|
||||
disable_ssh_service ()
|
||||
{
|
||||
GDBusConnection *connection;
|
||||
GError *error = NULL;
|
||||
GVariant *temp_variant;
|
||||
g_autoptr(GDBusConnection) connection = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
g_autoptr(GVariant) stop_result = NULL;
|
||||
g_autoptr(GVariant) disable_result = NULL;
|
||||
|
||||
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
|
||||
if (!connection)
|
||||
{
|
||||
g_critical ("Error connecting to D-Bus system bus: %s", error->message);
|
||||
g_clear_error (&error);
|
||||
return 1;
|
||||
}
|
||||
|
||||
temp_variant = g_dbus_connection_call_sync (connection,
|
||||
"org.freedesktop.systemd1",
|
||||
"/org/freedesktop/systemd1",
|
||||
"org.freedesktop.systemd1.Manager",
|
||||
"StopUnit",
|
||||
g_variant_new ("(ss)", SSHD_SERVICE, "replace"),
|
||||
(GVariantType *) "(o)",
|
||||
G_DBUS_CALL_FLAGS_NONE,
|
||||
-1,
|
||||
NULL,
|
||||
&error);
|
||||
if (!temp_variant)
|
||||
stop_result = g_dbus_connection_call_sync (connection,
|
||||
"org.freedesktop.systemd1",
|
||||
"/org/freedesktop/systemd1",
|
||||
"org.freedesktop.systemd1.Manager",
|
||||
"StopUnit",
|
||||
g_variant_new ("(ss)", SSHD_SERVICE, "replace"),
|
||||
(GVariantType *) "(o)",
|
||||
G_DBUS_CALL_FLAGS_NONE,
|
||||
-1,
|
||||
NULL,
|
||||
&error);
|
||||
if (!stop_result)
|
||||
{
|
||||
g_critical ("Error stopping " SSHD_SERVICE ": %s", error->message);
|
||||
g_clear_error (&error);
|
||||
return 1;
|
||||
}
|
||||
|
||||
g_variant_unref (temp_variant);
|
||||
disable_result = g_dbus_connection_call_sync (connection,
|
||||
"org.freedesktop.systemd1",
|
||||
"/org/freedesktop/systemd1",
|
||||
"org.freedesktop.systemd1.Manager",
|
||||
"DisableUnitFiles",
|
||||
g_variant_new ("(^asb)", service_list, FALSE,
|
||||
FALSE),
|
||||
(GVariantType *) "(a(sss))",
|
||||
G_DBUS_CALL_FLAGS_NONE,
|
||||
-1,
|
||||
NULL,
|
||||
&error);
|
||||
|
||||
temp_variant = g_dbus_connection_call_sync (connection,
|
||||
"org.freedesktop.systemd1",
|
||||
"/org/freedesktop/systemd1",
|
||||
"org.freedesktop.systemd1.Manager",
|
||||
"DisableUnitFiles",
|
||||
g_variant_new ("(^asb)", service_list, FALSE,
|
||||
FALSE),
|
||||
(GVariantType *) "(a(sss))",
|
||||
G_DBUS_CALL_FLAGS_NONE,
|
||||
-1,
|
||||
NULL,
|
||||
&error);
|
||||
|
||||
if (!temp_variant)
|
||||
if (!stop_result)
|
||||
{
|
||||
g_critical ("Error disabling " SSHD_SERVICE ": %s", error->message);
|
||||
g_clear_error (&error);
|
||||
return 1;
|
||||
}
|
||||
|
||||
g_variant_unref (temp_variant);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,8 @@ typedef struct
|
|||
GCancellable *cancellable;
|
||||
} CallbackData;
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (CallbackData, g_free)
|
||||
|
||||
static void
|
||||
set_switch_state (GtkSwitch *gtkswitch,
|
||||
gboolean active)
|
||||
|
@ -48,12 +50,15 @@ set_switch_state (GtkSwitch *gtkswitch,
|
|||
static void
|
||||
active_state_ready_callback (GObject *source_object,
|
||||
GAsyncResult *result,
|
||||
CallbackData *callback_data)
|
||||
gpointer user_data)
|
||||
{
|
||||
GVariant *active_variant, *child_variant, *tmp_variant;
|
||||
g_autoptr(CallbackData) callback_data = user_data;
|
||||
g_autoptr(GVariant) active_variant = NULL;
|
||||
g_autoptr(GVariant) child_variant = NULL;
|
||||
g_autoptr(GVariant) tmp_variant = NULL;
|
||||
const gchar *active_state;
|
||||
gboolean active;
|
||||
GError *error = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
active_variant = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object),
|
||||
result, &error);
|
||||
|
@ -65,9 +70,6 @@ active_state_ready_callback (GObject *source_object,
|
|||
if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
||||
g_warning ("Error getting remote login state: %s", error->message);
|
||||
|
||||
g_clear_error (&error);
|
||||
g_free (callback_data);
|
||||
|
||||
/* the switch will be remain insensitive, since the current state could
|
||||
* not be determined */
|
||||
return;
|
||||
|
@ -79,25 +81,21 @@ active_state_ready_callback (GObject *source_object,
|
|||
|
||||
active = g_str_equal (active_state, "active");
|
||||
|
||||
g_variant_unref (tmp_variant);
|
||||
g_variant_unref (child_variant);
|
||||
g_variant_unref (active_variant);
|
||||
|
||||
/* set the switch to the correct state */
|
||||
if (callback_data->gtkswitch)
|
||||
set_switch_state (callback_data->gtkswitch, active);
|
||||
|
||||
g_free (callback_data);
|
||||
}
|
||||
|
||||
static void
|
||||
path_ready_callback (GObject *source_object,
|
||||
GAsyncResult *result,
|
||||
CallbackData *callback_data)
|
||||
gpointer user_data)
|
||||
{
|
||||
GVariant *path_variant, *child_variant;
|
||||
g_autoptr(CallbackData) callback_data = user_data;
|
||||
g_autoptr(GVariant) path_variant = NULL;
|
||||
g_autoptr(GVariant) child_variant = NULL;
|
||||
const gchar *object_path;
|
||||
GError *error = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
path_variant = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object),
|
||||
result, &error);
|
||||
|
@ -105,24 +103,15 @@ path_ready_callback (GObject *source_object,
|
|||
if (!path_variant)
|
||||
{
|
||||
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
||||
{
|
||||
g_free (callback_data);
|
||||
g_clear_error (&error);
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
|
||||
/* this may fail if systemd or remote login service is not available */
|
||||
g_debug ("Error getting remote login state: %s", error->message);
|
||||
|
||||
g_clear_error (&error);
|
||||
|
||||
/* hide the remote login button, since the service is not available */
|
||||
if (callback_data->button)
|
||||
gtk_widget_hide (callback_data->button);
|
||||
|
||||
g_free (callback_data);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -141,45 +130,36 @@ path_ready_callback (GObject *source_object,
|
|||
G_DBUS_CALL_FLAGS_NONE,
|
||||
-1,
|
||||
callback_data->cancellable,
|
||||
(GAsyncReadyCallback) active_state_ready_callback,
|
||||
active_state_ready_callback,
|
||||
callback_data);
|
||||
|
||||
g_variant_unref (child_variant);
|
||||
g_variant_unref (path_variant);
|
||||
g_steal_pointer (&callback_data);
|
||||
}
|
||||
|
||||
static void
|
||||
state_ready_callback (GObject *source_object,
|
||||
GAsyncResult *result,
|
||||
CallbackData *callback_data)
|
||||
gpointer user_data)
|
||||
{
|
||||
GVariant *state_variant, *child_variant;
|
||||
g_autoptr(CallbackData) callback_data = user_data;
|
||||
g_autoptr(GVariant) state_variant = NULL;
|
||||
g_autoptr(GVariant) child_variant = NULL;
|
||||
const gchar *state_string;
|
||||
GError *error = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
state_variant = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object),
|
||||
result, &error);
|
||||
if (!state_variant)
|
||||
{
|
||||
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
||||
{
|
||||
g_free (callback_data);
|
||||
g_clear_error (&error);
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
|
||||
/* this may fail if systemd or remote login service is not available */
|
||||
g_debug ("Error getting remote login state: %s", error->message);
|
||||
|
||||
g_clear_error (&error);
|
||||
|
||||
/* hide the remote login button, since the service is not available */
|
||||
if (callback_data->button)
|
||||
gtk_widget_hide (callback_data->button);
|
||||
|
||||
g_free (callback_data);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -199,35 +179,30 @@ state_ready_callback (GObject *source_object,
|
|||
G_DBUS_CALL_FLAGS_NONE,
|
||||
-1,
|
||||
callback_data->cancellable,
|
||||
(GAsyncReadyCallback) path_ready_callback,
|
||||
path_ready_callback,
|
||||
callback_data);
|
||||
g_steal_pointer (&callback_data);
|
||||
}
|
||||
else if (g_str_equal (state_string, "disabled"))
|
||||
{
|
||||
/* service is available, but is currently disabled */
|
||||
set_switch_state (callback_data->gtkswitch, FALSE);
|
||||
|
||||
g_free (callback_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* unknown state */
|
||||
g_warning ("Unknown state %s for %s", state_string, SSHD_SERVICE);
|
||||
|
||||
g_free (callback_data);
|
||||
}
|
||||
|
||||
g_variant_unref (child_variant);
|
||||
g_variant_unref (state_variant);
|
||||
}
|
||||
|
||||
static void
|
||||
bus_ready_callback (GObject *source_object,
|
||||
GAsyncResult *result,
|
||||
CallbackData *callback_data)
|
||||
gpointer user_data)
|
||||
{
|
||||
GDBusConnection *connection;
|
||||
GError *error = NULL;
|
||||
g_autoptr(CallbackData) callback_data = user_data;
|
||||
g_autoptr(GDBusConnection) connection = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
connection = g_bus_get_finish (result, &error);
|
||||
|
||||
|
@ -235,8 +210,6 @@ bus_ready_callback (GObject *source_object,
|
|||
{
|
||||
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
||||
g_warning ("Error getting remote login state: %s", error->message);
|
||||
g_clear_error (&error);
|
||||
g_free (callback_data);
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -251,8 +224,9 @@ bus_ready_callback (GObject *source_object,
|
|||
G_DBUS_CALL_FLAGS_NONE,
|
||||
-1,
|
||||
callback_data->cancellable,
|
||||
(GAsyncReadyCallback) state_ready_callback,
|
||||
state_ready_callback,
|
||||
callback_data);
|
||||
g_steal_pointer (&callback_data);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -271,7 +245,7 @@ cc_remote_login_get_enabled (GCancellable *cancellable,
|
|||
callback_data->cancellable = cancellable;
|
||||
|
||||
g_bus_get (G_BUS_TYPE_SYSTEM, callback_data->cancellable,
|
||||
(GAsyncReadyCallback) bus_ready_callback, callback_data);
|
||||
bus_ready_callback, callback_data);
|
||||
}
|
||||
|
||||
static gint std_err;
|
||||
|
@ -281,7 +255,7 @@ child_watch_func (GPid pid,
|
|||
gint status,
|
||||
gpointer user_data)
|
||||
{
|
||||
CallbackData *callback_data = user_data;
|
||||
g_autoptr(CallbackData) callback_data = user_data;
|
||||
if (status != 0)
|
||||
{
|
||||
g_warning ("Error enabling or disabling remote login service");
|
||||
|
@ -292,8 +266,6 @@ child_watch_func (GPid pid,
|
|||
g_spawn_close_pid (pid);
|
||||
|
||||
gtk_widget_set_sensitive (GTK_WIDGET (callback_data->gtkswitch), TRUE);
|
||||
|
||||
g_free (user_data);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -302,11 +274,10 @@ cc_remote_login_set_enabled (GCancellable *cancellable,
|
|||
{
|
||||
gchar *command[] = { "pkexec", LIBEXECDIR "/cc-remote-login-helper", NULL,
|
||||
NULL };
|
||||
GError *error = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
GPid pid;
|
||||
CallbackData *callback_data;
|
||||
|
||||
|
||||
if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (gtkswitch), "set-from-dbus")) == 1)
|
||||
{
|
||||
g_object_set_data (G_OBJECT (gtkswitch), "set-from-dbus", NULL);
|
||||
|
@ -331,8 +302,5 @@ cc_remote_login_set_enabled (GCancellable *cancellable,
|
|||
g_child_watch_add (pid, child_watch_func, callback_data);
|
||||
|
||||
if (error)
|
||||
{
|
||||
g_error ("Error running cc-remote-login-helper: %s", error->message);
|
||||
g_clear_error (&error);
|
||||
}
|
||||
g_error ("Error running cc-remote-login-helper: %s", error->message);
|
||||
}
|
||||
|
|
|
@ -102,10 +102,10 @@ cc_sharing_networks_update_status (CcSharingNetworks *self)
|
|||
static void
|
||||
cc_sharing_update_networks (CcSharingNetworks *self)
|
||||
{
|
||||
GVariant *networks;
|
||||
g_autoptr(GVariant) networks = NULL;
|
||||
char *uuid, *network_name, *carrier_type;
|
||||
GVariantIter iter;
|
||||
GError *error = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
g_list_free_full (self->networks, cc_sharing_network_free);
|
||||
self->networks = NULL;
|
||||
|
@ -115,7 +115,6 @@ cc_sharing_update_networks (CcSharingNetworks *self)
|
|||
g_dbus_proxy_set_cached_property (G_DBUS_PROXY (self->proxy),
|
||||
"SharingStatus",
|
||||
g_variant_new_uint32 (GSD_SHARING_STATUS_OFFLINE));
|
||||
g_error_free (error);
|
||||
cc_list_box_adjust_scrolling (GTK_LIST_BOX (self->listbox));
|
||||
return;
|
||||
}
|
||||
|
@ -132,8 +131,6 @@ cc_sharing_update_networks (CcSharingNetworks *self)
|
|||
}
|
||||
self->networks = g_list_reverse (self->networks);
|
||||
cc_list_box_adjust_scrolling (GTK_LIST_BOX (self->listbox));
|
||||
|
||||
g_variant_unref (networks);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -141,7 +138,7 @@ cc_sharing_networks_remove_network (GtkWidget *button,
|
|||
CcSharingNetworks *self)
|
||||
{
|
||||
GtkWidget *row;
|
||||
GError *error = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
gboolean ret;
|
||||
const char *uuid;
|
||||
|
||||
|
@ -153,11 +150,9 @@ cc_sharing_networks_remove_network (GtkWidget *button,
|
|||
uuid,
|
||||
NULL,
|
||||
&error);
|
||||
if (!ret) {
|
||||
if (!ret)
|
||||
g_warning ("Failed to remove service %s: %s",
|
||||
self->service_name, error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
cc_sharing_update_networks (self);
|
||||
cc_sharing_update_networks_box (self);
|
||||
|
@ -169,7 +164,7 @@ cc_sharing_networks_enable_network (GtkSwitch *widget,
|
|||
gpointer user_data)
|
||||
{
|
||||
CcSharingNetworks *self = user_data;
|
||||
GError *error = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
gboolean ret;
|
||||
|
||||
if (state) {
|
||||
|
@ -190,7 +185,6 @@ cc_sharing_networks_enable_network (GtkSwitch *widget,
|
|||
} else {
|
||||
g_warning ("Failed to %s service %s: %s", state ? "enable" : "disable",
|
||||
self->service_name, error->message);
|
||||
g_error_free (error);
|
||||
g_signal_handlers_block_by_func (widget,
|
||||
cc_sharing_networks_enable_network, self);
|
||||
gtk_switch_set_active (widget, !state);
|
||||
|
@ -321,7 +315,8 @@ cc_sharing_update_networks_box (CcSharingNetworks *self)
|
|||
{
|
||||
gboolean current_visible;
|
||||
const char *current_network;
|
||||
GList *children, *l;
|
||||
g_autoptr(GList) children = NULL;
|
||||
GList *l;
|
||||
|
||||
children = gtk_container_get_children (GTK_CONTAINER (self->listbox));
|
||||
for (l = children; l != NULL; l = l->next) {
|
||||
|
@ -331,7 +326,6 @@ cc_sharing_update_networks_box (CcSharingNetworks *self)
|
|||
row != self->no_network_row)
|
||||
gtk_widget_destroy (row);
|
||||
}
|
||||
g_list_free (children);
|
||||
|
||||
current_network = gsd_sharing_get_current_network (self->proxy);
|
||||
|
||||
|
|
|
@ -226,7 +226,8 @@ cc_sharing_panel_main_list_box_row_activated (GtkListBox *listbox,
|
|||
GtkListBoxRow *row,
|
||||
CcSharingPanel *self)
|
||||
{
|
||||
gchar *widget_name, *found;
|
||||
g_autofree gchar *widget_name = NULL;
|
||||
gchar *found;
|
||||
|
||||
widget_name = g_strdup (gtk_buildable_get_name (GTK_BUILDABLE (row)));
|
||||
|
||||
|
@ -239,14 +240,11 @@ cc_sharing_panel_main_list_box_row_activated (GtkListBox *listbox,
|
|||
found = g_strrstr (widget_name, "button");
|
||||
|
||||
if (!found)
|
||||
goto out;
|
||||
return;
|
||||
|
||||
memcpy (found, "dialog", 6);
|
||||
|
||||
cc_sharing_panel_run_dialog (self, widget_name);
|
||||
|
||||
out:
|
||||
g_free (widget_name);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -364,7 +362,7 @@ cc_sharing_panel_add_folder (GtkListBox *box,
|
|||
CcSharingPanel *self)
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
gchar *folder = NULL;
|
||||
g_autofree gchar *folder = NULL;
|
||||
gboolean matching = FALSE;
|
||||
GList *rows, *l;
|
||||
|
||||
|
@ -418,7 +416,6 @@ cc_sharing_panel_add_folder (GtkListBox *box,
|
|||
cc_list_box_adjust_scrolling (GTK_LIST_BOX (box));
|
||||
|
||||
bail:
|
||||
g_free (folder);
|
||||
gtk_widget_destroy (dialog);
|
||||
}
|
||||
|
||||
|
@ -438,7 +435,7 @@ cc_sharing_panel_media_sharing_dialog_response (GtkDialog *dialog,
|
|||
gint reponse_id,
|
||||
CcSharingPanel *self)
|
||||
{
|
||||
GPtrArray *folders;
|
||||
g_autoptr(GPtrArray) folders = NULL;
|
||||
GtkWidget *box;
|
||||
GList *rows, *l;
|
||||
|
||||
|
@ -459,8 +456,6 @@ cc_sharing_panel_media_sharing_dialog_response (GtkDialog *dialog,
|
|||
g_ptr_array_add (folders, NULL);
|
||||
|
||||
cc_media_sharing_set_preferences ((gchar **) folders->pdata);
|
||||
|
||||
g_ptr_array_free (folders, TRUE);
|
||||
}
|
||||
|
||||
#define ICON_NAME_FOLDER "folder-symbolic"
|
||||
|
@ -505,14 +500,14 @@ cc_sharing_panel_new_media_sharing_row (const char *uri_or_path,
|
|||
{
|
||||
GtkWidget *row, *box, *w;
|
||||
GUserDirectory dir = G_USER_N_DIRECTORIES;
|
||||
GIcon *icon;
|
||||
g_autoptr(GIcon) icon = NULL;
|
||||
guint i;
|
||||
char *basename, *path;
|
||||
GFile *file;
|
||||
g_autofree gchar *basename = NULL;
|
||||
g_autofree gchar *path = NULL;
|
||||
g_autoptr(GFile) file = NULL;
|
||||
|
||||
file = g_file_new_for_commandline_arg (uri_or_path);
|
||||
path = g_file_get_path (file);
|
||||
g_object_unref (file);
|
||||
|
||||
row = gtk_list_box_row_new ();
|
||||
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
||||
|
@ -534,12 +529,10 @@ cc_sharing_panel_new_media_sharing_row (const char *uri_or_path,
|
|||
w = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_MENU);
|
||||
gtk_widget_set_margin_end (w, 12);
|
||||
gtk_container_add (GTK_CONTAINER (box), w);
|
||||
g_object_unref (icon);
|
||||
|
||||
/* Label */
|
||||
basename = g_filename_display_basename (path);
|
||||
w = gtk_label_new (basename);
|
||||
g_free (basename);
|
||||
gtk_container_add (GTK_CONTAINER (box), w);
|
||||
|
||||
/* Remove button */
|
||||
|
@ -554,7 +547,7 @@ cc_sharing_panel_new_media_sharing_row (const char *uri_or_path,
|
|||
G_CALLBACK (cc_sharing_panel_remove_folder), self);
|
||||
g_object_set_data (G_OBJECT (w), "row", row);
|
||||
|
||||
g_object_set_data_full (G_OBJECT (row), "path", path, g_free);
|
||||
g_object_set_data_full (G_OBJECT (row), "path", g_steal_pointer (&path), g_free);
|
||||
|
||||
gtk_widget_show_all (row);
|
||||
|
||||
|
@ -588,9 +581,10 @@ cc_sharing_panel_new_add_media_sharing_row (CcSharingPanel *self)
|
|||
static void
|
||||
cc_sharing_panel_setup_media_sharing_dialog (CcSharingPanel *self)
|
||||
{
|
||||
gchar **folders, **list;
|
||||
g_auto(GStrv) folders = NULL;
|
||||
GStrv list;
|
||||
GtkWidget *box, *networks, *grid, *w;
|
||||
char *path;
|
||||
g_autofree gchar *path = NULL;
|
||||
|
||||
path = g_find_program_in_path ("rygel");
|
||||
if (path == NULL)
|
||||
|
@ -598,7 +592,6 @@ cc_sharing_panel_setup_media_sharing_dialog (CcSharingPanel *self)
|
|||
gtk_widget_hide (WID ("media-sharing-button"));
|
||||
return;
|
||||
}
|
||||
g_free (path);
|
||||
|
||||
g_signal_connect (WID ("media-sharing-dialog"), "response",
|
||||
G_CALLBACK (cc_sharing_panel_media_sharing_dialog_response),
|
||||
|
@ -630,9 +623,6 @@ cc_sharing_panel_setup_media_sharing_dialog (CcSharingPanel *self)
|
|||
g_signal_connect (G_OBJECT (box), "row-activated",
|
||||
G_CALLBACK (cc_sharing_panel_add_folder), self);
|
||||
|
||||
|
||||
g_strfreev (folders);
|
||||
|
||||
networks = cc_sharing_networks_new (self->sharing_proxy, "rygel");
|
||||
grid = WID ("grid4");
|
||||
gtk_grid_attach (GTK_GRID (grid), networks, 0, 4, 2, 1);
|
||||
|
@ -676,7 +666,7 @@ cc_sharing_panel_setup_label (CcSharingPanel *self,
|
|||
GtkWidget *label,
|
||||
const gchar *hostname)
|
||||
{
|
||||
gchar *text;
|
||||
g_autofree gchar *text = NULL;
|
||||
|
||||
if (label == WID ("personal-file-sharing-label"))
|
||||
text = g_strdup_printf (_("File Sharing allows you to share your Public folder with others on your current network using: <a href=\"dav://%s\">dav://%s</a>"), hostname, hostname);
|
||||
|
@ -688,8 +678,6 @@ cc_sharing_panel_setup_label (CcSharingPanel *self,
|
|||
g_assert_not_reached ();
|
||||
|
||||
gtk_label_set_label (GTK_LABEL (label), text);
|
||||
|
||||
g_free (text);
|
||||
}
|
||||
|
||||
typedef struct
|
||||
|
@ -698,13 +686,17 @@ typedef struct
|
|||
GtkWidget *label;
|
||||
} GetHostNameData;
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GetHostNameData, g_free);
|
||||
|
||||
static void
|
||||
cc_sharing_panel_get_host_name_fqdn_done (GDBusConnection *connection,
|
||||
cc_sharing_panel_get_host_name_fqdn_done (GObject *object,
|
||||
GAsyncResult *res,
|
||||
GetHostNameData *data)
|
||||
gpointer user_data)
|
||||
{
|
||||
GError *error = NULL;
|
||||
GVariant *variant;
|
||||
GDBusConnection *connection = G_DBUS_CONNECTION (object);
|
||||
g_autoptr(GetHostNameData) data = user_data;
|
||||
g_autoptr(GError) error = NULL;
|
||||
g_autoptr(GVariant) variant = NULL;
|
||||
const gchar *fqdn;
|
||||
|
||||
variant = g_dbus_connection_call_finish (connection, res, &error);
|
||||
|
@ -716,36 +708,29 @@ cc_sharing_panel_get_host_name_fqdn_done (GDBusConnection *connection,
|
|||
|
||||
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
||||
{
|
||||
gchar *hostname;
|
||||
g_autofree gchar *hostname = NULL;
|
||||
|
||||
hostname = cc_hostname_entry_get_hostname (CC_HOSTNAME_ENTRY (data->panel->hostname_entry));
|
||||
|
||||
cc_sharing_panel_setup_label (data->panel, data->label, hostname);
|
||||
|
||||
g_free (hostname);
|
||||
}
|
||||
|
||||
g_free (data);
|
||||
g_error_free (error);
|
||||
return;
|
||||
}
|
||||
|
||||
g_variant_get (variant, "(&s)", &fqdn);
|
||||
|
||||
cc_sharing_panel_setup_label (data->panel, data->label, fqdn);
|
||||
|
||||
g_variant_unref (variant);
|
||||
g_object_unref (connection);
|
||||
g_free (data);
|
||||
}
|
||||
|
||||
static void
|
||||
cc_sharing_panel_bus_ready (GObject *object,
|
||||
GAsyncResult *res,
|
||||
GetHostNameData *data)
|
||||
gpointer user_data)
|
||||
{
|
||||
GDBusConnection *connection;
|
||||
GError *error = NULL;
|
||||
g_autoptr(GDBusConnection) connection = NULL;
|
||||
g_autoptr(GetHostNameData) data = user_data;
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
connection = g_bus_get_finish (res, &error);
|
||||
|
||||
|
@ -755,17 +740,13 @@ cc_sharing_panel_bus_ready (GObject *object,
|
|||
|
||||
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
||||
{
|
||||
gchar *hostname;
|
||||
g_autofree gchar *hostname = NULL;
|
||||
|
||||
hostname = cc_hostname_entry_get_hostname (CC_HOSTNAME_ENTRY (data->panel->hostname_entry));
|
||||
|
||||
cc_sharing_panel_setup_label (data->panel, data->label, hostname);
|
||||
|
||||
g_free (hostname);
|
||||
}
|
||||
|
||||
g_error_free (error);
|
||||
g_free (data);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -779,8 +760,9 @@ cc_sharing_panel_bus_ready (GObject *object,
|
|||
G_DBUS_CALL_FLAGS_NONE,
|
||||
-1,
|
||||
data->panel->hostname_cancellable,
|
||||
(GAsyncReadyCallback) cc_sharing_panel_get_host_name_fqdn_done,
|
||||
cc_sharing_panel_get_host_name_fqdn_done,
|
||||
data);
|
||||
g_steal_pointer (&data);
|
||||
}
|
||||
|
||||
|
||||
|
@ -818,7 +800,7 @@ cc_sharing_panel_setup_label_with_hostname (CcSharingPanel *self,
|
|||
get_hostname_data->label = label;
|
||||
g_bus_get (G_BUS_TYPE_SYSTEM,
|
||||
self->hostname_cancellable,
|
||||
(GAsyncReadyCallback) cc_sharing_panel_bus_ready,
|
||||
cc_sharing_panel_bus_ready,
|
||||
get_hostname_data);
|
||||
}
|
||||
|
||||
|
@ -926,7 +908,7 @@ cc_sharing_panel_check_schema_available (CcSharingPanel *self,
|
|||
const gchar *schema_id)
|
||||
{
|
||||
GSettingsSchemaSource *source;
|
||||
GSettingsSchema *schema;
|
||||
g_autoptr(GSettingsSchema) schema = NULL;
|
||||
|
||||
source = g_settings_schema_source_get_default ();
|
||||
if (!source)
|
||||
|
@ -936,7 +918,6 @@ cc_sharing_panel_check_schema_available (CcSharingPanel *self,
|
|||
if (!schema)
|
||||
return FALSE;
|
||||
|
||||
g_settings_schema_unref (schema);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -1110,13 +1091,12 @@ sharing_proxy_ready (GObject *source,
|
|||
{
|
||||
CcSharingPanel *self;
|
||||
GDBusProxy *proxy;
|
||||
GError *error = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
proxy = G_DBUS_PROXY (gsd_sharing_proxy_new_for_bus_finish (res, &error));
|
||||
if (!proxy) {
|
||||
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
||||
g_warning ("Failed to get sharing proxy: %s", error->message);
|
||||
g_error_free (error);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -35,17 +35,15 @@
|
|||
void
|
||||
file_share_write_out_password (const char *password)
|
||||
{
|
||||
char *to_hash;
|
||||
char *ascii_digest;
|
||||
char *line;
|
||||
char *filename;
|
||||
g_autofree gchar *to_hash = NULL;
|
||||
g_autofree gchar *ascii_digest = NULL;
|
||||
g_autofree gchar *line = NULL;
|
||||
g_autofree gchar *filename = NULL;
|
||||
FILE *file;
|
||||
|
||||
to_hash = g_strdup_printf ("%s:%s:%s", USER, REALM, password);
|
||||
ascii_digest = g_compute_checksum_for_string (G_CHECKSUM_MD5, to_hash, strlen (to_hash));
|
||||
g_free (to_hash);
|
||||
line = g_strdup_printf ("%s:%s:%s\n", USER, REALM, ascii_digest);
|
||||
g_free (ascii_digest);
|
||||
|
||||
filename = g_build_filename (g_get_user_config_dir (), "user-share", "passwd", NULL);
|
||||
|
||||
|
@ -54,7 +52,4 @@ file_share_write_out_password (const char *password)
|
|||
fwrite (line, strlen (line), 1, file);
|
||||
fclose (file);
|
||||
}
|
||||
|
||||
g_free (filename);
|
||||
g_free (line);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue