Skip to content

Commit

Permalink
various small qt gui fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nonlin-lin-chaos-order-etc-etal committed Aug 27, 2017
1 parent 5c3d629 commit 3d5fb07
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 16 deletions.
2 changes: 1 addition & 1 deletion qt/i2pd_qt/ClientTunnelPane.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected slots:

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);
Expand Down
36 changes: 27 additions & 9 deletions qt/i2pd_qt/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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)) {}*/
}
}

Expand Down Expand Up @@ -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);

Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
32 changes: 28 additions & 4 deletions qt/i2pd_qt/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
#include "SignatureTypeComboboxFactory.h"
#include "pagewithbackbutton.h"

#include <iostream>

template<typename ValueType>
bool isType(boost::any& a) {
return
Expand Down Expand Up @@ -97,7 +99,7 @@ class MainWindowItem : public QObject {
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(""))
Expand Down Expand Up @@ -203,6 +205,21 @@ class ComboBoxItem : public MainWindowItem {
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<std::string>(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_) {};
Expand Down Expand Up @@ -418,14 +435,15 @@ private slots:
QString getStatusPageHtml(bool showHiddenInfo);

QList<MainWindowItem*> 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);
Expand Down Expand Up @@ -453,6 +471,8 @@ public slots:
void anchorClickedHandler(const QUrl & link);
void backClickedFromChild();

void logDestinationComboBoxValueChanged(const QString & text);

private:
QString datadir;
QString confpath;
Expand Down Expand Up @@ -635,13 +655,17 @@ public slots:
{
// 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<std::string> (I2P_CLIENT_TUNNEL_DESTINATION);
std::cout << "had read tunnel dest: " << dest << std::endl;
}
int port = section.second.get<int> (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<int>(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<std::string, std::string> options;
Expand Down
14 changes: 12 additions & 2 deletions qt/i2pd_qt/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
</size>
</property>
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="statusPage">
<property name="sizePolicy">
Expand Down Expand Up @@ -506,6 +506,16 @@
<property name="sizeConstraint">
<enum>QLayout::SetMaximumSize</enum>
</property>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Destination:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="logDestinationComboBox"/>
</item>
<item>
<widget class="QLabel" name="logFileLabel">
<property name="text">
Expand Down Expand Up @@ -3007,7 +3017,7 @@ Comma separated list of base64 identities:</string>
<item>
<widget class="QLabel" name="label_42">
<property name="text">
<string>SIgnature type:</string>
<string>Signature type:</string>
</property>
</widget>
</item>
Expand Down

0 comments on commit 3d5fb07

Please sign in to comment.