Index: channels/bookmarks.py ================================================================== --- channels/bookmarks.py +++ channels/bookmarks.py @@ -49,28 +49,32 @@ "timer": [], "history": [] } default = "favourite" fixed_size = [32,24] + reserved_names = ["favourite", "radiotray", "scripts", "search", "timer", "history", "links", "themes"] #+ self.parent.features.keys() # cache list, to determine if a PLS url is bookmarked urls = [] def gui(self, parent): parent.notebook_channels.set_menu_label_text(parent.v_bookmarks, "bookmarks") + self.update_categories() GenericChannel.gui(self, parent) uikit.tree_column(self.gtk_cat, "Group") - # this channel does not actually retrieve/parse data from anywhere + # custom categories are shown as subfolder below `favourite` def update_categories(self): - pass + cust_cats = list(set(self.streams.keys()) - set(self.reserved_names)) + if len(self.categories) < 2 or type(self.categories[1]) is not list: + self.categories.insert(1, []) + self.categories[1] = cust_cats # but category sub-plugins might provide a hook category_plugins = {} def update_streams(self, cat): - if cat in self.category_plugins: return self.category_plugins[cat].update_streams(cat) or [] else: return self.streams.get(cat, []) @@ -104,11 +108,11 @@ return str(url) in self.urls # called from main window / menu / context menu, # when bookmark is to be added for a selected stream entry - def add(self, row): + def add(self, row, target="favourite"): # Add / copy some row attributes row["favourite"] = 1 if not row.get("favicon"): pass# row["favicon"] = favicon.file(row.get("homepage")) @@ -116,11 +120,11 @@ row["listformat"] = self.parent.channel().listformat if not len(row.get("extra", "")): row["extra"] = self.parent.channel().module # append to storage - self.streams["favourite"].append(row) + self.streams[target].append(row) self.save() self.load(self.default) self.urls.append(row["url"]) ADDED contrib/new_favourite_cat.py Index: contrib/new_favourite_cat.py ================================================================== --- contrib/new_favourite_cat.py +++ contrib/new_favourite_cat.py @@ -0,0 +1,80 @@ +# encoding: utf-8 +# api: streamtuner2 +# title: New favourite category +# description: Introduces new bookmarks categories +# version: 0.2 +# type: feature +# category: ui +# config: - +# priority: optional +# +# Adds a "New favourite category..." under Station > Extensions menu. +# New categories will show up in the bookmarks channel under favourite. +# + +from uikit import * +from config import * + +# +class new_favourite_cat (object): + plugin = "new_favourite_cat" + meta = plugin_meta() + parent = None + w = None + + # hook up menu entry + def __init__(self, parent): + self.parent = parent + uikit.add_menu([parent.extensions], "New favourite category…", self.win, insert=3) + self.create_submenu(parent) + self.update_submenu() + + # show input window + def win(self, *w): + w = self.w = gtk.Dialog( + 'New bookmark category', + self.parent.win_streamtuner2, + gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, + (gtk.STOCK_OK, gtk.RESPONSE_APPLY) + ) + input = gtk.Entry(35) + w.vbox.pack_start(input) + log.UI(w.vbox.get_children()) + w.show_all() + self.add(self.w, w.run(), input.get_text()) + + # add category + def add(self, w, r, title): + bm = self.parent.bookmarks + have = bm.streams.has_key(title) + w.destroy() + if r == gtk.RESPONSE_APPLY: + log.NEW(title) + if not have: + bm.streams[title] = {} + if r == gtk.RESPONSE_DELETE_EVENT: + if have: + bm.streams.remove(title) + self.update_submenu() + bm.update_categories() + bm.display_categories() + + # introduce MenuItem+Menu + def create_submenu(self, parent): + self.submenu = gtk.Menu() + for title, target, i in [("Bookmark to", parent.streammenu, 1), ("Add bookmark to", parent.streamactions, 3)]: + mi = gtk.ImageMenuItem(gtk.STOCK_INDENT) + mi.set_submenu(self.submenu) + mi.set_label(title) + mi.show_all() + target.insert(mi, i) + + # bookmark to > … submenu w/ custom categories + def update_submenu(self): + bmc = self.parent.bookmarks.categories + [self.submenu.remove(w) for w in self.submenu.get_children()] + if len(bmc) >= 2 and type(bmc[1]) is list: + for label in bmc[1]: + uikit.add_menu([self.submenu], label, lambda w,target=label: self.parent.bookmark(w, target)) + self.submenu.show_all() + Index: gtk3.xml.gz ================================================================== --- gtk3.xml.gz +++ gtk3.xml.gz cannot compute difference between binary files Index: st2.py ================================================================== --- st2.py +++ st2.py @@ -2,11 +2,11 @@ # encoding: UTF-8 # api: python # type: application # title: streamtuner2 # description: Directory browser for internet radio, audio and video streams -# version: 2.2.1-dev20180820 +# version: 2.2.1-dev20181218 # state: stable # author: Mario Salzer # license: Public Domain # url: http://freshcode.club/projects/streamtuner2 # config: @@ -321,12 +321,12 @@ log.UI("on_category_clicked", category, self.current_channel) self.on_reload_clicked(None, reload=0) pass # Add current selection to bookmark store - def bookmark(self, widget): - self.bookmarks.add(self.row()) + def bookmark(self, widget, target="favourite"): + self.bookmarks.add(self.row(), target) self.channel().row_icon(gtk.STOCK_ABOUT) # refresh bookmarks tab self.bookmarks.load(self.bookmarks.default) # Reload category tree