fix custom proxy support

This commit is contained in:
Damien Elmes 2012-05-20 18:29:11 +09:00
parent dfe7f5bf16
commit a134338f5a
3 changed files with 19 additions and 65 deletions

View file

@ -86,9 +86,6 @@ class Preferences(QDialog):
self.connect(self.form.syncDeauth, SIGNAL("clicked()"),
self.onSyncDeauth)
self.form.proxyHost.setText(self.prof['proxyHost'])
self.form.proxyPort.setValue(self.prof['proxyPort'])
self.form.proxyUser.setText(self.prof['proxyUser'])
self.form.proxyPass.setText(self.prof['proxyPass'])
def _hideAuth(self):
self.form.syncDeauth.setShown(False)
@ -104,9 +101,6 @@ Not currently enabled; click the sync button in the main window to enable."""))
self.prof['autoSync'] = self.form.syncOnProgramOpen.isChecked()
self.prof['syncMedia'] = self.form.syncMedia.isChecked()
self.prof['proxyHost'] = unicode(self.form.proxyHost.text())
self.prof['proxyPort'] = int(self.form.proxyPort.value())
self.prof['proxyUser'] = unicode(self.form.proxyUser.text())
self.prof['proxyPass'] = unicode(self.form.proxyPass.text())
# Backup
######################################################################

View file

@ -12,6 +12,8 @@ from anki.db import DB
from anki.utils import isMac, isWin, intTime, checksum
from anki.lang import langs
from aqt.utils import showWarning, fontForPlatform
from httplib2 import ProxyInfo
import anki.sync
import aqt.forms
metaConf = dict(
@ -51,10 +53,7 @@ profileConf = dict(
syncKey=None,
syncMedia=True,
autoSync=True,
proxyHost='',
proxyPort=8080,
proxyUser='',
proxyPass='',
proxyHost='', # despite the name, stores full URL
proxyType=3,
)
@ -140,6 +139,20 @@ computer."""))
if name != "_global":
self.name = name
self.profile = prof
# export proxy settings
if prof['proxyHost'] == "off":
# force off; override environment
anki.sync.HTTP_PROXY = None
elif prof['proxyHost']:
url = prof['proxyHost']
if url.lower().startswith("https"):
method = "https"
else:
method = "http"
anki.sync.HTTP_PROXY = ProxyInfo.from_url(url, method)
else:
# use environment
anki.sync.HTTP_PROXY = ProxyInfo.from_environment()
return True
def save(self):

View file

@ -251,7 +251,7 @@
<item>
<widget class="QLabel" name="label_13">
<property name="text">
<string>&lt;b&gt;Proxy&lt;/b&gt;&lt;br&gt;If your system needs a proxy to access the internet, enter your details below. Leave &quot;Host&quot; blank to disable proxy support.</string>
<string>&lt;b&gt;Proxy&lt;/b&gt;&lt;br&gt;If your system needs a proxy to access the internet, enter your details below.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
@ -266,63 +266,13 @@
<item row="0" column="0">
<widget class="QLabel" name="label_14">
<property name="text">
<string>Host</string>
<string>URL</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="proxyHost"/>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_15">
<property name="text">
<string>Port</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QSpinBox" name="proxyPort">
<property name="minimumSize">
<size>
<width>60</width>
<height>0</height>
</size>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>65535</number>
</property>
<property name="value">
<number>8080</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_19">
<property name="text">
<string>Username</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="proxyUser"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_20">
<property name="text">
<string>Password</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="proxyPass">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
</layout>
</item>
<item>
@ -486,9 +436,6 @@
<tabstop>syncOnProgramOpen</tabstop>
<tabstop>syncDeauth</tabstop>
<tabstop>proxyHost</tabstop>
<tabstop>proxyPort</tabstop>
<tabstop>proxyUser</tabstop>
<tabstop>proxyPass</tabstop>
<tabstop>numBackups</tabstop>
<tabstop>buttonBox</tabstop>
<tabstop>tabWidget</tabstop>