@@ -262,7 +262,6 @@ def create_icons(self):
262
262
QtGui .QIcon (":/images/match-pending-90.png" ),
263
263
QtGui .QIcon (":/images/match-pending-100.png" ),
264
264
]
265
- self .icon_plugins = icontheme .lookup ('applications-system' , icontheme .ICON_SIZE_MENU )
266
265
267
266
def _update_selection (self , selected_view ):
268
267
for view in self ._views :
@@ -404,6 +403,75 @@ def __str__(self):
404
403
return f"{ name } 's header"
405
404
406
405
406
+ def _alternative_versions (album ):
407
+ config = get_config ()
408
+ versions = album .release_group .versions
409
+
410
+ album_tracks_count = album .get_num_total_files () or len (album .tracks )
411
+ preferred_countries = set (config .setting ['preferred_release_countries' ])
412
+ preferred_formats = set (config .setting ['preferred_release_formats' ])
413
+ ORDER_BEFORE , ORDER_AFTER = 0 , 1
414
+
415
+ alternatives = []
416
+ for version in versions :
417
+ trackmatch = countrymatch = formatmatch = ORDER_BEFORE
418
+ if version ['totaltracks' ] != album_tracks_count :
419
+ trackmatch = ORDER_AFTER
420
+ if preferred_countries :
421
+ countries = set (version ['countries' ])
422
+ if not countries or not countries .intersection (preferred_countries ):
423
+ countrymatch = ORDER_AFTER
424
+ if preferred_formats :
425
+ formats = set (version ['formats' ])
426
+ if not formats or not formats .intersection (preferred_formats ):
427
+ formatmatch = ORDER_AFTER
428
+ group = (trackmatch , countrymatch , formatmatch )
429
+ # order by group, name, and id on push
430
+ heappush (alternatives , (group , version ['name' ], version ['id' ], version ['extra' ]))
431
+
432
+ while alternatives :
433
+ yield heappop (alternatives )
434
+
435
+
436
+ def _build_other_versions_actions (releases_menu , album , alternative_versions ):
437
+ heading = QtGui .QAction (album .release_group .version_headings , parent = releases_menu )
438
+ heading .setDisabled (True )
439
+ font = heading .font ()
440
+ font .setBold (True )
441
+ heading .setFont (font )
442
+ yield heading
443
+
444
+ prev_group = None
445
+ for group , action_text , release_id , extra in alternative_versions :
446
+ if group != prev_group :
447
+ if prev_group is not None :
448
+ sep = QtGui .QAction (parent = releases_menu )
449
+ sep .setSeparator (True )
450
+ yield sep
451
+ prev_group = group
452
+ action = QtGui .QAction (action_text , parent = releases_menu )
453
+ action .setCheckable (True )
454
+ if extra :
455
+ action .setToolTip (extra )
456
+ if album .id == release_id :
457
+ action .setChecked (True )
458
+ action .triggered .connect (partial (album .switch_release_version , release_id ))
459
+ yield action
460
+
461
+
462
+ def _add_other_versions (releases_menu , album , action_loading ):
463
+
464
+ alt_versions = list (_alternative_versions (album ))
465
+
466
+ alt_versions_count = len (alt_versions )
467
+ if alt_versions_count > 1 :
468
+ releases_menu .setTitle (_ ("&Other versions (%d)" ) % alt_versions_count )
469
+
470
+ actions = _build_other_versions_actions (releases_menu , album , alt_versions )
471
+ releases_menu .insertActions (action_loading , actions )
472
+ releases_menu .removeAction (action_loading )
473
+
474
+
407
475
class BaseTreeView (QtWidgets .QTreeWidget ):
408
476
409
477
def __init__ (self , window , parent = None ):
@@ -412,7 +480,6 @@ def __init__(self, window, parent=None):
412
480
self .setAccessibleDescription (_ (self .DESCRIPTION ))
413
481
self .tagger = QtCore .QCoreApplication .instance ()
414
482
self .window = window
415
- self .panel = parent
416
483
# Should multiple files dropped be assigned to tracks sequentially?
417
484
self ._move_to_multi_tracks = True
418
485
@@ -435,6 +502,8 @@ def __init__(self, window, parent=None):
435
502
self .doubleClicked .connect (self .activate_item )
436
503
self .setUniformRowHeights (True )
437
504
505
+ self .icon_plugins = icontheme .lookup ('applications-system' , icontheme .ICON_SIZE_MENU )
506
+
438
507
def contextMenuEvent (self , event ):
439
508
item = self .itemAt (event .pos ())
440
509
if not item :
@@ -450,8 +519,9 @@ def add_actions(*args):
450
519
menu_builder (menu , self .window .actions , * args )
451
520
452
521
if isinstance (obj , Track ):
453
- if can_view_info :
454
- add_actions (MainAction .VIEW_INFO )
522
+ add_actions (
523
+ MainAction .VIEW_INFO if can_view_info else None ,
524
+ )
455
525
plugin_actions = list (ext_point_track_actions )
456
526
if obj .num_linked_files == 1 :
457
527
add_actions (
@@ -519,77 +589,28 @@ def add_actions(*args):
519
589
if isinstance (obj , Album ) and not isinstance (obj , NatAlbum ) and obj .loaded :
520
590
releases_menu = QtWidgets .QMenu (_ ("&Other versions" ), menu )
521
591
releases_menu .setToolTipsVisible (True )
592
+ releases_menu .setEnabled (False )
522
593
add_actions (
523
594
'-' ,
524
595
releases_menu ,
525
596
)
526
- loading = releases_menu .addAction (_ ("Loading…" ))
527
- loading .setDisabled (True )
528
- action_more = releases_menu .addAction (_ ("Show &more details…" ))
529
- action_more .triggered .connect (self .window .actions [MainAction .ALBUM_OTHER_VERSIONS ].trigger )
530
-
531
- if len (self .selectedItems ()) == 1 and obj .release_group :
532
- def _add_other_versions ():
533
- releases_menu .removeAction (loading )
534
- releases_menu .removeAction (action_more )
535
- heading = releases_menu .addAction (obj .release_group .version_headings )
536
- heading .setDisabled (True )
537
- font = heading .font ()
538
- font .setBold (True )
539
- heading .setFont (font )
540
-
541
- versions = obj .release_group .versions
542
-
543
- album_tracks_count = obj .get_num_total_files () or len (obj .tracks )
544
- preferred_countries = set (config .setting ['preferred_release_countries' ])
545
- preferred_formats = set (config .setting ['preferred_release_formats' ])
546
- ORDER_BEFORE , ORDER_AFTER = 0 , 1
547
-
548
- alternatives = []
549
- for version in versions :
550
- trackmatch = countrymatch = formatmatch = ORDER_BEFORE
551
- if version ['totaltracks' ] != album_tracks_count :
552
- trackmatch = ORDER_AFTER
553
- if preferred_countries :
554
- countries = set (version ['countries' ])
555
- if not countries or not countries .intersection (preferred_countries ):
556
- countrymatch = ORDER_AFTER
557
- if preferred_formats :
558
- formats = set (version ['formats' ])
559
- if not formats or not formats .intersection (preferred_formats ):
560
- formatmatch = ORDER_AFTER
561
- group = (trackmatch , countrymatch , formatmatch )
562
- # order by group, name, and id on push
563
- heappush (alternatives , (group , version ['name' ], version ['id' ], version ['extra' ]))
564
-
565
- prev_group = None
566
- while alternatives :
567
- group , action_text , release_id , extra = heappop (alternatives )
568
- if group != prev_group :
569
- if prev_group is not None :
570
- releases_menu .addSeparator ()
571
- prev_group = group
572
- action = releases_menu .addAction (action_text )
573
- action .setCheckable (True )
574
- if extra :
575
- action .setToolTip (extra )
576
- if obj .id == release_id :
577
- action .setChecked (True )
578
- action .triggered .connect (partial (obj .switch_release_version , release_id ))
579
-
580
- versions_count = len (versions )
581
- if versions_count > 1 :
582
- releases_menu .setTitle (_ ("&Other versions (%d)" ) % versions_count )
583
-
584
- releases_menu .addSeparator ()
585
- action = releases_menu .addAction (action_more )
586
- if obj .release_group .loaded :
587
- _add_other_versions ()
597
+ action_more_details = releases_menu .addAction (_ ("Show &more details…" ))
598
+ action_more_details .triggered .connect (self .window .actions [MainAction .ALBUM_OTHER_VERSIONS ].trigger )
599
+
600
+ album = obj
601
+ if len (self .selectedItems ()) == 1 and album .release_group :
602
+ action_loading = QtGui .QAction (_ ("Loading…" ), parent = releases_menu )
603
+ action_loading .setDisabled (True )
604
+ action_other_versions_separator = QtGui .QAction (parent = releases_menu )
605
+ action_other_versions_separator .setSeparator (True )
606
+ releases_menu .insertActions (action_more_details , [action_loading , action_other_versions_separator ])
607
+
608
+ if album .release_group .loaded :
609
+ _add_other_versions (releases_menu , album , action_loading )
588
610
else :
589
- obj .release_group .load_versions (_add_other_versions )
611
+ callback = partial (_add_other_versions , releases_menu , album , action_loading )
612
+ album .release_group .load_versions (callback )
590
613
releases_menu .setEnabled (True )
591
- else :
592
- releases_menu .setEnabled (False )
593
614
594
615
if config .setting ['enable_ratings' ] and \
595
616
len (self .window .selected_objects ) == 1 and isinstance (obj , Track ):
@@ -613,7 +634,7 @@ def _add_other_versions():
613
634
614
635
if plugin_actions :
615
636
plugin_menu = QtWidgets .QMenu (_ ("P&lugins" ), menu )
616
- plugin_menu .setIcon (self .panel . icon_plugins )
637
+ plugin_menu .setIcon (self .icon_plugins )
617
638
add_actions (
618
639
'-' ,
619
640
plugin_menu ,
@@ -632,7 +653,7 @@ def _add_other_versions():
632
653
633
654
if scripts :
634
655
scripts_menu = ScriptsMenu (scripts , _ ("&Run scripts" ), menu )
635
- scripts_menu .setIcon (self .panel . icon_plugins )
656
+ scripts_menu .setIcon (self .icon_plugins )
636
657
add_actions (
637
658
'-' ,
638
659
scripts_menu ,
@@ -855,8 +876,8 @@ class FileTreeView(BaseTreeView):
855
876
header_state = 'file_view_header_state'
856
877
header_locked = 'file_view_header_locked'
857
878
858
- def __init__ (self , window , parent = None ):
859
- super ().__init__ (window , parent )
879
+ def __init__ (self , * args , ** kwargs ):
880
+ super ().__init__ (* args , ** kwargs )
860
881
self .unmatched_files = ClusterItem (self .tagger .unclustered_files , False , self )
861
882
self .unmatched_files .update ()
862
883
self .unmatched_files .setExpanded (True )
@@ -891,8 +912,8 @@ class AlbumTreeView(BaseTreeView):
891
912
header_state = 'album_view_header_state'
892
913
header_locked = 'album_view_header_locked'
893
914
894
- def __init__ (self , window , parent = None ):
895
- super ().__init__ (window , parent )
915
+ def __init__ (self , * args , ** kwargs ):
916
+ super ().__init__ (* args , ** kwargs )
896
917
self .tagger .album_added .connect (self .add_album )
897
918
self .tagger .album_removed .connect (self .remove_album )
898
919
0 commit comments