[devhelp: 8/22] configuration: new list of disabled books
- From: Frederic Peters <fpeters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [devhelp: 8/22] configuration: new list of disabled books
- Date: Mon, 12 Jul 2010 09:20:12 +0000 (UTC)
commit f6b1d5e4ddd57187618fafbd3ea814171d05c2b2
Author: Aleksander Morgado <aleksander lanedo com>
Date: Thu May 20 12:13:54 2010 +0200
configuration: new list of disabled books
data/devhelp.schemas.in | 12 +++++
src/dh-book-manager-dialog.c | 63 ++++++++++++++++------------
src/dh-book-manager.c | 93 +++++++++++++++++++++++++++++++++++++++---
src/dh-book-manager.h | 14 ++++--
src/dh-book.c | 43 +++++++++++++++++--
src/dh-book.h | 1 +
src/dh-util.c | 39 ++++++++++++++----
src/dh-util.h | 2 +
8 files changed, 217 insertions(+), 50 deletions(-)
---
diff --git a/data/devhelp.schemas.in b/data/devhelp.schemas.in
index 21e40eb..eebeb72 100644
--- a/data/devhelp.schemas.in
+++ b/data/devhelp.schemas.in
@@ -127,6 +127,18 @@
</locale>
</schema>
<schema>
+ <key>/schemas/apps/devhelp/state/main/contents/books_disabled</key>
+ <applyto>/apps/devhelp/state/main/contents/books_disabled</applyto>
+ <owner>devhelp</owner>
+ <type>list</type>
+ <default></default>
+ <locale name="C">
+ <short>Books disabled</short>
+ <long>List of books disabled by the user.</long>
+ </locale>
+ </schema>
+
+ <schema>
<key>/schemas/apps/devhelp/ui/use_system_fonts</key>
<applyto>/apps/devhelp/ui/use_system_fonts</applyto>
<owner>devhelp</owner>
diff --git a/src/dh-book-manager-dialog.c b/src/dh-book-manager-dialog.c
index 18777b9..d59ff13 100644
--- a/src/dh-book-manager-dialog.c
+++ b/src/dh-book-manager-dialog.c
@@ -33,7 +33,8 @@ typedef struct {
GtkWidget *dialog;
GtkTreeView *treeview;
GtkListStore *store;
- DhBase *base;
+ DhBookManager *book_manager;
+ gboolean modified;
} DhBookManagerDialog;
/* List store columns... */
@@ -41,28 +42,33 @@ typedef struct {
#define LTCOLUMN_TITLE 1
#define LTCOLUMN_BOOK 2
-#define DH_CONF_PATH "/apps/devhelp"
-
-static DhBookManagerDialog *prefs;
+static DhBookManagerDialog *dlg;
static void
book_manager_dialog_init (void)
{
- if (!prefs) {
- prefs = g_new0 (DhBookManagerDialog, 1);
+ if (!dlg) {
+ dlg = g_new0 (DhBookManagerDialog, 1);
- prefs->base = dh_base_get ();
+ dlg->book_manager = dh_base_get_book_manager (dh_base_get ());
}
}
static void
book_manager_dialog_close_cb (GtkButton *button, gpointer user_data)
{
- DhBookManagerDialog *prefs = user_data;
+ DhBookManagerDialog *dlg = 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 (dlg->modified) {
+ dh_book_manager_update (dlg->book_manager);
+ }
- gtk_widget_destroy (GTK_WIDGET (prefs->dialog));
+ gtk_widget_destroy (GTK_WIDGET (dlg->dialog));
- prefs->dialog = NULL;
+ dlg->dialog = NULL;
}
static void
@@ -72,14 +78,14 @@ book_manager_tree_selection_toggled_cb (GtkCellRendererToggle *cell_renderer,
{
GtkTreeIter iter;
- if (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (prefs->store),
+ if (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (dlg->store),
&iter,
path))
{
gpointer book = NULL;
gboolean enabled;
- gtk_tree_model_get (GTK_TREE_MODEL (prefs->store),
+ gtk_tree_model_get (GTK_TREE_MODEL (dlg->store),
&iter,
LTCOLUMN_BOOK, &book,
LTCOLUMN_ENABLED, &enabled,
@@ -89,9 +95,15 @@ book_manager_tree_selection_toggled_cb (GtkCellRendererToggle *cell_renderer,
/* Update book conf */
dh_book_set_enabled (book, !enabled);
- gtk_list_store_set (prefs->store, &iter,
+ gtk_list_store_set (dlg->store, &iter,
LTCOLUMN_ENABLED, !enabled,
-1);
+
+ /* Set the modified flag so that we know we must
+ * update conf & trees */
+ if (!dlg->modified) {
+ dlg->modified = TRUE;
+ }
}
}
}
@@ -100,11 +112,8 @@ static void
book_manager_dialog_populate_store (void)
{
GList *l;
- DhBookManager *book_manager;
-
- book_manager = dh_base_get_book_manager (prefs->base);
- for (l = dh_book_manager_get_books (book_manager);
+ for (l = dh_book_manager_get_books (dlg->book_manager);
l;
l = g_list_next (l)) {
GtkTreeIter iter;
@@ -112,8 +121,8 @@ book_manager_dialog_populate_store (void)
book = DH_BOOK (l->data);
- gtk_list_store_append (prefs->store, &iter);
- gtk_list_store_set (prefs->store, &iter,
+ gtk_list_store_append (dlg->store, &iter);
+ gtk_list_store_set (dlg->store, &iter,
LTCOLUMN_ENABLED, dh_book_get_enabled (book),
LTCOLUMN_TITLE, dh_book_get_title (book),
LTCOLUMN_BOOK, book,
@@ -129,8 +138,8 @@ dh_book_manager_dialog_show (GtkWindow *parent)
book_manager_dialog_init ();
- if (prefs->dialog != NULL) {
- gtk_window_present (GTK_WINDOW (prefs->dialog));
+ if (dlg->dialog != NULL) {
+ gtk_window_present (GTK_WINDOW (dlg->dialog));
return;
}
@@ -141,15 +150,15 @@ dh_book_manager_dialog_show (GtkWindow *parent)
path,
"book_manager_dialog",
NULL,
- "book_manager_dialog", &prefs->dialog,
- "book_manager_store", &prefs->store,
- "book_manager_treeview", &prefs->treeview,
+ "book_manager_dialog", &dlg->dialog,
+ "book_manager_store", &dlg->store,
+ "book_manager_treeview", &dlg->treeview,
NULL);
g_free (path);
dh_util_builder_connect (
builder,
- prefs,
+ dlg,
"book_manager_close_button", "clicked", book_manager_dialog_close_cb,
"book_manager_toggle_enabled", "toggled", book_manager_tree_selection_toggled_cb,
NULL);
@@ -158,6 +167,6 @@ dh_book_manager_dialog_show (GtkWindow *parent)
book_manager_dialog_populate_store ();
- gtk_window_set_transient_for (GTK_WINDOW (prefs->dialog), parent);
- gtk_widget_show_all (prefs->dialog);
+ gtk_window_set_transient_for (GTK_WINDOW (dlg->dialog), parent);
+ gtk_widget_show_all (dlg->dialog);
}
diff --git a/src/dh-book-manager.c b/src/dh-book-manager.c
index f41251b..ca07836 100644
--- a/src/dh-book-manager.c
+++ b/src/dh-book-manager.c
@@ -25,11 +25,12 @@
#include <string.h>
#include "dh-link.h"
+#include "dh-util.h"
#include "dh-book.h"
#include "dh-book-manager.h"
typedef struct {
- /* The list of all books found in the system */
+ /* The list of all DhBooks found in the system */
GList *books;
} DhBookManagerPriv;
@@ -55,15 +56,13 @@ static void
book_manager_finalize (GObject *object)
{
DhBookManagerPriv *priv;
- GList *walker;
+ GList *l;
priv = GET_PRIVATE (object);
/* Destroy all books */
- walker = priv->books;
- while (walker) {
- g_object_unref (walker->data);
- walker = g_list_next (walker);
+ for (l = priv->books; l; l = g_list_next (l)) {
+ g_object_unref (l->data);
}
g_list_free (priv->books);
@@ -89,6 +88,37 @@ dh_book_manager_init (DhBookManager *book_manager)
}
static void
+book_manager_clean_list_of_disabled_books (GSList *disabled_books)
+{
+ GSList *sl;
+
+ for (sl = disabled_books; sl; sl = g_slist_next (sl)) {
+ g_free (sl->data);
+ }
+ g_slist_free (sl);
+}
+
+static void
+book_manager_check_status_from_conf (DhBookManager *book_manager)
+{
+ GSList *disabled_books, *sl;
+
+ disabled_books = dh_util_state_load_disabled_books ();
+
+ for (sl = disabled_books; sl; sl = g_slist_next (sl)) {
+ DhBook *book;
+
+ book = dh_book_manager_get_book_by_name (book_manager,
+ (const gchar *)sl->data);
+ if (book) {
+ dh_book_set_enabled (book, FALSE);
+ }
+ }
+
+ book_manager_clean_list_of_disabled_books (disabled_books);
+}
+
+static void
book_manager_add_books_in_data_dir (DhBookManager *book_manager,
const gchar *data_dir)
{
@@ -123,6 +153,9 @@ dh_book_manager_populate (DhBookManager *book_manager)
book_manager,
"/Library/Developer/Shared/Documentation/DocSets");
#endif
+
+ /* Once all books are loaded, check enabled status from conf */
+ book_manager_check_status_from_conf (book_manager);
}
static gchar *
@@ -287,6 +320,54 @@ dh_book_manager_get_books (DhBookManager *book_manager)
return GET_PRIVATE (book_manager)->books;
}
+DhBook *
+dh_book_manager_get_book_by_name (DhBookManager *book_manager,
+ const gchar *name)
+{
+ DhBook *book = NULL;
+ GList *l;
+
+ g_return_val_if_fail (book_manager, NULL);
+
+ for (l = GET_PRIVATE (book_manager)->books;
+ l && !book;
+ l = g_list_next (l)) {
+ if (g_strcmp0 (name,
+ dh_book_get_name (DH_BOOK (l->data))) == 0) {
+ book = l->data;
+ }
+ }
+
+ return book;
+}
+
+void
+dh_book_manager_update (DhBookManager *book_manager)
+{
+ DhBookManagerPriv *priv;
+ GSList *disabled_books = NULL;
+ GList *l;
+
+ g_return_if_fail (book_manager);
+
+ priv = GET_PRIVATE (book_manager);
+
+ /* Create list of disabled books */
+ for (l = priv->books; l; l = g_list_next (l)) {
+ DhBook *book = DH_BOOK (l->data);
+
+ if (!dh_book_get_enabled (book)) {
+ disabled_books = g_slist_append (disabled_books,
+ g_strdup (dh_book_get_name (book)));
+ }
+ }
+
+ /* Store in conf */
+ dh_util_state_store_disabled_books (disabled_books);
+
+ book_manager_clean_list_of_disabled_books (disabled_books);
+}
+
DhBookManager *
dh_book_manager_new (void)
{
diff --git a/src/dh-book-manager.h b/src/dh-book-manager.h
index 6fcc4c7..bda6b98 100644
--- a/src/dh-book-manager.h
+++ b/src/dh-book-manager.h
@@ -26,6 +26,8 @@
#include <gtk/gtk.h>
+#include <dh-book.h>
+
G_BEGIN_DECLS
typedef struct _DhBookManager DhBookManager;
@@ -46,11 +48,13 @@ struct _DhBookManagerClass {
GObjectClass parent_class;
};
-GType dh_book_manager_get_type (void) G_GNUC_CONST;
-DhBookManager *dh_book_manager_new (void);
-void dh_book_manager_populate (DhBookManager *book_manager);
-GList *dh_book_manager_get_books (DhBookManager *book_manager);
-
+GType dh_book_manager_get_type (void) G_GNUC_CONST;
+DhBookManager *dh_book_manager_new (void);
+void dh_book_manager_populate (DhBookManager *book_manager);
+GList *dh_book_manager_get_books (DhBookManager *book_manager);
+DhBook *dh_book_manager_get_book_by_name (DhBookManager *book_manager,
+ const gchar *name);
+void dh_book_manager_update (DhBookManager *book_manager);
G_END_DECLS
diff --git a/src/dh-book.c b/src/dh-book.c
index 1af4a69..28c9735 100644
--- a/src/dh-book.c
+++ b/src/dh-book.c
@@ -34,6 +34,8 @@ typedef struct {
gchar *path;
/* Enable or disabled? */
gboolean enabled;
+ /* Book name */
+ gchar *name;
/* Book title */
gchar *title;
/* Generated book tree */
@@ -97,6 +99,7 @@ dh_book_init (DhBook *book)
{
DhBookPriv *priv = GET_PRIVATE (book);
+ priv->name = NULL;
priv->path = NULL;
priv->title = NULL;
priv->enabled = TRUE;
@@ -111,6 +114,22 @@ unref_node_link (GNode *node,
dh_link_unref (node->data);
}
+static gchar *
+book_get_name_from_path (const gchar *path)
+{
+ gchar *name;
+ gchar *aux;
+
+ g_return_val_if_fail (path, NULL);
+
+ name = g_path_get_basename (path);
+ aux = strrchr (name, '.');
+ if (aux) {
+ *aux = '\0';
+ }
+ return name;
+}
+
DhBook *
dh_book_new (const gchar *book_path)
{
@@ -123,11 +142,8 @@ dh_book_new (const gchar *book_path)
book = g_object_new (DH_TYPE_BOOK, NULL);
priv = GET_PRIVATE (book);
- /* Store path */
- priv->path = g_strdup (book_path);
-
/* Parse file storing contents in the book struct */
- if (!dh_parser_read_file (priv->path,
+ if (!dh_parser_read_file (book_path,
&priv->tree,
&priv->keywords,
&error)) {
@@ -141,9 +157,16 @@ dh_book_new (const gchar *book_path)
return NULL;
}
+ /* Store path */
+ priv->path = g_strdup (book_path);
+
/* Setup title */
priv->title = g_strdup (dh_link_get_name ((DhLink *)priv->tree->data));
+ /* Setup name */
+ priv->name = book_get_name_from_path (book_path);
+
+
return book;
}
@@ -172,6 +195,18 @@ dh_book_get_tree (DhBook *book)
}
const gchar *
+dh_book_get_name (DhBook *book)
+{
+ DhBookPriv *priv;
+
+ g_return_val_if_fail (DH_IS_BOOK (book), NULL);
+
+ priv = GET_PRIVATE (book);
+
+ return priv->name;
+}
+
+const gchar *
dh_book_get_title (DhBook *book)
{
DhBookPriv *priv;
diff --git a/src/dh-book.h b/src/dh-book.h
index 587ba63..8d3ed3f 100644
--- a/src/dh-book.h
+++ b/src/dh-book.h
@@ -50,6 +50,7 @@ GType dh_book_get_type (void) G_GNUC_CONST;
DhBook *dh_book_new (const gchar *book_path);
GList *dh_book_get_keywords (DhBook *book);
GNode *dh_book_get_tree (DhBook *book);
+const gchar *dh_book_get_name (DhBook *book);
const gchar *dh_book_get_title (DhBook *book);
gboolean dh_book_get_enabled (DhBook *book);
void dh_book_set_enabled (DhBook *book,
diff --git a/src/dh-util.c b/src/dh-util.c
index 7ef964c..77a0b32 100644
--- a/src/dh-util.c
+++ b/src/dh-util.c
@@ -125,7 +125,7 @@ cf_string_to_utf8 (CFStringRef str)
CFIndex len;
gchar *ret;
- len = CFStringGetMaximumSizeForEncoding (CFStringGetLength (str),
+ len = CFStringGetMaximumSizeForEncoding (CFStringGetLength (str),
kCFStringEncodingUTF8) + 1;
ret = g_malloc (len);
@@ -142,7 +142,7 @@ static gchar *
util_get_mac_data_dir (void)
{
const gchar *env;
- CFBundleRef cf_bundle;
+ CFBundleRef cf_bundle;
UInt32 type;
UInt32 creator;
CFURLRef cf_url;
@@ -165,7 +165,7 @@ util_get_mac_data_dir (void)
if (type != 'APPL') {
return NULL;
}
-
+
cf_url = CFBundleCopyBundleURL (cf_bundle);
cf_string = CFURLCopyFileSystemPath (cf_url, kCFURLPOSIXPathStyle);
ret = cf_string_to_utf8 (cf_string);
@@ -238,7 +238,7 @@ util_state_item_free (DhUtilStateItem *item)
}
static void
-util_state_setup_widget (GtkWidget *widget,
+util_state_setup_widget (GtkWidget *widget,
const gchar *name)
{
DhUtilStateItem *item;
@@ -464,6 +464,29 @@ dh_util_state_manage_paned (GtkPaned *paned,
NULL);
}
+GSList *
+dh_util_state_load_disabled_books (void)
+{
+ gchar *key;
+ GSList *disabled_books = NULL;
+
+ key = util_state_get_key ("main/contents", "disabled_books");
+ ige_conf_get_string_list (ige_conf_get (), key, &disabled_books);
+ g_free(key);
+
+ return disabled_books;
+}
+
+void
+dh_util_state_store_disabled_books (GSList *disabled_books)
+{
+ gchar *key;
+
+ key = util_state_get_key ("main/contents", "disabled_books");
+ ige_conf_set_string_list (ige_conf_get (), key, disabled_books);
+ g_free(key);
+}
+
static gboolean
util_state_notebook_timeout_cb (gpointer notebook)
{
@@ -477,7 +500,7 @@ util_state_notebook_timeout_cb (gpointer notebook)
item->timeout_id = 0;
page = gtk_notebook_get_nth_page (
- notebook,
+ notebook,
gtk_notebook_get_current_page (notebook));
page_name = dh_util_state_get_notebook_page_name (page);
if (page_name) {
@@ -568,7 +591,7 @@ split_font_string (const gchar *name_and_size,
if (!desc) {
return FALSE;
}
-
+
mask = (PANGO_FONT_MASK_FAMILY | PANGO_FONT_MASK_SIZE);
if ((pango_font_description_get_set_fields (desc) & mask) == mask) {
*size = PANGO_PIXELS (pango_font_description_get_size (desc));
@@ -608,7 +631,7 @@ dh_util_font_get_variable (gchar **name,
#endif
} else {
ige_conf_get_string (conf,
- DH_CONF_VARIABLE_FONT,
+ DH_CONF_VARIABLE_FONT,
&name_and_size);
}
@@ -640,7 +663,7 @@ dh_util_font_get_fixed (gchar **name,
#endif
} else {
ige_conf_get_string (conf,
- DH_CONF_FIXED_FONT,
+ DH_CONF_FIXED_FONT,
&name_and_size);
}
diff --git a/src/dh-util.h b/src/dh-util.h
index a033d99..5e3de88 100644
--- a/src/dh-util.h
+++ b/src/dh-util.h
@@ -49,6 +49,8 @@ void dh_util_state_manage_notebook (GtkNotebook *notebook,
void dh_util_state_set_notebook_page_name (GtkWidget *page,
const gchar *page_name);
const gchar *dh_util_state_get_notebook_page_name (GtkWidget *page);
+GSList * dh_util_state_load_disabled_books (void);
+void dh_util_state_store_disabled_books (GSList *disabled_books);
void dh_util_font_get_variable (gchar **name,
gdouble *size,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]