All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] console/gtk: add qemu_console_get_label
@ 2015-02-17  9:44 Gerd Hoffmann
  2015-02-17 16:39 ` Programmingkid
  0 siblings, 1 reply; 3+ messages in thread
From: Gerd Hoffmann @ 2015-02-17  9:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: Programmingkid, Gerd Hoffmann, Anthony Liguori

Add a new function to get a nice label for a given QemuConsole.
Drop the labeling code in gtk.c and use the new function instead.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 include/ui/console.h |  1 +
 ui/console.c         | 15 +++++++++++++++
 ui/gtk.c             | 12 +-----------
 3 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/include/ui/console.h b/include/ui/console.h
index 8a4d671..d4439a5 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -309,6 +309,7 @@ QemuConsole *qemu_console_lookup_by_device(DeviceState *dev, uint32_t head);
 bool qemu_console_is_visible(QemuConsole *con);
 bool qemu_console_is_graphic(QemuConsole *con);
 bool qemu_console_is_fixedsize(QemuConsole *con);
+char *qemu_console_get_label(QemuConsole *con);
 int qemu_console_get_index(QemuConsole *con);
 uint32_t qemu_console_get_head(QemuConsole *con);
 QemuUIInfo *qemu_console_get_ui_info(QemuConsole *con);
diff --git a/ui/console.c b/ui/console.c
index 87574a7..b64a73e 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -1788,6 +1788,21 @@ bool qemu_console_is_fixedsize(QemuConsole *con)
     return con && (con->console_type != TEXT_CONSOLE);
 }
 
+char *qemu_console_get_label(QemuConsole *con)
+{
+    if (con->console_type == GRAPHIC_CONSOLE) {
+        if (con->device) {
+            return g_strdup(object_get_typename(con->device));
+        }
+        return g_strdup("VGA");
+    } else {
+        if (con->chr && con->chr->label) {
+            return g_strdup(con->chr->label);
+        }
+        return g_strdup_printf("vc%d", con->index);
+    }
+}
+
 int qemu_console_get_index(QemuConsole *con)
 {
     if (con == NULL) {
diff --git a/ui/gtk.c b/ui/gtk.c
index b271ee4..f22d835 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -1702,17 +1702,7 @@ static GSList *gd_vc_gfx_init(GtkDisplayState *s, VirtualConsole *vc,
                               QemuConsole *con, int idx,
                               GSList *group, GtkWidget *view_menu)
 {
-    Object *obj;
-
-    obj = object_property_get_link(OBJECT(con), "device", NULL);
-    if (obj) {
-        vc->label = g_strdup_printf("%s", object_get_typename(obj));
-    } else if (qemu_console_is_graphic(con)) {
-        vc->label = g_strdup_printf("VGA");
-    } else {
-        vc->label = g_strdup_printf("vc%d", idx);
-    }
-
+    vc->label = qemu_console_get_label(con);
     vc->s = s;
     vc->gfx.scale_x = 1.0;
     vc->gfx.scale_y = 1.0;
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] console/gtk: add qemu_console_get_label
  2015-02-17  9:44 [Qemu-devel] [PATCH] console/gtk: add qemu_console_get_label Gerd Hoffmann
@ 2015-02-17 16:39 ` Programmingkid
  2015-02-18  8:18   ` Gerd Hoffmann
  0 siblings, 1 reply; 3+ messages in thread
From: Programmingkid @ 2015-02-17 16:39 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: qemu-devel, Anthony Liguori


On Feb 17, 2015, at 4:44 AM, Gerd Hoffmann wrote:

> Add a new function to get a nice label for a given QemuConsole.
> Drop the labeling code in gtk.c and use the new function instead.
> 
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
> include/ui/console.h |  1 +
> ui/console.c         | 15 +++++++++++++++
> ui/gtk.c             | 12 +-----------
> 3 files changed, 17 insertions(+), 11 deletions(-)
> 
> diff --git a/include/ui/console.h b/include/ui/console.h
> index 8a4d671..d4439a5 100644
> --- a/include/ui/console.h
> +++ b/include/ui/console.h
> @@ -309,6 +309,7 @@ QemuConsole *qemu_console_lookup_by_device(DeviceState *dev, uint32_t head);
> bool qemu_console_is_visible(QemuConsole *con);
> bool qemu_console_is_graphic(QemuConsole *con);
> bool qemu_console_is_fixedsize(QemuConsole *con);
> +char *qemu_console_get_label(QemuConsole *con);
> int qemu_console_get_index(QemuConsole *con);
> uint32_t qemu_console_get_head(QemuConsole *con);
> QemuUIInfo *qemu_console_get_ui_info(QemuConsole *con);
> diff --git a/ui/console.c b/ui/console.c
> index 87574a7..b64a73e 100644
> --- a/ui/console.c
> +++ b/ui/console.c
> @@ -1788,6 +1788,21 @@ bool qemu_console_is_fixedsize(QemuConsole *con)
>     return con && (con->console_type != TEXT_CONSOLE);
> }
> 
> +char *qemu_console_get_label(QemuConsole *con)
> +{
> +    if (con->console_type == GRAPHIC_CONSOLE) {
> +        if (con->device) {
> +            return g_strdup(object_get_typename(con->device));
> +        }
> +        return g_strdup("VGA");
> +    } else {
> +        if (con->chr && con->chr->label) {
> +            return g_strdup(con->chr->label);
> +        }
> +        return g_strdup_printf("vc%d", con->index);
> +    }
> +}
> +
> int qemu_console_get_index(QemuConsole *con)
> {
>     if (con == NULL) {
> diff --git a/ui/gtk.c b/ui/gtk.c
> index b271ee4..f22d835 100644
> --- a/ui/gtk.c
> +++ b/ui/gtk.c
> @@ -1702,17 +1702,7 @@ static GSList *gd_vc_gfx_init(GtkDisplayState *s, VirtualConsole *vc,
>                               QemuConsole *con, int idx,
>                               GSList *group, GtkWidget *view_menu)
> {
> -    Object *obj;
> -
> -    obj = object_property_get_link(OBJECT(con), "device", NULL);
> -    if (obj) {
> -        vc->label = g_strdup_printf("%s", object_get_typename(obj));
> -    } else if (qemu_console_is_graphic(con)) {
> -        vc->label = g_strdup_printf("VGA");
> -    } else {
> -        vc->label = g_strdup_printf("vc%d", idx);
> -    }
> -
> +    vc->label = qemu_console_get_label(con);
>     vc->s = s;
>     vc->gfx.scale_x = 1.0;
>     vc->gfx.scale_y = 1.0;
> -- 
> 1.8.3.1
> 

Thanks for this code. Is this how I should display the Serial console?

void myDisplaySerialConsole()
{
    QemuConsole *con;
    char *name;
    int index = 0;
    
    con = qemu_console_lookup_by_index(0);
    while(con != NULL) {
        name = qemu_console_get_label(con);
        
        /* If we found the console */
        if (strstr(name, "Serial")) {
            console_select(index);
            break;
        }        
        index++;
        con = qemu_console_lookup_by_index(index);
    }
    
}

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] console/gtk: add qemu_console_get_label
  2015-02-17 16:39 ` Programmingkid
