← Back to team overview

ayatana-commits team mailing list archive

[Merge] lp:~cjcurran/indicator-sound/mprisv2 into lp:indicator-sound

 

Conor Curran has proposed merging lp:~cjcurran/indicator-sound/mprisv2 into lp:indicator-sound.

Requested reviews:
  Indicator Applet Developers (indicator-applet-developers)


Tidies arturl parsing so as it can handle URI's and file paths seemlessly.
Fixes the positioning of each dbusmenuitem in the correct place in relation to the other related items
MPRIS previous and next methods fixed (wrong method name doh!)

And some refactoring, alot more of that to come


-- 
https://code.launchpad.net/~cjcurran/indicator-sound/mprisv2/+merge/29583
Your team ayatana-commits is subscribed to branch lp:indicator-sound.
=== modified file 'src/indicator-sound.c'
--- src/indicator-sound.c	2010-07-08 15:12:59 +0000
+++ src/indicator-sound.c	2010-07-09 16:24:46 +0000
@@ -366,10 +366,10 @@
   title = title_widget_new (newitem);
   GtkMenuItem *menu_title_widget = GTK_MENU_ITEM(title);
 
-  dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, menu_title_widget, parent);
-
   gtk_widget_show_all(title);
 
+	dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, menu_title_widget, parent);
+
   return TRUE;
 }
 

