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 clear_connectmenu (void);
/* For any widgets accessed from multiple functions. */
static GtkWidget *window;
+static GtkWidget *connectitem;
+static GtkWidget *connectmenu;
+static GtkWidget *no_connections;
+static GtkWidget *refresh_vmlist;
+static GtkWidget *refresh_vmlist_separator;
static GtkWidget *connection_area;
static GtkWidget *ca_hostname;
static GtkWidget *ca_button;
/* Menus. */
enum menuNums {
- FILE_MENU,
+ CONNECT_MENU,
VIEW_MENU,
SEND_KEY_MENU,
WINDOW_MENU,
};
static struct menuItem menuItems[] = {
- { FILE_MENU, NULL, "_File", "File" },
+ { CONNECT_MENU, NULL, "_Connect", "Connect" },
{ VIEW_MENU, NULL, "_View", "View" },
{ SEND_KEY_MENU, NULL, "_Send Key", "Send Key" },
{ WINDOW_MENU, NULL, "_Window", "Window" },
{
GtkWidget *vbox;
GtkWidget *menubar;
- GtkWidget *file;
- GtkWidget *filemenu;
GtkWidget *view;
GtkWidget *viewmenu;
GtkWidget *sendkey;
/* Menubar. */
menubar = gtk_menu_bar_new ();
- file = menu_item_new (FILE_MENU);
- filemenu = gtk_menu_new ();
- gtk_menu_item_set_submenu (GTK_MENU_ITEM (file), filemenu);
+ connectitem = menu_item_new (CONNECT_MENU);
+ connectmenu = gtk_menu_new ();
+ gtk_menu_item_set_submenu (GTK_MENU_ITEM (connectitem), connectmenu);
+
+ no_connections = gtk_menu_item_new_with_label ("Not connected");
+ gtk_menu_append (GTK_MENU (connectmenu), no_connections);
+ gtk_widget_set_sensitive (no_connections, FALSE);
+
+ /* This is not added to the menu yet, but will be when we are
+ * connected.
+ */
+ refresh_vmlist =
+ gtk_menu_item_new_with_label ("Refresh list of virtual machines");
+ g_object_ref (refresh_vmlist);
+ refresh_vmlist_separator = gtk_separator_menu_item_new ();
+ g_object_ref (refresh_vmlist_separator);
#if 0
screenshot = gtk_menu_item_new_with_mnemonic ("_Screenshot");
helpmenu = gtk_menu_new ();
gtk_menu_item_set_submenu (GTK_MENU_ITEM (help), helpmenu);
- gtk_menu_bar_append (GTK_MENU_BAR (menubar), file);
+ gtk_menu_bar_append (GTK_MENU_BAR (menubar), connectitem);
gtk_menu_bar_append (GTK_MENU_BAR (menubar), view);
gtk_menu_bar_append (GTK_MENU_BAR (menubar), sendkey);
gtk_menu_bar_append (GTK_MENU_BAR (menubar), wind);
}
static GtkWidget *
-menu_item_new(int which_menu)
+menu_item_new (int which_menu)
{
GtkWidget *widget;
GtkWidget *label;
text = menuItems[which_menu].ungrabbed_text;
- widget = gtk_menu_item_new();
- label = g_object_new(GTK_TYPE_ACCEL_LABEL, NULL);
- gtk_label_set_text_with_mnemonic(GTK_LABEL(label), text);
- gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
+ widget = gtk_menu_item_new ();
+ label = g_object_new (GTK_TYPE_ACCEL_LABEL, NULL);
+ gtk_label_set_text_with_mnemonic (GTK_LABEL (label), text);
+ gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
- gtk_container_add(GTK_CONTAINER(widget), label);
- gtk_accel_label_set_accel_widget(GTK_ACCEL_LABEL(label), widget);
- gtk_widget_show(label);
+ gtk_container_add (GTK_CONTAINER (widget), label);
+ gtk_accel_label_set_accel_widget (GTK_ACCEL_LABEL (label), widget);
+ gtk_widget_show (label);
menuItems[which_menu].label = label;
wui_thread_send_login (username, password);
}
+/* Remove all menu items from the Connect menu. */
+static void
+remove_menu_item (GtkWidget *menu_item, gpointer data)
+{
+ gtk_container_remove (GTK_CONTAINER (connectmenu), menu_item);
+}
+
+static void
+clear_connectmenu (void)
+{
+ DEBUG ("clear Connect menu");
+ gtk_container_foreach (GTK_CONTAINER (connectmenu), remove_menu_item, NULL);
+}
+
/* The WUI thread has changed its state to connected. */
gboolean
main_connected (gpointer data)
gtk_widget_show (connection_area);
gtk_widget_hide (login_area);
+
+ clear_connectmenu ();
+ gtk_menu_append (GTK_MENU (connectmenu), no_connections);
+ gtk_widget_show_all (connectmenu);
+
return FALSE;
}
ASSERT_IS_MAIN_THREAD ();
/*
- gtk_label_set_text (GTK_LABEL (ca_error), str);
+ gtk_label_set_text (GTK_LABEL (la_error), str);
*/
g_free (str);
ASSERT_IS_MAIN_THREAD ();
/*
- gtk_label_set_text (GTK_LABEL (ca_error), str);
+ gtk_label_set_text (GTK_LABEL (...), str);
*/
g_free (str);
}
/* The WUI thread has updated the vm list. */
+static void
+add_vm_to_connectmenu (gpointer _vm, gpointer data)
+{
+ struct vm *vm = (struct vm *) _vm;
+ GtkWidget *item;
+
+ DEBUG ("adding %s to Connect menu", vm->description);
+
+ item = gtk_menu_item_new_with_label (vm->description);
+ gtk_menu_append (GTK_MENU (connectmenu), item);
+}
+
gboolean
main_vmlist_updated (gpointer data)
{
+ GSList *vmlist;
+
DEBUG ("vmlist updated");
ASSERT_IS_MAIN_THREAD ();
+ /* Get the new vmlist. */
+ if (wui_thread_get_vmlist (&vmlist)) {
+ clear_connectmenu ();
+
+ gtk_menu_append (GTK_MENU (connectmenu), refresh_vmlist);
+
+ if (vmlist != NULL) {
+ gtk_menu_append (GTK_MENU (connectmenu), refresh_vmlist_separator);
+ g_slist_foreach (vmlist, add_vm_to_connectmenu, NULL);
+ }
+ free_vmlist (vmlist);
+
+ /* Grrrr Gtk is stupid. */
+ gtk_widget_show_all (connectmenu);
+ }
+
return FALSE;
}