CoverArt Browser
v2.0
Browse your cover-art albums in Rhythmbox
|
00001 # -*- Mode: python; coding: utf-8; tab-width: 4; indent-tabs-mode: nil; -*- 00002 # 00003 # Copyright (C) 2012 - fossfreedom 00004 # Copyright (C) 2012 - Agustin Carrasco 00005 # 00006 # This program is free software; you can redistribute it and/or modify 00007 # it under the terms of the GNU General Public License as published by 00008 # the Free Software Foundation; either version 2, or (at your option) 00009 # any later version. 00010 # 00011 # This program is distributed in the hope that it will be useful, 00012 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 # GNU General Public License for more details. 00015 # 00016 # You should have received a copy of the GNU General Public License 00017 # along with this program; if not, write to the Free Software 00018 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 00019 00020 # define plugin 00021 from gi.repository import Gtk 00022 from gi.repository import RB 00023 from gi.repository import GObject 00024 from coverart_rb3compat import Menu 00025 from coverart_external_plugins import CreateExternalPluginMenu 00026 from coverart_entryview import CoverArtEntryView 00027 from coverart_rb3compat import ActionGroup 00028 from coverart_rb3compat import ApplicationShell 00029 from coverart_browser_prefs import CoverLocale 00030 import rb 00031 00032 class CoverArtPlayEntryView(CoverArtEntryView): 00033 __hash__ = GObject.__hash__ 00034 00035 def __init__(self, shell, source): 00036 ''' 00037 Initializes the entryview. 00038 ''' 00039 super(CoverArtPlayEntryView, self).__init__(shell, source) 00040 00041 def define_menu(self): 00042 popup = Menu(self.plugin, self.shell) 00043 popup.load_from_file('N/A', 00044 'ui/coverart_play_pop_rb3.ui') 00045 signals = { 00046 'remove_from_playlist_menu_item': self.remove_from_playlist_menu_item_callback 00047 } 00048 00049 popup.connect_signals(signals) 00050 popup.connect('pre-popup', self.pre_popup_menu_callback) 00051 self.popup = popup 00052 00053 def pre_popup_menu_callback(self, *args): 00054 ''' 00055 Callback when the popup menu is about to be displayed 00056 ''' 00057 00058 if not self.external_plugins: 00059 self.external_plugins = \ 00060 CreateExternalPluginMenu("playlist_entry_view", 1, self.popup) 00061 self.external_plugins.create_menu('play_popup_menu') 00062 00063 def remove_from_playlist_menu_item_callback(self, *args): 00064 print ("remove_from_playlist_menu_item_callback") 00065 entries = self.get_selected_entries() 00066 for entry in entries: 00067 print (entry) 00068 self.source.source_query_model.remove_entry(entry) 00069 00070 def do_show_popup(self, over_entry): 00071 if over_entry: 00072 print("CoverArtBrowser DEBUG - do_show_popup()") 00073 00074 self.popup.popup(self.source, 00075 'play_popup_menu', 0, Gtk.get_current_event_time()) 00076 00077 return over_entry 00078 00079 def play_track_menu_item_callback(self, *args): 00080 print("CoverArtBrowser DEBUG - play_track_menu_item_callback()") 00081 00082 selected = self.get_selected_entries() 00083 entry = selected[0] 00084 00085 # Start the music 00086 player = self.shell.props.shell_player 00087 player.play_entry(entry, self.source) 00088 00089 print("CoverArtBrowser DEBUG - play_track_menu_item_callback()") 00090 00091 00092 class CoverArtPlaySource(RB.Source): 00093 ''' 00094 Source utilized by the plugin to show all it's ui. 00095 ''' 00096 00097 def __init__(self, **kwargs): 00098 ''' 00099 Initializes the source. 00100 ''' 00101 super(CoverArtPlaySource, self).__init__() 00102 self.external_plugins = None 00103 self.hasActivated = False 00104 00105 def initialise(self, plugin, shell, source): 00106 self.plugin = plugin 00107 self.shell = shell 00108 self.source = source 00109 00110 def do_selected(self): 00111 ''' 00112 Called by Rhythmbox when the source is selected. It makes sure to 00113 create the ui the first time the source is shown. 00114 ''' 00115 print("CoverArtBrowser DEBUG - do_selected") 00116 00117 # first time of activation -> add graphical stuff 00118 if not self.hasActivated: 00119 self.do_impl_activate() 00120 00121 # indicate that the source was activated before 00122 self.hasActivated = True 00123 00124 print("CoverArtBrowser DEBUG - end do_selected") 00125 00126 def connect_library_signals(self): 00127 pass 00128 00129 def do_impl_activate(self): 00130 ''' 00131 Called by do_selected the first time the source is activated. 00132 It creates all the source ui and connects the necessary signals for it 00133 correct behavior. 00134 ''' 00135 print ('do_impl_activate') 00136 self.hasActivated = True 00137 00138 self.entryview = CoverArtPlayEntryView(self.shell, self.source) 00139 self.entryview.props.hexpand = True 00140 self.entryview.props.vexpand = True 00141 grid = Gtk.Grid() 00142 grid.attach(self.entryview, 0, 1, 1, 1) 00143 00144 self.entryview.set_model(self.source.source_query_model) 00145 00146 # enable sorting on the entryview 00147 #entryview.set_columns_clickable(True) 00148 self.shell.props.library_source.get_entry_view().set_columns_clickable( 00149 True) 00150 00151 cl = CoverLocale() 00152 cl.switch_locale(cl.Locale.LOCALE_DOMAIN) 00153 location = rb.find_plugin_file(self.plugin, 'ui/playsource-toolbar.ui') 00154 ui = Gtk.Builder() 00155 ui.set_translation_domain(cl.Locale.RB) 00156 ui.add_from_file(location) 00157 toolbar_menu = ui.get_object('playsource-toolbar') 00158 app = self.shell.props.application 00159 app.link_shared_menus(toolbar_menu) 00160 bar = RB.ButtonBar.new(toolbar_menu, toolbar_menu) 00161 grid.attach(bar, 0, 0, 1, 1) 00162 00163 grid.show_all() 00164 self.pack_start(grid, True, True, 0) 00165 00166 appshell = ApplicationShell(self.shell) 00167 action_group = ActionGroup(self.shell, 'PlaySourceActions') 00168 action_group.add_action(func=self.clear_playsource, 00169 action_name='playsource-clear', action_state=ActionGroup.STANDARD, 00170 action_type='app') 00171 action_group.add_action(func=self.shuffle_playsource, 00172 action_name='playsource-shuffle', action_state=ActionGroup.STANDARD, 00173 action_type='app') 00174 appshell.insert_action_group(action_group) 00175 00176 def clear_playsource(self, *args): 00177 for row in self.entryview.props.model: 00178 self.entryview.props.model.remove_entry(row[0]) 00179 00180 def shuffle_playsource(self, *args): 00181 self.entryview.props.model.shuffle_entries() 00182 00183 00184 GObject.type_register(CoverArtPlayEntryView)