aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConor Curran <conor.curran@canonical.com>2010-10-07 14:29:19 +0100
committerConor Curran <conor.curran@canonical.com>2010-10-07 14:29:19 +0100
commit6dbff525c98d2871da60432dd4bb6b8d9eff26bd (patch)
tree0f0651aa2ef46f5325c5abf949e2c9a01d717035
parent6a2214ba0ab2dad2963f94f65639845eb35fafaa (diff)
parentd966a9ff70a81fae4508fed79ce207424df652f1 (diff)
downloadayatana-indicator-sound-6dbff525c98d2871da60432dd4bb6b8d9eff26bd.tar.gz
ayatana-indicator-sound-6dbff525c98d2871da60432dd4bb6b8d9eff26bd.tar.bz2
ayatana-indicator-sound-6dbff525c98d2871da60432dd4bb6b8d9eff26bd.zip
fix for translation title bug
-rw-r--r--src/mpris2-controller.vala5
-rw-r--r--src/music-player-bridge.vala157
-rw-r--r--src/player-controller.vala4
3 files changed, 72 insertions, 94 deletions
diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala
index 54e1868..29dd4cf 100644
--- a/src/mpris2-controller.vala
+++ b/src/mpris2-controller.vala
@@ -135,10 +135,7 @@ public class Mpris2Controller : GLib.Object
return changed_updates;
}
- private TransportMenuitem.state determine_play_state(string status){
- if(status == null)
- return TransportMenuitem.state.PAUSED;
-
+ private TransportMenuitem.state determine_play_state(string status){
if(status != null && status == "Playing"){
return TransportMenuitem.state.PLAYING;
}
diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala
index 61dfa2e..9ba4ef6 100644
--- a/src/music-player-bridge.vala
+++ b/src/music-player-bridge.vala
@@ -35,12 +35,8 @@ public class MusicPlayerBridge : GLib.Object
playersDB = new FamiliarPlayersDB();
registered_clients = new HashMap<string, PlayerController> ();
listener = Listener.ref_default();
- listener.indicator_added += on_indicator_added;
- listener.indicator_removed.connect(on_indicator_removed);
- listener.indicator_modified.connect(on_indicator_modified);
listener.server_added.connect(on_server_added);
listener.server_removed.connect(on_server_removed);
- listener.server_count_changed.connect(on_server_count_changed);
}
private void try_to_add_inactive_familiar_clients(){
@@ -53,13 +49,13 @@ public class MusicPlayerBridge : GLib.Object
debug("attempting to make an app info from %s", app);
DesktopAppInfo info = new DesktopAppInfo.from_filename(app);
- if(info == null){
+
+ if(info == null){
warning("Could not create a desktopappinfo instance from app: %s", app);
continue;
}
+
GLib.AppInfo app_info = info as GLib.AppInfo;
- // TODO refactor to remove need for further name refactoring in the player controller
- // truncate should not do a down() on the name
PlayerController ctrl = new PlayerController(this.root_menu,
truncate_player_name(app_info.get_name()),
calculate_menu_position(),
@@ -67,24 +63,10 @@ public class MusicPlayerBridge : GLib.Object
ctrl.app_info = app_info;
if(ctrl.app_info == null)
warning("for some reason the app info is null");
-
- this.registered_clients.set(truncate_player_name(app_info.get_name()), ctrl);
+ this.registered_clients.set(determine_key(app), ctrl);
}
}
-
- private static string truncate_player_name(string app_info_name)
- {
- string result = app_info_name.down().strip();
-
- var tokens = result.split(" ");
-
- if(tokens.length > 1){
- result = tokens[0];
- }
- debug("truncate player name %s", result);
- return result;
- }
-
+
private int calculate_menu_position()
{
if(this.registered_clients.size == 0){
@@ -99,42 +81,52 @@ public class MusicPlayerBridge : GLib.Object
{
debug("MusicPlayerBridge -> on_server_added with value %s", type);
if(server_is_not_of_interest(type)) return;
- string client_name = type.split(".")[1];
- if (root_menu != null && client_name != null){
- // If we have an instance already for this player, ensure it is switched to active
- if(this.registered_clients.keys.contains(client_name)){
- debug("It figured out that it already has an instance for this player already");
- this.registered_clients[client_name].update_state(PlayerController.state.READY);
- this.registered_clients[client_name].activate();
- }
- else{
- //else init a new one
- PlayerController ctrl = new PlayerController(root_menu,
- client_name,
- calculate_menu_position(),
- PlayerController.state.READY);
- registered_clients.set(client_name, ctrl);
- debug("New Client of name %s has successfully registered with us", client_name);
- }
- // irregardless check that it has a desktop file if not kick off a request for it
- if(this.registered_clients[client_name].app_info == null){
- listener_get_server_property_cb cb = (listener_get_server_property_cb)desktop_info_callback;
- this.listener.server_get_desktop(object, cb, this);
- }
+ if ( this.root_menu != null ){
+ listener_get_server_property_cb cb = (listener_get_server_property_cb)desktop_info_callback;
+ this.listener.server_get_desktop(object, cb, this);
}
}
+ private void desktop_info_callback ( Indicate.ListenerServer server,
+ owned string path,
+ void* data )
+ {
+ MusicPlayerBridge bridge = data as MusicPlayerBridge;
+ AppInfo? app_info = create_app_info(path);
+ var name = truncate_player_name(app_info.get_name());
+ if(path.contains("/") && bridge.playersDB.already_familiar(path) == false){
+ debug("About to store desktop file path: %s", path);
+ bridge.playersDB.insert(path);
+ PlayerController ctrl = new PlayerController(bridge.root_menu,
+ name,
+ bridge.calculate_menu_position(),
+ PlayerController.state.READY);
+ ctrl.set("app_info", app_info);
+ bridge.registered_clients.set(determine_key(path), ctrl);
+ debug("successfully created appinfo and instance from path and set it on the respective instance");
+ }
+ else{
+ var key = determine_key(path);
+ bridge.registered_clients[key].update_state(PlayerController.state.READY);
+ bridge.registered_clients[key].activate();
+ debug("Ignoring desktop file path callback because the db cache file has it already: %s", path);
+ }
+ }
+
public void on_server_removed(Indicate.ListenerServer object, string type)
{
debug("MusicPlayerBridge -> on_server_removed with value %s", type);
if(server_is_not_of_interest(type)) return;
- string client_name = type.split(".")[1];
- if (root_menu != null && client_name != null){
- registered_clients[client_name].hibernate();
- debug("Successively offlined client %s", client_name);
+ if (root_menu != null){
+ var tmp = type.split(".");
+ debug("attempt to remove %s", tmp[tmp.length-1]);
+ if(tmp.length > 0){
+ registered_clients[tmp[tmp.length - 1]].hibernate();
+ debug("Successively offlined client %s", tmp[tmp.length - 1]);
+ }
}
}
-
+
private bool server_is_not_of_interest(string type){
if (type == null) return true;
if (type.contains("music") == false) {
@@ -144,50 +136,12 @@ public class MusicPlayerBridge : GLib.Object
return false;
}
- private void desktop_info_callback(Indicate.ListenerServer server,
- owned string path, void* data)
- {
- MusicPlayerBridge bridge = data as MusicPlayerBridge;
- if(path.contains("/") && bridge.playersDB.already_familiar(path) == false){
- debug("About to store desktop file path: %s", path);
- bridge.playersDB.insert(path);
- AppInfo? app_info = create_app_info(path);
- if(app_info != null){
- PlayerController ctrl = bridge.registered_clients[app_info.get_name().down().strip()];
- ctrl.set("app_info", app_info);
- debug("successfully created appinfo from path and set it on the respective instance");
- }
- }
- else{
- debug("Ignoring desktop file path because its either invalid of the db cache file has it already: %s", path);
- }
- }
-
public void set_root_menu_item(Dbusmenu.Menuitem menu)
{
this.root_menu = menu;
try_to_add_inactive_familiar_clients();
}
- public void on_server_count_changed(Indicate.ListenerServer object, uint i)
- {
- debug("MusicPlayerBridge-> on_server_count_changed with value %u", i);
- }
- public void on_indicator_added(ListenerServer object, ListenerIndicator p0)
- {
- debug("MusicPlayerBridge-> on_indicator_added");
- }
-
- public void on_indicator_removed(Indicate.ListenerServer object, Indicate.ListenerIndicator p0)
- {
- debug("MusicPlayerBridge -> on_indicator_removed");
- }
-
- public void on_indicator_modified(Indicate.ListenerServer object, Indicate.ListenerIndicator p0, string s)
- {
- debug("MusicPlayerBridge -> indicator_modified with vale %s", s );
- }
-
public static AppInfo? create_app_info(string path)
{
DesktopAppInfo info = new DesktopAppInfo.from_filename(path);
@@ -199,6 +153,33 @@ public class MusicPlayerBridge : GLib.Object
return app_info;
}
+ private static string truncate_player_name(owned string app_info_name)
+ {
+ string result = app_info_name.down().strip();
+
+ var tokens = result.split(" ");
+
+ if(tokens.length > 1){
+ result = tokens[0];
+ }
+ debug("truncate player name %s", result);
+ return result;
+ }
+
+ private static string? determine_key(owned string path)
+ {
+ var tokens = path.split("/");
+ if ( tokens.length < 2) return null;
+ var filename = tokens[tokens.length - 1];
+ var result = filename.split(".")[0];
+ var temp = result.split("-");
+ if (temp.length > 1){
+ result = temp[0];
+ }
+ debug("determine key result = %s", result);
+ return result;
+ }
+
}
diff --git a/src/player-controller.vala b/src/player-controller.vala
index f5ec205..d5b79e7 100644
--- a/src/player-controller.vala
+++ b/src/player-controller.vala
@@ -160,8 +160,8 @@ public class PlayerController : GLib.Object
private static string format_client_name(string client_name)
{
string formatted = client_name;
- if(formatted.len() > 1){
- formatted = client_name.up(1).concat(client_name.slice(1, client_name.len()));
+ if(formatted.length > 1){
+ formatted = client_name.up(1).concat(client_name.slice(1, client_name.length));
debug("PlayerController->format_client_name - : %s", formatted);
}
return formatted;