aboutsummaryrefslogtreecommitdiffstats
path: root/devices.c
diff options
context:
space:
mode:
authorkraxel <kraxel>2008-11-04 12:34:30 +0000
committerkraxel <kraxel>2008-11-04 12:34:30 +0000
commit5c906e533c9673d57b66f7c7ff4a40621fcaa9ab (patch)
tree120df72a76094929374ffff38ca24db3b800e12b /devices.c
parent92fa8f0a1bb08dbb13822c39798ad569d912e12e (diff)
downloadqemu-gtk-5c906e533c9673d57b66f7c7ff4a40621fcaa9ab.tar.gz
use info chardev.
Diffstat (limited to 'devices.c')
-rw-r--r--devices.c195
1 files changed, 134 insertions, 61 deletions
diff --git a/devices.c b/devices.c
index 49d5679..d34468a 100644
--- a/devices.c
+++ b/devices.c
@@ -46,6 +46,17 @@ static char unplug_usb_xml[] =
" </menubar>\n"
"</ui>\n";
+static char open_term_xml[] =
+"<ui>\n"
+" <menubar name='MainMenu'>\n"
+" <menu action='DevicesMenu'>\n"
+" <menu action='OpenTermSubMenu'>\n"
+"%s"
+" </menu>\n"
+" </menu>\n"
+" </menubar>\n"
+"</ui>\n";
+
/* ----------------------------------------------------------------- */
static void menu_cb_change_media(GtkAction *action, void *data)
@@ -129,6 +140,20 @@ static void menu_cb_unplug_usb(GtkAction *action, void *data)
monitor_append(win, "info usb");
}
+static void menu_cb_open_term(GtkAction *action, void *data)
+{
+ struct qemu_window *win = data;
+ char name[32], file[256];
+
+ if (2 != sscanf(gtk_action_get_name(action), "OpenTerm_%[^_]_%255s",
+ name, file))
+ return;
+ if (1 || debug)
+ fprintf(stderr, "%s: %s -- %s\n", __FUNCTION__, name, file);
+
+ conn_open_term(win, name, file, -1);
+}
+
/* ----------------------------------------------------------------- */
static void add_entry(struct qemu_window *win,
@@ -165,6 +190,38 @@ static int skip_line(char *str, int pos)
return len;
}
+static int menu_del(struct qemu_window *win, struct qemu_menu *menu)
+{
+ if (menu->id) {
+ gtk_ui_manager_remove_ui(win->ui, menu->id);
+ menu->id = 0;
+ }
+ if (menu->ag) {
+ gtk_ui_manager_remove_action_group(win->ui, menu->ag);
+ g_object_unref(menu->ag);
+ menu->ag = NULL;
+ }
+ return 0;
+}
+
+static int menu_add(struct qemu_window *win, struct qemu_menu *menu, char *xml)
+{
+ GError *err = NULL;
+
+ if (debug)
+ fprintf(stderr, "---\n%s---\n", xml);
+ gtk_ui_manager_insert_action_group(win->ui, menu->ag, 1);
+ menu->id = gtk_ui_manager_add_ui_from_string(win->ui, xml, -1, &err);
+ if (!menu->id) {
+ g_message("building menu failed: %s", err->message);
+ g_error_free(err);
+ return -1;
+ }
+ return 0;
+}
+
+/* ----------------------------------------------------------------- */
+
void devices_parse_info_block(struct qemu_window *win, char *str)
{
char name[32], type[16], line[256], *file, *ptr, *xml;
@@ -172,21 +229,12 @@ void devices_parse_info_block(struct qemu_window *win, char *str)
int removable, pos, len, rc, eject;
char *c_xml = NULL, *e_xml = NULL;
int c_pos = 0, e_pos = 0;
- GError *err = NULL;
/* remove */
- if (win->mc_id) {
- gtk_ui_manager_remove_ui(win->ui, win->mc_id);
- win->mc_id = 0;
- }
- if (win->mc_ag) {
- gtk_ui_manager_remove_action_group(win->ui, win->mc_ag);
- g_object_unref(win->mc_ag);
- win->mc_ag = NULL;
- }
+ menu_del(win, &win->mc);
/* start */
- win->mc_ag = gtk_action_group_new("MediaActions");
+ win->mc.ag = gtk_action_group_new("MediaActions");
/* parse & build */
for (pos = 0;; pos += len) {
@@ -223,12 +271,12 @@ void devices_parse_info_block(struct qemu_window *win, char *str)
__FUNCTION__, name, type, file, line);
snprintf(label, sizeof(label), "%s (%s, %s)", name, type, file);
- add_entry(win, win->mc_ag, menu_cb_change_media, &c_xml, &c_pos,
+ add_entry(win, win->mc.ag, menu_cb_change_media, &c_xml, &c_pos,
label, "ChangeMedia", name);
if (eject) {
snprintf(label, sizeof(label), "%s (%s, %s)", name, type, file);
- add_entry(win, win->mc_ag, menu_cb_eject_media, &e_xml, &e_pos,
+ add_entry(win, win->mc.ag, menu_cb_eject_media, &e_xml, &e_pos,
label, "EjectMedia", name);
}
}
@@ -239,14 +287,7 @@ void devices_parse_info_block(struct qemu_window *win, char *str)
e_pos ? e_xml : "");
/* add */
- if (debug)
- fprintf(stderr, "---\n%s---\n", xml);
- gtk_ui_manager_insert_action_group(win->ui, win->mc_ag, 1);
- win->mc_id = gtk_ui_manager_add_ui_from_string(win->ui, xml, -1, &err);
- if (!win->mc_id) {
- g_message("building media change menu failed: %s", err->message);
- g_error_free(err);
- }
+ menu_add(win, &win->mc, xml);
free(c_xml);
free(e_xml);
@@ -257,24 +298,15 @@ void devices_parse_info_usb(struct qemu_window *win, char *str)
{
char device[16], name[64], speed[16], *xml;
char label[128];
- GError *err = NULL;
int pos, len, rc;
char *i_xml = NULL;
int i_pos = 0;
/* remove */
- if (win->usb_id) {
- gtk_ui_manager_remove_ui(win->ui, win->usb_id);
- win->usb_id = 0;
- }
- if (win->usb_ag) {
- gtk_ui_manager_remove_action_group(win->ui, win->usb_ag);
- g_object_unref(win->usb_ag);
- win->usb_ag = NULL;
- }
+ menu_del(win, &win->usb);
/* start */
- win->usb_ag = gtk_action_group_new("UnplugUsbActions");
+ win->usb.ag = gtk_action_group_new("UnplugUsbActions");
/* parse & build */
for (pos = 0;; pos += len) {
@@ -293,7 +325,7 @@ void devices_parse_info_usb(struct qemu_window *win, char *str)
__FUNCTION__, device, speed, name);
snprintf(label, sizeof(label), "%s (%s)", name, device);
- add_entry(win, win->usb_ag, menu_cb_unplug_usb, &i_xml, &i_pos,
+ add_entry(win, win->usb.ag, menu_cb_unplug_usb, &i_xml, &i_pos,
label, "UnplugUsb", device);
}
@@ -302,14 +334,7 @@ void devices_parse_info_usb(struct qemu_window *win, char *str)
i_pos ? i_xml : "");
/* add */
- if (debug)
- fprintf(stderr, "---\n%s---\n", xml);
- gtk_ui_manager_insert_action_group(win->ui, win->usb_ag, 1);
- win->usb_id = gtk_ui_manager_add_ui_from_string(win->ui, xml, -1, &err);
- if (!win->usb_id) {
- g_message("building unplug usb menu failed: %s", err->message);
- g_error_free(err);
- }
+ menu_add(win, &win->usb, xml);
free(i_xml);
free(xml);
@@ -319,24 +344,15 @@ void devices_parse_info_usbhost(struct qemu_window *win, char *str)
{
char device[16], speed[16], class[32], name[64], *xml;
char action[128], label[128];
- GError *err = NULL;
int pos, len, rc, vendor, product;
char *i_xml = NULL;
int i_pos = 0;
/* remove */
- if (win->usbhost_id) {
- gtk_ui_manager_remove_ui(win->ui, win->usbhost_id);
- win->usbhost_id = 0;
- }
- if (win->usbhost_ag) {
- gtk_ui_manager_remove_action_group(win->ui, win->usbhost_ag);
- g_object_unref(win->usbhost_ag);
- win->usbhost_ag = NULL;
- }
+ menu_del(win, &win->usbhost);
/* start */
- win->usbhost_ag = gtk_action_group_new("PlugUsbActions");
+ win->usbhost.ag = gtk_action_group_new("PlugUsbActions");
/* parse & build */
for (pos = 0;; pos += len) {
@@ -360,12 +376,12 @@ void devices_parse_info_usbhost(struct qemu_window *win, char *str)
snprintf(label, sizeof(label), "%s (host %s)", name, device);
snprintf(action, sizeof(action), "host:%s", device);
- add_entry(win, win->usbhost_ag, menu_cb_plug_usb, &i_xml, &i_pos,
+ add_entry(win, win->usbhost.ag, menu_cb_plug_usb, &i_xml, &i_pos,
label, "PlugUsb", action);
}
/* static */
- add_entry(win, win->usbhost_ag, menu_cb_plug_usb, &i_xml, &i_pos,
+ add_entry(win, win->usbhost.ag, menu_cb_plug_usb, &i_xml, &i_pos,
"QEMU USB Tablet (virtual)", "PlugUsb", "tablet");
xml = malloc(i_pos + strlen(plug_usb_xml));
@@ -373,14 +389,70 @@ void devices_parse_info_usbhost(struct qemu_window *win, char *str)
i_pos ? i_xml : "");
/* add */
- if (debug)
- fprintf(stderr, "---\n%s---\n", xml);
- gtk_ui_manager_insert_action_group(win->ui, win->usbhost_ag, 1);
- win->usbhost_id = gtk_ui_manager_add_ui_from_string(win->ui, xml, -1, &err);
- if (!win->usbhost_id) {
- g_message("building host usb menu failed: %s", err->message);
- g_error_free(err);
+ menu_add(win, &win->usbhost, xml);
+
+ free(i_xml);
+ free(xml);
+}
+
+void devices_parse_info_chardev(struct qemu_window *win, char *str)
+{
+ char name[32], file[256], *xml;
+ char action[128], label[128];
+ int pos, len, rc;
+ char *i_xml = NULL;
+ int i_pos = 0;
+
+ /* remove */
+ menu_del(win, &win->chardev);
+
+ /* start */
+ win->chardev.ag = gtk_action_group_new("OpenTermActions");
+
+ /* parse & build */
+ for (pos = 0;; pos += len) {
+ rc = sscanf(str+pos, "%31[^:]: filename=%255[^\r\n]%n",
+ name, file, &len);
+ if (rc != 2) {
+ /* parse error, try to skip line */
+ if (0 == (len = skip_line(str, pos)))
+ break;
+ continue;
+ }
+ while (str[pos+len] == '\r' || str[pos+len] == '\n')
+ len++;
+
+ /* filter out */
+ if (strcmp(name, "monitor") == 0)
+ continue;
+ if (strcmp(name, "gdb") == 0)
+ continue;
+ if (strncmp(file, "vc:", 3) == 0)
+ continue;
+ if (strncmp(file, "null", 4) == 0)
+ continue;
+
+ /* save away first serial */
+ if (strcmp(name, "serial0") == 0) {
+ free(win->sercon);
+ win->sercon = strdup(file);
+ }
+
+ if (1 || debug)
+ fprintf(stderr, "%s: %s -- \"%s\"\n",
+ __FUNCTION__, name, file);
+
+ snprintf(label, sizeof(label), "%s", name);
+ snprintf(action, sizeof(action), "%s_%s", name, file);
+ add_entry(win, win->chardev.ag, menu_cb_open_term, &i_xml, &i_pos,
+ label, "OpenTerm", action);
}
+ xml = malloc(i_pos + strlen(open_term_xml));
+ sprintf(xml, open_term_xml,
+ i_pos ? i_xml : "");
+
+ /* add */
+ menu_add(win, &win->chardev, xml);
free(i_xml);
free(xml);
@@ -391,4 +463,5 @@ void devices_rescan(struct qemu_window *win)
monitor_append(win, "info block");
monitor_append(win, "info usb");
monitor_append(win, "info usbhost");
+ monitor_append(win, "info chardev");
}