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
=== modified file 'src/music-player-bridge.vala'
--- src/music-player-bridge.vala 2010-12-21 14:53:56 +0000
+++ src/music-player-bridge.vala 2010-12-23 19:37:21 +0000
@@ -27,7 +27,6 @@
27 private Dbusmenu.Menuitem root_menu;27 private Dbusmenu.Menuitem root_menu;
28 private HashMap<string, PlayerController> registered_clients; 28 private HashMap<string, PlayerController> registered_clients;
29 private Mpris2Watcher watcher;29 private Mpris2Watcher watcher;
30 private const string DESKTOP_PREFIX = "/usr/share/applications/";
31 private Settings settings;30 private Settings settings;
32 31
33 public MusicPlayerBridge()32 public MusicPlayerBridge()
@@ -49,17 +48,17 @@
49 {48 {
50 foreach ( string desktop in this.settings_manager.fetch_interested()){49 foreach ( string desktop in this.settings_manager.fetch_interested()){
51 debug ( "interested client found : %s", desktop );50 debug ( "interested client found : %s", desktop );
52 string path = DESKTOP_PREFIX.concat ( desktop.concat( ".desktop" ) );51 AppInfo? app_info = create_app_info ( desktop.concat( ".desktop" ) );
53 AppInfo? app_info = create_app_info ( path );
54 if ( app_info == null ){52 if ( app_info == null ){
55 warning ( "Could not create app_info for path %s \n Getting out of here ", path);53 warning ( "Could not create app_info for path %s \n Getting out of here ",
54 desktop );
56 continue;55 continue;
57 }56 }
58 var mpris_key = determine_key ( path );57 var mpris_key = determine_key ( desktop );
59 PlayerController ctrl = new PlayerController ( this.root_menu, 58 PlayerController ctrl = new PlayerController ( this.root_menu,
60 app_info,59 app_info,
61 null,60 null,
62 this.fetch_icon_name(path),61 this.fetch_icon_name(desktop),
63 calculate_menu_position(),62 calculate_menu_position(),
64 PlayerController.state.OFFLINE );63 PlayerController.state.OFFLINE );
65 this.registered_clients.set(mpris_key, ctrl); 64 this.registered_clients.set(mpris_key, ctrl);
@@ -84,21 +83,21 @@
84 return;83 return;
85 }84 }
86 debug ( "client_has_become_available %s", desktop );85 debug ( "client_has_become_available %s", desktop );
87 string path = DESKTOP_PREFIX.concat ( desktop.concat( ".desktop" ) );86 AppInfo? app_info = create_app_info ( desktop.concat( ".desktop" ) );
88 AppInfo? app_info = create_app_info ( path );
89 if ( app_info == null ){87 if ( app_info == null ){
90 warning ( "Could not create app_info for path %s \n Getting out of here ", path);88 warning ( "Could not create app_info for path %s \n Getting out of here ",
89 desktop );
91 return;90 return;
92 }91 }
93 92
94 var mpris_key = determine_key ( path );93 var mpris_key = determine_key ( desktop );
95 // Are we sure clients will appear like this with the new registration method in place. 94 // Are we sure clients will appear like this with the new registration method in place.
96 if ( this.registered_clients.has_key (mpris_key) == false ){95 if ( this.registered_clients.has_key (mpris_key) == false ){
97 debug("New client has registered that we have not seen before: %s", dbus_name );96 debug("New client has registered that we have not seen before: %s", dbus_name );
98 PlayerController ctrl = new PlayerController ( this.root_menu,97 PlayerController ctrl = new PlayerController ( this.root_menu,
99 app_info,98 app_info,
100 dbus_name,99 dbus_name,
101 this.fetch_icon_name(path), 100 this.fetch_icon_name(desktop),
102 this.calculate_menu_position(),101 this.calculate_menu_position(),
103 PlayerController.state.READY );102 PlayerController.state.READY );
104 this.registered_clients.set ( mpris_key, ctrl );103 this.registered_clients.set ( mpris_key, ctrl );
@@ -135,22 +134,24 @@
135 this.watcher.client_disappeared += this.client_has_vanished;134 this.watcher.client_disappeared += this.client_has_vanished;
136 }135 }
137136
138 private static AppInfo? create_app_info ( string path )137 private static AppInfo? create_app_info ( string desktop )
139 {138 {
140 DesktopAppInfo info = new DesktopAppInfo.from_filename ( path ) ;139 DesktopAppInfo info = new DesktopAppInfo ( desktop ) ;
141 if ( path == null || info == null ){140 if ( desktop == null || info == null ){
142 warning ( "Could not create a desktopappinfo instance from app: %s", path );141 warning ( "Could not create a desktopappinfo instance from app: %s", desktop );
143 return null;142 return null;
144 }143 }
145 GLib.AppInfo app_info = info as GLib.AppInfo;144 GLib.AppInfo app_info = info as GLib.AppInfo;
146 return app_info;145 return app_info;
147 }146 }
148 147
149 private static string? fetch_icon_name(string desktop_path)148 private static string? fetch_icon_name(string desktop)
150 {149 {
150 // We know the appinfo is good because it was loaded in the previous reg step.
151 DesktopAppInfo info = new DesktopAppInfo ( desktop.concat( ".desktop" ) ) ;
151 KeyFile desktop_keyfile = new KeyFile ();152 KeyFile desktop_keyfile = new KeyFile ();
152 try{153 try{
153 desktop_keyfile.load_from_file (desktop_path, KeyFileFlags.NONE);154 desktop_keyfile.load_from_file (info.get_filename(), KeyFileFlags.NONE);
154 }155 }
155 catch(GLib.FileError error){156 catch(GLib.FileError error){
156 warning("Error loading keyfile - FileError");157 warning("Error loading keyfile - FileError");
@@ -172,24 +173,19 @@
172 }173 }
173174
174 /*175 /*
175 Messy but necessary method to consolidate desktop filesnames and mpris dbus names176 Messy but necessary method to consolidate desktop filesnames and mpris dbus
176 into the one single word string (used as the key in the players hash).177 names into the one single word string (used as the key in the players hash).
177 So this means that we can determine the key for the players_hash from the 178 So this means that we can determine the key for the players_hash from the
178 dbus interface name or the desktop file name.179 dbus interface name or the desktop file name, at startup offline/online and
180 shutdown.
179 */181 */
180 private static string? determine_key(owned string path)182 private static string? determine_key(owned string desktop_or_interface)
181 {183 {
182 var tokens = path.split( "/" );184 var result = desktop_or_interface;
183 if ( tokens.length < 2 ){185 var tokens = desktop_or_interface.split( "." );
184 // try to split on "."186 if ( tokens.length > 1 ){
185 tokens = path.split(".");187 result = tokens[tokens.length - 1];
186 if ( tokens.length < 2 ){
187 // don't know what this is
188 return null;
189 }
190 }188 }
191 var filename = tokens[tokens.length - 1];
192 var result = filename.split(".")[0];
193 var temp = result.split("-");189 var temp = result.split("-");
194 if (temp.length > 1){190 if (temp.length > 1){
195 result = temp[0];191 result = temp[0];
196192
=== modified file 'src/settings-manager.vala'
--- src/settings-manager.vala 2010-12-15 16:23:15 +0000
+++ src/settings-manager.vala 2010-12-23 19:37:21 +0000
@@ -27,7 +27,7 @@
27 }27 }
28 construct{28 construct{
29 this.settings = new Settings ("com.canonical.indicators.sound");29 this.settings = new Settings ("com.canonical.indicators.sound");
30 settings.changed["blacklisted-media-players"].connect (on_blacklist_event); 30 this.settings.changed["blacklisted-media-players"].connect (on_blacklist_event);
31 }31 }
32 32
33 public string[] fetch_blacklist()33 public string[] fetch_blacklist()
@@ -40,12 +40,21 @@
40 return this.settings.get_strv ("interested-media-players");40 return this.settings.get_strv ("interested-media-players");
41 }41 }
4242
43 public bool add_interested(string app_desktop_name)43 public void clear_list()
44 {44 {
45 string[] already_interested = fetch_interested();45 this.settings.reset("interested-media-players");
46 }
47
48 public void add_interested(string app_desktop_name)
49 {
50 var already_interested = fetch_interested();
51 foreach ( var s in already_interested){
52 if ( s == app_desktop_name ) return;
53 }
46 already_interested += (app_desktop_name);54 already_interested += (app_desktop_name);
47 return this.settings.set_strv( "interested-media-players",55 this.settings.set_strv( "interested-media-players",
48 already_interested );56 already_interested );
57 this.settings.apply();
49 }58 }
5059
51 private void on_blacklist_event()60 private void on_blacklist_event()

Subscribers

People subscribed via source and target branches