Enlightenment CVS committal

Author  : rephorm
Project : e17
Module  : apps/e

Dir     : e17/apps/e/src/bin


Modified Files:
        e_eap_editor.c e_eap_editor.h e_int_border_menu.c e_user.c 
        e_user.h e_utils.c e_utils.h 


Log Message:

Re-enable create/edit icon from border menu.

===================================================================
RCS file: /cvs/e/e17/apps/e/src/bin/e_eap_editor.c,v
retrieving revision 1.76
retrieving revision 1.77
diff -u -3 -r1.76 -r1.77
--- e_eap_editor.c      28 Mar 2007 05:58:54 -0000      1.76
+++ e_eap_editor.c      13 Apr 2007 00:49:24 -0000      1.77
@@ -22,14 +22,12 @@
    int          terminal;
    int          show_in_menus;
 
-   int          new_desktop;
-   int           saved; /* whether desktop has been saved or not */
-
    E_Desktop_Edit *editor;
 };
 
 /* local subsystem functions */
 
+static int            _e_desktop_edit_view_create(E_Desktop_Edit *editor, 
E_Container *con);
 static void           _e_desktop_edit_free(E_Desktop_Edit *editor);
 static void          *_e_desktop_edit_create_data(E_Config_Dialog *cfd);
 static void           _e_desktop_edit_free_data(E_Config_Dialog *cfd, 
E_Config_Dialog_Data *data);
@@ -51,26 +49,128 @@
 /* externally accessible functions */
 
 EAPI E_Desktop_Edit *
-e_desktop_edit_show(E_Container *con, Efreet_Desktop *desktop)
+e_desktop_border_edit(E_Container *con, E_Border *bd)
 {
-   E_Config_Dialog_View *v;
    E_Desktop_Edit *editor;
+   const char *bname, *bclass;
+   char path[PATH_MAX];
 
    if (!con) return NULL;
-
    editor = E_OBJECT_ALLOC(E_Desktop_Edit, E_DESKTOP_EDIT_TYPE, 
_e_desktop_edit_free);
    if (!editor) return NULL;
-   v = E_NEW(E_Config_Dialog_View, 1);
-   if (!v)
+   if (bd->desktop)
+     editor->desktop = bd->desktop;
+
+   bname = bd->client.icccm.name;
+   if ((bname) && (bname[0] == 0)) bname = NULL;
+   bclass = bd->client.icccm.class;
+   if ((bclass) && (bclass[0] == 0)) bclass = NULL;
+
+   /* the border does not yet have a desktop entry. add one and pre-populate
+      it with values from the border */
+   if (!editor->desktop)
+     {
+       const char *desktop_dir, *icon_dir;
+
+       desktop_dir = e_user_desktop_dir_get();
+
+       if (!desktop_dir || !e_util_dir_check(desktop_dir)) return;
+
+       icon_dir = e_user_icon_dir_get();
+       if (!icon_dir || !e_util_dir_check(icon_dir)) return;
+
+       if (bname) 
+         {
+            snprintf(path, sizeof(path), "%s/%s.desktop", desktop_dir, bname);
+            editor->desktop = efreet_desktop_empty_new(path);
+         }
+       else
+         editor->desktop = efreet_desktop_empty_new(NULL);
+
+       if (!editor->desktop)
+         {
+            //XXX out of memory?
+            return;
+         }
+         if (bclass) editor->desktop->name = strdup(bclass);
+         if (bclass) editor->desktop->startup_wm_class = strdup(bclass);
+         if (bd->client.icccm.command.argc > 0)
+           // FIXME this should concat the entire argv array together
+           editor->desktop->exec = strdup(bd->client.icccm.command.argv[0]);
+         else if (bname)
+           editor->desktop->exec = strdup(bname); 
+
+         if (bd->client.netwm.startup_id > 0)
+           editor->desktop->startup_notify = 1;
+         if (bd->client.netwm.icons)
+           {
+              /* FIXME
+               * - Find the icon with the best size
+               * - Should use mkstemp
+               */
+              const char *tmp;
+
+              snprintf(path, sizeof(path), "%s/%s-%.6f.png", icon_dir, bname, 
ecore_time_get());
+              if (e_util_icon_save(&(bd->client.netwm.icons[0]), path))
+                {
+                   editor->tmp_image_path = strdup(path);
+                   editor->desktop->icon = strdup(path);
+                }
+              else
+                fprintf(stderr, "Could not save file from ARGB: %s\n", path);
+           }
+     }
+
+#if 0
+   if ((!bname) && (!bclass))
+     {
+       e_util_dialog_show(_("Incomplete Window Properties"),
+                          _("The window you are creating an icon for<br>"
+                            "does not contain window name and class<br>"
+                            "properties, so the needed properties for<br>"
+                            "the icon so that it will be used for this<br>"
+                            "window cannot be guessed. You will need to<br>"
+                            "use the window title instead. This will only<br>"
+                            "work if the window title is the same at<br>"
+                            "the time the window starts up, and does not<br>"
+                            "change."));
+     }
+#endif 
+   if (!_e_desktop_edit_view_create(editor, con))
      {
        e_object_del(E_OBJECT(editor));
-       return NULL;
+       editor = NULL;
      }
+   return editor;
+}
+
+EAPI E_Desktop_Edit *
+e_desktop_edit(E_Container *con, Efreet_Desktop *desktop)
+{
+   E_Desktop_Edit *editor;
 
-   editor->img = NULL;
+   if (!con) return NULL;
+   editor = E_OBJECT_ALLOC(E_Desktop_Edit, E_DESKTOP_EDIT_TYPE, 
_e_desktop_edit_free);
+   if (!editor) return NULL;
    if (desktop)
      editor->desktop = desktop;
 
+   if (!_e_desktop_edit_view_create(editor, con))
+     {
+       e_object_del(E_OBJECT(editor));
+       editor = NULL;
+     }
+   return editor;
+}
+
+static int
+_e_desktop_edit_view_create(E_Desktop_Edit *editor, E_Container *con)
+{
+   E_Config_Dialog_View *v;
+   v = E_NEW(E_Config_Dialog_View, 1);
+   if (!v)
+       return 0;
+
    /* view methods */
    v->create_cfdata           = _e_desktop_edit_create_data;
    v->free_cfdata             = _e_desktop_edit_free_data;
@@ -84,7 +184,7 @@
                                     "E", "_desktop_editor_dialog",
                                     "enlightenment/desktop_editor", 0, 
                                     v, editor);
