static void vinagre_connection_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { VinagreConnection *conn; g_return_if_fail (VINAGRE_IS_CONNECTION (object)); conn = VINAGRE_CONNECTION (object); switch (prop_id) { case PROP_PROTOCOL: vinagre_connection_set_protocol (conn, g_value_get_string (value)); break; case PROP_HOST: vinagre_connection_set_host (conn, g_value_get_string (value)); break; case PROP_PORT: vinagre_connection_set_port (conn, g_value_get_int (value)); break; case PROP_USERNAME: vinagre_connection_set_username (conn, g_value_get_string (value)); break; case PROP_PASSWORD: vinagre_connection_set_password (conn, g_value_get_string (value)); break; case PROP_FULLSCREEN: vinagre_connection_set_fullscreen (conn, g_value_get_boolean (value)); break; case PROP_NAME: vinagre_connection_set_name (conn, g_value_get_string (value)); break; case PROP_WIDTH: vinagre_connection_set_width (conn, g_value_get_uint (value)); break; case PROP_HEIGHT: vinagre_connection_set_height (conn, g_value_get_uint (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
VinagreConnection * vinagre_connection_clone (VinagreConnection *conn) { VinagreConnection *new_conn; new_conn = vinagre_connection_new (); vinagre_connection_set_host (new_conn, vinagre_connection_get_host (conn)); vinagre_connection_set_port (new_conn, vinagre_connection_get_port (conn)); vinagre_connection_set_username (new_conn, vinagre_connection_get_username (conn)); vinagre_connection_set_password (new_conn, vinagre_connection_get_password (conn)); vinagre_connection_set_name (new_conn, vinagre_connection_get_name (conn)); vinagre_connection_set_desktop_name (new_conn, vinagre_connection_get_desktop_name (conn)); vinagre_connection_set_view_only (new_conn, vinagre_connection_get_view_only (conn)); vinagre_connection_set_scaling (new_conn, vinagre_connection_get_scaling (conn)); vinagre_connection_set_fullscreen (new_conn, vinagre_connection_get_fullscreen (conn)); return new_conn; }
VinagreConnection * vinagre_connection_new_from_string (const gchar *uri, gchar **error_msg, gboolean use_bookmarks) { VinagreConnection *conn = NULL; gint port; gchar *host; if (!vinagre_connection_split_string (uri, &host, &port, error_msg)) return NULL; if (use_bookmarks) conn = vinagre_bookmarks_exists (vinagre_bookmarks_get_default (), host, port); if (!conn) { conn = vinagre_connection_new (); vinagre_connection_set_host (conn, host); vinagre_connection_set_port (conn, port); } g_free (host); return conn; }
static VinagreConnection * impl_new_connection_from_file (VinagreProtocol *plugin, const gchar *data, gboolean use_bookmarks, gchar **error_msg) { GKeyFile *file; GError *error; gboolean loaded; gchar *host, *actual_host, *protocol; gint port; VinagreConnection *conn; *error_msg = NULL; conn = NULL; host = NULL; protocol = NULL; error = NULL; file = g_key_file_new (); loaded = g_key_file_load_from_data (file, data, -1, 0, &error); if (!loaded) { if (error) { *error_msg = g_strdup (error->message); g_error_free (error); } else *error_msg = g_strdup (_("Could not parse the file.")); goto the_end; } if (!g_key_file_has_group (file, "connection")) { /* Translators: Do not translate "connection". It's the name of a group in the .spice (.ini like) file. */ *error_msg = g_strdup (_("The file is not a Spice one: Missing the group \"connection\".")); goto the_end; } if (!g_key_file_has_key (file, "connection", "host", NULL)) { /* Translators: Do not translate "host". It's the name of a key in the .spice (.ini like) file. */ *error_msg = g_strdup (_("The file is not a Spice one: Missing the key \"host\".")); goto the_end; } host = g_key_file_get_string (file, "connection", "host", NULL); port = g_key_file_get_integer (file, "connection", "port", NULL); if (!port) { if (!vinagre_connection_split_string (host, "spice", &protocol, &actual_host, &port, error_msg)) goto the_end; g_free (host); host = actual_host; } if (use_bookmarks) conn = vinagre_bookmarks_exists (vinagre_bookmarks_get_default (), "spice", host, port); if (!conn) { gchar *s_value; conn = vinagre_spice_connection_new (); vinagre_connection_set_host (conn, host); vinagre_connection_set_port (conn, port); s_value = g_key_file_get_string (file, "connection", "password", NULL); vinagre_connection_set_password (conn, s_value); g_free (s_value); } the_end: g_free (host); g_free (protocol); g_key_file_free (file); return conn; }
VinagreConnection * vinagre_connection_new_from_file (const gchar *uri, gchar **error_msg, gboolean use_bookmarks) { GKeyFile *file; GError *error; gboolean loaded; VinagreConnection *conn; gchar *host, *actual_host, *data; gint port; int file_size; GFile *file_a; *error_msg = NULL; host = NULL; data = NULL; conn = NULL; error = NULL; file = NULL; conn = NULL; file_a = g_file_new_for_commandline_arg (uri); loaded = g_file_load_contents (file_a, NULL, &data, &file_size, NULL, &error); if (!loaded) { if (error) { *error_msg = g_strdup (error->message); g_error_free (error); } else *error_msg = g_strdup (_("Could not open the file.")); goto the_end; } file = g_key_file_new (); loaded = g_key_file_load_from_data (file, data, file_size, 0, &error); if (!loaded) { if (error) { *error_msg = g_strdup (error->message); g_error_free (error); } else *error_msg = g_strdup (_("Could not parse the file.")); goto the_end; } host = g_key_file_get_string (file, "connection", "host", NULL); port = g_key_file_get_integer (file, "connection", "port", NULL); if (host) { if (!port) { if (!vinagre_connection_split_string (host, &actual_host, &port, error_msg)) goto the_end; g_free (host); host = actual_host; } if (use_bookmarks) conn = vinagre_bookmarks_exists (vinagre_bookmarks_get_default (), host, port); if (!conn) { gchar *username, *password; gint shared; GError *e = NULL; conn = vinagre_connection_new (); vinagre_connection_set_host (conn, host); vinagre_connection_set_port (conn, port); username = g_key_file_get_string (file, "connection", "username", NULL); vinagre_connection_set_username (conn, username); g_free (username); password = g_key_file_get_string (file, "connection", "password", NULL); vinagre_connection_set_password (conn, password); g_free (password); shared = g_key_file_get_integer (file, "options", "shared", &e); if (e) g_error_free (e); else if (shared == 0 || shared == 1) vinagre_connection_set_shared (conn, shared); else g_message (_("Bad value for 'shared' flag: %d. It is supposed to be 0 or 1. Ignoring it."), shared); } g_free (host); } else *error_msg = g_strdup (_("Could not find the host address in the file.")); the_end: g_free (data); g_object_unref (file_a); if (file) g_key_file_free (file); return conn; }