From e2cb03ab32d2d219a3fd363306bb4bf56fdd3242 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mo=C5=84?= Date: Sun, 1 Mar 2009 13:31:15 +0100 Subject: [PATCH] add store preset window --- gdigi.c | 2 +- gdigi.h | 2 +- gui.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 2 deletions(-) diff --git a/gdigi.c b/gdigi.c index 864d382..b1e492f 100644 --- a/gdigi.c +++ b/gdigi.c @@ -234,7 +234,7 @@ void set_preset_level(int level) set_option(PRESET_LEVEL, PRESET_POSITION, level); } -void store_preset_name(int x, gchar *name) +void store_preset_name(int x, const gchar *name) { static char set_name[] = {0xF0, 0x00, 0x00, 0x10, 0x00, 0x5e, 0x02, 0x39, 0x00, 0x04, 0x00, 0x01, 0x00 /* preset number */, 0x00 /* name starts here */, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; diff --git a/gdigi.h b/gdigi.h index 67108aa..d860747 100644 --- a/gdigi.h +++ b/gdigi.h @@ -496,7 +496,7 @@ typedef enum { void set_option(guint id, guint position, guint value); void switch_preset(guint bank, guint x); -void store_preset_name(int x, gchar *name); +void store_preset_name(int x, const gchar *name); void set_preset_level(int level); GStrv query_preset_names(PresetBank bank); diff --git a/gui.c b/gui.c index 8b237ac..1819e04 100644 --- a/gui.c +++ b/gui.c @@ -258,6 +258,59 @@ GtkWidget *create_preset_tree() return treeview; } +static void show_store_preset_window(GtkWidget *window, gchar *default_name) +{ + GtkWidget *dialog, *cmbox, *entry, *table, *label; + GStrv names; + int x; + + dialog = gtk_dialog_new_with_buttons("Store preset", + GTK_WINDOW(window), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, + NULL); + + table = gtk_table_new(2, 2, FALSE); + gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), table); + + cmbox = gtk_combo_box_new_text(); + names = query_preset_names(PRESETS_USER); + for (x=0; xvbox); + if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { + gint number = gtk_combo_box_get_active(GTK_COMBO_BOX(cmbox)); + if (number != -1) { + store_preset_name(number, gtk_entry_get_text(GTK_ENTRY(entry))); + } + } + + gtk_widget_destroy(dialog); +} +static void action_store_cb(GtkAction *action) +{ + GtkWidget *window = g_object_get_data(G_OBJECT(action), "window"); + show_store_preset_window(window, NULL); +} + static void action_show_about_dialog_cb(GtkAction *action) { static const gchar * const authors[] = { @@ -326,6 +379,21 @@ static void action_open_preset_cb(GtkAction *action) gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); Preset *preset = create_preset_from_xml_file(filename); if (preset != NULL) { + gtk_widget_hide(dialog); + + GList *iter = preset->params; + while (iter) { + SettingParam *param = iter->data; + iter = iter->next; + + /* sending those is likely to freeze/reboot device */ + if ((param->id == 8704) || (param->id == 8705)) + continue; + + set_option(param->id, param->position, param->value); + }; + show_store_preset_window(window, preset->name); + preset_free(preset); loaded = TRUE; } @@ -347,9 +415,11 @@ static void action_quit_cb(GtkAction *action) static GtkActionEntry entries[] = { {"File", NULL, "_File"}, + {"Preset", NULL, "_Preset"}, {"Help", NULL, "_Help"}, {"Open", GTK_STOCK_OPEN, "_Open", "O", "Open preset file", G_CALLBACK(action_open_preset_cb)}, {"Quit", GTK_STOCK_QUIT, "_Quit", "Q", "Quit", G_CALLBACK(action_quit_cb)}, + {"Store", NULL, "_Store", "S", "Store", G_CALLBACK(action_store_cb)}, {"About", GTK_STOCK_ABOUT, "_About", "A", "About", G_CALLBACK(action_show_about_dialog_cb)}, }; static guint n_entries = G_N_ELEMENTS(entries); @@ -362,6 +432,9 @@ static const gchar *menu_info = " " " " " " +" " +" " +" " " " " " " " @@ -398,6 +471,9 @@ static void add_menubar(GtkWidget *window, GtkWidget *vbox) 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/Preset/Store"); + 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);