summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2021-02-20 20:16:38 +0000
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2021-02-20 20:16:38 +0000
commitd1486a92a0ef29e19c40d1ffcea0f6cafbc13c7d (patch)
tree64af4abeec50cb795bb82d64e05d2c6e240c1346
parentd91f0a6c0f3f14a81644e9b530e0b72f3aa08580 (diff)
use ecore_on url - nuke warnings and use mouse up for popup
-rw-r--r--src/e_mod_config.c14
-rw-r--r--src/e_mod_main.c281
-rw-r--r--src/e_mod_main.h1
3 files changed, 94 insertions, 202 deletions
diff --git a/src/e_mod_config.c b/src/e_mod_config.c
index d84c920..e13db6f 100644
--- a/src/e_mod_config.c
+++ b/src/e_mod_config.c
@@ -77,7 +77,7 @@ _create_data(E_Config_Dialog *cfd)
77} 77}
78 78
79static void 79static void
80_free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata) 80_free_data(E_Config_Dialog *cfd EINA_UNUSED, E_Config_Dialog_Data *cfdata)
81{ 81{
82 if (!forecasts_config) 82 if (!forecasts_config)
83 return; 83 return;
@@ -102,7 +102,7 @@ _poll_time_slider_changed_cb(void *data, Evas_Object *obj,
102} 102}
103 103
104static void 104static void
105_radio_changed_cb(void *data, Evas_Object *obj, 105_radio_changed_cb(void *data, Evas_Object *obj EINA_UNUSED,
106 void *event_info EINA_UNUSED) 106 void *event_info EINA_UNUSED)
107{ 107{
108 E_Config_Dialog *cfd = data; 108 E_Config_Dialog *cfd = data;
@@ -123,7 +123,7 @@ _text_location_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part)
123} 123}
124 124
125static void 125static void
126_item_location_del(void *data, Evas_Object *obj) 126_item_location_del(void *data, Evas_Object *obj EINA_UNUSED)
127{ 127{
128 Places_Location *location = data; 128 Places_Location *location = data;
129 129
@@ -131,7 +131,7 @@ _item_location_del(void *data, Evas_Object *obj)
131} 131}
132 132
133static void 133static void
134_locations_selected_cb(void *data, Evas_Object *obj, 134_locations_selected_cb(void *data, Evas_Object *obj EINA_UNUSED,
135 void *event_info EINA_UNUSED) 135 void *event_info EINA_UNUSED)
136{ 136{
137 E_Config_Dialog_Data *cfdata; 137 E_Config_Dialog_Data *cfdata;
@@ -186,8 +186,8 @@ _locations_fill(E_Config_Dialog_Data *cfdata)
186} 186}
187 187
188static void 188static void
189_categories_selected_cb(void *data, Evas_Object *obj, 189_categories_selected_cb(void *data, Evas_Object *obj EINA_UNUSED,
190 void *event_info EINA_UNUSED) 190 void *event_info EINA_UNUSED)
191{ 191{
192 E_Config_Dialog_Data *cfdata; 192 E_Config_Dialog_Data *cfdata;
193 Elm_Object_Item *it; 193 Elm_Object_Item *it;
@@ -206,7 +206,7 @@ _categories_selected_cb(void *data, Evas_Object *obj,
206} 206}
207 207
208static void 208static void
209_item_location_id_del(void *data, Evas_Object *obj) 209_item_location_id_del(void *data, Evas_Object *obj EINA_UNUSED)
210{ 210{
211 Places_Category *category = data; 211 Places_Category *category = data;
212 free(category); 212 free(category);
diff --git a/src/e_mod_main.c b/src/e_mod_main.c
index e86493e..3e4bd73 100644
--- a/src/e_mod_main.c
+++ b/src/e_mod_main.c
@@ -2,8 +2,7 @@
2#include "e_mod_main.h" 2#include "e_mod_main.h"
3#include <json-c/json.h> 3#include <json-c/json.h>
4 4
5#define _XOPEN_SOURCE 5char *strptime(const char *s, const char *format, struct tm *tm);
6#include <time.h>
7 6
8#define FORECASTS 2 7#define FORECASTS 2
9#define KM_TO_MI 1.609344 8#define KM_TO_MI 1.609344
@@ -42,10 +41,9 @@ struct _Instance
42 Evas_Object *forecasts_obj; 41 Evas_Object *forecasts_obj;
43 Forecasts *forecasts; 42 Forecasts *forecasts;
44 Ecore_Timer *check_timer; 43 Ecore_Timer *check_timer;
45 Ecore_Con_Server *server; 44 Ecore_Con_Url *url;
46 Ecore_Event_Handler *add_handler; 45 Ecore_Event_Handler *url_data_handler;
47 Ecore_Event_Handler *del_handler; 46 Ecore_Event_Handler *url_complete_handler;
48 Ecore_Event_Handler *data_handler;
49 47
50 struct 48 struct
51 { 49 {
@@ -99,17 +97,9 @@ struct _Forecasts
99 Evas_Object *icon_obj; 97 Evas_Object *icon_obj;
100}; 98};
101 99
102struct
103{
104 const char *host;
105 int port;
106} proxy = {
107 NULL, 0
108};
109
110/* Module Function Protos */ 100/* Module Function Protos */
111static void _forecasts_cb_mouse_down(void *data, Evas *e, Evas_Object *obj, 101static void _forecasts_cb_mouse_up(void *data, Evas *e, Evas_Object *obj,
112 void *event_info); 102 void *event_info);
113static void _forecasts_menu_cb_configure(void *data, E_Menu *m, 103static void _forecasts_menu_cb_configure(void *data, E_Menu *m,
114 E_Menu_Item *mi); 104 E_Menu_Item *mi);
115static void _forecasts_menu_cb_post(void *data, E_Menu *m); 105static void _forecasts_menu_cb_post(void *data, E_Menu *m);
@@ -117,10 +107,8 @@ static Eina_Bool _forecasts_cb_check(void *data);
117static Config_Item *_forecasts_config_item_get(const char *id); 107static Config_Item *_forecasts_config_item_get(const char *id);
118static Forecasts *_forecasts_new(Evas *evas); 108static Forecasts *_forecasts_new(Evas *evas);
119static void _forecasts_free(Forecasts *w); 109static void _forecasts_free(Forecasts *w);
120static void _forecasts_get_proxy(void); 110static Eina_Bool _forecasts_url_data(void *data, int type, void *event);
121static Eina_Bool _forecasts_server_add(void *data, int type, void *event); 111static Eina_Bool _forecasts_url_complete(void *data, int type, void *event);
122static Eina_Bool _forecasts_server_del(void *data, int type, void *event);
123static Eina_Bool _forecasts_server_data(void *data, int type, void *event);
124static int _forecasts_parse(void *data); 112static int _forecasts_parse(void *data);
125static void _forecasts_converter(Instance *inst); 113static void _forecasts_converter(Instance *inst);
126static void _forecasts_convert_degrees(int *value, int dir); 114static void _forecasts_convert_degrees(int *value, int dir);
@@ -128,7 +116,7 @@ static void _forecasts_convert_distances(int *value, int dir);
128static void _forecasts_convert_pressures(float *value, int dir); 116static void _forecasts_convert_pressures(float *value, int dir);
129static void _forecasts_display_set(Instance *inst, int ok); 117static void _forecasts_display_set(Instance *inst, int ok);
130static void _forecasts_popup_content_create(Instance *inst); 118static void _forecasts_popup_content_create(Instance *inst);
131static void _cb_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info); 119static void _cb_mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info);
132static void _cb_mouse_in(void *data, Evas *e, Evas_Object *obj, void *event_info); 120static void _cb_mouse_in(void *data, Evas *e, Evas_Object *obj, void *event_info);
133static void _cb_mouse_out(void *data, Evas *e, Evas_Object *obj, void *event_info); 121static void _cb_mouse_out(void *data, Evas *e, Evas_Object *obj, void *event_info);
134static Evas_Object *_forecasts_popup_icon_create(Evas *evas, const char *code); 122static Evas_Object *_forecasts_popup_icon_create(Evas *evas, const char *code);
@@ -159,28 +147,24 @@ _gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style)
159 inst->gcc = gcc; 147 inst->gcc = gcc;
160 inst->popup = NULL; 148 inst->popup = NULL;
161 inst->forecasts_obj = o; 149 inst->forecasts_obj = o;
162 evas_object_event_callback_add(inst->forecasts_obj, EVAS_CALLBACK_MOUSE_DOWN, 150 evas_object_event_callback_add(inst->forecasts_obj, EVAS_CALLBACK_MOUSE_UP,
163 _cb_mouse_down, inst); 151 _cb_mouse_up, inst);
164 evas_object_event_callback_add(inst->forecasts_obj, EVAS_CALLBACK_MOUSE_IN, 152 evas_object_event_callback_add(inst->forecasts_obj, EVAS_CALLBACK_MOUSE_IN,
165 _cb_mouse_in, inst); 153 _cb_mouse_in, inst);
166 evas_object_event_callback_add(inst->forecasts_obj, EVAS_CALLBACK_MOUSE_OUT, 154 evas_object_event_callback_add(inst->forecasts_obj, EVAS_CALLBACK_MOUSE_OUT,
167 _cb_mouse_out, inst); 155 _cb_mouse_out, inst);
168 156
169 if (!inst->add_handler) 157 if (!inst->url_data_handler)
170 inst->add_handler = 158 inst->url_data_handler =
171 ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, 159 ecore_event_handler_add(ECORE_CON_EVENT_URL_DATA,
172 _forecasts_server_add, inst); 160 _forecasts_url_data, inst);
173 if (!inst->del_handler) 161 if (!inst->url_complete_handler)
174 inst->del_handler = 162 inst->url_complete_handler =
175 ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DEL, 163 ecore_event_handler_add(ECORE_CON_EVENT_URL_COMPLETE,
176 _forecasts_server_del, inst); 164 _forecasts_url_complete, inst);
177 if (!inst->data_handler) 165
178 inst->data_handler = 166 evas_object_event_callback_add(w->forecasts_obj, EVAS_CALLBACK_MOUSE_UP,
179 ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DATA, 167 _forecasts_cb_mouse_up, inst);
180 _forecasts_server_data, inst);
181
182 evas_object_event_callback_add(w->forecasts_obj, EVAS_CALLBACK_MOUSE_DOWN,
183 _forecasts_cb_mouse_down, inst);
184 forecasts_config->instances = 168 forecasts_config->instances =
185 eina_list_append(forecasts_config->instances, inst); 169 eina_list_append(forecasts_config->instances, inst);
186 170
@@ -202,24 +186,22 @@ _gc_shutdown(E_Gadcon_Client *gcc)
202 if (inst->popup) _forecasts_popup_destroy(inst); 186 if (inst->popup) _forecasts_popup_destroy(inst);
203 if (inst->check_timer) 187 if (inst->check_timer)
204 ecore_timer_del(inst->check_timer); 188 ecore_timer_del(inst->check_timer);
205 if (inst->add_handler) 189 if (inst->url_data_handler)
206 ecore_event_handler_del(inst->add_handler); 190 ecore_event_handler_del(inst->url_data_handler);
207 if (inst->data_handler) 191 if (inst->url_complete_handler)
208 ecore_event_handler_del(inst->data_handler); 192 ecore_event_handler_del(inst->url_complete_handler);
209 if (inst->del_handler) 193 if (inst->url)
210 ecore_event_handler_del(inst->del_handler); 194 ecore_con_url_free(inst->url);
211 if (inst->server)
212 ecore_con_server_del(inst->server);
213 if (inst->area) 195 if (inst->area)
214 eina_stringshare_del(inst->area); 196 eina_stringshare_del(inst->area);
215 eina_strbuf_free(inst->buffer); 197 eina_strbuf_free(inst->buffer);
216 198
217 inst->server = NULL; 199 inst->url = NULL;
218 forecasts_config->instances = 200 forecasts_config->instances =
219 eina_list_remove(forecasts_config->instances, inst); 201 eina_list_remove(forecasts_config->instances, inst);
220 202
221 evas_object_event_callback_del(w->forecasts_obj, EVAS_CALLBACK_MOUSE_DOWN, 203 evas_object_event_callback_del(w->forecasts_obj, EVAS_CALLBACK_MOUSE_UP,
222 _forecasts_cb_mouse_down); 204 _forecasts_cb_mouse_up);
223 205
224 _forecasts_free(w); 206 _forecasts_free(w);
225 E_FREE(inst); 207 E_FREE(inst);
@@ -249,13 +231,13 @@ _gc_orient(E_Gadcon_Client *gcc, E_Gadcon_Orient orient)
249} 231}
250 232
251static const char * 233static const char *
252_gc_label(const E_Gadcon_Client_Class *client_class) 234_gc_label(const E_Gadcon_Client_Class *client_class EINA_UNUSED)
253{ 235{
254 return D_("Forecasts"); 236 return D_("Forecasts");
255} 237}
256 238
257static Evas_Object * 239static Evas_Object *
258_gc_icon(const E_Gadcon_Client_Class *client_class, Evas *evas) 240_gc_icon(const E_Gadcon_Client_Class *client_class EINA_UNUSED, Evas *evas)
259{ 241{
260 Evas_Object *o; 242 Evas_Object *o;
261 char buf[4096]; 243 char buf[4096];
@@ -268,7 +250,7 @@ _gc_icon(const E_Gadcon_Client_Class *client_class, Evas *evas)
268} 250}
269 251
270static const char * 252static const char *
271_gc_id_new(const E_Gadcon_Client_Class *client_class) 253_gc_id_new(const E_Gadcon_Client_Class *client_class EINA_UNUSED)
272{ 254{
273 Config_Item *ci; 255 Config_Item *ci;
274 256
@@ -277,14 +259,14 @@ _gc_id_new(const E_Gadcon_Client_Class *client_class)
277} 259}
278 260
279static void 261static void
280_forecasts_cb_mouse_down(void *data, Evas *e, Evas_Object *obj, 262_forecasts_cb_mouse_up(void *data, Evas *e EINA_UNUSED,
281 void *event_info) 263 Evas_Object *obj EINA_UNUSED,
264 void *event_info)
282{ 265{
283 Instance *inst; 266 Instance *inst = data;
284 Evas_Event_Mouse_Down *ev; 267 Evas_Event_Mouse_Up *ev = event_info;
285 268
286 inst = data; 269 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
287 ev = event_info;
288 if ((ev->button == 3) && (!forecasts_config->menu)) 270 if ((ev->button == 3) && (!forecasts_config->menu))
289 { 271 {
290 E_Menu *m; 272 E_Menu *m;
@@ -312,7 +294,7 @@ _forecasts_cb_mouse_down(void *data, Evas *e, Evas_Object *obj,
312} 294}
313 295
314static void 296static void
315_forecasts_menu_cb_post(void *data, E_Menu *m) 297_forecasts_menu_cb_post(void *data EINA_UNUSED, E_Menu *m EINA_UNUSED)
316{ 298{
317 if (!forecasts_config->menu) 299 if (!forecasts_config->menu)
318 return; 300 return;
@@ -321,7 +303,7 @@ _forecasts_menu_cb_post(void *data, E_Menu *m)
321} 303}
322 304
323static void 305static void
324_forecasts_menu_cb_configure(void *data, E_Menu *m, E_Menu_Item *mi) 306_forecasts_menu_cb_configure(void *data, E_Menu *m EINA_UNUSED, E_Menu_Item *mi EINA_UNUSED)
325{ 307{
326 Instance *inst; 308 Instance *inst;
327 309
@@ -367,7 +349,6 @@ _forecasts_config_item_get(const char *id)
367 ci->id = eina_stringshare_add(id); 349 ci->id = eina_stringshare_add(id);
368 ci->poll_time = 60.0; 350 ci->poll_time = 60.0;
369 ci->degrees = DEGREES_C; 351 ci->degrees = DEGREES_C;
370 ci->host = eina_stringshare_add("www.enlightenment.org");
371 ci->lat = ci->lon = 0; 352 ci->lat = ci->lon = 0;
372 ci->show_text = 1; 353 ci->show_text = 1;
373 ci->popup_on_hover = 1; 354 ci->popup_on_hover = 1;
@@ -385,6 +366,7 @@ E_API E_Module_Api e_modapi = {
385E_API void * 366E_API void *
386e_modapi_init(E_Module *m) 367e_modapi_init(E_Module *m)
387{ 368{
369 ecore_con_url_init();
388 bindtextdomain(PACKAGE, LOCALE_DIR); 370 bindtextdomain(PACKAGE, LOCALE_DIR);
389 bind_textdomain_codeset(PACKAGE, "UTF-8"); 371 bind_textdomain_codeset(PACKAGE, "UTF-8");
390 372
@@ -396,7 +378,6 @@ e_modapi_init(E_Module *m)
396 E_CONFIG_VAL(D, T, id, STR); 378 E_CONFIG_VAL(D, T, id, STR);
397 E_CONFIG_VAL(D, T, poll_time, DOUBLE); 379 E_CONFIG_VAL(D, T, poll_time, DOUBLE);
398 E_CONFIG_VAL(D, T, degrees, INT); 380 E_CONFIG_VAL(D, T, degrees, INT);
399 E_CONFIG_VAL(D, T, host, STR);
400 E_CONFIG_VAL(D, T, show_text, INT); 381 E_CONFIG_VAL(D, T, show_text, INT);
401 E_CONFIG_VAL(D, T, popup_on_hover, INT); 382 E_CONFIG_VAL(D, T, popup_on_hover, INT);
402 E_CONFIG_VAL(D, T, location_id, INT); 383 E_CONFIG_VAL(D, T, location_id, INT);
@@ -421,7 +402,6 @@ e_modapi_init(E_Module *m)
421 ci = E_NEW(Config_Item, 1); 402 ci = E_NEW(Config_Item, 1);
422 ci->poll_time = 60.0; 403 ci->poll_time = 60.0;
423 ci->degrees = DEGREES_C; 404 ci->degrees = DEGREES_C;
424 ci->host = eina_stringshare_add("www.enlightenment.org");
425 ci->lat = ci->lon = 0; 405 ci->lat = ci->lon = 0;
426 ci->id = eina_stringshare_add("0"); 406 ci->id = eina_stringshare_add("0");
427 ci->show_text = 1; 407 ci->show_text = 1;
@@ -429,7 +409,6 @@ e_modapi_init(E_Module *m)
429 409
430 forecasts_config->items = eina_list_append(forecasts_config->items, ci); 410 forecasts_config->items = eina_list_append(forecasts_config->items, ci);
431 } 411 }
432 _forecasts_get_proxy();
433 412
434 forecasts_config->module = m; 413 forecasts_config->module = m;
435 e_gadcon_provider_register(&_gadcon_class); 414 e_gadcon_provider_register(&_gadcon_class);
@@ -437,7 +416,7 @@ e_modapi_init(E_Module *m)
437} 416}
438 417
439E_API int 418E_API int
440e_modapi_shutdown(E_Module *m) 419e_modapi_shutdown(E_Module *m EINA_UNUSED)
441{ 420{
442 forecasts_config->module = NULL; 421 forecasts_config->module = NULL;
443 e_gadcon_provider_unregister(&_gadcon_class); 422 e_gadcon_provider_unregister(&_gadcon_class);
@@ -458,8 +437,6 @@ e_modapi_shutdown(E_Module *m)
458 ci = forecasts_config->items->data; 437 ci = forecasts_config->items->data;
459 if (ci->id) 438 if (ci->id)
460 eina_stringshare_del(ci->id); 439 eina_stringshare_del(ci->id);
461 if (ci->host)
462 eina_stringshare_del(ci->host);
463 if (ci->location) 440 if (ci->location)
464 eina_stringshare_del(ci->location); 441 eina_stringshare_del(ci->location);
465 442
@@ -472,11 +449,12 @@ e_modapi_shutdown(E_Module *m)
472 E_FREE(forecasts_config); 449 E_FREE(forecasts_config);
473 E_CONFIG_DD_FREE(conf_item_edd); 450 E_CONFIG_DD_FREE(conf_item_edd);
474 E_CONFIG_DD_FREE(conf_edd); 451 E_CONFIG_DD_FREE(conf_edd);
452 ecore_con_url_shutdown();
475 return 1; 453 return 1;
476} 454}
477 455
478E_API int 456E_API int
479e_modapi_save(E_Module *m) 457e_modapi_save(E_Module *m EINA_UNUSED)
480{ 458{
481 e_config_domain_save("module.forecasts", conf_edd, forecasts_config); 459 e_config_domain_save("module.forecasts", conf_edd, forecasts_config);
482 return 1; 460 return 1;
@@ -529,101 +507,47 @@ _forecasts_free(Forecasts *w)
529 w = NULL; 507 w = NULL;
530} 508}
531 509
532static void
533_forecasts_get_proxy(void)
534{
535 const char *env;
536 const char *host = NULL;
537 const char *p;
538 int port = 0;
539
540 env = getenv("http_proxy");
541 if ((!env) || (!*env)) env = getenv("HTTP_PROXY");
542 if ((!env) || (!*env)) return;
543 if (strncmp(env, "http://", 7)) return;
544
545 host = strchr(env, ':');
546 host += 3;
547 p = strchr(host, ':');
548 if (p)
549 {
550 if (sscanf(p + 1, "%d", &port) != 1)
551 port = 0;
552 }
553 if ((host) && (port))
554 {
555 if (proxy.host) eina_stringshare_del(proxy.host);
556 proxy.host = eina_stringshare_add_length(host, p - host);
557 proxy.port = port;
558 }
559}
560
561static Eina_Bool 510static Eina_Bool
562_forecasts_cb_check(void *data) 511_forecasts_cb_check(void *data)
563{ 512{
564 Instance *inst; 513 Instance *inst = data;
565 514 char buf[256];
566 /* check that data is valid */
567 if (!(inst = data)) return EINA_FALSE;
568 515
569 /* if we have a previous server, delete it */ 516 /* if we have a previous server, delete it */
570 if (inst->server) ecore_con_server_del(inst->server); 517 if (inst->url) ecore_con_url_free(inst->url);
571 518 snprintf(buf, sizeof(buf),
572 /* server deleted, set variable to NULL */ 519 "https://www.enlightenment.org/weather.php?lat=%s&lon=%s",
573 inst->server = NULL; 520 inst->ci->lat, inst->ci->lon);
574 521 DEBUG("FC: URL: %s", buf);
575 if (proxy.port != 0) 522 inst->url = ecore_con_url_new(buf);
576 inst->server = 523 if (!inst->url) return EINA_FALSE;
577 ecore_con_server_connect(ECORE_CON_REMOTE_NODELAY, 524 ecore_con_url_http_version_set(inst->url, ECORE_CON_URL_HTTP_VERSION_1_0);
578 proxy.host, proxy.port, inst); 525 ecore_con_url_get(inst->url);
579 else
580 inst->server =
581 ecore_con_server_connect(ECORE_CON_REMOTE_NODELAY | ECORE_CON_USE_MIXED, inst->ci->host, 443, inst);
582
583 if (!inst->server) return EINA_FALSE;
584 return EINA_TRUE; 526 return EINA_TRUE;
585} 527}
586 528
587static Eina_Bool 529static Eina_Bool
588_forecasts_server_add(void *data, int type, void *event) 530_forecasts_url_data(void *data, int type EINA_UNUSED, void *event)
589{ 531{
590 Instance *inst; 532 Instance *inst = data;
591 Ecore_Con_Event_Server_Add *ev; 533 Ecore_Con_Event_Url_Data *ev = event;
592 char buf[1024];
593 char forecast[1024];
594 534
595 inst = data; 535 if ((!inst->url) || (inst->url != ev->url_con)) return EINA_TRUE;
596 if (!inst) 536 eina_strbuf_append_length(inst->buffer, (const char *)ev->data, ev->size);
597 return EINA_TRUE;
598
599 ev = event;
600 if ((!inst->server) || (inst->server != ev->server))
601 return EINA_TRUE;
602
603 snprintf(forecast, sizeof(forecast), "/weather.php?lat=%s&lon=%s", inst->ci->lat, inst->ci->lon);
604 snprintf(buf, sizeof(buf)-strlen(forecast)-(strlen(inst->ci->host)*2), "GET https://%s%s HTTP/1.1\r\n"
605 "Host: %s\r\n"
606 "Connection: close\r\n\r\n",
607 inst->ci->host, forecast, inst->ci->host);
608 DEBUG("Server: %s", buf);
609 ecore_con_server_send(inst->server, buf, strlen(buf));
610 return EINA_FALSE; 537 return EINA_FALSE;
611} 538}
612 539
613static Eina_Bool 540static Eina_Bool
614_forecasts_server_del(void *data, int type, void *event) 541_forecasts_url_complete(void *data, int type EINA_UNUSED, void *event)
615{ 542{
616 Instance *inst; 543 Instance *inst = data;
617 Ecore_Con_Event_Server_Del *ev; 544 Ecore_Con_Event_Url_Complete *ev = event;
618 int ret; 545 int ret;
619 546
620 inst = data; 547 if ((!inst->url) || (inst->url != ev->url_con)) return EINA_TRUE;
621 ev = event; 548 DEBUG("FC: status: %i %s", ev->status, eina_strbuf_string_get(inst->buffer));
622 if ((!inst->server) || (inst->server != ev->server)) 549 ecore_con_url_free(inst->url);
623 return EINA_TRUE; 550 inst->url = NULL;
624
625 ecore_con_server_del(inst->server);
626 inst->server = NULL;
627 551
628 eina_stringshare_replace(&inst->location, inst->ci->location); 552 eina_stringshare_replace(&inst->location, inst->ci->location);
629 ret = _forecasts_parse(inst); 553 ret = _forecasts_parse(inst);
@@ -631,22 +555,6 @@ _forecasts_server_del(void *data, int type, void *event)
631 _forecasts_display_set(inst, ret); 555 _forecasts_display_set(inst, ret);
632 556
633 eina_strbuf_string_free(inst->buffer); 557 eina_strbuf_string_free(inst->buffer);
634
635 return EINA_FALSE;
636}
637
638static Eina_Bool
639_forecasts_server_data(void *data, int type, void *event)
640{
641 Instance *inst;
642 Ecore_Con_Event_Server_Data *ev;
643
644 inst = data;
645 ev = event;
646
647 if ((!inst->server) || (inst->server != ev->server))
648 return EINA_TRUE;
649 eina_strbuf_append_length(inst->buffer, ev->data, ev->size);
650 return EINA_FALSE; 558 return EINA_FALSE;
651} 559}
652 560
@@ -678,8 +586,8 @@ _epoch_days(struct tm *tm_in)
678static int 586static int
679_forecasts_parse(void *data) 587_forecasts_parse(void *data)
680{ 588{
681 Instance *inst; 589 Instance *inst = data;
682 char *needle; 590 const char *result;
683 const char *timestamp, *code; 591 const char *timestamp, *code;
684 time_t now; 592 time_t now;
685 struct tm *tm_local, *tm_data; 593 struct tm *tm_local, *tm_data;
@@ -695,11 +603,7 @@ _forecasts_parse(void *data)
695 "Sat", 603 "Sat",
696 }; 604 };
697 605
698 inst = data; 606 if (!inst->buffer) return 0;
699 if (!inst)
700 return 0;
701 if (!inst->buffer)
702 return 0;
703 607
704 for (int i = 0; i < FORECASTS; i++) 608 for (int i = 0; i < FORECASTS; i++)
705 { 609 {
@@ -710,11 +614,10 @@ _forecasts_parse(void *data)
710 tm_local = localtime(&now); 614 tm_local = localtime(&now);
711 days_prev = _epoch_days(tm_local); 615 days_prev = _epoch_days(tm_local);
712 616
713 needle = strstr(eina_strbuf_string_get(inst->buffer), "\r\n\r\n"); 617 result = eina_strbuf_string_get(inst->buffer);
714 if (!needle) goto error; 618 if (!result) goto error;
715 needle += 4;
716 619
717 json_object *o_root = json_tokener_parse(needle); 620 json_object *o_root = json_tokener_parse(result);
718 if (!o_root) goto error; 621 if (!o_root) goto error;
719 json_object *o_properties = json_object_object_get(o_root, "properties"); 622 json_object *o_properties = json_object_object_get(o_root, "properties");
720 if (!o_properties) goto error; 623 if (!o_properties) goto error;
@@ -805,7 +708,7 @@ _forecasts_parse(void *data)
805 return 1; 708 return 1;
806 709
807error: 710error:
808 fprintf(stderr, "ERROR: Couldn't parse info from %s\n", inst->ci->host); 711 printf("FC: ERROR: Couldn't parse info\n");
809 return 0; 712 return 0;
810} 713}
811 714
@@ -871,13 +774,12 @@ _forecasts_convert_pressures(float *value, int dir)
871} 774}
872 775
873static void 776static void
874_forecasts_display_set(Instance *inst, int ok) 777_forecasts_display_set(Instance *inst, int ok EINA_UNUSED)
875{ 778{
876 char buf[4096]; 779 char buf[4096];
877 char m[4096]; 780 char m[4096];
878 781
879 if (!inst) 782 if (!inst) return;
880 return;
881 783
882 snprintf(m, sizeof(m), "%s/forecasts.edj", 784 snprintf(m, sizeof(m), "%s/forecasts.edj",
883 e_module_dir_get(forecasts_config->module)); 785 e_module_dir_get(forecasts_config->module));
@@ -1175,13 +1077,12 @@ _forecasts_popup_destroy(Instance *inst)
1175} 1077}
1176 1078
1177static void 1079static void
1178_cb_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info) 1080_cb_mouse_up(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
1179{ 1081{
1180 Instance *inst; 1082 Instance *inst = data;
1181 Evas_Event_Mouse_Down *ev; 1083 Evas_Event_Mouse_Up *ev = event_info;
1182
1183 if (!(inst = data)) return;
1184 1084
1085 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
1185 if (!inst->ci->popup_on_hover) 1086 if (!inst->ci->popup_on_hover)
1186 { 1087 {
1187 if (!inst->popup) _forecasts_popup_content_create(inst); 1088 if (!inst->popup) _forecasts_popup_content_create(inst);
@@ -1189,33 +1090,25 @@ _cb_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info)
1189 return; 1090 return;
1190 } 1091 }
1191 1092
1192 ev = event_info; 1093 if (ev->button == 1) e_gadcon_popup_toggle_pinned(inst->popup);
1193 if (ev->button == 1)
1194 {
1195 e_gadcon_popup_toggle_pinned(inst->popup);
1196 }
1197} 1094}
1198 1095
1199static void 1096static void
1200_cb_mouse_in(void *data, Evas *e, Evas_Object *obj, void *event_info) 1097_cb_mouse_in(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
1201{ 1098{
1202 Instance *inst; 1099 Instance *inst = data;
1203 1100
1204 if (!(inst = data)) return;
1205 if (!inst->ci->popup_on_hover) return; 1101 if (!inst->ci->popup_on_hover) return;
1206
1207 if (!inst->popup) _forecasts_popup_content_create(inst); 1102 if (!inst->popup) _forecasts_popup_content_create(inst);
1208 e_gadcon_popup_show(inst->popup); 1103 e_gadcon_popup_show(inst->popup);
1209} 1104}
1210 1105
1211static void 1106static void
1212_cb_mouse_out(void *data, Evas *e, Evas_Object *obj, void *event_info) 1107_cb_mouse_out(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
1213{ 1108{
1214 Instance *inst; 1109 Instance *inst = data;
1215 1110
1216 if (!(inst = data)) return;
1217 if (!(inst->popup)) return; 1111 if (!(inst->popup)) return;
1218
1219 if (inst->popup->pinned) return; 1112 if (inst->popup->pinned) return;
1220 e_gadcon_popup_hide(inst->popup); 1113 e_gadcon_popup_hide(inst->popup);
1221} 1114}
diff --git a/src/e_mod_main.h b/src/e_mod_main.h
index 78dd1af..e867224 100644
--- a/src/e_mod_main.h
+++ b/src/e_mod_main.h
@@ -34,7 +34,6 @@ struct _Config_Item
34 34
35 double poll_time; 35 double poll_time;
36 int degrees; 36 int degrees;
37 const char *host;
38 int show_text; 37 int show_text;
39 int popup_on_hover; 38 int popup_on_hover;
40 39