[Slim-Checkins] r12194 - in /trunk/server: ./ Slim/Networking/ Slim/Networking/SliMP3/ Slim/Player/ Slim/Plugin/MusicMagic/ Slim/Utils/

adrian at svn.slimdevices.com adrian at svn.slimdevices.com
Sat Jun 2 04:33:53 PDT 2007


Author: adrian
Date: Sat Jun  2 04:33:53 2007
New Revision: 12194

URL: http://svn.slimdevices.com?rev=12194&view=rev
Log:
Bug: N/A
Description: remove old prefs code - all preferences now handled by
object based preferences

Modified:
    trunk/server/Slim/Networking/SliMP3/Protocol.pm
    trunk/server/Slim/Networking/UDP.pm
    trunk/server/Slim/Player/Client.pm
    trunk/server/Slim/Player/Player.pm
    trunk/server/Slim/Player/Transporter.pm
    trunk/server/Slim/Plugin/MusicMagic/Importer.pm
    trunk/server/Slim/Plugin/MusicMagic/Plugin.pm
    trunk/server/Slim/Utils/Prefs.pm
    trunk/server/scanner.pl
    trunk/server/slimserver.pl

Modified: trunk/server/Slim/Networking/SliMP3/Protocol.pm
URL: http://svn.slimdevices.com/trunk/server/Slim/Networking/SliMP3/Protocol.pm?rev=12194&r1=12193&r2=12194&view=diff
==============================================================================
--- trunk/server/Slim/Networking/SliMP3/Protocol.pm (original)
+++ trunk/server/Slim/Networking/SliMP3/Protocol.pm Sat Jun  2 04:33:53 2007
@@ -18,8 +18,11 @@
 use Slim::Utils::Log;
 use Slim::Utils::Misc;
 use Slim::Utils::Network;
+use Slim::Utils::Prefs;
 
 my $log = logger('network.protocol.slimp3');
+
+my $prefs = preferences('server');
 
 sub processMessage {
 	my ($client, $msg) = @_;
@@ -101,6 +104,14 @@
 			$client->macaddress($mac);
 			$client->init;
 
+			# remember all slimp3 clients so we can say hello to them on next server startup
+			my %slimp3s = map { $_ => 1 } @{ $prefs->get('slimp3clients') };
+
+			if (!$slimp3{$id}) {
+				$slimp3{$id} = 1;
+				$prefs->set('slimp3clients', [ keys %slimp3 ]);
+			}
+
 		} else {
 
 			Slim::Networking::Discovery::sayHello($sock, $clientpaddr);

Modified: trunk/server/Slim/Networking/UDP.pm
URL: http://svn.slimdevices.com/trunk/server/Slim/Networking/UDP.pm?rev=12194&r1=12193&r2=12194&view=diff
==============================================================================
--- trunk/server/Slim/Networking/UDP.pm (original)
+++ trunk/server/Slim/Networking/UDP.pm Sat Jun  2 04:33:53 2007
@@ -48,7 +48,7 @@
 	Slim::Networking::Select::addRead($udpsock, \&readUDP);
 
 	# say hello to the old slimp3 clients that we might remember...
-	for my $clientID (Slim::Utils::Prefs::getKeys('clients')) {
+	for my $clientID (@{ preferences('server')->get('slimp3clients') || [] }) {
 
 		# make sure any new preferences get set to default values
 		assert($clientID);

Modified: trunk/server/Slim/Player/Client.pm
URL: http://svn.slimdevices.com/trunk/server/Slim/Player/Client.pm?rev=12194&r1=12193&r2=12194&view=diff
==============================================================================
--- trunk/server/Slim/Player/Client.pm (original)
+++ trunk/server/Slim/Player/Client.pm Sat Jun  2 04:33:53 2007
@@ -80,11 +80,11 @@
 	assert(!defined(getClient($id)));
 
 	# The following indexes are unused:
-	# 2, 3, 8, 11, 12, 13, 16, 23, 24, 25, 26, 27, 33, 34, 53
+	# 1, 2, 3, 8, 11, 12, 13, 16, 23, 24, 25, 26, 27, 33, 34, 53
 	# 64, 65, 66, 67, 68, 72,
 
 	$client->[0] = $id;
-	$client->[1] = Slim::Utils::Prefs::getClientPrefs($id); # _prefs
+#	$client->[1]
 
 #	$client->[2]
 #	$client->[3]
@@ -234,7 +234,6 @@
 	my $client = shift;
 
 	# make sure any preferences unique to this client may not have set are set to the default
-
 	$prefs->client($client)->init($defaultPrefs);
 
 	# init display including setting any display specific preferences to default
@@ -886,201 +885,6 @@
 	return $client->modeStack(-1);
 }
 
-sub paramOrPref {
-	my $client = shift;
-	my $name   = shift;
-
-	my $mode   = $client->modeParameterStack(-1) || return undef;
-
-	if (defined $mode && defined $mode->{$name}) {
-		return $mode->{$name};
-	}
-
-	return $prefs->client($client)->get($name);
-}
-	
-sub getPref {
-	prefGet(@_);
-}
-
-sub setPref {
-	prefSet(@_);
-}
-
-# method for getting/setting prefs
-# for non-indexed prefs the first parameter should be the pref name
-# for indexed prefs the first parameter should be a two element array reference
-# with the pref name first and the index second
-sub pref {
-	my $client = shift;
-	my $pref = shift;
-	my $value = shift;
-
-	my $ind = undef;
-
-	return undef unless defined $pref;
-
-	if (ref($pref) eq "ARRAY") {
-		($pref,$ind) = @$pref;
-	}
-
-	if (defined $value) {
-		return $client->prefSet($pref,$value,$ind);
-	} else {
-		return $client->prefGet($pref,$ind);
-	}
-}
-
-sub prefGet {
-	my $client = shift;
-	my $pref = shift;
-	my $ind = shift;
-
-	if (defined $ind) {
-		$client->prefGetInd($pref,$ind);
-	} else {
-		return $client->_prefs()->{$pref};
-	}
-}
-
-sub prefGetInd {
-	my $client = shift;
-	my $pref = shift;
-	my $index = shift;
-
-	my $prefs = $client->_prefs();
-
-	if (defined $prefs->{$pref}) {
-		if (ref $prefs->{$pref} eq 'ARRAY') {
-			return $prefs->{$pref}[$index];
-		} elsif (ref $prefs->{$pref} eq 'HASH') {
-			return $prefs->{$pref}{$index};
-		}
-	}
-	return undef;
-}
-
-sub prefGetArray {
-	my $client = shift;
-	my $arrayPref = shift;
-	
-	my $prefs = $client->_prefs();
-
-	if (defined($prefs->{$arrayPref}) && ref($prefs->{$arrayPref}) eq 'ARRAY') {
-		return @{$prefs->{$arrayPref}};
-	} else {
-		return ();
-	}
-}
-
-sub prefGetArrayMax{
-	my $client = shift;
-	my $arrayPref = shift;
-	
-	my $prefs = $client->_prefs();
-	
-	if (defined($prefs->{$arrayPref}) && ref($prefs->{$arrayPref}) eq 'ARRAY') {
-		my @prefArray = @{$prefs->{$arrayPref}};
-		my $max = $#prefArray;
-		return $max;
-	} else {
-		return undef;
-	}
-}
-
-sub prefGetHash {
-	my $client = shift;
-	my $hashPref = shift;
-	
-	my $prefs = $client->_prefs();
-
-	if (defined($prefs->{$hashPref}) && ref($prefs->{$hashPref}) eq 'HASH') {
-		return %{$prefs->{$hashPref}};
-	} else {
-		return ();
-	}
-}
-
-sub prefGetKeys {
-	my $client = shift;
-	my $hashPref = shift;
-	
-	my $prefs = $client->_prefs();
-
-	if (defined($prefs->{$hashPref}) && ref($prefs->{$hashPref}) eq 'HASH') {
-		return keys %{$prefs->{$hashPref}};
-	} else {
-		return ();
-	}
-}
-
-sub prefIsDefined {
-	my $client = shift;
-	my $key = shift;
-	my $ind = shift;
-	
-	my $prefs = $client->_prefs();
-	
-	if (defined($ind)) {
-		if (defined $prefs->{$key}) {
-			if (ref $prefs->{$key} eq 'ARRAY') {
-				return defined $prefs->{$key}[$ind];
-			} elsif (ref $prefs->{$key} eq 'HASH') {
-				return defined $prefs->{$key}{$ind};
-			}
-		}
-	}
-	return defined $prefs->{$key};
-}
-
-# using wrappers for methods which involve changing the preference
-# so that we don't have to worry about writing out the preferences
-
-=head2 prefSet( $client, $prefName, $value, $index )
-
-Sets the client preference to the specified value.
-
-See L<Slim::Utils::Prefs::set>
-
-=cut
-
-sub prefSet {
-	my $client = shift;
-	my $pref = shift;
-	my $value = shift;
-	my $ind = shift;
-	
-	return Slim::Utils::Prefs::set($pref,$value,$ind,$client,$client->_prefs());
-}
-
-=head2 prefPush( $client, $prefName, $value )
-
-Appends the value to the specified client array preference.
-
-=cut
-
-sub prefPush {
-	my $client = shift;
-	my $pref = shift;
-	my $value = shift;
-	
-	Slim::Utils::Prefs::push($pref,$value,$client->_prefs());
-}
-
-=head2 prefDelete( $client, $prefName, $index )
-
-Removes a client pref specified by the name and index.
-
-=cut
-
-sub prefDelete {
-	my $client = shift;
-	my $pref = shift;
-	my $ind = shift;
-	
-	Slim::Utils::Prefs::delete($pref,$ind,$client->_prefs());
-}
-
 =head2 masterOrSelf( $client )
 
 See L<Slim::Player::Sync> for more information.
@@ -1254,13 +1058,6 @@
 	@_ ? ($r->[0] = shift) : $r->[0];
 }
 
-# the _prefs method should not be used to access individual prefs
-# use the pref* methods for working with client prefs
-sub _prefs {
-	my $r = shift;
-	@_ ? ($r->[1] = shift) : $r->[1];
-}
-
 =head2 revision()
 
 Returns the firmware revision of the client.

Modified: trunk/server/Slim/Player/Player.pm
URL: http://svn.slimdevices.com/trunk/server/Slim/Player/Player.pm?rev=12194&r1=12193&r2=12194&view=diff
==============================================================================
--- trunk/server/Slim/Player/Player.pm (original)
+++ trunk/server/Slim/Player/Player.pm Sat Jun  2 04:33:53 2007
@@ -35,7 +35,6 @@
 	'digitalVolumeControl' => 1,
 	'preampVolumeControl'  => 0,
 	'disabledirsets'       => [],
-#	'doublesize'           => 0,
 	'irmap'                => \&Slim::Hardware::IR::defaultMapFile(),
 	'menuItem'             => [qw(
 		NOW_PLAYING
@@ -49,7 +48,6 @@
 		PLUGINS
 	)],
 	'mp3SilencePrelude'    => 0,
-#	'offDisplaySize'       => 0,
 	'pitch'                => 100,
 	'power'                => 1,
 	'powerOffBrightness'   => 1,
@@ -62,207 +60,11 @@
 	'syncPower'            => 0,
 	'syncVolume'           => 0,
 	'treble'               => 50,
-#	'upgrade-5.4b1-script' => 1,
-#	'upgrade-5.4b2-script' => 1,
-#	'upgrade-6.1b1-script' => 1,
-#	'upgrade-6.2-script'   => 1,
-#	'upgrade-R4627-script' => 1,
-#	'upgrade-R8775-script' => 1,
-#	'upgrade-R9279-script' => 1,
 	'volume'               => 50,
 	'syncBufferThreshold'  => 128,
 	'bufferThreshold'      => 255,
 	'powerOnResume'        => 'PauseOff-NoneOn',
 };