=== modified file 'src/mpris-controller-v2.vala'
--- src/mpris-controller-v2.vala	2010-06-16 17:19:35 +0000
+++ src/mpris-controller-v2.vala	2010-07-09 16:24:46 +0000
@@ -21,8 +21,8 @@
 
 public class MprisControllerV2 : MprisController
 {		
-	public MprisControllerV2(string name, PlayerController controller){
-		base(name, controller, "org.mpris.MediaPlayer.Player");
+	public MprisControllerV2(PlayerController ctrl, string inter="org.mpris.MediaPlayer.Player"){
+		Object(owner: ctrl, mpris_interface: inter);				
 	}
 
 }

=== modified file 'src/mpris-controller.vala'
--- src/mpris-controller.vala	2010-07-08 16:47:28 +0000
+++ src/mpris-controller.vala	2010-07-09 16:24:46 +0000
@@ -22,32 +22,42 @@
 
 public class MprisController : GLib.Object
 {
-  private DBus.Connection connection;
-  public dynamic DBus.Object mpris_player;
-	private PlayerController controller;
-  struct status {
+	private DBus.Connection connection;
+	public dynamic DBus.Object mpris_player{get; construct;}	
+	public PlayerController owner {get; construct;}	
+	public string mpris_interface {get; construct;}
+	private string name;
+
+	
+	struct status {
     public int32 playback;
     //public int32 shuffle; // Not used just yet
     //public int32 repeat;
     //public int32 endless;
   }
 		
-	public MprisController(string name, PlayerController controller, string mpris_interface="org.freedesktop.MediaPlayer"){
+	public MprisController(PlayerController ctrl, string inter="org.freedesktop.MediaPlayer"){
+		Object(owner: ctrl, mpris_interface: inter);		
+	}
+
+	construct{
     try {
       this.connection = DBus.Bus.get (DBus.BusType.SESSION);
     } catch (Error e) {
       error("Problems connecting to the session bus - %s", e.message);
     }		
-		this.controller = controller;
-		this.mpris_player = this.connection.get_object ("org.mpris.".concat(name.down()) , "/Player", mpris_interface);				
-    this.mpris_player.TrackChange += onTrackChange;	
+		this.mpris_player = this.connection.get_object ("org.mpris.".concat(this.owner.name.down()) , "/Player", this.mpris_interface);				
+
+		debug("just attempting to establish an mpris connection to %s, %s, %s", "org.mpris.".concat(this.owner.name.down()) , "/Player", this.mpris_interface); 
+
+		this.mpris_player.TrackChange += onTrackChange;	
     this.mpris_player.StatusChange += onStatusChange;	
 
 		status st = this.mpris_player.GetStatus();
 		int play_state =  st.playback;
 		debug("GetStatusChange - play state %i", play_state);
-		(this.controller.custom_items[this.controller.TRANSPORT] as TransportMenuitem).change_play_state(play_state);
-		this.controller.custom_items[this.controller.METADATA].update(this.mpris_player.GetMetadata(),
+		(this.owner.custom_items[this.owner.TRANSPORT] as TransportMenuitem).change_play_state(play_state);
+		this.owner.custom_items[this.owner.METADATA].update(this.mpris_player.GetMetadata(),
 		                            MetadataMenuitem.attributes_format());
 		
 	}
@@ -56,8 +66,8 @@
 	private void onTrackChange(dynamic DBus.Object mpris_client, HashTable<string,Value?> ht)
 	{
 		debug("onTrackChange");
-		this.controller.custom_items[this.controller.METADATA].reset(MetadataMenuitem.attributes_format());
-		this.controller.custom_items[this.controller.METADATA].update(ht,
+		this.owner.custom_items[this.owner.METADATA].reset(MetadataMenuitem.attributes_format());
+		this.owner.custom_items[this.owner.METADATA].update(ht,
 		                            MetadataMenuitem.attributes_format());
 	}
 
@@ -84,10 +94,10 @@
 			}
 		}
 		else if(command == TransportMenuitem.action.PREVIOUS){
-			this.mpris_player.previous();
+			this.mpris_player.Prev();
 		}
 		else if(command == TransportMenuitem.action.NEXT){
-			this.mpris_player.next();
+			this.mpris_player.Next();
 		}
 	}
 
@@ -107,7 +117,7 @@
 		Value v = Value(typeof(int));
 		v.set_int(play_state);
 		ht.insert("state", v); 
-		this.controller.custom_items[this.controller.TRANSPORT].update(ht, TransportMenuitem.attributes_format());
+		this.owner.custom_items[this.owner.TRANSPORT].update(ht, TransportMenuitem.attributes_format());
 	}
 
 	

=== modified file 'src/music-player-bridge.vala'
--- src/music-player-bridge.vala	2010-07-08 16:47:28 +0000
+++ src/music-player-bridge.vala	2010-07-09 16:24:46 +0000
@@ -52,28 +52,34 @@
 					warning("App string in keyfile is null therefore moving on to next player");
 					continue;
 				}
-				try{
-					DesktopAppInfo info = new DesktopAppInfo.from_filename(app); 
-					if(info == null){
-						warning("Could not create a desktopappinfo instance from app: %s", app);
-						continue;					
-					}
-					GLib.AppInfo app_info = info as GLib.AppInfo;
-					PlayerController ctrl = new PlayerController(this.root_menu, 
-					                                             app_info.get_name(), 
-					                                             PlayerController.state.OFFLINE);
-					ctrl.set("app_info", app_info);
-					this.registered_clients.set(app_info.get_name().down().strip(), ctrl);					
-					debug("Created a player controller for %s which was found in the cache file", app_info.get_name().down().strip());
-					count += 1;					
-				}
-				catch(Error er){
-					warning("desktop path in cache is not formatted as we have anticipated");
-				}
+				DesktopAppInfo info = new DesktopAppInfo.from_filename(app); 
+				if(info == null){
+					warning("Could not create a desktopappinfo instance from app: %s", app);
+					continue;					
+				}
+				GLib.AppInfo app_info = info as GLib.AppInfo;
+				PlayerController ctrl = new PlayerController(this.root_menu, 
+				                                             app_info.get_name(),
+				                                             calculate_menu_position(),
+				                                             PlayerController.state.OFFLINE);
+				ctrl.set("app_info", app_info);
+				this.registered_clients.set(app_info.get_name().down().strip(), ctrl);					
+				debug("Created a player controller for %s which was found in the cache file", app_info.get_name().down().strip());
+				count += 1;					
 			}
 			break;
 		}
 	}
