| 1 |
# Copyright (C) 2008-2010 Adam Olsen |
| 2 |
# |
| 3 |
# This program is free software; you can redistribute it and/or modify |
| 4 |
# it under the terms of the GNU General Public License as published by |
| 5 |
# the Free Software Foundation; either version 2, or (at your option) |
| 6 |
# any later version. |
| 7 |
# |
| 8 |
# This program is distributed in the hope that it will be useful, |
| 9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 |
# GNU General Public License for more details. |
| 12 |
# |
| 13 |
# You should have received a copy of the GNU General Public License |
| 14 |
# along with this program; if not, write to the Free Software |
| 15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 16 |
# |
| 17 |
# |
| 18 |
# The developers of the Exaile media player hereby grant permission |
| 19 |
# for non-GPL compatible GStreamer and Exaile plugins to be used and |
| 20 |
# distributed together with GStreamer and Exaile. This permission is |
| 21 |
# above and beyond the permissions granted by the GPL license by which |
| 22 |
# Exaile is covered. If you modify this code, you may extend this |
| 23 |
# exception to your version of the code, but you are not obligated to |
| 24 |
# do so. If you do not wish to do so, delete this exception statement |
| 25 |
# from your version. |
| 26 |
|
| 27 |
from xlgui.preferences import widgets |
| 28 |
from xl import common, xdg |
| 29 |
from xl.nls import gettext as _ |
| 30 |
|
| 31 |
# TODO: If we ever add another engine, need to make sure that |
| 32 |
# gstreamer-specific stuff doesn't accidentally get loaded |
| 33 |
from xl.player.gst.sink import get_devices, SINK_PRESETS |
| 34 |
|
| 35 |
name = _('Playback') |
| 36 |
icon = 'media-playback-start' |
| 37 |
ui = xdg.get_data_path('ui', 'preferences', 'playback.ui') |
| 38 |
|
| 39 |
|
| 40 |
class EnginePreference(widgets.ComboPreference): |
| 41 |
default = "gstreamer" |
| 42 |
name = 'player/engine' |
| 43 |
restart_required = True |
| 44 |
|
| 45 |
|
| 46 |
class AudioSinkPreference(widgets.ComboPreference): |
| 47 |
default = "auto" |
| 48 |
name = 'player/audiosink' |
| 49 |
|
| 50 |
def __init__(self, preferences, widget): |
| 51 |
widgets.ComboPreference.__init__(self, preferences, widget) |
| 52 |
model = self.widget.get_model() |
| 53 |
|
| 54 |
# always list auto first, custom last |
| 55 |
def keyfunc(item): |
| 56 |
name = item[0] |
| 57 |
if name == 'auto': |
| 58 |
return common.LowestStr(name) |
| 59 |
elif name == 'custom': |
| 60 |
return common.HighestStr(name) |
| 61 |
else: |
| 62 |
return name |
| 63 |
|
| 64 |
for name, preset in sorted(SINK_PRESETS.items(), key=keyfunc): |
| 65 |
model.append((name, preset['name'])) |
| 66 |
self._set_value() |
| 67 |
|
| 68 |
|
| 69 |
class CustomAudioSinkPreference(widgets.Preference, widgets.Conditional): |
| 70 |
default = "" |
| 71 |
name = "player/custom_sink_pipe" |
| 72 |
condition_preference_name = 'player/audiosink' |
| 73 |
|
| 74 |
def __init__(self, preferences, widget): |
| 75 |
widgets.Preference.__init__(self, preferences, widget) |
| 76 |
widgets.Conditional.__init__(self) |
| 77 |
|
| 78 |
def on_check_condition(self): |
| 79 |
return self.get_condition_value() == 'custom' |
| 80 |
|
| 81 |
def on_condition_met(self): |
| 82 |
self.show_widget() |
| 83 |
|
| 84 |
def on_condition_failed(self): |
| 85 |
self.hide_widget() |
| 86 |
|
| 87 |
|
| 88 |
class SelectDeviceForSinkPreference(widgets.ComboPreference, widgets.MultiConditional): |
| 89 |
default = 'auto' |
| 90 |
name = "player/audiosink_device" |
| 91 |
condition_preference_names = ['player/audiosink', 'player/show_hidden_devices'] |
| 92 |
|
| 93 |
def __init__(self, preferences, widget): |
| 94 |
self.is_enabled = False |
| 95 |
widgets.ComboPreference.__init__(self, preferences, widget) |
| 96 |
widgets.MultiConditional.__init__(self) |
| 97 |
|
| 98 |
def on_check_condition(self): |
| 99 |
return self.get_condition_value('player/audiosink') == 'auto' |
| 100 |
|
| 101 |
def on_condition_met(self): |
| 102 |
# disable because the clear() causes a settings write |
| 103 |
self.is_enabled = False |
| 104 |
|
| 105 |
model = self.widget.get_model() |
| 106 |
if model is None: |
| 107 |
return |
| 108 |
|
| 109 |
model.clear() |
| 110 |
|
| 111 |
for device_name, device_id, _create_audiosink_cb in get_devices(): |
| 112 |
model.append((device_id, device_name)) |
| 113 |
|
| 114 |
self.is_enabled = True |
| 115 |
self._set_value() |
| 116 |
|
| 117 |
self.show_widget() |
| 118 |
self.set_widget_sensitive(True) |
| 119 |
|
| 120 |
def on_condition_failed(self): |
| 121 |
if self.get_condition_value() == 'custom': |
| 122 |
self.hide_widget() |
| 123 |
else: |
| 124 |
self.show_widget() |
| 125 |
self.set_widget_sensitive(False) |
| 126 |
self.is_enabled = False |
| 127 |
model = self.widget.get_model() |
| 128 |
if model: |
| 129 |
model.clear() |
| 130 |
|
| 131 |
def done(self): |
| 132 |
return self.is_enabled |
| 133 |
|
| 134 |
def _get_value(self): |
| 135 |
if self.is_enabled: |
| 136 |
return widgets.ComboPreference._get_value(self) |
| 137 |
return '' |
| 138 |
|
| 139 |
|
| 140 |
class ShowHiddenDevicesPreference(widgets.CheckPreference, widgets.Conditional): |
| 141 |
default = False |
| 142 |
name = 'player/show_hidden_devices' |
| 143 |
condition_preference_name = 'player/audiosink' |
| 144 |
|
| 145 |
def __init__(self, preferences, widget): |
| 146 |
widgets.CheckPreference.__init__(self, preferences, widget) |
| 147 |
widgets.Conditional.__init__(self) |
| 148 |
|
| 149 |
def on_check_condition(self): |
| 150 |
return self.get_condition_value() == 'auto' |
| 151 |
|
| 152 |
def on_condition_met(self): |
| 153 |
self.show_widget() |
| 154 |
|
| 155 |
def on_condition_failed(self): |
| 156 |
self.hide_widget() |
| 157 |
|
| 158 |
|
| 159 |
class ResumePreference(widgets.CheckPreference): |
| 160 |
default = True |
| 161 |
name = 'player/resume_playback' |
| 162 |
|
| 163 |
|
| 164 |
class PausedPreference(widgets.CheckPreference, widgets.CheckConditional): |
| 165 |
default = False |
| 166 |
name = 'player/resume_paused' |
| 167 |
condition_preference_name = 'player/resume_playback' |
| 168 |
|
| 169 |
def __init__(self, preferences, widget): |
| 170 |
widgets.CheckPreference.__init__(self, preferences, widget) |
| 171 |
widgets.CheckConditional.__init__(self) |
| 172 |
|
| 173 |
|
| 174 |
class EnqueueBeginsPlayback(widgets.CheckPreference): |
| 175 |
default = True |
| 176 |
name = 'queue/enqueue_begins_playback' |
| 177 |
|
| 178 |
|
| 179 |
class RemoveQueuedItemWhenPlayed(widgets.CheckPreference): |
| 180 |
default = True |
| 181 |
name = 'queue/remove_item_when_played' |
| 182 |
|
| 183 |
|
| 184 |
class RemoveQueuedItemAfterPlayed(widgets.CheckPreference, widgets.CheckConditional): |
| 185 |
default = False |
| 186 |
name = 'queue/remove_item_after_played' |
| 187 |
condition_preference_name = 'queue/remove_item_when_played' |
| 188 |
|
| 189 |
def __init__(self, preferences, widget): |
| 190 |
widgets.CheckPreference.__init__(self, preferences, widget) |
| 191 |
widgets.CheckConditional.__init__(self) |
| 192 |
|
| 193 |
|
| 194 |
class DisableNewTrackWhenPlaying(widgets.CheckPreference): |
| 195 |
default = False |
| 196 |
name = 'queue/disable_new_track_when_playing' |
| 197 |
|
| 198 |
|
| 199 |
class GaplessPlayback(widgets.CheckPreference): |
| 200 |
default = True |
| 201 |
name = 'player/gapless_playback' |
| 202 |
|
| 203 |
|
| 204 |
class EngineConditional(widgets.Conditional): |
| 205 |
""" |
| 206 |
True if the specified engine is selected |
| 207 |
""" |
| 208 |
|
| 209 |
condition_preference_name = 'player/engine' |
| 210 |
conditional_engine = '' |
| 211 |
|
| 212 |
def on_check_condition(self): |
| 213 |
if self.get_condition_value() == self.conditional_engine: |
| 214 |
return True |
| 215 |
|
| 216 |
return False |
| 217 |
|
| 218 |
|
| 219 |
class AutoAdvancePlayer(widgets.CheckPreference, EngineConditional): |
| 220 |
default = True |
| 221 |
name = 'player/auto_advance' |
| 222 |
conditional_engine = 'gstreamer' |
| 223 |
|
| 224 |
def __init__(self, preferences, widget): |
| 225 |
widgets.CheckPreference.__init__(self, preferences, widget) |
| 226 |
EngineConditional.__init__(self) |
| 227 |
|
| 228 |
|
| 229 |
class AutoAdvanceDelay(widgets.SpinPreference, widgets.MultiConditional): |
| 230 |
default = 0 |
| 231 |
name = "player/auto_advance_delay" |
| 232 |
condition_preference_names = ['player/auto_advance', 'player/engine'] |
| 233 |
|
| 234 |
def __init__(self, preferences, widget): |
| 235 |
widgets.SpinPreference.__init__(self, preferences, widget) |
| 236 |
widgets.MultiConditional.__init__(self) |
| 237 |
|
| 238 |
def on_check_condition(self): |
| 239 |
if not self.condition_widgets['player/auto_advance'].get_active(): |
| 240 |
return False |
| 241 |
|
| 242 |
if self.get_condition_value('player/engine') == 'gstreamer': |
| 243 |
return True |
| 244 |
|
| 245 |
return False |
| 246 |
|
| 247 |
|
| 248 |
class UserFadeTogglePreference(widgets.CheckPreference, EngineConditional): |
| 249 |
default = False |
| 250 |
name = 'player/user_fade_enabled' |
| 251 |
conditional_engine = 'gstreamer' |
| 252 |
|
| 253 |
def __init__(self, preferences, widget): |
| 254 |
widgets.CheckPreference.__init__(self, preferences, widget) |
| 255 |
EngineConditional.__init__(self) |
| 256 |
|
| 257 |
|
| 258 |
class UserFadeDurationPreference(widgets.SpinPreference, EngineConditional): |
| 259 |
default = 1000 |
| 260 |
name = 'player/user_fade' |
| 261 |
conditional_engine = 'gstreamer' |
| 262 |
|
| 263 |
def __init__(self, preferences, widget): |
| 264 |
widgets.SpinPreference.__init__(self, preferences, widget) |
| 265 |
EngineConditional.__init__(self) |
| 266 |
|
| 267 |
|
| 268 |
class CrossfadingPreference(widgets.CheckPreference, EngineConditional): |
| 269 |
default = False |
| 270 |
name = 'player/crossfading' |
| 271 |
conditional_engine = 'gstreamer' |
| 272 |
|
| 273 |
def __init__(self, preferences, widget): |
| 274 |
widgets.CheckPreference.__init__(self, preferences, widget) |
| 275 |
EngineConditional.__init__(self) |
| 276 |
|
| 277 |
|
| 278 |
class CrossfadeDurationPreference(widgets.SpinPreference, EngineConditional): |
| 279 |
default = 1000 |
| 280 |
name = 'player/crossfade_duration' |
| 281 |
conditional_engine = 'gstreamer' |
| 282 |
|
| 283 |
def __init__(self, preferences, widget): |
| 284 |
widgets.SpinPreference.__init__(self, preferences, widget) |
| 285 |
EngineConditional.__init__(self) |
| 286 |
|
| 287 |
|
| 288 |
# vim: et sts=4 sw=4 |