[virt-tools-list] [PATCH virt-viewer] Adapt to spice-gtk single-header include policy

Jonathon Jongsma jjongsma at redhat.com
Fri Oct 9 20:55:26 UTC 2015


Unfortunately, there was no single-header include for the GTK+ library
until just recently (spice-client-gtk.h), so this requires bumping the
spice-gtk version requirement to a unreleased git version.
---
 configure.ac                           |   2 +-
 src/remote-viewer-main.c               |   2 +-
 src/virt-viewer-display-spice.c        |   2 +-
 src/virt-viewer-display-spice.h        |   3 +-
 src/virt-viewer-file-transfer-dialog.c | 236 +++++++++++++++++++++++++++++++++
 src/virt-viewer-file-transfer-dialog.h |  75 +++++++++++
 src/virt-viewer-main.c                 |   2 +-
 src/virt-viewer-session-spice.c        |   7 +-
 src/virt-viewer-session-spice.h        |   3 +-
 9 files changed, 318 insertions(+), 14 deletions(-)
 create mode 100644 src/virt-viewer-file-transfer-dialog.c
 create mode 100644 src/virt-viewer-file-transfer-dialog.h

diff --git a/configure.ac b/configure.ac
index cf75f0e..34bf22a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -19,7 +19,7 @@ GTK2_REQUIRED="2.18.0"
 GTK3_REQUIRED="3.0"
 GTK_VNC1_REQUIRED="0.3.8"
 GTK_VNC2_REQUIRED="0.4.0"
-SPICE_GTK_REQUIRED="0.29.35"
+SPICE_GTK_REQUIRED="0.30.6"
 SPICE_PROTOCOL_REQUIRED="0.12.7"
 GOVIRT_REQUIRED="0.3.2"
 
diff --git a/src/remote-viewer-main.c b/src/remote-viewer-main.c
index 81cf736..6ac2523 100644
--- a/src/remote-viewer-main.c
+++ b/src/remote-viewer-main.c
@@ -34,7 +34,7 @@
 #include <vncdisplay.h>
 #endif
 #ifdef HAVE_SPICE_GTK
-#include <spice-option.h>
+#include <spice-client.h>
 #endif
 #ifdef HAVE_OVIRT
 #include <govirt/ovirt-options.h>
diff --git a/src/virt-viewer-display-spice.c b/src/virt-viewer-display-spice.c
index c3dbd75..7a27847 100644
--- a/src/virt-viewer-display-spice.c
+++ b/src/virt-viewer-display-spice.c
@@ -25,7 +25,7 @@
 #include <config.h>
 
 #include <math.h>
-#include <spice-audio.h>
+#include <spice-client.h>
 
 #include <glib/gi18n.h>
 
diff --git a/src/virt-viewer-display-spice.h b/src/virt-viewer-display-spice.h
index 3c30270..e6b4a05 100644
--- a/src/virt-viewer-display-spice.h
+++ b/src/virt-viewer-display-spice.h
@@ -25,8 +25,7 @@
 #define _VIRT_VIEWER_DISPLAY_SPICE_H
 
 #include <glib-object.h>
-#include <spice-widget.h>
-#include <spice-audio.h>
+#include <spice-client-gtk.h>
 
 #include "virt-viewer-display.h"
 #include "virt-viewer-session-spice.h"
