From: Mario Rugiero <mrugi...@gmail.com>

FDO, AFAICT, doesn't impose a folder with the theme name
in the root of the package.
In particular, the theme in [0] does not do that, relying
on having index.theme on its root.
Such a package silently failed to install.
By treating root as a special case, it got installed properly.
As a regression test, the theme [1] was tested.

[0]: https://www.gnome-look.org/content/show.php/Shadow?content=170398
[1]: https://www.gnome-look.org/p/1243493/
---
 src/utils.c | 67 +++++++++++++++++++++++++++++++++++------------------
 1 file changed, 44 insertions(+), 23 deletions(-)

diff --git a/src/utils.c b/src/utils.c
index 09d356d..11633bc 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -169,35 +169,56 @@ _failed:
             dir = g_dir_open(tmp_dir, 0, NULL);
             if(dir)
             {
-                const char* name;
-                while((name = g_dir_read_name(dir)) != NULL)
+                const gchar* name;
+                gboolean is_theme;
+                char* index_theme;
+
+                /* NOTE: the root directory is a special case */
+                name = "";
+                index_theme = g_build_filename(tmp_dir, name, "index.theme", 
NULL);
+                is_theme = g_file_test(index_theme, G_FILE_TEST_EXISTS);
+                g_free(index_theme);
+
+                while(!is_theme && ((name = g_dir_read_name(dir)) != NULL))
                 {
-                    char* index_theme = g_build_filename(tmp_dir, name, 
"index.theme", NULL);
-                    gboolean is_theme = g_file_test(index_theme, 
G_FILE_TEST_EXISTS);
+                    index_theme = g_build_filename(tmp_dir, name, 
"index.theme", NULL);
+                    is_theme = g_file_test(index_theme, G_FILE_TEST_EXISTS);
                     g_free(index_theme);
-                    if(is_theme)
+                }
+
+                if(is_theme)
+                {
+                    char* theme_tmp = g_build_filename(tmp_dir, name, NULL);
+                    /* NOTE: quick and dirty name heuristic for when all the
+                     * files are dropped at the root of the package, just
+                     * name it as the package itself.
+                     * Leaving them polluting the $XDG_DATA_HOME seemed like
+                     * a bad idea.
+                     */
+                    gchar* target_name = g_strcmp0("", name) ?
+                                         g_strdup(name) :
+                                         g_path_get_basename(package_path);
+                    char* theme_target = g_build_filename(user_icons_dir, 
target_name, NULL);
+
+                    if(g_rename(theme_tmp, theme_target) == 0)
                     {
-                        char* theme_tmp = g_build_filename(tmp_dir, name, 
NULL);
-                        char* theme_target = g_build_filename(user_icons_dir, 
name, NULL);
-                        if(g_rename(theme_tmp, theme_target) == 0)
-                        {
-                            /* the theme is now installed to 
$XDG_DATA_HOME/icons */
-                            GSList* l= g_slist_find_custom(app.icon_themes, 
name, (GCompareFunc)icon_theme_cmp_name);
-                            if(l)
-                            {
-                                IconTheme* theme = (IconTheme*)l->data;
-                                g_debug("installed theme: %p, %s", theme, 
theme->name);
-                                /* update UI */
-                                insert_theme_to_models(theme);
-                            }
-                        }
-                        else
+                        /* the theme is now installed to $XDG_DATA_HOME/icons 
*/
+                        GSList* l= g_slist_find_custom(app.icon_themes, 
target_name, (GCompareFunc)icon_theme_cmp_name);
+                        if(l)
                         {
-                            /* errors happened */
+                            IconTheme* theme = (IconTheme*)l->data;
+                            g_debug("installed theme: %p, %s", theme, 
theme->name);
+                            /* update UI */
+                            insert_theme_to_models(theme);
                         }
-                        g_free(theme_target);
-                        g_free(theme_tmp);
                     }
+                    else
+                    {
+                        /* errors happened */
+                    }
+                    g_free(target_name);
+                    g_free(theme_target);
+                    g_free(theme_tmp);
                 }
                 g_dir_close(dir);
 
-- 
2.17.1



_______________________________________________
Lxde-list mailing list
Lxde-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxde-list

Reply via email to