static gboolean init_ui (gint *argc, gchar **argv[]) { GtkWidget *main_window; gint window_width, window_height; gchar *ui_path = NULL; GError *error = NULL; GOptionContext *context; context = g_option_context_new ("- graphical SSDP debug tool"); g_option_context_add_main_entries (context, entries, NULL); g_option_context_add_group (context, gtk_get_option_group (TRUE)); if (!g_option_context_parse (context, argc, argv, &error)) { g_print ("Failed to parse options: %s\n", error->message); g_error_free (error); return FALSE; } /* Try to fetch the ui file from the CWD first */ ui_path = UI_FILE; if (!g_file_test (ui_path, G_FILE_TEST_EXISTS)) { /* Then Try to fetch it from the system path */ ui_path = UI_DIR "/" UI_FILE; if (!g_file_test (ui_path, G_FILE_TEST_EXISTS)) ui_path = NULL; } if (ui_path == NULL) { g_critical ("Unable to load the GUI file %s", UI_FILE); return FALSE; } builder = gtk_builder_new(); if (gtk_builder_add_from_file(builder, ui_path, NULL) == 0) return FALSE; main_window = GTK_WIDGET(gtk_builder_get_object (builder, "main-window")); g_assert (main_window != NULL); /* 80% of the screen but don't get bigger than 1000x800 */ window_width = CLAMP ((gdk_screen_width () * 80 / 100), 10, 1000); window_height = CLAMP ((gdk_screen_height () * 80 / 100), 10, 800); gtk_window_set_default_size (GTK_WINDOW (main_window), window_width, window_height); gtk_builder_connect_signals (builder, NULL); setup_treeviews (); gtk_widget_show_all (main_window); return TRUE; }
static gboolean init_ui (gint *argc, gchar **argv[]) { GtkWidget *main_window; gint window_width, window_height; gchar *ui_path = NULL; gtk_init (argc, argv); /* Try to fetch the ui file from the CWD first */ ui_path = UI_FILE; if (!g_file_test (ui_path, G_FILE_TEST_EXISTS)) { /* Then Try to fetch it from the system path */ ui_path = UI_DIR "/" UI_FILE; if (!g_file_test (ui_path, G_FILE_TEST_EXISTS)) ui_path = NULL; } if (ui_path == NULL) { g_critical ("Unable to load the GUI file %s", UI_FILE); return FALSE; } builder = gtk_builder_new(); if (gtk_builder_add_from_file(builder, ui_path, NULL) == 0) return FALSE; main_window = GTK_WIDGET(gtk_builder_get_object (builder, "main-window")); g_assert (main_window != NULL); /* 80% of the screen but don't get bigger than 1000x800 */ window_width = CLAMP ((gdk_screen_width () * 80 / 100), 10, 1000); window_height = CLAMP ((gdk_screen_height () * 80 / 100), 10, 800); gtk_window_set_default_size (GTK_WINDOW (main_window), window_width, window_height); gtk_builder_connect_signals (builder, NULL); setup_treeviews (); gtk_widget_show_all (main_window); return TRUE; }
gboolean init_ui (gint *argc, gchar **argv[]) { GtkWidget *about_dialog; GdkPixbuf *icon_pixbuf; GtkWidget *hpaned; GtkWidget *vpaned; gint window_width, window_height; gint position; GError *error = NULL; double w,h; gtk_init (argc, argv); builder = gtk_builder_new (); g_assert (builder != NULL); gtk_builder_set_translation_domain (builder, GETTEXT_PACKAGE); if (!gtk_builder_add_from_file (builder, UI_FILE, &error)) { g_critical ("Unable to load the GUI file %s: %s", UI_FILE, error->message); g_error_free (error); return FALSE; } main_window = GTK_WIDGET (gtk_builder_get_object (builder, "main-window")); about_dialog = GTK_WIDGET (gtk_builder_get_object (builder, "about-dialog")); hpaned = GTK_WIDGET (gtk_builder_get_object (builder, "main-window-hpaned")); vpaned = GTK_WIDGET (gtk_builder_get_object (builder, "main-window-vpaned")); g_assert (main_window != NULL); g_assert (about_dialog != NULL); g_assert (hpaned != NULL); g_assert (vpaned != NULL); /* 80% of the screen but don't get bigger than 1000x800 */ /* FIXME: Replace with proper functions */ G_GNUC_BEGIN_IGNORE_DEPRECATIONS w = gdk_screen_width () * 0.8; h = gdk_screen_height () * 0.8; G_GNUC_END_IGNORE_DEPRECATIONS /* Keep 5/4 aspect */ if (w/h > 1.25) { h = w / 1.25; } else { w = h * 1.25; } window_width = CLAMP ((int) w, 10, 1000); window_height = CLAMP ((int) h, 10, 800); gtk_window_set_default_size (GTK_WINDOW (main_window), window_width, window_height); gtk_window_resize (GTK_WINDOW (main_window), window_width, window_height); icon_pixbuf = load_pixbuf_file (ICON_FILE); if (icon_pixbuf == NULL) { return FALSE; } gtk_window_set_icon (GTK_WINDOW (main_window), icon_pixbuf); gtk_window_set_icon (GTK_WINDOW (about_dialog), icon_pixbuf); gtk_about_dialog_set_logo (GTK_ABOUT_DIALOG (about_dialog), icon_pixbuf); gtk_about_dialog_set_version (GTK_ABOUT_DIALOG (about_dialog), VERSION); g_object_unref (icon_pixbuf); gtk_builder_connect_signals (builder, NULL); init_icons (); setup_treeviews (); init_action_dialog (builder); gtk_widget_show_all (main_window); /* Give device treeview 40% of the main window */ g_object_get (hpaned, "max-position", &position, NULL); position = position * 40 / 100; g_object_set (hpaned, "position", position, NULL); /* Give details treeview 60% of 60% of the main window */ g_object_get (vpaned, "max-position", &position, NULL); position = position * 60 / 100; g_object_set (vpaned, "position", position, NULL); return TRUE; }