[vinagre] Added RDP support. Closes #503456.



commit cedbdba3d6bd2aa083752d82287f856a93a385c1
Author: Jonh Wendell <jwendell gnome org>
Date:   Sun Jun 27 12:00:56 2010 -0300

    Added RDP support. Closes #503456.
    
    Still requires some work. Release early and often.

 configure.ac                              |   22 +++
 plugins/Makefile.am                       |    7 +-
 plugins/rdp/Makefile.am                   |   30 ++++
 plugins/rdp/rdp.vinagre-plugin.desktop.in |   11 ++
 plugins/rdp/vinagre-rdp-connection.c      |   99 +++++++++++++
 plugins/rdp/vinagre-rdp-connection.h      |   59 ++++++++
 plugins/rdp/vinagre-rdp-plugin.c          |  171 ++++++++++++++++++++++
 plugins/rdp/vinagre-rdp-plugin.h          |   74 ++++++++++
 plugins/rdp/vinagre-rdp-tab.c             |  225 +++++++++++++++++++++++++++++
 plugins/rdp/vinagre-rdp-tab.h             |   61 ++++++++
 10 files changed, 758 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 6f68cd4..825cac6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -157,6 +157,26 @@ if test "x$enable_ssh" = "xyes" ; then
 fi
 AM_CONDITIONAL(SSH, test "x$enable_ssh" = "xyes")
 
+dnl ****************************
+dnl *** Checks for RDP stuff ***
+dnl ****************************
+
+AC_ARG_ENABLE(rdp,
+              AS_HELP_STRING([--enable-rdp],
+                             [Enable RDP plugin (default=yes)]),
+              enable_rdp=${enableval},
+              enable_rdp=yes)
+
+if test "x$enable_rdp" = "xyes" ; then
+  AC_PATH_PROG(RDESKTOP_PROGRAM, rdesktop, "rdesktop")
+  PKG_CHECK_MODULES(RDP,\
+  libxml-2.0 >= $XML_REQUIRED)
+  AC_SUBST(RDP_CFLAGS)
+  AC_SUBST(RDP_LIBS)
+  AC_DEFINE([VINAGRE_ENABLE_RDP],[1],[We want rdp support])
+fi
+AM_CONDITIONAL(RDP, test "x$enable_rdp" = "xyes")
+
 # Check for telepathy
 AC_ARG_ENABLE(telepathy,
               AS_HELP_STRING([--enable-telepathy=@<:@no/yes/auto@:>@],
@@ -283,6 +303,7 @@ plugin-loaders/c/Makefile
 plugins/Makefile
 plugins/vnc/Makefile
 plugins/ssh/Makefile
+plugins/rdp/Makefile
 vinagre/Makefile
 vinagre/view/Makefile
 ])
@@ -303,4 +324,5 @@ Configure summary:
 	GNOME Panel applet..........:  ${enable_applet}
 	Telepathy support ..........:  ${have_telepathy}
 	SSH plugin .................:  ${enable_ssh}
+	RDP plugin .................:  ${enable_rdp}
 "
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 5d78bb9..0018cee 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -1,6 +1,7 @@
 DIST_SUBDIRS =	\
   vnc		\
-  ssh
+  ssh		\
+  rdp
 
 SUBDIRS = 		\
   vnc
@@ -9,4 +10,8 @@ if SSH
 SUBDIRS += ssh
 endif
 
+if RDP
+SUBDIRS += rdp
+endif
+
 -include $(top_srcdir)/git.mk
