[beast: 10/12] BEAST: avoid use of the 'category_id' field, use GQuark to identify categories



commit 131a217b30dfa0eb41fb81bdd467425811651f2f
Author: Tim Janik <timj gnu org>
Date:   Mon Sep 21 09:39:21 2015 +0200

    BEAST: avoid use of the 'category_id' field, use GQuark to identify categories

 beast-gtk/bstapp.cc        |    8 +++-----
 beast-gtk/bstbseutils.cc   |   12 ++++++++++++
 beast-gtk/bstbseutils.hh   |    1 +
 beast-gtk/bstpartdialog.cc |    7 +++----
 beast-gtk/bstsnetrouter.cc |   10 +++++-----
 beast-gtk/bstutils.cc      |    2 +-
 6 files changed, 25 insertions(+), 15 deletions(-)
---
diff --git a/beast-gtk/bstapp.cc b/beast-gtk/bstapp.cc
index 1525104..d722ad3 100644
--- a/beast-gtk/bstapp.cc
+++ b/beast-gtk/bstapp.cc
@@ -17,8 +17,7 @@
 
 
 /* --- prototypes --- */
-static void           bst_app_run_script_proc     (gpointer     data,
-                                                   size_t       category_id);
+static void           bst_app_run_script_proc     (gpointer data, size_t action_id);
 static GxkActionList* demo_entries_create         (BstApp      *app);
 static GxkActionList* skin_entries_create         (BstApp      *app);
 static void           app_action_exec             (gpointer     data,
@@ -793,11 +792,10 @@ skin_entries_create (BstApp *app)
 }
 
 static void
-bst_app_run_script_proc (gpointer data,
-                         size_t   category_id)
+bst_app_run_script_proc (gpointer data, size_t action_id)
 {
   BstApp *self = BST_APP (data);
-  BseCategory *cat = bse_category_from_id (category_id);
+  BseCategory *cat = bse_category_find (g_quark_to_string (action_id));
   SfiProxy super = bst_app_get_current_super (self);
   const gchar *song = "", *wave_repo = "", *snet = "", *csynth = "";
 
diff --git a/beast-gtk/bstbseutils.cc b/beast-gtk/bstbseutils.cc
index 5837a63..7beba63 100644
--- a/beast-gtk/bstbseutils.cc
+++ b/beast-gtk/bstbseutils.cc
@@ -64,6 +64,18 @@ bst_procedure_get_title (const gchar *procedure)
   return NULL;
 }
 
+
+BseCategory*
+bse_category_find (const gchar* pattern)
+{
+  BseCategorySeq *cseq = NULL;
+  if (pattern)
+    cseq = bse_categories_match (pattern);
+  if (cseq && cseq->n_cats == 1)
+    return cseq->cats[0];
+  return NULL;
+}
+
 /// Return the character index of the last string segment not containing @a separator.
 uint
 bst_path_leaf_index (const String &path, char separator)
diff --git a/beast-gtk/bstbseutils.hh b/beast-gtk/bstbseutils.hh
index 96a2f41..38f4c18 100644
--- a/beast-gtk/bstbseutils.hh
+++ b/beast-gtk/bstbseutils.hh
@@ -40,6 +40,7 @@ Bse::ErrorType    bst_project_import_midi_file    (Bse::ProjectH   project,
                                                  const gchar    *file_name);
 const gchar*    bst_procedure_get_title         (const gchar    *procedure);
 uint            bst_path_leaf_index             (const String &path, char separator = '/');
+BseCategory*    bse_category_find               (const gchar* pattern);
 
 
 G_END_DECLS
diff --git a/beast-gtk/bstpartdialog.cc b/beast-gtk/bstpartdialog.cc
index 5932f6f..c772451 100644
--- a/beast-gtk/bstpartdialog.cc
+++ b/beast-gtk/bstpartdialog.cc
@@ -27,8 +27,7 @@ static gboolean part_dialog_action_check        (gpointer                data,
                                                  guint64                 action_stamp);
 static void     part_dialog_action_exec         (gpointer                data,
                                                  size_t                  action);
-static void     part_dialog_run_script_proc     (gpointer                data,
-                                                 size_t                  category_id);
+static void     part_dialog_run_script_proc     (gpointer data, size_t action_id);
 
 
 /* --- track actions --- */