diff --git a/src/virt-viewer-file-transfer-dialog.c b/src/virt-viewer-file-transfer-dialog.c
new file mode 100644
index 0000000..a52fac9
--- /dev/null
+++ b/src/virt-viewer-file-transfer-dialog.c
@@ -0,0 +1,236 @@
+/*
+ * Virt Viewer: A virtual machine console viewer
+ *
+ * Copyright (C) 2015 Red Hat, Inc.
+ *
+ * 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
+ */
+
+#include "virt-viewer-file-transfer-dialog.h"
+#include <glib/gi18n.h>
+
+G_DEFINE_TYPE(VirtViewerFileTransferDialog, virt_viewer_file_transfer_dialog, GTK_TYPE_DIALOG)
+
+#define FILE_TRANSFER_DIALOG_PRIVATE(o) \
+        (G_TYPE_INSTANCE_GET_PRIVATE((o), VIRT_VIEWER_TYPE_FILE_TRANSFER_DIALOG, VirtViewerFileTransferDialogPrivate))
+
+struct _VirtViewerFileTransferDialogPrivate
+{
+    /* GHashTable<SpiceFileTransferTask, widgets> */
+    GHashTable *file_transfers;
+};
+
+
+/*
+static void
+virt_viewer_file_transfer_dialog_get_property(GObject *object,
+                                              guint property_id,
+                                              GValue *value,
+                                              GParamSpec *pspec)
+{
+    switch (property_id)
+    {
+        default:
+            G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+    }
+}
+
+static void
+virt_viewer_file_transfer_dialog_set_property(GObject *object,
+                                              guint property_id,
+                                              const GValue *value,
+                                              GParamSpec *pspec)
+{
+    switch (property_id)
+    {
+        default:
+            G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+    }
+}
+*/
+
+static void
+virt_viewer_file_transfer_dialog_dispose(GObject *object)
+{
+    VirtViewerFileTransferDialog *self = VIRT_VIEWER_FILE_TRANSFER_DIALOG(object);
+
+    if (self->priv->file_transfers) {
+        g_hash_table_unref(self->priv->file_transfers);
+        self->priv->file_transfers = NULL;
+    }
+
+    G_OBJECT_CLASS(virt_viewer_file_transfer_dialog_parent_class)->dispose(object);
+}
+
+static void
+virt_viewer_file_transfer_dialog_finalize(GObject *object)
+{
+    G_OBJECT_CLASS(virt_viewer_file_transfer_dialog_parent_class)->finalize(object);
+}
+
+static void
+virt_viewer_file_transfer_dialog_class_init(VirtViewerFileTransferDialogClass *klass)
+{
+    GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+    g_type_class_add_private(klass, sizeof(VirtViewerFileTransferDialogPrivate));
+
+    //object_class->get_property = virt_viewer_file_transfer_dialog_get_property;
+    //object_class->set_property = virt_viewer_file_transfer_dialog_set_property;
+    object_class->dispose = virt_viewer_file_transfer_dialog_dispose;
+    object_class->finalize = virt_viewer_file_transfer_dialog_finalize;
+}
+
+static void
+dialog_response(GtkDialog *dialog,
+                gint response_id,
+                gpointer user_data G_GNUC_UNUSED)
+{
+    VirtViewerFileTransferDialog *self = VIRT_VIEWER_FILE_TRANSFER_DIALOG(dialog);
+    GHashTableIter iter;
+    gpointer key, value;
+
+    g_debug("%s: %i", G_STRFUNC, response_id);
+    if (response_id == GTK_RESPONSE_CANCEL) {
+        /* cancel all current tasks */
+        g_hash_table_iter_init(&iter, self->priv->file_transfers);
+
+        while (g_hash_table_iter_next(&iter, &key, &value)) {
+            spice_file_transfer_task_cancel(SPICE_FILE_TRANSFER_TASK(key));
+        }
+    }
+}
+
+static void task_cancel_clicked(GtkButton *button G_GNUC_UNUSED,
+                                gpointer user_data)
+{
+    SpiceFileTransferTask *task = SPICE_FILE_TRANSFER_TASK(user_data);
+    spice_file_transfer_task_cancel(task);
+}
+
+typedef struct {
+    GtkWidget *vbox;
+    GtkWidget *hbox;
+    GtkWidget *progress;
+    GtkWidget *label;
+    GtkWidget *cancel;
+} TaskWidgets;
+
+static TaskWidgets *task_widgets_new(SpiceFileTransferTask *task)
+{
+    TaskWidgets *w = g_new0(TaskWidgets, 1);
+
+    w->vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 6);
+    w->hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 12);
+    w->progress = gtk_progress_bar_new();
+    gtk_widget_set_hexpand(w->progress, TRUE);
+    gtk_widget_set_valign(w->progress, GTK_ALIGN_CENTER);
+    w->label = gtk_label_new(spice_file_transfer_task_get_filename(task));
+    gtk_widget_set_hexpand(w->label, TRUE);
+    gtk_widget_set_valign(w->label, GTK_ALIGN_END);
+    gtk_widget_set_halign(w->label, GTK_ALIGN_START);
+    w->cancel = gtk_button_new_from_icon_name("gtk-cancel", GTK_ICON_SIZE_SMALL_TOOLBAR);
+    gtk_widget_set_hexpand(w->cancel, FALSE);
+    gtk_widget_set_valign(w->cancel, GTK_ALIGN_CENTER);
+    g_signal_connect(w->cancel, "clicked",
+                     G_CALLBACK(task_cancel_clicked), task);
+
+    gtk_box_pack_start(GTK_BOX(w->hbox), w->progress, TRUE, TRUE, 0);
+    gtk_box_pack_start(GTK_BOX(w->hbox), w->cancel, FALSE, TRUE, 0);
+    gtk_box_pack_start(GTK_BOX(w->vbox), w->label, TRUE, TRUE, 0);
+    gtk_box_pack_start(GTK_BOX(w->vbox), w->hbox, TRUE, TRUE, 0);
+
+    gtk_widget_show_all(w->vbox);
+    return w;
+}
+
+static void task_widgets_free(TaskWidgets *w)
+{
+    g_free(w);
+}
+
+static void
+virt_viewer_file_transfer_dialog_init(VirtViewerFileTransferDialog *self)
+{
+    GtkBox *content = GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(self)));
+
+    self->priv = FILE_TRANSFER_DIALOG_PRIVATE(self);
+
+    gtk_widget_set_size_request(GTK_WIDGET(content), 400, -1);
+    gtk_container_set_border_width(GTK_CONTAINER(content), 12);
+    self->priv->file_transfers = g_hash_table_new_full(g_direct_hash, g_direct_equal,
+                                                       g_object_unref,
+                                                       (GDestroyNotify)task_widgets_free);
+    gtk_dialog_add_button(GTK_DIALOG(self), _("Cancel"), GTK_RESPONSE_CANCEL);
+    gtk_dialog_set_default_response(GTK_DIALOG(self),
+                                    GTK_RESPONSE_CANCEL);
+    g_signal_connect(self, "response", G_CALLBACK(dialog_response), NULL);
+}
+
+VirtViewerFileTransferDialog *
+virt_viewer_file_transfer_dialog_new(GtkWindow *parent)
+{
+    return g_object_new(VIRT_VIEWER_TYPE_FILE_TRANSFER_DIALOG,
+                        "title", _("File Transfers"),
+                        "transient-for", parent,
+                        "resizable", FALSE,
+                        NULL);
+}
+
+static void task_progress_notify(GObject *object,
+                                 GParamSpec *pspec G_GNUC_UNUSED,
+                                 gpointer user_data)
+{
+    VirtViewerFileTransferDialog *self = VIRT_VIEWER_FILE_TRANSFER_DIALOG(user_data);
+    SpiceFileTransferTask *task = SPICE_FILE_TRANSFER_TASK(object);
+    TaskWidgets *w = g_hash_table_lookup(self->priv->file_transfers, task);
+    g_return_if_fail(w);
+
+    double pct = spice_file_transfer_task_get_progress(task);
+    gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(w->progress), pct);
+}
+
+static void task_finished(SpiceFileTransferTask *task,
+                          GError *error G_GNUC_UNUSED,
+                          gpointer user_data)
+{
+    VirtViewerFileTransferDialog *self = VIRT_VIEWER_FILE_TRANSFER_DIALOG(user_data);
+    TaskWidgets *w = g_hash_table_lookup(self->priv->file_transfers, task);
+    g_return_if_fail(w);
+
+    gtk_widget_destroy(w->vbox);
+
+    g_hash_table_remove(self->priv->file_transfers, task);
+
+    /* if this is the last transfer, close the dialog */
+    if (!g_hash_table_size(self->priv->file_transfers))
+        gtk_widget_hide(GTK_WIDGET(self));
+}
+
+void virt_viewer_file_transfer_dialog_add_task(VirtViewerFileTransferDialog *self,
+                                               SpiceFileTransferTask *task)
+{
+    GtkBox *content = GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(self)));
+    TaskWidgets *w = task_widgets_new(task);
+
+    gtk_box_pack_start(content,
+                       w->vbox,
+                       TRUE, TRUE, 12);
+    g_hash_table_insert(self->priv->file_transfers, g_object_ref(task), w);
+    g_signal_connect(task, "notify::progress", G_CALLBACK(task_progress_notify), self);
+    g_signal_connect(task, "finished", G_CALLBACK(task_finished), self);
+
+    gtk_widget_show(GTK_WIDGET(self));
+}
diff --git a/src/virt-viewer-file-transfer-dialog.h b/src/virt-viewer-file-transfer-dialog.h
new file mode 100644
index 0000000..27fbba2
--- /dev/null
+++ b/src/virt-viewer-file-transfer-dialog.h
@@ -0,0 +1,75 @@
+/*
+ * Virt Viewer: A virtual machine console viewer
+ *
+ * Copyright (C) 2015 Red Hat, Inc.
+ *
+ * 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
+ */
+
+#ifndef __VIRT_VIEWER_FILE_TRANSFER_DIALOG_H__
+#define __VIRT_VIEWER_FILE_TRANSFER_DIALOG_H__
+
+#include <gtk/gtk.h>
+#include <spice-file-transfer-task.h>
+
+G_BEGIN_DECLS
+
+#define VIRT_VIEWER_TYPE_FILE_TRANSFER_DIALOG virt_viewer_file_transfer_dialog_get_type()
+
+#define VIRT_VIEWER_FILE_TRANSFER_DIALOG(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+  VIRT_VIEWER_TYPE_FILE_TRANSFER_DIALOG, VirtViewerFileTransferDialog))
+
+#define VIRT_VIEWER_FILE_TRANSFER_DIALOG_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST((klass), \
+  VIRT_VIEWER_TYPE_FILE_TRANSFER_DIALOG, VirtViewerFileTransferDialogClass))
+
+#define VIRT_VIEWER_IS_FILE_TRANSFER_DIALOG(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE((obj), \
+  VIRT_VIEWER_TYPE_FILE_TRANSFER_DIALOG))
+
+#define VIRT_VIEWER_IS_FILE_TRANSFER_DIALOG_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE((klass), \
+  VIRT_VIEWER_TYPE_FILE_TRANSFER_DIALOG))
+
+#define VIRT_VIEWER_FILE_TRANSFER_DIALOG_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS((obj), \
+  VIRT_VIEWER_TYPE_FILE_TRANSFER_DIALOG, VirtViewerFileTransferDialogClass))
+
+typedef struct _VirtViewerFileTransferDialog VirtViewerFileTransferDialog;
+typedef struct _VirtViewerFileTransferDialogClass VirtViewerFileTransferDialogClass;
+typedef struct _VirtViewerFileTransferDialogPrivate VirtViewerFileTransferDialogPrivate;
+
+struct _VirtViewerFileTransferDialog
+{
+    GtkDialog parent;
+
+    VirtViewerFileTransferDialogPrivate *priv;
+};
+
+struct _VirtViewerFileTransferDialogClass
+{
+    GtkDialogClass parent_class;
+};
+
+GType virt_viewer_file_transfer_dialog_get_type(void) G_GNUC_CONST;
+
+VirtViewerFileTransferDialog *virt_viewer_file_transfer_dialog_new(GtkWindow *parent);
+void virt_viewer_file_transfer_dialog_add_task(VirtViewerFileTransferDialog *self,
+                                               SpiceFileTransferTask *task);
+
+G_END_DECLS
+
+#endif /* __VIRT_VIEWER_FILE_TRANSFER_DIALOG_H__ */
diff --git a/src/virt-viewer-main.c b/src/virt-viewer-main.c
index 505b472..9b9807a 100644
--- a/src/virt-viewer-main.c
+++ b/src/virt-viewer-main.c
@@ -29,7 +29,7 @@
 #include <vncdisplay.h>
 #endif
 #ifdef HAVE_SPICE_GTK
