]> Nutra Git (v2) - gamesguru/feather.git/commitdiff
wizard: fix lookahead validation
authortobtoht <tob@featherwallet.org>
Sun, 29 Sep 2024 19:58:40 +0000 (21:58 +0200)
committertobtoht <tob@featherwallet.org>
Sun, 29 Sep 2024 20:01:04 +0000 (22:01 +0200)
src/wizard/PageSetSubaddressLookahead.cpp
src/wizard/PageSetSubaddressLookahead.h
src/wizard/PageSetSubaddressLookahead.ui

index c6c896a943d8488da520b289e075d2da8bb1ebb7..6d9e05b4bf911ad3b4e9fb65ff4ae7cabafab91c 100644 (file)
@@ -5,7 +5,9 @@
 #include "ui_PageSetSubaddressLookahead.h"
 #include "WalletWizard.h"
 
-#include <QIntValidator>
+#include <QRegularExpressionValidator>
+
+#include "Icons.h"
 
 PageSetSubaddressLookahead::PageSetSubaddressLookahead(WizardFields *fields, QWidget *parent)
         : QWizardPage(parent)
@@ -14,11 +16,19 @@ PageSetSubaddressLookahead::PageSetSubaddressLookahead(WizardFields *fields, QWi
 {
     ui->setupUi(this);
 
-    // uint32_t can go up to 4294967294, but this isn't realistic
-    auto indexValidator = new QIntValidator(1, 2147483647, this);
+    auto *indexValidator = new QRegularExpressionValidator{QRegularExpression("[0-9]{0,5}")};
 
     ui->line_major->setValidator(indexValidator);
+    connect(ui->line_major, &QLineEdit::textChanged, [this]{
+        this->completeChanged();
+    });
+
     ui->line_minor->setValidator(indexValidator);
+    connect(ui->line_major, &QLineEdit::textChanged, [this]{
+        this->completeChanged();
+    });
+
+    ui->infoFrame->setInfo(icons()->icon("warning"), "Lookahead must be non-zero.");
 
     this->setTitle("Subaddress Lookahead");
 }
@@ -31,6 +41,7 @@ void PageSetSubaddressLookahead::initializePage() {
         ui->line_major->setText("50");
         ui->line_minor->setText("200");
     }
+    ui->infoFrame->hide();
 }
 
 bool PageSetSubaddressLookahead::validatePage() {
@@ -40,4 +51,19 @@ bool PageSetSubaddressLookahead::validatePage() {
 
 int PageSetSubaddressLookahead::nextId() const {
     return WalletWizard::Page_WalletFile;
-}
\ No newline at end of file
+}
+
+bool PageSetSubaddressLookahead::isComplete() const {
+    ui->infoFrame->hide();
+
+    if (ui->line_major->text().isEmpty() || ui->line_major->text().toInt() == 0) {
+       ui->infoFrame->show();
+       return false;
+   }
+   if (ui->line_minor->text().isEmpty() || ui->line_minor->text().toInt() == 0) {
+       ui->infoFrame->show();
+       return false;
+   }
+
+   return true;
+}
index 04fb4c392f735ac8a20af51120027925a4b52a56..fc7a6d380d9326bbb6293f5ffe2ce520a9d995b2 100644 (file)
@@ -22,6 +22,7 @@ public:
     void initializePage() override;
     bool validatePage() override;
     int nextId() const override;
+    bool isComplete() const override;
 
 private:
     Ui::PageSetSubaddressLookahead *ui;
index 6fd4d8f4830dd2fc1b5637ef2b4ac4efbe248b33..b724fe32b1a880e76c08dff0acc0a5497124e24b 100644 (file)
@@ -23,6 +23,9 @@
        </property>
       </widget>
      </item>
+     <item row="0" column="1">
+      <widget class="QLineEdit" name="line_major"/>
+     </item>
      <item row="1" column="0">
       <widget class="QLabel" name="label_2">
        <property name="text">
        </property>
       </widget>
      </item>
-     <item row="0" column="1">
-      <widget class="QLineEdit" name="line_major"/>
-     </item>
      <item row="1" column="1">
       <widget class="QLineEdit" name="line_minor"/>
      </item>
     </layout>
    </item>
+   <item>
+    <widget class="InfoFrame" name="infoFrame">
+     <property name="frameShape">
+      <enum>QFrame::StyledPanel</enum>
+     </property>
+     <property name="frameShadow">
+      <enum>QFrame::Raised</enum>
+     </property>
+    </widget>
+   </item>
   </layout>
  </widget>
+ <customwidgets>
+  <customwidget>
+   <class>InfoFrame</class>
+   <extends>QFrame</extends>
+   <header>components.h</header>
+   <container>1</container>
+  </customwidget>
+ </customwidgets>
  <resources/>
  <connections/>
 </ui>