Example #1
0
 def init_alternatives(self):
     try:
         conflict_items = self.app.provider.get_note_alternatives(self.note.id)
         if conflict_items:
             template = self.ui.alternativeVersions.text()
             conflicts = map(
                 lambda item: Note.from_tuple(self.app.provider.get_note(
                     item,
                 )), self.note.conflict_items,
             )
             text = template % ', '.join(map(
                 lambda note: '<a href="%d">%s</a>' % (
                     note.id, note.title,
                 ), conflicts,
             ))
             self.ui.alternativeVersions.setText(text)
             self.ui.alternativeVersions.linkActivated.connect(
                 lambda id: self.app.indicator.open(
                     Note.from_tuple(self.app.provider.get_note(int(id))),
                 )
             )
         else:
             self.ui.alternativeVersions.hide()
     except DBusException:
         self.ui.alternativeVersions.hide()
Example #2
0
 def init_alternatives(self):
     try:
         conflict_items = self.app.provider.get_note_alternatives(
             self.note.id)
         if conflict_items:
             conflicts = map(
                 lambda item: Note.from_tuple(
                     self.app.provider.get_note(item, )),
                 self.note.conflict_items,
             )
             text = self.alternatives_template % ', '.join(
                 map(
                     lambda note: u'<a href="%d">%s</a>' % (
                         note.id,
                         note.title,
                     ),
                     conflicts,
                 ))
             self.ui.alternativeVersions.setText(text)
             self.ui.alternativeVersions.linkActivated.connect(
                 lambda id: self.app.indicator.open(
                     Note.from_tuple(self.app.provider.get_note(int(id))),
                 ))
         else:
             self.ui.alternativeVersions.hide()
     except DBusException:
         self.ui.alternativeVersions.hide()
Example #3
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(),
     )))
Example #4
0
 def create(self, attach=None, notebook_id=NONE_ID):
     note_struct = Note(  # maybe replace NONE's to somthing better
         id=NONE_ID,
         title=self.tr('New note'),
         content=self.tr("New note content"),
         tags=dbus.Array([], signature='i'),
         notebook=notebook_id,
         created=NONE_VAL,
         updated=NONE_VAL,
         place='',
     ).struct
     note = Note.from_tuple(self.app.provider.create_note(note_struct), )
     editor = self.open(note)
     if attach:
         editor.resource_edit.add_attach(attach)
Example #5
0
 def match(self, context):
     if not context.isValid():
         return
     query = context.query()
     search = query.__str__()  # PyQt is shit
     if len(search) < 3:
         return
     if search.lower() in 'create note':
         action = Plasma.QueryMatch(self.runner)
         action.setText("Create new note in everpad")
         action.setType(Plasma.QueryMatch.ExactMatch)
         action.setIcon(KIcon("everpad"))
         action.setData(str(CREATE))
         context.addMatch(query, action)
     if search.lower() in 'settings and management':
         action = Plasma.QueryMatch(self.runner)
         action.setText("Open everpad settings")
         action.setType(Plasma.QueryMatch.ExactMatch)
         action.setIcon(KIcon("everpad"))
         action.setData(str(SETTINGS))
         context.addMatch(query, action)
     blank = dbus.Array([], signature='i')
     for note_struct in provider.find_notes(
         search, blank, blank, 0,
         1000, Note.ORDER_TITLE, -1,
     ):
         note = Note.from_tuple(note_struct)
         action = Plasma.QueryMatch(self.runner)
         action.setText(note.title)
         action.setSubtext(html2text(note.content))
         action.setType(Plasma.QueryMatch.ExactMatch)
         action.setIcon(KIcon("everpad"))
         action.setData(str(note.id))
         context.addMatch(query, action)
