mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
handle proxy config in libanki
This commit is contained in:
parent
d143a50358
commit
cf7ed9ea2f
3 changed files with 0 additions and 85 deletions
|
@ -85,7 +85,6 @@ class Preferences(QDialog):
|
||||||
else:
|
else:
|
||||||
self.connect(self.form.syncDeauth, SIGNAL("clicked()"),
|
self.connect(self.form.syncDeauth, SIGNAL("clicked()"),
|
||||||
self.onSyncDeauth)
|
self.onSyncDeauth)
|
||||||
self.form.proxyHost.setText(self.prof['proxyHost'])
|
|
||||||
|
|
||||||
def _hideAuth(self):
|
def _hideAuth(self):
|
||||||
self.form.syncDeauth.setShown(False)
|
self.form.syncDeauth.setShown(False)
|
||||||
|
@ -100,7 +99,6 @@ Not currently enabled; click the sync button in the main window to enable."""))
|
||||||
def updateNetwork(self):
|
def updateNetwork(self):
|
||||||
self.prof['autoSync'] = self.form.syncOnProgramOpen.isChecked()
|
self.prof['autoSync'] = self.form.syncOnProgramOpen.isChecked()
|
||||||
self.prof['syncMedia'] = self.form.syncMedia.isChecked()
|
self.prof['syncMedia'] = self.form.syncMedia.isChecked()
|
||||||
self.prof['proxyHost'] = unicode(self.form.proxyHost.text())
|
|
||||||
|
|
||||||
# Backup
|
# Backup
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
|
@ -12,7 +12,6 @@ from anki.db import DB
|
||||||
from anki.utils import isMac, isWin, intTime, checksum
|
from anki.utils import isMac, isWin, intTime, checksum
|
||||||
from anki.lang import langs
|
from anki.lang import langs
|
||||||
from aqt.utils import showWarning, fontForPlatform
|
from aqt.utils import showWarning, fontForPlatform
|
||||||
from httplib2 import ProxyInfo
|
|
||||||
import anki.sync
|
import anki.sync
|
||||||
import aqt.forms
|
import aqt.forms
|
||||||
|
|
||||||
|
@ -53,8 +52,6 @@ profileConf = dict(
|
||||||
syncKey=None,
|
syncKey=None,
|
||||||
syncMedia=True,
|
syncMedia=True,
|
||||||
autoSync=True,
|
autoSync=True,
|
||||||
proxyHost='', # despite the name, stores full URL
|
|
||||||
proxyType=3,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
class ProfileManager(object):
|
class ProfileManager(object):
|
||||||
|
@ -139,7 +136,6 @@ computer."""))
|
||||||
if name != "_global":
|
if name != "_global":
|
||||||
self.name = name
|
self.name = name
|
||||||
self.profile = prof
|
self.profile = prof
|
||||||
self.setupProxy()
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
|
@ -285,44 +281,3 @@ create table if not exists profiles
|
||||||
sql = "update profiles set data = ? where name = ?"
|
sql = "update profiles set data = ? where name = ?"
|
||||||
self.db.execute(sql, cPickle.dumps(self.meta), "_global")
|
self.db.execute(sql, cPickle.dumps(self.meta), "_global")
|
||||||
self.db.commit()
|
self.db.commit()
|
||||||
|
|
||||||
# Proxy handling
|
|
||||||
######################################################################
|
|
||||||
|
|
||||||
def setupProxy(self):
|
|
||||||
prof = self.profile
|
|
||||||
# export proxy settings
|
|
||||||
if prof['proxyHost'] == "off":
|
|
||||||
# force off; override environment
|
|
||||||
anki.sync.HTTP_PROXY = None
|
|
||||||
elif prof['proxyHost']:
|
|
||||||
url = prof['proxyHost']
|
|
||||||
anki.sync.HTTP_PROXY = ProxyInfo.from_url(
|
|
||||||
url, self.proxyMethod(url))
|
|
||||||
else:
|
|
||||||
# set in env?
|
|
||||||
p = ProxyInfo.from_environment()
|
|
||||||
if not p:
|
|
||||||
# platform-specific fetch
|
|
||||||
url = None
|
|
||||||
if isWin:
|
|
||||||
r = urllib.getproxies_registry()
|
|
||||||
if 'https' in r:
|
|
||||||
url = r['https']
|
|
||||||
elif 'http' in r:
|
|
||||||
url = r['http']
|
|
||||||
elif isMac:
|
|
||||||
r = urllib.getproxies_macosx_sysconf()
|
|
||||||
if 'https' in r:
|
|
||||||
url = r['https']
|
|
||||||
elif 'http' in r:
|
|
||||||
url = r['http']
|
|
||||||
if url:
|
|
||||||
p = ProxyInfo.from_url(url, self.proxyMethod(url))
|
|
||||||
anki.sync.HTTP_PROXY = p
|
|
||||||
|
|
||||||
def proxyMethod(self, url):
|
|
||||||
if url.lower().startswith("https"):
|
|
||||||
return "https"
|
|
||||||
else:
|
|
||||||
return "http"
|
|
||||||
|
|
|
@ -248,33 +248,6 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="label_13">
|
|
||||||
<property name="text">
|
|
||||||
<string><b>Proxy</b><br>If your system needs a proxy to access the internet, enter your details below.</string>
|
|
||||||
</property>
|
|
||||||
<property name="wordWrap">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<layout class="QGridLayout" name="gridLayout_3">
|
|
||||||
<property name="verticalSpacing">
|
|
||||||
<number>6</number>
|
|
||||||
</property>
|
|
||||||
<item row="0" column="0">
|
|
||||||
<widget class="QLabel" name="label_14">
|
|
||||||
<property name="text">
|
|
||||||
<string>URL</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1">
|
|
||||||
<widget class="QLineEdit" name="proxyHost"/>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<spacer name="verticalSpacer_2">
|
<spacer name="verticalSpacer_2">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
@ -288,16 +261,6 @@
|
||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="label_12">
|
|
||||||
<property name="text">
|
|
||||||
<string>Some settings will take effect after you restart Anki.</string>
|
|
||||||
</property>
|
|
||||||
<property name="alignment">
|
|
||||||
<set>Qt::AlignCenter</set>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QWidget" name="tab">
|
<widget class="QWidget" name="tab">
|
||||||
|
@ -435,7 +398,6 @@
|
||||||
<tabstop>syncMedia</tabstop>
|
<tabstop>syncMedia</tabstop>
|
||||||
<tabstop>syncOnProgramOpen</tabstop>
|
<tabstop>syncOnProgramOpen</tabstop>
|
||||||
<tabstop>syncDeauth</tabstop>
|
<tabstop>syncDeauth</tabstop>
|
||||||
<tabstop>proxyHost</tabstop>
|
|
||||||
<tabstop>numBackups</tabstop>
|
<tabstop>numBackups</tabstop>
|
||||||
<tabstop>buttonBox</tabstop>
|
<tabstop>buttonBox</tabstop>
|
||||||
<tabstop>tabWidget</tabstop>
|
<tabstop>tabWidget</tabstop>
|
||||||
|
|
Loading…
Reference in a new issue