def do_get_filters(self):
        """
        Adds filters
        """
        filters = Unity.FilterSet.new()
        filter_icon = Gio.ThemedIcon.new(SVG_DIR+'group-recent.svg')

        tags_filter = Unity.CheckOptionFilter.new('tags', _('Tags'), filter_icon, True)
        for tag_struct in everpad_provider.list_tags():
            tag = Tag.from_tuple(tag_struct)
            tags_filter.add_option(str(tag.id), tag.name, filter_icon)
        filters.add(tags_filter)

        notebooks_filter = Unity.RadioOptionFilter.new('notebooks', _('Notebooks'), filter_icon, True)
        for notebook_struct in everpad_provider.list_notebooks():
            notebook = Notebook.from_tuple(notebook_struct)
            notebooks_filter.add_option(str(notebook.id), notebook.name, filter_icon)
        filters.add(notebooks_filter)

        places_filter = Unity.RadioOptionFilter.new('places', _('Places'), filter_icon, True)
        for place_struct in everpad_provider.list_places():
            place = Place.from_tuple(place_struct)
            places_filter.add_option(str(place.id), place.name, filter_icon)
        filters.add(places_filter)
        return filters
Esempio n. 2
0
 def test_load(self):
     tag = Tag.from_tuple((0, '123'))
     self.assertEqual(
         tag.name,
         '123',
         'load from struct',
     )
Esempio n. 3
0
    def test_serialise(self):
        class Fake(object):
            id = 0
            name = "123"

        tag = Tag.from_obj(Fake())
        self.assertEqual(tag.struct, (0, "123"), "serialise to struct")
Esempio n. 4
0
 def test_serialise(self):
     class Fake(object):
         id = 0
         name = '123'
     tag = Tag.from_obj(Fake())
     self.assertEqual(
         tag.struct, (0, '123'),
         'serialise to struct',
     )
Esempio n. 5
0
 def test_serialise(self):
     class Fake(object):
         id = 0
         name = '123'
     tag = Tag.from_obj(Fake())
     self.assertEqual(
         tag.struct, (0, '123'),
         'serialise to struct',
     )
Esempio n. 6
0
 def __init__(self, parent, app, widget, on_change):
     """Init and connect signals"""
     self.parent = parent
     self.app = app
     self.widget = widget
     self.tags_list = map(lambda tag: Tag.from_tuple(tag).name, self.app.provider.list_tags())
     self.completer = QCompleter()
     self.completer_model = QStringListModel()
     self.completer.setModel(self.completer_model)
     self.completer.activated.connect(self.update_completion)
     self.update_completion()
     self.widget.setCompleter(self.completer)
     self.widget.textChanged.connect(Slot()(on_change))
     self.widget.textEdited.connect(self.update_completion)
Esempio n. 7
0
 def update_props(self):
     icon = Gio.ThemedIcon.new("/usr/share/icons/unity-icon-theme/places/svg/group-recent.svg")
     tags = Unity.CheckOptionFilter.new('tags', _('Tags'), icon, True)
     for tag_struct in provider.list_tags():
         tag = Tag.from_tuple(tag_struct)
         tags.add_option(str(tag.id), tag.name, icon)
     notebooks = Unity.RadioOptionFilter.new('notebooks', _('Notebooks'), icon, True)
     for notebook_struct in provider.list_notebooks():
         notebook = Notebook.from_tuple(notebook_struct)
         notebooks.add_option(str(notebook.id), notebook.name, icon)
     places = Unity.RadioOptionFilter.new('places', _('Places'), icon, True)
     for place_struct in provider.list_places():
         place = Place.from_tuple(place_struct)
         places.add_option(str(place.id), place.name, icon)
     self._lens.props.filters = [notebooks, tags, places]
Esempio n. 8
0
    def test_give(self):
        class Fake(object):
            id = 0

            @property
            def id_dbus(self):
                return self.id

            @id_dbus.setter
            def id_dbus(self, val):
                self.id = val + 12

        tag = Tag.from_tuple((0, "123"))
        obj = Fake()
        tag.give_to_obj(obj)
        self.assertEqual(obj.id, 12, "give data to object")
