Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Spotimcgui: Views: Playlist List: Add context actions for playlists.

  • Loading branch information...
commit daeaf5ac33145cfb7d26cd6b6b4d97bf705c2e70 1 parent 872f83f
@mazkolain authored
View
119 resources/libs/spotimcgui/views/playlists/list.py
@@ -32,6 +32,10 @@ class PlaylistView(BaseListContainerView):
container_id = 1700
list_id = 1701
+ context_menu_id = 5700
+ context_play_playlist = 5702
+ context_set_current = 5703
+
__starred_loader = None
__inbox_loader = None
__container_loader = None
@@ -56,59 +60,80 @@ def __init__(self, session, container, playlist_manager):
)
+ def _get_playlist_loader(self, playlist_id):
+ if playlist_id == 'starred':
+ return self.__starred_loader
+
+ elif playlist_id == 'inbox':
+ return self.__inbox_loader
+
+ else:
+ return self.__container_loader.playlist(int(playlist_id))
+
+
+ def _show_selected_playlist(self, view_manager):
+ item = self.get_list(view_manager).getSelectedItem()
+ playlist_id = item.getProperty('PlaylistId')
+ session = view_manager.get_var('session')
+ pm = view_manager.get_var('playlist_manager')
+ loader_obj = self._get_playlist_loader(playlist_id)
+
+ #Special treatment for starred & inbox
+ if playlist_id in ['starred', 'inbox']:
+ loader_obj = self.__starred_loader
+ view_obj = detail.SpecialPlaylistDetailView(
+ session, loader_obj.get_playlist(), pm,
+ loader_obj.get_name(), loader_obj.get_thumbnails()
+ )
+
+ else:
+ view_obj = detail.PlaylistDetailView(
+ session, loader_obj.get_playlist(), pm
+ )
+
+ view_manager.add_view(view_obj)
+
+
+ def _start_playlist_playback(self, view_manager):
+ item = self.get_list(view_manager).getSelectedItem()
+ playlist_id = item.getProperty('PlaylistId')
+ track_list = self._get_playlist_loader(playlist_id).get_tracks()
+ session = view_manager.get_var('session')
+ playlist_manager = view_manager.get_var('playlist_manager')
+ playlist_manager.play(track_list, session)
+
+
+ def _set_current_playlist(self, view_manager):
+ item = self.get_list(view_manager).getSelectedItem()
+ playlist_id = item.getProperty('PlaylistId')
+ track_list = self._get_playlist_loader(playlist_id).get_tracks()
+ playlist_manager = view_manager.get_var('playlist_manager')
+ session = view_manager.get_var('session')
+ playlist_manager.set_tracks(track_list, session)
+
+
def click(self, view_manager, control_id):
if control_id == PlaylistView.list_id:
- item = self.get_list(view_manager).getSelectedItem()
- playlist_id = item.getProperty('PlaylistId')
- session = view_manager.get_var('session')
- pm = view_manager.get_var('playlist_manager')
-
- if playlist_id == 'starred':
- loader_obj = self.__starred_loader
- view_obj = detail.SpecialPlaylistDetailView(
- session, loader_obj.get_playlist(), pm,
- loader_obj.get_name(), loader_obj.get_thumbnails()
- )
-
- elif playlist_id == 'inbox':
- loader_obj = self.__inbox_loader
- view_obj = detail.SpecialPlaylistDetailView(
- session, loader_obj.get_playlist(), pm,
- loader_obj.get_name(), loader_obj.get_thumbnails()
- )
-
- else:
- loader_obj = self.__container_loader.playlist(int(playlist_id))
- view_obj = detail.PlaylistDetailView(
- session, loader_obj.get_playlist(), pm
- )
-
- view_manager.add_view(view_obj)
+ self._show_selected_playlist(view_manager)
+
+ elif control_id == PlaylistView.context_play_playlist:
+ self._start_playlist_playback(view_manager)
+ view_manager.get_window().setFocus(self.get_container(view_manager))
+
+ elif control_id == PlaylistView.context_set_current:
+ self._set_current_playlist(view_manager)
+ view_manager.get_window().setFocus(self.get_container(view_manager))
def action(self, view_manager, action_id):
+ #Run parent implementation's actions
+ BaseListContainerView.action(self, view_manager, action_id)
+
playlist_manager = view_manager.get_var('playlist_manager')
#Do nothing if playing, as it may result counterproductive
- if not playlist_manager.is_playing():
- if action_id == 79:
- item = self.get_list(view_manager).getSelectedItem()
- playlist_id = item.getProperty('PlaylistId')
-
- #Get the playlist's tracks
- if playlist_id == 'starred':
- track_list = self.__starred_loader.get_tracks()
-
- elif playlist_id == 'inbox':
- track_list = self.__inbox_loader.get_tracks()
-
- else:
- index = int(playlist_id)
- loader_obj = self.__container_loader.playlist(index)
- track_list = loader_obj.get_tracks()
-
- session = view_manager.get_var('session')
- playlist_manager.play(track_list, session)
+ if action_id == 79 and not playlist_manager.is_playing():
+ self._start_playlist_playback(view_manager)
def get_container(self, view_manager):
@@ -119,6 +144,10 @@ def get_list(self, view_manager):
return view_manager.get_window().getControl(PlaylistView.list_id)
+ def get_context_menu_id(self):
+ return PlaylistView.context_menu_id
+
+
def _add_playlist(self, list, key, loader, show_owner):
item = xbmcgui.ListItem()
item.setProperty("PlaylistId", str(key))
View
29 resources/skins/DefaultSkin/720p/main-window.xml
@@ -1173,6 +1173,7 @@
Control.IsVisible(1200) |
Control.IsVisible(1300) |
Control.IsVisible(1500) |
+ Control.IsVisible(1700) |
Control.IsVisible(1800) |
Control.IsVisible(6000)
</visible>
@@ -1382,6 +1383,34 @@
</control>
+ <!-- Album tracks browsing options -->
+ <control type="grouplist" id="5700">
+ <include>spotimc_leftmenu_grouplist</include>
+ <description>Playlist options</description>
+ <onright>1700</onright>
+ <visible>Control.IsVisible(1700)</visible>
+
+ <control type="label" id="5701">
+ <include>spotimc_leftmenu_label</include>
+ <label>Selected playlist:</label>
+ </control>
+
+ <control type="button" id="5702">
+ <include>spotimc_leftmenu_button</include>
+ <description></description>
+ <label>Play</label>
+ <visible>True</visible>
+ </control>
+
+ <control type="button" id="5703">
+ <include>spotimc_leftmenu_button</include>
+ <description></description>
+ <label>Set current</label>
+ <visible>Player.Playing | Player.Paused</visible>
+ </control>
+ </control>
+
+
<!-- Playlist options -->
<control type="grouplist" id="5800">
<include>spotimc_leftmenu_grouplist</include>
Please sign in to comment.
Something went wrong with that request. Please try again.