+
+	private int calculate_menu_position()
+	{
+		if(this.registered_clients.size == 0){
+			return 2;
+		}
+		else{
+			return (2 + (this.registered_clients.size * 4));
+		}
+	}
 	
 	public void on_server_added(Indicate.ListenerServer object, string type)
   {
@@ -89,8 +95,13 @@
 			}
 			//else init a new one
 			else{			
-				PlayerController ctrl = new PlayerController(root_menu, client_name, PlayerController.state.READY);
+				
+				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

=== modified file 'src/player-controller.vala'
--- src/player-controller.vala	2010-07-08 16:47:28 +0000
+++ src/player-controller.vala	2010-07-09 16:24:46 +0000
@@ -42,13 +42,16 @@
 	public ArrayList<PlayerItem> custom_items;	
 	public MprisController mpris_adaptor;
 	public AppInfo? app_info { get; set;}
+	public int menu_offset { get; set;}
 		
-	public PlayerController(Dbusmenu.Menuitem root, string client_name, state initial_state)
+	public PlayerController(Dbusmenu.Menuitem root, string client_name, int offset, state initial_state)
 	{
 		this.root_menu = root;
 		this.name = format_client_name(client_name.strip());
 		this.custom_items = new ArrayList<PlayerItem>();
 		this.update_state(initial_state);
+		this.menu_offset = offset;
+		debug("offset = %i", offset);
 		construct_widgets();
 		establish_mpris_connection();
 		update_layout();
@@ -89,13 +92,17 @@
 			debug("establish_mpris_connection - Not ready to connect");
 			return;
 		}
+
 		if(this.name == "Vlc"){
-			this.mpris_adaptor = new MprisControllerV2(this.name, this);
+			debug("establishing a vlc mpris controller");
+			this.mpris_adaptor = new MprisController(this, "org.mpris.MediaPlayer.Player");
 		}
 		else{
-			this.mpris_adaptor = new MprisController(this.name, this);
+			this.mpris_adaptor = new MprisController(this);
 		}
+		
 		if(this.mpris_adaptor.connected() == true){
+			debug("yup I'm connected");
 			this.update_state(state.CONNECTED);
 		}
 		else{
@@ -120,6 +127,10 @@
 		debug("about the set the visibility on both the transport and metadata widget to %s", visibility.to_string());
 		this.custom_items[TRANSPORT].property_set_bool(MENUITEM_PROP_VISIBLE, visibility);
 		this.custom_items[METADATA].property_set_bool(MENUITEM_PROP_VISIBLE, visibility);
+		// DEBUG
+		if(this.mpris_adaptor == null){
+			warning("Why is the mpris object null");
+		}
 	}
 	
 	
@@ -140,9 +151,8 @@
 		TransportMenuitem transport_item = new TransportMenuitem(this);
 		this.custom_items.add(transport_item);
 
-		int offset = 2;
 		foreach(PlayerItem item in this.custom_items){
-			root_menu.child_add_position(item, offset + this.custom_items.index_of(item));			
+			root_menu.child_add_position(item, this.menu_offset + this.custom_items.index_of(item));			
 		}
 	}	
 	

=== modified file 'src/player-item.vala'
--- src/player-item.vala	2010-07-07 12:22:18 +0000
+++ src/player-item.vala	2010-07-09 16:24:46 +0000
@@ -55,8 +55,17 @@
 			Value? v = data.lookup(search_key);
 			
 			if (v.holds (typeof (string))){
-				debug("with value : %s", v.get_string());
-				this.property_set(property, this.sanitize_string(v.get_string()));
+				string update = v.get_string().strip();
+				debug("with value : %s", update);
+				if(property.contains("arturl")){
+					try{
+						update = Filename.from_uri(update.strip());
+					}
+					catch(ConvertError e){
+						warning("Problem converting URI %s to file path", update); 
+					}
+				}
+				this.property_set(property, update);
 			}			    
 			else if (v.holds (typeof (int))){
 				debug("with value : %i", v.get_int());
@@ -80,15 +89,5 @@
 		return true;		
 	}
 
-	public static string sanitize_string(string st)
-	{
-		string result = st.strip();
-		if(result.has_prefix("file:///")){
-			result = result.slice(7, result.len());		                   
-		}
-		debug("Sanitize string - result = %s", result);
-		return result;
-	}
-
 }
 

=== modified file 'src/transport-menu-item.vala'
--- src/transport-menu-item.vala	2010-07-08 16:47:28 +0000
+++ src/transport-menu-item.vala	2010-07-09 16:24:46 +0000
@@ -44,6 +44,7 @@
 		int input = input_value.get_int();
 		debug("handle_event with value %s", input.to_string());
 		// Fire and forgot - the widget would not have sent it over it didn't think it was relevant.
+		debug("transport owner name = %s", this.owner.name);
 		this.owner.mpris_adaptor.transport_event((action)input);
 	}	
 


Follow ups