Пример #1
0
 def prepare_to_exit(self, action=None, param=None):
     """
         Save window position and view
     """
     if self._is_fs:
         return
     if self.settings.get_value('save-state'):
         self.window.save_view_state()
         # Save current track
         if self.player.current_track.id is None:
             track_id = -1
         elif self.player.current_track.id == Type.RADIOS:
             radios = Radios()
             track_id = radios.get_id(
                 self.player.current_track.album_artist)
         else:
             track_id = self.player.current_track.id
         self.settings.set_value('track-id', GLib.Variant('i', track_id))
         # Save current playlist
         if self.player.current_track.id == Type.RADIOS:
             playlist_ids = [Type.RADIOS]
         elif not self.player.get_user_playlist_ids():
             playlist_ids = []
         else:
             playlist_ids = self.player.get_user_playlist_ids()
         self.settings.set_value('playlist-ids',
                                 GLib.Variant('ai', playlist_ids))
     self.player.stop_all()
     if self.window:
         self.window.stop_all()
     self.quit()
Пример #2
0
 def prepare_to_exit(self, action=None, param=None):
     """
         Save window position and view
     """
     if self._is_fs:
         return
     if self.settings.get_value('save-state'):
         self.window.save_view_state()
         # Save current track
         if self.player.current_track.id is None:
             track_id = -1
         elif self.player.current_track.id == Type.RADIOS:
             radios = Radios()
             track_id = radios.get_id(
                                     self.player.current_track.album_artist)
         else:
             track_id = self.player.current_track.id
         self.settings.set_value('track-id', GLib.Variant('i',
                                                          track_id))
         # Save current playlist
         if self.player.current_track.id == Type.RADIOS:
             playlist_ids = [Type.RADIOS]
         elif not self.player.get_user_playlist_ids():
             playlist_ids = []
         else:
             playlist_ids = self.player.get_user_playlist_ids()
         self.settings.set_value('playlist-ids', GLib.Variant('ai',
                                                              playlist_ids))
     self.player.stop_all()
     if self.window:
         self.window.stop_all()
     self.quit()
Пример #3
0
 def prepare_to_exit(self, action=None, param=None, exit=True):
     """
         Save window position and view
     """
     if self.__is_fs:
         return
     if self.settings.get_value('save-state'):
         self.window.save_view_state()
         # Save current track
         if self.player.current_track.id is None:
             track_id = -1
         elif self.player.current_track.id == Type.RADIOS:
             from lollypop.radios import Radios
             radios = Radios()
             track_id = radios.get_id(
                                 self.player.current_track.album_artists[0])
         else:
             track_id = self.player.current_track.id
             # Save albums context
             try:
                 dump(self.player.context.genre_ids,
                      open(DataPath + "/genre_ids.bin", "wb"))
                 dump(self.player.context.artist_ids,
                      open(DataPath + "/artist_ids.bin", "wb"))
                 self.player.shuffle_albums(False)
                 dump(self.player.get_albums(),
                      open(DataPath + "/albums.bin", "wb"))
             except Exception as e:
                 print("Application::prepare_to_exit()", e)
         dump(track_id, open(DataPath + "/track_id.bin", "wb"))
         dump([self.player.is_playing, self.player.is_party],
              open(DataPath + "/player.bin", "wb"))
         # Save current playlist
         if self.player.current_track.id == Type.RADIOS:
             playlist_ids = [Type.RADIOS]
         elif not self.player.get_user_playlist_ids():
             playlist_ids = []
         else:
             playlist_ids = self.player.get_user_playlist_ids()
         dump(playlist_ids,
              open(DataPath + "/playlist_ids.bin", "wb"))
     if self.player.current_track.id is not None:
         position = self.player.position
     else:
         position = 0
     dump(position, open(DataPath + "/position.bin", "wb"))
     self.player.stop_all()
     self.window.stop_all()
     if self.charts is not None:
         self.charts.stop()
     if exit:
         self.quit()
