Prompt for a hostname by default
This commit is contained in:
parent
01b794abfa
commit
e18d4f220e
54
src/main.c
54
src/main.c
|
@ -25,6 +25,7 @@
|
|||
#include <vncdisplay.h>
|
||||
#include <vncutil.h>
|
||||
#include "vncviewer.h"
|
||||
#include "../config.h"
|
||||
|
||||
/* constants */
|
||||
#ifndef PROGNAME
|
||||
|
@ -42,12 +43,56 @@ static const GOptionEntry options [] =
|
|||
};
|
||||
|
||||
|
||||
static char * _vncviewer_get_hostname(void)
|
||||
{
|
||||
GtkWidget * dialog;
|
||||
GtkWidget * box;
|
||||
GtkWidget * widget;
|
||||
GtkWidget * content;
|
||||
char * hostname = NULL;
|
||||
|
||||
dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_QUESTION,
|
||||
GTK_BUTTONS_NONE,
|
||||
#if GTK_CHECK_VERSION(2, 6, 0)
|
||||
"%s", PACKAGE);
|
||||
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
|
||||
#endif
|
||||
"Please choose a hostname to connect to");
|
||||
#if GTK_CHECK_VERSION(2, 10, 0)
|
||||
gtk_message_dialog_set_image(GTK_MESSAGE_DIALOG(dialog),
|
||||
gtk_image_new_from_icon_name("gnome-remote-desktop",
|
||||
GTK_ICON_SIZE_DIALOG));
|
||||
#endif
|
||||
gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CANCEL,
|
||||
GTK_RESPONSE_REJECT);
|
||||
gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CONNECT,
|
||||
GTK_RESPONSE_ACCEPT);
|
||||
gtk_dialog_set_default_response(GTK_DIALOG(dialog),
|
||||
GTK_RESPONSE_ACCEPT);
|
||||
gtk_window_set_title(GTK_WINDOW(dialog), PACKAGE);
|
||||
box = gtk_hbox_new(FALSE, 4);
|
||||
widget = gtk_label_new("Hostname: ");
|
||||
gtk_box_pack_start(GTK_BOX(box), widget, FALSE, TRUE, 0);
|
||||
widget = gtk_entry_new();
|
||||
gtk_entry_set_activates_default(GTK_ENTRY(widget), TRUE);
|
||||
gtk_box_pack_start(GTK_BOX(box), widget, TRUE, TRUE, 0);
|
||||
gtk_widget_show_all(box);
|
||||
content = gtk_bin_get_child(GTK_BIN(dialog));
|
||||
gtk_container_add(GTK_CONTAINER(content), box);
|
||||
if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
|
||||
hostname = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
|
||||
gtk_widget_destroy(dialog);
|
||||
return hostname;
|
||||
}
|
||||
|
||||
|
||||
/* main */
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
gchar *name;
|
||||
gchar *name, *hostname = NULL;
|
||||
GOptionContext *context;
|
||||
GError *error = NULL;
|
||||
gchar ** args2[2] = { NULL, NULL };
|
||||
|
||||
name = g_strdup_printf("- Simple VNC Client on Gtk-VNC %s",
|
||||
vnc_util_get_version_string());
|
||||
|
@ -63,11 +108,14 @@ int main(int argc, char **argv)
|
|||
return 1;
|
||||
}
|
||||
if (!args || (g_strv_length(args) != 1)) {
|
||||
fprintf(stderr, "Usage: " PROGNAME " [hostname][:display]\n");
|
||||
return 1;
|
||||
if((hostname = _vncviewer_get_hostname()) == NULL)
|
||||
return 0;
|
||||
args2[0] = hostname;
|
||||
args = args2;
|
||||
}
|
||||
vncviewer(args);
|
||||
gtk_main();
|
||||
g_free(hostname);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ sources=vncviewer.c,main.c
|
|||
install=$(BINDIR)
|
||||
|
||||
[main.c]
|
||||
depends=vncviewer.h
|
||||
depends=vncviewer.h,../config.h
|
||||
|
||||
[vncviewer.c]
|
||||
depends=vncviewer.h,../config.h
|
||||
|
|
Loading…
Reference in New Issue
Block a user