commit 182c192558085adc665c5073f12d842b8e7b7ffa
parent 12e2beadd9ed51faae0035f12f22f7176054205f
Author: SomberNight <somber.night@protonmail.com>
Date: Fri, 19 Jun 2020 04:48:20 +0200
qt: easier import/export of channel backups
Diffstat:
4 files changed, 42 insertions(+), 11 deletions(-)
diff --git a/electrum/gui/kivy/uix/dialogs/lightning_channels.py b/electrum/gui/kivy/uix/dialogs/lightning_channels.py
@@ -9,6 +9,7 @@ from kivy.clock import Clock
from electrum.util import bh2u
from electrum.lnutil import LOCAL, REMOTE, format_short_channel_id
+from electrum.lnchannel import AbstractChannel, Channel
from electrum.gui.kivy.i18n import _
from .question import Question
@@ -285,7 +286,7 @@ Builder.load_string(r'''
class ChannelBackupPopup(Popup):
- def __init__(self, chan, app, **kwargs):
+ def __init__(self, chan: AbstractChannel, app: 'ElectrumWindow', **kwargs):
super(ChannelBackupPopup,self).__init__(**kwargs)
self.chan = chan
self.app = app
@@ -320,7 +321,7 @@ class ChannelBackupPopup(Popup):
class ChannelDetailsPopup(Popup):
- def __init__(self, chan, app, **kwargs):
+ def __init__(self, chan: Channel, app: 'ElectrumWindow', **kwargs):
super(ChannelDetailsPopup,self).__init__(**kwargs)
self.is_closed = chan.is_closed()
self.is_redeemed = chan.is_redeemed()
diff --git a/electrum/gui/qt/channels_list.py b/electrum/gui/qt/channels_list.py
@@ -132,7 +132,8 @@ class ChannelsList(MyTreeView):
_("If you lose your wallet file, the only thing you can do with a backup is to request your channel to be closed, so that your funds will be sent on-chain."),
])
data = self.lnworker.export_channel_backup(channel_id)
- self.main_window.show_qrcode(data, 'channel backup', help_text=msg)
+ self.main_window.show_qrcode(data, 'channel backup', help_text=msg,
+ show_copy_text_btn=True)
def request_force_close(self, channel_id):
def task():
@@ -147,6 +148,8 @@ class ChannelsList(MyTreeView):
menu.setSeparatorsCollapsible(True) # consecutive separators are merged together
selected = self.selected_in_column(self.Columns.NODE_ALIAS)
if not selected:
+ menu.addAction(_("Import channel backup"), lambda: self.parent.do_process_from_text_channel_backup())
+ menu.exec_(self.viewport().mapToGlobal(position))
return
multi_select = len(selected) > 1
if multi_select:
diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py
@@ -585,7 +585,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
def select_backup_dir(self, b):
name = self.config.get('backup_dir', '')
- dirname = QFileDialog.getExistingDirectory(self, "Select your SSL certificate file", name)
+ dirname = QFileDialog.getExistingDirectory(self, "Select your wallet backup directory", name)
if dirname:
self.config.set_key('backup_dir', dirname)
self.backup_dir_e.setText(dirname)
@@ -2395,10 +2395,12 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
d = SeedDialog(self, seed, passphrase)
d.exec_()
- def show_qrcode(self, data, title = _("QR code"), parent=None, help_text=None):
+ def show_qrcode(self, data, title = _("QR code"), parent=None, *,
+ help_text=None, show_copy_text_btn=False):
if not data:
return
- d = QRDialog(data, parent or self, title, help_text=help_text)
+ d = QRDialog(data, parent or self, title, help_text=help_text,
+ show_copy_text_btn=show_copy_text_btn)
d.exec_()
@protected
@@ -2605,7 +2607,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
self.show_critical(_("Electrum was unable to parse your transaction") + ":\n" + repr(e))
return
- def import_channel_backup(self, encrypted):
+ def import_channel_backup(self, encrypted: str):
if not self.question('Import channel backup?'):
return
try:
@@ -2658,6 +2660,13 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
if tx:
self.show_transaction(tx)
+ def do_process_from_text_channel_backup(self):
+ text = text_dialog(self, _('Input channel backup'), _("Channel Backup:"), _("Load backup"))
+ if not text:
+ return
+ if text.startswith('channel_backup:'):
+ self.import_channel_backup(text)
+
def do_process_from_file(self):
tx = self.read_tx_from_file()
if tx:
diff --git a/electrum/gui/qt/qrcodewidget.py b/electrum/gui/qt/qrcodewidget.py
@@ -93,7 +93,16 @@ class QRCodeWidget(QWidget):
class QRDialog(WindowModalDialog):
- def __init__(self, data, parent=None, title = "", show_text=False, help_text=None):
+ def __init__(
+ self,
+ data,
+ parent=None,
+ title="",
+ show_text=False,
+ *,
+ help_text=None,
+ show_copy_text_btn=False,
+ ):
WindowModalDialog.__init__(self, parent, title)
vbox = QVBoxLayout()
@@ -119,14 +128,23 @@ class QRDialog(WindowModalDialog):
p.save(filename, 'png')
self.show_message(_("QR code saved to file") + " " + filename)
- def copy_to_clipboard():
+ def copy_image_to_clipboard():
p = qrw.grab()
QApplication.clipboard().setPixmap(p)
self.show_message(_("QR code copied to clipboard"))
- b = QPushButton(_("Copy"))
+ def copy_text_to_clipboard():
+ QApplication.clipboard().setText(data)
+ self.show_message(_("Text copied to clipboard"))
+
+ b = QPushButton(_("Copy Image"))
hbox.addWidget(b)
- b.clicked.connect(copy_to_clipboard)
+ b.clicked.connect(copy_image_to_clipboard)
+
+ if show_copy_text_btn:
+ b = QPushButton(_("Copy Text"))
+ hbox.addWidget(b)
+ b.clicked.connect(copy_text_to_clipboard)
b = QPushButton(_("Save"))
hbox.addWidget(b)