[Slim-Checkins] r10039 - in /trunk/server: Plugins/Live365/Plugin.pm Slim/Buttons/Common.pm

kdf at svn.slimdevices.com kdf at svn.slimdevices.com
Mon Sep 25 19:37:59 PDT 2006


Author: kdf
Date: Mon Sep 25 19:37:57 2006
New Revision: 10039

URL: http://svn.slimdevices.com?rev=10039&view=rev
Log:
Bug: 4167, 4205
Description: 
	- Sort sleep options so that sleep at end of current song fits on chronological order (skipping to next value requires the next value to be able to be larger)

	- Support press-and-hold favourites to add items from TrackInfo, RemoteTrackInfo, Live365, OPML/XML Browsing (item level only, not category level), Mixer lists, current playlist. uPNP browsing, and browsetree.  Contains some hacks to make it all work right now. Ideally all listing should be lists of objects with url and title elements when it can be supported as a favourite. Currently,with all hacks in place, anything that doesn't resolve to a url and title will NOT be added.


Modified:
    trunk/server/Plugins/Live365/Plugin.pm
    trunk/server/Slim/Buttons/Common.pm

Modified: trunk/server/Plugins/Live365/Plugin.pm
URL: http://svn.slimdevices.com/trunk/server/Plugins/Live365/Plugin.pm?rev=10039&r1=10038&r2=10039&view=diff
==============================================================================
--- trunk/server/Plugins/Live365/Plugin.pm (original)
+++ trunk/server/Plugins/Live365/Plugin.pm Mon Sep 25 19:37:57 2006
@@ -893,6 +893,16 @@
 	return (\%pages, undef);
 }
 
+sub getLive365 {
+	my $client = shift;
+	
+	if ( defined $live365->{$client} ) {
+		return $live365->{$client};
+	} else {
+		return undef;
+	}
+}
+
 sub initPlugin {
 	$::d_plugins && msg("Live365: initPlugin()\n");
 

Modified: trunk/server/Slim/Buttons/Common.pm
URL: http://svn.slimdevices.com/trunk/server/Slim/Buttons/Common.pm?rev=10039&r1=10038&r2=10039&view=diff
==============================================================================
--- trunk/server/Slim/Buttons/Common.pm (original)
+++ trunk/server/Slim/Buttons/Common.pm Mon Sep 25 19:37:57 2006
@@ -732,33 +732,91 @@
 
 		if (defined $buttonarg && $buttonarg eq "add") {
 
+			# First lets try for a listRef from INPUT.*
 			my $list = $client->modeParam('listRef');
-
+			my $obj;
+			my $title;
+			my $url;
+			
+			# If there is a list, try grabbing the current index.
 			if ($list) {
 			
-				my $obj = $list->[$client->modeParam('listIndex')];
+				$obj = $list->[$client->modeParam('listIndex')];
+			
+			# hack to grab currently browsed item from current playlist (needs to use INPUT.List at some point)
+			} elsif (mode($client) eq 'playlist') {
+			
+				$obj = Slim::Player::Playlist::song($client, Slim::Buttons::Playlist::browseplaylistindex($client));
+			}
+			
+			# if that doesn't work, perhaps we have a track param from something like trackinfo
+			if (!blessed($obj) && $client->modeParam('track')) {
+			
+				$obj = $client->modeParam('track');
+			
+			# specific HACK for Live365
+			} elsif(Slim::Player::ProtocolHandlers->handlerForURL('live365://') && (Plugins::Live365::Plugin::getLive365($client))) {
+
+				my $live365 = Plugins::Live365::Plugin::getLive365($client);
+				my $station = $live365->getCurrentStation();
+				
+				$title = $station->{STATION_TITLE};
+				$url   = $station->{STATION_ADDRESS};
+				
+				# fix url to activate protocol handler
+				$url =~ s/http\:/live365\:/;
+			}
+			
+			# start with the object if we have one
+			if ($obj && !$url) {
 				
 				if (blessed($obj) && $obj->can('url')) {
-
-					my $title;
-
-					if ($obj->can('name')) {
-						$title = $obj->name;
+					$url = $obj->url;
+				
+				# xml browser uses hash lists with url and name values.
+				} elsif (ref($obj) eq 'HASH') {
+					
+					$url = $obj->{'url'};
+				}
+				
+				if (blessed($obj) && $obj->can('name')) {
+
+					$title = $obj->name;
+				}elsif (ref($obj) eq 'HASH') {
+
+					$title = $obj->{'name'} || $obj->{'title'};
+				} else {
+					
+					# failing specified name values, try the db title
+					$title = Slim::Music::Info::standardTitle($client, $obj);
+				}
+			} 
+			
+			# remoteTrackInfo uses url and title params for lists.
+			if ($client->modeParam('url') && !$url) {
+				
+				$url   = $client->modeParam('url');
+				$title = $client->modeParam('title');
+			}
+
+			if ($url && $title) {
+				Slim::Utils::Favorites->clientAdd($client, $url, $title);
+				$client->showBriefly($client->string('FAVORITES_ADDING'), $title);
+			
+			# if all of that fails, send the debug with a best guess helper for tracing back
+			} else {
+
+				if ($::d_favorites) { 
+					msg("Favorites: no valid url found, not adding favorite\n");
+					
+					if ($obj) {
+						msg(Data::Dumper::Dumper($obj));
+					
 					} else {
-						$title = Slim::Music::Info::standardTitle($client, $obj);
+						Slim::Utils::Misc::bt();
 					}
-	
-					if ($title) {
-						Slim::Utils::Favorites->clientAdd($client, $obj, $title);
-						$client->showBriefly($client->string('FAVORITES_ADDING'), $title);
-					}
-
-				} else {
-
-					$::d_favorites && msg("list item is not an object, not adding favorite\n");
-					$::d_favorites && msg(Data::Dumper::Dumper($obj));
 				}
-			}			
+			}
 
 		} elsif (mode($client) ne 'FAVORITES') {
 
@@ -874,7 +932,7 @@
 		}
 
 		# add the 'after this song' option only if there is a defined value.
-		my @sleepChoices = $remaining ? (0, $remaining, 15,30,45,60,90) : (0,15,30,45,60,90);
+		my @sleepChoices = $remaining ? sort(0, $remaining, 15,30,45,60,90) : (0,15,30,45,60,90);
 		my $i = 0;
 
 		# find the next value for the sleep timer



More information about the checkins mailing list