[Ovirt-devel] [PATCH] viewer bugfixes / interfaces improvements
Mohammed Morsi
mmorsi at redhat.com
Mon Apr 13 17:00:19 UTC 2009
- allow user to click enter to submit hostname / login forms
- wire 'refresh list of virtual machines' menu item to
correct action
- display error on incorrect login
- change title when viewing vm, indicate ctrl+alt to grab mouse
- check if vm is running before trying to connect to it
(also we may want to not show non-running vms)
---
internal.h | 7 ++++-
main.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
wui_thread.c | 15 +++++++++++
3 files changed, 94 insertions(+), 4 deletions(-)
diff --git a/internal.h b/internal.h
index 950fd05..04512f9 100644
--- a/internal.h
+++ b/internal.h
@@ -106,6 +106,7 @@ struct vm {
int vnc_port;
int forward_vnc_port;
char *uuid; /* Printable UUID. */
+ char *state;
/* Only the fields above this point are required. The remainder may
* be NULL / -1 to indicate they were missing in the data we got
@@ -116,7 +117,6 @@ struct vm {
long mem_used; /* Kbytes */
int vcpus_allocated;
int vcpus_used;
- char *state;
char *mac_addr; /* Printable MAC addr. */
};
@@ -144,6 +144,11 @@ extern gboolean wui_thread_has_valid_vmlist (void);
*/
extern gboolean wui_thread_is_busy (void);
+/* Returns true if the main vm list contains a
+ * running vm w/ the same name as specified one
+ */
+extern gboolean main_vmlist_has_running_vm(struct vm*);
+
/* Callbacks from the WUI thread to the main thread. The WUI thread
* adds these to the Glib main loop using g_idle_add, which means they
* actually get executed in the context of the main thread.
diff --git a/main.c b/main.c
index 390046a..7a543e0 100644
--- a/main.c
+++ b/main.c
@@ -63,7 +63,10 @@ gboolean check_cert = TRUE;
/* Private functions. */
static void start_ui (void);
static GtkWidget *menu_item_new (int which_menu);
+static void refresh_menu_vm_list (GtkWidget *, gpointer);
+static void connect_to_wui_on_enter (GtkWidget *, gpointer);
static void connect_to_wui (GtkWidget *, gpointer);
+static void login_to_wui_on_enter (GtkWidget *, gpointer);
static void login_to_wui (GtkWidget *, gpointer);
static gboolean delete_event (GtkWidget *widget, GdkEvent *event, gpointer data);
static void destroy (GtkWidget *widget, gpointer data);
@@ -94,6 +97,7 @@ static GtkWidget *login_area;
static GtkWidget *la_username;
static GtkWidget *la_password;
static GtkWidget *la_button;
+static GtkWidget *la_error;
static GtkWidget *notebook;
static GtkWidget *statusbar;
static guint statusbar_ctx;
@@ -126,6 +130,11 @@ static struct menuItem menuItems[] = {
/* Window title. */
static const char *title = "oVirt Viewer";
+// when running vm
+// 47 chars
+static const char *title_vm =
+ "oVirt Viewer: (ctrl+alt to grab/release mouse) ";
+
/* Gtk widget styles. Avoid installation hassles by keeping this
* inside the binary. It can still be overridden by the user (who
* will do that?)
@@ -242,7 +251,9 @@ start_ui (void)
GtkWidget *ca_vbox;
GtkWidget *ca_hbox;
GtkWidget *ca_label;
+ GtkWidget *la_vbox;
GtkWidget *la_hbox;
+ GtkWidget *la_label;
DEBUG ("creating viewer windows and menus");
@@ -287,6 +298,9 @@ start_ui (void)
refresh_vmlist_separator = gtk_separator_menu_item_new ();
g_object_ref (refresh_vmlist_separator);
+ g_signal_connect (G_OBJECT (refresh_vmlist), "activate",
+ G_CALLBACK (refresh_menu_vm_list), NULL);
+
#if 0
screenshot = gtk_menu_item_new_with_mnemonic ("_Screenshot");
gtk_menu_append (GTK_MENU (filemenu), screenshot);
@@ -338,24 +352,36 @@ start_ui (void)
gtk_widget_set_name (connection_area, "ovirt-viewer-connection-area");
+ g_signal_connect (G_OBJECT (ca_hostname), "key-release-event",
+ G_CALLBACK (connect_to_wui_on_enter), NULL);
g_signal_connect (G_OBJECT (ca_button), "clicked",
G_CALLBACK (connect_to_wui), NULL);
login_area = gtk_event_box_new ();
+ la_vbox = gtk_vbox_new (FALSE, 0);
la_hbox = gtk_hbox_new (FALSE, 0);
+ la_label = gtk_label_new ("Username / password:");
la_username = gtk_entry_new ();
gtk_entry_set_width_chars (GTK_ENTRY (la_username), 12);
la_password = gtk_entry_new ();
gtk_entry_set_width_chars (GTK_ENTRY (la_password), 12);
gtk_entry_set_visibility (GTK_ENTRY (la_password), FALSE);
la_button = gtk_button_new_with_label ("Login");
+ la_error = gtk_label_new (NULL);
gtk_container_add (GTK_CONTAINER (la_hbox), la_username);
gtk_container_add (GTK_CONTAINER (la_hbox), la_password);
gtk_container_add (GTK_CONTAINER (la_hbox), la_button);
- gtk_container_add (GTK_CONTAINER (login_area), la_hbox);
+ gtk_box_pack_start (GTK_BOX (la_vbox), la_label, TRUE, FALSE, 4);
+ gtk_box_pack_start (GTK_BOX (la_vbox), la_hbox, TRUE, FALSE, 4);
+ gtk_box_pack_start (GTK_BOX (la_vbox), la_error, TRUE, FALSE, 4);
+ gtk_container_add (GTK_CONTAINER (login_area), la_vbox);
gtk_widget_set_name (login_area, "ovirt-viewer-login-area");
+ g_signal_connect (G_OBJECT (la_username), "key-release-event",
+ G_CALLBACK (login_to_wui_on_enter), NULL);
+ g_signal_connect (G_OBJECT (la_password), "key-release-event",
+ G_CALLBACK (login_to_wui_on_enter), NULL);
g_signal_connect (G_OBJECT (la_button), "clicked",
G_CALLBACK (login_to_wui), NULL);
@@ -467,6 +493,21 @@ help_about (GtkWidget *menu)
}
static void
+refresh_menu_vm_list(GtkWidget *widget, gpointer data)
+{
+ wui_thread_send_refresh_vm_list();
+}
+
+static void
+connect_to_wui_on_enter (GtkWidget *widget, gpointer data)
+{
+ // if key released was not 'enter' key
+ if(((GdkEventKey *)data)->type == GDK_KEY_RELEASE && (((GdkEventKey *)data)->keyval & 0xFF) != 13 ) return;
+
+ connect_to_wui(widget, data);
+}
+
+static void
connect_to_wui (GtkWidget *widget, gpointer data)
{
const char *hostname;
@@ -485,6 +526,15 @@ connect_to_wui (GtkWidget *widget, gpointer data)
}
static void
+login_to_wui_on_enter (GtkWidget *widget, gpointer data)
+{
+ // if key released was not 'enter' key
+ if(((GdkEventKey *)data)->type == GDK_KEY_RELEASE && (((GdkEventKey *)data)->keyval & 0xFF) != 13 ) return;
+
+ login_to_wui(widget, data);
+}
+
+static void
login_to_wui (GtkWidget *widget, gpointer data)
{
const char *username, *password;
@@ -511,6 +561,7 @@ connect_to_vm (GtkWidget *widget, gpointer _vm)
const char *label;
const char* hostname;
char *label2;
+ char new_title[97]; // 47 chars for title + 50 for vm name
DEBUG ("searching tabs for uuid %s", vm->uuid);
@@ -531,6 +582,14 @@ connect_to_vm (GtkWidget *widget, gpointer _vm)
DEBUG ("not found, creating new tab");
+ // before we open vnc connection, make sure vm is running
+ gboolean vm_running = main_vmlist_has_running_vm(vm);
+
+ if(!vm_running){
+ main_status_error (g_strdup ("VM not running"));
+ return;
+ }
+
/* This VM isn't in the notebook already, so create a new console. */
hostname = gtk_entry_get_text (GTK_ENTRY (ca_hostname));
fd = viewer_open_vnc_socket(hostname, vm->forward_vnc_port);
@@ -542,6 +601,16 @@ connect_to_vm (GtkWidget *widget, gpointer _vm)
return;
}
+ main_status_error(g_strdup(""));
+
+ for(i = 0; i < 47; ++i) new_title[i] = title_vm[i];
+ for(i = 0; i < 50; ++i){
+ if(vm->description[i] == '\0') break;
+ new_title[47 + i] = vm->description[i];
+ }
+ new_title[i < 50 ? i+47 : 96] = '\0';
+ gtk_window_set_title (GTK_WINDOW (window), new_title);
+
/*
gtk_signal_connect(GTK_OBJECT(child), "vnc-pointer-grab",
GTK_SIGNAL_FUNC(viewer_grab), window);
@@ -912,9 +981,7 @@ main_login_error (gpointer _str)
DEBUG ("login error: %s", str);
ASSERT_IS_MAIN_THREAD ();
- /*
gtk_label_set_text (GTK_LABEL (la_error), str);
- */
g_free (str);
return FALSE;
@@ -985,6 +1052,9 @@ add_vm_to_connectmenu (gpointer _vm, gpointer data)
struct vm *vm = (struct vm *) _vm;
GtkWidget *item;
+ // TODO only present running vms ?
+ // if(vm->state == "running")
+
DEBUG ("adding %s to Connect menu", vm->description);
item = gtk_menu_item_new_with_label (vm->description);
diff --git a/wui_thread.c b/wui_thread.c
index c51c43f..cbf7892 100644
--- a/wui_thread.c
+++ b/wui_thread.c
@@ -1093,3 +1093,18 @@ parse_vm_from_xml (xmlNodePtr node)
return ret;
}
+
+gboolean
+main_vmlist_has_running_vm(struct vm* _vm)
+{
+ // TODO ? get list and wait to be retreived
+ // wui_thread_send_refresh_vm_list();
+
+ // find vm in list
+ GSList* res = g_slist_find_custom (vmlist, _vm, compare_vm);
+
+ // return true if running
+ if(res != NULL) return STREQ (((struct vm*) res->data)->state, "running");
+
+ return FALSE;
+}
--
1.6.0.6
More information about the ovirt-devel
mailing list