예제 #1
0
파일: service.py 프로젝트: cas--/everpad
 def test_notebooks(self):
     """Test notebooks"""
     notebooks = []
     for i in range(100):
         notebooks.append(
             Notebook.from_tuple(self.service.create_notebook(str(i),
                                                              None), ))
         self.assertEqual(notebooks[-1].name, str(i))
     for num, notebook in enumerate(notebooks):
         if num % 2:
             self.service.delete_notebook(notebook.id)
             with self.assertRaises(DBusException):
                 self.service.get_notebook(notebook.id)
             notebooks.remove(notebook)
     self.assertEqual(
         self._to_ids(notebooks),
         self._to_ids(
             map(
                 Notebook.from_tuple,
                 self.service.list_notebooks(),
             )),
     )
     for num, notebook in enumerate(notebooks):
         notebook.name += '*'
         if num % 2:
             self.service.delete_notebook(notebook.id)
             with self.assertRaises(DBusException):
                 self.service.update_notebook(notebook.struct)
         else:
             updated = Notebook.from_tuple(
                 self.service.update_notebook(notebook.struct), )
             self.assertEqual(notebook.name, updated.name)
예제 #2
0
 def test_notebooks(self):
     """Test notebooks"""
     notebooks = []
     for i in range(100):
         notebooks.append(Notebook.from_tuple(
             self.service.create_notebook(str(i), None),
         ))
         self.assertEqual(notebooks[-1].name, str(i))
     for num, notebook in enumerate(notebooks):
         if num % 2:
             self.service.delete_notebook(notebook.id)
             with self.assertRaises(DBusException):
                 self.service.get_notebook(notebook.id)
             notebooks.remove(notebook)
     self.assertEqual(
         self._to_ids(notebooks), self._to_ids(map(
             Notebook.from_tuple, self.service.list_notebooks(),
         )),
     )
     for num, notebook in enumerate(notebooks):
         notebook.name += '*'
         if num % 2:
             self.service.delete_notebook(notebook.id)
             with self.assertRaises(DBusException):
                 self.service.update_notebook(notebook.struct)
         else:
             updated = Notebook.from_tuple(
                 self.service.update_notebook(notebook.struct),
             )
             self.assertEqual(notebook.name, updated.name)
예제 #3
0
파일: list.py 프로젝트: AnderSilva/everpad
    def _reload_notebooks_list(self, select_notebook_id=None):
        # TODO could enable selecting an already selected stack
        self.notebooksModel.clear()
        root = QStandardItem(QIcon.fromTheme('user-home'), self.tr('All Notes'))
        self.notebooksModel.appendRow(root)
        selected_item = root

        stacks = {}
        for notebook_struct in self.app.provider.list_notebooks():
            notebook = Notebook.from_tuple(notebook_struct)
            count = self.app.provider.get_notebook_notes_count(notebook.id)
            item = QNotebookItem(notebook, count)

            if(notebook.stack == ''):
                root.appendRow(item)
            else:
                if(notebook.stack not in stacks.keys()):
                    stack = QStandardItem(QIcon.fromTheme('user-home'), notebook.stack)
                    stack.stack = notebook.stack
                    root.appendRow(stack)
                    stacks[notebook.stack] = stack

                stacks[notebook.stack].appendRow(item)

            if select_notebook_id and notebook.id == select_notebook_id:
                selected_item = item

        self.ui.notebooksList.expandAll()

        if selected_item and not select_notebook_id == SELECT_NONE:
            index = self.notebooksModel.indexFromItem(selected_item)
            self.ui.notebooksList.setCurrentIndex(index)
            self.notebook_selected(index)
예제 #4
0
    def _reload_notebooks_list(self, select_notebook_id=None):
        # TODO could enable selecting an already selected stack
        self.notebooksModel.clear()
        root = QStandardItem(QIcon.fromTheme('user-home'),
                             self.tr('All Notes'))
        self.notebooksModel.appendRow(root)
        selected_item = root

        stacks = {}
        for notebook_struct in self.app.provider.list_notebooks():
            notebook = Notebook.from_tuple(notebook_struct)
            count = self.app.provider.get_notebook_notes_count(notebook.id)
            item = QNotebookItem(notebook, count)

            if (notebook.stack == ''):
                root.appendRow(item)
            else:
                if (notebook.stack not in stacks.keys()):
                    stack = QStandardItem(QIcon.fromTheme('user-home'),
                                          notebook.stack)
                    stack.stack = notebook.stack
                    root.appendRow(stack)
                    stacks[notebook.stack] = stack

                stacks[notebook.stack].appendRow(item)

            if select_notebook_id and notebook.id == select_notebook_id:
                selected_item = item

        self.ui.notebooksList.expandAll()

        if selected_item and not select_notebook_id == SELECT_NONE:
            index = self.notebooksModel.indexFromItem(selected_item)
            self.ui.notebooksList.setCurrentIndex(index)
            self.notebook_selected(index)
