Exemple #1
0
 def change_auth(self):
     if get_auth_token():
         self.app.provider.remove_authentication()
     else:
         consumer = oauth.Consumer(CONSUMER_KEY, CONSUMER_SECRET)
         client = oauth.Client(consumer)
         resp, content = client.request(
             'https://%s/oauth?oauth_callback=' % HOST + urllib.quote('http://localhost:15216/'), 
         'GET')
         data = dict(urlparse.parse_qsl(content))
         url = 'https://%s/OAuth.action?oauth_token=' % HOST + urllib.quote(data['oauth_token'])
         webbrowser.open(url)
         os.system('killall everpad-web-auth')
         try:
             subprocess.Popen([
                 'everpad-web-auth', '--token', data['oauth_token'],
                 '--secret', data['oauth_token_secret'],
             ])
         except OSError:
             subprocess.Popen([
                 'python', '../auth.py', '--token',
                 data['oauth_token'], '--secret',
                 data['oauth_token_secret'],
             ])
     self.update_tabs()
Exemple #2
0
 def update(self):
     self.menu.clear()
     try:
         version = self.app.provider.get_api_version()
     except (dbus.exceptions.UnknownMethodException, dbus.exceptions.DBusException):  # dbus raise some magic
         version = -1
     if version != API_VERSION:
         action = self.menu.addAction(self.tr("API version missmatch, please restart"))
         action.setEnabled(False)
         self.menu.addAction(self.tr("Restart everpad"), self.kill_all)
         return
     if get_auth_token():
         pin_notes = self.app.provider.find_notes(
             "", dbus.Array([], signature="i"), dbus.Array([], signature="i"), 0, 20, Note.ORDER_UPDATED_DESC, 1
         )
         notes = self.app.provider.find_notes(
             "",
             dbus.Array([], signature="i"),
             dbus.Array([], signature="i"),
             0,
             20 - len(pin_notes),
             Note.ORDER_UPDATED_DESC,
             0,
         )
         if len(notes) + len(pin_notes) or self.app.provider.is_first_synced():
             self.menu.addAction(self.tr("All Notes"), self.show_all_notes)
             self.menu.addSeparator()
             if len(pin_notes):
                 for struct in pin_notes:
                     self._add_note(struct)
                 self.menu.addSeparator()
             for struct in notes:
                 self._add_note(struct)
             self.menu.addSeparator()
             self.menu.addAction(self.tr("Create Note"), self.create)
             first_sync = False
         else:
             first_sync = True
         if self.app.provider.get_status() == STATUS_SYNC:
             action = self.menu.addAction(
                 self.tr("Wait, first sync in progress") if first_sync else self.tr("Sync in progress")
             )
             action.setEnabled(False)
         else:
             if first_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:
                     label = self.tr("Last Sync: Just now")
                 elif delta_sync == 1:
                     label = self.tr("Last Sync: %s min ago") % delta_sync
                 else:
                     label = self.tr("Last Sync: %s mins ago") % delta_sync
             self.menu.addAction(label, 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)
Exemple #3
0
 def init_network(self):
     while True:
         try:
             self.auth_token = get_auth_token()
             self.note_store = get_note_store(self.auth_token)
             break
         except socket.error:
             time.sleep(30)
Exemple #4
0
 def init_network(self):
     while True:
         try:
             self.auth_token = get_auth_token()
             self.note_store = get_note_store(self.auth_token)
             break
         except socket.error:
             time.sleep(30)
