i18n hunter strikes again :)
[platform/upstream/enlightenment.git] / src / bin / e_entry_dialog.c
1 #include "e.h"
2
3 /* Private function definitions */
4 static void _e_entry_dialog_free(E_Entry_Dialog *dia);
5 static void _e_entry_dialog_ok(void *data, E_Dialog *dia);
6 static void _e_entry_dialog_cancel(void *data, E_Dialog *dia);
7 static void _e_entry_dialog_delete(E_Win *win);
8
9 /* Externally accesible functions */
10 EAPI E_Entry_Dialog *
11 e_entry_dialog_show(const char *title, const char *icon, const char *text,
12                     const char *initial_text,
13                     const char *button_text, const char *button2_text,
14                     void (*ok_func)(char *text, void *data), 
15                     void (*cancel_func)(void *data), void *data) 
16 {
17    E_Entry_Dialog *ed;
18    E_Dialog *dia;
19    Evas_Object *o, *ob;
20    int w, h;
21
22    ed = E_OBJECT_ALLOC(E_Entry_Dialog, E_ENTRY_DIALOG_TYPE, _e_entry_dialog_free);
23    ed->ok.func = ok_func;
24    ed->ok.data = data;
25    ed->cancel.func = cancel_func;
26    ed->cancel.data = data;
27    if (initial_text)
28      ed->text = strdup(initial_text);
29    
30    dia = e_dialog_new(e_container_current_get(e_manager_current_get()), "E", "_entry_dialog");
31    if (!dia) 
32      {
33         e_object_del(E_OBJECT(ed));
34         return NULL;
35      }
36    dia->data = ed;
37    ed->dia = dia;
38    
39    e_win_delete_callback_set(dia->win, _e_entry_dialog_delete);
40    
41    if (title) e_dialog_title_set(dia, title);
42    if (icon) e_dialog_icon_set(dia, icon, 64);
43    
44    o = e_widget_list_add(dia->win->evas, 0, 0);
45    if (text) 
46      {
47         ob = e_widget_label_add(dia->win->evas, text);
48         e_widget_list_object_append(o, ob, 1, 0, 0.5);
49      }
50    
51    ed->entry = e_widget_entry_add(dia->win->evas, &(ed->text));
52    e_widget_list_object_append(o, ed->entry, 1, 1, 0.5);
53    e_widget_min_size_get(o, &w, &h);
54    e_dialog_content_set(dia, o, w, h);
55    
56    e_dialog_button_add(dia, !button_text ? _("OK") : button_text, NULL, _e_entry_dialog_ok, ed);
57    e_dialog_button_add(dia, !button2_text ? _("Cancel") : button2_text, NULL, _e_entry_dialog_cancel, ed);
58    
59    e_win_centered_set(dia->win, 1);
60    e_dialog_show(dia);
61    return ed;
62 }
63
64 /* Private Function Bodies */
65 static void
66 _e_entry_dialog_free(E_Entry_Dialog *ed)
67 {
68    e_object_del(E_OBJECT(ed->dia));
69    E_FREE(ed->text);
70    free(ed);
71 }
72     
73 static void
74 _e_entry_dialog_ok(void *data, E_Dialog *dia) 
75 {
76    E_Entry_Dialog *ed;
77    
78    ed = data;
79    e_object_ref(E_OBJECT(ed));
80    if (ed->ok.func) ed->ok.func(ed->text, ed->ok.data);
81    e_object_del(E_OBJECT(ed));
82    e_object_unref(E_OBJECT(ed));
83 }
84
85 static void
86 _e_entry_dialog_cancel(void *data, E_Dialog *dia) 
87 {
88    E_Entry_Dialog *ed;
89    
90    ed = data;
91    e_object_ref(E_OBJECT(ed));
92    if (ed->cancel.func) ed->cancel.func(ed->cancel.data);
93    e_object_del(E_OBJECT(ed));
94    e_object_unref(E_OBJECT(ed));
95 }
96
97 static void
98 _e_entry_dialog_delete(E_Win *win) 
99 {
100    E_Dialog *dia;
101    E_Entry_Dialog *ed;
102    
103    dia = win->data;
104    ed = dia->data;
105    e_object_del(E_OBJECT(ed));
106 }