Add json file support
This commit is contained in:
parent
1e6260ad75
commit
241211c4e9
|
@ -1,5 +1,11 @@
|
|||
{
|
||||
"C_Cpp.errorSquiggles": "Disabled",
|
||||
"cmake.configureOnOpen": false,
|
||||
"C_Cpp.dimInactiveRegions": false
|
||||
"C_Cpp.dimInactiveRegions": false,
|
||||
"files.associations": {
|
||||
"array": "cpp",
|
||||
"string": "cpp",
|
||||
"string_view": "cpp",
|
||||
"*.inc": "cpp"
|
||||
}
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
#include "MyDialog.hh"
|
||||
#include "../cfgfile2/cfgfile.hh"
|
||||
|
||||
MyDialog::MyDialog(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &ref_builder)
|
||||
: Gtk::Dialog(cobject),
|
||||
|
@ -15,23 +14,46 @@ ref_Glade(ref_builder)
|
|||
ref_builder->get_widget("btnpath", btnpath);
|
||||
|
||||
// Read Configs
|
||||
std::string config;
|
||||
if(readCfgFile("xe_config","Longterm",config)){
|
||||
entry_lts->set_text(config);
|
||||
std::string config_longterm, config_stable, config_devel;
|
||||
|
||||
// Open json file
|
||||
std::ifstream json_file("xe_config.json");
|
||||
if (json_file.is_open())
|
||||
{
|
||||
// Read data from json file
|
||||
data = json::parse(json_file);
|
||||
config_longterm = data["Longterm"];
|
||||
config_stable = data["Stable"];
|
||||
config_devel = data["Develop"];
|
||||
config_unix = data["Release_Path_Unix"];
|
||||
config_win32 = data["Release_Path_Win32"];
|
||||
|
||||
// Set text from json file data
|
||||
entry_lts->set_text(config_longterm);
|
||||
entry_stable->set_text(config_stable);
|
||||
entry_dev->set_text(config_devel);
|
||||
}
|
||||
if(readCfgFile("xe_config","Stable",config)){
|
||||
entry_stable->set_text(config);
|
||||
}
|
||||
if(readCfgFile("xe_config","Develop",config)){
|
||||
entry_dev->set_text(config);
|
||||
}
|
||||
readCfgFile("xe_config","Release_Path_Unix",config_unix);
|
||||
readCfgFile("xe_config","Release_Path_Win32",config_win32);
|
||||
|
||||
// std::string config;
|
||||
// if(readCfgFile("xe_config","Longterm",config)){
|
||||
// entry_lts->set_text(config);
|
||||
// }
|
||||
// if(readCfgFile("xe_config","Stable",config)){
|
||||
// entry_stable->set_text(config);
|
||||
// }
|
||||
// if(readCfgFile("xe_config","Develop",config)){
|
||||
// entry_dev->set_text(config);
|
||||
// }
|
||||
// readCfgFile("xe_config","Release_Path_Unix",config_unix);
|
||||
// readCfgFile("xe_config","Release_Path_Win32",config_win32);
|
||||
|
||||
// Use different path for Linux filesystem and Windows
|
||||
if(unix_file_system_detected()){
|
||||
if (unix_file_system_detected())
|
||||
{
|
||||
entry_path->set_text(config_unix);
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
entry_path->set_text(config_win32);
|
||||
}
|
||||
|
||||
|
@ -39,19 +61,26 @@ ref_Glade(ref_builder)
|
|||
btnpath->signal_clicked().connect(sigc::mem_fun(*this, &MyDialog::btnpath_clicked));
|
||||
}
|
||||
|
||||
void MyDialog::on_response(int response_id){
|
||||
void MyDialog::on_response(int response_id)
|
||||
{
|
||||
// Save Configs to a file
|
||||
if(response_id == Gtk::RESPONSE_OK){
|
||||
if (response_id == Gtk::RESPONSE_OK)
|
||||
{
|
||||
Glib::ustring config;
|
||||
std::fstream outfile;
|
||||
|
||||
// Initalize Config for path
|
||||
if(unix_file_system_detected()){
|
||||
if (unix_file_system_detected())
|
||||
{
|
||||
config_unix = entry_path->get_text();
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
config_win32 = entry_path->get_text();
|
||||
}
|
||||
// Open the config file
|
||||
outfile.open("xe_config",std::ios_base::out);
|
||||
outfile.open("xe_config.json", std::ios_base::out);
|
||||
/*OutPut contents to the file
|
||||
Simple Contents of xe_config:
|
||||
Longterm=x.x
|
||||
|
@ -60,25 +89,45 @@ void MyDialog::on_response(int response_id){
|
|||
Release_Path_Unix=/xxx/xxx
|
||||
Release_Path_Win32=X:\xxx\xxx
|
||||
*/
|
||||
if(outfile.is_open()){
|
||||
outfile<<"This is the config file of Xe Release"<<std::endl;
|
||||
outfile<<"See more on github.com/daleclack/Xe-Release"<<std::endl;
|
||||
outfile<<std::endl;
|
||||
config=entry_lts->get_text();
|
||||
outfile<<"Longterm="<<config<<std::endl;
|
||||
config=entry_stable->get_text();
|
||||
outfile<<"Stable="<<config<<std::endl;
|
||||
config=entry_dev->get_text();
|
||||
outfile<<"Develop="<<config<<std::endl;
|
||||
outfile<<"Release_Path_Unix="<<config_unix<<std::endl;
|
||||
outfile<<"Release_Path_Win32="<<config_win32<<std::endl;
|
||||
if (outfile.is_open())
|
||||
{
|
||||
// Create json object
|
||||
json out_data = json::parse(R"(
|
||||
{
|
||||
"Longterm":"",
|
||||
"Stable":"",
|
||||
"Develop":"",
|
||||
"Release_Path_Unix":"",
|
||||
"Release_Path_Win32":""
|
||||
}
|
||||
)");
|
||||
|
||||
// Load config to json file
|
||||
out_data["Longterm"] = entry_lts->get_text();
|
||||
out_data["Stable"] = entry_stable->get_text();
|
||||
out_data["Develop"] = entry_dev->get_text();
|
||||
out_data["Release_Path_Unix"] = config_unix;
|
||||
out_data["Release_Path_Win32"] = config_win32;
|
||||
outfile << out_data;
|
||||
// outfile<<"This is the config file of Xe Release"<<std::endl;
|
||||
// outfile<<"See more on github.com/daleclack/Xe-Release"<<std::endl;
|
||||
// outfile<<std::endl;
|
||||
// config=entry_lts->get_text();
|
||||
// outfile<<"Longterm="<<config<<std::endl;
|
||||
// config=entry_stable->get_text();
|
||||
// outfile<<"Stable="<<config<<std::endl;
|
||||
// config=entry_dev->get_text();
|
||||
// outfile<<"Develop="<<config<<std::endl;
|
||||
// outfile<<"Release_Path_Unix="<<config_unix<<std::endl;
|
||||
// outfile<<"Release_Path_Win32="<<config_win32<<std::endl;
|
||||
}
|
||||
outfile.close();
|
||||
}
|
||||
hide();
|
||||
}
|
||||
|
||||
MyDialog * MyDialog::create(Gtk::Window& parent){
|
||||
MyDialog *MyDialog::create(Gtk::Window &parent)
|
||||
{
|
||||
// Create a dialog
|
||||
auto builder = Gtk::Builder::create_from_resource("/org/gtk/daleclack/prefs.ui");
|
||||
|
||||
|
@ -89,7 +138,8 @@ MyDialog * MyDialog::create(Gtk::Window& parent){
|
|||
return dialog;
|
||||
}
|
||||
|
||||
void MyDialog::btnpath_clicked(){
|
||||
void MyDialog::btnpath_clicked()
|
||||
{
|
||||
// Create a Dialog
|
||||
dialog = Gtk::FileChooserNative::create("Select a folder", *this,
|
||||
Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER, "OK", "Cancel");
|
||||
|
@ -99,8 +149,10 @@ void MyDialog::btnpath_clicked(){
|
|||
dialog->show();
|
||||
}
|
||||
|
||||
void MyDialog::dialog_response(int response_id){
|
||||
if(response_id == Gtk::RESPONSE_ACCEPT){
|
||||
void MyDialog::dialog_response(int response_id)
|
||||
{
|
||||
if (response_id == Gtk::RESPONSE_ACCEPT)
|
||||
{
|
||||
Glib::ustring path = dialog->get_filename();
|
||||
entry_path->set_text(path);
|
||||
}
|
||||
|
@ -123,10 +175,12 @@ MsgBox::MsgBox(Gtk::Window &parent)
|
|||
vbox->pack_start(hbox);
|
||||
}
|
||||
|
||||
void MsgBox::Init(Glib::ustring msg){
|
||||
void MsgBox::Init(Glib::ustring msg)
|
||||
{
|
||||
msg_label.set_label(msg);
|
||||
}
|
||||
|
||||
void MsgBox::on_response(int response_id){
|
||||
void MsgBox::on_response(int response_id)
|
||||
{
|
||||
hide();
|
||||
}
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
#include <gtkmm.h>
|
||||
#include <fstream>
|
||||
#include "../cfgfile2/cfgfile.hh"
|
||||
#include "../json_nlohmann/json.hpp"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
class MyDialog : public Gtk::Dialog{
|
||||
public:
|
||||
|
@ -19,6 +21,9 @@ private:
|
|||
//Strings to store path on Windows and Unix-Like systems
|
||||
std::string config_win32,config_unix;
|
||||
|
||||
// Json data
|
||||
json data;
|
||||
|
||||
//Signal Handlers
|
||||
Glib::RefPtr<Gtk::FileChooserNative> dialog;
|
||||
void btnpath_clicked();
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue