aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/conf_display/e_int_config_desk.c
blob: cd4ab6915dbfd57308397309c958cbd66bed91e9 (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
#include "e.h"

static void *_create_data(E_Config_Dialog *cfd);
static void _free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
static int _basic_apply(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
static Evas_Object *_basic_create(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata);
static void _cb_config(void *data, void *data2);
static Eina_Bool _cb_bg_change(void *data, int type, void *event);

struct _E_Config_Dialog_Data 
{
   int con_num;
   int zone_num;
   int desk_x;
   int desk_y;
   char *bg;
   char *name;
   char *profile;
   
   Evas_Object *preview;
   Ecore_Event_Handler *hdl;
};

E_Config_Dialog *
e_int_config_desk(E_Container *con, const char *params)
{
   E_Config_Dialog *cfd;
   E_Config_Dialog_View *v;
   E_Config_Dialog_Data *cfdata;
   int con_num, zone_num, dx, dy;

   if (!params) return NULL;
   con_num = zone_num = dx = dy = -1;
   if (sscanf(params, "%i %i %i %i", &con_num, &zone_num, &dx, &dy) != 4)
     return NULL;
   
   if (e_config_dialog_find("E", "internal/desk")) return NULL;

   v = E_NEW(E_Config_Dialog_View, 1);
   
   cfdata = E_NEW(E_Config_Dialog_Data, 1);
   cfdata->con_num = con_num;
   cfdata->zone_num = zone_num;
   cfdata->desk_x = dx;
   cfdata->desk_y = dy;
   
   v->create_cfdata = _create_data;
   v->free_cfdata = _free_data;
   v->basic.apply_cfdata = _basic_apply;
   v->basic.create_widgets = _basic_create;
   v->override_auto_apply = 1;
   
   cfd = e_config_dialog_new(con, _("Desk Settings"), "E", "internal/desk",
			     "preferences-desktop", 0, v, cfdata);
   return cfd;
}

static void
_fill_data(E_Config_Dialog_Data *cfdata) 
{
   Eina_List *l;
   const char *bg;
   char name[40];
   int ok = 0;
   E_Config_Desktop_Window_Profile *prof;
   
   bg = e_bg_file_get(cfdata->con_num, cfdata->zone_num, cfdata->desk_x, cfdata->desk_y);
   if (!bg)
     bg = e_theme_edje_file_get("base/theme/backgrounds", "e/desktop/background");
   cfdata->bg = strdup(bg);
   
   for (l = e_config->desktop_names; l; l = l->next) 
     {
	E_Config_Desktop_Name *dn;
	
	dn = l->data;
	if (!dn) continue;
	if (dn->container != cfdata->con_num) continue;
	if (dn->zone != cfdata->zone_num) continue;
	if ((dn->desk_x != cfdata->desk_x) || (dn->desk_y != cfdata->desk_y)) 
	  continue;
	
	if (dn->name)
	  cfdata->name = strdup(dn->name);
	ok = 1;
	break;
     }
   if (!ok)
     {     
	snprintf(name, sizeof(name), _(e_config->desktop_default_name), cfdata->desk_x, cfdata->desk_y);
	cfdata->name = strdup(name);
     }

   ok = 0;
   EINA_LIST_FOREACH(e_config->desktop_window_profiles, l, prof)
     {
        if (!((prof->container == cfdata->con_num) &&
              (prof->zone == cfdata->zone_num) &&
              (prof->desk_x == cfdata->desk_x) &&
              (prof->desk_y == cfdata->desk_y)))
          continue;

        if (prof->profile)
          cfdata->profile = strdup(prof->profile);
        ok = 1;
        break;
     }

   if (!ok)
     cfdata->profile = strdup(e_config->desktop_default_window_profile);
}

static void *
_create_data(E_Config_Dialog *cfd) 
{
   E_Config_Dialog_Data *cfdata;
   
   cfdata = cfd->data;
   if (!cfdata) return NULL;
   _fill_data(cfdata);
   return cfdata;
}

static void
_free_data(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata) 
{
   if (cfdata->hdl)
     ecore_event_handler_del(cfdata->hdl);
   if (cfdata->bg)
     E_FREE(cfdata->bg);
   if (cfdata->name)
     E_FREE(cfdata->name);
   if (cfdata->profile)
     E_FREE(cfdata->profile);
   E_FREE(cfdata);
}

static int
_basic_apply(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata) 
{
   char name[40];
   
   if (!cfdata->name[0]) 
     {
	snprintf(name, sizeof(name), _(e_config->desktop_default_name), 
                 cfdata->desk_x, cfdata->desk_y);
	cfdata->name = strdup(name);
     }

   if (!cfdata->profile[0]) 
     cfdata->profile = strdup(e_config->desktop_default_window_profile);

   e_desk_name_del(cfdata->con_num, cfdata->zone_num, 
                   cfdata->desk_x, cfdata->desk_y);
   e_desk_name_add(cfdata->con_num, cfdata->zone_num, 
                   cfdata->desk_x, cfdata->desk_y, cfdata->name);
   e_desk_name_update();

   e_desk_window_profile_del(cfdata->con_num, cfdata->zone_num, 
                             cfdata->desk_x, cfdata->desk_y);
   e_desk_window_profile_add(cfdata->con_num, cfdata->zone_num, 
                             cfdata->desk_x, cfdata->desk_y, cfdata->profile);
   e_desk_window_profile_update();
   
   e_bg_del(cfdata->con_num, cfdata->zone_num, cfdata->desk_x, cfdata->desk_y);
   e_bg_add(cfdata->con_num, cfdata->zone_num, 
            cfdata->desk_x, cfdata->desk_y, cfdata->bg);
   e_bg_update();

   e_config_save_queue();
   return 1;
}

static Evas_Object *
_basic_create(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata) 
{
   Evas_Object *o, *of, *ob;
   E_Zone *zone;
   
   zone = e_zone_current_get(cfd->con);
   
   o = e_widget_list_add(evas, 0, 0);

   of = e_widget_frametable_add(evas, _("Desktop Name"), 0);
   ob = e_widget_label_add(evas, _("Name:"));
   e_widget_frametable_object_append(of, ob, 0, 0, 1, 1, 1, 1, 1, 0);
   ob = e_widget_entry_add(evas, &(cfdata->name), NULL, NULL, NULL);
   e_widget_frametable_object_append(of, ob, 1, 0, 2, 1, 1, 1, 1, 0);
   e_widget_list_object_append(o, of, 1, 1, 0.5);

   of = e_widget_frametable_add(evas, _("Desktop Window Profile"), 0);
   ob = e_widget_label_add(evas, _("Profile Name:"));
   e_widget_frametable_object_append(of, ob, 0, 0, 1, 1, 1, 1, 1, 0);
   ob = e_widget_entry_add(evas, &(cfdata->profile), NULL, NULL, NULL);
   e_widget_entry_readonly_set(ob, !(e_config->use_desktop_window_profile));
   e_widget_frametable_object_append(of, ob, 1, 0, 2, 1, 1, 1, 1, 0);
   e_widget_list_object_append(o, of, 1, 1, 0.5);
   
   of = e_widget_frametable_add(evas, _("Desktop Wallpaper"), 0);
   ob = e_widget_preview_add(evas, 240, (240 * zone->h) / zone->w);
   cfdata->preview = ob;
   if (cfdata->bg)
     e_widget_preview_edje_set(ob, cfdata->bg, "e/desktop/background");
   e_widget_frametable_object_append(of, ob, 0, 0, 3, 1, 1, 1, 1, 0);
   ob = e_widget_button_add(evas, _("Set"), "configure", 
			    _cb_config, cfdata, NULL);
   e_widget_frametable_object_append(of, ob, 1, 1, 1, 1, 1, 1, 1, 0);
   e_widget_list_object_append(o, of, 1, 1, 0.5);

   if (cfdata->hdl)
     ecore_event_handler_del(cfdata->hdl);
   cfdata->hdl = ecore_event_handler_add(E_EVENT_BG_UPDATE, _cb_bg_change, cfdata);
   
   return o;
}

static void 
_cb_config(void *data, void *data2 __UNUSED__) 
{
   E_Config_Dialog_Data *cfdata;
   char buf[256];
   
   cfdata = data;
   if (!cfdata) return;
   snprintf(buf, sizeof(buf), "%i %i %i %i", 
	    cfdata->con_num, cfdata->zone_num, cfdata->desk_x, cfdata->desk_y);
   e_configure_registry_call("internal/wallpaper_desk", 
                             e_container_current_get(e_manager_current_get()), 
                             buf);
}

static Eina_Bool
_cb_bg_change(void *data, int type, void *event)
{
   E_Event_Bg_Update *ev;
   E_Config_Dialog_Data *cfdata;
   const char *file;
   
   if (type != E_EVENT_BG_UPDATE) return ECORE_CALLBACK_PASS_ON;
   
   cfdata = data;
   ev = event;
   if (ev->container != cfdata->con_num) return ECORE_CALLBACK_PASS_ON;
   if (ev->zone != cfdata->zone_num) return ECORE_CALLBACK_PASS_ON;
   if (ev->desk_x != cfdata->desk_x) return ECORE_CALLBACK_PASS_ON;
   if (ev->desk_y != cfdata->desk_y) return ECORE_CALLBACK_PASS_ON;
   
   file = e_bg_file_get(cfdata->con_num, cfdata->zone_num, 
                        cfdata->desk_x, cfdata->desk_y);
   E_FREE(cfdata->bg);
   cfdata->bg = strdup(file);
   e_widget_preview_edje_set(cfdata->preview, cfdata->bg, 
                             "e/desktop/background");

   return ECORE_CALLBACK_PASS_ON;
}