Patchwork gtk: Add control menu with stop, reset and power-down entries

login
register
mail settings
Submitter Jan Kiszka
Date Feb. 22, 2013, 2:56 p.m.
Message ID <51278735.4040908@siemens.com>
Download mbox | patch
Permalink /patch/222542/
State New
Headers show

Comments

Jan Kiszka - Feb. 22, 2013, 2:56 p.m.
This adds basic guest control commands to a new menu - a nice
added-value for the GTK UI.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 ui/gtk.c |   64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 63 insertions(+), 1 deletions(-)
Anthony Liguori - Feb. 22, 2013, 3:35 p.m.
Jan Kiszka <jan.kiszka@siemens.com> writes:

> This adds basic guest control commands to a new menu - a nice
> added-value for the GTK UI.
>
> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
> ---
>  ui/gtk.c |   64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
>  1 files changed, 63 insertions(+), 1 deletions(-)
>
> diff --git a/ui/gtk.c b/ui/gtk.c
> index bc4ec67..5445a61 100644
> --- a/ui/gtk.c
> +++ b/ui/gtk.c
> @@ -84,6 +84,12 @@ typedef struct GtkDisplayState
>      GtkWidget *file_menu;
>      GtkWidget *quit_item;
>  
> +    GtkWidget *control_menu_item;

Let's rename the File menu to Machine and stick it all under there.

> +    GtkWidget *control_menu;
> +    GtkWidget *stop_item;
> +    GtkWidget *reset_item;
> +    GtkWidget *powerdown_item;
> +
>      GtkWidget *view_menu_item;
>      GtkWidget *view_menu;
>      GtkWidget *full_screen_item;
> @@ -117,6 +123,8 @@ typedef struct GtkDisplayState
>      GdkCursor *null_cursor;
>      Notifier mouse_mode_notifier;
>      gboolean free_scale;
> +
> +    bool external_stop_update;
>  } GtkDisplayState;
>  
>  static GtkDisplayState *global_state;
> @@ -160,14 +168,19 @@ static void gd_update_caption(GtkDisplayState *s)
>      const char *status = "";
>      gchar *title;
>      const char *grab = "";
> +    bool is_stopped = !runstate_is_running();
>  
>      if (gd_is_grab_active(s)) {
>          grab = " - Press Ctrl+Alt+G to release grab";
>      }
>  
> -    if (!runstate_is_running()) {
> +    if (is_stopped) {
>          status = " [Stopped]";
>      }
> +    s->external_stop_update = true;
> +    gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->stop_item),
> +                                   is_stopped);
> +    s->external_stop_update = false;

We also need a vmstate listener in order to catch stop from the monitor.

