1
0

qml: add LabelSync toggle

This commit is contained in:
Sander van Grieken
2023-07-11 12:51:37 +02:00
parent bb8c73cabd
commit b6863b4854
7 changed files with 68 additions and 24 deletions

View File

@@ -41,6 +41,7 @@ class ElectrumTranslator(QTranslator):
def translate(self, context, source_text, disambiguation, n):
return _(source_text, context=context)
class ElectrumGui(BaseElectrumGui, Logger):
@profiler
@@ -91,7 +92,7 @@ class ElectrumGui(BaseElectrumGui, Logger):
Exception_Hook.maybe_setup(config=config, slot=self.app.appController.crash)
# Initialize any QML plugins
run_hook('init_qml', self)
run_hook('init_qml', self.app)
self.app.engine.load('electrum/gui/qml/components/main.qml')
def close(self):

View File

@@ -217,6 +217,25 @@ Pane {
}
}
RowLayout {
Layout.columnSpan: 2
Layout.fillWidth: true
Layout.leftMargin: -constants.paddingSmall
spacing: 0
Switch {
id: syncLabels
onCheckedChanged: {
if (activeFocus)
AppController.setPluginEnabled('labels', checked)
}
}
Label {
Layout.fillWidth: true
text: qsTr('Synchronize labels')
wrapMode: Text.Wrap
}
}
PrefsHeading {
Layout.columnSpan: 2
text: qsTr('Wallet behavior')
@@ -384,5 +403,6 @@ Pane {
useFallbackAddress.checked = Config.useFallbackAddress
enableDebugLogs.checked = Config.enableDebugLogs
useRecoverableChannels.checked = Config.useRecoverableChannels
syncLabels.checked = AppController.isPluginEnabled('labels')
}
}

View File

@@ -19,6 +19,7 @@ from electrum.logging import Logger, get_logger
from electrum.bip21 import BITCOIN_BIP21_URI_SCHEME, LIGHTNING_URI_SCHEME
from electrum.base_crash_reporter import BaseCrashReporter, EarlyExceptionsQueue
from electrum.network import Network
from electrum.plugin import run_hook
from .qeconfig import QEConfig
from .qedaemon import QEDaemon
@@ -70,10 +71,11 @@ class QEAppController(BaseCrashReporter, QObject):
sendingBugreportFailure = pyqtSignal(str)
secureWindowChanged = pyqtSignal()
def __init__(self, qedaemon: 'QEDaemon', plugins: 'Plugins'):
def __init__(self, qeapp: 'ElectrumQmlApplication', qedaemon: 'QEDaemon', plugins: 'Plugins'):
BaseCrashReporter.__init__(self, None, None, None)
QObject.__init__(self)
self._app = qeapp
self._qedaemon = qedaemon
self._plugins = plugins
self.config = qedaemon.daemon.config
@@ -224,12 +226,18 @@ class QEAppController(BaseCrashReporter, QObject):
return s
@pyqtSlot(str, bool)
def setPluginEnabled(self, plugin, enabled):
def setPluginEnabled(self, plugin: str, enabled: bool):
if enabled:
self._plugins.enable(plugin)
# note: all enabled plugins will receive this hook:
run_hook('init_qml', self._app)
else:
self._plugins.disable(plugin)
@pyqtSlot(str, result=bool)
def isPluginEnabled(self, plugin: str):
return bool(self._plugins.get(plugin))
@pyqtSlot(result=bool)
def isAndroid(self):
return 'ANDROID_DATA' in os.environ
@@ -369,7 +377,7 @@ class ElectrumQmlApplication(QGuiApplication):
self._qeconfig = QEConfig(config)
self._qenetwork = QENetwork(daemon.network, self._qeconfig)
self.daemon = QEDaemon(daemon)
self.appController = QEAppController(self.daemon, self.plugins)
self.appController = QEAppController(self, self.daemon, self.plugins)
self._maxAmount = QEAmount(is_max=True)
self.context.setContextProperty('AppController', self.appController)
self.context.setContextProperty('Config', self._qeconfig)