-
-our %upgradeScripts = (
-
-	# Allow the "upgrading" of old menu items to new ones.
-	'5.4b1' => sub {
-
-		my $client = shift;
-		my $index  = 0;
-
-		foreach my $menuItem ($client->prefGetArray('menuItem')) {
-
-			if ($menuItem eq 'ShoutcastBrowser') {
-				$client->prefSet('menuItem', 'RADIO', $index);
-				last;
-			}
-
-			$index++;
-		}
-	},
-
-	'5.4b2' => sub {
-		my $client = shift;
-
-		my $addedBrowse = 0;
-		my @newitems = ();
-
-		foreach my $menuItem ($client->prefGetArray('menuItem')) {
-
-			if ($menuItem =~ 'BROWSE_') {
-
-				if (!$addedBrowse) {
-					push @newitems, 'BROWSE_MUSIC';
-					$addedBrowse = 1;
-				}
-
-			} else {
-
-				push @newitems, $menuItem;
-			}
-		}
-
-		$client->prefSet('menuItem', \@newitems);
-	},
-
-	'6.1b1' => sub {
-		my $client = shift;
-
-		if (Slim::Buttons::SqueezeNetwork::clientIsCapable($client)) {
-			# append a menu item to connect to squeezenetwork to the home menu
-			$client->prefPush('menuItem', 'SQUEEZENETWORK_CONNECT');
-		}
-	},
-
-	'6.2' => sub {
-		my $client = shift;
-		#kill all alarm settings
-		my $alarm = $client->prefGet('alarm') || 0;
-		
-		if (ref $alarm ne 'ARRAY') {
-			my $alarmTime = $client->prefGet('alarmtime') || 0;
-			my $alarmplaylist = $client->prefGet('alarmplaylist') || '';
-			my $alarmvolume = $client->prefGet('alarmvolume') || 50;
-			$client->prefDelete('alarm');
-			$client->prefDelete('alarmtime');
-			$client->prefDelete('alarmplaylist');
-			$client->prefDelete('alarmvolume');
-			$client->prefSet('alarm',[$alarm,0,0,0,0,0,0,0]);
-			$client->prefSet('alarmtime',[$alarmTime,0,0,0,0,0,0,0]);
-			$client->prefSet('alarmplaylist',[$alarmplaylist,'','','','','','','']);
-			$client->prefSet('alarmvolume',[$alarmvolume,50,50,50,50,50,50,50]);
-		}
-	},
-
-	'R4627' => sub {
-		my $client = shift;
-		my $menuItem = $client->prefGet('menuItem') || 0;
-		
-		# Add RandomMix to home and clear unused prefs
-		if (ref $menuItem eq 'ARRAY') {
-
-			my $insertPos = undef;
-			my $randomMixFound = 0;
-
-			for (my $i = 0; $i < @$menuItem; $i++) {
-
-				if (@$menuItem[$i] eq 'RandomPlay::Plugin') {
-					$randomMixFound = 1;
-					last;
-				} elsif (@$menuItem[$i] eq 'SEARCH') {
-					$insertPos = $i + 1;
-				}
-			}
-
-			if (!$randomMixFound) {
-
-				if (defined $insertPos) {
-
-					# Insert random mix after SEARCH
-					splice(@$menuItem, $insertPos, 0, 'RandomPlay::Plugin');
-				} else {
-					push (@$menuItem, 'RandomPlay::Plugin');
-				}
-
-				$client->prefSet('menuItem', $menuItem);
-			}
-
-			# Clear old prefs
-			$client->prefDelete('plugin_random_exclude_genres');
-			Slim::Utils::Prefs::delete('plugin_random_remove_old_tracks');
-		}
-	},
-
-	'R8775' => sub {
-		my $client = shift;
-		my $menuItem = $client->prefGet('menuItem') || 0;
-
-		# Add Favorites to home
-		if (ref($menuItem) ne 'ARRAY') {
-			return;
-		}
-
-		my $insertPos = undef;
-
-		# Insert Favorites before SAVED_PLAYLISTS
-		for (my $i = 0; $i < @$menuItem; $i++) {
-
-			if (@$menuItem[$i] eq 'FAVORITES') {
-
-				return;
-
-			} elsif (@$menuItem[$i] eq 'SAVED_PLAYLISTS') {
-
-				$insertPos = $i;
-			}
-		}
-
-		if (defined $insertPos) {
-
-			splice(@$menuItem, $insertPos, 0, 'FAVORITES');
-
-		} else {
-
-			push (@$menuItem, 'FAVORITES');
-		}
-
-		$client->prefSet('menuItem', $menuItem);
-	},
-	
-	'R9279' => sub {
-		my $client = shift;
-		my $menuItem = $client->prefGet('menuItem') || 0;
-
-		# Add Favorites to home
-		if (ref($menuItem) ne 'ARRAY') {
-			return;
-		}
-		
-		# DigitalInput menu item for Transporter only
-		if (blessed($client) ne 'Slim::Player::Transporter') {
-			return;
-		}
-
-		my $insertPos = undef;
-
-		# Insert DigitalInput before SETTINGS
-		for (my $i = 0; $i < @$menuItem; $i++) {
-
-			if (@$menuItem[$i] eq 'DigitalInput::Plugin') {
-
-				return;
-
-			} elsif (@$menuItem[$i] eq 'SETTINGS') {
-
-				$insertPos = $i;
-			}
-		}
-
-		if (defined $insertPos) {
-
-			splice(@$menuItem, $insertPos, 0, 'DigitalInput::Plugin');
-
-		} else {
-
-			push (@$menuItem, 'DigitalInput::Plugin');
-		}
-
-		$client->prefSet('menuItem', $menuItem);
-	},
-);
 
 sub new {
 	my $class    = shift;

Modified: trunk/server/Slim/Player/Transporter.pm
URL: http://svn.slimdevices.com/trunk/server/Slim/Player/Transporter.pm?rev=12194&r1=12193&r2=12194&view=diff
==============================================================================
--- trunk/server/Slim/Player/Transporter.pm (original)
+++ trunk/server/Slim/Player/Transporter.pm Sat Jun  2 04:33:53 2007
@@ -54,7 +54,6 @@
 	my $client = shift;
 
 	# make sure any preferences unique to this client may not have set are set to the default
-
 	$prefs->client($client)->init($defaultPrefs);
 
 	$client->SUPER::init();

Modified: trunk/server/Slim/Plugin/MusicMagic/Importer.pm
URL: http://svn.slimdevices.com/trunk/server/Slim/Plugin/MusicMagic/Importer.pm?rev=12194&r1=12193&r2=12194&view=diff
==============================================================================
--- trunk/server/Slim/Plugin/MusicMagic/Importer.pm (original)
+++ trunk/server/Slim/Plugin/MusicMagic/Importer.pm Sat Jun  2 04:33:53 2007
@@ -87,15 +87,6 @@
 
 	Slim::Plugin::MusicMagic::Common::checkDefaults();
 
-	if (grep {$_ eq 'MusicMagic::Plugin'} Slim::Utils::Prefs::getArray('disabledplugins')) {
-
-		$log->info("Not initializing: disabled.");
-
-		$initialized = 0;
-
-		return 0;
-	}
-
 	$MMSport = $prefs->get('port');
 	$MMSHost = $prefs->get('host');
 

Modified: trunk/server/Slim/Plugin/MusicMagic/Plugin.pm
URL: http://svn.slimdevices.com/trunk/server/Slim/Plugin/MusicMagic/Plugin.pm?rev=12194&r1=12193&r2=12194&view=diff
==============================================================================
--- trunk/server/Slim/Plugin/MusicMagic/Plugin.pm (original)
+++ trunk/server/Slim/Plugin/MusicMagic/Plugin.pm Sat Jun  2 04:33:53 2007
@@ -121,15 +121,6 @@
 	
 	Slim::Plugin::MusicMagic::Common::checkDefaults();
 	
-	if (grep { $_ eq 'MusicMagic::Plugin' } Slim::Utils::Prefs::getArray('disabledplugins')) {
-
-		$log->info("Not initializing: disabled");
-
-		$initialized = 0;
-
-		return 0;		
-	}
-
 	$MMSport = $prefs->get('port');
 	$MMSHost = $prefs->get('host');
 
@@ -357,13 +348,6 @@
 		return;
 	}
 
