mirror of
https://gitlab.com/virt-viewer/virt-viewer.git
synced 2024-12-22 13:33:58 +03:00
Add remote-viewer program
This program is meant for direct URI connections. ex: remote-viewer vnc://uri
This commit is contained in:
parent
80a3192603
commit
2a8ed0522e
3
.gitignore
vendored
3
.gitignore
vendored
@ -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
|
||||
|
@ -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/
|
||||
|
@ -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
|
||||
|
114
src/Makefile.am
114
src/Makefile.am
@ -1,57 +1,85 @@
|
||||
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@ \
|
||||
@GMODULE2_LIBS@ \
|
||||
$(NULL)
|
||||
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
|
||||
remote_viewer_LDFLAGS = \
|
||||
@GMODULE2_LIBS@ \
|
||||
$(NULL)
|
||||
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)
|
||||
|
148
src/remote-viewer-main.c
Normal file
148
src/remote-viewer-main.c
Normal file
@ -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@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:
|
||||
*/
|
141
src/remote-viewer.c
Normal file
141
src/remote-viewer.c
Normal file
@ -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@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:
|
||||
*/
|
56
src/remote-viewer.h
Normal file
56
src/remote-viewer.h
Normal file
@ -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@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 */
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user