summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/gui/loggerwindow.py
diff options
context:
space:
mode:
authorTomás Touceda <chiiph@leap.se>2014-08-06 15:42:17 -0300
committerTomás Touceda <chiiph@leap.se>2014-08-06 15:42:17 -0300
commit0c6ec2f7a5aae716b76d508066fbb69b378fbf43 (patch)
tree53146a054c4df007717b5153cef61fad78cb02c5 /src/leap/bitmask/gui/loggerwindow.py
parenta43edd95e531c4be733846aae4ee8273df0a11ad (diff)
parentf4e6d6a77b8b5498e9190c3d35841ef39222cfec (diff)
Merge remote-tracking branch 'refs/remotes/ivan/bug/pastebin-does-not-work' into develop
Diffstat (limited to 'src/leap/bitmask/gui/loggerwindow.py')
-rw-r--r--src/leap/bitmask/gui/loggerwindow.py113
1 files changed, 59 insertions, 54 deletions
diff --git a/src/leap/bitmask/gui/loggerwindow.py b/src/leap/bitmask/gui/loggerwindow.py
index 3a8354b1..c4f44dd7 100644
--- a/src/leap/bitmask/gui/loggerwindow.py
+++ b/src/leap/bitmask/gui/loggerwindow.py
@@ -18,11 +18,10 @@
"""
History log window
"""
-import logging
import cgi
+import logging
from PySide import QtCore, QtGui
-from twisted.internet import threads
from ui_loggerwindow import Ui_LoggerWindow
@@ -38,6 +37,9 @@ class LoggerWindow(QtGui.QDialog):
"""
Window that displays a history of the logged messages in the app.
"""
+ _paste_ok = QtCore.Signal(object)
+ _paste_error = QtCore.Signal(object)
+
def __init__(self, handler):
"""
Initialize the widget with the custom handler.
@@ -45,9 +47,6 @@ class LoggerWindow(QtGui.QDialog):
:param handler: Custom handler that supports history and signal.
:type handler: LeapLogHandler.
"""
- from twisted.internet import reactor
- self.reactor = reactor
-
QtGui.QDialog.__init__(self)
leap_assert(handler, "We need a handler for the logger window")
leap_assert_type(handler, LeapLogHandler)
@@ -67,6 +66,9 @@ class LoggerWindow(QtGui.QDialog):
self.ui.cbCaseInsensitive.stateChanged.connect(self._load_history)
self.ui.btnPastebin.clicked.connect(self._pastebin_this)
+ self._paste_ok.connect(self._pastebin_ok)
+ self._paste_error.connect(self._pastebin_err)
+
self._current_filter = ""
self._current_history = ""
@@ -193,6 +195,45 @@ class LoggerWindow(QtGui.QDialog):
self.ui.btnPastebin.setText(self.tr("Send to Pastebin.com"))
self.ui.btnPastebin.setEnabled(True)
+ def _pastebin_ok(self, link):
+ """
+ Handle a successful paste.
+
+ :param link: the recently created pastebin link.
+ :type link: str
+ """
+ self._set_pastebin_sending(False)
+ msg = self.tr("Your pastebin link <a href='{0}'>{0}</a>")
+ msg = msg.format(link)
+
+ # We save the dialog in an instance member to avoid dialog being
+ # deleted right after we exit this method
+ self._msgBox = msgBox = QtGui.QMessageBox(
+ QtGui.QMessageBox.Information, self.tr("Pastebin OK"), msg)
+ msgBox.setWindowModality(QtCore.Qt.NonModal)
+ msgBox.show()
+
+ def _pastebin_err(self, failure):
+ """
+ Handle a failure in paste.
+
+ :param failure: the exception that made the paste fail.
+ :type failure: Exception
+ """
+ self._set_pastebin_sending(False)
+ logger.error(repr(failure))
+
+ msg = self.tr("Sending logs to Pastebin failed!")
+ if isinstance(failure, pastebin.PostLimitError):
+ msg = self.tr('Maximum posts per day reached')
+
+ # We save the dialog in an instance member to avoid dialog being
+ # deleted right after we exit this method
+ self._msgBox = msgBox = QtGui.QMessageBox(
+ QtGui.QMessageBox.Critical, self.tr("Pastebin Error"), msg)
+ msgBox.setWindowModality(QtCore.Qt.NonModal)
+ msgBox.show()
+
def _pastebin_this(self):
"""
Send the current log history to pastebin.com and gives the user a link
@@ -204,55 +245,19 @@ class LoggerWindow(QtGui.QDialog):
"""
content = self._current_history
pb = pastebin.PastebinAPI()
- link = pb.paste(PASTEBIN_API_DEV_KEY, content,
- paste_name="Bitmask log",
- paste_expire_date='1M')
-
- # convert to 'raw' link
- link = "http://pastebin.com/raw.php?i=" + link.split('/')[-1]
-
- return link
-
- def pastebin_ok(link):
- """
- Callback handler for `do_pastebin`.
-
- :param link: the recently created pastebin link.
- :type link: str
- """
- self._set_pastebin_sending(False)
- msg = self.tr("Your pastebin link <a href='{0}'>{0}</a>")
- msg = msg.format(link)
-
- # We save the dialog in an instance member to avoid dialog being
- # deleted right after we exit this method
- self._msgBox = msgBox = QtGui.QMessageBox(
- QtGui.QMessageBox.Information, self.tr("Pastebin OK"), msg)
- msgBox.setWindowModality(QtCore.Qt.NonModal)
- msgBox.show()
-
- def pastebin_err(failure):
- """
- Errback handler for `do_pastebin`.
-
- :param failure: the failure that triggered the errback.
- :type failure: twisted.python.failure.Failure
- """
- self._set_pastebin_sending(False)
- logger.error(repr(failure))
-
- msg = self.tr("Sending logs to Pastebin failed!")
- if failure.check(pastebin.PostLimitError):
- msg = self.tr('Maximum posts per day reached')
+ try:
+ link = pb.paste(PASTEBIN_API_DEV_KEY, content,
+ paste_name="Bitmask log",
+ paste_expire_date='1M')
+ # convert to 'raw' link
+ link = "http://pastebin.com/raw.php?i=" + link.split('/')[-1]
- # We save the dialog in an instance member to avoid dialog being
- # deleted right after we exit this method
- self._msgBox = msgBox = QtGui.QMessageBox(
- QtGui.QMessageBox.Critical, self.tr("Pastebin Error"), msg)
- msgBox.setWindowModality(QtCore.Qt.NonModal)
- msgBox.show()
+ self._paste_ok.emit(link)
+ except Exception as e:
+ self._paste_error.emit(e)
self._set_pastebin_sending(True)
- d = threads.deferToThread(do_pastebin)
- d.addCallback(pastebin_ok)
- d.addErrback(pastebin_err)
+
+ self._paste_thread = QtCore.QThread()
+ self._paste_thread.run = lambda: do_pastebin()
+ self._paste_thread.start()