Example #6
0
    def tag_selected(self, index):
        self.notesModel.setRowCount(0)

        item = self.tagsModel.itemFromIndex(index)
        if hasattr(item, 'tag'):
            tag_id = item.tag.id
        else:
            tag_id = 0

        self._current_notebook = SELECT_NONE
        self._current_tag = tag_id

        tag_filter = [tag_id] if tag_id > 0 else dbus.Array([], signature='i')
        notes = self.app.provider.find_notes(
            '',
            dbus.Array([], signature='i'),
            tag_filter,
            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)
Example #7
0
        def test_open_note_links(self):
            """Test open note links"""
            guid = 'guid'
            note = Note(
                id=123,
            )

            self.app.open = MagicMock()
            self.service.get_note_by_guid = MagicMock(
                return_value=note.struct,
            )

            link = "evernote:///view/123/123/{guid}/123/".format(
                guid=guid,
            )
            self.editor = Editor(self.note)
            self.editor.note_edit.link_clicked(QUrl(link))

            self.assertEqual(
                self.service.get_note_by_guid.call_args[0][0], guid,
            )
            self.assertEqual(
                self.app.open.call_args[0][0].id, note.id,
            )
            del self.app.open
Example #8
0
 def update_title(self):
     title = self.note_edit.title
     if self.note.conflict_parent:
         title += self.tr(' altrentive of: %s') % (Note.from_tuple(
             self.app.provider.get_note(
                 self.note.conflict_parent, )).title, )
     self.setWindowTitle(self.tr('Everpad / %s') % title)
Example #9
0
 def update_title(self):
     title = self.note_edit.title
     if self.note.conflict_parent:
         title += self.tr(" alternative of: %s") % (
             Note.from_tuple(self.app.provider.get_note(self.note.conflict_parent)).title,
         )
     self.setWindowTitle(self.tr("Everpad / %s") % title)
Example #10
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
        notebook_filter = [notebook_id] if notebook_id > 0 else dbus.Array([], signature='i')
        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)
Example #11
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),
     )
Example #12
0
 def link_clicked(self, url):
     if url.scheme() == 'evernote':
         note_guid = url.toString().split('/')[6]
         note = Note.from_tuple(
             self.app.provider.get_note_by_guid(note_guid), )
         self.app.open(note)
     else:
         webbrowser.open(url.toString())
Example #13
0
 def link_clicked(self, url):
     if url.scheme() == 'evernote':
         note_guid = url.toString().split('/')[6]
         note = Note.from_tuple(
             self.app.provider.get_note_by_guid(note_guid),
         )
         self.app.open(note)
     else:
         webbrowser.open(url.toString())
Example #14
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))
def search_all(search, results):
    for note_struct in provider.find_notes(
        search, dbus.Array([], signature="i"), dbus.Array([], signature="i"), 0, 100, Note.ORDER_TITLE, -1
    ):
        note = Note.from_tuple(note_struct)
        # TODO: Fix so it can return system lang encoding
        tags = ", ".join([tag.title().encode("ascii", errors="replace") for tag in note.tags])
        results.append(
            u"%s%s%s%s%s"
            % (note.id, SPLIT_CHARACTER, tags, SPLIT_CHARACTER, note.title.encode("ascii", errors="replace"))
        )
Example #16
0
 def __init__(self, note, *args, **kwargs):
     """init dialog and connect signals"""
     QDialog.__init__(self, *args, **kwargs)
     self.app = QApplication.instance()
     self.canceled = False
     self.ui = Ui_ShareNote()
     self.ui.setupUi(self)
     self.setWindowIcon(get_icon())
     self.note = Note.from_tuple(self.app.provider.get_note(note.id), )
     self.app.data_changed.connect(self.data_changed)
     self.ui.cancelButton.clicked.connect(self.cancel)
     self.ui.copyButton.clicked.connect(self.copy_url)
     if not self.note.share_url:
         self.start_sharing()
     self.update()
Example #17
0
 def create(self, attach=None):
     note_struct = Note(  # maybe replace NONE's to somthing better
         id=NONE_ID,
         title=self.tr("New note"),
         content=self.tr("New note content"),
         tags=dbus.Array([], signature="i"),
         notebook=NONE_ID,
         created=NONE_VAL,
         updated=NONE_VAL,
         place="",
     ).struct
     note = Note.from_tuple(self.app.provider.create_note(note_struct))
     editor = self.open(note)
     if attach:
         editor.resource_edit.add_attach(attach)