Esempio n. 9
0
 def update_props(self):
     icon = Gio.ThemedIcon.new(resource_filename("share/icons/unity-icon-theme/places/svg/group-recent.svg"))
     tags = Unity.CheckOptionFilter.new('tags', _('Tags'), icon, True)
     for tag_struct in provider.list_tags():
         tag = Tag.from_tuple(tag_struct)
         tags.add_option(str(tag.id), tag.name, icon)
     notebooks = Unity.RadioOptionFilter.new('notebooks', _('Notebooks'), icon, True)
     for notebook_struct in provider.list_notebooks():
         notebook = Notebook.from_tuple(notebook_struct)
         notebooks.add_option(str(notebook.id), notebook.name, icon)
     places = Unity.RadioOptionFilter.new('places', _('Places'), icon, True)
     for place_struct in provider.list_places():
         place = Place.from_tuple(place_struct)
         places.add_option(str(place.id), place.name, icon)
     self._lens.props.filters = [notebooks, tags, places]
     self._lens.props.search_in_global = bool(int(provider.get_settings_value('search-on-home') or 1))
Esempio n. 10
0
 def test_tags(self):
     """Test tags"""
     tags = map(str, range(100))
     notebook = Notebook.from_tuple(
         self.service.create_notebook('test', None), )
     self.service.create_note(
         Note(
             id=NONE_ID,
             title='New note',
             content="New note content",
             tags=tags,
             notebook=notebook.id,
             created=NONE_VAL,
             updated=NONE_VAL,
             place='',
         ).struct)
     remote_tags = map(Tag.from_tuple, self.service.list_tags())
     self.assertEqual(set(tags),
                      set(map(
                          lambda tag: tag.name,
                          remote_tags,
                      )))
     filtered = []
     for num, tag in enumerate(remote_tags):
         if num % 2:
             filtered.append(tag)
         else:
             self.service.delete_tag(tag.id)
     tags = filtered  # tags.remove(tag) not work, wtf
     self.assertEqual(
         self._to_ids(tags),
         self._to_ids(map(
             Tag.from_tuple,
             self.service.list_tags(),
         )),
     )
     filtered = []
     for num, tag in enumerate(tags):
         tag.name += '*'
         if num % 2:
             self.service.delete_tag(tag.id)
             with self.assertRaises(DBusException):
                 self.service.update_tag(tag.struct)
         else:
             updated = Tag.from_tuple(self.service.update_tag(tag.struct), )
             self.assertEqual(tag.name, updated.name)
             filtered.append(updated)
Esempio n. 11
0
 def __init__(self, parent, widget, on_change):
     """Init and connect signals"""
     self.parent = parent
     self.app = QApplication.instance()
     self.widget = widget
     self.tags_list = map(
         lambda tag: Tag.from_tuple(tag).name,
         self.app.provider.list_tags(),
     )
     self.completer = QCompleter()
     self.completer_model = QStringListModel()
     self.completer.setModel(self.completer_model)
     self.completer.activated.connect(self.update_completion)
     self.update_completion()
     self.widget.setCompleter(self.completer)
     self.widget.textChanged.connect(Slot()(on_change))
     self.widget.textEdited.connect(self.update_completion)
Esempio n. 12
0
 def update_props(self):
     icon = Gio.ThemedIcon.new(
         "/usr/share/icons/unity-icon-theme/places/svg/group-recent.svg")
     tags = Unity.CheckOptionFilter.new('tags', _('Tags'), icon, True)
     for tag_struct in provider.list_tags():
         tag = Tag.from_tuple(tag_struct)
         tags.add_option(str(tag.id), tag.name, icon)
     notebooks = Unity.RadioOptionFilter.new('notebooks', _('Notebooks'),
                                             icon, True)
     for notebook_struct in provider.list_notebooks():
         notebook = Notebook.from_tuple(notebook_struct)
         notebooks.add_option(str(notebook.id), notebook.name, icon)
     places = Unity.RadioOptionFilter.new('places', _('Places'), icon, True)
     for place_struct in provider.list_places():
         place = Place.from_tuple(place_struct)
         places.add_option(str(place.id), place.name, icon)
     self._lens.props.filters = [notebooks, tags, places]
Esempio n. 13
0
    def test_give(self):
        class Fake(object):
            id = 0
            @property
            def id_dbus(self):
                return self.id

            @id_dbus.setter
            def id_dbus(self, val):
                self.id = val + 12
        tag = Tag.from_tuple((0, '123'))
        obj = Fake()
        tag.give_to_obj(obj)
        self.assertEqual(
            obj.id, 12,
            'give data to object',
        )