예제 #5
0
 def init_notebooks(self):
     frame = QFrame()
     layout = QVBoxLayout()
     frame.setLayout(layout)
     self.ui.scrollArea.setWidget(frame)
     for notebook_struct in self.app.provider.list_notebooks():
         notebook = Notebook.from_tuple(notebook_struct)
         count = self.app.provider.get_notebook_notes_count(notebook.id)
         widget = QWidget()
         menu = QMenu(self)
         menu.addAction(self.tr('Change Name'), Slot()(partial(
             self.change_notebook, notebook=notebook,
         )))
         action = menu.addAction(self.tr('Remove Notebook'), Slot()(partial(
             self.remove_notebook, notebook=notebook,
         )))
         action.setEnabled(False)
         widget.ui = Ui_Notebook()
         widget.ui.setupUi(widget)
         widget.ui.name.setText(notebook.name)
         widget.ui.content.setText(self.tr('Containts %d notes') % count)
         widget.ui.actionBtn.setIcon(QIcon.fromTheme('gtk-properties'))
         widget.setFixedHeight(50)
         layout.addWidget(widget)
         widget.ui.actionBtn.clicked.connect(Slot()(partial(
             self.show_notebook_menu,
             menu=menu, widget=widget,
         )))
    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
예제 #7
0
파일: list.py 프로젝트: berzjackson/everpad
    def new_notebook(self):
        name, status = self._notebook_new_name(self.tr('Create new notebook'))
        if status:
            notebook_struct = self.app.provider.create_notebook(name)
            notebook = Notebook.from_tuple(notebook_struct)

            self.app.send_notify(self.tr('Notebook "%s" created!') % notebook.name)
            self._reload_notebooks_list(notebook.id)
예제 #8
0
파일: list.py 프로젝트: guofengstc/everpad
    def new_notebook(self):
        name, status = self._notebook_new_name(self.tr('Create new notebook'))
        if status:
            notebook_struct = self.app.provider.create_notebook(name)
            notebook = Notebook.from_tuple(notebook_struct)

            self.app.send_notify(
                self.tr('Notebook "%s" created!') % notebook.name)
            self._reload_notebooks_list(notebook.id)
예제 #9
0
 def __init__(self, parent, widget, on_change):
     """Init and connect signals"""
     self.parent = parent
     self.app = QApplication.instance()
     self.widget = widget
     for notebook_struct in self.app.provider.list_notebooks():
         notebook = Notebook.from_tuple(notebook_struct)
         self.widget.addItem(notebook.name, userData=notebook.id)
     self.widget.currentIndexChanged.connect(Slot()(on_change))
예제 #10
0
파일: widgets.py 프로젝트: MikeyG/gevernote
 def __init__(self, parent, widget, on_change):
     """Init and connect signals"""
     self.parent = parent
     self.app = QApplication.instance()
     self.widget = widget
     for notebook_struct in self.app.provider.list_notebooks():
         notebook = Notebook.from_tuple(notebook_struct)
         self.widget.addItem(notebook.name, userData=notebook.id)
     self.widget.currentIndexChanged.connect(Slot()(on_change))
예제 #11
0
파일: list.py 프로젝트: berzjackson/everpad
 def _notebook_new_name(self, title, exclude=''):
     names = map(lambda nb: Notebook.from_tuple(nb).name, self.app.provider.list_notebooks())
     try:
         names.remove(exclude)
     except ValueError:
         pass
     name, status = QInputDialog.getText(self, title, self.tr('Enter notebook name:'), text=exclude)
     while name in names and status:
         message = self.tr('Notebook with this name already exist. Enter notebook name')
         name, status = QInputDialog.getText(self, title, message)
     return name, status
