[virt-tools-list] [virt-viewer][PATCH v2] app/window: Set display menu not sensitive when needed

Lukas Venhoda lvenhoda at redhat.com
Thu Apr 16 11:59:23 UTC 2015


Displays menu must be sensitive only when at least one display is
enabled.
---

v2:
Removed ternary operator from line 33.
sensitive = (keys != NULL) is enough here.

---
 src/virt-viewer-app.c    |  6 +++++-
 src/virt-viewer-window.c | 13 +++++++++++++
 src/virt-viewer-window.h |  1 +
 3 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c
index 563117a..7cf0c60 100644
--- a/src/virt-viewer-app.c
+++ b/src/virt-viewer-app.c
@@ -2253,17 +2253,21 @@ window_update_menu_displays_cb(gpointer value,
     GtkMenuShell *submenu;
     GList *keys = g_hash_table_get_keys(self->priv->displays);
     GList *tmp;
+    gboolean sensitive;

     keys = g_list_sort(keys, update_menu_displays_sort);
     submenu = window_empty_display_submenu(VIRT_VIEWER_WINDOW(value));

+    sensitive = (keys != NULL);
+    virt_viewer_window_set_menu_displays_sensitive(VIRT_VIEWER_WINDOW(value), sensitive);
+
     tmp = keys;
     while (tmp) {
         int nth = GPOINTER_TO_INT(tmp->data);
         VirtViewerWindow *vwin = virt_viewer_app_get_nth_window(self, nth);
         VirtViewerDisplay *display = VIRT_VIEWER_DISPLAY(g_hash_table_lookup(self->priv->displays, tmp->data));
         GtkWidget *item;
-        gboolean visible, sensitive;
+        gboolean visible;
         gchar *label;

         label = g_strdup_printf(_("Display %d"), nth + 1);
diff --git a/src/virt-viewer-window.c b/src/virt-viewer-window.c
index 18ae1bc..a1eceb5 100644
--- a/src/virt-viewer-window.c
+++ b/src/virt-viewer-window.c
@@ -1257,6 +1257,19 @@ virt_viewer_window_update_title(VirtViewerWindow *self)
 }

 void
+virt_viewer_window_set_menu_displays_sensitive(VirtViewerWindow *self, gboolean sensitive)
+{
+    VirtViewerWindowPrivate *priv;
+    GtkWidget *menu;
+
+    g_return_if_fail(VIRT_VIEWER_IS_WINDOW(self));
+
+    priv = self->priv;
+    menu = GTK_WIDGET(gtk_builder_get_object(priv->builder, "menu-displays"));
+    gtk_widget_set_sensitive(menu, sensitive);
+}
+
+void
 virt_viewer_window_set_usb_options_sensitive(VirtViewerWindow *self, gboolean sensitive)
 {
     VirtViewerWindowPrivate *priv;
diff --git a/src/virt-viewer-window.h b/src/virt-viewer-window.h
index 8a4322b..1f1e130 100644
--- a/src/virt-viewer-window.h
+++ b/src/virt-viewer-window.h
@@ -69,6 +69,7 @@ GtkWindow* virt_viewer_window_get_window (VirtViewerWindow* window);
 VirtViewerNotebook* virt_viewer_window_get_notebook (VirtViewerWindow* window);
 void virt_viewer_window_set_display(VirtViewerWindow *self, VirtViewerDisplay *display);
 VirtViewerDisplay* virt_viewer_window_get_display(VirtViewerWindow *self);
+void virt_viewer_window_set_menu_displays_sensitive(VirtViewerWindow *self, gboolean sensitive);
 void virt_viewer_window_set_usb_options_sensitive(VirtViewerWindow *self, gboolean sensitive);
 void virt_viewer_window_update_title(VirtViewerWindow *self);
 void virt_viewer_window_show(VirtViewerWindow *self);
--
2.3.0




More information about the virt-tools-list mailing list