Added pocket in the services tab for connection

This commit is contained in:
Manuel Cortez 2015-06-21 21:20:53 -05:00
parent c929b965fe
commit cfccebc1bb
6 changed files with 82 additions and 6 deletions

View File

@ -37,3 +37,5 @@ spelling_language = string(default="")
save_followers_in_autocompletion_db = boolean(default=False)
save_friends_in_autocompletion_db = boolean(default=False)
[services]
pocket_access_token = string(default="")

View File

@ -867,3 +867,11 @@ class conversationBufferController(searchBufferController):
if number_of_items > 0:
self.session.sound.play("search_updated.ogg")
class pocketBufferController(baseBufferController):
def __init__(self, parent, name, sessionObject, account, sound=None, function=None, bufferType=None, *args, **kwargs):
super(pocketBufferController, self).__init__(parent, name, sessionObject, account, sound, function, bufferType, *args, **kwargs)
self.type = "pocket"
def start_stream(self):
log.debug("Starting stream for buffer %s, account %s and type %s" % (self.name, self.account, self.type))
log.debug("args: %s, kwargs: %s" % (self.args, self.kwargs))

View File

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import os
import webbrowser
import pocket
import sound_lib
import paths
import widgetUtils
@ -14,7 +15,10 @@ from extra.autocompletionUsers import settings
from pubsub import pub
import logging
import config_utils
from pocket_utils import authorisationHandler
import BaseHTTPServer
log = logging.getLogger("Settings")
import keys
class globalSettingsController(object):
def __init__(self):
@ -138,7 +142,12 @@ class accountSettingsController(globalSettingsController):
self.dialog.set_value("sound", "output", self.config["sound"]["output_device"])
self.dialog.set_value("sound", "session_mute", self.config["sound"]["session_mute"])
self.dialog.set_value("sound", "soundpack", self.config["sound"]["current_soundpack"])
self.dialog.create_audio_services()
self.dialog.create_services()
if self.config["services"]["pocket_access_token"] == "":
self.dialog.services.set_pocket(False)
else:
self.dialog.services.set_pocket(True)
widgetUtils.connect_event(self.dialog.services.pocketBtn, widgetUtils.BUTTON_PRESSED, self.manage_pocket)
self.dialog.set_value("services", "apiKey", self.config["sound"]["sndup_api_key"])
self.dialog.realize()
self.dialog.set_title(_(u"Account settings for %s") % (self.user,))
@ -247,3 +256,26 @@ class accountSettingsController(globalSettingsController):
change = self.dialog.buffers.get_event(ev)
if change == True:
self.dialog.buffers.change_selected_item()
def manage_pocket(self, *args, **kwargs):
if self.dialog.services.get_pocket_status() == _(u"Connect your Pocket account"):
self.connect_pocket()
else:
self.disconnect_pocket()
def connect_pocket(self):
dlg = self.dialog.services.show_pocket_dialog()
if dlg == widgetUtils.YES:
request_token = pocket.Pocket.get_request_token(consumer_key=keys.keyring.get("pocket_consumer_key"), redirect_uri="http://127.0.0.1:8080")
auth_url = pocket.Pocket.get_auth_url(code=request_token, redirect_uri="http://127.0.0.1:8080")
webbrowser.open_new_tab(auth_url)
httpd = BaseHTTPServer.HTTPServer(('127.0.0.1', 8080), authorisationHandler.handler)
while authorisationHandler.logged == False:
httpd.handle_request()
user_credentials = pocket.Pocket.get_credentials(consumer_key=keys.keyring.get("pocket_consumer_key"), code=request_token)
self.dialog.services.set_pocket(True)
self.config["services"]["pocket_access_token"] = user_credentials["access_token"]
def disconnect_dropbox(self):
self.config["services"]["pocket_access_token"] = ""
self.dialog.services.set_pocket(False)

View File

@ -0,0 +1 @@
# -*- coding: utf-8 -*-

View File

@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
import BaseHTTPServer, application
logged = False
class handler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(self):
global logged
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
logged = True
self.wfile.write("You have successfully logged into Pocket with" + application.name + ". "
"You can close this window now.")

View File

@ -265,9 +265,9 @@ class sound(wx.Panel):
def get(self, control):
return getattr(self, control).GetStringSelection()
class audioServicesPanel(wx.Panel):
class servicesPanel(wx.Panel):
def __init__(self, parent):
super(audioServicesPanel, self).__init__(parent)
super(servicesPanel, self).__init__(parent)
mainSizer = wx.BoxSizer(wx.VERTICAL)
apiKeyLabel = wx.StaticText(self, -1, _(u"If you have a SndUp account, enter your API Key here. If your API Key is invalid, " + application.name + " will fail to upload. If there is no API Key here, " + application.name + " will upload annonymously."))
self.apiKey = wx.TextCtrl(self, -1)
@ -278,8 +278,25 @@ class audioServicesPanel(wx.Panel):
apiKeyBox.Add(apiKeyLabel, 0, wx.ALL, 5)
apiKeyBox.Add(self.apiKey, 0, wx.ALL, 5)
mainSizer.Add(apiKeyBox, 0, wx.ALL, 5)
self.pocketBtn = wx.Button(self, -1)
mainSizer.Add(self.pocketBtn, 0, wx.ALL, 5)
self.SetSizer(mainSizer)
def set_pocket(self, active=True):
if active == True:
self.pocketBtn.SetLabel(_(u"Disconnect your Pocket account"))
else:
self.pocketBtn.SetLabel(_(u"Connect your Pocket account"))
def show_pocket_dialog(self):
return wx.MessageDialog(self, _(u"The authorization request will be opened in your browser. You only need to do this once. Do you want to continue?"), _(u"Pocket Authorization"), wx.YES_NO).ShowModal()
def show_pocket_authorization_error(self):
wx.MessageDialog(self, _(u"Error during authorization. Try again later."), _(u"Error!"), wx.ICON_ERROR).ShowModal()
def get_pocket_status(self):
return self.pocketBtn.GetLabel()
class configurationDialog(baseDialog.BaseWXDialog):
def set_title(self, title):
@ -317,9 +334,10 @@ class configurationDialog(baseDialog.BaseWXDialog):
def create_sound(self, output_devices, input_devices, soundpacks):
self.sound = sound(self.notebook, output_devices, input_devices, soundpacks)
self.notebook.AddPage(self.sound, _(u"Sound"))
def create_audio_services(self):
self.services = audioServicesPanel(self.notebook)
self.notebook.AddPage(self.services, _(u"Audio Services"))
def create_services(self):
self.services = servicesPanel(self.notebook)
self.notebook.AddPage(self.services, _(u"Services"))
def realize(self):
self.sizer.Add(self.notebook, 0, wx.ALL, 5)