fixed locale code, added locale files, made wx use locale files, fixed some bugs, and added platform-specific files to the main program

This commit is contained in:
jp9000
2013-12-07 10:22:56 -07:00
parent a899606d53
commit 70290b8c2b
21 changed files with 278 additions and 30 deletions

View File

@@ -29,12 +29,24 @@ include_directories(SYSTEM ${obs_SOURCE_DIR}/libobs)
link_libraries(${wxWidgets_LIBRARIES} libobs)
if(WIN32)
set(obs_platform_src
platform-windows.cpp)
elseif(APPLE)
set(obs_platform_src
platform-osx.cpp)
elseif(UNIX)
set(obs_platform_src
platform-nix.cpp)
endif()
add_executable(obs
window-main-basic.cpp
wx-subclass.cpp
wx-wrappers.cpp
obs-app.cpp
forms/OBSWindows.cpp)
forms/OBSWindows.cpp
${obs_platform_src})
if(APPLE)
set_target_properties(obs PROPERTIES

View File

@@ -17,3 +17,15 @@ obs_SOURCES = window-main-basic.cpp \
wx-subclass.cpp \
wx-wrappers.cpp \
forms/OBSWindows.cpp
if OS_WIN
obs_SOURCES += platform-windows.cpp
endif
if OS_OSX
obs_SOURCES += platform-osx.cpp
endif
if OS_NIX
obs_SOURCES += platform-nix.cpp
endif

View File

@@ -24,6 +24,7 @@
#include "window-main-basic.hpp"
#include "obs-wrappers.hpp"
#include "wx-wrappers.hpp"
#include "platform.hpp"
using namespace std;
@@ -50,6 +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_int(globalConfig, "Window", "PosX", -1);
config_set_default_int(globalConfig, "Window", "PosY", -1);
config_set_default_int(globalConfig, "Window", "SizeX", -1);
@@ -59,7 +61,7 @@ void OBSApp::InitGlobalConfigDefaults()
static bool do_mkdir(const char *path)
{
if (os_mkdir(path) == MKDIR_ERROR) {
blog(LOG_ERROR, "Failed to create directory %s", path);
OBSErrorBox(NULL, "Failed to create directory %s", path);
return false;
}
@@ -84,7 +86,7 @@ bool OBSApp::InitGlobalConfig()
stringstream str;
if (!homePath) {
blog(LOG_ERROR, "Failed to get home path");
OBSErrorBox(NULL, "Failed to get home path");
return false;
}
@@ -93,7 +95,7 @@ bool OBSApp::InitGlobalConfig()
int errorcode = globalConfig.Open(path.c_str(), CONFIG_OPEN_ALWAYS);
if (errorcode != CONFIG_SUCCESS) {
blog(LOG_ERROR, "Failed to open global.ini: %d", errorcode);
OBSErrorBox(NULL, "Failed to open global.ini: %d", errorcode);
return false;
}
@@ -101,6 +103,27 @@ bool OBSApp::InitGlobalConfig()
return true;
}
bool OBSApp::InitLocale()
{
const char *lang = config_get_string(globalConfig, "General",
"Language");
stringstream file;
file << "locale/" << lang << ".txt";
string path;
if (!GetDataFilePath(file.str().c_str(), path)) {
/* use en-US by default if language file is not found */
if (!GetDataFilePath("locale/en-US.txt", path)) {
OBSErrorBox(NULL, "Failed to open locale file");
return false;
}
}
textLookup = text_lookup_create(path.c_str());
return true;
}
bool OBSApp::OnInit()
{
base_set_log_handler(do_log);
@@ -111,6 +134,8 @@ bool OBSApp::OnInit()
return false;
if (!InitGlobalConfig())
return false;
if (!InitLocale())
return false;
if (!obs_startup())
return false;
@@ -120,6 +145,7 @@ bool OBSApp::OnInit()
OBSBasic *mainWindow = new OBSBasic();
/* this is a test */
struct obs_video_info ovi;
ovi.graphics_module = "libobs-opengl";
ovi.fps_num = 30000;

View File

@@ -28,16 +28,25 @@ public:
class OBSApp : public OBSAppBase {
ConfigFile globalConfig;
TextLookup textLookup;
wxFrame *dummyWindow;
bool InitGlobalConfig();
void InitGlobalConfigDefaults();
bool InitConfigDefaults();
bool InitLocale();
public:
virtual bool OnInit();
virtual int OnExit();
virtual void CleanUp();
inline const char *GetString(const char *lookupVal)
{
return textLookup.GetString(lookupVal);
}
};
wxDECLARE_APP(OBSApp);
#define Str(lookupVal) wxGetApp().GetString(lookupVal)

View File

@@ -21,6 +21,7 @@
#include <stdarg.h>
#include <util/config-file.h>
#include <util/text-lookup.h>
#include <obs.h>
/* RAII wrappers */
@@ -79,6 +80,33 @@ public:
inline operator config_t() {return config;}
};
class TextLookup {
lookup_t lookup;
public:
inline TextLookup() : lookup(NULL) {}
inline TextLookup(lookup_t lookup) : lookup(lookup) {}
inline ~TextLookup() {text_lookup_destroy(lookup);}
inline TextLookup& operator=(lookup_t val)
{
text_lookup_destroy(lookup);
lookup = val;
return *this;
}
inline operator lookup_t() {return lookup;}
inline const char *GetString(const char *lookupVal)
{
const char *out;
if (!text_lookup_getstr(lookup, lookupVal, &out))
return lookupVal;
return out;
}
};
class OBSSource {
obs_source_t source;

25
obs/platform-nix.cpp Normal file
View File

@@ -0,0 +1,25 @@
/******************************************************************************
Copyright (C) 2013 by Hugh Bailey <obs.jim@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
#include <sstream>
#include "platform.hpp"
bool GetDataFilePath(const char *data, string &output)
{
// TODO
return true;
}

25
obs/platform-osx.cpp Normal file
View File

@@ -0,0 +1,25 @@
/******************************************************************************
Copyright (C) 2013 by Hugh Bailey <obs.jim@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
#include <sstream>
#include "platform.hpp"
bool GetDataFilePath(const char *data, string &output)
{
// TODO
return true;
}

27
obs/platform-windows.cpp Normal file
View File

@@ -0,0 +1,27 @@
/******************************************************************************
Copyright (C) 2013 by Hugh Bailey <obs.jim@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
#include <sstream>
#include "platform.hpp"
bool GetDataFilePath(const char *data, string &output)
{
stringstream str;
str << "../../data/obs-studio/" << data;
output = str.str();
return true;
}

24
obs/platform.hpp Normal file
View File

@@ -0,0 +1,24 @@
/******************************************************************************
Copyright (C) 2013 by Hugh Bailey <obs.jim@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
#pragma once
#include <string>
using namespace std;
/* Gets the path of obs-studio specific data files (such as locale) */
bool GetDataFilePath(const char *data, string &path);

View File

@@ -19,6 +19,8 @@
#include <wx/frame.h>
#include <wx/listctrl.h>
#include "obs-app.hpp"
/*
* Fixes windows fonts to be default dialog fonts (I don't give a crap what
* microsoft "recommends", the fonts they recommend look like utter garbage)
@@ -26,7 +28,7 @@
#ifdef _
#undef _
#define _(str) str
#define _(str) Str(str)
#endif
class WindowSubclass : public wxFrame {

View File

@@ -16,6 +16,7 @@
******************************************************************************/
#include <wx/window.h>
#include <wx/msgdlg.h>
#include <obs.h>
#include "wx-wrappers.hpp"
@@ -31,3 +32,16 @@ gs_window WxToGSWindow(const wxWindow *wxwin)
#endif
return window;
}
void OBSErrorBox(wxWindow *parent, const char *message, ...)
{
va_list args;
char output[4096];
va_start(args, message);
vsnprintf(output, 4095, message, args);
va_end(args);
wxMessageBox(message, "Error");
blog(LOG_ERROR, "%s", output);
}

View File

@@ -21,3 +21,4 @@ struct gs_window;
class wxWindow;
gs_window WxToGSWindow(const wxWindow *window);
void OBSErrorBox(wxWindow *parent, const char *message, ...);