summaryrefslogtreecommitdiff
path: root/src/bin/e_eap_editor.c
blob: af8a2b79c0f149aae9e6434cfae46eab8fbe9d33 (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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
#include "e.h"

typedef struct _E_App_Edit E_App_Edit;
typedef struct _E_App_Edit_CFData E_App_Edit_CFData;

struct _E_App_Edit
{      
   E_App       *eap;

   Evas_Object *img;
   Evas_Object *img_widget;
   int          img_set;
   
   E_App_Edit_CFData *cfdata;
};

struct _E_App_Edit_CFData
{
   /*- BASIC -*/
   char *name;
   char *exe;
   /*- ADVANCED -*/
   char *generic;
   char *comment;
   char *wname;
   char *wclass;
   char *wtitle;
   char *wrole;
   char *iclass;
   int   startup_notify;
   int   wait_exit;
   /*- common -*/
   char *image;
   E_App_Edit *editor;
};

/* local subsystem functions */

static void           _e_eap_edit_fill_data(E_App_Edit_CFData *cdfata);
static void          *_e_eap_edit_create_data(E_Config_Dialog *cfd);
static void           _e_eap_edit_free_data(E_Config_Dialog *cfd, void *data);
static int            _e_eap_edit_basic_apply_data(E_Config_Dialog *cfd, void *data);
static int            _e_eap_edit_advanced_apply_data(E_Config_Dialog *cfd, void *data);
static Evas_Object   *_e_eap_edit_basic_create_widgets(E_Config_Dialog *cfd, Evas *evas, void *data);
static Evas_Object   *_e_eap_edit_advanced_create_widgets(E_Config_Dialog *cfd, Evas *evas, void *data);
static void           _e_eap_edit_select_cb(Evas_Object *obj, char *file, void *data);
static void           _e_eap_edit_hilite_cb(Evas_Object *obj, char *file, void *data);

#define IFDUP(src, dst) if (src) dst = strdup(src); else dst = NULL

/* FIXME: this eap editor is half-done. first advanced mode needs to ALSO
 * cover basic config - image saving is broken, makign new icons is broken
 * along with e_apps.c etc. all in all - this is not usable.
 */

/* externally accessible functions */

EAPI void
e_eap_edit_show(E_Container *con, E_App *a)
{
   E_Config_Dialog *cfd;
   E_Config_Dialog_View *v;
   E_App_Edit *editor;

   if (!con) return;
   
   editor = E_NEW(E_App_Edit, 1);
   if (!editor) return;
   
   editor->eap = a;
   editor->img = NULL;
   e_object_ref(E_OBJECT(editor->eap));
   
   v = E_NEW(E_Config_Dialog_View, 1);
   if (v)
     {
	/* methods */
	v->create_cfdata           = _e_eap_edit_create_data;
	v->free_cfdata             = _e_eap_edit_free_data;
	v->basic.apply_cfdata      = _e_eap_edit_basic_apply_data;
	v->basic.create_widgets    = _e_eap_edit_basic_create_widgets;
	v->advanced.apply_cfdata   = _e_eap_edit_advanced_apply_data;
	v->advanced.create_widgets = _e_eap_edit_advanced_create_widgets;
	/* create config diaolg for NULL object/data */
	cfd = e_config_dialog_new(con, _("Eap Editor"), NULL, 0, v, editor);
     }
}

/* local subsystem functions */

static void 
_e_eap_edit_fill_data(E_App_Edit_CFData *cfdata)
{
   /*- BASIC -*/
   IFDUP(cfdata->editor->eap->name, cfdata->name);
   IFDUP(cfdata->editor->eap->exe, cfdata->exe);
   /*- ADVANCED -*/
   IFDUP(cfdata->editor->eap->generic, cfdata->generic);
   IFDUP(cfdata->editor->eap->comment, cfdata->comment);
   IFDUP(cfdata->editor->eap->win_name, cfdata->wname);
   IFDUP(cfdata->editor->eap->win_class, cfdata->wclass);
   IFDUP(cfdata->editor->eap->win_title, cfdata->wtitle);
   IFDUP(cfdata->editor->eap->win_role, cfdata->wrole);
   IFDUP(cfdata->editor->eap->icon_class, cfdata->iclass);   
   cfdata->startup_notify = cfdata->editor->eap->startup_notify;
   cfdata->wait_exit = cfdata->editor->eap->wait_exit;
}

static void *
_e_eap_edit_create_data(E_Config_Dialog *cfd)
{
   E_App_Edit_CFData *cfdata;
   
   cfdata = E_NEW(E_App_Edit_CFData, 1);
   if (!cfdata) return NULL;
   cfdata->editor = cfd->data;
   cfdata->image = NULL;
   _e_eap_edit_fill_data(cfdata);
   return cfdata;
}

static void
_e_eap_edit_free_data(E_Config_Dialog *cfd, void *data)
{
   E_App_Edit_CFData *cfdata;
   
   cfdata = data;
   E_FREE(cfdata->name);
   E_FREE(cfdata->exe);
   E_FREE(cfdata->generic);
   E_FREE(cfdata->comment);
   E_FREE(cfdata->wname);
   E_FREE(cfdata->wclass);
   E_FREE(cfdata->wtitle);
   E_FREE(cfdata->wrole);
   E_FREE(cfdata->iclass);   
   E_FREE(cfdata->image);
   e_object_unref(E_OBJECT(cfdata->editor->eap));
   E_FREE(cfdata->editor);
   free(data);
}

static int
_e_eap_edit_basic_apply_data(E_Config_Dialog *cfd, void *data)
{
   E_App_Edit *editor;
   E_App *eap;
   E_App_Edit_CFData *cfdata;
   
   cfdata = data;
   editor = cfdata->editor;
   eap = editor->eap;
   
   if (eap->name) evas_stringshare_del(eap->name);
   if (eap->exe) evas_stringshare_del(eap->exe);
   if (eap->image) evas_stringshare_del(eap->image);
   
   if (cfdata->name) eap->name = evas_stringshare_add(cfdata->name);
   if (cfdata->exe) eap->exe = evas_stringshare_add(cfdata->exe);
   if (cfdata->image) eap->image = evas_stringshare_add(cfdata->image);
   
   eap->startup_notify = cfdata->startup_notify;
   eap->wait_exit = cfdata->wait_exit;
   
   /* FIXME: hardcoded until the eap editor provides fields to change it */
   eap->width = 128;
   eap->height = 128;   

   if ((eap->name) && (eap->exe))
     e_app_fields_save(eap);
   
   return 1;
}

static int
_e_eap_edit_advanced_apply_data(E_Config_Dialog *cfd, void *data)
{
   E_App_Edit *editor;
   E_App *eap;
   E_App_Edit_CFData *cfdata;
   
   cfdata = data;
   editor = cfdata->editor;
   eap = editor->eap;
   
   if (eap->name) evas_stringshare_del(eap->name);
   if (eap->exe) evas_stringshare_del(eap->exe);
   if (eap->image) evas_stringshare_del(eap->image);
   
   if (eap->generic) evas_stringshare_del(eap->generic);
   if (eap->comment) evas_stringshare_del(eap->comment);
   if (eap->win_name) evas_stringshare_del(eap->win_name);
   if (eap->win_class) evas_stringshare_del(eap->win_class);   
   if (eap->win_title) evas_stringshare_del(eap->win_title);
   if (eap->win_role) evas_stringshare_del(eap->win_role);
   if (eap->icon_class) evas_stringshare_del(eap->icon_class);
   
   if (cfdata->startup_notify) eap->startup_notify = 1;   
   else eap->startup_notify = 0;
   if (cfdata->wait_exit) eap->wait_exit = 1;
   else eap->wait_exit = 0;
   
   if (cfdata->name) eap->name = evas_stringshare_add(cfdata->name);
   if (cfdata->exe) eap->exe = evas_stringshare_add(cfdata->exe);
   if (cfdata->image) eap->image = evas_stringshare_add(cfdata->image);
   
   if (cfdata->generic) eap->generic = evas_stringshare_add(cfdata->generic);
   if (cfdata->comment) eap->comment = evas_stringshare_add(cfdata->comment);
   if (cfdata->wname) eap->win_name = evas_stringshare_add(cfdata->wname);
   if (cfdata->wclass) eap->win_class = evas_stringshare_add(cfdata->wclass);
   if (cfdata->wtitle) eap->win_title = evas_stringshare_add(cfdata->wtitle);
   if (cfdata->wrole) eap->win_role = evas_stringshare_add(cfdata->wrole);
   if (cfdata->iclass) eap->icon_class = evas_stringshare_add(cfdata->iclass);

   /* FIXME: hardcoded until the eap editor provides fields to change it */
   eap->width = 128;
   eap->height = 128;
   
   if ((eap->name) && (eap->exe))
     e_app_fields_save(eap);
   return 1;
}


static Evas_Object *
_e_eap_edit_basic_create_widgets(E_Config_Dialog *cfd, Evas *evas, void *data)
{
   E_App_Edit_CFData *cfdata;
   E_App_Edit *editor;
   E_App *eap;
   Evas_Object *ol, *o;
   Evas_Object *entry;   
   
   cfdata = data;
   editor = cfdata->editor;
   eap = editor->eap;
   
   ol = e_widget_table_add(evas, 0);
   
   o = e_widget_frametable_add(evas, _("Icon"), 0);
   
   if ((!editor->img) || (editor->img_set != 1))
     {
	editor->img = e_icon_add(evas);   
	if (eap->path)
	  {      
	     e_icon_file_key_set(editor->img, eap->path, "images/0");
	     e_icon_fill_inside_set(editor->img, 1);	
	  }
     }
   else if (editor->img_set)
     {
        editor->img = e_icon_add(evas);
	e_icon_file_set(editor->img, cfdata->image);
	e_icon_fill_inside_set(editor->img, 1);	
     }
   
   editor->img_widget = e_widget_iconsel_add(evas, editor->img, 48, 48, 
					     &(cfdata->image));
   e_widget_iconsel_select_callback_add(editor->img_widget, _e_eap_edit_select_cb, editor);
   e_widget_iconsel_hilite_callback_add(editor->img_widget, _e_eap_edit_hilite_cb, editor);
   e_widget_frametable_object_append(o, editor->img_widget,
				     0, 0, 1, 1,
				     1, 1, 1, 1);
   e_widget_table_object_append(ol, o, 0, 0, 1, 1, 1 ,1, 1, 1);
   
   
   o = e_widget_frametable_add(evas, _("Basic Info"), 0);
   e_widget_frametable_object_append(o, e_widget_label_add(evas, _("App name")),
				     0, 0, 1, 1,
				     1, 1, 1, 1);
   
   entry = e_widget_entry_add(evas, &(cfdata->name));
   e_widget_min_size_set(entry, 100, 1);
   e_widget_frametable_object_append(o, entry,
				     1, 0, 1, 1,
				     1, 1, 1, 1);
   e_widget_frametable_object_append(o, e_widget_label_add(evas, _("Executable")),
				     0, 1, 1, 1,
				     1, 1, 1, 1);
   e_widget_frametable_object_append(o, e_widget_entry_add(evas, &(cfdata->exe)),
				     1, 1, 1, 1,
				     1, 1, 1, 1);   
   e_widget_table_object_append(ol, o, 1, 0, 1, 1, 1 ,1, 1, 1);
      
   return ol;
}

static Evas_Object *
_e_eap_edit_advanced_create_widgets(E_Config_Dialog *cfd, Evas *evas, void *data)
{
   E_App_Edit_CFData *cfdata;
   E_App_Edit *editor;
   E_App *eap;
   Evas_Object *ol, *o;
   Evas_Object *entry;   
   
   cfdata = data;
   editor = cfdata->editor;
   eap = editor->eap;
   
   ol = _e_eap_edit_basic_create_widgets(cfd, evas, data);
   
   o = e_widget_frametable_add(evas, _("General"), 0);

   /*- general info -*/
   e_widget_frametable_object_append(o, e_widget_label_add(evas, _("Generic Info")),
				     0, 0, 1, 1,
				     1, 1, 1, 1);
   
   entry = e_widget_entry_add(evas, &(cfdata->generic));
   e_widget_min_size_set(entry, 100, 1);   
   e_widget_frametable_object_append(o, entry,
				     1, 0, 1, 1,
				     1, 1, 1, 1);
   e_widget_frametable_object_append(o, e_widget_label_add(evas, _("Comment")),
				     0, 1, 1, 1,
				     1, 1, 1, 1);
   e_widget_frametable_object_append(o, e_widget_entry_add(evas, &(cfdata->comment)),
				     1, 1, 1, 1,
				     1, 1, 1, 1);
   e_widget_table_object_append(ol, o, 0, 1, 1, 1, 1 ,1, 1, 1);
   
   
   /*- window info -*/
   o = e_widget_frametable_add(evas, _("Window"), 0);
   
   e_widget_frametable_object_append(o, e_widget_label_add(evas, _("Window Name")),
				     0, 0, 1, 1,
				     1, 1, 1, 1);
   
   entry = e_widget_entry_add(evas, &(cfdata->wname));
   e_widget_min_size_set(entry, 100, 1);      
   e_widget_frametable_object_append(o, entry,
				     1, 0, 1, 1,
				     1, 1, 1, 1);
   e_widget_frametable_object_append(o, e_widget_label_add(evas, _("Window Class")),
				     0, 1, 1, 1,
				     1, 1, 1, 1);
   e_widget_frametable_object_append(o, e_widget_entry_add(evas, &(cfdata->wclass)),
				     1, 1, 1, 1,
				     1, 1, 1, 1);
   e_widget_frametable_object_append(o, e_widget_label_add(evas, _("Window Title")),
				     0, 2, 1, 1,
				     1, 1, 1, 1);
   e_widget_frametable_object_append(o, e_widget_entry_add(evas, &(cfdata->wtitle)),
				     1, 2, 1, 1,
				     1, 1, 1, 1);
   e_widget_frametable_object_append(o, e_widget_label_add(evas, _("Window Role")),
				     0, 3, 1, 1,
				     1, 1, 1, 1);
   e_widget_frametable_object_append(o, e_widget_entry_add(evas, &(cfdata->wrole)),
				     1, 3, 1, 1,
				     1, 1, 1, 1);
   e_widget_table_object_append(ol, o, 0, 2, 1, 1, 1 ,1, 1, 1);
   
   /*- icon info -*/
   o = e_widget_frametable_add(evas, _("Icon Theme"), 0);
      
   e_widget_frametable_object_append(o, e_widget_label_add(evas, _("Icon Class")),
				     0, 0, 1, 1,
				     1, 1, 1, 1);
   
   entry = e_widget_entry_add(evas, &(cfdata->iclass));
   e_widget_min_size_set(entry, 100, 1);   
   e_widget_frametable_object_append(o, entry,
				     1, 0, 1, 1,
				     1, 1, 1, 1);
   
   e_widget_table_object_append(ol, o, 1, 1, 1, 1, 1 ,1, 1, 1);
   
   
   /*- misc info -*/
   o = e_widget_frametable_add(evas, _("Misc"), 0);     
   e_widget_frametable_object_append(o, e_widget_check_add(evas, _("Startup Notify"), &(cfdata->startup_notify)),
				     0, 0, 1, 1,
				     1, 1, 1, 1);
   e_widget_frametable_object_append(o, e_widget_check_add(evas, _("Wait Exit"), &(cfdata->wait_exit)),
				     0, 1, 1, 1,
				     1, 1, 1, 1);
   e_widget_table_object_append(ol, o, 1, 2, 1, 1, 1 ,1, 1, 1);
      
   return ol;
}

void
_e_eap_edit_select_cb(Evas_Object *obj, char *file, void *data)
{
   E_App_Edit *editor;
   
   editor = data;
   editor->img_set = 1;
   printf("selected: %s\n", file);
}

void
_e_eap_edit_hilite_cb(Evas_Object *obj, char *file, void *data)
{
   E_App_Edit *editor;
   
   editor = data;
   editor->img_set = 1;   
   printf("hilited: %s\n", file);
}