mirror of https://github.com/odrling/Aegisub
Clean up AegisubLocale a bit
Don't let the user cancel the language selection dialog on first startup, and don't bother with the dialog at all if there's only one language available. Originally committed to SVN as r6602.
This commit is contained in:
parent
0b9a21bf82
commit
e120bec4f0
|
@ -34,9 +34,6 @@
|
||||||
/// @ingroup utility
|
/// @ingroup utility
|
||||||
///
|
///
|
||||||
|
|
||||||
|
|
||||||
///////////
|
|
||||||
// Headers
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#ifndef AGI_PRE
|
#ifndef AGI_PRE
|
||||||
|
@ -52,34 +49,17 @@
|
||||||
#include "aegisublocale.h"
|
#include "aegisublocale.h"
|
||||||
#include "standard_paths.h"
|
#include "standard_paths.h"
|
||||||
|
|
||||||
/// @brief Constructor
|
|
||||||
///
|
|
||||||
AegisubLocale::AegisubLocale () {
|
|
||||||
locale = NULL;
|
|
||||||
curCode = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// @brief DOCME
|
|
||||||
///
|
|
||||||
AegisubLocale::~AegisubLocale() {
|
AegisubLocale::~AegisubLocale() {
|
||||||
delete locale;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// @brief Initialize
|
|
||||||
/// @param language
|
|
||||||
///
|
|
||||||
void AegisubLocale::Init(int language) {
|
void AegisubLocale::Init(int language) {
|
||||||
if (language == -1) language = wxLANGUAGE_ENGLISH;
|
if (language == -1)
|
||||||
if (locale) delete locale;
|
language = wxLANGUAGE_ENGLISH;
|
||||||
|
|
||||||
if (!wxLocale::IsAvailable(language)) {
|
if (!wxLocale::IsAvailable(language))
|
||||||
language = wxLANGUAGE_UNKNOWN;
|
language = wxLANGUAGE_UNKNOWN;
|
||||||
}
|
|
||||||
|
|
||||||
curCode = language;
|
locale.reset(new wxLocale(language));
|
||||||
locale = new wxLocale(language);
|
|
||||||
|
|
||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
locale->AddCatalogLookupPathPrefix(StandardPaths::DecodePath("?data/locale/"));
|
locale->AddCatalogLookupPathPrefix(StandardPaths::DecodePath("?data/locale/"));
|
||||||
|
@ -93,13 +73,7 @@ void AegisubLocale::Init(int language) {
|
||||||
setlocale(LC_CTYPE, "C");
|
setlocale(LC_CTYPE, "C");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// @brief Pick a language
|
|
||||||
/// @return
|
|
||||||
///
|
|
||||||
int AegisubLocale::PickLanguage() {
|
int AegisubLocale::PickLanguage() {
|
||||||
// Get list
|
|
||||||
wxArrayInt langs = GetAvailableLanguages();
|
wxArrayInt langs = GetAvailableLanguages();
|
||||||
|
|
||||||
// Check if english is in it, else add it
|
// Check if english is in it, else add it
|
||||||
|
@ -114,31 +88,37 @@ int AegisubLocale::PickLanguage() {
|
||||||
langs.Insert(user, 0);
|
langs.Insert(user, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Nothing to pick
|
||||||
|
if (langs.empty()) return -1;
|
||||||
|
|
||||||
|
// Only one language, so don't bother asking the user
|
||||||
|
if (langs.size() == 1 && !locale)
|
||||||
|
return langs[0];
|
||||||
|
|
||||||
// Generate names
|
// Generate names
|
||||||
wxArrayString langNames;
|
wxArrayString langNames;
|
||||||
for (size_t i=0;i<langs.Count();i++) {
|
for (size_t i = 0; i < langs.size(); ++i)
|
||||||
langNames.Add(wxLocale::GetLanguageName(langs[i]));
|
langNames.Add(wxLocale::GetLanguageName(langs[i]));
|
||||||
}
|
|
||||||
|
|
||||||
// Nothing to pick
|
long style = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxOK | wxCENTRE;
|
||||||
if (langs.Count() == 0) return -1;
|
if (locale)
|
||||||
|
style |= wxCANCEL;
|
||||||
|
|
||||||
// Popup
|
wxSingleChoiceDialog dialog(NULL, "Please choose a language:", "Language", langNames, 0, style);
|
||||||
int picked = wxGetSingleChoiceIndex("Please choose a language:","Language",langNames,NULL,-1,-1,true,300,400);
|
if (dialog.ShowModal() == wxID_OK) {
|
||||||
if (picked == -1) return -1;
|
int picked = dialog.GetSelection();
|
||||||
|
if (locale && langs[picked] == locale->GetLanguage())
|
||||||
|
return -1;
|
||||||
return langs[picked];
|
return langs[picked];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// @brief Get list of available languages
|
|
||||||
///
|
|
||||||
wxArrayInt AegisubLocale::GetAvailableLanguages() {
|
wxArrayInt AegisubLocale::GetAvailableLanguages() {
|
||||||
wxArrayInt final;
|
wxArrayInt final;
|
||||||
|
|
||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
wxString temp1;
|
|
||||||
|
|
||||||
// Open directory
|
// Open directory
|
||||||
wxString folder = StandardPaths::DecodePath("?data/locale/");
|
wxString folder = StandardPaths::DecodePath("?data/locale/");
|
||||||
wxDir dir;
|
wxDir dir;
|
||||||
|
@ -146,19 +126,17 @@ wxArrayInt AegisubLocale::GetAvailableLanguages() {
|
||||||
if (!dir.Open(folder)) return final;
|
if (!dir.Open(folder)) return final;
|
||||||
|
|
||||||
// Enumerate folders
|
// Enumerate folders
|
||||||
|
wxString temp1;
|
||||||
for (bool cont = dir.GetFirst(&temp1, "", wxDIR_DIRS); cont; cont = dir.GetNext(&temp1)) {
|
for (bool cont = dir.GetFirst(&temp1, "", wxDIR_DIRS); cont; cont = dir.GetNext(&temp1)) {
|
||||||
// Check if .so exists inside folder
|
// Check if .so exists inside folder
|
||||||
wxFileName file(folder + temp1 + "/aegisub.mo");
|
if (wxFileName::FileExists(folder + temp1 + "/aegisub.mo")) {
|
||||||
if (file.FileExists()) {
|
|
||||||
const wxLanguageInfo *lang = wxLocale::FindLanguageInfo(temp1);
|
const wxLanguageInfo *lang = wxLocale::FindLanguageInfo(temp1);
|
||||||
if (lang) {
|
if (lang) {
|
||||||
final.Add(lang->Language);
|
final.Add(lang->Language);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
const char* langs[] = {
|
const char* langs[] = {
|
||||||
"ca",
|
"ca",
|
||||||
"cs",
|
"cs",
|
||||||
|
|
|
@ -34,33 +34,20 @@
|
||||||
/// @ingroup utility
|
/// @ingroup utility
|
||||||
///
|
///
|
||||||
|
|
||||||
|
#include <libaegisub/scoped_ptr.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//////////////
|
|
||||||
// Prototypes
|
|
||||||
class wxLocale;
|
class wxLocale;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// DOCME
|
/// DOCME
|
||||||
/// @class AegisubLocale
|
/// @class AegisubLocale
|
||||||
/// @brief DOCME
|
/// @brief DOCME
|
||||||
///
|
///
|
||||||
/// DOCME
|
/// DOCME
|
||||||
class AegisubLocale {
|
class AegisubLocale {
|
||||||
private:
|
agi::scoped_ptr<wxLocale> locale;
|
||||||
|
|
||||||
/// DOCME
|
|
||||||
wxLocale *locale;
|
|
||||||
wxArrayInt GetAvailableLanguages();
|
wxArrayInt GetAvailableLanguages();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/// DOCME
|
|
||||||
int curCode;
|
|
||||||
|
|
||||||
AegisubLocale();
|
|
||||||
~AegisubLocale();
|
~AegisubLocale();
|
||||||
void Init(int language);
|
void Init(int language);
|
||||||
int PickLanguage();
|
int PickLanguage();
|
||||||
|
|
|
@ -185,10 +185,9 @@ struct app_language : public Command {
|
||||||
|
|
||||||
void operator()(agi::Context *c) {
|
void operator()(agi::Context *c) {
|
||||||
// Get language
|
// Get language
|
||||||
int old = wxGetApp().locale.curCode;
|
|
||||||
int newCode = wxGetApp().locale.PickLanguage();
|
int newCode = wxGetApp().locale.PickLanguage();
|
||||||
// Is OK?
|
// Is OK?
|
||||||
if (newCode != -1 && newCode != old) {
|
if (newCode != -1) {
|
||||||
// Set code
|
// Set code
|
||||||
OPT_SET("App/Locale")->SetInt(newCode);
|
OPT_SET("App/Locale")->SetInt(newCode);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue