Permalink
Browse files

use separate sort and sort order buttons for album and artist views a…

…nd connect signals for these buttons to sort independently
  • Loading branch information...
1 parent c0edd48 commit 161997c0d022611b7910d418242b9d0f67cf73c8 @fossfreedom committed Jan 8, 2014
View
@@ -1741,6 +1741,12 @@ class AlbumManager(GObject.Object):
# properties
progress = GObject.property(type=float, default=0)
+
+ # signals
+ __gsignals__ = {
+ 'sort': (GObject.SIGNAL_RUN_LAST, None, (object,))
+ }
+
def __init__(self, plugin, current_view):
super(AlbumManager, self).__init__()
@@ -1768,6 +1774,10 @@ def _connect_signals(self):
# connect signal to the loader so it shows the albums when it finishes
self._load_finished_id = self.loader.connect('model-load-finished',
self._load_finished_callback)
+ self.connect('sort', self._sort_album)
+
+ def _sort_album(self, widget, direction):
+ self.model.sort(reverse=direction)
def _load_finished_callback(self, *args):
self.artist_man.loader.load_artists()
View
@@ -507,6 +507,10 @@ def show(self, artist_name, show):
if self._tree_store.iter_is_valid(artist_iter):
self._tree_store.set_value(artist_iter, self.columns['show'], show)
+
+
+ def sort(self, reverse=False):
+ pass
class ArtistCellRenderer(Gtk.CellRendererPixbuf):
@@ -663,6 +667,11 @@ class ArtistManager(GObject.Object):
# properties
progress = GObject.property(type=float, default=0)
+ # signals
+ __gsignals__ = {
+ 'sort': (GObject.SIGNAL_RUN_LAST, None, (object,))
+ }
+
def __init__(self, plugin, album_manager, shell):
super(ArtistManager, self).__init__()
@@ -684,6 +693,10 @@ def _connect_signals(self):
Connects the manager to all the needed signals for it to work.
'''
self.loader.connect('model-load-finished', self._load_finished_callback)
+ self.connect('sort', self._sort_artist)
+
+ def _sort_artist(self, widget, direction):
+ self.model.sort(reverse=direction)
def _load_finished_callback(self, *args):
self.cover_man.load_covers()
@@ -1018,6 +1031,8 @@ def switch_to_view(self, source, album):
def do_update_toolbar(self, *args):
self.source.toolbar_manager.set_enabled(False, ToolbarObject.SORT_BY)
self.source.toolbar_manager.set_enabled(False, ToolbarObject.SORT_ORDER)
+ self.source.toolbar_manager.set_enabled(True, ToolbarObject.SORT_BY_ARTIST)
+ self.source.toolbar_manager.set_enabled(True, ToolbarObject.SORT_ORDER_ARTIST)
def on_drag_drop(self, widget, context, x, y, time):
'''
@@ -142,6 +142,8 @@ def __init__(self):
PANED_POSITION='paned-position',
SORT_BY='sort-by',
SORT_ORDER='sort-order',
+ SORT_BY_ARTIST='sort-by-artist',
+ SORT_ORDER_ARTIST='sort-order-artist',
RATING='rating-threshold',
AUTOSTART='autostart',
TOOLBAR_POS='toolbar-pos',
View
@@ -275,12 +275,7 @@ def _setup_source(self):
# create an album manager
self.album_manager = AlbumManager(self.plugin, self.viewmgr.current_view)
- # initialise the toolbar manager
- self.toolbar_manager = ToolbarManager(self.plugin, self.page,
- self.album_manager.model, self.viewmgr)
-
self.viewmgr.current_view.initialise(self)
- self.viewmgr.current_view.emit('update-toolbar')
# setup cover search pane
colour = self.viewmgr.get_selection_colour()
@@ -323,6 +318,11 @@ def _setup_source(self):
self.artist_paned.connect('button-release-event',
self.artist_paned_button_release_callback)
+
+ # initialise the toolbar manager
+ self.toolbar_manager = ToolbarManager(self.plugin, self.page,
+ self.viewmgr)
+ self.viewmgr.current_view.emit('update-toolbar')
print("CoverArtBrowser DEBUG - end _setup_source")
@@ -980,11 +980,15 @@ def __init__(self, shell):
cl = CoverLocale()
cl.switch_locale(cl.Locale.LOCALE_DOMAIN)
- self._values[CoverIconView.name] = [_('Tiles'), GLib.Variant.new_string('coverart-browser-tile')]
+ self._values[CoverIconView.name] = [_('Tiles'),
+ GLib.Variant.new_string('coverart-browser-tile')]
if webkit_support():
- self._values[CoverFlowView.name] = [_('Flow'), GLib.Variant.new_string('coverart-browser-coverflow')]
- self._values[ArtistView.name] = [_('Artist'), GLib.Variant.new_string('coverart-browser-artist')]
- self._values[ListView.name] = [library_name, GLib.Variant.new_string('coverart-browser-list')]
+ self._values[CoverFlowView.name] = [_('Flow'),
+ GLib.Variant.new_string('coverart-browser-coverflow')]
+ self._values[ArtistView.name] = [_('Artist'),
+ GLib.Variant.new_string('coverart-browser-artist')]
+ self._values[ListView.name] = [library_name,
+ GLib.Variant.new_string('coverart-browser-list')]
cl.switch_locale(cl.Locale.RB)
print (self._values)
@@ -1052,10 +1056,7 @@ def __init__(self, source, window):
self._lastview = None
self.controller = ViewController(source.shell, self)
- #self.controller.add_key_pair(CoverFlowView.name, 'flowview_button')
- #self.controller.add_key_pair(CoverIconView.name, 'iconview_button')
- #self.controller.add_key_pair(ArtistView.name, 'artistview_button')
-
+
# connect signal and properties
self._connect_signals()
self._connect_properties()
View
@@ -377,10 +377,10 @@ def get_current_description(self):
class SortPopupController(OptionsController):
- def __init__(self, plugin, album_model):
+ def __init__(self, plugin, viewmgr):
super(SortPopupController, self).__init__()
- self._album_model = album_model
+ self._viewmgr=viewmgr
self.plugin = plugin
# sorts dictionary
cl = CoverLocale()
@@ -418,11 +418,60 @@ def do_action(self):
settings = gs.get_setting(gs.Path.PLUGIN)
settings[gs.PluginKey.SORT_BY] = sort
- self._album_model.sort(sort)
+ self._viewmgr.current_view.get_default_manager().emit('sort', False)
def get_current_image(self):
sort = self.values[self.current_key]
return self._spritesheet[sort]
+
+class ArtistSortPopupController(OptionsController):
+
+ def __init__(self, plugin, viewmgr):
+ super(ArtistSortPopupController, self).__init__()
+
+ self._viewmgr = viewmgr
+ self.plugin = plugin
+ # sorts dictionary
+ cl = CoverLocale()
+ cl.switch_locale(cl.Locale.LOCALE_DOMAIN)
+
+ self.values = OrderedDict([(_('Sort by album name'), 'name'),
+ (_('Sort by year'), 'year'),
+ (_('Sort by rating'), 'rating')])
+
+ self.options = list(self.values.keys())
+
+ # get the current sort key and initialise the superclass
+ gs = GSetting()
+ source_settings = gs.get_setting(gs.Path.PLUGIN)
+ value = source_settings[gs.PluginKey.SORT_BY_ARTIST]
+
+ self._spritesheet = None
+ self.update_images(False)
+
+ self.current_key = list(self.values.keys())[
+ list(self.values.values()).index(value)]
+
+ def update_images(self, *args):
+ self._spritesheet = self.create_spritesheet( self.plugin,
+ self._spritesheet, 'sort') # need the "artist_sort_sprite" file
+
+ if args[-1]:
+ self.update_image = True
+
+ def do_action(self):
+ sort = self.values[self.current_key]
+
+ gs = GSetting()
+ settings = gs.get_setting(gs.Path.PLUGIN)
+ settings[gs.PluginKey.SORT_BY_ARTIST] = sort
+
+ self._viewmgr.current_view.get_default_manager().emit('sort', False)
+
+ def get_current_image(self):
+ sort = self.values[self.current_key]
+ return self._spritesheet[sort]
+
class PropertiesMenuController(OptionsController):
artist_paned_display = GObject.property(type=bool, default=False)
@@ -584,12 +633,12 @@ def get_current_description(self):
class SortOrderToggleController(OptionsController):
- def __init__(self, plugin, album_model):
+ def __init__(self, plugin, viewmgr):
super(SortOrderToggleController, self).__init__()
- self._album_model = album_model
+ self._viewmgr = viewmgr
self.plugin = plugin
-
+
# options
self.values = OrderedDict([(_('Sort in descending order'), False),
(_('Sort in ascending order'), True)])
@@ -600,11 +649,15 @@ def __init__(self, plugin, album_model):
# set the current key
self.gs = GSetting()
self.settings = self.gs.get_setting(self.gs.Path.PLUGIN)
- sort_order = self.settings[self.gs.PluginKey.SORT_ORDER]
+ self.key = self.get_key()
+ sort_order = self.settings[self.key]
self.current_key = list(self.values.keys())[
list(self.values.values()).index(sort_order)]
self.update_images(False)
+ def get_key(self):
+ return self.gs.PluginKey.SORT_ORDER
+
def update_images(self, *args):
# initialize images
if len(self._images) > 0:
@@ -622,13 +675,21 @@ def do_action(self):
sort_order = self.values[self.current_key]
if not sort_order or\
- sort_order != self.settings[self.gs.PluginKey.SORT_ORDER]:
- self._album_model.sort(reverse=True)
+ sort_order != self.settings[self.key]:
+ self._viewmgr.current_view.get_default_manager().emit('sort', True) #(reverse=True)
- self.settings[self.gs.PluginKey.SORT_ORDER] = sort_order
+ self.settings[self.key] = sort_order
def get_current_image(self):
return self._images[self.get_current_key_index()]
+
+class ArtistSortOrderToggleController(SortOrderToggleController):
+
+ def __init__(self, plugin, model):
+ super(ArtistSortOrderToggleController, self).__init__(plugin, model)
+
+ def get_key(self):
+ return self.gs.PluginKey.SORT_ORDER_ARTIST
class AlbumSearchEntryController(OptionsController):
View
@@ -28,9 +28,11 @@
from coverart_controllers import PlaylistPopupController
from coverart_controllers import GenrePopupController
from coverart_controllers import SortPopupController
+from coverart_controllers import ArtistSortPopupController
from coverart_controllers import PropertiesMenuController
from coverart_controllers import DecadePopupController
from coverart_controllers import SortOrderToggleController
+from coverart_controllers import ArtistSortOrderToggleController
from coverart_controllers import AlbumSearchEntryController
from coverart_widgets import SearchEntry
from coverart_browser_prefs import webkit_support
@@ -142,25 +144,24 @@ class ToolbarObject(object):
PROPERTIES='properties_button'
SORT_BY='sort_by'
SORT_ORDER='sort_order'
+ SORT_BY_ARTIST='sort_by_artist'
+ SORT_ORDER_ARTIST='sort_order_artist'
GENRE='genre_button'
PLAYLIST='playlist_button'
DECADE='decade_button'
SEARCH='search'
- #ICONVIEW='iconview_button'
- #FLOWVIEW='flowview_button'
- #ARTISTVIEW='artistview_button'
VIEW='view_button'
class ToolbarManager(GObject.Object):
# properties
toolbar_pos = GObject.property(type=str, default=TopToolbar.name)
- def __init__(self, plugin, main_box, album_model, viewmgr):
+ def __init__(self, plugin, main_box, viewmgr):
super(ToolbarManager, self).__init__()
self.plugin = plugin
# create the buttons controllers
- controllers = self._create_controllers(plugin, album_model, viewmgr)
+ controllers = self._create_controllers(plugin, viewmgr)
# initialize toolbars
self._bars = {}
@@ -202,15 +203,20 @@ def _connect_properties(self):
setting.bind(gs.PluginKey.TOOLBAR_POS, self, 'toolbar_pos',
Gio.SettingsBindFlags.GET)
- def _create_controllers(self, plugin, album_model, viewmgr):
+ def _create_controllers(self, plugin, viewmgr):
controllers = {}
+ album_model=viewmgr.source.album_manager.model
controllers[ToolbarObject.PROPERTIES] = \
PropertiesMenuController(plugin, viewmgr.source)
controllers[ToolbarObject.SORT_BY] = \
- SortPopupController(plugin, album_model)
+ SortPopupController(plugin, viewmgr)
controllers[ToolbarObject.SORT_ORDER] = \
- SortOrderToggleController(plugin, album_model)
+ SortOrderToggleController(plugin, viewmgr)
+ controllers[ToolbarObject.SORT_BY_ARTIST] = \
+ ArtistSortPopupController(plugin, viewmgr)
+ controllers[ToolbarObject.SORT_ORDER_ARTIST] = \
+ ArtistSortOrderToggleController(plugin, viewmgr)
controllers[ToolbarObject.GENRE] = \
GenrePopupController(plugin, album_model)
controllers[ToolbarObject.PLAYLIST] = \
@@ -220,9 +226,6 @@ def _create_controllers(self, plugin, album_model, viewmgr):
controllers[ToolbarObject.SEARCH] = \
AlbumSearchEntryController(album_model)
- #controllers[ToolbarObject.ICONVIEW] = viewmgr.controller
- #controllers[ToolbarObject.FLOWVIEW] = viewmgr.controller
- #controllers[ToolbarObject.ARTISTVIEW] = viewmgr.controller
controllers[ToolbarObject.VIEW] = viewmgr.controller
return controllers
View
@@ -23,6 +23,7 @@
from gi.repository import GLib
from gi.repository import GObject
from gi.repository import Gio
+
import cairo
from coverart_browser_prefs import GSetting
@@ -58,16 +59,15 @@ def controller(self, controller):
'notify::current-key', self._update_current_key)
self._update_image_changed_id = self._controller.connect(
'notify::update-image', self._update_image)
- self._sensitive_changed_id = self._controller.connect(
- 'notify::enabled', self._update_sensitivity)
+ self._visible_changed_id = self._controller.connect(
+ 'notify::enabled', self._update_visibility)
# update the menu and current key
self.update_options()
self.update_current_key()
- def _update_sensitivity(self, *args):
- self.set_sensitive(self._controller.enabled)
- #self._update_image()
+ def _update_visibility(self, *args):
+ self.set_visible(self._controller.enabled)
def _update_options(self, *args):
self.update_options()
@@ -1276,7 +1276,11 @@ def do_update_toolbar(self, *args):
called when update-toolbar signal is emitted
by default the toolbar objects are made visible
'''
- self.source.toolbar_manager.set_enabled(True)
+ from coverart_toolbar import ToolbarObject
+ self.source.toolbar_manager.set_enabled(True, ToolbarObject.SORT_BY)
+ self.source.toolbar_manager.set_enabled(True, ToolbarObject.SORT_ORDER)
+ self.source.toolbar_manager.set_enabled(False, ToolbarObject.SORT_BY_ARTIST)
+ self.source.toolbar_manager.set_enabled(False, ToolbarObject.SORT_ORDER_ARTIST)
def resize_icon(self, cover_size):
'''
Oops, something went wrong.

0 comments on commit 161997c

Please sign in to comment.