Пример #1
0
class HistoryPlugin(object):
    '''Implements logic for plugin'''
    
    def get_preferences_pane(self):
        return history_preferences
    
    def enable(self, exaile):
        self.exaile = exaile
    
    def on_gui_loaded(self):
        save_on_exit = settings.get_option('plugin/history/save_on_exit', history_preferences.save_on_exit_default)
        shown = settings.get_option('plugin/history/shown', False)
    
        # immutable playlist that stores everything we've played
        self.history_loc = os.path.join(xdg.get_data_dir(), 'history')
        
        self.history_playlist = HistoryPlaylist( player.PLAYER )
        
        if save_on_exit:
            self.history_playlist.load_from_location( self.history_loc )
        
        self.history_page = HistoryPlaylistPage( self.history_playlist, player.PLAYER )
        self.history_tab = NotebookTab(main.get_playlist_notebook(), self.history_page )
        
        # add menu item to 'view' to display our playlist 
        self.menu = menu.check_menu_item( 'history', '', _('Playback history'), \
            lambda *e: self.is_shown(), self.on_playback_history )
            
        providers.register( 'menubar-view-menu', self.menu )
        
        # add the history playlist to the primary notebook
        if save_on_exit and shown:
            self.show_history( True )
        
    def teardown(self, exaile):
        '''Called when exaile is exiting'''
        
        if settings.get_option('plugin/history/save_on_exit', history_preferences.save_on_exit_default ):
            self.history_playlist.save_to_location( self.history_loc )
            settings.set_option( 'plugin/history/shown', self.is_shown() )
        else:
            settings.set_option( 'plugin/history/shown', False )
            
        self.show_history(False)
    
    def disable(self, exaile):
    
        '''Called when the plugin is disabled'''
        if self.menu:
            providers.unregister( 'menubar-view-menu', self.menu )
            self.menu = None
            
        self.show_history(False)

        if os.path.exists( self.history_loc ):
            # TODO: The parent should be the Preferences window, but we don't
            # have access to it, so this just uses the main window.
            dialog = Gtk.MessageDialog( exaile.gui.main.window, Gtk.DialogFlags.MODAL, Gtk.MessageType.QUESTION, Gtk.ButtonsType.YES_NO,
                                        _('Erase stored history?') )
                
            if dialog.run() == Gtk.ResponseType.YES:
                try:
                    os.unlink( self.history_loc )
                except:
                    pass
                    
            dialog.destroy()
        
    def is_shown(self):
        return main.get_playlist_notebook().page_num( self.history_page ) != -1
    
    def on_playback_history(self, menu, name, parent, context):
        self.show_history( not self.is_shown() )
        
    def show_history(self, show):

        if show == self.is_shown():
            return
    
        if show:
            pn = main.get_playlist_notebook()
            pn.add_tab( self.history_tab, self.history_page  )
        else:
            self.history_tab.close()
