[aisleriot] theme: svg: Add support for loading user-installed themes



commit e26fbb651193175fa4f720bdb8cd371c67e3fe43
Author: Christian Persch <chpe src gnome org>
Date:   Wed Feb 16 20:45:30 2022 +0100

    theme: svg: Add support for loading user-installed themes
    
    Look for themes in .local/share/aisleriot/cards.
    
    https://gitlab.gnome.org/GNOME/aisleriot/-/issues/268

 src/lib/ar-card-theme-private.h |  4 ++++
 src/lib/ar-card-theme-svg.c     | 10 ++++++++--
 src/lib/ar-card-theme.c         | 17 +++++++++++++++++
 3 files changed, 29 insertions(+), 2 deletions(-)
---
diff --git a/src/lib/ar-card-theme-private.h b/src/lib/ar-card-theme-private.h
index 426ab732..d0907b47 100644
--- a/src/lib/ar-card-theme-private.h
+++ b/src/lib/ar-card-theme-private.h
@@ -115,6 +115,10 @@ gboolean _ar_card_theme_class_foreach_env (ArCardThemeClass *klass,
                                               const char *env,
                                               ArCardThemeForeachFunc callback,
                                               gpointer data);
+gboolean _ar_card_theme_class_foreach_user_dir (ArCardThemeClass *klass,
+                                               const char *name,
+                                               ArCardThemeForeachFunc callback,
+                                               gpointer data);
 
 void _ar_card_theme_emit_changed (ArCardTheme *theme);
 
diff --git a/src/lib/ar-card-theme-svg.c b/src/lib/ar-card-theme-svg.c
index 41f7fb6c..2ae69080 100644
--- a/src/lib/ar-card-theme-svg.c
+++ b/src/lib/ar-card-theme-svg.c
@@ -138,8 +138,14 @@ ar_card_theme_svg_class_foreach_theme_dir (ArCardThemeClass *klass,
   /* If we're installed in a non-system prefix, also load the card themes
    * from the system prefix.
    */
-  if (!ar_runtime_is_system_prefix ())
-    return callback (klass, "/usr/share/aisleriot/cards", data);
+  if (!ar_runtime_is_system_prefix ()) {
+    if (!callback (klass, "/usr/share/aisleriot/cards", data))
+      return FALSE;
+  }
+
+  /* Load user-installed themes */
+  if (!_ar_card_theme_class_foreach_user_dir (klass, "cards", callback, data))
+    return FALSE;
 
   return TRUE;
 }
diff --git a/src/lib/ar-card-theme.c b/src/lib/ar-card-theme.c
index 8b80f413..09e62e65 100644
--- a/src/lib/ar-card-theme.c
+++ b/src/lib/ar-card-theme.c
@@ -324,6 +324,23 @@ _ar_card_theme_class_foreach_env (ArCardThemeClass *klass,
   return retval;
 }
 
+gboolean
+_ar_card_theme_class_foreach_user_dir (ArCardThemeClass *klass,
+                                      const char *name,
+                                      ArCardThemeForeachFunc callback,
+                                      gpointer data)
+{
+  const char *udd = g_get_user_data_dir();
+  if (!udd)
+    return TRUE;
+
+  char *path = g_build_filename(udd, "aisleriot", name, NULL);
+  gboolean rv = callback(klass, path, data);
+  g_free(path);
+
+  return rv;
+}
+
 /* public API */
 
 /**


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