1 #include "e.h"
2 #include "e_mod_main.h"
3 
4 struct _E_Config_Dialog_Data
5 {
6    const char       *dir;
7    int               show_label, eap_label;
8    int               lock_move;
9    int               track_launch;
10    int               dont_add_nonorder;
11    int               icon_menu_mouseover;
12 
13    Evas_Object      *tlist;
14    Evas_Object      *radio_name;
15    Evas_Object      *radio_comment;
16    Evas_Object      *radio_generic;
17    E_Confirm_Dialog *dialog_delete;
18 };
19 
20 /* Protos */
21 static void        *_create_data(E_Config_Dialog *cfd);
22 static void         _free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
23 static Evas_Object *_basic_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata);
24 static int          _basic_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
25 static void         _cb_add(void *data, void *data2);
26 static void         _cb_del(void *data, void *data2);
27 static void         _cb_config(void *data, void *data2);
28 static void         _cb_entry_ok(void *data, char *text);
29 static void         _cb_confirm_dialog_yes(void *data);
30 static void         _cb_confirm_dialog_destroy(void *data);
31 static void         _load_tlist(E_Config_Dialog_Data *cfdata);
32 static void         _show_label_cb_change(void *data, Evas_Object *obj);
33 
34 void
_config_ibar_module(Config_Item * ci)35 _config_ibar_module(Config_Item *ci)
36 {
37    E_Config_Dialog *cfd;
38    E_Config_Dialog_View *v;
39    char buf[4096];
40 
41    v = E_NEW(E_Config_Dialog_View, 1);
42 
43    /* Dialog Methods */
44    v->create_cfdata = _create_data;
45    v->free_cfdata = _free_data;
46    v->basic.apply_cfdata = _basic_apply_data;
47    v->basic.create_widgets = _basic_create_widgets;
48    v->advanced.apply_cfdata = NULL;
49    v->advanced.create_widgets = NULL;
50 
51    snprintf(buf, sizeof(buf), "%s/e-module-ibar.edj",
52             e_module_dir_get(ibar_config->module));
53 
54    /* Create The Dialog */
55    cfd = e_config_dialog_new(NULL,
56                              _("IBar Settings"),
57                              "E", "_e_mod_ibar_config_dialog",
58                              buf, 0, v, ci);
59    ibar_config->config_dialog = cfd;
60 }
61 
62 static void
_fill_data(Config_Item * ci,E_Config_Dialog_Data * cfdata)63 _fill_data(Config_Item *ci, E_Config_Dialog_Data *cfdata)
64 {
65    if (ci->dir)
66      cfdata->dir = eina_stringshare_ref(ci->dir);
67    else
68      cfdata->dir = eina_stringshare_add("");
69    cfdata->show_label = ci->show_label;
70    cfdata->eap_label = ci->eap_label;
71    cfdata->lock_move = ci->lock_move;
72    cfdata->dont_add_nonorder = ci->dont_add_nonorder;
73    cfdata->track_launch = !ci->dont_track_launch;
74    cfdata->icon_menu_mouseover = !ci->dont_icon_menu_mouseover;
75 }
76 
77 static void *
_create_data(E_Config_Dialog * cfd)78 _create_data(E_Config_Dialog *cfd)
79 {
80    E_Config_Dialog_Data *cfdata;
81    Config_Item *ci;
82 
83    ci = cfd->data;
84    cfdata = E_NEW(E_Config_Dialog_Data, 1);
85    _fill_data(ci, cfdata);
86    return cfdata;
87 }
88 
89 static void
_free_data(E_Config_Dialog * cfd EINA_UNUSED,E_Config_Dialog_Data * cfdata)90 _free_data(E_Config_Dialog *cfd EINA_UNUSED, E_Config_Dialog_Data *cfdata)
91 {
92    if (cfdata->dir) eina_stringshare_del(cfdata->dir);
93    if (cfdata->dialog_delete) e_object_del(E_OBJECT(cfdata->dialog_delete));
94    ibar_config->config_dialog = NULL;
95    E_FREE(cfdata);
96 }
97 
98 static Evas_Object *
_basic_create_widgets(E_Config_Dialog * cfd EINA_UNUSED,Evas * evas,E_Config_Dialog_Data * cfdata)99 _basic_create_widgets(E_Config_Dialog *cfd EINA_UNUSED, Evas *evas, E_Config_Dialog_Data *cfdata)
100 {
101    Evas_Object *o, *of, *ol, *ob, *ot;
102    E_Radio_Group *rg;
103 
104    o = e_widget_list_add(evas, 0, 0);
105 
106    of = e_widget_frametable_add(evas, _("Selected source"), 0);
107    ol = e_widget_ilist_add(evas, 32, 32, &(cfdata->dir));
108    cfdata->tlist = ol;
109    _load_tlist(cfdata);
110    e_widget_size_min_set(ol, 140, 140);
111    e_widget_frametable_object_append(of, ol, 0, 0, 1, 2, 1, 1, 1, 0);
112 
113    ot = e_widget_table_add(e_win_evas_win_get(evas), 0);
114    ob = e_widget_button_add(evas, _("Add"), "list-add", _cb_add, cfdata, NULL);
115    e_widget_table_object_append(ot, ob, 0, 0, 1, 1, 1, 1, 1, 0);
116    ob = e_widget_button_add(evas, _("Delete"), "list-remove", _cb_del, cfdata, NULL);
117    e_widget_table_object_append(ot, ob, 0, 1, 1, 1, 1, 1, 1, 0);
118    ob = e_widget_button_add(evas, _("Contents"), "configure", _cb_config, cfdata, NULL);
119    e_widget_table_object_append(ot, ob, 0, 2, 1, 1, 1, 1, 1, 0);
120 
121    if (!e_configure_registry_exists("applications/ibar_applications"))
122      e_widget_disabled_set(ob, 1);
123 
124    e_widget_frametable_object_append(of, ot, 1, 0, 1, 1, 1, 1, 1, 0);
125    e_widget_list_object_append(o, of, 1, 1, 0.5);
126 
127    of = e_widget_framelist_add(evas, _("Icon Labels"), 0);
128    ob = e_widget_check_add(evas, _("Show icon label"), &(cfdata->show_label));
129    e_widget_on_change_hook_set(ob, _show_label_cb_change, cfdata);
130    e_widget_framelist_object_append(of, ob);
131 
132    rg = e_widget_radio_group_new(&(cfdata->eap_label));
133 
134    cfdata->radio_name = e_widget_radio_add(evas, _("Name"), 0, rg);
135    e_widget_framelist_object_append(of, cfdata->radio_name);
136    if (!cfdata->show_label) e_widget_disabled_set(cfdata->radio_name, 1);
137 
138    cfdata->radio_comment = e_widget_radio_add(evas, _("Comment"), 1, rg);
139    e_widget_framelist_object_append(of, cfdata->radio_comment);
140    if (!cfdata->show_label) e_widget_disabled_set(cfdata->radio_comment, 1);
141 
142    cfdata->radio_generic = e_widget_radio_add(evas, _("Generic"), 2, rg);
143    e_widget_framelist_object_append(of, cfdata->radio_generic);
144    if (!cfdata->show_label) e_widget_disabled_set(cfdata->radio_generic, 1);
145 
146    e_widget_list_object_append(o, of, 1, 1, 0.5);
147 
148    of = e_widget_framelist_add(evas, _("Misc"), 0);
149    ob = e_widget_check_add(evas, _("Lock icon move"), &(cfdata->lock_move));
150    e_widget_framelist_object_append(of, ob);
151    ob = e_widget_check_add(evas, _("Don't add items on launch"), &(cfdata->dont_add_nonorder));
152    e_widget_framelist_object_append(of, ob);
153    ob = e_widget_check_add(evas, _("Track launch"), &(cfdata->track_launch));
154    e_widget_framelist_object_append(of, ob);
155    ob = e_widget_check_add(evas, _("Menu on mouse over"), &(cfdata->icon_menu_mouseover));
156    e_widget_framelist_object_append(of, ob);
157 
158    e_widget_list_object_append(o, of, 1, 1, 0.5);
159 
160    return o;
161 }
162 
163 static int
_basic_apply_data(E_Config_Dialog * cfd,E_Config_Dialog_Data * cfdata)164 _basic_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata)
165 {
166    Config_Item *ci;
167 
168    ci = cfd->data;
169    if (ci->dir) eina_stringshare_del(ci->dir);
170    ci->dir = NULL;
171    if (cfdata->dir) ci->dir = eina_stringshare_ref(cfdata->dir);
172    ci->show_label = cfdata->show_label;
173    ci->eap_label = cfdata->eap_label;
174    ci->lock_move = cfdata->lock_move;
175    ci->dont_add_nonorder = cfdata->dont_add_nonorder;
176    ci->dont_track_launch = !cfdata->track_launch;
177    ci->dont_icon_menu_mouseover = !cfdata->icon_menu_mouseover;
178    _ibar_config_update(ci);
179    e_config_save_queue();
180    return 1;
181 }
182 
183 static void
_cb_add(void * data,void * data2 EINA_UNUSED)184 _cb_add(void *data, void *data2 EINA_UNUSED)
185 {
186    E_Config_Dialog_Data *cfdata;
187 
188    cfdata = data;
189    e_entry_dialog_show(_("Create new IBar source"), "enlightenment",
190                        _("Enter a name for this new source:"), "", NULL, NULL,
191                        _cb_entry_ok, NULL, cfdata);
192 }
193 
194 static void
_cb_del(void * data,void * data2 EINA_UNUSED)195 _cb_del(void *data, void *data2 EINA_UNUSED)
196 {
197    char buf[4096];
198    E_Config_Dialog_Data *cfdata;
199    E_Confirm_Dialog *dialog;
200 
201    cfdata = data;
202    if (cfdata->dialog_delete) return;
203 
204    snprintf(buf, sizeof(buf), _("You requested to delete \"%s\".<ps/><ps/>"
205                                 "Are you sure you want to delete this bar source?"),
206             cfdata->dir);
207 
208    dialog = e_confirm_dialog_show(_("Are you sure you want to delete this bar source?"),
209                                   "application-exit", buf, _("Delete"), _("Keep"),
210                                   _cb_confirm_dialog_yes, NULL, cfdata, NULL,
211                                   _cb_confirm_dialog_destroy, cfdata);
212    cfdata->dialog_delete = dialog;
213 }
214 
215 static void
_cb_config(void * data,void * data2 EINA_UNUSED)216 _cb_config(void *data, void *data2 EINA_UNUSED)
217 {
218    char path[PATH_MAX];
219    E_Config_Dialog_Data *cfdata;
220 
221    cfdata = data;
222    e_user_dir_snprintf(path, sizeof(path), "applications/bar/%s/.order",
223                        cfdata->dir);
224    e_configure_registry_call("internal/ibar_other", NULL, path);
225 }
226 
227 static void
_cb_entry_ok(void * data,char * text)228 _cb_entry_ok(void *data, char *text)
229 {
230    char buf[4096];
231    char tmp[4096] = {0};
232    FILE *f;
233    size_t len;
234 
235    len = e_user_dir_snprintf(buf, sizeof(buf), "applications/bar/%s", text);
236    if (len + sizeof("/.order") >= sizeof(buf)) return;
237    while (!ecore_file_exists(buf))
238      {
239         ecore_file_mkdir(buf);
240         memcpy(buf + len, "/.order", sizeof("/.order"));
241         e_user_dir_concat_static(tmp, "applications/bar/default/.order");
242         if (ecore_file_cp(tmp, buf)) break;
243         f = fopen(buf, "w");
244         if (!f) break;
245         /* Populate this .order file with some defaults */
246         snprintf(tmp, sizeof(tmp),
247                  "terminology.desktop\n"
248                  "sylpheed.desktop\n"
249                  "firefox.desktop\n"
250                  "openoffice.desktop\n"
251                  "xchat.desktop\n"
252                  "gimp.desktop\n");
253         fwrite(tmp, sizeof(char), strlen(tmp), f);
254         fclose(f);
255         break;
256      }
257 
258    _load_tlist(data);
259 }
260 
261 static void
_cb_confirm_dialog_yes(void * data)262 _cb_confirm_dialog_yes(void *data)
263 {
264    E_Config_Dialog_Data *cfdata;
265    char buf[4096];
266 
267    cfdata = data;
268    if (e_user_dir_snprintf(buf, sizeof(buf), "applications/bar/%s", cfdata->dir) >= sizeof(buf))
269      return;
270    if (ecore_file_is_dir(buf))
271      ecore_file_recursive_rm(buf);
272 
273    _load_tlist(cfdata);
274 }
275 
276 static void
_cb_confirm_dialog_destroy(void * data)277 _cb_confirm_dialog_destroy(void *data)
278 {
279    E_Config_Dialog_Data *cfdata;
280 
281    cfdata = data;
282    cfdata->dialog_delete = NULL;
283 }
284 
285 static void
_load_tlist(E_Config_Dialog_Data * cfdata)286 _load_tlist(E_Config_Dialog_Data *cfdata)
287 {
288    Eina_List *dirs;
289    char buf[4096], *file;
290    int selnum = -1;
291    int i = 0;
292    size_t len;
293 
294    e_widget_ilist_clear(cfdata->tlist);
295 
296    len = e_user_dir_concat_static(buf, "applications/bar");
297    if (len + 2 >= sizeof(buf)) return;
298    dirs = ecore_file_ls(buf);
299 
300    buf[len] = '/';
301    len++;
302 
303    EINA_LIST_FREE(dirs, file)
304      {
305         if (file[0] == '.') continue;
306         if (eina_strlcpy(buf + len, file, sizeof(buf) - len) >= sizeof(buf) - len)
307           continue;
308         if (ecore_file_is_dir(buf))
309           {
310              e_widget_ilist_append(cfdata->tlist, NULL, file, NULL, NULL, file);
311              if ((cfdata->dir) && (!strcmp(cfdata->dir, file)))
312                selnum = i;
313              i++;
314           }
315 
316         free(file);
317      }
318 
319    e_widget_ilist_go(cfdata->tlist);
320    if (selnum >= 0) e_widget_ilist_selected_set(cfdata->tlist, selnum);
321 }
322 
323 static void
_show_label_cb_change(void * data,Evas_Object * obj EINA_UNUSED)324 _show_label_cb_change(void *data, Evas_Object *obj EINA_UNUSED)
325 {
326    E_Config_Dialog_Data *cfdata;
327 
328    cfdata = data;
329    if (!cfdata) return;
330    e_widget_disabled_set(cfdata->radio_name, !cfdata->show_label);
331    e_widget_disabled_set(cfdata->radio_comment, !cfdata->show_label);
332    e_widget_disabled_set(cfdata->radio_generic, !cfdata->show_label);
333 }
334 
335