Merge lp:~cjcurran/indicator-sound/refactor-desktop-file-loading into lp:~indicator-applet-developers/indicator-sound/trunk_3

Proposed by Conor Curran
Status: Merged
Merged at revision: 104
Proposed branch: lp:~cjcurran/indicator-sound/refactor-desktop-file-loading
Merge into: lp:~indicator-applet-developers/indicator-sound/trunk_3
Diff against target: 166 lines (+42/-37)
2 files modified
src/music-player-bridge.vala (+27/-31)
src/settings-manager.vala (+15/-6)
To merge this branch: bzr merge lp:~cjcurran/indicator-sound/refactor-desktop-file-loading
Reviewer Review Type Date Requested Status
Neil J. Patel (community) Approve
Review via email: mp+44613@code.launchpad.net

Description of the change

see bug attached

To post a comment you must log in.
Revision history for this message
Neil J. Patel (njpatel) wrote :

makes sense, approved.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/music-player-bridge.vala'
2--- src/music-player-bridge.vala 2010-12-21 14:53:56 +0000
3+++ src/music-player-bridge.vala 2010-12-23 19:37:21 +0000
4@@ -27,7 +27,6 @@
5 private Dbusmenu.Menuitem root_menu;
6 private HashMap<string, PlayerController> registered_clients;
7 private Mpris2Watcher watcher;
8- private const string DESKTOP_PREFIX = "/usr/share/applications/";
9 private Settings settings;
10
11 public MusicPlayerBridge()
12@@ -49,17 +48,17 @@
13 {
14 foreach ( string desktop in this.settings_manager.fetch_interested()){
15 debug ( "interested client found : %s", desktop );
16- string path = DESKTOP_PREFIX.concat ( desktop.concat( ".desktop" ) );
17- AppInfo? app_info = create_app_info ( path );
18+ AppInfo? app_info = create_app_info ( desktop.concat( ".desktop" ) );
19 if ( app_info == null ){
20- warning ( "Could not create app_info for path %s \n Getting out of here ", path);
21+ warning ( "Could not create app_info for path %s \n Getting out of here ",
22+ desktop );
23 continue;
24 }
25- var mpris_key = determine_key ( path );
26+ var mpris_key = determine_key ( desktop );
27 PlayerController ctrl = new PlayerController ( this.root_menu,
28 app_info,
29 null,
30- this.fetch_icon_name(path),
31+ this.fetch_icon_name(desktop),
32 calculate_menu_position(),
33 PlayerController.state.OFFLINE );
34 this.registered_clients.set(mpris_key, ctrl);
35@@ -84,21 +83,21 @@
36 return;
37 }
38 debug ( "client_has_become_available %s", desktop );
39- string path = DESKTOP_PREFIX.concat ( desktop.concat( ".desktop" ) );
40- AppInfo? app_info = create_app_info ( path );
41+ AppInfo? app_info = create_app_info ( desktop.concat( ".desktop" ) );
42 if ( app_info == null ){
43- warning ( "Could not create app_info for path %s \n Getting out of here ", path);
44+ warning ( "Could not create app_info for path %s \n Getting out of here ",
45+ desktop );
46 return;
47 }
48
49- var mpris_key = determine_key ( path );
50+ var mpris_key = determine_key ( desktop );
51 // Are we sure clients will appear like this with the new registration method in place.
52 if ( this.registered_clients.has_key (mpris_key) == false ){
53 debug("New client has registered that we have not seen before: %s", dbus_name );
54 PlayerController ctrl = new PlayerController ( this.root_menu,
55 app_info,
56 dbus_name,
57- this.fetch_icon_name(path),
58+ this.fetch_icon_name(desktop),
59 this.calculate_menu_position(),
60 PlayerController.state.READY );
61 this.registered_clients.set ( mpris_key, ctrl );
62@@ -135,22 +134,24 @@
63 this.watcher.client_disappeared += this.client_has_vanished;
64 }
65
66- private static AppInfo? create_app_info ( string path )
67+ private static AppInfo? create_app_info ( string desktop )
68 {
69- DesktopAppInfo info = new DesktopAppInfo.from_filename ( path ) ;
70- if ( path == null || info == null ){
71- warning ( "Could not create a desktopappinfo instance from app: %s", path );
72+ DesktopAppInfo info = new DesktopAppInfo ( desktop ) ;
73+ if ( desktop == null || info == null ){
74+ warning ( "Could not create a desktopappinfo instance from app: %s", desktop );
75 return null;
76 }
77 GLib.AppInfo app_info = info as GLib.AppInfo;
78 return app_info;
79 }
80
81- private static string? fetch_icon_name(string desktop_path)
82+ private static string? fetch_icon_name(string desktop)
83 {
84+ // We know the appinfo is good because it was loaded in the previous reg step.
85+ DesktopAppInfo info = new DesktopAppInfo ( desktop.concat( ".desktop" ) ) ;
86 KeyFile desktop_keyfile = new KeyFile ();
87 try{
88- desktop_keyfile.load_from_file (desktop_path, KeyFileFlags.NONE);
89+ desktop_keyfile.load_from_file (info.get_filename(), KeyFileFlags.NONE);
90 }
91 catch(GLib.FileError error){
92 warning("Error loading keyfile - FileError");
93@@ -172,24 +173,19 @@
94 }
95
96 /*
97- Messy but necessary method to consolidate desktop filesnames and mpris dbus names
98- into the one single word string (used as the key in the players hash).
99+ Messy but necessary method to consolidate desktop filesnames and mpris dbus
100+ names into the one single word string (used as the key in the players hash).
101 So this means that we can determine the key for the players_hash from the
102- dbus interface name or the desktop file name.
103+ dbus interface name or the desktop file name, at startup offline/online and
104+ shutdown.
105 */
106- private static string? determine_key(owned string path)
107+ private static string? determine_key(owned string desktop_or_interface)
108 {
109- var tokens = path.split( "/" );
110- if ( tokens.length < 2 ){
111- // try to split on "."
112- tokens = path.split(".");
113- if ( tokens.length < 2 ){
114- // don't know what this is
115- return null;
116- }
117+ var result = desktop_or_interface;
118+ var tokens = desktop_or_interface.split( "." );
119+ if ( tokens.length > 1 ){
120+ result = tokens[tokens.length - 1];
121 }
122- var filename = tokens[tokens.length - 1];
123- var result = filename.split(".")[0];
124 var temp = result.split("-");
125 if (temp.length > 1){
126 result = temp[0];
127
128=== modified file 'src/settings-manager.vala'
129--- src/settings-manager.vala 2010-12-15 16:23:15 +0000
130+++ src/settings-manager.vala 2010-12-23 19:37:21 +0000
131@@ -27,7 +27,7 @@
132 }
133 construct{
134 this.settings = new Settings ("com.canonical.indicators.sound");
135- settings.changed["blacklisted-media-players"].connect (on_blacklist_event);
136+ this.settings.changed["blacklisted-media-players"].connect (on_blacklist_event);
137 }
138
139 public string[] fetch_blacklist()
140@@ -40,12 +40,21 @@
141 return this.settings.get_strv ("interested-media-players");
142 }
143
144- public bool add_interested(string app_desktop_name)
145- {
146- string[] already_interested = fetch_interested();
147+ public void clear_list()
148+ {
149+ this.settings.reset("interested-media-players");
150+ }
151+
152+ public void add_interested(string app_desktop_name)
153+ {
154+ var already_interested = fetch_interested();
155+ foreach ( var s in already_interested){
156+ if ( s == app_desktop_name ) return;
157+ }
158 already_interested += (app_desktop_name);
159- return this.settings.set_strv( "interested-media-players",
160- already_interested );
161+ this.settings.set_strv( "interested-media-players",
162+ already_interested );
163+ this.settings.apply();
164 }
165
166 private void on_blacklist_event()

Subscribers

People subscribed via source and target branches