Example #18
0
 def get_note(self):
     return Note(
         id=randint(1, 100000),
         title=deepcopy(self._title),
         content=deepcopy(self._content),
         created=randint(1000000, 9000000),
         updated=randint(1000000, 9000000),
         notebook=randint(1, 100000),
         tags=deepcopy(self._tags),
         place=deepcopy(self._place),
         pinnded=True,
         conflict_parent=randint(1, 100000),
         conflict_items=range(10),
         share_date=randint(1000000, 9000000),
         share_url=deepcopy(self._url),
     )
Example #19
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)
Example #20
0
 def search(self, search, results):
     try:
         version = provider.get_api_version()
     except (  # dbus raise some magic
             dbus.exceptions.UnknownMethodException,
             dbus.exceptions.DBusException,
     ):
         version = -1
     if version < API_VERSION:
         dim = datetime.now() - getattr(self, 'last_api_notify',
                                        datetime.now())
         if dim.seconds > 600:
             Notify.init("everpad")
             Notify.Notification.new(
                 'everpad', _('Please restart everpad via indicator'),
                 '').show()
             self.last_api_notify = datetime.now()
         return
     elif version > API_VERSION:
         sys.exit(0)
     if self.notebook_filter_id:
         notebooks = [self.notebook_filter_id]
     else:
         notebooks = dbus.Array([], signature='i')
     if self.place_filter_id:
         place = self.place_filter_id
     else:
         place = 0
     tags = dbus.Array(self.tag_filter_ids, signature='i')
     for note_struct in provider.find_notes(
             search,
             notebooks,
             tags,
             place,
             1000,
             Note.ORDER_TITLE,
             -1,
     ):
         note = Note.from_tuple(note_struct)
         results.append(json.dumps({
             'id': note.id,
             'search': search
         }), 'everpad-note',
                        self.pin_notes if note.pinnded else self.all_notes,
                        "text/html", note.title, html2text(note.content),
                        '')
Example #21
0
 def __init__(self, note, *args, **kwargs):
     """init dialog and connect signals"""
     QDialog.__init__(self, *args, **kwargs)
     self.app = QApplication.instance()
     self.canceled = False
     self.ui = Ui_ShareNote()
     self.ui.setupUi(self)
     self.setWindowIcon(get_icon())
     self.note = Note.from_tuple(
         self.app.provider.get_note(note.id),
     )
     self.app.data_changed.connect(self.data_changed)
     self.ui.cancelButton.clicked.connect(self.cancel)
     self.ui.copyButton.clicked.connect(self.copy_url)
     if not self.note.share_url:
         self.start_sharing()
     self.update()
Example #22
0
 def preview(self, scope, uri):
     obj = json.loads(uri)
     note = Note.from_tuple(provider.get_note(obj['id']))
     preview = Unity.GenericPreview.new(
         note.title, html2text(note.content), None,
     )
     edit = Unity.PreviewAction.new("edit", "Edit", None)
     image = None
     for _res in provider.get_note_resources(note.id):
         res = Resource.from_tuple(_res)
         if 'image' in res.mime:
             image = 'file://%s' % res.file_path
     if image:
         preview.props.image_source_uri = image
     edit.connect('activated', self.handle_uri)
     preview.add_action(edit)
     return preview
Example #23
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)
Example #24
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))
Example #25
0
 def preview(self, scope, uri):
     obj = json.loads(uri)
     note = Note.from_tuple(provider.get_note(obj['id']))
     preview = Unity.GenericPreview.new(
         note.title,
         html2text(note.content),
         None,
     )
     edit = Unity.PreviewAction.new("edit", "Edit", None)
     image = None
     for _res in provider.get_note_resources(note.id):
         res = Resource.from_tuple(_res)
         if 'image' in res.mime:
             image = 'file://%s' % res.file_path
     if image:
         preview.props.image_source_uri = image
     edit.connect('activated', self.handle_uri)
     preview.add_action(edit)
     return preview
