summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
a1aebc1)
- 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)
int vnc_port;
int forward_vnc_port;
char *uuid; /* Printable UUID. */
int vnc_port;
int forward_vnc_port;
char *uuid; /* Printable UUID. */
/* Only the fields above this point are required. The remainder may
* be NULL / -1 to indicate they were missing in the data we got
/* Only the fields above this point are required. The remainder may
* be NULL / -1 to indicate they were missing in the data we got
long mem_used; /* Kbytes */
int vcpus_allocated;
int vcpus_used;
long mem_used; /* Kbytes */
int vcpus_allocated;
int vcpus_used;
char *mac_addr; /* Printable MAC addr. */
};
char *mac_addr; /* Printable MAC addr. */
};
*/
extern gboolean wui_thread_is_busy (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.
/* 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.
/* Private functions. */
static void start_ui (void);
static GtkWidget *menu_item_new (int which_menu);
/* 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 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);
static void login_to_wui (GtkWidget *, gpointer);
static gboolean delete_event (GtkWidget *widget, GdkEvent *event, gpointer data);
static void destroy (GtkWidget *widget, gpointer data);
static GtkWidget *la_username;
static GtkWidget *la_password;
static GtkWidget *la_button;
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;
static GtkWidget *notebook;
static GtkWidget *statusbar;
static guint statusbar_ctx;
/* Window title. */
static const char *title = "oVirt Viewer";
/* 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?)
/* Gtk widget styles. Avoid installation hassles by keeping this
* inside the binary. It can still be overridden by the user (who
* will do that?)
GtkWidget *ca_vbox;
GtkWidget *ca_hbox;
GtkWidget *ca_label;
GtkWidget *ca_vbox;
GtkWidget *ca_hbox;
GtkWidget *ca_label;
DEBUG ("creating viewer windows and menus");
DEBUG ("creating viewer windows and menus");
refresh_vmlist_separator = gtk_separator_menu_item_new ();
g_object_ref (refresh_vmlist_separator);
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);
#if 0
screenshot = gtk_menu_item_new_with_mnemonic ("_Screenshot");
gtk_menu_append (GTK_MENU (filemenu), screenshot);
gtk_widget_set_name (connection_area, "ovirt-viewer-connection-area");
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 ();
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_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_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 (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");
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);
g_signal_connect (G_OBJECT (la_button), "clicked",
G_CALLBACK (login_to_wui), NULL);
+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;
connect_to_wui (GtkWidget *widget, gpointer data)
{
const char *hostname;
+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;
login_to_wui (GtkWidget *widget, gpointer data)
{
const char *username, *password;
const char *label;
const char* hostname;
char *label2;
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);
DEBUG ("searching tabs for uuid %s", vm->uuid);
DEBUG ("not found, creating new tab");
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);
/* 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);
+ 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);
/*
gtk_signal_connect(GTK_OBJECT(child), "vnc-pointer-grab",
GTK_SIGNAL_FUNC(viewer_grab), window);
DEBUG ("login error: %s", str);
ASSERT_IS_MAIN_THREAD ();
DEBUG ("login error: %s", str);
ASSERT_IS_MAIN_THREAD ();
gtk_label_set_text (GTK_LABEL (la_error), str);
gtk_label_set_text (GTK_LABEL (la_error), str);
g_free (str);
return FALSE;
g_free (str);
return FALSE;
struct vm *vm = (struct vm *) _vm;
GtkWidget *item;
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);
DEBUG ("adding %s to Connect menu", vm->description);
item = gtk_menu_item_new_with_label (vm->description);
+
+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;
+}