~mhr3/unity-lens-applications/fix-1066816

« back to all changes in this revision

Viewing changes to src/daemon.vala

  • Committer: Tarmac
  • Author(s): Pawel Stolowski
  • Date: 2012-09-25 15:54:53 UTC
  • mfrom: (304.1.3 use-icon-uri)
  • Revision ID: tarmac-20120925155453-k97wlxhk040vtwcc
Use icon_url when displaying preview of an installable app; use find_pkg_icon instead of find_app_install_icon_path, as it also uses icons from ~/.cache/software-center/icons. Removed find_app_install_icon_path as it's no longer used.. Fixes: https://bugs.launchpad.net/bugs/1054085. Approved by Michal Hruby.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
  const int64 TOP_RATED_ITEMS_CACHE_LIFETIME = 24*3600; // 24 hours
42
42
 
43
43
  const string ICON_PATH = Config.DATADIR + "/icons/unity-icon-theme/places/svg/";
44
 
  const string ICON_APP_INSTALL_PATH = Config.DATADIR + "/app-install/icons";
 
44
  const string GENERIC_APP_ICON = "applications-other";
45
45
 
46
46
  public class Daemon : GLib.Object
47
47
  {
791
791
      }
792
792
    }
793
793
 
794
 
    /**
795
 
     * Find app icon in DATADIR/app-install/icons trying all supported image extensions.
796
 
     */
797
 
    private string find_app_install_icon_path (string icon_name)
 
794
    public Icon find_pkg_icon (string? desktop_file, string icon_name)
798
795
    {
799
 
      string icon = @"$ICON_APP_INSTALL_PATH/$icon_name.";
800
 
 
801
 
      foreach (string ext in image_extensions)
 
796
      if (desktop_file != null)
802
797
      {
803
 
        string path = icon + ext;
804
 
        if (FileUtils.test (path, FileTest.EXISTS))
805
 
        {
806
 
          return path;
807
 
        }
 
798
        string desktop_id = Path.get_basename (desktop_file);
 
799
        bool installed = AppInfoManager.get_default().lookup (desktop_id) != null;
 
800
 
 
801
        /* If the app is already installed we should be able to pull the
 
802
         * icon from the theme */
 
803
        if (installed)
 
804
          return new ThemedIcon (icon_name);
808
805
      }
809
 
      var default_icon = new ThemedIcon ("applications-other");
810
 
      return default_icon.to_string ();
811
 
    }
812
 
 
813
 
    public Icon find_pkg_icon (string desktop_file, string icon_name)
814
 
    {
815
 
      string desktop_id = Path.get_basename (desktop_file);
816
 
      bool installed = AppInfoManager.get_default().lookup (desktop_id) != null;
817
 
 
818
 
      /* If the app is already installed we should be able to pull the
819
 
       * icon from the theme */
820
 
      if (installed)
821
 
        return new ThemedIcon (icon_name);
822
806
 
823
807
      /* App is not installed - we need to find the right icon in the bowels
824
808
       * of the software center */
873
857
      }
874
858
 
875
859
      /* Cache the fact that we couldn't find this icon */
876
 
      var icon = new ThemedIcon ("applications-other");
 
860
      var icon = new ThemedIcon (GENERIC_APP_ICON);
877
861
      file_icon_cache.insert (icon_name, icon);
878
862
 
879
863
      return icon;
1145
1129
 
1146
1130
              launcherservice.connect_to_launcher ();
1147
1131
              string desktop_file = preview_installable_desktop_file;
1148
 
              string icon = find_app_install_icon_path (preview_installable_icon_file);
1149
 
              
1150
 
              launcherservice.add_launcher_item_from_position (appname, icon, 0, 0, 32, desktop_file, tid);
 
1132
              Icon icon = find_pkg_icon (null, preview_installable_icon_file);
 
1133
              launcherservice.add_launcher_item_from_position (appname, icon.to_string (), 0, 0, 32, desktop_file, tid);
1151
1134
            }
1152
1135
            catch (IOError e)
1153
1136
            {
1296
1279
            debug ("Requesting pkg info: %s, %s\n", pkgname, appname);
1297
1280
            sc_data_provider.get_app_details (appname, pkgname);
1298
1281
 
1299
 
            Icon icon;
 
1282
            Icon? icon = null;
1300
1283
            if (installed)
1301
1284
              icon = new GLib.ThemedIcon (sc_data_provider.icon);
1302
1285
            else
1303
 
              icon = new GLib.FileIcon (File.new_for_path (find_app_install_icon_path (sc_data_provider.icon)));
 
1286
            {
 
1287
              icon = find_pkg_icon (null, sc_data_provider.icon);
 
1288
              if (icon.to_string () == GENERIC_APP_ICON && sc_data_provider.icon_url != null && sc_data_provider.icon_url != "")
 
1289
              {
 
1290
                icon = new GLib.FileIcon (File.new_for_uri (sc_data_provider.icon_url));
 
1291
              }
 
1292
            }
1304
1293
 
1305
1294
            Icon? screenshot = null;
1306
1295