Example #26
0
 def search(self, search, results):
     if self.notebook_filter_id:
         notebooks = [self.notebook_filter_id]
     else:
         notebooks = dbus.Array([], signature='i')
     if self.place_filter_id:
         place = self.place_filter_id
     else:
         place = 0
     tags = dbus.Array(self.tag_filter_ids, signature='i')
     for note_struct in provider.find_notes(
         search, notebooks, tags, place,
         100, Note.ORDER_TITLE,
     ):
         note = Note.from_tuple(note_struct)
         results.append(str(note.id),
             'everpad-note', self.category, "text/html", note.title,
             ''.join(BeautifulSoup(note.content).findAll(text=True)),
         '')
Example #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),
     )
Example #28
0
 def update(self):
     self.menu.clear()
     if get_auth_token():
         for note_struct in self.app.provider.find_notes(
             "", dbus.Array([], signature="i"), dbus.Array([], signature="i"), 0, 20, Note.ORDER_UPDATED_DESC
         ):
             note = Note.from_tuple(note_struct)
             self.menu.addAction(note.title[:40], Slot()(partial(self.open, note=note)))
         self.menu.addSeparator()
         self.menu.addAction(self.tr("Create Note"), self.create)
         if self.app.provider.get_status() == STATUS_SYNC:
             action = self.menu.addAction(self.tr("Sync in progress"))
             action.setEnabled(False)
         else:
             self.menu.addAction(
                 self.tr("Last sync: %s") % self.app.provider.get_last_sync(), Slot()(self.app.provider.sync)
             )
     self.menu.addAction(self.tr("Settings and Management"), self.show_management)
     self.menu.addSeparator()
     self.menu.addAction(self.tr("Exit"), self.exit)
Example #29
0
 def create(self, attach=None, notebook_id=NONE_ID):
     note_struct = Note(  # maybe replace NONE's to somthing better
         id=NONE_ID,
         title=self.tr('New note'),
         content=self.tr("New note content"),
         tags=dbus.Array([], signature='i'),
         notebook=notebook_id,
         created=NONE_VAL,
         updated=NONE_VAL,
         conflict_parent=NONE_VAL,
         conflict_items=dbus.Array([], signature='i'),
         place='',
         share_date=NONE_VAL,
         share_url='',
     ).struct
     note = Note.from_tuple(
         self.app.provider.create_note(note_struct),
     )
     editor = self.open(note)
     if attach:
         editor.resource_edit.add_all_attach(attach)
Example #30
0
 def search(self, search, results):
     try:
         version = provider.get_api_version()
     except (  # dbus raise some magic
         dbus.exceptions.UnknownMethodException,
         dbus.exceptions.DBusException,
     ):
         version = -1
     if version < API_VERSION:
         dim = datetime.now() - getattr(self, 'last_api_notify', datetime.now())
         if dim.seconds > 600:
             Notify.init("everpad")
             Notify.Notification.new(
                 'everpad',
                  _('Please restart everpad via indicator'),
             '').show()
             self.last_api_notify = datetime.now()
         return
     elif version > API_VERSION:
         sys.exit(0)
     if self.notebook_filter_id:
         notebooks = [self.notebook_filter_id]
     else:
         notebooks = dbus.Array([], signature='i')
     if self.place_filter_id:
         place = self.place_filter_id
     else:
         place = 0
     tags = dbus.Array(self.tag_filter_ids, signature='i')
     for note_struct in provider.find_notes(
         search, notebooks, tags, place,
         1000, Note.ORDER_TITLE, -1,
     ):
         note = Note.from_tuple(note_struct)
         results.append(json.dumps({'id': note.id, 'search': search}),
             'everpad-note', self.pin_notes if note.pinnded else self.all_notes,
             "text/html", note.title, html2text(note.content),
         '')