예제 #12
0
 def test_notes_with_notebook_and_places(self):
     """Test notes with notebook and places"""
     notebook = Notebook.from_tuple(
         self.service.create_notebook('test', None),
     )
     notes = []
     get_place = lambda num: '123' if num < 50 else '456'
     for i in range(100):
         notes.append(Note.from_tuple(self.service.create_note(Note(
             id=NONE_ID,
             title='New note',
             content="New note content",
             tags=['123', '345'],
             notebook=notebook.id,
             created=NONE_VAL,
             updated=NONE_VAL,
             place=get_place(i),
         ).struct)))
     filtered = []
     for num, note in enumerate(notes):
         if not num % 2:
             self.service.update_note(note.struct)  # mark note exist
             filtered.append(note)
     notes = filtered  # notes.remove(note) not work, wtf
     self.assertEqual(
         self._to_ids(notes), self._to_ids(map(
             Note.from_tuple, self.service.find_notes(
                 '', dbus.Array([], signature='i'),
                 dbus.Array([], signature='i'), 0,
                 100, Note.ORDER_UPDATED_DESC, -1,
             ),
         )),
     )
     filtered = []
     for num, note in enumerate(notes):
         note.title += '*'
         if num % 2:
             self.service.delete_note(note.id)
             with self.assertRaises(DBusException):
                 self.service.update_note(note.struct)
         else:
             updated = Note.from_tuple(
                 self.service.update_note(note.struct),
             )
             self.assertEqual(note.title, updated.title)
             filtered.append(updated)
     self.assertEqual(len(filtered),
         self.service.get_notebook_notes_count(notebook.id),
     )
     self.assertEqual(set(['123', '456']), set(map(
         lambda place: Place.from_tuple(place).name,
         self.service.list_places(),
     )))
예제 #13
0
파일: lens.py 프로젝트: altawu/everpad
 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]
예제 #14
0
파일: lens.py 프로젝트: AnderSilva/everpad
 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))
예제 #15
0
파일: list.py 프로젝트: guofengstc/everpad
 def _notebook_new_name(self, title, exclude=''):
     names = map(lambda nb: Notebook.from_tuple(nb).name,
                 self.app.provider.list_notebooks())
     try:
         names.remove(exclude)
     except ValueError:
         pass
     name, status = QInputDialog.getText(self,
                                         title,
                                         self.tr('Enter notebook name:'),
                                         text=exclude)
     while name in names and status:
         message = self.tr(
             'Notebook with this name already exist. Enter notebook name')
         name, status = QInputDialog.getText(self, title, message)
     return name, status
예제 #16
0
파일: service.py 프로젝트: cas--/everpad
 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)
예제 #17
0
파일: service.py 프로젝트: cas--/everpad
 def test_note_resources(self):
     """Test note resources"""
     notebook = Notebook.from_tuple(
         self.service.create_notebook('test', None), )
     struct = self.service.create_note(
         Note(
             id=NONE_ID,
             title='New note',
             content="New note content",
             tags=[],
             notebook=notebook.id,
             created=NONE_VAL,
             updated=NONE_VAL,
             place='',
         ).struct)
     note = Note.from_tuple(self.service.update_note(struct))
     resources = []
     for i in range(100):
         resources.append(
             Resource(
                 id=NONE_ID,
                 file_name="name/%d" % i,
                 file_path="path/%d" % i,
                 mime='image/png',
                 hash='',
             ))
     self.service.update_note_resources(
         note.struct,
         map(lambda resource: resource.struct, resources),
     )
     received = map(Resource.from_tuple,
                    self.service.get_note_resources(note.id))
     self.assertEqual(
         self._file_names(resources),
         self._file_names(received),
     )
     received = received[:50]
     self.service.update_note_resources(
         note.struct,
         map(lambda resource: resource.struct, received),
     )
     new_received = map(Resource.from_tuple,
                        self.service.get_note_resources(note.id))
     self.assertEqual(
         self._file_names(new_received),
         self._file_names(received),
     )
예제 #18
0
    def notebook_selected(self, index):
        self.notesModel.setRowCount(0)

        item = self.notebooksModel.itemFromIndex(index)
        if hasattr(item, 'notebook'):
            notebook_id = item.notebook.id
        else:
            notebook_id = 0

        self._current_notebook = notebook_id
        self._current_tag = SELECT_NONE

        notebook_filter = [notebook_id] if notebook_id > 0 else dbus.Array(
            [], signature='i')

        if hasattr(
                item,
                'stack'):  # stack selected, retrieve all underlying notebooks
            notebook_filter = []
            for notebook_struct in self.app.provider.list_notebooks():
                notebook = Notebook.from_tuple(notebook_struct)
                if (notebook.stack == item.stack):
                    notebook_filter.append(notebook.id)

        notes = self.app.provider.find_notes(
            '',
            notebook_filter,
            dbus.Array([], signature='i'),
            0,
            2**31 - 1,
            Note.ORDER_TITLE,
            -1,
        )  # fails with sys.maxint in 64

        for note_struct in notes:
            note = Note.from_tuple(note_struct)
            self.notesModel.appendRow(QNoteItemFactory(note).make_items())

        sort_order = self.sort_order
        if sort_order is None:
            sort_order = self.app.settings.value('list-notes-sort-order')

        if sort_order:
            logicalIndex, order = sort_order
            order = Qt.SortOrder.values[order]
            self.ui.notesList.sortByColumn(int(logicalIndex), order)
예제 #19
0
파일: lens.py 프로젝트: guofengstc/everpad
 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]
