Commit 4c4e628a authored by Jonh Wendell's avatar Jonh Wendell
Browse files

First step (in a total of XX) towards plugin support.

Things aren't compiling. Just committed because I don't want to loose
the work I've done so far. Tomorrow I continue, it's 2 am dude...
parent c89feeab
......@@ -72,10 +72,17 @@ PKG_CHECK_MODULES(VINAGRE, \
gconf-2.0 >= $GCONF_REQUIRED \
gthread-2.0 >= $GTHREAD_REQUIRED \
gnome-keyring-1 \
gtk-vnc-1.0 >= $GTK_VNC_REQUIRED)
)
AC_SUBST(VINAGRE_CFLAGS)
AC_SUBST(VINAGRE_LIBS)
PKG_CHECK_MODULES(VNC, \
gtk-vnc-1.0 >= $GTK_VNC_REQUIRED \
libxml-2.0
)
AC_SUBST(VNC_CFLAGS)
AC_SUBST(VNC_LIBS)
# Check for telepathy
AC_ARG_ENABLE(telepathy,
AS_HELP_STRING([--enable-telepathy=@<:@no/yes/auto@:>@],
......
......@@ -3,18 +3,20 @@ plugindir = $(VINAGRE_PLUGINS_LIBS_DIR)
INCLUDES = \
-I$(top_srcdir) \
$(VINAGRE_CFLAGS) \
$(VNC_CFLAGS) \
$(WARN_CFLAGS) \
$(DISABLE_DEPRECATED_CFLAGS)
plugin_LTLIBRARIES = libvnc.la
libvnc_la_SOURCES = \
vinagre-vnc-plugin.h \
vinagre-vnc-plugin.c
libvnc_la_SOURCES = \
vinagre-vnc-plugin.h \
vinagre-vnc-plugin.c \
vinagre-vnc-connection.h \
vinagre-vnc-connection.c
libvnc_la_LDFLAGS = $(PLUGIN_LIBTOOL_FLAGS)
libvnc_la_LIBADD = $(VINAGRE_LIBS)
libvnc_la_LIBADD = $(VNC_LIBS)
#uidir = $(VINAGRE_PLUGINS_DATA_DIR)/vnc
#ui_DATA = vnc.ui
......
......@@ -20,6 +20,7 @@
*/
#include <glib/gi18n.h>
#include <vinagre/vinagre-utils.h>
#include "vinagre-vnc-connection.h"
struct _VinagreVncConnectionPrivate
......@@ -47,7 +48,6 @@ vinagre_vnc_connection_init (VinagreVncConnection *conn)
{
conn->priv = G_TYPE_INSTANCE_GET_PRIVATE (conn, VINAGRE_TYPE_VNC_CONNECTION, VinagreVncConnectionPrivate);
vinagre_connection_set_protocol (VINAGRE_CONNECTION (conn), VINAGRE_CONNECTION_PROTOCOL_VNC);
conn->priv->desktop_name = NULL;
conn->priv->view_only = FALSE;
conn->priv->scaling = FALSE;
......@@ -136,8 +136,8 @@ vnc_fill_writer (VinagreConnection *conn, xmlTextWriter *writer)
VinagreVncConnection *vnc_conn = VINAGRE_VNC_CONNECTION (conn);
VINAGRE_CONNECTION_CLASS (vinagre_vnc_connection_parent_class)->impl_fill_writer (conn, writer);
xmlTextWriterWriteFormatElement (writer, "view_only", "%d", vnc_conn->priv->view_only);
xmlTextWriterWriteFormatElement (writer, "scaling", "%d", vnc_conn->priv->scaling);
xmlTextWriterWriteFormatElement (writer, (const xmlChar *)"view_only", "%d", vnc_conn->priv->view_only);
xmlTextWriterWriteFormatElement (writer, (const xmlChar *)"scaling", "%d", vnc_conn->priv->scaling);
}
static void
......@@ -154,9 +154,9 @@ vnc_parse_item (VinagreConnection *conn, xmlNode *root)
s_value = xmlNodeGetContent (curr);
if (!xmlStrcmp(curr->name, (const xmlChar *)"view_only"))
vinagre_vnc_connection_set_view_only (vnc_conn, vinagre_utils_parse_boolean (s_value));
vinagre_vnc_connection_set_view_only (vnc_conn, vinagre_utils_parse_boolean ((const gchar *)s_value));
else if (!xmlStrcmp(curr->name, (const xmlChar *)"scaling"))
vinagre_vnc_connection_set_scaling (vnc_conn, vinagre_utils_parse_boolean (s_value));
vinagre_vnc_connection_set_scaling (vnc_conn, vinagre_utils_parse_boolean ((const gchar *)s_value));
xmlFree (s_value);
}
......
......@@ -22,7 +22,7 @@
#ifndef __VINAGRE_VNC_CONNECTION_H__
#define __VINAGRE_VNC_CONNECTION_H__
#include "vinagre-connection.h"
#include <vinagre/vinagre-connection.h>
G_BEGIN_DECLS
......
......@@ -23,6 +23,7 @@
#endif
#include "vinagre-vnc-plugin.h"
#include "vinagre-vnc-connection.h"
#include <string.h>
#include <glib/gi18n-lib.h>
......@@ -32,7 +33,7 @@
#include <vinagre/vinagre-debug.h>
#include <vinagre/vinagre-utils.h>
#define VINAGRE_SORT_PLUGIN_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), VINAGRE_TYPE_SORT_PLUGIN, VinagreVncPluginPrivate))
#define VINAGRE_VNC_PLUGIN_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), VINAGRE_TYPE_VNC_PLUGIN, VinagreVncPluginPrivate))
VINAGRE_PLUGIN_REGISTER_TYPE(VinagreVncPlugin, vinagre_vnc_plugin)
......@@ -65,6 +66,113 @@ impl_get_context_group (VinagrePlugin *plugin)
return vnc_display_get_option_group ();
}
static const gchar *
impl_get_protocol (VinagrePlugin *plugin)
{
return "vnc";
}
static VinagreConnection *
impl_new_connection (VinagrePlugin *plugin)
{
return vinagre_vnc_connection_new ();
}
static VinagreConnection *
impl_new_connection_from_file (VinagrePlugin *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;
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"))
{
*error_msg = g_strdup (_("The file is not a VNC one: Missing the group \"connection\"."));
goto the_end;
}
if (!g_key_file_has_key (file, "connection", "host", NULL))
{
*error_msg = g_strdup (_("The file is not a VNC 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, &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 (), "vnc", host, port);
if (!conn)
{
gchar *s_value;
gint shared;
conn = vinagre_vnc_connection_new ();
vinagre_connection_set_host (conn, host);
vinagre_connection_set_port (conn, port);
s_value = g_key_file_get_string (file, "connection", "username", NULL);
vinagre_connection_set_username (conn, s_value);
g_free (s_value);
s_value = g_key_file_get_string (file, "connection", "password", NULL);
vinagre_connection_set_password (conn, s_value);
g_free (s_value);
shared = g_key_file_get_integer (file, "options", "shared", NULL);
if (shared == 0 || shared == 1)
vinagre_vnc_connection_set_shared (VINAGRE_VNC_CONNECTION (conn), shared);
else
g_message (_("Bad value for 'shared' flag: %d. It is supposed to be 0 or 1. Ignoring it."), shared);
}
the_end:
g_free (host);
g_free (protocol);
g_key_file_free (file);
return conn;
}
static void
vinagre_vnc_plugin_init (VinagreVncPlugin *plugin)
{
......@@ -91,5 +199,8 @@ vinagre_vnc_plugin_class_init (VinagreVncPluginClass *klass)
plugin_class->deactivate = impl_deactivate;
plugin_class->update_ui = impl_update_ui;
plugin_class->get_context_group = impl_get_context_group;
plugin_class->get_protocol = impl_get_protocol;
plugin_class->new_connection = impl_new_connection;
plugin_class->new_connection_from_file = impl_new_connection_from_file;
}
/* vim: set ts=8: */
......@@ -47,7 +47,6 @@ INST_H_FILES = \
vinagre-tab.h \
vinagre-ui.h \
vinagre-utils.h \
vinagre-vnc-connection.h \
vinagre-vnc-tab.h \
vinagre-window.h \
$(NULL)
......@@ -87,7 +86,6 @@ libvinagre_la_SOURCES = \
vinagre-prefs.c \
vinagre-tab.c \
vinagre-utils.c \
vinagre-vnc-connection.c \
vinagre-vnc-tab.c \
vinagre-window.c \
$(NOINST_H_FILES) \
......@@ -154,7 +152,6 @@ vinagre_applet_SOURCES = \
vinagre-applet.c \
vinagre-bookmarks.h vinagre-bookmarks.c \
vinagre-connection.h vinagre-connection.c \
vinagre-vnc-connection.c vinagre-vnc-connection.h \
vinagre-utils.h vinagre-utils.c \
vinagre-enums.h vinagre-enums.c \
vinagre-bookmarks-entry.h vinagre-bookmarks-entry.c \
......
......@@ -33,6 +33,8 @@
#include "vinagre-connection.h"
#include "vinagre-bookmarks-migration.h"
#include "vinagre-bookmarks.h"
#include "vinagre-plugin.h"
#include "vinagre-plugins-engine.h"
static void
fill_xml (GSList *list, xmlTextWriter *writer)
......@@ -153,6 +155,15 @@ create_list (GKeyFile *kf)
GSList *entries;
gchar **conns;
gsize length, i;
VinagrePlugin *plugin;
plugin = g_hash_table_lookup (vinagre_plugin_engine_get_plugins_by_protocol (vinagre_plugins_engine_get_default ()),
"vnc");
if (!plugin)
{
g_warning (_("Error while migrating bookmarks: VNC plugin is not activated"));
return NULL;
}
entries = NULL;
conns = g_key_file_get_groups (kf, &length);
......@@ -167,29 +178,25 @@ create_list (GKeyFile *kf)
if (!s_value)
continue;
conn = vinagre_connection_new (VINAGRE_CONNECTION_PROTOCOL_VNC);
vinagre_connection_set_name (conn, conns[i]);
vinagre_connection_set_host (conn, s_value);
g_free (s_value);
conn = vinagre_plugin_new_connection (plugin);
i_value = g_key_file_get_integer (kf, conns[i], "port", NULL);
if (i_value == 0)
i_value = 5900;
vinagre_connection_set_port (conn, i_value);
b_value = g_key_file_get_boolean (kf, conns[i], "view_only", NULL);
//vinagre_connection_set_view_only (conn, b_value);
b_value = g_key_file_get_boolean (kf, conns[i], "fullscreen", NULL);
vinagre_connection_set_fullscreen (conn, b_value);
b_value = g_key_file_get_boolean (kf, conns[i], "scaling", NULL);
//vinagre_connection_set_scaling (conn, b_value);
g_object_set (conn,
"name", conns[i],
"host", s_value,
"port", i_value,
"view-only", g_key_file_get_boolean (kf, conns[i], "view_only", NULL),
"fullscreen", g_key_file_get_boolean (kf, conns[i], "fullscreen", NULL),
"scaling", g_key_file_get_boolean (kf, conns[i], "scaling", NULL),
NULL);
entries = g_slist_insert_sorted (entries,
vinagre_bookmarks_entry_new_conn (conn),
(GCompareFunc)vinagre_bookmarks_entry_compare);
g_object_unref (conn);
g_free (s_value);
}
g_strfreev (conns);
......
......@@ -119,7 +119,7 @@ show_dialog_conn (VinagreBookmarks *book,
VinagreBookmarksEntry *entry,
gboolean is_add)
{
gchar *str, *host, *error_str;
gchar *str, *host, *error_str, *protocol;
gint port;
GladeXML *xml;
GtkWidget *dialog, *host_entry, *name_entry;
......@@ -127,7 +127,6 @@ show_dialog_conn (VinagreBookmarks *book,
GtkWidget *box, *tree, *save_button;
VinagreConnection *conn;
const gchar *name;
VinagreConnectionProtocol protocol;
xml = glade_xml_new (vinagre_utils_get_glade_filename (),
"bookmarks_add_edit_conn_dialog",
......
......@@ -28,6 +28,8 @@
#include "vinagre-bookmarks-entry.h"
#include "vinagre-bookmarks-migration.h"
#include "vinagre-connection.h"
#include "vinagre-plugin.h"
#include "vinagre-plugins-engine.h"
struct _VinagreBookmarksPrivate
{
......@@ -145,10 +147,10 @@ vinagre_bookmarks_class_init (VinagreBookmarksClass *klass)
}
static VinagreConnection *
find_conn_by_host (GSList *entries,
VinagreConnectionProtocol protocol,
find_conn_by_host (GSList *entries,
const gchar *protocol,
const gchar *host,
gint port)
gint port)
{
GSList *l;
VinagreConnection *conn;
......@@ -171,7 +173,7 @@ find_conn_by_host (GSList *entries,
conn = vinagre_bookmarks_entry_get_conn (entry);
if ( (g_str_equal (host, vinagre_connection_get_host (conn))) &&
(port == vinagre_connection_get_port (conn)) &&
(protocol == vinagre_connection_get_protocol (conn)) )
(g_str_equal (protocol, vinagre_connection_get_protocol (conn))) )
return g_object_ref (conn);
break;
......@@ -184,9 +186,9 @@ find_conn_by_host (GSList *entries,
VinagreConnection *
vinagre_bookmarks_exists (VinagreBookmarks *book,
VinagreConnectionProtocol protocol,
const gchar *host,
gint port)
const gchar *protocol,
const gchar *host,
gint port)
{
VinagreConnection *conn = NULL;
GSList *l, *next;
......@@ -238,7 +240,8 @@ vinagre_bookmarks_parse_item (xmlNode *root)
VinagreConnection *conn;
xmlNode *curr;
xmlChar *s_value;
VinagreConnectionProtocol protocol = VINAGRE_CONNECTION_PROTOCOL_VNC;
gchar *protocol = NULL;
VinagrePlugin *plugin;
/* Loop to discover the protocol */
for (curr = root->children; curr; curr = curr->next)
......@@ -247,12 +250,23 @@ vinagre_bookmarks_parse_item (xmlNode *root)
continue;
s_value = xmlNodeGetContent (curr);
protocol = vinagre_connection_protocol_by_name ((const gchar *)s_value);
protocol = g_strdup ((const gchar *)s_value);
xmlFree (s_value);
break;
}
conn = vinagre_connection_new (protocol);
if (!protocol)
protocol = g_strdup ("vnc");
plugin = g_hash_table_lookup (vinagre_plugin_engine_get_plugins_by_protocol (vinagre_plugins_engine_get_default ()),
protocol);
if (!plugin)
{
g_warning (_("The protocol %s is not supported."), protocol);
goto out;
}
conn = vinagre_plugin_new_connection (plugin);
vinagre_connection_parse_item (conn, root);
if (vinagre_connection_get_host (conn))
......@@ -260,6 +274,8 @@ vinagre_bookmarks_parse_item (xmlNode *root)
g_object_unref (conn);
out:
g_free (protocol);
return entry;
}
......
......@@ -24,8 +24,8 @@
#include <glib.h>
#include <glib-object.h>
#include "vinagre-connection.h"
#include "vinagre-bookmarks-entry.h"
#include <vinagre/vinagre-connection.h>
#include <vinagre/vinagre-bookmarks-entry.h>
G_BEGIN_DECLS
......@@ -57,8 +57,6 @@ struct _VinagreBookmarks
VinagreBookmarksPrivate *priv;
};
#include "vinagre-window.h"
GType vinagre_bookmarks_get_type (void) G_GNUC_CONST;
VinagreBookmarks *vinagre_bookmarks_get_default (void);
......@@ -71,9 +69,9 @@ gboolean vinagre_bookmarks_remove_entry (VinagreBookmarks *book,
VinagreBookmarksEntry *entry);
VinagreConnection *vinagre_bookmarks_exists (VinagreBookmarks *book,
VinagreConnectionProtocol protocol,
const gchar *host,
gint port);
const gchar *protocol,
const gchar *host,
gint port);
VinagreBookmarksEntry *vinagre_bookmarks_name_exists (VinagreBookmarks *book,
VinagreBookmarksEntry *parent,
......
......@@ -26,11 +26,12 @@
#include "vinagre-connection.h"
#include "vinagre-enums.h"
#include "vinagre-bookmarks.h"
#include "vinagre-vnc-connection.h"
#include "vinagre-plugin.h"
#include "vinagre-plugins-engine.h"
struct _VinagreConnectionPrivate
{
VinagreConnectionProtocol protocol;
gchar *protocol;
gchar *host;
gint port;
gchar *username;
......@@ -53,9 +54,6 @@ enum
PROP_FULLSCREEN
};
gint vinagre_connection_default_port [VINAGRE_CONNECTION_PROTOCOL_INVALID-1] = {5900, 3389};
gchar* vinagre_connection_protos [VINAGRE_CONNECTION_PROTOCOL_INVALID-1] = {"vnc", "rdp"};
#define VINAGRE_CONNECTION_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), VINAGRE_TYPE_CONNECTION, VinagreConnectionPrivate))
G_DEFINE_ABSTRACT_TYPE (VinagreConnection, vinagre_connection, G_TYPE_OBJECT);
......@@ -64,7 +62,7 @@ vinagre_connection_init (VinagreConnection *conn)
{
conn->priv = G_TYPE_INSTANCE_GET_PRIVATE (conn, VINAGRE_TYPE_CONNECTION, VinagreConnectionPrivate);
conn->priv->protocol = VINAGRE_CONNECTION_PROTOCOL_INVALID;
conn->priv->protocol = NULL;
conn->priv->host = NULL;
conn->priv->port = 0;
conn->priv->password = NULL;
......@@ -78,6 +76,7 @@ vinagre_connection_finalize (GObject *object)
{
VinagreConnection *conn = VINAGRE_CONNECTION (object);
g_free (conn->priv->protocol);
g_free (conn->priv->host);
g_free (conn->priv->username);
g_free (conn->priv->password);
......@@ -98,7 +97,7 @@ vinagre_connection_set_property (GObject *object, guint prop_id, const GValue *v
switch (prop_id)
{
case PROP_PROTOCOL:
vinagre_connection_set_protocol (conn, g_value_get_enum (value));
vinagre_connection_set_protocol (conn, g_value_get_string (value));
break;
case PROP_HOST:
......@@ -144,7 +143,7 @@ vinagre_connection_get_property (GObject *object, guint prop_id, GValue *value,
switch (prop_id)
{
case PROP_PROTOCOL:
g_value_set_enum (value, conn->priv->protocol);
g_value_set_string (value, conn->priv->protocol);
break;
case PROP_HOST:
......@@ -216,8 +215,9 @@ default_parse_item (VinagreConnection *conn, xmlNode *root)
xmlFree (s_value);
}
if (conn->priv->port <= 0)
vinagre_connection_set_port (conn, vinagre_connection_default_port [conn->priv->protocol-1]);
// TODO:
// if (conn->priv->port <= 0)
// vinagre_connection_set_port (conn, vinagre_connection_default_port [conn->priv->protocol-1]);
}
......@@ -251,16 +251,15 @@ vinagre_connection_class_init (VinagreConnectionClass *klass)
g_object_class_install_property (object_class,
PROP_PROTOCOL,
g_param_spec_enum ("protocol",
"protocol",
"connection protocol",
VINAGRE_TYPE_CONNECTION_PROTOCOL,
VINAGRE_CONNECTION_PROTOCOL_VNC,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_NICK |
G_PARAM_STATIC_NAME |
G_PARAM_STATIC_BLURB));
g_param_spec_string ("protocol",
"protocol",
"connection protocol",
NULL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_NICK |
G_PARAM_STATIC_NAME |
G_PARAM_STATIC_BLURB));
g_object_class_install_property (object_class,
PROP_HOST,
......@@ -361,39 +360,19 @@ vinagre_connection_class_init (VinagreConnectionClass *klass)
void
vinagre_connection_set_protocol (VinagreConnection *conn,
VinagreConnectionProtocol protocol)
const gchar *protocol)
{
g_return_if_fail (VINAGRE_IS_CONNECTION (conn));
conn->priv->protocol = protocol;
g_free (conn->priv->protocol);
conn->priv->protocol = g_strdup (protocol);
}
VinagreConnectionProtocol
vinagre_connection_get_protocol (VinagreConnection *conn)
{
g_return_val_if_fail (VINAGRE_IS_CONNECTION (conn),
VINAGRE_CONNECTION_PROTOCOL_INVALID);
return conn->priv->protocol;
}
const gchar *
vinagre_connection_get_protocol_as_string (VinagreConnection *conn)
vinagre_connection_get_protocol (VinagreConnection *conn)
{
g_return_val_if_fail (VINAGRE_IS_CONNECTION (conn), NULL);
return vinagre_connection_protos [conn->priv->protocol-1];
}
VinagreConnectionProtocol
vinagre_connection_protocol_by_name (const gchar *protocol)
{
int i;
for (i = VINAGRE_CONNECTION_PROTOCOL_VNC; i <= VINAGRE_CONNECTION_PROTOCOL_INVALID; i++)
if (g_strcmp0 (vinagre_connection_protos [i-1], protocol) == 0)
return i;
return VINAGRE_CONNECTION_PROTOCOL_INVALID;
return conn->priv->protocol;
}
void
......@@ -499,6 +478,7 @@ vinagre_connection_get_name (VinagreConnection *conn)
GdkPixbuf *
vinagre_connection_get_icon (VinagreConnection *conn)
{
/*
GdkPixbuf *pixbuf;
GtkIconTheme *icon_theme;
gchar *icon_name;
......@@ -517,31 +497,23 @@ vinagre_connection_get_icon (VinagreConnection *conn)
g_free (icon_name);
return pixbuf;
}
VinagreConnectionProtocol
protocol_by_name (const gchar *protocol)
{
gint i;
for (i=1; i<VINAGRE_CONNECTION_PROTOCOL_INVALID; i++)
if (g_strcmp0 (vinagre_connection_protos[i-1], protocol) == 0)
return i;
return VINAGRE_CONNECTION_PROTOCOL_INVALID;
*/
// TODO:
return NULL;
}