|
From: <arn...@us...> - 2007-12-29 22:04:07
|
Revision: 954
http://dcplusplus.svn.sourceforge.net/dcplusplus/?rev=954&view=rev
Author: arnetheduck
Date: 2007-12-29 14:04:05 -0800 (Sat, 29 Dec 2007)
Log Message:
-----------
Fix language selector
Modified Paths:
--------------
dcplusplus/trunk/SConstruct
dcplusplus/trunk/changelog.txt
dcplusplus/trunk/dcpp/DCPlusPlus.cpp
dcplusplus/trunk/dcpp/DCPlusPlus.h
dcplusplus/trunk/dcpp/File.cpp
dcplusplus/trunk/dcpp/SettingsManager.cpp
dcplusplus/trunk/dcpp/SettingsManager.h
dcplusplus/trunk/dcpp/Util.cpp
dcplusplus/trunk/dcpp/Util.h
dcplusplus/trunk/win32/AppearancePage.cpp
dcplusplus/trunk/win32/AppearancePage.h
dcplusplus/trunk/win32/DCPlusPlus.rc
dcplusplus/trunk/win32/stdafx.h
Modified: dcplusplus/trunk/SConstruct
===================================================================
--- dcplusplus/trunk/SConstruct 2007-12-29 14:47:58 UTC (rev 953)
+++ dcplusplus/trunk/SConstruct 2007-12-29 22:04:05 UTC (rev 954)
@@ -158,7 +158,7 @@
pot_args = ['xgettext','--from-code=UTF-8', '--foreign-user', '--package-name=$PACKAGE',
'--copyright-holder=Jacek Sieka', '--msg...@li...',
- '--no-wrap', '--keyword=_', '--output=$TARGET', '$SOURCES']
+ '--no-wrap', '--keyword=_', '--keyword=T_', '--output=$TARGET', '$SOURCES']
pot_bld = Builder (action = Action([pot_args], 'Extracting messages to $TARGET from $SOURCES'))
env.Append(BUILDERS = {'PotBuild' : pot_bld})
Modified: dcplusplus/trunk/changelog.txt
===================================================================
--- dcplusplus/trunk/changelog.txt 2007-12-29 14:47:58 UTC (rev 953)
+++ dcplusplus/trunk/changelog.txt 2007-12-29 22:04:05 UTC (rev 954)
@@ -6,7 +6,8 @@
* [ADC] Searches filtered by token if available so that each search window only gets its own results
* [ADC] Implemented test version of bloom filters which will dramatically reduce hub bandwidth usage for TTH searches
* Fixed a crash with partial list browsing
-
+* Replaced homegrown i18n solution with gettext
+§
-- 0.704 2007-12-14 --
* Hub lists added to utilize Coral's distributed network (ullner)
* Use system header arrows on common controls 6+ (thanks poy)
Modified: dcplusplus/trunk/dcpp/DCPlusPlus.cpp
===================================================================
--- dcplusplus/trunk/dcpp/DCPlusPlus.cpp 2007-12-29 14:47:58 UTC (rev 953)
+++ dcplusplus/trunk/dcpp/DCPlusPlus.cpp 2007-12-29 22:04:05 UTC (rev 954)
@@ -89,12 +89,10 @@
_nl_msg_cat_cntr++;
}
- printf(_("test"));
+ //if(!SETTING(LANGUAGE_FILE).empty()) {
+ //ResourceManager::getInstance()->loadLanguage(SETTING(LANGUAGE_FILE));
+ //}
- if(!SETTING(LANGUAGE_FILE).empty()) {
- ResourceManager::getInstance()->loadLanguage(SETTING(LANGUAGE_FILE));
- }
-
FavoriteManager::getInstance()->load();
CryptoManager::getInstance()->loadCertificates();
Modified: dcplusplus/trunk/dcpp/DCPlusPlus.h
===================================================================
--- dcplusplus/trunk/dcpp/DCPlusPlus.h 2007-12-29 14:47:58 UTC (rev 953)
+++ dcplusplus/trunk/dcpp/DCPlusPlus.h 2007-12-29 22:04:05 UTC (rev 954)
@@ -170,7 +170,7 @@
#ifdef BUILDING_DCPP
#define PACKAGE "dcpp"
-#define LOCALEDIR (Util::getDataPath() + "/locale/").c_str()
+#define LOCALEDIR Util::getLocalePath().c_str()
#define _(String) dgettext(PACKAGE, String)
#endif
Modified: dcplusplus/trunk/dcpp/File.cpp
===================================================================
--- dcplusplus/trunk/dcpp/File.cpp 2007-12-29 14:47:58 UTC (rev 953)
+++ dcplusplus/trunk/dcpp/File.cpp 2007-12-29 22:04:05 UTC (rev 954)
@@ -419,7 +419,8 @@
hFind = ::FindFirstFile(Text::toT(path + pattern).c_str(), &data);
if(hFind != INVALID_HANDLE_VALUE) {
do {
- ret.push_back(path + Text::fromT(data.cFileName));
+ const char* extra = (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? "\\" : "";
+ ret.push_back(path + Text::fromT(data.cFileName) + extra);
} while(::FindNextFile(hFind, &data));
::FindClose(hFind);
@@ -429,7 +430,8 @@
if (dir) {
while (struct dirent* ent = readdir(dir)) {
if (fnmatch(pattern.c_str(), ent->d_name, 0) == 0) {
- ret.push_back(path + Text::toUtf8(ent->d_name));
+ const char* extra = (ent->d_type & DT_DIR) ? "/" : "";
+ ret.push_back(path + Text::toUtf8(ent->d_name) + extra);
}
}
closedir(dir);
Modified: dcplusplus/trunk/dcpp/SettingsManager.cpp
===================================================================
--- dcplusplus/trunk/dcpp/SettingsManager.cpp 2007-12-29 14:47:58 UTC (rev 953)
+++ dcplusplus/trunk/dcpp/SettingsManager.cpp 2007-12-29 22:04:05 UTC (rev 954)
@@ -37,7 +37,7 @@
// Strings
"Nick", "UploadSpeed", "Description", "DownloadDirectory", "EMail", "ExternalIp",
"Font", "MainFrameOrder", "MainFrameWidths", "HubFrameOrder", "HubFrameWidths",
- "LanguageFile", "SearchFrameOrder", "SearchFrameWidths", "FavHubsFrameOrder", "FavHubsFrameWidths",
+ "SearchFrameOrder", "SearchFrameWidths", "FavHubsFrameOrder", "FavHubsFrameWidths",
"HublistServers", "QueueFrameOrder", "QueueFrameWidths", "PublicHubsFrameOrder", "PublicHubsFrameWidths",
"UsersFrameOrder", "UsersFrameWidths", "HttpProxy", "LogDirectory", "LogFormatPostDownload",
"LogFormatPostUpload", "LogFormatMainChat", "LogFormatPrivateChat", "FinishedOrder", "FinishedWidths",
@@ -335,11 +335,14 @@
xml.stepOut();
}
+ if(SETTING(PRIVATE_ID).length() != 39 || CID(SETTING(PRIVATE_ID)).isZero()) {
+ set(PRIVATE_ID, CID::generate().toBase32());
+ }
+
double v = Util::toDouble(SETTING(CONFIG_VERSION));
// if(v < 0.x) { // Fix old settings here }
- if(v <= 0.674 || SETTING(PRIVATE_ID).length() != 39 || CID(SETTING(PRIVATE_ID)).isZero()) {
- set(PRIVATE_ID, CID::generate().toBase32());
+ if(v <= 0.674) {
// Formats changed, might as well remove these...
set(LOG_FORMAT_POST_DOWNLOAD, Util::emptyString);
Modified: dcplusplus/trunk/dcpp/SettingsManager.h
===================================================================
--- dcplusplus/trunk/dcpp/SettingsManager.h 2007-12-29 14:47:58 UTC (rev 953)
+++ dcplusplus/trunk/dcpp/SettingsManager.h 2007-12-29 22:04:05 UTC (rev 954)
@@ -48,7 +48,7 @@
enum StrSetting { STR_FIRST,
NICK = STR_FIRST, UPLOAD_SPEED, DESCRIPTION, DOWNLOAD_DIRECTORY, EMAIL, EXTERNAL_IP,
TEXT_FONT, MAINFRAME_ORDER, MAINFRAME_WIDTHS, HUBFRAME_ORDER, HUBFRAME_WIDTHS,
- LANGUAGE_FILE, SEARCHFRAME_ORDER, SEARCHFRAME_WIDTHS, FAVHUBSFRAME_ORDER, FAVHUBSFRAME_WIDTHS,
+ SEARCHFRAME_ORDER, SEARCHFRAME_WIDTHS, FAVHUBSFRAME_ORDER, FAVHUBSFRAME_WIDTHS,
HUBLIST_SERVERS, QUEUEFRAME_ORDER, QUEUEFRAME_WIDTHS, PUBLICHUBSFRAME_ORDER, PUBLICHUBSFRAME_WIDTHS,
USERSFRAME_ORDER, USERSFRAME_WIDTHS, HTTP_PROXY, LOG_DIRECTORY, LOG_FORMAT_POST_DOWNLOAD,
LOG_FORMAT_POST_UPLOAD, LOG_FORMAT_MAIN_CHAT, LOG_FORMAT_PRIVATE_CHAT, FINISHED_ORDER, FINISHED_WIDTHS,
Modified: dcplusplus/trunk/dcpp/Util.cpp
===================================================================
--- dcplusplus/trunk/dcpp/Util.cpp 2007-12-29 14:47:58 UTC (rev 953)
+++ dcplusplus/trunk/dcpp/Util.cpp 2007-12-29 22:04:05 UTC (rev 954)
@@ -63,6 +63,7 @@
string Util::configPath;
string Util::systemPath;
string Util::dataPath;
+string Util::localePath;
static void sgenrand(unsigned long seed);
@@ -88,12 +89,14 @@
systemPath = Util::getFilePath(Text::fromT(buf));
configPath = systemPath;
dataPath = systemPath;
+ localePath = dataPath + "locale\\";
#else
systemPath = "/etc/";
char* home = getenv("HOME");
configPath = home ? Text::toUtf8(home) + "/.dc++/" : "/tmp/";
dataPath = configPath; // dataPath in linux is usually prefix + /share/app_name, so we can't represent it here
+ localePath = dataPath; // TODO no good default here either, fix
#endif
// Load boot settings
Modified: dcplusplus/trunk/dcpp/Util.h
===================================================================
--- dcplusplus/trunk/dcpp/Util.h 2007-12-29 14:47:58 UTC (rev 953)
+++ dcplusplus/trunk/dcpp/Util.h 2007-12-29 22:04:05 UTC (rev 954)
@@ -127,6 +127,7 @@
static const string& getConfigPath() { return configPath; }
static const string& getDataPath() { return dataPath; }
static const string& getSystemPath() { return systemPath; }
+ static const string& getLocalePath() { return localePath; }
/** Path of file lists */
static string getListPath() { return getConfigPath() + "FileLists" PATH_SEPARATOR_STR; }
@@ -379,6 +380,8 @@
static string systemPath;
/** Various resources (help files etc) */
static string dataPath;
+ /** Translations */
+ static string localePath;
static bool away;
static bool manualAway;
Modified: dcplusplus/trunk/win32/AppearancePage.cpp
===================================================================
--- dcplusplus/trunk/win32/AppearancePage.cpp 2007-12-29 14:47:58 UTC (rev 953)
+++ dcplusplus/trunk/win32/AppearancePage.cpp 2007-12-29 22:04:05 UTC (rev 954)
@@ -23,6 +23,8 @@
#include "AppearancePage.h"
#include <dcpp/SettingsManager.h>
+#include <dcpp/File.h>
+
#include "WinUtil.h"
PropPage::TextItem AppearancePage::texts[] = {
@@ -30,7 +32,6 @@
{ IDC_SETTINGS_DEFAULT_AWAY_MSG, ResourceManager::SETTINGS_DEFAULT_AWAY_MSG },
{ IDC_SETTINGS_TIME_STAMPS_FORMAT, ResourceManager::SETTINGS_TIME_STAMPS_FORMAT },
{ IDC_SETTINGS_LANGUAGE_FILE, ResourceManager::SETTINGS_LANGUAGE_FILE },
- { IDC_BROWSE, ResourceManager::BROWSE_ACCEL },
{ IDC_SETTINGS_REQUIRES_RESTART, ResourceManager::SETTINGS_REQUIRES_RESTART },
{ 0, ResourceManager::SETTINGS_AUTO_AWAY }
};
@@ -38,7 +39,6 @@
PropPage::Item AppearancePage::items[] = {
{ IDC_DEFAULT_AWAY_MESSAGE, SettingsManager::DEFAULT_AWAY_MESSAGE, PropPage::T_STR },
{ IDC_TIME_STAMPS_FORMAT, SettingsManager::TIME_STAMPS_FORMAT, PropPage::T_STR },
- { IDC_LANGUAGE, SettingsManager::LANGUAGE_FILE, PropPage::T_STR },
{ 0, 0, PropPage::T_END }
};
@@ -57,13 +57,44 @@
{ 0, ResourceManager::SETTINGS_AUTO_AWAY }
};
-AppearancePage::AppearancePage(SmartWin::Widget* parent) : PropPage(parent) {
+AppearancePage::AppearancePage(SmartWin::Widget* parent) : PropPage(parent), languages(0) {
createDialog(IDD_APPEARANCEPAGE);
PropPage::translate(handle(), texts);
PropPage::read(handle(), items, listItems, ::GetDlgItem(handle(), IDC_APPEARANCE_BOOLEANS));
- attachButton(IDC_BROWSE)->onClicked(std::tr1::bind(&AppearancePage::handleBrowse, this));
+ languages = attachComboBox(IDC_LANGUAGE);
+
+ StringList dirs = File::findFiles(Util::getLocalePath(), "*");
+
+ TStringList langs;
+
+ langs.push_back(_T("en"));
+
+ for(StringList::const_iterator i = dirs.begin(); i != dirs.end(); ++i) {
+ string dir = *i + "LC_MESSAGES" PATH_SEPARATOR_STR;
+ StringList files = File::findFiles(dir, "*.mo");
+ if(find(files.begin(), files.end(), dir + "dcpp.mo") == files.end() && find(files.begin(), files.end(), dir + "dcpp-win32.mo") == files.end()) {
+ continue;
+ }
+ // TODO Convert to real language name?
+ langs.push_back(Text::toT(Util::getLastDir(*i)));
+ }
+
+ std::sort(langs.begin(), langs.end(), noCaseStringLess());
+
+ languages->addValue(T_("Default"));
+
+ int selected = 0, j = 1;
+ const tstring cur = Text::toT(SETTING(LANGUAGE));
+ for(TStringList::const_iterator i = langs.begin(); i != langs.end(); ++i, ++j) {
+ languages->addValue(*i);
+ if(selected != 0 && *i == cur || (*i == _T("en") && cur == _T("C"))) {
+ selected = j;
+ }
+ }
+
+ languages->setSelectedIndex(selected);
}
AppearancePage::~AppearancePage() {
@@ -72,16 +103,14 @@
void AppearancePage::write()
{
PropPage::write(handle(), items, listItems, ::GetDlgItem(handle(), IDC_APPEARANCE_BOOLEANS));
-}
-void AppearancePage::handleBrowse() {
- TCHAR buf[MAX_PATH];
- static const TCHAR types[] = _T("Language Files\0*.xml\0All Files\0*.*\0");
-
- ::GetDlgItemText(handle(), IDC_LANGUAGE, buf, MAX_PATH);
- tstring x = buf;
-
- if(WinUtil::browseFile(x, handle(), false, Text::toT(Util::getDataPath()), types) == IDOK) {
- ::SetDlgItemText(handle(), IDC_LANGUAGE, x.c_str());
+ tstring lang = languages->getText();
+
+ if(lang == T_("Default")) {
+ SettingsManager::getInstance()->set(SettingsManager::LANGUAGE, "");
+ } else if(lang == _T("en")) {
+ SettingsManager::getInstance()->set(SettingsManager::LANGUAGE, "C");
+ } else {
+ SettingsManager::getInstance()->set(SettingsManager::LANGUAGE, Text::fromT(lang));
}
}
Modified: dcplusplus/trunk/win32/AppearancePage.h
===================================================================
--- dcplusplus/trunk/win32/AppearancePage.h 2007-12-29 14:47:58 UTC (rev 953)
+++ dcplusplus/trunk/win32/AppearancePage.h 2007-12-29 22:04:05 UTC (rev 954)
@@ -35,7 +35,7 @@
static TextItem texts[];
static ListItem listItems[];
- void handleBrowse();
+ WidgetComboBox* languages;
};
#endif // !defined(DCPLUSPLUS_WIN32_APPEARANCE_PAGE_H)
Modified: dcplusplus/trunk/win32/DCPlusPlus.rc
===================================================================
--- dcplusplus/trunk/win32/DCPlusPlus.rc 2007-12-29 14:47:58 UTC (rev 953)
+++ dcplusplus/trunk/win32/DCPlusPlus.rc 2007-12-29 22:04:05 UTC (rev 954)
@@ -188,9 +188,8 @@
EDITTEXT IDC_DEFAULT_AWAY_MESSAGE,16,152,145,14,ES_MULTILINE | ES_AUTOHSCROLL | WS_VSCROLL
GROUPBOX "Set timestamps",IDC_SETTINGS_TIME_STAMPS_FORMAT,174,141,96,32
EDITTEXT IDC_TIME_STAMPS_FORMAT,180,152,80,15,ES_AUTOHSCROLL
- GROUPBOX "Language file",IDC_SETTINGS_LANGUAGE_FILE,7,174,261,32
- EDITTEXT IDC_LANGUAGE,16,185,188,14,ES_AUTOHSCROLL
- PUSHBUTTON "&Browse...",IDC_BROWSE,210,185,50,14
+ GROUPBOX "Language",IDC_SETTINGS_LANGUAGE_FILE,7,174,261,32
+ COMBOBOX IDC_LANGUAGE,16,185,238,14,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | WS_VSCROLL | WS_TABSTOP
LTEXT "Note; most of these options require that you restart DC++",IDC_SETTINGS_REQUIRES_RESTART,7,210,253,8
END
Modified: dcplusplus/trunk/win32/stdafx.h
===================================================================
--- dcplusplus/trunk/win32/stdafx.h 2007-12-29 14:47:58 UTC (rev 953)
+++ dcplusplus/trunk/win32/stdafx.h 2007-12-29 22:04:05 UTC (rev 954)
@@ -44,8 +44,9 @@
using std::tr1::placeholders::_1;
using std::tr1::placeholders::_2;
-#define LOCALEDIR (dcpp::Util::getDataPath() + "/locale/").c_str()
+#define LOCALEDIR dcpp::Util::getLocalePath().c_str()
#define PACKAGE "dcpp-win32"
#define _(String) gettext(String)
+#define T_(String) Text::toT(gettext(String))
#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|