-   return editor;
+   return 1;
 }
 
 /* local subsystem functions */
@@ -95,6 +195,8 @@
    E_OBJECT_CHECK(editor);
    E_OBJECT_TYPE_CHECK(editor, E_EAP_EDIT_TYPE);
 
+   IFFREE(editor->tmp_image_path);
+
    E_FREE(editor);
 }
 
@@ -108,8 +210,6 @@
    Efreet_Desktop *desktop = NULL; 
    char path[PATH_MAX];
 
-   printf("create data\n");
-
    cfdata = E_NEW(E_Config_Dialog_Data, 1);
    if (!cfdata) return NULL;
    cfdata->editor = cfd->data;
@@ -153,7 +253,7 @@
    if (!cfdata->desktop)
      {
        cfdata->desktop = efreet_desktop_empty_new(path);
-       cfdata->new_desktop = 1;
+       cfdata->editor->new_desktop = 1;
      }
 
    if (!desktop) desktop = cfdata->desktop;
@@ -184,8 +284,19 @@
 static void
 _e_desktop_edit_free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata)
 {
-   if (cfdata->desktop && cfdata->new_desktop && !cfdata->saved)
-     efreet_desktop_free(cfdata->desktop);
+   if (cfdata->desktop && cfdata->editor->new_desktop && 
!cfdata->editor->saved)
+       efreet_desktop_free(cfdata->desktop);
+
+   if (cfdata->editor->tmp_image_path) 
+     {
+       if (!cfdata->desktop || !cfdata->editor->saved ||
+           !cfdata->desktop->icon ||
+           strcmp(cfdata->editor->tmp_image_path, cfdata->desktop->icon))
+         {
+            ecore_file_unlink(cfdata->editor->tmp_image_path);
+         }
+     }
+     
 
    IFFREE(cfdata->name);
    IFFREE(cfdata->generic_name);
@@ -236,7 +347,7 @@
    cfdata->desktop->no_display = !cfdata->show_in_menus;
 
    if (cfdata->desktop->orig_path && cfdata->desktop->orig_path[0])
-     cfdata->saved = efreet_desktop_save(cfdata->desktop);
+     cfdata->editor->saved = efreet_desktop_save(cfdata->desktop);
    else
      {
        /* find a suitable name to save the desktop as */
@@ -272,7 +383,7 @@
             i++;
          }
 
-       cfdata->saved = efreet_desktop_save_as(cfdata->desktop, path);
+       cfdata->editor->saved = efreet_desktop_save_as(cfdata->desktop, path);
      }
    return 1;
 }
@@ -477,7 +588,6 @@
    cfdata = data;
    file = e_widget_fsel_selection_path_get(cfdata->editor->fsel);
 
-   printf("selected file: %s\n", file);
    IFFREE(cfdata->icon);
    IFDUP(file, cfdata->icon);
 
