Merge pull request #1492 from ctrlcctrlv/uncopyable-seed

Make seed uncopyable
This commit is contained in:
ThomasV 2015-10-31 10:59:19 +01:00
commit b1ab49a282
3 changed files with 25 additions and 8 deletions

View File

@ -416,7 +416,7 @@ class InstallWizard(QDialog):
return True return True
def show_seed(self, seed, sid): def show_seed(self, seed, sid):
vbox = seed_dialog.show_seed_box_msg(seed, sid) vbox = seed_dialog.show_seed_box_msg(seed, sid, paranoid=True)
vbox.addLayout(Buttons(CancelButton(self), OkButton(self, _("Next")))) vbox.addLayout(Buttons(CancelButton(self), OkButton(self, _("Next"))))
self.set_layout(vbox) self.set_layout(vbox)
return self.exec_() return self.exec_()

View File

@ -8,10 +8,26 @@ from util import ButtonsTextEdit
class ShowQRTextEdit(ButtonsTextEdit): class ShowQRTextEdit(ButtonsTextEdit):
def __init__(self, text=None): def __init__(self, text=None, paranoid=False):
ButtonsTextEdit.__init__(self, text) ButtonsTextEdit.__init__(self, text)
self.setReadOnly(1) self.setReadOnly(1)
self.addButton(":icons/qrcode.png", self.qr_show, _("Show as QR code")) self.addButton(":icons/qrcode.png", self.qr_show, _("Show as QR code"))
self.paranoid = paranoid
if paranoid:
# Paranoid flag forces the user to write down what's in the box,
# like Mycelium does. This is useful since many users just copy
# and paste their code, then when disaster strikes they don't have
# it written down anywhere.
self.setAcceptDrops(False) # No dragging and dropping
# Use custom context menu to remove copy/paste from menu
self.setContextMenuPolicy(Qt.ActionsContextMenu)
self.qaction = QAction(_("Show as QR code"), self)
self.qaction.triggered.connect(self.qr_show)
self.addAction(self.qaction)
# No text selection allowed.
self.setTextInteractionFlags(Qt.NoTextInteraction)
run_hook('show_text_edit', self) run_hook('show_text_edit', self)
def qr_show(self): def qr_show(self):
@ -23,6 +39,7 @@ class ShowQRTextEdit(ButtonsTextEdit):
QRDialog(s).exec_() QRDialog(s).exec_()
def contextMenuEvent(self, e): def contextMenuEvent(self, e):
if self.paranoid: return
m = self.createStandardContextMenu() m = self.createStandardContextMenu()
m.addAction(_("Show as QR code"), self.qr_show) m.addAction(_("Show as QR code"), self.qr_show)
m.exec_(e.globalPos()) m.exec_(e.globalPos())

View File

@ -47,9 +47,9 @@ def icon_filename(sid):
return ":icons/seed.png" return ":icons/seed.png"
def show_seed_box_msg(seedphrase, sid=None): def show_seed_box_msg(seedphrase, sid=None, paranoid=False):
msg = _("Your wallet generation seed is") + ":" msg = _("Your wallet generation seed is") + ":"
vbox = show_seed_box(msg, seedphrase, sid) vbox = show_seed_box(msg, seedphrase, sid, paranoid=paranoid)
save_msg = _("Please save these %d words on paper (order is important).")%len(seedphrase.split()) + " " save_msg = _("Please save these %d words on paper (order is important).")%len(seedphrase.split()) + " "
msg2 = save_msg + " " \ msg2 = save_msg + " " \
+ _("This seed will allow you to recover your wallet in case of computer failure.") + "<br/>" \ + _("This seed will allow you to recover your wallet in case of computer failure.") + "<br/>" \
@ -60,11 +60,11 @@ def show_seed_box_msg(seedphrase, sid=None):
vbox.addStretch(1) vbox.addStretch(1)
return vbox return vbox
def show_seed_box(msg, seed, sid): def show_seed_box(msg, seed, sid, paranoid=False):
vbox, seed_e = enter_seed_box(msg, None, sid=sid, text=seed) vbox, seed_e = enter_seed_box(msg, None, sid=sid, text=seed, paranoid=paranoid)
return vbox return vbox
def enter_seed_box(msg, window, sid=None, text=None): def enter_seed_box(msg, window, sid=None, text=None, paranoid=False):
vbox = QVBoxLayout() vbox = QVBoxLayout()
logo = QLabel() logo = QLabel()
logo.setPixmap(QPixmap(icon_filename(sid)).scaledToWidth(56)) logo.setPixmap(QPixmap(icon_filename(sid)).scaledToWidth(56))
@ -75,7 +75,7 @@ def enter_seed_box(msg, window, sid=None, text=None):
seed_e = ScanQRTextEdit() seed_e = ScanQRTextEdit()
seed_e.setTabChangesFocus(True) seed_e.setTabChangesFocus(True)
else: else:
seed_e = ShowQRTextEdit(text=text) seed_e = ShowQRTextEdit(text=text, paranoid=paranoid)
seed_e.setMaximumHeight(130) seed_e.setMaximumHeight(130)
vbox.addWidget(label) vbox.addWidget(label)
grid = QGridLayout() grid = QGridLayout()