>  
>      if (qemu_name) {
>          title = g_strdup_printf("QEMU (%s)%s%s", qemu_name, status, grab);
> @@ -589,6 +602,30 @@ static void gd_menu_quit(GtkMenuItem *item, void *opaque)
>      qmp_quit(NULL);
>  }
>  
> +static void gd_menu_stop(GtkMenuItem *item, void *opaque)
> +{
> +    GtkDisplayState *s = opaque;
> +
> +    if (s->external_stop_update) {
> +        return;
> +    }
> +    if (runstate_is_running()) {
> +        qmp_stop(NULL);
> +    } else {
> +        qmp_cont(NULL);
> +    }
> +}
> +
> +static void gd_menu_reset(GtkMenuItem *item, void *opaque)
> +{
> +    qmp_system_reset(NULL);
> +}
> +
> +static void gd_menu_powerdown(GtkMenuItem *item, void *opaque)
> +{
> +    qmp_system_powerdown(NULL);
> +}
> +
>  static void gd_menu_switch_vc(GtkMenuItem *item, void *opaque)
>  {
>      GtkDisplayState *s = opaque;
> @@ -954,6 +991,12 @@ static void gd_connect_signals(GtkDisplayState *s)
>  
>      g_signal_connect(s->quit_item, "activate",
>                       G_CALLBACK(gd_menu_quit), s);
> +    g_signal_connect(s->stop_item, "activate",
> +                     G_CALLBACK(gd_menu_stop), s);
> +    g_signal_connect(s->reset_item, "activate",
> +                     G_CALLBACK(gd_menu_reset), s);
> +    g_signal_connect(s->powerdown_item, "activate",
> +                     G_CALLBACK(gd_menu_powerdown), s);
>      g_signal_connect(s->full_screen_item, "activate",
>                       G_CALLBACK(gd_menu_full_screen), s);
>      g_signal_connect(s->zoom_in_item, "activate",
> @@ -995,6 +1038,22 @@ static void gd_create_menus(GtkDisplayState *s)
>                                   "<QEMU>/File/Quit");
>      gtk_accel_map_add_entry("<QEMU>/File/Quit", item.keyval, item.modifier);
>  
> +    s->control_menu = gtk_menu_new();
> +    gtk_menu_set_accel_group(GTK_MENU(s->control_menu), accel_group);
> +    s->control_menu_item = gtk_menu_item_new_with_mnemonic(_("_Control"));
> +
> +    s->stop_item = gtk_check_menu_item_new_with_mnemonic(_("_Stop"));
> +    gtk_menu_append(GTK_MENU(s->control_menu), s->stop_item);

There's a stock menu for this.

http://developer.gnome.org/gtk3/stable/gtk3-Stock-Items.html#GTK-STOCK-STOP:CAPS

> +
> +    separator = gtk_separator_menu_item_new();
> +    gtk_menu_append(GTK_MENU(s->control_menu), separator);
> +
> +    s->reset_item = gtk_image_menu_item_new_with_mnemonic(_("_Reset"));
> +    gtk_menu_append(GTK_MENU(s->control_menu), s->reset_item);
> +
> +    s->powerdown_item = gtk_image_menu_item_new_with_mnemonic(_("_Power-down"));

Regards,

Anthony Liguori

> +    gtk_menu_append(GTK_MENU(s->control_menu), s->powerdown_item);
> +
>      s->view_menu = gtk_menu_new();
>      gtk_menu_set_accel_group(GTK_MENU(s->view_menu), accel_group);
>      s->view_menu_item = gtk_menu_item_new_with_mnemonic(_("_View"));
> @@ -1072,6 +1131,9 @@ static void gd_create_menus(GtkDisplayState *s)
>      gtk_menu_item_set_submenu(GTK_MENU_ITEM(s->file_menu_item), s->file_menu);
>      gtk_menu_shell_append(GTK_MENU_SHELL(s->menu_bar), s->file_menu_item);
>  
> +    gtk_menu_item_set_submenu(GTK_MENU_ITEM(s->control_menu_item), s->control_menu);
> +    gtk_menu_shell_append(GTK_MENU_SHELL(s->menu_bar), s->control_menu_item);
> +
>      gtk_menu_item_set_submenu(GTK_MENU_ITEM(s->view_menu_item), s->view_menu);
>      gtk_menu_shell_append(GTK_MENU_SHELL(s->menu_bar), s->view_menu_item);
>  }
> -- 
> 1.7.3.4
Jan Kiszka - Feb. 22, 2013, 3:38 p.m.
On 2013-02-22 16:35, Anthony Liguori wrote:
> Jan Kiszka <jan.kiszka@siemens.com> writes:
> 
>> This adds basic guest control commands to a new menu - a nice
>> added-value for the GTK UI.
>>
>> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
>> ---
>>  ui/gtk.c |   64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
>>  1 files changed, 63 insertions(+), 1 deletions(-)
>>
>> diff --git a/ui/gtk.c b/ui/gtk.c
>> index bc4ec67..5445a61 100644
>> --- a/ui/gtk.c
>> +++ b/ui/gtk.c
>> @@ -84,6 +84,12 @@ typedef struct GtkDisplayState
>>      GtkWidget *file_menu;
>>      GtkWidget *quit_item;
>>  
>> +    GtkWidget *control_menu_item;
> 
> Let's rename the File menu to Machine and stick it all under there.

Ok.

