[virt-tools-list] [PATCH virt-viewer 04/17] Add remote-viewer program
Marc-André Lureau
marcandre.lureau at gmail.com
Fri Jan 27 13:51:23 UTC 2012
From: Marc-André Lureau <marcandre.lureau at redhat.com>
This program is meant for direct URI connections.
ex: remote-viewer vnc://uri
---
.gitignore | 3 +
mingw32-virt-viewer.spec.in | 1 +
po/POTFILES.in | 2 +
src/Makefile.am | 108 +++++++++++++++++++-------------
src/remote-viewer-main.c | 148 +++++++++++++++++++++++++++++++++++++++++++
src/remote-viewer.c | 141 +++++++++++++++++++++++++++++++++++++++++
src/remote-viewer.h | 56 ++++++++++++++++
virt-viewer.spec.in | 1 +
8 files changed, 417 insertions(+), 43 deletions(-)
create mode 100644 src/remote-viewer-main.c
create mode 100644 src/remote-viewer.c
create mode 100644 src/remote-viewer.h
diff --git a/.gitignore b/.gitignore
index 5879464..6435031 100644
--- a/.gitignore
+++ b/.gitignore
@@ -23,6 +23,7 @@ man/*.1
missing
.deps/
.libs
+src/remote-viewer
src/virt-viewer
po/POTFILES
po/stamp-it
@@ -33,3 +34,5 @@ po/stamp-it
*/#*#
stamp-h1
INSTALL
+*.lo
+*.la
diff --git a/mingw32-virt-viewer.spec.in b/mingw32-virt-viewer.spec.in
index 39565b4..e0f1c49 100644
--- a/mingw32-virt-viewer.spec.in
+++ b/mingw32-virt-viewer.spec.in
@@ -69,6 +69,7 @@ rm -rf $RPM_BUILD_ROOT
%files -f virt-viewer.lang
%defattr(-,root,root)
%{_mingw32_bindir}/virt-viewer.exe
+%{_mingw32_bindir}/remote-viewer.exe
%dir %{_mingw32_datadir}/virt-viewer/
%dir %{_mingw32_datadir}/virt-viewer/ui/
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 57b6c52..49ae4f5 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,3 +1,5 @@
+src/remote-viewer-main.c
+src/remote-viewer.c
src/virt-viewer-about.xml
src/virt-viewer-app.c
src/virt-viewer-auth.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 4643de9..f4917dd 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,57 +1,79 @@
+NULL =
+# we are forced to use a shared library,
+# because libtool reordred .a after .la libs, and it fails to link
+noinst_LTLIBRARIES = libvirt-viewer.la
bin_PROGRAMS = virt-viewer
builderxmldir = $(pkgdatadir)/ui
-builderxml_DATA = \
- virt-viewer.xml \
- virt-viewer-about.xml \
- virt-viewer-auth.xml
+builderxml_DATA = \
+ virt-viewer.xml \
+ virt-viewer-about.xml \
+ virt-viewer-auth.xml \
+ $(NULL)
EXTRA_DIST = $(builderxml_DATA)
-virt_viewer_SOURCES = \
- virt-viewer-main.c \
- virt-viewer.h virt-viewer.c \
- virt-viewer-util.h virt-viewer-util.c \
- virt-viewer-auth.h virt-viewer-auth.c \
- virt-viewer-events.h virt-viewer-events.c \
- virt-viewer-app.h virt-viewer-app.c \
- virt-viewer-session.h virt-viewer-session.c \
- virt-viewer-display.h virt-viewer-display.c \
- virt-viewer-notebook.h virt-viewer-notebook.c \
- virt-viewer-window.h virt-viewer-window.c \
- view/autoDrawer.c \
- view/autoDrawer.h \
- view/drawer.c \
- view/drawer.h \
- view/ovBox.c \
- view/ovBox.h
+virt_viewer_SOURCES = \
+ virt-viewer-events.h virt-viewer-events.c \
+ virt-viewer.h virt-viewer.c \
+ virt-viewer-main.c \
+ $(NULL)
+virt_viewer_LDADD = libvirt-viewer.la
+virt_viewer_LDFLAGS = @LIBVIRT_LIBS@
+virt_viewer_CFLAGS = $(AM_CFLAGS) @LIBVIRT_CFLAGS@
+
+if HAVE_SPICE_GTK
+bin_PROGRAMS += remote-viewer
+remote_viewer_SOURCES = \
+ remote-viewer.h remote-viewer.c \
+ remote-viewer-main.c \
+ $(NULL)
+remote_viewer_LDADD = libvirt-viewer.la
+endif
+
+libvirt_viewer_la_SOURCES = \
+ virt-viewer-util.h virt-viewer-util.c \
+ virt-viewer-auth.h virt-viewer-auth.c \
+ virt-viewer-app.h virt-viewer-app.c \
+ virt-viewer-session.h virt-viewer-session.c \
+ virt-viewer-display.h virt-viewer-display.c \
+ virt-viewer-notebook.h virt-viewer-notebook.c \
+ virt-viewer-window.h virt-viewer-window.c \
+ view/autoDrawer.c \
+ view/autoDrawer.h \
+ view/drawer.c \
+ view/drawer.h \
+ view/ovBox.c \
+ view/ovBox.h \
+ $(NULL)
+libvirt_viewer_la_LIBADD = \
+ @GMODULE2_LIBS@ \
+ @GTK_LIBS@ \
+ @LIBXML2_LIBS@ \
+ $(NULL)
if HAVE_GTK_VNC
-virt_viewer_SOURCES += \
- virt-viewer-session-vnc.h virt-viewer-session-vnc.c \
- virt-viewer-display-vnc.h virt-viewer-display-vnc.c
+libvirt_viewer_la_SOURCES += \
+ virt-viewer-session-vnc.h virt-viewer-session-vnc.c \
+ virt-viewer-display-vnc.h virt-viewer-display-vnc.c \
+ $(NULL)
+libvirt_viewer_la_LIBADD += @GTK_VNC_LIBS@
endif
if HAVE_SPICE_GTK
-virt_viewer_SOURCES += \
- virt-viewer-session-spice.h virt-viewer-session-spice.c \
- virt-viewer-display-spice.h virt-viewer-display-spice.c
+libvirt_viewer_la_SOURCES += \
+ virt-viewer-session-spice.h virt-viewer-session-spice.c \
+ virt-viewer-display-spice.h virt-viewer-display-spice.c \
+ $(NULL)
+libvirt_viewer_la_LIBADD += @SPICE_GTK_LIBS@
endif
-virt_viewer_LDADD = \
- @GTK_VNC_LIBS@ \
- @SPICE_GTK_LIBS@ \
- @GMODULE2_LIBS@ \
- @GTK_LIBS@ \
- @LIBXML2_LIBS@ \
- @LIBVIRT_LIBS@
-
-virt_viewer_CFLAGS = \
- @GTK_VNC_CFLAGS@ \
- @SPICE_GTK_CFLAGS@ \
+AM_CFLAGS = \
@GMODULE2_CFLAGS@ \
- @GTK_CFLAGS@ \
- @LIBXML2_CFLAGS@ \
- @LIBVIRT_CFLAGS@ \
- @WARN_CFLAGS@ \
- -DLOCALE_DIR=\""$(datadir)/locale"\"
+ @GTK_CFLAGS@ \
+ @GTK_VNC_CFLAGS@ \
+ @LIBXML2_CFLAGS@ \
+ @SPICE_GTK_CFLAGS@ \
+ @WARN_CFLAGS@ \
+ -DLOCALE_DIR=\""$(datadir)/locale"\" \
+ $(NULL)
diff --git a/src/remote-viewer-main.c b/src/remote-viewer-main.c
new file mode 100644
index 0000000..54670d1
--- /dev/null
+++ b/src/remote-viewer-main.c
@@ -0,0 +1,148 @@
+/*
+ * Remote Viewer: A spice/vnc client based on virt-viewer
+ *
+ * Copyright (C) 2011 Red Hat,
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Marc-André Lureau <marcandre.lureau at redhat.com>
+ */
+
+#include <config.h>
+#include <locale.h>
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <stdlib.h>
+
+#ifdef HAVE_GTK_VNC
+#include <vncdisplay.h>
+#endif
+#ifdef HAVE_SPICE_GTK
+#include <spice-option.h>
+#endif
+
+#include "remote-viewer.h"
+#include "virt-viewer-app.h"
+
+static void
+remote_viewer_version(void)
+{
+ g_print(_("remote-viewer version %s\n"), VERSION);
+ exit(0);
+}
+
+int
+main(int argc, char **argv)
+{
+ GOptionContext *context;
+ GError *error = NULL;
+ int ret = 1;
+ int zoom = 100;
+ gchar **args = NULL;
+ gboolean verbose = FALSE;
+ gboolean debug = FALSE;
+ gboolean direct = FALSE;
+ gboolean fullscreen = FALSE;
+ RemoteViewer *viewer = NULL;
+ VirtViewerApp *app;
+ const char *help_msg = N_("Run '" PACKAGE " --help' to see a full list of available command line options");
+ const GOptionEntry options [] = {
+ { "version", 'V', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
+ remote_viewer_version, N_("Display version information"), NULL },
+ { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
+ N_("Display verbose information"), NULL },
+ { "direct", 'd', 0, G_OPTION_ARG_NONE, &direct,
+ N_("Direct connection with no automatic tunnels"), NULL },
+ { "zoom", 'z', 0, G_OPTION_ARG_INT, &zoom,
+ N_("Zoom level of window, in percentage"), "ZOOM" },
+ { "debug", '\0', 0, G_OPTION_ARG_NONE, &debug,
+ N_("Display debugging information"), NULL },
+ { "full-screen", 'f', 0, G_OPTION_ARG_NONE, &fullscreen,
+ N_("Open in full screen mode"), NULL },
+ { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_STRING_ARRAY, &args,
+ NULL, "URI" },
+ { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
+ };
+
+ setlocale(LC_ALL, "");
+ bindtextdomain(GETTEXT_PACKAGE, LOCALE_DIR);
+ bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
+ textdomain(GETTEXT_PACKAGE);
+
+ /* Setup command line options */
+ context = g_option_context_new (_("- Remote viewer client"));
+ g_option_context_add_main_entries (context, options, NULL);
+ g_option_context_add_group (context, gtk_get_option_group (TRUE));
+#ifdef HAVE_GTK_VNC
+ g_option_context_add_group (context, vnc_display_get_option_group ());
+#endif
+ g_option_context_parse (context, &argc, &argv, &error);
+ if (error) {
+ g_printerr("%s\n%s\n",
+ error->message,
+ gettext(help_msg));
+ g_error_free(error);
+ goto cleanup;
+ }
+
+ g_option_context_free(context);
+
+ if (!args || (g_strv_length(args) != 1)) {
+ g_printerr(_("\nUsage: %s [OPTIONS] URI\n\n%s\n\n"), argv[0], help_msg);
+ goto cleanup;
+ }
+
+ if (zoom < 10 || zoom > 200) {
+ g_printerr(_("Zoom level must be within 10-200\n"));
+ goto cleanup;
+ }
+
+ virt_viewer_app_set_debug(debug);
+
+ viewer = remote_viewer_new(args[0], verbose);
+ if (viewer == NULL)
+ goto cleanup;
+
+ app = VIRT_VIEWER_APP(viewer);
+ g_object_set(app,
+ "fullscreen", fullscreen,
+ "guest-name", args[0],
+ NULL);
+ virt_viewer_window_set_zoom_level(virt_viewer_app_get_main_window(app), zoom);
+ virt_viewer_app_set_direct(app, direct);
+
+ if (!virt_viewer_app_start(app))
+ goto cleanup;
+
+ gtk_main();
+
+ ret = 0;
+
+cleanup:
+ if (viewer)
+ g_object_unref(viewer);
+ g_strfreev(args);
+
+ return ret;
+}
+
+/*
+ * Local variables:
+ * c-indent-level: 8
+ * c-basic-offset: 8
+ * tab-width: 8
+ * indent-tabs-mode: t
+ * End:
+ */
diff --git a/src/remote-viewer.c b/src/remote-viewer.c
new file mode 100644
index 0000000..d5c9824
--- /dev/null
+++ b/src/remote-viewer.c
@@ -0,0 +1,141 @@
+/*
+ * Virt Viewer: A virtual machine console viewer
+ *
+ * Copyright (C) 2007-2009 Red Hat,
+ * Copyright (C) 2009 Daniel P. Berrange
+ * Copyright (C) 2010 Marc-André Lureau
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Marc-André Lureau <marcandre.lureau at redhat.com>
+ */
+
+#include <config.h>
+#include <gtk/gtk.h>
+#include <glib/gprintf.h>
+#include <glib/gi18n.h>
+
+#include "virt-viewer-app.h"
+#include "remote-viewer.h"
+
+struct _RemoteViewerPrivate {
+ int _dummy;
+};
+
+G_DEFINE_TYPE (RemoteViewer, remote_viewer, VIRT_VIEWER_TYPE_APP)
+#define GET_PRIVATE(o) \
+ (G_TYPE_INSTANCE_GET_PRIVATE ((o), REMOTE_VIEWER_TYPE, RemoteViewerPrivate))
+
+static gboolean remote_viewer_start(VirtViewerApp *self);
+
+static void
+remote_viewer_get_property (GObject *object, guint property_id,
+ GValue *value G_GNUC_UNUSED, GParamSpec *pspec)
+{
+ switch (property_id) {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+static void
+remote_viewer_set_property (GObject *object, guint property_id,
+ const GValue *value G_GNUC_UNUSED, GParamSpec *pspec)
+{
+ switch (property_id) {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+static void
+remote_viewer_dispose (GObject *object)
+{
+ G_OBJECT_CLASS(remote_viewer_parent_class)->dispose (object);
+}
+
+static void
+remote_viewer_class_init (RemoteViewerClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ VirtViewerAppClass *app_class = VIRT_VIEWER_APP_CLASS (klass);
+
+ g_type_class_add_private (klass, sizeof (RemoteViewerPrivate));
+
+ object_class->get_property = remote_viewer_get_property;
+ object_class->set_property = remote_viewer_set_property;
+ object_class->dispose = remote_viewer_dispose;
+
+ app_class->start = remote_viewer_start;
+}
+
+static void
+remote_viewer_init(RemoteViewer *self)
+{
+ self->priv = GET_PRIVATE(self);
+}
+
+RemoteViewer *
+remote_viewer_new(const gchar *uri, gboolean verbose)
+{
+ return g_object_new(REMOTE_VIEWER_TYPE,
+ "guri", uri,
+ "verbose", verbose,
+ NULL);
+}
+
+static gboolean
+remote_viewer_start(VirtViewerApp *app)
+{
+ gchar *guri;
+ gchar *type;
+ gboolean ret = FALSE;
+
+ g_object_get(app, "guri", &guri, NULL);
+ g_return_val_if_fail(guri != NULL, FALSE);
+
+ DEBUG_LOG("Opening display to %s", guri);
+
+ if (virt_viewer_util_extract_host(guri, &type, NULL, NULL, NULL, NULL) < 0) {
+ virt_viewer_app_simple_message_dialog(app, _("Cannot determine the connection type from URI"));
+ goto cleanup;
+ }
+
+ if (virt_viewer_app_create_session(app, type) < 0) {
+ virt_viewer_app_simple_message_dialog(app, _("Couldn't create a session for this type: %s"), type);
+ goto cleanup;
+ }
+
+ if (virt_viewer_app_activate(app) < 0) {
+ virt_viewer_app_simple_message_dialog(app, _("Failed to initiate connection"));
+ goto cleanup;
+ }
+
+ ret = VIRT_VIEWER_APP_CLASS(remote_viewer_parent_class)->start(app);
+
+ cleanup:
+ g_free(guri);
+ g_free(type);
+ return ret;
+}
+
+/*
+ * Local variables:
+ * c-indent-level: 8
+ * c-basic-offset: 8
+ * tab-width: 8
+ * indent-tabs-mode: t
+ * End:
+ */
diff --git a/src/remote-viewer.h b/src/remote-viewer.h
new file mode 100644
index 0000000..1ff6d8d
--- /dev/null
+++ b/src/remote-viewer.h
@@ -0,0 +1,56 @@
+/*
+ * Virt Viewer: A virtual machine console viewer
+ *
+ * Copyright (C) 2007 Red Hat,
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Daniel P. Berrange <berrange at redhat.com>
+ */
+
+#ifndef REMOTE_VIEWER_H
+#define REMOTE_VIEWER_H
+
+#include <glib-object.h>
+#include "virt-viewer-app.h"
+
+G_BEGIN_DECLS
+
+#define REMOTE_VIEWER_TYPE remote_viewer_get_type()
+#define REMOTE_VIEWER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), REMOTE_VIEWER_TYPE, RemoteViewer))
+#define REMOTE_VIEWER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), REMOTE_VIEWER_TYPE, RemoteViewerClass))
+#define REMOTE_VIEWER_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), REMOTE_VIEWER_TYPE))
+#define REMOTE_VIEWER_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), REMOTE_VIEWER_TYPE))
+#define REMOTE_VIEWER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), REMOTE_VIEWER_TYPE, RemoteViewerClass))
+
+typedef struct _RemoteViewerPrivate RemoteViewerPrivate;
+
+typedef struct {
+ VirtViewerApp parent;
+ RemoteViewerPrivate *priv;
+} RemoteViewer;
+
+typedef struct {
+ VirtViewerAppClass parent_class;
+} RemoteViewerClass;
+
+GType remote_viewer_get_type (void);
+
+RemoteViewer *
+remote_viewer_new(const gchar *uri, gboolean verbose);
+
+G_END_DECLS
+
+#endif /* REMOTE_VIEWER_H */
diff --git a/virt-viewer.spec.in b/virt-viewer.spec.in
index c894099..e27eae6 100644
--- a/virt-viewer.spec.in
+++ b/virt-viewer.spec.in
@@ -122,6 +122,7 @@ rm -rf $RPM_BUILD_ROOT
%defattr(-,root,root,-)
%doc README COPYING AUTHORS ChangeLog NEWS
%{_bindir}/%{name}
+%{_bindir}/remote-viewer
%dir %{_datadir}/%{name}
%dir %{_datadir}/%{name}/ui/
%{_datadir}/%{name}/ui/virt-viewer.xml
--
1.7.7.6
More information about the virt-tools-list
mailing list