diff options
author | kraxel <kraxel> | 2007-08-20 12:44:06 +0000 |
---|---|---|
committer | kraxel <kraxel> | 2007-08-20 12:44:06 +0000 |
commit | 6bac6719a031722e116431e0cb26c9f4f50d0d07 (patch) | |
tree | da5a1dd2b03ae77c985a4219ef73fedab248748f /vnc.c | |
parent | 01af1cbcc50199d9f7e6e4756500e5cab2382747 (diff) | |
download | xenwatch-6bac6719a031722e116431e0cb26c9f4f50d0d07.tar.gz |
more gtk-vnc tweaks
Diffstat (limited to 'vnc.c')
-rw-r--r-- | vnc.c | 141 |
1 files changed, 100 insertions, 41 deletions
@@ -45,11 +45,12 @@ struct vnc_window { enum vnc_state conn_state; /* config */ + int standalone; + int disconn_close; int fullscreen; int showpointer; int grab_pointer; int grab_keyboard; - int standalone; int debug; }; @@ -99,61 +100,68 @@ static void vnc_release(struct vnc_window *vnc) free(vnc); } -#if 0 -static char *vnc_passwd(rfbClient* cl) +static void vnc_connect_to(struct vnc_window *vnc, + char *hostname, int tcpport) +{ + snprintf(vnc->display, sizeof(vnc->display), "%s:%d", + hostname, tcpport - 5900); + snprintf(vnc->hostname, sizeof(vnc->hostname),"%s", hostname); + snprintf(vnc->tcpport, sizeof(vnc->tcpport),"%d", tcpport); + + vnc->conn_state = CONN_CONNECTING; + vnc_window_texts(vnc); + vnc_display_open_host(VNC_DISPLAY(vnc->vnc), vnc->hostname, vnc->tcpport); +} + +static int user_getstring(GtkWidget *window, char *title, char *message, + char *dest, int dlen, int hide) { - struct vnc_window *vnc = rfbClientGetClientData(cl, vnc_open); GtkWidget *dialog, *label, *entry; - char *passwd = NULL; const char *txt; - char message[256]; + int retval; - if (vnc->debug) - fprintf(stderr,"%s: called\n", __FUNCTION__); - /* Create the widgets */ - dialog = gtk_dialog_new_with_buttons("Password needed", - vnc->win ? GTK_WINDOW(vnc->win) : NULL, + dialog = gtk_dialog_new_with_buttons(title, + GTK_WINDOW(window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL); - - snprintf(message, sizeof(message), - "Please enter vnc screen password for \"%s\".", - vnc->client->desktopName ? : "unknown"); + gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT); + label = gtk_label_new(message); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); + entry = gtk_entry_new(); - gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE); + gtk_entry_set_text(GTK_ENTRY(entry), dest); gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE); - gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog)->vbox), 10); + if (hide) + gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE); gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), label); gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), entry); - gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT); + gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog)->vbox), 10); +#if 0 /* FIXME: doesn't work ... */ + gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), 10); +#endif /* show and wait for response */ gtk_widget_show_all(dialog); switch (gtk_dialog_run(GTK_DIALOG(dialog))) { case GTK_RESPONSE_ACCEPT: txt = gtk_entry_get_text(GTK_ENTRY(entry)); - passwd = strdup(txt); - if (vnc->debug) - fprintf(stderr,"%s: OK: \"%s\"\n", __FUNCTION__, passwd); + snprintf(dest, dlen, "%s", txt); + retval = 0; break; default: - if (vnc->debug) - fprintf(stderr,"%s: canceled\n", __FUNCTION__); - passwd = strdup(""); + retval = -1; break; } gtk_widget_destroy(dialog); - - return passwd; + return retval; } -#endif /* ------------------------------------------------------------------ */ /* vnc widget callbacks */ @@ -184,6 +192,8 @@ static void vnc_disconnected(GtkWidget *vncdisplay, void *data) fprintf(stderr, "%s\n", __FUNCTION__); vnc->conn_state = CONN_DISCONNECTED; vnc_window_texts(vnc); + if (vnc->disconn_close) + gtk_widget_destroy(vnc->win); } static void vnc_grab(GtkWidget *vncdisplay, void *data) @@ -206,12 +216,45 @@ static void vnc_ungrab(GtkWidget *vncdisplay, void *data) vnc_window_texts(vnc); } -static void vnc_credential(GtkWidget *vncdisplay, void *data) +static void vnc_credential(GtkWidget *vncdisplay, + GValueArray *credList, + void *data) { struct vnc_window *vnc = data; - - if (1 || vnc->debug) - fprintf(stderr, "%s: not implemented yet\n", __FUNCTION__); + char *val, msg[127], str[128]; + int i, rc; + + for (i = 0 ; i < credList->n_values ; i++) { + GValue *cred = g_value_array_get_nth(credList, i); + switch (g_value_get_enum(cred)) { + case VNC_DISPLAY_CREDENTIAL_USERNAME: + snprintf(msg, sizeof(msg), "Username for %s ?", vnc->display); + rc = user_getstring(vnc->win, "Authentication", msg, + str, sizeof(str), 0); + if (0 != rc) + return; + val = str; + break; + case VNC_DISPLAY_CREDENTIAL_PASSWORD: + snprintf(msg, sizeof(msg), "Password for %s ?", vnc->display); + rc = user_getstring(vnc->win, "Authentication", msg, + str, sizeof(str), 1); + if (0 != rc) + return; + val = str; + break; + case VNC_DISPLAY_CREDENTIAL_CLIENTNAME: + val = "vnc"; + break; + default: + fprintf(stderr, "can't handle credential type %d\n", + g_value_get_enum(cred)); + return; + } + vnc_display_set_credential(VNC_DISPLAY(vnc->vnc), + g_value_get_enum(cred), + val); + } } /* ------------------------------------------------------------------ */ @@ -305,11 +348,30 @@ static void menu_cb_grab_keyboard(GtkToggleAction *action, gpointer user_data) static void menu_cb_connect(GtkToggleAction *action, gpointer user_data) { struct vnc_window *vnc = user_data; + char str[128], hostname[65]; + int rc, displayno, port; if (vnc->conn_state == CONN_CONNECTED) return; - if (1 || vnc->debug) - fprintf(stderr, "%s: not implemented yet\n", __FUNCTION__); + if (vnc->debug) + fprintf(stderr, "%s\n", __FUNCTION__); + snprintf(str, sizeof(str), "%s", vnc->display); + rc = user_getstring(vnc->win, "Connecting", + "Connect to vnc display ?", + str, sizeof(str), 0); + if (0 != rc) + return; + + if (2 == sscanf(str, "%64[^:]:%d", hostname, &displayno)) { + port = displayno + 5900; + goto connect; + } + if (2 == sscanf(str, "%64[^:]::%d", hostname, &port)) + goto connect; + return; + +connect: + vnc_connect_to(vnc, hostname, port); } static void menu_cb_reconnect(GtkToggleAction *action, gpointer user_data) @@ -454,13 +516,11 @@ GtkWidget *vnc_open(char *hostname, int tcpport, unsigned long flags, memset(vnc,0,sizeof(*vnc)); vnc->standalone = (flags & VNC_FLAG_STANDALONE); vnc->showpointer = (flags & VNC_FLAG_SHOW_MOUSE); + vnc->grab_pointer = (flags & VNC_FLAG_GRAB_MOUSE); + vnc->grab_keyboard = (flags & VNC_FLAG_GRAB_KEYBOARD); + vnc->disconn_close = (flags & VNC_FLAG_DISCONNECT_CLOSE); vnc->debug = debug_level; - snprintf(vnc->display, sizeof(vnc->display), "%s:%d", - hostname, tcpport - 5900); - snprintf(vnc->hostname, sizeof(vnc->hostname),"%s", hostname); - snprintf(vnc->tcpport, sizeof(vnc->tcpport),"%d", tcpport); - /* gtk toplevel */ vnc->win = gtk_window_new(GTK_WINDOW_TOPLEVEL); g_signal_connect(G_OBJECT(vnc->win), "destroy", @@ -560,9 +620,8 @@ GtkWidget *vnc_open(char *hostname, int tcpport, unsigned long flags, gtk_window_fullscreen(GTK_WINDOW(vnc->win)); /* connect */ - vnc->conn_state = CONN_CONNECTING; - vnc_window_texts(vnc); - vnc_display_open_host(VNC_DISPLAY(vnc->vnc), vnc->hostname, vnc->tcpport); + if (hostname) + vnc_connect_to(vnc, hostname, tcpport); return vnc->win; |