> 
>> +    GtkWidget *control_menu;
>> +    GtkWidget *stop_item;
>> +    GtkWidget *reset_item;
>> +    GtkWidget *powerdown_item;
>> +
>>      GtkWidget *view_menu_item;
>>      GtkWidget *view_menu;
>>      GtkWidget *full_screen_item;
>> @@ -117,6 +123,8 @@ typedef struct GtkDisplayState
>>      GdkCursor *null_cursor;
>>      Notifier mouse_mode_notifier;
>>      gboolean free_scale;
>> +
>> +    bool external_stop_update;
>>  } GtkDisplayState;
>>  
>>  static GtkDisplayState *global_state;
>> @@ -160,14 +168,19 @@ static void gd_update_caption(GtkDisplayState *s)
>>      const char *status = "";
>>      gchar *title;
>>      const char *grab = "";
>> +    bool is_stopped = !runstate_is_running();
>>  
>>      if (gd_is_grab_active(s)) {
>>          grab = " - Press Ctrl+Alt+G to release grab";
>>      }
>>  
>> -    if (!runstate_is_running()) {
>> +    if (is_stopped) {
>>          status = " [Stopped]";
>>      }
>> +    s->external_stop_update = true;
>> +    gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->stop_item),
>> +                                   is_stopped);
>> +    s->external_stop_update = false;
> 
> We also need a vmstate listener in order to catch stop from the monitor.

Nope, we get this event already.

> 
>>  
>>      if (qemu_name) {
>>          title = g_strdup_printf("QEMU (%s)%s%s", qemu_name, status, grab);
>> @@ -589,6 +602,30 @@ static void gd_menu_quit(GtkMenuItem *item, void *opaque)
>>      qmp_quit(NULL);
>>  }
>>  
>> +static void gd_menu_stop(GtkMenuItem *item, void *opaque)
>> +{
>> +    GtkDisplayState *s = opaque;
>> +
>> +    if (s->external_stop_update) {
>> +        return;
>> +    }
>> +    if (runstate_is_running()) {
>> +        qmp_stop(NULL);
>> +    } else {
>> +        qmp_cont(NULL);
>> +    }
>> +}
>> +
>> +static void gd_menu_reset(GtkMenuItem *item, void *opaque)
>> +{
>> +    qmp_system_reset(NULL);
>> +}
>> +
>> +static void gd_menu_powerdown(GtkMenuItem *item, void *opaque)
>> +{
>> +    qmp_system_powerdown(NULL);
>> +}
>> +
>>  static void gd_menu_switch_vc(GtkMenuItem *item, void *opaque)
>>  {
>>      GtkDisplayState *s = opaque;
>> @@ -954,6 +991,12 @@ static void gd_connect_signals(GtkDisplayState *s)
>>  
>>      g_signal_connect(s->quit_item, "activate",
>>                       G_CALLBACK(gd_menu_quit), s);
>> +    g_signal_connect(s->stop_item, "activate",
>> +                     G_CALLBACK(gd_menu_stop), s);
>> +    g_signal_connect(s->reset_item, "activate",
>> +                     G_CALLBACK(gd_menu_reset), s);
>> +    g_signal_connect(s->powerdown_item, "activate",
>> +                     G_CALLBACK(gd_menu_powerdown), s);
>>      g_signal_connect(s->full_screen_item, "activate",
>>                       G_CALLBACK(gd_menu_full_screen), s);
>>      g_signal_connect(s->zoom_in_item, "activate",
>> @@ -995,6 +1038,22 @@ static void gd_create_menus(GtkDisplayState *s)
>>                                   "<QEMU>/File/Quit");
>>      gtk_accel_map_add_entry("<QEMU>/File/Quit", item.keyval, item.modifier);
>>  
>> +    s->control_menu = gtk_menu_new();
>> +    gtk_menu_set_accel_group(GTK_MENU(s->control_menu), accel_group);
>> +    s->control_menu_item = gtk_menu_item_new_with_mnemonic(_("_Control"));
>> +
>> +    s->stop_item = gtk_check_menu_item_new_with_mnemonic(_("_Stop"));
>> +    gtk_menu_append(GTK_MENU(s->control_menu), s->stop_item);
> 
> There's a stock menu for this.
> 
> http://developer.gnome.org/gtk3/stable/gtk3-Stock-Items.html#GTK-STOCK-STOP:CAPS

Ok, v2 follows.

Jan
Jan Kiszka - Feb. 22, 2013, 3:57 p.m.
On 2013-02-22 16:38, Jan Kiszka wrote:
>>> @@ -995,6 +1038,22 @@ static void gd_create_menus(GtkDisplayState *s)
>>>                                   "<QEMU>/File/Quit");
>>>      gtk_accel_map_add_entry("<QEMU>/File/Quit", item.keyval, item.modifier);
>>>  
>>> +    s->control_menu = gtk_menu_new();
>>> +    gtk_menu_set_accel_group(GTK_MENU(s->control_menu), accel_group);
>>> +    s->control_menu_item = gtk_menu_item_new_with_mnemonic(_("_Control"));
>>> +
>>> +    s->stop_item = gtk_check_menu_item_new_with_mnemonic(_("_Stop"));
>>> +    gtk_menu_append(GTK_MENU(s->control_menu), s->stop_item);
>>
>> There's a stock menu for this.
>>
>> http://developer.gnome.org/gtk3/stable/gtk3-Stock-Items.html#GTK-STOCK-STOP:CAPS
> 
> Ok, v2 follows.

