[devhelp: 13/22] preferences dialog: add bookshelf tab
- From: Frederic Peters <fpeters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [devhelp: 13/22] preferences dialog: add bookshelf tab
- Date: Mon, 12 Jul 2010 09:20:37 +0000 (UTC)
commit 826284ab4b1655cf3b43abf67110013ef7a50b71
Author: Aleksander Morgado <aleksander lanedo com>
Date: Tue Jul 6 11:44:26 2010 +0200
preferences dialog: add bookshelf tab
data/ui/devhelp.builder | 230 ++++++++++++++++++++++-------------------------
src/dh-preferences.c | 206 +++++++++++++++++++++++++++++++-----------
2 files changed, 261 insertions(+), 175 deletions(-)
---
diff --git a/data/ui/devhelp.builder b/data/ui/devhelp.builder
index eafcf78..bd60e5d 100644
--- a/data/ui/devhelp.builder
+++ b/data/ui/devhelp.builder
@@ -2,10 +2,21 @@
<interface>
<!-- interface-requires gtk+ 2.12 -->
<!-- interface-naming-policy toplevel-contextual -->
+ <object class="GtkListStore" id="book_manager_store">
+ <columns>
+ <!-- column-name enabled -->
+ <column type="gboolean"/>
+ <!-- column-name title -->
+ <column type="gchararray"/>
+ <!-- column-name book -->
+ <column type="gpointer"/>
+ </columns>
+ </object>
<object class="GtkDialog" id="preferences_dialog">
<property name="border_width">5</property>
<property name="title" translatable="yes">Preferences</property>
- <property name="resizable">False</property>
+ <property name="default_width">500</property>
+ <property name="default_height">300</property>
<property name="type_hint">dialog</property>
<property name="has_separator">False</property>
<child internal-child="vbox">
@@ -13,33 +24,21 @@
<property name="visible">True</property>
<property name="spacing">2</property>
<child>
- <object class="GtkVBox" id="outer_vbox">
+ <object class="GtkNotebook" id="notebook1">
<property name="visible">True</property>
- <property name="border_width">5</property>
- <property name="spacing">18</property>
+ <property name="can_focus">True</property>
<child>
- <object class="GtkVBox" id="font_vbox">
+ <object class="GtkVBox" id="outer_vbox1">
<property name="visible">True</property>
- <property name="spacing">6</property>
- <child>
- <object class="GtkLabel" id="label6">
- <property name="visible">True</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes"><b>Fonts</b></property>
- <property name="use_markup">True</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">0</property>
- </packing>
- </child>
<child>
- <object class="GtkAlignment" id="alignment1">
+ <object class="GtkAlignment" id="alignment2">
<property name="visible">True</property>
- <property name="left_padding">12</property>
+ <property name="top_padding">8</property>
+ <property name="bottom_padding">8</property>
+ <property name="left_padding">8</property>
+ <property name="right_padding">8</property>
<child>
- <object class="GtkVBox" id="vbox3">
+ <object class="GtkVBox" id="vbox4">
<property name="visible">True</property>
<property name="spacing">6</property>
<child>
@@ -67,7 +66,7 @@
<property name="column_spacing">6</property>
<property name="row_spacing">6</property>
<child>
- <object class="GtkLabel" id="label8">
+ <object class="GtkLabel" id="label4">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">_Variable width: </property>
@@ -75,12 +74,12 @@
<property name="mnemonic_widget">variable_font_button</property>
</object>
<packing>
- <property name="x_options">GTK_FILL</property>
+ <property name="x_options"></property>
<property name="y_options"></property>
</packing>
</child>
<child>
- <object class="GtkLabel" id="label9">
+ <object class="GtkLabel" id="label5">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">_Fixed width:</property>
@@ -98,20 +97,22 @@
<object class="GtkFontButton" id="variable_font_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="receives_default">False</property>
+ <property name="receives_default">True</property>
<property name="use_font">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
- <property name="y_options"></property>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkFontButton" id="fixed_font_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="receives_default">False</property>
+ <property name="receives_default">True</property>
+ <property name="font_name">Monospace 12</property>
<property name="use_font">True</property>
</object>
<packing>
@@ -119,11 +120,14 @@
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
+ <property name="x_options"></property>
<property name="y_options"></property>
</packing>
</child>
</object>
<packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
@@ -131,139 +135,121 @@
</child>
</object>
<packing>
- <property name="position">1</property>
+ <property name="position">0</property>
</packing>
</child>
</object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">0</property>
- </packing>
</child>
- </object>
- <packing>
- <property name="position">1</property>
- </packing>
- </child>
- <child internal-child="action_area">
- <object class="GtkHButtonBox" id="dialog-action_area1">
- <property name="visible">True</property>
- <property name="layout_style">end</property>
- <child>
- <object class="GtkButton" id="preferences_close_button">
- <property name="label">gtk-close</property>
+ <child type="tab">
+ <object class="GtkLabel" id="label1">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="can_default">True</property>
- <property name="receives_default">False</property>
- <property name="use_stock">True</property>
+ <property name="label" translatable="yes"><b>Fonts</b></property>
+ <property name="use_markup">True</property>
</object>
<packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">0</property>
+ <property name="tab_fill">False</property>
</packing>
</child>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="pack_type">end</property>
- <property name="position">0</property>
- </packing>
- </child>
- </object>
- </child>
- <action-widgets>
- <action-widget response="-7">preferences_close_button</action-widget>
- </action-widgets>
- </object>
- <object class="GtkListStore" id="book_manager_store">
- <columns>
- <!-- column-name enabled -->
- <column type="gboolean"/>
- <!-- column-name title -->
- <column type="gchararray"/>
- <!-- column-name book -->
- <column type="gpointer"/>
- </columns>
- </object>
- <object class="GtkDialog" id="book_manager_dialog">
- <property name="border_width">5</property>
- <property name="title" translatable="yes">Book Manager</property>
- <property name="default_width">500</property>
- <property name="default_height">300</property>
- <property name="type_hint">normal</property>
- <property name="has_separator">False</property>
- <child internal-child="vbox">
- <object class="GtkVBox" id="dialog-vbox2">
- <property name="visible">True</property>
- <property name="spacing">2</property>
- <child>
- <object class="GtkVBox" id="internal-vbox1">
- <property name="visible">True</property>
<child>
- <object class="GtkScrolledWindow" id="scrolledwindow1">
+ <object class="GtkVBox" id="outer_vbox2">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="hscrollbar_policy">automatic</property>
- <property name="vscrollbar_policy">automatic</property>
<child>
- <object class="GtkTreeView" id="book_manager_treeview">
+ <object class="GtkAlignment" id="alignment1">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="model">book_manager_store</property>
- <property name="headers_clickable">False</property>
- <property name="enable_grid_lines">vertical</property>
+ <property name="top_padding">8</property>
+ <property name="bottom_padding">8</property>
+ <property name="left_padding">8</property>
+ <property name="right_padding">8</property>
<child>
- <object class="GtkTreeViewColumn" id="treeviewcolumn1">
- <property name="title">Enabled</property>
- <child>
- <object class="GtkCellRendererToggle" id="book_manager_toggle_enabled"/>
- <attributes>
- <attribute name="active">0</attribute>
- </attributes>
- </child>
- </object>
- </child>
- <child>
- <object class="GtkTreeViewColumn" id="treeviewcolumn2">
- <property name="title">Title</property>
+ <object class="GtkScrolledWindow" id="scrolledwindow1">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="hscrollbar_policy">automatic</property>
+ <property name="vscrollbar_policy">automatic</property>
<child>
- <object class="GtkCellRendererText" id="cellrenderertext1"/>
- <attributes>
- <attribute name="text">1</attribute>
- </attributes>
+ <object class="GtkTreeView" id="book_manager_treeview">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="model">book_manager_store</property>
+ <property name="headers_clickable">False</property>
+ <property name="search_column">0</property>
+ <property name="enable_grid_lines">vertical</property>
+ <child>
+ <object class="GtkTreeViewColumn" id="treeviewcolumn1">
+ <property name="title">Enabled</property>
+ <child>
+ <object class="GtkCellRendererToggle" id="book_manager_toggle_enabled"/>
+ <attributes>
+ <attribute name="active">0</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkTreeViewColumn" id="treeviewcolumn2">
+ <property name="title">Title</property>
+ <child>
+ <object class="GtkCellRendererText" id="cellrenderertext1"/>
+ <attributes>
+ <attribute name="text">1</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
+ </object>
</child>
</object>
</child>
</object>
+ <packing>
+ <property name="position">0</property>
+ </packing>
</child>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
+ <child type="tab">
+ <object class="GtkLabel" id="label2">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes"><b>Book Shelf</b></property>
+ <property name="use_markup">True</property>
+ </object>
+ <packing>
+ <property name="position">1</property>
+ <property name="tab_fill">False</property>
+ </packing>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child type="tab">
+ <placeholder/>
+ </child>
</object>
<packing>
+ <property name="padding">2</property>
<property name="position">1</property>
</packing>
</child>
<child internal-child="action_area">
- <object class="GtkHButtonBox" id="dialog-action_area2">
+ <object class="GtkHButtonBox" id="dialog-action_area1">
<property name="visible">True</property>
<property name="layout_style">end</property>
<child>
- <object class="GtkButton" id="book_manager_close_button">
- <property name="label" translatable="yes">Close</property>
+ <object class="GtkButton" id="preferences_close_button">
+ <property name="label">gtk-close</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="receives_default">True</property>
+ <property name="can_default">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
- <property name="position">1</property>
+ <property name="position">0</property>
</packing>
</child>
</object>
@@ -276,7 +262,7 @@
</object>
</child>
<action-widgets>
- <action-widget response="0">book_manager_close_button</action-widget>
+ <action-widget response="-7">preferences_close_button</action-widget>
</action-widgets>
</object>
</interface>
diff --git a/src/dh-preferences.c b/src/dh-preferences.c
index f4986ba..3f4de39 100644
--- a/src/dh-preferences.c
+++ b/src/dh-preferences.c
@@ -29,39 +29,54 @@
typedef struct {
GtkWidget *dialog;
+ /* Fonts tab */
GtkWidget *system_fonts_button;
GtkWidget *fonts_table;
GtkWidget *variable_font_button;
GtkWidget *fixed_font_button;
-
guint use_system_fonts_id;
guint system_var_id;
guint system_fixed_id;
guint var_id;
guint fixed_id;
+
+ /* Book Shelf tab */
+ DhBookManager *book_manager;
+ GtkTreeView *booklist_treeview;
+ GtkListStore *booklist_store;
+ gboolean booklist_modified;
} DhPreferences;
-static void preferences_font_set_cb (GtkFontButton *button,
- gpointer user_data);
-static void preferences_close_cb (GtkButton *button,
- gpointer user_data);
-static void preferences_system_fonts_toggled_cb (GtkToggleButton *button,
- gpointer user_data);
+/* Fonts-tab related */
+static void preferences_fonts_font_set_cb (GtkFontButton *button,
+ gpointer user_data);
+static void preferences_fonts_system_fonts_toggled_cb (GtkToggleButton *button,
+ gpointer user_data);
#if 0
-static void preferences_var_font_notify_cb (IgeConf *client,
- const gchar *path,
- gpointer user_data);
-static void preferences_fixed_font_notify_cb (IgeConf *client,
- const gchar *path,
- gpointer user_data);
-static void preferences_use_system_font_notify_cb (IgeConf *client,
- const gchar *path,
- gpointer user_data);
-static void preferences_connect_conf_listeners (void);
+static void preferences_fonts_var_font_notify_cb (IgeConf *client,
+ const gchar *path,
+ gpointer user_data);
+static void preferences_fonts_fixed_font_notify_cb (IgeConf *client,
+ const gchar *path,
+ gpointer user_data);
+static void preferences_fonts_use_system_font_notify_cb (IgeConf *client,
+ const gchar *path,
+ gpointer user_data);
+static void preferences_connect_conf_listeners (void);
#endif
-static void preferences_get_font_names (gboolean use_system_fonts,
- gchar **variable,
- gchar **fixed);
+static void preferences_fonts_get_font_names (gboolean use_system_fonts,
+ gchar **variable,
+ gchar **fixed);
+
+/* Bookshelf-tab related */
+static void preferences_bookshelf_tree_selection_toggled_cb (GtkCellRendererToggle *cell_renderer,
+ gchar *path,
+ gpointer user_data);
+static void preferences_bookshelf_populate_store (void);
+
+/* Common */
+static void preferences_close_cb (GtkButton *button,
+ gpointer user_data);
#define DH_CONF_PATH "/apps/devhelp"
#define DH_CONF_USE_SYSTEM_FONTS DH_CONF_PATH "/ui/use_system_fonts"
@@ -70,6 +85,11 @@ static void preferences_get_font_names (gboolean use_sys
#define DH_CONF_SYSTEM_VARIABLE_FONT "/desktop/gnome/interface/font_name"
#define DH_CONF_SYSTEM_FIXED_FONT "/desktop/gnome/interface/monospace_font_name"
+/* Book list store columns... */
+#define LTCOLUMN_ENABLED 0
+#define LTCOLUMN_TITLE 1
+#define LTCOLUMN_BOOK 2
+
static DhPreferences *prefs;
static void
@@ -78,10 +98,40 @@ preferences_init (void)
if (!prefs) {
prefs = g_new0 (DhPreferences, 1);
}
+
+ if (!prefs->book_manager) {
+ prefs->book_manager = dh_base_get_book_manager (dh_base_get ());
+ }
+}
+
+static void
+preferences_close_cb (GtkButton *button, gpointer user_data)
+{
+ DhPreferences *prefs = user_data;
+
+ /* If any change was done, tell the book manager to update itself
+ * This will update conf and notify the trees so that they get
+ * updated as well */
+ if (prefs->booklist_modified) {
+ dh_book_manager_update (prefs->book_manager);
+ }
+
+ gtk_widget_destroy (GTK_WIDGET (prefs->dialog));
+
+ prefs->dialog = NULL;
+ prefs->system_fonts_button = NULL;
+ prefs->fonts_table = NULL;
+ prefs->variable_font_button = NULL;
+ prefs->fixed_font_button = NULL;
+ prefs->booklist_treeview = NULL;
+ prefs->booklist_store = NULL;
+ prefs->book_manager = NULL;
+ prefs->booklist_modified = FALSE;
}
static void
-preferences_font_set_cb (GtkFontButton *button, gpointer user_data)
+preferences_fonts_font_set_cb (GtkFontButton *button,
+ gpointer user_data)
{
DhPreferences *prefs = user_data;
const gchar *font_name;
@@ -99,22 +149,8 @@ preferences_font_set_cb (GtkFontButton *button, gpointer user_data)
}
static void
-preferences_close_cb (GtkButton *button, gpointer user_data)
-{
- DhPreferences *prefs = user_data;
-
- gtk_widget_destroy (GTK_WIDGET (prefs->dialog));
-
- prefs->dialog = NULL;
- prefs->system_fonts_button = NULL;
- prefs->fonts_table = NULL;
- prefs->variable_font_button = NULL;
- prefs->fixed_font_button = NULL;
-}
-
-static void
-preferences_system_fonts_toggled_cb (GtkToggleButton *button,
- gpointer user_data)
+preferences_fonts_system_fonts_toggled_cb (GtkToggleButton *button,
+ gpointer user_data)
{
DhPreferences *prefs = user_data;
gboolean active;
@@ -130,9 +166,9 @@ preferences_system_fonts_toggled_cb (GtkToggleButton *button,
#if 0
static void
-preferences_var_font_notify_cb (IgeConf *client,
- const gchar *path,
- gpointer user_data)
+preferences_fonts_var_font_notify_cb (IgeConf *client,
+ const gchar *path,
+ gpointer user_data)
{
DhPreferences *prefs = user_data;
gboolean use_system_fonts;
@@ -151,9 +187,9 @@ preferences_var_font_notify_cb (IgeConf *client,
}
static void
-preferences_fixed_font_notify_cb (IgeConf *client,
- const gchar *path,
- gpointer user_data)
+preferences_fonts_fixed_font_notify_cb (IgeConf *client,
+ const gchar *path,
+ gpointer user_data)
{
DhPreferences *prefs = user_data;
gboolean use_system_fonts;
@@ -172,9 +208,9 @@ preferences_fixed_font_notify_cb (IgeConf *client,
}
static void
-preferences_use_system_font_notify_cb (IgeConf *client,
- const gchar *path,
- gpointer user_data)
+preferences_fonts_use_system_font_notify_cb (IgeConf *client,
+ const gchar *path,
+ gpointer user_data)
{
DhPreferences *prefs = user_data;
gboolean use_system_fonts;
@@ -231,9 +267,9 @@ preferences_connect_conf_listeners (void)
/* FIXME: Use the functions in dh-util.c for this. */
static void
-preferences_get_font_names (gboolean use_system_fonts,
- gchar **variable,
- gchar **fixed)
+preferences_fonts_get_font_names (gboolean use_system_fonts,
+ gchar **variable,
+ gchar **fixed)
{
gchar *var_font_name, *fixed_font_name;
IgeConf *conf;
@@ -265,6 +301,65 @@ preferences_get_font_names (gboolean use_system_fonts,
*fixed = fixed_font_name;
}
+static void
+preferences_bookshelf_tree_selection_toggled_cb (GtkCellRendererToggle *cell_renderer,
+ gchar *path,
+ gpointer user_data)
+{
+ GtkTreeIter iter;
+
+ if (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (prefs->booklist_store),
+ &iter,
+ path))
+ {
+ gpointer book = NULL;
+ gboolean enabled;
+
+ gtk_tree_model_get (GTK_TREE_MODEL (prefs->booklist_store),
+ &iter,
+ LTCOLUMN_BOOK, &book,
+ LTCOLUMN_ENABLED, &enabled,
+ -1);
+
+ if (book) {
+ /* Update book conf */
+ dh_book_set_enabled (book, !enabled);
+
+ gtk_list_store_set (prefs->booklist_store, &iter,
+ LTCOLUMN_ENABLED, !enabled,
+ -1);
+
+ /* Set the modified flag so that we know we must
+ * update conf & trees */
+ if (!prefs->booklist_modified) {
+ prefs->booklist_modified = TRUE;
+ }
+ }
+ }
+}
+
+static void
+preferences_bookshelf_populate_store (void)
+{
+ GList *l;
+
+ for (l = dh_book_manager_get_books (prefs->book_manager);
+ l;
+ l = g_list_next (l)) {
+ GtkTreeIter iter;
+ DhBook *book;
+
+ book = DH_BOOK (l->data);
+
+ gtk_list_store_append (prefs->booklist_store, &iter);
+ gtk_list_store_set (prefs->booklist_store, &iter,
+ LTCOLUMN_ENABLED, dh_book_get_enabled (book),
+ LTCOLUMN_TITLE, dh_book_get_title (book),
+ LTCOLUMN_BOOK, book,
+ -1);
+ }
+}
+
void
dh_preferences_show_dialog (GtkWindow *parent)
{
@@ -292,16 +387,19 @@ dh_preferences_show_dialog (GtkWindow *parent)
"system_fonts_button", &prefs->system_fonts_button,
"variable_font_button", &prefs->variable_font_button,
"fixed_font_button", &prefs->fixed_font_button,
+ "book_manager_store", &prefs->booklist_store,
+ "book_manager_treeview", &prefs->booklist_treeview,
NULL);
g_free (path);
dh_util_builder_connect (
builder,
prefs,
- "variable_font_button", "font_set", preferences_font_set_cb,
- "fixed_font_button", "font_set", preferences_font_set_cb,
+ "variable_font_button", "font_set", preferences_fonts_font_set_cb,
+ "fixed_font_button", "font_set", preferences_fonts_font_set_cb,
+ "system_fonts_button", "toggled", preferences_fonts_system_fonts_toggled_cb,
+ "book_manager_toggle_enabled", "toggled", preferences_bookshelf_tree_selection_toggled_cb,
"preferences_close_button", "clicked", preferences_close_cb,
- "system_fonts_button", "toggled", preferences_system_fonts_toggled_cb,
NULL);
ige_conf_get_bool (ige_conf_get (),
@@ -311,7 +409,7 @@ dh_preferences_show_dialog (GtkWindow *parent)
use_system_fonts);
gtk_widget_set_sensitive (prefs->fonts_table, !use_system_fonts);
- preferences_get_font_names (FALSE, &var_font_name, &fixed_font_name);
+ preferences_fonts_get_font_names (FALSE, &var_font_name, &fixed_font_name);
if (var_font_name) {
gtk_font_button_set_font_name (GTK_FONT_BUTTON (prefs->variable_font_button),
@@ -325,6 +423,8 @@ dh_preferences_show_dialog (GtkWindow *parent)
g_free (fixed_font_name);
}
+ preferences_bookshelf_populate_store ();
+
g_object_unref (builder);
gtk_window_set_transient_for (GTK_WINDOW (prefs->dialog), parent);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]