+ return main_vbox;
+}
+
+static gboolean notebook_switch_page(GtkNotebook *notebook, GtkWidget *widget,
+ guint page, gpointer data)
+
+{
+ struct gui *ui = (struct gui *) data;
+ struct gui_entry *ge;
+
+ if (!page) {
+ set_job_menu_visible(ui, 0);
+ set_view_results_visible(ui, 0);
+ return TRUE;
+ }
+
+ set_job_menu_visible(ui, 1);
+ ge = get_ge_from_page(ui, page, NULL);
+ if (ge)
+ update_button_states(ui, ge);
+
+ return TRUE;
+}
+
+static gint compare_recent_items(GtkRecentInfo *a, GtkRecentInfo *b)
+{
+ time_t time_a = gtk_recent_info_get_visited(a);
+ time_t time_b = gtk_recent_info_get_visited(b);
+
+ return time_b - time_a;
+}
+
+static void add_recent_file_items(struct gui *ui)
+{
+ const gchar *gfio = g_get_application_name();
+ GList *items, *item;
+ int i = 0;
+
+ if (ui->recent_ui_id) {
+ gtk_ui_manager_remove_ui(ui->uimanager, ui->recent_ui_id);
+ gtk_ui_manager_ensure_update(ui->uimanager);
+ }
+ ui->recent_ui_id = gtk_ui_manager_new_merge_id(ui->uimanager);
+
+ if (ui->actiongroup) {
+ gtk_ui_manager_remove_action_group(ui->uimanager, ui->actiongroup);
+ g_object_unref(ui->actiongroup);
+ }
+ ui->actiongroup = gtk_action_group_new("RecentFileActions");
+
+ gtk_ui_manager_insert_action_group(ui->uimanager, ui->actiongroup, -1);
+
+ items = gtk_recent_manager_get_items(ui->recentmanager);
+ items = g_list_sort(items, (GCompareFunc) compare_recent_items);
+
+ for (item = items; item && item->data; item = g_list_next(item)) {
+ GtkRecentInfo *info = (GtkRecentInfo *) item->data;
+ gchar *action_name;
+ const gchar *label;
+ GtkAction *action;
+
+ if (!gtk_recent_info_has_application(info, gfio))
+ continue;
+
+ /*
+ * We only support local files for now
+ */
+ if (!gtk_recent_info_is_local(info) || !gtk_recent_info_exists(info))
+ continue;
+
+ action_name = g_strdup_printf("RecentFile%u", i++);
+ label = gtk_recent_info_get_display_name(info);
+
+ action = g_object_new(GTK_TYPE_ACTION,
+ "name", action_name,
+ "label", label, NULL);
+
+ g_object_set_data_full(G_OBJECT(action), "gtk-recent-info",
+ gtk_recent_info_ref(info),
+ (GDestroyNotify) gtk_recent_info_unref);
+
+
+ g_signal_connect(action, "activate", G_CALLBACK(recent_open), ui);
+
+ gtk_action_group_add_action(ui->actiongroup, action);
+ g_object_unref(action);
+
+ gtk_ui_manager_add_ui(ui->uimanager, ui->recent_ui_id,
+ "/MainMenu/FileMenu/FileRecentFiles",
+ label, action_name,
+ GTK_UI_MANAGER_MENUITEM, FALSE);
+
+ g_free(action_name);
+
+ if (i == 8)
+ break;
+ }
+
+ g_list_foreach(items, (GFunc) gtk_recent_info_unref, NULL);
+ g_list_free(items);
+}
+
+static void drag_and_drop_received(GtkWidget *widget, GdkDragContext *ctx,
+ gint x, gint y, GtkSelectionData *seldata,
+ guint info, guint time, gpointer *data)
+{
+ struct gui *ui = (struct gui *) data;
+ gchar **uris;
+ GtkWidget *source;
+
+ source = gtk_drag_get_source_widget(ctx);
+ if (source && widget == gtk_widget_get_toplevel(source)) {
+ gtk_drag_finish(ctx, FALSE, FALSE, time);
+ return;
+ }
+
+ uris = gtk_selection_data_get_uris(seldata);
+ if (!uris) {
+ gtk_drag_finish(ctx, FALSE, FALSE, time);
+ return;
+ }
+
+ if (uris[0])
+ do_file_open_with_tab(ui, uris[0]);
+
+ gtk_drag_finish(ctx, TRUE, FALSE, time);
+ g_strfreev(uris);
+}
+
+static void init_ui(int *argc, char **argv[], struct gui *ui)
+{
+ GtkSettings *settings;
+ GtkWidget *vbox;
+
+ /* Magical g*thread incantation, you just need this thread stuff.
+ * Without it, the update that happens in gfio_update_thread_status
+ * doesn't really happen in a timely fashion, you need expose events
+ */
+#if !GLIB_CHECK_VERSION(2, 31, 0)
+ if (!g_thread_supported())
+ g_thread_init(NULL);
+#endif
+
+ gdk_threads_init();
+
+ gtk_init(argc, argv);
+ settings = gtk_settings_get_default();
+ gtk_settings_set_long_property(settings, "gtk_tooltip_timeout", 10, "gfio setting");
+#if !GLIB_CHECK_VERSION(2, 36, 0)
+ g_type_init();
+#endif
+ gdk_color_parse("#fffff4", &gfio_color_lightyellow);
+ gdk_color_parse("white", &gfio_color_white);
+
+ ui->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_title(GTK_WINDOW(ui->window), "fio");
+ gtk_window_set_default_size(GTK_WINDOW(ui->window), 1024, 768);
+
+ g_signal_connect(ui->window, "delete-event", G_CALLBACK(quit_clicked), ui);
+ g_signal_connect(ui->window, "destroy", G_CALLBACK(quit_clicked), ui);
+
+ ui->vbox = gtk_vbox_new(FALSE, 0);
+ gtk_container_add(GTK_CONTAINER(ui->window), ui->vbox);
+
+ ui->uimanager = gtk_ui_manager_new();
+ ui->menu = get_menubar_menu(ui->window, ui->uimanager, ui);
+ gfio_ui_setup(settings, ui->menu, ui->vbox, ui->uimanager);
+
+ ui->recentmanager = gtk_recent_manager_get_default();
+ add_recent_file_items(ui);
+
+ ui->notebook = gtk_notebook_new();
+ g_signal_connect(ui->notebook, "switch-page", G_CALLBACK(notebook_switch_page), ui);
+ gtk_notebook_set_scrollable(GTK_NOTEBOOK(ui->notebook), 1);
+ gtk_notebook_popup_enable(GTK_NOTEBOOK(ui->notebook));
+ gtk_container_add(GTK_CONTAINER(ui->vbox), ui->notebook);
+
+ vbox = new_main_page(ui);
+ gtk_drag_dest_set(GTK_WIDGET(ui->window), GTK_DEST_DEFAULT_ALL, NULL, 1, GDK_ACTION_COPY);
+ gtk_drag_dest_add_uri_targets(GTK_WIDGET(ui->window));
+ g_signal_connect(ui->window, "drag-data-received", G_CALLBACK(drag_and_drop_received), ui);
+
+ gtk_notebook_append_page(GTK_NOTEBOOK(ui->notebook), vbox, gtk_label_new("Main"));
+