elm config - allow the ability to save out to another hidden profile 92/83592/2
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>
Thu, 31 Dec 2015 06:38:20 +0000 (15:38 +0900)
committerHermet Park <chuneon.park@samsung.com>
Fri, 12 Aug 2016 05:58:36 +0000 (22:58 -0700)
support the ability to have hidden profiles that begin with a dot (.)
char like all hidden files/dirs. to do this we need to also be able to
create profiles with a given name (a hidden name) without switching to
them, so add the ability to save out to a specific profile name
without switching to it. of course this means to list profiles we need
to list them or list ALL includiing hidden profiles.

@feature

Change-Id: I9e4f7281e3b2bf2a2054b71573c59d7d15f0e2b2

src/lib/elm_config.c
src/lib/elm_config.h
src/lib/elm_priv.h

index 92bc737..e78370b 100644 (file)
@@ -1012,7 +1012,7 @@ _elm_config_colors_free(const char *palette_name)
 }
 
 Eina_List *
-_elm_config_profiles_list(void)
+_elm_config_profiles_list(Eina_Bool hide_profiles)
 {
    Eina_File_Direct_Info *info;
    Eina_List *flist = NULL;
@@ -1024,8 +1024,7 @@ _elm_config_profiles_list(void)
    len = _elm_config_user_dir_snprintf(buf, sizeof(buf), "config");
 
    file_it = eina_file_stat_ls(buf);
-   if (!file_it)
-     goto sys;
+   if (!file_it) goto sys;
 
    buf[len] = '/';
    len++;
@@ -1034,15 +1033,15 @@ _elm_config_profiles_list(void)
 
    EINA_ITERATOR_FOREACH(file_it, info)
      {
-        if (info->name_length >= len)
-          continue;
+        if (info->name_length >= len) continue;
+        if ((hide_profiles) && (info->path[info->name_start] == '.')) continue;
 
         if (info->type == EINA_FILE_DIR)
           {
              flist =
                eina_list_sorted_insert(flist, _sort_files_cb,
-                                       eina_stringshare_add(info->path +
-                                                            info->name_start));
+                                       eina_stringshare_add
+                                         (info->path + info->name_start));
           }
      }
 
@@ -1054,8 +1053,7 @@ sys:
                            sizeof("config") - 1);
 
    file_it = eina_file_stat_ls(buf);
-   if (!file_it)
-     goto list_free;
+   if (!file_it) goto list_free;
 
    buf[len] = '/';
    len++;
@@ -1063,26 +1061,26 @@ sys:
    len = sizeof(buf) - len;
    EINA_ITERATOR_FOREACH(file_it, info)
      {
-        if (info->name_length >= len)
-          continue;
+        if (info->name_length >= len) continue;
+        if ((hide_profiles) && (info->path[info->name_start] == '.')) continue;
 
         switch (info->type)
           {
            case EINA_FILE_DIR:
-           {
-              const Eina_List *l;
-              const char *tmp;
-
-              EINA_LIST_FOREACH(flist, l, tmp)
-                if (!strcmp(info->path + info->name_start, tmp))
-                  break;
+               {
+                  const Eina_List *l;
+                  const char *tmp;
 
-              if (!l)
-                flist =
-                  eina_list_sorted_insert(flist, _sort_files_cb,
-                                          eina_stringshare_add(info->path +
-                                                               info->name_start));
-           }
+                  EINA_LIST_FOREACH(flist, l, tmp)
+                    {
+                       if (!strcmp(info->path + info->name_start, tmp)) break;
+                    }
+                  if (!l)
+                    flist = eina_list_sorted_insert(flist, _sort_files_cb,
+                                                    eina_stringshare_add
+                                                    (info->path +
+                                                     info->name_start));
+               }
            break;
 
            default:
@@ -1093,9 +1091,7 @@ sys:
    return flist;
 
 list_free:
-   EINA_LIST_FREE(flist, dir)
-     eina_stringshare_del(dir);
-
+   EINA_LIST_FREE(flist, dir) eina_stringshare_del(dir);
    return NULL;
 }
 
@@ -1675,7 +1671,7 @@ err:
 }
 
 Eina_Bool
-_elm_config_save(void)
+_elm_config_save(const char *profile)
 {
    char buf[4096], buf2[4096];
    int ok = 0, ret;
@@ -1696,7 +1692,7 @@ _elm_config_save(void)
      }
 
    len = _elm_config_user_dir_snprintf(buf, sizeof(buf), "config/%s",
-                                       _elm_profile);
+                                       profile ? profile : _elm_profile);
    if (len + 1 >= sizeof(buf))
      return EINA_FALSE;
 
