summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2015-12-31 15:38:20 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2016-01-05 22:24:58 +0900
commit9f51ad064259a0184fa7eee3db8abedd92e32230 (patch)
tree4e140b96620d8b1474f7afa6e862fb8a238b3548
parentb4f8b8c0c66095730d4436db3987c3fad34aec95 (diff)
elm config - allow the ability to save out to another hidden profile
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
-rw-r--r--src/lib/elm_config.c82
-rw-r--r--src/lib/elm_config.h30
-rw-r--r--src/lib/elm_priv.h4
3 files changed, 80 insertions, 36 deletions
diff --git a/src/lib/elm_config.c b/src/lib/elm_config.c
index 88595dc2b..e15e8fea8 100644
--- a/src/lib/elm_config.c
+++ b/src/lib/elm_config.c
@@ -1053,7 +1053,7 @@ _elm_config_colors_free(const char *palette_name)
1053} 1053}
1054 1054
1055Eina_List * 1055Eina_List *
1056_elm_config_profiles_list(void) 1056_elm_config_profiles_list(Eina_Bool hide_profiles)
1057{ 1057{
1058 Eina_File_Direct_Info *info; 1058 Eina_File_Direct_Info *info;
1059 Eina_List *flist = NULL; 1059 Eina_List *flist = NULL;
@@ -1065,8 +1065,7 @@ _elm_config_profiles_list(void)
1065 len = _elm_config_user_dir_snprintf(buf, sizeof(buf), "config"); 1065 len = _elm_config_user_dir_snprintf(buf, sizeof(buf), "config");
1066 1066
1067 file_it = eina_file_stat_ls(buf); 1067 file_it = eina_file_stat_ls(buf);
1068 if (!file_it) 1068 if (!file_it) goto sys;
1069 goto sys;
1070 1069
1071 buf[len] = '/'; 1070 buf[len] = '/';
1072 len++; 1071 len++;
@@ -1075,15 +1074,15 @@ _elm_config_profiles_list(void)
1075 1074
1076 EINA_ITERATOR_FOREACH(file_it, info) 1075 EINA_ITERATOR_FOREACH(file_it, info)
1077 { 1076 {
1078 if (info->name_length >= len) 1077 if (info->name_length >= len) continue;
1079 continue; 1078 if ((hide_profiles) && (info->path[info->name_start] == '.')) continue;
1080 1079
1081 if (info->type == EINA_FILE_DIR) 1080 if (info->type == EINA_FILE_DIR)
1082 { 1081 {
1083 flist = 1082 flist =
1084 eina_list_sorted_insert(flist, _sort_files_cb, 1083 eina_list_sorted_insert(flist, _sort_files_cb,
1085 eina_stringshare_add(info->path + 1084 eina_stringshare_add
1086 info->name_start)); 1085 (info->path + info->name_start));
1087 } 1086 }
1088 } 1087 }
1089 1088
@@ -1095,8 +1094,7 @@ sys:
1095 sizeof("config") - 1); 1094 sizeof("config") - 1);
1096 1095
1097 file_it = eina_file_stat_ls(buf); 1096 file_it = eina_file_stat_ls(buf);
1098 if (!file_it) 1097 if (!file_it) goto list_free;
1099 goto list_free;
1100 1098
1101 buf[len] = '/'; 1099 buf[len] = '/';
1102 len++; 1100 len++;
@@ -1104,26 +1102,26 @@ sys:
1104 len = sizeof(buf) - len; 1102 len = sizeof(buf) - len;
1105 EINA_ITERATOR_FOREACH(file_it, info) 1103 EINA_ITERATOR_FOREACH(file_it, info)
1106 { 1104 {
1107 if (info->name_length >= len) 1105 if (info->name_length >= len) continue;
1108 continue; 1106 if ((hide_profiles) && (info->path[info->name_start] == '.')) continue;
1109 1107
1110 switch (info->type) 1108 switch (info->type)
1111 { 1109 {
1112 case EINA_FILE_DIR: 1110 case EINA_FILE_DIR:
1113 { 1111 {
1114 const Eina_List *l; 1112 const Eina_List *l;
1115 const char *tmp; 1113 const char *tmp;
1116
1117 EINA_LIST_FOREACH(flist, l, tmp)
1118 if (!strcmp(info->path + info->name_start, tmp))
1119 break;
1120 1114
1121 if (!l) 1115 EINA_LIST_FOREACH(flist, l, tmp)
1122 flist = 1116 {
1123 eina_list_sorted_insert(flist, _sort_files_cb, 1117 if (!strcmp(info->path + info->name_start, tmp)) break;
1124 eina_stringshare_add(info->path + 1118 }
1125 info->name_start)); 1119 if (!l)
1126 } 1120 flist = eina_list_sorted_insert(flist, _sort_files_cb,
1121 eina_stringshare_add
1122 (info->path +
1123 info->name_start));
1124 }
1127 break; 1125 break;
1128 1126
1129 default: 1127 default:
@@ -1134,9 +1132,7 @@ sys:
1134 return flist; 1132 return flist;
1135 1133
1136list_free: 1134list_free:
1137 EINA_LIST_FREE(flist, dir) 1135 EINA_LIST_FREE(flist, dir) eina_stringshare_del(dir);
1138 eina_stringshare_del(dir);
1139
1140 return NULL; 1136 return NULL;
1141} 1137}
1142 1138
@@ -1700,7 +1696,7 @@ err:
1700} 1696}
1701 1697
1702Eina_Bool 1698Eina_Bool
1703_elm_config_save(void) 1699_elm_config_save(const char *profile)
1704{ 1700{
1705 char buf[4096], buf2[4096]; 1701 char buf[4096], buf2[4096];
1706 int ok = 0, ret; 1702 int ok = 0, ret;
@@ -1721,7 +1717,7 @@ _elm_config_save(void)
1721 } 1717 }
1722 1718
1723 len = _elm_config_user_dir_snprintf(buf, sizeof(buf), "config/%s", 1719 len = _elm_config_user_dir_snprintf(buf, sizeof(buf), "config/%s",
1724 _elm_profile); 1720 profile ? profile : _elm_profile);
1725 if (len + 1 >= sizeof(buf)) 1721 if (len + 1 >= sizeof(buf))
1726 return EINA_FALSE; 1722 return EINA_FALSE;
1727 1723
@@ -1733,8 +1729,11 @@ _elm_config_save(void)
1733 return EINA_FALSE; 1729 return EINA_FALSE;
1734 } 1730 }
1735 1731
1736 if (!_elm_config_profile_save()) 1732 if (!profile)
1737 return EINA_FALSE; 1733 {
1734 if (!_elm_config_profile_save())
1735 return EINA_FALSE;
1736 }
1738 1737
1739 buf[len] = '/'; 1738 buf[len] = '/';
1740 len++; 1739 len++;
@@ -1889,7 +1888,7 @@ _config_update(void)
1889 _elm_config->config_version = ELM_CONFIG_VERSION; 1888 _elm_config->config_version = ELM_CONFIG_VERSION;
1890 /* after updating user config, we must save */ 1889 /* after updating user config, we must save */
1891 _config_free(tcfg); 1890 _config_free(tcfg);
1892 _elm_config_save(); 1891 _elm_config_save(NULL);
1893} 1892}
1894 1893
1895static void 1894static void
@@ -2387,7 +2386,7 @@ elm_config_password_show_last_timeout_set(double password_show_last_timeout)
2387EAPI Eina_Bool 2386EAPI Eina_Bool
2388elm_config_save(void) 2387elm_config_save(void)
2389{ 2388{
2390 return _elm_config_save(); 2389 return _elm_config_save(NULL);
2391} 2390}
2392 2391
2393EAPI void 2392EAPI void
@@ -2418,7 +2417,13 @@ elm_config_profile_dir_free(const char *p_dir)
2418EAPI Eina_List * 2417EAPI Eina_List *
2419elm_config_profile_list_get(void) 2418elm_config_profile_list_get(void)
2420{ 2419{
2421 return _elm_config_profiles_list(); 2420 return _elm_config_profiles_list(EINA_TRUE);
2421}
2422
2423EAPI Eina_List *
2424elm_config_profile_list_full_get(void)
2425{
2426 return _elm_config_profiles_list(EINA_FALSE);
2422} 2427}
2423 2428
2424EAPI void 2429EAPI void
@@ -2437,6 +2442,14 @@ elm_config_profile_set(const char *profile)
2437 _elm_config_profile_set(profile); 2442 _elm_config_profile_set(profile);
2438} 2443}
2439 2444
2445EAPI void
2446elm_config_profile_save(const char *profile)
2447{
2448 EINA_SAFETY_ON_NULL_RETURN(profile);
2449 _elm_config_save(profile);
2450}
2451
2452
2440EAPI const char * 2453EAPI const char *
2441elm_config_engine_get(void) 2454elm_config_engine_get(void)
2442{ 2455{
@@ -3368,6 +3381,7 @@ elm_config_all_flush(void)
3368 } 3381 }
3369 3382
3370 ecore_file_unlink(buf2); 3383 ecore_file_unlink(buf2);
3384 elm_config_save();
3371 return; 3385 return;
3372 3386
3373err: 3387err:
diff --git a/src/lib/elm_config.h b/src/lib/elm_config.h
index e7bece0f1..12c2ff460 100644
--- a/src/lib/elm_config.h
+++ b/src/lib/elm_config.h
@@ -116,6 +116,22 @@ EAPI void elm_config_profile_dir_free(const char *p_dir);
116EAPI Eina_List *elm_config_profile_list_get(void); 116EAPI Eina_List *elm_config_profile_list_get(void);
117 117
118/** 118/**
119 * Get Elementary's list of available profiles including hidden ones.
120 *
121 * This gets a full list of profiles even with hidden names that should not
122 * be user-visible.
123 *
124 * @return The profiles list. List node data are the profile name
125 * strings.
126 * @ingroup Profile
127 *
128 * @note One must free this list, after usage, with the function
129 * elm_config_profile_list_free().
130 * @since 1.17
131 */
132EAPI Eina_List *elm_config_profile_list_full_get(void);
133
134/**
119 * Free Elementary's list of available profiles. 135 * Free Elementary's list of available profiles.
120 * 136 *
121 * @param l The profiles list, as returned by elm_config_profile_list_get(). 137 * @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);
138EAPI void elm_config_profile_set(const char *profile); 154EAPI void elm_config_profile_set(const char *profile);
139 155
140/** 156/**
157 * Take the current config and write it out to the named profile
158 *
159 * This will take the current in-memory config and write it out to the named
160 * profile specified by @p profile. This will not change profile for the
161 * application or make other processes switch profile.
162 *
163 * @param profile The profile's name
164 * @ingroup Profile
165 *
166 * @since 1.17
167 */
168EAPI void elm_config_profile_save(const char *profile);
169
170/**
141 * @} 171 * @}
142 */ 172 */
143 173
diff --git a/src/lib/elm_priv.h b/src/lib/elm_priv.h
index f0dfd01da..f5f1cde38 100644
--- a/src/lib/elm_priv.h
+++ b/src/lib/elm_priv.h
@@ -433,7 +433,7 @@ void _elm_config_init(void);
433void _elm_config_sub_init(void); 433void _elm_config_sub_init(void);
434void _elm_config_shutdown(void); 434void _elm_config_shutdown(void);
435void _elm_config_sub_shutdown(void); 435void _elm_config_sub_shutdown(void);
436Eina_Bool _elm_config_save(void); 436Eina_Bool _elm_config_save(const char *profile);
437void _elm_config_reload(void); 437void _elm_config_reload(void);
438size_t _elm_config_user_dir_snprintf(char *dst, size_t size, 438size_t _elm_config_user_dir_snprintf(char *dst, size_t size,
439 const char *fmt, ...) 439 const char *fmt, ...)
@@ -445,7 +445,7 @@ void _elm_recache(void);
445const char *_elm_config_current_profile_get(void); 445const char *_elm_config_current_profile_get(void);
446const char *_elm_config_profile_dir_get(const char *prof, 446const char *_elm_config_profile_dir_get(const char *prof,
447 Eina_Bool is_user); 447 Eina_Bool is_user);
448Eina_List *_elm_config_profiles_list(void); 448Eina_List *_elm_config_profiles_list(Eina_Bool hide_profiles);
449void _elm_config_all_update(void); 449void _elm_config_all_update(void);
450void _elm_config_profile_set(const char *profile); 450void _elm_config_profile_set(const char *profile);
451 451