Main Page | Data Structures | Directories | File List | Data Fields | Globals

e_mod_source_picture.c

Go to the documentation of this file.
00001 #include "dEvian.h"
00002 
00003 static int _cb_timer_picture_change(void *data);
00004 static void _was_set_bg_add(Source_Picture *source, char *name);
00005 static void _was_set_bg_purge(Source_Picture *source, int in_use);
00006 
00007 
00008 /*
00009   Add a source to a devian
00010   Return:
00011    - 0 on success
00012    - 1 if fails
00013 */
00014 int devian_source_picture_add(dEvian *devian)
00015 {
00016   Source_Picture *source;
00017 
00018   DSOURCE(("dEvian: Source picture creation START\n"));
00019 
00020   source = E_NEW(Source_Picture, 1);
00021   source->devian = devian;
00022   
00023   /* Set new name for devian */
00024   devian_devian_set_name(devian, SOURCE_PICTURE, NULL);
00025 
00026   /* Attach picture */
00027   if ( !devian_data_picture_cache_attach(source, 0) )
00028     {
00029       devian_source_picture_del(source);
00030       return 1;
00031     }
00032 
00033   /* Timer to change picture */
00034   if (devian->conf->picture_timer_active)
00035     devian_source_picture_timer_change_set(source, 1, 0);
00036 
00037   source->was_set_bg = NULL;
00038 
00039   devian->conf->source_type = SOURCE_PICTURE;
00040   devian->source = source;
00041 
00042   DSOURCE(("dEvian: Source picture creation OK\n"));
00043 
00044   return 0;
00045 }
00046 
00047 void devian_source_picture_del(Source_Picture *source)
00048 {
00049   devian_data_picture_cache_detach(source, 0);
00050   devian_data_picture_cache_detach(source, 1);
00051 
00052   if (source->timer)
00053     {
00054       ecore_timer_del(source->timer);
00055     }
00056 
00057   if (dEvianM->conf->sources_picture_set_bg_purge)
00058     _was_set_bg_purge(source, 0);
00059 
00060   source->devian->source = NULL;
00061   source->devian->conf->source_type = SOURCE_NO;
00062 
00063   E_FREE(source);
00064 
00065   DSOURCE(("dEvian: Source deleted\n"));
00066 
00067 }
00068 
00069 /*
00070   Change the picture of a picture source
00071   Return:
00072     - 1 on success
00073     - 0 on fail
00074 */
00075 int devian_source_picture_change(Source_Picture *source)
00076 {
00077   int old_part;
00078 
00079   old_part = devian_container_edje_part_get(source->devian);
00080 
00081   if (!devian_data_picture_cache_attach(source,
00082           !old_part))
00083     return 0;
00084 
00085   if(!devian_container_edje_part_change(source->devian))
00086       return 0;
00087 
00088   devian_container_resize_auto(source->devian);
00089             
00090   return 1;
00091 }
00092 
00093 int devian_source_picture_set_bg(Source_Picture *source)
00094 {
00095   E_Zone *zone;
00096   char *file = NULL;
00097   char *name;
00098   char buf[4096];
00099 
00100   zone = e_zone_current_get(dEvianM->container);
00101   if (!zone)
00102     return 0;
00103 
00104   if (!devian_container_edje_part_get(source->devian))
00105     {
00106       if (source->picture0)
00107   {
00108     file = source->picture0->path;
00109     name = source->picture0->picture_description->name;
00110   }
00111     }
00112   else
00113     {
00114       if (source->picture1)
00115   {
00116     file = source->picture1->path;
00117     name = source->picture1->picture_description->name;
00118   }
00119       else
00120   return 0;
00121     }
00122   if (!file)
00123     return 0;
00124 
00125   if (dEvianM->conf->sources_picture_set_bg_purge)
00126     _was_set_bg_purge(source, 1);
00127 
00128   if (!ecore_file_exists(file))
00129     {
00130       snprintf(buf, sizeof(buf),
00131                _(
00132                  "<hilight>File %s doesnt exists.</hilight><br><br>"
00133      "This file is in dEvian's picture list, but it seems you removed it from the disk<br>"
00134      "It cant be set as background, sorry."
00135                  ),
00136                file
00137                );
00138       e_module_dialog_show(_("dEvian Module Error"), buf);
00139       return 0;
00140     }
00141 
00142   if (!strstr(file, ".edj"))
00143     {
00144       if (ecore_file_app_installed("e17setroot"))
00145   {
00146     Ecore_Exe *exe;
00147     
00148     snprintf(buf, 4096, "e17setroot -s %s", file);
00149     DSOURCE(("Set background with %s", buf));
00150     exe = ecore_exe_run(buf, NULL);
00151     if (exe)
00152       {
00153         ecore_exe_free(exe);
00154         if (dEvianM->conf->sources_picture_set_bg_purge)
00155     _was_set_bg_add(source, name);
00156       }
00157   }
00158       else
00159   {
00160     snprintf(buf, sizeof(buf),
00161        _(
00162          "<hilight>e17setroot needed</hilight><br><br>"
00163          "%s is not an edje file !<br>"
00164          "dEvian need e17setroot util from e_utils package to set you're picture as background"
00165          "Please install it and try again"
00166          ),
00167        file
00168        );
00169     e_module_dialog_show(_("dEvian Module Error"), buf);
00170     return 0;
00171   }
00172     }
00173   else
00174     { 
00175       DSOURCE(("Set edje background %s", file));
00176 
00177       if ((zone->container->num == 0) && (zone->num == 0) &&
00178     (zone->desk_x_current == 0) && (zone->desk_y_current == 0))
00179   {
00180     e_lib_background_set(strdup(file));
00181   }
00182       else
00183   {
00184     e_lib_desktop_background_del(zone->container->num, zone->num, zone->desk_x_current, zone->desk_y_current);
00185     e_lib_desktop_background_add(zone->container->num, zone->num, zone->desk_x_current, zone->desk_y_current, strdup(file));
00186   }
00187     }
00188 
00189   return 1;
00190 }
00191 
00192 int devian_source_picture_viewer(Source_Picture *source)
00193 {
00194   char *file;
00195   char buf[4096];
00196 
00197   if (!devian_container_edje_part_get(source->devian))
00198     {
00199       if (source->picture0)
00200   {
00201     file = source->picture0->path;
00202   }
00203       else
00204   return 0;
00205     }
00206   else
00207     {
00208       if (source->picture1)
00209   {
00210     file = source->picture1->path;
00211   }
00212       else
00213   return 0;
00214     }
00215   if (!file)
00216     return 0;
00217   if (!ecore_file_exists(file))
00218     {
00219       snprintf(buf, sizeof(buf),
00220                _(
00221                  "<hilight>File %s doesnt exists.</hilight><br><br>"
00222      "This file is in dEvian's picture list, but it seems you removed it from the disk<br>"
00223      "It cant be set opened in a viewer, sorry."
00224                  ),
00225                file
00226                );
00227       e_module_dialog_show(_("dEvian Module Error"), buf);
00228       return 0;
00229     }  
00230   
00231   if (ecore_file_app_installed("exhibit"))
00232     {
00233       Ecore_Exe *exe;
00234       
00235       snprintf(buf, 4096, "exhibit %s", file);
00236       DSOURCE(("Viewer: %s", buf));
00237       exe = ecore_exe_run(buf, NULL);
00238       if (exe)
00239   ecore_exe_free(exe);
00240     }
00241   else
00242     {
00243       snprintf(buf, sizeof(buf),
00244          _(
00245      "<hilight>exhibit not found !</hilight><br><br>"
00246      "Exhibit in an image viewer writen with Enlightenment Librairies. You can get it on E cvs"
00247      )
00248          );
00249       e_module_dialog_show(_("dEvian Module Error"), buf);
00250       return 0;
00251     }
00252 
00253   return 1;
00254 }
00255 
00256 int devian_source_picture_evas_object_get(dEvian *devian,
00257             Evas_Object **picture0,
00258             Evas_Object **picture1)
00259 {
00260   Source_Picture *source;
00261 
00262   source = (Source_Picture *)devian->source;
00263 
00264   if ((!source->picture0) && (!source->picture1))
00265     return 0;
00266 
00267   if (source->picture0)
00268     *picture0 = source->picture0->picture;
00269   else
00270     *picture0 = NULL;
00271   if (source->picture1)
00272     *picture1 = source->picture1->picture;
00273   else
00274     *picture1 = NULL;
00275 
00276   return 1;
00277 }
00278 
00279 int devian_source_picture_original_size_get(Source_Picture *source,
00280               int part, int *w, int *h)
00281 {
00282   if (!source)
00283     return 0;
00284 
00285   if (part == -1)
00286     {
00287       if ( (part = devian_container_edje_part_get(source->devian)) == -1 )
00288   return 0;
00289     }
00290 
00291   if (!part && source->picture0)
00292     {
00293       *w = source->picture0->original_w;
00294       *h = source->picture0->original_h;
00295       return 1;
00296     }
00297 
00298   if (part && source->picture1)
00299     {
00300       *w = source->picture1->original_w;
00301       *h = source->picture1->original_h;
00302       return 1;
00303     }
00304 
00305   return 0;
00306 }
00307 
00308 void devian_source_picture_dialog_infos(Source_Picture *source)
00309 {
00310   E_Dialog *dia;
00311   char buf[4096];
00312   char *path;
00313   int edje_part;
00314 
00315   edje_part = devian_container_edje_part_get(source->devian);
00316   if(!edje_part)
00317     path = source->picture0->path;
00318   else
00319     path = source->picture1->path;
00320 
00321   dia = e_dialog_new(dEvianM->container);
00322   if (!dia)
00323     return;
00324 
00325   snprintf( buf, 4096,
00326       "<hilight>Informations</hilight><br>"
00327       "Picture name : %s<br>"
00328       "Picture path : %s<br>"
00329       "<br>"
00330       "Total pictures in local list : %d",
00331       devian_source_picture_name_get(source, edje_part),
00332       path,
00333       evas_list_count(dEvianM->picture_list_local->pictures) );
00334   e_dialog_title_set(dia, "dEvian Module - Picture Informations");
00335   e_dialog_icon_set(dia, "enlightenment/e", 64);
00336   e_dialog_text_set(dia, buf);
00337   e_dialog_button_add(dia, _("Ok"), NULL, NULL, NULL);
00338   e_win_centered_set(dia->win, 1);
00339   e_dialog_show(dia);
00340 
00341 }
00342 
00343 char *devian_source_picture_name_get(Source_Picture *source, int part)
00344 {
00345   char *name;
00346   name = NULL;
00347 
00348   if (part == -1)
00349     {
00350       part = devian_container_edje_part_get(source->devian);
00351     }
00352 
00353   if (!part && source->picture0)
00354     name = source->picture0->picture_description->name;
00355   
00356   if (part && source->picture1)
00357     name = source->picture1->picture_description->name;
00358   
00359   return name;
00360 }
00361 
00362 void devian_source_picture_timer_change_set(Source_Picture *source, int active, int time)
00363 {
00364   if (time && (time < SOURCE_PICTURE_TIMER_MIN))
00365     return;
00366  
00367   source->devian->conf->picture_timer_active = active;
00368   if (!time)
00369     time = source->devian->conf->picture_timer_s;
00370   else
00371     source->devian->conf->picture_timer_s = time;
00372 
00373   if (!active)
00374     {
00375       if (source->timer)
00376   {
00377     devian_container_edje_part_change_set(source->devian, 0);
00378     ecore_timer_del(source->timer);
00379     source->timer = NULL;
00380   }
00381       return;
00382     }
00383 
00384   if (source->timer)
00385     ecore_timer_del(source->timer);
00386   source->timer = ecore_timer_add(time,
00387           _cb_timer_picture_change,
00388           source);
00389   devian_container_edje_part_change_set(source->devian, 1);
00390 }
00391 
00392 /* Private functions */
00393 
00394 static int _cb_timer_picture_change(void *data)
00395 {
00396   Source_Picture *source;
00397   source = data;
00398 
00399   devian_source_picture_change(source);
00400 
00401   return 1;
00402 }
00403 
00404 static void _was_set_bg_add(Source_Picture *source, char *name)
00405 {
00406   char *home;
00407   char *file_edj;
00408 
00409   file_edj = E_NEW(char, DEVIAN_MAX_PATH);
00410   home = e_user_homedir_get();
00411   snprintf(file_edj, DEVIAN_MAX_PATH, "%s/.e/e/backgrounds/%s.edj", home, name);
00412   free(home);
00413 
00414   source->was_set_bg = evas_list_append(source->was_set_bg, file_edj);
00415 }
00416 
00417 static void _was_set_bg_purge(Source_Picture *source, int in_use)
00418 {
00419   char *file;
00420   int n;
00421 
00422   if (!evas_list_count(source->was_set_bg))
00423     return;
00424 
00425   while ( (n = evas_list_count(source->was_set_bg)) )
00426     {
00427       file = evas_list_data(source->was_set_bg);
00428       DSOURCE(("was_set_bg check %d %s", n, file));
00429       if (!strcmp(e_config->desktop_default_background, file))
00430   {
00431     if (in_use)
00432       {
00433         if (n==1)
00434     break;
00435         else
00436     {
00437       source->was_set_bg = evas_list_remove(source->was_set_bg, file);
00438       E_FREE(file);
00439       continue;
00440     }
00441       }
00442     else
00443       {
00444         source->was_set_bg = evas_list_remove(source->was_set_bg, file);
00445         E_FREE(file);
00446         continue;
00447       }
00448   }
00449       DSOURCE(("was_set_bg remove %s", file));
00450       if (ecore_file_exists(file))
00451   ecore_file_unlink(file);
00452       source->was_set_bg = evas_list_remove(source->was_set_bg, file);
00453       E_FREE(file);
00454     }
00455 
00456   return;
00457 }

Generated on Fri Jan 6 02:26:26 2006 for dEvian by  doxygen 1.4.4