예제 #20
0
파일: list.py 프로젝트: AnderSilva/everpad
    def rename_stack(self):
        index = self.ui.notebooksList.currentIndex()
        item = self.notebooksModel.itemFromIndex(index)
        stack = item.stack
        name, status = self._stack_new_name(
            self.tr('Rename stack'), stack,
        )
        if status:
            # loop notebooks and update stack str
            for notebook_struct in self.app.provider.list_notebooks():
                notebook = Notebook.from_tuple(notebook_struct)
                if(notebook.stack == item.stack):
                    notebook.stack = name
                    self.app.provider.update_notebook(notebook.struct)

            self.app.send_notify(self.tr('Stack "%s" renamed!') % name)
            self._reload_notebooks_list(notebook.id)
예제 #21
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)
예제 #22
0
    def rename_stack(self):
        index = self.ui.notebooksList.currentIndex()
        item = self.notebooksModel.itemFromIndex(index)
        stack = item.stack
        name, status = self._stack_new_name(
            self.tr('Rename stack'),
            stack,
        )
        if status:
            # loop notebooks and update stack str
            for notebook_struct in self.app.provider.list_notebooks():
                notebook = Notebook.from_tuple(notebook_struct)
                if (notebook.stack == item.stack):
                    notebook.stack = name
                    self.app.provider.update_notebook(notebook.struct)

            self.app.send_notify(self.tr('Stack "%s" renamed!') % name)
            self._reload_notebooks_list(notebook.id)
예제 #23
0
    def remove_stack(self):
        msg = QMessageBox(
            QMessageBox.Critical, self.tr("You are trying to delete a stack"),
            self.
            tr("Are you sure want to delete this stack? Notebooks and notes are preserved."
               ), QMessageBox.Yes | QMessageBox.No)
        if msg.exec_() == QMessageBox.Yes:
            index = self.ui.notebooksList.currentIndex()
            item = self.notebooksModel.itemFromIndex(index)
            # loop notebooks and remove stack str
            for notebook_struct in self.app.provider.list_notebooks():
                notebook = Notebook.from_tuple(notebook_struct)
                if (notebook.stack == item.stack):
                    print "Clearing one notebook from its stack."
                    notebook.stack = ''
                    self.app.provider.update_notebook(notebook.struct)

            self._reload_notebooks_list()
예제 #24
0
파일: list.py 프로젝트: AnderSilva/everpad
    def remove_stack(self):
        msg = QMessageBox(
            QMessageBox.Critical,
            self.tr("You are trying to delete a stack"),
            self.tr("Are you sure want to delete this stack? Notebooks and notes are preserved."),
            QMessageBox.Yes | QMessageBox.No
        )
        if msg.exec_() == QMessageBox.Yes:
            index = self.ui.notebooksList.currentIndex()
            item = self.notebooksModel.itemFromIndex(index)
            # loop notebooks and remove stack str
            for notebook_struct in self.app.provider.list_notebooks():
                notebook = Notebook.from_tuple(notebook_struct)
                if(notebook.stack == item.stack):
                    print "Clearing one notebook from its stack."
                    notebook.stack = ''
                    self.app.provider.update_notebook(notebook.struct)

            self._reload_notebooks_list()
예제 #25
0
 def setUp(self):
     self.service = ProviderService()
     self.service._session = get_db_session()
     models.Note.session = self.service._session
     self.app = app
     app.update(self.service)
     notebook = Notebook.from_tuple(
         self.service.create_notebook('test', None),
     )
     self.note = Note.from_tuple(self.service.create_note(Note(
         id=NONE_ID,
         title='New note',
         content="New note content",
         tags=[],
         notebook=notebook.id,
         created=NONE_VAL,
         updated=NONE_VAL,
         place='',
     ).struct))
예제 #26
0
 def setUp(self):
     self.service = ProviderService()
     self.service._session = get_db_session()
     models.Note.session = self.service._session
     self.app = app
     self.app.update(self.service)
     notebook = Notebook.from_tuple(
         self.service.create_notebook('test', None),
     )
     self.note = Note.from_tuple(self.service.create_note(Note(
         id=NONE_ID,
         title='New note',
         content="New note content",
         tags=[],
         notebook=notebook.id,
         created=NONE_VAL,
         updated=NONE_VAL,
         place='',
     ).struct))
