aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/ibar/e_mod_config.c
blob: 9d531162ce0bddb6f95843641c79371c01b70025 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
#include "e.h"
#include "e_mod_main.h"

struct _E_Config_Dialog_Data
{
   const char       *dir;
   int               show_label, eap_label;
   int               lock_move;
   int               track_launch;

   Evas_Object      *tlist;
   Evas_Object      *radio_name;
   Evas_Object      *radio_comment;
   Evas_Object      *radio_generic;
   E_Confirm_Dialog *dialog_delete;
};

/* Protos */
static void        *_create_data(E_Config_Dialog *cfd);
static void         _free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
static Evas_Object *_basic_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata);
static int          _basic_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
static void         _cb_add(void *data, void *data2);
static void         _cb_del(void *data, void *data2);
static void         _cb_config(void *data, void *data2);
static void         _cb_entry_ok(void *data, char *text);
static void         _cb_confirm_dialog_yes(void *data);
static void         _cb_confirm_dialog_destroy(void *data);
static void         _load_tlist(E_Config_Dialog_Data *cfdata);
static void         _show_label_cb_change(void *data, Evas_Object *obj);

void
_config_ibar_module(Config_Item *ci)
{
   E_Config_Dialog *cfd;
   E_Config_Dialog_View *v;
   char buf[4096];

   v = E_NEW(E_Config_Dialog_View, 1);

   /* Dialog Methods */
   v->create_cfdata = _create_data;
   v->free_cfdata = _free_data;
   v->basic.apply_cfdata = _basic_apply_data;
   v->basic.create_widgets = _basic_create_widgets;
   v->advanced.apply_cfdata = NULL;
   v->advanced.create_widgets = NULL;

   snprintf(buf, sizeof(buf), "%s/e-module-ibar.edj",
            e_module_dir_get(ibar_config->module));

   /* Create The Dialog */
   cfd = e_config_dialog_new(e_container_current_get(e_manager_current_get()),
                             _("IBar Settings"),
                             "E", "_e_mod_ibar_config_dialog",
                             buf, 0, v, ci);
   ibar_config->config_dialog = cfd;
}

static void
_fill_data(Config_Item *ci, E_Config_Dialog_Data *cfdata)
{
   if (ci->dir)
     cfdata->dir = eina_stringshare_ref(ci->dir);
   else
     cfdata->dir = eina_stringshare_add("");
   cfdata->show_label = ci->show_label;
   cfdata->eap_label = ci->eap_label;
   cfdata->lock_move = ci->lock_move;
   cfdata->track_launch = !ci->dont_track_launch;
}

static void *
_create_data(E_Config_Dialog *cfd)
{
   E_Config_Dialog_Data *cfdata;
   Config_Item *ci;

   ci = cfd->data;
   cfdata = E_NEW(E_Config_Dialog_Data, 1);
   _fill_data(ci, cfdata);
   return cfdata;
}

static void
_free_data(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata)
{
   if (cfdata->dir) eina_stringshare_del(cfdata->dir);
   if (cfdata->dialog_delete) e_object_del(E_OBJECT(cfdata->dialog_delete));
   ibar_config->config_dialog = NULL;
   E_FREE(cfdata);
}

