Fix background config
This commit is contained in:
parent
b8ee36433d
commit
97e35965f1
|
@ -8,17 +8,17 @@ class ModelColumns : public Glib::Object
|
|||
public:
|
||||
// Create a new object
|
||||
static Glib::RefPtr<ModelColumns> create(Glib::ustring &branch1,
|
||||
Glib::ustring &version1, guint mode1)
|
||||
Glib::ustring &version1, guint mode2)
|
||||
{
|
||||
return Glib::make_refptr_for_instance<ModelColumns>(
|
||||
new ModelColumns(branch1, version1, mode1));
|
||||
new ModelColumns(branch1, version1, mode2));
|
||||
}
|
||||
static Glib::RefPtr<ModelColumns> create(const char *branch1,
|
||||
const char *version1, guint mode1)
|
||||
const char *version1, guint mode2)
|
||||
{
|
||||
Glib::ustring temp_branch(branch1), temp_version(version1);
|
||||
return Glib::make_refptr_for_instance<ModelColumns>(
|
||||
new ModelColumns(temp_branch, temp_version, mode1));
|
||||
new ModelColumns(temp_branch, temp_version, mode2));
|
||||
}
|
||||
|
||||
// Get Value of branch and version
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "MyPrefs.hh"
|
||||
#include "xerelease.hh"
|
||||
|
||||
MyPrefs::MyPrefs(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &ref_builder)
|
||||
: Gtk::Box(cobject),
|
||||
|
@ -25,9 +26,11 @@ MyPrefs::MyPrefs(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &ref_
|
|||
selection = Gtk::NoSelection::create(ver_list);
|
||||
|
||||
// List content for test
|
||||
ver_list->append(ModelColumns::create("Longterm", "5.15", 0));
|
||||
ver_list->append(ModelColumns::create("Stable", "9.1", 1));
|
||||
ver_list->append(ModelColumns::create("Develop", "-1", 1));
|
||||
// ver_list->append(ModelColumns::create("Longterm", "5.15", 0));
|
||||
// ver_list->append(ModelColumns::create("Stable", "9.1", 1));
|
||||
// ver_list->append(ModelColumns::create("Develop", "-1", 1));
|
||||
load_config();
|
||||
apply_config();
|
||||
version_view.set_model(selection);
|
||||
|
||||
// Add Column View
|
||||
|
@ -58,12 +61,39 @@ MyPrefs::MyPrefs(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &ref_
|
|||
version_view.append_column(mode_column);
|
||||
}
|
||||
|
||||
void MyPrefs::load_config()
|
||||
{
|
||||
// Open the json file
|
||||
std::fstream json_file;
|
||||
json_file.open("xe_config.json", std::ios_base::in);
|
||||
if (json_file.is_open())
|
||||
{
|
||||
data = json::parse(json_file);
|
||||
}
|
||||
else
|
||||
{
|
||||
data = json::parse(
|
||||
R"({
|
||||
"Branches": ["Longterm","Stable","Develop"],
|
||||
"Modes": [0,1,1],
|
||||
"Release_Path_Darwin": "./",
|
||||
"Release_Path_Unix": "./",
|
||||
"Release_Path_Win32": "./",
|
||||
"Versions": ["5.15","9.1","<empty>"],
|
||||
"background": 3,
|
||||
"dark_mode": false
|
||||
})");
|
||||
}
|
||||
data_backup = data;
|
||||
json_config_init(data);
|
||||
}
|
||||
|
||||
void MyPrefs::btnok_clicked()
|
||||
{
|
||||
// Save Configs to a file
|
||||
Glib::ustring config;
|
||||
std::fstream outfile;
|
||||
|
||||
|
||||
// Config for Branches, Versions and Modes
|
||||
str_vec branches, versions;
|
||||
std::vector<guint> modes;
|
||||
|
@ -116,7 +146,7 @@ void MyPrefs::btnok_clicked()
|
|||
)");
|
||||
|
||||
// Get Branchs, Versions and Modes
|
||||
for(int i = 0; i < ver_list->get_n_items(); i++)
|
||||
for (int i = 0; i < ver_list->get_n_items(); i++)
|
||||
{
|
||||
// Get Item
|
||||
auto item = ver_list->get_item(i);
|
||||
|
@ -141,6 +171,9 @@ void MyPrefs::btnok_clicked()
|
|||
// Set Current json data
|
||||
data = out_data;
|
||||
|
||||
// Update data for xe release core
|
||||
json_config_init(data);
|
||||
|
||||
// Show Dialog
|
||||
msg_dialog1.Init("Config File Saved!");
|
||||
msg_dialog1.present();
|
||||
|
@ -154,17 +187,23 @@ void MyPrefs::btnreset_clicked()
|
|||
data = data_backup;
|
||||
|
||||
// Reset content of entries
|
||||
reset_entries();
|
||||
apply_config();
|
||||
|
||||
// Update data for xe release core
|
||||
json_config_init(data);
|
||||
|
||||
// Show Dialog
|
||||
msg_dialog1.Init("Config Reseted!\n Press \"OK\" to save.");
|
||||
msg_dialog1.present();
|
||||
}
|
||||
|
||||
void MyPrefs::reset_entries()
|
||||
void MyPrefs::apply_config()
|
||||
{
|
||||
str_vec branchs_vec, versions_vec;
|
||||
// str_vec branches_vec, versions_vec, modes_vec;
|
||||
// Read json data
|
||||
str_vec branches_vec = data["Branches"];
|
||||
str_vec versions_vec = data["Versions"];
|
||||
std::vector<guint> modes_vec = data["Modes"];
|
||||
config_unix = data["Release_Path_Unix"];
|
||||
config_win32 = data["Release_Path_Win32"];
|
||||
config_darwin = data["Release_Path_Darwin"];
|
||||
|
@ -172,6 +211,11 @@ void MyPrefs::reset_entries()
|
|||
background_id = data["background"];
|
||||
|
||||
// Set text from json file data
|
||||
for (int i = 0; i < branches_vec.size(); i++)
|
||||
{
|
||||
ver_list->append(ModelColumns::create(
|
||||
branches_vec[i].c_str(), versions_vec[i].c_str(), modes_vec[i]));
|
||||
}
|
||||
|
||||
// Use different path for Linux filesystem and Windows
|
||||
switch (get_os_type())
|
||||
|
@ -325,6 +369,13 @@ int MyPrefs::get_background_id()
|
|||
return background_id;
|
||||
}
|
||||
|
||||
void MyPrefs::set_background_id(int back_id)
|
||||
{
|
||||
// Set background id
|
||||
background_id = back_id;
|
||||
btnok_clicked();
|
||||
}
|
||||
|
||||
MyListStore MyPrefs::get_model()
|
||||
{
|
||||
// The store for the dropdown and list
|
||||
|
|
|
@ -17,8 +17,15 @@ public:
|
|||
MyPrefs(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &ref_builder);
|
||||
static MyPrefs *create();
|
||||
void set_parent_win(Gtk::Window *parent);
|
||||
|
||||
// xe_config file management
|
||||
void load_config();
|
||||
void save_config_now();
|
||||
|
||||
// Background preferences
|
||||
void set_background_id(int back_id);
|
||||
int get_background_id();
|
||||
|
||||
MyListStore get_model();
|
||||
int background_id = 3;
|
||||
|
||||
|
@ -73,7 +80,7 @@ private:
|
|||
void dialog_response(int response_id);
|
||||
void btnok_clicked();
|
||||
void btnreset_clicked();
|
||||
void reset_entries();
|
||||
void apply_config();
|
||||
};
|
||||
|
||||
// static inline bool unix_file_system_detected()
|
||||
|
|
|
@ -84,6 +84,7 @@ MyWin::MyWin()
|
|||
// Set background from the config
|
||||
// The vaild background id is 1 to 3
|
||||
// else the background 3 will load
|
||||
back_id = prefs->get_background_id();
|
||||
switch (back_id)
|
||||
{
|
||||
case 1:
|
||||
|
@ -192,8 +193,9 @@ void MyWin::background1()
|
|||
// Update config
|
||||
if (!start)
|
||||
{
|
||||
prefs->background_id = 1;
|
||||
prefs->save_config_now();
|
||||
prefs->set_background_id(1);
|
||||
// prefs->background_id = 1;
|
||||
// prefs->save_config_now();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -214,8 +216,9 @@ void MyWin::background2()
|
|||
// Update config
|
||||
if (!start)
|
||||
{
|
||||
prefs->background_id = 2;
|
||||
prefs->save_config_now();
|
||||
prefs->set_background_id(2);
|
||||
// prefs->background_id = 2;
|
||||
// prefs->save_config_now();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -236,8 +239,9 @@ void MyWin::background3()
|
|||
// Update config
|
||||
if (!start)
|
||||
{
|
||||
prefs->background_id = 3;
|
||||
prefs->save_config_now();
|
||||
prefs->set_background_id(3);
|
||||
// prefs->background_id = 3;
|
||||
// prefs->save_config_now();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -116,7 +116,7 @@ static void path_translate(char *result, const char *version)
|
|||
}
|
||||
}
|
||||
|
||||
void release_mode_1(struct tm *local, const XeVer &version1, char *callback_str)
|
||||
void get_release_str(struct tm *local, const XeVer &version1, char *callback_str)
|
||||
{
|
||||
// Print Version of release mode 1 in the file
|
||||
char filename[MAX_PATH];
|
||||
|
@ -141,30 +141,6 @@ void release_mode_1(struct tm *local, const XeVer &version1, char *callback_str)
|
|||
return;
|
||||
}
|
||||
|
||||
void release_mode_2(struct tm *local, const XeVer &version1, char *callback_str)
|
||||
{
|
||||
// Print Version of release mode 2 in the file
|
||||
char filename[57];
|
||||
path_translate(filename, version1.version);
|
||||
// sprintf(filename, "xe-%c.x", rel[0]);
|
||||
int devel1; // stable release version
|
||||
int year2 = local->tm_year + 1900,
|
||||
month2 = local->tm_mon + 1, day2 = local->tm_mday;
|
||||
// get release version
|
||||
devel1 = total_year_day(version1.year, year2) -
|
||||
total_day(version1.year, stable_month, version1.day) +
|
||||
total_day(year2, month2, day2);
|
||||
snprintf(callback_str, 57, "Xeinit %s Version:%s.%d\n",
|
||||
version1.branch, version1.version, devel1);
|
||||
freopen(filename, "a", stdout);
|
||||
// put all output in the release file
|
||||
// output:development branch time in xe-release
|
||||
printf("%4d-%02d-%02d ", local->tm_year + 1900, local->tm_mon + 1, local->tm_mday);
|
||||
printf("%s.%d build:%d\n", version1.version, devel1, xeapi1(local));
|
||||
fclose(stdout);
|
||||
return;
|
||||
}
|
||||
|
||||
void json_config_init(json &user_data)
|
||||
{
|
||||
data1 = user_data;
|
||||
|
|
|
@ -18,9 +18,7 @@ int total_day(int year,int month,int day);
|
|||
|
||||
int total_year_day(int year1,int year2);
|
||||
|
||||
void release_mode_1(struct tm *local,const XeVer &version1, char *callback_str);
|
||||
|
||||
void release_mode_2(struct tm *local,const XeVer &version1, char *callback_str);
|
||||
void get_release_str(struct tm *local,const XeVer &version1, char *callback_str);
|
||||
|
||||
void json_config_init(json &user_data);
|
||||
|
||||
|
|
Loading…
Reference in New Issue