예제 #27
0
 def test_note_resources(self):
     """Test note resources"""
     notebook = Notebook.from_tuple(
         self.service.create_notebook('test', None),
     )
     struct = self.service.create_note(Note(
         id=NONE_ID,
         title='New note',
         content="New note content",
         tags=[],
         notebook=notebook.id,
         created=NONE_VAL,
         updated=NONE_VAL,
         place='',
     ).struct)
     note = Note.from_tuple(self.service.update_note(struct))
     resources = []
     for i in range(100):
         resources.append(Resource(
             id=NONE_ID,
             file_name="name/%d" % i,
             file_path="path/%d" % i,
             mime='image/png',
             hash='',
         ))
     self.service.update_note_resources(note.struct,
         map(lambda resource: resource.struct, resources),
     )
     received = map(Resource.from_tuple,
         self.service.get_note_resources(note.id))
     self.assertEqual(
         self._file_names(resources), self._file_names(received),
     )
     received = received[:50]
     self.service.update_note_resources(note.struct,
         map(lambda resource: resource.struct, received),
     )
     new_received = map(Resource.from_tuple,
         self.service.get_note_resources(note.id))
     self.assertEqual(
         self._file_names(new_received), self._file_names(received),
     )
예제 #28
0
파일: list.py 프로젝트: berzjackson/everpad
    def _reload_notebooks_list(self, select_notebook_id=None):
        self.notebooksModel.clear()
        root = QStandardItem(QIcon.fromTheme('user-home'), self.tr('All Notes'))
        self.notebooksModel.appendRow(root)

        selected_item = root
        for notebook_struct in self.app.provider.list_notebooks():
            notebook = Notebook.from_tuple(notebook_struct)
            count = self.app.provider.get_notebook_notes_count(notebook.id)
            item = QNotebookItem(notebook, count)
            root.appendRow(item)

            if select_notebook_id and notebook.id == select_notebook_id:
                selected_item = item

        self.ui.notebooksList.expandAll()
        if selected_item:
            index = self.notebooksModel.indexFromItem(selected_item)
            self.ui.notebooksList.setCurrentIndex(index)
            self.notebook_selected(index)
예제 #29
0
파일: lens.py 프로젝트: cas--/everpad
 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))
예제 #30
0
파일: list.py 프로젝트: guofengstc/everpad
    def _reload_notebooks_list(self, select_notebook_id=None):
        self.notebooksModel.clear()
        root = QStandardItem(QIcon.fromTheme('user-home'),
                             self.tr('All Notes'))
        self.notebooksModel.appendRow(root)

        selected_item = root
        for notebook_struct in self.app.provider.list_notebooks():
            notebook = Notebook.from_tuple(notebook_struct)
            count = self.app.provider.get_notebook_notes_count(notebook.id)
            item = QNotebookItem(notebook, count)
            root.appendRow(item)

            if select_notebook_id and notebook.id == select_notebook_id:
                selected_item = item

        self.ui.notebooksList.expandAll()
        if selected_item:
            index = self.notebooksModel.indexFromItem(selected_item)
            self.ui.notebooksList.setCurrentIndex(index)
            self.notebook_selected(index)
예제 #31
0
파일: list.py 프로젝트: AnderSilva/everpad
    def notebook_selected(self, index):
        self.notesModel.setRowCount(0)

        item = self.notebooksModel.itemFromIndex(index)
        if hasattr(item, 'notebook'):
            notebook_id = item.notebook.id
        else:
            notebook_id = 0

        self._current_notebook = notebook_id
        self._current_tag = SELECT_NONE

        notebook_filter = [notebook_id] if notebook_id > 0 else dbus.Array([], signature='i')

        if hasattr(item, 'stack'):  # stack selected, retrieve all underlying notebooks
            notebook_filter = []
            for notebook_struct in self.app.provider.list_notebooks():
                notebook = Notebook.from_tuple(notebook_struct)
                if(notebook.stack == item.stack):
                    notebook_filter.append(notebook.id)

        notes = self.app.provider.find_notes(
            '', notebook_filter, dbus.Array([], signature='i'),
            0, 2 ** 31 - 1, Note.ORDER_TITLE, -1,
        )  # fails with sys.maxint in 64

        for note_struct in notes:
            note = Note.from_tuple(note_struct)
            self.notesModel.appendRow(QNoteItemFactory(note).make_items())

        sort_order = self.sort_order
        if sort_order is None:
            sort_order = self.app.settings.value('list-notes-sort-order')

        if sort_order:
            logicalIndex, order = sort_order
            order = Qt.SortOrder.values[order]
            self.ui.notesList.sortByColumn(int(logicalIndex), order)
