Beispiel #1
0
class PasswordsPopover(Gtk.Popover):
    """
        Show saved passwords
    """
    def __init__(self):
        """
            Init popover
        """
        Gtk.Popover.__init__(self)
        self.__filter = ""
        self.__helper = PasswordsHelper()
        self.set_position(Gtk.PositionType.BOTTOM)
        builder = Gtk.Builder()
        builder.add_from_resource('/org/gnome/Eolie/PopoverPasswords.ui')
        builder.connect_signals(self)
        self.__listbox = builder.get_object("listbox")
        self.__listbox.set_filter_func(self.__filter_func)
        self.__listbox.set_sort_func(self.__sort_func)
        self.add(builder.get_object('widget'))
        self.set_size_request(400, 300)

    def populate(self):
        """
            Populate popover
        """
        self.__helper.get_all(self.__add_password)

#######################
# PROTECTED           #
#######################

    def _on_search_changed(self, entry):
        """
            Update filter
            @param entry as Gtk.Entry
        """
        self.__filter = entry.get_text()
        self.__listbox.invalidate_filter()

    def _on_remove_all_clicked(self, button):
        """
            Remove all passwords
            @param button as Gtk.Button
        """
        for child in self.__listbox.get_children():
            child.delete()

#######################
# PRIVATE             #
#######################

    def __filter_func(self, row):
        """
            Filter rows
            @param row as Row
        """
        return self.__filter in row.item.get_property("uri")

    def __sort_func(self, row1, row2):
        """
            Sort rows
            @param row1 as Row
            @param row2 as Row
        """
        return row2.item.get_property("username") <\
            row1.item.get_property("username")

    def __add_password(self, attributes, password, uri, index, count):
        """
            Add password to model
            @param attributes as {}
            @param password as str
            @param uri as None
            @param index as int
            @param count as int
        """
        if attributes is None:
            return
        try:
            item = Item()
            item.set_property("username", attributes["login"])
            item.set_property("uri", attributes["formSubmitURL"])
            item.set_property("uuid", attributes["uuid"])
            child = Row(item, self.__helper)
            child.show()
            self.__listbox.add(child)
        except:
            # Here because firsts Eolie releases do not
            # provide formSubmitURL
            # FIXME Remove later
            pass
Beispiel #2
0
class PasswordsPopover(Gtk.Popover):
    """
        Show saved passwords
    """
    def __init__(self):
        """
            Init popover
        """
        Gtk.Popover.__init__(self)
        self.__filter = ""
        self.__helper = PasswordsHelper()
        self.set_position(Gtk.PositionType.BOTTOM)
        builder = Gtk.Builder()
        builder.add_from_resource('/org/gnome/Eolie/PopoverPasswords.ui')
        builder.connect_signals(self)
        self.__listbox = builder.get_object("listbox")
        self.__listbox.set_filter_func(self.__filter_func)
        self.add(builder.get_object('widget'))
        self.set_size_request(300, 300)

    def populate(self):
        """
            Populate popover
        """
        self.__helper.get_all(self.__add_password)

#######################
# PROTECTED           #
#######################

    def _on_search_changed(self, entry):
        """
            Update filter
            @param entry as Gtk.Entry
        """
        self.__filter = entry.get_text()
        self.__listbox.invalidate_filter()

    def _on_remove_all_clicked(self, button):
        """
            Remove all passwords
            @param button as Gtk.Button
        """
        for child in self.__listbox.get_children():
            child.delete()

#######################
# PRIVATE             #
#######################

    def __filter_func(self, row):
        """
            Filter rows
            @param row as Row
        """
        return self.__filter in row.item.get_property("uri")

    def __add_password(self, attributes, password, uri):
        """
            Add password to model
            @param attributes as {}
            @param password as str
            @param uri as None
        """
        if attributes is None:
            return
        item = Item()
        item.set_property("uri", attributes["formSubmitURL"])
        child = Row(item, self.__helper)
        child.show()
        self.__listbox.add(child)