[ekiga/ds-gsettings3] GSettings: Converted keys to enum.
- From: Damien Sandras <dsandras src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ekiga/ds-gsettings3] GSettings: Converted keys to enum.
- Date: Sat, 14 Dec 2013 17:15:08 +0000 (UTC)
commit 6fc6d34dc6c9bc15954130b12441520656da86bc
Author: Damien Sandras <dsandras beip be>
Date: Sat Dec 14 17:42:29 2013 +0100
GSettings: Converted keys to enum.
A few changes:
- gmmenuaddon has been enhanced to support enums for radio entries
- generic radio widgets <-> string/int gsettings mappings have been
added
- the main and call windows have been ported to the new scheme
I reorganised the file structure during this work.
lib/Makefile.am | 12 ++
lib/engine/gui/gtk-frontend/call-window.cpp | 2 +
lib/engine/gui/gtk-frontend/main_window.cpp | 276 ++++++++-------------------
lib/gui/gmmenuaddon.c | 99 ++--------
lib/gui/gmmenuaddon.h | 44 ++---
lib/{ => settings}/ekiga-settings.h | 1 +
lib/settings/settings-mappings.c | 107 +++++++++++
lib/settings/settings-mappings.h | 91 +++++++++
plugins/ldap/Makefile.am | 1 +
src/Makefile.am | 1 +
10 files changed, 325 insertions(+), 309 deletions(-)
---
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 7db1f1f..a7b2a9d 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -18,6 +18,7 @@ AM_CPPFLAGS = \
-I$(top_srcdir)/lib \
-I$(top_srcdir)/lib/gui \
-I$(top_srcdir)/lib/platform \
+ -I$(top_srcdir)/lib/settings \
-I$(top_srcdir)/lib/engine \
-I$(top_srcdir)/lib/engine/account \
-I$(top_srcdir)/lib/engine/addressbook \
@@ -77,6 +78,17 @@ if WIN32
libekiga_la_SOURCES += platform/winpaths.h
endif
+
+##
+# Sources out of the settings directory
+##
+
+libekiga_la_SOURCES += \
+ settings/settings-mappings.h \
+ settings/settings-mappings.c \
+ settings/ekiga-settings.h
+
+
##
# Sources out of the pixops directory
##
diff --git a/lib/engine/gui/gtk-frontend/call-window.cpp b/lib/engine/gui/gtk-frontend/call-window.cpp
index d914d0d..e09182b 100644
--- a/lib/engine/gui/gtk-frontend/call-window.cpp
+++ b/lib/engine/gui/gtk-frontend/call-window.cpp
@@ -2017,6 +2017,7 @@ ekiga_call_window_init_menu (EkigaCallWindow *cw)
GTK_MENU_NEW(_("_View")),
+ /*
GTK_MENU_RADIO_ENTRY("local_video", _("_Local Video"),
_("Local video image"),
NULL, '1',
@@ -2035,6 +2036,7 @@ ekiga_call_window_init_menu (EkigaCallWindow *cw)
NULL,
G_CALLBACK (display_changed_cb), cw,
false, false),
+ */
GTK_MENU_SEPARATOR,
GTK_MENU_ENTRY("zoom_in", NULL, _("Zoom in"),
diff --git a/lib/engine/gui/gtk-frontend/main_window.cpp b/lib/engine/gui/gtk-frontend/main_window.cpp
index be96825..db87eba 100644
--- a/lib/engine/gui/gtk-frontend/main_window.cpp
+++ b/lib/engine/gui/gtk-frontend/main_window.cpp
@@ -37,7 +37,7 @@
#include "config.h"
-#include "ekiga-settings.h"
+#include "settings-mappings.h"
#include "main_window.h"
@@ -201,26 +201,27 @@ static const std::string ekiga_main_window_get_call_url (EkigaMainWindow *mw);
static void on_chat_unread_alert (GtkWidget*,
gpointer);
+
/* DESCRIPTION : This callback is called when the control panel
- * section key changes (which can be when the radio
- * menu is changed!)
- * BEHAVIOR : Sets the right page, and also sets
- * the good value for the radio menu.
+ * section changes.
+ * BEHAVIOR : Disable the Contact menu item when the dialpad is
+ * displayed.
* PRE : /
*/
-static void panel_section_setting_changed (GSettings *settings,
- gchar *key,
- gpointer data);
+static void panel_section_changed (GtkNotebook *notebook,
+ GtkWidget *page,
+ guint page_num,
+ gpointer user_data);
-/* DESCRIPTION : This callback is called when the preview is changed.
+/* DESCRIPTION : This callback is called when the preview button is toggled.
* BEHAVIOR : Show / hide the call window.
* PRE : /
*/
-static void video_preview_changed (GSettings *settings,
- gchar *key,
+static void video_preview_changed (GtkToggleToolButton *button,
gpointer data);
+
/** Pull a trigger from a Ekiga::Service
*
* @param data is a pointer to the Ekiga::Trigger
@@ -237,28 +238,6 @@ static void show_widget_cb (GtkWidget * /*widget*/,
gpointer data);
-/* DESCRIPTION : This callback is called when the user clicks a button
- * in the actions toolbar to change a page in the notebook.
- * BEHAVIOR : Update the config key accordingly.
- * PRE : A valid pointer to the main window GmObject.
- */
-static void roster_panel_section_action_clicked_cb (GtkWidget * /*widget*/,
- gpointer data);
-static void dialpad_panel_section_action_clicked_cb (GtkWidget * /*widget*/,
- gpointer data);
-static void history_panel_section_action_clicked_cb (GtkWidget * /*widget*/,
- gpointer data);
-
-
-/* DESCRIPTION : This callback is called when the user toggles the
- * preview button in the actions toolbar.
- * BEHAVIOR : Update the config key accordingly.
- * PRE : A valid pointer to the main window GmObject.
- */
-static void video_preview_action_toggled_cb (GtkToggleToolButton *b,
- gpointer data);
-
-
/* DESCRIPTION : This callback is called when the user
* presses a key.
* BEHAVIOR : Sends a DTMF if we are in a call.
@@ -691,6 +670,7 @@ on_history_selection_changed (G_GNUC_UNUSED GtkWidget* view,
EkigaMainWindow *mw = EKIGA_MAIN_WINDOW (self);
gint section;
GtkWidget* menu = gtk_menu_get_widget (mw->priv->main_menu, "contact");
+ std::cout << menu << std::endl << std::flush;
section = gtk_notebook_get_current_page (GTK_NOTEBOOK (mw->priv->main_notebook));
@@ -770,60 +750,18 @@ on_chat_unread_alert (G_GNUC_UNUSED GtkWidget* widget,
static void
-panel_section_setting_changed (GSettings *settings,
- gchar *key,
- gpointer data)
+panel_section_changed (G_GNUC_UNUSED GtkNotebook *notebook,
+ G_GNUC_UNUSED GtkWidget *page,
+ guint section,
+ gpointer data)
{
- EkigaMainWindow* mw = EKIGA_MAIN_WINDOW (data);
+ EkigaMainWindow *mw = EKIGA_MAIN_WINDOW (data);
GtkWidget* menu = NULL;
- gint section = 0;
g_return_if_fail (EKIGA_IS_MAIN_WINDOW (data));
- section = g_settings_get_int (settings, key);
-
- /* Update notebook section */
- gtk_notebook_set_current_page (GTK_NOTEBOOK (mw->priv->main_notebook), section);
-
- /* Update menu section */
- g_signal_handlers_block_by_func (mw->priv->main_menu,
- (gpointer) radio_menu_changed_cb,
- (gpointer) "panel-section");
- menu = gtk_menu_get_widget (mw->priv->main_menu, "dialpad");
- gtk_radio_menu_select_with_widget (menu, section);
- g_signal_handlers_unblock_by_func (mw->priv->main_menu,
- (gpointer) radio_menu_changed_cb,
- (gpointer) "panel-section");
-
- /* Update toggle button toolbar */
- // FIXME: I don't like 3 identical functions. But callbacks allow only
- // one argument and GSettings things require two. g_object_set_data
- // could be the solution.
- g_signal_handlers_block_by_func (mw->priv->toggle_buttons[CONTACTS],
- (gpointer) roster_panel_section_action_clicked_cb,
- mw);
- g_signal_handlers_block_by_func (mw->priv->toggle_buttons[DIALPAD],
- (gpointer) dialpad_panel_section_action_clicked_cb,
- mw);
- g_signal_handlers_block_by_func (mw->priv->toggle_buttons[CALL],
- (gpointer) history_panel_section_action_clicked_cb,
- mw);
- gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (mw->priv->toggle_buttons[section]), true);
- g_signal_handlers_unblock_by_func (mw->priv->toggle_buttons[CONTACTS],
- (gpointer) roster_panel_section_action_clicked_cb,
- mw);
- g_signal_handlers_unblock_by_func (mw->priv->toggle_buttons[DIALPAD],
- (gpointer) dialpad_panel_section_action_clicked_cb,
- mw);
- g_signal_handlers_unblock_by_func (mw->priv->toggle_buttons[CALL],
- (gpointer) history_panel_section_action_clicked_cb,
- mw);
-
- if (section == mw->priv->roster_view_page_number)
- on_roster_selection_changed (mw->priv->roster_view, data);
- else if (section == mw->priv->call_history_page_number)
- on_roster_selection_changed (mw->priv->call_history_view, data);
- else { // we're not on a page where that menu makes sense
+ if (section != (unsigned) mw->priv->roster_view_page_number
+ && section != (unsigned) mw->priv->call_history_page_number) {
menu = gtk_menu_get_widget (mw->priv->main_menu, "contact");
gtk_widget_set_sensitive (menu, FALSE);
@@ -833,18 +771,16 @@ panel_section_setting_changed (GSettings *settings,
static void
-video_preview_changed (GSettings *settings,
- gchar *key,
+video_preview_changed (GtkToggleToolButton *button,
gpointer data)
{
g_return_if_fail (EKIGA_IS_MAIN_WINDOW (data));
EkigaMainWindow* mw = EKIGA_MAIN_WINDOW (data);
- GtkWidget *menu_item = NULL;
if (mw->priv->calling_state == Standby) {
- bool toggled = g_settings_get_boolean (settings, key);
+ bool toggled = gtk_toggle_tool_button_get_active (button);
boost::shared_ptr<GtkFrontend> gtk_frontend = mw->priv->gtk_frontend.lock ();
if (gtk_frontend) {
@@ -854,14 +790,6 @@ video_preview_changed (GSettings *settings,
else
gtk_widget_show (call_window);
}
- g_signal_handlers_block_by_func (mw->priv->preview_button,
- (gpointer) video_preview_action_toggled_cb, mw);
- menu_item = gtk_menu_get_widget (mw->priv->main_menu, "preview");
- gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item), toggled);
- gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (mw->priv->preview_button),
- toggled);
- g_signal_handlers_unblock_by_func (mw->priv->preview_button,
- (gpointer) video_preview_action_toggled_cb, mw);
}
}
@@ -889,50 +817,6 @@ show_widget_cb (GtkWidget * /*widget*/,
static void
-roster_panel_section_action_clicked_cb (GtkWidget * /*widget*/,
- gpointer data)
-{
- EkigaMainWindow *mw = EKIGA_MAIN_WINDOW (data);
-
- if (mw->priv->user_interface_settings->get_int ("panel-section") != CONTACTS)
- mw->priv->user_interface_settings->set_int ("panel-section", CONTACTS);
-}
-
-
-static void
-dialpad_panel_section_action_clicked_cb (GtkWidget * /*widget*/,
- gpointer data)
-{
- EkigaMainWindow *mw = EKIGA_MAIN_WINDOW (data);
-
- if (mw->priv->user_interface_settings->get_int ("panel-section") != DIALPAD)
- mw->priv->user_interface_settings->set_int ("panel-section", DIALPAD);
-}
-
-
-static void
-history_panel_section_action_clicked_cb (GtkWidget * /*widget*/,
- gpointer data)
-{
- EkigaMainWindow *mw = EKIGA_MAIN_WINDOW (data);
-
- if (mw->priv->user_interface_settings->get_int ("panel-section") != CALL)
- mw->priv->user_interface_settings->set_int ("panel-section", CALL);
-}
-
-
-static void
-video_preview_action_toggled_cb (GtkToggleToolButton *b,
- gpointer data)
-{
- if (EKIGA_MAIN_WINDOW (data)->priv->video_devices_settings->get_bool ("enable-preview")
- != gtk_toggle_tool_button_get_active (b))
- EKIGA_MAIN_WINDOW (data)->priv->video_devices_settings->set_bool ("enable-preview",
- gtk_toggle_tool_button_get_active (b));
-}
-
-
-static void
dialpad_button_clicked_cb (EkigaDialpad * /* dialpad */,
const gchar *button_text,
EkigaMainWindow *mw)
@@ -1107,7 +991,6 @@ ekiga_main_window_init_uri_toolbar (EkigaMainWindow *mw)
static void
ekiga_main_window_init_actions_toolbar (EkigaMainWindow *mw)
{
- int cps = 0;
GtkWidget *image = NULL;
GtkToolItem *item = NULL;
@@ -1124,12 +1007,15 @@ ekiga_main_window_init_actions_toolbar (EkigaMainWindow *mw)
gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (mw->priv->preview_button), image);
gtk_tool_item_set_expand (GTK_TOOL_ITEM (mw->priv->preview_button), false);
gtk_toolbar_insert (GTK_TOOLBAR (mw->priv->actions_toolbar), GTK_TOOL_ITEM (mw->priv->preview_button), -1);
- gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (mw->priv->preview_button),
- mw->priv->video_devices_settings->get_bool ("enable-preview"));
gtk_widget_set_tooltip_text (GTK_WIDGET (mw->priv->preview_button),
_("Display images from your camera device"));
+ g_settings_bind (mw->priv->video_devices_settings->get_g_settings (),
+ "enable-preview",
+ mw->priv->preview_button,
+ "active",
+ G_SETTINGS_BIND_DEFAULT);
g_signal_connect (mw->priv->preview_button, "toggled",
- G_CALLBACK (video_preview_action_toggled_cb), (gpointer) mw);
+ G_CALLBACK (video_preview_changed), mw);
/* Separator */
item = gtk_separator_tool_item_new ();
@@ -1137,8 +1023,6 @@ ekiga_main_window_init_actions_toolbar (EkigaMainWindow *mw)
GTK_TOOL_ITEM (item), -1);
/* The roster button */
- cps = (PanelSection) mw->priv->user_interface_settings->get_int ("panel-section");
-
image = gtk_image_new_from_icon_name ("avatar-default", GTK_ICON_SIZE_MENU);
mw->priv->toggle_buttons[CONTACTS] = gtk_radio_tool_button_new (NULL);
gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (mw->priv->toggle_buttons[CONTACTS]), image);
@@ -1146,6 +1030,13 @@ ekiga_main_window_init_actions_toolbar (EkigaMainWindow *mw)
gtk_toolbar_insert (GTK_TOOLBAR (mw->priv->actions_toolbar), mw->priv->toggle_buttons[CONTACTS], -1);
gtk_widget_set_tooltip_text (GTK_WIDGET (mw->priv->toggle_buttons[CONTACTS]),
_("View the contacts list"));
+ g_settings_bind_with_mapping (mw->priv->user_interface_settings->get_g_settings (),
+ "panel-section", mw->priv->toggle_buttons[CONTACTS],
+ "active",
+ G_SETTINGS_BIND_DEFAULT,
+ string_gsettings_get_from_active, string_gsettings_set_from_active,
+ (gpointer) "contacts",
+ NULL);
/* The dialpad button */
image = gtk_image_new_from_icon_name ("input-dialpad", GTK_ICON_SIZE_MENU);
@@ -1156,6 +1047,13 @@ ekiga_main_window_init_actions_toolbar (EkigaMainWindow *mw)
gtk_toolbar_insert (GTK_TOOLBAR (mw->priv->actions_toolbar), mw->priv->toggle_buttons[DIALPAD], -1);
gtk_widget_set_tooltip_text (GTK_WIDGET (mw->priv->toggle_buttons[DIALPAD]),
_("View the dialpad"));
+ g_settings_bind_with_mapping (mw->priv->user_interface_settings->get_g_settings (),
+ "panel-section", mw->priv->toggle_buttons[DIALPAD],
+ "active",
+ G_SETTINGS_BIND_DEFAULT,
+ string_gsettings_get_from_active, string_gsettings_set_from_active,
+ (gpointer) "dialpad",
+ NULL);
/* The history button */
image = gtk_image_new_from_icon_name ("document-open-recent", GTK_ICON_SIZE_MENU);
@@ -1166,15 +1064,13 @@ ekiga_main_window_init_actions_toolbar (EkigaMainWindow *mw)
gtk_toolbar_insert (GTK_TOOLBAR (mw->priv->actions_toolbar), mw->priv->toggle_buttons[CALL], -1);
gtk_widget_set_tooltip_text (GTK_WIDGET (mw->priv->toggle_buttons[CALL]),
_("View the call history"));
-
- gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (mw->priv->toggle_buttons[cps]), true);
-
- g_signal_connect (mw->priv->toggle_buttons[CONTACTS], "clicked",
- G_CALLBACK (roster_panel_section_action_clicked_cb), mw);
- g_signal_connect (mw->priv->toggle_buttons[DIALPAD], "clicked",
- G_CALLBACK (dialpad_panel_section_action_clicked_cb), mw);
- g_signal_connect (mw->priv->toggle_buttons[CALL], "clicked",
- G_CALLBACK (history_panel_section_action_clicked_cb), mw);
+ g_settings_bind_with_mapping (mw->priv->user_interface_settings->get_g_settings (),
+ "panel-section", mw->priv->toggle_buttons[CALL],
+ "active",
+ G_SETTINGS_BIND_DEFAULT,
+ string_gsettings_get_from_active, string_gsettings_set_from_active,
+ (gpointer) "call-history",
+ NULL);
}
static void
@@ -1185,10 +1081,6 @@ ekiga_main_window_init_menu (EkigaMainWindow *mw)
GtkWidget *prefs_window = NULL;
GtkWidget *assistant_window = NULL;
- PanelSection cps = DIALPAD;
- bool show_offline_contacts = false;
- bool enable_preview = false;
-
mw->priv->main_menu = gtk_menu_bar_new ();
g_return_if_fail (mw != NULL);
@@ -1202,11 +1094,6 @@ ekiga_main_window_init_menu (EkigaMainWindow *mw)
prefs_window = GTK_WIDGET (gtk_frontend->get_preferences_window ());
assistant_window = GTK_WIDGET (gtk_frontend->get_assistant_window ());
- /* Default values */
- cps = (PanelSection) mw->priv->user_interface_settings->get_int ("panel-section");
- show_offline_contacts = mw->priv->contacts_settings->get_bool ("show-offline-contacts");
- enable_preview = mw->priv->video_devices_settings->get_bool ("enable-preview");
-
static MenuEntry gnomemeeting_menu [] =
{
GTK_MENU_NEW (_("_Chat")),
@@ -1273,40 +1160,31 @@ ekiga_main_window_init_menu (EkigaMainWindow *mw)
GTK_MENU_TOGGLE_ENTRY("preview", _("_Video Preview"),
_("Display images from your camera device"),
NULL, 0,
- mw->priv->video_devices_settings->get_g_settings (),
- G_CALLBACK (toggle_menu_changed_cb),
- (gpointer) "enable-preview", enable_preview, TRUE),
+ mw->priv->video_devices_settings->get_g_settings (), "enable-preview",
+ TRUE),
GTK_MENU_SEPARATOR,
GTK_MENU_RADIO_ENTRY("contacts", _("Con_tacts"), _("View the contacts list"),
NULL, 0,
- mw->priv->user_interface_settings->get_g_settings (),
- G_CALLBACK (radio_menu_changed_cb),
- (gpointer) "panel-section",
- (cps == CONTACTS), TRUE),
+ mw->priv->user_interface_settings->get_g_settings (), "panel-section",
+ TRUE),
GTK_MENU_RADIO_ENTRY("dialpad", _("_Dialpad"), _("View the dialpad"),
NULL, 0,
- mw->priv->user_interface_settings->get_g_settings (),
- G_CALLBACK (radio_menu_changed_cb),
- (gpointer) "panel-section",
- (cps == DIALPAD), TRUE),
- GTK_MENU_RADIO_ENTRY("callhistory", _("_Call History"), _("View the call history"),
+ mw->priv->user_interface_settings->get_g_settings (), "panel-section",
+ TRUE),
+ GTK_MENU_RADIO_ENTRY("call-history", _("_Call History"), _("View the call history"),
NULL, 0,
- mw->priv->user_interface_settings->get_g_settings (),
- G_CALLBACK (radio_menu_changed_cb),
- (gpointer) "panel-section",
- (cps == CALL), TRUE),
+ mw->priv->user_interface_settings->get_g_settings (), "panel-section",
+ TRUE),
GTK_MENU_SEPARATOR,
GTK_MENU_TOGGLE_ENTRY ("showofflinecontacts", _("Show Offline _Contacts"),
_("Show offline contacts"),
NULL, 0,
- mw->priv->contacts_settings->get_g_settings (),
- G_CALLBACK (toggle_menu_changed_cb),
- (gpointer) "show-offline-contacts",
- show_offline_contacts, TRUE),
+ mw->priv->contacts_settings->get_g_settings (), "show-offline-contacts",
+ TRUE),
GTK_MENU_NEW(_("_Help")),
@@ -1422,6 +1300,8 @@ static void
ekiga_main_window_init_gui (EkigaMainWindow *mw)
{
GtkWidget *window_vbox;
+ // FIXME ??? ekiga-settings.h
+ static const gchar *main_views [] = { "contacts", "dialpad", "call-history", NULL };
gtk_window_set_title (GTK_WINDOW (mw), _("Ekiga"));
@@ -1472,17 +1352,25 @@ ekiga_main_window_init_gui (EkigaMainWindow *mw)
gtk_widget_realize (GTK_WIDGET (mw));
gtk_widget_show_all (window_vbox);
- /* Show the current panel section */
- PanelSection section =
- (PanelSection) mw->priv->user_interface_settings->get_int ("panel-section");
- gtk_notebook_set_current_page (GTK_NOTEBOOK (mw->priv->main_notebook), section);
+ /* Update the widget when the user changes the configuration */
+ g_settings_bind_with_mapping (mw->priv->user_interface_settings->get_g_settings (),
+ "panel-section", mw->priv->main_notebook,
+ "page",
+ G_SETTINGS_BIND_DEFAULT,
+ string_gsettings_get_from_int,
+ string_gsettings_set_from_int,
+ (gpointer) main_views,
+ NULL);
+
+ /* Update the menu when the page is changed */
+ g_signal_connect (mw->priv->main_notebook, "switch-page",
+ G_CALLBACK (panel_section_changed), mw);
}
+
static void
ekiga_main_window_init (EkigaMainWindow *mw)
{
- gchar *signal_name = NULL;
-
mw->priv = new EkigaMainWindowPrivate;
/* Accelerators */
@@ -1505,19 +1393,9 @@ ekiga_main_window_init (EkigaMainWindow *mw)
for (int i = 0 ; i < NUM_SECTIONS ; i++)
mw->priv->toggle_buttons[i] = NULL;
-
- /* Update the widget when the user changes the configuration */
- signal_name = g_strdup_printf ("changed::%s", "panel-section");
- g_signal_connect (mw->priv->user_interface_settings->get_g_settings (),
- signal_name,
- G_CALLBACK (panel_section_setting_changed), mw);
- g_free (signal_name);
-
- g_signal_connect (mw->priv->video_devices_settings->get_g_settings (),
- "changed::enable-preview",
- G_CALLBACK (video_preview_changed), mw);
}
+
static GObject *
ekiga_main_window_constructor (GType the_type,
guint n_construct_properties,
diff --git a/lib/gui/gmmenuaddon.c b/lib/gui/gmmenuaddon.c
index e212a6b..554877d 100644
--- a/lib/gui/gmmenuaddon.c
+++ b/lib/gui/gmmenuaddon.c
@@ -41,6 +41,8 @@
#include <libintl.h>
#include <gdk/gdkkeysyms.h>
+#include "settings-mappings.h"
+
/* Notice, this implementation sets the menu item name as data of the menu
* widget, the statusbar and also the given structure.
@@ -130,60 +132,6 @@ menu_item_selected (GtkWidget *w,
/* The public functions */
-// FIXME: I'm not particularly happy with those public callbacks
-// because they require a GSettings parameter to be passed
-// to the GtkMenu structure...
-void
-radio_menu_changed_cb (GtkWidget *widget,
- gpointer data)
-{
- GSList *group = NULL;
-
- GSettings *settings = NULL;
- int group_last_pos = 0;
- int active = 0;
-
- g_return_if_fail (data != NULL);
-
- settings = g_object_get_data (G_OBJECT (widget), "settings");
- g_return_if_fail (settings != NULL);
-
- group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (widget));
- group_last_pos = g_slist_length (group) - 1; /* If length 1, last pos is 0 */
-
- /* Only do something when a new CHECK_MENU_ITEM becomes active,
- not when it becomes inactive */
- if (gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (widget))) {
-
- while (group) {
-
- if (group->data == widget)
- break;
-
- active++;
- group = g_slist_next (group);
- }
-
- g_settings_set_int (settings, (gchar *) data, group_last_pos - active);
- }
-}
-
-
-void
-toggle_menu_changed_cb (GtkWidget *widget,
- gpointer data)
-{
- GSettings *settings = NULL;
- g_return_if_fail (data != NULL);
-
- settings = g_object_get_data (G_OBJECT (widget), "settings");
- g_return_if_fail (settings != NULL);
-
- g_settings_set_boolean (settings, (gchar *) data,
- gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (widget)));
-}
-
-
void
gtk_build_menu (GtkWidget *menubar,
MenuEntry *menu,
@@ -195,8 +143,6 @@ gtk_build_menu (GtkWidget *menubar,
GtkWidget *image = NULL;
GtkStockItem item;
- GSList *group = NULL;
-
int i = 0;
gchar *menu_name = NULL;
@@ -204,11 +150,6 @@ gtk_build_menu (GtkWidget *menubar,
while (menu [i].type != MENU_END) {
- GSList *new_group = NULL;
-
- if (menu [i].type != MENU_RADIO_ENTRY)
- group = NULL;
-
if (menu [i].stock_id && !menu [i].stock_is_theme && !menu [i].name) {
if (gtk_stock_lookup (menu [i].stock_id, &item))
@@ -228,25 +169,23 @@ gtk_build_menu (GtkWidget *menubar,
else if (menu [i].type == MENU_TOGGLE_ENTRY) {
menu [i].widget = gtk_check_menu_item_new_with_mnemonic (menu_name);
- if (menu [i].settings)
- g_object_set_data (G_OBJECT (menu [i].widget), "settings", menu [i].settings);
- gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu [i].widget),
- menu [i].enabled);
+ if (menu [i].settings && menu [i].key)
+ g_settings_bind (menu [i].settings, menu [i].key,
+ menu [i].widget, "active", G_SETTINGS_BIND_DEFAULT);
}
else if (menu [i].type == MENU_RADIO_ENTRY) {
- if (group == NULL)
- group = new_group;
-
- menu [i].widget = gtk_radio_menu_item_new_with_mnemonic (group,
- menu_name);
- if (menu [i].settings)
- g_object_set_data (G_OBJECT (menu [i].widget), "settings", menu [i].settings);
-
- gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu [i].widget),
- menu [i].enabled);
-
- group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menu[i].widget));
+ menu [i].widget = gtk_check_menu_item_new_with_mnemonic (menu_name);
+ g_object_set (menu [i].widget, "draw-as-radio", TRUE, NULL);
+
+ if (menu [i].settings && menu [i].key)
+ g_settings_bind_with_mapping (menu [i].settings, menu [i].key,
+ menu [i].widget, "active",
+ G_SETTINGS_BIND_DEFAULT,
+ string_gsettings_get_from_active,
+ string_gsettings_set_from_active,
+ (gpointer) menu [i].id,
+ NULL);
}
if (menu [i].stock_id && show_icons) {
@@ -342,6 +281,9 @@ gtk_build_menu (GtkWidget *menubar,
gtk_menu_shell_append (GTK_MENU_SHELL (menu_widget),
menu [i].widget);
+ if (!menu [i].sensitive)
+ gtk_widget_set_sensitive (GTK_WIDGET (menu [i].widget), FALSE);
+
if (menu [i].id) {
if (menu [i].type != MENU_SUBMENU_NEW)
@@ -352,9 +294,6 @@ gtk_build_menu (GtkWidget *menubar,
menu_widget);
}
- if (!menu [i].sensitive)
- gtk_widget_set_sensitive (GTK_WIDGET (menu [i].widget), FALSE);
-
gtk_widget_show (menu [i].widget);
i++;
diff --git a/lib/gui/gmmenuaddon.h b/lib/gui/gmmenuaddon.h
index 2cb3009..7be53bf 100644
--- a/lib/gui/gmmenuaddon.h
+++ b/lib/gui/gmmenuaddon.h
@@ -68,58 +68,42 @@ typedef struct _MenuEntry {
guint accel;
MenuEntryType type;
GSettings *settings;
+ const char *key;
GCallback func;
GClosureNotify clofunc;
gpointer data;
GtkWidget *widget;
- gboolean enabled;
- gboolean sensitive;
+ gboolean enabled; // FIXME
+ gboolean sensitive; // FIXME
} MenuEntry;
#define GTK_MENU_SEPARATOR \
-{NULL, NULL, NULL, NULL, FALSE, 0, MENU_SEP, NULL, NULL, NULL, NULL, NULL, TRUE, TRUE}
+{NULL, NULL, NULL, NULL, FALSE, 0, MENU_SEP, NULL, NULL, NULL, NULL, NULL, NULL, TRUE, TRUE}
#define GTK_MENU_ENTRY(a, b, c, d, e, f, g, h) \
-{a, b, c, d, FALSE, e, MENU_ENTRY, NULL, f, NULL, g, NULL, TRUE, h}
+{a, b, c, d, FALSE, e, MENU_ENTRY, NULL, NULL, f, NULL, g, NULL, TRUE, h}
#define GTK_MENU_THEME_ENTRY(a, b, c, d, e, f, g, h) \
-{a, b, c, d, TRUE, e, MENU_ENTRY, NULL, f, NULL, g, NULL, TRUE, h}
+{a, b, c, d, TRUE, e, MENU_ENTRY, NULL, NULL, f, NULL, g, NULL, TRUE, h}
#define GTK_MENU_ENTRY_WITH_CLOSURE(a, b, c, d, e, f, g, h, i) \
-{a, b, c, d, FALSE, e, MENU_ENTRY, NULL, f, g, h, NULL, TRUE, i}
+{a, b, c, d, FALSE, e, MENU_ENTRY, NULL, NULL, f, g, h, NULL, TRUE, i}
-#define GTK_MENU_RADIO_ENTRY(a, b, c, d, e, f, g, h, i, j) \
-{a, b, c, d, FALSE, e, MENU_RADIO_ENTRY, f, g, NULL, h, NULL, i, j}
+#define GTK_MENU_RADIO_ENTRY(a, b, c, d, e, f, g, h) \
+{a, b, c, d, FALSE, e, MENU_RADIO_ENTRY, f, g, NULL, NULL, NULL, NULL, TRUE, h}
-#define GTK_MENU_TOGGLE_ENTRY(a, b, c, d, e, f, g, h, i, j) \
-{a, b, c, d, FALSE, e, MENU_TOGGLE_ENTRY, f, g, NULL, h, NULL, i, j}
+#define GTK_MENU_TOGGLE_ENTRY(a, b, c, d, e, f, g, h) \
+{a, b, c, d, FALSE, e, MENU_TOGGLE_ENTRY, f, g, NULL, NULL, NULL, NULL, TRUE, h}
#define GTK_MENU_NEW(a) \
-{NULL, a, NULL, NULL, FALSE, 0, MENU_NEW, NULL, NULL, NULL, NULL, NULL, TRUE, TRUE}
+{NULL, a, NULL, NULL, FALSE, 0, MENU_NEW, NULL, NULL, NULL, NULL, NULL, NULL, TRUE, TRUE}
#define GTK_SUBMENU_NEW(a, b) \
-{a, b, NULL, NULL, FALSE, 0, MENU_SUBMENU_NEW, NULL, NULL, NULL, NULL, NULL, TRUE, TRUE}
+{a, b, NULL, NULL, FALSE, 0, MENU_SUBMENU_NEW, NULL, NULL, NULL, NULL, NULL, NULL, TRUE, TRUE}
#define GTK_MENU_END \
-{NULL, NULL, NULL, NULL, FALSE, 0, MENU_END, NULL, NULL, NULL, NULL, NULL, TRUE, TRUE}
-
-
-/* DESCRIPTION : This callback is called when the user
- * selects a different option in a radio menu.
- * BEHAVIOR : Sets the config key.
- * PRE : data is the config key.
- */
-void radio_menu_changed_cb (GtkWidget *,
- gpointer);
-
-
-/* DESCRIPTION : This callback is called when the user toggles an
- * BEHAVIOR : Updates the config key given as parameter.
- * PRE : data is the key.
- */
-void toggle_menu_changed_cb (GtkWidget *,
- gpointer);
+{NULL, NULL, NULL, NULL, FALSE, 0, MENU_END, NULL, NULL, NULL, NULL, NULL, NULL, TRUE, TRUE}
/* DESCRIPTION : /
diff --git a/lib/ekiga-settings.h b/lib/settings/ekiga-settings.h
similarity index 99%
rename from lib/ekiga-settings.h
rename to lib/settings/ekiga-settings.h
index d582226..611e437 100644
--- a/lib/ekiga-settings.h
+++ b/lib/settings/ekiga-settings.h
@@ -70,6 +70,7 @@
#define CONTACTS_SCHEMA "org.gnome." PACKAGE_NAME ".contacts"
+
namespace Ekiga {
/*
diff --git a/lib/settings/settings-mappings.c b/lib/settings/settings-mappings.c
new file mode 100644
index 0000000..cee2be0
--- /dev/null
+++ b/lib/settings/settings-mappings.c
@@ -0,0 +1,107 @@
+
+/* Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2014 Damien Sandras <dsandras seconix com>
+ *
+ * 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; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *
+ * Ekiga is licensed under the GPL license and as a special exception,
+ * you have permission to link or otherwise combine this program with the
+ * programs OPAL, OpenH323 and PWLIB, and distribute the combination,
+ * without applying the requirements of the GNU GPL to the OPAL, OpenH323
+ * and PWLIB programs, as long as you do follow the requirements of the
+ * GNU GPL for all the rest of the software thus combined.
+ */
+
+
+/*
+ * settings-mappings.c - description
+ * -----------------------------------
+ * begin : Sat 14 Dec 2013
+ * copyright : (C) 2000-2014 by Damien Sandras
+ * description : GSettings methods and helpers.
+ */
+
+#include "settings-mappings.h"
+
+GVariant *
+string_gsettings_set_from_int (const GValue *gvalue,
+ G_GNUC_UNUSED const GVariantType *expected_type,
+ gpointer data)
+{
+ const gchar **values = (const gchar **) data;
+
+ return g_variant_new_string (values [g_value_get_int (gvalue)]);
+}
+
+
+gboolean
+string_gsettings_get_from_int (GValue *gvalue,
+ GVariant *variant,
+ gpointer data)
+{
+ const gchar *value = NULL;
+ const gchar **values = (const gchar **) data;
+ int i = 0;
+
+ // GSettings value
+ value = g_variant_get_string (variant, NULL);
+
+ while (values [i] != NULL) {
+ if (g_strcmp0 (values [i], value) == 0) {
+ g_value_set_int (gvalue, i);
+ return TRUE;
+ }
+ i++;
+ }
+
+ return FALSE;
+}
+
+
+GVariant *
+string_gsettings_set_from_active (const GValue *gvalue,
+ G_GNUC_UNUSED const GVariantType *expected_type,
+ gpointer data)
+{
+ const gchar *value = (const gchar *) data;
+ GVariant *retval = NULL;
+
+ if (g_value_get_boolean (gvalue))
+ retval = g_variant_new_string (value);
+
+ return retval;
+}
+
+
+gboolean
+string_gsettings_get_from_active (GValue *gvalue,
+ GVariant *variant,
+ gpointer data)
+{
+ const gchar *id = (const gchar *) (data);
+ const gchar *value = NULL;
+
+ // GSettings value
+ value = g_variant_get_string (variant, NULL);
+
+ if (g_strcmp0 (value, id) == 0)
+ g_value_set_boolean (gvalue, TRUE);
+ else
+ g_value_set_boolean (gvalue, FALSE);
+
+ return TRUE;
+}
+
diff --git a/lib/settings/settings-mappings.h b/lib/settings/settings-mappings.h
new file mode 100644
index 0000000..5445191
--- /dev/null
+++ b/lib/settings/settings-mappings.h
@@ -0,0 +1,91 @@
+
+/* Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2014 Damien Sandras <dsandras seconix com>
+ *
+ * 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; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *
+ * Ekiga is licensed under the GPL license and as a special exception,
+ * you have permission to link or otherwise combine this program with the
+ * programs OPAL, OpenH323 and PWLIB, and distribute the combination,
+ * without applying the requirements of the GNU GPL to the OPAL, OpenH323
+ * and PWLIB programs, as long as you do follow the requirements of the
+ * GNU GPL for all the rest of the software thus combined.
+ */
+
+
+/*
+ * settings-mappings.c - description
+ * -----------------------------------
+ * begin : Sat 14 Dec 2013
+ * copyright : (C) 2000-2014 by Damien Sandras
+ * description : GSettings methods and helpers.
+ */
+
+#ifndef SETTINGS_MAPPINGS_H_
+#define SETTINGS_MAPPINGS_H_
+
+#include "config.h"
+
+#include <glib.h>
+#include <gio/gio.h>
+
+G_BEGIN_DECLS
+
+/* DESCRIPTION : Callback to be used with g_settings_bind_with_mapping
+ * BEHAVIOR : Converts a "int" property object into a string based
+ * GSettings value. Particularly useful with enums.
+ * PRE : data is an array of string values whose index corresponds
+ * to the "int" property.
+ */
+GVariant * string_gsettings_set_from_int (const GValue *gvalue,
+ const GVariantType *expected_type,
+ gpointer data);
+
+
+/* DESCRIPTION : Callback to be used with g_settings_bind_with_mapping
+ * BEHAVIOR : Converts a string based GSettings value into a "int"
+ * property object. Particularly useful with enums.
+ * PRE : data is an array of string values whose index corresponds
+ * to the "int" property.
+ */
+gboolean string_gsettings_get_from_int (GValue *gvalue,
+ GVariant *variant,
+ gpointer data);
+
+
+/* DESCRIPTION : Callback to be used with g_settings_bind_with_mapping
+ * BEHAVIOR : Converts a "toggle" property object into a string based
+ * GSettings value. Particularly useful with enums.
+ * PRE : data is the string value to set when the object is
+ * toggled.
+ */
+GVariant * string_gsettings_set_from_active (const GValue *gvalue,
+ const GVariantType *expected_type,
+ gpointer data);
+
+/* DESCRIPTION : Callback to be used with g_settings_bind_with_mapping
+ * BEHAVIOR : Converts a string based GSettings value into a "toggle"
+ * property object. Particularly useful with enums.
+ * PRE : data is the string value to set when the object is
+ * toggled.
+ */
+gboolean string_gsettings_get_from_active (GValue *gvalue,
+ GVariant *variant,
+ gpointer data);
+
+G_END_DECLS
+
+#endif
diff --git a/plugins/ldap/Makefile.am b/plugins/ldap/Makefile.am
index 71b978d..c9154c9 100644
--- a/plugins/ldap/Makefile.am
+++ b/plugins/ldap/Makefile.am
@@ -3,6 +3,7 @@ plugin_LTLIBRARIES = libgmldap.la
AM_CPPFLAGS = \
$(LDAP_CFLAGS) $(BOOST_CPPFLAGS) $(GLIB_CFLAGS) $(XML_CFLAGS) \
-I$(top_srcdir)/lib/ \
+ -I$(top_srcdir)/lib/settings \
-I$(top_srcdir)/lib/engine/framework \
-I$(top_srcdir)/lib/engine/addressbook
diff --git a/src/Makefile.am b/src/Makefile.am
index d725009..0a135b4 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -3,6 +3,7 @@ AM_CPPFLAGS = \
-I$(top_srcdir)/lib/gmconf \
-I$(top_srcdir)/lib/gui \
-I$(top_srcdir)/lib/platform \
+ -I$(top_srcdir)/lib/settings \
-I$(top_srcdir)/lib/engine/ \
-I$(top_srcdir)/lib/engine/framework \
-I$(top_srcdir)/lib/engine/gui/gtk-frontend \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]