d93ec8be41c1dc4993ffcd77b0a1689d7356acf2
[framework/uifw/e17.git] / src / modules / wizard / page_080.c
1 /* Quick launch chooser */
2 #include "e.h"
3 #include "e_mod_main.h"
4
5 static Eina_List *desktops = NULL;
6 static int *desktops_add = NULL;
7 static int desktops_num = 0;
8
9 static int
10 _cb_sort_desks(Efreet_Desktop *d1, Efreet_Desktop *d2)
11 {
12    if (!d1->name) return 1;
13    if (!d2->name) return -1;
14    return strcmp(d1->name, d2->name);
15 }
16
17 EAPI int
18 wizard_page_init(E_Wizard_Page *pg __UNUSED__)
19 {
20    Eina_List *desks = NULL;
21    Efreet_Desktop *desk;
22    
23    desks = efreet_util_desktop_name_glob_list("*");
24    desks = eina_list_sort(desks, 0, (Eina_Compare_Cb)_cb_sort_desks);
25    EINA_LIST_FREE(desks, desk)
26      {
27         if (!desk->exec)
28           {
29              efreet_desktop_free(desk);
30              continue;
31           }
32         desktops = eina_list_append(desktops, desk);
33      }
34    if (desktops)
35      {
36         desktops_num = eina_list_count(desktops);
37         desktops_add = calloc(sizeof(int), desktops_num);
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 __UNUSED__)
50 {
51    Evas_Object *o, *of, *ob, *li, *ck;
52    Evas_Coord mw, mh;
53    Eina_List *l;
54    int i;
55
56    if (!desktops) return 0;
57    
58    o = e_widget_list_add(pg->evas, 1, 0);
59    e_wizard_title_set(_("Quick Launch"));
60    
61    of = e_widget_framelist_add(pg->evas, _("Select Applications"), 0);
62
63    li = e_widget_list_add(pg->evas, 1, 0);
64    ob = e_widget_scrollframe_simple_add(pg->evas, li);
65    e_widget_size_min_set(ob, 140 * e_scale, 140 * e_scale);
66
67    for (i = 0, l = desktops; l ; l = l->next, i++)
68      {
69         Efreet_Desktop *desk;
70         const char *icon;
71         
72         desk = l->data;
73         icon = NULL;
74         if (desk->icon)
75           icon = efreet_icon_path_find(e_config->icon_theme, 
76                                        desk->icon, 48);
77         ck = e_widget_check_icon_add(pg->evas, desk->name, 
78                                      icon, 32 * e_scale, 32 * e_scale,
79                                      &(desktops_add[i]));
80         e_widget_list_object_append(li, ck, 1, 1, 0.0);
81         evas_object_show(ck);
82      }
83
84    e_widget_size_min_get(li, &mw, &mh);
85    evas_object_resize(li, mw, mh);
86    
87    e_widget_framelist_object_append(of, ob);
88    e_widget_list_object_append(o, of, 1, 1, 0.5);
89    evas_object_show(ob);
90    evas_object_show(of);
91    evas_object_show(li);
92    
93    e_wizard_page_show(o);
94
95    return 1; /* 1 == show ui, and wait for user, 0 == just continue */
96 }
97
98 EAPI int
99 wizard_page_hide(E_Wizard_Page *pg)
100 {
101    evas_object_del(pg->data);
102    return 1;
103 }
104
105 EAPI int
106 wizard_page_apply(E_Wizard_Page *pg __UNUSED__)
107 {
108    Efreet_Desktop *desk;
109    Eina_List *l;
110    int i;
111    FILE *f;
112    char buf[PATH_MAX];
113
114    e_user_dir_concat_static(buf, "applications/bar/default");
115    ecore_file_mkpath(buf);
116    e_user_dir_concat_static(buf, "applications/bar/default/.order");
117    f = fopen(buf, "w");
118    if (f)
119      {
120         for (i = 0, l = desktops; l ; l = l->next, i++)
121           {
122              if (desktops_add[i])
123                {
124                   char *p;
125                   
126                   desk = l->data;
127                   p = strrchr(desk->orig_path, '/');
128                   if (!p) p = desk->orig_path;
129                   else p++;
130                   fprintf(f, "%s\n", p);
131                }
132           }
133         fclose(f);
134      }
135    EINA_LIST_FREE(desktops, desk)
136      efreet_desktop_free(desk);
137
138    if (desktops_add)
139      {
140         free(desktops_add);
141         desktops_add = NULL;
142      }
143    desktops_num = 0;
144    return 1;
145 }