[SCM] calf/master: Implement GConf-based configuration of rack ears. Needs to be changed in gconf-editor directly for now.

js at users.alioth.debian.org js at users.alioth.debian.org
Tue May 7 15:40:21 UTC 2013


The following commit has been merged in the master branch:
commit 42ae66d84f0a1981dc2c3cf9343e3409fee5256e
Author: Krzysztof Foltman <wdev at foltman.com>
Date:   Sat Sep 11 12:31:43 2010 +0100

    Implement GConf-based configuration of rack ears. Needs to be changed in gconf-editor directly for now.

diff --git a/src/calf/gui.h b/src/calf/gui.h
index b423da6..82b1dd3 100644
--- a/src/calf/gui.h
+++ b/src/calf/gui.h
@@ -27,6 +27,7 @@
 #include <vector>
 #include <gtk/gtk.h>
 #include "giface.h"
+#include "gui_config.h"
 
 namespace calf_plugins {
 
@@ -114,7 +115,6 @@ public:
     plugin_ctl_iface *plugin;
     preset_access_iface *preset_access;
     std::vector<param_control *> params;
-    bool draw_rackmounts;
 
     plugin_gui(plugin_gui_window *_window);
     GtkWidget *create_from_xml(plugin_ctl_iface *_plugin, const char *xml);
@@ -149,15 +149,27 @@ class main_window_owner_iface;
 struct gui_environment_iface
 {
     virtual bool check_condition(const char *name)=0;
+    virtual calf_utils::config_db_iface *get_config_db() = 0;
+    virtual calf_utils::gui_config *get_config() = 0;
     virtual ~gui_environment_iface() {}
 };
 
 /// Trivial implementation of gui_environment_iface
 class gui_environment: public gui_environment_iface
 {
+private:
+    calf_utils::config_db_iface *config_db;
+    calf_utils::gui_config gui_config;
+
 public:
     std::set<std::string> conditions;
+
+public:
+    gui_environment();
     virtual bool check_condition(const char *name) { return conditions.count(name) != 0; }
+    virtual calf_utils::config_db_iface *get_config_db() { return config_db; }
+    virtual calf_utils::gui_config *get_config() { return &gui_config; }
+    ~gui_environment();
 };
 
 /// Interface used by the plugin to communicate with the main hosting window
@@ -182,7 +194,7 @@ struct main_window_owner_iface
     virtual ~main_window_owner_iface() {}
 };
 
-class plugin_gui_window
+class plugin_gui_window: public calf_utils::config_listener_iface
 {
 public:
     plugin_gui *gui;
@@ -192,6 +204,7 @@ public:
     gui_environment_iface *environment;
     main_window_iface *main;
     int source_id;
+    calf_utils::config_notifier_iface *notifier;
 
     plugin_gui_window(gui_environment_iface *_env, main_window_iface *_main);
     std::string make_gui_preset_list(GtkActionGroup *grp, bool builtin, char &ch);
@@ -199,6 +212,7 @@ public:
     void fill_gui_presets(bool builtin, char &ch);
     void create(plugin_ctl_iface *_plugin, const char *title, const char *effect);
     void close();
+    virtual void on_config_change();
     static gboolean on_idle(void *data);
     static void on_window_destroyed(GtkWidget *window, gpointer data);
     ~plugin_gui_window();
diff --git a/src/calf/gui_config.h b/src/calf/gui_config.h
index a923376..ecbca24 100644
--- a/src/calf/gui_config.h
+++ b/src/calf/gui_config.h
@@ -6,6 +6,8 @@
 #include <gconf/gconf-client.h>
 #include <string>
 
+namespace calf_utils {
+
 struct config_exception: public std::exception
 {
     std::string content;
@@ -15,7 +17,18 @@ struct config_exception: public std::exception
     virtual ~config_exception() throw() { }
 };
 
-struct gui_config_db_iface
+struct config_listener_iface
+{
+    virtual void on_config_change() = 0;
+    virtual ~config_listener_iface() {}
+};
+
+struct config_notifier_iface
+{
+    virtual ~config_notifier_iface() {}
+};
+
+struct config_db_iface
 {
     virtual bool has_dir(const char *key) = 0;
     virtual bool get_bool(const char *key, bool def_value) = 0;
@@ -24,10 +37,11 @@ struct gui_config_db_iface
     virtual void set_bool(const char *key, bool value) = 0;
     virtual void set_int(const char *key, int value) = 0;
     virtual void set_string(const char *key, const std::string &value) = 0;
-    virtual ~gui_config_db_iface() {}
+    virtual config_notifier_iface *add_listener(config_listener_iface *listener) = 0;
+    virtual ~config_db_iface() {}
 };
 
-class gconf_config_db: public gui_config_db_iface
+class gconf_config_db: public config_db_iface
 {
 protected:
     GConfClient *client;
@@ -42,8 +56,8 @@ public:
     virtual void set_bool(const char *key, bool value);
     virtual void set_int(const char *key, int value);
     virtual void set_string(const char *key, const std::string &value);
+    virtual config_notifier_iface *add_listener(config_listener_iface *listener);
     virtual ~gconf_config_db();
-    
 };
 
 struct gui_config
@@ -53,8 +67,10 @@ struct gui_config
     
     gui_config();
     ~gui_config();
-    void load(gui_config_db_iface *db);
-    void save(gui_config_db_iface *db);
+    void load(config_db_iface *db);
+    void save(config_db_iface *db);
+};
+
 };
 
 #endif
