Changeset 356:c937146a645c in SMSSender


Ignore:
Timestamp:
Mar 31, 2014 9:43:11 PM (5 years ago)
Author:
Sämy Zehnder <saemy.zehnder@…>
Branch:
separation-frontend-backend
Message:
  • Translations are now discovered by looking at the ":/locale/" directory instead of explicitly having to specify them in every library. This also fixes a bug where translations were sometimes not available in the program although they were defined.
Files:
25 edited

Legend:

Unmodified
Added
Removed
  • common/business/ilibrary.h

    r320 r356  
    5353    virtual QString compatibilityVersion() const =0; // To prevent loading too old/new libraries
    5454
    55     virtual QSet<QTranslator*> translators() const =0;
    5655    virtual QSet<IContactImporter::Builder *> contactImporters() const =0;
    5756    /**
  • frontend/business/settings_base.cpp

    r316 r356  
    5252
    5353QList<QLocale> BaseSettings::getLocales(){
    54     QList<QLocale> return_;
    55 
    56     return_.append(QLocale(QLocale::English)); // Default language
     54    QList<QLocale> locales;
     55
     56    locales.append(QLocale(QLocale::English)); // Default language
    5757
    5858    QDirIterator i(getLocalePath());
    5959    while (i.hasNext()) {
    60          QString localeStr = QFileInfo(i.next()).baseName();
    61          QLocale locale(localeStr);
    62          if ((locale != QLocale::c()) && (!return_.contains(locale))){ // Was the creation of the locale successful?
    63              return_.append(locale);
    64          }
    65      }
    66      return return_;
     60        // [prefix].[locale].qm
     61        QString localeStr = i.next().split('.').at(1);
     62
     63        QLocale locale(localeStr);
     64        if ((locale != QLocale::c()) && (!locales.contains(locale))){
     65            // This locale string is valid and has not been seen before.
     66            locales.append(locale);
     67        }
     68    }
     69    return locales;
    6770}
    6871
  • frontend/gui/bootstrap.cpp

    r353 r356  
    5151    loadLibraries();
    5252
     53    initTranslators();
    5354    installTranslators();
    5455    setNetworkProxy();
     
    122123}
    123124
     125
     126/**
     127 * Crawls the directory 'kTranslationsPath' for files named
     128 * [prefix].[language].qm and adds them to the pool of available translation
     129 * files.
     130 */
     131void Bootstrap::initTranslators() {
     132    QDir translationDir = m_managerFactory->settingsManager()->getLocalePath();
     133    QStringList translationFilters;
     134    translationFilters.append("*.qm");
     135    translationDir.setNameFilters(translationFilters);
     136    translationDir.setFilter(QDir::Files | QDir::Readable);
     137
     138    foreach (QString filename, translationDir.entryList()) {
     139        QStringList parts = filename.split('.');
     140        Q_ASSERT(parts.size() == 3);
     141
     142        QString prefix = parts.first();
     143        m_translationPrefixes.insert(prefix + ".");
     144    }
     145}
     146
    124147void Bootstrap::installTranslators() {
    125     // Remove old translators
     148    // Removes old translators.
    126149    uninstallTranslators();
    127150
    128     // Get the new locale
     151    // Gets the new locale.
    129152    QLocale locale = m_managerFactory->settingsManager()->getLocale();
    130153    QLocale::setDefault(locale);
    131154
    132     // Enable swiss german translations (FIXME: Does this make any sense?)
    133     QLocale sysLocale = locale;
    134     if ((locale.language() == QLocale::German) && (locale.country() != QLocale::Switzerland)) {
    135         sysLocale = QLocale(QLocale::German, QLocale::Switzerland);
    136     }
    137 
    138     // Load the qt translator
    139     QTranslator* qtTranslator = new QTranslator();
    140     qtTranslator->load("qt_" + sysLocale.name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
    141     installTranslator(qtTranslator);
    142 
    143     // Load the app translator
    144     QTranslator* appTranslator = new QTranslator();
    145     appTranslator->load(locale.name(), m_managerFactory->settingsManager()->getLocalePath().absolutePath());
    146     installTranslator(appTranslator);
    147 
    148     // Library translators
    149     foreach (ILibrary *library, m_libraryLoader->libraries()) {
    150         foreach (QTranslator *translator, library->translators()) {
    151             installTranslator(translator);
    152         }
    153     }
    154 }
    155 
    156 void Bootstrap::installTranslator(QTranslator *translator) {
    157     qApp->installTranslator(translator);
    158     m_translators.insert(translator);
     155    // Installs the Qt translator.
     156    installTranslator(locale, "qt_",
     157                      QLibraryInfo::location(QLibraryInfo::TranslationsPath));
     158
     159    // Installs our translators.
     160    QString localePath =
     161            m_managerFactory->settingsManager()->getLocalePath().absolutePath();
     162    foreach (QString prefix, m_translationPrefixes) {
     163        installTranslator(locale, prefix, localePath);
     164    }
     165}
     166
     167void Bootstrap::installTranslator(const QLocale &locale, const QString &prefix,
     168                                  const QString &path) {
     169    QScopedPointer<QTranslator> t(new QTranslator(this));
     170    if (t->load(locale, prefix, "", path)) {
     171        qApp->installTranslator(t.data());
     172        m_translators.insert(t.take());
     173    }
    159174}
    160175
  • frontend/gui/bootstrap.h

    r316 r356  
    6262    void setNetworkProxy();
    6363
     64    void initTranslators();
    6465    void installTranslators();
    65     void installTranslator(QTranslator *translator);
     66    void installTranslator(const QLocale &locale, const QString &prefix,
     67                           const QString &path);
    6668    void uninstallTranslators();
    6769
     
    7072    QScopedPointer<Persistence::PersistenceFactory> m_persistenceFactory;
    7173    QScopedPointer<LibraryLoader> m_libraryLoader;
     74    QSet<QString> m_translationPrefixes;
    7275    QSet<QTranslator*> m_translators;
    7376
  • frontend/gui/lib/frontend-gui.qrc

    r315 r356  
    3434    </qresource>
    3535    <qresource prefix="/locale">
    36         <file alias="de.qm">../locale/de.qm</file>
    37         <file alias="fr.qm">../locale/fr.qm</file>
    38         <file alias="it.qm">../locale/it.qm</file>
    39         <file alias="de_CH.qm">../locale/de_CH.qm</file>
     36        <file alias="frontend-gui.de.qm">../locale/de.qm</file>
     37        <file alias="frontend-gui.fr.qm">../locale/fr.qm</file>
     38        <file alias="frontend-gui.it.qm">../locale/it.qm</file>
     39        <file alias="frontend-gui.de_CH.qm">../locale/de_CH.qm</file>
    4040    </qresource>
    4141</RCC>
  • frontend/lib/frontend.qrc

    r315 r356  
    11<RCC>
    22    <qresource prefix="/locale">
    3         <file alias="de.qm">../locale/de.qm</file>
    4         <file alias="fr.qm">../locale/fr.qm</file>
    5         <file alias="it.qm">../locale/it.qm</file>
    6         <file alias="de_CH.qm">../locale/de_CH.qm</file>
     3        <file alias="frontend-base.de.qm">../locale/de.qm</file>
     4        <file alias="frontend-base.fr.qm">../locale/fr.qm</file>
     5        <file alias="frontend-base.it.qm">../locale/it.qm</file>
     6        <file alias="frontend-base.de_CH.qm">../locale/de_CH.qm</file>
    77    </qresource>
    88    <qresource prefix="/certs">
  • gateways/ETHZ/gui/ethz.cpp

    r347 r356  
    3131bool Library::doInit(
    3232        const IBaseIntegrationHelper::Factory &integrationHelperFactory,
    33         QSet<QTranslator*> *translators, IGateway **gateway,
    34         QSet<IContactImporter::Builder *> *contactImporters)
     33        IGateway **gateway, QSet<IContactImporter::Builder *> *contactImporters)
    3534{
    36     // Translators
    37     QLocale l; // Loads default locale
    38     QScopedPointer<QTranslator> t(new QTranslator);
    39     if (t->load("schoolnet-" + l.name(), ":/locale")) {
    40         translators->insert(t.take());
    41     }
    42 
    4335    // Gateway
    4436    *gateway = new Gateway;
  • gateways/ETHZ/gui/ethz.h

    r347 r356  
    3333protected:
    3434    bool doInit(const IIntegrationHelper::Factory &integrationHelperFactory,
    35                 QSet<QTranslator*> *translators, IGateway **gateway,
     35                IGateway **gateway,
    3636                QSet<IContactImporter::Builder *> *contactImporters);
    3737
  • gateways/ETHZ/gui/lib/ethz-gui.qrc

    r347 r356  
    44    </qresource>
    55    <qresource prefix="/locale">
    6         <file alias="ethz-de.qm">../locale/de.qm</file>
    7         <file alias="ethz-fr.qm">../locale/fr.qm</file>
    8         <file alias="ethz-it.qm">../locale/it.qm</file>
    9         <file alias="ethz-de_CH.qm">../locale/de_CH.qm</file>
     6        <file alias="ethz-gui.de.qm">../locale/de.qm</file>
     7        <file alias="ethz-gui.fr.qm">../locale/fr.qm</file>
     8        <file alias="ethz-gui.it.qm">../locale/it.qm</file>
     9        <file alias="ethz-gui.de_CH.qm">../locale/de_CH.qm</file>
    1010    </qresource>
    1111</RCC>
  • gateways/ETHZ/lib/ethz.qrc

    r347 r356  
    44    </qresource>
    55    <qresource prefix="/locale">
    6         <file alias="ethz-de.qm">../locale/de.qm</file>
    7         <file alias="ethz-fr.qm">../locale/fr.qm</file>
    8         <file alias="ethz-it.qm">../locale/it.qm</file>
    9         <file alias="ethz-de_CH.qm">../locale/de_CH.qm</file>
     6        <file alias="ethz-base.de.qm">../locale/de.qm</file>
     7        <file alias="ethz-base.fr.qm">../locale/fr.qm</file>
     8        <file alias="ethz-base.it.qm">../locale/it.qm</file>
     9        <file alias="ethz-base.de_CH.qm">../locale/de_CH.qm</file>
    1010    </qresource>
    1111</RCC>
  • gateways/Schoolnet/gui/lib/schoolnet-gui.qrc

    r315 r356  
    99        <file>question_list.png</file>
    1010    </qresource>
     11    <qresource prefix="/locale">
     12        <file alias="schoolnet-gui.de.qm">../locale/de.qm</file>
     13        <file alias="schoolnet-gui.fr.qm">../locale/fr.qm</file>
     14        <file alias="schoolnet-gui.it.qm">../locale/it.qm</file>
     15        <file alias="schoolnet-gui.de_CH.qm">../locale/de_CH.qm</file>
     16    </qresource>
    1117</RCC>
  • gateways/Schoolnet/gui/schoolnet.cpp

    r320 r356  
    3333bool Library::doInit(
    3434        const IBaseIntegrationHelper::Factory &integrationHelperFactory,
    35         QSet<QTranslator*> *translators, IGateway **gateway,
    36         QSet<IContactImporter::Builder *> *contactImporters)
     35        IGateway **gateway, QSet<IContactImporter::Builder *> *contactImporters)
    3736{
    38     // Translators
    39     QLocale l; // Loads default locale
    40     QScopedPointer<QTranslator> t(new QTranslator);
    41     if (t->load("schoolnet-" + l.name(), ":/locale")) {
    42         translators->insert(t.take());
    43     }
    44 
    4537    // Gateway
    4638    *gateway = new Gateway;
  • gateways/Schoolnet/gui/schoolnet.h

    r320 r356  
    3939protected:
    4040    bool doInit(const IIntegrationHelper::Factory &integrationHelperFactory,
    41                 QSet<QTranslator*> *translators, IGateway **gateway,
     41                IGateway **gateway,
    4242                QSet<IContactImporter::Builder *> *contactImporters);
    4343
  • gateways/Schoolnet/lib/schoolnet.qrc

    r315 r356  
    44    </qresource>
    55    <qresource prefix="/locale">
    6         <file alias="schoolnet-de.qm">../locale/de.qm</file>
    7         <file alias="schoolnet-fr.qm">../locale/fr.qm</file>
    8         <file alias="schoolnet-it.qm">../locale/it.qm</file>
    9         <file alias="schoolnet-de_CH.qm">../locale/de_CH.qm</file>
     6        <file alias="schoolnet-base.de.qm">../locale/de.qm</file>
     7        <file alias="schoolnet-base.fr.qm">../locale/fr.qm</file>
     8        <file alias="schoolnet-base.it.qm">../locale/it.qm</file>
     9        <file alias="schoolnet-base.de_CH.qm">../locale/de_CH.qm</file>
    1010    </qresource>
    1111</RCC>
  • gateways/Smartphone/gui/lib/smartphone-gui.qrc

    r336 r356  
    55        <file>disconnected.png</file>
    66    </qresource>
     7    <qresource prefix="/locale">
     8        <file alias="smartphone-gui.de.qm">../locale/de.qm</file>
     9        <file alias="smartphone-gui.fr.qm">../locale/fr.qm</file>
     10        <file alias="smartphone-gui.it.qm">../locale/it.qm</file>
     11        <file alias="smartphone-gui.de_CH.qm">../locale/de_CH.qm</file>
     12    </qresource>
    713</RCC>
  • gateways/Smartphone/gui/smartphone.cpp

    r336 r356  
    3030bool Library::doInit(
    3131        const IBaseIntegrationHelper::Factory &integrationHelperFactory,
    32         QSet<QTranslator*> *translators, IGateway **gateway,
    33         QSet<IContactImporter::Builder *> *contactImporters)
     32        IGateway **gateway, QSet<IContactImporter::Builder *> *contactImporters)
    3433{
    35     // Translators
    36     QLocale l; // Loads default locale
    37     QScopedPointer<QTranslator> t(new QTranslator);
    38     if (t->load("smartphone-" + l.name(), ":/locale")) {
    39         translators->insert(t.take());
    40     }
    41 
    4234    // Create the smartphone manager
    4335    m_smartphoneManager.reset(new SmartphoneManager);
  • gateways/Smartphone/gui/smartphone.h

    r336 r356  
    3434protected: /* BaseLibrary */
    3535    bool doInit(const IIntegrationHelper::Factory &integrationHelperFactory,
    36                 QSet<QTranslator*> *translators, IGateway **gateway,
     36                IGateway **gateway,
    3737                QSet<IContactImporter::Builder *> *contactImporters);
    3838
  • gateways/Smartphone/lib/smartphone.qrc

    r336 r356  
    22    <qresource prefix="/certs"/>
    33    <qresource prefix="/locale">
    4         <file alias="smartphone-de.qm">../locale/de.qm</file>
    5         <file alias="smartphone-fr.qm">../locale/fr.qm</file>
    6         <file alias="smartphone-it.qm">../locale/it.qm</file>
    7         <file alias="smartphone-de_CH.qm">../locale/de_CH.qm</file>
     4        <file alias="smartphone-base.de.qm">../locale/de.qm</file>
     5        <file alias="smartphone-base.fr.qm">../locale/fr.qm</file>
     6        <file alias="smartphone-base.it.qm">../locale/it.qm</file>
     7        <file alias="smartphone-base.de_CH.qm">../locale/de_CH.qm</file>
    88    </qresource>
    99</RCC>
  • gateways/Sunrise/gui/lib/sunrise-gui.qrc

    r330 r356  
    33        <file>Sunrise.ico</file>
    44    </qresource>
     5    <qresource prefix="/locale">
     6        <file alias="sunrise-gui.de.qm">../locale/de.qm</file>
     7        <file alias="sunrise-gui.de_CH.qm">../locale/de_CH.qm</file>
     8        <file alias="sunrise-gui.fr.qm">../locale/fr.qm</file>
     9        <file alias="sunrise-gui.it.qm">../locale/it.qm</file>
     10    </qresource>
    511</RCC>
  • gateways/Sunrise/gui/sunrise.cpp

    r330 r356  
    3030bool Library::doInit(
    3131        const IBaseIntegrationHelper::Factory &integrationHelperFactory,
    32         QSet<QTranslator*> *translators, IGateway **gateway,
    33         QSet<IContactImporter::Builder *> *contactImporters) {
    34     // Translators
    35     QLocale l; // Loads default locale
    36     QScopedPointer<QTranslator> t(new QTranslator);
    37     if (t->load("sunrise-" + l.name(), ":/locale")) {
    38         translators->insert(t.take());
    39     }
    40 
     32        IGateway **gateway,
     33        QSet<IContactImporter::Builder *> *contactImporters)
     34{
    4135    // Gateway
    4236    Gateway *gtwy = new Gateway();
  • gateways/Sunrise/gui/sunrise.h

    r330 r356  
    3030protected:
    3131    bool doInit(const IIntegrationHelper::Factory &integrationHelperFactory,
    32                 QSet<QTranslator*> *translators, IGateway **gateway,
     32                IGateway **gateway,
    3333                QSet<IContactImporter::Builder *> *contactImporters);
    3434
  • gateways/Sunrise/lib/sunrise.qrc

    r330 r356  
    44    </qresource>
    55    <qresource prefix="/locale">
    6         <file alias="sunrise-de.qm">../locale/de.qm</file>
    7         <file alias="sunrise-de_CH.qm">../locale/de_CH.qm</file>
    8         <file alias="sunrise-fr.qm">../locale/fr.qm</file>
    9         <file alias="sunrise-it.qm">../locale/it.qm</file>
     6        <file alias="sunrise-base.de.qm">../locale/de.qm</file>
     7        <file alias="sunrise-base.de_CH.qm">../locale/de_CH.qm</file>
     8        <file alias="sunrise-base.fr.qm">../locale/fr.qm</file>
     9        <file alias="sunrise-base.it.qm">../locale/it.qm</file>
    1010    </qresource>
    1111</RCC>
  • gateways/common/business/baselibrary.cpp

    r324 r356  
    2323BaseLibrary::~BaseLibrary() {
    2424    qDeleteAll(m_contactImporters);
    25     qDeleteAll(m_translators);
    2625}
    2726
    2827bool BaseLibrary::init(const IBaseIntegrationHelper::Factory &integrationHelperFactory) {
    2928    IGateway *gateway = NULL;
    30     bool successful = doInit(integrationHelperFactory, &m_translators, &gateway, &m_contactImporters);
     29    bool successful =
     30            doInit(integrationHelperFactory, &gateway, &m_contactImporters);
    3131    m_gateway.reset(gateway);
    3232
     
    3434}
    3535
    36 QSet<QTranslator*> BaseLibrary::translators() const {
    37     return m_translators;
    38 }
    3936QSet<IContactImporter::Builder *> BaseLibrary::contactImporters() const {
    4037    return m_contactImporters;
  • gateways/common/business/baselibrary.h

    r320 r356  
    2222#include <QSet>
    2323#include <QString>
    24 #include <QTranslator>
    2524
    2625#include "common/business/icontactimporter.h"
     
    4847    virtual bool init(const IIntegrationHelper::Factory &integrationHelperFactory);
    4948
    50     virtual QSet<QTranslator *> translators() const;
    5149    virtual QSet<IContactImporter::Builder *> contactImporters() const;
    5250    virtual IGateway *gateway() const;
     
    6664     */
    6765    virtual bool doInit(const IIntegrationHelper::Factory &integrationHelperFactory,
    68                         QSet<QTranslator*> *translators, IGateway **gateways,
     66                        IGateway **gateways,
    6967                        QSet<IContactImporter::Builder *> *contactImporters) =0;
    7068
    7169private:
    72     QSet<QTranslator *> m_translators;
    7370    QScopedPointer<IGateway> m_gateway;
    7471    QSet<IContactImporter::Builder *> m_contactImporters;
  • gateways/common/gateways-common.pro

    r350 r356  
    4444    persistence/defaultaccountstoragehelper.cpp
    4545
     46RESOURCES = \
     47    lib/gateways-common.qrc
     48
    4649install_dev_files:unix {
    4750    ADDITIONAL_INSTALLS = $$HEADERS ../*.pri
Note: See TracChangeset for help on using the changeset viewer.