343
343
props.insert ("quicklist", l._object_path);
348
public class LauncherFavorites : Object
350
public signal void changed ();
352
private static LauncherFavorites? singleton = null;
353
private Settings settings;
355
/* We keep both a map and a list in order to have the correct sorting */
356
private HashTable<string,AppInfo?> fav_cache;
357
private string[] fav_list;
359
private LauncherFavorites ()
361
settings = new Settings ("com.canonical.Unity.Launcher");
362
fav_cache = new HashTable<string,AppInfo?> (str_hash, str_equal);
365
settings.changed["favorites"].connect (reset_fav_cache);
368
private void reset_fav_cache ()
370
fav_cache.remove_all ();
371
fav_list = settings.get_strv ("favorites");
372
foreach (string id in fav_list)
374
fav_cache.insert (id, null);
381
* Get the default singleton Unity.LauncherFavorites instance, creating it
382
* dynamically if necessary.
384
* @return: (transfer none): The singleton Unity.LauncherFavorites.
385
* If calling from C do not free this instance.
388
public static unowned LauncherFavorites get_default ()
390
if (singleton == null)
391
singleton = new LauncherFavorites ();
396
public bool has_app_info (AppInfo appinfo) {
397
if (appinfo.get_id () == null)
399
critical ("Can not look up favorite for AppInfo with NULL id");
403
return has_app_id (appinfo.get_id ());
406
public bool has_app_id (string app_id)
408
return fav_cache.lookup_extended (app_id, null, null);
411
public AppInfo? lookup (string app_id)
414
bool has_id = fav_cache.lookup_extended (app_id, null, out appinfo);
416
/* If we don't have the appinfo cached, pull it out of the
417
* AppInfoManager and cache it */
423
var appman = AppInfoManager.get_default ();
424
appinfo = appman.lookup (app_id);
425
fav_cache.insert (app_id, appinfo);
427
// FIXME: We really should return a dummy AppInfo for faves
428
// where we can't find the .desktop file...
431
critical ("Can't find AppInfo for favorite '%s'", app_id);
440
public string[] enumerate_ids ()
445
public AppInfo[] enumerate_app_infos ()
448
var infos = new AppInfo[fav_cache.size ()];
450
foreach (string id in fav_list)
452
var appinfo = lookup (id);
348
461
} /* namespace */