[vinagre: 12/22] Added VinagreProtocol interface
- From: Jonh Wendell <jwendell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vinagre: 12/22] Added VinagreProtocol interface
- Date: Fri, 30 Jul 2010 21:43:20 +0000 (UTC)
commit 341b00da4fda52d1fed08efe7fb2c8ad6c6088dc
Author: Jonh Wendell <jwendell gnome org>
Date: Fri Jul 30 16:07:02 2010 +0200
Added VinagreProtocol interface
vinagre/Makefile.am | 3 +
vinagre/vinagre-protocol.c | 352 ++++++++++++++++++++++++++++++++++++++++++++
vinagre/vinagre-protocol.h | 104 +++++++++++++
3 files changed, 459 insertions(+), 0 deletions(-)
---
diff --git a/vinagre/Makefile.am b/vinagre/Makefile.am
index 5927a8e..7a04eac 100644
--- a/vinagre/Makefile.am
+++ b/vinagre/Makefile.am
@@ -45,6 +45,7 @@ INST_H_FILES = \
vinagre-dnd.h \
vinagre-ssh.h \
vinagre-cache-prefs.h \
+ vinagre-protocol.h \
$(NULL)
headerdir = $(prefix)/include/vinagre- VINAGRE_API_VERSION@/vinagre
@@ -77,6 +78,7 @@ handwritten_sources = \
pty_open.c \
vinagre-ssh.c \
vinagre-cache-prefs.c \
+ vinagre-protocol.c \
$(NULL)
libvinagre_la_SOURCES = \
@@ -171,6 +173,7 @@ vinagre_applet_SOURCES = \
pty_open.h pty_open.c \
vinagre-ssh.h vinagre-ssh.c \
vinagre-cache-prefs.h vinagre-cache-prefs.c \
+ vinagre-protocol.h vinagre-protocol.c \
$(NULL)
if AVAHI
diff --git a/vinagre/vinagre-protocol.c b/vinagre/vinagre-protocol.c
new file mode 100644
index 0000000..b42f18c
--- /dev/null
+++ b/vinagre/vinagre-protocol.c
@@ -0,0 +1,352 @@
+/*
+ * vinagre-protocol.c
+ * This file is part of vinagre
+ *
+ * Copyright (C) 2010 Jonh Wendell <wendell bani com br>
+ *
+ * vinagre-protocol.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-protocol.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/>.
+ */
+
+#include "vinagre-protocol.h"
+
+G_DEFINE_INTERFACE (VinagreProtocol, vinagre_protocol, G_TYPE_OBJECT)
+
+static const gchar *
+dummy (VinagreProtocol *protocol)
+{
+ return NULL;
+}
+
+static gchar **
+default_get_public_description (VinagreProtocol *protocol)
+{
+ return NULL;
+}
+
+static gint
+default_get_default_port (VinagreProtocol *protocol)
+{
+ return 0;
+}
+
+static GSList *
+default_get_context_groups (VinagreProtocol *protocol)
+{
+ return NULL;
+}
+
+static GtkFileFilter *
+default_get_file_filter (VinagreProtocol *protocol)
+{
+ return NULL;
+}
+
+static GtkWidget *
+default_new_tab (VinagreProtocol *protocol,
+ VinagreConnection *conn,
+ VinagreWindow *window)
+{
+ return NULL;
+}
+
+static VinagreConnection *
+default_new_connection (VinagreProtocol *protocol)
+{
+ return NULL;
+}
+
+static VinagreConnection *
+default_new_connection_from_file (VinagreProtocol *protocol,
+ const gchar *data,
+ gboolean use_bookmarks,
+ gchar **error_msg)
+{
+ return NULL;
+}
+
+static GtkWidget *
+default_get_connect_widget (VinagreProtocol *protocol,
+ VinagreConnection *initial_settings)
+{
+ return NULL;
+}
+
+static void
+default_parse_mdns_dialog (VinagreProtocol *protocol,
+ GtkWidget *connect_widget,
+ GtkWidget *dialog)
+{
+}
+
+static GdkPixbuf *
+default_get_icon (VinagreProtocol *protocol,
+ gint size)
+{
+ return NULL;
+}
+
+void
+vinagre_protocol_default_init (VinagreProtocolInterface *iface)
+{
+ iface->get_protocol = dummy;
+ iface->get_public_description = default_get_public_description;
+ iface->get_default_port = default_get_default_port;
+ iface->get_mdns_service = dummy;
+ iface->get_context_groups = default_get_context_groups;
+ iface->get_file_filter = default_get_file_filter;
+ iface->new_tab = default_new_tab;
+ iface->new_connection = default_new_connection;
+ iface->new_connection_from_file = default_new_connection_from_file;
+ iface->get_connect_widget = default_get_connect_widget;
+ iface->parse_mdns_dialog = default_parse_mdns_dialog;
+ iface->get_icon_name = dummy;
+ iface->get_icon = default_get_icon;
+}
+
+const gchar *
+vinagre_protocol_get_protocol (VinagreProtocol *protocol)
+{
+ VinagreProtocolInterface *iface;
+
+ g_return_val_if_fail (VINAGRE_IS_PROTOCOL (protocol), NULL);
+
+ iface = VINAGRE_PROTOCOL_GET_IFACE (protocol);
+
+ if (iface->get_protocol != NULL)
+ {
+ return iface->get_protocol (protocol);
+ }
+
+ return NULL;
+}
+
+gchar **
+vinagre_protocol_get_public_description (VinagreProtocol *protocol)
+{
+ VinagreProtocolInterface *iface;
+
+ g_return_val_if_fail (VINAGRE_IS_PROTOCOL (protocol), NULL);
+
+ iface = VINAGRE_PROTOCOL_GET_IFACE (protocol);
+
+ if (iface->get_public_description != NULL)
+ {
+ return iface->get_public_description (protocol);
+ }
+
+ return NULL;
+}
+
+gint
+vinagre_protocol_get_default_port (VinagreProtocol *protocol)
+{
+ VinagreProtocolInterface *iface;
+
+ g_return_val_if_fail (VINAGRE_IS_PROTOCOL (protocol), 0);
+
+ iface = VINAGRE_PROTOCOL_GET_IFACE (protocol);
+
+ if (iface->get_default_port != NULL)
+ {
+ return iface->get_default_port (protocol);
+ }
+
+ return 0;
+}
+
+const gchar *
+vinagre_protocol_get_mdns_service (VinagreProtocol *protocol)
+{
+ VinagreProtocolInterface *iface;
+
+ g_return_val_if_fail (VINAGRE_IS_PROTOCOL (protocol), NULL);
+
+ iface = VINAGRE_PROTOCOL_GET_IFACE (protocol);
+
+ if (iface->get_mdns_service != NULL)
+ {
+ return iface->get_mdns_service (protocol);
+ }
+
+ return NULL;
+}
+
+GSList *
+vinagre_protocol_get_context_groups (VinagreProtocol *protocol)
+{
+ VinagreProtocolInterface *iface;
+
+ g_return_val_if_fail (VINAGRE_IS_PROTOCOL (protocol), NULL);
+
+ iface = VINAGRE_PROTOCOL_GET_IFACE (protocol);
+
+ if (iface->get_context_groups != NULL)
+ {
+ return iface->get_context_groups (protocol);
+ }
+
+ return NULL;
+}
+
+GtkFileFilter *
+vinagre_protocol_get_file_filter (VinagreProtocol *protocol)
+{
+ VinagreProtocolInterface *iface;
+
+ g_return_val_if_fail (VINAGRE_IS_PROTOCOL (protocol), NULL);
+
+ iface = VINAGRE_PROTOCOL_GET_IFACE (protocol);
+
+ if (iface->get_file_filter != NULL)
+ {
+ return iface->get_file_filter (protocol);
+ }
+
+ return NULL;
+}
+
+GtkWidget *
+vinagre_protocol_new_tab (VinagreProtocol *protocol,
+ VinagreConnection *conn,
+ VinagreWindow *window)
+{
+ VinagreProtocolInterface *iface;
+
+ g_return_val_if_fail (VINAGRE_IS_PROTOCOL (protocol), NULL);
+
+ iface = VINAGRE_PROTOCOL_GET_IFACE (protocol);
+
+ if (iface->new_tab != NULL)
+ {
+ return iface->new_tab (protocol, conn, window);
+ }
+
+ return NULL;
+}
+
+VinagreConnection *
+vinagre_protocol_new_connection (VinagreProtocol *protocol)
+{
+ VinagreProtocolInterface *iface;
+
+ g_return_val_if_fail (VINAGRE_IS_PROTOCOL (protocol), NULL);
+
+ iface = VINAGRE_PROTOCOL_GET_IFACE (protocol);
+
+ if (iface->new_connection != NULL)
+ {
+ return iface->new_connection (protocol);
+ }
+
+ return NULL;
+}
+
+VinagreConnection *
+vinagre_protocol_new_connection_from_file (VinagreProtocol *protocol,
+ const gchar *data,
+ gboolean use_bookmarks,
+ gchar **error_msg)
+{
+ VinagreProtocolInterface *iface;
+
+ g_return_val_if_fail (VINAGRE_IS_PROTOCOL (protocol), NULL);
+
+ iface = VINAGRE_PROTOCOL_GET_IFACE (protocol);
+
+ if (iface->new_connection_from_file != NULL)
+ {
+ return iface->new_connection_from_file (protocol, data, use_bookmarks, error_msg);
+ }
+
+ return NULL;
+}
+
+/**
+ * vinagre_protocol_get_connect_widget:
+ *
+ * @protocol: a protocol
+ * @initial_settings: (allow-none): bla bla
+ * @returns: (allow-none): a widget
+ */
+GtkWidget *
+vinagre_protocol_get_connect_widget (VinagreProtocol *protocol,
+ VinagreConnection *initial_settings)
+{
+ VinagreProtocolInterface *iface;
+
+ g_return_val_if_fail (VINAGRE_IS_PROTOCOL (protocol), NULL);
+
+ iface = VINAGRE_PROTOCOL_GET_IFACE (protocol);
+
+ if (iface->get_connect_widget != NULL)
+ {
+ return iface->get_connect_widget (protocol, initial_settings);
+ }
+
+ return NULL;
+}
+
+void
+vinagre_protocol_parse_mdns_dialog (VinagreProtocol *protocol,
+ GtkWidget *connect_widget,
+ GtkWidget *dialog)
+{
+ VinagreProtocolInterface *iface;
+
+ g_return_if_fail (VINAGRE_IS_PROTOCOL (protocol));
+
+ iface = VINAGRE_PROTOCOL_GET_IFACE (protocol);
+
+ if (iface->parse_mdns_dialog != NULL)
+ {
+ iface->parse_mdns_dialog (protocol, connect_widget, dialog);
+ }
+}
+
+const gchar *
+vinagre_protocol_get_icon_name (VinagreProtocol *protocol)
+{
+ VinagreProtocolInterface *iface;
+
+ g_return_val_if_fail (VINAGRE_IS_PROTOCOL (protocol), NULL);
+
+ iface = VINAGRE_PROTOCOL_GET_IFACE (protocol);
+
+ if (iface->get_icon_name != NULL)
+ {
+ return iface->get_icon_name (protocol);
+ }
+
+ return NULL;
+}
+
+GdkPixbuf *
+vinagre_protocol_get_icon (VinagreProtocol *protocol,
+ gint size)
+{
+ VinagreProtocolInterface *iface;
+
+ g_return_val_if_fail (VINAGRE_IS_PROTOCOL (protocol), NULL);
+
+ iface = VINAGRE_PROTOCOL_GET_IFACE (protocol);
+
+ if (iface->get_icon != NULL)
+ {
+ return iface->get_icon (protocol, size);
+ }
+
+ return NULL;
+}
+
+/* vim: set ts=8: */
diff --git a/vinagre/vinagre-protocol.h b/vinagre/vinagre-protocol.h
new file mode 100644
index 0000000..fa61c0e
--- /dev/null
+++ b/vinagre/vinagre-protocol.h
@@ -0,0 +1,104 @@
+/*
+ * vinagre-protocol.h
+ * This file is part of vinagre
+ *
+ * Copyright (C) 2010 Jonh Wendell <wendell bani com br>
+ *
+ * vinagre-protocol.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-protocol.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_PROTOCOL_H__
+#define __VINAGRE_PROTOCOL_H__
+
+#include <glib-object.h>
+#include <libpeas/peas.h>
+
+#include "vinagre-window.h"
+
+G_BEGIN_DECLS
+
+/*
+ * Type checking and casting macros
+ */
+#define VINAGRE_TYPE_PROTOCOL (vinagre_protocol_get_type())
+#define VINAGRE_PROTOCOL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), VINAGRE_TYPE_PROTOCOL, VinagreProtocol))
+#define VINAGRE_PROTOCOL_IFACE(klass) (G_TYPE_CHECK_IFACE_CAST((klass), VINAGRE_TYPE_PROTOCOL, VinagreProtocolInterface))
+#define VINAGRE_IS_PROTOCOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), VINAGRE_TYPE_PROTOCOL))
+#define VINAGRE_IS_PROTOCOL_IFACE(klass) (G_TYPE_CHECK_IFACE_TYPE ((klass), VINAGRE_TYPE_PROTOCOL))
+#define VINAGRE_PROTOCOL_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE((obj), VINAGRE_TYPE_PROTOCOL, VinagreProtocolInterface))
+
+typedef struct _VinagreProtocol VinagreProtocol;
+typedef struct _VinagreProtocolInterface VinagreProtocolInterface;
+
+struct _VinagreProtocolInterface
+{
+ GTypeInterface g_iface;
+
+ /* Virtual public methods */
+ GSList *(*get_context_groups) (VinagreProtocol *protocol);
+ const gchar *(*get_protocol) (VinagreProtocol *protocol);
+ gchar **(*get_public_description) (VinagreProtocol *protocol);
+ gint (*get_default_port) (VinagreProtocol *protocol);
+ VinagreConnection *(*new_connection) (VinagreProtocol *protocol);
+ VinagreConnection *(*new_connection_from_file) (VinagreProtocol *protocol,
+ const gchar *data,
+ gboolean use_bookmarks,
+ gchar **error_msg);
+ const gchar *(*get_mdns_service) (VinagreProtocol *protocol);
+ GtkWidget *(*new_tab) (VinagreProtocol *protocol,
+ VinagreConnection *conn,
+ VinagreWindow *window);
+ GtkWidget *(*get_connect_widget) (VinagreProtocol *protocol,
+ VinagreConnection *initial_settings);
+ void (*parse_mdns_dialog) (VinagreProtocol *protocol,
+ GtkWidget *connect_widget,
+ GtkWidget *dialog);
+ GtkFileFilter *(*get_file_filter) (VinagreProtocol *protocol);
+ GdkPixbuf *(*get_icon) (VinagreProtocol *protocol,
+ gint size);
+ const gchar *(*get_icon_name) (VinagreProtocol *protocol);
+};
+
+/*
+ * Public methods
+ */
+GType vinagre_protocol_get_type (void) G_GNUC_CONST;
+
+void vinagre_protocol_parse_mdns_dialog (VinagreProtocol *protocol,
+ GtkWidget *connect_widget,
+ GtkWidget *dialog);
+GSList * vinagre_protocol_get_context_groups (VinagreProtocol *protocol);
+const gchar * vinagre_protocol_get_protocol (VinagreProtocol *protocol);
+gchar ** vinagre_protocol_get_public_description (VinagreProtocol *protocol);
+gint vinagre_protocol_get_default_port (VinagreProtocol *protocol);
+VinagreConnection * vinagre_protocol_new_connection (VinagreProtocol *protocol);
+VinagreConnection * vinagre_protocol_new_connection_from_file (VinagreProtocol *protocol,
+ const gchar *data,
+ gboolean use_bookmarks,
+ gchar **error_msg);
+const gchar * vinagre_protocol_get_mdns_service (VinagreProtocol *protocol);
+
+GtkWidget * vinagre_protocol_new_tab (VinagreProtocol *protocol,
+ VinagreConnection *conn,
+ VinagreWindow *window);
+GtkWidget * vinagre_protocol_get_connect_widget (VinagreProtocol *protocol,
+ VinagreConnection *initial_settings);
+GtkFileFilter * vinagre_protocol_get_file_filter (VinagreProtocol *protocol);
+
+GdkPixbuf * vinagre_protocol_get_icon (VinagreProtocol *protocol,
+ gint size);
+const gchar * vinagre_protocol_get_icon_name (VinagreProtocol *protocol);
+
+#endif /* __VINAGRE_PROTOCOL_H__ */
+/* vim: set ts=8: */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]