Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mining: add buttons/mouse scroll to CPU threads; improve button labels; set "Start mining" button as primary #3742

Merged
merged 1 commit into from
Nov 27, 2021

Conversation

rating89us
Copy link
Contributor

image

pages/Mining.qml Outdated Show resolved Hide resolved
Copy link
Collaborator

@selsta selsta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diff --git a/pages/Mining.qml b/pages/Mining.qml
index 78a31854..42b54721 100644
--- a/pages/Mining.qml
+++ b/pages/Mining.qml
@@ -37,6 +37,7 @@ Rectangle {
     color: "transparent"
     property alias miningHeight: mainLayout.height
     property double currentHashRate: 0
+    property int threads: idealThreadCount / 2
 
     ColumnLayout {
         id: mainLayout
@@ -111,19 +112,16 @@ Rectangle {
                         id: removeThreadButton
                         small: true
                         primary: false
-                        text: qsTr("-") + translationManager.emptyString
-                        enabled: soloMinerThreadsLine.text > 1
-                        onClicked: {
-                                soloMinerThreadsLine.text = Number(soloMinerThreadsLine.text) - 1
-                        }
+                        text: qsTr("−") + translationManager.emptyString
+                        enabled: threads > 1
+                        onClicked: threads--
                     }
 
                     MoneroComponents.TextPlain {
-                        id: soloMinerThreadsLine
                         Layout.bottomMargin: 1
                         Layout.minimumWidth: 45
                         color: MoneroComponents.Style.defaultFontColor
-                        text: idealThreadCount / 2
+                        text: threads
                         horizontalAlignment: Text.AlignHCenter
                         font.pixelSize: 16
 
@@ -131,11 +129,10 @@ Rectangle {
                             anchors.fill: parent
                             scrollGestureEnabled: false
                             onWheel: {
-                                if (wheel.angleDelta.y > 0 && Number(soloMinerThreadsLine.text) < idealThreadCount) {
-                                    return soloMinerThreadsLine.text = Number(soloMinerThreadsLine.text) + 1
-                                }
-                                else if (wheel.angleDelta.y < 0 && Number(soloMinerThreadsLine.text) > 1) {
-                                    return soloMinerThreadsLine.text = Number(soloMinerThreadsLine.text) - 1
+                                if (wheel.angleDelta.y > 0 && threads < idealThreadCount) {
+                                    return threads++
+                                } else if (wheel.angleDelta.y < 0 && threads > 1) {
+                                    return threads--
                                 }
                             }
                         }
@@ -146,9 +143,9 @@ Rectangle {
                         small: true
                         primary: false
                         text: qsTr("+") + translationManager.emptyString
-                        enabled: soloMinerThreadsLine.text < idealThreadCount
+                        enabled: threads < idealThreadCount
                         onClicked: {
-                            soloMinerThreadsLine.text = Number(soloMinerThreadsLine.text) + 1
+                            threads++
                         }
                     }
                 }
@@ -161,7 +158,7 @@ Rectangle {
                         text: qsTr("Use half (recommended)") +  translationManager.emptyString
                         enabled: startSoloMinerButton.enabled
                         onClicked: {
-                                soloMinerThreadsLine.text = Math.floor(idealThreadCount / 2);
+                                threads = idealThreadCount / 2
                                 appWindow.showStatusMessage(qsTr("Set to use recommended # of threads"),3)
                         }
                     }
@@ -173,7 +170,7 @@ Rectangle {
                         text: qsTr("Use all threads") + " (" + idealThreadCount + ")" + translationManager.emptyString
                         enabled: startSoloMinerButton.enabled
                         onClicked: {
-                            soloMinerThreadsLine.text = idealThreadCount
+                            threads = idealThreadCount
                             appWindow.showStatusMessage(qsTr("Set to use all threads") + translationManager.emptyString,3)
                         }
                     }
@@ -215,7 +212,7 @@ Rectangle {
                         id: backgroundMining
                         enabled: startSoloMinerButton.enabled
                         checked: persistentSettings.allow_background_mining
-                        onClicked: {persistentSettings.allow_background_mining = checked}
+                        onClicked: persistentSettings.allow_background_mining = checked
                         text: qsTr("Background mining (experimental)") + translationManager.emptyString
                     }
                 }
@@ -246,7 +243,7 @@ Rectangle {
                         primary: !stopSoloMinerButton.enabled
                         text: qsTr("Start mining") + translationManager.emptyString
                         onClicked: {
-                            var success = walletManager.startMining(appWindow.currentWallet.address(0, 0), soloMinerThreadsLine.text, persistentSettings.allow_background_mining, persistentSettings.miningIgnoreBattery)
+                            var success = walletManager.startMining(appWindow.currentWallet.address(0, 0), threads, persistentSettings.allow_background_mining, persistentSettings.miningIgnoreBattery)
                             if (success) {
                                 update()
                             } else {

I would recommend to use a property int for the threadCount. Otherwise you keep using strings for numbers, which isn't nice.

pages/Mining.qml Outdated Show resolved Hide resolved
pages/Mining.qml Outdated Show resolved Hide resolved
@luigi1111 luigi1111 merged commit 917d6d4 into monero-project:master Nov 27, 2021
@rating89us rating89us deleted the patch-117 branch November 30, 2021 02:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants