settign elog will ask for username and password

This commit is contained in:
carina@hades 2023-12-12 16:17:11 -05:00
parent 72f5cd98e5
commit d254bb9d2d
2 changed files with 93 additions and 45 deletions

View File

@ -10,6 +10,7 @@
#include <QCoreApplication> #include <QCoreApplication>
#include <QDialog> #include <QDialog>
#include <QFileDialog> #include <QFileDialog>
#include <QInputDialog>
#include <QScrollArea> #include <QScrollArea>
#include <QProcess> #include <QProcess>
#include <QMessageBox> #include <QMessageBox>
@ -134,51 +135,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){
leElogName->setReadOnly(true); leElogName->setReadOnly(true);
layout->addWidget(leElogName, rowID, 4); layout->addWidget(leElogName, rowID, 4);
connect(bnLock, &QPushButton::clicked, this, [=](){ connect(bnLock, &QPushButton::clicked, this, &MainWindow::SetAndLockInfluxElog);
if( leInfluxIP->isReadOnly() ){
bnLock->setText("Lock and Set");
leInfluxIP->setReadOnly(false);
leDatabaseName->setReadOnly(false);
leElogIP->setReadOnly(false);
leElogName->setReadOnly(false);
leInfluxIP->setEnabled(true);
leDatabaseName->setEnabled(true);
leElogIP->setEnabled(true);
leElogName->setEnabled(true);
leInfluxIP->setStyleSheet("color : blue;");
leDatabaseName->setStyleSheet("color : blue;");
leElogIP->setStyleSheet("color : blue;");
leElogName->setStyleSheet("color : blue;");
}else{
bnLock->setText("Unlock");
leInfluxIP->setReadOnly(true);
leDatabaseName->setReadOnly(true);
leElogIP->setReadOnly(true);
leElogName->setReadOnly(true);
leInfluxIP->setStyleSheet("");
leDatabaseName->setStyleSheet("");
leElogIP->setStyleSheet("");
leElogName->setStyleSheet("");
influxIP = leInfluxIP->text();
dataBaseName = leDatabaseName->text();
elogIP = leElogIP->text();
elogName = leElogName->text();
SaveProgramSettings();
SetUpInflux();
if( elogName != "" ) CheckElog();
}
});
} }
@ -1368,6 +1325,94 @@ void MainWindow::SetSyncMode(){
} }
void MainWindow::SetAndLockInfluxElog(){
if( leInfluxIP->isReadOnly() ){
bnLock->setText("Lock and Set");
leInfluxIP->setReadOnly(false);
leDatabaseName->setReadOnly(false);
leElogIP->setReadOnly(false);
leElogName->setReadOnly(false);
leInfluxIP->setEnabled(true);
leDatabaseName->setEnabled(true);
leElogIP->setEnabled(true);
leElogName->setEnabled(true);
leInfluxIP->setStyleSheet("color : blue;");
leDatabaseName->setStyleSheet("color : blue;");
leElogIP->setStyleSheet("color : blue;");
leElogName->setStyleSheet("color : blue;");
}else{
bnLock->setText("Unlock");
leInfluxIP->setReadOnly(true);
leDatabaseName->setReadOnly(true);
leElogIP->setReadOnly(true);
leElogName->setReadOnly(true);
leInfluxIP->setStyleSheet("");
leDatabaseName->setStyleSheet("");
leElogIP->setStyleSheet("");
leElogName->setStyleSheet("");
influxIP = leInfluxIP->text();
dataBaseName = leDatabaseName->text();
elogIP = leElogIP->text();
elogName = leElogName->text();
if( !elogIP.isEmpty() && !elogName.isEmpty() ){
QDialog dialog;
dialog.setWindowTitle("ELog Login info.");
QVBoxLayout layout(&dialog);
QFormLayout formLayout;
QLineEdit usernameLineEdit;
QLineEdit passwordLineEdit;
passwordLineEdit.setEchoMode(QLineEdit::Password);
formLayout.addRow("Username:", &usernameLineEdit);
formLayout.addRow("Password:", &passwordLineEdit);
usernameLineEdit.setText(elogUser);
passwordLineEdit.setText(elogPWD);
layout.addLayout(&formLayout);
// Buttons for OK and Cancel
QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
layout.addWidget(&buttonBox);
QObject::connect(&buttonBox, &QDialogButtonBox::accepted, &dialog, &QDialog::accept);
QObject::connect(&buttonBox, &QDialogButtonBox::rejected, &dialog, &QDialog::reject);
// Show the dialog and get the result
if (dialog.exec() == QDialog::Accepted) {
QString username = usernameLineEdit.text();
QString password = passwordLineEdit.text();
// Check if username and password are not empty
if (!username.isEmpty() && !password.isEmpty()) {
elogUser = username;
elogPWD = password;
} else {
qDebug() << "Please enter both username and password.";
}
}
}
SaveProgramSettings();
SetUpInflux();
CheckElog();
}
}
bool MainWindow::CommentDialog(bool isStartRun){ bool MainWindow::CommentDialog(bool isStartRun){
if( isStartRun ) runID ++; if( isStartRun ) runID ++;
@ -1729,6 +1774,8 @@ void MainWindow::CheckElog(){
AppendElog("test append elog."); AppendElog("test append elog.");
}else{ }else{
LogMsg("<font style=\"color : red;\">Elog missing inputs. skip.</font>"); LogMsg("<font style=\"color : red;\">Elog missing inputs. skip.</font>");
leElogIP->setEnabled(false);
leElogName->setEnabled(false);
return; return;
} }

View File

@ -90,6 +90,7 @@ private slots:
void SetSyncMode(); void SetSyncMode();
void SetAndLockInfluxElog();
private: private: