~jejones/do/future-actionsource

« back to all changes in this revision

Viewing changes to Do/src/Do.Core/SimpleUniverseManager.cs

  • Committer: Jason Jones
  • Date: 2008-11-20 06:10:13 UTC
  • mfrom: (621.1.93 do-future)
  • Revision ID: jasonedwardjones@gmail.com-20081120061013-rvut5x49nqb8hahi
MergedĀ fromĀ future.

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
                /// </value>
53
53
                int UpdateTimeout {
54
54
                        get {
55
 
                                return (DBus.PowerState.OnBattery ()) ? 10*60*1000 : 2*60*1000;
 
55
                                return DBus.PowerState.OnBattery () ? 10*60*1000 : 2*60*1000;
56
56
                        }
57
57
                }
58
58
                
61
61
                /// </value>
62
62
                int UpdateRunTime {
63
63
                        get {
64
 
                                return (DBus.PowerState.OnBattery ()) ? 600 : 200;
 
64
                                return DBus.PowerState.OnBattery () ? 600 : 200;
65
65
                        }
66
66
                }
67
67
                
75
75
                        UpdatesEnabled = true;
76
76
                }
77
77
 
78
 
                public IList<IObject> Search (string query, Type[] searchFilter)
 
78
                public IList<IObject> Search (string query, IEnumerable<Type> filter)
79
79
                {       
80
 
                        if (searchFilter.Length == 1 && searchFilter[0] == typeof (IAction))
81
 
                                lock (action_lock)
82
 
                                        return Search (query, searchFilter, actions, null);
83
 
                        
84
 
                        lock (universe_lock) 
85
 
                                return Search (query, searchFilter, universe.Values, null);
86
 
                }
87
 
                
88
 
                public IList<IObject> Search (string query, Type[] searchFilter, IObject otherObj)
89
 
                {
90
 
                        if (searchFilter.Length == 1 && searchFilter[0] == typeof (IAction))
91
 
                                lock (action_lock)
92
 
                                        return Search (query, searchFilter, actions, otherObj);
93
 
                        
94
 
                        lock (universe_lock) 
95
 
                                return Search (query, searchFilter, universe.Values, otherObj);
96
 
                }
97
 
                
98
 
                public IList<IObject> Search (string query, Type[] searchFilter, IEnumerable<IObject> baseArray)
99
 
                {
100
 
                        return Search (query, searchFilter, baseArray, null);
101
 
                }
102
 
                
103
 
                public IList<IObject> Search (string query, Type[] searchFilter, IEnumerable<IObject> baseArray, IObject compareObj)
104
 
                {
105
 
                        List<IObject> results = new List<IObject> ();
106
 
                        query = query.ToLower ();
107
 
                        
108
 
                        foreach (DoObject obj in baseArray) {
109
 
                                obj.UpdateRelevance (query, compareObj as DoObject);
110
 
                                if (Math.Abs (obj.Relevance) > epsilon) {
111
 
                                        if (searchFilter.Length == 0) {
112
 
                                                results.Add (obj);
113
 
                                        } else {
114
 
                                                foreach (Type t in searchFilter) {
115
 
                                                        if (t.IsInstanceOfType (obj.Inner)) {
116
 
                                                                results.Add (obj);
117
 
                                                                break;
118
 
                                                        }
119
 
                                                }
120
 
                                        }
121
 
                                }
122
 
                        }
123
 
                        results.Sort ();
124
 
                        return results.ToArray ();
 
80
                                return Search (query, filter, (IObject) null);
 
81
                }
 
82
                
 
83
                public IList<IObject> Search (string query, IEnumerable<Type> filter, IObject other)
 
84
                {
 
85
                        if (filter.Count () == 1 && filter.First () == typeof (IAction))
 
86
                                lock (action_lock)
 
87
                                        return Search (query, filter, actions, other);
 
88
                        else
 
89
                                lock (universe_lock) 
 
90
                                        return Search (query, filter, universe.Values, other);
 
91
                }
 
92
                
 
93
                public IList<IObject> Search (string query, IEnumerable<Type> filter, IEnumerable<IObject> objects)
 
94
                {
 
95
                        return Search (query, filter, objects, null);
 
96
                }
 
97
                
 
98
                public IList<IObject> Search (string query, IEnumerable<Type> filter, IEnumerable<IObject> objects, IObject other)
 
99
                {
 
100
                        return objects
 
101
                                .Where (iobj => {
 
102
                                        DoObject o = iobj as DoObject;
 
103
                                        o.UpdateRelevance (query, other as DoObject);
 
104
                                        return epsilon < Math.Abs (o.Relevance) && 
 
105
                                                (!filter.Any () || o.Inner.IsAssignableToAny (filter));
 
106
                                })
 
107
                                .OrderByDescending (o => (o as DoObject).Relevance)
 
108
                                .ToArray ();
125
109
                }
126
110
                
127
111
                /// <summary>
167
151
                
168
152
                internal static bool SourceSupportsItem (IItemSource source, IItem item)
169
153
                {
170
 
                        // While is used to get to the innermost wrapped IItem.
171
 
                        while (item is DoItem)
172
 
                                item = (item as DoItem).Inner as IItem;
173
 
                        
174
 
                        return source.SupportedItemTypes
175
 
                                .Where (t => t.IsInstanceOfType (item))
176
 
                                .Any ();
 
154
                        item = DoItem.EnsureIItem (item);;
 
155
                        return source.SupportedItemTypes.Any (t => t.IsInstanceOfType (item));
177
156
                }
178
157
                
179
158
                /// <summary>
215
194
                                if (thread.IsAlive)
216
195
                                        thread.Join ();
217
196
                                
218
 
                                if (DateTime.Now.Subtract (last_action_update).TotalMinutes > 4) {
 
197
                                if (DateTime.Now.Subtract (last_action_update).TotalMilliseconds > 10 * UpdateTimeout) {
219
198
                                        Log.Info ("Updating Actions");
220
199
                                        ReloadActions ();
221
200
                                        last_action_update = DateTime.Now;