[evolution/wip/webkit2] Make it easier to change evolution .ui files by the users



commit f71e75d3c878b47ea8461ac1f5563282ada0d1f6
Author: Milan Crha <mcrha redhat com>
Date:   Thu Jun 30 22:52:13 2016 +0200

    Make it easier to change evolution .ui files by the users
    
    The main problems used to be that the .ui file definitions were stored
    in a system directory and that an evolution update overwrote any changes
    there.
    
    Since now on, the .ui files are versioned and they can be copied into
    ~/.config/evolution/ui/ and modified there. The evolution will use those
    files as long as their version will match the version of the file
    in the system directory (it's the "evolution-ui-version" attribute
    of the root "ui" element). In case the versions do not match,
    the system file will be used instead and a warning about version
    mismatch will be printed on the console, thus the users can notice
    the change and either update their file or remove it, as needed.

 e-util/e-misc-utils.c       |   65 +++++++++++++++++++++++++++++++++++++++++-
 ui/evolution-calendars.ui   |    2 +-
 ui/evolution-contacts.ui    |    2 +-
 ui/evolution-mail-reader.ui |    2 +-
 ui/evolution-mail.ui        |    2 +-
 ui/evolution-memos.ui       |    2 +-
 ui/evolution-shell.ui       |    2 +-
 ui/evolution-tasks.ui       |    2 +-
 8 files changed, 70 insertions(+), 9 deletions(-)
---
diff --git a/e-util/e-misc-utils.c b/e-util/e-misc-utils.c
index 3f51e46..3dcc7f0 100644
--- a/e-util/e-misc-utils.c
+++ b/e-util/e-misc-utils.c
@@ -55,8 +55,9 @@
 #include "e-alert-sink.h"
 #include "e-client-cache.h"
 #include "e-filter-option.h"
-#include "e-util-private.h"
 #include "e-mktemp.h"
+#include "e-util-private.h"
+#include "e-xml-utils.h"
 
 typedef struct _WindowData WindowData;
 
@@ -762,6 +763,66 @@ e_load_ui_builder_definition (GtkBuilder *builder,
        }
 }
 
+static gdouble
+e_get_ui_manager_definition_file_version (const gchar *filename)
+{
+       xmlDocPtr doc;
+       xmlNode *root;
+       gdouble version = -1.0;
+
+       g_return_val_if_fail (filename != NULL, version);
+
+       doc = e_xml_parse_file (filename);
+       if (!doc)
+               return version;
+
+       root = xmlDocGetRootElement (doc);
+       if (root && g_strcmp0 ((const gchar *) root->name, "ui") == 0) {
+               version = e_xml_get_double_prop_by_name_with_default (root, (const xmlChar *) 
"evolution-ui-version", -1.0);
+       }
+
+       xmlFreeDoc (doc);
+
+       return version;
+}
+
+static gchar *
+e_pick_ui_manager_definition_file (const gchar *basename)
+{
+       gchar *system_filename, *user_filename;
+       gdouble system_version, user_version;
+
+       g_return_val_if_fail (basename != NULL, NULL);
+
+       system_filename = g_build_filename (EVOLUTION_UIDIR, basename, NULL);
+       user_filename = g_build_filename (e_get_user_config_dir (), "ui", basename, NULL);
+
+       if (!g_file_test (user_filename, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
+               g_free (user_filename);
+
+               return system_filename;
+       }
+
+       user_version = e_get_ui_manager_definition_file_version (user_filename);
+       system_version = e_get_ui_manager_definition_file_version (system_filename);
+
+       /* Versions are equal and the system version is a positive number */
+       if (user_version - system_version >= -1e-9 &&
+           user_version - system_version <= 1e-9 &&
+           system_version > 1e-9) {
+               g_free (system_filename);
+
+               return user_filename;
+       }
+
+       g_warning ("User's UI file '%s' version (%.1f) doesn't match expected version (%.1f), skipping it. 
Either correct the version or remove the file.",
+               user_filename, user_version, system_version);
+
+       g_free (user_filename);
+
+       return system_filename;
+}
+
 /**
  * e_load_ui_manager_definition:
  * @ui_manager: a #GtkUIManager
@@ -785,7 +846,7 @@ e_load_ui_manager_definition (GtkUIManager *ui_manager,
        g_return_val_if_fail (GTK_IS_UI_MANAGER (ui_manager), 0);
        g_return_val_if_fail (basename != NULL, 0);
 
-       filename = g_build_filename (EVOLUTION_UIDIR, basename, NULL);
+       filename = e_pick_ui_manager_definition_file (basename);
        merge_id = gtk_ui_manager_add_ui_from_file (
                ui_manager, filename, &error);
        g_free (filename);
diff --git a/ui/evolution-calendars.ui b/ui/evolution-calendars.ui
index bef4b85..580764c 100644
--- a/ui/evolution-calendars.ui
+++ b/ui/evolution-calendars.ui
@@ -1,4 +1,4 @@
-<ui>
+<ui evolution-ui-version="1.0">
   <menubar name='main-menu'>
     <menu action='file-menu'>
       <placeholder name='file-actions'>
diff --git a/ui/evolution-contacts.ui b/ui/evolution-contacts.ui
index a153998..1e2679c 100644
--- a/ui/evolution-contacts.ui
+++ b/ui/evolution-contacts.ui
@@ -1,4 +1,4 @@
-<ui>
+<ui evolution-ui-version="1.0">
   <menubar name='main-menu'>
     <menu action='file-menu'>
       <placeholder name='file-actions'>
diff --git a/ui/evolution-mail-reader.ui b/ui/evolution-mail-reader.ui
index a3b878f..d005a1e 100644
--- a/ui/evolution-mail-reader.ui
+++ b/ui/evolution-mail-reader.ui
@@ -1,4 +1,4 @@
-<ui>
+<ui evolution-ui-version="1.0">
   <menubar name='main-menu'>
     <menu action='file-menu'>
       <placeholder name='file-actions'>
diff --git a/ui/evolution-mail.ui b/ui/evolution-mail.ui
index ccff82d..322c83b 100644
--- a/ui/evolution-mail.ui
+++ b/ui/evolution-mail.ui
@@ -1,4 +1,4 @@
-<ui>
+<ui evolution-ui-version="1.0">
   <menubar name='main-menu'>
     <menu action='file-menu'>
       <placeholder name='mail-send-receiver'>
diff --git a/ui/evolution-memos.ui b/ui/evolution-memos.ui
index 0a2c3d8..6ad5399 100644
--- a/ui/evolution-memos.ui
+++ b/ui/evolution-memos.ui
@@ -1,4 +1,4 @@
-<ui>
+<ui evolution-ui-version="1.0">
   <menubar name='main-menu'>
     <menu action='file-menu'>
       <placeholder name='file-actions'>
diff --git a/ui/evolution-shell.ui b/ui/evolution-shell.ui
index c7a5320..bc7e349 100644
--- a/ui/evolution-shell.ui
+++ b/ui/evolution-shell.ui
@@ -1,4 +1,4 @@
-<ui>
+<ui evolution-ui-version="1.0">
   <menubar name='main-menu'>
     <menu action='file-menu'>
       <menu action='new-menu'/>
diff --git a/ui/evolution-tasks.ui b/ui/evolution-tasks.ui
index acef77f..494f271 100644
--- a/ui/evolution-tasks.ui
+++ b/ui/evolution-tasks.ui
@@ -1,4 +1,4 @@
-<ui>
+<ui evolution-ui-version="1.0">
   <menubar name='main-menu'>
     <menu action='file-menu'>
       <placeholder name='file-actions'>


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