From 223f09dc94b72b9f56fab7f809e0763b852ae462 Mon Sep 17 00:00:00 2001 From: Jaquee Date: Thu, 2 Mar 2017 15:44:37 +0100 Subject: [PATCH] preparations for background mining requires #1827 --- main.cpp | 5 ++++ main.qml | 3 ++- pages/Mining.qml | 41 ++++++++++++++++++++++++++++++- src/libwalletqt/WalletManager.cpp | 4 +-- src/libwalletqt/WalletManager.h | 2 +- 5 files changed, 50 insertions(+), 5 deletions(-) diff --git a/main.cpp b/main.cpp index 53ab4752..5b05cd1f 100644 --- a/main.cpp +++ b/main.cpp @@ -159,6 +159,7 @@ int main(int argc, char *argv[]) // Windows, ~/Monero Accounts/ on nix / osx bool isWindows = false; bool isIOS = false; + bool isMac = false; #ifdef Q_OS_WIN isWindows = true; QStringList moneroAccountsRootDir = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation); @@ -168,6 +169,10 @@ int main(int argc, char *argv[]) #elif defined(Q_OS_UNIX) QStringList moneroAccountsRootDir = QStandardPaths::standardLocations(QStandardPaths::HomeLocation); #endif +#ifdef Q_OS_MAC + isMac = true; +#endif + engine.rootContext()->setContextProperty("isWindows", isWindows); engine.rootContext()->setContextProperty("isIOS", isIOS); diff --git a/main.qml b/main.qml index 2713fb23..aa2dd41a 100644 --- a/main.qml +++ b/main.qml @@ -818,6 +818,7 @@ ApplicationWindow { property bool auto_donations_enabled : false property int auto_donations_amount : 50 property bool allow_background_mining : false + property bool miningIgnoreBattery : true property bool testnet: false property string daemon_address: "localhost:18081" property string payment_id @@ -857,7 +858,7 @@ ApplicationWindow { return; } else handleTransactionConfirmed() - } + } } StandardDialog { diff --git a/pages/Mining.qml b/pages/Mining.qml index 03fbfce8..12cef72b 100644 --- a/pages/Mining.qml +++ b/pages/Mining.qml @@ -64,6 +64,7 @@ Rectangle { anchors.left: parent.left anchors.right: parent.right anchors.top: parent.top + spacing: 20 Label { id: soloTitleLabel @@ -97,6 +98,7 @@ Rectangle { color: "#4A4949" text: qsTr("CPU threads") + translationManager.emptyString fontSize: 16 + Layout.preferredWidth: 120 } LineEdit { id: soloMinerThreadsLine @@ -108,6 +110,43 @@ Rectangle { } RowLayout { + // Disable this option until stable + visible: false + Layout.leftMargin: 125 + CheckBox { + id: backgroundMining + enabled: startSoloMinerButton.enabled + checked: persistentSettings.allow_background_mining + onClicked: {persistentSettings.allow_background_mining = checked} + text: qsTr("Background mining (experimental)") + translationManager.emptyString + checkedIcon: "../images/checkedVioletIcon.png" + uncheckedIcon: "../images/uncheckedIcon.png" + } + + } + + RowLayout { + // Disable this option until stable + visible: false + Layout.leftMargin: 125 + CheckBox { + id: ignoreBattery + enabled: startSoloMinerButton.enabled + checked: !persistentSettings.miningIgnoreBattery + onClicked: {persistentSettings.miningIgnoreBattery = !checked} + text: qsTr("Enable mining when running on battery") + translationManager.emptyString + checkedIcon: "../images/checkedVioletIcon.png" + uncheckedIcon: "../images/uncheckedIcon.png" + } + } + + RowLayout { + Label { + id: manageSoloMinerLabel + color: "#4A4949" + text: qsTr("Manage miner") + translationManager.emptyString + fontSize: 16 + } StandardButton { visible: true @@ -120,7 +159,7 @@ Rectangle { releasedColor: "#FF6C3C" pressedColor: "#FF4304" onClicked: { - var success = walletManager.startMining(appWindow.currentWallet.address, soloMinerThreadsLine.text) + var success = walletManager.startMining(appWindow.currentWallet.address, soloMinerThreadsLine.text, persistentSettings.allow_background_mining, persistentSettings.miningIgnoreBattery) if (success) { update() } else { diff --git a/src/libwalletqt/WalletManager.cpp b/src/libwalletqt/WalletManager.cpp index b6a736e1..ad77ad48 100644 --- a/src/libwalletqt/WalletManager.cpp +++ b/src/libwalletqt/WalletManager.cpp @@ -262,11 +262,11 @@ bool WalletManager::isMining() const return m_pimpl->isMining(); } -bool WalletManager::startMining(const QString &address, quint32 threads) +bool WalletManager::startMining(const QString &address, quint32 threads, bool backgroundMining, bool ignoreBattery) { if(threads == 0) threads = 1; - return m_pimpl->startMining(address.toStdString(), threads); + return m_pimpl->startMining(address.toStdString(), threads, backgroundMining, ignoreBattery); } bool WalletManager::stopMining() diff --git a/src/libwalletqt/WalletManager.h b/src/libwalletqt/WalletManager.h index bb55c587..01afc064 100644 --- a/src/libwalletqt/WalletManager.h +++ b/src/libwalletqt/WalletManager.h @@ -114,7 +114,7 @@ public: Q_INVOKABLE double miningHashRate() const; Q_INVOKABLE bool isMining() const; - Q_INVOKABLE bool startMining(const QString &address, quint32 threads); + Q_INVOKABLE bool startMining(const QString &address, quint32 threads, bool backgroundMining, bool ignoreBattery); Q_INVOKABLE bool stopMining(); // QML missing such functionality, implementing these helpers here