1
/* ApplicationItemSource.cs
3
* GNOME Do is the legal property of its developers. Please refer to the
4
* COPYRIGHT file distributed with this
7
* This program is free software: you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation, either version 3 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24
using System.Collections.Generic;
31
namespace Do.Platform.Linux {
33
public class ApplicationItemSource : IItemSource {
35
const bool show_hidden = false;
37
private IEnumerable<IItem> app_items;
40
/// Locations to search for .desktop files.
42
static IEnumerable<String> DesktopFilesDirectories {
45
"~/.local/share/applications/wine",
46
"~/.local/share/applications",
47
"/usr/share/applications",
48
"/usr/share/applications/kde",
49
"/usr/share/applications/kde4",
50
"/usr/share/gdm/applications",
51
"/usr/local/share/applications",
57
public ApplicationItemSource ()
59
app_items = Enumerable.Empty<IItem> ();
62
public IEnumerable<Type> SupportedItemTypes {
63
get { yield return typeof (ApplicationItem); }
67
get { return Catalog.GetString ("Applications"); }
70
public string Description {
71
get { return Catalog.GetString ("Finds applications in many locations."); }
75
get { return "gnome-applications"; }
79
/// Given an absolute path to a directory, scan that directory for
80
/// .desktop files, creating an ApplicationItem for each desktop file
81
/// found and adding the ApplicationItem to the list of
84
/// <param name="dir">
85
/// A <see cref="System.String"/> containing an absolute path to a
87
/// where .desktop files can be found.
89
private static IEnumerable<ApplicationItem> LoadDesktopFiles (string dir)
91
if (!Directory.Exists (dir))
92
return Enumerable.Empty<ApplicationItem> ();
94
return Directory.GetFiles (dir, "*.desktop")
95
.Select (file => new ApplicationItem (file))
96
.Where (app => !string.IsNullOrEmpty (app.Name) &&
97
app.IsAppropriateForCurrentDesktop &&
98
(show_hidden || !app.NoDisplay));
101
public void UpdateItems ()
103
// Updating is turned off because it uses a ridiculous amount of memory.
104
if (app_items.Any ()) return;
106
app_items = DesktopFilesDirectories
107
.Select (dir => dir.Replace ("~", Paths.UserHome))
108
.Select (dir => LoadDesktopFiles (dir))
109
.Aggregate ((a, b) => Enumerable.Concat (a, b))
114
public IEnumerable<IItem> Items {
115
get { return app_items; }
118
public IEnumerable<IItem> ChildrenOfItem (IItem item)