Merge lp:~cszikszoy/do/NetworkService into lp:do
- NetworkService
- Merge into trunk
Proposed by
Chris S.
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | not available | ||||
Proposed branch: | lp:~cszikszoy/do/NetworkService | ||||
Merge into: | lp:do | ||||
Diff against target: | None lines | ||||
To merge this branch: | bzr merge lp:~cszikszoy/do/NetworkService | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
David Siegel (community) | Disapprove | ||
Review via email: mp+7295@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Chris S. (cszikszoy) wrote : | # |
Revision history for this message
David Siegel (djsiegel-deactivatedaccount) wrote : | # |
Removing elements from the Universe is not a good solution. Users will have no idea why they cannot find items and actions that are usually there.
Also, adding a boolean to Element is not appropriate.
review:
Disapprove
Revision history for this message
David Siegel (djsiegel-deactivatedaccount) wrote : | # |
However, the Network service seems like a reasonable way to let plugins know when they should stop trying (and failing) to talk to the network. Remove the universe stuff and we can take another look.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'Do.Platform.Linux/Do.Platform.Linux.mdp' |
2 | --- Do.Platform.Linux/Do.Platform.Linux.mdp 2009-06-05 19:45:45 +0000 |
3 | +++ Do.Platform.Linux/Do.Platform.Linux.mdp 2009-06-10 05:30:30 +0000 |
4 | @@ -49,6 +49,7 @@ |
5 | <File name="src/Do.Platform/Do.Platform.Linux/Do.Platform.Linux.DBus/Registrar.cs" subtype="Code" buildaction="Compile" /> |
6 | <File name="src/Do.Platform/Do.Platform.Linux/SystemService.cs" subtype="Code" buildaction="Compile" /> |
7 | <File name="src/Do.Universe/NullApplicationItem.cs" subtype="Code" buildaction="Compile" /> |
8 | + <File name="src/Do.Platform/Do.Platform.Linux/NetworkService.cs" subtype="Code" buildaction="Compile" /> |
9 | </Contents> |
10 | <References> |
11 | <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> |
12 | |
13 | === modified file 'Do.Platform.Linux/Makefile.am' |
14 | --- Do.Platform.Linux/Makefile.am 2009-05-29 01:26:23 +0000 |
15 | +++ Do.Platform.Linux/Makefile.am 2009-06-10 05:30:30 +0000 |
16 | @@ -21,6 +21,7 @@ |
17 | src/Do.Platform/Do.Platform.Linux/TrayIconPreferences.cs \ |
18 | src/Do.Platform/Do.Platform.Linux/TrayIconService.cs \ |
19 | src/Do.Platform/Do.Platform.Linux/UniverseFactoryService.cs \ |
20 | + src/Do.Platform/Do.Platform.Linux/NetworkService.cs \ |
21 | src/Do.Universe/ApplicationItem.cs \ |
22 | src/Do.Universe/CategoryItem.cs \ |
23 | src/Do.Universe/NullApplicationItem.cs \ |
24 | |
25 | === modified file 'Do.Platform.Linux/Resources/Do.Platform.Linux.addin.xml' |
26 | --- Do.Platform.Linux/Resources/Do.Platform.Linux.addin.xml 2009-02-17 22:48:40 +0000 |
27 | +++ Do.Platform.Linux/Resources/Do.Platform.Linux.addin.xml 2009-06-10 05:30:30 +0000 |
28 | @@ -23,6 +23,7 @@ |
29 | <Service type="Do.Platform.Common.EventsOnlyNotificationsService" /> |
30 | |
31 | <Service type="Do.Platform.Linux.SystemService" /> |
32 | + <Service type="Do.Platform.Linux.NetworkService" /> |
33 | <Service type="Do.Platform.Linux.TrayIconService" /> |
34 | <Service type="Do.Platform.Linux.ConsoleLogService" /> |
35 | <Service type="Do.Platform.Linux.EnvironmentService" /> |
36 | |
37 | === added file 'Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/NetworkService.cs' |
38 | --- Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/NetworkService.cs 1970-01-01 00:00:00 +0000 |
39 | +++ Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/NetworkService.cs 2009-06-10 16:44:20 +0000 |
40 | @@ -0,0 +1,94 @@ |
41 | +// NetworkService.cs |
42 | +// |
43 | +// GNOME Do is the legal property of its developers. Please refer to the |
44 | +// COPYRIGHT file distributed with this source distribution. |
45 | +// |
46 | +// This program is free software: you can redistribute it and/or modify |
47 | +// it under the terms of the GNU General Public License as published by |
48 | +// the Free Software Foundation, either version 3 of the License, or |
49 | +// (at your option) any later version. |
50 | +// |
51 | +// This program is distributed in the hope that it will be useful, |
52 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
53 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
54 | +// GNU General Public License for more details. |
55 | +// |
56 | +// You should have received a copy of the GNU General Public License |
57 | +// along with this program. If not, see <http://www.gnu.org/licenses/>. |
58 | +// |
59 | + |
60 | +using System; |
61 | +using System.Reflection; |
62 | + |
63 | +using NDesk.DBus; |
64 | +using org.freedesktop.DBus; |
65 | + |
66 | +using Do.Platform.ServiceStack; |
67 | +using Do.Platform.Linux.DBus; |
68 | + |
69 | +namespace Do.Platform.Linux |
70 | +{ |
71 | + |
72 | + public class NetworkService : INetworkService |
73 | + { |
74 | + const string NetworkManagerName = "org.freedesktop.NetworkManager"; |
75 | + const string NetworkManagerPath = "/org/freedesktop/NetworkManager"; |
76 | + |
77 | + [Interface(NetworkManagerName)] |
78 | + interface INetworkManager : org.freedesktop.DBus.Properties |
79 | + { |
80 | + event StateChangedHandler StateChanged; |
81 | + } |
82 | + |
83 | + delegate void StateChangedHandler (uint state); |
84 | + |
85 | + INetworkManager network; |
86 | + |
87 | + public event EventHandler<NetworkStateChangedEventArgs> StateChanged; |
88 | + |
89 | + public NetworkService () |
90 | + { |
91 | + try { |
92 | + BusG.Init (); |
93 | + if (Bus.System.NameHasOwner (NetworkManagerName)) { |
94 | + network = Bus.System.GetObject<INetworkManager> (NetworkManagerName, new ObjectPath (NetworkManagerPath)); |
95 | + network.StateChanged += OnStateChanged; |
96 | + } |
97 | + } catch (Exception e) { |
98 | + Log<NetworkService>.Error ("Could not initialize dbus: {0}", e.Message); |
99 | + Log<NetworkService>.Debug (e.StackTrace); |
100 | + } |
101 | + |
102 | + SetConnected (); |
103 | + } |
104 | + |
105 | + void OnStateChanged (uint state) |
106 | + { |
107 | + NetworkState newState = (NetworkState) Enum.ToObject (typeof (NetworkState), state); |
108 | + SetConnected (); |
109 | + if (StateChanged != null) { |
110 | + StateChanged (this, new NetworkStateChangedEventArgs (newState)); |
111 | + } |
112 | + } |
113 | + |
114 | + void SetConnected () |
115 | + { |
116 | + if (this.State == NetworkState.Connected) |
117 | + IsConnected = true; |
118 | + else |
119 | + IsConnected = false; |
120 | + } |
121 | + |
122 | + NetworkState State { |
123 | + get { |
124 | + return (NetworkState) Enum.ToObject (typeof (NetworkState), network.Get (NetworkManagerName, "State")); |
125 | + } |
126 | + } |
127 | + |
128 | + #region INetworkService |
129 | + |
130 | + public bool IsConnected { get; private set; } |
131 | + |
132 | + #endregion |
133 | + } |
134 | +} |
135 | \ No newline at end of file |
136 | |
137 | === modified file 'Do.Platform/Do.Platform.mdp' |
138 | --- Do.Platform/Do.Platform.mdp 2009-06-05 19:45:45 +0000 |
139 | +++ Do.Platform/Do.Platform.mdp 2009-06-10 05:30:30 +0000 |
140 | @@ -76,6 +76,9 @@ |
141 | <File name="src/System/Linq/EnumerableExtensions.cs" subtype="Code" buildaction="Compile" /> |
142 | <File name="src/Do.Platform/AbstractSystemService.cs" subtype="Code" buildaction="Compile" /> |
143 | <File name="src/Do.Platform/Do.Platform.Default/DefaultSystemService.cs" subtype="Code" buildaction="Compile" /> |
144 | + <File name="src/Do.Platform/INetworkService.cs" subtype="Code" buildaction="Compile" /> |
145 | + <File name="src/Do.Platform/NetworkStateChangedEventArgs.cs" subtype="Code" buildaction="Compile" /> |
146 | + <File name="src/Do.Platform/Do.Platform.Default/NetworkService.cs" subtype="Code" buildaction="Compile" /> |
147 | </Contents> |
148 | <References> |
149 | <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> |
150 | |
151 | === modified file 'Do.Platform/Makefile.am' |
152 | --- Do.Platform/Makefile.am 2009-02-17 21:58:50 +0000 |
153 | +++ Do.Platform/Makefile.am 2009-06-10 05:30:30 +0000 |
154 | @@ -25,6 +25,7 @@ |
155 | src/Do.Platform/Do.Platform.Default/SecurePreferencesService.cs \ |
156 | src/Do.Platform/Do.Platform.Default/UniverseFactoryService.cs \ |
157 | src/Do.Platform/Do.Platform.Default/WindowingService.cs \ |
158 | + src/Do.Platform/Do.Platform.Default/NetworkService.cs \ |
159 | src/Do.Platform/Do.Platform.Preferences/PreferencesFactory.cs \ |
160 | src/Do.Platform/Do.Platform.Preferences/PreferencesImplementation.cs \ |
161 | src/Do.Platform/Do.Platform.ServiceStack/IInitializedService.cs \ |
162 | @@ -49,6 +50,8 @@ |
163 | src/Do.Platform/PreferencesChangedEventArgs.cs \ |
164 | src/Do.Platform/SecurePreferencesWrapper.cs \ |
165 | src/Do.Platform/Services.cs \ |
166 | + src/Do.Platform/INetworkService.cs \ |
167 | + src/Do.Platform/NetworkStateChangedEventArgs.cs \ |
168 | src/Do.Universe/Do.Universe.Common/EmailAction.cs \ |
169 | src/Do.Universe/Do.Universe.Common/OpenAction.cs \ |
170 | src/Do.Universe/Do.Universe.Common/OpenUrlAction.cs \ |
171 | |
172 | === added file 'Do.Platform/src/Do.Platform/Do.Platform.Default/NetworkService.cs' |
173 | --- Do.Platform/src/Do.Platform/Do.Platform.Default/NetworkService.cs 1970-01-01 00:00:00 +0000 |
174 | +++ Do.Platform/src/Do.Platform/Do.Platform.Default/NetworkService.cs 2009-06-10 05:30:30 +0000 |
175 | @@ -0,0 +1,48 @@ |
176 | +/* NetworkService.cs |
177 | + * |
178 | + * GNOME Do is the legal property of its developers. Please refer to the |
179 | + * COPYRIGHT file distributed with this |
180 | + * source distribution. |
181 | + * |
182 | + * This program is free software: you can redistribute it and/or modify |
183 | + * it under the terms of the GNU General Public License as published by |
184 | + * the Free Software Foundation, either version 3 of the License, or |
185 | + * (at your option) any later version. |
186 | + * |
187 | + * This program is distributed in the hope that it will be useful, |
188 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
189 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
190 | + * GNU General Public License for more details. |
191 | + * |
192 | + * You should have received a copy of the GNU General Public License |
193 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
194 | + */ |
195 | + |
196 | +using System; |
197 | + |
198 | +using Do.Platform; |
199 | + |
200 | +namespace Do.Platform.Default |
201 | +{ |
202 | + |
203 | + public class NetworkService : INetworkService |
204 | + { |
205 | + public event EventHandler<NetworkStateChangedEventArgs> StateChanged; |
206 | + |
207 | + public NetworkService () |
208 | + { |
209 | + connected = true; |
210 | + } |
211 | + |
212 | + bool connected; |
213 | + |
214 | + #region INetworkService |
215 | + |
216 | + public bool IsConnected |
217 | + { |
218 | + get { return connected; } |
219 | + } |
220 | + |
221 | + #endregion |
222 | + } |
223 | +} |
224 | |
225 | === added file 'Do.Platform/src/Do.Platform/INetworkService.cs' |
226 | --- Do.Platform/src/Do.Platform/INetworkService.cs 1970-01-01 00:00:00 +0000 |
227 | +++ Do.Platform/src/Do.Platform/INetworkService.cs 2009-06-10 05:30:30 +0000 |
228 | @@ -0,0 +1,42 @@ |
229 | +/* INetworkService.cs |
230 | + * |
231 | + * GNOME Do is the legal property of its developers. Please refer to the |
232 | + * COPYRIGHT file distributed with this |
233 | + * source distribution. |
234 | + * |
235 | + * This program is free software: you can redistribute it and/or modify |
236 | + * it under the terms of the GNU General Public License as published by |
237 | + * the Free Software Foundation, either version 3 of the License, or |
238 | + * (at your option) any later version. |
239 | + * |
240 | + * This program is distributed in the hope that it will be useful, |
241 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
242 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
243 | + * GNU General Public License for more details. |
244 | + * |
245 | + * You should have received a copy of the GNU General Public License |
246 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
247 | + */ |
248 | + |
249 | +using System; |
250 | + |
251 | +using Do.Platform.ServiceStack; |
252 | + |
253 | +namespace Do.Platform |
254 | +{ |
255 | + |
256 | + public enum NetworkState { |
257 | + Unknown = 0, |
258 | + Asleep, |
259 | + Connecting, |
260 | + Connected, |
261 | + Disconnected |
262 | + } |
263 | + |
264 | + public interface INetworkService : IService |
265 | + { |
266 | + event EventHandler<NetworkStateChangedEventArgs> StateChanged; |
267 | + |
268 | + bool IsConnected { get; } |
269 | + } |
270 | +} |
271 | \ No newline at end of file |
272 | |
273 | === added file 'Do.Platform/src/Do.Platform/NetworkStateChangedEventArgs.cs' |
274 | --- Do.Platform/src/Do.Platform/NetworkStateChangedEventArgs.cs 1970-01-01 00:00:00 +0000 |
275 | +++ Do.Platform/src/Do.Platform/NetworkStateChangedEventArgs.cs 2009-06-10 05:30:30 +0000 |
276 | @@ -0,0 +1,35 @@ |
277 | +/* NetworkStatusChangedEventArgs.cs |
278 | + * |
279 | + * GNOME Do is the legal property of its developers. Please refer to the |
280 | + * COPYRIGHT file distributed with this |
281 | + * source distribution. |
282 | + * |
283 | + * This program is free software: you can redistribute it and/or modify |
284 | + * it under the terms of the GNU General Public License as published by |
285 | + * the Free Software Foundation, either version 3 of the License, or |
286 | + * (at your option) any later version. |
287 | + * |
288 | + * This program is distributed in the hope that it will be useful, |
289 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
290 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
291 | + * GNU General Public License for more details. |
292 | + * |
293 | + * You should have received a copy of the GNU General Public License |
294 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
295 | + */ |
296 | + |
297 | +using System; |
298 | + |
299 | +namespace Do.Platform { |
300 | + |
301 | + public class NetworkStateChangedEventArgs : EventArgs |
302 | + { |
303 | + public NetworkState NewState { get; private set; } |
304 | + |
305 | + public NetworkStateChangedEventArgs (NetworkState newState) |
306 | + { |
307 | + NewState = newState; |
308 | + } |
309 | + } |
310 | + |
311 | +} |
312 | \ No newline at end of file |
313 | |
314 | === modified file 'Do.Platform/src/Do.Platform/Services.cs' |
315 | --- Do.Platform/src/Do.Platform/Services.cs 2009-02-17 21:58:50 +0000 |
316 | +++ Do.Platform/src/Do.Platform/Services.cs 2009-06-10 05:30:30 +0000 |
317 | @@ -43,6 +43,7 @@ |
318 | static IEnvironmentService environment; |
319 | static INotificationsService notifications; |
320 | static IUniverseFactoryService universe_factory; |
321 | + static INetworkService network; |
322 | |
323 | /// <summary> |
324 | /// Initializes the class. Must be called after Mono.Addins is initialized; if this is |
325 | @@ -99,6 +100,8 @@ |
326 | application = null; |
327 | if (service is AbstractSystemService) |
328 | system = null; |
329 | + if (service is INetworkService) |
330 | + network = null; |
331 | } |
332 | |
333 | /// <summary> |
334 | @@ -175,6 +178,14 @@ |
335 | return universe_factory; |
336 | } |
337 | } |
338 | + |
339 | + public static INetworkService Network { |
340 | + get { |
341 | + if (network == null) |
342 | + network = LocateService<INetworkService, Default.NetworkService> (); |
343 | + return network; |
344 | + } |
345 | + } |
346 | |
347 | public static PreferencesFactory Preferences { |
348 | get { |
349 | |
350 | === modified file 'Do.Universe/src/Do.Universe/Element.cs' |
351 | --- Do.Universe/src/Do.Universe/Element.cs 2009-01-17 22:13:37 +0000 |
352 | +++ Do.Universe/src/Do.Universe/Element.cs 2009-06-10 07:29:46 +0000 |
353 | @@ -116,6 +116,14 @@ |
354 | |
355 | public abstract string Icon { get; } |
356 | |
357 | + /// <value> |
358 | + /// Provides an indication of whether or not this element requires an active |
359 | + /// network connection. |
360 | + /// </value> |
361 | + public virtual bool NetworkRequired { |
362 | + get { return false; } |
363 | + } |
364 | + |
365 | public override int GetHashCode () |
366 | { |
367 | return UniqueId.GetHashCode (); |
368 | |
369 | === modified file 'Do/src/Do.Core/UniverseManager.cs' |
370 | --- Do/src/Do.Core/UniverseManager.cs 2009-01-25 20:32:52 +0000 |
371 | +++ Do/src/Do.Core/UniverseManager.cs 2009-06-10 07:42:46 +0000 |
372 | @@ -80,6 +80,13 @@ |
373 | update_thread = new Thread (new ThreadStart (UniverseUpdateLoop)); |
374 | update_thread.IsBackground = true; |
375 | update_thread.Priority = ThreadPriority.Lowest; |
376 | + |
377 | + Services.Network.StateChanged += OnNetworkStateChanged; |
378 | + } |
379 | + |
380 | + void OnNetworkStateChanged (object sender, NetworkStateChangedEventArgs e) |
381 | + { |
382 | + Reload (); |
383 | } |
384 | |
385 | public void Initialize () |
386 | @@ -190,11 +197,11 @@ |
387 | Log<UniverseManager>.Debug ("Reloading actions..."); |
388 | lock (universe) { |
389 | foreach (Act action in PluginManager.Actions) { |
390 | - universe.Remove (action.UniqueId); |
391 | - } |
392 | - foreach (Act action in PluginManager.Actions) { |
393 | - universe [action.UniqueId] = action; |
394 | - } |
395 | + if (universe.ContainsKey (action.UniqueId)) |
396 | + universe.Remove (action.UniqueId); |
397 | + } |
398 | + foreach (Act action in PluginManager.Actions.Where (a => ShouldUpdate (a))) |
399 | + universe [action.UniqueId] = action; |
400 | } |
401 | } |
402 | |
403 | @@ -211,24 +218,37 @@ |
404 | if (source == null) throw new ArgumentNullException ("source"); |
405 | |
406 | safeSource = source.RetainSafe (); |
407 | - Log<UniverseManager>.Debug ("Reloading item source \"{0}\"...", safeSource.Name); |
408 | oldItems = safeSource.Items; |
409 | // We call UpdateItems outside of the lock so as not to block other |
410 | // threads in contention for the lock if UpdateItems blocks. |
411 | - safeSource.UpdateItems (); |
412 | - newItems = safeSource.Items; |
413 | + if (ShouldUpdate (source)) { |
414 | + Log<UniverseManager>.Debug ("Reloading item source \"{0}\"...", safeSource.Name); |
415 | + safeSource.UpdateItems (); |
416 | + newItems = safeSource.Items; |
417 | + } else { |
418 | + newItems = Enumerable.Empty<Item> (); |
419 | + } |
420 | |
421 | lock (universe) { |
422 | foreach (Item item in oldItems) { |
423 | if (universe.ContainsKey (item.UniqueId)) |
424 | universe.Remove (item.UniqueId); |
425 | } |
426 | + //only add the items if no net access is required, or if it is, if we have net access |
427 | foreach (Item item in newItems) { |
428 | universe [item.UniqueId] = item; |
429 | } |
430 | } |
431 | } |
432 | |
433 | + bool ShouldUpdate (Element element) |
434 | + { |
435 | + if (element.NetworkRequired && !Services.Network.IsConnected) |
436 | + return false; |
437 | + else |
438 | + return true; |
439 | + } |
440 | + |
441 | void ReloadUniverse () |
442 | { |
443 | Log<UniverseManager>.Info ("Reloading universe..."); |
Fix for https:/ /bugs.edge. launchpad. net/bugs/ 324484 - Add network connection info to Do.Platform
This patch adds a generic Network service to Do.Platform and a NetworkManager implementation to Do.Platform.Linux
The Network service contains one boolean property (IsConnected) and an event (StateChanged).
Do.Universe.Element was updated and given a boolean property NetAccessRequired. This property defaults to false. Elements (Actions or ItemSources) requiring network access should override this and set it to true.
Do.Core. UniverseManager was also updated to be connection state aware. If no network connection is active, Elements (Actions or ItemSources) requiring network access will be removed from universe. When a network connection is re-established, those items will be added back.