Пример #4
0
 def __save_state(self):
     """
         Save window position and view
     """
     if self.is_fullscreen():
         return
     if self.settings.get_value("save-state"):
         self.window.save_view_state()
         # Save current track
         if self.player.current_track.id is None:
             track_id = -1
         elif self.player.current_track.id == Type.RADIOS:
             from lollypop.radios import Radios
             radios = Radios()
             track_id = radios.get_id(
                 self.player.current_track.album_artists[0])
         else:
             track_id = self.player.current_track.id
             # Save albums context
             try:
                 dump(self.player.context.genre_ids,
                      open(LOLLYPOP_DATA_PATH + "/genre_ids.bin", "wb"))
                 dump(self.player.context.artist_ids,
                      open(LOLLYPOP_DATA_PATH + "/artist_ids.bin", "wb"))
                 self.player.shuffle_albums(False)
                 dump(self.player.get_albums(),
                      open(LOLLYPOP_DATA_PATH + "/albums.bin", "wb"))
             except Exception as e:
                 print("Application::__save_state()", e)
         dump(track_id, open(LOLLYPOP_DATA_PATH + "/track_id.bin", "wb"))
         dump([self.player.is_playing, self.player.is_party],
              open(LOLLYPOP_DATA_PATH + "/player.bin", "wb"))
         # Save current playlist
         if self.player.current_track.id == Type.RADIOS:
             playlist_ids = [Type.RADIOS]
         elif not self.player.get_user_playlist_ids():
             playlist_ids = []
         else:
             playlist_ids = self.player.get_user_playlist_ids()
         dump(playlist_ids,
              open(LOLLYPOP_DATA_PATH + "/playlist_ids.bin", "wb"))
     if self.player.current_track.id is not None:
         position = self.player.position
     else:
         position = 0
     dump(position, open(LOLLYPOP_DATA_PATH + "/position.bin", "wb"))
     self.player.stop_all()
     self.window.stop_all()
Пример #5
0
 def set_radio(self, name, uri):
     """
         Set radio for non DB radios (Tunein)
         @param name as string
         @param uri as string
     """
     from lollypop.radios import Radios
     radios = Radios()
     self.id = Type.RADIOS
     self._radio_id = radios.get_id(name)
     self._radio_name = name
     self._uri = uri
     # Generate a tmp album id, needed by InfoController
     album_id = 0
     for i in list(map(ord, name)):
         album_id += i
     self.album.id = album_id
Пример #6
0
    def __save_state(self):
        """
            Save window position and view
        """
        if not self.settings.get_value("save-state"):
            return

        if self.player.current_track.id is None or\
                self.player.current_track.mtime == 0:
            track_id = None
        elif self.player.current_track.id == Type.RADIOS:
            from lollypop.radios import Radios
            radios = Radios()
            track_id = radios.get_id(self.player.current_track.radio_name)
        else:
            track_id = self.player.current_track.id
            # Save albums context
            try:
                with open(LOLLYPOP_DATA_PATH + "/Albums.bin", "wb") as f:
                    dump(list(self.player.albums), f)
            except Exception as e:
                Logger.error("Application::__save_state(): %s" % e)
        dump(track_id, open(LOLLYPOP_DATA_PATH + "/track_id.bin", "wb"))
        dump([self.player.is_playing, self.player.is_party],
             open(LOLLYPOP_DATA_PATH + "/player.bin", "wb"))
        dump(self.player.queue, open(LOLLYPOP_DATA_PATH + "/queue.bin", "wb"))
        # Save current playlist
        if self.player.current_track.id == Type.RADIOS:
            playlist_ids = [Type.RADIOS]
        elif not self.player.playlist_ids:
            playlist_ids = []
        else:
            playlist_ids = self.player.playlist_ids
        dump(playlist_ids, open(LOLLYPOP_DATA_PATH + "/playlist_ids.bin",
                                "wb"))
        if self.player.current_track.id is not None:
            position = self.player.position
        else:
            position = 0
        dump(position, open(LOLLYPOP_DATA_PATH + "/position.bin", "wb"))
        self.player.stop_all()
        self.__window.container.stop_all()