Add settings dialog
This commit is contained in:
parent
6f2d8b9710
commit
37807b56d2
|
@ -9,7 +9,7 @@ set(CMAKE_AUTORCC ON)
|
|||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(QT NAMES Qt5 Qt6 REQUIRED COMPONENTS Widgets)
|
||||
find_package(QT NAMES Qt5 REQUIRED COMPONENTS Widgets)
|
||||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
|
||||
|
||||
set(PROJECT_SOURCES
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 10.0.1, 2023-07-05T21:46:10. -->
|
||||
<!-- Written by QtCreator 10.0.1, 2023-07-09T18:55:22. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "branchdialog.h"
|
||||
#include "ui_branchdialog.h"
|
||||
#include <fstream>
|
||||
|
||||
BranchDialog::BranchDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
|
@ -8,6 +9,42 @@ BranchDialog::BranchDialog(QWidget *parent) :
|
|||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
void BranchDialog::setup_config(json &json_data)
|
||||
{
|
||||
std::string longterm_str, stable_str, devel_str, path_str;
|
||||
// Get configs from json data
|
||||
if(!json_data.empty()){
|
||||
longterm_str = json_data["Longterm"];
|
||||
stable_str = json_data["Stable"];
|
||||
devel_str = json_data["Develop"];
|
||||
switch(get_os_type()){
|
||||
case OS_Type::Darwin:
|
||||
darwin_path_str = json_data["Release_Path_Darwin"];
|
||||
path_str = darwin_path_str;
|
||||
break;
|
||||
case OS_Type::Linux:
|
||||
unix_path_str = json_data["Release_Path_Unix"];
|
||||
path_str = unix_path_str;
|
||||
break;
|
||||
case OS_Type::Windows:
|
||||
win32_path_str = json_data["Release_Path_Win32"];
|
||||
path_str = win32_path_str;
|
||||
break;
|
||||
}
|
||||
// Set the config to the lineedit widget
|
||||
ui->line_longterm->setText(QString(longterm_str.c_str()));
|
||||
ui->line_devel->setText(QString(devel_str.c_str()));
|
||||
ui->line_stable->setText(QString(stable_str.c_str()));
|
||||
ui->line_path->setText(QString(path_str.c_str()));
|
||||
}else{
|
||||
// Default configs
|
||||
ui->line_longterm->setText(QString("default config"));
|
||||
ui->line_stable->setText(QString("default config"));
|
||||
ui->line_devel->setText(QString("default config"));
|
||||
ui->line_path->setText(QString("./"));
|
||||
}
|
||||
}
|
||||
|
||||
BranchDialog::~BranchDialog()
|
||||
{
|
||||
delete ui;
|
||||
|
@ -15,12 +52,55 @@ BranchDialog::~BranchDialog()
|
|||
|
||||
void BranchDialog::on_buttonBox_accepted()
|
||||
{
|
||||
// Get config values
|
||||
std::string longterm_str, stable_str, devel_str;
|
||||
longterm_str = ui->line_longterm->text().toStdString();
|
||||
stable_str = ui->line_stable->text().toStdString();
|
||||
devel_str = ui->line_devel->text().toStdString();
|
||||
switch(get_os_type()){
|
||||
case OS_Type::Darwin:
|
||||
darwin_path_str = ui->line_path->text().toStdString();
|
||||
break;
|
||||
case OS_Type::Linux:
|
||||
unix_path_str = ui->line_path->text().toStdString();
|
||||
break;
|
||||
case OS_Type::Windows:
|
||||
win32_path_str = ui->line_path->text().toStdString();
|
||||
break;
|
||||
}
|
||||
|
||||
// Create json object to save data
|
||||
json data = json::parse(R"(
|
||||
{
|
||||
"Develop": "",
|
||||
"Longterm": "",
|
||||
"Release_Path_Darwin": "",
|
||||
"Release_Path_Unix": "",
|
||||
"Release_Path_Win32": "",
|
||||
"Stable": "",
|
||||
"background": 3,
|
||||
"dark_mode": false
|
||||
})");
|
||||
|
||||
// Update json config values
|
||||
data["Longterm"] = longterm_str;
|
||||
data["Stable"] = stable_str;
|
||||
data["Develop"] = devel_str;
|
||||
data["Release_Path_Unix"] = unix_path_str;
|
||||
data["Release_Path_Darwin"] = darwin_path_str;
|
||||
data["Release_Path_Win32"] = win32_path_str;
|
||||
|
||||
// Save json data to the file
|
||||
std::fstream outfile;
|
||||
outfile.open("xe_config.json", std::ios::out);
|
||||
if(outfile.is_open()){
|
||||
outfile << data;
|
||||
}
|
||||
outfile.close();
|
||||
}
|
||||
|
||||
|
||||
void BranchDialog::on_buttonBox_rejected()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ class BranchDialog : public QDialog
|
|||
|
||||
public:
|
||||
explicit BranchDialog(QWidget *parent = nullptr);
|
||||
void setup_config(json &json_data);
|
||||
~BranchDialog();
|
||||
|
||||
private slots:
|
||||
|
@ -23,6 +24,12 @@ private slots:
|
|||
|
||||
private:
|
||||
Ui::BranchDialog *ui;
|
||||
|
||||
// Json object
|
||||
json json_data1;
|
||||
|
||||
// string to save custom path configs
|
||||
std::string unix_path_str, win32_path_str, darwin_path_str;
|
||||
};
|
||||
|
||||
#endif // BRANCHDIALOG_H
|
||||
|
|
|
@ -10,6 +10,12 @@
|
|||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Branchs Config</string>
|
||||
</property>
|
||||
|
@ -33,7 +39,7 @@
|
|||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QWidget" name="gridLayoutWidget">
|
||||
<widget class="QWidget" name="verticalLayoutWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>-1</x>
|
||||
|
@ -42,7 +48,95 @@
|
|||
<height>251</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout"/>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_info">
|
||||
<property name="text">
|
||||
<string>Release Branchs Config:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>Path:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Stable:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLineEdit" name="line_path"/>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="line_stable"/>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="line_longterm"/>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="line_devel"/>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_long">
|
||||
<property name="text">
|
||||
<string>Longterm:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string> Development: </string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QPushButton" name="btn_path">
|
||||
<property name="text">
|
||||
<string>Browse dir for path...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources>
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#include "mainwindow.h"
|
||||
#include "./ui_mainwindow.h"
|
||||
#include "branchdialog.h"
|
||||
#include "./ui_branchdialog.h"
|
||||
#include <QMessageBox>
|
||||
#include <fstream>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
|
@ -14,16 +15,68 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
QPalette palette(this->palette());
|
||||
palette.setBrush(QPalette::Window, QBrush(pixmap));
|
||||
this->setPalette(palette);
|
||||
|
||||
// Update time for versions generation
|
||||
local = new tm;
|
||||
update_time();
|
||||
get_config();
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
delete local;
|
||||
// delete dialog;
|
||||
}
|
||||
|
||||
void MainWindow::get_config()
|
||||
{}
|
||||
{
|
||||
// Read config from json file
|
||||
std::fstream infile;
|
||||
infile.open("xe_config.json", std::ios_base::in);
|
||||
|
||||
// Read json data from file
|
||||
if(infile.is_open()){
|
||||
json_data = json::parse(infile);
|
||||
longterm_ver = json_data["Longterm"];
|
||||
stable_ver = json_data["Stable"];
|
||||
devel_ver = json_data["Develop"];
|
||||
|
||||
switch(get_os_type()){
|
||||
case OS_Type::Darwin:
|
||||
break;
|
||||
case OS_Type::Linux:
|
||||
break;
|
||||
case OS_Type::Windows:
|
||||
break;
|
||||
}
|
||||
|
||||
dark_mode = json_data["dark_mode"];
|
||||
}else{
|
||||
// Show a error messagebox
|
||||
QMessageBox msgbox;
|
||||
msgbox.setIcon(QMessageBox::Critical);
|
||||
msgbox.setText(QString("No vaild config file found!\nPlease create a config by the \"Preferences\" Menu"));
|
||||
msgbox.addButton(QMessageBox::Ok);
|
||||
msgbox.exec();
|
||||
|
||||
// Initalize default config
|
||||
longterm_ver = "";
|
||||
stable_ver = "";
|
||||
devel_ver = "";
|
||||
path = "./";
|
||||
dark_mode = false;
|
||||
}
|
||||
infile.close();
|
||||
}
|
||||
|
||||
void MainWindow::update_time(){
|
||||
// Get local time
|
||||
time_t t;
|
||||
t = time(NULL);
|
||||
localtime_s(local, &t);
|
||||
year.setNum(local->tm_year + 1900);
|
||||
}
|
||||
|
||||
void MainWindow::on_btn_ver_clicked()
|
||||
{
|
||||
|
@ -90,6 +143,37 @@ void MainWindow::on_actionXeRelease_10_14_triggered()
|
|||
void MainWindow::on_actionRelease_branchs_triggered()
|
||||
{
|
||||
BranchDialog dialog(this);
|
||||
dialog.setup_config(json_data);
|
||||
dialog.exec();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_actionAbout_XeRelease_Qt_triggered()
|
||||
{
|
||||
// Create icon
|
||||
QPixmap pixmap = QPixmap(":/xe_res/res/Xe-Release.png");
|
||||
QMessageBox msgbox;
|
||||
QString detailed_text, version = "17.0 The Flying Dream\n";
|
||||
detailed_text = version;
|
||||
detailed_text += "Build With Qt ";
|
||||
detailed_text += QT_VERSION_STR;
|
||||
detailed_text += "\n\nA tool to get versions by date and user settings\n";
|
||||
detailed_text +="\n© 2019—";
|
||||
detailed_text += year;
|
||||
detailed_text += " The Xe Project";
|
||||
|
||||
// Text of message box
|
||||
msgbox.setText(QString("### About Xe Release Qt Version"));
|
||||
msgbox.setInformativeText(detailed_text);
|
||||
msgbox.setTextFormat(Qt::TextFormat::MarkdownText);
|
||||
|
||||
// Icons
|
||||
msgbox.setIconPixmap(pixmap);
|
||||
msgbox.setWindowIcon(QIcon(pixmap));
|
||||
|
||||
// Only a Button
|
||||
msgbox.setStandardButtons(QMessageBox::Ok);
|
||||
msgbox.setDefaultButton(QMessageBox::Ok);
|
||||
msgbox.exec();
|
||||
}
|
||||
|
||||
|
|
|
@ -3,9 +3,12 @@
|
|||
|
||||
#include <QMainWindow>
|
||||
#include <string>
|
||||
#include "xerelease.hh"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui { class MainWindow; }
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
}
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
|
@ -31,12 +34,29 @@ private slots:
|
|||
|
||||
void on_actionRelease_branchs_triggered();
|
||||
|
||||
void on_actionAbout_XeRelease_Qt_triggered();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
// Ui::BranchDialog dialog;
|
||||
// struct for time
|
||||
struct tm *local;
|
||||
QString year;
|
||||
|
||||
|
||||
// Release names
|
||||
json json_data;
|
||||
// Version string of branchs
|
||||
std::string longterm_ver, stable_ver, devel_ver;
|
||||
|
||||
// Path to save the file
|
||||
std::string path;
|
||||
|
||||
// Mode string, will be enable soon
|
||||
// This config item is for compatibility
|
||||
// with the Xe Release Gtkmm4 Version
|
||||
bool dark_mode;
|
||||
|
||||
void get_config();
|
||||
void update_time();
|
||||
};
|
||||
#endif // MAINWINDOW_H
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Xe Release 17 Qt Version</string>
|
||||
<string>Xe Release Qt Version</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset resource="../xe_resource.qrc">
|
||||
|
@ -137,7 +137,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>640</width>
|
||||
<height>37</height>
|
||||
<height>25</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
|
|
Loading…
Reference in New Issue