From 44e1c3779770441c6c4ae8d2639587ea6036e9bf Mon Sep 17 00:00:00 2001 From: nonlin-lin-chaos-order-etc-etal Date: Wed, 20 Nov 2024 10:28:25 +0800 Subject: [PATCH] Fix #103 --- src/i2pd | 2 +- src/mainwindow.cpp | 5 ++++- src/mainwindow.h | 21 +++++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/i2pd b/src/i2pd index 905c6de..d241e5d 160000 --- a/src/i2pd +++ b/src/i2pd @@ -1 +1 @@ -Subproject commit 905c6debf2a7f7e651a7916e646a2aee25ba57c7 +Subproject commit d241e5d5cbf7c78de7badf19608a164d355dbf54 diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 433630a..f88bf0c 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -306,7 +306,7 @@ MainWindow::MainWindow(std::shared_ptr logStream_, QWidget *paren initStringBox( OPTION("addressbook","defaulturl",[]{return "";}), uiSettings->addressbookDefaultURLLineEdit); initStringBox( OPTION("addressbook","subscriptions",[]{return "";}), uiSettings->addressbookSubscriptionsURLslineEdit); - initUInt16Box( OPTION("limits","transittunnels",[]{return "2500";}), uiSettings->maxNumOfTransitTunnelsLineEdit, tr("maxNumberOfTransitTunnels")); + initUIntBox( OPTION("limits","transittunnels",[]{return "2500";}), uiSettings->maxNumOfTransitTunnelsLineEdit, tr("maxNumberOfTransitTunnels")); initUInt16Box( OPTION("limits","openfiles",[]{return "0";}), uiSettings->maxNumOfOpenFilesLineEdit, tr("maxNumberOfOpenFiles")); initUInt32Box( OPTION("limits","coresize",[]{return "0";}), uiSettings->coreFileMaxSizeNumberLineEdit, tr("coreFileMaxSize")); @@ -709,6 +709,9 @@ void MainWindow::initCheckBox(ConfigOption option, QCheckBox* checkBox) { void MainWindow::initIntegerBox(ConfigOption option, QLineEdit* numberLineEdit, QString fieldNameTranslated){ configItems.append(new IntegerStringItem(option, numberLineEdit, fieldNameTranslated, this)); } +void MainWindow::initUIntBox(ConfigOption option, QLineEdit* numberLineEdit, QString fieldNameTranslated){ + configItems.append(new UIntStringItem(option, numberLineEdit, fieldNameTranslated, this)); +} void MainWindow::initUInt32Box(ConfigOption option, QLineEdit* numberLineEdit, QString fieldNameTranslated){ configItems.append(new UInt32StringItem(option, numberLineEdit, fieldNameTranslated, this)); } diff --git a/src/mainwindow.h b/src/mainwindow.h index 1522e4c..2f7b2c2 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -158,6 +158,8 @@ public: out << boost::any_cast(optionValue); }else if(isType(optionValue)) { out << boost::any_cast(optionValue); + }else if(isType(optionValue)) { + out << boost::any_cast(optionValue); }else if(isType(optionValue)) { out << boost::any_cast(optionValue); }else out << boost::any_cast(optionValue); //let it throw @@ -330,6 +332,24 @@ public: virtual QString toString(){return QString::number(boost::any_cast(optionValue));} virtual boost::any fromString(QString s){return boost::any(std::stoi(s.toStdString()));} }; +class UIntStringItem : public BaseFormattedStringItem { +public: + UIntStringItem(ConfigOption option_, QLineEdit* lineEdit_, QString fieldNameTranslated_, MainWindow* mw) : + BaseFormattedStringItem(option_, lineEdit_, fieldNameTranslated_, + QApplication::tr("Must be a valid integer."), mw) {} + virtual ~UIntStringItem(){} + virtual bool isValid(bool & alreadyDisplayedIfWrong){ + bool correct = BaseFormattedStringItem::isValid(alreadyDisplayedIfWrong); + if(!correct)return false; + alreadyDisplayedIfWrong = false; + auto str=lineEdit->text(); + bool ok; + str.toUInt(&ok); + return ok; + } + virtual QString toString(){return QString::number(boost::any_cast(optionValue));} + virtual boost::any fromString(QString s){return boost::any(std::stoul(s.toStdString()));} +}; class UShortStringItem : public BaseFormattedStringItem { public: UShortStringItem(ConfigOption option_, QLineEdit* lineEdit_, QString fieldNameTranslated_, MainWindow* mw) : @@ -543,6 +563,7 @@ protected: void initTCPPortBox(ConfigOption option, QLineEdit* portLineEdit, QString fieldNameTranslated); void initCheckBox(ConfigOption option, QCheckBox* checkBox); void initIntegerBox(ConfigOption option, QLineEdit* numberLineEdit, QString fieldNameTranslated); + void initUIntBox(ConfigOption option, QLineEdit* numberLineEdit, QString fieldNameTranslated); void initUInt32Box(ConfigOption option, QLineEdit* numberLineEdit, QString fieldNameTranslated); void initUInt16Box(ConfigOption option, QLineEdit* numberLineEdit, QString fieldNameTranslated); void initStringBox(ConfigOption option, QLineEdit* lineEdit);