static Evas_Object *
_basic_create_widgets(E_Config_Dialog *cfd __UNUSED__, Evas *evas, E_Config_Dialog_Data *cfdata)
{
   Evas_Object *o, *of, *ol, *ob, *ot;
   E_Radio_Group *rg;

   o = e_widget_list_add(evas, 0, 0);

   of = e_widget_frametable_add(evas, _("Selected source"), 0);
   ol = e_widget_ilist_add(evas, 32, 32, &(cfdata->dir));
   cfdata->tlist = ol;
   _load_tlist(cfdata);
   e_widget_size_min_set(ol, 140, 140);
   e_widget_frametable_object_append(of, ol, 0, 0, 1, 2, 1, 1, 1, 0);

   ot = e_widget_table_add(evas, 0);
   ob = e_widget_button_add(evas, _("Add"), "list-add", _cb_add, cfdata, NULL);
   e_widget_table_object_append(ot, ob, 0, 0, 1, 1, 1, 1, 1, 0);
   ob = e_widget_button_add(evas, _("Delete"), "list-remove", _cb_del, cfdata, NULL);
   e_widget_table_object_append(ot, ob, 0, 1, 1, 1, 1, 1, 1, 0);
   ob = e_widget_button_add(evas, _("Setup"), "configure", _cb_config, cfdata, NULL);
   e_widget_table_object_append(ot, ob, 0, 2, 1, 1, 1, 1, 1, 0);

   if (!e_configure_registry_exists("applications/ibar_applications"))
     e_widget_disabled_set(ob, 1);

   e_widget_frametable_object_append(of, ot, 1, 0, 1, 1, 1, 1, 1, 0);
   e_widget_list_object_append(o, of, 1, 1, 0.5);

   of = e_widget_framelist_add(evas, _("Icon Labels"), 0);
   ob = e_widget_check_add(evas, _("Show icon label"), &(cfdata->show_label));
   e_widget_on_change_hook_set(ob, _show_label_cb_change, cfdata);
   e_widget_framelist_object_append(of, ob);

   rg = e_widget_radio_group_new(&(cfdata->eap_label));

   cfdata->radio_name = e_widget_radio_add(evas, _("Name"), 0, rg);
   e_widget_framelist_object_append(of, cfdata->radio_name);
   if (!cfdata->show_label) e_widget_disabled_set(cfdata->radio_name, 1);

   cfdata->radio_comment = e_widget_radio_add(evas, _("Comment"), 1, rg);
   e_widget_framelist_object_append(of, cfdata->radio_comment);
   if (!cfdata->show_label) e_widget_disabled_set(cfdata->radio_comment, 1);

   cfdata->radio_generic = e_widget_radio_add(evas, _("Generic"), 2, rg);
   e_widget_framelist_object_append(of, cfdata->radio_generic);
   if (!cfdata->show_label) e_widget_disabled_set(cfdata->radio_generic, 1);

   e_widget_list_object_append(o, of, 1, 1, 0.5);

   of = e_widget_framelist_add(evas, _("Misc"), 0);
   ob = e_widget_check_add(evas, _("Lock icon move"), &(cfdata->lock_move));
   e_widget_framelist_object_append(of, ob);
   ob = e_widget_check_add(evas, _("Track launch"), &(cfdata->track_launch));
   e_widget_framelist_object_append(of, ob);

   e_widget_list_object_append(o, of, 1, 1, 0.5);

   return o;
}

static int
_basic_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata)
{
   Config_Item *ci;

   ci = cfd->data;
   if (ci->dir) eina_stringshare_del(ci->dir);
   ci->dir = NULL;
   if (cfdata->dir) ci->dir = eina_stringshare_ref(cfdata->dir);
   ci->show_label = cfdata->show_label;
   ci->eap_label = cfdata->eap_label;
   ci->lock_move = cfdata->lock_move;
   ci->dont_track_launch = !cfdata->track_launch;
   _ibar_config_update(ci);
   e_config_save_queue();
   return 1;
}

static void
_cb_add(void *data, void *data2 __UNUSED__)
{
   E_Config_Dialog_Data *cfdata;

   cfdata = data;
   e_entry_dialog_show(_("Create new IBar source"), "enlightenment",
                       _("Enter a name for this new source:"), "", NULL, NULL,
                       _cb_entry_ok, NULL, cfdata);
}

static void
_cb_del(void *data, void *data2 __UNUSED__)
{
   char buf[4096];
   E_Config_Dialog_Data *cfdata;
   E_Confirm_Dialog *dialog;

   cfdata = data;
   if (cfdata->dialog_delete) return;

   snprintf(buf, sizeof(buf), _("You requested to delete \"%s\".<br><br>"
                                "Are you sure you want to delete this bar source?"),
            cfdata->dir);

   dialog = e_confirm_dialog_show(_("Are you sure you want to delete this bar source?"),
                                  "application-exit", buf, _("Delete"), _("Keep"),
                                  _cb_confirm_dialog_yes, NULL, cfdata, NULL,
                                  _cb_confirm_dialog_destroy, cfdata);
   cfdata->dialog_delete = dialog;
}