===================================================================
RCS file: /cvs/e/e17/apps/e/src/bin/e_eap_editor.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -3 -r1.8 -r1.9
--- e_eap_editor.h      28 Mar 2007 05:58:01 -0000      1.8
+++ e_eap_editor.h      13 Apr 2007 00:49:24 -0000      1.9
@@ -23,12 +23,17 @@
    Evas_Object *img_widget;
    Evas_Object *fsel;
    E_Dialog    *fsel_dia;
-   int          img_set;
+   //int          img_set;
+
+   char *tmp_image_path;
+   int new_desktop;
+   int saved; /* whether desktop has been saved or not */
    
    E_Config_Dialog *cfd;
 };
 
-EAPI E_Desktop_Edit *e_desktop_edit_show(E_Container *con, Efreet_Desktop 
*desktop);
+EAPI E_Desktop_Edit *e_desktop_border_edit(E_Container *con, E_Border *bd);
+EAPI E_Desktop_Edit *e_desktop_edit(E_Container *con, Efreet_Desktop *desktop);
 
 #endif
 #endif
===================================================================
RCS file: /cvs/e/e17/apps/e/src/bin/e_int_border_menu.c,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -3 -r1.60 -r1.61
--- e_int_border_menu.c 8 Apr 2007 21:00:30 -0000       1.60
+++ e_int_border_menu.c 13 Apr 2007 00:49:24 -0000      1.61
@@ -252,18 +252,18 @@
                                  "e/widgets/border/default/skip_winlist");
      }
    
-#if 0
+#if 1
    if (!bd->internal) 
      {
        mi = e_menu_item_new(m);
        e_menu_item_separator_set(mi, 1);
        
-       if (bd->app)
+       if (bd->desktop)
          {
             mi = e_menu_item_new(m);
             e_menu_item_label_set(mi, _("Edit Icon"));
             e_menu_item_callback_set(mi, _e_border_menu_cb_icon_edit, bd);
-             e_app_icon_add_to_menu_item(bd->app, mi);
+             e_util_desktop_menu_item_icon_add(bd->desktop, "16x16", mi);
          }
        else if (bd->client.icccm.class) /* icons with no class useless to 
borders */
          {
@@ -531,94 +531,14 @@
      }
 }
 
-#if 0
 static void
 _e_border_menu_cb_icon_edit(void *data, E_Menu *m, E_Menu_Item *mi)
 {
-   E_App *a;
    E_Border *bd;
-   char *bname = NULL, *bclass = NULL;
-   char path[4096];
    
    bd = data;
-   a = bd->app;
-   
-   bname = bd->client.icccm.name;
-   if ((bname) && (bname[0] == 0)) bname = NULL;
-   bclass = bd->client.icccm.class;
-   if ((bclass) && (bclass[0] == 0)) bclass = NULL;
-            
-   if (!a)
-     {
-       if (bname) 
-         {
-            const char *homedir;
-
-            homedir = e_user_homedir_get();
-            snprintf(path, sizeof(path), 
"%s/.e/e/applications/all/%s.desktop", 
-                     homedir, bname);
-            a = e_app_empty_new(path);
-         }
-       else
-         a = e_app_empty_new(NULL);
-
-       if (a)
-         {          
-            if (bname) a->win_name = evas_stringshare_add(bname);
-            if (bclass) a->win_class = evas_stringshare_add(bclass);
-            if (bd->client.icccm.window_role)
-              a->win_role = evas_stringshare_add(bd->client.icccm.window_role);
-            if (bclass) a->icon_class = evas_stringshare_add(bclass);
-            if (bclass) a->name = evas_stringshare_add(bclass);
-            if (bname) a->exe = evas_stringshare_add(bname);
-            if (bd->client.netwm.startup_id > 0)
-              a->startup_notify = 1;
-            if (bd->client.netwm.icons)
-              {
-                 /* FIXME
-                  * - Find the icon with the best size
-                  * - Should use mkstemp
-                  */
-                 const char *tmp;
-
-                 tmp = getenv("TMPDIR");
-                 if (!tmp) tmp = getenv("TMP");
-                 if (!tmp) tmp = "/tmp";
-                 snprintf(path, sizeof(path), "%s/%s-%.6f.png", tmp, bname, 
ecore_time_get());
-                 if (e_util_icon_save(&(bd->client.netwm.icons[0]), path))
-                   {
-                      a->image = evas_stringshare_add(path);
-                      a->width = bd->client.netwm.icons[0].width;
-                      a->height = bd->client.netwm.icons[0].height;
-                      a->tmpfile = 1;
-                   }
-                 else
-                   fprintf(stderr, "Could not save file from ARGB: %s\n", 
path);
-              }
-            bd->app = a;
-            e_object_ref(E_OBJECT(bd->app));
-         }
-     }
-   if (!a) return;
-   if (a->orig)
-     e_eap_edit_show(m->zone->container, a->orig);
-   else
-     e_eap_edit_show(m->zone->container, a);
-   if ((!bname) && (!bclass))
-     {
-       e_util_dialog_show(_("Incomplete Window Properties"),
-                          _("The window you are creating an icon for<br>"
-                            "does not contain window name and class<br>"
-                            "properties, so the needed properties for<br>"
-                            "the icon so that it will be used for this<br>"
-                            "window cannot be guessed. You will need to<br>"
-                            "use the window title instead. This will only<br>"
-                            "work if the window title is the same at<br>"
-                            "the time the window starts up, and does not<br>"
-                            "change."));
-     }
+   e_desktop_border_edit(m->zone->container, bd);
 }
