41e29c96e601de599f9e68994ac06d0f621ba3b5
[framework/uifw/e17.git] / src / modules / wizard / page_020.c
1 /* Profile chooser */
2 #include "e.h"
3 #include "e_mod_main.h"
4
5 static const char *profile = NULL;
6 static Evas_Object *textblock = NULL;
7
8 static void
9 _profile_change(void *data __UNUSED__, Evas_Object *obj __UNUSED__)
10 {
11    char buf[PATH_MAX];
12    const char *dir;
13    Efreet_Desktop *desk = NULL;
14
15    e_prefix_data_snprintf(buf, sizeof(buf), "data/config/%s", profile);
16    dir = strdup(buf);
17    if (!dir)
18      {
19         e_widget_textblock_markup_set(textblock, _("Unknown"));
20         return;
21      }
22    snprintf(buf, sizeof(buf), "%s/profile.desktop", dir);
23    desk = efreet_desktop_new(buf);
24    if (desk)
25      e_widget_textblock_markup_set(textblock, desk->comment);
26    else
27      e_widget_textblock_markup_set(textblock, _("Unknown"));
28    if (desk) efreet_desktop_free(desk);
29
30    // enable next once you choose a profile
31    e_wizard_button_next_enable_set(1);
32 }
33
34 EAPI int
35 wizard_page_init(E_Wizard_Page *pg __UNUSED__)
36 {
37    return 1;
38 }
39
40 EAPI int
41 wizard_page_shutdown(E_Wizard_Page *pg __UNUSED__)
42 {
43    return 1;
44 }
45
46 EAPI int
47 wizard_page_show(E_Wizard_Page *pg)
48 {
49    Evas_Object *o, *of, *ob;
50    Eina_List *l, *profiles;
51    int i, sel = -1;
52    Evas_Object *ilist;
53
54    o = e_widget_list_add(pg->evas, 1, 0);
55    e_wizard_title_set(_("Profile"));
56    of = e_widget_framelist_add(pg->evas, _("Select one"), 0);
57    
58    ob = e_widget_ilist_add(pg->evas, 32 * e_scale, 32 * e_scale, &profile);
59    e_widget_size_min_set(ob, 140 * e_scale, 70 * e_scale);
60    ilist = ob;
61    e_widget_on_change_hook_set(ob, _profile_change, NULL);
62
63    e_widget_ilist_freeze(ob);
64
65    profiles = e_config_profile_list();
66    for (i = 0, l = profiles; l; l = l->next, i++)
67      {
68         Efreet_Desktop *desk = NULL;
69         char buf[PATH_MAX], *prof;
70         const char *label, *dir;
71         Evas_Object *ic;
72
73         prof = l->data;
74         if (e_config_profile_get())
75           {
76              if (!strcmp(prof, e_config_profile_get()))
77                {
78                   free(prof);
79                   continue;
80                }
81           }
82         e_prefix_data_snprintf(buf, sizeof(buf), "data/config/%s", prof);
83         // if it's not a system profile - don't offer it
84         if (!ecore_file_is_dir(buf))
85           {
86              free(prof);
87              continue;
88           }
89         dir = strdup(buf);
90         if (!dir)
91           {
92              free(prof);
93              continue;
94           }
95         snprintf(buf, sizeof(buf), "%s/profile.desktop", dir);
96         desk = efreet_desktop_new(buf);
97         label = prof;
98         if ((desk) && (desk->name)) label = desk->name;
99         snprintf(buf, sizeof(buf), "%s/icon.edj", dir);
100         if ((desk) && (desk->icon))
101           snprintf(buf, sizeof(buf), "%s/%s", dir, desk->icon);
102         else
103           e_prefix_data_concat_static(buf, "data/images/enlightenment.png");
104         ic = e_util_icon_add(buf, pg->evas);
105         e_widget_ilist_append(ob, ic, label, NULL, NULL, prof);
106         free(prof);
107         if (desk) efreet_desktop_free(desk);
108      }
109    if (profiles) eina_list_free(profiles);
110
111    e_widget_ilist_go(ob);
112    e_widget_ilist_thaw(ob);
113
114    e_widget_framelist_object_append(of, ob);
115
116    ob = e_widget_textblock_add(pg->evas);
117    e_widget_size_min_set(ob, 140 * e_scale, 70 * e_scale);
118    e_widget_textblock_markup_set(ob, _("Select a profile"));
119    textblock = ob;
120
121    e_widget_framelist_object_append(of, ob);
122
123    e_widget_list_object_append(o, of, 1, 1, 0.5);
124
125    if (sel >= 0) e_widget_ilist_selected_set(ilist, sel);
126
127    evas_object_show(ob);
128    evas_object_show(of);
129    e_wizard_page_show(o);
130    pg->data = of;
131    e_wizard_button_next_enable_set(0);
132    return 1; /* 1 == show ui, and wait for user, 0 == just continue */
133 }
134
135 EAPI int
136 wizard_page_hide(E_Wizard_Page *pg)
137 {
138    evas_object_del(pg->data);
139    // actually apply profile
140    if (e_config_profile_get())
141      {
142         char buf[PATH_MAX];
143         if (e_user_dir_snprintf(buf, sizeof(buf), "config/%s", 
144                                 e_config_profile_get()) >= sizeof(buf))
145           return 1;
146         ecore_file_recursive_rm(buf);
147      }
148    if (!profile) profile = "standard";
149    e_config_profile_set(profile);
150    return 1;
151 }
152
153 EAPI int
154 wizard_page_apply(E_Wizard_Page *pg __UNUSED__)
155 {
156    // no need. done in page_070's wizard_page_show()
157    return 1;
158 }