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