@@ -1708,8 +1704,11 @@ _elm_config_save(void)
         return EINA_FALSE;
      }
 
-   if (!_elm_config_profile_save())
-     return EINA_FALSE;
+   if (!profile)
+     {
+        if (!_elm_config_profile_save())
+          return EINA_FALSE;
+     }
 
    buf[len] = '/';
    len++;
@@ -1851,7 +1850,7 @@ _config_update(void)
    _elm_config->config_version = ELM_CONFIG_VERSION;
    /* after updating user config, we must save */
    _config_free(tcfg);
-   _elm_config_save();
+   _elm_config_save(NULL);
 }
 
 static void
@@ -2352,7 +2351,7 @@ elm_config_password_show_last_timeout_set(double password_show_last_timeout)
 EAPI Eina_Bool
 elm_config_save(void)
 {
-   return _elm_config_save();
+   return _elm_config_save(NULL);
 }
 
 EAPI void
@@ -2383,7 +2382,13 @@ elm_config_profile_dir_free(const char *p_dir)
 EAPI Eina_List *
 elm_config_profile_list_get(void)
 {
-   return _elm_config_profiles_list();
+   return _elm_config_profiles_list(EINA_TRUE);
+}
+
+EAPI Eina_List *
+elm_config_profile_list_full_get(void)
+{
+   return _elm_config_profiles_list(EINA_FALSE);
 }
 
 EAPI void
@@ -2402,6 +2407,14 @@ elm_config_profile_set(const char *profile)
    _elm_config_profile_set(profile);
 }
 
+EAPI void
+elm_config_profile_save(const char *profile)
+{
+   EINA_SAFETY_ON_NULL_RETURN(profile);
+   _elm_config_save(profile);
+}
+
+
 EAPI const char *
 elm_config_engine_get(void)
 {
@@ -3367,6 +3380,7 @@ elm_config_all_flush(void)
      }
 
    ecore_file_unlink(buf2);
+   elm_config_save();
    return;
 
 err:
index 87761f5..dbb800d 100644 (file)
@@ -116,6 +116,22 @@ EAPI void        elm_config_profile_dir_free(const char *p_dir);
 EAPI Eina_List  *elm_config_profile_list_get(void);
 
 /**
+ * Get Elementary's list of available profiles including hidden ones.
+ *
+ * This gets a full list of profiles even with hidden names that should not
+ * be user-visible.
+ *
+ * @return The profiles list. List node data are the profile name
+ *         strings.
+ * @ingroup Profile
+ *
+ * @note One must free this list, after usage, with the function
+ *       elm_config_profile_list_free().
+ * @since 1.17
+ */
+EAPI Eina_List  *elm_config_profile_list_full_get(void);
+
+/**
  * Free Elementary's list of available profiles.
  *
  * @param l The profiles list, as returned by elm_config_profile_list_get().
@@ -138,6 +154,20 @@ EAPI void        elm_config_profile_list_free(Eina_List *l);
 EAPI void        elm_config_profile_set(const char *profile);
 
 /**
+ * Take the current config and write it out to the named profile
+ *
+ * This will take the current in-memory config and write it out to the named
+ * profile specified by @p profile. This will not change profile for the
+ * application or make other processes switch profile.
+ * 
+ * @param profile The profile's name
+ * @ingroup Profile
+ *
+ * @since 1.17
+ */
+EAPI void        elm_config_profile_save(const char *profile);
+
+/**
  * @}
  */
 
index f2c74f9..ad537c5 100644 (file)
@@ -439,7 +439,7 @@ void                 _elm_config_init(void);
 void                 _elm_config_sub_init(void);
 void                 _elm_config_shutdown(void);
 void                 _elm_config_sub_shutdown(void);
-Eina_Bool            _elm_config_save(void);
+Eina_Bool            _elm_config_save(const char *profile);
 void                 _elm_config_reload(void);
 size_t               _elm_config_user_dir_snprintf(char *dst, size_t size,
                                                    const char *fmt, ...)
@@ -451,7 +451,7 @@ void                 _elm_recache(void);
 const char          *_elm_config_current_profile_get(void);
 const char          *_elm_config_profile_dir_get(const char *prof,
                                                  Eina_Bool is_user);
-Eina_List           *_elm_config_profiles_list(void);
+Eina_List           *_elm_config_profiles_list(Eina_Bool hide_profiles);
 void                 _elm_config_all_update(void);
 void                 _elm_config_profile_set(const char *profile);