[evolution-data-server/openismus-work-3-8] EBookBackendFile: Implement EBookBackend->set_locale() & ->get_locale()



commit 87efc5c00d952a0a17885cfce37ec62fd7b74bea
Author: Tristan Van Berkom <tristanvb openismus com>
Date:   Thu May 23 16:26:26 2013 +0900

    EBookBackendFile: Implement EBookBackend->set_locale() & ->get_locale()

 addressbook/backends/file/e-book-backend-file.c |   50 +++++++++++++++++++++++
 1 files changed, 50 insertions(+), 0 deletions(-)
---
diff --git a/addressbook/backends/file/e-book-backend-file.c b/addressbook/backends/file/e-book-backend-file.c
index 2a6afa2..89533da 100644
--- a/addressbook/backends/file/e-book-backend-file.c
+++ b/addressbook/backends/file/e-book-backend-file.c
@@ -79,6 +79,7 @@ struct _EBookBackendFilePrivate {
        gchar     *base_directory;
        gchar     *photo_dirname;
        gchar     *revision;
+       gchar     *locale;
        gint       rev_counter;
        gboolean   revision_guards;
        GRWLock    lock;
@@ -666,6 +667,22 @@ e_book_backend_file_load_revision (EBookBackendFile *bf)
 }
 
 static void
+e_book_backend_file_load_locale (EBookBackendFile *bf)
+{
+       GError *error = NULL;
+
+       if (!e_book_backend_sqlitedb_get_locale (bf->priv->sqlitedb,
+                                                SQLITEDB_FOLDER_ID,
+                                                &bf->priv->locale,
+                                                &error)) {
+               g_warning (
+                       G_STRLOC ": Error loading database locale setting: %s",
+                       error ? error->message : "Unknown error");
+               g_clear_error (&error);
+       }
+}
+
+static void
 set_revision (EBookBackendFile *bf,
               EContact *contact)
 {
@@ -1496,6 +1513,7 @@ e_book_backend_file_finalize (GObject *object)
 
        g_free (priv->photo_dirname);
        g_free (priv->revision);
+       g_free (priv->locale);
        g_free (priv->base_directory);
        g_rw_lock_clear (&(priv->lock));
 
@@ -1503,6 +1521,33 @@ e_book_backend_file_finalize (GObject *object)
        G_OBJECT_CLASS (e_book_backend_file_parent_class)->finalize (object);
 }
 
+static void
+e_book_backend_file_set_locale (EBookBackend *backend,
+                               const gchar  *locale)
+{
+       EBookBackendFile *bf = E_BOOK_BACKEND_FILE (backend);
+       GError *error = NULL;
+
+       if (!e_book_backend_sqlitedb_set_locale (bf->priv->sqlitedb,
+                                                SQLITEDB_FOLDER_ID,
+                                                locale,
+                                                &error)) {
+               g_free (bf->priv->locale);
+               bf->priv->locale = g_strdup (locale);
+
+               g_warning ("Failed to set locale on SQLiteDB: %s", error->message);
+               g_error_free (error);
+       }
+}
+
+static const gchar *
+e_book_backend_file_get_locale (EBookBackend *backend)
+{
+       EBookBackendFile *bf = E_BOOK_BACKEND_FILE (backend);
+
+       return bf->priv->locale;
+}
+
 static gboolean
 book_backend_file_initable_init (GInitable *initable,
                                  GCancellable *cancellable,
@@ -1623,6 +1668,9 @@ book_backend_file_initable_init (GInitable *initable,
                }
        }
 
+       /* Load the locale */
+       e_book_backend_file_load_locale (E_BOOK_BACKEND_FILE (initable));
+
        /* Resolve the photo directory here. */
        priv->photo_dirname =
                e_book_backend_file_extract_path_from_source (
@@ -1696,6 +1744,8 @@ e_book_backend_file_class_init (EBookBackendFileClass *class)
        backend_class->notify_update            = e_book_backend_file_notify_update;
        backend_class->get_direct_book          = e_book_backend_file_get_direct_book;
        backend_class->configure_direct         = e_book_backend_file_configure_direct;
+       backend_class->set_locale               = e_book_backend_file_set_locale;
+       backend_class->get_locale               = e_book_backend_file_get_locale;
 
        sync_class->open_sync                   = e_book_backend_file_open;
        sync_class->get_backend_property_sync   = e_book_backend_file_get_backend_property;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]