-#include <spice-option.h>
+#include <spice-client.h>
 #endif
 #include "virt-viewer.h"
 
diff --git a/src/virt-viewer-session-spice.c b/src/virt-viewer-session-spice.c
index eb0761d..61c96ec 100644
--- a/src/virt-viewer-session-spice.c
+++ b/src/virt-viewer-session-spice.c
@@ -24,14 +24,9 @@
 
 #include <config.h>
 
-#include <spice-audio.h>
 #include <glib/gi18n.h>
+#include <spice-client-gtk.h>
 
-#include <spice-option.h>
-#include <spice-util.h>
-#include <spice-client.h>
-
-#include <usb-device-widget.h>
 #include "virt-viewer-file.h"
 #include "virt-viewer-util.h"
 #include "virt-viewer-session-spice.h"
diff --git a/src/virt-viewer-session-spice.h b/src/virt-viewer-session-spice.h
index 95bdcdf..aa1f7e8 100644
--- a/src/virt-viewer-session-spice.h
+++ b/src/virt-viewer-session-spice.h
@@ -25,8 +25,7 @@
 #define _VIRT_VIEWER_SESSION_SPICE_H
 
 #include <glib-object.h>
-#include <spice-widget.h>
-#include <spice-audio.h>
+#include <spice-client.h>
 
 #include "virt-viewer-session.h"
 
-- 
2.1.0




More information about the virt-tools-list mailing list