X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=main.c;h=bb456efbab89d9df0bd7427527de770ea35a8a8c;hb=2c24cea28b2f4702105fcf4f54fc4e923697174a;hp=390046a3a5ab45375e185b19fce5d11dab04a230;hpb=838aa4673bea4bf0e33a9e5045e4deba393a317d;p=ovirt-viewer.git diff --git a/main.c b/main.c index 390046a..bb456ef 100644 --- a/main.c +++ b/main.c @@ -58,12 +58,17 @@ gboolean debug = 0; * configure or on the command line. */ const char *cainfo = CAINFO; -gboolean check_cert = TRUE; +gboolean check_cert = FALSE; // do we want this enabled by default ? + // would require a CA by default (self-signed wont work) + // (don't set to true, change var/flag to no_check_cert) /* 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 +99,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 +132,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?) @@ -148,7 +159,7 @@ static const GOptionEntry options[] = { { "cainfo", 0, 0, G_OPTION_ARG_STRING, &cainfo, "set the path of the CA certificate bundle", NULL }, { "check-certificate", 0, 0, G_OPTION_ARG_NONE, &check_cert, - "if --no-check-certificate is passed we don't check the SSL certificate of the server", NULL }, + "check the SSL certificate of the server", NULL }, { "debug", 'd', 0, G_OPTION_ARG_NONE, &debug, "turn on debugging messages", NULL }, { "version", 'V', 0, G_OPTION_ARG_NONE, &print_version, @@ -242,7 +253,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 +300,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 +354,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 +495,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 +528,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 +563,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 +584,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 +603,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 +983,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 +1054,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);