@@ -322,10 +321,10 @@ event_canvas_clicked (BstEventRoll           *eroll,
 }
 
 static void
-part_dialog_run_script_proc (gpointer data, size_t category_id)
+part_dialog_run_script_proc (gpointer data, size_t action_id)
 {
   BstPartDialog *self = BST_PART_DIALOG (data);
-  BseCategory *cat = bse_category_from_id (category_id);
+  BseCategory *cat = bse_category_find (g_quark_to_string (action_id));
   Bse::PartH part = self->proll->part;
 
   bst_procedure_exec_auto (cat->type,
diff --git a/beast-gtk/bstsnetrouter.cc b/beast-gtk/bstsnetrouter.cc
index bc50a50..9ff719c 100644
--- a/beast-gtk/bstsnetrouter.cc
+++ b/beast-gtk/bstsnetrouter.cc
@@ -17,7 +17,7 @@
 
 enum {
   ROUTER_TOOL_EDIT              = 0,
-  ROUTER_TOOL_CREATE_LINK       = G_MAXINT - 1024,      /* don't clash with category IDs */
+  ROUTER_TOOL_CREATE_LINK       = G_MAXINT - 1024,      /* don't clash with category IDs / GQuarks */
   ROUTER_TOOL_TOGGLE_PALETTE,
   ROUTER_TOOL_CHANNEL_HINTS
 };
@@ -326,7 +326,7 @@ static void
 bst_router_run_method (gpointer user_data, size_t action_id)
 {
   BstSNetRouter *self = BST_SNET_ROUTER (user_data);
-  BseCategory *cat = bse_category_from_id (action_id);
+  BseCategory *cat = bse_category_find (g_quark_to_string (action_id));
   bst_procedure_exec_auto (cat->type,
                            "synth-net", SFI_TYPE_PROXY, self->snet.proxy_id(),
                            BSE_IS_CSYNTH (self->snet.proxy_id()) ? "custom-synth" : "", SFI_TYPE_PROXY, 
self->snet.proxy_id(),
@@ -774,7 +774,7 @@ bst_snet_router_event (GtkWidget *widget,
           ROUTER_TOOL (self) != ROUTER_TOOL_CREATE_LINK) /* add new source */
         {
           Bse::ErrorType error;
-          BseCategory *cat = bse_category_from_id (ROUTER_TOOL (self));
+          BseCategory *cat = bse_category_find (g_quark_to_string (ROUTER_TOOL (self)));
 
           handled = TRUE;
           gnome_canvas_window_to_world (canvas,
@@ -844,7 +844,7 @@ static void
 snet_router_tool2text (BstSNetRouter *self)
 {
   GtkLabel *label = (GtkLabel*) gxk_radget_find (self->palette, "type-label");
-  BseCategory *cat = ROUTER_TOOL (self) ? bse_category_from_id (ROUTER_TOOL (self)) : 0;
+  BseCategory *cat = ROUTER_TOOL (self) ? bse_category_find (g_quark_to_string (ROUTER_TOOL (self))) : 0;
   const gchar *blurb = cat ? bse_type_blurb (cat->type) : NULL;
   const gchar *authors = cat ? bse_type_authors (cat->type) : NULL;
   const gchar *license = cat ? bse_type_license (cat->type) : NULL;
@@ -1106,7 +1106,7 @@ bst_snet_router_init (BstSNetRouter      *self)
         gxk_action_list_add_translated (toolbar_modules, cat->type,
                                         _(toolbar_types[n].name), NULL,
                                         _(toolbar_types[n].tip),
-                                        cat->category_id,
+                                        g_quark_from_string (cat->category),
                                         stock_id,
                                         NULL, bst_router_popup_select, self);
       }
diff --git a/beast-gtk/bstutils.cc b/beast-gtk/bstutils.cc
index d1b7f34..c87c786 100644
--- a/beast-gtk/bstutils.cc
+++ b/beast-gtk/bstutils.cc
@@ -475,7 +475,7 @@ bst_action_list_add_cat (GxkActionList          *alist,
 
   gxk_action_list_add_translated (alist, NULL, p, NULL,
                                   gxk_factory_path_get_leaf (cat->category),
-                                  cat->category_id, stock_id,
+                                  g_quark_from_string (cat->category), stock_id,
                                   acheck, aexec, user_data);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]