Hmm, I suppose "stock image" and "check" exclude each other, don't they?
Still, I will pick up the accelerator.

Jan
Anthony Liguori - Feb. 22, 2013, 4:51 p.m.
Jan Kiszka <jan.kiszka@siemens.com> writes:

> On 2013-02-22 16:38, Jan Kiszka wrote:
>>>> @@ -995,6 +1038,22 @@ static void gd_create_menus(GtkDisplayState *s)
>>>>                                   "<QEMU>/File/Quit");
>>>>      gtk_accel_map_add_entry("<QEMU>/File/Quit", item.keyval, item.modifier);
>>>>  
>>>> +    s->control_menu = gtk_menu_new();
>>>> +    gtk_menu_set_accel_group(GTK_MENU(s->control_menu), accel_group);
>>>> +    s->control_menu_item = gtk_menu_item_new_with_mnemonic(_("_Control"));
>>>> +
>>>> +    s->stop_item = gtk_check_menu_item_new_with_mnemonic(_("_Stop"));
>>>> +    gtk_menu_append(GTK_MENU(s->control_menu), s->stop_item);
>>>
>>> There's a stock menu for this.
>>>
>>> http://developer.gnome.org/gtk3/stable/gtk3-Stock-Items.html#GTK-STOCK-STOP:CAPS
>> 
>> Ok, v2 follows.
>
> Hmm, I suppose "stock image" and "check" exclude each other, don't they?
> Still, I will pick up the accelerator.

Yeah, but you can pick up the label text which should be automagically
internationalized.

Regards,

Anthony Liguori

>
> Jan
>
> -- 
> Siemens AG, Corporate Technology, CT RTC ITP SDP-DE
> Corporate Competence Center Embedded Linux

Patch

diff --git a/ui/gtk.c b/ui/gtk.c
index bc4ec67..5445a61 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -84,6 +84,12 @@  typedef struct GtkDisplayState
     GtkWidget *file_menu;
     GtkWidget *quit_item;
 
+    GtkWidget *control_menu_item;
+    GtkWidget *control_menu;
+    GtkWidget *stop_item;
+    GtkWidget *reset_item;
+    GtkWidget *powerdown_item;
+
     GtkWidget *view_menu_item;
     GtkWidget *view_menu;
     GtkWidget *full_screen_item;
@@ -117,6 +123,8 @@  typedef struct GtkDisplayState
     GdkCursor *null_cursor;
     Notifier mouse_mode_notifier;
     gboolean free_scale;
+
+    bool external_stop_update;
 } GtkDisplayState;
 
 static GtkDisplayState *global_state;
@@ -160,14 +168,19 @@  static void gd_update_caption(GtkDisplayState *s)
     const char *status = "";
     gchar *title;
     const char *grab = "";
+    bool is_stopped = !runstate_is_running();
 
     if (gd_is_grab_active(s)) {
         grab = " - Press Ctrl+Alt+G to release grab";
     }
 
