Ejemplo n.º 1
0
class AddPage(gtk.HBox):
    def __init__(self):
        gtk.HBox.__init__(self)

        self.aibizhi_cache_page = CachePage(Aibizhi())
        self.bizhi360_cache_page = CachePage(Bizhi360())

        self.aibizhi_cache_page.cache_view.try_to_fetch()
        self.bizhi360_cache_page.cache_view.try_to_fetch()
        self.system_wallpapers_page = SystemPage(
            get_system_wallpaper_dirs()[0])
        self.picture_wallpapers_page = PicturePage(get_images_dir())
        self.download_wallpapaers_page = UserPage(get_download_wallpaper_dir())

        self.task_page = TaskPage()

        self.__init_navigatebar()

        self.switch_page = gtk.VBox()
        self.pack_start(self.navigatebar, False, True)
        self.pack_start(self.switch_page, True, True)

        self.switch_page.add(self.system_wallpapers_page)
        event_manager.add_callback("downloading-tasks-number",
                                   self.on_download_item_changed)
        self.connect("expose-event", self.on_addpage_expose_event)

    def set_theme(self, theme):
        self.system_wallpapers_page.set_theme(theme)
        self.picture_wallpapers_page.set_theme(theme)
        self.download_wallpapaers_page.set_theme(theme)
        self.aibizhi_cache_page.set_theme(theme)
        self.bizhi360_cache_page.set_theme(theme)

    def on_download_item_changed(self, name, obj, data):
        pass

    def __init_navigatebar(self):
        self.navigatebar = TreeView(enable_drag_drop=False,
                                    enable_multiple_select=False)
        self.navigatebar.connect("single-click-item",
                                 self.on_navigatebar_single_click)
        self.navigatebar.set_size_request(132, -1)
        self.navigatebar.draw_mask = self.on_navigatebar_draw_mask

        local_expand_item = ExpandItem(_("Library"))
        network_expand_item = ExpandItem(_("Internet"))
        self.navigatebar.add_items([
            local_expand_item,
            network_expand_item,
        ])
        local_expand_item.add_childs(
            [(_("System"), self.system_wallpapers_page),
             (_("Pictures"), self.picture_wallpapers_page),
             (_("Favorites"), self.download_wallpapaers_page)],
            expand=True)
        network_expand_item.add_childs([
            (_("360 Wallpaper"), self.bizhi360_cache_page),
            (_("LoveWallpaper"), self.aibizhi_cache_page),
        ],
                                       expand=True)

        self.navigatebar.set_highlight_item(self.navigatebar.get_items()[1])

    def on_addpage_expose_event(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation

        self.draw_mask(cr, *rect)

    def on_navigatebar_draw_mask(self, cr, x, y, w, h):
        self.draw_mask(cr, x, y, w, h)
        draw_line(cr, (x + w, y), (0, h), "#d6d6d6")

    def draw_mask(self, cr, x, y, w, h):
        '''
        Draw mask interface.
        
        @param cr: Cairo context.
        @param x: X coordiante of draw area.
        @param y: Y coordiante of draw area.
        @param w: Width of draw area.
        @param h: Height of draw area.
        '''
        cr.set_source_rgb(1, 1, 1)
        cr.rectangle(x, y, w, h)
        cr.fill()

    def on_navigatebar_single_click(self, widget, item, column, x, y):
        if item.widget:
            widget.set_highlight_item(item)
            switch_box(self.switch_page, item.widget)
class DetailWindow(Window):
    '''
    class docs
    '''

    def __init__(self):
        '''
        init docs
        '''
        Window.__init__(self, enable_resize=True)
        self.set_size_request(WINDOW_WIDTH, WINDOW_HEIGHT)
        self.set_position(gtk.WIN_POS_CENTER)
        self.set_skip_taskbar_hint(True)
        self.set_skip_pager_hint(True)
        self.resizable = True

        self.classified_items = None
        self.__init_pixbuf()

        self.main_box = gtk.VBox()
        self.titlebar_box = gtk.HBox()
        self.toolbar_box = gtk.HBox()
        self.toolbar_box.set_size_request(-1, TOOLBAR_HEIGHT)

        self.main_view_box = gtk.HBox()
        self.main_view_box.set_size_request(WINDOW_WIDTH,
                                            WINDOW_HEIGHT - TITLEBAR_HEIGHT - TOOLBAR_HEIGHT - 23)

        self.add_titlebar()
        self.treeview_box = gtk.VBox()
        self.main_view_box.pack_start(self.treeview_box, False, False)
        self.listview_box = gtk.VBox()
        self.main_view_box.pack_start(self.listview_box, True, True)
        self.refresh_view() #add treeview and listview

        self.main_box.pack_start(self.toolbar_box, False, False)
        # self.main_box.pack_start(self.main_view_box, False, False)
        self.main_box.pack_start(self.main_view_box, True, True)
        # self.main_box.connect("expose-event", self.on_main_box_expose_event)

        main_box_align = gtk.Alignment(0.5, 0.5, 1, 1)
        main_box_align.set_padding(2, 2, 2, 2)
        main_box_align.add(self.main_box)

        self.window_frame.pack_start(self.titlebar_box, False, False)
        self.window_frame.pack_start(main_box_align)
        
    @property
    def is_empty(self):
        return not bool(len(self.classified_items))

    def __init_pixbuf(self):
        self.import_btn_pixbuf = gtk.gdk.pixbuf_new_from_file(app_theme.get_theme_file_path("image/toolbar_import.png"))
        self.export_btn_pixbuf = gtk.gdk.pixbuf_new_from_file(app_theme.get_theme_file_path("image/toolbar_export.png"))
        self.delete_btn_pixbuf = gtk.gdk.pixbuf_new_from_file(app_theme.get_theme_file_path("image/toolbar_delete.png"))
        self.refresh_btn_pixbuf = gtk.gdk.pixbuf_new_from_file(app_theme.get_theme_file_path("image/toolbar_refresh.png"))

        self.skin_preview_pixbuf = app_theme.get_pixbuf("frame.png")

    def _init_data(self):
        self.__init_data()
        
    def __init_data(self):
        self.classified_items = {}
        rows = db.get_all()

        for row in rows:
            app_name = row[MESSAGE].app_name
            self.classified_items.setdefault(app_name, []).append(row)
            
    def add_to_view(self):
        row = db.get_last()
        
        # add to data
        app_name = row[MESSAGE].app_name
        if app_name in self.classified_items.keys():
            self.classified_items[app_name].insert(0, row)
        else:
            self.classified_items.setdefault(app_name, []).insert(0, row)
            self.treeview_add_item(app_name)

        # add to view
        if app_name == self.treeview.get_highlight_item().get_title():
            self.factory.prepend_item(row)
            
    def refresh_view(self):
        self.__init_data()
        if len(self.classified_items):
            self.add_treeview()
            self.current_showed_items = self.get_items_from_treeview_highlight()
            self.add_listview(self.current_showed_items)
        else:
            align = gtk.Alignment(0.5, 0.5, 0, 0)
            align.add(Label(_("(Empty)")))
            container_remove_all(self.treeview_box)
            container_remove_all(self.listview_box)
            self.listview_box.pack_start(align, True, True)
        self.main_view_box.show_all()

        container_remove_all(self.toolbar_box)
        self.add_toolbar()
        self.toolbar_box.show_all()

    def on_main_box_expose_event(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation

        cr.rectangle(*rect)
        cr.set_source_rgb(*STROKE_LINE_COLOR)
        cr.stroke_preserve()
        cr.set_source_rgb(1, 1, 1)
        cr.fill()


    def on_treeview_draw_mask(self, cr, x, y, w, h):
        cr.set_source_rgb(1, 1, 1)
        cr.rectangle(x, y, w, h)
        cr.fill()

        cr.move_to(x, y)
        cr.line_to(x + w, y)
        cr.set_source_rgb(*STROKE_LINE_COLOR)
        cr.stroke()
        draw_line(cr, (x+w-1, y), (x+w-1, y+h), "#b2b2b2")

    def on_treeview_click_item(self, widget, item, column, x, y):
        if not item.is_parent:
            widget.set_highlight_item(item)

            self.current_showed_items = self.get_items_from_treeview_highlight()
            self.add_listview(self.current_showed_items)

            for comb_item in self.category_comb.items:
                if comb_item.title == item.title:
                    self.category_comb.set_select_index(comb_item_value_to_index(comb_item.item_value))

    def on_treeview_double_click_item(self, widget, item, column, x, y):
        if item.is_parent:
            if item.is_expand:
                item.unexpand()
            else:
                item.expand()

    def on_treeview_right_press_items(self, widget, root_x, root_y, current_item, select_items):
        '''
        docs
        '''
        self.treeview.set_highlight_item(current_item)
        if not current_item.is_parent:
            def on_add_to_bl():
                blacklist.add(current_item.title)
                current_item.is_in_blacklist = True
                current_item.emit_redraw_request()
            def on_remove_from_bl():
                blacklist.remove(current_item.title)
                current_item.is_in_blacklist = False
                current_item.emit_redraw_request()

            menu_items = []
            if current_item.title in blacklist.bl:
                menu_items.append((None, _("Remove from Blacklist"), on_remove_from_bl))
            else:
                menu_items.append((None, _("Add to Blacklist"), on_add_to_bl))

            Menu(menu_items, True).show((int(root_x), int(root_y)))

    def add_treeview(self):
        categories = self.classified_items.keys()
        # root eles
        self.root_ele_software = TreeViewItem(_("Software Messages"), True)
        self.root_ele_system = TreeViewItem(_("System Messages"), True)
        self.treeview = TreeView([self.root_ele_software, self.root_ele_system], expand_column=0)

        # add child items , CAN'T add_child_items before treeview constructed
        software_children = []
        system_children = []
        for category in categories:
            treeview_item = TreeViewItem(category)
            if category in blacklist.bl:
                treeview_item.is_in_blacklist = True

            if category in SYSTEM_SOFTWARE_LIST:
                system_children.append(treeview_item)
            else:
                software_children.append(treeview_item)

        self.root_ele_software.add_child_items(software_children)
        self.root_ele_system.add_child_items(system_children)
        self.treeview.draw_mask = self.on_treeview_draw_mask

        if len(software_children):
            self.treeview.set_highlight_item(software_children[0])
        elif len(system_children):
            self.treeview.set_highlight_item(system_children[0])
            
        self.treeview.set_size_request(220, -1)
        self.treeview.connect("single-click-item", self.on_treeview_click_item)
        self.treeview.connect("right-press-items", self.on_treeview_right_press_items)
        self.treeview.connect("double-click-item", self.on_treeview_double_click_item)

        container_remove_all(self.treeview_box)
        self.treeview_box.pack_start(self.treeview, True, True)
        self.treeview_box.show_all()
        
    def treeview_add_item(self, item):
        if item in SYSTEM_SOFTWARE_LIST:
            self.root_ele_system.add_child_items([TreeViewItem(item)])
        else:
            self.root_ele_software.add_child_items([TreeViewItem(item)])
        self.treeview_box.show_all()

    def add_listview(self, items):
        container_remove_all(self.listview_box)

        if len(items) != 0:
            self.factory = ListviewFactory(items, "detail")
            self.listview = self.factory.listview

            self.listview_box.pack_start(self.listview)
        else:
            empty_box_align = gtk.Alignment(0.5, 0.5, 0, 0)
            empty_box_align.add(Label("(Empty)"))
            self.listview_box.pack_start(empty_box_align)

        self.listview_box.show_all()

    def get_items_from_treeview_highlight(self):
        '''
        docs
        '''
        app_name = self.treeview.get_highlight_item().get_title()
        return self.classified_items[app_name]

    def add_titlebar(self,
                     button_mask=["min", "max", "close"],
                     icon_path=app_theme.get_theme_file_path("image/icon_little.png"),
                     app_name=_("Message Manager"),
                     title=None,
                     add_separator=False,
                     show_title=True,
                     enable_gaussian=True,
                     ):

        # Init titlebar.
        self.titlebar = Titlebar(button_mask,
                                 icon_path,
                                 app_name,
                                 title,
                                 add_separator,
                                 show_title=show_title,
                                 enable_gaussian=enable_gaussian,
                                 )

        self.titlebar.max_button.connect("clicked", lambda w: self.toggle_max_window())
        self.titlebar.min_button.connect("clicked", self.close_callback)
        self.titlebar.close_button.connect("clicked", self.close_callback)

        if self.resizable:
            self.add_toggle_event(self.titlebar)
        self.add_move_event(self.titlebar)

        self.titlebar_box.add(self.titlebar)


    def add_toolbar(self):

        toolbar_btn_box = gtk.HBox()
        toolbar_btn_box_align = gtk.Alignment(0.5, 0.5, 0, 0)

        import_btn = ToolbarItem(self.import_btn_pixbuf, _("Import"))
        import_btn.connect("clicked", self.on_toolbar_import_clicked)
        export_btn = ToolbarItem(self.export_btn_pixbuf, _("Export"))
        export_btn.connect("clicked", self.on_toolbar_export_clicked)
        delete_btn = ToolbarItem(self.delete_btn_pixbuf, _("Delete"))
        delete_btn.connect("clicked", self.on_toolbar_delete_clicked)
        refresh_btn = ToolbarItem(self.refresh_btn_pixbuf, _("Refresh"))
        refresh_btn.connect("clicked", self.on_toolbar_refresh_clicked)

        toolbar_btn_box.pack_start(import_btn, False, False, 2)
        toolbar_btn_box.pack_start(export_btn, False, False, 2)
        toolbar_btn_box.pack_start(delete_btn, False, False, 2)
        toolbar_btn_box.pack_start(refresh_btn, False, False, 2)
        toolbar_btn_box_align.add(toolbar_btn_box)

        look_in_Label = Label(
            _("Look up in"),
            text_color=ui_theme.get_color("title_text"),
            )

        self.category_comb = ComboBox([(_("All"), 0)])
        self.category_comb.add_items([(item, index) for index, item in enumerate(self.classified_items)], clear_first=False)
        self.time_comb = ComboBox([(_("Today"), 0),
                                   (_("Last week"), 1),
                                   (_("Last month"), 2),
                                   (_("Last three months"), 3),
                                   (_("Last year"), 4),
                                   (_("All"), 5)
                                   ])

        self.category_comb.set_size_request(-1, TOOLBAR_ENTRY_HEIGHT)
        self.category_comb.connect("item-selected", self.on_category_comb_item_selected)
        self.time_comb.set_size_request(-1, TOOLBAR_ENTRY_HEIGHT)
        self.time_comb.connect("item-selected", self.on_time_comb_item_selected)
        combos_box = gtk.HBox()
        combos_box.pack_start(self.category_comb, False, False, 5)
        combos_box.pack_start(self.time_comb, False, False)

        combos_box_align = gtk.Alignment(0.5, 0.5, 1, 1)
        padding_height = (TOOLBAR_HEIGHT - TOOLBAR_ENTRY_HEIGHT) / 2
        combos_box_align.set_padding(padding_height, padding_height, 5, 5)
        combos_box_align.add(combos_box)


        find_content_Label = Label(
            _("Find in content"),
            text_color=ui_theme.get_color("title_text"),
            )


        search_entry = SearchEntry()
        search_entry.connect("action-active", self.on_search_entry_action_active)
        search_entry_align = gtk.Alignment(0.5, 0.5, 1, 1)
        search_entry_align.set_padding(padding_height, padding_height, 5, 5)
        search_entry_align.add(search_entry)

        #Align left
        self.toolbar_box.pack_start(toolbar_btn_box_align, False, False, 5)

        #Align right
        self.toolbar_box.pack_end(search_entry_align, False, True, 5)
        self.toolbar_box.pack_end(find_content_Label, False, False, 5)
        self.toolbar_box.pack_end(combos_box_align, False, False, 0)
        self.toolbar_box.pack_end(look_in_Label, False, False, 5)
        self.toolbar_box.pack_end(ToolbarSep(), False, False, 5)


    def on_category_comb_item_selected(self, widget, item_title, item_value, item_index):
        if item_title != "All":
            for item in self.treeview.get_items():
                if item.title == item_title:
                    self.treeview.set_highlight_item(item)
                    self.current_showed_items = self.get_items_from_treeview_highlight()
                    self.add_listview(self.current_showed_items)
                    break


    def on_time_comb_item_selected(self, widget, item_title, item_value, item_index):
        if item_value != 5:
            filtrated_result = []
            for item in self.current_showed_items:
                item_datetime = datetime.strptime(item[TIME], "%Y/%m/%d-%H:%M:%S")
                if datetime.today() - item_datetime < timedelta_dict[item_value]:
                    filtrated_result.append(item)
            self.current_showed_items = filtrated_result
            self.add_listview(filtrated_result)


    def get_search_result_iter(self, search_str):
        filter_keywords = search_str.split()

        for item in self.current_showed_items:
            item_message = item[MESSAGE]
            for keyword in filter_keywords:
                # print "from %s search %s result %s:" % (item_message.body, keyword, item_message.body.find(keyword) != -1)
                if item_message.body.find(keyword) != -1:
                    yield item
                    continue

    def on_search_entry_action_active(self, widget, text):
        search_result_iter = self.get_search_result_iter(text)

        self.add_listview(list(search_result_iter))

    def on_toolbar_import_clicked(self, widget):
        self.filename_to_import = ""

        def ok_clicked(filename):
            self.filename_to_import = filename

        OpenFileDialog(_("Select File to Import"), self, ok_clicked, None)

        if len(self.filename_to_import) != 0:
            try:
                def import_db_func():
                    db.import_db(self.filename_to_import)
                    self.refresh_view()
                threading.Thread(target=import_db_func).start()
            except Exception, e:
                pass
class MainBox(gtk.HBox):
    def __init__(self):
        gtk.HBox.__init__(self)
        self.connect("expose-event", self.on_page_expose_event)

        self.aibizhi_cache_page = CachePage(Aibizhi())
        self.bizhi360_cache_page = CachePage(Bizhi360())
        self.aibizhi_cache_page.cache_view.try_to_fetch()
        self.bizhi360_cache_page.cache_view.try_to_fetch()

        self.favorites_page = FavoritePage(get_favorite_dir())
        self.pictures_page = LocalPicturePage(get_download_wallpaper_dir())

        self.add_item = AddItem()
        self.pictures_page.select_view.add_items([self.add_item])

        self.task_page = TaskPage()
        
        self.switch_page = gtk.VBox()
        self.__init_navigatebar()

        self.pack_start(self.navigatebar, False, True)
        self.pack_start(self.switch_page, True, True)

        event_manager.add_callback("switch-to-local-pictures", self.switch_to_local_pictures)

    def switch_to_local_pictures(self, name, obj, data=None):
        item = self.navigatebar.get_items()[2]
        self.on_navigatebar_single_click(self.navigatebar, item, 0, 0, 0)

    def __init_navigatebar(self):
        self.navigatebar = TreeView(enable_drag_drop=False, enable_multiple_select=False)
        self.navigatebar.connect("single-click-item", self.on_navigatebar_single_click)
        self.navigatebar.set_size_request(132, -1)
        self.navigatebar.draw_mask = self.on_navigatebar_draw_mask
        
        local_expand_item = ExpandItem(_("Library"))
        network_expand_item = ExpandItem(_("Internet"))
        self.navigatebar.add_items([local_expand_item, 
                                    network_expand_item, 
                                   ])
        local_expand_item.add_childs([
            (FavoritesTitle, self.favorites_page),
            (LocalWallpapersTitle, self.pictures_page),
            ],
            expand=True)
        network_expand_item.add_childs([(_("360 Wallpaper"), self.bizhi360_cache_page), 
                                        (_("LoveWallpaper"), self.aibizhi_cache_page),
                                       ], expand=True)        
        
        if get_favorite_number() == 0:
            self.navigatebar.set_highlight_item(self.navigatebar.get_items()[2])
            self.switch_page.add(self.pictures_page)
        else:
            self.navigatebar.set_highlight_item(self.navigatebar.get_items()[1])
            self.switch_page.add(self.favorites_page)

    def draw_mask(self, cr, x, y, w, h):
        cr.set_source_rgb(1, 1, 1)
        cr.rectangle(x, y, w, h)
        cr.fill()

    def on_page_expose_event(self, widget, event):    
        cr = widget.window.cairo_create()
        width, height= widget.size_request()
        self.draw_mask(cr, 0, 0, width, height)

    def on_navigatebar_draw_mask(self, cr, x, y, w, h):    
        self.draw_mask(cr, x, y, w, h)
        draw_line(cr, (x + w, y), (0, h), "#d6d6d6")        

    def on_navigatebar_single_click(self, widget, item, column, x, y):
        if item.widget:
            widget.set_highlight_item(item)
            switch_box(self.switch_page, item.widget)
Ejemplo n.º 4
0
class SearchUI(DialogBox):
    def __init__(self):
        DialogBox.__init__(
            self, _("Lyrics search"), 460, 300, DIALOG_MASK_MULTIPLE_PAGE, close_callback=self.hide_all, 
            modal=False, window_hint=None, skip_taskbar_hint=False, window_pos=gtk.WIN_POS_CENTER)
        
        self.artist_entry = InputEntry()
        self.artist_entry.set_size(130, 23)
        self.title_entry = InputEntry()
        self.title_entry.set_size(130, 23)
        artist_label = Label(_("Artist:"))
        title_label = Label(_("Title:"))
        right_align = gtk.Alignment()
        right_align.set(0, 0, 0, 1)
        
        self.search_button = Button(_("Search"))
        self.search_button.connect("clicked", self.search_lyric_cb)
        self.process_id = 0
        
        info_box = gtk.HBox(spacing=25)
        
        control_box = gtk.HBox(spacing=5)
        title_box = gtk.HBox(spacing=5)        
        title_box.pack_start(title_label, False, False)
        title_box.pack_start(self.title_entry)
        artist_box = gtk.HBox(spacing=5)
        artist_box.pack_start(artist_label, False, False)
        artist_box.pack_start(self.artist_entry)
        control_box.pack_start(title_box, False, False)
        control_box.pack_start(artist_box, False, False)
        
        info_box.pack_start(control_box, False, False)
        info_box.pack_start(self.search_button, False, False)
        
        sort_items = [ lambda items, reverse : self.sort_by_key(items, reverse, "title"),
                       lambda items, reverse : self.sort_by_key(items, reverse, "artist")]
        self.result_view = TreeView()
        self.result_view.set_expand_column(0)
        self.result_view.connect("double-click-item", self.double_click_cb)
        self.result_view.set_column_titles([_("Title"), _("Artist")], sort_items)
        self.result_view.draw_mask = self.draw_view_mask
        
        self.prompt_label = Label("")
        download_button = Button(_("Download"))
        download_button.connect("clicked", self.download_lyric_cb)
        cancel_button = Button(_("Close"))
        cancel_button.connect("clicked", lambda w: self.hide_all())
        
        info_box_align = gtk.Alignment()
        info_box_align.set_padding(5, 0, 5, 0)
        info_box_align.add(info_box)
        
        self.body_box.set_spacing(5)
        self.body_box.pack_start(info_box_align, False, False)
        self.body_box.pack_start(self.result_view, True, True)
        self.left_button_box.set_buttons([self.prompt_label])
        self.right_button_box.set_buttons([download_button, cancel_button])
        self.lrc_manager = LrcManager()
        
    def show_window(self):    
        DialogBox.show_window(self)
        self.present()
                
    def draw_view_mask(self, cr, x, y, width, height):            
        draw_alpha_mask(cr, x, y, width, height, "layoutMiddle")
        
    def sort_by_key(self, items, sort_reverse, sort_key):    
        return sorted(items, reverse=sort_reverse, key=lambda item: getattr(item, sort_key))
        
    def double_click_cb(self, widget, item, colume, x, y):   
        self.download_lyric_cb(widget)
        
    def search_engine(self, artist, title, pid):    
        
        ting_result = poster.query_lrc_info(artist, title)
        self.render_lyrics(ting_result, pid=pid)
        
        ttplayer_result = TTPlayer().request(artist, title)
        self.render_lyrics(ttplayer_result, pid=pid)
        
        ttpod_result = TTPod().request(artist, title)        
        self.render_lyrics(ttpod_result, pid=pid)
        
        duomi_result = DUOMI().request(artist, title)
        self.render_lyrics(duomi_result, pid=pid, last=True)
        
        
    def search_lyric_cb(self, widget):
        self.result_view.clear()
        artist = self.artist_entry.entry.get_text()
        title = self.title_entry.entry.get_text()
        # widget.set_sensitive(False)
        self.prompt_label.set_text(_("Now searching..."))
        if artist == "" and title == "":
            self.prompt_label.set_text(_("Not found!"))
            return
        self.process_id += 1
        utils.ThreadLoad(self.search_engine, artist, title, self.process_id).start()
        
    @post_gui
    def render_lyrics(self, result, last=False, pid=1):
        '''docs'''
        if pid != self.process_id:
            return
        
        if result != None:
            try:
                items = [SearchItem(each_info) for each_info in result]
            except:    
                pass
            else:
                self.result_view.add_items(items)

            self.prompt_label.set_text(_("%d lyrics found") % len(self.result_view.get_items()))
        else:    
            if last:
                if len(self.result_view.get_items()) > 0:
                    self.prompt_label.set_text(_("%d lyrics found") % len(self.result_view.get_items()))
                else:
                    self.prompt_label.set_text(_("Not found!"))
                    

    def download_lyric_cb(self, widget):
        select_items = self.result_view.select_rows
        save_filepath = self.lrc_manager.get_lrc_filepath(Player.song)
        if len(select_items) > 0:
            self.prompt_label.set_text(_("Downloading lyrics..."))
            item = self.result_view.get_items()[select_items[0]]
            url = item.get_url()
            net_encode = item.get_netcode()
            utils.ThreadRun(utils.download, self.render_download, [url, save_filepath, net_encode]).start()
            
    @post_gui        
    def render_download(self, result):
        if result:
            Dispatcher.reload_lrc(Player.song)
            self.prompt_label.set_text("%s %s" % (_("File save to"), config.get("lyrics", "save_lrc_path")))
        else:    
            self.prompt_label.set_text(_("Download failed."))
Ejemplo n.º 5
0
class MainBox(gtk.HBox):
    def __init__(self):
        gtk.HBox.__init__(self)
        self.connect("expose-event", self.on_page_expose_event)

        self.aibizhi_cache_page = CachePage(Aibizhi())
        self.bizhi360_cache_page = CachePage(Bizhi360())
        self.aibizhi_cache_page.cache_view.try_to_fetch()
        self.bizhi360_cache_page.cache_view.try_to_fetch()

        self.favorites_page = FavoritePage(get_favorite_dir())
        self.pictures_page = LocalPicturePage(get_download_wallpaper_dir())

        self.add_item = AddItem()
        self.pictures_page.select_view.add_items([self.add_item])

        self.task_page = TaskPage()

        self.switch_page = gtk.VBox()
        self.__init_navigatebar()

        self.pack_start(self.navigatebar, False, True)
        self.pack_start(self.switch_page, True, True)

        event_manager.add_callback("switch-to-local-pictures",
                                   self.switch_to_local_pictures)

    def switch_to_local_pictures(self, name, obj, data=None):
        item = self.navigatebar.get_items()[2]
        self.on_navigatebar_single_click(self.navigatebar, item, 0, 0, 0)

    def __init_navigatebar(self):
        self.navigatebar = TreeView(enable_drag_drop=False,
                                    enable_multiple_select=False)
        self.navigatebar.connect("single-click-item",
                                 self.on_navigatebar_single_click)
        self.navigatebar.set_size_request(132, -1)
        self.navigatebar.draw_mask = self.on_navigatebar_draw_mask

        local_expand_item = ExpandItem(_("Library"))
        network_expand_item = ExpandItem(_("Internet"))
        self.navigatebar.add_items([
            local_expand_item,
            network_expand_item,
        ])
        local_expand_item.add_childs([
            (FavoritesTitle, self.favorites_page),
            (LocalWallpapersTitle, self.pictures_page),
        ],
                                     expand=True)
        network_expand_item.add_childs([
            (_("360 Wallpaper"), self.bizhi360_cache_page),
            (_("LoveWallpaper"), self.aibizhi_cache_page),
        ],
                                       expand=True)

        if get_favorite_number() == 0:
            self.navigatebar.set_highlight_item(
                self.navigatebar.get_items()[2])
            self.switch_page.add(self.pictures_page)
        else:
            self.navigatebar.set_highlight_item(
                self.navigatebar.get_items()[1])
            self.switch_page.add(self.favorites_page)

    def draw_mask(self, cr, x, y, w, h):
        cr.set_source_rgb(1, 1, 1)
        cr.rectangle(x, y, w, h)
        cr.fill()

    def on_page_expose_event(self, widget, event):
        cr = widget.window.cairo_create()
        width, height = widget.size_request()
        self.draw_mask(cr, 0, 0, width, height)

    def on_navigatebar_draw_mask(self, cr, x, y, w, h):
        self.draw_mask(cr, x, y, w, h)
        draw_line(cr, (x + w, y), (0, h), "#d6d6d6")

    def on_navigatebar_single_click(self, widget, item, column, x, y):
        if item.widget:
            widget.set_highlight_item(item)
            switch_box(self.switch_page, item.widget)
class AddPage(gtk.HBox):
    
    def __init__(self):
        gtk.HBox.__init__(self)

        self.aibizhi_cache_page = CachePage(Aibizhi())
        self.bizhi360_cache_page = CachePage(Bizhi360())
        
        self.aibizhi_cache_page.cache_view.try_to_fetch()
        self.bizhi360_cache_page.cache_view.try_to_fetch()
        self.system_wallpapers_page = SystemPage(get_system_wallpaper_dirs()[0])
        self.picture_wallpapers_page = PicturePage(get_images_dir())
        self.download_wallpapaers_page = UserPage(get_download_wallpaper_dir())

        self.task_page = TaskPage()
        
        self.__init_navigatebar()
        
        self.switch_page = gtk.VBox()
        self.pack_start(self.navigatebar, False, True)
        self.pack_start(self.switch_page, True, True)
        
        self.switch_page.add(self.system_wallpapers_page)
        event_manager.add_callback("downloading-tasks-number", self.on_download_item_changed)
        self.connect("expose-event", self.on_addpage_expose_event)
        
    def set_theme(self, theme):
        self.system_wallpapers_page.set_theme(theme)
        self.picture_wallpapers_page.set_theme(theme)
        self.download_wallpapaers_page.set_theme(theme)
        self.aibizhi_cache_page.set_theme(theme)
        self.bizhi360_cache_page.set_theme(theme)

    def on_download_item_changed(self, name, obj, data):    
        pass

    def __init_navigatebar(self):    
        self.navigatebar = TreeView(enable_drag_drop=False, enable_multiple_select=False)
        self.navigatebar.connect("single-click-item", self.on_navigatebar_single_click)
        self.navigatebar.set_size_request(132, -1)
        self.navigatebar.draw_mask = self.on_navigatebar_draw_mask
        
        local_expand_item = ExpandItem(_("Library"))
        network_expand_item = ExpandItem(_("Internet"))
        self.navigatebar.add_items([local_expand_item, 
                                    network_expand_item, 
                                   ])
        local_expand_item.add_childs([(_("System"), self.system_wallpapers_page),
                                      (_("Pictures"), self.picture_wallpapers_page), 
                                      (_("Favorites"), self.download_wallpapaers_page)], expand=True)
        network_expand_item.add_childs([(_("360 Wallpaper"), self.bizhi360_cache_page), 
                                        (_("LoveWallpaper"), self.aibizhi_cache_page),
                                       ], expand=True)        
        
        self.navigatebar.set_highlight_item(self.navigatebar.get_items()[1])
        
    def on_addpage_expose_event(self, widget, event):    
        cr = widget.window.cairo_create()
        rect = widget.allocation
        
        self.draw_mask(cr, *rect)
        
    def on_navigatebar_draw_mask(self, cr, x, y, w, h):    
        self.draw_mask(cr, x, y, w, h)
        draw_line(cr, (x + w, y), (0, h), "#d6d6d6")        
        
    def draw_mask(self, cr, x, y, w, h):
        '''
        Draw mask interface.
        
        @param cr: Cairo context.
        @param x: X coordiante of draw area.
        @param y: Y coordiante of draw area.
        @param w: Width of draw area.
        @param h: Height of draw area.
        '''
        cr.set_source_rgb(1, 1, 1)
        cr.rectangle(x, y, w, h)
        cr.fill()
        

    def on_navigatebar_single_click(self, widget, item, column, x, y):
        if item.widget:
            widget.set_highlight_item(item)
            switch_box(self.switch_page, item.widget)
Ejemplo n.º 7
0
class PlaylistUI(gtk.VBox):
    '''Playlist UI.'''
	
    def __init__(self):
        '''Init.'''
        gtk.VBox.__init__(self)

        # Init catagory list.
        self.category_list = TreeView()
        self.category_list.draw_mask = self.draw_category_list_mask
        self.category_list.connect("single-click-item", self.on_category_single_click)
        self.category_list.connect("right-press-items", self.on_category_right_press)
        self.category_list.set_size_request(CATEGROYLIST_WIDTH, -1)
        
        # Init SearchEntry.
        self.entry_box = SearchEntry("")
        self.entry_box.entry.connect("changed", self.search_cb)
        self.entry_box.set_no_show_all(True)
        entry_align = gtk.Alignment()
        entry_align.set(0, 0, 1, 1)
        entry_align.set_padding(2, 0, 10, 10)
        entry_align.add(self.entry_box)
        entry_align.connect("expose-event", self.expose_entry_mask)
        
        # Init toolbar.
        self.toolbar_box = gtk.HBox(spacing=45)
        self.search_button = self.__create_simple_toggle_button("search", self.show_text_entry, 
                                                                _("Search in Current Playlist"))
        
        self.__create_simple_button("list", self.popup_list_menu, _("Playlist Operations"))
        self.__create_simple_button("add", self.popup_add_menu, _("Add"))
        
        self.playmode_button = PlaymodeButton(config.get("setting", "loop_mode", "list_mode").split("_")[0])
        Tooltip.text(self.playmode_button, _("Playback Order"))
        self.playmode_button.connect("button-press-event", self.popup_sort_menu)
        self.toolbar_box.pack_start(self.playmode_button, False, False)
        self.__create_simple_button("delete", self.popup_delete_menu, _("Delete"))
        toolbar_align = gtk.Alignment()
        toolbar_align.set_padding(6, 6, 28, 0)
        toolbar_align.add(self.toolbar_box)
        toolbar_align.connect("expose-event", self.expose_toolbar_mask)
                
        self.right_box = gtk.VBox()
        self.right_box.connect("size-allocate", self.on_right_box_size_allocate)
        self.list_paned = HPaned(handle_color=app_theme.get_color("panedHandler"), enable_drag=True)
        self.list_paned.pack1(self.category_list, True, True)
        self.list_paned.pack2(self.right_box, True, False)
        bottom_box = gtk.VBox()
        bottom_box.set_size_request(-1, 22)
        self.pack_start(self.list_paned, True, True)            
        self.pack_start(entry_align, False, False)            
        self.pack_start(toolbar_align, False, True)            
        
        # Current
        self.current_playlist = None
        self.search_time_source = 0        
        self.current_item = None
        self.search_flag = False
        self.cache_items = None
        self.delete_source_id = None
        self.drag_source_id = None
        self.menu_source_id = None
        self.song_notify_id = None
        self.detail_menu = None
        
        if MediaDB.isloaded():
            self.__on_db_loaded(MediaDB)
        else:    
            MediaDB.connect("loaded", self.__on_db_loaded)
            
        Player.connect("loaded", self.__on_player_loaded)    
        Dispatcher.connect("play-song", self.__play_and_add)
        Dispatcher.connect("add-songs", self.__add_songs_to_list)
        Dispatcher.connect("new-cd-playlist", self.__new_audiocd_playlist)
        Dispatcher.connect("del-cd-playlist", self.delete_audiocd_list)
        Dispatcher.connect("save-current-list", self.save_current_playlist)
        config.connect("config-changed", self.on_config_changed)
        
    def on_config_changed(self, config, section, option, value):    
        if section == "setting" and option == "loop_mode":
            icon_name = value.split("_")[0]
            self.playmode_button.update_dpixbufs(icon_name, True)
        
    def on_right_box_size_allocate(self, widget, rect):    
        if self.current_item:
            if rect.width > HIDE_PLAYLIST_WIDTH:
                self.current_item.song_view.set_hide_columns(None)
            else:    
                self.current_item.song_view.set_hide_columns([1])
        
    def expose_toolbar_mask(self, widget, event):    
        cr = widget.window.cairo_create()
        rect = widget.allocation
        cr.set_source_rgba(1, 1, 1, 0.95)
        cr.rectangle(rect.x, rect.y, rect.width, rect.height)
        cr.fill()
        
        draw_line(cr, (rect.x, rect.y + 1), 
                  (rect.x + rect.width, rect.y + 1), "#b0b0b0")
        return False
    
    def expose_entry_mask(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation
        draw_alpha_mask(cr, rect.x , rect.y, rect.width, rect.height, "toolbarEntry")
        
    def draw_category_list_mask(self, cr, x, y, width, height):
        draw_alpha_mask(cr, x, y, width, height, "layoutLeft")
        
    def draw_item_mask(self, cr, x, y, width, height):    
        draw_vlinear(cr, x, y, width, height,
                     app_theme.get_shadow_color("editlistItemPress").get_color_info())        
        
    def __on_db_loaded(self, db):        
        if not MediaDB.get_playlists():
            MediaDB.create_playlist("local", _("Default List"))            
            
        # From MediaDB loaded playlists.    
        init_items = [ListTreeItem(pl) for pl in MediaDB.get_playlists()]    
        self.category_list.add_items(init_items)
        
        # Init Category_list.
        self.category_list.set_highlight_item(self.get_categroy_item_by_index(self.get_save_item_index()))
        self.current_item = self.category_list.get_highlight_item()
        
        self.delete_source_id = self.current_item.song_view.connect("delete-select-items", self.parser_delete_items)
        self.drag_source_id = self.current_item.song_view.connect("drag-data-received", self.parser_drag_event)
        self.menu_source_id = self.current_item.song_view.connect("right-press-items", self.popup_detail_menu)

        Player.set_source(self.current_item.song_view)
        self.right_box.add(self.current_item.get_list_widget())
        self.list_paned.show_all()
        
    def __on_player_loaded(self, player):   
        if self.current_item:
            self.current_item.song_view.reset_error_items()
            self.current_item.song_view.set_highlight_song(Player.song)
        
    def __play_and_add(self, widget, song):    
        self.current_item.song_view.add_songs(song, play=True)
        
    def __add_songs_to_list(self, widget, songs):
        if songs and self.current_item.song_view:
            self.current_item.song_view.add_songs(songs)
        
    def get_selected_song_view(self):    
        if self.current_item:
            return self.current_item.song_view
            
    def search_cb(self, widget, text):        
        if not self.search_flag:
            self.cache_items = self.current_item.song_view.get_items()
        
        # Clear song_view select status    
        self.current_item.song_view.clear_highlight()
        self.current_item.song_view.select_rows = []
        
        if text != "":
            self.search_flag = True
            results = filter(lambda item: text.lower().replace(" ", "") in item.get_song().get("search", ""), self.cache_items)
            self.current_item.song_view.set_song_items(results)
        else:    
            self.search_flag = False
            self.current_item.song_view.set_song_items(self.cache_items)
            
            if Player.song:
                self.current_item.song_view.set_highlight_song(Player.song)
        
    def parser_delete_items(self, widget, items):    
        if self.search_flag:
            if self.cache_items != None:
                [self.cache_items.remove(item) for item in items if item in self.cache_items]
        
    def parser_drag_event(self, widget, context, x, y, selection, info, timestamp):
        if self.search_flag:
            self.reset_search_entry()
            
    def reset_search_entry(self):        
        self.search_button.set_active(False)
            
    def __create_simple_toggle_button(self, name, callback, tip_msg=""):        
        toggle_button = ToggleButton(
            app_theme.get_pixbuf("toolbar/%s_normal.png" % name),
            app_theme.get_pixbuf("toolbar/%s_press.png" % name),
            )
        toggle_button.connect("toggled", callback)
        
        if tip_msg:
            Tooltip.text(toggle_button, tip_msg)
            
        self.toolbar_box.pack_start(toggle_button, False, False)
        return toggle_button
            
    def __create_simple_button(self, name, callback, tip_msg=""):        
        button = ImageButton(
            app_theme.get_pixbuf("toolbar/%s_normal.png" % name),
            app_theme.get_pixbuf("toolbar/%s_hover.png" % name),
            app_theme.get_pixbuf("toolbar/%s_press.png" % name),
            )
        button.connect("button-press-event", callback)
        if tip_msg:
            Tooltip.text(button, tip_msg)
            
        self.toolbar_box.pack_start(button, False, False)
        return button
                                                        
    def popup_add_menu(self, widget, event):
        self.current_item.song_view.popup_add_menu(int(event.x_root), int(event.y_root))
        
        
    def popup_list_menu(self, widget, event):    
        menu_items = [(None, _("New List"), self.new_list),
                      (None, _("Import List"), self.leading_in_list),
                      (None, _("Open List"), self.add_to_list),
                      (None, _("Export List"), self.leading_out_list),
                      (None, _("Remove List"), self.delete_item_list),
                      None,
                      (None, _("Save all Lists"), self.save_all_list)]
        Menu(menu_items, True).show((int(event.x_root), int(event.y_root)))
        
    def new_list(self, items=[], name=None):    
        index = len(self.category_list.get_items())
        if name is None:
            name = "%s%d" % (_("New List"), index)
        input_dialog = InputDialog(_("New List"), name, 300, 100, lambda name : self.create_new_playlist(name, items))
        input_dialog.show_all()
        
    def create_new_playlist(self, name, items):    
        self.category_list.add_items([ListTreeItem(Playlist("local", name, items))])
        
    def __new_audiocd_playlist(self, obj, name, songs, udi):
        self.category_list.add_items([ListTreeItem(CDPlaylist("audiocd", name, songs), udi=udi)]) 
        
    def get_categroy_other_items(self):    
        other_items = []
        highlight_item = self.category_list.get_highlight_item()
        for item in self.category_list.get_items():
            if highlight_item == item:
                continue
            other_items.append(item)
        return other_items    
    
    def get_categroy_index_by_item(self, item):
        index = -1
        for each_index, each_item in enumerate(self.category_list.get_items()):
            if item == each_item: 
                index = each_index
                break
        return index    
    
    def get_categroy_item_by_index(self, index):
        try:
            return self.category_list.get_items()[index]
        except:
            return None
        
    def get_edit_sub_menu(self, select_items, move=False):    
        sub_menu_items = []
        if len(self.category_list.get_items()) > 1:
            other_category_items = self.get_categroy_other_items()
            sub_menu_items = [(None, category_item.get_title(), 
                               self.edit_list_item, category_item, select_items ,move) for category_item in other_category_items]
        if sub_menu_items:    
            sub_menu_items.extend([None, ((app_theme.get_pixbuf("toolbar/add_normal.png"), None, None),
                                          _("New List"), self.edit_new_list_item, select_items, move)])
        else:    
            sub_menu_items.extend([((app_theme.get_pixbuf("toolbar/add_normal.png"), None, None),
                                    _("New List"), self.edit_new_list_item, select_items, move)])
        return Menu(sub_menu_items)
    
    def edit_list_item(self, category_item, select_items, move):
        try:
            category_item.song_view.add_items(select_items)
            category_item.song_view.update_item_index()
            category_item.song_view.update_vadjustment()        
            if move:
                self.current_item.song_view.remove_select_items()
        except:        
            pass
        else:
            self.current_item.song_view.update_item_index()
            self.current_item.song_view.update_vadjustment()
        
    def edit_new_list_item(self, select_items, move):    
        self.new_list([item.get_song().get("uri") for item in select_items])
        if move:
            self.current_item.song_view.remove_select_items()
        self.current_item.song_view.update_item_index()    
        self.current_item.song_view.update_vadjustment()
        
    def leading_in_list(self):    
        uri = WindowLoadPlaylist().run()
        try:
            p_name = utils.get_filename(uri)
            pl = MediaDB.create_playlist("local", p_name, [])
            new_item = ListTreeItem(pl)
            self.category_list.add_items([new_item])
            new_item.song_view.async_add_uris(uri)
        except:    
            pass
        
    def leading_out_list(self, item):    
        if not item:
            item = self.current_item
        WindowExportPlaylist(item.get_songs()).run()
        
    def add_to_list(self, item=None):    
        uri = WindowLoadPlaylist().run()
        if uri:
            try:
                if not item:
                    item = self.current_item
                item.song_view.async_add_uris(uri)
            except: pass    
            
    def delete_audiocd_list(self, obj, udi):
        reset = False
        for item in self.category_list.get_items():
            if item.udi == udi:
                reset = True
                self.category_list.delete_items([item])
        if reset:        
            self.reset_highlight_item(self.category_list.get_items()[-1])    
            
    def delete_item_list(self, item):
        if len(self.category_list.get_items()) == 1:
            return
        
        index = self.get_categroy_index_by_item(item)
        self.category_list.delete_items([item])
        
        max_index = len(self.category_list.get_items()) - 1
        if index <= max_index: 
            new_index = index
        else:    
            new_index = index- 1
        self.reset_highlight_item(self.category_list.get_items()[new_index])    
        
    def save_all_list(self):    
        uri = WinDir().run()
        if uri:
            try:
                save_name_dict = {}
                dir_name = utils.get_path_from_uri(uri)
                for item in self.category_list.get_items():
                    item_name = item.get_title()
                    save_name_dict[item_name] = save_name_dict.get(item_name, -1) + 1
                    if save_name_dict.get(item_name) > 0:
                        filename = "%s%d.%s" % (os.path.join(dir_name, item_name), save_name_dict.get(item_name), "m3u")
                    else:    
                        filename = "%s.%s" % (os.path.join(dir_name, item_name), "m3u")
                    utils.export_playlist(item.get_songs(), filename, "m3u")
            except:        
                pass
        
    def reset_highlight_item(self, item):    
        self.category_list.set_highlight_item(item)
        self.on_category_single_click(None, item, None, None, None)
        
        
    def get_current_item_index(self):    
        item = self.category_list.get_highlight_item()
        index = self.get_categroy_index_by_item(item)
        if index is None:
            return 0
        else:
            return index
    
    def popup_sort_menu(self, widget, event):
        self.current_item.song_view.get_playmode_menu([int(event.x_root), int(event.y_root)])
    
    def popup_delete_menu(self, widget, event):
        self.current_item.song_view.popup_delete_menu(int(event.x_root), int(event.y_root))
        
    def get_save_item_index(self):    
        index = config.getint("playlist", "current_index")
        if index <= len(self.category_list.get_items()) - 1:
            return index
        return 0
    
    def on_category_right_press(self, widget, x, y, item, column):    
        if not item:
            menu_items = [
                (None, _("New List"), self.new_list),
                (None, _("Import List"), self.leading_in_list),
                None,
                (None, _("Save all Lists"), self.save_all_list)
                ]
        else:    
            menu_items = [
                (None, _("Rename"), lambda : self.rename_item_list(item)),
                (None, _("Remove List"), lambda : self.delete_item_list(item)),
                (None, _("Open List"), lambda : self.add_to_list(item)),
                None,
                (None, _("Save all Lists"), self.save_all_list)
                ]
            
        Menu(menu_items, True).show((x, y))    
            
    def rename_item_list(self, item):        
        input_dialog = InputDialog(_("Rename"), item.get_title(), 300, 100,
                                   lambda name: item.set_title(name))    
        input_dialog.show_all()
        
    def on_category_button_press(self, widget, event):    
        if event.button == 3:
            self.popup_list_menu(widget, event)
        
    def on_category_single_click(self, widget, item, column, x, y):        
        self.reset_search_entry()
        if self.drag_source_id != None or self.delete_source_id != None or self.menu_source_id !=None:
            gobject.source_remove(self.drag_source_id)
            gobject.source_remove(self.delete_source_id)
            gobject.source_remove(self.menu_source_id)

        self.current_item = item
        self.category_list.set_highlight_item(item)
        
        self.delete_source_id = self.current_item.song_view.connect("delete-select-items", self.parser_delete_items)
        self.drag_source_id = self.current_item.song_view.connect("drag-data-received", self.parser_drag_event)
        self.menu_source_id = self.current_item.song_view.connect("right-press-items", self.popup_detail_menu)

        container_remove_all(self.right_box)
        self.right_box.add(item.get_list_widget())
        self.list_paned.show_all()
        
    def show_text_entry(self, widget):        
        if widget.get_active():
            self.entry_box.set_no_show_all(False)
            self.entry_box.show_all()
            self.entry_box.focus_input()
        else:    
            self.entry_box.hide_all()            
            self.entry_box.set_no_show_all(True)                        
            self.entry_box.entry.set_text("")
            
    def popup_detail_menu(self, widget, x, y, item, select_items):        
        if self.detail_menu != None:
            self.detail_menu.destroy()
        play_mode_menu = self.current_item.song_view.get_playmode_menu(align=True)
        sort_dict = OrderedDict()
        sort_dict["file"] = _("By Filename")        
        sort_dict["title"] = _("By Title")
        sort_dict["artist"] = _("By Artist")        
        sort_dict["album"] = _("By Album") 
        sort_dict["genre"] = _("By Genre")
        sort_dict["#track"] = _("By Track")
        sort_dict["#playcount"] = _("By Play Count")
        sort_dict["#added"] = _("By Date Added")

        sort_items = [(None, value, self.current_item.song_view.set_sort_keyword, key) for key, value in sort_dict.iteritems()]
        sort_items.append(None)
        sort_items.append((None, _("Randomize"), self.current_item.song_view.random_reorder))
        sub_sort_menu = Menu(sort_items)
        add_to_list_menu = self.get_edit_sub_menu(select_items)
        move_to_list_menu = self.get_edit_sub_menu(select_items, True)
        self.detail_menu = Menu([(None, _("Play"),  self.current_item.song_view.play_select_item),
                                 (None, _("Add to List"), add_to_list_menu),
                                 (None, _("move to List"), move_to_list_menu),
                                 None,
                                 (None, _("Remove Track"), self.current_item.song_view.remove_select_items),
                                 (None, _("Move to Trash"), self.current_item.song_view.try_move_trash),
                                 (None, _("Clear List"), self.current_item.song_view.erase_items),
                                 None,
                                 (None, _("Playback Order"), play_mode_menu),
                                 (None, _("Sort"), sub_sort_menu),
                                 (None, _("Convert"), self.current_item.song_view.songs_convert),
                                 (None, _("Open directory"), self.current_item.song_view.open_song_dir),
                                 (None, _("Properties"), self.current_item.song_view.open_song_editor),
                                 ], True)
        
        if item and item.song.get_type() == "cue":
            self.detail_menu.set_menu_item_sensitive_by_index(5, False)
            self.detail_menu.set_menu_item_sensitive_by_index(10, False)
        self.detail_menu.show((int(x), int(y)))
        
        
    def save_current_playlist(self, *args):    
        index = self.get_current_item_index()        
        config.set("playlist","current_index", str(index))
        
    def save_to_library(self):    
        if self.search_flag:
            self.reset_search_entry()
                  
        MediaDB.full_erase_playlists()
        for item in self.category_list.get_items():
            if item.udi is not None:
                continue
            songs = item.get_songs()
            name = item.get_title()
            MediaDB.create_playlist("local", name, songs)