def load(self): '''load songs and playlists from db file''' self.logdebug("Loading library...") # Load songs try: db_objs = utils.load_db(get_config_file("songs.db")) except: self.logexception("Failed to load library") db_objs = [] # Load playlists try: pls_objs = utils.load_db(get_config_file("playlists.db")) except: self.logexception("Failed load playlists") pls_objs = [] if db_objs: for obj in db_objs: try: song_type = obj["song_type"] except KeyError: self.logerror("Song with no type found, %s", obj.get("uri")) if song_type not in self.__song_types: self.logwarn("Song type %s not exist, for registration", song_type) self.register_type(song_type) if self.__force_check: s = Song() s.init_from_dict(obj) s["uri"] = utils.realuri(s.get("uri")) else: s = Song(obj) s.set_type(song_type) if not self.__force_check or not self.__songs.has_key(s.get("uri")): self.add(s) if pls_objs: for pl_obj in pls_objs: name, infos = pl_obj if self.__force_check: infos = map(utils.realuri, infos) self.create_playlist("local", name, infos) if self.__force_check: self.save() self.__dirty = False # fire signal self.__reset_queued_signal() gobject.timeout_add(AUTOSAVE_TIMEOUT, self.interval_async_save) gobject.timeout_add(SIGNAL_DB_QUERY_FIRED * 20, self.__fire_queued_signal) self.logdebug("%s songs loaded in %s types", len(self.__songs), len(self.__song_types)) self.logdebug("Finish loading library") gobject.idle_add(self.__delay_post_load)
def reload_song_from_file(self, song): s = Song() s.init_from_dict({"uri": song.get("uri")}) s["uri"] = utils.realuri(s.get("uri")) s.read_from_file() new_tags = {} for key in TAG_KEYS.values() + ["#size", "#mtime", "ctime"]: if s.has_key(key) and not song.has_key(key): new_tags[key] = s.get(key) elif not s.has_key(key) and song.has_key(key): new_tags[key] = song.get(key) elif s.get(key) != song.get(key): new_tags[key] = s.get(key) self.set_property(song, new_tags)
def reload_song_from_file(self, song): s = Song() s.init_from_dict({"uri":song.get("uri")}) s["uri"] = utils.realuri(s.get("uri")) s.read_from_file() new_tags = {} for key in TAG_KEYS.values() + ["#size", "#mtime", "ctime"]: if s.has_key(key) and not song.has_key(key): new_tags[key] = s.get(key) elif not s.has_key(key) and song.has_key(key): new_tags[key] = song.get(key) elif s.get(key) != song.get(key): new_tags[key] = s.get(key) self.set_property(song, new_tags)
def load(self): save_flag = False try: db_objs = utils.load_db(self.__user_save_db) except: db_objs = None if db_objs is None: save_flag = True self.logexception("Faild load user db, will to load default db") try: db_objs = utils.load_db(self.__default_db) except: db_objs = [] if db_objs: for obj in db_objs: s = Song(obj) s.set_type(self.__type) if not self.__songs.has_key(s.get("uri")): self.logdebug("load webcast %s" % s) self.add(s) if save_flag: self.set_dirty() self.asyc_save() self.__dirty = False # fire signal self.__reset_queued_signal() gobject.timeout_add(AUTOSAVE_TIMEOUT, self.asyc_save) gobject.timeout_add(SIGNAL_DB_QUERY_FIRED * 20, self.__fire_queued_signal) gobject.idle_add(self.__delay_post_load)
def load(self): save_flag = False try: db_objs = utils.load_db(self.__user_save_db) except: db_objs = None if db_objs is None: save_flag = True self.logexception("Faild load user db, will to load default db") try: db_objs = utils.load_db(self.__default_db) except: db_objs = [] if db_objs: for obj in db_objs: s = Song(obj) s.set_type(self.__type) if not self.__songs.has_key(s.get("uri")): # self.logdebug("load webcast %s" % s) self.add(s) if save_flag: self.set_dirty() self.asyc_save() self.__dirty = False # fire signal self.__reset_queued_signal() gobject.timeout_add(AUTOSAVE_TIMEOUT, self.asyc_save) gobject.timeout_add(SIGNAL_DB_QUERY_FIRED * 20, self.__fire_queued_signal) gobject.idle_add(self.__delay_post_load)
class WebcastListItem(gobject.GObject): __gsignals__ = {"redraw-request" : ( gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),} def __init__(self, tags, draw_collect=False): gobject.GObject.__init__(self) self.webcast = Song() self.webcast.init_from_dict(tags) self.webcast.set_type("webcast") if draw_collect: self.is_collected = True else: self.is_collected = WebcastsDB.is_collected(tags["uri"]) self.webcast["collect"] = self.is_collected self.index = None self.webcast_normal_pixbuf = app_theme.get_pixbuf("webcast/webcast_normal.png").get_pixbuf() self.webcast_press_pixbuf = app_theme.get_pixbuf("webcast/webcast_press.png").get_pixbuf() self.collect_normal_pixbuf = app_theme.get_pixbuf("webcast/collect_normal.png").get_pixbuf() self.collect_press_pixbuf = app_theme.get_pixbuf("webcast/collect_press.png").get_pixbuf() self.__update_size() def set_index(self, index): self.index = index def get_index(self): return self.index def emit_redraw_request(self): self.emit("redraw-request") def __update_size(self): self.title = self.webcast.get_str("title") self.webcast_icon_padding_x = 10 self.webcast_icon_padding_y = 5 self.webcast_icon_w = self.webcast_normal_pixbuf.get_width() self.webcast_icon_h = self.webcast_normal_pixbuf.get_height() self.title_padding_x = 5 self.title_padding_y = 5 self.title_w, self.title_h = get_content_size(self.title, DEFAULT_FONT_SIZE) self.collect_icon_padding_x = 2 self.collect_icon_padding_y = 5 self.collect_icon_w = self.collect_normal_pixbuf.get_width() self.collect_icon_h = self.collect_normal_pixbuf.get_height() def render_webcast_icon(self, cr, rect, in_select, in_highlight): icon_x = rect.x + self.webcast_icon_padding_x icon_y = rect.y + (rect.height - self.webcast_icon_h) / 2 if in_select: pixbuf = self.webcast_press_pixbuf else: pixbuf = self.webcast_normal_pixbuf draw_pixbuf(cr, pixbuf, icon_x, icon_y) def render_title(self, cr, rect, in_select, in_highlight): rect.x += self.title_padding_x rect.width -= self.title_padding_x * 2 render_item_text(cr, self.title, rect, in_select, in_highlight) def render_collect_icon(self, cr, rect, in_select, in_highlight): icon_y = rect.y + (rect.height - self.collect_icon_h) / 2 rect.x += self.collect_icon_padding_x if self.is_collected: pixbuf = self.collect_press_pixbuf else: pixbuf = self.collect_normal_pixbuf draw_pixbuf(cr, pixbuf, rect.x , icon_y) def render_block(self, cr, rect, in_select, in_highlight): pass def get_column_sizes(self): return [ (self.webcast_icon_w + self.webcast_icon_padding_x * 2, self.webcast_icon_h + self.webcast_icon_padding_y * 2), (360, self.title_h + self.title_padding_y * 2), (self.collect_icon_w + self.collect_icon_padding_x * 2, self.collect_icon_h + self.collect_icon_padding_y * 2), (50, 1) ] def get_renders(self): return [self.render_webcast_icon, self.render_title, self.render_collect_icon, self.render_block] def toggle_is_collected(self): if self.is_collected: self.is_collected = False else: self.is_collected = True self.webcast["collect"] = self.is_collected self.emit_redraw_request() def set_draw_collect(self, value): self.draw_collect_flag = value self.emit_redraw_request() def get_tags(self): return self.webcast.get_dict() def __hash__(self): return hash(self.webcast.get("uri")) def __cmp__(self, other_item): if not other_item: return -1 try: return cmp(self.webcast.get("search"), other_item.webcast.get("search")) except AttributeError: return -1 def __eq__(self, other_item): try: return self.webcast.get("uri") == other_item.webcast.get("uri") except: return False def __repr__(self): return "<Webcast %s>" % self.webcast.get("uri")
class WebcastListItem(gobject.GObject): __gsignals__ = { "redraw-request": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()), } def __init__(self, tags, draw_collect=False): gobject.GObject.__init__(self) self.webcast = Song() self.webcast.init_from_dict(tags) self.webcast.set_type("webcast") if draw_collect: self.is_collected = True else: self.is_collected = WebcastsDB.is_collected(tags["uri"]) self.webcast["collect"] = self.is_collected self.index = None self.webcast_normal_pixbuf = app_theme.get_pixbuf( "webcast/webcast_normal.png").get_pixbuf() self.webcast_press_pixbuf = app_theme.get_pixbuf( "webcast/webcast_press.png").get_pixbuf() self.collect_normal_pixbuf = app_theme.get_pixbuf( "webcast/collect_normal.png").get_pixbuf() self.collect_press_pixbuf = app_theme.get_pixbuf( "webcast/collect_press.png").get_pixbuf() self.__update_size() def set_index(self, index): self.index = index def get_index(self): return self.index def emit_redraw_request(self): self.emit("redraw-request") def __update_size(self): self.title = self.webcast.get_str("title") self.webcast_icon_padding_x = 10 self.webcast_icon_padding_y = 5 self.webcast_icon_w = self.webcast_normal_pixbuf.get_width() self.webcast_icon_h = self.webcast_normal_pixbuf.get_height() self.title_padding_x = 5 self.title_padding_y = 5 self.title_w, self.title_h = get_content_size(self.title, DEFAULT_FONT_SIZE) self.collect_icon_padding_x = 2 self.collect_icon_padding_y = 5 self.collect_icon_w = self.collect_normal_pixbuf.get_width() self.collect_icon_h = self.collect_normal_pixbuf.get_height() def render_webcast_icon(self, cr, rect, in_select, in_highlight): icon_x = rect.x + self.webcast_icon_padding_x icon_y = rect.y + (rect.height - self.webcast_icon_h) / 2 if in_select: pixbuf = self.webcast_press_pixbuf else: pixbuf = self.webcast_normal_pixbuf draw_pixbuf(cr, pixbuf, icon_x, icon_y) def render_title(self, cr, rect, in_select, in_highlight): rect.x += self.title_padding_x rect.width -= self.title_padding_x * 2 render_item_text(cr, self.title, rect, in_select, in_highlight) def render_collect_icon(self, cr, rect, in_select, in_highlight): icon_y = rect.y + (rect.height - self.collect_icon_h) / 2 rect.x += self.collect_icon_padding_x if self.is_collected: pixbuf = self.collect_press_pixbuf else: pixbuf = self.collect_normal_pixbuf draw_pixbuf(cr, pixbuf, rect.x, icon_y) def render_block(self, cr, rect, in_select, in_highlight): pass def get_column_sizes(self): return [(self.webcast_icon_w + self.webcast_icon_padding_x * 2, self.webcast_icon_h + self.webcast_icon_padding_y * 2), (360, self.title_h + self.title_padding_y * 2), (self.collect_icon_w + self.collect_icon_padding_x * 2, self.collect_icon_h + self.collect_icon_padding_y * 2), (50, 1)] def get_renders(self): return [ self.render_webcast_icon, self.render_title, self.render_collect_icon, self.render_block ] def toggle_is_collected(self): if self.is_collected: self.is_collected = False else: self.is_collected = True self.webcast["collect"] = self.is_collected self.emit_redraw_request() def set_draw_collect(self, value): self.draw_collect_flag = value self.emit_redraw_request() def get_tags(self): return self.webcast.get_dict() def __hash__(self): return hash(self.webcast.get("uri")) def __cmp__(self, other_item): if not other_item: return -1 try: return cmp(self.webcast.get("search"), other_item.webcast.get("search")) except AttributeError: return -1 def __eq__(self, other_item): try: return self.webcast.get("uri") == other_item.webcast.get("uri") except: return False def __repr__(self): return "<Webcast %s>" % self.webcast.get("uri")
def load(self): '''load songs and playlists from db file''' self.logdebug("Loading library...") # Load songs try: db_objs = utils.load_db(get_config_file("songs.db")) except: self.logexception("Failed to load library") db_objs = [] # Load playlists try: pls_objs = utils.load_db(get_config_file("playlists.db")) except: self.logexception("Failed load playlists") pls_objs = [] if db_objs: for obj in db_objs: try: song_type = obj["song_type"] except KeyError: self.logerror("Song with no type found, %s", obj.get("uri")) if song_type not in self.__song_types: self.logwarn("Song type %s not exist, for registration", song_type) self.register_type(song_type) if self.__force_check: s = Song() s.init_from_dict(obj) s["uri"] = utils.realuri(s.get("uri")) else: s = Song(obj) s.set_type(song_type) if not self.__force_check or not self.__songs.has_key( s.get("uri")): self.add(s) if pls_objs: for pl_obj in pls_objs: name, infos = pl_obj if self.__force_check: infos = map(utils.realuri, infos) self.create_playlist("local", name, infos) if self.__force_check: self.save() self.__dirty = False # fire signal self.__reset_queued_signal() gobject.timeout_add(AUTOSAVE_TIMEOUT, self.interval_async_save) gobject.timeout_add(SIGNAL_DB_QUERY_FIRED * 20, self.__fire_queued_signal) self.logdebug("%s songs loaded in %s types", len(self.__songs), len(self.__song_types)) self.logdebug("Finish loading library") gobject.idle_add(self.__delay_post_load)