Esempio n. 14
0
 def test_tags(self):
     """Test tags"""
     tags = map(str, range(100))
     notebook = Notebook.from_tuple(
         self.service.create_notebook('test', None),
     )
     self.service.create_note(Note(
         id=NONE_ID,
         title='New note',
         content="New note content",
         tags=tags,
         notebook=notebook.id,
         created=NONE_VAL,
         updated=NONE_VAL,
         place='',
     ).struct)
     remote_tags = map(Tag.from_tuple, self.service.list_tags())
     self.assertEqual(set(tags), set(map(
         lambda tag: tag.name, remote_tags,
     )))
     filtered = []
     for num, tag in enumerate(remote_tags):
         if num % 2:
             filtered.append(tag)
         else:
             self.service.delete_tag(tag.id)
     tags = filtered  # tags.remove(tag) not work, wtf
     self.assertEqual(
         self._to_ids(tags), self._to_ids(map(
             Tag.from_tuple, self.service.list_tags(),
         )),
     )
     filtered = []
     for num, tag in enumerate(tags):
         tag.name += '*'
         if num % 2:
             self.service.delete_tag(tag.id)
             with self.assertRaises(DBusException):
                 self.service.update_tag(tag.struct)
         else:
             updated = Tag.from_tuple(
                 self.service.update_tag(tag.struct),
             )
             self.assertEqual(tag.name, updated.name)
             filtered.append(updated)
Esempio n. 15
0
 def update_props(self):
     icon = Gio.ThemedIcon.new(
         resource_filename(
             "share/icons/unity-icon-theme/places/svg/group-recent.svg"))
     tags = Unity.CheckOptionFilter.new('tags', _('Tags'), icon, True)
     for tag_struct in provider.list_tags():
         tag = Tag.from_tuple(tag_struct)
         tags.add_option(str(tag.id), tag.name, icon)
     notebooks = Unity.RadioOptionFilter.new('notebooks', _('Notebooks'),
                                             icon, True)
     for notebook_struct in provider.list_notebooks():
         notebook = Notebook.from_tuple(notebook_struct)
         notebooks.add_option(str(notebook.id), notebook.name, icon)
     places = Unity.RadioOptionFilter.new('places', _('Places'), icon, True)
     for place_struct in provider.list_places():
         place = Place.from_tuple(place_struct)
         places.add_option(str(place.id), place.name, icon)
     self._lens.props.filters = [notebooks, tags, places]
     self._lens.props.search_in_global = bool(
         int(provider.get_settings_value('search-on-home') or 1))
Esempio n. 16
0
    def _reload_tags_list(self, select_tag_id=None):
        # TODO nested tags
        self.tagsModel.clear()
        tagRoot = QStandardItem(QIcon.fromTheme('user-home'), self.tr('All Tags'))
        self.tagsModel.appendRow(tagRoot)
        selected_item = tagRoot

        for tag_struct in self.app.provider.list_tags():
            tag = Tag.from_tuple(tag_struct)
            count = self.app.provider.get_tag_notes_count(tag.id)
            item = QTagItem(tag, count)
            tagRoot.appendRow(item)

            if select_tag_id and tag.id == select_tag_id:
                selected_item = item

        self.ui.tagsList.expandAll()
        if selected_item and not select_tag_id == SELECT_NONE:
            index = self.tagsModel.indexFromItem(selected_item)
            self.ui.tagsList.setCurrentIndex(index)
            self.tag_selected(index)
Esempio n. 17
0
    def _reload_tags_list(self, select_tag_id=None):
        # TODO nested tags
        self.tagsModel.clear()
        tagRoot = QStandardItem(QIcon.fromTheme('user-home'),
                                self.tr('All Tags'))
        self.tagsModel.appendRow(tagRoot)
        selected_item = tagRoot

        for tag_struct in self.app.provider.list_tags():
            tag = Tag.from_tuple(tag_struct)
            count = self.app.provider.get_tag_notes_count(tag.id)
            item = QTagItem(tag, count)
            tagRoot.appendRow(item)

            if select_tag_id and tag.id == select_tag_id:
                selected_item = item

        self.ui.tagsList.expandAll()
        if selected_item and not select_tag_id == SELECT_NONE:
            index = self.tagsModel.indexFromItem(selected_item)
            self.ui.tagsList.setCurrentIndex(index)
            self.tag_selected(index)
Esempio n. 18
0
 def test_load(self):
     tag = Tag.from_tuple((0, "123"))
     self.assertEqual(tag.name, "123", "load from struct")
Esempio n. 19
0
 def test_load(self):
     tag = Tag.from_tuple((0, '123'))
     self.assertEqual(
         tag.name, '123',
         'load from struct',
     )