# Copyright 2021 (c) Anna Schumaker. import db import scanner from gi.repository import Gtk from gi.repository import GObject from . import view class LibraryButtons(Gtk.Box): def __init__(self, library): Gtk.Box.__init__(self) self.append(scanner.RemoveButton(library)) self.append(scanner.UpdateButton(library)) self.add_css_class("linked") class LibraryPopover(Gtk.Popover): def __init__(self, library): Gtk.Popover.__init__(self) box = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 10) box.append(LibraryButtons(library)) box.append(scanner.EnableSwitch(library)) self.set_child(box) class ProgressBar(Gtk.Box): def __init__(self): Gtk.Box.__init__(self) self.append(Gtk.Label.new(" ")) self.append(scanner.ProgressBar()) self.append(Gtk.Label.new(" ")) class AddPlaylistEntry(Gtk.Entry): def __init__(self): Gtk.Entry.__init__(self) self.set_placeholder_text("Add new playlist") self.set_icon_from_icon_name(Gtk.EntryIconPosition.PRIMARY, "list-add") self.connect("icon-release", self.icon_released) def icon_released(self, entry, pos): if pos == Gtk.EntryIconPosition.SECONDARY: self.set_text("") else: self.emit("activate") def do_activate(self): if self.get_text() != "": self.emit("activated-playlist", db.user.Table.find(self.get_text())) scanner.commit() self.set_text("") def do_changed(self): icon = None if self.get_text() == "" else "edit-clear-symbolic" self.set_icon_from_icon_name(Gtk.EntryIconPosition.SECONDARY, icon) @GObject.Signal(arg_types=(db.playlist.Playlist,)) def activated_playlist(self, playlist): pass class AddPlaylistPopover(Gtk.Popover): def __init__(self): Gtk.Popover.__init__(self) self.add_css_class("normal-icons") self.box = Gtk.Box.new(Gtk.Orientation.VERTICAL, 5) self.box.append(view.UserView()) self.box.append(AddPlaylistEntry()) self.box.set_focus_child(self.box.get_last_child()) self.set_child(self.box) def get_view(self): return self.box.get_first_child() def get_entry(self): return self.box.get_last_child() class AddPlaylistButton(Gtk.MenuButton): def __init__(self): Gtk.MenuButton.__init__(self) self.set_icon_name("list-add") self.set_direction(Gtk.ArrowType.UP) self.set_popover(AddPlaylistPopover()) self.get_popover().get_view().connect("activate", self.view_activate) self.get_popover().get_entry().connect("activated-playlist", self.entry_activate) def entry_activate(self, entry, playlist): self.emit("add-to-playlist", playlist) def view_activate(self, view, position): self.emit("add-to-playlist", view.get_model().get_item(position)) @GObject.Signal(arg_types=(db.playlist.Playlist,)) def add_to_playlist(self, playlist): pass class AddUpdateBox(Gtk.Box): def __init__(self): Gtk.Box.__init__(self) self.add_css_class("large-icons") self.add_css_class("linked") self.set_homogeneous(True) self.set_margin_top(5) self.set_margin_bottom(5) self.set_margin_start(5) self.set_margin_end(5) self.append(AddPlaylistButton()) self.append(scanner.AddFolderButton()) self.append(scanner.UpdateAllButton())