[devhelp/wip/book-manager-singleton] Preferences: do not store the DhBookManager
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [devhelp/wip/book-manager-singleton] Preferences: do not store the DhBookManager
- Date: Mon, 1 May 2017 14:05:05 +0000 (UTC)
commit 3d89e7886a9056daf00dd155305e8497cf64cd5a
Author: Sébastien Wilmet <swilmet gnome org>
Date: Mon May 1 16:00:39 2017 +0200
Preferences: do not store the DhBookManager
And use g_signal_connect_object().
src/dh-preferences.c | 81 +++++++++++++++++++-------------------------------
1 files changed, 31 insertions(+), 50 deletions(-)
---
diff --git a/src/dh-preferences.c b/src/dh-preferences.c
index a0757a0..083315a 100644
--- a/src/dh-preferences.c
+++ b/src/dh-preferences.c
@@ -24,8 +24,8 @@
#include <string.h>
#include "dh-book.h"
+#include "dh-book-manager.h"
#include "dh-util.h"
-#include "dh-app.h"
#include "dh-settings.h"
static GtkWidget *prefs_dialog = NULL;
@@ -40,13 +40,6 @@ enum {
};
typedef struct {
- DhBookManager *book_manager;
-
- /* signals */
- gulong book_created_id;
- gulong book_deleted_id;
- gulong group_by_language_id;
-
/* Fonts tab */
GtkCheckButton *system_fonts_button;
GtkGrid *fonts_grid;
@@ -67,21 +60,6 @@ typedef struct {
G_DEFINE_TYPE_WITH_PRIVATE (DhPreferences, dh_preferences, GTK_TYPE_DIALOG)
static void
-dh_preferences_finalize (GObject *object)
-{
- DhPreferencesPrivate *priv;
-
- priv = dh_preferences_get_instance_private (DH_PREFERENCES (object));
-
- g_signal_handler_disconnect (priv->book_manager, priv->book_created_id);
- g_signal_handler_disconnect (priv->book_manager, priv->book_deleted_id);
- g_signal_handler_disconnect (priv->book_manager, priv->group_by_language_id);
- g_clear_object (&priv->book_manager);
-
- G_OBJECT_CLASS (dh_preferences_parent_class)->finalize (object);
-}
-
-static void
dh_preferences_response (GtkDialog *dlg,
gint response_id)
{
@@ -91,12 +69,9 @@ dh_preferences_response (GtkDialog *dlg,
static void
dh_preferences_class_init (DhPreferencesClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (klass);
- object_class->finalize = dh_preferences_finalize;
-
dialog_class->response = dh_preferences_response;
/* Bind class to template */
@@ -417,14 +392,15 @@ preferences_bookshelf_add_book_to_store (DhPreferences *prefs,
static void
preferences_bookshelf_populate_store (DhPreferences *prefs)
{
- DhPreferencesPrivate *priv = dh_preferences_get_instance_private (prefs);
+ DhBookManager *book_manager;
GList *l;
gboolean group_by_language;
- group_by_language = dh_book_manager_get_group_by_language (priv->book_manager);
+ book_manager = dh_book_manager_get_singleton ();
+ group_by_language = dh_book_manager_get_group_by_language (book_manager);
/* This list already comes ordered, but we don't care */
- for (l = dh_book_manager_get_books (priv->book_manager);
+ for (l = dh_book_manager_get_books (book_manager);
l;
l = g_list_next (l)) {
preferences_bookshelf_add_book_to_store (prefs,
@@ -532,11 +508,9 @@ preferences_bookshelf_book_created_cb (DhBookManager *book_manager,
GObject *book_object,
DhPreferences *prefs)
{
- DhPreferencesPrivate *priv = dh_preferences_get_instance_private (prefs);
-
preferences_bookshelf_add_book_to_store (prefs,
DH_BOOK (book_object),
- dh_book_manager_get_group_by_language (priv->book_manager));
+ dh_book_manager_get_group_by_language (book_manager));
}
static void
@@ -545,8 +519,11 @@ preferences_bookshelf_tree_selection_toggled_cb (GtkCellRendererToggle *cell_ren
DhPreferences *prefs)
{
DhPreferencesPrivate *priv = dh_preferences_get_instance_private (prefs);
+ DhBookManager *book_manager;
GtkTreeIter iter;
+ book_manager = dh_book_manager_get_singleton ();
+
if (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (priv->bookshelf_store),
&iter,
path)) {
@@ -568,7 +545,7 @@ preferences_bookshelf_tree_selection_toggled_cb (GtkCellRendererToggle *cell_ren
-1);
/* Now we need to look for the language group of this item,
* in order to set the inconsistent state if applies */
- if (dh_book_manager_get_group_by_language (priv->book_manager)) {
+ if (dh_book_manager_get_group_by_language (book_manager)) {
preferences_bookshelf_set_language_inconsistent (prefs, dh_book_get_language
(book));
}
@@ -576,7 +553,7 @@ preferences_bookshelf_tree_selection_toggled_cb (GtkCellRendererToggle *cell_ren
GtkTreeIter loop_iter;
/* We should only reach this if we are grouping by language */
- g_assert (dh_book_manager_get_group_by_language (priv->book_manager) == TRUE);
+ g_assert (dh_book_manager_get_group_by_language (book_manager) == TRUE);
/* Set new status in the language group item */
gtk_list_store_set (priv->bookshelf_store, &iter,
@@ -613,7 +590,7 @@ static void
dh_preferences_init (DhPreferences *prefs)
{
DhPreferencesPrivate *priv;
- GApplication *app;
+ DhBookManager *book_manager;
DhSettings *settings;
GSettings *settings_fonts;
GSettings *settings_contents;
@@ -622,21 +599,25 @@ dh_preferences_init (DhPreferences *prefs)
gtk_widget_init_template (GTK_WIDGET (prefs));
- app = g_application_get_default ();
-
- priv->book_manager = g_object_ref (dh_app_peek_book_manager (DH_APP (app)));
- priv->book_created_id = g_signal_connect (priv->book_manager,
- "book-created",
- G_CALLBACK (preferences_bookshelf_book_created_cb),
- prefs);
- priv->book_deleted_id = g_signal_connect (priv->book_manager,
- "book-deleted",
- G_CALLBACK (preferences_bookshelf_book_deleted_cb),
- prefs);
- priv->group_by_language_id = g_signal_connect (priv->book_manager,
- "notify::group-by-language",
- G_CALLBACK
(preferences_bookshelf_group_by_language_cb),
- prefs);
+ book_manager = dh_book_manager_get_singleton ();
+
+ g_signal_connect_object (book_manager,
+ "book-created",
+ G_CALLBACK (preferences_bookshelf_book_created_cb),
+ prefs,
+ 0);
+
+ g_signal_connect_object (book_manager,
+ "book-deleted",
+ G_CALLBACK (preferences_bookshelf_book_deleted_cb),
+ prefs,
+ 0);
+
+ g_signal_connect_object (book_manager,
+ "notify::group-by-language",
+ G_CALLBACK (preferences_bookshelf_group_by_language_cb),
+ prefs,
+ 0);
/* setup GSettings bindings */
settings = dh_settings_get_singleton ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]