mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 22:42:25 -04:00
add timeout and better error msg to getshared
This commit is contained in:
parent
cbb7f236cd
commit
f4f3c94ec0
1 changed files with 28 additions and 12 deletions
|
@ -5,7 +5,7 @@
|
||||||
from PyQt4.QtGui import *
|
from PyQt4.QtGui import *
|
||||||
from PyQt4.QtCore import *
|
from PyQt4.QtCore import *
|
||||||
import ankiqt, simplejson, time, cStringIO, zipfile, tempfile, os, re
|
import ankiqt, simplejson, time, cStringIO, zipfile, tempfile, os, re
|
||||||
import traceback, urllib2
|
import traceback, urllib2, socket, cgi
|
||||||
from ankiqt.ui.utils import saveGeom, restoreGeom, showInfo
|
from ankiqt.ui.utils import saveGeom, restoreGeom, showInfo
|
||||||
from anki.utils import fmtTimeSpan
|
from anki.utils import fmtTimeSpan
|
||||||
|
|
||||||
|
@ -29,6 +29,11 @@ class GetShared(QDialog):
|
||||||
self.form = ankiqt.forms.getshared.Ui_Dialog()
|
self.form = ankiqt.forms.getshared.Ui_Dialog()
|
||||||
self.form.setupUi(self)
|
self.form.setupUi(self)
|
||||||
self.ok = True
|
self.ok = True
|
||||||
|
self.conErrMsg = _("""\
|
||||||
|
<b>Unable to connect to the server.<br><br>
|
||||||
|
Please check your network connection or try again in a few minutes.</b><br>
|
||||||
|
<br>
|
||||||
|
Error was:<pre>%s</pre>""")
|
||||||
restoreGeom(self, "getshared")
|
restoreGeom(self, "getshared")
|
||||||
self.setupTable()
|
self.setupTable()
|
||||||
self.onChangeType(type)
|
self.onChangeType(type)
|
||||||
|
@ -49,16 +54,24 @@ class GetShared(QDialog):
|
||||||
self.limit)
|
self.limit)
|
||||||
|
|
||||||
def fetchData(self):
|
def fetchData(self):
|
||||||
|
self.parent.setProgressParent(None)
|
||||||
|
self.parent.deck.startProgress()
|
||||||
|
self.parent.deck.updateProgress()
|
||||||
|
try:
|
||||||
|
socket.setdefaulttimeout(30)
|
||||||
try:
|
try:
|
||||||
sock = urllib2.urlopen(
|
sock = urllib2.urlopen(
|
||||||
"http://anki.ichi2.net/file/search?t=%d" % self.type)
|
"http://anki.ichi2.net/file/search?t=%d" % self.type)
|
||||||
self.allList = simplejson.loads(unicode(sock.read()))
|
self.allList = simplejson.loads(unicode(sock.read()))
|
||||||
except:
|
except:
|
||||||
showInfo(_("Unable to connect to server.\n\n") +
|
showInfo(self.conErrMsg % cgi.escape(unicode(
|
||||||
traceback.format_exc())
|
traceback.format_exc(), "utf-8", "replace")))
|
||||||
self.close()
|
self.close()
|
||||||
self.ok = False
|
self.ok = False
|
||||||
return
|
return
|
||||||
|
finally:
|
||||||
|
self.parent.deck.finishProgress()
|
||||||
|
socket.setdefaulttimeout(None)
|
||||||
self.form.search.setFocus()
|
self.form.search.setFocus()
|
||||||
self.typeChanged()
|
self.typeChanged()
|
||||||
self.limit()
|
self.limit()
|
||||||
|
@ -156,8 +169,10 @@ class GetShared(QDialog):
|
||||||
tmpfile = os.fdopen(fd, "w+b")
|
tmpfile = os.fdopen(fd, "w+b")
|
||||||
cnt = 0
|
cnt = 0
|
||||||
try:
|
try:
|
||||||
|
socket.setdefaulttimeout(30)
|
||||||
self.parent.setProgressParent(self)
|
self.parent.setProgressParent(self)
|
||||||
self.parent.startProgress()
|
self.parent.startProgress()
|
||||||
|
self.parent.updateProgress()
|
||||||
try:
|
try:
|
||||||
sock = urllib2.urlopen(
|
sock = urllib2.urlopen(
|
||||||
"http://anki.ichi2.net/file/get?id=%d" %
|
"http://anki.ichi2.net/file/get?id=%d" %
|
||||||
|
@ -171,11 +186,12 @@ class GetShared(QDialog):
|
||||||
self.parent.updateProgress(
|
self.parent.updateProgress(
|
||||||
label=_("Downloaded %dKB") % (cnt/1024.0))
|
label=_("Downloaded %dKB") % (cnt/1024.0))
|
||||||
except:
|
except:
|
||||||
showInfo(_("Unable to connect to server.\n\n") +
|
showInfo(self.conErrMsg % cgi.escape(unicode(
|
||||||
unicode(traceback.format_exc(), "utf-8", "replace"))
|
traceback.format_exc(), "utf-8", "replace")))
|
||||||
self.close()
|
self.close()
|
||||||
return
|
return
|
||||||
finally:
|
finally:
|
||||||
|
socket.setdefaulttimeout(None)
|
||||||
self.parent.setProgressParent(None)
|
self.parent.setProgressParent(None)
|
||||||
self.parent.finishProgress()
|
self.parent.finishProgress()
|
||||||
QDialog.accept(self)
|
QDialog.accept(self)
|
||||||
|
|
Loading…
Reference in a new issue