From 3d5fb07ca8290a9f964f4c21022aec659711dd74 Mon Sep 17 00:00:00 2001 From: hypnosis-i2p Date: Sun, 27 Aug 2017 12:39:00 +0800 Subject: [PATCH] various small qt gui fixes --- qt/i2pd_qt/ClientTunnelPane.h | 2 +- qt/i2pd_qt/mainwindow.cpp | 36 ++++++++++++++++++++++++++--------- qt/i2pd_qt/mainwindow.h | 32 +++++++++++++++++++++++++++---- qt/i2pd_qt/mainwindow.ui | 14 ++++++++++++-- 4 files changed, 68 insertions(+), 16 deletions(-) diff --git a/qt/i2pd_qt/ClientTunnelPane.h b/qt/i2pd_qt/ClientTunnelPane.h index 7052211a..511209e5 100644 --- a/qt/i2pd_qt/ClientTunnelPane.h +++ b/qt/i2pd_qt/ClientTunnelPane.h @@ -85,7 +85,7 @@ protected: ctc->setaddress(addressLineEdit->text().toStdString()); - auto dportStr=portLineEdit->text(); + auto dportStr=destinationPortLineEdit->text(); int dportInt=dportStr.toInt(&ok); if(!ok)return false; ctc->setdestinationPort(dportInt); diff --git a/qt/i2pd_qt/mainwindow.cpp b/qt/i2pd_qt/mainwindow.cpp index 79516206..ac431672 100644 --- a/qt/i2pd_qt/mainwindow.cpp +++ b/qt/i2pd_qt/mainwindow.cpp @@ -143,10 +143,16 @@ MainWindow::MainWindow(QWidget *parent) : initFileChooser( OPTION("","tunconf",[](){return "";}), ui->tunnelsConfigFileLineEdit, ui->tunnelsConfigFileBrowsePushButton); initFileChooser( OPTION("","pidfile",[]{return "";}), ui->pidFileLineEdit, ui->pidFileBrowsePushButton); - logOption=initNonGUIOption( OPTION("","log",[]{return "";})); daemonOption=initNonGUIOption( OPTION("","daemon",[]{return "";})); serviceOption=initNonGUIOption( OPTION("","service",[]{return "";})); + ui->logDestinationComboBox->clear(); + ui->logDestinationComboBox->insertItems(0, QStringList() + << QApplication::translate("MainWindow", "stdout", 0) + << QApplication::translate("MainWindow", "file", 0) + ); + initLogDestinationCombobox( OPTION("","log",[]{return "";}), ui->logDestinationComboBox); + logFileNameOption=initFileChooser( OPTION("","logfile",[]{return "";}), ui->logFileLineEdit, ui->logFileBrowsePushButton); initLogLevelCombobox(OPTION("","loglevel",[]{return "";}), ui->logLevelComboBox); @@ -246,6 +252,10 @@ MainWindow::MainWindow(QWidget *parent) : loadAllConfigs(); + QObject::connect(ui->logDestinationComboBox, SIGNAL(currentIndexChanged(const QString &)), + this, SLOT(logDestinationComboBoxValueChanged(const QString &))); + logDestinationComboBoxValueChanged(ui->logDestinationComboBox->currentText()); + //tunnelsFormGridLayoutWidget = new QWidget(ui->tunnelsScrollAreaWidgetContents); //tunnelsFormGridLayoutWidget->setObjectName(QStringLiteral("tunnelsFormGridLayoutWidget")); //tunnelsFormGridLayoutWidget->setGeometry(QRect(0, 0, 621, 451)); @@ -281,6 +291,13 @@ MainWindow::MainWindow(QWidget *parent) : //QMetaObject::connectSlotsByName(this); } +void MainWindow::logDestinationComboBoxValueChanged(const QString & text) { + bool stdout = text==QString("stdout"); + ui->logFileLineEdit->setEnabled(!stdout); + ui->logFileBrowsePushButton->setEnabled(!stdout); +} + + void MainWindow::updateRouterCommandsButtons() { bool acceptsTunnels = i2p::context.AcceptsTunnels (); routerCommandsUI->declineTransitTunnelsPushButton->setEnabled(acceptsTunnels); @@ -518,6 +535,9 @@ void MainWindow::initFolderChooser(ConfigOption option, QLineEdit* folderLineEdi configItems.append(new ComboBoxItem(option, comboBox)); QObject::connect(comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(saveAllConfigs())); }*/ +void MainWindow::initLogDestinationCombobox(ConfigOption option, QComboBox* comboBox){ + configItems.append(new LogDestinationComboBoxItem(option, comboBox)); +} void MainWindow::initLogLevelCombobox(ConfigOption option, QComboBox* comboBox){ configItems.append(new LogLevelComboBoxItem(option, comboBox)); } @@ -572,10 +592,7 @@ void MainWindow::loadAllConfigs(){ LogPrint(eLogWarning, "Daemon: please rename i2p.conf to i2pd.conf here: ", config); } else { config = i2p::fs::DataDirPath("i2pd.conf"); - if (!i2p::fs::Exists (config)) { - // use i2pd.conf only if exists - config = ""; /* reset */ - } + /*if (!i2p::fs::Exists (config)) {}*/ } } @@ -605,8 +622,8 @@ void MainWindow::loadAllConfigs(){ /** returns false iff not valid items present and save was aborted */ bool MainWindow::saveAllConfigs(){ programOptionsWriterCurrentSection=""; - if(!logFileNameOption->lineEdit->text().trimmed().isEmpty())logOption->optionValue=boost::any(std::string("file")); - else logOption->optionValue=boost::any(std::string("stdout")); + /*if(!logFileNameOption->lineEdit->text().trimmed().isEmpty())logOption->optionValue=boost::any(std::string("file")); + else logOption->optionValue=boost::any(std::string("stdout"));*/ daemonOption->optionValue=boost::any(false); serviceOption->optionValue=boost::any(false); @@ -623,9 +640,10 @@ bool MainWindow::saveAllConfigs(){ using namespace std; + QString backup=confpath+"~"; if(QFile::exists(backup)) QFile::remove(backup);//TODO handle errors - QFile::rename(confpath, backup);//TODO handle errors + if(QFile::exists(confpath)) QFile::rename(confpath, backup);//TODO handle errors ofstream outfile; outfile.open(confpath.toStdString());//TODO handle errors outfile << out.str().c_str(); @@ -740,7 +758,7 @@ void MainWindow::SaveTunnelsConfig() { QString backup=tunconfpath+"~"; if(QFile::exists(backup)) QFile::remove(backup);//TODO handle errors - QFile::rename(tunconfpath, backup);//TODO handle errors + if(QFile::exists(tunconfpath)) QFile::rename(tunconfpath, backup);//TODO handle errors ofstream outfile; outfile.open(tunconfpath.toStdString());//TODO handle errors outfile << out.str().c_str(); diff --git a/qt/i2pd_qt/mainwindow.h b/qt/i2pd_qt/mainwindow.h index 829cac37..27f1ccc2 100644 --- a/qt/i2pd_qt/mainwindow.h +++ b/qt/i2pd_qt/mainwindow.h @@ -57,6 +57,8 @@ #include "SignatureTypeComboboxFactory.h" #include "pagewithbackbutton.h" +#include + template bool isType(boost::any& a) { return @@ -97,7 +99,7 @@ public: std::string optName=""; if(!option.section.isEmpty())optName=option.section.toStdString()+std::string("."); optName+=option.option.toStdString(); - qDebug() << "loadFromConfigOption[" << optName.c_str() << "]"; + //qDebug() << "loadFromConfigOption[" << optName.c_str() << "]"; boost::any programOption; i2p::config::GetOptionAsAny(optName, programOption); optionValue=programOption.empty()?boost::any(std::string("")) @@ -203,6 +205,21 @@ public: virtual void saveToStringStream(std::stringstream& out)=0; virtual bool isValid() { return true; } }; +class LogDestinationComboBoxItem : public ComboBoxItem { +public: + LogDestinationComboBoxItem(ConfigOption option_, QComboBox* comboBox_) : ComboBoxItem(option_, comboBox_) {}; + virtual ~LogDestinationComboBoxItem(){} + virtual void loadFromConfigOption(){ + MainWindowItem::loadFromConfigOption(); + const char * ld = boost::any_cast(optionValue).c_str(); + comboBox->setCurrentText(QString(ld)); + } + virtual void saveToStringStream(std::stringstream& out){ + optionValue=comboBox->currentText().toStdString(); + MainWindowItem::saveToStringStream(out); + } + virtual bool isValid() { return true; } +}; class LogLevelComboBoxItem : public ComboBoxItem { public: LogLevelComboBoxItem(ConfigOption option_, QComboBox* comboBox_) : ComboBoxItem(option_, comboBox_) {}; @@ -418,14 +435,15 @@ protected: QString getStatusPageHtml(bool showHiddenInfo); QList configItems; - NonGUIOptionItem* logOption; NonGUIOptionItem* daemonOption; NonGUIOptionItem* serviceOption; + //LogDestinationComboBoxItem* logOption; FileChooserItem* logFileNameOption; FileChooserItem* initFileChooser(ConfigOption option, QLineEdit* fileNameLineEdit, QPushButton* fileBrowsePushButton); void initFolderChooser(ConfigOption option, QLineEdit* folderLineEdit, QPushButton* folderBrowsePushButton); //void initCombobox(ConfigOption option, QComboBox* comboBox); + void initLogDestinationCombobox(ConfigOption option, QComboBox* comboBox); void initLogLevelCombobox(ConfigOption option, QComboBox* comboBox); void initSignatureTypeCombobox(ConfigOption option, QComboBox* comboBox); void initIPAddressBox(ConfigOption option, QLineEdit* addressLineEdit, QString fieldNameTranslated); @@ -453,6 +471,8 @@ public slots: void anchorClickedHandler(const QUrl & link); void backClickedFromChild(); + void logDestinationComboBoxValueChanged(const QString & text); + private: QString datadir; QString confpath; @@ -635,13 +655,17 @@ private: { // mandatory params std::string dest; - if (type == I2P_TUNNELS_SECTION_TYPE_CLIENT || type == I2P_TUNNELS_SECTION_TYPE_UDPCLIENT) + if (type == I2P_TUNNELS_SECTION_TYPE_CLIENT || type == I2P_TUNNELS_SECTION_TYPE_UDPCLIENT) { dest = section.second.get (I2P_CLIENT_TUNNEL_DESTINATION); + std::cout << "had read tunnel dest: " << dest << std::endl; + } int port = section.second.get (I2P_CLIENT_TUNNEL_PORT); + std::cout << "had read tunnel port: " << port << std::endl; // optional params std::string keys = section.second.get (I2P_CLIENT_TUNNEL_KEYS, ""); std::string address = section.second.get (I2P_CLIENT_TUNNEL_ADDRESS, "127.0.0.1"); - int destinationPort = section.second.get (I2P_CLIENT_TUNNEL_DESTINATION_PORT, 0); + int destinationPort = section.second.get(I2P_CLIENT_TUNNEL_DESTINATION_PORT, 0); + std::cout << "had read tunnel destinationPort: " << destinationPort << std::endl; i2p::data::SigningKeyType sigType = section.second.get (I2P_CLIENT_TUNNEL_SIGNATURE_TYPE, i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256); // I2CP std::map options; diff --git a/qt/i2pd_qt/mainwindow.ui b/qt/i2pd_qt/mainwindow.ui index 6945a2a2..16a0822b 100644 --- a/qt/i2pd_qt/mainwindow.ui +++ b/qt/i2pd_qt/mainwindow.ui @@ -188,7 +188,7 @@ - 0 + 1 @@ -506,6 +506,16 @@ QLayout::SetMaximumSize + + + + Destination: + + + + + + @@ -3007,7 +3017,7 @@ Comma separated list of base64 identities: - SIgnature type: + Signature type: