summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2014-03-23 14:26:29 +0000
committerGeorge Hazan <george.hazan@gmail.com>2014-03-23 14:26:29 +0000
commit58002bcdddc61a9290bcfd0459c38ea044f88de7 (patch)
treee97f6a25d08956254a1e8177e78688d16ecc49ae /src/modules
parentfb86ce59e1c9970560cb3b4482c798d7572edee7 (diff)
ability to select & store the langpack chosen
git-svn-id: http://svn.miranda-ng.org/main/trunk@8702 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/langpack/langpack.cpp135
-rw-r--r--src/modules/langpack/langpack.h63
-rw-r--r--src/modules/langpack/lpopts.cpp189
3 files changed, 387 insertions, 0 deletions
diff --git a/src/modules/langpack/langpack.cpp b/src/modules/langpack/langpack.cpp
new file mode 100644
index 0000000000..56fd08f64f
--- /dev/null
+++ b/src/modules/langpack/langpack.cpp
@@ -0,0 +1,135 @@
+/*
+
+Miranda NG: the free IM client for Microsoft* Windows*
+
+Copyright (c) 2012-14 Miranda NG project (http://miranda-ng.org),
+Copyright (c) 2000-12 Miranda IM project,
+all portions of this codebase are copyrighted to the people
+listed in contributors.txt.
+
+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, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#include "..\..\core\commonheaders.h"
+#include "langpack.h"
+
+MIR_CORE_DLL(int) LoadLangPackDescr(const TCHAR *szLangPack, LANGPACK_INFO *lpInfo);
+
+BOOL EnumLangpacks(ENUM_PACKS_CALLBACK callback, WPARAM wParam, LPARAM lParam)
+{
+ if (callback == NULL) return FALSE;
+
+ BOOL res = FALSE;
+
+ /* language folder */
+ ptrT langpack(db_get_tsa(NULL, "Langpack", "Current"));
+
+ LANGPACK_INFO pack;
+ PathToAbsoluteT(_T("\\langpack_*.txt"), pack.tszFullPath);
+
+ BOOL fPackFound = FALSE;
+ WIN32_FIND_DATA wfd;
+ HANDLE hFind = FindFirstFile(pack.tszFullPath, &wfd);
+ if (hFind != INVALID_HANDLE_VALUE) {
+ do {
+ if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue;
+ /* get data */
+ TCHAR tszFullPath[MAX_PATH];
+ PathToAbsoluteT(_T("\\"), tszFullPath);
+ lstrcat(tszFullPath, wfd.cFileName);
+
+ ZeroMemory(&pack, sizeof(pack));
+ if (!LoadLangPackDescr(tszFullPath, &pack)) {
+ pack.ftFileDate = wfd.ftLastWriteTime;
+ /* enabled? */
+ if (langpack && !lstrcmpi(langpack, wfd.cFileName)) {
+ if (!fPackFound) pack.flags |= LPF_ENABLED;
+ fPackFound = TRUE;
+ }
+ /* callback */
+ res = callback(&pack, wParam, lParam);
+ if (!res) { FindClose(hFind); return FALSE; }
+ }
+ } while (FindNextFile(hFind, &wfd));
+ FindClose(hFind);
+ }
+
+ /* default langpack: English */
+ if (callback != NULL) {
+ ZeroMemory(&pack, sizeof(pack));
+ pack.Locale = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
+ lstrcpy(pack.tszLanguage, _T("English"));
+ lstrcpyA(pack.szAuthors, "Miranda NG Development Team");
+ lstrcpyA(pack.szAuthorEmail, "project-info@miranda-ng.org");
+ DWORD v = CallService(MS_SYSTEM_GETVERSION, 0, 0);
+ mir_snprintf(pack.szLastModifiedUsing, sizeof(pack.szLastModifiedUsing), "%d.%d.%d.%d", ((v >> 24) & 0xFF), ((v >> 16) & 0xFF), ((v >> 8) & 0xFF), (v & 0xFF));
+ /* file date */
+ if (GetModuleFileName(NULL, pack.tszFullPath, SIZEOF(pack.tszFullPath))) {
+ lstrcpy(pack.tszFileName, _tcsrchr(pack.tszFullPath, '\\') + 1);
+ HANDLE hFile = CreateFile(pack.tszFileName, 0, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
+ if (hFile != INVALID_HANDLE_VALUE) {
+ GetFileTime(hFile, NULL, NULL, &pack.ftFileDate);
+ CloseHandle(hFile);
+ }
+ }
+ pack.flags = LPF_DEFAULT;
+
+ if (!fPackFound) pack.flags |= LPF_ENABLED;
+ /* callback */
+ if (!callback(&pack, wParam, lParam)) return FALSE;
+ }
+
+ return fPackFound;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+void Langpack_LoadLangpack(void)
+{
+ HookEvent(ME_OPT_INITIALISE, LangpackOptionsInit);
+
+ TCHAR szSearch[MAX_PATH];
+ PathToAbsoluteT(_T("\\"), szSearch);
+
+ /* try to load langpack */
+ ptrT langpack(db_get_tsa(NULL, "Langpack", "Current"));
+ if (langpack && langpack[0] != '\0') {
+ lstrcat(szSearch, langpack);
+
+ DWORD dwAttrib = GetFileAttributes(szSearch);
+ if (dwAttrib != INVALID_FILE_ATTRIBUTES && !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY))
+ LoadLangPack(szSearch);
+ }
+ /* else try to load first file */
+ else if (!langpack) {
+ lstrcat(szSearch, _T("langpack_*.txt"));
+
+ WIN32_FIND_DATA fd;
+ HANDLE hFind = FindFirstFile(szSearch, &fd);
+ if (hFind != INVALID_HANDLE_VALUE) {
+ do {
+ /* search first langpack that could be loaded */
+ if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue;
+ /* load langpack */
+ PathToAbsoluteT(_T("\\"), szSearch);
+ lstrcat(szSearch, fd.cFileName);
+ if (!LoadLangPack(szSearch))
+ db_set_ws(NULL, "Langpack", "Current", fd.cFileName);
+ break;
+ } while (FindNextFile(hFind, &fd));
+ FindClose(hFind);
+ }
+ }
+}
diff --git a/src/modules/langpack/langpack.h b/src/modules/langpack/langpack.h
new file mode 100644
index 0000000000..47f44de94d
--- /dev/null
+++ b/src/modules/langpack/langpack.h
@@ -0,0 +1,63 @@
+/*
+
+Miranda NG: the free IM client for Microsoft* Windows*
+
+Copyright (c) 2012-14 Miranda NG project (http://miranda-ng.org),
+Copyright (c) 2000-12 Miranda IM project,
+all portions of this codebase are copyrighted to the people
+listed in contributors.txt.
+
+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, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+static INT_PTR srvTranslateString(WPARAM wParam, LPARAM lParam);
+static INT_PTR srvTranslateMenu(WPARAM wParam, LPARAM lParam);
+static INT_PTR srvRegisterLP(WPARAM wParam, LPARAM lParam);
+static INT_PTR srvGetDefaultCodePage(WPARAM, LPARAM);
+static INT_PTR srvGetDefaultLocale(WPARAM, LPARAM);
+static INT_PTR srvPcharToTchar(WPARAM wParam, LPARAM lParam);
+static INT_PTR srvReloadLangpack(WPARAM wParam, LPARAM lParam);
+static INT_PTR srvGetPluginLangpack(WPARAM wParam, LPARAM lParam);
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+#define LPF_ENABLED (1<<0) // pack is enabled
+#define LPF_NOLOCALE (1<<1) // pack has no valid locale
+#define LPF_DEFAULT (1<<2) // pack is the english default (no langpack)
+
+/* Langpack Info */
+struct LANGPACK_INFO
+{
+ TCHAR tszLanguage[64];
+ LCID Locale;
+ WORD codepage;
+ char szAuthors[2048];
+ char szAuthorEmail[128];
+ char szLastModifiedUsing[64];
+ char szPluginsIncluded[4080];
+ FILETIME ftFileDate;
+ TCHAR tszFileName[MAX_PATH]; /* just the file name itself */
+ TCHAR tszFullPath[MAX_PATH]; /* full path to the langpack */
+ BYTE flags; /* see LPIF_* flags */
+};
+
+typedef BOOL(*ENUM_PACKS_CALLBACK) (LANGPACK_INFO *pack, WPARAM wParam, LPARAM lParam);
+BOOL EnumLangpacks(ENUM_PACKS_CALLBACK callback, WPARAM wParam, LPARAM lParam);
+
+int LangpackOptionsInit(WPARAM wParam, LPARAM);
+
+void Langpack_LoadLangpack(void);
diff --git a/src/modules/langpack/lpopts.cpp b/src/modules/langpack/lpopts.cpp
new file mode 100644
index 0000000000..f52254afff
--- /dev/null
+++ b/src/modules/langpack/lpopts.cpp
@@ -0,0 +1,189 @@
+/*
+
+Miranda NG: the free IM client for Microsoft* Windows*
+
+Copyright (c) 2012-14 Miranda NG project (http://miranda-ng.org),
+Copyright (c) 2000-12 Miranda IM project,
+all portions of this codebase are copyrighted to the people
+listed in contributors.txt.
+
+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, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#include "..\..\core\commonheaders.h"
+#include "langpack.h"
+
+static void DisplayPackInfo(HWND hwndDlg, const LANGPACK_INFO *pack)
+{
+ /* locale string */
+ if (!(pack->flags & LPF_NOLOCALE)) {
+ TCHAR szLocaleName[256], szLanguageName[128], szContryName[128];
+
+ if (!GetLocaleInfo(pack->Locale, WINVER >= _WIN32_WINNT_WIN7 ? LOCALE_SENGLISHLANGUAGENAME : LOCALE_SENGLANGUAGE, szLanguageName, SIZEOF(szLanguageName)))
+ szLanguageName[0] = _T('\0');
+ if (!GetLocaleInfo(pack->Locale, WINVER >= _WIN32_WINNT_WIN7 ? LOCALE_SENGLISHCOUNTRYNAME : LOCALE_SENGCOUNTRY, szContryName, SIZEOF(szContryName)))
+ szContryName[0] = _T('\0');
+
+ /* add some note if its incompatible */
+ if (szLanguageName[0] && szContryName[0]) {
+ mir_sntprintf(szLocaleName, SIZEOF(szLocaleName), _T("%s (%s)"), TranslateTS(szLanguageName), TranslateTS(szContryName));
+ if (!IsValidLocale(pack->Locale, LCID_INSTALLED)) {
+ TCHAR *pszIncompat;
+ pszIncompat = TranslateT("(incompatible)");
+ szLocaleName[SIZEOF(szLocaleName) - lstrlen(pszIncompat) - 1] = 0;
+ lstrcat(lstrcat(szLocaleName, _T(" ")), pszIncompat);
+ }
+ SetDlgItemText(hwndDlg, IDC_LANGLOCALE, szLocaleName);
+ }
+ else SetDlgItemText(hwndDlg, IDC_LANGLOCALE, TranslateT("Unknown"));
+ }
+ else SetDlgItemText(hwndDlg, IDC_LANGLOCALE, TranslateT("Unknown"));
+
+ /* file date */
+ SYSTEMTIME stFileDate;
+ TCHAR szDate[128]; szDate[0] = 0;
+ if (FileTimeToSystemTime(&pack->ftFileDate, &stFileDate))
+ GetDateFormat((LCID)CallService(MS_LANGPACK_GETLOCALE, 0, 0), DATE_SHORTDATE, &stFileDate, NULL, szDate, SIZEOF(szDate));
+ SetDlgItemText(hwndDlg, IDC_LANGDATE, szDate);
+
+ /* plugins included */
+ SetDlgItemTextA(hwndDlg, IDC_PLUGINSINCLUDED, pack->szPluginsIncluded);
+ if (pack->szPluginsIncluded[0]) {
+ if (!IsWindowVisible(GetDlgItem(hwndDlg, IDC_PLUGINSINCLUDEDLABEL))) {
+ ShowWindow(GetDlgItem(hwndDlg,IDC_PLUGINSINCLUDEDLABEL), SW_SHOW);
+ ShowWindow(GetDlgItem(hwndDlg, IDC_PLUGINSINCLUDED), SW_SHOW);
+ }
+ }
+ else {
+ ShowWindow(GetDlgItem(hwndDlg, IDC_PLUGINSINCLUDEDLABEL), SW_HIDE);
+ ShowWindow(GetDlgItem(hwndDlg, IDC_PLUGINSINCLUDED), SW_HIDE);
+ }
+
+ /* general */
+ SetDlgItemTextA(hwndDlg, IDC_LANGMODUSING, pack->szLastModifiedUsing);
+ SetDlgItemTextA(hwndDlg, IDC_LANGAUTHORS, pack->szAuthors);
+ SetDlgItemTextA(hwndDlg, IDC_LANGEMAIL, pack->szAuthorEmail);
+ SetDlgItemText(hwndDlg, IDC_LANGINFOFRAME, TranslateTS(pack->tszLanguage));
+}
+
+static BOOL InsertPackItemEnumProc(LANGPACK_INFO *pack, WPARAM wParam, LPARAM lParam)
+{
+ LANGPACK_INFO *pack2 = (LANGPACK_INFO*)mir_alloc(sizeof(LANGPACK_INFO));
+ if (pack2 == NULL) return FALSE;
+ CopyMemory(pack2, pack, sizeof(LANGPACK_INFO));
+
+ /* insert */
+ TCHAR tszName[512];
+ mir_sntprintf(tszName, sizeof(tszName), _T("%s [%s]"),
+ TranslateTS(pack->tszLanguage),
+ pack->flags & LPF_DEFAULT ? TranslateT("built-in") : pack->tszFileName);
+ UINT message = pack->flags & LPF_DEFAULT ? CB_INSERTSTRING : CB_ADDSTRING;
+ int idx = SendMessage((HWND)wParam, message, 0, (LPARAM)tszName);
+ SendMessage((HWND)wParam, CB_SETITEMDATA, idx, (LPARAM)pack2);
+ if (pack->flags & LPF_ENABLED) {
+ SendMessage((HWND)wParam, CB_SETCURSEL, idx, 0);
+ DisplayPackInfo(GetParent((HWND)wParam), pack);
+ }
+
+ return TRUE;
+}
+
+INT_PTR CALLBACK DlgLangpackOpt(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ HWND hwndList = GetDlgItem(hwndDlg, IDC_LANGUAGES);
+
+ switch (msg) {
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hwndDlg);
+ ComboBox_ResetContent(hwndList);
+ EnumLangpacks(InsertPackItemEnumProc, (WPARAM)hwndList, (LPARAM)0);
+ return TRUE;
+
+ case WM_DESTROY:
+ {
+ int count = ListBox_GetCount(hwndList);
+ for (int i = 0; i < count; i++)
+ mir_free((LANGPACK_INFO*)ListBox_GetItemData(hwndList, i));
+ ComboBox_ResetContent(hwndList);
+ }
+ return TRUE;
+
+ case WM_COMMAND:
+ switch (LOWORD(wParam)) {
+ case IDC_LANGEMAIL:
+ {
+ char buf[512];
+ lstrcpyA(buf, "mailto:");
+ if (GetWindowTextA(GetDlgItem(hwndDlg, LOWORD(wParam)), &buf[7], sizeof(buf)-7))
+ CallService(MS_UTILS_OPENURL, FALSE, (LPARAM)buf);
+ }
+ break;
+
+ case IDC_MORELANG:
+ CallService(MS_UTILS_OPENURL, TRUE, (LPARAM)"http://wiki.miranda-ng.org/index.php?title=Langpacks/en#Download");
+ break;
+
+ case IDC_LANGUAGES:
+ if (HIWORD(wParam) == CBN_SELCHANGE) {
+ int idx = ComboBox_GetCurSel(hwndList);
+ LANGPACK_INFO *pack = (LANGPACK_INFO*)ComboBox_GetItemData(hwndList, idx);
+ DisplayPackInfo(hwndDlg, pack);
+ if (!(pack->flags & LPF_ENABLED))
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ }
+ }
+ break;
+
+ case WM_NOTIFY:
+ if (LPNMHDR(lParam)->code == PSN_APPLY) {
+ TCHAR tszPath[MAX_PATH]; tszPath[0] = 0;
+ int idx = ComboBox_GetCurSel(hwndList);
+ int count = ComboBox_GetCount(hwndList);
+ for (int i = 0; i < count; i++) {
+ LANGPACK_INFO *pack = (LANGPACK_INFO*)ComboBox_GetItemData(hwndList, idx);
+ if (i == idx) {
+ db_set_ws(NULL, "Langpack", "Current", pack->tszFileName);
+ lstrcpy(tszPath, pack->tszFullPath);
+ pack->flags |= LPF_ENABLED;
+ }
+ else pack->flags &= ~LPF_ENABLED;
+ }
+
+ if (tszPath[0]) {
+ CallService(MS_LANGPACK_RELOAD, 0, (LPARAM)tszPath);
+ CloseWindow(GetParent(hwndDlg));
+ DestroyWindow(GetParent(hwndDlg));
+ }
+ }
+ break;
+ }
+ return FALSE;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+int LangpackOptionsInit(WPARAM wParam, LPARAM)
+{
+ OPTIONSDIALOGPAGE odp = { sizeof(odp) };
+ odp.hInstance = hInst;
+ odp.pfnDlgProc = DlgLangpackOpt;
+ odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_LANGUAGES);
+ odp.position = -1300000000;
+ odp.pszTitle = LPGEN("Languages");
+ odp.pszGroup = LPGEN("Customize");
+ odp.flags = ODPF_BOLDGROUPS;
+ Options_AddPage(wParam, &odp);
+ return 0;
+}