summaryrefslogtreecommitdiff
path: root/src/bin/e_bg.c
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@gmail.com>2009-12-17 23:05:51 +0000
committerGustavo Sverzut Barbieri <barbieri@gmail.com>2009-12-17 23:05:51 +0000
commit8a8025c6d84e49b264d1e1974e64869123cb67fc (patch)
treec8e63b0e395bdd68f9bd0fffb3a40c7f61e29fe4 /src/bin/e_bg.c
parent9710ec6536b0df66d6b0748ead00b542aa3ed4a6 (diff)
e_bg: improvements and start import process (unfinished!)
I ran out of time, so if someone wants to finish the move of e_int_config_wallpaper_import.c to standard e_bg.c I appreciate the help. Skeleton is there. With this, it is possible to remove code from conf_wallpaper and have that functionality in both wallpaper and wallpaper2. SVN revision: 44527
Diffstat (limited to 'src/bin/e_bg.c')
-rw-r--r--src/bin/e_bg.c171
1 files changed, 145 insertions, 26 deletions
diff --git a/src/bin/e_bg.c b/src/bin/e_bg.c
index 28c7cb7..053082e 100644
--- a/src/bin/e_bg.c
+++ b/src/bin/e_bg.c
@@ -27,6 +27,16 @@ struct _E_Bg_Anim_Params
27 } freedom; 27 } freedom;
28}; 28};
29 29
30struct _E_Bg_Image_Import
31{
32 E_Object e_obj_inherit;
33 struct {
34 void (*func)(void *data, const char *edje_file);
35 void *data;
36 } cb;
37 // TODO: win and widget meat
38};
39
30/* externally accessible functions */ 40/* externally accessible functions */
31EAPI int 41EAPI int
32e_bg_init(void) 42e_bg_init(void)
@@ -39,7 +49,13 @@ e_bg_init(void)
39 "preferences-desktop-wallpaper", 49 "preferences-desktop-wallpaper",
40 e_bg_handler_set, NULL, 50 e_bg_handler_set, NULL,
41 e_bg_handler_test, NULL); 51 e_bg_handler_test, NULL);
42 if (bg_hdl) e_fm2_mime_handler_glob_add(bg_hdl, "*.edj"); 52 if (bg_hdl)
53 {
54 e_fm2_mime_handler_glob_add(bg_hdl, "*.edj");
55 // TODO:
56 //e_fm2_mime_handler_mime_add(bg_hdl, "image/png");
57 //e_fm2_mime_handler_mime_add(bg_hdl, "image/jpeg");
58 }
43 59
44 /* Register files in use */ 60 /* Register files in use */
45 if (e_config->desktop_default_background) 61 if (e_config->desktop_default_background)
@@ -383,9 +399,19 @@ e_bg_zone_slide(E_Zone *zone, int prev_x, int prev_y)
383} 399}
384 400
385EAPI void 401EAPI void
386e_bg_default_set(char *file) 402e_bg_default_set(const char *file)
387{ 403{
388 E_Event_Bg_Update *ev; 404 E_Event_Bg_Update *ev;
405 Eina_Bool changed;
406
407 file = eina_stringshare_add(file);
408 changed = file != e_config->desktop_default_background;
409
410 if (!changed)
411 {
412 eina_stringshare_del(file);
413 return;
414 }
389 415
390 if (e_config->desktop_default_background) 416 if (e_config->desktop_default_background)
391 { 417 {
@@ -396,7 +422,7 @@ e_bg_default_set(char *file)
396 if (file) 422 if (file)
397 { 423 {
398 e_filereg_register(file); 424 e_filereg_register(file);
399 e_config->desktop_default_background = eina_stringshare_add(file); 425 e_config->desktop_default_background = file;
400 } 426 }
401 else 427 else
402 e_config->desktop_default_background = NULL; 428 e_config->desktop_default_background = NULL;
@@ -410,18 +436,35 @@ e_bg_default_set(char *file)
410} 436}
411 437
412EAPI void 438EAPI void
413e_bg_add(int container, int zone, int desk_x, int desk_y, char *file) 439e_bg_add(int container, int zone, int desk_x, int desk_y, const char *file)
414{ 440{
441 const Eina_List *l;
415 E_Config_Desktop_Background *cfbg; 442 E_Config_Desktop_Background *cfbg;
416 E_Event_Bg_Update *ev; 443 E_Event_Bg_Update *ev;
417 444
445 file = eina_stringshare_add(file);
446
447 EINA_LIST_FOREACH(e_config->desktop_backgrounds, l, cfbg)
448 {
449 if ((cfbg) &&
450 (cfbg->container == container) &&
451 (cfbg->zone == zone) &&
452 (cfbg->desk_x == desk_x) &&
453 (cfbg->desk_y == desk_y) &&
454 (cfbg->file == file))
455 {
456 eina_stringshare_del(file);
457 return;
458 }
459 }
460
418 e_bg_del(container, zone, desk_x, desk_y); 461 e_bg_del(container, zone, desk_x, desk_y);
419 cfbg = E_NEW(E_Config_Desktop_Background, 1); 462 cfbg = E_NEW(E_Config_Desktop_Background, 1);
420 cfbg->container = container; 463 cfbg->container = container;
421 cfbg->zone = zone; 464 cfbg->zone = zone;
422 cfbg->desk_x = desk_x; 465 cfbg->desk_x = desk_x;
423 cfbg->desk_y = desk_y; 466 cfbg->desk_y = desk_y;
424 cfbg->file = eina_stringshare_add(file); 467 cfbg->file = file;
425 e_config->desktop_backgrounds = eina_list_append(e_config->desktop_backgrounds, cfbg); 468 e_config->desktop_backgrounds = eina_list_append(e_config->desktop_backgrounds, cfbg);
426 469
427 e_filereg_register(cfbg->file); 470 e_filereg_register(cfbg->file);
@@ -437,8 +480,8 @@ e_bg_add(int container, int zone, int desk_x, int desk_y, char *file)
437EAPI void 480EAPI void
438e_bg_del(int container, int zone, int desk_x, int desk_y) 481e_bg_del(int container, int zone, int desk_x, int desk_y)
439{ 482{
440 Eina_List *l = NULL; 483 Eina_List *l;
441 E_Config_Desktop_Background *cfbg = NULL; 484 E_Config_Desktop_Background *cfbg;
442 E_Event_Bg_Update *ev; 485 E_Event_Bg_Update *ev;
443 486
444 EINA_LIST_FOREACH(e_config->desktop_backgrounds, l, cfbg) 487 EINA_LIST_FOREACH(e_config->desktop_backgrounds, l, cfbg)
@@ -483,38 +526,114 @@ e_bg_update(void)
483 } 526 }
484} 527}
485 528
486EAPI void 529static inline Eina_Bool
487e_bg_handler_set(Evas_Object *obj, const char *path, void *data) 530_e_bg_file_edje_check(const char *path)
488{ 531{
489 E_Container *con; 532 const char *ext;
490 E_Zone *zone; 533 const size_t extlen = sizeof(".edj") - 1;
491 E_Desk *desk; 534 size_t len;
535
536 if (!path) return EINA_FALSE;
492 537
538 len = strlen(path);
539 if (len <= extlen) return EINA_FALSE;
540 ext = path + len - extlen;
541 return memcmp(ext, ".edj", extlen) == 0;
542}
543
544/**
545 * Go through process of importing an image as E background.
546 *
547 * This will go through process of importing an image as E
548 * background. It will ask fill/tile mode of the image, as well as
549 * quality to use.
550 *
551 * User can cancel operation at any time, and in this case callback is
552 * called with @c NULL as second parameter.
553 *
554 * The operation can be cancelled by application/module as well using
555 * e_object_del(). Even in this case the callback is called so user
556 * can free possibly allocated data.
557 *
558 * @param image_file source file to use, must be supported by Evas.
559 * @param cb callback to call when import process is done. The first
560 * argument is the given data, while the second is the path to
561 * the imported background file (edje) that can be used with
562 * e_bg_add() or e_bg_default_set(). Note that if this argument
563 * is @c NULL, then the import process was cancelled!
564 * This function is @b always called and after it returns
565 * E_Bg_Image_Import is deleted.
566 * @param data pointer to data to be given to callback.
567 *
568 * @return E_Object that handles the import process. It will die
569 * automatically when user cancels the process or when code
570 * automatically calls e_object_del(). Before dying, callback
571 * will always be called.
572 */
573EAPI E_Bg_Image_Import *
574e_bg_image_import_new(const char *image_file, void (*cb)(void *data, const char *edje_file), const void *data)
575{
576 // TODO: create win and process similar to e_int_config_wallpaper_import()
577 // TODO: and remove e_int_config_wallpaper_import.[ch]
578 return NULL;
579}
580
581/**
582 * Set background to image, as required in e_fm2_mime_handler_new()
583 */
584EAPI void
585e_bg_handler_set(Evas_Object *obj __UNUSED__, const char *path, void *data __UNUSED__)
586{
493 if (!path) return; 587 if (!path) return;
494 con = e_container_current_get(e_manager_current_get()); 588
495 zone = e_zone_current_get(con); 589 if (_e_bg_file_edje_check(path))
496 desk = e_desk_current_get(zone); 590 {
497 e_bg_del(con->num, zone->num, desk->x, desk->y); 591 E_Container *con = e_container_current_get(e_manager_current_get());
498 e_bg_add(con->num, zone->num, desk->x, desk->y, (char *)path); 592 E_Zone *zone = e_zone_current_get(con);
499 e_bg_update(); 593 E_Desk *desk = e_desk_current_get(zone);
500 e_config_save_queue(); 594
595 e_bg_add(con->num, zone->num, desk->x, desk->y, path);
596 e_bg_update();
597 e_config_save_queue();
598 }
599
600 e_bg_image_import_new(path, NULL, NULL);
501} 601}
502 602
603/**
604 * Test if possible to set background to file, as required in
605 * e_fm2_mime_handler_new()
606 *
607 * This handler tests for files that would be acceptable for setting
608 * background.
609 *
610 * You should just register it with "*.edj" (glob matching extension)
611 * or "image/" (mimetypes)that are acceptable with Evas loaders.
612 *
613 * Just edje files with "e/desktop/background" group are used.
614 */
503EAPI int 615EAPI int
504e_bg_handler_test(Evas_Object *obj, const char *path, void *data) 616e_bg_handler_test(Evas_Object *obj __UNUSED__, const char *path, void *data __UNUSED__)
505{ 617{
618
506 if (!path) return 0; 619 if (!path) return 0;
507 if (edje_file_group_exists(path, "e/desktop/background")) return 1; 620
508 return 0; 621 if (_e_bg_file_edje_check(path))
622 {
623 if (edje_file_group_exists(path, "e/desktop/background")) return 1;
624 return 0;
625 }
626
627 /* it's image/png or image/jpeg, we'll import it. */
628 return 1;
509} 629}
510 630
511/* local subsystem functions */ 631/* local subsystem functions */
512static void 632static void
513_e_bg_signal(void *data, Evas_Object *obj, const char *emission, const char *source) 633_e_bg_signal(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
514{ 634{
515 E_Zone *zone; 635 E_Zone *zone = data;
516 636
517 zone = data;
518 if (zone->prev_bg_object) 637 if (zone->prev_bg_object)
519 { 638 {
520 evas_object_del(zone->prev_bg_object); 639 evas_object_del(zone->prev_bg_object);
@@ -533,7 +652,7 @@ _e_bg_signal(void *data, Evas_Object *obj, const char *emission, const char *sou
533} 652}
534 653
535static void 654static void
536_e_bg_event_bg_update_free(void *data, void *event) 655_e_bg_event_bg_update_free(void *data __UNUSED__, void *event)
537{ 656{
538 free(event); 657 free(event);
539} 658}