summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Blumenkrantz <zmike@samsung.com>2014-07-30 12:27:56 -0400
committerMike Blumenkrantz <zmike@osg.samsung.com>2014-08-19 17:48:42 -0400
commitf87c66b44e6d5df17e5bfa2d018ceae7a71a6662 (patch)
tree571a385f6c8730c5935e210e01c0f11b0ddfb038
parent81101718581e44327a4a47c63ba18749ff3c2792 (diff)
add config menu in settings
-rw-r--r--src/Makefile.am2
-rw-r--r--src/ds_config.c65
-rw-r--r--src/e_mod_config.c244
-rw-r--r--src/e_mod_main.c46
-rw-r--r--src/e_mod_main.h5
5 files changed, 92 insertions, 270 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index d056588..f330a27 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -11,7 +11,7 @@ pkgdir = $(module_dir)/$(PACKAGE)/$(MODULE_ARCH)
11pkg_LTLIBRARIES = module.la 11pkg_LTLIBRARIES = module.la
12module_la_SOURCES = e_mod_main.h \ 12module_la_SOURCES = e_mod_main.h \
13 e_mod_main.c \ 13 e_mod_main.c \
14 e_mod_config.c \ 14 ds_config.c \
15 maximize.c \ 15 maximize.c \
16 moveresize.c \ 16 moveresize.c \
17 desksanity.c 17 desksanity.c
diff --git a/src/ds_config.c b/src/ds_config.c
new file mode 100644
index 0000000..9f20345
--- /dev/null
+++ b/src/ds_config.c
@@ -0,0 +1,65 @@
1#include "e_mod_main.h"
2
3static E_Int_Menu_Augmentation *maug = NULL;
4
5
6static void
7_ds_menu_ruler(void *data EINA_UNUSED, E_Menu *m EINA_UNUSED, E_Menu_Item *mi)
8{
9 ds_config->disable_ruler = mi->toggle;
10 if (ds_config->disable_ruler)
11 mr_shutdown();
12 else
13 mr_init();
14}
15
16static void
17_ds_menu_maximize(void *data EINA_UNUSED, E_Menu *m EINA_UNUSED, E_Menu_Item *mi)
18{
19 ds_config->disable_maximize = mi->toggle;
20 if (ds_config->disable_maximize)
21 maximize_shutdown();
22 else
23 maximize_init();
24}
25
26static void
27_ds_menu_add(void *data EINA_UNUSED, E_Menu *m)
28{
29 E_Menu_Item *mi;
30 E_Menu *subm;
31
32 mi = e_menu_item_new(m);
33 e_menu_item_label_set(mi, D_("Desksanity"));
34 e_menu_item_icon_edje_set(mi, mod->edje_file, "icon");
35
36 subm = e_menu_new();
37 e_menu_title_set(subm, D_("Options"));
38 e_menu_item_submenu_set(mi, subm);
39
40 mi = e_menu_item_new(subm);
41 e_menu_item_label_set(mi, D_("Disable Move/Resize Ruler"));
42 e_menu_item_check_set(mi, 1);
43 e_menu_item_toggle_set(mi, ds_config->disable_ruler);
44 e_menu_item_callback_set(mi, _ds_menu_ruler, NULL);
45
46 mi = e_menu_item_new(subm);
47 e_menu_item_label_set(mi, D_("Disable Maximize Effects"));
48 e_menu_item_check_set(mi, 1);
49 e_menu_item_toggle_set(mi, ds_config->disable_maximize);
50 e_menu_item_callback_set(mi, _ds_menu_maximize, NULL);
51}
52
53EINTERN void
54ds_config_init(void)
55{
56 maug = e_int_menus_menu_augmentation_add_sorted
57 ("config/1", D_("Desksanity"), _ds_menu_add, NULL, NULL, NULL);
58}
59
60EINTERN void
61ds_config_shutdown(void)
62{
63 e_int_menus_menu_augmentation_del("config/1", maug);
64 maug = NULL;
65}
diff --git a/src/e_mod_config.c b/src/e_mod_config.c
deleted file mode 100644
index 7733afb..0000000
--- a/src/e_mod_config.c
+++ /dev/null
@@ -1,244 +0,0 @@
1#include "e_mod_main.h"
2#if 0
3
4static void
5_free_data(E_Config_Dialog *cfd EINA_UNUSED, E_Config_Dialog_Data *cfdata EINA_UNUSED)
6{
7 mod->cfd = NULL;
8 mod->label = mod->cfd_list[0] = mod->cfd_list[1] = NULL;
9}
10/*
11static void *
12_create_data(E_Config_Dialog *cfd EINA_UNUSED)
13{
14 return NULL;
15}
16
17static int
18_basic_apply(E_Config_Dialog *cfd EINA_UNUSED, E_Config_Dialog_Data *cfdata EINA_UNUSED)
19{
20 return 0;
21}
22
23static int
24_basic_check_changed(E_Config_Dialog *cfd EINA_UNUSED, E_Config_Dialog_Data *cfdata EINA_UNUSED)
25{
26 return 0;
27}
28*/
29
30static void
31_obj_del(Echievement *ec, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
32{
33 if (obj == ec->dialog.icon)
34 ec->dialog.icon = NULL;
35 else
36 ec->dialog.label = NULL;
37}
38
39static Evas_Object *
40_item_create(Evas *evas, Echievement *ec, Eina_Bool save)
41{
42 Evas_Object *table, *icon, *label;
43 char progress[128];
44 unsigned int goal, counter;
45
46 etrophy_trophy_goal_get(ec->trophy, &goal, &counter);
47 table = e_widget_frametable_add(evas, D_(etrophy_trophy_name_get(ec->trophy)), 1);
48
49 icon = e_widget_image_add_from_file(evas, PACKAGE_DATA_DIR "/trophy.png",
50 64, 64);
51 if (save) ec->dialog.icon = icon;
52 evas_object_event_callback_add(icon, EVAS_CALLBACK_DEL, (Evas_Object_Event_Cb)_obj_del, ec);
53 e_widget_frametable_object_append(table, icon, 0, 0, 1, 2, 1, 1, 1, 0);
54 label = e_widget_label_add(evas, D_(etrophy_trophy_description_get(ec->trophy)));
55 e_widget_frametable_object_append(table, label, 1, 0, 3, 1, 1, 1, 1, 0);
56
57 if (etrophy_trophy_earned_get(ec->trophy))
58 {
59 char date[256];
60 char buf[512];
61 time_t t0;
62
63 t0 = etrophy_trophy_date_get(ec->trophy);
64 strftime(date, sizeof(date), "%d %B %Y - %r", localtime(&t0));
65 snprintf(buf, sizeof(buf), D_("Achieved: %s"), date);
66 label = e_widget_label_add(evas, buf);
67 }
68 else if (goal < 2)
69 label = e_widget_label_add(evas, D_("Not achieved"));
70 else
71 {
72 snprintf(progress, sizeof(progress), D_("Progress: %u/%u"), counter, goal);
73 label = e_widget_label_add(evas, progress);
74 }
75 if (save) ec->dialog.label = label;
76 evas_object_event_callback_add(label, EVAS_CALLBACK_DEL, (Evas_Object_Event_Cb)_obj_del, ec);
77 e_widget_frametable_object_append(table, label, 1, 1, 3, 1, 1, 1, 1, 0);
78
79 return table;
80}
81
82static Evas_Object *
83_basic_create(E_Config_Dialog *cfd EINA_UNUSED, Evas *evas, E_Config_Dialog_Data *cfdata EINA_UNUSED)
84{
85 Evas_Object *toolbook, *list, *item, *sf;
86 Echievement *ec;
87 int mw, mh, mww;
88
89 toolbook = e_widget_toolbook_add(evas, 48 * e_scale, 48 * e_scale);
90
91 /* FIXME it should be scrollable and all initial items should
92 be visible */
93 mod->cfd_list[0] = list = e_widget_list_add(evas, 1, 0);
94 EINA_INLIST_FOREACH(EINA_INLIST_GET(mod->trophies_list), ec)
95 {
96 if (!etrophy_trophy_earned_get(ec->trophy)) continue;
97 item = _item_create(evas, ec, EINA_FALSE);
98 e_widget_list_object_append(list, item, 1, 1, 0.5);
99 }
100 e_widget_size_min_get(list, &mw, &mh);
101
102 if (mw < 320) mw = 320;
103 if (mh < 220) mh = 220;
104
105 evas_object_resize(list, mw, mh);
106 sf = e_widget_scrollframe_simple_add(evas, list);
107 e_widget_size_min_set(sf, 320, 220);
108 e_widget_toolbook_page_append(toolbook, NULL, D_("My Trophies"),
109 sf, 1, 1, 1, 1, 0.5, 0.0);
110
111 mod->cfd_list[1] = list = e_widget_list_add(evas, 1, 0);
112
113 EINA_INLIST_FOREACH(EINA_INLIST_GET(mod->trophies_list), ec)
114 {
115 if ((!etrophy_trophy_earned_get(ec->trophy)) && (!etrophy_trophy_visibility_get(ec->trophy))) continue;
116 item = _item_create(evas, ec, EINA_TRUE);
117 e_widget_list_object_append(list, item, 1, 1, 0.5);
118 }
119 e_widget_size_min_get(list, &mww, &mh);
120
121 if (mww < mw) mww = mw;
122 if (mh < 220) mh = 220;
123
124 evas_object_resize(list, mww, mh);
125 sf = e_widget_scrollframe_simple_add(evas, list);
126 e_widget_size_min_set(sf, 320, 220);
127 e_widget_toolbook_page_append(toolbook, NULL, D_("All Trophies"),
128 sf, 1, 1, 1, 1, 0.5, 0.0);
129
130 e_widget_toolbook_page_show(toolbook, 0);
131 list = e_widget_list_add(evas, 0, 0);
132 e_widget_list_object_append(list, toolbook, 1, 1, 0.5);
133 {
134 char buf[1024];
135 unsigned score = etrophy_gamescore_trophies_points_get(ds_config->gs);
136
137 /* FIXME: this can look better */
138 snprintf(buf, sizeof(buf), DP_("%u Echievement Point", "%u Echievement Points", score), score);
139 mod->label = item = e_widget_label_add(evas, buf);
140 e_widget_list_object_append(list, item, 0, 0, 0.5);
141 }
142 return list;
143}
144
145static void
146_totals_update(void)
147{
148 char buf[1024];
149 unsigned score = etrophy_gamescore_trophies_points_get(ds_config->gs);
150
151 snprintf(buf, sizeof(buf), DP_("%u Echievement Point", "%u Echievement Points", score), score);
152 e_widget_label_text_set(mod->label, buf);
153}
154
155E_Config_Dialog *
156e_int_config_echievements(E_Container *con, const char *params EINA_UNUSED)
157{
158 E_Config_Dialog *cfd = NULL;
159 E_Config_Dialog_View *v = NULL;
160 char buf[4096];
161
162 if (e_config_dialog_find("Echievements", "extensions/echievements"))
163 return NULL;
164
165 mod->obj_del_cb = (Evas_Object_Event_Cb)_obj_del;
166 v = E_NEW(E_Config_Dialog_View, 1);
167 v->free_cfdata = _free_data;
168 v->basic.create_widgets = _basic_create;
169/*
170 v->create_cfdata = _create_data;
171 v->basic.apply_cfdata = _basic_apply;
172 v->basic.check_changed = _basic_check_changed;
173*/
174 snprintf(buf, sizeof(buf), "%s/e-module-echievements.edj",
175 mod->module->dir);
176
177 cfd = e_config_dialog_new(con, D_("Echievements"), "Echievements",
178 "extensions/echievements", buf, 0, v, NULL);
179
180 e_dialog_resizable_set(cfd->dia, 1);
181 mod->cfd = cfd;
182 return cfd;
183}
184
185EINTERN void
186ech_cfg_ech_update(Echievement *ec)
187{
188 char progress[128];
189 unsigned int goal, counter;
190
191 if (!mod->cfd) return;
192 if ((!ec->dialog.icon) || (!ec->dialog.label)) return;
193 etrophy_trophy_goal_get(ec->trophy, &goal, &counter);
194 if (etrophy_trophy_earned_get(ec->trophy))
195 {
196 char date[256];
197 char buf[512];
198 time_t t0;
199
200 t0 = etrophy_trophy_date_get(ec->trophy);
201 strftime(date, sizeof(date), "%d %B %Y - %r", localtime(&t0));
202 snprintf(buf, sizeof(buf), D_("Achieved: %s"), date);
203 e_widget_label_text_set(ec->dialog.label, buf);
204 }
205 else if (goal < 2)
206 e_widget_label_text_set(ec->dialog.label, D_("Not achieved"));
207 else
208 {
209 snprintf(progress, sizeof(progress), D_("Progress: %u/%u"), counter, goal);
210 e_widget_label_text_set(ec->dialog.label, progress);
211 }
212 e_widget_frametable_object_repack(e_widget_parent_get(ec->dialog.label), ec->dialog.label, 1, 1, 3, 1, 1, 1, 1, 0);
213 _totals_update();
214}
215
216EINTERN void
217ech_cfg_ech_add(Echievement *ec)
218{
219 Evas *e;
220 Evas_Object *item;
221 int mh;
222 int w;
223
224 if (!mod->cfd) return;
225 /* use "all trophies" list current width
226 * since it's guaranteed to be correct for the moment
227 */
228 evas_object_geometry_get(mod->cfd_list[1], NULL, NULL, &w, NULL);
229 e = evas_object_evas_get(mod->cfd_list[0]);
230 item = _item_create(e, ec, EINA_FALSE);
231 e_widget_list_object_append(mod->cfd_list[0], item, 1, 1, 0.5);
232 e_widget_size_min_get(mod->cfd_list[0], NULL, &mh);
233
234 evas_object_resize(mod->cfd_list[0], w, mh);
235
236 if (ec->dialog.icon || ec->dialog.label) return;
237
238 item = _item_create(e, ec, EINA_TRUE);
239 e_widget_list_object_append(mod->cfd_list[1], item, 1, 1, 0.5);
240 e_widget_size_min_get(mod->cfd_list[1], NULL, &mh);
241 evas_object_resize(mod->cfd_list[1], w, mh);
242 _totals_update();
243}
244#endif
diff --git a/src/e_mod_main.c b/src/e_mod_main.c
index 7b63dc5..ed0041c 100644
--- a/src/e_mod_main.c
+++ b/src/e_mod_main.c
@@ -2,7 +2,6 @@
2 2
3EAPI E_Module_Api e_modapi = {E_MODULE_API_VERSION, "Desksanity"}; 3EAPI E_Module_Api e_modapi = {E_MODULE_API_VERSION, "Desksanity"};
4static E_Config_DD *conf_edd = NULL; 4static E_Config_DD *conf_edd = NULL;
5static Eina_List *handlers = NULL;
6 5
7EINTERN Mod *mod = NULL; 6EINTERN Mod *mod = NULL;
8EINTERN Config *ds_config = NULL; 7EINTERN Config *ds_config = NULL;
@@ -16,46 +15,45 @@ _e_mod_ds_config_load(void)
16 #define T Config 15 #define T Config
17 #define D conf_edd 16 #define D conf_edd
18 E_CONFIG_VAL(D, T, config_version, UINT); 17 E_CONFIG_VAL(D, T, config_version, UINT);
18 E_CONFIG_VAL(D, T, disable_ruler, UCHAR);
19 E_CONFIG_VAL(D, T, disable_maximize, UCHAR);
19 20
20 //ds_config = e_config_domain_load("module.desksanity", conf_edd); 21 ds_config = e_config_domain_load("module.desksanity", conf_edd);
21 if (ds_config) 22 if (ds_config)
22 { 23 {
23 if (!e_util_module_config_check("Desksanity", ds_config->config_version, MOD_CONFIG_FILE_VERSION)) 24 if (!e_util_module_config_check("Desksanity", ds_config->config_version, MOD_CONFIG_FILE_VERSION))
24 {} 25 E_FREE(ds_config);
25 } 26 }
26 27
27 if (!ds_config) 28 if (!ds_config)
28 { 29 ds_config = E_NEW(Config, 1);
29 ds_config = E_NEW(Config, 1); 30 ds_config->config_version = MOD_CONFIG_FILE_VERSION;
30 ds_config->config_version = (MOD_CONFIG_FILE_EPOCH << 16);
31 }
32} 31}
33 32
34EAPI void * 33EAPI void *
35e_modapi_init(E_Module *m) 34e_modapi_init(E_Module *m)
36{ 35{
37 char buf[4096]; 36 char buf[PATH_MAX];
38 37
39 bindtextdomain(PACKAGE, LOCALEDIR); 38 bindtextdomain(PACKAGE, LOCALEDIR);
40 bind_textdomain_codeset(PACKAGE, "UTF-8"); 39 bind_textdomain_codeset(PACKAGE, "UTF-8");
41 40
42 snprintf(buf, sizeof(buf), "%s/e-module-desksanity.edj", m->dir); 41 snprintf(buf, sizeof(buf), "%s/e-module-desksanity.edj", m->dir);
43 elm_theme_overlay_add(NULL, buf); 42 elm_theme_overlay_add(NULL, buf);
44//
45 //e_configure_registry_category_add("appearance", 80, D_("Look"),
46 //NULL, "preferences-look");
47 //e_configure_registry_item_add("extensions/desksanity", 110, D_("Echievements"),
48 //NULL, buf, e_int_config_desksanity);
49 43
50 efx_init(); 44 efx_init();
45 _e_mod_ds_config_load();
51 46
52 mod = E_NEW(Mod, 1); 47 mod = E_NEW(Mod, 1);
53 mod->module = m; 48 mod->module = m;
54 mod->edje_file = eina_stringshare_add(buf); 49 mod->edje_file = eina_stringshare_add(buf);
55 50
51 ds_config_init();
56 ds_init(); 52 ds_init();
57 mr_init(); 53 if (!ds_config->disable_ruler)
58 maximize_init(); 54 mr_init();
55 if (!ds_config->disable_maximize)
56 maximize_init();
59 57
60 return m; 58 return m;
61} 59}
@@ -63,19 +61,17 @@ e_modapi_init(E_Module *m)
63EAPI int 61EAPI int
64e_modapi_shutdown(E_Module *m EINA_UNUSED) 62e_modapi_shutdown(E_Module *m EINA_UNUSED)
65{ 63{
66 e_configure_registry_item_del("appearance/desksanity"); 64 if (!ds_config->disable_maximize)
67 65 maximize_shutdown();
68 e_configure_registry_category_del("extensions"); 66 if (!ds_config->disable_ruler)
69 67 mr_shutdown();
70 E_FREE_FUNC(mod->cfd, e_object_del);
71 maximize_shutdown();
72 mr_shutdown();
73 ds_shutdown(); 68 ds_shutdown();
74 //e_config_domain_save("module.desksanity", conf_edd, ds_config); 69 ds_config_shutdown();
70 e_config_domain_save("module.desksanity", conf_edd, ds_config);
71 E_FREE(ds_config);
75 E_CONFIG_DD_FREE(conf_edd); 72 E_CONFIG_DD_FREE(conf_edd);
76 eina_stringshare_del(mod->edje_file); 73 eina_stringshare_del(mod->edje_file);
77 E_FREE(mod); 74 E_FREE(mod);
78 E_FREE_LIST(handlers, ecore_event_handler_del);
79 //efx_shutdown(); broken... 75 //efx_shutdown(); broken...
80 return 1; 76 return 1;
81} 77}
@@ -83,7 +79,7 @@ e_modapi_shutdown(E_Module *m EINA_UNUSED)
83EAPI int 79EAPI int
84e_modapi_save(E_Module *m EINA_UNUSED) 80e_modapi_save(E_Module *m EINA_UNUSED)
85{ 81{
86 //e_config_domain_save("module.desksanity", conf_edd, ds_config); 82 e_config_domain_save("module.desksanity", conf_edd, ds_config);
87 return 1; 83 return 1;
88} 84}
89 85
diff --git a/src/e_mod_main.h b/src/e_mod_main.h
index 38dc2b3..ab8f04b 100644
--- a/src/e_mod_main.h
+++ b/src/e_mod_main.h
@@ -35,6 +35,8 @@ typedef struct Mod
35typedef struct Config 35typedef struct Config
36{ 36{
37 unsigned int config_version; 37 unsigned int config_version;
38 Eina_Bool disable_ruler;
39 Eina_Bool disable_maximize;
38} Config; 40} Config;
39 41
40extern Mod *mod; 42extern Mod *mod;
@@ -49,4 +51,7 @@ EINTERN void mr_init(void);
49EINTERN void maximize_init(void); 51EINTERN void maximize_init(void);
50EINTERN void maximize_shutdown(void); 52EINTERN void maximize_shutdown(void);
51 53
54
55EINTERN void ds_config_init(void);
56EINTERN void ds_config_shutdown(void);
52#endif 57#endif