[virt-tools-list] [PATCH virt-viewer v3 00/10] Replace oVirt foreign menu with dedicated dialog
Christophe Fergeau
cfergeau at redhat.com
Mon Sep 5 12:15:18 UTC 2016
On Tue, Aug 02, 2016 at 06:17:31PM +0200, Christophe Fergeau wrote:
> > Eduardo Lima (Etrunko) (10):
> > ovirt-foreign-menu: Remove timer used to refresh iso list
> > ovirt-foreign-menu: Add accessors for current iso and iso list
> > ovirt-foreign-menu: Remove GtkMenu related functions
> > ovirt-foreign-menu: Notify of new files even if nothing changed
> > UI: Make 'Change CD' menu item a submenu under 'File' toplevel menu
> > Introduce ISO List dialog
> > Run iso-dialog when 'Change CD' menu is activated
> > remote-viewer: Make ovirt-foreign-menu a property
> > iso-dialog: Implement functionality provided by oVirt foreign menu
> > iso-dialog: Use header bar for buttons
>
> I'm not sure how to approach this series as I don't think
> 'ovirt-foreign-menu: Add accessors for current iso and iso list'
See the attached patch for some variation around this which avoids
relying on notify::file and add an async method to do it.
Christophe
-------------- next part --------------
From 910272343409332953fe9a91b8e6d8398290c380 Mon Sep 17 00:00:00 2001
From: Christophe Fergeau <cfergeau at redhat.com>
Date: Mon, 5 Sep 2016 12:13:42 +0200
Subject: [virt-viewer] Add ovirt_foreign_menu_set_current_iso_name_async
---
src/ovirt-foreign-menu.c | 42 +++++++++++++++++++++++++------------
src/ovirt-foreign-menu.h | 9 +++++++-
src/remote-viewer-iso-list-dialog.c | 14 +++++++------
3 files changed, 45 insertions(+), 20 deletions(-)
diff --git a/src/ovirt-foreign-menu.c b/src/ovirt-foreign-menu.c
index 8320552..2923554 100644
--- a/src/ovirt-foreign-menu.c
+++ b/src/ovirt-foreign-menu.c
@@ -47,7 +47,7 @@ static void ovirt_foreign_menu_fetch_storage_domain_async(OvirtForeignMenu *menu
static void ovirt_foreign_menu_fetch_vm_cdrom_async(OvirtForeignMenu *menu);
static void ovirt_foreign_menu_refresh_cdrom_file_async(OvirtForeignMenu *menu);
static void ovirt_foreign_menu_fetch_iso_list_async(OvirtForeignMenu *menu);
-static void updated_cdrom_cb(GObject *source_object, GAsyncResult *result, gpointer user_data);
+static void iso_name_set_cb(GObject *source_object, GAsyncResult *result, gpointer user_data);
G_DEFINE_TYPE (OvirtForeignMenu, ovirt_foreign_menu, G_TYPE_OBJECT)
@@ -102,8 +102,14 @@ ovirt_foreign_menu_get_current_iso_name(OvirtForeignMenu *foreign_menu)
void
-ovirt_foreign_menu_set_current_iso_name(OvirtForeignMenu *foreign_menu, char *name)
+ovirt_foreign_menu_set_current_iso_name_async(OvirtForeignMenu *foreign_menu,
+ char *name,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
+ GTask *task = g_task_new(foreign_menu, cancellable, callback, user_data);
+
g_return_if_fail(foreign_menu->priv->cdrom != NULL);
g_return_if_fail(foreign_menu->priv->next_iso_name == NULL);
@@ -120,9 +126,17 @@ ovirt_foreign_menu_set_current_iso_name(OvirtForeignMenu *foreign_menu, char *na
NULL);
ovirt_cdrom_update_async(foreign_menu->priv->cdrom, TRUE,
foreign_menu->priv->proxy, NULL,
- updated_cdrom_cb, foreign_menu);
+ iso_name_set_cb, task);
}
+gboolean ovirt_foreign_menu_set_current_iso_name_finish(OvirtForeignMenu *foreign_menu,
+ GAsyncResult *result,
+ GError **error)
+{
+ g_return_val_if_fail(OVIRT_IS_FOREIGN_MENU(foreign_menu), FALSE);
+
+ return g_task_propagate_boolean(G_TASK(result), error);
+}
GList*
ovirt_foreign_menu_get_iso_names(OvirtForeignMenu *foreign_menu)
@@ -359,15 +373,16 @@ ovirt_foreign_menu_start(OvirtForeignMenu *menu)
}
-static void updated_cdrom_cb(GObject *source_object,
- GAsyncResult *result,
- gpointer user_data)
+static void iso_name_set_cb(GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
{
GError *error = NULL;
OvirtForeignMenu *foreign_menu;
gboolean updated;
+ GTask *task = G_TASK(user_data);
- foreign_menu = OVIRT_FOREIGN_MENU(user_data);
+ foreign_menu = OVIRT_FOREIGN_MENU(g_task_get_source_object(task));
updated = ovirt_cdrom_update_finish(OVIRT_CDROM(source_object),
result, &error);
g_debug("Finished updating cdrom content");
@@ -375,14 +390,19 @@ static void updated_cdrom_cb(GObject *source_object,
g_free(foreign_menu->priv->current_iso_name);
foreign_menu->priv->current_iso_name = foreign_menu->priv->next_iso_name;
foreign_menu->priv->next_iso_name = NULL;
- goto end;
+ g_task_return_boolean(task, TRUE);
+ return;
}
/* Reset old state back as we were not successful in switching to
* the new ISO */
if (error != NULL) {
g_warning("failed to update cdrom resource: %s", error->message);
- g_clear_error(&error);
+ g_task_return_error(task, error);
+ } else {
+ g_warn_if_reached();
+ g_task_return_error(task, g_error_new_literal(OVIRT_ERROR, OVIRT_ERROR_FAILED,
+ "failed to update cdrom resource"));
}
g_debug("setting OvirtCdrom:file back to '%s'",
foreign_menu->priv->current_iso_name);
@@ -390,12 +410,8 @@ static void updated_cdrom_cb(GObject *source_object,
"file", foreign_menu->priv->current_iso_name,
NULL);
g_clear_pointer(&foreign_menu->priv->next_iso_name, g_free);
-
-end:
- g_object_notify(G_OBJECT(foreign_menu), "file");
}
-
static void ovirt_foreign_menu_set_files(OvirtForeignMenu *menu,
const GList *files)
{
diff --git a/src/ovirt-foreign-menu.h b/src/ovirt-foreign-menu.h
index f1a1ddb..df4a50e 100644
--- a/src/ovirt-foreign-menu.h
+++ b/src/ovirt-foreign-menu.h
@@ -71,7 +71,14 @@ OvirtForeignMenu *ovirt_foreign_menu_new_from_file(VirtViewerFile *self);
void ovirt_foreign_menu_start(OvirtForeignMenu *menu);
char *ovirt_foreign_menu_get_current_iso_name(OvirtForeignMenu *menu);
-void ovirt_foreign_menu_set_current_iso_name(OvirtForeignMenu *menu, char *name);
+void ovirt_foreign_menu_set_current_iso_name_async(OvirtForeignMenu *foreign_menu,
+ char *name,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+gboolean ovirt_foreign_menu_set_current_iso_name_finish(OvirtForeignMenu *foreign_menu,
+ GAsyncResult *result,
+ GError **error);
GList *ovirt_foreign_menu_get_iso_names(OvirtForeignMenu *menu);
diff --git a/src/remote-viewer-iso-list-dialog.c b/src/remote-viewer-iso-list-dialog.c
index dd652d7..6455308 100644
--- a/src/remote-viewer-iso-list-dialog.c
+++ b/src/remote-viewer-iso-list-dialog.c
@@ -27,6 +27,8 @@
#include "virt-viewer-util.h"
#include "ovirt-foreign-menu.h"
+static void ovirt_foreign_menu_notify_file(OvirtForeignMenu *foreign_menu, GAsyncResult *result, RemoteViewerISOListDialog *self);
+
G_DEFINE_TYPE(RemoteViewerISOListDialog, remote_viewer_iso_list_dialog, GTK_TYPE_DIALOG)
#define DIALOG_PRIVATE(o) \
@@ -180,7 +182,9 @@ remote_viewer_iso_list_dialog_toggled(GtkCellRendererToggle *cell_renderer G_GNU
gtk_dialog_set_response_sensitive(GTK_DIALOG(self), GTK_RESPONSE_NONE, FALSE);
gtk_widget_set_sensitive(priv->tree_view, FALSE);
- ovirt_foreign_menu_set_current_iso_name(priv->foreign_menu, active ? NULL : name);
+ ovirt_foreign_menu_set_current_iso_name_async(priv->foreign_menu, active ? NULL : name, NULL,
+ (GAsyncReadyCallback)ovirt_foreign_menu_notify_file,
+ self);
gtk_tree_path_free(tree_path);
g_free(name);
}
@@ -232,7 +236,7 @@ remote_viewer_iso_list_dialog_init(RemoteViewerISOListDialog *self)
static void
ovirt_foreign_menu_notify_file(OvirtForeignMenu *foreign_menu,
- GParamSpec *pspec G_GNUC_UNUSED,
+ GAsyncResult *result,
RemoteViewerISOListDialog *self)
{
RemoteViewerISOListDialogPrivate *priv = self->priv;
@@ -241,7 +245,9 @@ ovirt_foreign_menu_notify_file(OvirtForeignMenu *foreign_menu,
GtkTreeIter iter;
gchar *name;
gboolean active, match = FALSE;
+ GError *error = NULL;
+ g_warn_if_fail(ovirt_foreign_menu_set_current_iso_name_finish(foreign_menu, result, &error));
if (!gtk_tree_model_get_iter_first(model, &iter))
goto end;
@@ -303,10 +309,6 @@ remote_viewer_iso_list_dialog_new(GtkWindow *parent, GObject *foreign_menu)
self->priv->foreign_menu = OVIRT_FOREIGN_MENU(g_object_ref(foreign_menu));
g_signal_connect(foreign_menu,
- "notify::file",
- (GCallback)ovirt_foreign_menu_notify_file,
- dialog);
- g_signal_connect(foreign_menu,
"notify::files",
(GCallback)ovirt_foreign_menu_notify_files,
dialog);
--
2.7.4
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/virt-tools-list/attachments/20160905/0de972a4/attachment.sig>
More information about the virt-tools-list
mailing list