static void remmina_file_editor_browse_avahi(GtkWidget* button, RemminaFileEditor* gfe) { GtkWidget* dialog; gchar* host; dialog = aui_service_dialog_new(_("Choose a Remote Desktop Server"), GTK_WINDOW(gfe), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL); gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(gfe)); aui_service_dialog_set_resolve_service (AUI_SERVICE_DIALOG (dialog), TRUE); aui_service_dialog_set_resolve_host_name (AUI_SERVICE_DIALOG (dialog), TRUE); aui_service_dialog_set_browse_service_types (AUI_SERVICE_DIALOG (dialog), gfe->priv->avahi_service_type, NULL); if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { host = g_strdup_printf("[%s]:%i", aui_service_dialog_get_host_name (AUI_SERVICE_DIALOG (dialog)), aui_service_dialog_get_port (AUI_SERVICE_DIALOG (dialog))); } else { host = NULL; } gtk_widget_destroy (dialog); if (host) { gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child (GTK_BIN (gfe->priv->server_combo))), host); g_free(host); } }
int main(int argc, char*argv[]) { GtkWidget *d; gtk_init(&argc, &argv); if (g_str_has_suffix(argv[0], "bvnc")) { d = aui_service_dialog_new("Choose VNC server", NULL, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_CONNECT, GTK_RESPONSE_ACCEPT, NULL); aui_service_dialog_set_browse_service_types(AUI_SERVICE_DIALOG(d), "_rfb._tcp", NULL); } else { d = aui_service_dialog_new("Choose SSH server", NULL, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_CONNECT, GTK_RESPONSE_ACCEPT, NULL); aui_service_dialog_set_browse_service_types(AUI_SERVICE_DIALOG(d), "_ssh._tcp", NULL); } aui_service_dialog_set_resolve_service(AUI_SERVICE_DIALOG(d), TRUE); aui_service_dialog_set_resolve_host_name(AUI_SERVICE_DIALOG(d), !avahi_nss_support()); gtk_window_present(GTK_WINDOW(d)); if (gtk_dialog_run(GTK_DIALOG(d)) == GTK_RESPONSE_ACCEPT) { char a[AVAHI_ADDRESS_STR_MAX], *u = NULL, *n = NULL; char *h = NULL, *t = NULL; const AvahiStringList *txt; t = g_strdup(aui_service_dialog_get_service_type(AUI_SERVICE_DIALOG(d))); n = g_strdup(aui_service_dialog_get_service_name(AUI_SERVICE_DIALOG(d))); if (avahi_nss_support()) h = g_strdup(aui_service_dialog_get_host_name(AUI_SERVICE_DIALOG(d))); else h = g_strdup(avahi_address_snprint(a, sizeof(a), aui_service_dialog_get_address(AUI_SERVICE_DIALOG(d)))); g_print("Connecting to '%s' ...\n", n); if (avahi_domain_equal(t, "_rfb._tcp")) { char p[AVAHI_DOMAIN_NAME_MAX+16]; snprintf(p, sizeof(p), "%s:%u", h, aui_service_dialog_get_port(AUI_SERVICE_DIALOG(d))-5900); gtk_widget_destroy(d); g_print("xvncviewer %s\n", p); execlp("xvncviewer", "xvncviewer", p, NULL); } else { char p[16]; snprintf(p, sizeof(p), "%u", aui_service_dialog_get_port(AUI_SERVICE_DIALOG(d))); for (txt = aui_service_dialog_get_txt_data(AUI_SERVICE_DIALOG(d)); txt; txt = txt->next) { char *key, *value; if (avahi_string_list_get_pair((AvahiStringList*) txt, &key, &value, NULL) < 0) break; if (strcmp(key, "u") == 0) u = g_strdup(value); avahi_free(key); avahi_free(value); } gtk_widget_destroy(d); if (u) { g_print("ssh -p %s -l %s %s\n", p, u, h); if (isatty(0) || !getenv("DISPLAY")) execlp("ssh", "ssh", "-p", p, "-l", u, h, NULL); else { execlp("x-terminal-emulator", "x-terminal-emulator", "-T", n, "-e", "ssh", "-p", p, "-l", u, h, NULL); execlp("gnome-terminal", "gnome-terminal", "-t", n, "-x", "ssh", "-p", p, "-l", u, h, NULL); execlp("xterm", "xterm", "-T", n, "-e", "ssh", "-p", p, "-l", u, h, NULL); } } else { g_print("ssh -p %s %s\n", p, h); if (isatty(0) || !getenv("DISPLAY")) execlp("ssh", "ssh", "-p", p, h, NULL); else { execlp("x-terminal-emulator", "x-terminal-emulator", "-T", n, "-e", "ssh", "-p", p, h, NULL); execlp("gnome-terminal", "gnome-terminal", "-t", n, "-x", "ssh", "-p", p, h, NULL); execlp("xterm", "xterm", "-T", n, "-e", "ssh", "-p", p, h, NULL); } } } g_warning("execlp() failed: %s\n", strerror(errno)); g_free(h); g_free(u); g_free(t); g_free(n); } else { gtk_widget_destroy(d); g_print("Canceled.\n"); } return 1; }
static void vinagre_connect_find_button_cb (GtkButton *button, VinagreConnectDialog *dialog) { GtkWidget *d; GtkTreeIter tree_iter; gchar *service; GtkWidget *options = NULL; VinagreProtocol *plugin = NULL; if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (dialog->protocol_combo), &tree_iter)) { g_warning (_("Could not get the active protocol from the protocol list.")); return; } gtk_tree_model_get (GTK_TREE_MODEL (dialog->protocol_store), &tree_iter, PROTOCOL_MDNS, &service, PROTOCOL_PLUGIN, &plugin, PROTOCOL_OPTIONS, &options, -1); if (!service) { if (plugin) g_object_unref (plugin); return; } d = aui_service_dialog_new (_("Choose a Remote Desktop"), GTK_WINDOW(dialog->dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL); gtk_window_set_transient_for (GTK_WINDOW(d), GTK_WINDOW(dialog->dialog)); aui_service_dialog_set_resolve_service (AUI_SERVICE_DIALOG(d), TRUE); aui_service_dialog_set_resolve_host_name (AUI_SERVICE_DIALOG(d), TRUE); aui_service_dialog_set_browse_service_types (AUI_SERVICE_DIALOG(d), service, NULL); if (gtk_dialog_run(GTK_DIALOG(d)) == GTK_RESPONSE_ACCEPT) { gchar *tmp; AvahiAddress *address; char a[AVAHI_ADDRESS_STR_MAX]; address = aui_service_dialog_get_address (AUI_SERVICE_DIALOG (d)); avahi_address_snprint (a, sizeof(a), address); if (address->proto == AVAHI_PROTO_INET6) tmp = g_strdup_printf ("[%s]::%d", a, aui_service_dialog_get_port (AUI_SERVICE_DIALOG (d))); else tmp = g_strdup_printf ("%s:%d", a, aui_service_dialog_get_port (AUI_SERVICE_DIALOG (d))); gtk_entry_set_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (dialog->host_entry))), tmp); g_free (tmp); if (plugin && options) vinagre_protocol_parse_mdns_dialog (plugin, options, d); } g_free (service); gtk_widget_destroy (d); if (plugin) g_object_unref (plugin); }