-	if (grep {$_ eq 'MusicMagic::Plugin'} Slim::Utils::Prefs::getArray('disabledplugins')) {
-
-		$log->debug("Don't get moods list, it's disabled");
-
-		return %moodHash;
-	}
-	
 	$MMSport = $prefs->get('port') unless $MMSport;
 	$MMSHost = $prefs->get('host') unless $MMSHost;
 

Modified: trunk/server/Slim/Utils/Prefs.pm
URL: http://svn.slimdevices.com/trunk/server/Slim/Utils/Prefs.pm?rev=12194&r1=12193&r2=12194&view=diff
==============================================================================
--- trunk/server/Slim/Utils/Prefs.pm (original)
+++ trunk/server/Slim/Utils/Prefs.pm Sat Jun  2 04:33:53 2007
@@ -5,1239 +5,6 @@
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License, 
 # version 2.
-
-use strict;
-
-use File::Basename qw(dirname);
-use File::Spec::Functions qw(:ALL);
-use File::Path;
-use File::Slurp;
-use FindBin qw($Bin);
-use Digest::MD5;
-use YAML::Syck qw(DumpFile LoadFile Dump);
-
-use Slim::Utils::Log;
-#use Slim::Utils::Misc;
-#use Slim::Utils::Network;
-use Slim::Utils::Unicode;
-
-our %prefs = ();
-my $prefsPath;
-my $prefsFile;
-my $canWrite;
-my $canWriteAtomic = 0;
-my $writePending = 0;
-
-our %upgradeScripts = ();
-our %DEFAULT = ();
-our %prefChange = ();
-
-my $DEFAULT_DBSOURCE = 'dbi:mysql:hostname=127.0.0.1;port=9092;database=%s';
-
-my $log = logger('prefs');
-
-sub init {
-
-	init_new();
-
-	# These are scripts that are run once on old prefs file to bring them
-	# up-to-date with specific changes we want to push out to default prefs.
-	%upgradeScripts = (
-		# moves client preferences to a hash under the 'clients' key
-		'6.2b1' => sub {
-			for my $key (keys %prefs) {
-				# clear out any old 'clients' pref
-				if (!defined $prefs{'clients'} || ref($prefs{'clients'}) ne "HASH") {
-					$prefs{'clients'} = {};
-				}
-
-				# move old client preferences to new hash
-				if ($key =~ /^((?:[[:xdigit:]]{2}:){5}[[:xdigit:]]{2})-(.+)/) {
-					# matched hexidecimal client id (mac address)
-					$prefs{'clients'}{$1}{$2} = $prefs{$key};
-					CORE::delete($prefs{$key});
-				} elsif ($key =~ /^((?:\d{1,3}\.){3}\d{1,3}(?::\d+)?)-(.+)/) {
-					# matched ip address (optional port) client id (HTTP client)
-					$prefs{'clients'}{$1}{$2} = $prefs{$key};
-					CORE::delete($prefs{$key});
-				}
-			}
-		},
-
-		'6.2b1-2005-09-19' => sub {
-
-			# ExBrowse2 went away.
-			if ($prefs{'skin'} eq 'ExBrowse2') {
-				$prefs{'skin'} = 'ExBrowse3';
-			}
-		},
-
-		'6.2.1-2005-11-07' => sub {
-
-			# Bug 2410 - We need a better solution for iTunes
-			# rescanning, but in the meantime, don't scan every 60
-			# seconds. Let the Plugin reset the value.
-			if (defined $prefs{'itunesscaninterval'} && $prefs{'itunesscaninterval'} == 60) {
-				delete $prefs{'itunesscaninterval'};
-			}
-		},
-
-		'6.5b1-2006-01-25' => sub {
-
-			if (Slim::Utils::OSDetect::OS() eq 'unix') {
-				my $olddb = catdir(Slim::Utils::Prefs::get('cachedir'), '.slimserversql.db');
-				my $newdb = catdir(Slim::Utils::Prefs::get('cachedir'), 'slimserversql.db');
-				my $oldPref = catdir(preferencesPath(), '.slimserver.pref');
-				my $newPref = catdir(preferencesPath(), 'slimserver.pref');
-
-				if (-e $olddb) {
-					rename($olddb,$newdb);
-				}
-
-				if (-e $oldPref && $prefsFile eq $oldPref) {
-					# have loaded old file name at this point, move and change to new name
-					rename($oldPref, $newPref);
-					$prefsFile = $newPref;
-				}
-			}
-		},
-						   
-		'6.5b1-2006-02-03' => sub {
-
-			# Update our language list to be in line with ISO 639-1
-			my %languages = (
-				'CZ' => 'CS',
-				'DK' => 'DA',
-				'JP' => 'JA',
-				'SE' => 'SV',
-			);
-
-			my $newLang = $languages{ $prefs{'language'} };
-
-			if (defined $newLang) {
-				$prefs{'language'} = $newLang;
-			}
-		},
-
-		'6.5b1-2006-05-06' => sub {
-			#check for empty date time setitngs and set defaults to current formats
-			Slim::Utils::Prefs::set('screensaverTimeFormat', Slim::Utils::Prefs::get('timeFormat'))
-				unless Slim::Utils::Prefs::get('screensaverTimeFormat');
-			Slim::Utils::Prefs::set('screensaverDateFormat', Slim::Utils::Prefs::get('longdateFormat'))
-				unless Slim::Utils::Prefs::get('screensaverDateFormat');
-		},
-
-		# The change to force stderr to off requires a clean log config.
-		'7.0a1-2006-11-18' => sub {
-			unlink Slim::Utils::Log->defaultConfigFile;
-		},
-	);
-
-	# When adding new server and client preference options, put a default value for the option
-	# into the DEFAULT hash.  For client options put the key => value pair in the client hash
-	# in the client key of the main hash.
-	# If the preference ends in a digit or a # then it will be interpreted as an array preference,
-	# so if this is not what you intend, don't end it with a digit or a #
-	# Squeezebox G may include several prefs not needed by other players.  For those defaults, use
-	# %Slim::Player::Player::GPREFS
-	%DEFAULT = (
-		"httpport"		=> 9000,
-		"audiodir"		=> defaultAudioDir(),
-		"playlistdir"		=> defaultPlaylistDir(),
-		"cachedir"		=> defaultCacheDir(),
-		"securitySecret"	=> makeSecuritySecret(),
-		"csrfProtectionLevel"	=> 1,
-		"skin"			=> "Default",
-		"language"		=> "EN",
-		"refreshRate"		=> 30,
-		"displaytexttimeout"	=> 1.0,
-		'browseagelimit'	=> 100,
-		"playtrackalbum"	=> 1,
-		"ignoredarticles"	=> "The El La Los Las Le Les",
-		"splitList"		=> '',
-		"authorize"		=> 0,				# No authorization by default
-		"username"		=> '',
-		"password"		=> '',
-		"filterHosts"		=> 0,				# No filtering by default
-#		"allowedHosts"		=> join(',', Slim::Utils::Network::hostAddr()),
-		"tcpReadMaximum"	=> 20,
-		"tcpWriteMaximum"	=> 20,
-		"tcpConnectMaximum"	=> 30,
-		"streamWriteMaximum"	=> 30,
-		'webproxy'		=> '',
-		"udpChunkSize"		=> 1400,
-		'itemsPerPage'		=> 50,
-		'disableStatistics'	=> 0,
-		'artfolder'		=> '',
-		'coverThumb'		=> '',
-		'coverArt'		=> '',
-		'thumbSize'		=> 100,
-		'longdateFormat'	=> q(%A, %B |%d, %Y),
-		'shortdateFormat'	=> q(%m/%d/%Y),
-		'showYear'		=> 0,
-		'timeFormat'		=> q(|%I:%M:%S %p),
-		'titleFormatWeb'	=> 1,
-		'ignoreDirRE'		=> '',
-		'checkVersion'		=> 1,
-		'checkVersionInterval'	=> 60*60*24,
-		'mDNSname'		=> 'SlimServer',
-		'titleFormat'		=> [
-			'TITLE',
-			'DISC-TRACKNUM. TITLE',
-			'TRACKNUM. TITLE',
-			'TRACKNUM. ARTIST - TITLE',
-			'TRACKNUM. TITLE (ARTIST)',
-			'TRACKNUM. TITLE - ARTIST - ALBUM',
-			'FILE.EXT',
-			'TRACKNUM. TITLE from ALBUM by ARTIST',
-			'TITLE (ARTIST)',
-			'ARTIST - TITLE'
-		],
-		'guessFileFormats'	=> [
-			'(ARTIST - ALBUM) TRACKNUM - TITLE', 
-			'/ARTIST/ALBUM/TRACKNUM - TITLE', 
-			'/ARTIST/ALBUM/TRACKNUM TITLE', 
-			'/ARTIST/ALBUM/TRACKNUM. TITLE' 
-		],
-		'disabledplugins'	=> [],
-		'enabledfonts'		=> ['small', 'medium', 'large', 'huge'],
-		'persistPlaylists'	=> 1,
-		'reshuffleOnRepeat'	=> 0,
-		'saveShuffled'		=> 0,
-		'searchSubString'	=> 0,
-		'maxBitrate'		=> 320,
-		'composerInArtists'	=> 0,
-		'groupdiscs' 		=> 0,
-		'remotestreamtimeout'	=> 5, # seconds to try to connect for a remote stream
-		'prefsWriteDelay'	=> 30,
-		'dbsource'		=> $DEFAULT_DBSOURCE,
-		'dbusername'		=> 'slimserver',
-		'dbpassword'		=> '',
-		'commonAlbumTitles'	=> ['Greatest Hits', 'Best of...', 'Live'],
-		'commonAlbumTitlesToggle' => 0,
-		'noGenreFilter'		=> 0,
-		'variousArtistAutoIdentification' => 0,
-		'useBandAsAlbumArtist'  => 0,
-		'upgrade-6.2b1-script'	=> 1,
-		'upgrade-6.2b1-2005-09-19-script' => 1,
-		'upgrade-6.2.1-2005-11-07-script' => 1,
-		'upgrade-6.5b1-2006-01-25-script' => 1,
-		'upgrade-6.5b1-2006-02-03-script' => 1,
-		'upgrade-6.5b1-2006-03-31-script' => 1,
-		'upgrade-7.0a1-2006-11-18-script' => 1,
-		'rank-PLUGIN_PICKS_MODULE_NAME' => 4,
-		'disabledextensionsaudio' => '',
-		'disabledextensionsplaylist' => '',
-		'serverPriority' => '',
-		'scannerPriority' => '0',
-		'bufferSecs' => 3,
-		'maxWMArate' => 9999,
-	);
-
-	# The following hash contains functions that are executed when the pref corresponding to
-	# the hash key is changed.  Client specific preferences are contained in a hash stored
-	# under the main hash key 'CLIENTPREFS'.
-	# The functions expect the parameters $pref and $newvalue for non-client specific functions
-	# where $pref is the preference which changed and $newvalue is the new value of the preference.
-	# Client specific functions also expect a $client param containing a reference to the client
-	# struct.  The param order is $client,$pref,$newvalue.
-	%prefChange = (
-
-		'CLIENTPREFS' => {
-
-			'irmap' => sub {
-				my ($client,$newvalue) = @_;
-
-				require Slim::Hardware::IR;
-
-				Slim::Hardware::IR::loadMapFile($newvalue);
-
-				if ($newvalue eq Slim::Hardware::IR::defaultMapFile()) {
-					#Slim::Utils::PluginManager->addDefaultMaps();
-				}
-			},
-		},
-
-		'checkVersion' => sub {
-			my $newValue = shift;
-			if ($newValue) {
-				main::checkVersion();
-			}
-		},
-
-		'ignoredarticles' => sub {
-			Slim::Utils::Text::clearCaseArticleCache();
-		},
-
-		'audiodir' => sub {
-			my $newvalue = shift;
-
-			Slim::Buttons::BrowseTree->init;
-			Slim::Music::MusicFolderScan->init;
-		},
-
-		'playlistdir' => sub {
-			my $newvalue = shift;
-
-			if ($newvalue && !-d $newvalue) {
-
-				mkpath($newvalue) or do {
-
-					logError("Could't create playlistdir: [$newvalue]");
-					return;
-				};
-			}
-
-			Slim::Music::PlaylistFolderScan->init;
-
-			for my $client (Slim::Player::Client::clients()) {
-				Slim::Buttons::Home::updateMenu($client);
-			}
-		},
-
-		'persistPlaylists' => sub {
-
-			my $newvalue = shift;
-
-			if ($newvalue) {
-
-				Slim::Control::Request::subscribe(
-					\&Slim::Player::Playlist::modifyPlaylistCallback, 
-					[['playlist']]
-					);
-
-				for my $client (Slim::Player::Client::clients()) {
-					next if Slim::Player::Sync::isSlave($client);
-					
-					my $request = Slim::Control::Request->new( 
-						$client, 
-						['playlist','load_done'],
-					);
-					Slim::Player::Playlist::modifyPlaylistCallback($request);
-				}
-
-			} else {
-				Slim::Control::Request::unsubscribe(\&Slim::Player::Playlist::modifyPlaylistCallback);
-			}
-		},
-				   
-		'httpport' => sub {
-			Slim::Web::HTTP::adjustHTTPPort();
-		}
-	);
-}
-
-# This needs to be run after Logging is initialized.
-sub loadLogHandler {
-
-	$log = logger('prefs');
-}
-
-sub makeSecuritySecret {
-	
-	# each SlimServer installation should have a unique,
-	# strongly random value for securitySecret. This routine
-	# will be called by checkServerPrefs() the first time
-	# SlimServer is started to "seed" the prefs file with a
-	# value for this installation
-	#
-	# do we already have a value?
-	
-	my $currentVal = get('securitySecret');
-	
-	if (defined($currentVal) && ($currentVal =~ m|^[0-9a-f]{32}$|)) {
-
-		if ($log) {
-
-			$log->debug("Server already has a securitySecret - returning existing");
-		}
-
-		return $currentVal;
-	}
-	
-	# make a new value, based on a random number
-	
-	my $hash = new Digest::MD5;
-	
-	$hash->add(rand());
-	
-	# explicitly "set" this so it persists through shutdown/startupa
-	my $secret = $hash->hexdigest();
-
-	if ($log) {
-		$log->debug("Creating a securitySecret for this installation.");
-	}
-
-	set('securitySecret', $secret);
-
-	return $secret;
-}
-
-sub defaultAudioDir {
-	my $path;
-
-	if (Slim::Utils::OSDetect::OS() eq 'mac') {
-
-		$path = ($ENV{'HOME'} . '/Music');
-
-	} elsif (Slim::Utils::OSDetect::OS() eq 'win') {
-
-		Slim::bootstrap::tryModuleLoad('Win32::Registry');
-
-		if (!$@) {
-
-			my $folder;
-
-			if ($::HKEY_CURRENT_USER->Open("Software\\Microsoft\\Windows"
-				   ."\\CurrentVersion\\Explorer\\Shell Folders", $folder)) {
-
-				my ($type, $value);
-				if ($folder->QueryValueEx("My Music", $type, $value)) {
-					$path = $value;
-				} elsif ($folder->QueryValueEx("Personal", $type, $value)) {
-					$path = $value . '\\My Music';
-				}
-			}
-		}		
-	}
-
-	if ($path && -d $path) {
-		return $path;
-	} else {
-		return '';
-	}
-}
-
-sub defaultPlaylistDir {
-	my $path;
-
-	if (Slim::Utils::OSDetect::OS() eq 'mac') {
-
-		$path = $ENV{'HOME'} . '/Music/Playlists';
-
-	} elsif (Slim::Utils::OSDetect::OS() eq 'win') {
-
-		$path = $Bin . '/Playlists';
-
-	} else {
-
-		$path = '';
-	}
-
-	if ($path) {
-
-		# We've seen people have the defaultPlayListDir be a file. So
-		# change the path slightly to allow for that.
-		if (-f $path) {
-			$path .= 'SlimServer';
-		}
-
-		if (!-d $path) {
-			mkpath($path) or msg("Couldn't create playlist path: $path - $!\n");
-		}
-	}
-
-	return $path;
-}
-
-sub defaultCacheDir {
-	my $CacheDir = catdir($Bin,'Cache');
-
-	my $os = Slim::Utils::OSDetect::OS();
-
-	if ($os eq 'mac') {
-
-		$CacheDir = catdir($ENV{'HOME'}, '/Library/Caches/SlimServer');
-
-	} elsif ($os eq 'unix') {
-
-		$CacheDir = catdir($ENV{'HOME'},'Cache');
-	}
-
-	my @CacheDirs = splitdir($CacheDir);
-	pop @CacheDirs;
-
-	my $CacheParent = catdir(@CacheDirs);
-
-	if ((!-e $CacheDir && !-w $CacheParent) || (-e $CacheDir && !-w $CacheDir)) {
-		$CacheDir = undef;
-	}
-
-	return $CacheDir;
-}
-
-sub makeCacheDir {
-	my $cacheDir = get("cachedir") || defaultCacheDir();
-	
-	if (defined $cacheDir && !-d $cacheDir) {
-
-		mkpath($cacheDir) or do {
-
-			logBacktrace("Couldn't create cache dir for $cacheDir : $!");
-			return;
-		};
-	}
-}
-
-sub homeURL {
-        my $host = $main::httpaddr || Slim::Utils::Network::hostname() || '127.0.0.1';
-        my $port = preferences('server')->get('httpport');
-
-        return "http://$host:$port/";
-}
-
-# Some routines to add and remove preference change handlers
-sub addPrefChangeHandler {
-	my ($pref,$handlerRef,$forClient) = @_;
-	if (defined($pref) && ref($handlerRef) eq 'CODE') {
-		if ($forClient) {
-			$prefChange{'CLIENTPREFS'}{$pref} = $handlerRef;
-		} else {
-			$prefChange{$pref} = $handlerRef;
-		}
-	} else {
-		warn "Invalid attempt to add a preference change handler.\n" 
-			, defined($pref) ? "Invalid code reference supplied.\n" : "No preference supplied.\n";
-	}
-}
-
-sub removePrefChangeHandler {
-	my ($pref,$forClient) = @_;
-	if ($forClient) {
-		CORE::delete($prefChange{'CLIENTPREFS'}{$pref});
-	} else {
-		CORE::delete($prefChange{$pref});
-	}
-}
-
-sub onChange {
-	my $key = shift;
-	my $value = shift;
-	my $ind = shift;
-	my $client = shift;
-	
-	if (defined($client)) {
-		if (defined($key) && exists($prefChange{'CLIENTPREFS'}{$key})) {
-			&{$prefChange{'CLIENTPREFS'}{$key}}($client,$value, $key, $ind);
-		}
-	} else {
-		if (defined($key) && exists($prefChange{$key})) {
-			&{$prefChange{$key}}($value, $key, $ind);
-		}
-	}
-}
-
-# This makes sure all the server preferences defined in %DEFAULT are in the pref file.
-# If they aren't there already they are set to the value in %DEFAULT
-sub checkServerPrefs {
-	for my $key (keys %DEFAULT) {
-		if (!defined($prefs{$key})) {
-			if (ref($DEFAULT{$key}) eq 'ARRAY') {
-				my @temp = @{$DEFAULT{$key}};
-				$prefs{$key} = \@temp;
-			} elsif (ref($DEFAULT{$key}) eq 'HASH') {
-				my %temp = %{$DEFAULT{$key}};
-				$prefs{$key} = \%temp;
-			} else {
-				$prefs{$key} = $DEFAULT{$key};
-			}
-		} elsif (ref($DEFAULT{$key}) eq 'HASH') {
-			# check defaults for individual hash prefs
-			for my $subkey (keys %{$DEFAULT{$key}}) {
-				if (!defined $prefs{$key}{$subkey}) {
-					$prefs{$key}{$subkey} = $DEFAULT{$key}{$subkey};
-				}
-			}
-		}
-	}
-
-	# Always Upgrade SQLite to MySQL
-	if ($prefs{'dbsource'} =~ /SQLite/) {
-		$prefs{'dbsource'} = $DEFAULT_DBSOURCE;
-	}
-
-	for my $version (sort keys %upgradeScripts) {
-
-		if (Slim::Utils::Prefs::get("upgrade-$version-script")) {
-			&{$upgradeScripts{$version}}();
-			Slim::Utils::Prefs::set("upgrade-$version-script", 0);
-		}
-	}
-
-	# write it out
-	writePrefs();
-}
-
-# This makes sure all the client preferences defined in the submitted hash are in the pref file.
-sub initClientPrefs {
-	my $client = shift;
-	my $defaultPrefs = shift;
-	
-	my $prefs = getClientPrefs($client->id());
-
-	for my $key (keys %{$defaultPrefs}) {
-
-		if (!defined($prefs->{$key})) {
-
-			# Take a copy of the default prefs
-			if (ref($defaultPrefs->{$key}) eq 'ARRAY') {
-
-				$prefs->{$key} = [ @{$defaultPrefs->{$key}} ];
-
-			} elsif (ref($defaultPrefs->{$key}) eq 'HASH') {
-
-				$prefs->{$key} = { %{$defaultPrefs->{$key}} };
-
-			} elsif (defined($defaultPrefs->{$key})) {
-
-				$prefs->{$key} = $defaultPrefs->{$key};
-			}
-
-		} elsif (ref($defaultPrefs->{$key}) eq 'HASH') {
-
-			# check defaults for individual hash prefs
-			for my $subkey (keys %{$defaultPrefs->{$key}}) {
-
-				if (!defined $prefs->{$key}{$subkey}) {
-
-					$prefs->{$key}{$subkey} = $defaultPrefs->{$key}{$subkey};
-				}
-			}
-		}
-	}
-
-	scheduleWrite() unless $writePending;
-}
-
-sub push {
-	my $arrayPref = shift;
-	my $value     = shift;
-
-	# allow clients to specify the preference hash to modify
-	my $prefs     = shift || \%prefs;
-
-	if (!defined($prefs->{$arrayPref})) {
-
-		# auto-vivify
-		$prefs->{$arrayPref} = [];
-	}
-
-	if (ref($prefs->{$arrayPref}) eq 'ARRAY') {
-
-		CORE::push(@{$prefs->{$arrayPref}}, $value);
-
-	} else {
-
-		logBacktrace("Attempted to push a value onto a scalar pref!");
-	}
-
-	scheduleWrite() unless $writePending;
-}
-
-sub clientPush {
-	my $client = shift;
-	my $arrayPref = shift;
-	my $value = shift;
-	$client->prefPush($arrayPref,$value);
-}
-
-# getArrayMax($arrayPref)
-sub getArrayMax{
-	my $arrayPref = shift;
-	if (defined($prefs{$arrayPref}) && ref($prefs{$arrayPref}) eq 'ARRAY') {
-		my @prefArray = @{$prefs{$arrayPref}};
-		my $max = $#prefArray;
-		return $max;
-	} else {
-		return undef;
-	}
-}
-# clientGetArrayMax($client, $arrayPref)
-sub clientGetArrayMax {
-	my $client = shift;
-	my $arrayPref = shift;
-	assert($client);
-	return $client->prefGetArrayMax($arrayPref);
-}
-
-# getArray($arrayPref)
-sub getArray {
-	my $arrayPref = shift;
-
-	if (defined($prefs{($arrayPref)}) && ref($prefs{$arrayPref}) eq 'ARRAY') {
-		return @{$prefs{($arrayPref)}};
-	} else {
-		return ();
-	}
-}
-
-# clientGetArray($client, $arrayPref)
-sub clientGetArray {
-	my $client = shift;
-	my $arrayPref = shift;
-	assert($client);
-	return $client->prefGetArray($arrayPref);
-}
-
-# getClientPrefs($clientid)
-# returns a reference to the hash of client preferences for the client with the id provided
-# creates an empty hash if none currently exists.
-sub getClientPrefs {
-	my $clientid = shift;
-
-	if (!defined $prefs{'clients'}{$clientid} || ref($prefs{'clients'}{$clientid}) ne "HASH") {
-
-		$prefs{'clients'}{$clientid} = {};
-	}
-	
-	return $prefs{'clients'}{$clientid};
-}
-
-# get($pref)
-sub get { 
-
-	return $prefs{$_[0]};
-}
-
-# getIjd($pref,$index)
-# for indexed (array or hash) prefs
-sub getInd {
-	my ($pref,$index) = @_;
-
-	if (defined $prefs{$pref}) {
-
-		if (ref $prefs{$pref} eq 'ARRAY') {
-
-			return $prefs{$pref}[$index];
-
-		} elsif (ref $prefs{$pref} eq 'HASH') {
-
-			return $prefs{$pref}{$index};
-		}
-	}
-
-	return undef;
-}
-
-# getKeys($pref)
-# gets the keys of a hash pref
-sub getKeys {
-	my $hashPref = shift;
-
-	if (defined($prefs{$hashPref}) && ref($prefs{$hashPref}) eq 'HASH') {
-
-		return keys %{$prefs{$hashPref}};
-
-	} else {
-
-		return ();
-	}
-}
-
-# getHash($pref)
-sub getHash {
-	my $hashPref = shift;
-
-	if (defined($prefs{($hashPref)}) && ref($prefs{$hashPref}) eq 'HASH') {
-
-		return %{$prefs{($hashPref)}};
-
-	} else {
-
-		return ();
-	}
-}
-
-# clientGetKeys($client, $hashPref)
-sub clientGetKeys {
-	my $client = shift;
-	my $hashPref = shift;
-
-	assert($client);
-
-	return $client->prefGetKeys($hashPref);
-}
-	
-# clientGetHash($client, $hashPref)
-sub clientGetHash {
-	my $client   = shift;
-	my $hashPref = shift;
-
-	assert($client);
-
-	return $client->prefGetHash($hashPref);
-}
-	
-# clientGet($client, $pref [,$ind])
-sub clientGet {
-	my $client = shift;
-	my $key = shift;
-	my $ind = shift;
-
-	if (!defined($client)) {
-
-		$log->logBacktrace("Undefined client!");
-
-		return undef;
-	}
-
-	return $client->prefGet($key,$ind);
-}
-
-sub getDefault {
-	my $key = shift;
-	my $ind = shift;
-
-	if (defined($ind)) {
-
-		if (defined $DEFAULT{$key}) {
-
-			if (ref $DEFAULT{$key} eq 'ARRAY') {
-
-				return $DEFAULT{$key}[$ind];
-
-			} elsif (ref $DEFAULT{$key} eq 'HASH') {
-
-				return $DEFAULT{$key}{$ind};
-			}
-		}
-	}
-
-	return $DEFAULT{$key};
-}
-
-sub set {
-	my $key   = shift || return;
-	my $value = shift;
-	my $ind   = shift;
-
-	# allow clients to specify the preference hash to modify
-	my $client = shift;
-	my $prefsRef = shift || \%prefs;
-	
-	my $oldvalue;
-
-	# We always want to write out just bytes to the pref file, so turn off
-	# the UTF8 flag.
-	$value = Slim::Utils::Unicode::utf8off($value);
-
-	if (defined $ind) {
-
-		if (defined $prefsRef->{$key}) {
-			if (ref $prefsRef->{$key} eq 'ARRAY') {
-				if (defined($prefsRef->{$key}[$ind]) && defined($value) && $value eq $prefsRef->{$key}[$ind]) {
-						return $value;
-				}
-
-				$oldvalue = $prefsRef->{$key}[$ind];
-				$prefsRef->{$key}[$ind] = $value;
-			} elsif (ref $prefsRef->{$key} eq 'HASH') {
-				if (defined($prefsRef->{$key}{$ind}) && defined($value) && $value eq $prefsRef->{$key}{$ind}) {
-						return $value;
-				}
-
-				$oldvalue = $prefsRef->{$key}{$ind};
-				$prefsRef->{$key}{$ind} = $value;
-			}
-		} elsif ( $ind =~ /\D/ ) {
-			# Setting hash pref where no keys currently exist
-			$prefsRef->{$key}{$ind} = $value;
-		} else {
-			# Setting array pref where no indexes currently exist
-			$prefsRef->{$key}[$ind] = $value;
-		}
-
-	} elsif ($key =~ /(.+?)(\d+)$/) { 
-
-		# trying to set a member of an array pref directly
-		# re-call function the correct way
-		return set($1,$value,$2,$client,$prefsRef);
-
-	} else {
-
-		if (defined($prefsRef->{$key}) && defined($value) && $value eq $prefsRef->{$key}) {
-				return $value;
-		}
-
-		$oldvalue = $prefsRef->{$key};
-		$prefsRef->{$key} = $value;
-	}
-
-	onChange($key, $value, $ind, $client);
-
-	# must mark $ind as defined or indexed prefs cause an error in this msg
-	if (defined $ind) {
-
-		if ($log) {
-			$log->debug("Setting prefs $key $ind to " . ((defined $value) ? $value : "undef"));
-		}
-
-	} else {
-
-		if ($log) {
-			$log->debug("Setting prefs $key to " . ((defined $value) ? $value : "undef"));
-		}
-	}
-
-	if (!$writePending) {
-		scheduleWrite();
-	}
-
-	return $oldvalue;
-}
-
-sub setArray {
-	my $key   = shift;
-	my $value = shift;
-	
-	my $oldvalue = $prefs{$key};
-	
-	$prefs{$key} = $value;
-	
-	onChange($key, $value);
-
-	if ($log) {
-		$log->debug(sprintf("%s => %s", $key, Data::Dump::dump($value)));
-	}
-
-	if (!$writePending) {
-		scheduleWrite();
-	}
-
-	return $oldvalue;
-}
-
-sub maxRate {
-	my $client   = shift || return 0;
-	my $soloRate = shift;
-
-	# The default for a new client will be undef.
-	my $rate     = preferences('server')->client($client)->get('maxBitrate');
-
-	if (!defined $rate) {
-
-		# Possibly the first time this pref has been accessed
-		# if maxBitrate hasn't been set yet, allow wired squeezeboxen and ALL SB2's to default to no limit, others to 320kbps
-		if ($client->isa("Slim::Player::Squeezebox2")) {
-
-			$rate = 0;
-
-		} elsif ($client->isa("Slim::Player::Squeezebox") && !defined $client->signalStrength()) {
-
-			$rate = 0;
-
-		} else {
-
-			$rate = 320;
-		}
-	}
-
-	# override the saved or default bitrate if a transcodeBitrate has been set via HTTP parameter
-	$rate = $client->prefGet('transcodeBitrate') || $rate;
-
-	if ($soloRate) {
-		return $rate;
-	}
-
-	if ($rate != 0) {
-		logger('player.source')->debug(sprintf("Setting maxBitRate for %s to: %d", $client->name, $rate));
-	}
-	
-	# if we're the master, make sure we return the lowest common denominator bitrate.
-	my @playergroup = ($client, Slim::Player::Sync::syncedWith($client));
-	
-	for my $everyclient (@playergroup) {
-
-		if ($everyclient->prefGet('silent')) {
-			next;
-		}
-
-		my $otherRate = maxRate($everyclient, 1);
-		
-		# find the lowest bitrate limit of the sync group. Zero refers to no limit.
-		$rate = ($otherRate && (($rate && $otherRate < $rate) || !$rate)) ? $otherRate : $rate;
-	}
-
-	# return lowest bitrate limit.
-	return $rate;
-}
-
-sub delete {
-	my $key = shift;
-	my $ind = shift;
-
-	# allow clients to specify the preference hash to modify
-	my $prefs = shift || \%prefs;
-	
-	if (!defined $prefs->{$key}) {
-		return;
-	}
-	if (defined($ind)) {
-		if (ref($prefs->{$key}) eq 'ARRAY') {
-			splice(@{$prefs->{$key}},$ind,1);
-		} elsif (ref($prefs->{$key}) eq 'HASH') {
-			CORE::delete $prefs->{$key}{$ind};
-		}
-	} elsif ($key =~ /(.+?)(\d+)$/) { 
-		#trying to delete a member of an array pref directly
-		#re-call function the correct way
-		Slim::Utils::Prefs::delete($1,$2,$prefs);
-	} elsif (ref($prefs->{$key}) eq 'ARRAY') {
-		#clear an array pref
-		$prefs->{$key} = [];
-	} else {
-		CORE::delete $prefs->{$key};
-	}
-	scheduleWrite() unless $writePending;
-}
-
-sub clientDelete {
-	my $client = shift;
-	my $key = shift;
-	my $ind = shift;
-	
-	$client->prefDelete($key,$ind);
-}
-
-sub isDefined {
-	my $key = shift;
-	my $ind = shift;
-	if (defined($ind)) {
-		if (defined $prefs{$key}) {
-			if (ref $prefs{$key} eq 'ARRAY') {
-				return defined $prefs{$key}[$ind];
-			} elsif (ref $prefs{$key} eq 'HASH') {
-				return defined $prefs{$key}{$ind};
-			}
-		}
-	}
-	return defined $prefs{$key};
-}
-
-sub clientIsDefined {
-	my $client = shift;
-	my $key = shift;
-	my $ind = shift;
-	
-	return $client->prefIsDefined($key,$ind);
-}
-
-sub scheduleWrite {
-	my $writeDelay = get('prefsWriteDelay') || 0;
-	
-	$writePending = 1;
-	
-	if ($writeDelay > 0) {
-		Slim::Utils::Timers::setTimer(0, (Time::HiRes::time() + $writeDelay), \&writePrefs, 1);
-	} else {
-		writePrefs();
-	}
-}	
-
-sub writePending {
-	return $writePending;
-}
-
-sub writePrefs {
-
-	return unless $canWrite;
-
-	my $writeFile = prefsFile();
-	my $prefdump  = Dump(\%prefs);
-
-	my %writeAttr = (
-		'atomic'  => $canWriteAtomic,
-		'buf_ref' => \$prefdump,
-		'binmode' => ':raw',
-	);
-
-	if ($log) {
-
-		$log->info("Writing out prefs in $writeFile");
-	}
-
-	eval { File::Slurp::write_file($writeFile, \%writeAttr) };
-
-	if ($@) {
-		logError("Couldn't write prefs file: [$writeFile] - [$@]");
-	}
-
-	$writePending = 0;
-}
-
-sub preferencesPath {
-	my $setPath = shift;
-
-	if (defined $setPath) { 
-		$prefsPath = $setPath;
-	}
-
-	if (defined($prefsPath)) {
-		return $prefsPath;
-	}
-
-	if (Slim::Utils::OSDetect::OS() eq 'mac') {
-
-		$prefsPath = catdir($ENV{'HOME'}, 'Library', 'SlimDevices');
-
-	} elsif (Slim::Utils::OSDetect::OS() eq 'win')  {
-
-		$prefsPath = $Bin;
-
-	} else {
-
-	 	$prefsPath = $ENV{'HOME'};
-	}
-
-	if ($log) {
-		$log->info("The default prefs directory is $prefsPath");
-	}
-
-	return $prefsPath;
-}
-
-sub prefsFile {
-	my $setFile = shift;
-	
-	# Bug: 2354 - if the user has passed in a prefs file - set the prefs
-	# path based off of that.
-	if (defined $setFile) { 
-
-		$prefsFile = $setFile;
-
-		preferencesPath(dirname($prefsFile));
-	}
-	
-	if (defined($prefsFile)) {
-		return $prefsFile;
-	}
-
-	my $pref_path = preferencesPath();
-
-	if (Slim::Utils::OSDetect::OS() eq 'win')  {	
-
-		$prefsFile = catdir($pref_path, 'slimserver.pref');
-
-	} elsif (Slim::Utils::OSDetect::OS() eq 'mac') {
-
-		$prefsFile = catdir($pref_path, 'slimserver.pref');
-
-	} else {
-
-		if (-r '/etc/slimserver.conf') {
-
-			$prefsFile = '/etc/slimserver.conf';
-
-			preferencesPath(dirname($prefsFile));
-
-		} elsif (-r catdir($pref_path, '.slimserver.pref')) {
-
-			$prefsFile = catdir($pref_path, '.slimserver.pref');
-
-		} else {
-
-			$prefsFile = catdir($pref_path, 'slimserver.pref');
-		}
-	}
-
-	if ($log) {
-		$log->info("The default prefs file location is $prefsFile");
-	}
-
-	return $prefsFile;
-}
-
-# Figures out where the preferences file should be on our platform, and loads it.
-sub load {
-	my $setFile = shift;
-	my $nosetup = shift;
-
-	my $readFile = prefsFile($setFile);
-
-	# if we found some file to read, then let's read it!
-	eval {
-		if (-r $readFile) {
-
-			open(NUPREFS, $readFile);
-			my $firstline = <NUPREFS>;
-			close(NUPREFS);
-
-			if ($firstline =~ /^---/) {
-
-				# it's a YAML formatted file
-				if ($log) {
-					$log->info("Loading YAML style prefs file: $readFile");
-				}
-
-				my $prefref = LoadFile($readFile);
-
-				%prefs = %$prefref;
-
-			} else {
-
-				# it's the old style prefs file
-				if ($log) {
-					$log->info("Loading old style prefs file: $readFile");
-				}
-
-				loadOldPrefs($readFile);
-			}
-		}
-	};
-
-	if ($@) {
-
-		print(
-			"There was an error reading your SlimServer configuration file - it might be corrupted!: [$@]\n",
-			"If you are on a Unix platform, you may need to install YAML::Syck\n",
-			"Run './Bin/build-perl-modules.pl YAML::Syck'",
-			"\n\n",
-			"Exiting\n",
-		);
-
-		exit;
-	}
-
-	# see if we can write out the real prefs file
-	$canWrite = (-e prefsFile() && -w prefsFile()) || (-w preferencesPath());
-	
-	$canWriteAtomic = (-w preferencesPath) ? 1 : 0;
-	
-	if (!$canWrite && !$nosetup) {
-
-		logError("Can't write to preferences file: $prefsFile, any changes made will not be saved!");
-	}
-}
-
-sub loadOldPrefs {
-	my $readFile = shift;
-	open(NUPREFS, $readFile);
-	while (<NUPREFS>) {
-		chomp; 			# no newline
-		s/^\s+//;		# no leading white
-		next unless length;	#anything left?
-		my ($var, $value) = split(/\s=\s/, $_, 2);
-		if ($var =~ /^(.+?)\%(.+)$/) {
-			#part of hash
-			$prefs{$1}{$2} = $value;
-		} elsif ($var =~ /(.+?)(\d+|#)$/) {
-			#part of array
-			if ($2 eq '#') {
-				$prefs{$1} = [] if $value == -1;
-			} else {
-				$prefs{$1}[$2] = $value;
-			}
-		} else {
-			$prefs{$var} = $value;
-		}
-	}
-	close(NUPREFS);	
-}	
-
-
-########################################################################################################
-# new object based preferences - some of above will migrate to use these, both used during migration
-########################################################################################################
 
 =head1 NAME
 
@@ -1295,15 +62,24 @@
 
 =cut
 
+use strict;
+
+use Exporter::Lite;
+use Getopt::Long qw(:config pass_through);
+
 use Slim::Utils::Prefs::Namespace;
 use Slim::Utils::Prefs::OldPrefs;
-
-use Exporter::Lite;
-use Getopt::Long qw(:config pass_through);
+use Slim::Utils::Log;
 
 our @EXPORT = qw(preferences);
 
+my $DEFAULT_DBSOURCE = 'dbi:mysql:hostname=127.0.0.1;port=9092;database=%s';
+
+my $log   = logger('prefs');
+
 my $path; # path to directory where preferences are stored
+
+my %namespaces;
 
 # we need to check for prefsdir being set on cmdline as we are run before the server parses options
 Getopt::Long::GetOptions('prefsdir=s' => \$path);
@@ -1312,7 +88,6 @@
 
 my $prefs = preferences('server');
 
-my %namespaces;
 
 =head2 preferences( $namespace )
 
@@ -1338,7 +113,7 @@
 	return [ keys %namespaces ];
 }
 
