[devhelp/aleksander/profiles: 1/4] profile: new 'DhProfile' to handle profiles
- From: Aleksander Morgado <aleksm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [devhelp/aleksander/profiles: 1/4] profile: new 'DhProfile' to handle profiles
- Date: Thu, 1 May 2014 16:40:12 +0000 (UTC)
commit 10514a32f7f7abbe2c44ff2a7f05b2ee777152c0
Author: Aleksander Morgado <aleksander aleksander es>
Date: Wed Apr 30 17:52:34 2014 +0200
profile: new 'DhProfile' to handle profiles
Single book manager supported for now.
src/Makefile.am | 4 +-
src/dh-app.c | 28 ++++--
src/dh-app.h | 4 +-
src/dh-assistant.c | 2 +-
src/dh-book-manager.c | 15 +---
src/dh-book-manager.h | 3 +-
src/dh-preferences.c | 2 +-
src/dh-profile.c | 238 +++++++++++++++++++++++++++++++++++++++++++++++++
src/dh-profile.h | 60 ++++++++++++
src/dh-window.c | 4 +-
10 files changed, 332 insertions(+), 28 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 43d4096..403d699 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -52,6 +52,7 @@ INST_H_FILES = \
dh-assistant.h \
dh-assistant-view.h \
dh-book-manager.h \
+ dh-profile.h \
dh-language.h \
dh-book.h \
dh-book-tree.h \
@@ -71,7 +72,8 @@ libdevhelp_3_la_SOURCES = \
dh-assistant.c \
dh-assistant-view.c \
dh-book-manager.c \
- dh-common.c \
+ dh-profile.c \
+ dh-common.c \
dh-language.c \
dh-book.c \
dh-book-tree.c \
diff --git a/src/dh-app.c b/src/dh-app.c
index 411a59d..9dbf567 100644
--- a/src/dh-app.c
+++ b/src/dh-app.c
@@ -25,19 +25,23 @@
#include "devhelp.h"
#include "dh-app.h"
+#include "dh-profile.h"
#include "dh-preferences.h"
#include "dh-util.h"
typedef struct {
- DhBookManager *book_manager;
+ /* Local profile, always available */
+ DhProfile *local;
+ /* Currently selected profile */
+ DhProfile *current;
} DhAppPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (DhApp, dh_app, GTK_TYPE_APPLICATION);
/******************************************************************************/
-DhBookManager *
-dh_app_peek_book_manager (DhApp *app)
+DhProfile *
+dh_app_peek_profile (DhApp *app)
{
DhAppPrivate *priv;
@@ -45,7 +49,7 @@ dh_app_peek_book_manager (DhApp *app)
priv = dh_app_get_instance_private (app);
- return priv->book_manager;
+ return priv->current;
}
GtkWindow *
@@ -373,9 +377,16 @@ dh_app_startup (GApplication *application)
/* Setup accelerators */
setup_accelerators (app);
- /* Load the book manager */
- priv->book_manager = dh_book_manager_new ();
- dh_book_manager_populate (priv->book_manager);
+ /* Load the local profile */
+ priv->local = dh_profile_new (_("Local"), g_get_system_data_dirs ());
+
+ /* TODO: when mutiple profiles available, look for the last used one and
+ * mark it as current */
+
+ if (!priv->current) {
+ priv->current = g_object_ref (priv->local);
+ dh_profile_populate (priv->current);
+ }
}
/******************************************************************************/
@@ -405,7 +416,8 @@ dh_app_dispose (GObject *object)
DhApp *app = DH_APP (object);
DhAppPrivate *priv = dh_app_get_instance_private (app);
- g_clear_object (&priv->book_manager);
+ g_clear_object (&priv->current);
+ g_clear_object (&priv->local);
G_OBJECT_CLASS (dh_app_parent_class)->dispose (object);
}
diff --git a/src/dh-app.h b/src/dh-app.h
index 9280f65..5c878c1 100644
--- a/src/dh-app.h
+++ b/src/dh-app.h
@@ -21,7 +21,7 @@
#include <gtk/gtk.h>
-#include "dh-book-manager.h"
+#include "dh-profile.h"
G_BEGIN_DECLS
@@ -47,7 +47,7 @@ GType dh_app_get_type (void) G_GNUC_CONST;
DhApp *dh_app_new (void);
-DhBookManager *dh_app_peek_book_manager (DhApp *self);
+DhProfile *dh_app_peek_profile (DhApp *self);
GtkWindow *dh_app_peek_first_window (DhApp *self);
GtkWindow *dh_app_peek_assistant (DhApp *self);
diff --git a/src/dh-assistant.c b/src/dh-assistant.c
index 39adef9..916c60f 100644
--- a/src/dh-assistant.c
+++ b/src/dh-assistant.c
@@ -129,7 +129,7 @@ dh_assistant_new (DhApp *application)
priv = dh_assistant_get_instance_private (DH_ASSISTANT (assistant));
dh_assistant_view_set_book_manager (DH_ASSISTANT_VIEW (priv->view),
- dh_app_peek_book_manager (application));
+ dh_profile_peek_book_manager (dh_app_peek_profile
(application)));
return assistant;
}
diff --git a/src/dh-book-manager.c b/src/dh-book-manager.c
index a8e1ad2..676f8a2 100644
--- a/src/dh-book-manager.c
+++ b/src/dh-book-manager.c
@@ -329,19 +329,10 @@ book_manager_add_books_in_data_dir (DhBookManager *book_manager,
}
void
-dh_book_manager_populate (DhBookManager *book_manager)
+dh_book_manager_populate (DhBookManager *book_manager,
+ const gchar *path)
{
- const gchar * const * system_dirs;
-
- book_manager_add_books_in_data_dir (book_manager,
- g_get_user_data_dir ());
-
- system_dirs = g_get_system_data_dirs ();
- while (*system_dirs) {
- book_manager_add_books_in_data_dir (book_manager,
- *system_dirs);
- system_dirs++;
- }
+ book_manager_add_books_in_data_dir (book_manager, path);
}
static gchar *
diff --git a/src/dh-book-manager.h b/src/dh-book-manager.h
index 148aded..47f6268 100644
--- a/src/dh-book-manager.h
+++ b/src/dh-book-manager.h
@@ -45,7 +45,8 @@ struct _DhBookManagerClass {
GType dh_book_manager_get_type (void) G_GNUC_CONST;
DhBookManager *dh_book_manager_new (void);
-void dh_book_manager_populate (DhBookManager *book_manager);
+void dh_book_manager_populate (DhBookManager *book_manager,
+ const gchar *path);
GList *dh_book_manager_get_books (DhBookManager *book_manager);
GList *dh_book_manager_get_languages (DhBookManager *book_manager);
diff --git a/src/dh-preferences.c b/src/dh-preferences.c
index 5ebbe10..7cab273 100644
--- a/src/dh-preferences.c
+++ b/src/dh-preferences.c
@@ -625,7 +625,7 @@ dh_preferences_init (DhPreferences *prefs)
app = g_application_get_default ();
priv->settings = dh_settings_get ();
- priv->book_manager = g_object_ref (dh_app_peek_book_manager (DH_APP (app)));
+ priv->book_manager = g_object_ref (dh_profile_peek_book_manager (dh_app_peek_profile (DH_APP
(app))));
priv->book_created_id = g_signal_connect (priv->book_manager,
"book-created",
G_CALLBACK (preferences_bookshelf_book_created_cb),
diff --git a/src/dh-profile.c b/src/dh-profile.c
new file mode 100644
index 0000000..2ff9938
--- /dev/null
+++ b/src/dh-profile.c
@@ -0,0 +1,238 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2014 Aleksander Morgado <aleksander aleksander es>
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+#include <string.h>
+
+#include "dh-profile.h"
+#include "dh-book-manager.h"
+
+typedef struct {
+ /* Profile setup */
+ gchar *id;
+ gchar *name;
+ gchar **paths;
+ /* The book manager of the profile */
+ DhBookManager *book_manager;
+} DhProfilePrivate;
+
+enum {
+ PROP_0,
+ PROP_ID,
+ PROP_NAME,
+ PROP_PATHS,
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (DhProfile, dh_profile, G_TYPE_OBJECT)
+
+/******************************************************************************/
+
+void
+dh_profile_populate (DhProfile *self)
+{
+ DhProfilePrivate *priv;
+ guint i;
+
+ priv = dh_profile_get_instance_private (self);
+
+ for (i = 0; priv->paths[i]; i++)
+ dh_book_manager_populate (priv->book_manager, priv->paths[i]);
+}
+
+/******************************************************************************/
+
+DhBookManager *
+dh_profile_peek_book_manager (DhProfile *self)
+{
+ DhProfilePrivate *priv;
+
+ priv = dh_profile_get_instance_private (self);
+
+ return priv->book_manager;
+}
+
+const gchar *
+dh_profile_get_id (DhProfile *self)
+{
+ DhProfilePrivate *priv;
+
+ priv = dh_profile_get_instance_private (self);
+
+ return priv->id;
+}
+
+const gchar *
+dh_profile_get_name (DhProfile *self)
+{
+ DhProfilePrivate *priv;
+
+ priv = dh_profile_get_instance_private (self);
+
+ return priv->name;
+}
+
+const gchar * const *
+dh_profile_get_paths (DhProfile *self)
+{
+ DhProfilePrivate *priv;
+
+ priv = dh_profile_get_instance_private (self);
+
+ return (const gchar * const *)priv->paths;
+}
+
+/******************************************************************************/
+
+DhProfile *
+dh_profile_new (const gchar *id,
+ const gchar *name,
+ const gchar *const *paths)
+{
+ return g_object_new (DH_TYPE_PROFILE,
+ "id", id,
+ "name", name,
+ "paths", paths,
+ NULL);
+}
+
+static void
+dh_profile_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ DhProfilePrivate *priv;
+
+ priv = dh_profile_get_instance_private (DH_PROFILE (object));
+
+ switch (prop_id)
+ {
+ case PROP_ID:
+ priv->id = g_value_dup_string (value);
+ break;
+ case PROP_NAME:
+ priv->name = g_value_dup_string (value);
+ break;
+ case PROP_PATHS:
+ priv->paths = g_value_dup_boxed (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+dh_profile_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ DhProfilePrivate *priv;
+
+ priv = dh_profile_get_instance_private (DH_PROFILE (object));
+
+ switch (prop_id)
+ {
+ case PROP_ID:
+ g_value_set_string (value, priv->id);
+ break;
+ case PROP_NAME:
+ g_value_set_string (value, priv->name);
+ break;
+ case PROP_PATHS:
+ g_value_set_boxed (value, priv->paths);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+dh_profile_finalize (GObject *object)
+{
+ DhProfilePrivate *priv;
+
+ priv = dh_profile_get_instance_private (DH_PROFILE (object));
+
+ g_free (priv->id);
+ g_free (priv->name);
+ g_strfreev (priv->paths);
+
+ G_OBJECT_CLASS (dh_profile_parent_class)->finalize (object);
+}
+
+static void
+dh_profile_dispose (GObject *object)
+{
+ DhProfilePrivate *priv;
+
+ priv = dh_profile_get_instance_private (DH_PROFILE (object));
+
+ g_clear_object (&priv->book_manager);
+
+ G_OBJECT_CLASS (dh_profile_parent_class)->dispose (object);
+}
+
+static void
+dh_profile_init (DhProfile *object)
+{
+ DhProfilePrivate *priv;
+
+ priv = dh_profile_get_instance_private (DH_PROFILE (object));
+
+ priv->book_manager = dh_book_manager_new ();
+}
+
+static void
+dh_profile_class_init (DhProfileClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->set_property = dh_profile_set_property;
+ object_class->get_property = dh_profile_get_property;
+ object_class->finalize = dh_profile_finalize;
+ object_class->dispose = dh_profile_dispose;
+
+ g_object_class_install_property (object_class,
+ PROP_ID,
+ g_param_spec_string ("id", "ID", "Profile ID",
+ NULL,
+ (G_PARAM_READWRITE |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_NICK |
+ G_PARAM_STATIC_BLURB)));
+
+ g_object_class_install_property (object_class,
+ PROP_NAME,
+ g_param_spec_string ("name", "Name", "Profile name",
+ NULL,
+ (G_PARAM_READWRITE |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_NICK |
+ G_PARAM_STATIC_BLURB)));
+ g_object_class_install_property (object_class,
+ PROP_PATHS,
+ g_param_spec_boxed ("paths", "Paths", "Profile paths",
+ G_TYPE_STRV,
+ (G_PARAM_READWRITE |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_NICK |
+ G_PARAM_STATIC_BLURB)));
+}
diff --git a/src/dh-profile.h b/src/dh-profile.h
new file mode 100644
index 0000000..25df9a9
--- /dev/null
+++ b/src/dh-profile.h
@@ -0,0 +1,60 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2014 Aleksander Morgado <aleksander aleksander es>
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __DH_PROFILE_H__
+#define __DH_PROFILE_H__
+
+#include <gtk/gtk.h>
+
+#include "dh-book-manager.h"
+
+G_BEGIN_DECLS
+
+typedef struct _DhProfile DhProfile;
+typedef struct _DhProfileClass DhProfileClass;
+
+#define DH_TYPE_PROFILE (dh_profile_get_type ())
+#define DH_PROFILE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), DH_TYPE_PROFILE, DhProfile))
+#define DH_PROFILE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), DH_TYPE_PROFILE, DhProfileClass))
+#define DH_IS_PROFILE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), DH_TYPE_PROFILE))
+#define DH_IS_PROFILE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), DH_TYPE_PROFILE))
+#define DH_PROFILE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), DH_TYPE_PROFILE, DhProfileClass))
+
+struct _DhProfile {
+ GObject parent_instance;
+};
+
+struct _DhProfileClass {
+ GObjectClass parent_class;
+};
+
+GType dh_profile_get_type (void) G_GNUC_CONST;
+DhProfile *dh_profile_new (const gchar *id,
+ const gchar *name,
+ const gchar * const *paths);
+void dh_profile_populate (DhProfile *self);
+
+const gchar *dh_profile_get_id (DhProfile *self);
+const gchar *dh_profile_get_name (DhProfile *self);
+const gchar *const *dh_profile_get_paths (DhProfile *self);
+DhBookManager *dh_profile_peek_book_manager (DhProfile *self);
+
+
+G_END_DECLS
+
+#endif /* __DH_PROFILE_H__ */
diff --git a/src/dh-window.c b/src/dh-window.c
index 4f558db..73d2f11 100644
--- a/src/dh-window.c
+++ b/src/dh-window.c
@@ -664,7 +664,7 @@ window_populate (DhWindow *window)
const char *prev_icon, *next_icon;
priv = dh_window_get_instance_private (window);
- book_manager = dh_app_peek_book_manager (DH_APP (gtk_window_get_application (GTK_WINDOW (window))));
+ book_manager = dh_profile_peek_book_manager (dh_app_peek_profile (DH_APP (gtk_window_get_application
(GTK_WINDOW (window)))));
if (gtk_widget_get_direction (GTK_WIDGET (window)) == GTK_TEXT_DIR_RTL) {
prev_icon = "go-previous-rtl-symbolic";
@@ -746,7 +746,7 @@ find_library_equivalent (DhWindow *window,
book_id = components[4];
filename = components[6];
- book_manager = dh_app_peek_book_manager (DH_APP (gtk_window_get_application (GTK_WINDOW (window))));
+ book_manager = dh_profile_peek_book_manager (dh_app_peek_profile (DH_APP (gtk_window_get_application
(GTK_WINDOW (window)))));
/* use list pointer to iterate */
for (books = dh_book_manager_get_books (book_manager);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]