/* * Copyright (c) 2009 Tomasz Moń * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; under version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include "gdigi.h" #include "gui.h" #include "effects.h" #include "preset.h" extern EffectList effects[]; extern int n_effects; void value_changed_option_cb(GtkSpinButton *spinbutton, EffectSettings *setting) { g_return_if_fail(setting != NULL); int val = gtk_spin_button_get_value_as_int(spinbutton); set_option(setting->option, setting->position, val); } void toggled_cb(GtkToggleButton *button, Effect *effect) { g_return_if_fail(effect != NULL); guint val = gtk_toggle_button_get_active(button); set_option(effect->option, effect->position, val); } GtkWidget *create_table(EffectSettings *settings, gint amt) { GtkWidget *table, *label, *widget; GtkObject *adj; int x; table = gtk_table_new(2, amt, FALSE); for (x = 0; xlabel); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), FALSE); g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(toggled_cb), effect); return button; } typedef struct { gint id; /* effect group ID (value) */ gint option; /* option ID */ gint position; /* position */ GtkWidget *child; /* child widget */ } EffectSettingsGroup; void effect_settings_group_free(EffectSettingsGroup *group) { /* destroy widget without parent */ if (gtk_widget_get_parent(group->child) == NULL) gtk_widget_destroy(group->child); g_object_unref(group->child); g_free(group); } void combo_box_changed_cb(GtkComboBox *widget, gpointer data) { GtkWidget *child; GtkWidget *vbox; EffectSettingsGroup *settings = NULL; gchar *name = NULL; gint x; g_object_get(G_OBJECT(widget), "active", &x, NULL); vbox = g_object_get_data(G_OBJECT(widget), "vbox"); if (x != -1) { name = g_strdup_printf("SettingsGroup%d", x); settings = g_object_get_data(G_OBJECT(widget), name); g_free(name); if (settings != NULL) set_option(settings->option, settings->position, settings->id); child = g_object_get_data(G_OBJECT(widget), "active_child"); if (child != NULL) { gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(gtk_widget_get_parent(vbox))), child); } gtk_container_add(GTK_CONTAINER(gtk_widget_get_parent(gtk_widget_get_parent(vbox))), settings->child); gtk_widget_show_all(gtk_widget_get_parent(gtk_widget_get_parent(vbox))); g_object_set_data(G_OBJECT(widget), "active_child", settings->child); } } GtkWidget *create_widget_container(EffectGroup *group, gint amt) { GtkWidget *vbox; GtkWidget *widget; GtkWidget *combo_box = NULL; EffectSettingsGroup *settings = NULL; gchar *name = NULL; gint x; gint cmbox_no = -1; vbox = gtk_vbox_new(FALSE, 0); for (x = 0; xid = group[x].id; settings->option = group[x].option; settings->position = group[x].position; settings->child = widget; name = g_strdup_printf("SettingsGroup%d", cmbox_no); g_object_set_data_full(G_OBJECT(combo_box), name, settings, ((GDestroyNotify)effect_settings_group_free)); g_free(name); } else { widget = create_table(group[x].settings, group[x].settings_amt); gtk_container_add(GTK_CONTAINER(vbox), widget); } } return vbox; }; GtkWidget *create_vbox(Effect *widgets, gint amt) { GtkWidget *vbox; GtkWidget *hbox; GtkWidget *widget; GtkWidget *table; int x; vbox = gtk_vbox_new(FALSE, 0); hbox = gtk_hbox_new(FALSE, 0); gtk_box_set_homogeneous(GTK_BOX(hbox), TRUE); for (x = 0; x", NULL }; static const gchar copyright[] = "Copyright \xc2\xa9 2009 Tomasz Moń"; static const gchar website[] = "http://desowin.org/gdigi/"; GtkWidget *window = g_object_get_data(G_OBJECT(action), "window"); gtk_show_about_dialog(GTK_WINDOW(window), "authors", authors, "copyright", copyright, "website", website, NULL); } typedef struct { gchar *name; gchar *suffix; } SupportedFileTypes; static SupportedFileTypes file_types[] = { {"RP250Preset", "*.rp250p"}, }; static guint n_file_types = G_N_ELEMENTS(file_types); static void action_open_preset_cb(GtkAction *action) { static GtkWidget *dialog = NULL; static gchar *last_directory = NULL; if (dialog != NULL) return; GtkWidget *window = g_object_get_data(G_OBJECT(action), "window"); dialog = gtk_file_chooser_dialog_new("Open Preset", GTK_WINDOW(window), GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); if (last_directory) gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), last_directory); GtkFileFilter *filter; filter = gtk_file_filter_new(); gtk_file_filter_set_name(filter, "All Supported Types"); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter); int x; for (x=0; xO", "Open preset file", G_CALLBACK(action_open_preset_cb)}, {"Quit", GTK_STOCK_QUIT, "_Quit", "Q", "Quit", G_CALLBACK(action_quit_cb)}, {"About", GTK_STOCK_ABOUT, "_About", "A", "About", G_CALLBACK(action_show_about_dialog_cb)}, }; static guint n_entries = G_N_ELEMENTS(entries); static const gchar *menu_info = "" " " " " " " " " " " " " " " " " " " " " ""; static void add_menubar(GtkWidget *window, GtkWidget *vbox) { GtkUIManager *ui; GtkActionGroup *actions; GtkAction *action; GError *error = NULL; actions = gtk_action_group_new("Actions"); gtk_action_group_add_actions(actions, entries, n_entries, NULL); ui = gtk_ui_manager_new(); gtk_ui_manager_insert_action_group(ui, actions, 0); g_object_unref(actions); gtk_window_add_accel_group(GTK_WINDOW(window), gtk_ui_manager_get_accel_group(ui)); if (!gtk_ui_manager_add_ui_from_string(ui, menu_info, -1, &error)) { g_message("building menus failed: %s", error->message); g_error_free(error); error = NULL; } gtk_box_pack_start(GTK_BOX(vbox), gtk_ui_manager_get_widget(ui, "/MenuBar"), FALSE, FALSE, 0); action = gtk_ui_manager_get_action(ui, "/MenuBar/File/Quit"); g_object_set_data(G_OBJECT(action), "window", window); action = gtk_ui_manager_get_action(ui, "/MenuBar/File/Open"); g_object_set_data(G_OBJECT(action), "window", window); action = gtk_ui_manager_get_action(ui, "/MenuBar/Help/About"); g_object_set_data(G_OBJECT(action), "window", window); g_object_unref(ui); } void create_window() { GtkWidget *window; GtkWidget *vbox; GtkWidget *hbox; GtkWidget *widget; GtkWidget *sw; /* scrolled window to carry preset treeview */ gint x; window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(window), "gdigi"); vbox = gtk_vbox_new(FALSE, 0); gtk_container_add(GTK_CONTAINER(window), vbox); add_menubar(window, vbox); hbox = gtk_hbox_new(FALSE, 0); gtk_container_add(GTK_CONTAINER(vbox), hbox); sw = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); gtk_box_pack_start(GTK_BOX(hbox), sw, FALSE, FALSE, 0); widget = create_preset_tree(); gtk_container_add(GTK_CONTAINER(sw), widget); vbox = gtk_vbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 2); for (x = 0; x