[virt-tools-list] [PATCH virt-viewer 07/10] iso-dialog: Implement functionality provided by oVirt foreign menu

Christophe Fergeau cfergeau at redhat.com
Tue Jan 17 16:13:05 UTC 2017


On Fri, Jan 13, 2017 at 07:11:09PM -0200, Eduardo Lima (Etrunko) wrote:
> Signed-off-by: Eduardo Lima (Etrunko) <etrunko at redhat.com>
> ---
>  src/remote-viewer-iso-list-dialog.c        | 205 ++++++++++++++++++++++++++++-
>  src/resources/ui/remote-viewer-iso-list.ui |   5 +-
>  2 files changed, 206 insertions(+), 4 deletions(-)
> 
> diff --git a/src/remote-viewer-iso-list-dialog.c b/src/remote-viewer-iso-list-dialog.c
> index 858719c..00371ff 100644
> --- a/src/remote-viewer-iso-list-dialog.c
> +++ b/src/remote-viewer-iso-list-dialog.c
> @@ -20,12 +20,16 @@
>  
>  #include <config.h>
>  
> +#include <stdlib.h>
>  #include <glib/gi18n.h>
>  
>  #include "remote-viewer-iso-list-dialog.h"
>  #include "virt-viewer-util.h"
>  #include "ovirt-foreign-menu.h"
>  
> +static void ovirt_foreign_menu_iso_name_changed(OvirtForeignMenu *foreign_menu, GAsyncResult *result, RemoteViewerISOListDialog *self);
> +static void remote_viewer_iso_list_dialog_show_error(RemoteViewerISOListDialog *self, gchar *message);
> +
>  G_DEFINE_TYPE(RemoteViewerISOListDialog, remote_viewer_iso_list_dialog, GTK_TYPE_DIALOG)
>  
>  #define DIALOG_PRIVATE(o) \
> @@ -33,17 +37,32 @@ G_DEFINE_TYPE(RemoteViewerISOListDialog, remote_viewer_iso_list_dialog, GTK_TYPE
>  
>  struct _RemoteViewerISOListDialogPrivate
>  {
> +    GtkListStore *list_store;
>      GtkWidget *stack;
> +    GtkWidget *tree_view;
>      OvirtForeignMenu *foreign_menu;
>  };
>  
> +enum RemoteViewerISOListDialogModel
> +{
> +    ISO_IS_ACTIVE = 0,
> +    ISO_NAME,
> +    FONT_WEIGHT,
> +};
> +
> +void remote_viewer_iso_list_dialog_toggled(GtkCellRendererToggle *cell_renderer, gchar *path, gpointer user_data);
> +void remote_viewer_iso_list_dialog_row_activated(GtkTreeView *view, GtkTreePath *path, GtkTreeViewColumn *col, gpointer user_data);
> +
>  static void
>  remote_viewer_iso_list_dialog_dispose(GObject *object)
>  {
>      RemoteViewerISOListDialog *self = REMOTE_VIEWER_ISO_LIST_DIALOG(object);
>      RemoteViewerISOListDialogPrivate *priv = self->priv;
>  
> -    g_clear_object(&priv->foreign_menu);
> +    if (priv->foreign_menu) {
> +        g_signal_handlers_disconnect_by_data(priv->foreign_menu, object);
> +        g_clear_object(&priv->foreign_menu);
> +    }
>      G_OBJECT_CLASS(remote_viewer_iso_list_dialog_parent_class)->dispose(object);
>  }
>  
> @@ -58,6 +77,74 @@ remote_viewer_iso_list_dialog_class_init(RemoteViewerISOListDialogClass *klass)
>  }
>  
>  static void
> +remote_viewer_iso_list_dialog_show_files(RemoteViewerISOListDialog *self)
> +{
> +    RemoteViewerISOListDialogPrivate *priv = self->priv = DIALOG_PRIVATE(self);
> +    gtk_stack_set_visible_child_full(GTK_STACK(priv->stack), "iso-list",
> +                                     GTK_STACK_TRANSITION_TYPE_SLIDE_LEFT);
> +    gtk_dialog_set_response_sensitive(GTK_DIALOG(self), GTK_RESPONSE_NONE, TRUE);
> +}
> +
> +static void
> +remote_viewer_iso_list_dialog_foreach(char *name, RemoteViewerISOListDialog *self)
> +{
> +    RemoteViewerISOListDialogPrivate *priv = self->priv;
> +    char * current_iso = ovirt_foreign_menu_get_current_iso_name(self->priv->foreign_menu);
> +    gboolean active = g_strcmp0(current_iso, name) == 0;
> +    gint weight = active ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL;
> +    GtkTreeIter iter;
> +
> +    gtk_list_store_append(priv->list_store, &iter);
> +    gtk_list_store_set(priv->list_store, &iter,
> +                       ISO_IS_ACTIVE, active,
> +                       ISO_NAME, name,
> +                       FONT_WEIGHT, weight, -1);
> +
> +    if (active) {
> +        GtkTreePath *path = gtk_tree_model_get_path(GTK_TREE_MODEL(priv->list_store), &iter);
> +        gtk_tree_view_set_cursor(GTK_TREE_VIEW(priv->tree_view), path, NULL, FALSE);
> +        gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(priv->tree_view), path, NULL, TRUE, 0.5, 0.5);
> +        gtk_tree_path_free(path);
> +    }
> +
> +    free(current_iso);
> +}
> +
> +static void
> +fetch_iso_names_cb(OvirtForeignMenu *foreign_menu,
> +                   GAsyncResult *result,
> +                   RemoteViewerISOListDialog *self)
> +{
> +    RemoteViewerISOListDialogPrivate *priv = self->priv;
> +    GError *error = NULL;
> +    GList *iso_list;
> +
> +    iso_list = ovirt_foreign_menu_fetch_iso_names_finish(foreign_menu, result, &error);
> +
> +    if (!iso_list) {
> +        remote_viewer_iso_list_dialog_show_error(self, error ? error->message : _("Failed to fetch CD names"));
> +        g_clear_error(&error);

You need to stop showing the spinner when an error occurred here or it
will spin indefinitely.

> +        return;
> +    }
> +
> +    iso_list = ovirt_foreign_menu_get_iso_names(priv->foreign_menu);

Is it intended that you get iso_list once from ovirt_foreign_menu_fetch_iso_names_finish and then
from ovirt_foreign_menu_get_iso_names?

Christophe
-------------- 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/20170117/0f8b28b1/attachment.sig>


More information about the virt-tools-list mailing list