예제 #32
0
파일: service.py 프로젝트: cas--/everpad
 def setUp(self):
     self.service = ProviderService()
     self.service._session = get_db_session()
     models.Note.session = self.service._session  # TODO: fix that shit
     self.notebook = Notebook.from_tuple(
         self.service.create_notebook('test', None), )
     self.notebook2 = Notebook.from_tuple(
         self.service.create_notebook('test2', None), )
     self.notebook3 = Notebook.from_tuple(
         self.service.create_notebook(u'Блокнот', None), )
     notes = [
         self.service.create_note(
             Note(
                 id=NONE_ID,
                 title='New note',
                 content="New note content",
                 tags=['ab', 'cd'],
                 notebook=self.notebook.id,
                 created=NONE_VAL,
                 updated=NONE_VAL,
                 place='first',
                 pinnded=False,
             ).struct),
         self.service.create_note(
             Note(
                 id=NONE_ID,
                 title='Old note',
                 content="Old note content",
                 tags=['ef', 'gh'],
                 notebook=self.notebook2.id,
                 created=NONE_VAL,
                 updated=NONE_VAL,
                 place='second',
                 pinnded=False,
             ).struct),
         self.service.create_note(
             Note(
                 id=NONE_ID,
                 title='not',
                 content="oke",
                 tags=['ab', 'gh'],
                 notebook=self.notebook.id,
                 created=NONE_VAL,
                 updated=NONE_VAL,
                 place='second',
                 pinnded=True,
             ).struct),
         self.service.create_note(
             Note(
                 id=NONE_ID,
                 title=u'Заметка',
                 content=u"Заметка",
                 tags=[u'тэг'],
                 notebook=self.notebook.id,
                 created=NONE_VAL,
                 updated=NONE_VAL,
                 place=u'место',
                 pinnded=False,
             ).struct),
         self.service.create_note(
             Note(
                 id=NONE_ID,
                 title=u'заметка',
                 content=u"заметка",
                 tags=[u'тэг'],
                 notebook=self.notebook.id,
                 created=NONE_VAL,
                 updated=NONE_VAL,
                 place=u'место',
                 pinnded=False,
             ).struct),
     ]
     self.notes = map(
         lambda note: Note.from_tuple(self.service.update_note(note)),
         notes)
예제 #33
0
파일: service.py 프로젝트: cas--/everpad
 def test_notes_with_notebook_and_places(self):
     """Test notes with notebook and places"""
     notebook = Notebook.from_tuple(
         self.service.create_notebook('test', None), )
     notes = []
     get_place = lambda num: '123' if num < 50 else '456'
     for i in range(100):
         notes.append(
             Note.from_tuple(
                 self.service.create_note(
                     Note(
                         id=NONE_ID,
                         title='New note',
                         content="New note content",
                         tags=['123', '345'],
                         notebook=notebook.id,
                         created=NONE_VAL,
                         updated=NONE_VAL,
                         place=get_place(i),
                     ).struct)))
     filtered = []
     for num, note in enumerate(notes):
         if not num % 2:
             self.service.update_note(note.struct)  # mark note exist
             filtered.append(note)
     notes = filtered  # notes.remove(note) not work, wtf
     self.assertEqual(
         self._to_ids(notes),
         self._to_ids(
             map(
                 Note.from_tuple,
                 self.service.find_notes(
                     '',
                     dbus.Array([], signature='i'),
                     dbus.Array([], signature='i'),
                     0,
                     100,
                     Note.ORDER_UPDATED_DESC,
                     -1,
                 ),
             )),
     )
     filtered = []
     for num, note in enumerate(notes):
         note.title += '*'
         if num % 2:
             self.service.delete_note(note.id)
             with self.assertRaises(DBusException):
                 self.service.update_note(note.struct)
         else:
             updated = Note.from_tuple(
                 self.service.update_note(note.struct), )
             self.assertEqual(note.title, updated.title)
             filtered.append(updated)
     self.assertEqual(
         len(filtered),
         self.service.get_notebook_notes_count(notebook.id),
     )
     self.assertEqual(
         set(['123', '456']),
         set(
             map(
                 lambda place: Place.from_tuple(place).name,
                 self.service.list_places(),
             )))
예제 #34
0
 def setUp(self):
     self.service = ProviderService()
     self.service._session = get_db_session()
     models.Note.session = self.service._session  # TODO: fix that shit
     self.notebook = Notebook.from_tuple(
         self.service.create_notebook('test', None),
     )
     self.notebook2 = Notebook.from_tuple(
         self.service.create_notebook('test2', None),
     )
     self.notebook3 = Notebook.from_tuple(
         self.service.create_notebook(u'Блокнот', None),
     )
     notes = [
         self.service.create_note(Note(
             id=NONE_ID,
             title='New note',
             content="New note content",
             tags=['ab', 'cd'],
             notebook=self.notebook.id,
             created=NONE_VAL,
             updated=NONE_VAL,
             place='first',
             pinnded=False,
         ).struct),
         self.service.create_note(Note(
             id=NONE_ID,
             title='Old note',
             content="Old note content",
             tags=['ef', 'gh'],
             notebook=self.notebook2.id,
             created=NONE_VAL,
             updated=NONE_VAL,
             place='second',
             pinnded=False,
         ).struct),
         self.service.create_note(Note(
             id=NONE_ID,
             title='not',
             content="oke",
             tags=['ab', 'gh'],
             notebook=self.notebook.id,
             created=NONE_VAL,
             updated=NONE_VAL,
             place='second',
             pinnded=True,
         ).struct),
         self.service.create_note(Note(
             id=NONE_ID,
             title=u'Заметка',
             content=u"Заметка",
             tags=[u'тэг'],
             notebook=self.notebook.id,
             created=NONE_VAL,
             updated=NONE_VAL,
             place=u'место',
             pinnded=False,
         ).struct),
         self.service.create_note(Note(
             id=NONE_ID,
             title=u'заметка',
             content=u"заметка",
             tags=[u'тэг'],
             notebook=self.notebook.id,
             created=NONE_VAL,
             updated=NONE_VAL,
             place=u'место',
             pinnded=False,
         ).struct),
     ]
     self.notes = map(lambda note:
         Note.from_tuple(self.service.update_note(note)),
     notes)