Exemple #5
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)
         self.menu.addAction(
             self.tr('Restart everpad'), self.kill_all,
         )
         return
     if get_auth_token():
         pin_notes = self.app.provider.find_notes(
             '', dbus.Array([], signature='i'),
             dbus.Array([], signature='i'), 0,
             20, Note.ORDER_UPDATED_DESC, 1,
         )
         notes = self.app.provider.find_notes(
             '', dbus.Array([], signature='i'),
             dbus.Array([], signature='i'), 0,
             20 - len(pin_notes), Note.ORDER_UPDATED_DESC, 0,
         )
         if len(notes) + len(pin_notes) or self.app.provider.is_first_synced():
             self.menu.addAction(self.tr('All Notes'), self.show_all_notes)
             self.menu.addSeparator()
             if len(pin_notes):
                 for struct in pin_notes:
                     self._add_note(struct)
                 self.menu.addSeparator()
             for struct in notes:
                 self._add_note(struct)
             self.menu.addSeparator()
             self.menu.addAction(self.tr('Create Note'), self.create)
             first_sync = False
         else:
             first_sync = True
         if self.app.provider.get_status() == STATUS_SYNC:
             action = self.menu.addAction(
                 self.tr('Wait, first sync in progress') if first_sync
                 else self.tr('Sync in progress')
             )
             action.setEnabled(False)
         else:
             if first_sync:
                 label = self.tr('Please perform first sync')
             else:
                 label = self.tr('Last sync: %s') % self.app.provider.get_last_sync()
             self.menu.addAction(label, 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)
Exemple #6
0
 def run(self):
     self.session = get_db_session()
     self.sq = self.session.query
     self.auth_token = get_auth_token()
     self.note_store = get_note_store(self.auth_token)
     self.perform()
     while True:
         self.mutex.lock()
         self.wait_condition.wait(self.mutex)
         self.perform()
         self.mutex.unlock()
Exemple #7
0
 def update_tabs(self):
     if get_auth_token():
         self.ui.authBtn.setText(self.tr('Remove Authorisation'))
         self.ui.notebookTab.setEnabled(True)
         self.init_notebooks()
     else:
         self.ui.authBtn.setText(self.tr('Authorise'))
         self.ui.notebookTab.setEnabled(False)
     self.ui.autoStart.setCheckState(Qt.Checked
         if os.path.isfile(self.startup_file)
     else Qt.Unchecked)
Exemple #8
0
def get_note_store(auth_token=None):
    if not auth_token:
        auth_token = get_auth_token()
    user_store_uri = "https://" + HOST + "/edam/user"

    user_store_http_client = THttpClient.THttpClient(user_store_uri,
            http_proxy=get_proxy_config(urlparse(user_store_uri).scheme))
    user_store_protocol = TBinaryProtocol.TBinaryProtocol(user_store_http_client)
    user_store = UserStore.Client(user_store_protocol)
    note_store_url = user_store.getNoteStoreUrl(auth_token)
    note_store_http_client = THttpClient.THttpClient(note_store_url,
            http_proxy=get_proxy_config(urlparse(note_store_url).scheme))
    note_store_protocol = TBinaryProtocol.TBinaryProtocol(note_store_http_client)
    return NoteStore.Client(note_store_protocol)
Exemple #9
0
 def update_tabs(self):
     if get_auth_token():
         self.ui.authBtn.setText(self.tr('Remove Authorisation'))
     else:
         self.ui.authBtn.setText(self.tr('Authorise'))
     self.ui.autoStart.setCheckState(Qt.Checked
         if os.path.isfile(self.startup_file)
     else Qt.Unchecked)
     self.ui.noteFont.setCurrentFont(QFont(self.app.settings.value(
         'note-font-family', DEFAULT_FONT,
     )))
     self.ui.noteSize.setValue(int(self.app.settings.value(
         'note-font-size', DEFAULT_FONT_SIZE,
     )))
     self.ui.blackTray.setCheckState(Qt.Checked
         if int(self.app.settings.value('black-icon', 0))
     else Qt.Unchecked)
