added tabbed view
new config page with ability to edit config file new features in config class - setting member variables new button locations in gui
This commit is contained in:
parent
268aa3a1ad
commit
4344e7c118
@ -203,7 +203,8 @@ if (${GUI})
|
||||
add_executable(iprefresher-gui
|
||||
src/maingui.cpp
|
||||
src/gui/MainWindow.cpp
|
||||
src/gui/MainWindow.h ${UI_GENERATED_HEADERS})
|
||||
inc/gui/MainWindow.h
|
||||
${UI_GENERATED_HEADERS})
|
||||
|
||||
if (${WinBuild})
|
||||
# hide console window when starting ui on windows
|
||||
|
29
inc/Config.h
29
inc/Config.h
@ -18,6 +18,13 @@ public:
|
||||
*/
|
||||
static bool readConfig();
|
||||
|
||||
/**
|
||||
* save back configuration to file
|
||||
*
|
||||
* @return success of config write
|
||||
*/
|
||||
static bool saveConfig();
|
||||
|
||||
/**
|
||||
* validate config file
|
||||
*
|
||||
@ -63,12 +70,32 @@ public:
|
||||
*/
|
||||
static const std::string &getChatId();
|
||||
|
||||
/**
|
||||
* set all parameters without telegram support
|
||||
*
|
||||
* @param domainname Dynu Domain name
|
||||
* @param dynuapikey Dynu api key
|
||||
* @param domainid Dynu domain id
|
||||
*/
|
||||
static void setValues(const std::string &domainname, const std::string &dynuapikey, const std::string &domainid);
|
||||
|
||||
/**
|
||||
* set all parameters with telegram support
|
||||
*
|
||||
* @param domainname Dynu Domain name
|
||||
* @param dynuapikey Dynu api key
|
||||
* @param domainid Dynu domain id
|
||||
* @param telegramApiKey Telegram api key
|
||||
* @param chatId Telegram chat id
|
||||
*/
|
||||
static void setValues(const std::string &domainname, const std::string &dynuapikey, const std::string &domainid,
|
||||
const std::string &telegramApiKey, const std::string &chatId);
|
||||
|
||||
private:
|
||||
/**
|
||||
* private constructor --> don't allow instance of this class
|
||||
*/
|
||||
Config();
|
||||
Config() = default;
|
||||
|
||||
/**
|
||||
* helper variable for managing telegram Support
|
||||
|
@ -29,7 +29,14 @@ public:
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
|
||||
/**
|
||||
* all static initializations of custom gui elements
|
||||
*/
|
||||
void initGui();
|
||||
|
||||
private slots:
|
||||
|
||||
/**
|
||||
* executed click handler for config button
|
||||
*/
|
||||
@ -40,7 +47,13 @@ private slots:
|
||||
*/
|
||||
void refreshIPBtn();
|
||||
|
||||
/**
|
||||
* executed click handler for save config btn
|
||||
*/
|
||||
void saveConfigBtn();
|
||||
|
||||
signals:
|
||||
|
||||
/**
|
||||
* append a String line to the Log field
|
||||
*
|
@ -64,6 +64,11 @@ bool Config::readConfig() {
|
||||
return !(Config::dynuapikey.empty() || Config::domainid.empty() || Config::domainname.empty());
|
||||
}
|
||||
|
||||
bool Config::saveConfig() {
|
||||
// todo save config
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Config::validateConfig() {
|
||||
libconfig::Config cfg;
|
||||
try {
|
||||
@ -137,4 +142,14 @@ const std::string &Config::getChatId() {
|
||||
return chatId;
|
||||
}
|
||||
|
||||
Config::Config() = default;
|
||||
void Config::setValues(const std::string &domainname, const std::string &dynuapikey, const std::string &domainid) {
|
||||
Config::domainname = domainname;
|
||||
Config::dynuapikey = dynuapikey;
|
||||
Config::domainid = domainid;
|
||||
}
|
||||
|
||||
void Config::setValues(const std::string &domainname, const std::string &dynuapikey, const std::string &domainid, const std::string &telegramApiKey, const std::string &chatId) {
|
||||
setValues(domainname, dynuapikey, domainid);
|
||||
Config::telegramApiKey = telegramApiKey;
|
||||
Config::chatId = chatId;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "MainWindow.h"
|
||||
#include "inc/gui/MainWindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
#include "api/IPAPI.h"
|
||||
@ -11,20 +11,12 @@
|
||||
MainWindow::MainWindow() : QMainWindow(), ui(new Ui::MainWindow) {
|
||||
ui->setupUi(this);
|
||||
|
||||
// needs to be defined with new -- would be termintated after this constructor.
|
||||
new std::thread([this]() {
|
||||
IPAPI ipapi;
|
||||
std::string ip = ipapi.getGlobalIp();
|
||||
Logger::message("Current global IP: " + ip);
|
||||
std::string msg = "Your current global IP: " + ip;
|
||||
this->ui->labelCurrentIP->setText(msg.c_str());
|
||||
});
|
||||
|
||||
// set config info label and initial check if config is valid
|
||||
ui->labelConfig->setText(Config::validateConfig() ? "Config is: OK" : "Config is: NOT OK");
|
||||
// initialize gui with start parameters
|
||||
initGui();
|
||||
|
||||
connect(ui->buttonCheckConfig, SIGNAL(clicked()), this, SLOT(checkConfigBtn()));
|
||||
connect(ui->buttonRefreshIP, SIGNAL(clicked()), this, SLOT(refreshIPBtn()));
|
||||
connect(ui->buttonSaveConfig, SIGNAL(clicked()), this, SLOT(saveConfigBtn()));
|
||||
|
||||
connect(this, SIGNAL(appendLogField(QString)), ui->textLog, SLOT(appendPlainText(QString)));
|
||||
}
|
||||
@ -33,6 +25,7 @@ MainWindow::~MainWindow() {
|
||||
// todo check if disconnects are really necessary
|
||||
disconnect(ui->buttonCheckConfig);
|
||||
disconnect(ui->buttonRefreshIP);
|
||||
this->destroy();
|
||||
delete ui;
|
||||
}
|
||||
|
||||
@ -81,4 +74,56 @@ void MainWindow::refreshIPBtn() {
|
||||
Logger::message("Finished refreshing Dynu IP.");
|
||||
this->appendLogField("Finished refreshing Dynu IP.");
|
||||
});
|
||||
}
|
||||
|
||||
void MainWindow::saveConfigBtn() {
|
||||
if (ui->telegramsupportCheckbox->isChecked()) {
|
||||
Config::setValues(
|
||||
ui->domainnameedit->text().toStdString(),
|
||||
ui->dynuapikeyedit->text().toStdString(),
|
||||
ui->domainidedit->text().toStdString(),
|
||||
ui->telegramapikeyedit->text().toStdString(),
|
||||
ui->chatidedit->text().toStdString());
|
||||
} else {
|
||||
Config::setValues(
|
||||
ui->domainnameedit->text().toStdString(),
|
||||
ui->dynuapikeyedit->text().toStdString(),
|
||||
ui->domainidedit->text().toStdString());
|
||||
}
|
||||
Config::saveConfig();
|
||||
}
|
||||
|
||||
void MainWindow::initGui() {
|
||||
// needs to be defined with new -- would be termintated after the constructor call.
|
||||
new std::thread([this]() {
|
||||
IPAPI ipapi;
|
||||
std::string ip = ipapi.getGlobalIp();
|
||||
Logger::message("Current global IP: " + ip);
|
||||
std::string msg = "Your current global IP: " + ip;
|
||||
this->ui->labelCurrentIP->setText(msg.c_str());
|
||||
});
|
||||
|
||||
// set config info label and initial check if config is valid
|
||||
ui->labelConfig->setText(Config::validateConfig() ? "Config is: OK" : "Config is: NOT OK");
|
||||
|
||||
if (Config::readConfig()) {
|
||||
ui->dynuapikeyedit->setText(Config::getDynuapikey().c_str());
|
||||
ui->domainidedit->setText(Config::getDomainid().c_str());
|
||||
ui->domainnameedit->setText(Config::getDomainname().c_str());
|
||||
|
||||
if (Config::isTelegramSupported()) {
|
||||
ui->telegramsupportCheckbox->setCheckState(Qt::Checked);
|
||||
ui->telegramapikeyedit->setText(Config::getTelegramApiKey().c_str());
|
||||
ui->chatidedit->setText(Config::getChatId().c_str());
|
||||
} else {
|
||||
ui->telegramsupportCheckbox->setCheckState(Qt::Unchecked);
|
||||
ui->telegramapikeyedit->setDisabled(true);
|
||||
ui->chatidedit->setDisabled(true);
|
||||
}
|
||||
} else {
|
||||
// todo duplicate code with above
|
||||
ui->telegramsupportCheckbox->setCheckState(Qt::Unchecked);
|
||||
ui->telegramapikeyedit->setDisabled(true);
|
||||
ui->chatidedit->setDisabled(true);
|
||||
}
|
||||
}
|
@ -10,36 +10,16 @@
|
||||
<height>618</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="cursor">
|
||||
<cursorShape>ArrowCursor</cursorShape>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>MainWindow</string>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">/*background-color: rgb(69, 196, 255);</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<widget class="QPushButton" name="buttonRefreshIP">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>290</x>
|
||||
<y>300</y>
|
||||
<width>91</width>
|
||||
<height>33</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Refresh IP</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="labelCurrentIP">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>40</x>
|
||||
<y>60</y>
|
||||
<width>301</width>
|
||||
<height>17</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Your current global IP:</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPlainTextEdit" name="textLog">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
@ -48,7 +28,7 @@
|
||||
<rect>
|
||||
<x>40</x>
|
||||
<y>410</y>
|
||||
<width>691</width>
|
||||
<width>741</width>
|
||||
<height>191</height>
|
||||
</rect>
|
||||
</property>
|
||||
@ -69,31 +49,268 @@
|
||||
<string>Log:</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="buttonCheckConfig">
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>270</x>
|
||||
<y>140</y>
|
||||
<width>91</width>
|
||||
<height>33</height>
|
||||
<x>40</x>
|
||||
<y>20</y>
|
||||
<width>741</width>
|
||||
<height>351</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Check Config</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="labelConfig">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>270</x>
|
||||
<y>180</y>
|
||||
<width>141</width>
|
||||
<height>17</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Config is: undefined</string>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="basic">
|
||||
<attribute name="title">
|
||||
<string>Basic</string>
|
||||
</attribute>
|
||||
<widget class="QLabel" name="labelCurrentIP">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>30</y>
|
||||
<width>301</width>
|
||||
<height>17</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Your current global IP:</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="labelConfig">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>70</y>
|
||||
<width>141</width>
|
||||
<height>17</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Config is: undefined</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>120</y>
|
||||
<width>231</width>
|
||||
<height>151</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Actions</string>
|
||||
</property>
|
||||
<widget class="QPushButton" name="buttonCheckConfig">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>30</x>
|
||||
<y>50</y>
|
||||
<width>91</width>
|
||||
<height>33</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="cursor">
|
||||
<cursorShape>ArrowCursor</cursorShape>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Check Config</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="buttonRefreshIP">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>30</x>
|
||||
<y>100</y>
|
||||
<width>91</width>
|
||||
<height>33</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Refresh IP</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QWidget" name="config">
|
||||
<attribute name="title">
|
||||
<string>Config</string>
|
||||
</attribute>
|
||||
<widget class="QCheckBox" name="telegramsupportCheckbox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>30</x>
|
||||
<y>120</y>
|
||||
<width>181</width>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Telegram Notifications</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="buttonSaveConfig">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>630</x>
|
||||
<y>270</y>
|
||||
<width>91</width>
|
||||
<height>33</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Save Config</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>30</x>
|
||||
<y>20</y>
|
||||
<width>101</width>
|
||||
<height>17</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Dynu API Key</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>460</x>
|
||||
<y>20</y>
|
||||
<width>111</width>
|
||||
<height>17</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Domain ID</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>30</x>
|
||||
<y>170</y>
|
||||
<width>131</width>
|
||||
<height>17</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Telegram API Key</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>30</x>
|
||||
<y>240</y>
|
||||
<width>64</width>
|
||||
<height>17</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Chat ID</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="dynuapikeyedit">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>30</x>
|
||||
<y>40</y>
|
||||
<width>211</width>
|
||||
<height>31</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="domainidedit">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>460</x>
|
||||
<y>40</y>
|
||||
<width>113</width>
|
||||
<height>31</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="chatidedit">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>30</x>
|
||||
<y>260</y>
|
||||
<width>113</width>
|
||||
<height>31</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="telegramapikeyedit">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>30</x>
|
||||
<y>190</y>
|
||||
<width>311</width>
|
||||
<height>31</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="domainnameedit">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>280</x>
|
||||
<y>40</y>
|
||||
<width>161</width>
|
||||
<height>31</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>domain.dynu.net</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>280</x>
|
||||
<y>20</y>
|
||||
<width>111</width>
|
||||
<height>17</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Domainname</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QWidget" name="settings">
|
||||
<attribute name="title">
|
||||
<string>Settings</string>
|
||||
</attribute>
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>30</y>
|
||||
<width>161</width>
|
||||
<height>17</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Select your language:</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QComboBox" name="languageComboBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>60</y>
|
||||
<width>94</width>
|
||||
<height>31</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
|
@ -7,7 +7,7 @@
|
||||
int main(int argc, char *argv[]) {
|
||||
QApplication a(argc, argv);
|
||||
MainWindow w;
|
||||
w.setWindowTitle("startUpService");
|
||||
w.setWindowTitle("Dynu IP Refresher");
|
||||
w.show();
|
||||
|
||||
return QApplication::exec();
|
||||
|
Loading…
Reference in New Issue
Block a user