*Back to the icon review.
authorDavid Walter Seikel <onefang@gmail.com>
Mon, 25 Sep 2006 12:50:23 +0000 (12:50 +0000)
committerDavid Walter Seikel <onefang@gmail.com>
Mon, 25 Sep 2006 12:50:23 +0000 (12:50 +0000)
*Rearrange and shuffle the code a bit to get the icon stuff all
together.

*Make sure that all paths through the icon finding code get counted and
timed properly, because speeding things up is next after the icon review.

SVN revision: 26139

legacy/ecore/src/lib/ecore_desktop/ecore_desktop.c
legacy/ecore/src/lib/ecore_desktop/ecore_desktop_icon.c

index 45ea689..2a73b66 100644 (file)
@@ -217,9 +217,6 @@ _ecore_desktop_get(const char *file, const char *lang)
          result->group = ecore_hash_get(result->data, "KDE Desktop Entry");
        if (result->group)
          {
-            char               *eap_name = NULL;
-            char               *exe = NULL;
-            char               *categories = NULL;
             int                 size = 0;
 
             value = (char *) ecore_file_get_file(result->original_path);
@@ -235,7 +232,6 @@ _ecore_desktop_get(const char *file, const char *lang)
                    sprintf(result->eap_name, "%s.edj", value);
                  if (temp) *temp = '.';
               }
-            eap_name = result->eap_name;
 
             IFGETDUP(value, "Name", result->name);
             IFGETDUP(value, "GenericName", result->generic);
@@ -249,6 +245,8 @@ _ecore_desktop_get(const char *file, const char *lang)
             IFGETDUP(value, "Exec", result->exec);
             if (result->exec)
               {
+                 char               *exe = NULL;
+
                  exe = strchr(result->exec, ' ');
                  if (exe)
                    {
@@ -256,7 +254,6 @@ _ecore_desktop_get(const char *file, const char *lang)
                       exe++;
                       result->exec_params = strdup(exe);
                    }
-                 exe = result->exec;
               }
 
             IFGETDUP(value, "StartupWMClass", result->window_class);
@@ -287,6 +284,10 @@ _ecore_desktop_get(const char *file, const char *lang)
             IFGETDUP(value, "X-Enlightenment-WindowTitle", result->window_title);
             IFGETDUP(value, "X-Enlightenment-WindowRole", result->window_role);
 
+            IFGETDUP(value, "Categories", result->categories);
+            if (result->categories)
+              result->Categories =
+                 ecore_desktop_paths_to_hash(result->categories);
             IFGETDUP(value, "Icon", result->icon);
             IFGETDUP(value, "X-Enlightenment-IconTheme", result->icon_theme);
             IFGETDUP(value, "X-Enlightenment-IconClass", result->icon_class);
@@ -325,39 +326,8 @@ _ecore_desktop_get(const char *file, const char *lang)
                    }
               }
 
-            IFGETDUP(value, "Categories", result->categories);
-            if (result->categories)
-              result->Categories =
-                 ecore_desktop_paths_to_hash(result->categories);
-            categories = result->categories;
-
-            value = ecore_hash_get(result->group, "OnlyShowIn");
-            if (value)
-              result->OnlyShowIn =
-                 ecore_desktop_paths_to_hash(value);
-            value = ecore_hash_get(result->group, "NotShowIn");
-            if (value)
-              result->NotShowIn =
-                 ecore_desktop_paths_to_hash(value);
-            value = ecore_hash_get(result->group, "X-KDE-StartupNotify");
-            if (value)
-              result->startup = (strcmp(value, "true") == 0);
-            value = ecore_hash_get(result->group, "StartupNotify");
-            if (value)
-              result->startup = (strcmp(value, "true") == 0);
-            value = ecore_hash_get(result->group, "X-Enlightenment-WaitExit");
-            if (value)
-              result->wait_exit = (strcmp(value, "true") == 0);
-            value = ecore_hash_get(result->group, "NoDisplay");
-            if (value)
-              result->no_display = (strcmp(value, "true") == 0);
-            value = ecore_hash_get(result->group, "Hidden");
-            if (value)
-              result->hidden = (strcmp(value, "true") == 0);
-
-            /*
-             *    icon/class is a list of standard icons from the theme that can override the icon created above.
-             *    Use (from .desktop) eap name,exe name,categories.  It's case sensitive, the reccomendation is to lowercase it.
+            /*    icon/class is a list of standard icons from the theme that can override the icon created above.
+             *    Use (from .desktop) name,exe name,categories.  It's case sensitive, the reccomendation is to lowercase it.
              *    It should be most specific to most generic.  firefox,browser,internet for instance
              */
 
@@ -369,12 +339,12 @@ _ecore_desktop_get(const char *file, const char *lang)
                  size = 0;
                  if ((result->icon) && (strchr(result->icon, '/') == NULL))
                    size += strlen(result->icon) + 1;
