diff options
author | kraxel <kraxel> | 2008-09-30 14:46:55 +0000 |
---|---|---|
committer | kraxel <kraxel> | 2008-09-30 14:46:55 +0000 |
commit | 9552fcc68f43b03f0b16b6e2b15781c656e04171 (patch) | |
tree | ca1f6fbd7e832f5e2e00efe4da2f76f8698d40bf | |
parent | 663d6ac861b4c527044f6a1f10466ec3001de5f8 (diff) | |
download | qemu-gtk-9552fcc68f43b03f0b16b6e2b15781c656e04171.tar.gz |
- quit on vm exit by default.
- wind up eject.
-rw-r--r-- | VERSION | 2 | ||||
-rw-r--r-- | devices.c | 78 | ||||
-rw-r--r-- | qemu-gtk.c | 17 |
3 files changed, 70 insertions, 27 deletions
@@ -1 +1 @@ -0.3 +0.4 @@ -10,13 +10,15 @@ /* ----------------------------------------------------------------- */ -static char mc_xml_start[] = +static char media_xml[] = "<ui>\n" " <menubar name='MainMenu'>\n" " <menu action='DevicesMenu'>\n" -" <menu action='MediaChangeSubMenu'>\n"; - -static char mc_xml_end[] = +" <menu action='EjectMediaSubMenu'>\n" +"%s" +" </menu>\n" +" <menu action='ChangeMediaSubMenu'>\n" +"%s" " </menu>\n" " </menu>\n" " </menubar>\n" @@ -60,14 +62,30 @@ static void menu_cb_change_media(GtkAction *action, void *data) gtk_widget_destroy(dialog); } +static void menu_cb_eject_media(GtkAction *action, void *data) +{ + struct qemu_window *win = data; + char name[32], cmd[128]; + + if (1 != sscanf(gtk_action_get_name(action), "EjectMedia_%31s", name)) + return; + if (debug) + fprintf(stderr, "%s: %s\n", __FUNCTION__, name); + + snprintf(cmd, sizeof(cmd), "eject %s", name); + monitor_append(win, cmd); + monitor_append(win, "info block"); +} + void devices_parse_info_block(struct qemu_window *win, char *str) { - char name[32], type[16], line[256], *file, *ptr; + char name[32], type[16], line[256], *file, *ptr, *xml; char action[128], label[128]; - int removable, pos, xpos, len, rc; - GtkActionEntry entry; + int removable, pos, len, rc, eject; + GtkActionEntry c_entry, e_entry; + char *c_xml = NULL, *e_xml = NULL; + int c_pos = 0, e_pos = 0; GError *err = NULL; - char *xml; /* remove */ if (win->mc_id) { @@ -81,12 +99,11 @@ void devices_parse_info_block(struct qemu_window *win, char *str) } /* start */ - memset(&entry, 0, sizeof(entry)); - entry.callback = G_CALLBACK(menu_cb_change_media); - win->mc_ag = gtk_action_group_new("ChangeMediaActions"); - - xpos = 0; xml = malloc(strlen(mc_xml_start)+1); - xpos += sprintf(xml+xpos, "%s", mc_xml_start); + memset(&c_entry, 0, sizeof(c_entry)); + c_entry.callback = G_CALLBACK(menu_cb_change_media); + memset(&e_entry, 0, sizeof(e_entry)); + e_entry.callback = G_CALLBACK(menu_cb_eject_media); + win->mc_ag = gtk_action_group_new("MediaActions"); /* parse & build */ for (pos = 0;; pos += len) { @@ -104,8 +121,10 @@ void devices_parse_info_block(struct qemu_window *win, char *str) ptr = strchr(file, ' '); if (ptr) *ptr = 0; + eject = 1; } else { file = "<empty>"; + eject = 0; } if (debug) fprintf(stderr, "%s: %s (%s, %s) - [%s]\n", @@ -113,16 +132,27 @@ void devices_parse_info_block(struct qemu_window *win, char *str) snprintf(action, sizeof(action), "ChangeMedia_%s", name); snprintf(label, sizeof(label), "%s (%s, %s)", name, type, file); - xml = realloc(xml, xpos + 128); - xpos += snprintf(xml+xpos, 128, " <menuitem action='%s'/>\n", action); - entry.name = action; - entry.label = label; - gtk_action_group_add_actions(win->mc_ag, &entry, 1, win); + c_entry.name = action; + c_entry.label = label; + gtk_action_group_add_actions(win->mc_ag, &c_entry, 1, win); + c_xml = realloc(c_xml, c_pos + 128); + c_pos += snprintf(c_xml+c_pos, 128, " <menuitem action='%s'/>\n", action); + + if (eject) { + snprintf(action, sizeof(action), "EjectMedia_%s", name); + snprintf(label, sizeof(label), "%s (%s, %s)", name, type, file); + e_entry.name = action; + e_entry.label = label; + gtk_action_group_add_actions(win->mc_ag, &e_entry, 1, win); + e_xml = realloc(e_xml, e_pos + 128); + e_pos += snprintf(e_xml+e_pos, 128, " <menuitem action='%s'/>\n", action); + } } - /* finish */ - xml = realloc(xml, xpos + strlen(mc_xml_end)+1); - xpos += sprintf(xml+xpos, "%s", mc_xml_end); + xml = malloc(e_pos + c_pos + strlen(media_xml)); + sprintf(xml, media_xml, + e_pos ? e_xml : "", + c_pos ? c_xml : ""); /* add */ if (debug) @@ -133,4 +163,8 @@ void devices_parse_info_block(struct qemu_window *win, char *str) g_message("building media change menu failed: %s", err->message); g_error_free(err); } + + free(c_xml); + free(e_xml); + free(xml); } @@ -437,7 +437,10 @@ static const GtkActionEntry entries[] = { },{ /* --- sub menus --- */ - .name = "MediaChangeSubMenu", + .name = "EjectMediaSubMenu", + .label = "_Eject media", + },{ + .name = "ChangeMediaSubMenu", .label = "_Change media", },{ @@ -535,8 +538,8 @@ static char ui_xml[] = " <menuitem action='RunGdb'/>" " </menu>" " <menu action='DevicesMenu'>" -" <menu action='MediaChangeSubMenu'>" -" </menu>" +" <menu action='EjectMediaSubMenu'/>" +" <menu action='ChangeMediaSubMenu'/>" " </menu>" " <menu action='HelpMenu'>" " <menuitem action='About'/>" @@ -666,6 +669,7 @@ static void usage(FILE *fp) "options:\n" " -h Print this text.\n" " -d Raise debug level.\n" + " -k Keep window open on VM shutdown.\n" " -m Enable monitor logging and access.\n" " -c <dev> Show serial console.\n" "\n" @@ -680,16 +684,20 @@ main(int argc, char *argv[]) struct qemu_window *win; char *console_tab = NULL; int monitor_tab = 0; + int quit_on_shutdown = 1; int c; gtk_init(&argc, &argv); for (;;) { - if (-1 == (c = getopt(argc, argv, "hdmc:"))) + if (-1 == (c = getopt(argc, argv, "hdkmc:"))) break; switch (c) { case 'd': debug++; break; + case 'k': + quit_on_shutdown = 0; + break; case 'm': monitor_tab++; break; @@ -715,6 +723,7 @@ main(int argc, char *argv[]) if (-1 == monitor_connect(win, argv[optind])) { exit(1); } + win->quit_on_shutdown = quit_on_shutdown; /* tabs */ if (monitor_tab) |