summaryrefslogtreecommitdiff
path: root/onionshare_gui
diff options
context:
space:
mode:
authorMiguel Jacq <mig@mig5.net>2020-05-31 17:44:57 +1000
committerMiguel Jacq <mig@mig5.net>2020-05-31 17:44:57 +1000
commit4cf508ed8e05fc38762ca49942d3a83a3d8123f5 (patch)
tree7915ab91c68b8802c4ba5100693629173cc47eef /onionshare_gui
parent1c424500f0b0e1e2bb7b17ce144cce16e20e5493 (diff)
downloadonionshare-4cf508ed8e05fc38762ca49942d3a83a3d8123f5.tar.gz
onionshare-4cf508ed8e05fc38762ca49942d3a83a3d8123f5.zip
#1115 Add QR Code for onion URL
Diffstat (limited to 'onionshare_gui')
-rw-r--r--onionshare_gui/tab/server_status.py20
-rw-r--r--onionshare_gui/widgets.py60
2 files changed, 78 insertions, 2 deletions
diff --git a/onionshare_gui/tab/server_status.py b/onionshare_gui/tab/server_status.py
index 0fbc11b6..10d45bcc 100644
--- a/onionshare_gui/tab/server_status.py
+++ b/onionshare_gui/tab/server_status.py
@@ -24,7 +24,8 @@ from PyQt5 import QtCore, QtWidgets, QtGui
from onionshare import strings
from ..widgets import Alert
-
+from ..widgets import Image
+from ..widgets import QRCodeDialog
class ServerStatus(QtWidgets.QWidget):
"""
@@ -96,6 +97,14 @@ class ServerStatus(QtWidgets.QWidget):
self.copy_hidservauth_button = QtWidgets.QPushButton(
strings._("gui_copy_hidservauth")
)
+ self.show_url_qr_code_button = QtWidgets.QPushButton(strings._("gui_show_url_qr_code"))
+ self.show_url_qr_code_button.hide()
+ self.show_url_qr_code_button.clicked.connect(self.show_url_qr_code_button_clicked)
+ self.show_url_qr_code_button.setFlat(True)
+ self.show_url_qr_code_button.setStyleSheet(
+ self.common.gui.css["server_status_url_buttons"]
+ )
+
self.copy_hidservauth_button.setFlat(True)
self.copy_hidservauth_button.setStyleSheet(
self.common.gui.css["server_status_url_buttons"]
@@ -103,6 +112,7 @@ class ServerStatus(QtWidgets.QWidget):
self.copy_hidservauth_button.clicked.connect(self.copy_hidservauth)
url_buttons_layout = QtWidgets.QHBoxLayout()
url_buttons_layout.addWidget(self.copy_url_button)
+ url_buttons_layout.addWidget(self.show_url_qr_code_button)
url_buttons_layout.addWidget(self.copy_hidservauth_button)
url_buttons_layout.addStretch()
@@ -190,6 +200,8 @@ class ServerStatus(QtWidgets.QWidget):
self.url.show()
self.copy_url_button.show()
+ self.show_url_qr_code_button.show()
+
if self.settings.get("general", "client_auth"):
self.copy_hidservauth_button.show()
else:
@@ -364,6 +376,12 @@ class ServerStatus(QtWidgets.QWidget):
self.cancel_server()
self.button_clicked.emit()
+ def show_url_qr_code_button_clicked(self):
+ """
+ Show a QR code of the onion URL.
+ """
+ self.qr_code_dialog = QRCodeDialog(self.common, self.get_url())
+
def start_server(self):
"""
Start the server.
diff --git a/onionshare_gui/widgets.py b/onionshare_gui/widgets.py
index 74ef2c88..3b1180b3 100644
--- a/onionshare_gui/widgets.py
+++ b/onionshare_gui/widgets.py
@@ -18,7 +18,8 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
from PyQt5 import QtCore, QtWidgets, QtGui
-
+from onionshare import strings
+import qrcode
class Alert(QtWidgets.QMessageBox):
"""
@@ -90,3 +91,60 @@ class MinimumWidthWidget(QtWidgets.QWidget):
super(MinimumWidthWidget, self).__init__()
self.setMinimumWidth(width)
+
+class Image(qrcode.image.base.BaseImage):
+ def __init__(self, border, width, box_size):
+ self.border = border
+ self.width = width
+ self.box_size = box_size
+ size = (width + border * 2) * box_size
+ self._image = QtGui.QImage(
+ size, size, QtGui.QImage.Format_RGB16)
+ self._image.fill(QtCore.Qt.white)
+
+ def pixmap(self):
+ return QtGui.QPixmap.fromImage(self._image)
+
+ def drawrect(self, row, col):
+ painter = QtGui.QPainter(self._image)
+ painter.fillRect(
+ (col + self.border) * self.box_size,
+ (row + self.border) * self.box_size,
+ self.box_size, self.box_size,
+ QtCore.Qt.black)
+
+ def save(self, stream, kind=None):
+ pass
+
+
+class QRCodeDialog(QtWidgets.QDialog):
+ """
+ A dialog showing a QR code.
+ """
+
+ def __init__(self, common, text):
+ super(QRCodeDialog, self).__init__()
+
+ self.common = common
+ self.text = text
+
+ self.common.log("QrCode", "__init__")
+
+ self.qr_label = QtWidgets.QLabel(self)
+ self.qr_label.setPixmap(
+ qrcode.make(self.text, image_factory=Image).pixmap())
+
+ self.qr_label_description = QtWidgets.QLabel(self)
+ self.qr_label_description.setText(strings._("gui_qr_code_description"))
+ self.qr_label_description.setWordWrap(True)
+
+ self.setWindowTitle(strings._("gui_qr_code_dialog_title"))
+ self.setWindowIcon(
+ QtGui.QIcon(self.common.get_resource_path("images/logo.png"))
+ )
+ layout = QtWidgets.QVBoxLayout(self)
+ layout.addWidget(self.qr_label)
+ layout.addWidget(self.qr_label_description)
+
+ self.exec_()
+