-                 if (eap_name)
-                   size += strlen(eap_name) + 1;
-                 if (exe)
-                   size += strlen(exe) + 1;
-                 if (categories)
-                   size += strlen(categories) + 1;
+                 if (result->eap_name)
+                   size += strlen(result->eap_name) + 1;
+                 if (result->exec)
+                   size += strlen(result->exec) + 1;
+                 if (result->categories)
+                   size += strlen(result->categories) + 1;
                  result->icon_class = malloc(size + 1);
                  if (result->icon_class)
                    {
@@ -391,18 +361,18 @@ _ecore_desktop_get(const char *file, const char *lang)
                       /* We do this here coz we don't want to lower case the result->icon part later. */
                       p = result->icon_class;
                       p += strlen(result->icon_class);
-                      if ((eap_name) && (eap_name[0] != '\0'))
+                      if ((result->eap_name) && (result->eap_name[0] != '\0'))
                         {
                            if (done)
                              strcat(result->icon_class, ",");
-                           strcat(result->icon_class, eap_name);
+                           strcat(result->icon_class, result->eap_name);
                            done = 1;
                         }
-                      if ((exe) && (exe[0] != '\0'))
+                      if ((result->exec) && (result->exec[0] != '\0'))
                         {
                            char               *tmp;
 
-                           tmp = strdup(ecore_file_get_file(exe));
+                           tmp = strdup(ecore_file_get_file(result->exec));
                            if (tmp)
                              {
                                 char               *p2;
@@ -424,11 +394,11 @@ _ecore_desktop_get(const char *file, const char *lang)
                                 free(tmp);
                              }
                         }
-                      if ((categories) && (categories[0] != '\0'))
+                      if ((result->categories) && (result->categories[0] != '\0'))
                         {
                            if (done)
                              strcat(result->icon_class, ",");
-                           strcat(result->icon_class, categories);
+                           strcat(result->icon_class, result->categories);
                            done = 1;
                         }
                       while (*p != '\0')
@@ -441,6 +411,31 @@ _ecore_desktop_get(const char *file, const char *lang)
                         }
                    }
               }
+
+            value = ecore_hash_get(result->group, "OnlyShowIn");
+            if (value)
+              result->OnlyShowIn =
+                 ecore_desktop_paths_to_hash(value);
+            value = ecore_hash_get(result->group, "NotShowIn");
+            if (value)
+              result->NotShowIn =
+                 ecore_desktop_paths_to_hash(value);
+            value = ecore_hash_get(result->group, "X-KDE-StartupNotify");
+            if (value)
+              result->startup = (strcmp(value, "true") == 0);
+            value = ecore_hash_get(result->group, "StartupNotify");
+            if (value)
+              result->startup = (strcmp(value, "true") == 0);
+            value = ecore_hash_get(result->group, "X-Enlightenment-WaitExit");
+            if (value)
+              result->wait_exit = (strcmp(value, "true") == 0);
+            value = ecore_hash_get(result->group, "NoDisplay");
+            if (value)
+              result->no_display = (strcmp(value, "true") == 0);
+            value = ecore_hash_get(result->group, "Hidden");
+            if (value)
+              result->hidden = (strcmp(value, "true") == 0);
+
          }
        else
          {
index 3be2d16..9883dc2 100644 (file)
@@ -53,45 +53,50 @@ EAPI char         *
 ecore_desktop_icon_find(const char *icon, const char *icon_size,
                        const char *icon_theme)
 {
-   char           *dir = NULL, *icn;
+   char           *result = NULL, *icn;
    Ecore_List     *icons;
    int             in_cache = 0;
    double          begin;
 
    begin = ecore_time_get();
-   if (icon == NULL)
-      return NULL;
-
-   /* Easy check first, was a full path supplied? */
-   if ((icon[0] == '/') && (ecore_file_exists(icon)))
-      return strdup(icon);
-
-   if (icon_size == NULL)
-      icon_size = "48x48";
-   if (icon_theme == NULL)
-      icon_theme = "hicolor";
-
-   icons = ecore_desktop_paths_to_list(icon);
-   if (!icons)
-      return NULL;
-   ecore_list_goto_first(icons);
-   while ((icn = ecore_list_next(icons)))
+   if (icon)
      {
-       char *ext;
+        /* Easy check first, was a full path supplied? */
+        if ((icon[0] == '/') && (ecore_file_exists(icon)))
+           result = strdup(icon);
+       else
+         {
+             icons = ecore_desktop_paths_to_list(icon);
+             if (icons)
+              {
+
+                  if (icon_size == NULL)
+                     icon_size = "48x48";
+                  if (icon_theme == NULL)
+                     icon_theme = "hicolor";
+                  ecore_list_goto_first(icons);
+                  while ((icn = ecore_list_next(icons)))
+                    {
+                      char *ext;
 #ifdef DEBUG
-       fprintf(stderr, "\tTrying To Find Icon %s\n", icn);
+                      fprintf(stderr, "\tTrying To Find Icon %s\n", icn);
 #endif
-       ext = strrchr(icn, '.');
-       /* Check for unsupported extension */
-       if ((ext) && (!strcmp(ext, ".ico"))) continue;
+                      ext = strrchr(icn, '.');
+                      /* Check for unsupported extension */
+                      if ((ext) && (!strcmp(ext, ".ico")))
+                         continue;
 
-       dir = _ecore_desktop_icon_find0(icn, icon_size, icon_theme);
-       if (dir)
-          break;
-     }
-   ecore_list_destroy(icons);
+                      result = _ecore_desktop_icon_find0(icn, icon_size, icon_theme);
+                      if (result)
+                         break;
+                    }
+                  ecore_list_destroy(icons);
+
+              } /* if (icons) */
+         } /* if ((icon[0] == '/') && (ecore_file_exists(icon))) ; else */
+     } /* if (icon) */
 
-   if (dir)
+   if (result)
      {
         if (in_cache)
           {
@@ -109,7 +114,8 @@ ecore_desktop_icon_find(const char *icon, const char *icon_size,
         instrumentation.icons_not_found_time += ecore_time_get() - begin;
         instrumentation.icons_not_found++;
      }
-   return dir;
+
+   return result;
 }
 
 /** Search for an icon the fdo way.