diff --git a/plugins/rdp/Makefile.am b/plugins/rdp/Makefile.am
new file mode 100644
index 0000000..ea62151
--- /dev/null
+++ b/plugins/rdp/Makefile.am
@@ -0,0 +1,30 @@
+# rdp plugin
+plugindir = $(VINAGRE_PLUGINS_LIBS_DIR)
+
+INCLUDES = \
+	-I$(top_srcdir) 				\
+	$(VINAGRE_CFLAGS) 				\
+	$(WARN_CFLAGS)					\
+	$(DISABLE_DEPRECATED_CFLAGS)	
+
+plugin_LTLIBRARIES = librdp.la
+
+librdp_la_SOURCES = 						\
+	vinagre-rdp-plugin.h vinagre-rdp-plugin.c		\
+	vinagre-rdp-connection.h vinagre-rdp-connection.c	\
+	vinagre-rdp-tab.h vinagre-rdp-tab.c
+
+librdp_la_LDFLAGS = $(PLUGIN_LIBTOOL_FLAGS)
+librdp_la_LIBADD  = $(rdp_LIBS)
+
+plugin_in_files = rdp.vinagre-plugin.desktop.in
+
+rdp.vinagre-plugin: rdp.vinagre-plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache
+
+plugin_DATA = $(plugin_in_files:.vinagre-plugin.desktop.in=.vinagre-plugin)
+
+EXTRA_DIST = $(plugin_in_files)
+CLEANFILES = $(plugin_DATA)
+DISTCLEANFILES = $(plugin_DATA)
+
+-include $(top_srcdir)/git.mk
diff --git a/plugins/rdp/rdp.vinagre-plugin.desktop.in b/plugins/rdp/rdp.vinagre-plugin.desktop.in
new file mode 100644
index 0000000..cbbc83b
--- /dev/null
+++ b/plugins/rdp/rdp.vinagre-plugin.desktop.in
@@ -0,0 +1,11 @@
+[Vinagre Plugin]
+Module=rdp
+IAge=1
+_Name=RDP
+_Description=RDP support
+Authors=Jonh Wendell
+Copyright=Copyright © 2010 Jonh Wendell
+Website=http://www.bani.com.br
+Version=1.0
+Engine=1
+Icon=vinagre
diff --git a/plugins/rdp/vinagre-rdp-connection.c b/plugins/rdp/vinagre-rdp-connection.c
new file mode 100644
index 0000000..9e2c91f
--- /dev/null
+++ b/plugins/rdp/vinagre-rdp-connection.c
@@ -0,0 +1,99 @@
+/*
+ * vinagre-rdp-connection.c
+ * Child class of abstract VinagreConnection, specific to RDP protocol
+ * This file is part of vinagre
+ *
+ * Copyright (C) 2010 - Jonh Wendell <wendell bani com br>
+ *
+ * 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/>.
+ */
+
+#include <glib/gi18n.h>
+#include <vinagre/vinagre-utils.h>
+#include <vinagre/vinagre-cache-prefs.h>
+#include "vinagre-rdp-connection.h"
+
+struct _VinagreRdpConnectionPrivate
+{
+  gint dummy;
+};
+
+#define VINAGRE_RDP_CONNECTION_PRIVATE(o)  (G_TYPE_INSTANCE_GET_PRIVATE ((o), VINAGRE_TYPE_RDP_CONNECTION, VinagreRdpConnectionPrivate))
+G_DEFINE_TYPE (VinagreRdpConnection, vinagre_rdp_connection, VINAGRE_TYPE_CONNECTION);
+
+static void
+vinagre_rdp_connection_init (VinagreRdpConnection *conn)
+{
+  conn->priv = G_TYPE_INSTANCE_GET_PRIVATE (conn, VINAGRE_TYPE_RDP_CONNECTION, VinagreRdpConnectionPrivate);
+}
+
+static void
+vinagre_rdp_connection_constructed (GObject *object)
+{
+  vinagre_connection_set_protocol (VINAGRE_CONNECTION (object), "rdp");
+}
+
+static void
+rdp_fill_writer (VinagreConnection *conn, xmlTextWriter *writer)
+{
+  VINAGRE_CONNECTION_CLASS (vinagre_rdp_connection_parent_class)->impl_fill_writer (conn, writer);
+}
+
+static void
+rdp_parse_item (VinagreConnection *conn, xmlNode *root)
+{
+  VINAGRE_CONNECTION_CLASS (vinagre_rdp_connection_parent_class)->impl_parse_item (conn, root);
+}
+
+static void
+rdp_parse_options_widget (VinagreConnection *conn, GtkWidget *widget)
+{
+  GtkWidget *u_entry;
+
+  u_entry = g_object_get_data (G_OBJECT (widget), "username_entry");
+  if (!u_entry)
+    {
+      g_warning ("Wrong widget passed to rdp_parse_options_widget()");
+      return;
+    }
+
+  vinagre_cache_prefs_set_string  ("rdp-connection", "username", gtk_entry_get_text (GTK_ENTRY (u_entry)));
+
+  g_object_set (conn,
+		"username", gtk_entry_get_text (GTK_ENTRY (u_entry)),
+		NULL);
+}
+
+static void
+vinagre_rdp_connection_class_init (VinagreRdpConnectionClass *klass)
+{
+  GObjectClass* object_class = G_OBJECT_CLASS (klass);
+  VinagreConnectionClass* parent_class = VINAGRE_CONNECTION_CLASS (klass);
+
+  g_type_class_add_private (klass, sizeof (VinagreRdpConnectionPrivate));
+
+  object_class->constructed  = vinagre_rdp_connection_constructed;
+
+  parent_class->impl_fill_writer = rdp_fill_writer;
+  parent_class->impl_parse_item  = rdp_parse_item;
+  parent_class->impl_parse_options_widget = rdp_parse_options_widget;
+}
+
+VinagreConnection *
+vinagre_rdp_connection_new (void)
+{
+  return VINAGRE_CONNECTION (g_object_new (VINAGRE_TYPE_RDP_CONNECTION, NULL));
+}
+
+/* vim: set ts=8: */
diff --git a/plugins/rdp/vinagre-rdp-connection.h b/plugins/rdp/vinagre-rdp-connection.h
new file mode 100644
index 0000000..b9e48be
--- /dev/null
+++ b/plugins/rdp/vinagre-rdp-connection.h
@@ -0,0 +1,59 @@
+/*
+ * vinagre-rdp-connection.h
+ * Child class of abstract VinagreConnection, specific to RDP protocol
+ * This file is part of vinagre
+ *
+ * Copyright (C) 2010 - Jonh Wendell <wendell bani com br>
+ *
+ * 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/>.
+ */
+
+#ifndef __VINAGRE_RDP_CONNECTION_H__
+#define __VINAGRE_RDP_CONNECTION_H__
+
+#include <vinagre/vinagre-connection.h>
+
+G_BEGIN_DECLS
+
+#define VINAGRE_TYPE_RDP_CONNECTION             (vinagre_rdp_connection_get_type ())
+#define VINAGRE_RDP_CONNECTION(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), VINAGRE_TYPE_RDP_CONNECTION, VinagreRdpConnection))
+#define VINAGRE_RDP_CONNECTION_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), VINAGRE_TYPE_RDP_CONNECTION, VinagreRdpConnectionClass))
+#define VINAGRE_IS_RDP_CONNECTION(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VINAGRE_TYPE_RDP_CONNECTION))
+#define VINAGRE_IS_RDP_CONNECTION_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), VINAGRE_TYPE_RDP_CONNECTION))
+#define VINAGRE_RDP_CONNECTION_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), VINAGRE_TYPE_RDP_CONNECTION, VinagreRdpConnectionClass))
+
+typedef struct _VinagreRdpConnectionClass   VinagreRdpConnectionClass;
+typedef struct _VinagreRdpConnection        VinagreRdpConnection;
+typedef struct _VinagreRdpConnectionPrivate VinagreRdpConnectionPrivate;
+
+struct _VinagreRdpConnectionClass
+{
+  VinagreConnectionClass parent_class;
+};
+
+struct _VinagreRdpConnection
+{
+  VinagreConnection parent_instance;
+  VinagreRdpConnectionPrivate *priv;
+};
+
+
+GType vinagre_rdp_connection_get_type (void) G_GNUC_CONST;
+
+VinagreConnection*  vinagre_rdp_connection_new (void);
+
+G_END_DECLS
+
+#endif /* __VINAGRE_RDP_CONNECTION_H__  */
+/* vim: set ts=8: */
diff --git a/plugins/rdp/vinagre-rdp-plugin.c b/plugins/rdp/vinagre-rdp-plugin.c
new file mode 100644
index 0000000..c37690c
--- /dev/null
+++ b/plugins/rdp/vinagre-rdp-plugin.c
@@ -0,0 +1,171 @@
+/*
+ * vinagre-rdp-plugin.c
+ * This file is part of vinagre
+ *
+ * Copyright (C) 2010 Jonh Wendell <wendell bani com br>
+ * 
+ * vinagre-rdp-plugin.c 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.
+ * 
+ * vinagre-rdp-plugin.c 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/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib/gi18n-lib.h>
+#include <gmodule.h>
+
+#include <vinagre/vinagre-debug.h>
+#include <vinagre/vinagre-cache-prefs.h>
+
+#include "vinagre-rdp-plugin.h"
+#include "vinagre-rdp-connection.h"
+#include "vinagre-rdp-tab.h"
+
+#define VINAGRE_RDP_PLUGIN_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), VINAGRE_TYPE_RDP_PLUGIN, VinagreRdpPluginPrivate))
+
+VINAGRE_PLUGIN_REGISTER_TYPE(VinagreRdpPlugin, vinagre_rdp_plugin)
+
+static void
+impl_activate (VinagrePlugin *plugin,
+               VinagreWindow *window)
+{
+  vinagre_debug_message (DEBUG_PLUGINS, "VinagreRdpPlugin Activate");
+}
+
+static void
+impl_deactivate  (VinagrePlugin *plugin,
+                  VinagreWindow *window)
+{
+  vinagre_debug_message (DEBUG_PLUGINS, "VinagreRdpPlugin Deactivate");
+}
+
+static void
+impl_update_ui (VinagrePlugin *plugin,
+                VinagreWindow *window)
+{
+  vinagre_debug_message (DEBUG_PLUGINS, "VinagreRdpPlugin Update UI");
+}
+
+static const gchar *
+impl_get_protocol (VinagrePlugin *plugin)
+{
+  return "rdp";
+}
+
+static gchar **
+impl_get_public_description (VinagrePlugin *plugin)
+{
+  gchar **result = g_new (gchar *, 3);
+
+  result[0] = g_strdup (_("RDP"));
+  /* Translators: This is a description of the RDP protocol. It appears at Connect dialog. */
+  result[1] = g_strdup (_("Access MS Windows machines"));
+  result[2] = NULL;
+
+  return result;
+}
+
+static VinagreConnection *
+impl_new_connection (VinagrePlugin *plugin)
+{
+  return vinagre_rdp_connection_new ();
+}
+
+static GtkWidget *
+impl_new_tab (VinagrePlugin     *plugin,
+	      VinagreConnection *conn,
+	      VinagreWindow     *window)
+{
+  return vinagre_rdp_tab_new (conn, window);
+}
+
+static gint
+impl_get_default_port (VinagrePlugin *plugin)
+{
+  return 3389;
+}
+
+static void
+vinagre_rdp_plugin_init (VinagreRdpPlugin *plugin)
+{
+  vinagre_debug_message (DEBUG_PLUGINS, "VinagreRdpPlugin initializing");
+}
+
+static void
+vinagre_rdp_plugin_finalize (GObject *object)
+{
+  vinagre_debug_message (DEBUG_PLUGINS, "VinagreRdpPlugin finalizing");
+
+  G_OBJECT_CLASS (vinagre_rdp_plugin_parent_class)->finalize (object);
+}
+
+static GtkWidget *
+impl_get_connect_widget (VinagrePlugin *plugin, VinagreConnection *conn)
+{
+  GtkWidget *box, *label, *u_box, *u_entry;
+  gchar     *str;
+
+  box = gtk_vbox_new (FALSE, 0);
+
+  str = g_strdup_printf ("<b>%s</b>", _("RDP Options"));
+  label = gtk_label_new (str);
+  g_free (str);
+  gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
+  gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
+  gtk_misc_set_padding (GTK_MISC (label), 0, 6);
+  gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
+
+  u_box = gtk_hbox_new (FALSE, 4);
+  label = gtk_label_new ("  ");
+  gtk_box_pack_start (GTK_BOX (u_box), label, FALSE, FALSE, 0);
+
+  label = gtk_label_new_with_mnemonic (_("_Username:"));
+  gtk_box_pack_start (GTK_BOX (u_box), label, FALSE, FALSE, 0);
+
+  u_entry = gtk_entry_new ();
+  /* Translators: This is the tooltip for the username field in a RDP connection */
+  gtk_widget_set_tooltip_text (u_entry, _("Optional. If blank, your username will be used. Also, it can be supplied in the Machine field above, in the form username hostname "));
+  g_object_set_data (G_OBJECT (box), "username_entry", u_entry);
+  gtk_box_pack_start (GTK_BOX (u_box), u_entry, TRUE, TRUE, 5);
+  gtk_label_set_mnemonic_widget (GTK_LABEL (label), u_entry);
+  str = g_strdup (VINAGRE_IS_CONNECTION (conn) ?
+		  vinagre_connection_get_username (conn) :
+		  vinagre_cache_prefs_get_string  ("rdp-connection", "username", ""));
+  gtk_entry_set_text (GTK_ENTRY (u_entry), str);
+  gtk_entry_set_activates_default (GTK_ENTRY (u_entry), TRUE);
+  g_free (str);
+
+  gtk_box_pack_start (GTK_BOX (box), u_box, TRUE, TRUE, 0);
+  return box;
+}
+
+static void
+vinagre_rdp_plugin_class_init (VinagreRdpPluginClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  VinagrePluginClass *plugin_class = VINAGRE_PLUGIN_CLASS (klass);
+
+  object_class->finalize   = vinagre_rdp_plugin_finalize;
+
+  plugin_class->activate   = impl_activate;
+  plugin_class->deactivate = impl_deactivate;
+  plugin_class->update_ui  = impl_update_ui;
+  plugin_class->get_protocol  = impl_get_protocol;
+  plugin_class->get_public_description  = impl_get_public_description;
+  plugin_class->new_connection = impl_new_connection;
+  plugin_class->new_tab = impl_new_tab;
+  plugin_class->get_default_port = impl_get_default_port;
+  plugin_class->get_connect_widget = impl_get_connect_widget;
+}
+/* vim: set ts=8: */
diff --git a/plugins/rdp/vinagre-rdp-plugin.h b/plugins/rdp/vinagre-rdp-plugin.h
new file mode 100644
index 0000000..213198d
--- /dev/null
+++ b/plugins/rdp/vinagre-rdp-plugin.h
@@ -0,0 +1,74 @@
+/*
+ * vinagre-rdp-plugin.h
+ * This file is part of vinagre
+ *
+ * Copyright (C) 2010 Jonh Wendell <wendell bani com br>
+ * 
+ * vinagre-rdp-plugin.h 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.
+ * 
+ * vinagre-rdp-plugin.h 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/>.
+ */
+
+#ifndef __VINAGRE_RDP_PLUGIN_H__
+#define __VINAGRE_RDP_PLUGIN_H__
+
+#include <glib.h>
+#include <glib-object.h>
+#include <vinagre/vinagre-plugin.h>
+
+G_BEGIN_DECLS
+
+/*
+ * Type checking and casting macros
+ */
+#define VINAGRE_TYPE_RDP_PLUGIN                 (vinagre_rdp_plugin_get_type ())
+#define VINAGRE_RDP_PLUGIN(o)                   (G_TYPE_CHECK_INSTANCE_CAST ((o), VINAGRE_TYPE_RDP_PLUGIN, VinagreRdpPlugin))
+#define VINAGRE_RDP_PLUGIN_CLASS(k)             (G_TYPE_CHECK_CLASS_CAST((k), VINAGRE_TYPE_RDP_PLUGIN, VinagreRdpPluginClass))
+#define VINAGRE_IS_RDP_PLUGIN(o)                (G_TYPE_CHECK_INSTANCE_TYPE ((o), VINAGRE_TYPE_RDP_PLUGIN))
+#define VINAGRE_IS_RDP_PLUGIN_CLASS(k)          (G_TYPE_CHECK_CLASS_TYPE ((k), VINAGRE_TYPE_RDP_PLUGIN))
+#define VINAGRE_RDP_PLUGIN_GET_CLASS(o)         (G_TYPE_INSTANCE_GET_CLASS ((o), VINAGRE_TYPE_RDP_PLUGIN, VinagreRdpPluginClass))
+
+/* Private structure type */
+typedef struct _VinagreRdpPluginPrivate	VinagreRdpPluginPrivate;
+
+/*
+ * Main object structure
+ */
+typedef struct _VinagreRdpPlugin		VinagreRdpPlugin;
+
+struct _VinagreRdpPlugin
+{
+  VinagrePlugin parent_instance;
+};
+
+/*
+ * Class definition
+ */
+typedef struct _VinagreRdpPluginClass	VinagreRdpPluginClass;
+
+struct _VinagreRdpPluginClass
+{
+  VinagrePluginClass parent_class;
+};
+
+/*
+ * Public methods
+ */
+GType	vinagre_rdp_plugin_get_type		(void) G_GNUC_CONST;
+
+/* All the plugins must implement this function */
+G_MODULE_EXPORT GType register_vinagre_plugin (GTypeModule *module);
+
+G_END_DECLS
+
+#endif /* __VINAGRE_RDP_PLUGIN_H__ */
+/* vim: set ts=8: */
diff --git a/plugins/rdp/vinagre-rdp-tab.c b/plugins/rdp/vinagre-rdp-tab.c
new file mode 100644
index 0000000..2685555
--- /dev/null
+++ b/plugins/rdp/vinagre-rdp-tab.c
@@ -0,0 +1,225 @@
+/*
+ * vinagre-rdp-tab.c
+ * RDP Implementation for VinagreRdpTab widget
+ * This file is part of vinagre
+ *
+ * Copyright (C) 2010 - Jonh Wendell <wendell bani com br>
+ *
+ * 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/>.
+ */
+
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include <glib/gi18n.h>
+#include <gdk/gdkx.h>
+
+#include <vinagre/vinagre-utils.h>
+#include <vinagre/vinagre-prefs.h>
+
+#include "vinagre-rdp-tab.h"
+#include "vinagre-rdp-connection.h"
+
+#define VINAGRE_RDP_TAB_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), VINAGRE_TYPE_RDP_TAB, VinagreRdpTabPrivate))
+
+struct _VinagreRdpTabPrivate
+{
+  GtkWidget *box;
+  GPid pid;
+  guint child;
+};
+
+G_DEFINE_TYPE (VinagreRdpTab, vinagre_rdp_tab, VINAGRE_TYPE_TAB)
+
+static gchar *
+rdp_tab_get_tooltip (VinagreTab *tab)
+{
+  VinagreConnection *conn = vinagre_tab_get_conn (tab);
+
+  return  g_markup_printf_escaped (
+				  "<b>%s</b> %s\n"
+				  "<b>%s</b> %d",
+				  _("Host:"), vinagre_connection_get_host (conn),
+				  _("Port:"), vinagre_connection_get_port (conn));
+}
+
+static GdkPixbuf *
+rdp_tab_get_screenshot (VinagreTab *tab)
+{
+  return NULL;
+}
+
+static void
+emit_connected_signal (GtkSocket *socket, VinagreRdpTab *rdp_tab)
+{
+  g_signal_emit_by_name (rdp_tab, "tab-initialized");
+  gtk_widget_grab_focus (rdp_tab->priv->box);
+}
+
+static void
+child_exited (GPid pid, gint status, VinagreRdpTab *rdp_tab)
+{
+  if (rdp_tab->priv->pid > 0)
+    {
+      g_spawn_close_pid (rdp_tab->priv->pid);
+      rdp_tab->priv->pid = 0;
+      if (WIFEXITED (status))
+        vinagre_tab_remove_from_notebook (VINAGRE_TAB (rdp_tab));
+      else
+        g_signal_emit_by_name (rdp_tab, "tab-disconnected");
+    }
+}
+
+static gboolean
+delay_connect (GObject *object)
+{
+  gchar **arg;
+  const gchar *username;
+  gint i;
+  GError *error = NULL;
+  VinagreRdpTab *rdp_tab = VINAGRE_RDP_TAB (object);
+  VinagreTab    *tab = VINAGRE_TAB (object);
+  VinagreConnection *conn = vinagre_tab_get_conn (tab);
+
+  username = vinagre_connection_get_username (conn);
+  i = 0;
+
+  arg = g_new (gchar *, 9);
+  arg[i++] = g_strdup ("rdesktop");
+
+  arg[i++] = g_strdup ("-K");
+
+  if (vinagre_connection_get_fullscreen (conn))
+    arg[i++] = g_strdup ("-f");
+
+  arg[i++] = g_strdup ("-X");
+  arg[i++] = g_strdup_printf ("%d", gtk_socket_get_id (GTK_SOCKET (rdp_tab->priv->box)));
+
+  if (username && *username)
+    {
+      arg[i++] = g_strdup ("-u");
+      arg[i++] = g_strdup (username);
+    }
+
+  arg[i++] = g_strdup_printf ("%s:%d",
+			      vinagre_connection_get_host (conn),
+			      vinagre_connection_get_port (conn));
+  arg[i++] = NULL;
+
+  if (!g_spawn_async (NULL,
+		      arg,
+		      NULL,
+		      G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
+		      NULL,
+		      NULL,
+		      &rdp_tab->priv->pid,
+		      &error))
+    {
+      vinagre_utils_show_error (_("Error while executing rdesktop"),
+				error ? error->message : _("Unknown error"),
+				GTK_WINDOW (vinagre_tab_get_window (tab)));
+      vinagre_tab_remove_from_notebook (tab);
+      goto _end;
+    }
+
+  rdp_tab->priv->child = g_child_watch_add (rdp_tab->priv->pid,
+					    (GChildWatchFunc)child_exited, rdp_tab);
+  gtk_widget_show_all (GTK_WIDGET (rdp_tab));
+
+  vinagre_tab_add_recent_used (tab);
+  vinagre_tab_set_state (tab, VINAGRE_TAB_STATE_CONNECTED);
+
+_end:
+  g_strfreev (arg);
+
+  return FALSE;
+}
+
+static void
+vinagre_rdp_tab_constructed (GObject *object)
+{
+  if (G_OBJECT_CLASS (vinagre_rdp_tab_parent_class)->constructed)
+    G_OBJECT_CLASS (vinagre_rdp_tab_parent_class)->constructed (object);
+
+  g_idle_add ((GSourceFunc)delay_connect, object);
+}
+
+static void
+vinagre_rdp_tab_dispose (GObject *object)
+{
+  VinagreRdpTab *rdp_tab = VINAGRE_RDP_TAB (object);
+
+  if (rdp_tab->priv->pid > 0)
+    {
+      g_spawn_close_pid (rdp_tab->priv->pid);
+      kill (rdp_tab->priv->pid, SIGTERM);
+      rdp_tab->priv->pid = 0;
+    }
+
+  if (rdp_tab->priv->child > 0)
+    {
+      g_source_remove (rdp_tab->priv->child);
+      rdp_tab->priv->child = 0;
+    }
+
+  G_OBJECT_CLASS (vinagre_rdp_tab_parent_class)->dispose (object);
+}
+
+static void 
+vinagre_rdp_tab_class_init (VinagreRdpTabClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  VinagreTabClass* tab_class = VINAGRE_TAB_CLASS (klass);
+
+  object_class->constructed = vinagre_rdp_tab_constructed;
+  object_class->dispose = vinagre_rdp_tab_dispose;
+
+  tab_class->impl_get_tooltip = rdp_tab_get_tooltip;
+  tab_class->impl_get_screenshot = rdp_tab_get_screenshot;
+
+  g_type_class_add_private (object_class, sizeof (VinagreRdpTabPrivate));
+}
+
+static void
+vinagre_rdp_tab_init (VinagreRdpTab *rdp_tab)
+{
+  rdp_tab->priv = VINAGRE_RDP_TAB_GET_PRIVATE (rdp_tab);
+
+  rdp_tab->priv->pid = 0;
+  rdp_tab->priv->child = 0;
+
+  /* Create the rdp widget */
+  rdp_tab->priv->box = gtk_socket_new ();
+  gtk_widget_set_can_focus (rdp_tab->priv->box, TRUE);
+  vinagre_tab_add_view (VINAGRE_TAB (rdp_tab), rdp_tab->priv->box);
+  gtk_widget_show (rdp_tab->priv->box);
+
+  g_signal_connect (rdp_tab->priv->box,
+		    "plug-added",
+		    G_CALLBACK (emit_connected_signal),
+		    rdp_tab);
+
+}
+
+GtkWidget *
+vinagre_rdp_tab_new (VinagreConnection *conn,
+		     VinagreWindow     *window)
+{
+  return GTK_WIDGET (g_object_new (VINAGRE_TYPE_RDP_TAB,
+				   "conn", conn,
+				   "window", window,
+				   NULL));
+}
+
+/* vim: set ts=8: */
diff --git a/plugins/rdp/vinagre-rdp-tab.h b/plugins/rdp/vinagre-rdp-tab.h
new file mode 100644
index 0000000..143ffdd
--- /dev/null
+++ b/plugins/rdp/vinagre-rdp-tab.h
@@ -0,0 +1,61 @@
+/*
+ * vinagre-rdp-tab.h
+ * RDP Tab
+ * This file is part of vinagre
+ *
+ * Copyright (C) 2010 - Jonh Wendell <wendell bani com br>
+ *
+ * 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/>.
+ */
+
+#ifndef __VINAGRE_RDP_TAB_H__
+#define __VINAGRE_RDP_TAB_H__
+
+#include <vinagre/vinagre-tab.h>
+
+G_BEGIN_DECLS
+
+#define VINAGRE_TYPE_RDP_TAB              (vinagre_rdp_tab_get_type())
+#define VINAGRE_RDP_TAB(obj)              (G_TYPE_CHECK_INSTANCE_CAST((obj), VINAGRE_TYPE_RDP_TAB, VinagreRdpTab))
+#define VINAGRE_RDP_TAB_CONST(obj)        (G_TYPE_CHECK_INSTANCE_CAST((obj), VINAGRE_TYPE_RDP_TAB, VinagreRdpTab const))
+#define VINAGRE_RDP_TAB_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST((klass), VINAGRE_TYPE_RDP_TAB, VinagreRdpTabClass))
+#define VINAGRE_IS_RDP_TAB(obj)           (G_TYPE_CHECK_INSTANCE_TYPE((obj), VINAGRE_TYPE_RDP_TAB))
+#define VINAGRE_IS_RDP_TAB_CLASS(klass)...(G_TYPE_CHECK_CLASS_TYPE ((klass), VINAGRE_TYPE_RDP_TAB))
+#define VINAGRE_RDP_TAB_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS((obj), VINAGRE_TYPE_RDP_TAB, VinagreRdpTabClass))
+
+typedef struct _VinagreRdpTabPrivate VinagreRdpTabPrivate;
+typedef struct _VinagreRdpTab        VinagreRdpTab;
+typedef struct _VinagreRdpTabClass   VinagreRdpTabClass;
+
+
+struct _VinagreRdpTab 
+{
+  VinagreTab tab;
+  VinagreRdpTabPrivate *priv;
+};
+
+struct _VinagreRdpTabClass 
+{
+  VinagreTabClass parent_class;
+};
+
+GType		vinagre_rdp_tab_get_type		(void) G_GNUC_CONST;
+
+GtkWidget *	vinagre_rdp_tab_new 			(VinagreConnection *conn,
+							 VinagreWindow     *window);
+
+G_END_DECLS
+
+#endif  /* __VINAGRE_RDP_TAB_H__  */
+/* vim: set ts=8: */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]