diff --git a/src/calf/main_win.h b/src/calf/main_win.h
index d19c0f9..31a185e 100644
--- a/src/calf/main_win.h
+++ b/src/calf/main_win.h
@@ -22,10 +22,11 @@
 #define __CALF_MAIN_WIN_H
 
 #include "gui.h"
+#include "gui_config.h"
 
 namespace calf_plugins {
 
-    class main_window: public main_window_iface, public gui_environment
+    class main_window: public main_window_iface, public gui_environment, public calf_utils::config_listener_iface
     {
     public:
         struct plugin_strip
@@ -33,7 +34,7 @@ namespace calf_plugins {
             main_window *main_win;
             plugin_ctl_iface *plugin;
             plugin_gui_window *gui_win;
-            GtkWidget *name, *button, *midi_in, *audio_in[2], *audio_out[2], *extra;
+            GtkWidget *name, *button, *midi_in, *audio_in[2], *audio_out[2], *extra, *leftBox, *rightBox;
         };
         
         struct add_plugin_params
@@ -58,6 +59,7 @@ namespace calf_plugins {
         int source_id;
         main_window_owner_iface *owner;
         std::string current_filename;
+        calf_utils::config_notifier_iface *notifier;
 
     protected:
         volatile bool save_file_on_next_idle_call;
@@ -67,6 +69,7 @@ namespace calf_plugins {
         std::string make_plugin_list(GtkActionGroup *actions);
         static void add_plugin_action(GtkWidget *src, gpointer data);
         void display_error(const char *error, const char *filename);
+        void on_config_change();
 
     public:
         main_window();
@@ -85,6 +88,7 @@ namespace calf_plugins {
         void save_file();
         void save_file_as();
         void save_file_from_sighandler();
+        void show_rack_ears(bool show);
     private:
         static const GtkActionEntry actions[];
         static void on_open_action(GtkWidget *widget, main_window *main);
diff --git a/src/gui.cpp b/src/gui.cpp
index 4fa32d0..1a7e85b 100644
--- a/src/gui.cpp
+++ b/src/gui.cpp
@@ -18,6 +18,7 @@
  * Boston, MA  02110-1301  USA
  */
  
+#include <calf/gui_config.h>
 #include <calf/gui_controls.h>
 #include <calf/preset.h>
 #include <calf/preset_gui.h>
@@ -40,11 +41,6 @@ plugin_gui::plugin_gui(plugin_gui_window *_window)
     param_count = 0;
     container = NULL;
     effect_name = NULL;
-    const char *ev = getenv("CALF_NO_RACK_EARS");
-    if (ev && atoi(ev))
-        draw_rackmounts = false;
-    else
-        draw_rackmounts = true;
     preset_access = new gui_preset_access(this);
 }
 
@@ -493,8 +489,10 @@ plugin_gui_window::plugin_gui_window(gui_environment_iface *_env, main_window_if
     user_preset_actions = NULL;
     command_actions = NULL;
     environment = _env;
+    notifier = NULL;
     main = _main;
     assert(environment);
+
 }
 
 void plugin_gui_window::on_window_destroyed(GtkWidget *window, gpointer data)
@@ -625,7 +623,7 @@ void plugin_gui_window::create(plugin_ctl_iface *_jh, const char *title, const c
     
     gtk_widget_show_all(GTK_WIDGET(sw));
     
-    gui->show_rack_ears(gui->draw_rackmounts);
+    gui->show_rack_ears(environment->get_config()->rack_ears);
     
     gtk_widget_size_request(GTK_WIDGET(container), &req);
     int wx = max(req.width + 10, req2.width);
@@ -644,10 +642,23 @@ void plugin_gui_window::create(plugin_ctl_iface *_jh, const char *title, const c
     source_id = g_timeout_add_full(G_PRIORITY_LOW, 1000/30, on_idle, this, NULL); // 30 fps should be enough for everybody
     gtk_ui_manager_ensure_update(ui_mgr);
     gui->plugin->send_configures(gui);
+    
+    notifier = environment->get_config_db()->add_listener(this);
+}
+
+void plugin_gui_window::on_config_change()
+{
+    environment->get_config()->load(environment->get_config_db());
+    gui->show_rack_ears(environment->get_config()->rack_ears);
 }
 
 void plugin_gui_window::close()
 {
+    if (notifier)
+    {
+        delete notifier;
+        notifier = NULL;
+    }
     if (source_id)
         g_source_remove(source_id);
     source_id = 0;
@@ -671,3 +682,16 @@ void calf_plugins::activate_command(GtkAction *action, activate_command_params *
 }
 
 
+/***************************** GUI environment ********************************************/
+
+gui_environment::gui_environment()
+{
+    config_db = new calf_utils::gconf_config_db("/apps/calf");
+    gui_config.load(config_db);
+}
+
+gui_environment::~gui_environment()
+{
+    delete config_db;
+}
+
diff --git a/src/gui_config.cpp b/src/gui_config.cpp
index 667c24c..50164f8 100644
--- a/src/gui_config.cpp
+++ b/src/gui_config.cpp
@@ -1,6 +1,7 @@
 #include <calf/gui_config.h>
 
 using namespace std;
+using namespace calf_utils;
 
 gui_config::gui_config()
 {
@@ -13,14 +14,14 @@ gui_config::~gui_config()
 {
 }
 
-void gui_config::load(gui_config_db_iface *db)
+void gui_config::load(config_db_iface *db)
 {
     rows = db->get_int("rack-rows", gui_config().rows);
     cols = db->get_int("rack-cols", gui_config().cols);
     rack_ears = db->get_bool("show-rack-ears", gui_config().rack_ears);
 }
 
-void gui_config::save(gui_config_db_iface *db)
+void gui_config::save(config_db_iface *db)
 {
     db->set_int("rack-rows", rows);
     db->set_int("rack-cols", cols);
@@ -117,6 +118,46 @@ void gconf_config_db::set_string(const char *key, const std::string &value)
         handle_error(err);
 }
 
+class gconf_notifier: public config_notifier_iface
+{
+protected:
+    GConfClient *client;
+    config_listener_iface *listener;
+    guint notify_id;
+public:
+    gconf_notifier(GConfClient *_client, config_listener_iface *_listener, const gchar *namespace_section);
+    static void cb_notify(GConfClient *_client, guint cnxn_id, GConfEntry *entry, gpointer pThis);
+    virtual ~gconf_notifier();
+};
+
+gconf_notifier::gconf_notifier(GConfClient *_client, config_listener_iface *_listener, const gchar *namespace_section)
+{
+    client = _client;
+    listener = _listener;
+    g_object_ref(G_OBJECT(client));
+    
+    GError *error = NULL;
+    notify_id = gconf_client_notify_add(client, namespace_section, cb_notify, this, NULL, &error);
+}
+
+void gconf_notifier::cb_notify(GConfClient *_client, guint cnxn_id, GConfEntry *entry, gpointer pThis)
+{
+    gconf_notifier *self = (gconf_notifier *)pThis;
+    self->listener->on_config_change();
+}
+
+gconf_notifier::~gconf_notifier()
+{
+    gconf_client_notify_remove(client, notify_id);
+    g_object_unref(G_OBJECT(client));
+}
+
+
+config_notifier_iface *gconf_config_db::add_listener(config_listener_iface *listener)
+{
+    return new gconf_notifier(client, listener, prefix.substr(0, prefix.length() - 1).c_str());
+}
+
 gconf_config_db::~gconf_config_db()
 {
     g_object_unref(G_OBJECT(client));
diff --git a/src/main_win.cpp b/src/main_win.cpp
index 8b36520..3e3a354 100644
--- a/src/main_win.cpp
+++ b/src/main_win.cpp
@@ -32,12 +32,8 @@ main_window::main_window()
 {
     toplevel = NULL;
     owner = NULL;
+    notifier = NULL;
     is_closed = true;
-    const char *ev = getenv("CALF_NO_RACK_EARS");
-    if (ev && atoi(ev))
-        draw_rackmounts = false;
-    else
-        draw_rackmounts = true;
 }
 
 static const char *ui_xml = 
@@ -189,6 +185,23 @@ extra_button_pressed(GtkWidget *button, main_window::plugin_strip *strip)
     return TRUE;
 }
 
+void main_window::show_rack_ears(bool show)
+{
+    for (std::map<plugin_ctl_iface *, plugin_strip *>::iterator i = plugins.begin(); i != plugins.end(); i++)
+    {
+        if (show)
+        {
+            gtk_widget_show(i->second->leftBox);
+            gtk_widget_show(i->second->rightBox);
+        }
+        else
+        {
+            gtk_widget_hide(i->second->leftBox);
+            gtk_widget_hide(i->second->rightBox);
+        }
+    }
+}
+
 main_window::plugin_strip *main_window::create_strip(plugin_ctl_iface *plugin)
 {
     plugin_strip *strip = new plugin_strip;
@@ -202,35 +215,41 @@ main_window::plugin_strip *main_window::create_strip(plugin_ctl_iface *plugin)
     g_object_get(G_OBJECT(strips_table), "n-rows", &row, "n-columns", &cols, NULL);
     gtk_table_resize(GTK_TABLE(strips_table), row + 4, cols);
     
-    if(draw_rackmounts) {
-        // images for left side
-        GtkWidget *nwImg     = gtk_image_new_from_file(PKGLIBDIR "/side_d_nw.png");
-        GtkWidget *swImg     = gtk_image_new_from_file(PKGLIBDIR "/side_d_sw.png");
-        GtkWidget *wImg      = gtk_image_new_from_file(PKGLIBDIR "/side_d_w.png");
-        gtk_widget_set_size_request(GTK_WIDGET(wImg), 56, 1);
-        
-        // images for right side
-        GtkWidget *neImg     = gtk_image_new_from_file(PKGLIBDIR "/side_d_ne.png");
-        GtkWidget *seImg     = gtk_image_new_from_file(PKGLIBDIR "/side_d_se.png");
-        GtkWidget *eImg      = gtk_image_new_from_file(PKGLIBDIR "/side_d_e.png");
-        gtk_widget_set_size_request(GTK_WIDGET(eImg), 56, 1);
-        
-        // pack left box
-        GtkWidget *leftBox = gtk_vbox_new(FALSE, 0);
-        gtk_box_pack_start(GTK_BOX(leftBox), GTK_WIDGET(nwImg), FALSE, FALSE, 0);
-        gtk_box_pack_start(GTK_BOX(leftBox), GTK_WIDGET(wImg), TRUE, TRUE, 0);
-        gtk_box_pack_end(GTK_BOX(leftBox), GTK_WIDGET(swImg), FALSE, FALSE, 0);
-        gtk_table_attach(GTK_TABLE(strips_table), leftBox, 0, 1, row, row + 4, (GtkAttachOptions)(0), (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), 0, 0);
-        gtk_widget_show_all(GTK_WIDGET(leftBox));
-        
-         // pack right box
-        GtkWidget *rightBox = gtk_vbox_new(FALSE, 0);
-        gtk_box_pack_start(GTK_BOX(rightBox), GTK_WIDGET(neImg), FALSE, FALSE, 0);
-        gtk_box_pack_start(GTK_BOX(rightBox), GTK_WIDGET(eImg), TRUE, TRUE, 0);
-        gtk_box_pack_end(GTK_BOX(rightBox), GTK_WIDGET(seImg), FALSE, FALSE, 0);
-        gtk_table_attach(GTK_TABLE(strips_table), rightBox, 5, 6, row, row + 4, (GtkAttachOptions)(0), (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), 0, 0);
-        gtk_widget_show_all(GTK_WIDGET(rightBox));
-    }
+    // images for left side
+    GtkWidget *nwImg     = gtk_image_new_from_file(PKGLIBDIR "/side_d_nw.png");
+    GtkWidget *swImg     = gtk_image_new_from_file(PKGLIBDIR "/side_d_sw.png");
+    GtkWidget *wImg      = gtk_image_new_from_file(PKGLIBDIR "/side_d_w.png");
+    gtk_widget_set_size_request(GTK_WIDGET(wImg), 56, 1);
+    
+    // images for right side
+    GtkWidget *neImg     = gtk_image_new_from_file(PKGLIBDIR "/side_d_ne.png");
+    GtkWidget *seImg     = gtk_image_new_from_file(PKGLIBDIR "/side_d_se.png");
+    GtkWidget *eImg      = gtk_image_new_from_file(PKGLIBDIR "/side_d_e.png");
+    gtk_widget_set_size_request(GTK_WIDGET(eImg), 56, 1);
+    
+    // pack left box
+    GtkWidget *leftBox = gtk_vbox_new(FALSE, 0);
+    gtk_box_pack_start(GTK_BOX(leftBox), GTK_WIDGET(nwImg), FALSE, FALSE, 0);
+    gtk_box_pack_start(GTK_BOX(leftBox), GTK_WIDGET(wImg), TRUE, TRUE, 0);
+    gtk_box_pack_end(GTK_BOX(leftBox), GTK_WIDGET(swImg), FALSE, FALSE, 0);
+    gtk_widget_show_all(GTK_WIDGET(leftBox));
+    if (!get_config()->rack_ears)
+        gtk_widget_hide(GTK_WIDGET(leftBox));
+    gtk_table_attach(GTK_TABLE(strips_table), leftBox, 0, 1, row, row + 4, (GtkAttachOptions)(0), (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), 0, 0);
+    
+     // pack right box
+    GtkWidget *rightBox = gtk_vbox_new(FALSE, 0);
+    gtk_box_pack_start(GTK_BOX(rightBox), GTK_WIDGET(neImg), FALSE, FALSE, 0);
+    gtk_box_pack_start(GTK_BOX(rightBox), GTK_WIDGET(eImg), TRUE, TRUE, 0);
+    gtk_box_pack_end(GTK_BOX(rightBox), GTK_WIDGET(seImg), FALSE, FALSE, 0);
+    gtk_widget_show_all(GTK_WIDGET(rightBox));
+    if (!get_config()->rack_ears)
+        gtk_widget_hide(GTK_WIDGET(rightBox));
+    gtk_table_attach(GTK_TABLE(strips_table), rightBox, 5, 6, row, row + 4, (GtkAttachOptions)(0), (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), 0, 0);
+    
+    strip->leftBox = leftBox;
+    strip->rightBox = rightBox;
+    
     
     // top light
     GtkWidget *topImg     = gtk_image_new_from_file(PKGLIBDIR "/light_top.png");
@@ -473,6 +492,15 @@ void main_window::create()
     gtk_window_add_accel_group(toplevel, gtk_ui_manager_get_accel_group(ui_mgr));
     gtk_widget_show_all(GTK_WIDGET(toplevel));
     source_id = g_timeout_add_full(G_PRIORITY_LOW, 1000/30, on_idle, this, NULL); // 30 fps should be enough for everybody
+    
+    notifier = get_config_db()->add_listener(this);
+    on_config_change();
+}
+
+void main_window::on_config_change()
+{
+    get_config()->load(get_config_db());
+    show_rack_ears(get_config()->rack_ears);    
 }
 
 void main_window::refresh_plugin(plugin_ctl_iface *plugin)
@@ -494,6 +522,11 @@ void main_window::close_guis()
 
 void main_window::on_closed()
 {
+    if (notifier)
+    {
+        delete notifier;
+        notifier = NULL;
+    }
     if (source_id)
         g_source_remove(source_id);
     is_closed = true;

-- 
calf audio plugins packaging



More information about the pkg-multimedia-commits mailing list