From d77ed790274de2cf7bfab2a2f23c1dd066982e94 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Thu, 28 Nov 2019 11:38:29 +0100 Subject: add undefine menu item --- domain.c | 7 +++++++ main.ui | 10 ++++++++++ vconsole.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vconsole.h | 1 + 4 files changed, 80 insertions(+) diff --git a/domain.c b/domain.c index 3a1faad..c519dee 100644 --- a/domain.c +++ b/domain.c @@ -554,6 +554,13 @@ void domain_kill(struct vconsole_domain *dom) virDomainFree(d); } +void domain_undefine(struct vconsole_domain *dom) +{ + virDomainPtr d = virDomainLookupByUUIDString(dom->conn->ptr, dom->uuid); + + virDomainUndefineFlags(d, VIR_DOMAIN_UNDEFINE_NVRAM); +} + void domain_free(struct vconsole_domain *dom) { virDomainPtr d = virDomainLookupByUUIDString(dom->conn->ptr, dom->uuid); diff --git a/main.ui b/main.ui index 782b854..00d71ef 100644 --- a/main.ui +++ b/main.ui @@ -177,6 +177,16 @@ False + + + Remove guest configuration + True + False + main.GuestUndefine + True + False + + Show _graphic console diff --git a/vconsole.c b/vconsole.c index 92e51f3..baa917b 100644 --- a/vconsole.c +++ b/vconsole.c @@ -147,6 +147,46 @@ static int gtk_getstring(GtkWidget *window, char *title, char *message, return retval; } +static int gtk_yesno(GtkWidget *window, char *title, char *message) +{ + GtkWidget *dialog, *label, *vbox; + bool retval; + + /* Create the widgets */ + dialog = gtk_dialog_new_with_buttons(title, + GTK_WINDOW(window), + GTK_DIALOG_DESTROY_WITH_PARENT, + "_Yes", GTK_RESPONSE_ACCEPT, + "_No", GTK_RESPONSE_REJECT, + NULL); + gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_REJECT); + + label = gtk_label_new(message); +#if GTK_CHECK_VERSION(3,16,0) + gtk_label_set_xalign(GTK_LABEL(label), 0); + gtk_label_set_yalign(GTK_LABEL(label), 0.5); +#else + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); +#endif + + vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); + gtk_container_add(GTK_CONTAINER(vbox), label); + gtk_box_set_spacing(GTK_BOX(vbox), 10); + + /* show and wait for response */ + gtk_widget_show_all(dialog); + switch (gtk_dialog_run(GTK_DIALOG(dialog))) { + case GTK_RESPONSE_ACCEPT: + retval = true; + break; + default: + retval = false; + break; + } + gtk_widget_destroy(dialog); + return retval; +} + /* ------------------------------------------------------------------ */ static void menu_cb_connect_ask(GSimpleAction *action, @@ -421,6 +461,25 @@ static void menu_cb_vm_edit(GSimpleAction *action, run_virsh_edit(dom); } +static void menu_cb_vm_undefine(GSimpleAction *action, + GVariant *parameter, + gpointer data) +{ + struct vconsole_window *win = data; + struct vconsole_domain *dom = find_guest(win); + char *msg; + bool undefine; + + if (dom) { + msg = g_strdup_printf("Really delete domain\n%s?", + dom->name); + undefine = gtk_yesno(win->toplevel, "Please confirm", msg); + g_free(msg); + if (undefine) + domain_undefine(dom); + } +} + static void menu_cb_vm_gfx(GSimpleAction *action, GVariant *parameter, gpointer data) @@ -613,6 +672,9 @@ static const GActionEntry entries[] = { /* --- guest menu --- */ .name = "GuestEdit", .activate = menu_cb_vm_edit, + },{ + .name = "GuestUndefine", + .activate = menu_cb_vm_undefine, },{ .name = "GuestGfx", .activate = menu_cb_vm_gfx, diff --git a/vconsole.h b/vconsole.h index 17fabb2..1a6b5e5 100644 --- a/vconsole.h +++ b/vconsole.h @@ -131,6 +131,7 @@ void domain_reboot(struct vconsole_domain *dom); void domain_shutdown(struct vconsole_domain *dom); void domain_reset(struct vconsole_domain *dom); void domain_kill(struct vconsole_domain *dom); +void domain_undefine(struct vconsole_domain *dom); void domain_free(struct vconsole_domain *dom); void domain_update(struct vconsole_connect *conn, -- cgit