static void
_cb_config(void *data, void *data2 __UNUSED__)
{
   char path[PATH_MAX];
   E_Config_Dialog_Data *cfdata;

   cfdata = data;
   e_user_dir_snprintf(path, sizeof(path), "applications/bar/%s/.order",
                       cfdata->dir);
   e_configure_registry_call("internal/ibar_other",
                             e_container_current_get(e_manager_current_get()),
                             path);
}

static void
_cb_entry_ok(void *data, char *text)
{
   char buf[4096];
   char tmp[4096];
   FILE *f;
   size_t len;

   len = e_user_dir_snprintf(buf, sizeof(buf), "applications/bar/%s", text);
   if (len + sizeof("/.order") >= sizeof(buf)) return;
   if (!ecore_file_exists(buf))
     {
        ecore_file_mkdir(buf);
        memcpy(buf + len, "/.order", sizeof("/.order"));
        f = fopen(buf, "w");
        if (f)
          {
             int ret = 0;

             /* Populate this .order file with some defaults */
             snprintf(tmp, sizeof(tmp), 
                      "terminology.desktop\n"
                      "sylpheed.desktop\n"
                      "firefox.desktop\n"
                      "openoffice.desktop\n" 
                      "xchat.desktop\n"
                      "gimp.desktop\n");
             ret = fwrite(tmp, sizeof(char), strlen(tmp), f);
             fclose(f);
          }
     }

   _load_tlist(data);
}

static void
_cb_confirm_dialog_yes(void *data)
{
   E_Config_Dialog_Data *cfdata;
   char buf[4096];

   cfdata = data;
   if (e_user_dir_snprintf(buf, sizeof(buf), "applications/bar/%s", cfdata->dir) >= sizeof(buf))
     return;
   if (ecore_file_is_dir(buf))
     ecore_file_recursive_rm(buf);

   _load_tlist(cfdata);
}

static void
_cb_confirm_dialog_destroy(void *data)
{
   E_Config_Dialog_Data *cfdata;

   cfdata = data;
   cfdata->dialog_delete = NULL;
}

static void
_load_tlist(E_Config_Dialog_Data *cfdata)
{
   Eina_List *dirs;
   char buf[4096], *file;
   int selnum = -1;
   int i = 0;
   size_t len;

   e_widget_ilist_clear(cfdata->tlist);

   len = e_user_dir_concat_static(buf, "applications/bar");
   if (len + 2 >= sizeof(buf)) return;
   dirs = ecore_file_ls(buf);

   buf[len] = '/';
   len++;

   EINA_LIST_FREE(dirs, file)
     {
        if (file[0] == '.') continue;
        if (eina_strlcpy(buf + len, file, sizeof(buf) - len) >= sizeof(buf) - len)
          continue;
        if (ecore_file_is_dir(buf))
          {
             e_widget_ilist_append(cfdata->tlist, NULL, file, NULL, NULL, file);
             if ((cfdata->dir) && (!strcmp(cfdata->dir, file)))
               selnum = i;
             i++;
          }

        free(file);
     }

   e_widget_ilist_go(cfdata->tlist);
   if (selnum >= 0) e_widget_ilist_selected_set(cfdata->tlist, selnum);
}

static void
_show_label_cb_change(void *data, Evas_Object *obj __UNUSED__)
{
   E_Config_Dialog_Data *cfdata;

   cfdata = data;
   if (!cfdata) return;
   e_widget_disabled_set(cfdata->radio_name, !cfdata->show_label);
   e_widget_disabled_set(cfdata->radio_comment, !cfdata->show_label);
   e_widget_disabled_set(cfdata->radio_generic, !cfdata->show_label);
}