Exemple #10
0
 def __init__(self, *args, **kwargs):
     QCoreApplication.__init__(self, *args, **kwargs)
     self.settings = QSettings('everpad', 'everpad-provider')
     session_bus = dbus.SessionBus()
     self.bus = dbus.service.BusName("com.everpad.Provider", session_bus)
     self.service = ProviderService(self, session_bus, '/EverpadProvider')
     self.sync_thread = SyncThread(self)
     self.sync_thread.sync_state_changed.connect(
         Slot(int)(self.service.sync_state_changed),
     )
     if get_auth_token():
         self.sync_thread.start()
     self.service.qobject.authenticate_signal.connect(
         self.on_authenticated,
     )
     self.service.qobject.remove_authenticate_signal.connect(
         self.on_remove_authenticated,
     )
Exemple #11
0
 def __init__(self, verbose, *args, **kwargs):
     App.__init__(self, *args, **kwargs)
     self.settings = QSettings('everpad', 'everpad-provider')
     self.verbose = verbose
     session_bus = dbus.SessionBus()
     self.bus = dbus.service.BusName("com.everpad.Provider", session_bus)
     self.service = ProviderService(self, session_bus, '/EverpadProvider')
     self.sync_thread = SyncThread(self)
     self.sync_thread.sync_state_changed.connect(
         Slot(int)(self.service.sync_state_changed), )
     self.sync_thread.data_changed.connect(
         Slot()(self.service.data_changed), )
     if get_auth_token():
         self.sync_thread.start()
     self.service.qobject.authenticate_signal.connect(
         self.on_authenticated, )
     self.service.qobject.remove_authenticate_signal.connect(
         self.on_remove_authenticated, )
Exemple #12
0
 def change_auth(self):
     if get_auth_token():
         self.app.provider.remove_authentication()
         self.update_tabs()
     else:
         self.ui.tabWidget.hide()
         self.ui.webView.show()
         consumer = oauth.Consumer(CONSUMER_KEY, CONSUMER_SECRET)
         client = oauth.Client(consumer)
         resp, content = client.request(
             'https://%s/oauth?oauth_callback=' % HOST + urllib.quote('http://everpad/'), 
         'GET')
         data = dict(urlparse.parse_qsl(content))
         url = 'http://%s/OAuth.action?oauth_token=' % HOST + urllib.quote(data['oauth_token'])
         page = AuthPage(
             data['oauth_token'], data['oauth_token_secret'], self,
         )
         self.ui.webView.setPage(page)
         page.mainFrame().load(url)
Exemple #13
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)
Exemple #14
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)
         self.menu.addAction(
             self.tr('Restart everpad'),
             self.kill_all,
         )
         return
     if get_auth_token():
         pin_notes = self.app.provider.find_notes(
             '',
             dbus.Array([], signature='i'),
             dbus.Array([], signature='i'),
             0,
             20,
             Note.ORDER_UPDATED_DESC,
             1,
         )
         notes = self.app.provider.find_notes(
             '',
             dbus.Array([], signature='i'),
             dbus.Array([], signature='i'),
             0,
             20 - len(pin_notes),
             Note.ORDER_UPDATED_DESC,
             0,
         )
         if len(notes) + len(
                 pin_notes) or self.app.provider.is_first_synced():
             self.menu.addAction(self.tr('All Notes'), self.show_all_notes)
             self.menu.addSeparator()
             if len(pin_notes):
                 for struct in pin_notes:
                     self._add_note(struct)
                 self.menu.addSeparator()
             for struct in notes:
                 self._add_note(struct)
             self.menu.addSeparator()
             self.menu.addAction(self.tr('Create Note'), self.create)
             first_sync = False
         else:
             first_sync = True
         if self.app.provider.get_status() == STATUS_SYNC:
             action = self.menu.addAction(
                 self.tr('Wait, first sync in progress'
                         ) if first_sync else self.tr('Sync in progress'))
             action.setEnabled(False)
         else:
             if first_sync:
                 label = self.tr('Please perform first sync')
             else:
                 label = self.tr(
                     'Last sync: %s') % self.app.provider.get_last_sync()
             self.menu.addAction(label, 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)