add settings data for general page, query available languages
parent
9743b0efc5
commit
c5f497ec1d
|
@ -51,7 +51,7 @@ static void do_log(enum log_type type, const char *msg, va_list args)
|
|||
|
||||
void OBSApp::InitGlobalConfigDefaults()
|
||||
{
|
||||
config_set_default_string(globalConfig, "General", "Language", "en-US");
|
||||
config_set_default_string(globalConfig, "General", "Language", "en");
|
||||
config_set_default_int(globalConfig, "Window", "PosX", -1);
|
||||
config_set_default_int(globalConfig, "Window", "PosY", -1);
|
||||
config_set_default_int(globalConfig, "Window", "SizeX", -1);
|
||||
|
|
|
@ -41,6 +41,8 @@ public:
|
|||
virtual int OnExit();
|
||||
virtual void CleanUp();
|
||||
|
||||
inline config_t GlobalConfig() {return globalConfig;}
|
||||
|
||||
inline const char *GetString(const char *lookupVal)
|
||||
{
|
||||
return textLookup.GetString(lookupVal);
|
||||
|
@ -49,4 +51,6 @@ public:
|
|||
|
||||
wxDECLARE_APP(OBSApp);
|
||||
|
||||
inline config_t GetGlobalConfig() {return wxGetApp().GlobalConfig();}
|
||||
|
||||
#define Str(lookupVal) wxGetApp().GetString(lookupVal)
|
||||
|
|
|
@ -18,10 +18,15 @@
|
|||
#include <sstream>
|
||||
#include "platform.hpp"
|
||||
|
||||
#include <util/platform.h>
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
bool GetDataFilePath(const char *data, string &output)
|
||||
{
|
||||
stringstream str;
|
||||
str << "../../data/obs-studio/" << data;
|
||||
output = str.str();
|
||||
return true;
|
||||
return os_file_exists(output.c_str());
|
||||
}
|
||||
|
|
|
@ -15,25 +15,87 @@
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
|
||||
#include "settings-basic.hpp"
|
||||
#include "obs-app.hpp"
|
||||
|
||||
#include <string>
|
||||
using namespace std;
|
||||
#include "settings-basic.hpp"
|
||||
#include "window-settings-basic.hpp"
|
||||
#include "platform.hpp"
|
||||
|
||||
class GeneralSettings : public BasicSettingsData {
|
||||
ConfigFile localeIni;
|
||||
|
||||
int AddLanguage(const char *tag);
|
||||
void FillLanguageList(const char *currentLang);
|
||||
|
||||
public:
|
||||
GeneralSettings(OBSBasicSettings *window);
|
||||
|
||||
virtual void Apply();
|
||||
};
|
||||
|
||||
GeneralSettings::GeneralSettings(OBSBasicSettings *window)
|
||||
: BasicSettingsData(window)
|
||||
class LanguageInfo : public wxClientData {
|
||||
public:
|
||||
const char *tag;
|
||||
const char *name;
|
||||
const char *subLang;
|
||||
bool isDefault;
|
||||
|
||||
inline LanguageInfo(config_t config, const char *tag)
|
||||
: wxClientData (),
|
||||
tag (tag),
|
||||
name (config_get_string(config, tag, "Name")),
|
||||
subLang (config_get_string(config, tag, "SubLang")),
|
||||
isDefault (config_get_bool(config, tag, "DefaultSubLang"))
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
int GeneralSettings::AddLanguage(const char *tag)
|
||||
{
|
||||
LanguageInfo *info = new LanguageInfo(localeIni, tag);
|
||||
return window->languageList->Append(wxString(info->name, wxConvUTF8),
|
||||
info);
|
||||
}
|
||||
|
||||
void GeneralSettings::FillLanguageList(const char *currentLang)
|
||||
{
|
||||
size_t numSections = config_num_sections(localeIni);
|
||||
for (size_t i = 0; i < numSections; i++) {
|
||||
const char *lang = config_get_section(localeIni, i);
|
||||
int idx = AddLanguage(lang);
|
||||
|
||||
if (strcmp(lang, currentLang) == 0)
|
||||
window->languageList->SetSelection(idx);
|
||||
}
|
||||
}
|
||||
|
||||
GeneralSettings::GeneralSettings(OBSBasicSettings *window)
|
||||
: BasicSettingsData (window)
|
||||
{
|
||||
string path;
|
||||
if (!GetDataFilePath("locale/locale.ini", path))
|
||||
throw "Could not find locale/locale.ini path";
|
||||
if (localeIni.Open(path.c_str(), CONFIG_OPEN_EXISTING) != 0)
|
||||
throw "Could not open locale.ini";
|
||||
|
||||
const char *currentLang = config_get_string(GetGlobalConfig(),
|
||||
"General", "Language");
|
||||
FillLanguageList(currentLang);
|
||||
}
|
||||
|
||||
void GeneralSettings::Apply()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
BasicSettingsData *CreateBasicGeneralSettings(OBSBasicSettings *window)
|
||||
{
|
||||
BasicSettingsData *data = NULL;
|
||||
|
||||
try {
|
||||
data = new GeneralSettings(window);
|
||||
} catch (const char *error) {
|
||||
blog(LOG_ERROR, "CreateBasicGeneralSettings failed: %s", error);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,8 @@
|
|||
#pragma once
|
||||
|
||||
#include "settings.hpp"
|
||||
#include "window-settings-basic.hpp"
|
||||
|
||||
class OBSBasicSettings;
|
||||
|
||||
class BasicSettingsData : public SettingsData {
|
||||
protected:
|
||||
|
@ -27,3 +28,5 @@ protected:
|
|||
public:
|
||||
inline BasicSettingsData(OBSBasicSettings *window) : window(window) {}
|
||||
};
|
||||
|
||||
BasicSettingsData *CreateBasicGeneralSettings(OBSBasicSettings *window);
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
OBSBasicSettings::OBSBasicSettings(wxWindow *parent)
|
||||
: OBSBasicSettingsBase(parent)
|
||||
{
|
||||
unique_ptr<BasicSettingsData> data(CreateBasicGeneralSettings(this));
|
||||
settings = move(data);
|
||||
}
|
||||
|
||||
void OBSBasicSettings::PageChanged(wxListbookEvent &event)
|
||||
|
|
|
@ -18,9 +18,14 @@
|
|||
#pragma once
|
||||
|
||||
#include "forms/OBSWindows.h"
|
||||
#include "settings-basic.hpp"
|
||||
|
||||
#include <memory>
|
||||
using namespace std;
|
||||
|
||||
class OBSBasicSettings : public OBSBasicSettingsBase {
|
||||
protected:
|
||||
unique_ptr<BasicSettingsData> settings;
|
||||
|
||||
virtual void PageChanged(wxListbookEvent &event);
|
||||
virtual void PageChanging(wxListbookEvent &event);
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
#ifdef _
|
||||
#undef _
|
||||
#define _(str) Str(str)
|
||||
#define _(str) wxString(Str(str), wxConvUTF8)
|
||||
#endif
|
||||
|
||||
class DialogSubclass : public wxDialog {
|
||||
|
|
Loading…
Reference in New Issue