@ 2015-02-18  8:18   ` Gerd Hoffmann
  0 siblings, 0 replies; 3+ messages in thread
From: Gerd Hoffmann @ 2015-02-18  8:18 UTC (permalink / raw)
  To: Programmingkid; +Cc: qemu-devel, Anthony Liguori

  Hi,

> Thanks for this code. Is this how I should display the Serial console?


> void myDisplaySerialConsole()
> {
>     QemuConsole *con;
>     char *name;
>     int index = 0;
>     
>     con = qemu_console_lookup_by_index(0);
>     while(con != NULL) {
>         name = qemu_console_get_label(con);
>         
>         /* If we found the console */
>         if (strstr(name, "Serial")) {
>             console_select(index);
>             break;
>         }        
>         index++;
>         con = qemu_console_lookup_by_index(index);

This mixes up several things.

When initializing the UI you'll loop over the consoles, like this:

    QemuConsole *con;
    int i;

    for (i = 0;; i++) {
        con = qemu_console_lookup_by_index(i);
        if (!con) {
            break;
        }
        /*
         * add a menu entry for the console here,
         * using qemu_console_get_label() to get
         * the text for the menu entry
         */    
    }

When the menu entry is activated by the user use console_select() to
switch.

cheers,
  Gerd

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-02-18  8:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-17  9:44 [Qemu-devel] [PATCH] console/gtk: add qemu_console_get_label Gerd Hoffmann
2015-02-17 16:39 ` Programmingkid
2015-02-18  8:18   ` Gerd Hoffmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.