-
int main(int argc, char *argv[])
-
{
-
GError *error = NULL;
-
GOptionContext *context;
-
spice_connection *conn;
-
gchar *conf_file, *conf;
-
char *host = NULL, *port = NULL, *tls_port = NULL;
-
-
-
#if !GLIB_CHECK_VERSION(2,31,18)
-
g_thread_init(NULL);
-
#endif
-
/*国际化*/
-
bindtextdomain(GETTEXT_PACKAGE, SPICE_GTK_LOCALEDIR);
-
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
-
textdomain(GETTEXT_PACKAGE);
-
-
-
/*信号处理函数*/
-
signal(SIGINT, signal_handler);
-
signal(SIGTERM, signal_handler);
-
segv_handler = signal(SIGSEGV, signal_handler);
-
abrt_handler = signal(SIGABRT, signal_handler);
-
fpe_handler = signal(SIGFPE, signal_handler);
-
ill_handler = signal(SIGILL, signal_handler);
-
-
#ifndef WIN32
-
signal(SIGHUP, signal_handler);
-
bus_handler = signal(SIGBUS, signal_handler);
-
#endif
-
-
-
/*读取配置文件*/
-
keyfile = g_key_file_new();
-
-
-
int mode = S_IRWXU;
-
conf_file = g_build_filename(g_get_user_config_dir(), "spicy", NULL);
-
if (g_mkdir_with_parents(conf_file, mode) == -1)
-
SPICE_DEBUG("failed to create config directory");
-
g_free(conf_file);
-
-
-
conf_file = g_build_filename(g_get_user_config_dir(), "spicy", "settings", NULL);
-
if (!g_key_file_load_from_file(keyfile, conf_file,
-
G_KEY_FILE_KEEP_COMMENTS|G_KEY_FILE_KEEP_TRANSLATIONS, &error)) {
-
SPICE_DEBUG("Couldn't load configuration: %s", error->message);
-
g_clear_error(&error);
-
}
-
-
/*解析命令行传入的参数*/
-
/* parse opts */
-
gtk_init(&argc, &argv);
-
context = g_option_context_new(_("- spice client test application"));
-
g_option_context_set_summary(context, _("Gtk+ test client to connect to Spice servers."));
-
g_option_context_set_description(context, _("Report bugs to " PACKAGE_BUGREPORT "."));
-
g_option_context_add_group(context, spice_get_option_group());
-
g_option_context_set_main_group(context, spice_cmdline_get_option_group());
-
g_option_context_add_main_entries(context, cmd_entries, NULL);
-
g_option_context_add_group(context, gtk_get_option_group(TRUE));
-
if (!g_option_context_parse (context, &argc, &argv, &error)) {
-
g_print(_("option parsing failed: %s\n"), error->message);
-
exit(1);
-
}
-
g_option_context_free(context);
-
-
-
if (version) {
-
g_print("spicy " PACKAGE_VERSION "\n");
-
exit(0);
-
}
-
-
-
-
-
g_type_init();
-
mainloop = g_main_loop_new(NULL, false);
-
-
-
/*设置conn的通道默认回调函数,设置内部默认参数,读取命令行参数*/
-
conn = connection_new();
-
spice_set_session_option(conn->session);
-
spice_cmdline_session_setup(conn->session);
-
-
-
g_object_get(conn->session,
-
"host", &host,
-
"port", &port,
-
"tls-port", &tls_port,
-
NULL);
-
/* If user doesn't provide hostname and port, show the dialog window
-
instead of connecting to server automatically */
-
if (host == NULL || (port == NULL && tls_port == NULL)) {
-
int ret = connect_dialog(conn->session);
-
if (ret != 0) {
-
exit(0);
-
}
-
}
-
g_free(host);
-
g_free(port);
-
g_free(tls_port);
-
-
-
watch_stdin();
-
-
-
/*创建主通道,激活channel_new()*/
-
connection_connect(conn);
-
if (connections > 0)
-
g_main_loop_run(mainloop);
-
g_main_loop_unref(mainloop);
-
-
-
if ((conf = g_key_file_to_data(keyfile, NULL, &error)) == NULL ||
-
!g_file_set_contents(conf_file, conf, -1, &error)) {
-
SPICE_DEBUG("Couldn't save configuration: %s", error->message);
-
g_error_free(error);
-
error = NULL;
-
}
-
-
-
g_free(conf_file);
-
g_free(conf);
-
g_key_file_free(keyfile);
-
-
-
g_free(spicy_title);
-
-
-
setup_terminal(true);
-
return 0;
-
}
阅读(1650) | 评论(0) | 转发(0) |