Example #31
0
 def _add_note(self, struct):
     note = Note.from_tuple(struct)
     title = note.title[:40].replace("&", "&&")
     self.menu.addAction(title, Slot()(partial(self.open, note=note)))
Example #32
0
 def open_with_search_term(self, id, search_term):
     note = Note.from_tuple(self.app.provider.get_note(id))
     self.app.indicator.open(note, search_term)
Example #33
0
 def _add_note(self, menu, struct):
     note = Note.from_tuple(struct)
     title = note.title[:40].replace('&', '&&')
     menu.addAction(title, Slot()(partial(self.open, note=note)))
Example #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)
Example #35
0
 def data_changed(self):
     """On data changed slot"""
     self.note = Note.from_tuple(self.app.provider.get_note(self.note.id), )
     self.update()
    def search(self, search, filters):
        results = []
        try:
            version = everpad_provider.get_api_version()
        except (  # dbus raise some magic
                  dbus.exceptions.UnknownMethodException,
                  dbus.exceptions.DBusException,
        ):
            version = -1
        if version != API_VERSION:
            dim = datetime.now() - getattr(self, 'last_api_notify', datetime.now())
            if dim.seconds > 600:
                Notify.init("everpad")
                Notify.Notification.new('everpad', _('Wrong everpad API version'),
                                        '').show()
                self.last_api_notify = datetime.now()
            return results

        #read filters
        tags_filter = filters.get_filter_by_id('tags')
        tag_filter_ids = map(lambda tag: int(tag.props.id),
                             filter(lambda tag: tag.props.active, tags_filter.options))
        tags = dbus.Array(tag_filter_ids, signature='i')

        notebook_filter = filters.get_filter_by_id('notebooks').get_active_option()
        if notebook_filter:
            notebook_filter_id = int(notebook_filter.props.id)
        else:
            notebook_filter_id = None
        if notebook_filter_id:
            notebooks = [notebook_filter_id]
        else:
            notebooks = dbus.Array([], signature='i')

        place_filter = filters.get_filter_by_id('places').get_active_option()
        if place_filter:
            place_filter_id = int(place_filter.props.id)
        else:
            place_filter_id = None
        if place_filter_id:
            place = place_filter_id
        else:
            place = 0

        for note_struct in everpad_provider.find_notes(search, notebooks, tags,
                                                       place, 1000, Note.ORDER_TITLE, -1,
                                                       ):
            note = Note.from_tuple(note_struct)
            created = datetime.datetime.fromtimestamp(note.created/1000).strftime('%c')
            last_changed = datetime.datetime.fromtimestamp(note.updated/1000).strftime('%c')
            note_tags = ','.join(note.tags)
            note_uri = json.dumps({'id': note.id, 'search': search})
            results.append({'uri': note_uri,
                            'title': note.title,
                            'comment': self.extract_content(note.content),
                            'category': self.pin_notes if note.pinnded else self.all_notes,
                            'created': GLib.Variant('s', created),
                            'last_changed': GLib.Variant('s', last_changed),
                            'tags': GLib.Variant('s', note_tags)
                            })
        return results
Example #37
0
 def open_with_search_term(self, id, search_term):
     note = Note.from_tuple(self.app.provider.get_note(id))
     self.app.indicator.open(note, search_term)
Example #38
0
 def _add_note(self, menu, struct):
     note = Note.from_tuple(struct)
     title = note.title[:40].replace('&', '&&')
     menu.addAction(title, Slot()(
         partial(self.open, note=note)
     ))
Example #39
0
 def open(self, id):
     note = Note.from_tuple(self.app.provider.get_note(id))
     self.app.indicator.open(note)
Example #40
0
 def data_changed(self):
     """On data changed slot"""
     self.note = Note.from_tuple(
         self.app.provider.get_note(self.note.id),
     )
     self.update()
Example #41
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)
Example #42
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(),
             )))