-#endif
 
 static void
 _e_border_menu_cb_prop(void *data, E_Menu *m, E_Menu_Item *mi)
===================================================================
RCS file: /cvs/e/e17/apps/e/src/bin/e_user.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- e_user.c    22 Sep 2006 19:55:11 -0000      1.5
+++ e_user.c    13 Apr 2007 00:49:24 -0000      1.6
@@ -3,6 +3,8 @@
  */
 #include "e.h"
 
+static int _e_user_dir_check(const char *dir);
+
 /* externally accessible functions */
 EAPI const char *
 e_user_homedir_get(void)
@@ -20,3 +22,35 @@
      }
    return homedir;
 }
+
+/**
+ * Return the directory where user .desktop files should be stored.
+ * If the directory does not exist, it will be created. If it cannot be
+ * created, a dialog will be displayed an NULL will be returned
+ */
+EAPI const char *
+e_user_desktop_dir_get(void)
+{
+   static char dir[PATH_MAX] = "";
+   if (!dir[0])
+     snprintf(dir, sizeof(dir), "%s/applications", efreet_data_home_get());    
+  
+   return dir;
+}
+
+/**
+ * Return the directory where user .icon files should be stored.
+ * If the directory does not exist, it will be created. If it cannot be
+ * created, a dialog will be displayed an NULL will be returned
+ */
+EAPI const char *
+e_user_icon_dir_get(void)
+{
+   static char dir[PATH_MAX] = "";
+   if (!dir[0])
+     snprintf(dir, sizeof(dir), "%s/icons", efreet_data_home_get());
+  
+   return dir;
+}
+
+
===================================================================
RCS file: /cvs/e/e17/apps/e/src/bin/e_user.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- e_user.h    22 Sep 2006 19:55:11 -0000      1.5
+++ e_user.h    13 Apr 2007 00:49:24 -0000      1.6
@@ -7,6 +7,8 @@
 #define E_USER_H
 
 EAPI const char *e_user_homedir_get(void);
+EAPI const char *e_user_desktop_dir_get(void);
+EAPI const char *e_user_icon_dir_get(void);
 
 #endif
 #endif
===================================================================
RCS file: /cvs/e/e17/apps/e/src/bin/e_utils.c,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -3 -r1.66 -r1.67
--- e_utils.c   5 Apr 2007 06:59:02 -0000       1.66
+++ e_utils.c   13 Apr 2007 00:49:24 -0000      1.67
@@ -884,6 +884,28 @@
      }
 }
 
+int
+e_util_dir_check(const char *dir)
+{
+   if (!ecore_file_exists(dir))
+     {
+       if (!ecore_file_mkdir(dir))
+         {
+            e_util_dialog_show("Error creating the directory: %s. Check that 
you have correct permissions set.", dir);
+            return 0;
+         }
+     }
+   else
+     {
+       if (!ecore_file_is_dir(dir))
+         {
+            e_util_dialog_show("Error creating the directory: %s. A file of 
that name already exists.", dir);
+            return 0;
+         }
+     }
+   return 1;
+}
+
 /* local subsystem functions */
 static void
 _e_util_container_fake_mouse_up_cb(void *data)
@@ -905,4 +927,5 @@
    _e_util_dummy_timer = NULL;
    return 0;
 }
+
 
===================================================================
RCS file: /cvs/e/e17/apps/e/src/bin/e_utils.h,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -3 -r1.36 -r1.37
--- e_utils.h   3 Apr 2007 18:46:54 -0000       1.36
+++ e_utils.h   13 Apr 2007 00:49:24 -0000      1.37
@@ -51,6 +51,7 @@
 EAPI Evas_Object *e_util_desktop_icon_add(Efreet_Desktop *desktop, const char 
*size, Evas *evas);
 EAPI Evas_Object *e_util_icon_theme_icon_add(const char *icon_name, const char 
*size, Evas *evas);
 EAPI void         e_util_desktop_menu_item_icon_add(Efreet_Desktop *desktop, 
const char *size, E_Menu_Item *mi);
+int e_util_dir_check(const char *dir);
 
 #endif
 #endif



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to