Rev 24 | Blame | Last modification | View Log | RSS feed
/*
* Copyright (C) 2020, 2021 by Andreas Theofilu <andreas@theosys.at>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <QFileDialog>
#include <unistd.h>
#include "tqtsettings.h"
#include "terror.h"
#include "ui_tqtsettings.h"
#ifdef __ANDROID__
#include <QtQml/QQmlFile>
#include <android/log.h>
#endif
#include "tconfig.h"
TQtSettings::TQtSettings(QWidget *parent)
: QDialog(parent),
ui(new Ui::TQtSettings)
{
DECL_TRACER("TQtSettings::TQtSettings(QWidget *parent)");
ui->setupUi(this);
ui->lineEdit_projectPath->setText(TConfig::getProjectPath().c_str());
ui->lineEdit_Controller->setText(TConfig::getController().c_str());
ui->lineEdit_PType->setText(TConfig::getPanelType().c_str());
ui->spinBox_Port->setValue(TConfig::getPort());
ui->spinBox_Channel->setValue(TConfig::getChannel());
ui->comboBox_logLevel->setCurrentIndex(getLogLevelIndex(TConfig::getLogLevel()));
ui->checkBox_Format->setCheckState((TConfig::isLongFormat() ? Qt::CheckState::Checked : Qt::CheckState::Unchecked));
ui->checkBox_Scale->setCheckState((TConfig::getScale() ? Qt::CheckState::Checked : Qt::CheckState::Unchecked));
}
TQtSettings::~TQtSettings()
{
DECL_TRACER("TQtSettings::~TQtSettings()");
delete ui;
}
/*
void TQtSettings::on_kiconbutton_logFile_clicked()
{
std::string pt = TConfig::getLogFile();
size_t pos = pt.find_last_of("/");
if (pos != std::string::npos)
pt = pt.substr(0, pos);
else
{
char hv0[4096];
getcwd(hv0, sizeof(hv0));
pt = hv0;
}
QString actPath(pt.c_str());
QFileDialog fdialog(this, tr("Logfile"), actPath, tr("Logfile (*.log)"));
fdialog.setAcceptMode(QFileDialog::AcceptSave);
fdialog.setDefaultSuffix("log");
fdialog.setOption(QFileDialog::DontConfirmOverwrite);
QString fname;
if (fdialog.exec())
{
QDir dir = fdialog.directory();
QStringList list = fdialog.selectedFiles();
if (list.size() > 0)
fname = dir.absoluteFilePath(list.at(0));
else
return;
}
else
return;
ui->lineEdit_logFile->setText(fname);
if (TConfig::getLogFile().compare(fname.toStdString()) != 0)
{
mSetChanged = true;
TConfig::saveLogFile(fname.toStdString());
}
}
*/
void TQtSettings::on_kiconbutton_projectPath_clicked()
{
QString actPath(TConfig::getProjectPath().c_str());
QString fileName = QFileDialog::getExistingDirectory(this, tr("Directory of project"), actPath);
#ifdef __ANDROID__
QString fname = QQmlFile::urlToLocalFileOrQrc(fileName);
ui->lineEdit_projectPath->setText(fname);
#else
QString fname = fileName;
#endif
if (TConfig::getProjectPath().compare(fname.toStdString()) != 0)
{
mSetChanged = true;
TConfig::saveProjectPath(fname.toStdString());
}
}
/*
void TQtSettings::on_lineEdit_logFile_textChanged(const QString &arg1)
{
if (arg1.compare(TConfig::getLogFile().c_str()) == 0)
return;
mSetChanged = true;
TConfig::saveLogFile(arg1.toStdString());
}
*/
void TQtSettings::on_comboBox_logLevel_currentIndexChanged(int index)
{
int idx = getLogLevelIndex(TConfig::getLogLevel());
#ifdef __ANDROID__
__android_log_print(ANDROID_LOG_DEBUG, "tpanel", "LogLevel index=%d, old index=%d", index, idx);
#endif
if (idx == index)
return;
mSetChanged = true;
switch(index)
{
case 0: TConfig::saveLogLevel(SLOG_NONE); break;
case 1: TConfig::saveLogLevel(SLOG_INFO); break;
case 2: TConfig::saveLogLevel(SLOG_WARNING); break;
case 3: TConfig::saveLogLevel(SLOG_ERROR); break;
case 4: TConfig::saveLogLevel(SLOG_TRACE); break;
case 5: TConfig::saveLogLevel(SLOG_DEBUG); break;
case 6: TConfig::saveLogLevel(SLOG_PROTOCOL); break;
case 7: TConfig::saveLogLevel(SLOG_ALL); break;
}
}
void TQtSettings::on_lineEdit_projectPath_textChanged(const QString &arg1)
{
if (arg1.compare(TConfig::getProjectPath().c_str()) == 0)
return;
mSetChanged = true;
TConfig::saveProjectPath(arg1.toStdString());
}
void TQtSettings::on_lineEdit_Controller_textChanged(const QString &arg1)
{
if (arg1.compare(TConfig::getController().c_str()) == 0)
return;
mSetChanged = true;
TConfig::saveController(arg1.toStdString());
}
void TQtSettings::on_spinBox_Port_valueChanged(int arg1)
{
if (arg1 == TConfig::getPort())
return;
mSetChanged = true;
TConfig::savePort(arg1);
}
void TQtSettings::on_spinBox_Channel_valueChanged(int arg1)
{
if (arg1 == TConfig::getChannel())
return;
mSetChanged = true;
TConfig::saveChannel(arg1);
}
void TQtSettings::on_lineEdit_PType_textChanged(const QString &arg1)
{
if (arg1.compare(TConfig::getPanelType().c_str()) == 0)
return;
mSetChanged = true;
TConfig::savePanelType(arg1.toStdString());
}
int TQtSettings::getLogLevelIndex(const std::string &sl)
{
int idx = 0;
if (sl.compare(SLOG_NONE) == 0)
idx = 0;
else if (sl.compare(SLOG_INFO) == 0)
idx = 1;
else if (sl.compare(SLOG_WARNING) == 0)
idx = 2;
else if (sl.compare(SLOG_ERROR) == 0)
idx = 3;
else if (sl.compare(SLOG_TRACE) == 0)
idx = 4;
else if (sl.compare(SLOG_DEBUG) == 0)
idx = 5;
else if (sl.compare(SLOG_PROTOCOL) == 0)
idx = 6;
else if (sl.compare(SLOG_ALL) == 0)
idx = 7;
return idx;
}
void TQtSettings::on_checkBox_Format_toggled(bool checked)
{
if (TConfig::isLongFormat() == checked)
return;
mSetChanged = true;
TConfig::saveFormat(checked);
}
void TQtSettings::on_checkBox_Scale_toggled(bool checked)
{
if (TConfig::getScale() == checked)
return;
mSetChanged = true;
TConfig::saveScale(checked);
}