-    if (!runstate_is_running()) {
+    if (is_stopped) {
         status = " [Stopped]";
     }
+    s->external_stop_update = true;
+    gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->stop_item),
+                                   is_stopped);
+    s->external_stop_update = false;
 
     if (qemu_name) {
         title = g_strdup_printf("QEMU (%s)%s%s", qemu_name, status, grab);
@@ -589,6 +602,30 @@  static void gd_menu_quit(GtkMenuItem *item, void *opaque)
     qmp_quit(NULL);
 }
 
+static void gd_menu_stop(GtkMenuItem *item, void *opaque)
+{
+    GtkDisplayState *s = opaque;
+
+    if (s->external_stop_update) {
+        return;
+    }
+    if (runstate_is_running()) {
+        qmp_stop(NULL);
+    } else {
+        qmp_cont(NULL);
+    }
+}
+
+static void gd_menu_reset(GtkMenuItem *item, void *opaque)
+{
+    qmp_system_reset(NULL);
+}
+
+static void gd_menu_powerdown(GtkMenuItem *item, void *opaque)
+{
+    qmp_system_powerdown(NULL);
+}
+
 static void gd_menu_switch_vc(GtkMenuItem *item, void *opaque)
 {
     GtkDisplayState *s = opaque;
@@ -954,6 +991,12 @@  static void gd_connect_signals(GtkDisplayState *s)
 
     g_signal_connect(s->quit_item, "activate",
                      G_CALLBACK(gd_menu_quit), s);
+    g_signal_connect(s->stop_item, "activate",
+                     G_CALLBACK(gd_menu_stop), s);
+    g_signal_connect(s->reset_item, "activate",
+                     G_CALLBACK(gd_menu_reset), s);
+    g_signal_connect(s->powerdown_item, "activate",
+                     G_CALLBACK(gd_menu_powerdown), s);
     g_signal_connect(s->full_screen_item, "activate",
                      G_CALLBACK(gd_menu_full_screen), s);
     g_signal_connect(s->zoom_in_item, "activate",
@@ -995,6 +1038,22 @@  static void gd_create_menus(GtkDisplayState *s)
                                  "<QEMU>/File/Quit");
     gtk_accel_map_add_entry("<QEMU>/File/Quit", item.keyval, item.modifier);
 
+    s->control_menu = gtk_menu_new();
+    gtk_menu_set_accel_group(GTK_MENU(s->control_menu), accel_group);
+    s->control_menu_item = gtk_menu_item_new_with_mnemonic(_("_Control"));
+
+    s->stop_item = gtk_check_menu_item_new_with_mnemonic(_("_Stop"));
+    gtk_menu_append(GTK_MENU(s->control_menu), s->stop_item);
+
+    separator = gtk_separator_menu_item_new();
+    gtk_menu_append(GTK_MENU(s->control_menu), separator);
+
+    s->reset_item = gtk_image_menu_item_new_with_mnemonic(_("_Reset"));
+    gtk_menu_append(GTK_MENU(s->control_menu), s->reset_item);
+
+    s->powerdown_item = gtk_image_menu_item_new_with_mnemonic(_("_Power-down"));
+    gtk_menu_append(GTK_MENU(s->control_menu), s->powerdown_item);
+
     s->view_menu = gtk_menu_new();
     gtk_menu_set_accel_group(GTK_MENU(s->view_menu), accel_group);
     s->view_menu_item = gtk_menu_item_new_with_mnemonic(_("_View"));
@@ -1072,6 +1131,9 @@  static void gd_create_menus(GtkDisplayState *s)
     gtk_menu_item_set_submenu(GTK_MENU_ITEM(s->file_menu_item), s->file_menu);
     gtk_menu_shell_append(GTK_MENU_SHELL(s->menu_bar), s->file_menu_item);
 
+    gtk_menu_item_set_submenu(GTK_MENU_ITEM(s->control_menu_item), s->control_menu);
+    gtk_menu_shell_append(GTK_MENU_SHELL(s->menu_bar), s->control_menu_item);
+
     gtk_menu_item_set_submenu(GTK_MENU_ITEM(s->view_menu_item), s->view_menu);
     gtk_menu_shell_append(GTK_MENU_SHELL(s->menu_bar), s->view_menu_item);
 }