diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 14:36:24 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 14:36:24 +0000 |
commit | 9b6d8e63db85c30007b463e91f91a791969fa83f (patch) | |
tree | 0899af51d73c1bf986f73ae39a03c4436083018a /panels/sharing | |
parent | Initial commit. (diff) | |
download | gnome-control-center-9b6d8e63db85c30007b463e91f91a791969fa83f.tar.xz gnome-control-center-9b6d8e63db85c30007b463e91f91a791969fa83f.zip |
Adding upstream version 1:3.38.4.upstream/1%3.38.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'panels/sharing')
23 files changed, 3944 insertions, 0 deletions
diff --git a/panels/sharing/cc-gnome-remote-desktop.c b/panels/sharing/cc-gnome-remote-desktop.c new file mode 100644 index 0000000..c59f3b0 --- /dev/null +++ b/panels/sharing/cc-gnome-remote-desktop.c @@ -0,0 +1,162 @@ +/* + * Copyright (C) 2018 Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#include "config.h" + +#include "cc-gnome-remote-desktop.h" + +const SecretSchema * +cc_grd_vnc_password_get_schema (void) +{ + static const SecretSchema grd_vnc_password_schema = { + .name = "org.gnome.RemoteDesktop.VncPassword", + .flags = SECRET_SCHEMA_NONE, + .attributes = { + { "password", SECRET_SCHEMA_ATTRIBUTE_STRING }, + { "NULL", 0 }, + }, + }; + + return &grd_vnc_password_schema; +} + +gboolean +cc_grd_get_is_auth_method_prompt (GValue *value, + GVariant *variant, + gpointer user_data) +{ + const char * auth_method; + + auth_method = g_variant_get_string (variant, NULL); + + if (g_strcmp0 (auth_method, "prompt") == 0) + { + g_value_set_boolean (value, TRUE); + } + else if (g_strcmp0 (auth_method, "password") == 0) + { + g_value_set_boolean (value, FALSE); + } + else + { + g_warning ("Unhandled VNC auth method %s", auth_method); + g_value_set_boolean (value, FALSE); + } + + return TRUE; +} + +GVariant * +cc_grd_set_is_auth_method_prompt (const GValue *value, + const GVariantType *type, + gpointer user_data) +{ + char *auth_method; + + if (g_value_get_boolean (value)) + auth_method = "prompt"; + else + auth_method = "password"; + + return g_variant_new_string (auth_method); +} + +gboolean +cc_grd_get_is_auth_method_password (GValue *value, + GVariant *variant, + gpointer user_data) +{ + const char *auth_method; + + auth_method = g_variant_get_string (variant, NULL); + + if (g_strcmp0 (auth_method, "prompt") == 0) + { + g_value_set_boolean (value, FALSE); + } + else if (g_strcmp0 (auth_method, "password") == 0) + { + g_value_set_boolean (value, TRUE); + } + else + { + g_warning ("Unhandled VNC auth method %s", auth_method); + g_value_set_boolean (value, FALSE); + } + + return TRUE; +} + +GVariant * +cc_grd_set_is_auth_method_password (const GValue *value, + const GVariantType *type, + gpointer user_data) +{ + char *auth_method; + + if (g_value_get_boolean (value)) + auth_method = "password"; + else + auth_method = "prompt"; + + return g_variant_new_string (auth_method); +} + +static void +on_password_stored (GObject *source, + GAsyncResult *result, + gpointer user_data) +{ + GError *error = NULL; + + if (!secret_password_store_finish (result, &error)) + { + if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + { + g_warning ("Failed to store VNC password: %s", error->message); + } + g_error_free (error); + } +} + +void +cc_grd_store_vnc_password (const gchar *password, GCancellable *cancellable) +{ + secret_password_store (CC_GRD_VNC_PASSWORD_SCHEMA, + SECRET_COLLECTION_DEFAULT, + "GNOME Remote Desktop VNC password", + password, + cancellable, on_password_stored, NULL, + NULL); +} + +gchar * +cc_grd_lookup_vnc_password (GCancellable *cancellable) +{ + g_autoptr(GError) error = NULL; + g_autofree gchar *password = NULL; + + password = secret_password_lookup_sync (CC_GRD_VNC_PASSWORD_SCHEMA, + cancellable, &error, + NULL); + if (error) + g_warning ("Failed to get password: %s", error->message); + + return g_steal_pointer (&password); +} diff --git a/panels/sharing/cc-gnome-remote-desktop.h b/panels/sharing/cc-gnome-remote-desktop.h new file mode 100644 index 0000000..a3a99ae --- /dev/null +++ b/panels/sharing/cc-gnome-remote-desktop.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2018 Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#pragma once + +#include <libsecret/secret.h> + +G_BEGIN_DECLS + +const SecretSchema * cc_grd_vnc_password_get_schema (void); +#define CC_GRD_VNC_PASSWORD_SCHEMA cc_grd_vnc_password_get_schema () + +gboolean cc_grd_get_is_auth_method_prompt (GValue *value, + GVariant *variant, + gpointer user_data); + +GVariant * cc_grd_set_is_auth_method_prompt (const GValue *value, + const GVariantType *type, + gpointer user_data); + +gboolean cc_grd_get_is_auth_method_password (GValue *value, + GVariant *variant, + gpointer user_data); + +GVariant * cc_grd_set_is_auth_method_password (const GValue *value, + const GVariantType *type, + gpointer user_data); + +void cc_grd_store_vnc_password (const gchar *password, + GCancellable *cancellable); + +gchar * cc_grd_lookup_vnc_password (GCancellable *cancellable); + +G_END_DECLS diff --git a/panels/sharing/cc-media-sharing.c b/panels/sharing/cc-media-sharing.c new file mode 100644 index 0000000..d0f12aa --- /dev/null +++ b/panels/sharing/cc-media-sharing.c @@ -0,0 +1,146 @@ +/* + * Copyright (C) 2013 Intel, Inc + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Author: Thomas Wood <thomas.wood@intel.com> + * + */ + +#include "cc-media-sharing.h" + +#include <gio/gio.h> +#include <gio/gdesktopappinfo.h> +#include <glib/gstdio.h> + +static GKeyFile* +cc_media_sharing_open_key_file (void) +{ + g_autofree gchar *path = NULL; + GKeyFile *file; + + file = g_key_file_new (); + + path = g_build_filename (g_get_user_config_dir (), "rygel.conf", NULL); + + if (!g_key_file_load_from_file (file, path, + G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, + NULL)) + { + 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); + } + + return file; +} + +void +cc_media_sharing_get_preferences (gchar ***folders) +{ + g_autoptr(GKeyFile) file = NULL; + + file = cc_media_sharing_open_key_file (); + + if (folders) + { + gsize length; + GPtrArray *array; + GStrv str_list; + g_auto(GStrv) orig_list = NULL; + + str_list = g_key_file_get_string_list (file, "MediaExport", "uris", + &length, NULL); + orig_list = str_list; + array = g_ptr_array_new (); + + while (str_list && *str_list) + { + const char *dir; + + if (g_str_equal (*str_list, "@MUSIC@")) + dir = g_get_user_special_dir (G_USER_DIRECTORY_MUSIC); + else if (g_str_equal (*str_list, "@VIDEOS@")) + dir = g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS); + else if (g_str_equal (*str_list, "@PICTURES@")) + dir = g_get_user_special_dir (G_USER_DIRECTORY_PICTURES); + else + dir = g_strdup (*str_list); + + if (dir != NULL) + g_ptr_array_add (array, g_strdup (dir)); + + str_list++; + } + + g_ptr_array_add (array, NULL); + + *folders = (char **) g_ptr_array_free (array, FALSE); + } +} + +void +cc_media_sharing_set_preferences (gchar **folders) +{ + g_autoptr(GKeyFile) file = NULL; + gchar **str_list; + g_autofree gchar *path = NULL; + gsize length; + g_autofree gchar *data = NULL; + + file = cc_media_sharing_open_key_file (); + + g_key_file_set_boolean (file, "general", "upnp-enabled", TRUE); + g_key_file_set_boolean (file, "Tracker", "enabled", FALSE); + g_key_file_set_boolean (file, "Tracker3", "enabled", FALSE); + g_key_file_set_boolean (file, "MediaExport", "enabled", TRUE); + + str_list = folders; + length = 0; + + while (str_list && *str_list) + { + if (g_strcmp0 (*str_list, g_get_user_special_dir (G_USER_DIRECTORY_MUSIC)) == 0) + { + g_free (*str_list); + *str_list = g_strdup ("@MUSIC@"); + } + + if (g_strcmp0 (*str_list, g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS)) == 0) + { + g_free (*str_list); + *str_list = g_strdup ("@VIDEOS@"); + } + + if (g_strcmp0 (*str_list, g_get_user_special_dir (G_USER_DIRECTORY_PICTURES)) == 0) + { + g_free (*str_list); + *str_list = g_strdup ("@PICTURES@"); + } + + str_list++; + length++; + } + + g_key_file_set_string_list (file, "MediaExport", "uris", (const gchar**) folders, length); + + data = g_key_file_to_data (file, NULL, NULL); + + path = g_build_filename (g_get_user_config_dir (), "rygel.conf", NULL); + + g_file_set_contents (path, data, -1, NULL); +} diff --git a/panels/sharing/cc-media-sharing.h b/panels/sharing/cc-media-sharing.h new file mode 100644 index 0000000..7923db0 --- /dev/null +++ b/panels/sharing/cc-media-sharing.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2013 Intel, Inc + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Author: Thomas Wood <thomas.wood@intel.com> + * + */ + +#pragma once + +#include <glib.h> + +void cc_media_sharing_get_preferences (gchar ***folders); +void cc_media_sharing_set_preferences (gchar **folders); diff --git a/panels/sharing/cc-remote-login-helper.c b/panels/sharing/cc-remote-login-helper.c new file mode 100644 index 0000000..a9a07d0 --- /dev/null +++ b/panels/sharing/cc-remote-login-helper.c @@ -0,0 +1,158 @@ +/* + * Copyright (C) 2013 Intel, Inc + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Author: Thomas Wood <thomas.wood@intel.com> + * + */ + +#include <gio/gio.h> + +#ifndef SSHD_SERVICE +#define SSHD_SERVICE "sshd.service" +#endif + +static const gchar *service_list[] = { SSHD_SERVICE, NULL }; + +static gint +enable_ssh_service () +{ + 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); + return 1; + } + + start_result = g_dbus_connection_call_sync (connection, + "org.freedesktop.systemd1", + "/org/freedesktop/systemd1", + "org.freedesktop.systemd1.Manager", + "StartUnit", + g_variant_new ("(ss)", + SSHD_SERVICE, + "replace"), + (GVariantType *) "(o)", + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + + if (!start_result) + { + g_critical ("Error starting " SSHD_SERVICE ": %s", error->message); + return 1; + } + + 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); + + if (!enable_result) + { + g_critical ("Error enabling " SSHD_SERVICE ": %s", error->message); + return 1; + } + + return 0; +} + +static gint +disable_ssh_service () +{ + 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); + return 1; + } + + 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); + return 1; + } + + 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); + + if (!stop_result) + { + g_critical ("Error disabling " SSHD_SERVICE ": %s", error->message); + return 1; + } + + return 0; +} + +int +main (int argc, + char **argv) +{ + if (argc < 2) + return 1; + + if (argv[1] == NULL) + return 1; + + if (g_str_equal (argv[1], "enable")) + return enable_ssh_service (); + else if (g_str_equal (argv[1], "disable")) + return disable_ssh_service (); + + return 1; +} diff --git a/panels/sharing/cc-remote-login.c b/panels/sharing/cc-remote-login.c new file mode 100644 index 0000000..d185f7d --- /dev/null +++ b/panels/sharing/cc-remote-login.c @@ -0,0 +1,306 @@ +/* + * Copyright (C) 2013 Intel, Inc + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Author: Thomas Wood <thomas.wood@intel.com> + * + */ +#include "cc-remote-login.h" +#include <gio/gio.h> + +#ifndef SSHD_SERVICE +#define SSHD_SERVICE "sshd.service" +#endif + +typedef struct +{ + GtkSwitch *gtkswitch; + GtkWidget *button; + GCancellable *cancellable; +} CallbackData; + +G_DEFINE_AUTOPTR_CLEANUP_FUNC (CallbackData, g_free) + +static void +set_switch_state (GtkSwitch *gtkswitch, + gboolean active) +{ + if (gtk_switch_get_active (gtkswitch) != active) + { + g_object_set_data (G_OBJECT (gtkswitch), "set-from-dbus", + GINT_TO_POINTER (1)); + gtk_switch_set_active (gtkswitch, active); + } + gtk_widget_set_sensitive (GTK_WIDGET (gtkswitch), TRUE); +} + +static void +active_state_ready_callback (GObject *source_object, + GAsyncResult *result, + gpointer user_data) +{ + 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; + g_autoptr(GError) error = NULL; + + active_variant = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object), + result, &error); + + if (!active_variant) + { + /* print a warning if there was an error but the operation was not + * cancelled */ + if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + g_warning ("Error getting remote login state: %s", error->message); + + /* the switch will be remain insensitive, since the current state could + * not be determined */ + return; + } + + child_variant = g_variant_get_child_value (active_variant, 0); + tmp_variant = g_variant_get_variant (child_variant); + active_state = g_variant_get_string (tmp_variant, NULL); + + active = g_str_equal (active_state, "active"); + + /* set the switch to the correct state */ + if (callback_data->gtkswitch) + set_switch_state (callback_data->gtkswitch, active); +} + +static void +path_ready_callback (GObject *source_object, + GAsyncResult *result, + gpointer user_data) +{ + g_autoptr(CallbackData) callback_data = user_data; + g_autoptr(GVariant) path_variant = NULL; + g_autoptr(GVariant) child_variant = NULL; + const gchar *object_path; + g_autoptr(GError) error = NULL; + + path_variant = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object), + result, &error); + + if (!path_variant) + { + if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + return; + + /* this may fail if systemd or remote login service is not available */ + g_debug ("Error getting remote login state: %s", error->message); + + /* hide the remote login button, since the service is not available */ + if (callback_data->button) + gtk_widget_hide (callback_data->button); + + return; + } + + child_variant = g_variant_get_child_value (path_variant, 0); + object_path = g_variant_get_string (child_variant, NULL); + + g_dbus_connection_call (G_DBUS_CONNECTION (source_object), + "org.freedesktop.systemd1", + object_path, + "org.freedesktop.DBus.Properties", + "Get", + g_variant_new ("(ss)", + "org.freedesktop.systemd1.Unit", + "ActiveState"), + (GVariantType*) "(v)", + G_DBUS_CALL_FLAGS_NONE, + -1, + callback_data->cancellable, + active_state_ready_callback, + callback_data); + g_steal_pointer (&callback_data); +} + +static void +state_ready_callback (GObject *source_object, + GAsyncResult *result, + gpointer user_data) +{ + g_autoptr(CallbackData) callback_data = user_data; + g_autoptr(GVariant) state_variant = NULL; + g_autoptr(GVariant) child_variant = NULL; + const gchar *state_string; + 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)) + return; + + /* this may fail if systemd or remote login service is not available */ + g_debug ("Error getting remote login state: %s", error->message); + + /* hide the remote login button, since the service is not available */ + if (callback_data->button) + gtk_widget_hide (callback_data->button); + + return; + } + + child_variant = g_variant_get_child_value (state_variant, 0); + state_string = g_variant_get_string (child_variant, NULL); + + if (g_str_equal (state_string, "enabled")) + { + /* service is enabled, so check whether it is running or not */ + g_dbus_connection_call (G_DBUS_CONNECTION (source_object), + "org.freedesktop.systemd1", + "/org/freedesktop/systemd1", + "org.freedesktop.systemd1.Manager", + "GetUnit", + g_variant_new ("(s)", SSHD_SERVICE), + (GVariantType*) "(o)", + G_DBUS_CALL_FLAGS_NONE, + -1, + callback_data->cancellable, + 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); + } + else + { + /* unknown state */ + g_warning ("Unknown state %s for %s", state_string, SSHD_SERVICE); + } +} + +static void +bus_ready_callback (GObject *source_object, + GAsyncResult *result, + gpointer user_data) +{ + g_autoptr(CallbackData) callback_data = user_data; + g_autoptr(GDBusConnection) connection = NULL; + g_autoptr(GError) error = NULL; + + connection = g_bus_get_finish (result, &error); + + if (!connection) + { + if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + g_warning ("Error getting remote login state: %s", error->message); + + return; + } + + g_dbus_connection_call (connection, + "org.freedesktop.systemd1", + "/org/freedesktop/systemd1", + "org.freedesktop.systemd1.Manager", + "GetUnitFileState", + g_variant_new ("(s)", SSHD_SERVICE), + (GVariantType*) "(s)", + G_DBUS_CALL_FLAGS_NONE, + -1, + callback_data->cancellable, + state_ready_callback, + callback_data); + g_steal_pointer (&callback_data); +} + +void +cc_remote_login_get_enabled (GCancellable *cancellable, + GtkSwitch *gtkswitch, + GtkWidget *button) +{ + CallbackData *callback_data; + + /* disable the switch until the current state is known */ + gtk_widget_set_sensitive (GTK_WIDGET (gtkswitch), FALSE); + + callback_data = g_new (CallbackData, 1); + callback_data->gtkswitch = gtkswitch; + callback_data->button = button; + callback_data->cancellable = cancellable; + + g_bus_get (G_BUS_TYPE_SYSTEM, callback_data->cancellable, + bus_ready_callback, callback_data); +} + +static gint std_err; + +static void +child_watch_func (GPid pid, + gint status, + gpointer user_data) +{ + g_autoptr(CallbackData) callback_data = user_data; + if (status != 0) + { + g_warning ("Error enabling or disabling remote login service"); + + /* make sure the switch reflects the current status */ + cc_remote_login_get_enabled (callback_data->cancellable, callback_data->gtkswitch, NULL); + } + g_spawn_close_pid (pid); + + gtk_widget_set_sensitive (GTK_WIDGET (callback_data->gtkswitch), TRUE); +} + +void +cc_remote_login_set_enabled (GCancellable *cancellable, + GtkSwitch *gtkswitch) +{ + gchar *command[] = { "pkexec", LIBEXECDIR "/cc-remote-login-helper", NULL, + 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); + return; + } + + if (gtk_switch_get_active (gtkswitch)) + command[2] = "enable"; + else + command[2] = "disable"; + + gtk_widget_set_sensitive (GTK_WIDGET (gtkswitch), FALSE); + + g_spawn_async_with_pipes (NULL, command, NULL, + G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, NULL, + NULL, &pid, NULL, NULL, &std_err, &error); + + callback_data = g_new0 (CallbackData, 1); + callback_data->gtkswitch = gtkswitch; + callback_data->cancellable = cancellable; + + g_child_watch_add (pid, child_watch_func, callback_data); + + if (error) + g_error ("Error running cc-remote-login-helper: %s", error->message); +} diff --git a/panels/sharing/cc-remote-login.h b/panels/sharing/cc-remote-login.h new file mode 100644 index 0000000..c23ddcf --- /dev/null +++ b/panels/sharing/cc-remote-login.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2013 Intel, Inc + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Author: Thomas Wood <thomas.wood@intel.com> + * + */ + +#pragma once + +#include <gtk/gtk.h> + +void cc_remote_login_get_enabled (GCancellable *cancellable, + GtkSwitch *gtkswitch, + GtkWidget *button); +void cc_remote_login_set_enabled (GCancellable *cancellable, + GtkSwitch *gtkswitch); diff --git a/panels/sharing/cc-sharing-networks.c b/panels/sharing/cc-sharing-networks.c new file mode 100644 index 0000000..39ebf76 --- /dev/null +++ b/panels/sharing/cc-sharing-networks.c @@ -0,0 +1,567 @@ +/* + * Copyright (C) 2014 Bastien Nocera <hadess@hadess.net> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#include "config.h" + +#include <gtk/gtk.h> +#include <gio/gio.h> +#include <glib/gi18n.h> + +#include "cc-sharing-networks.h" +#include "org.gnome.SettingsDaemon.Sharing.h" +#include "gsd-sharing-enums.h" +#include "list-box-helper.h" + +struct _CcSharingNetworks { + GtkGrid parent_instance; + + GtkWidget *listbox; + + GtkWidget *current_row; + GtkWidget *current_label; + GtkWidget *current_icon; + GtkWidget *current_switch; + + GtkWidget *no_network_row; + + char *service_name; + GsdSharing *proxy; + CcSharingStatus status; + + GList *networks; /* list of CcSharingNetwork */ +}; + + +G_DEFINE_TYPE (CcSharingNetworks, cc_sharing_networks, GTK_TYPE_GRID) + +enum { + PROP_0, + PROP_PROXY, + PROP_SERVICE_NAME, + PROP_STATUS +}; + +static void cc_sharing_networks_class_init (CcSharingNetworksClass *klass); +static void cc_sharing_networks_init (CcSharingNetworks *self); +static void cc_sharing_networks_finalize (GObject *object); + +static void cc_sharing_update_networks_box (CcSharingNetworks *self); + +typedef struct { + char *uuid; + char *network_name; + char *carrier_type; +} CcSharingNetwork; + +static void +cc_sharing_network_free (gpointer data) +{ + CcSharingNetwork *net = data; + + g_free (net->uuid); + g_free (net->network_name); + g_free (net->carrier_type); + g_free (net); +} + +static void +cc_sharing_networks_update_status (CcSharingNetworks *self) +{ + CcSharingStatus status; + + if (self->networks == NULL) + status = CC_SHARING_STATUS_OFF; + else if (gtk_widget_is_visible (self->current_switch) && + gtk_switch_get_active (GTK_SWITCH (self->current_switch))) + status = CC_SHARING_STATUS_ACTIVE; + else + status = CC_SHARING_STATUS_ENABLED; + + if (status != self->status) { + self->status = status; + g_object_notify (G_OBJECT (self), "status"); + } +} + +static void +cc_sharing_update_networks (CcSharingNetworks *self) +{ + g_autoptr(GVariant) networks = NULL; + char *uuid, *network_name, *carrier_type; + GVariantIter iter; + g_autoptr(GError) error = NULL; + + g_list_free_full (self->networks, cc_sharing_network_free); + self->networks = NULL; + + if (!gsd_sharing_call_list_networks_sync (self->proxy, self->service_name, &networks, NULL, &error)) { + g_warning ("couldn't list networks: %s", error->message); + g_dbus_proxy_set_cached_property (G_DBUS_PROXY (self->proxy), + "SharingStatus", + g_variant_new_uint32 (GSD_SHARING_STATUS_OFFLINE)); + cc_list_box_adjust_scrolling (GTK_LIST_BOX (self->listbox)); + return; + } + + g_variant_iter_init (&iter, networks); + while (g_variant_iter_next (&iter, "(sss)", &uuid, &network_name, &carrier_type)) { + CcSharingNetwork *net; + + net = g_new0 (CcSharingNetwork, 1); + net->uuid = uuid; + net->network_name = network_name; + net->carrier_type = carrier_type; + self->networks = g_list_prepend (self->networks, net); + } + self->networks = g_list_reverse (self->networks); + cc_list_box_adjust_scrolling (GTK_LIST_BOX (self->listbox)); +} + +static void +cc_sharing_networks_remove_network (CcSharingNetworks *self, + GtkWidget *button) +{ + GtkWidget *row; + g_autoptr(GError) error = NULL; + gboolean ret; + const char *uuid; + + row = g_object_get_data (G_OBJECT (button), "row"); + uuid = g_object_get_data (G_OBJECT (row), "uuid"); + + ret = gsd_sharing_call_disable_service_sync (self->proxy, + self->service_name, + uuid, + NULL, + &error); + if (!ret) + g_warning ("Failed to remove service %s: %s", + self->service_name, error->message); + + cc_sharing_update_networks (self); + cc_sharing_update_networks_box (self); +} + +static gboolean +cc_sharing_networks_enable_network (CcSharingNetworks *self, + gboolean state, + GtkSwitch *widget) +{ + g_autoptr(GError) error = NULL; + gboolean ret; + + if (state) { + ret = gsd_sharing_call_enable_service_sync (self->proxy, + self->service_name, + NULL, + &error); + } else { + ret = gsd_sharing_call_disable_service_sync (self->proxy, + self->service_name, + gsd_sharing_get_current_network (self->proxy), + NULL, + &error); + } + + if (ret) { + gtk_switch_set_state (widget, state); + } else { + g_warning ("Failed to %s service %s: %s", state ? "enable" : "disable", + self->service_name, error->message); + g_signal_handlers_block_by_func (widget, + cc_sharing_networks_enable_network, self); + gtk_switch_set_active (widget, !state); + g_signal_handlers_unblock_by_func (widget, + cc_sharing_networks_enable_network, self); + } + + cc_sharing_update_networks (self); + cc_sharing_networks_update_status (self); + + return TRUE; +} + +static GtkWidget * +cc_sharing_networks_new_row (const char *uuid, + const char *network_name, + const char *carrier_type, + CcSharingNetworks *self) +{ + GtkWidget *row, *box, *w; + const char *icon_name; + + row = gtk_list_box_row_new (); + box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); + gtk_widget_show (box); + gtk_container_set_border_width (GTK_CONTAINER (box), 3); + gtk_widget_set_margin_start (box, 6); + gtk_container_add (GTK_CONTAINER (row), box); + + if (g_strcmp0 (carrier_type, "802-11-wireless") == 0) { + icon_name = "network-wireless-offline-symbolic"; + } else if (g_strcmp0 (carrier_type, "802-3-ethernet") == 0) { + icon_name = "network-wired-disconnected-symbolic"; + } else { + icon_name = "network-wired-symbolic"; + } + + w = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU); + gtk_widget_show (w); + gtk_widget_set_margin_end (w, 12); + gtk_container_add (GTK_CONTAINER (box), w); + + /* Label */ + w = gtk_label_new (network_name); + gtk_widget_show (w); + gtk_widget_set_margin_end (w, 12); + gtk_container_add (GTK_CONTAINER (box), w); + + /* Remove button */ + w = gtk_button_new_from_icon_name ("window-close-symbolic", GTK_ICON_SIZE_SMALL_TOOLBAR); + gtk_widget_show (w); + gtk_button_set_relief (GTK_BUTTON (w), GTK_RELIEF_NONE); + gtk_widget_set_margin_top (w, 3); + gtk_widget_set_margin_bottom (w, 3); + gtk_widget_set_margin_end (w, 12); + gtk_widget_set_valign (w, GTK_ALIGN_CENTER); + gtk_box_pack_end (GTK_BOX (box), w, FALSE, FALSE, 0); + g_signal_connect_object (G_OBJECT (w), "clicked", + G_CALLBACK (cc_sharing_networks_remove_network), self, G_CONNECT_SWAPPED); + g_object_set_data (G_OBJECT (w), "row", row); + + g_object_set_data_full (G_OBJECT (row), "uuid", g_strdup (uuid), g_free); + + return row; +} + +static GtkWidget * +cc_sharing_networks_new_current_row (CcSharingNetworks *self) +{ + GtkWidget *row, *box, *w; + + row = gtk_list_box_row_new (); + box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); + gtk_widget_show (box); + gtk_container_set_border_width (GTK_CONTAINER (box), 3); + gtk_widget_set_margin_start (box, 6); + gtk_container_add (GTK_CONTAINER (row), box); + + /* Icon */ + w = gtk_image_new_from_icon_name ("image-missing", GTK_ICON_SIZE_MENU); + gtk_widget_show (w); + gtk_widget_set_margin_end (w, 12); + gtk_container_add (GTK_CONTAINER (box), w); + self->current_icon = w; + + /* Label */ + w = gtk_label_new (""); + gtk_widget_show (w); + gtk_container_add (GTK_CONTAINER (box), w); + gtk_widget_set_margin_end (w, 12); + self->current_label = w; + + w = gtk_switch_new (); + gtk_widget_show (w); + gtk_widget_set_margin_top (w, 3); + gtk_widget_set_margin_bottom (w, 3); + gtk_widget_set_margin_end (w, 12); + gtk_widget_set_valign (w, GTK_ALIGN_CENTER); + gtk_box_pack_end (GTK_BOX (box), w, FALSE, FALSE, 0); + g_signal_connect_object (G_OBJECT (w), "state-set", + G_CALLBACK (cc_sharing_networks_enable_network), self, G_CONNECT_SWAPPED); + self->current_switch = w; + g_object_set_data (G_OBJECT (w), "row", row); + + return row; +} + +static GtkWidget * +cc_sharing_networks_new_no_network_row (CcSharingNetworks *self) +{ + GtkWidget *row, *box, *w; + + row = gtk_list_box_row_new (); + box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); + gtk_widget_show (box); + gtk_container_set_border_width (GTK_CONTAINER (box), 12); + gtk_container_add (GTK_CONTAINER (row), box); + + /* Label */ + w = gtk_label_new (_("No networks selected for sharing")); + gtk_widget_show (w); + gtk_widget_set_hexpand (w, TRUE); + gtk_widget_set_halign (w, GTK_ALIGN_CENTER); + gtk_style_context_add_class (gtk_widget_get_style_context (w), "dim-label"); + gtk_container_add (GTK_CONTAINER (box), w); + + return row; +} + +static void +cc_sharing_update_networks_box (CcSharingNetworks *self) +{ + gboolean current_visible; + const char *current_network; + g_autoptr(GList) children = NULL; + GList *l; + + children = gtk_container_get_children (GTK_CONTAINER (self->listbox)); + for (l = children; l != NULL; l = l->next) { + GtkWidget *row = l->data; + + if (row != self->current_row && + row != self->no_network_row) + gtk_widget_destroy (row); + } + + current_network = gsd_sharing_get_current_network (self->proxy); + + if (current_network != NULL && + !g_str_equal (current_network, "")) { + gboolean available; + const char *carrier_type, *icon_name, *current_network_name; + + gtk_widget_show (self->current_row); + current_visible = TRUE; + + /* Network name */ + g_object_set_data_full (G_OBJECT (self->current_row), + "uuid", g_strdup (current_network), g_free); + current_network_name = gsd_sharing_get_current_network_name (self->proxy); + gtk_label_set_label (GTK_LABEL (self->current_label), current_network_name); + + /* Icon */ + carrier_type = gsd_sharing_get_carrier_type (self->proxy); + if (g_strcmp0 (carrier_type, "802-11-wireless") == 0) { + icon_name = "network-wireless-signal-excellent-symbolic"; + } else if (g_strcmp0 (carrier_type, "802-3-ethernet") == 0) { + icon_name = "network-wired-symbolic"; + } else { + icon_name = "network-wired-symbolic"; + } + gtk_image_set_from_icon_name (GTK_IMAGE (self->current_icon), icon_name, GTK_ICON_SIZE_SMALL_TOOLBAR); + + /* State */ + available = gsd_sharing_get_sharing_status (self->proxy) == GSD_SHARING_STATUS_AVAILABLE; + gtk_widget_set_sensitive (self->current_switch, available); + //FIXME add a subtitle explaining why it's disabled + } else { + gtk_widget_hide (self->current_row); + current_visible = FALSE; + } + + for (l = self->networks; l != NULL; l = l->next) { + CcSharingNetwork *net = l->data; + GtkWidget *row; + + if (g_strcmp0 (net->uuid, current_network) == 0) { + g_signal_handlers_block_by_func (self->current_switch, + cc_sharing_networks_enable_network, self); + gtk_switch_set_state (GTK_SWITCH (self->current_switch), TRUE); + g_signal_handlers_unblock_by_func (self->current_switch, + cc_sharing_networks_enable_network, self); + continue; + } + + row = cc_sharing_networks_new_row (net->uuid, + net->network_name, + net->carrier_type, + self); + gtk_widget_show (row); + gtk_list_box_insert (GTK_LIST_BOX (self->listbox), row, -1); + } + + if (self->networks == NULL && + !current_visible) { + gtk_widget_show (self->no_network_row); + } else { + gtk_widget_hide (self->no_network_row); + } + + cc_sharing_networks_update_status (self); + + cc_list_box_adjust_scrolling (GTK_LIST_BOX (self->listbox)); +} + +static void +current_network_changed (CcSharingNetworks *self) +{ + cc_sharing_update_networks (self); + cc_sharing_update_networks_box (self); +} + +static void +cc_sharing_networks_constructed (GObject *object) +{ + CcSharingNetworks *self; + + G_OBJECT_CLASS (cc_sharing_networks_parent_class)->constructed (object); + + self = CC_SHARING_NETWORKS (object); + + gtk_list_box_set_header_func (GTK_LIST_BOX (self->listbox), + cc_list_box_update_header_func, NULL, + NULL); + + cc_list_box_setup_scrolling (GTK_LIST_BOX (self->listbox), 3); + + self->current_row = cc_sharing_networks_new_current_row (self); + gtk_list_box_insert (GTK_LIST_BOX (self->listbox), self->current_row, -1); + g_object_set_data (G_OBJECT (self), "switch", self->current_switch); + + self->no_network_row = cc_sharing_networks_new_no_network_row (self); + gtk_list_box_insert (GTK_LIST_BOX (self->listbox), self->no_network_row, -1); + + cc_sharing_update_networks (self); + cc_sharing_update_networks_box (self); + + g_signal_connect_object (self->proxy, "notify::current-network", + G_CALLBACK (current_network_changed), self, G_CONNECT_SWAPPED); +} + +static void +cc_sharing_networks_init (CcSharingNetworks *self) +{ + gtk_widget_init_template (GTK_WIDGET (self)); +} + +GtkWidget * +cc_sharing_networks_new (GDBusProxy *proxy, + const char *service_name) +{ + g_return_val_if_fail (GSD_IS_SHARING (proxy), NULL); + g_return_val_if_fail (service_name != NULL, NULL); + + return GTK_WIDGET (g_object_new (CC_TYPE_SHARING_NETWORKS, + "proxy", proxy, + "service-name", service_name, + NULL)); +} + +static void +cc_sharing_networks_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + CcSharingNetworks *self; + + self = CC_SHARING_NETWORKS (object); + + switch (prop_id) { + case PROP_SERVICE_NAME: + self->service_name = g_value_dup_string (value); + break; + case PROP_PROXY: + self->proxy = g_value_dup_object (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +cc_sharing_networks_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + CcSharingNetworks *self; + + self = CC_SHARING_NETWORKS (object); + + switch (prop_id) { + case PROP_STATUS: + g_value_set_uint (value, self->status); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +cc_sharing_networks_finalize (GObject *object) +{ + CcSharingNetworks *self; + + g_return_if_fail (object != NULL); + g_return_if_fail (CC_IS_SHARING_NETWORKS (object)); + + self = CC_SHARING_NETWORKS (object); + + g_return_if_fail (self != NULL); + + g_clear_object (&self->proxy); + g_clear_pointer (&self->service_name, g_free); + + if (self->networks != NULL) { + g_list_free_full (self->networks, cc_sharing_network_free); + self->networks = NULL; + } + + G_OBJECT_CLASS (cc_sharing_networks_parent_class)->finalize (object); +} + + +static void +cc_sharing_networks_class_init (CcSharingNetworksClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + object_class->set_property = cc_sharing_networks_set_property; + object_class->get_property = cc_sharing_networks_get_property; + object_class->finalize = cc_sharing_networks_finalize; + object_class->constructed = cc_sharing_networks_constructed; + + g_object_class_install_property (object_class, + PROP_PROXY, + g_param_spec_object ("proxy", + "proxy", + "proxy", + GSD_TYPE_SHARING_PROXY, + G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property (object_class, + PROP_SERVICE_NAME, + g_param_spec_string ("service-name", + "service-name", + "service-name", + NULL, + G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property (object_class, + PROP_STATUS, + g_param_spec_uint ("status", + "status", + "status", + CC_SHARING_STATUS_UNSET, CC_SHARING_STATUS_ACTIVE + 1, CC_SHARING_STATUS_OFF, + G_PARAM_READABLE)); + + gtk_widget_class_set_template_from_resource (widget_class, + "/org/gnome/control-center/sharing/cc-sharing-networks.ui"); + + gtk_widget_class_bind_template_child (widget_class, CcSharingNetworks, listbox); +} + +/* + * vim: sw=2 ts=8 cindent noai bs=2 + */ diff --git a/panels/sharing/cc-sharing-networks.h b/panels/sharing/cc-sharing-networks.h new file mode 100644 index 0000000..03918ab --- /dev/null +++ b/panels/sharing/cc-sharing-networks.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2014 Bastien Nocera <hadess@hadess.net> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#pragma once + +#include <gtk/gtkgrid.h> + +G_BEGIN_DECLS + +#define CC_TYPE_SHARING_NETWORKS (cc_sharing_networks_get_type ()) +G_DECLARE_FINAL_TYPE (CcSharingNetworks, cc_sharing_networks, CC, SHARING_NETWORKS, GtkGrid) + +typedef enum { + CC_SHARING_STATUS_UNSET, + CC_SHARING_STATUS_OFF, + CC_SHARING_STATUS_ENABLED, + CC_SHARING_STATUS_ACTIVE +} CcSharingStatus; + +GtkWidget * cc_sharing_networks_new (GDBusProxy *proxy, + const char *service_name); + +G_END_DECLS diff --git a/panels/sharing/cc-sharing-networks.ui b/panels/sharing/cc-sharing-networks.ui new file mode 100644 index 0000000..d646d32 --- /dev/null +++ b/panels/sharing/cc-sharing-networks.ui @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Generated with glade 3.18.1 --> +<interface> + <requires lib="gtk+" version="3.10"/> + <template class="CcSharingNetworks" parent="GtkGrid"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="margin_start">0</property> + <property name="margin_end">0</property> + <property name="margin_top">12</property> + <property name="margin_bottom">12</property> + <property name="row_spacing">12</property> + <property name="column_spacing">6</property> + <child> + <object class="GtkLabel" id="label15"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">Networks</property> + <attributes> + <attribute name="weight" value="bold"/> + </attributes> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">0</property> + <property name="width">2</property> + </packing> + </child> + <child> + <object class="GtkFrame" id="shared-networks-frame"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="hexpand">True</property> + <property name="shadow_type">in</property> + <child> + <object class="GtkListBox" id="listbox"> + <property name="visible">True</property> + <property name="can_focus">True</property> + </object> + </child> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">2</property> + <property name="width">2</property> + </packing> + </child> + <child> + <placeholder/> + </child> + </template> +</interface> diff --git a/panels/sharing/cc-sharing-panel.c b/panels/sharing/cc-sharing-panel.c new file mode 100644 index 0000000..0cdafe6 --- /dev/null +++ b/panels/sharing/cc-sharing-panel.c @@ -0,0 +1,1230 @@ +/* + * Copyright (C) 2013 Intel, Inc + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Author: Thomas Wood <thomas.wood@intel.com> + * + */ + +#include "cc-sharing-panel.h" +#include "cc-hostname-entry.h" + +#include "list-box-helper.h" +#include "cc-sharing-resources.h" +#include "cc-remote-login.h" +#include "file-share-properties.h" +#include "cc-media-sharing.h" +#include "cc-sharing-networks.h" +#include "cc-sharing-switch.h" +#include "cc-gnome-remote-desktop.h" +#include "org.gnome.SettingsDaemon.Sharing.h" + +#ifdef GDK_WINDOWING_WAYLAND +#include <gdk/gdkwayland.h> +#endif +#include <glib/gi18n.h> +#include <config.h> + +static void cc_sharing_panel_setup_label_with_hostname (CcSharingPanel *self, GtkWidget *label); +static GtkWidget *cc_sharing_panel_new_media_sharing_row (const char *uri_or_path, + CcSharingPanel *self); + +#define FILE_SHARING_SCHEMA_ID "org.gnome.desktop.file-sharing" +#define GNOME_REMOTE_DESKTOP_SCHEMA_ID "org.gnome.desktop.remote-desktop" +#define GNOME_REMOTE_DESKTOP_VNC_SCHEMA_ID "org.gnome.desktop.remote-desktop.vnc" + +typedef enum +{ + GRD_VNC_AUTH_METHOD_PROMPT, + GRD_VNC_AUTH_METHOD_PASSWORD +} GrdVncAuthMethod; + +struct _CcSharingPanel +{ + CcPanel parent_instance; + + GtkWidget *approve_connections_radiobutton; + GtkWidget *hostname_entry; + GtkWidget *main_list_box; + GtkWidget *master_switch; + GtkWidget *media_sharing_dialog; + GtkWidget *media_sharing_headerbar; + GtkWidget *media_sharing_row; + GtkWidget *media_sharing_switch; + GtkWidget *personal_file_sharing_dialog; + GtkWidget *personal_file_sharing_grid; + GtkWidget *personal_file_sharing_headerbar; + GtkWidget *personal_file_sharing_label; + GtkWidget *personal_file_sharing_password_entry; + GtkWidget *personal_file_sharing_password_label; + GtkWidget *personal_file_sharing_require_password_switch; + GtkWidget *personal_file_sharing_row; + GtkWidget *personal_file_sharing_switch; + GtkWidget *password_grid; + GtkWidget *remote_control_box; + GtkWidget *remote_control_checkbutton; + GtkWidget *remote_control_password_entry; + GtkWidget *remote_login_dialog; + GtkWidget *remote_login_label; + GtkWidget *remote_login_row; + GtkWidget *remote_login_switch; + GtkWidget *require_password_radiobutton; + GtkWidget *screen_sharing_dialog; + GtkWidget *screen_sharing_grid; + GtkWidget *screen_sharing_headerbar; + GtkWidget *screen_sharing_label; + GtkWidget *screen_sharing_row; + GtkWidget *screen_sharing_switch; + GtkWidget *shared_folders_grid; + GtkWidget *shared_folders_listbox; + GtkWidget *show_password_checkbutton; + + GDBusProxy *sharing_proxy; + + guint remote_desktop_name_watch; +}; + +CC_PANEL_REGISTER (CcSharingPanel, cc_sharing_panel) + +#define OFF_IF_VISIBLE(x, y) { if (gtk_widget_is_visible(x) && (y) != NULL && gtk_widget_is_sensitive(y)) gtk_switch_set_active (GTK_SWITCH(y), FALSE); } + +static void +cc_sharing_panel_master_switch_notify (CcSharingPanel *self) +{ + gboolean active; + + active = gtk_switch_get_active (GTK_SWITCH (self->master_switch)); + + if (!active) + { + /* disable all services if the master switch is not active */ + OFF_IF_VISIBLE(self->media_sharing_row, self->media_sharing_switch); + OFF_IF_VISIBLE(self->personal_file_sharing_row, self->personal_file_sharing_switch); + OFF_IF_VISIBLE(self->screen_sharing_row, self->screen_sharing_switch); + + gtk_switch_set_active (GTK_SWITCH (self->remote_login_switch), FALSE); + } + + gtk_widget_set_sensitive (self->main_list_box, active); +} + +static void +cc_sharing_panel_constructed (GObject *object) +{ + CcSharingPanel *self = CC_SHARING_PANEL (object); + + G_OBJECT_CLASS (cc_sharing_panel_parent_class)->constructed (object); + + /* add the master switch */ + cc_shell_embed_widget_in_header (cc_panel_get_shell (CC_PANEL (object)), + gtk_widget_get_parent (self->master_switch), + GTK_POS_RIGHT); +} + +static void +cc_sharing_panel_dispose (GObject *object) +{ + CcSharingPanel *self = CC_SHARING_PANEL (object); + + if (self->remote_desktop_name_watch) + g_bus_unwatch_name (self->remote_desktop_name_watch); + self->remote_desktop_name_watch = 0; + + if (self->media_sharing_dialog) + { + gtk_widget_destroy (self->media_sharing_dialog); + self->media_sharing_dialog = NULL; + } + + if (self->personal_file_sharing_dialog) + { + gtk_widget_destroy (self->personal_file_sharing_dialog); + self->personal_file_sharing_dialog = NULL; + } + + if (self->remote_login_dialog) + { + gtk_widget_destroy (self->remote_login_dialog); + self->remote_login_dialog = NULL; + } + + if (self->screen_sharing_dialog) + { + gtk_widget_destroy (self->screen_sharing_dialog); + self->screen_sharing_dialog = NULL; + } + + g_clear_object (&self->sharing_proxy); + + G_OBJECT_CLASS (cc_sharing_panel_parent_class)->dispose (object); +} + +static const char * +cc_sharing_panel_get_help_uri (CcPanel *panel) +{ + return "help:gnome-help/prefs-sharing"; +} + +static void +cc_sharing_panel_class_init (CcSharingPanelClass *klass) +{ + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + CcPanelClass *panel_class = CC_PANEL_CLASS (klass); + + object_class->constructed = cc_sharing_panel_constructed; + object_class->dispose = cc_sharing_panel_dispose; + + panel_class->get_help_uri = cc_sharing_panel_get_help_uri; + + gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/sharing/cc-sharing-panel.ui"); + + gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, approve_connections_radiobutton); + gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, hostname_entry); + gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, screen_sharing_grid); + gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, shared_folders_grid); + gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, main_list_box); + gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, media_sharing_dialog); + gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, media_sharing_headerbar); + gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, media_sharing_row); + gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, personal_file_sharing_dialog); + gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, personal_file_sharing_grid); + gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, personal_file_sharing_headerbar); + gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, personal_file_sharing_label); + gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, personal_file_sharing_password_entry); + gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, personal_file_sharing_password_label); + gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, personal_file_sharing_require_password_switch); + gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, personal_file_sharing_row); + gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, password_grid); + gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, remote_control_box); + gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, remote_control_checkbutton); + gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, remote_control_password_entry); + gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, remote_login_dialog); + gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, remote_login_label); + gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, remote_login_row); + gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, remote_login_switch); + gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, require_password_radiobutton); + gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, screen_sharing_dialog); + gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, screen_sharing_headerbar); + gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, screen_sharing_label); + gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, screen_sharing_row); + gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, shared_folders_listbox); + gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, show_password_checkbutton); + + g_type_ensure (CC_TYPE_HOSTNAME_ENTRY); +} + +static void +cc_sharing_panel_run_dialog (CcSharingPanel *self, + GtkWidget *dialog) +{ + GtkWidget *parent; + + /* ensure labels with the hostname are updated if the hostname has changed */ + cc_sharing_panel_setup_label_with_hostname (self, + self->screen_sharing_label); + cc_sharing_panel_setup_label_with_hostname (self, self->remote_login_label); + cc_sharing_panel_setup_label_with_hostname (self, + self->personal_file_sharing_label); + + + parent = cc_shell_get_toplevel (cc_panel_get_shell (CC_PANEL (self))); + + gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent)); + gtk_dialog_run (GTK_DIALOG (dialog)); +} + +static void +cc_sharing_panel_main_list_box_row_activated (CcSharingPanel *self, + GtkListBoxRow *row) +{ + GtkWidget *dialog; + + if (row == GTK_LIST_BOX_ROW (self->media_sharing_row)) + dialog = self->media_sharing_dialog; + else if (row == GTK_LIST_BOX_ROW (self->personal_file_sharing_row)) + dialog = self->personal_file_sharing_dialog; + else if (row == GTK_LIST_BOX_ROW (self->remote_login_row)) + dialog = self->remote_login_dialog; + else if (row == GTK_LIST_BOX_ROW (self->screen_sharing_row)) + dialog = self->screen_sharing_dialog; + else + return; + + gtk_list_box_select_row (GTK_LIST_BOX (self->main_list_box), NULL); + + cc_sharing_panel_run_dialog (self, dialog); +} + +static gboolean +cc_sharing_panel_switch_to_label_transform_func (GBinding *binding, + const GValue *source_value, + GValue *target_value, + CcSharingPanel *self) +{ + gboolean active; + + if (!G_VALUE_HOLDS_BOOLEAN (source_value)) + return FALSE; + + if (!G_VALUE_HOLDS_STRING (target_value)) + return FALSE; + + active = g_value_get_boolean (source_value); + + if (active) + g_value_set_string (target_value, C_("service is enabled", "On")); + else + g_value_set_string (target_value, C_("service is disabled", "Off")); + + /* ensure the master switch is active if one of the services is active */ + if (active) + gtk_switch_set_active (GTK_SWITCH (self->master_switch), TRUE); + + return TRUE; +} + +static gboolean +cc_sharing_panel_networks_to_label_transform_func (GBinding *binding, + const GValue *source_value, + GValue *target_value, + CcSharingPanel *self) +{ + CcSharingStatus status; + + if (!G_VALUE_HOLDS_UINT (source_value)) + return FALSE; + + if (!G_VALUE_HOLDS_STRING (target_value)) + return FALSE; + + status = g_value_get_uint (source_value); + + switch (status) { + case CC_SHARING_STATUS_OFF: + g_value_set_string (target_value, C_("service is disabled", "Off")); + break; + case CC_SHARING_STATUS_ENABLED: + g_value_set_string (target_value, C_("service is enabled", "Enabled")); + break; + case CC_SHARING_STATUS_ACTIVE: + g_value_set_string (target_value, C_("service is active", "Active")); + break; + default: + return FALSE; + } + + /* ensure the master switch is active if one of the services is active */ + if (status != CC_SHARING_STATUS_OFF) + gtk_switch_set_active (GTK_SWITCH (self->master_switch), TRUE); + + return TRUE; +} + +static void +cc_sharing_panel_bind_switch_to_label (CcSharingPanel *self, + GtkWidget *gtkswitch, + GtkWidget *row) +{ + g_object_bind_property_full (gtkswitch, "active", row, "secondary-label", + G_BINDING_SYNC_CREATE, + (GBindingTransformFunc) cc_sharing_panel_switch_to_label_transform_func, + NULL, self, NULL); +} + +static void +cc_sharing_panel_bind_networks_to_label (CcSharingPanel *self, + GtkWidget *networks, + GtkWidget *list_row) +{ + g_object_bind_property_full (networks, "status", list_row, "secondary-label", + G_BINDING_SYNC_CREATE, + (GBindingTransformFunc) cc_sharing_panel_networks_to_label_transform_func, + NULL, self, NULL); +} + +static void +cc_sharing_panel_bind_switch_to_widgets (GtkWidget *gtkswitch, + GtkWidget *first_widget, + ...) +{ + va_list w; + GtkWidget *widget; + + va_start (w, first_widget); + + g_object_bind_property (gtkswitch, "active", first_widget, + "sensitive", G_BINDING_SYNC_CREATE); + + while ((widget = va_arg (w, GtkWidget*))) + { + g_object_bind_property (gtkswitch, "active", widget, + "sensitive", G_BINDING_SYNC_CREATE); + } + + va_end (w); +} + +static void +cc_sharing_panel_add_folder (CcSharingPanel *self, + GtkListBoxRow *row) +{ + GtkWidget *dialog; + g_autofree gchar *folder = NULL; + gboolean matching = FALSE; + GList *rows, *l; + + if (!GPOINTER_TO_INT (g_object_get_data (G_OBJECT (row), "is-add"))) + return; + + dialog = gtk_file_chooser_dialog_new (_("Choose a Folder"), + GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self->shared_folders_listbox))), + GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, + _("_Cancel"), GTK_RESPONSE_CANCEL, + _("_Open"), GTK_RESPONSE_ACCEPT, + NULL); + gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (dialog), FALSE); + if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_ACCEPT) + goto bail; + + gtk_widget_hide (dialog); + + rows = gtk_container_get_children (GTK_CONTAINER (self->shared_folders_listbox)); + + folder = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog)); + if (!folder || g_str_equal (folder, "")) + goto bail; + + g_debug ("Trying to add %s", folder); + + for (l = rows; l != NULL; l = l->next) + { + const char *string; + + string = g_object_get_data (G_OBJECT (l->data), "path"); + matching = (g_strcmp0 (string, folder) == 0); + + if (matching) + { + g_debug ("Found a duplicate for %s", folder); + break; + } + } + + if (!matching) + { + GtkWidget *row; + int i; + + row = cc_sharing_panel_new_media_sharing_row (folder, self); + i = g_list_length (rows); + gtk_list_box_insert (GTK_LIST_BOX (self->shared_folders_listbox), row, i - 1); + gtk_widget_set_visible (row, TRUE); + } + cc_list_box_adjust_scrolling (GTK_LIST_BOX (self->shared_folders_listbox)); + +bail: + gtk_widget_destroy (dialog); +} + +static void +cc_sharing_panel_remove_folder (CcSharingPanel *self, + GtkButton *button) +{ + GtkWidget *row; + + row = g_object_get_data (G_OBJECT (button), "row"); + gtk_widget_destroy (row); + cc_list_box_adjust_scrolling (GTK_LIST_BOX (self->shared_folders_listbox)); +} + +static void +cc_sharing_panel_media_sharing_dialog_response (CcSharingPanel *self, + gint reponse_id) +{ + g_autoptr(GPtrArray) folders = NULL; + GtkWidget *box; + GList *rows, *l; + + box = self->shared_folders_listbox; + rows = gtk_container_get_children (GTK_CONTAINER (box)); + folders = g_ptr_array_new_with_free_func (g_free); + + for (l = rows; l != NULL; l = l->next) + { + const char *folder; + + folder = g_object_get_data (G_OBJECT (l->data), "path"); + if (folder == NULL) + continue; + g_ptr_array_add (folders, g_strdup (folder)); + } + + g_ptr_array_add (folders, NULL); + + cc_media_sharing_set_preferences ((gchar **) folders->pdata); +} + +#define ICON_NAME_FOLDER "folder-symbolic" +#define ICON_NAME_FOLDER_DESKTOP "user-desktop-symbolic" +#define ICON_NAME_FOLDER_DOCUMENTS "folder-documents-symbolic" +#define ICON_NAME_FOLDER_DOWNLOAD "folder-download-symbolic" +#define ICON_NAME_FOLDER_MUSIC "folder-music-symbolic" +#define ICON_NAME_FOLDER_PICTURES "folder-pictures-symbolic" +#define ICON_NAME_FOLDER_PUBLIC_SHARE "folder-publicshare-symbolic" +#define ICON_NAME_FOLDER_TEMPLATES "folder-templates-symbolic" +#define ICON_NAME_FOLDER_VIDEOS "folder-videos-symbolic" +#define ICON_NAME_FOLDER_SAVED_SEARCH "folder-saved-search-symbolic" + +static GIcon * +special_directory_get_gicon (GUserDirectory directory) +{ +#define ICON_CASE(x) \ + case G_USER_DIRECTORY_ ## x: \ + return g_themed_icon_new_with_default_fallbacks (ICON_NAME_FOLDER_ ## x); + + switch (directory) + { + ICON_CASE (DESKTOP); + ICON_CASE (DOCUMENTS); + ICON_CASE (DOWNLOAD); + ICON_CASE (MUSIC); + ICON_CASE (PICTURES); + ICON_CASE (PUBLIC_SHARE); + ICON_CASE (TEMPLATES); + ICON_CASE (VIDEOS); + + default: + return g_themed_icon_new_with_default_fallbacks (ICON_NAME_FOLDER); + } + +#undef ICON_CASE +} + +static GtkWidget * +cc_sharing_panel_new_media_sharing_row (const char *uri_or_path, + CcSharingPanel *self) +{ + GtkWidget *row, *box, *w; + GUserDirectory dir = G_USER_N_DIRECTORIES; + g_autoptr(GIcon) icon = NULL; + guint i; + 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); + + row = gtk_list_box_row_new (); + box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); + gtk_widget_show (box); + gtk_container_set_border_width (GTK_CONTAINER (box), 3); + gtk_widget_set_margin_start (box, 6); + gtk_container_add (GTK_CONTAINER (row), box); + + /* Find the icon and create it */ + for (i = 0; i < G_USER_N_DIRECTORIES; i++) + { + if (g_strcmp0 (path, g_get_user_special_dir (i)) == 0) + { + dir = i; + break; + } + } + + icon = special_directory_get_gicon (dir); + w = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_MENU); + gtk_widget_show (w); + gtk_widget_set_margin_end (w, 12); + gtk_container_add (GTK_CONTAINER (box), w); + + /* Label */ + basename = g_filename_display_basename (path); + w = gtk_label_new (basename); + gtk_widget_show (w); + gtk_container_add (GTK_CONTAINER (box), w); + + /* Remove button */ + w = gtk_button_new_from_icon_name ("window-close-symbolic", GTK_ICON_SIZE_SMALL_TOOLBAR); + gtk_widget_show (w); + gtk_button_set_relief (GTK_BUTTON (w), GTK_RELIEF_NONE); + gtk_widget_set_margin_top (w, 3); + gtk_widget_set_margin_bottom (w, 3); + gtk_widget_set_margin_end (w, 12); + gtk_widget_set_valign (w, GTK_ALIGN_CENTER); + gtk_box_pack_end (GTK_BOX (box), w, FALSE, FALSE, 0); + g_signal_connect_object (G_OBJECT (w), "clicked", + G_CALLBACK (cc_sharing_panel_remove_folder), self, G_CONNECT_SWAPPED); + g_object_set_data (G_OBJECT (w), "row", row); + + g_object_set_data_full (G_OBJECT (row), "path", g_steal_pointer (&path), g_free); + + return row; +} + +static GtkWidget * +cc_sharing_panel_new_add_media_sharing_row (CcSharingPanel *self) +{ + GtkWidget *row, *box, *w; + + row = gtk_list_box_row_new (); + box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); + gtk_widget_show (box); + gtk_container_set_border_width (GTK_CONTAINER (box), 3); + gtk_container_add (GTK_CONTAINER (row), box); + + w = gtk_image_new_from_icon_name ("list-add-symbolic", GTK_ICON_SIZE_SMALL_TOOLBAR); + gtk_widget_show (w); + gtk_container_add (GTK_CONTAINER (box), w); + gtk_widget_set_hexpand (w, TRUE); + gtk_widget_set_margin_top (w, 6); + gtk_widget_set_margin_bottom (w, 6); + + g_object_set_data (G_OBJECT (w), "row", row); + + g_object_set_data (G_OBJECT (row), "is-add", GINT_TO_POINTER (1)); + + return row; +} + +static void +cc_sharing_panel_setup_media_sharing_dialog (CcSharingPanel *self) +{ + g_auto(GStrv) folders = NULL; + GStrv list; + GtkWidget *row, *networks, *w; + g_autofree gchar *path = NULL; + + path = g_find_program_in_path ("rygel"); + if (path == NULL) + { + gtk_widget_hide (self->media_sharing_row); + return; + } + + g_signal_connect_object (self->media_sharing_dialog, "response", + G_CALLBACK (cc_sharing_panel_media_sharing_dialog_response), + self, G_CONNECT_SWAPPED); + + cc_media_sharing_get_preferences (&folders); + + gtk_list_box_set_header_func (GTK_LIST_BOX (self->shared_folders_listbox), + cc_list_box_update_header_func, NULL, + NULL); + cc_list_box_setup_scrolling (GTK_LIST_BOX (self->shared_folders_listbox), 3); + + list = folders; + while (list && *list) + { + row = cc_sharing_panel_new_media_sharing_row (*list, self); + gtk_widget_show (row); + gtk_list_box_insert (GTK_LIST_BOX (self->shared_folders_listbox), row, -1); + list++; + } + + row = cc_sharing_panel_new_add_media_sharing_row (self); + gtk_widget_show (row); + gtk_list_box_insert (GTK_LIST_BOX (self->shared_folders_listbox), row, -1); + + cc_list_box_adjust_scrolling (GTK_LIST_BOX (self->shared_folders_listbox)); + + g_signal_connect_object (self->shared_folders_listbox, "row-activated", + G_CALLBACK (cc_sharing_panel_add_folder), self, G_CONNECT_SWAPPED); + + networks = cc_sharing_networks_new (self->sharing_proxy, "rygel"); + gtk_grid_attach (GTK_GRID (self->shared_folders_grid), networks, 0, 4, 2, 1); + gtk_widget_show (networks); + + w = cc_sharing_switch_new (networks); + gtk_header_bar_pack_start (GTK_HEADER_BAR (self->media_sharing_headerbar), w); + self->media_sharing_switch = w; + + cc_sharing_panel_bind_networks_to_label (self, networks, + self->media_sharing_row); +} + +static gboolean +cc_sharing_panel_label_activate_link (GtkLabel *label, + gchar *uri, + GtkMenu *menu) +{ + gtk_menu_popup_at_pointer (menu, NULL); + + g_object_set_data_full (G_OBJECT (menu), "uri-text", g_strdup (uri), g_free); + + return TRUE; +} + +static void +copy_uri_to_clipboard (GtkMenuItem *item, + GtkMenu *menu) +{ + GtkClipboard *clipboard; + const gchar *text; + + text = g_object_get_data (G_OBJECT (menu), "uri-text"); + + clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD); + gtk_clipboard_set_text (clipboard, text, -1); +} + +static void +cc_sharing_panel_setup_label (CcSharingPanel *self, + GtkWidget *label, + const gchar *hostname) +{ + g_autofree gchar *text = NULL; + + if (label == self->personal_file_sharing_label) + { + g_autofree gchar *url = g_strdup_printf ("<a href=\"dav://%s\">dav://%s</a>", hostname, hostname); + /* TRANSLATORS: %s is replaced with a link to a dav://<hostname> URL */ + text = g_strdup_printf (_("File Sharing allows you to share your Public folder with others on your current network using: %s"), url); + } + else if (label == self->remote_login_label) + { + g_autofree gchar *command = g_strdup_printf ("<a href=\"ssh %s\">ssh %s</a>", hostname, hostname); + /* TRANSLATORS: %s is replaced with a link to a "ssh <hostname>" command to run */ + text = g_strdup_printf (_("When remote login is enabled, remote users can connect using the Secure Shell command:\n%s"), command); + } + else if (label == self->screen_sharing_label) + { + g_autofree gchar *url = g_strdup_printf ("<a href=\"vnc://%s\">vnc://%s</a>", hostname, hostname); + /* TRANSLATORS: %s is replaced with a link to a vnc://<hostname> URL */ + text = g_strdup_printf (_("Screen sharing allows remote users to view or control your screen by connecting to %s"), url); + } + else + g_assert_not_reached (); + + gtk_label_set_label (GTK_LABEL (label), text); +} + +typedef struct +{ + CcSharingPanel *panel; + GtkWidget *label; +} GetHostNameData; + +G_DEFINE_AUTOPTR_CLEANUP_FUNC (GetHostNameData, g_free); + +static void +cc_sharing_panel_get_host_name_fqdn_done (GObject *object, + GAsyncResult *res, + gpointer user_data) +{ + 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); + + if (variant == NULL) + { + /* Avahi service may not be available */ + g_debug ("Error calling GetHostNameFqdn: %s", error->message); + + if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + { + 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); + } + + return; + } + + g_variant_get (variant, "(&s)", &fqdn); + + cc_sharing_panel_setup_label (data->panel, data->label, fqdn); +} + +static void +cc_sharing_panel_bus_ready (GObject *object, + GAsyncResult *res, + gpointer user_data) +{ + g_autoptr(GDBusConnection) connection = NULL; + g_autoptr(GetHostNameData) data = user_data; + g_autoptr(GError) error = NULL; + + connection = g_bus_get_finish (res, &error); + + if (connection == NULL) + { + g_warning ("Could not connect to system bus: %s", error->message); + + if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + { + 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); + } + + return; + } + + g_dbus_connection_call (connection, + "org.freedesktop.Avahi", + "/", + "org.freedesktop.Avahi.Server", + "GetHostNameFqdn", + NULL, + (GVariantType*)"(s)", + G_DBUS_CALL_FLAGS_NONE, + -1, + cc_panel_get_cancellable (CC_PANEL (data->panel)), + cc_sharing_panel_get_host_name_fqdn_done, + data); + g_steal_pointer (&data); +} + + +static void +cc_sharing_panel_setup_label_with_hostname (CcSharingPanel *self, + GtkWidget *label) +{ + GtkWidget *menu; + GtkWidget *menu_item; + GetHostNameData *get_hostname_data; + + /* create the menu */ + menu = gtk_menu_new (); + + menu_item = gtk_menu_item_new_with_label (_("Copy")); + gtk_widget_show (menu_item); + + g_signal_connect (menu_item, "activate", G_CALLBACK (copy_uri_to_clipboard), + menu); + + gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item); + + /* show the menu when the link is activated */ + g_signal_connect (label, "activate-link", + G_CALLBACK (cc_sharing_panel_label_activate_link), menu); + + /* destroy the menu when the label is destroyed */ + g_signal_connect_swapped (label, "destroy", G_CALLBACK (gtk_widget_destroy), + menu); + + + /* set the hostname */ + get_hostname_data = g_new (GetHostNameData, 1); + get_hostname_data->panel = self; + get_hostname_data->label = label; + g_bus_get (G_BUS_TYPE_SYSTEM, + cc_panel_get_cancellable (CC_PANEL (self)), + cc_sharing_panel_bus_ready, + get_hostname_data); +} + +static gboolean +file_sharing_get_require_password (GValue *value, + GVariant *variant, + gpointer user_data) +{ + if (g_str_equal (g_variant_get_string (variant, NULL), "always")) + g_value_set_boolean (value, TRUE); + else + g_value_set_boolean (value, FALSE); + + return TRUE; +} + +static GVariant * +file_sharing_set_require_password (const GValue *value, + const GVariantType *type, + gpointer user_data) +{ + if (g_value_get_boolean (value)) + return g_variant_new_string ("always"); + else + return g_variant_new_string ("never"); +} + +static void +file_sharing_password_changed (GtkEntry *entry) +{ + file_share_write_out_password (gtk_entry_get_text (entry)); +} + +static void +cc_sharing_panel_setup_personal_file_sharing_dialog (CcSharingPanel *self) +{ + GSettings *settings; + GtkWidget *networks, *w; + + cc_sharing_panel_bind_switch_to_widgets (self->personal_file_sharing_require_password_switch, + self->personal_file_sharing_password_entry, + self->personal_file_sharing_password_label, + NULL); + + cc_sharing_panel_setup_label_with_hostname (self, + self->personal_file_sharing_label); + + /* the password cannot be read, so just make sure the entry is not empty */ + gtk_entry_set_text (GTK_ENTRY (self->personal_file_sharing_password_entry), + "password"); + + settings = g_settings_new (FILE_SHARING_SCHEMA_ID); + g_settings_bind_with_mapping (settings, "require-password", + self->personal_file_sharing_require_password_switch, + "active", + G_SETTINGS_BIND_DEFAULT, + file_sharing_get_require_password, + file_sharing_set_require_password, NULL, NULL); + + g_signal_connect (self->personal_file_sharing_password_entry, + "notify::text", G_CALLBACK (file_sharing_password_changed), + NULL); + + networks = cc_sharing_networks_new (self->sharing_proxy, "gnome-user-share-webdav"); + gtk_grid_attach (GTK_GRID (self->personal_file_sharing_grid), networks, 0, 3, 2, 1); + gtk_widget_show (networks); + + w = cc_sharing_switch_new (networks); + gtk_header_bar_pack_start (GTK_HEADER_BAR (self->personal_file_sharing_headerbar), w); + self->personal_file_sharing_switch = w; + + cc_sharing_panel_bind_networks_to_label (self, + networks, + self->personal_file_sharing_row); +} + +static void +remote_login_switch_activate (CcSharingPanel *self) +{ + cc_remote_login_set_enabled (cc_panel_get_cancellable (CC_PANEL (self)), GTK_SWITCH (self->remote_login_switch)); +} + +static void +cc_sharing_panel_setup_remote_login_dialog (CcSharingPanel *self) +{ + cc_sharing_panel_bind_switch_to_label (self, self->remote_login_switch, + self->remote_login_row); + + cc_sharing_panel_setup_label_with_hostname (self, self->remote_login_label); + + g_signal_connect_object (self->remote_login_switch, "notify::active", + G_CALLBACK (remote_login_switch_activate), self, G_CONNECT_SWAPPED); + gtk_widget_set_sensitive (self->remote_login_switch, FALSE); + + cc_remote_login_get_enabled (cc_panel_get_cancellable (CC_PANEL (self)), + GTK_SWITCH (self->remote_login_switch), + self->remote_login_row); +} + +static gboolean +cc_sharing_panel_check_schema_available (CcSharingPanel *self, + const gchar *schema_id) +{ + GSettingsSchemaSource *source; + g_autoptr(GSettingsSchema) schema = NULL; + + source = g_settings_schema_source_get_default (); + if (!source) + return FALSE; + + schema = g_settings_schema_source_lookup (source, schema_id, TRUE); + if (!schema) + return FALSE; + + return TRUE; +} + +static void +screen_sharing_show_cb (CcSharingPanel *self) +{ + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->show_password_checkbutton), + FALSE); +} + +static void +screen_sharing_hide_cb (CcSharingPanel *self) +{ + GtkToggleButton *ac_radio; + GtkEntry *pw_entry; + const gchar *password; + + ac_radio = GTK_TOGGLE_BUTTON (self->approve_connections_radiobutton); + pw_entry = GTK_ENTRY (self->remote_control_password_entry); + password = gtk_entry_get_text (pw_entry); + + if (password == NULL || *password == '\0') + gtk_toggle_button_set_active (ac_radio, TRUE); +} + +#define MAX_PASSWORD_SIZE 8 +static void +screen_sharing_password_insert_text_cb (CcSharingPanel *self, + gchar *new_text, + gint new_text_length, + gpointer position) +{ + int l, available_size; + + l = gtk_entry_buffer_get_bytes (gtk_entry_get_buffer (GTK_ENTRY (self->remote_control_password_entry))); + + if (l + new_text_length <= MAX_PASSWORD_SIZE) + return; + + g_signal_stop_emission_by_name (self->remote_control_password_entry, "insert-text"); + gtk_widget_error_bell (GTK_WIDGET (self->remote_control_password_entry)); + + available_size = g_utf8_strlen (new_text, MAX_PASSWORD_SIZE - l); + if (available_size == 0) + return; + + g_signal_handlers_block_by_func (self->remote_control_password_entry, + (gpointer) screen_sharing_password_insert_text_cb, + self); + gtk_editable_insert_text (GTK_EDITABLE (self->remote_control_password_entry), new_text, available_size, position); + g_signal_handlers_unblock_by_func (self->remote_control_password_entry, + (gpointer) screen_sharing_password_insert_text_cb, + self); +} +#undef MAX_PASSWORD_SIZE + +static void +on_vnc_password_entry_notify_text (CcSharingPanel *self) +{ + cc_grd_store_vnc_password (gtk_entry_get_text (GTK_ENTRY (self->remote_control_password_entry)), cc_panel_get_cancellable (CC_PANEL (self))); +} + +static void +cc_sharing_panel_setup_screen_sharing_dialog_gnome_remote_desktop (CcSharingPanel *self) +{ + g_autofree gchar *password = NULL; + g_autoptr(GSettings) vnc_settings = NULL; + GtkWidget *networks, *w; + + cc_sharing_panel_bind_switch_to_widgets (self->require_password_radiobutton, self->password_grid, NULL); + + cc_sharing_panel_setup_label_with_hostname (self, self->screen_sharing_label); + + g_object_bind_property (self->show_password_checkbutton, + "active", + self->remote_control_password_entry, + "visibility", + G_BINDING_SYNC_CREATE); + + /* make sure the password entry is hidden by default */ + g_signal_connect_object (self->screen_sharing_dialog, + "show", + G_CALLBACK (screen_sharing_show_cb), + self, + G_CONNECT_SWAPPED); + + g_signal_connect_object (self->screen_sharing_dialog, + "hide", + G_CALLBACK (screen_sharing_hide_cb), + self, + G_CONNECT_SWAPPED); + + password = cc_grd_lookup_vnc_password (cc_panel_get_cancellable (CC_PANEL (self))); + if (password != NULL) + gtk_entry_set_text (GTK_ENTRY (self->remote_control_password_entry), password); + + /* accept at most 8 bytes in password entry */ + g_signal_connect_object (self->remote_control_password_entry, + "insert-text", + G_CALLBACK (screen_sharing_password_insert_text_cb), + self, + G_CONNECT_SWAPPED); + + /* Bind settings to widgets */ + vnc_settings = g_settings_new (GNOME_REMOTE_DESKTOP_VNC_SCHEMA_ID); + + g_settings_bind (vnc_settings, + "view-only", + self->remote_control_checkbutton, + "active", + G_SETTINGS_BIND_DEFAULT | G_SETTINGS_BIND_INVERT_BOOLEAN); + + g_settings_bind_with_mapping (vnc_settings, + "auth-method", + self->approve_connections_radiobutton, + "active", + G_SETTINGS_BIND_DEFAULT, + cc_grd_get_is_auth_method_prompt, + cc_grd_set_is_auth_method_prompt, + NULL, + NULL); + + g_settings_bind_with_mapping (vnc_settings, + "auth-method", + self->require_password_radiobutton, + "active", + G_SETTINGS_BIND_DEFAULT, + cc_grd_get_is_auth_method_password, + cc_grd_set_is_auth_method_password, + NULL, + NULL); + + g_signal_connect_object (self->remote_control_password_entry, + "notify::text", + G_CALLBACK (on_vnc_password_entry_notify_text), + self, + G_CONNECT_SWAPPED); + + networks = cc_sharing_networks_new (self->sharing_proxy, "gnome-remote-desktop"); + gtk_box_pack_end (GTK_BOX (self->remote_control_box), networks, TRUE, TRUE, 0); + gtk_widget_show (networks); + + w = cc_sharing_switch_new (networks); + gtk_header_bar_pack_start (GTK_HEADER_BAR (self->screen_sharing_headerbar), w); + self->screen_sharing_switch = w; + + cc_sharing_panel_bind_networks_to_label (self, networks, + self->screen_sharing_row); +} + +static void +remote_desktop_name_appeared (GDBusConnection *connection, + const gchar *name, + const gchar *name_owner, + gpointer user_data) +{ + CcSharingPanel *self = CC_SHARING_PANEL (user_data); + + g_bus_unwatch_name (self->remote_desktop_name_watch); + self->remote_desktop_name_watch = 0; + + cc_sharing_panel_setup_screen_sharing_dialog_gnome_remote_desktop (self); + gtk_widget_show (self->screen_sharing_row); +} + +static void +check_remote_desktop_available (CcSharingPanel *self) +{ + if (!cc_sharing_panel_check_schema_available (self, GNOME_REMOTE_DESKTOP_SCHEMA_ID)) + return; + + if (!cc_sharing_panel_check_schema_available (self, GNOME_REMOTE_DESKTOP_VNC_SCHEMA_ID)) + return; + + self->remote_desktop_name_watch = g_bus_watch_name (G_BUS_TYPE_SESSION, + "org.gnome.Mutter.RemoteDesktop", + G_BUS_NAME_WATCHER_FLAGS_NONE, + remote_desktop_name_appeared, + NULL, + self, + NULL); +} + +static void +sharing_proxy_ready (GObject *source, + GAsyncResult *res, + gpointer user_data) +{ + CcSharingPanel *self; + GDBusProxy *proxy; + 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); + return; + } + + self = CC_SHARING_PANEL (user_data); + self->sharing_proxy = proxy; + + /* media sharing */ + cc_sharing_panel_setup_media_sharing_dialog (self); + + /* personal file sharing */ + if (cc_sharing_panel_check_schema_available (self, FILE_SHARING_SCHEMA_ID)) + cc_sharing_panel_setup_personal_file_sharing_dialog (self); + else + gtk_widget_hide (self->personal_file_sharing_row); + + /* remote login */ + cc_sharing_panel_setup_remote_login_dialog (self); + + /* screen sharing */ + check_remote_desktop_available (self); + gtk_widget_hide (self->screen_sharing_row); +} + +static void +cc_sharing_panel_init (CcSharingPanel *self) +{ + GtkWidget *box; + + g_resources_register (cc_sharing_get_resource ()); + + gtk_widget_init_template (GTK_WIDGET (self)); + + g_signal_connect_object (self->main_list_box, "row-activated", + G_CALLBACK (cc_sharing_panel_main_list_box_row_activated), self, G_CONNECT_SWAPPED); + + g_signal_connect (self->media_sharing_dialog, "response", + G_CALLBACK (gtk_widget_hide), NULL); + g_signal_connect (self->personal_file_sharing_dialog, "response", + G_CALLBACK (gtk_widget_hide), NULL); + g_signal_connect (self->remote_login_dialog, "response", + G_CALLBACK (gtk_widget_hide), NULL); + g_signal_connect (self->screen_sharing_dialog, "response", + G_CALLBACK (gtk_widget_hide), NULL); + + gtk_list_box_set_activate_on_single_click (GTK_LIST_BOX (self->main_list_box), + TRUE); + gtk_list_box_set_header_func (GTK_LIST_BOX (self->main_list_box), + cc_list_box_update_header_func, + NULL, NULL); + + /* create the master switch */ + box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); + gtk_widget_show (box); + + self->master_switch = gtk_switch_new (); + gtk_widget_show (self->master_switch); + atk_object_set_name (ATK_OBJECT (gtk_widget_get_accessible (self->master_switch)), _("Sharing")); + gtk_widget_set_valign (self->master_switch, GTK_ALIGN_CENTER); + gtk_box_pack_start (GTK_BOX (box), self->master_switch, FALSE, FALSE, 4); + + /* start the panel in the disabled state */ + gtk_switch_set_active (GTK_SWITCH (self->master_switch), FALSE); + gtk_widget_set_sensitive (self->main_list_box, FALSE); + g_signal_connect_object (self->master_switch, "notify::active", + G_CALLBACK (cc_sharing_panel_master_switch_notify), self, G_CONNECT_SWAPPED); + + gsd_sharing_proxy_new_for_bus (G_BUS_TYPE_SESSION, + G_DBUS_PROXY_FLAGS_NONE, + "org.gnome.SettingsDaemon.Sharing", + "/org/gnome/SettingsDaemon/Sharing", + cc_panel_get_cancellable (CC_PANEL (self)), + sharing_proxy_ready, + self); + + /* make sure the hostname entry isn't focused by default */ + g_signal_connect_swapped (self, "map", G_CALLBACK (gtk_widget_grab_focus), + self->main_list_box); +} + +CcSharingPanel * +cc_sharing_panel_new (void) +{ + return g_object_new (CC_TYPE_SHARING_PANEL, NULL); +} diff --git a/panels/sharing/cc-sharing-panel.h b/panels/sharing/cc-sharing-panel.h new file mode 100644 index 0000000..b8b69ab --- /dev/null +++ b/panels/sharing/cc-sharing-panel.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2013 Intel, Inc + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Author: Thomas Wood <thomas.wood@intel.com> + * + */ + +#pragma once + +#include <shell/cc-shell.h> + +G_BEGIN_DECLS + +#define CC_TYPE_SHARING_PANEL (cc_sharing_panel_get_type ()) +G_DECLARE_FINAL_TYPE (CcSharingPanel, cc_sharing_panel, CC, SHARING_PANEL, CcPanel) + +CcSharingPanel *cc_sharing_panel_new (void); + +G_END_DECLS diff --git a/panels/sharing/cc-sharing-panel.ui b/panels/sharing/cc-sharing-panel.ui new file mode 100644 index 0000000..40a112a --- /dev/null +++ b/panels/sharing/cc-sharing-panel.ui @@ -0,0 +1,703 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Generated with glade 3.18.1 --> +<interface> + <requires lib="gtk+" version="3.10"/> + <template class="CcSharingPanel" parent="CcPanel"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <child> + <object class="GtkScrolledWindow" id="sharing_panel"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="hscrollbar-policy">never</property> + <child> + <object class="HdyClamp"> + <property name="visible">True</property> + <property name="margin_top">32</property> + <property name="margin_bottom">32</property> + <property name="margin_start">12</property> + <property name="margin_end">12</property> + <child> + <object class="GtkBox"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="hexpand">True</property> + <property name="orientation">vertical</property> + <child> + <object class="GtkLabel" id="label6"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="margin_bottom">12</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">_Computer Name</property> + <property name="use_underline">True</property> + <property name="mnemonic_widget">hostname_entry</property> + <accessibility> + <relation type="label-for" target="hostname_entry"/> + </accessibility> + <attributes> + <attribute name="weight" value="bold"/> + </attributes> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="CcHostnameEntry" id="hostname_entry"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="margin_bottom">32</property> + <property name="invisible_char">●</property> + <accessibility> + <relation type="labelled-by" target="label6"/> + </accessibility> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkFrame" id="frame1"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label_xalign">0</property> + <property name="shadow_type">in</property> + <child> + <object class="GtkListBox" id="main_list_box"> + <property name="visible">True</property> + <property name="selection-mode">none</property> + <child> + <object class="CcListRow" id="personal_file_sharing_row"> + <property name="visible">True</property> + <property name="icon-name">go-next-symbolic</property> + <property name="use-underline">True</property> + <property name="title" translatable="yes">_File Sharing</property> + </object> + </child> + <child> + <object class="CcListRow" id="screen_sharing_row"> + <property name="visible">True</property> + <property name="icon-name">go-next-symbolic</property> + <property name="use-underline">True</property> + <property name="title" translatable="yes">_Screen Sharing</property> + </object> + </child> + <child> + <object class="CcListRow" id="media_sharing_row"> + <property name="visible">True</property> + <property name="icon-name">go-next-symbolic</property> + <property name="use-underline">True</property> + <property name="title" translatable="yes">_Media Sharing</property> + </object> + </child> + <child> + <object class="CcListRow" id="remote_login_row"> + <property name="visible">True</property> + <property name="icon-name">go-next-symbolic</property> + <property name="use-underline">True</property> + <property name="title" translatable="yes">_Remote Login</property> + </object> + </child> + </object> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">2</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="label12"> + <property name="can_focus">False</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">Some services are disabled because of no network access.</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">7</property> + </packing> + </child> + </object> + </child> + </object> + </child> + </object> + </child> + </template> + <object class="GtkDialog" id="personal_file_sharing_dialog"> + <property name="can_focus">False</property> + <property name="border_width">5</property> + <property name="title" translatable="yes">File Sharing</property> + <property name="resizable">False</property> + <property name="type_hint">dialog</property> + <property name="use_header_bar">1</property> + <child internal-child="vbox"> + <object class="GtkBox" id="dialog-vbox5"> + <property name="can_focus">False</property> + <property name="orientation">vertical</property> + <property name="spacing">2</property> + <child> + <object class="GtkGrid" id="personal_file_sharing_grid"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="margin_start">12</property> + <property name="margin_end">6</property> + <property name="margin_top">12</property> + <property name="margin_bottom">12</property> + <property name="row_spacing">12</property> + <property name="column_spacing">6</property> + <child> + <object class="GtkLabel" id="personal_file_sharing_label"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="xalign">0</property> + <property name="label">File Sharing allows you to share your Public folder with others on your current network using: <a href="dav://%s">dav://%s</a></property> + <property name="use_markup">True</property> + <property name="wrap">True</property> + <property name="max-width-chars">36</property> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">0</property> + <property name="width">2</property> + <property name="height">1</property> + </packing> + </child> + <child> + <object class="GtkGrid" id="require_password_grid"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="row_spacing">12</property> + <property name="column_spacing">6</property> + <child> + <object class="GtkLabel" id="label17"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="halign">start</property> + <property name="label" translatable="yes">_Require Password</property> + <property name="use_markup">True</property> + <property name="use_underline">True</property> + <property name="mnemonic_widget">personal_file_sharing_require_password_switch</property> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">0</property> + <property name="width">1</property> + <property name="height">1</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="personal_file_sharing_password_label"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="halign">start</property> + <property name="hexpand">True</property> + <property name="label" translatable="yes">_Password</property> + <property name="use_underline">True</property> + <property name="mnemonic_widget">personal_file_sharing_password_entry</property> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">1</property> + <property name="width">1</property> + <property name="height">1</property> + </packing> + </child> + <child> + <object class="GtkSwitch" id="personal_file_sharing_require_password_switch"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="halign">end</property> + </object> + <packing> + <property name="left_attach">1</property> + <property name="top_attach">0</property> + <property name="width">1</property> + <property name="height">1</property> + </packing> + </child> + <child> + <object class="GtkEntry" id="personal_file_sharing_password_entry"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="visibility">False</property> + <property name="invisible_char">●</property> + <property name="shadow_type">none</property> + <property name="invisible_char_set">True</property> + <property name="input_purpose">password</property> + </object> + <packing> + <property name="left_attach">1</property> + <property name="top_attach">1</property> + <property name="width">1</property> + <property name="height">1</property> + </packing> + </child> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">2</property> + <property name="width">2</property> + <property name="height">1</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + </object> + </child> + <child type="titlebar"> + <object class="GtkHeaderBar" id="personal_file_sharing_headerbar"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="title" translatable="yes">File Sharing</property> + <property name="show_close_button">True</property> + <child> + <placeholder/> + </child> + </object> + </child> + </object> + <object class="GtkDialog" id="remote_login_dialog"> + <property name="can_focus">False</property> + <property name="border_width">5</property> + <property name="title" translatable="yes">Remote Login</property> + <property name="resizable">False</property> + <property name="type_hint">dialog</property> + <property name="use_header_bar">1</property> + <child internal-child="vbox"> + <object class="GtkBox" id="dialog-vbox4"> + <property name="can_focus">False</property> + <property name="orientation">vertical</property> + <property name="spacing">2</property> + <property name="margin">12</property> + <child> + <object class="GtkBox" id="box9"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="orientation">vertical</property> + <child> + <object class="GtkGrid" id="grid5"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="margin_top">12</property> + <property name="margin_bottom">12</property> + <property name="row_spacing">12</property> + <property name="column_spacing">6</property> + <child> + <object class="GtkLabel" id="remote_login_label"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="xalign">0</property> + <property name="label">When remote login is enabled, remote users can connect using the Secure Shell command: +<a href="ssh %s">ssh %s</a></property> + <property name="use_markup">True</property> + <property name="wrap">True</property> + <property name="max-width-chars">36</property> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">0</property> + <property name="width">2</property> + <property name="height">1</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkBox"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <style> + <class name="frame"/> + <class name="view"/> + </style> + <child> + <object class="GtkBox"> + <property name="visible">True</property> + <property name="margin">12</property> + <child> + <object class="GtkLabel"> + <property name="visible">True</property> + <property name="label" translatable="yes">Remote Login</property> + <property name="hexpand">True</property> + <property name="xalign">0</property> + </object> + </child> + <child> + <object class="GtkSwitch" id="remote_login_switch"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="halign">end</property> + </object> + </child> + </object> + </child> + </object> + </child> + </object> + </child> + + </object> + <object class="GtkDialog" id="screen_sharing_dialog"> + <property name="can_focus">False</property> + <property name="border_width">5</property> + <property name="title" translatable="yes">Screen Sharing</property> + <property name="resizable">False</property> + <property name="type_hint">dialog</property> + <property name="use_header_bar">1</property> + <child internal-child="vbox"> + <object class="GtkBox" id="dialog-vbox1"> + <property name="can_focus">False</property> + <property name="orientation">vertical</property> + <property name="spacing">2</property> + <child> + <object class="GtkBox" id="box8"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="orientation">vertical</property> + <child> + <object class="GtkGrid" id="screen_sharing_grid"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="margin_start">12</property> + <property name="margin_end">6</property> + <property name="margin_bottom">12</property> + <property name="row_spacing">12</property> + <property name="column_spacing">6</property> + <child> + <object class="GtkLabel" id="screen_sharing_label"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="xalign">0</property> + <property name="label">Screen sharing allows remote users to view or control your screen by connecting to: <a href="vnc://%s">vnc://%s</a></property> + <property name="use_markup">True</property> + <property name="wrap">True</property> + <property name="max-width-chars">36</property> + <property name="margin_bottom">6</property> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">0</property> + <property name="width">2</property> + <property name="height">1</property> + </packing> + </child> + <child> + <object class="GtkBox" id="remote_control_box"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="orientation">vertical</property> + <property name="spacing">12</property> + <child> + <object class="GtkCheckButton" id="remote_control_checkbutton"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="draw_indicator">True</property> + <property name="use_underline">True</property> + <property name="label" translatable="yes">_Allow connections to control the screen</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkGrid" id="remote_control_grid"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="row_spacing">6</property> + <child> + <object class="GtkGrid" id="password_grid"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="row_spacing">6</property> + <property name="column_spacing">6</property> + <child> + <object class="GtkLabel" id="remote_control_password_label"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="halign">start</property> + <property name="margin_left">12</property> + <property name="label" translatable="yes">_Password:</property> + <property name="use_underline">True</property> + <property name="mnemonic_widget">remote_control_password_entry</property> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">0</property> + <property name="width">1</property> + <property name="height">1</property> + </packing> + </child> + <child> + <object class="GtkEntry" id="remote_control_password_entry"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="hexpand">True</property> + <property name="visibility">False</property> + <property name="invisible_char">●</property> + <property name="shadow_type">none</property> + <property name="input_purpose">password</property> + </object> + <packing> + <property name="left_attach">1</property> + <property name="top_attach">0</property> + <property name="width">1</property> + <property name="height">1</property> + </packing> + </child> + <child> + <object class="GtkCheckButton" id="show_password_checkbutton"> + <property name="label" translatable="yes">_Show Password</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="xalign">0</property> + <property name="draw_indicator">True</property> + <property name="use_underline">True</property> + </object> + <packing> + <property name="left_attach">1</property> + <property name="top_attach">1</property> + <property name="width">1</property> + <property name="height">1</property> + </packing> + </child> + <child> + <placeholder/> + </child> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">3</property> + <property name="width">1</property> + <property name="height">1</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="label2"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">Access Options</property> + <attributes> + <attribute name="weight" value="bold"/> + </attributes> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">0</property> + <property name="width">1</property> + <property name="height">1</property> + </packing> + </child> + <child> + <object class="GtkRadioButton" id="approve_connections_radiobutton"> + <property name="label" translatable="yes">_New connections must ask for access</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="xalign">0</property> + <property name="draw_indicator">True</property> + <property name="group">require_password_radiobutton</property> + <property name="use_underline">True</property> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">1</property> + <property name="width">1</property> + <property name="height">1</property> + </packing> + </child> + <child> + <object class="GtkRadioButton" id="require_password_radiobutton"> + <property name="label" translatable="yes">_Require a password</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="xalign">0</property> + <property name="draw_indicator">True</property> + <property name="use_underline">True</property> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">2</property> + <property name="width">1</property> + <property name="height">1</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">2</property> + <property name="width">2</property> + <property name="height">1</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + </object> + </child> + <child type="titlebar"> + <object class="GtkHeaderBar" id="screen_sharing_headerbar"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="title" translatable="yes">Screen Sharing</property> + <property name="show_close_button">True</property> + <child> + <placeholder/> + </child> + </object> + </child> + </object> + <object class="GtkDialog" id="media_sharing_dialog"> + <property name="can_focus">False</property> + <property name="border_width">5</property> + <property name="title" translatable="yes">Media Sharing</property> + <property name="resizable">False</property> + <property name="type_hint">dialog</property> + <child internal-child="vbox"> + <object class="GtkBox" id="dialog-vbox2"> + <property name="can_focus">False</property> + <property name="orientation">vertical</property> + <property name="spacing">2</property> + <child internal-child="action_area"> + <object class="GtkButtonBox" id="dialog-action_area2"> + <property name="can_focus">False</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkGrid" id="shared_folders_grid"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="margin_start">12</property> + <property name="margin_end">6</property> + <property name="margin_top">12</property> + <property name="margin_bottom">12</property> + <property name="row_spacing">12</property> + <property name="column_spacing">6</property> + <child> + <object class="GtkLabel" id="label13"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">Share music, photos and videos over the network.</property> + <property name="max-width-chars">36</property> + <property name="wrap">True</property> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">0</property> + <property name="width">2</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="label15"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">Folders</property> + <property name="mnemonic_widget">shared_folders_listbox</property> + <attributes> + <attribute name="weight" value="bold"/> + </attributes> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">1</property> + <property name="width">2</property> + </packing> + </child> + <child> + <object class="GtkFrame" id="shared_folders_frame"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="shadow_type">in</property> + <child> + <object class="GtkListBox" id="shared_folders_listbox"> + <property name="visible">True</property> + <property name="can_focus">True</property> + </object> + </child> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">3</property> + <property name="width">2</property> + </packing> + </child> + <child> + <placeholder/> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + </object> + </child> + <child type="titlebar"> + <object class="GtkHeaderBar" id="media_sharing_headerbar"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="title" translatable="yes">Media Sharing</property> + <property name="show_close_button">True</property> + <child> + <placeholder/> + </child> + </object> + </child> + </object> +</interface> diff --git a/panels/sharing/cc-sharing-switch.c b/panels/sharing/cc-sharing-switch.c new file mode 100644 index 0000000..4c75214 --- /dev/null +++ b/panels/sharing/cc-sharing-switch.c @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2014 Bastien Nocera <hadess@hadess.net> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#include "config.h" + +#include <gtk/gtk.h> +#include <gio/gio.h> +#include "cc-sharing-switch.h" + +struct _CcSharingSwitch { + GtkSwitch parent_instance; + + GtkWidget *widget; +}; + +G_DEFINE_TYPE (CcSharingSwitch, cc_sharing_switch, GTK_TYPE_SWITCH) + +enum { + PROP_0, + PROP_WIDGET +}; + +static void cc_sharing_switch_class_init (CcSharingSwitchClass *klass); +static void cc_sharing_switch_init (CcSharingSwitch *self); +static void cc_sharing_switch_finalize (GObject *object); + +static void +cc_sharing_switch_constructed (GObject *object) +{ + CcSharingSwitch *self; + GtkWidget *other_sw; + + G_OBJECT_CLASS (cc_sharing_switch_parent_class)->constructed (object); + + self = CC_SHARING_SWITCH (object); + + other_sw = g_object_get_data (G_OBJECT (self->widget), "switch"); + + g_object_bind_property (other_sw, "visible", self, "visible", G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL); + g_object_bind_property (other_sw, "state", self, "state", G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL); + g_object_bind_property (other_sw, "active", self, "active", G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL); + g_object_bind_property (other_sw, "sensitive", self, "sensitive", G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL); + + gtk_widget_set_valign (GTK_WIDGET (self), GTK_ALIGN_CENTER); +} + +static void +cc_sharing_switch_init (CcSharingSwitch *self) +{ +} + +GtkWidget * +cc_sharing_switch_new (GtkWidget *widget) +{ + g_return_val_if_fail (widget != NULL, NULL); + + return GTK_WIDGET (g_object_new (CC_TYPE_SHARING_SWITCH, + "widget", widget, + NULL)); +} + +static void +cc_sharing_switch_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + CcSharingSwitch *self; + + self = CC_SHARING_SWITCH (object); + + switch (prop_id) { + case PROP_WIDGET: + self->widget = g_value_dup_object (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +cc_sharing_switch_finalize (GObject *object) +{ + CcSharingSwitch *self; + + g_return_if_fail (object != NULL); + g_return_if_fail (CC_IS_SHARING_SWITCH (object)); + + self = CC_SHARING_SWITCH (object); + + g_return_if_fail (self != NULL); + + g_clear_object (&self->widget); + + G_OBJECT_CLASS (cc_sharing_switch_parent_class)->finalize (object); +} + +static void +cc_sharing_switch_class_init (CcSharingSwitchClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->set_property = cc_sharing_switch_set_property; + object_class->finalize = cc_sharing_switch_finalize; + object_class->constructed = cc_sharing_switch_constructed; + + g_object_class_install_property (object_class, + PROP_WIDGET, + g_param_spec_object ("widget", + "widget", + "widget", + GTK_TYPE_WIDGET, + G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); +} + +/* + * vim: sw=2 ts=8 cindent noai bs=2 + */ diff --git a/panels/sharing/cc-sharing-switch.h b/panels/sharing/cc-sharing-switch.h new file mode 100644 index 0000000..36920d8 --- /dev/null +++ b/panels/sharing/cc-sharing-switch.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2014 Bastien Nocera <hadess@hadess.net> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#pragma once + +#include <gtk/gtkswitch.h> + +G_BEGIN_DECLS + +#define CC_TYPE_SHARING_SWITCH (cc_sharing_switch_get_type ()) +G_DECLARE_FINAL_TYPE (CcSharingSwitch, cc_sharing_switch, CC, SHARING_SWITCH, GtkSwitch) + +GtkWidget * cc_sharing_switch_new (GtkWidget *widget); + +G_END_DECLS diff --git a/panels/sharing/file-share-properties.c b/panels/sharing/file-share-properties.c new file mode 100644 index 0000000..dcf741c --- /dev/null +++ b/panels/sharing/file-share-properties.c @@ -0,0 +1,55 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ + +/* + * Copyright (C) 2004 Red Hat, Inc. + * + * Nautilus is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * Nautilus is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * Authors: Alexander Larsson <alexl@redhat.com> + * + */ + +#include "file-share-properties.h" + +#include <string.h> +#include <stdio.h> + +#include <glib.h> + + +#define REALM "Please log in as the user guest" +#define USER "guest" + +void +file_share_write_out_password (const char *password) +{ + 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)); + line = g_strdup_printf ("%s:%s:%s\n", USER, REALM, ascii_digest); + + filename = g_build_filename (g_get_user_config_dir (), "user-share", "passwd", NULL); + + file = fopen (filename, "w"); + if (file != NULL) { + fwrite (line, strlen (line), 1, file); + fclose (file); + } +} diff --git a/panels/sharing/file-share-properties.h b/panels/sharing/file-share-properties.h new file mode 100644 index 0000000..b29d23f --- /dev/null +++ b/panels/sharing/file-share-properties.h @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2013 Intel, Inc + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#pragma once + +void file_share_write_out_password (const char *password); diff --git a/panels/sharing/gnome-sharing-panel.desktop.in.in b/panels/sharing/gnome-sharing-panel.desktop.in.in new file mode 100644 index 0000000..32d0b0a --- /dev/null +++ b/panels/sharing/gnome-sharing-panel.desktop.in.in @@ -0,0 +1,15 @@ +[Desktop Entry] +Name=Sharing +Comment=Control what you want to share with others +Exec=gnome-control-center sharing +# Translators: Do NOT translate or transliterate this text (this is an icon file name)! +Icon=preferences-system-sharing +Terminal=false +Type=Application +NoDisplay=true +StartupNotify=true +Categories=GNOME;GTK;Settings;DesktopSettings;X-GNOME-Settings-Panel;X-GNOME-AccountSettings; +OnlyShowIn=GNOME;Unity; +X-GNOME-Settings-Panel=sharing +# Translators: Search terms to find the Sharing panel. Do NOT translate or localize the semicolons! The list MUST also end with a semicolon! +Keywords=share;sharing;ssh;host;name;remote;desktop;media;audio;video;pictures;photos;movies;server;renderer; diff --git a/panels/sharing/gsd-sharing-enums.h b/panels/sharing/gsd-sharing-enums.h new file mode 100644 index 0000000..d117845 --- /dev/null +++ b/panels/sharing/gsd-sharing-enums.h @@ -0,0 +1,31 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2014 Bastien Nocera <hadess@hadess.net> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + * + */ + +#pragma once + +G_BEGIN_DECLS + +typedef enum { + GSD_SHARING_STATUS_OFFLINE, + GSD_SHARING_STATUS_DISABLED_MOBILE_BROADBAND, + GSD_SHARING_STATUS_DISABLED_LOW_SECURITY, + GSD_SHARING_STATUS_AVAILABLE +} GsdSharingStatus; + +G_END_DECLS diff --git a/panels/sharing/meson.build b/panels/sharing/meson.build new file mode 100644 index 0000000..b3803bc --- /dev/null +++ b/panels/sharing/meson.build @@ -0,0 +1,103 @@ +panels_list += cappletname +desktop = 'gnome-@0@-panel.desktop'.format(cappletname) + +desktop_in = configure_file( + input: desktop + '.in.in', + output: desktop + '.in', + configuration: desktop_conf +) + +i18n.merge_file( + desktop, + type: 'desktop', + input: desktop_in, + output: desktop, + po_dir: po_dir, + install: true, + install_dir: control_center_desktopdir +) + +polkit_conf = configuration_data() +polkit_conf.set('libexecdir', control_center_libexecdir) + +polkit = 'org.gnome.controlcenter.remote-login-helper.policy' + +polkit_in = configure_file( + input: polkit + '.in.in', + output: polkit + '.in', + configuration: polkit_conf +) + +i18n.merge_file( + polkit, + input: polkit_in, + output: polkit, + po_dir: po_dir, + install: true, + install_dir: join_paths(control_center_datadir, 'polkit-1', 'actions') +) + +sources = files( + 'cc-sharing-panel.c', + 'cc-media-sharing.c', + 'cc-remote-login.c', + 'cc-sharing-networks.c', + 'cc-sharing-switch.c', + 'cc-gnome-remote-desktop.c', + 'file-share-properties.c', +) + +resource_data = files( + 'cc-sharing-panel.ui', + 'cc-sharing-networks.ui', +) + +sources += gnome.compile_resources( + 'cc-' + cappletname + '-resources', + cappletname + '.gresource.xml', + c_name: 'cc_' + cappletname, + dependencies: resource_data, + export: true +) + +settings_daemon = 'org.gnome.SettingsDaemon' +gdbus = settings_daemon + '.Sharing' + +sources += gnome.gdbus_codegen( + gdbus, + gdbus + '.xml', + interface_prefix: settings_daemon + '.', + namespace: 'Gsd' +) + +cflags += [ + '-DLIBEXECDIR="@0@"'.format(control_center_libexecdir), + '-DSYSCONFDIR="@0@"'.format(control_center_sysconfdir) +] + +libsecret_dep = dependency('libsecret-1') + +panels_libs += static_library( + cappletname, + sources: sources, + include_directories: [ top_inc, common_inc ], + dependencies: [common_deps, libsecret_dep], + c_args: cflags +) + +name = 'cc-remote-login-helper' + +deps = [ + gio_dep, + glib_dep +] + +executable( + name, + name + '.c', + include_directories: top_inc, + dependencies: deps, + c_args: cflags, + install: true, + install_dir: control_center_libexecdir +) diff --git a/panels/sharing/org.gnome.SettingsDaemon.Sharing.xml b/panels/sharing/org.gnome.SettingsDaemon.Sharing.xml new file mode 100644 index 0000000..1710c3e --- /dev/null +++ b/panels/sharing/org.gnome.SettingsDaemon.Sharing.xml @@ -0,0 +1,19 @@ +<node name="/org/gnome/SettingsDaemon/Sharing"> + <interface name='org.gnome.SettingsDaemon.Sharing'> + <property name='CurrentNetworkName' type='s' access='read'/> + <property name='CurrentNetwork' type='s' access='read'/> + <property name='CarrierType' type='s' access='read'/> + <property name='SharingStatus' type='u' access='read'/> + <method name='EnableService'> + <arg name='service_name' direction='in' type='s'/> + </method> + <method name='DisableService'> + <arg name='service_name' direction='in' type='s'/> + <arg name='network' direction='in' type='s'/> + </method> + <method name='ListNetworks'> + <arg name='service_name' direction='in' type='s'/> + <arg name='networks' direction='out' type='a(sss)'/> + </method> + </interface> +</node> diff --git a/panels/sharing/org.gnome.controlcenter.remote-login-helper.policy.in.in b/panels/sharing/org.gnome.controlcenter.remote-login-helper.policy.in.in new file mode 100644 index 0000000..7fabac2 --- /dev/null +++ b/panels/sharing/org.gnome.controlcenter.remote-login-helper.policy.in.in @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE policyconfig PUBLIC + "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN" + "http://www.freedesktop.org/standards/PolicyKit/1.0/policyconfig.dtd"> +<policyconfig> + + <vendor>The GNOME Project</vendor> + <vendor_url>http://www.gnome.org/</vendor_url> + + <action id="org.gnome.controlcenter.remote-login-helper"> + <description>Enable or disable remote login</description> + <message>Authentication is required to enable or disable remote login</message> + <defaults> + <allow_any>no</allow_any> + <allow_inactive>no</allow_inactive> + <allow_active>auth_admin_keep</allow_active> + </defaults> + <annotate key="org.freedesktop.policykit.exec.path">@libexecdir@/cc-remote-login-helper</annotate> + </action> + +</policyconfig> + diff --git a/panels/sharing/sharing.gresource.xml b/panels/sharing/sharing.gresource.xml new file mode 100644 index 0000000..75c7f74 --- /dev/null +++ b/panels/sharing/sharing.gresource.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<gresources> + <gresource prefix="/org/gnome/control-center/sharing"> + <file preprocess="xml-stripblanks">cc-sharing-panel.ui</file> + <file preprocess="xml-stripblanks">cc-sharing-networks.ui</file> + </gresource> +</gresources> |