예제 #35
0
 def update(self):
     self.menu.clear()
     try:
         version = self.app.provider.get_api_version()
     except (  # dbus raise some magic
         dbus.exceptions.UnknownMethodException,
         dbus.exceptions.DBusException,
     ):
         version = -1
     if version != API_VERSION:
         action = self.menu.addAction(
             self.tr('API version missmatch, please restart'),
         )
         action.setEnabled(False)
         if version < API_VERSION:
             handler = self.app.provider.kill
         else:
             handler = partial(os.execlp, 'everpad', '--replace')
         self.menu.addAction(
             self.tr('Restart everpad'), handler,
         )
         return
     if self.app.provider.is_authenticated():
         pin_notes = self.app.provider.find_notes(
             '', dbus.Array([], signature='i'),
             dbus.Array([], signature='i'), 0,
             20, Note.ORDER_UPDATED_DESC, 1,
         )
         sort_by_notebook = bool(int(
             self.app.provider.get_settings_value('sort-by-notebook') or 0))
         has_notes = False
         if not sort_by_notebook:
             notes = self.app.provider.find_notes(
                 '', dbus.Array([], signature='i'),
                 dbus.Array([], signature='i'), 0,
                 20 - len(pin_notes), Note.ORDER_UPDATED_DESC, 0,
             )
             has_notes = bool(notes)
         else:
             notebooks = self.app.provider.list_notebooks()
             notes = {}
             for notebook_struct in notebooks:
                 notebook = Notebook.from_tuple(notebook_struct)
                 _notes = self.app.provider.find_notes('', [notebook.id],
                      dbus.Array([], signature='i'), 0,
                      20 - len(pin_notes), Note.ORDER_UPDATED_DESC, 0,
                 )
                 notes[notebook] = _notes
                 if _notes:
                     has_notes = True
         first_sync = not (
             has_notes or len(pin_notes) or self.app.provider.is_first_synced()
         )
         status_syncing = self.app.provider.get_status() == STATUS_SYNC
         if status_syncing and first_sync:
             sync_label = self.tr('Wait, first sync in progress')
         elif status_syncing and not first_sync:
             sync_label = self.tr('Sync in progress')
         elif not status_syncing and first_sync:
             sync_label = self.tr('Please perform first sync')
         else:
             last_sync = self.app.provider.get_last_sync()
             delta_sync = (
                 datetime.now() - datetime.strptime(last_sync, '%H:%M')
             ).seconds // 60
             if delta_sync == 0:
                 sync_label = self.tr('Last Sync: Just now')
             elif delta_sync == 1:
                 sync_label = self.tr('Last Sync: %s min ago') % delta_sync
             else:
                 sync_label = self.tr('Last Sync: %s mins ago') % delta_sync
         menu_items = {
             'create_note': [self.tr('Create Note'), self.create],
             'all_notes': [self.tr('All Notes'), self.show_all_notes],
             'sync': [sync_label, Slot()(self.app.provider.sync)],
             'pin_notes': pin_notes,
             'notes': notes,
         }
         for item in self.app.settings.value('menu-order', DEFAULT_INDICATOR_LAYOUT):
             if item == 'pin_notes' or item == 'notes':
                 if not first_sync and len(menu_items[item]):
                     self.menu.addSeparator()
                     if item == 'notes' and sort_by_notebook:
                         for notebook in menu_items[item]:
                             sub_menu = self.menu.addMenu(notebook.name)
                             _notes = menu_items[item][notebook]
                             for struct in _notes:
                                 self._add_note(sub_menu, struct)
                     else:
                         for struct in menu_items[item]:
                             self._add_note(self.menu, struct)
                     self.menu.addSeparator()
             else:
                 action = self.menu.addAction(menu_items[item][0], menu_items[item][1])
                 if status_syncing and item == 'sync':
                     action.setEnabled(False)
     self.menu.addSeparator()
     self.menu.addAction(self.tr('Settings and Management'), self.show_management)
     self.menu.addAction(self.tr('Exit'), self.exit)
