~henrix/ubuntu/precise/open-vm-dkms/lp-1416003

« back to all changes in this revision

Viewing changes to lib/appUtil/appUtilX11.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2008-10-23 15:32:00 UTC
  • mfrom: (1.1.2 upstream) (2.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20081023153200-gc1bfx89hj35c799
Tags: 2008.10.10-123053-2
* Correcting typo in dh_installinit call.
* Downgrading depends on module-assistant to recommends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
101
101
                         const char *iconName) // IN
102
102
{
103
103
   char *myIconName;
 
104
   char *baseIconName;
104
105
   /*
105
106
    * Use the GtkIconTheme to track down any available icons for this app.
106
107
    */
107
108
   GtkIconTheme *iconTheme = NULL;
108
109
   char *ctmp2;
109
 
   Bool foundIt; // Did we find this icon in the GtkIconTheme?
 
110
   Bool foundItInTheme; // Did we find this icon in the GtkIconTheme?
 
111
   Bool foundItInFile; // Did we find this icon directly in a file?
110
112
   static const char *extraIconPaths[] = {
 
113
      "/usr/share/icons",
111
114
      "/usr/share/pixmaps",
112
115
      "/usr/local/share/pixmaps",
113
116
      "/usr/local/share/icons",
122
125
 
123
126
   ASSERT(iconName);
124
127
 
 
128
   Debug("Collecting icons named %s\n", iconName);
 
129
 
125
130
   iconNameLen = strlen(iconName) + 1;
126
 
   myIconName = g_alloca(iconNameLen); // We need to modify the name sometimes
127
 
   Str_Strcpy(myIconName, iconName, iconNameLen);
 
131
   baseIconName = g_alloca(iconNameLen); // We need to modify the name sometimes
 
132
   Str_Strcpy(baseIconName, iconName, iconNameLen);
128
133
 
129
 
   ctmp2 = strrchr(myIconName, '.');
130
 
   if (*myIconName != '/' && ctmp2 && strlen(ctmp2) <= 5) {
 
134
   ctmp2 = strrchr(baseIconName, '.');
 
135
   if (*baseIconName != '/' && ctmp2 && strlen(ctmp2) <= 5) {
131
136
      /*
132
137
       * If it's a plain filename that we could possibly feed into GtkIconTheme as an
133
138
       * icon ID, trim the file extension to turn it into an icon ID string and make
138
143
 
139
144
   iconTheme = gtk_icon_theme_get_default();
140
145
   g_object_ref(G_OBJECT(iconTheme));
141
 
   foundIt = AppUtilIconThemeReallyHasIcon(iconTheme, myIconName);
142
 
   if (!foundIt) {
143
 
      /*
144
 
       * Try looking through some auxiliary icon themes.
145
 
       */
146
 
      int i;
147
 
      static const char *extraThemes[] = {
148
 
         /*
149
 
          * Some other icon themes to try.
150
 
          */
151
 
         "hicolor",
152
 
         "Bluecurve",
153
 
         "HighContrast-SVG",
154
 
         "HighContrastLargePrint",
155
 
         NULL
156
 
      };
157
 
      g_object_unref(G_OBJECT(iconTheme));
158
 
      iconTheme = gtk_icon_theme_new();
159
 
      for (i = 0; i < ARRAYSIZE(extraIconPaths); i++) {
160
 
         if (extraIconPaths[i]) {
161
 
            if (g_file_test(extraIconPaths[i], G_FILE_TEST_EXISTS)) {
162
 
               gtk_icon_theme_append_search_path(iconTheme, extraIconPaths[i]);
163
 
            } else {
164
 
               extraIconPaths[i] = NULL;
165
 
            }
166
 
         }
167
 
      }
168
 
 
169
 
      for (i = 0; extraThemes[i]; i++) {
170
 
         gtk_icon_theme_set_custom_theme(iconTheme, extraThemes[i]);
171
 
         foundIt = AppUtilIconThemeReallyHasIcon(iconTheme, myIconName);
172
 
         if (foundIt) {
173
 
            break;
174
 
         }
175
 
      }
176
 
   }
177
 
 
178
 
   if (!foundIt) {
 
146
   foundItInTheme = AppUtilIconThemeReallyHasIcon(iconTheme, baseIconName);
 
147
 
 
148
   if (!foundItInTheme) {
179
149
      /*
180
150
       * Try looking for it as a non-GtkIconTheme managed file, to deal with older
181
151
       * systems.
197
167
               g_snprintf(ctmp2, PATH_MAX, "%s/%s", extraIconPaths[i], iconName);
198
168
               if (g_file_test(ctmp2, G_FILE_TEST_EXISTS)) {
199
169
                  myIconName = ctmp2;
 
170
                  foundItInFile = TRUE;
200
171
               }
201
172
            } else {
202
173
               static const char *iconExtensions[] = {
213
184
                             iconName, iconExtensions[j]);
214
185
                  if (g_file_test(ctmp2, G_FILE_TEST_EXISTS)) {
215
186
                     myIconName = ctmp2;
 
187
                     foundItInFile = TRUE;
216
188
                     break;
217
189
                  }
218
190
               }
219
191
            }
220
192
         }
221
193
      } else {
 
194
         myIconName = g_alloca(iconNameLen + 1);
222
195
         Str_Strcpy(myIconName, iconName, iconNameLen);
223
 
      }
224
 
   }
225
 
 
226
 
   if (foundIt) {
 
196
         foundItInFile = TRUE;
 
197
      }
 
198
   }
 
199
 
 
200
   if (!foundItInTheme && !foundItInFile) {
 
201
      /*
 
202
       * Try looking through some auxiliary icon themes.
 
203
       */
 
204
      int i;
 
205
      static const char *extraThemes[] = {
 
206
         /*
 
207
          * Some other icon themes to try.
 
208
          */
 
209
         "hicolor",
 
210
         "Bluecurve",
 
211
         "HighContrast-SVG",
 
212
         "HighContrastLargePrint",
 
213
         "crystalsvg",
 
214
         "slick",
 
215
         NULL
 
216
      };
 
217
      g_object_unref(G_OBJECT(iconTheme));
 
218
      iconTheme = gtk_icon_theme_new();
 
219
      for (i = 0; i < ARRAYSIZE(extraIconPaths); i++) {
 
220
         if (extraIconPaths[i]) {
 
221
            if (g_file_test(extraIconPaths[i], G_FILE_TEST_EXISTS)) {
 
222
               gtk_icon_theme_append_search_path(iconTheme, extraIconPaths[i]);
 
223
            } else {
 
224
               extraIconPaths[i] = NULL;
 
225
            }
 
226
         }
 
227
      }
 
228
 
 
229
      for (i = 0; extraThemes[i]; i++) {
 
230
         gtk_icon_theme_set_custom_theme(iconTheme, extraThemes[i]);
 
231
         foundItInTheme = AppUtilIconThemeReallyHasIcon(iconTheme, baseIconName);
 
232
         if (foundItInTheme) {
 
233
            break;
 
234
         }
 
235
      }
 
236
   }
 
237
 
 
238
   if (foundItInTheme) {
227
239
      /*
228
240
       * If we know this icon can be loaded via GtkIconTheme, do so.
229
241
       */
231
243
      int i;
232
244
      Bool needToUseScalable;
233
245
 
234
 
      iconSizes = gtk_icon_theme_get_icon_sizes(iconTheme, myIconName);
 
246
      iconSizes = gtk_icon_theme_get_icon_sizes(iconTheme, baseIconName);
 
247
      Debug("Loading icon %s from iconTheme\n", baseIconName);
235
248
 
236
249
      ASSERT(iconSizes);
237
250
      needToUseScalable = (iconSizes[0] == -1 && iconSizes[1] == 0);
254
267
            thisSize = 64; // Render SVG icons to 64x64
255
268
         }
256
269
 
257
 
         iconInfo = gtk_icon_theme_lookup_icon(iconTheme, myIconName, thisSize, 0);
 
270
         iconInfo = gtk_icon_theme_lookup_icon(iconTheme, baseIconName, thisSize, 0);
258
271
 
259
272
         if (!iconInfo) {
260
 
            Debug("Couldn't find %s icon for size %d\n", myIconName, thisSize);
 
273
            Debug("Couldn't find %s icon for size %d\n", baseIconName, thisSize);
261
274
            continue;
262
275
         }
263
276
 
270
283
         if (pixbuf) {
271
284
            g_ptr_array_add(pixbufs, pixbuf);
272
285
         } else {
273
 
            Debug("WARNING: Not even a built-in pixbuf for icon %s\n", myIconName);
 
286
            Debug("WARNING: Not even a built-in pixbuf for icon %s\n", baseIconName);
274
287
         }
275
288
 
276
289
         gtk_icon_info_free(iconInfo);
278
291
 
279
292
      g_free(iconSizes);
280
293
 
281
 
   } else if (myIconName && myIconName[0] == '/') {
 
294
   } else if (foundItInFile && myIconName && myIconName[0] == '/') {
282
295
      GdkPixbuf *pixbuf;
 
296
      Debug("Loading icon %s from file\n", myIconName);
283
297
      pixbuf = gdk_pixbuf_new_from_file(myIconName, NULL);
284
298
      if (pixbuf) {
285
299
         g_ptr_array_add(pixbufs, pixbuf);
654
668
      "python2.4",
655
669
      "python2.3",
656
670
      "python2.2",
657
 
      "perl",
658
 
      "getproxy"
 
671
      "perl"
659
672
   };
660
673
   char cbuf[PATH_MAX];
661
674
   int i;
698
711
   ASSERT(appName);
699
712
 
700
713
   if (appName[0] == '/') {
701
 
      return g_strdup(appName);
 
714
      ctmp = g_strdup(appName);
 
715
      goto exit;
702
716
   }
703
717
 
704
718
   ctmp = g_find_program_in_path(appName);
705
719
   if (ctmp) {
706
 
      return ctmp;
707
 
   }
708
 
 
709
 
   if (cwd) {
710
 
      char cbuf[PATH_MAX];
711
 
 
712
 
      getcwd(cbuf, sizeof cbuf);
713
 
      chdir(cwd);
714
 
      ctmp = Posix_RealPath(appName);
715
 
      chdir(cbuf);
716
 
 
717
 
      return ctmp;
718
 
   }
719
 
 
720
 
   return NULL;
 
720
      goto exit;
 
721
   }
 
722
 
 
723
   /*
 
724
    * It's probably safe to assume that cwd is an absolute path (at the time of
 
725
    * writing, it is derived from /proc), but let's check to be sure.
 
726
    */
 
727
   if (cwd && cwd[0] == '/') {
 
728
 
 
729
      /* Don't add any unnecessary path separators. */
 
730
      char *cbuf = Str_Asprintf(NULL, "%s%s%s", cwd,
 
731
                                cwd[strlen(cwd) - 1] == '/' ? "" : "/",
 
732
                                appName);
 
733
      if (cbuf) {
 
734
         ctmp = Posix_RealPath(cbuf);
 
735
         free(cbuf);
 
736
      }
 
737
   }
 
738
 
 
739
 exit:
 
740
   return ctmp;
721
741
}
722
742
 
723
743