From 79ca59df627660d635a9373bfeb293592c173793 Mon Sep 17 00:00:00 2001 From: Karl 'vollmerk' Vollmer Date: Fri, 28 Sep 2007 04:34:02 +0000 Subject: fixed some localplay issues, now correctly shows the active instance at least for the MPD module --- lib/class/localplay.abstract.php | 2 +- lib/class/localplay.class.php | 22 ++++++++++++++++++++++ lib/class/user.class.php | 15 +++++++-------- lib/ui.lib.php | 9 +-------- modules/localplay/mpd.controller.php | 8 +++++--- server/localplay.ajax.php | 11 ++++++++++- templates/sidebar_localplay.inc.php | 17 ++++++++++++++--- themes/classic/templates/default.css | 8 ++++++-- 8 files changed, 66 insertions(+), 26 deletions(-) diff --git a/lib/class/localplay.abstract.php b/lib/class/localplay.abstract.php index d66750a7..12df43cb 100644 --- a/lib/class/localplay.abstract.php +++ b/lib/class/localplay.abstract.php @@ -60,7 +60,7 @@ abstract class localplay_controller { case 'radio': case 'song': default: - $url = $object->get_url(Stream::$session); + $url = $object->get_url(Stream::get_session()); break; } // end switch on objecttype diff --git a/lib/class/localplay.class.php b/lib/class/localplay.class.php index c5b16fd3..dc367b28 100644 --- a/lib/class/localplay.class.php +++ b/lib/class/localplay.class.php @@ -543,6 +543,18 @@ class Localplay { } // get_instances + /** + * current_instance + * This returns the UID of the current Instance + */ + public function current_instance() { + + $data = $this->_player->get_instance(); + + return $data['id']; + + } // current_instance + /** * add_instance * This adds a new instance for the current controller type @@ -553,6 +565,16 @@ class Localplay { } // add_instance + /** + * set_active_instance + * This sets the active instance of the localplay controller + */ + public function set_active_instance($instance) { + + $this->_player->set_active_instance($instance); + + } // set_active_instance + /** * delete * This removes songs from the players playlist as defined get function diff --git a/lib/class/user.class.php b/lib/class/user.class.php index 9ecc247a..2fc8412e 100644 --- a/lib/class/user.class.php +++ b/lib/class/user.class.php @@ -56,7 +56,7 @@ class User { $this->$key = $value; } - // Set the preferences for thsi user + // Set the preferences for this user $this->set_preferences(); // Make sure the Full name is always filled @@ -157,12 +157,11 @@ class User { } // get_preferences - /*! - @function set_preferences - @discussion sets the prefs for this specific - user - */ - function set_preferences() { + /** + * set_preferences + * sets the prefs for this specific user + */ + public function set_preferences() { $sql = "SELECT preference.name,user_preference.value FROM preference,user_preference WHERE user_preference.user='$this->id' " . "AND user_preference.preference=preference.id AND preference.type != 'system'"; @@ -172,7 +171,7 @@ class User { $key = $r['name']; $this->prefs[$key] = $r['value']; } - } // get_preferences + } // set_preferences /** * get_favorites diff --git a/lib/ui.lib.php b/lib/ui.lib.php index d0ae5bcb..859f90f3 100644 --- a/lib/ui.lib.php +++ b/lib/ui.lib.php @@ -130,11 +130,8 @@ function show_alphabet_list () { $list = array(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,1,2,3,4,5,6,7,8,9,"0",_('All')); - $selected = $_SESSION['browse']['filter']['alpha_match']; + $selected = $_SESSION['browse']['filter']['alpha_match']; - //$style_name = "style_" . strtolower($selected); - //${$style_name} = "style=\"font-weight:bold;\""; - echo "
"; foreach ($list as $l) { $style_name = "style_" . strtolower($l); @@ -142,10 +139,6 @@ function show_alphabet_list () { if ($l==$selected) $class .=" active"; echo "" . $l . "\n"; - /* without this, it also works and breaks line when needed only - $i++; - if ($i/5 == intval($i/5)) { echo "
"; } - */ } echo "
"; diff --git a/modules/localplay/mpd.controller.php b/modules/localplay/mpd.controller.php index afdd4442..4b3c953f 100644 --- a/modules/localplay/mpd.controller.php +++ b/modules/localplay/mpd.controller.php @@ -180,9 +180,11 @@ class AmpacheMpd extends localplay_controller { /** * get_instance * This returns the specified instance and all it's pretty variables + * If no instance is passed current is used */ - private function get_instance($instance) { + public function get_instance($instance='') { + $instance = $instance ? $instance : $GLOBALS['user']->prefs['mpd_active']; $instance = Dba::escape($instance); $sql = "SELECT * FROM `localplay_mpd` WHERE `id`='$instance'"; @@ -223,7 +225,7 @@ class AmpacheMpd extends localplay_controller { $user_id = $user_id ? $user_id : $GLOBALS['user']->id; - Preference::update('mpd_instance',$user_id,intval($uid)); + Preference::update('mpd_active',$user_id,intval($uid)); return true; @@ -522,7 +524,7 @@ class AmpacheMpd extends localplay_controller { public function connect() { // Look at the current instance and pull the options for said instance - $options = self::get_instance($GLOBALS['user']->prefs['mpd_active']); + $options = self::get_instance(); $this->_mpd = new mpd($options['host'],$options['port'],$options['password']); if ($this->_mpd->connected) { return true; } diff --git a/server/localplay.ajax.php b/server/localplay.ajax.php index 78142b18..5cc048f2 100644 --- a/server/localplay.ajax.php +++ b/server/localplay.ajax.php @@ -31,9 +31,18 @@ switch ($_REQUEST['action']) { $type = $_REQUEST['instance'] ? 'localplay' : 'stream'; - Preference::update('mpd_active',$GLOBALS['user']->id,$_REQUEST['instance']); + $localplay = new Localplay($GLOBALS['user']->prefs['localplay_controller']); + $localplay->set_active_instance($_REQUEST['instance']); Preference::update('play_type',$GLOBALS['user']->id,$type); + // Now reload the preferences into the user object + $GLOBALS['user']->set_preferences(); + + // We should also refesh the sidebar + ob_start(); + require_once Config::get('prefix') . '/templates/sidebar.inc.php'; + $results['sidebar'] = ob_get_contents(); + ob_end_clean(); break; default: $results['rfc3514'] = '0x1'; diff --git a/templates/sidebar_localplay.inc.php b/templates/sidebar_localplay.inc.php index 7525fd7f..eb24c2e4 100644 --- a/templates/sidebar_localplay.inc.php +++ b/templates/sidebar_localplay.inc.php @@ -1,22 +1,33 @@ +prefs['localplay_controller']); + $current_instance = $localplay->current_instance(); + $class = $current_instance ? '' : ' class="active_instance"'; +?>