1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 01:22:10 +01:00

Using better method for loading translations.

- it can now load xx_CC translation even if xx_DD is
  user's system locale
This commit is contained in:
nowrep 2012-04-04 18:48:54 +02:00
parent 1c883e4ec3
commit 9778773199
22 changed files with 58 additions and 69 deletions

View File

@ -61,7 +61,7 @@ AdBlockSubscription::AdBlockSubscription(QObject* parent)
void AdBlockSubscription::loadRules()
{
QString fileName = mApp->getActiveProfilPath() + "adblocklist.txt";
QString fileName = mApp->currentProfilePath() + "adblocklist.txt";
QFile file(fileName);
if (file.exists()) {
@ -126,7 +126,7 @@ void AdBlockSubscription::rulesDownloaded()
return;
}
QString fileName = mApp->getActiveProfilPath() + "adblocklist.txt";
QString fileName = mApp->currentProfilePath() + "adblocklist.txt";
QFile file(fileName);
if (!file.open(QFile::ReadWrite | QFile::Truncate)) {
qWarning() << "AdBlockSubscription::" << __FUNCTION__ << "Unable to open adblock file for writing:" << fileName;
@ -161,7 +161,7 @@ void AdBlockSubscription::rulesDownloaded()
void AdBlockSubscription::saveRules()
{
QString fileName = mApp->getActiveProfilPath() + "adblocklist.txt";
QString fileName = mApp->currentProfilePath() + "adblocklist.txt";
QFile file(fileName);
if (!file.open(QFile::ReadWrite | QFile::Truncate)) {

View File

@ -561,27 +561,14 @@ void MainApplication::connectDatabase()
void MainApplication::translateApp()
{
QLocale locale;
Settings settings;
settings.beginGroup("Language");
QString file = settings.value("language", locale.name().append(".qm")).toString();
QString shortLoc = file.left(2);
QString longLoc = file.left(5);
if (file == "" || !QFile::exists(TRANSLATIONSDIR + file)) {
return;
}
const QString &file = settings.value("Language/language", QLocale::system().name()).toString();
QTranslator* app = new QTranslator(this);
app->load(TRANSLATIONSDIR + file);
QTranslator* sys = new QTranslator(this);
app->load(file, TRANSLATIONSDIR);
if (QFile::exists(TRANSLATIONSDIR + "qt_" + longLoc + ".qm")) {
sys->load(TRANSLATIONSDIR + "qt_" + longLoc + ".qm");
}
else if (QFile::exists(TRANSLATIONSDIR + "qt_" + shortLoc + ".qm")) {
sys->load(TRANSLATIONSDIR + "qt_" + shortLoc + ".qm");
}
QTranslator* sys = new QTranslator(this);
sys->load("qt_" + file, TRANSLATIONSDIR);
m_activeLanguage = file;
@ -645,7 +632,7 @@ void MainApplication::saveSettings()
m_iconProvider->saveIconsToDatabase();
AdBlockManager::instance()->save();
QFile::remove(getActiveProfilPath() + "WebpageIcons.db");
QFile::remove(currentProfilePath() + "WebpageIcons.db");
Settings::syncSettings();
}

View File

@ -70,8 +70,8 @@ public:
QList<QupZilla*> mainWindows();
inline static MainApplication* getInstance() { return static_cast<MainApplication*>(QCoreApplication::instance()); }
inline QString getActiveProfilPath() { return m_activeProfil; }
inline QString getActiveLanguage() { return m_activeLanguage; }
inline QString currentProfilePath() { return m_activeProfil; }
inline QString currentLanguage() { return m_activeLanguage; }
inline bool isClosing() { return m_isClosing; }
inline bool isStartingAfterCrash() { return m_startingAfterCrash; }
inline int windowCount() { return m_mainWindows.count(); }

View File

@ -79,7 +79,7 @@
#include <QWebHistory>
#include <QMessageBox>
const QString QupZilla::VERSION = "1.1.8";
const QString QupZilla::VERSION = "1.2.0";
const QString QupZilla::BUILDTIME = __DATE__" "__TIME__;
const QString QupZilla::AUTHOR = "David Rosca";
const QString QupZilla::COPYRIGHT = "2010-2012";
@ -109,8 +109,6 @@ QupZilla::QupZilla(Qz::BrowserWindow type, QUrl startUrl)
setWindowTitle(tr("QupZilla"));
m_isStarting = true;
m_activeProfil = mApp->getActiveProfilPath();
m_activeLanguage = mApp->getActiveLanguage();
setupUi();
setupMenu();
@ -236,6 +234,7 @@ void QupZilla::setupUi()
locationBarWidth = settings.value("LocationBarWidth", 480).toInt();
websearchBarWidth = settings.value("WebSearchBarWidth", 140).toInt();
settings.endGroup();
QWidget* widget = new QWidget(this);
widget->setCursor(Qt::ArrowCursor);

View File

@ -95,9 +95,6 @@ public:
inline QAction* actionReload() { return m_actionReload; }
inline QMenu* superMenu() { return m_superMenu; }
inline QString activeProfil() { return m_activeProfil; }
inline QString activeLanguage() { return m_activeLanguage; }
inline bool isClosing() { return m_isClosing; }
inline QUrl homepageUrl() { return m_homepage; }
@ -262,8 +259,6 @@ private:
ProgressBar* m_progressBar;
QLabel* m_ipLabel;
QString m_activeProfil;
QString m_activeLanguage;
QString m_lastWindowTitle;
int m_sideBarWidth;

View File

@ -23,6 +23,12 @@ QSettings* Settings::m_settings = 0;
Settings::Settings()
{
#ifdef QT_DEBUG
if (!m_settings->group().isEmpty()) {
qWarning("Settings: Creating object with opened group!");
m_settings->endGroup();
}
#endif
}
void Settings::createSettings(const QString &fileName)
@ -62,7 +68,10 @@ QSettings* Settings::globalSettings()
Settings::~Settings()
{
#ifdef QT_DEBUG
if (!m_settings->group().isEmpty()) {
qWarning("Settings: Deleting object with opened group!");
m_settings->endGroup();
}
#endif
}

View File

@ -53,7 +53,7 @@ CookieJar::CookieJar(QupZilla* mainClass, QObject* parent)
: QNetworkCookieJar(parent)
, p_QupZilla(mainClass)
{
m_activeProfil = mApp->getActiveProfilPath();
m_activeProfil = mApp->currentProfilePath();
loadSettings();
}

View File

@ -82,7 +82,7 @@ void NetworkManager::loadSettings()
if (settings.value("AllowLocalCache", true).toBool()) {
m_diskCache = mApp->networkCache();
m_diskCache->setCacheDirectory(mApp->getActiveProfilPath() + "/networkcache");
m_diskCache->setCacheDirectory(mApp->currentProfilePath() + "/networkcache");
m_diskCache->setMaximumCacheSize(settings.value("MaximumCacheSize", 50).toInt() * 1024 * 1024); //MegaBytes
setCache(m_diskCache);
}
@ -370,7 +370,7 @@ void NetworkManager::removeLocalCertificate(const QSslCertificate &cert)
//Delete cert file from profile
bool deleted = false;
QDirIterator it(mApp->getActiveProfilPath() + "certificates", QDir::Files, QDirIterator::FollowSymlinks | QDirIterator::Subdirectories);
QDirIterator it(mApp->currentProfilePath() + "certificates", QDir::Files, QDirIterator::FollowSymlinks | QDirIterator::Subdirectories);
while (it.hasNext()) {
const QString &filePath = it.next();
const QList<QSslCertificate> &certs = QSslCertificate::fromPath(filePath);
@ -404,13 +404,13 @@ void NetworkManager::addLocalCertificate(const QSslCertificate &cert)
m_localCerts.append(cert);
QSslSocket::addDefaultCaCertificate(cert);
QDir dir(mApp->getActiveProfilPath());
QDir dir(mApp->currentProfilePath());
if (!dir.exists("certificates")) {
dir.mkdir("certificates");
}
QString certFileName = fileNameForCert(cert);
QString fileName = qz_ensureUniqueFilename(mApp->getActiveProfilPath() + "certificates/" + certFileName);
QString fileName = qz_ensureUniqueFilename(mApp->currentProfilePath() + "certificates/" + certFileName);
QFile file(fileName);
if (file.open(QFile::WriteOnly)) {
@ -486,7 +486,7 @@ void NetworkManager::loadCertificates()
}
}
#else
m_localCerts += QSslCertificate::fromPath(mApp->getActiveProfilPath() + "certificates/*.crt", QSsl::Pem, QRegExp::Wildcard);
m_localCerts += QSslCertificate::fromPath(mApp->currentProfilePath() + "certificates/*.crt", QSsl::Pem, QRegExp::Wildcard);
#endif
QSslSocket::setDefaultCaCertificates(m_caCerts + m_localCerts);

View File

@ -333,10 +333,10 @@ QString QupZillaSchemeReply::configPage()
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Platform"), qz_buildSystem()));
cPage.replace("%PATHS-TEXT%",
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Profile"), mApp->getActiveProfilPath()) +
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Settings"), mApp->getActiveProfilPath() + "settings.ini") +
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Saved session"), mApp->getActiveProfilPath() + "session.dat") +
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Pinned tabs"), mApp->getActiveProfilPath() + "pinnedtabs.dat") +
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Profile"), mApp->currentProfilePath()) +
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Settings"), mApp->currentProfilePath() + "settings.ini") +
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Saved session"), mApp->currentProfilePath() + "session.dat") +
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Pinned tabs"), mApp->currentProfilePath() + "pinnedtabs.dat") +
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Data"), mApp->DATADIR) +
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Themes"), mApp->THEMESDIR) +
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Translations"), mApp->TRANSLATIONSDIR));

View File

@ -148,7 +148,7 @@ void BrowsingLibrary::showRSS(QupZilla* mainClass)
void BrowsingLibrary::optimizeDatabase()
{
mApp->setOverrideCursor(Qt::WaitCursor);
QString profilePath = mApp->getActiveProfilPath();
QString profilePath = mApp->currentProfilePath();
QString sizeBefore = DownloadItem::fileSizeToString(QFileInfo(profilePath + "browsedata.db").size());
mApp->history()->optimizeHistory();
QString sizeAfter = DownloadItem::fileSizeToString(QFileInfo(profilePath + "browsedata.db").size());

View File

@ -54,14 +54,14 @@ void ClearPrivateData::historyClicked(bool state)
void ClearPrivateData::clearLocalStorage()
{
const QString &profile = mApp->getActiveProfilPath();
const QString &profile = mApp->currentProfilePath();
qz_removeDir(profile + "LocalStorage");
}
void ClearPrivateData::clearWebDatabases()
{
const QString &profile = mApp->getActiveProfilPath();
const QString &profile = mApp->currentProfilePath();
QWebDatabase::removeAllDatabases();
qz_removeDir(profile + "Databases");
@ -72,7 +72,7 @@ void ClearPrivateData::clearCache()
mApp->webSettings()->clearMemoryCaches();
mApp->networkManager()->cache()->clear();
QFile::remove(mApp->getActiveProfilPath() + "ApplicationCache.db");
QFile::remove(mApp->currentProfilePath() + "ApplicationCache.db");
}
void ClearPrivateData::clearIcons()

View File

@ -118,7 +118,7 @@ void Plugins::loadPlugins()
return;
}
QDir settingsDir(mApp->getActiveProfilPath() + "extensions/");
QDir settingsDir(mApp->currentProfilePath() + "extensions/");
if (!settingsDir.exists()) {
settingsDir.mkdir(settingsDir.absolutePath());
}
@ -200,7 +200,7 @@ PluginInterface* Plugins::initPlugin(PluginInterface* interface, QPluginLoader*
return 0;
}
interface->init(mApp->getActiveProfilPath() + "extensions/");
interface->init(mApp->currentProfilePath() + "extensions/");
if (!interface->testPlugin()) {
interface->unload();
@ -208,7 +208,7 @@ PluginInterface* Plugins::initPlugin(PluginInterface* interface, QPluginLoader*
return 0;
}
qApp->installTranslator(interface->getTranslator(mApp->getActiveLanguage()));
qApp->installTranslator(interface->getTranslator(mApp->currentLanguage()));
return interface;
}

View File

@ -60,11 +60,11 @@ void SpeedDial::loadSettings()
}
changed(allPages);
m_thumbnailsDir = mApp->getActiveProfilPath() + "thumbnails/";
m_thumbnailsDir = mApp->currentProfilePath() + "thumbnails/";
// If needed, create thumbnails directory
if (!QDir(m_thumbnailsDir).exists()) {
QDir(mApp->getActiveProfilPath()).mkdir("thumbnails");
QDir(mApp->currentProfilePath()).mkdir("thumbnails");
}
}

View File

@ -126,7 +126,7 @@ Preferences::Preferences(QupZilla* mainClass, QWidget* parent)
connect(ui->newTabUseCurrent, SIGNAL(clicked()), this, SLOT(useActualNewTab()));
//PROFILES
m_actProfileName = mApp->getActiveProfilPath();
m_actProfileName = mApp->currentProfilePath();
m_actProfileName = m_actProfileName.left(m_actProfileName.length() - 1);
m_actProfileName = m_actProfileName.mid(m_actProfileName.lastIndexOf("/"));
m_actProfileName.remove("/");
@ -351,14 +351,12 @@ Preferences::Preferences(QupZilla* mainClass, QWidget* parent)
//OTHER
//Languages
QString activeLanguage = "";
if (!p_QupZilla->activeLanguage().isEmpty()) {
activeLanguage = p_QupZilla->activeLanguage();
QString loc = activeLanguage;
loc.remove(".qm");
QLocale locale(loc);
if (!mApp->currentLanguage().isEmpty()) {
activeLanguage = mApp->currentLanguage();
QLocale locale(activeLanguage);
QString country = QLocale::countryToString(locale.country());
QString language = QLocale::languageToString(locale.language());
ui->languages->addItem(language + ", " + country + " (" + loc + ")", activeLanguage);
ui->languages->addItem(language + ", " + country + " (" + activeLanguage + ")", activeLanguage);
}
ui->languages->addItem("English (en_US)");
@ -374,7 +372,7 @@ Preferences::Preferences(QupZilla* mainClass, QWidget* parent)
QLocale locale(loc);
QString country = QLocale::countryToString(locale.country());
QString language = QLocale::languageToString(locale.language());
ui->languages->addItem(language + ", " + country + " (" + loc + ")", name);
ui->languages->addItem(language + ", " + country + " (" + loc + ")", loc);
}
// Proxy Configuration

View File

@ -311,7 +311,7 @@ CertificateInfoWidget::CertificateInfoWidget(const QSslCertificate &cert, QWidge
ui->issuedByO->setText(showCertInfo(cert.issuerInfo(QSslCertificate::Organization)));
ui->issuedByOU->setText(showCertInfo(cert.issuerInfo(QSslCertificate::OrganizationalUnitName)));
//Validity
QLocale locale = QLocale(mApp->getActiveLanguage().left(5));
QLocale locale = QLocale(mApp->currentLanguage());
ui->validityIssuedOn->setText(locale.toString(cert.effectiveDate(), "dddd d. MMMM yyyy"));
ui->validityExpiresOn->setText(locale.toString(cert.expiryDate(), "dddd d. MMMM yyyy"));
}

View File

@ -71,6 +71,7 @@ void TabBar::loadSettings()
settings.beginGroup("Browser-Tabs-Settings");
setMovable(settings.value("makeTabsMovable", true).toBool());
if (settings.value("ActivateLastTabWhenClosingActual", false).toBool()) {
setSelectionBehaviorOnRemove(QTabBar::SelectPreviousTab);
}

View File

@ -130,8 +130,8 @@ void TabWidget::loadSettings()
m_dontQuitWithOneTab = settings.value("dontQuitWithOneTab", false).toBool();
m_closedInsteadOpened = settings.value("closedInsteadOpenedTabs", false).toBool();
m_newTabAfterActive = settings.value("newTabAfterActive", true).toBool();
settings.endGroup();
settings.beginGroup("Web-URL-Settings");
m_urlOnNewTab = settings.value("newTabUrl", "qupzilla:speeddial").toUrl();
settings.endGroup();
@ -647,7 +647,7 @@ void TabWidget::savePinnedTabs()
stream << tabs;
stream << tabsHistory;
QFile file(mApp->getActiveProfilPath() + "pinnedtabs.dat");
QFile file(mApp->currentProfilePath() + "pinnedtabs.dat");
file.open(QIODevice::WriteOnly);
file.write(data);
file.close();
@ -655,7 +655,7 @@ void TabWidget::savePinnedTabs()
void TabWidget::restorePinnedTabs()
{
QFile file(mApp->getActiveProfilPath() + "pinnedtabs.dat");
QFile file(mApp->currentProfilePath() + "pinnedtabs.dat");
file.open(QIODevice::ReadOnly);
QByteArray sd = file.readAll();
file.close();

View File

@ -803,7 +803,7 @@ void WebView::createSelectedTextContextMenu(QMenu* menu, const QWebHitTestResult
menu->addAction(QIcon::fromTheme("mail-message-new"), tr("Send text..."), this, SLOT(sendLinkByMail()))->setData(selectedText);
menu->addSeparator();
QString langCode = mApp->getActiveLanguage().left(2);
QString langCode = mApp->currentLanguage().left(2);
QUrl googleTranslateUrl = QUrl(QString("http://translate.google.com/#auto|%1|%2").arg(langCode, selectedText));
Action* gtwact = new Action(QIcon(":icons/menu/translate.png"), tr("Google Translate"));
gtwact->setData(googleTranslateUrl);

View File

@ -66,7 +66,7 @@ bool AKN_Plugin::testPlugin()
QTranslator* AKN_Plugin::getTranslator(const QString &locale)
{
QTranslator* translator = new QTranslator(this);
translator->load(":/accesskeysnavigation/locale/" + locale);
translator->load(locale, ":/accesskeysnavigation/locale/");
return translator;
}

View File

@ -72,8 +72,8 @@ bool MouseGestures::mousePress(QObject* obj, QMouseEvent* event)
if (frame->scrollBarGeometry(Qt::Vertical).contains(event->pos()) ||
frame->scrollBarGeometry(Qt::Horizontal).contains(event->pos())) {
return false;
}
return false;
}
m_filter->mouseButtonPressEvent(event);

View File

@ -35,7 +35,7 @@ PluginSpec MouseGesturesPlugin::pluginSpec()
spec.name = "Mouse Gestures";
spec.info = "Mouse gestures for QupZilla";
spec.description = "Provides support for navigating in webpages by mouse gestures";
spec.version = "0.2.1";
spec.version = "0.3.1";
spec.author = "David Rosca <nowrep@gmail.com>";
spec.icon = QPixmap(":/mousegestures/data/icon.png");
spec.hasSettings = true;
@ -69,7 +69,7 @@ bool MouseGesturesPlugin::testPlugin()
QTranslator* MouseGesturesPlugin::getTranslator(const QString &locale)
{
QTranslator* translator = new QTranslator(this);
translator->load(":/mousegestures/locale/" + locale);
translator->load(locale, ":/mousegestures/locale/");
return translator;
}

View File

@ -98,7 +98,7 @@ QTranslator* TestPlugin::getTranslator(const QString &locale)
// QString locale will contains "fr_FR.qm" for French locale
QTranslator* translator = new QTranslator(this);
translator->load(":/testplugin/locale/" + locale);
translator->load(locale, ":/testplugin/locale/");
return translator;
}