summaryrefslogtreecommitdiffstats
path: root/Project/main.cpp
diff options
context:
space:
mode:
authorThales Lima Oliveira <thaleslima.ufu@gmail.com>2017-08-10 18:07:02 -0300
committerThales Lima Oliveira <thaleslima.ufu@gmail.com>2017-08-10 18:07:02 -0300
commite5f19af9a5829a307951785e850e53fc4fcfac90 (patch)
tree5292932b350eac34b400c81cd4a68d2356fd835c /Project/main.cpp
parent8a1ffbc01135a1466ad7400518e4c56a4bdc3af5 (diff)
downloadPSP.git-e5f19af9a5829a307951785e850e53fc4fcfac90.tar.gz
PSP.git-e5f19af9a5829a307951785e850e53fc4fcfac90.tar.xz
PSP.git-e5f19af9a5829a307951785e850e53fc4fcfac90.zip
Model 1 machine fixed, init file under implementation
Diffstat (limited to 'Project/main.cpp')
-rw-r--r--Project/main.cpp69
1 files changed, 65 insertions, 4 deletions
diff --git a/Project/main.cpp b/Project/main.cpp
index e24860d..c4c6e40 100644
--- a/Project/main.cpp
+++ b/Project/main.cpp
@@ -2,17 +2,76 @@
#include <wx/event.h>
#include <wx/image.h>
#include <wx/stdpaths.h>
+#include <wx/textfile.h>
#include "MainFrame.h"
+#include "PropertiesData.h"
// Define the MainApp
class MainApp : public wxApp
{
-public:
+ public:
MainApp() {}
virtual ~MainApp() {}
- void LoadCatalogs(wxLocale* locale)
+ void LoadInitFile(PropertiesData* propertiesData)
{
+ wxTextFile file("config.ini");
+ auto data = propertiesData->GetGeneralPropertiesData();
+
+ if(!file.Open()) {
+ // Create default init file.
+ wxString defaultInitFile = "lang=en\ntheme=light\n";
+
+ file.Create();
+ file.AddLine(defaultInitFile);
+ file.Write();
+ file.Close();
+
+ data.language = wxLANGUAGE_ENGLISH;
+ data.theme = THEME_LIGHT;
+ propertiesData->SetGeneralPropertiesData(data);
+ }
+
+ wxString line;
+ for(line = file.GetFirstLine(); !file.Eof(); line = file.GetNextLine()) {
+ wxString tag = "";
+ wxString tagValue = "";
+ bool parseValue = false;
+ for(unsigned int i = 0; i < line.Len(); ++i) {
+ if(line[i] == '=') {
+ parseValue = true;
+ } else {
+ if(parseValue)
+ tagValue += line[i];
+ else
+ tag += line[i];
+ }
+ }
+ // Language
+ if(tag == "lang") {
+ if(tagValue == "pt-br" || tagValue == "pt") {
+ data.language = wxLANGUAGE_PORTUGUESE_BRAZILIAN;
+ } else if(tagValue == "en" || tagValue == "en-us" || tagValue == "en-uk") {
+ data.language = wxLANGUAGE_ENGLISH;
+ }
+ }
+ if(tag == "theme") {
+ if(tagValue == "light") {
+ data.theme = THEME_LIGHT;
+ } else if(tagValue == "dark") {
+ data.theme = THEME_DARK;
+ }
+ }
+ }
+ file.Close();
+
+ propertiesData->SetGeneralPropertiesData(data);
+ }
+
+ void LoadCatalogs(wxLocale* locale, PropertiesData* propertiesData)
+ {
+ LoadInitFile(propertiesData);
+
// Load computer settings.
locale->Init(locale->GetSystemLanguage(), wxLOCALE_DONT_LOAD_DEFAULT);
@@ -29,10 +88,12 @@ public:
wxImage::AddHandler(new wxPNGHandler);
wxImage::AddHandler(new wxJPEGHandler);
+ PropertiesData* propertiesData = new PropertiesData();
+
wxLocale* locale = new wxLocale();
- LoadCatalogs(locale);
+ LoadCatalogs(locale, propertiesData);
- MainFrame* mainFrame = new MainFrame(NULL, locale);
+ MainFrame* mainFrame = new MainFrame(NULL, locale, propertiesData);
SetTopWindow(mainFrame);
return GetTopWindow()->Show();
}