mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2024-11-26 13:48:38 -05:00
Merge pull request #110 from cjcliffe/save_window_pref
Save window prefs
This commit is contained in:
commit
d46e1b5b47
@ -114,6 +114,16 @@ void DeviceConfig::load(DataNode *node) {
|
||||
busy_lock.unlock();
|
||||
}
|
||||
|
||||
AppConfig::AppConfig() {
|
||||
winX.store(0);
|
||||
winY.store(0);
|
||||
winW.store(0);
|
||||
winH.store(0);
|
||||
winMax.store(false);
|
||||
themeId.store(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
DeviceConfig *AppConfig::getDevice(std::string deviceId) {
|
||||
if (deviceConfig.find(deviceId) == deviceConfig.end()) {
|
||||
@ -142,10 +152,58 @@ std::string AppConfig::getConfigDir() {
|
||||
return dataDir;
|
||||
}
|
||||
|
||||
|
||||
void AppConfig::setWindow(wxPoint winXY, wxSize winWH) {
|
||||
winX.store(winXY.x);
|
||||
winY.store(winXY.y);
|
||||
winW.store(winWH.x);
|
||||
winH.store(winWH.y);
|
||||
}
|
||||
|
||||
void AppConfig::setWindowMaximized(bool max) {
|
||||
winMax.store(max);
|
||||
}
|
||||
|
||||
bool AppConfig::getWindowMaximized() {
|
||||
return winMax.load();
|
||||
}
|
||||
|
||||
wxRect *AppConfig::getWindow() {
|
||||
wxRect *r = NULL;
|
||||
if (winH.load() && winW.load()) {
|
||||
r = new wxRect(winX.load(),winY.load(),winW.load(),winH.load());
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
void AppConfig::setTheme(int themeId) {
|
||||
this->themeId.store(themeId);
|
||||
}
|
||||
|
||||
int AppConfig::getTheme() {
|
||||
return themeId.load();
|
||||
}
|
||||
|
||||
|
||||
bool AppConfig::save() {
|
||||
DataTree cfg;
|
||||
|
||||
cfg.rootNode()->setName("cubicsdr_config");
|
||||
|
||||
if (winW.load() && winH.load()) {
|
||||
DataNode *window_node = cfg.rootNode()->newChild("window");
|
||||
|
||||
*window_node->newChild("x") = winX.load();
|
||||
*window_node->newChild("y") = winY.load();
|
||||
*window_node->newChild("w") = winW.load();
|
||||
*window_node->newChild("h") = winH.load();
|
||||
|
||||
*window_node->newChild("max") = winMax.load();
|
||||
|
||||
*window_node->newChild("theme") = themeId.load();
|
||||
}
|
||||
|
||||
DataNode *devices_node = cfg.rootNode()->newChild("devices");
|
||||
|
||||
std::map<std::string, DeviceConfig *>::iterator device_config_i;
|
||||
@ -154,6 +212,7 @@ bool AppConfig::save() {
|
||||
device_config_i->second->save(device_node);
|
||||
}
|
||||
|
||||
|
||||
std::string cfgFileDir = getConfigDir();
|
||||
|
||||
wxFileName cfgFile = wxFileName(cfgFileDir, "config.xml");
|
||||
@ -187,6 +246,37 @@ bool AppConfig::load() {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (cfg.rootNode()->hasAnother("window")) {
|
||||
int x,y,w,h;
|
||||
int max;
|
||||
|
||||
DataNode *win_node = cfg.rootNode()->getNext("window");
|
||||
|
||||
if (win_node->hasAnother("w") && win_node->hasAnother("h") && win_node->hasAnother("x") && win_node->hasAnother("y")) {
|
||||
win_node->getNext("x")->element()->get(x);
|
||||
win_node->getNext("y")->element()->get(y);
|
||||
win_node->getNext("w")->element()->get(w);
|
||||
win_node->getNext("h")->element()->get(h);
|
||||
|
||||
winX.store(x);
|
||||
winY.store(y);
|
||||
winW.store(w);
|
||||
winH.store(h);
|
||||
}
|
||||
|
||||
if (win_node->hasAnother("max")) {
|
||||
win_node->getNext("max")->element()->get(max);
|
||||
winMax.store(max?true:false);
|
||||
}
|
||||
|
||||
if (win_node->hasAnother("theme")) {
|
||||
int theme;
|
||||
win_node->getNext("theme")->element()->get(theme);
|
||||
themeId.store(theme);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (cfg.rootNode()->hasAnother("devices")) {
|
||||
DataNode *devices_node = cfg.rootNode()->getNext("devices");
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <wx/stdpaths.h>
|
||||
#include <wx/dir.h>
|
||||
#include <wx/filename.h>
|
||||
#include <wx/panel.h>
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
|
||||
@ -42,13 +43,26 @@ private:
|
||||
|
||||
class AppConfig {
|
||||
public:
|
||||
AppConfig();
|
||||
std::string getConfigDir();
|
||||
DeviceConfig *getDevice(std::string deviceId);
|
||||
|
||||
void setWindow(wxPoint winXY, wxSize winWH);
|
||||
wxRect *getWindow();
|
||||
|
||||
void setWindowMaximized(bool max);
|
||||
bool getWindowMaximized();
|
||||
|
||||
void setTheme(int themeId);
|
||||
int getTheme();
|
||||
|
||||
bool save();
|
||||
bool load();
|
||||
bool reset();
|
||||
|
||||
private:
|
||||
std::map<std::string, DeviceConfig *> deviceConfig;
|
||||
std::atomic_int winX,winY,winW,winH;
|
||||
std::atomic_bool winMax;
|
||||
std::atomic_int themeId;
|
||||
};
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
wxBEGIN_EVENT_TABLE(AppFrame, wxFrame)
|
||||
//EVT_MENU(wxID_NEW, AppFrame::OnNewWindow)
|
||||
EVT_MENU(wxID_CLOSE, AppFrame::OnClose)
|
||||
EVT_CLOSE(AppFrame::OnClose)
|
||||
EVT_MENU(wxID_ANY, AppFrame::OnMenu)
|
||||
EVT_COMMAND(wxID_ANY, wxEVT_THREAD, AppFrame::OnThread)
|
||||
EVT_IDLE(AppFrame::OnIdle)
|
||||
@ -190,13 +190,15 @@ AppFrame::AppFrame() :
|
||||
|
||||
menu = new wxMenu;
|
||||
|
||||
menu->AppendRadioItem(wxID_THEME_DEFAULT, "Default")->Check(true);
|
||||
menu->AppendRadioItem(wxID_THEME_RADAR, "RADAR");
|
||||
menu->AppendRadioItem(wxID_THEME_BW, "Black & White");
|
||||
menu->AppendRadioItem(wxID_THEME_SHARP, "Sharp");
|
||||
menu->AppendRadioItem(wxID_THEME_RAD, "Rad");
|
||||
menu->AppendRadioItem(wxID_THEME_TOUCH, "Touch");
|
||||
menu->AppendRadioItem(wxID_THEME_HD, "HD");
|
||||
int themeId = wxGetApp().getConfig()->getTheme();
|
||||
|
||||
menu->AppendRadioItem(wxID_THEME_DEFAULT, "Default")->Check(themeId==COLOR_THEME_DEFAULT);
|
||||
menu->AppendRadioItem(wxID_THEME_RADAR, "RADAR")->Check(themeId==COLOR_THEME_RADAR);
|
||||
menu->AppendRadioItem(wxID_THEME_BW, "Black & White")->Check(themeId==COLOR_THEME_BW);
|
||||
menu->AppendRadioItem(wxID_THEME_SHARP, "Sharp")->Check(themeId==COLOR_THEME_SHARP);
|
||||
menu->AppendRadioItem(wxID_THEME_RAD, "Rad")->Check(themeId==COLOR_THEME_RAD);
|
||||
menu->AppendRadioItem(wxID_THEME_TOUCH, "Touch")->Check(themeId==COLOR_THEME_TOUCH);
|
||||
menu->AppendRadioItem(wxID_THEME_HD, "HD")->Check(themeId==COLOR_THEME_HD);
|
||||
|
||||
menuBar->Append(menu, wxT("&Color Scheme"));
|
||||
|
||||
@ -302,8 +304,23 @@ AppFrame::AppFrame() :
|
||||
SetMenuBar(menuBar);
|
||||
|
||||
CreateStatusBar();
|
||||
SetClientSize(1280, 600);
|
||||
Centre();
|
||||
|
||||
wxRect *win = wxGetApp().getConfig()->getWindow();
|
||||
if (win) {
|
||||
this->SetPosition(win->GetPosition());
|
||||
this->SetClientSize(win->GetSize());
|
||||
} else {
|
||||
SetClientSize(1280, 600);
|
||||
Centre();
|
||||
}
|
||||
bool max = wxGetApp().getConfig()->getWindowMaximized();
|
||||
|
||||
if (max) {
|
||||
this->Maximize();
|
||||
}
|
||||
|
||||
ThemeMgr::mgr.setTheme(wxGetApp().getConfig()->getTheme());
|
||||
|
||||
Show();
|
||||
|
||||
#ifdef _WIN32
|
||||
@ -506,8 +523,12 @@ void AppFrame::OnMenu(wxCommandEvent& event) {
|
||||
|
||||
}
|
||||
|
||||
void AppFrame::OnClose(wxCommandEvent& WXUNUSED(event)) {
|
||||
Close(false);
|
||||
void AppFrame::OnClose(wxCloseEvent& event) {
|
||||
wxGetApp().getConfig()->setWindow(this->GetPosition(), this->GetClientSize());
|
||||
wxGetApp().getConfig()->setWindowMaximized(this->IsMaximized());
|
||||
wxGetApp().getConfig()->setTheme(ThemeMgr::mgr.getTheme());
|
||||
wxGetApp().getConfig()->save();
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
void AppFrame::OnNewWindow(wxCommandEvent& WXUNUSED(event)) {
|
||||
|
@ -65,7 +65,7 @@ public:
|
||||
|
||||
private:
|
||||
void OnMenu(wxCommandEvent& event);
|
||||
void OnClose(wxCommandEvent& event);
|
||||
void OnClose(wxCloseEvent& event);
|
||||
void OnNewWindow(wxCommandEvent& event);
|
||||
void OnIdle(wxIdleEvent& event);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user