~ubuntu-branches/ubuntu/precise/gnome-do/precise-proposed

« back to all changes in this revision

Viewing changes to Do.Addins/src/Do.Universe/ApplicationItemSource.cs

  • Committer: Bazaar Package Importer
  • Author(s): Christopher James Halse Rogers
  • Date: 2008-09-14 10:09:40 UTC
  • mto: (0.1.8 sid)
  • mto: This revision was merged to the branch mainline in revision 7.
  • Revision ID: james.westby@ubuntu.com-20080914100940-kyghudg7py14bu2z
Tags: upstream-0.6.0.0
ImportĀ upstreamĀ versionĀ 0.6.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
using System;
22
22
using System.IO;
23
23
using System.Collections.Generic;
 
24
using Mono.Unix;
24
25
 
25
26
namespace Do.Universe {
26
27
 
27
28
        public class ApplicationItemSource : IItemSource {
28
29
 
29
 
                private List<IItem> apps;
 
30
                private Dictionary<string,IItem> apps;
 
31
 
 
32
                bool show_hidden = false;
30
33
                
31
34
                /// <summary>
32
35
                /// Locations to search for .desktop files.
39
42
                                        "/usr/share/gdm/applications",
40
43
                                        "/usr/local/share/applications",
41
44
                                        "~/.local/share/applications",
 
45
                                        "~/.local/share/applications/wine",
42
46
                                        Desktop,
43
47
                                };
44
48
                        }
52
56
 
53
57
                public ApplicationItemSource ()
54
58
                {
55
 
                        apps = new List<IItem> ();
56
 
                        UpdateItems ();
 
59
                        apps = new Dictionary<string,IItem> ();
57
60
                }
58
61
 
59
62
                public Type [] SupportedItemTypes {
65
68
                }
66
69
 
67
70
                public string Name {
68
 
                        get { return "Applications"; }
 
71
                        get { return Catalog.GetString ("Applications"); }
69
72
                }
70
73
 
71
74
                public string Description {
72
 
                        get { return "Finds applications in many locations."; }
 
75
                        get { return Catalog.GetString ("Finds applications in many locations."); }
73
76
                }
74
77
 
75
78
                public string Icon {
89
92
                /// </param>
90
93
                private void LoadDesktopFiles (string dir)
91
94
                {
92
 
                        ApplicationItem app;
93
 
 
94
95
                        if (!Directory.Exists (dir)) return;
95
 
                        foreach (string filename in Directory.GetFiles (dir)) {
96
 
                                if (!filename.EndsWith (".desktop")) continue;
 
96
                        foreach (string file in Directory.GetFiles (dir, "*.desktop")) {
 
97
                ApplicationItem app;
 
98
 
 
99
                if (apps.ContainsKey (file)) continue;
97
100
                                try {
98
 
                                        app = new ApplicationItem (filename);
 
101
                                        app = new ApplicationItem (file);
99
102
                                } catch {
100
103
                                        continue;
101
104
                                }
102
 
                                apps.Add (app);
 
105
                                if (string.IsNullOrEmpty (app.Exec) || string.IsNullOrEmpty (app.Name))
 
106
                                        continue;
 
107
                                
 
108
                                if (!app.Hidden || show_hidden)
 
109
                                        apps [file] = app;
103
110
                        }
104
111
                }
105
112
 
106
113
                public void UpdateItems ()
107
114
                {
108
 
                        apps.Clear ();
 
115
                        // Updating is turned off because it uses a ridiculous amount of memory.
 
116
                        if (apps.Count > 0) return;
 
117
                        
109
118
                        foreach (string dir in DesktopFilesDirectories) {
110
119
                                LoadDesktopFiles (dir.Replace ("~", Paths.UserHome));
111
120
                        }
112
121
                }
113
122
 
114
123
                public ICollection<IItem> Items {
115
 
                        get { return apps; }
 
124
                        get { return apps.Values; }
116
125
                }
117
126
 
118
127
                public ICollection<IItem> ChildrenOfItem (IItem item)
119
128
                {
120
129
                        return null;
121
130
                }
 
131
 
122
132
        }
123
133
}