-sub init_new {
+sub init {
 	my %defaults = (
 		# Server Prefs not settable from web pages
 		'dbsource'              => $DEFAULT_DBSOURCE,
@@ -1470,7 +245,7 @@
 						 activeFont idleFont activeFont_curr idleFont_curr doublesize offDisplaySize largeTextFont
 						 menuItem
 						 irmap disabledirsets
-						 mute silent volume bass treble pitch repeat shuffle currentSong
+						 power mute silent volume bass treble pitch repeat shuffle currentSong
 						);
 
 		for my $pref (@migrate) {
@@ -1567,11 +342,202 @@
 
 =cut
 
+
+# FIXME - support functions - should these be here?
+
+use FindBin qw($Bin);
+use File::Spec::Functions qw(:ALL);
+use Digest::MD5;
+
+sub makeSecuritySecret {
+	# each SlimServer installation should have a unique,
+	# strongly random value for securitySecret. This routine
+	# will be called by the first time SlimServer is started
+	# to "seed" the prefs file with a value for this installation
+
+	my $hash = new Digest::MD5;
+
+	$hash->add(rand());
+
+	my $secret = $hash->hexdigest();
+
+	if ($log) {
+		$log->debug("Creating a securitySecret for this installation.");
+	}
+
+	$prefs->set('securitySecret', $secret);
+
+	return $secret;
+}
+
+sub defaultAudioDir {
+	my $path;
+
+	if (Slim::Utils::OSDetect::OS() eq 'mac') {
+
+		$path = ($ENV{'HOME'} . '/Music');
+
+	} elsif (Slim::Utils::OSDetect::OS() eq 'win') {
+
+		Slim::bootstrap::tryModuleLoad('Win32::Registry');
+
+		if (!$@) {
+
+			my $folder;
+
+			if ($::HKEY_CURRENT_USER->Open("Software\\Microsoft\\Windows"
+				   ."\\CurrentVersion\\Explorer\\Shell Folders", $folder)) {
+
+				my ($type, $value);
+				if ($folder->QueryValueEx("My Music", $type, $value)) {
+					$path = $value;
+				} elsif ($folder->QueryValueEx("Personal", $type, $value)) {
+					$path = $value . '\\My Music';
+				}
+			}
+		}
+	}
+
+	if ($path && -d $path) {
+		return $path;
+	} else {
+		return '';
+	}
+}
+
+sub defaultPlaylistDir {
+	my $path;
+
+	if (Slim::Utils::OSDetect::OS() eq 'mac') {
+
+		$path = $ENV{'HOME'} . '/Music/Playlists';
+
+	} elsif (Slim::Utils::OSDetect::OS() eq 'win') {
+
+		$path = $Bin . '/Playlists';
+
+	} else {
+
+		$path = '';
+	}
+
+	if ($path) {
+
+		# We've seen people have the defaultPlayListDir be a file. So
+		# change the path slightly to allow for that.
+		if (-f $path) {
+			$path .= 'SlimServer';
+		}
+
+		if (!-d $path) {
+			mkpath($path) or msg("Couldn't create playlist path: $path - $!\n");
+		}
+	}
+
+	return $path;
+}
+
+sub defaultCacheDir {
+	my $CacheDir = catdir($Bin,'Cache');
+
+	my $os = Slim::Utils::OSDetect::OS();
+
+	if ($os eq 'mac') {
+
+		$CacheDir = catdir($ENV{'HOME'}, '/Library/Caches/SlimServer');
+
+	} elsif ($os eq 'unix') {
+
+		$CacheDir = catdir($ENV{'HOME'},'Cache');
+	}
+
+	my @CacheDirs = splitdir($CacheDir);
+	pop @CacheDirs;
+
+	my $CacheParent = catdir(@CacheDirs);
+
+	if ((!-e $CacheDir && !-w $CacheParent) || (-e $CacheDir && !-w $CacheDir)) {
+		$CacheDir = undef;
+	}
+
+	return $CacheDir;
+}
+
+sub makeCacheDir {
+	my $cacheDir = $prefs->get('cachedir') || defaultCacheDir();
+
+	if (defined $cacheDir && !-d $cacheDir) {
+
+		mkpath($cacheDir) or do {
+
+			logBacktrace("Couldn't create cache dir for $cacheDir : $!");
+			return;
+		};
+	}
+}
+
+sub homeURL {
+	my $host = $main::httpaddr || Slim::Utils::Network::hostname() || '127.0.0.1';
+	my $port = $prefs->get('httpport');
+
+	return "http://$host:$port/";
+}
+
+sub maxRate {
+	my $client   = shift || return 0;
+	my $soloRate = shift;
+
+	# The default for a new client will be undef.
+	my $rate     = $prefs->client($client)->get('maxBitrate');
+
+	if (!defined $rate) {
+
+		# Possibly the first time this pref has been accessed
+		# if maxBitrate hasn't been set yet, allow wired squeezeboxen and ALL SB2's to default to no limit, others to 320kbps
+		if ($client->isa("Slim::Player::Squeezebox2")) {
+
+			$rate = 0;
+
+		} elsif ($client->isa("Slim::Player::Squeezebox") && !defined $client->signalStrength()) {
+
+			$rate = 0;
+
+		} else {
+
+			$rate = 320;
+		}
+	}
+
+	# override the saved or default bitrate if a transcodeBitrate has been set via HTTP parameter
+	$rate = $prefs->client($client)->get('transcodeBitrate') || $rate;
+
+	if ($soloRate) {
+		return $rate;
+	}
+
+	if ($rate != 0) {
+		logger('player.source')->debug(sprintf("Setting maxBitRate for %s to: %d", $client->name, $rate));
+	}
+	
+	# if we're the master, make sure we return the lowest common denominator bitrate.
+	my @playergroup = ($client, Slim::Player::Sync::syncedWith($client));
+	
+	for my $everyclient (@playergroup) {
+
+		if ($prefs->client($client)->get('silent')) {
+			next;
+		}
+
+		my $otherRate = maxRate($everyclient, 1);
+		
+		# find the lowest bitrate limit of the sync group. Zero refers to no limit.
+		$rate = ($otherRate && (($rate && $otherRate < $rate) || !$rate)) ? $otherRate : $rate;
+	}
+
+	# return lowest bitrate limit.
+	return $rate;
+}
+
 1;
 
 __END__
-
-# Local Variables:
-# tab-width:4
-# indent-tabs-mode:t
-# End:

Modified: trunk/server/scanner.pl
URL: http://svn.slimdevices.com/trunk/server/scanner.pl?rev=12194&r1=12193&r2=12194&view=diff
==============================================================================
--- trunk/server/scanner.pl (original)
+++ trunk/server/scanner.pl Sat Jun  2 04:33:53 2007
@@ -232,11 +232,6 @@
 	$log->info("SlimServer settings init...");
 
 	Slim::Utils::Prefs::init();
-	Slim::Utils::Prefs::load($::prefsFile);
-
-#	Slim::Utils::Prefs::set('prefsWriteDelay', 0);
-
-	Slim::Utils::Prefs::checkServerPrefs();
 
 	Slim::Utils::Prefs::makeCacheDir();	
 

Modified: trunk/server/slimserver.pl
URL: http://svn.slimdevices.com/trunk/server/slimserver.pl?rev=12194&r1=12193&r2=12194&view=diff
==============================================================================
--- trunk/server/slimserver.pl (original)
+++ trunk/server/slimserver.pl Sat Jun  2 04:33:53 2007
@@ -580,9 +580,6 @@
 
 	Slim::Utils::Prefs::init();
 
-	Slim::Utils::Prefs::load($prefsfile, $nosetup || $noserver);
-	Slim::Utils::Prefs::checkServerPrefs();
-
 	# options override existing preferences
 	if (defined($audiodir)) {
 		$prefs->set('audiodir', $audiodir);
@@ -859,10 +856,6 @@
 
 	Slim::Utils::PluginManager->shutdownPlugins();
 
-	if (Slim::Utils::Prefs::writePending()) {
-		Slim::Utils::Prefs::writePrefs();
-	}
-
 	Slim::Utils::Prefs::writeAll();
 
 	Slim::Networking::mDNS->stopAdvertising;



More information about the checkins mailing list