예제 #36
0
    def update(self):
        self.menu.clear()
        try:
            version = self.app.provider.get_api_version()
        except (  # dbus raise some magic
                dbus.exceptions.UnknownMethodException,
                dbus.exceptions.DBusException,
        ):
            version = -1
        if version != API_VERSION:
            action = self.menu.addAction(
                self.tr('API version missmatch, please restart'), )
            action.setEnabled(False)
            if version < API_VERSION:
                handler = self.app.provider.kill
            else:
                handler = partial(os.execlp, 'everpad', '--replace')
            self.menu.addAction(
                self.tr('Restart everpad'),
                handler,
            )
            return
        if self.app.provider.is_authenticated():
            pin_notes = self.app.provider.find_notes(
                '',
                dbus.Array([], signature='i'),
                dbus.Array([], signature='i'),
                0,
                20,
                Note.ORDER_UPDATED_DESC,
                1,
            )
            sort_by_notebook = bool(
                int(
                    self.app.provider.get_settings_value('sort-by-notebook')
                    or 0))
            has_notes = False
            if not sort_by_notebook:
                notes = self.app.provider.find_notes(
                    '',
                    dbus.Array([], signature='i'),
                    dbus.Array([], signature='i'),
                    0,
                    20 - len(pin_notes),
                    Note.ORDER_UPDATED_DESC,
                    0,
                )
                has_notes = bool(notes)
            else:
                notebooks = self.app.provider.list_notebooks()
                notes = {}
                for notebook_struct in notebooks:
                    notebook = Notebook.from_tuple(notebook_struct)
                    _notes = self.app.provider.find_notes(
                        '',
                        [notebook.id],
                        dbus.Array([], signature='i'),
                        0,
                        20 - len(pin_notes),
                        Note.ORDER_UPDATED_DESC,
                        0,
                    )
                    notes[notebook] = _notes
                    if _notes:
                        has_notes = True
            first_sync = not (has_notes or len(pin_notes)
                              or self.app.provider.is_first_synced())

            # Rate Limit indication added
            # STATUS_RATE = -1  # Rate Limit status
            # STATUS_NONE = 0
            # STATUS_SYNC = 1
            # status_syncing = self.app.provider.get_status() == STATUS_SYNC
            status_syncing = self.app.provider.get_status()

            if status_syncing < 0:
                sync_label = self.tr('Rate Limit')
            elif status_syncing and first_sync:
                sync_label = self.tr('Wait, first sync in progress')
            elif status_syncing and not first_sync:
                sync_label = self.tr('Sync in progress')
            elif not status_syncing and first_sync:
                sync_label = self.tr('Please perform first sync')
            else:
                last_sync = self.app.provider.get_last_sync()
                delta_sync = (datetime.now() - datetime.strptime(
                    last_sync, '%H:%M')).seconds // 60
                if delta_sync == 0:
                    sync_label = self.tr('Last Sync: Just now')
                elif delta_sync == 1:
                    sync_label = self.tr('Last Sync: %s min ago') % delta_sync
                else:
                    sync_label = self.tr('Last Sync: %s mins ago') % delta_sync

            menu_items = {
                'create_note': [self.tr('Create Note'), self.create],
                'all_notes': [self.tr('All Notes'), self.show_all_notes],
                'sync': [sync_label,
                         Slot()(self.app.provider.sync)],
                'pin_notes': pin_notes,
                'notes': notes,
            }
            for item in self.app.settings.value('menu-order',
                                                DEFAULT_INDICATOR_LAYOUT):
                if item == 'pin_notes' or item == 'notes':
                    if not first_sync and len(menu_items[item]):
                        self.menu.addSeparator()
                        if item == 'notes' and sort_by_notebook:
                            for notebook in menu_items[item]:
                                sub_menu = self.menu.addMenu(notebook.name)
                                _notes = menu_items[item][notebook]
                                for struct in _notes:
                                    self._add_note(sub_menu, struct)
                        else:
                            for struct in menu_items[item]:
                                self._add_note(self.menu, struct)
                        self.menu.addSeparator()
                else:
                    action = self.menu.addAction(menu_items[item][0],
                                                 menu_items[item][1])
                    if status_syncing and item == 'sync':
                        action.setEnabled(False)
        self.menu.addSeparator()
        self.menu.addAction(self.tr('Settings and Management'),
                            self.show_management)
        self.menu.addAction(self.tr('Exit'), self.exit)