Пример #2
0
class HistoryPlugin(object):
    '''Implements logic for plugin'''
    def get_preferences_pane(self):
        return history_preferences

    def enable(self, exaile):
        self.exaile = exaile

    def on_gui_loaded(self):
        save_on_exit = settings.get_option(
            'plugin/history/save_on_exit',
            history_preferences.save_on_exit_default)
        shown = settings.get_option('plugin/history/shown', False)

        # immutable playlist that stores everything we've played
        self.history_loc = os.path.join(xdg.get_data_dir(), 'history')

        self.history_playlist = HistoryPlaylist(player.PLAYER)

        if save_on_exit:
            self.history_playlist.load_from_location(self.history_loc)

        self.history_page = HistoryPlaylistPage(self.history_playlist,
                                                player.PLAYER)
        self.history_tab = NotebookTab(main.get_playlist_notebook(),
                                       self.history_page)

        # add menu item to 'view' to display our playlist
        self.menu = menu.check_menu_item(
            'history',
            '',
            _('Playback history'),
            lambda *e: self.is_shown(),
            self.on_playback_history,
        )

        providers.register('menubar-view-menu', self.menu)

        # add the history playlist to the primary notebook
        if save_on_exit and shown:
            self.show_history(True)

    def teardown(self, exaile):
        '''Called when exaile is exiting'''

        if settings.get_option('plugin/history/save_on_exit',
                               history_preferences.save_on_exit_default):
            self.history_playlist.save_to_location(self.history_loc)
            settings.set_option('plugin/history/shown', self.is_shown())
        else:
            settings.set_option('plugin/history/shown', False)

        self.show_history(False)

    def disable(self, exaile):
        '''Called when the plugin is disabled'''
        if self.menu:
            providers.unregister('menubar-view-menu', self.menu)
            self.menu = None

        self.show_history(False)

        if os.path.exists(self.history_loc):
            # TODO: The parent should be the Preferences window, but we don't
            # have access to it, so this just uses the main window.
            dialog = Gtk.MessageDialog(
                exaile.gui.main.window,
                Gtk.DialogFlags.MODAL,
                Gtk.MessageType.QUESTION,
                Gtk.ButtonsType.YES_NO,
                _('Erase stored history?'),
            )

            if dialog.run() == Gtk.ResponseType.YES:
                try:
                    os.unlink(self.history_loc)
                except Exception:
                    pass

            dialog.destroy()

    def is_shown(self):
        return main.get_playlist_notebook().page_num(self.history_page) != -1

    def on_playback_history(self, menu, name, parent, context):
        self.show_history(not self.is_shown())

    def show_history(self, show):

        if show == self.is_shown():
            return

        if show:
            pn = main.get_playlist_notebook()
            pn.add_tab(self.history_tab, self.history_page)
        else:
            self.history_tab.close()
Пример #3
0
class HistoryPlugin(object):
    '''Implements logic for plugin'''
    
    def __init__(self, exaile):
    
        self.exaile = exaile
    
        save_on_exit = settings.get_option('plugin/history/save_on_exit', history_preferences.save_on_exit_default)
        shown = settings.get_option('plugin/history/shown', False)
    
        # immutable playlist that stores everything we've played
        self.history_loc = os.path.join(xdg.get_data_dir(), 'history')
        
        self.history_playlist = HistoryPlaylist( player.PLAYER )
        
        if save_on_exit:
            self.history_playlist.load_from_location( self.history_loc )
        
        self.history_page = HistoryPlaylistPage( self.history_playlist, player.PLAYER )
        self.history_tab = NotebookTab(main.get_playlist_notebook(), self.history_page )
        
        # add menu item to 'view' to display our playlist 
        self.menu = menu.check_menu_item( 'history', '', _('Playback history'), \
            lambda *e: self.is_shown(), self.on_playback_history )
            
        providers.register( 'menubar-view-menu', self.menu )
        
        # add the history playlist to the primary notebook
        if save_on_exit and shown:
            self.show_history( True )
        
    def teardown_plugin(self, exaile):
        '''Called when exaile is exiting'''
        
        if settings.get_option('plugin/history/save_on_exit', history_preferences.save_on_exit_default ):
            self.history_playlist.save_to_location( self.history_loc )
            settings.set_option( 'plugin/history/shown', self.is_shown() )
        else:
            settings.set_option( 'plugin/history/shown', False )
            
        self.show_history(False)
    
    def disable_plugin(self, exaile):
    
        '''Called when the plugin is disabled'''
        if self.menu:
            providers.unregister( 'menubar-view-menu', self.menu )
            self.menu = None
            
        self.show_history(False)

        if os.path.exists( self.history_loc ):
        
            dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, 
                                        _('Erase stored history?') )
                
            if dialog.run() == gtk.RESPONSE_YES:
                try:
                    os.unlink( self.history_loc )
                except:
                    pass
                    
            dialog.destroy()
        
    def is_shown(self):
        return main.get_playlist_notebook().page_num( self.history_page ) != -1
    
    def on_playback_history(self, menu, name, parent, context):
        self.show_history( not self.is_shown() )
        
    def show_history(self, show):

        if show == self.is_shown():
            return
    
        if show:
            pn = main.get_playlist_notebook()
            pn.add_tab( self.history_tab, self.history_page  )
        else:
            self.history_tab.close()