Skip to content
Permalink
Browse files

Fix for #798 - users need to be able to set locale easily

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@7371 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux
timlinux committed Nov 10, 2007
1 parent 354e3ba commit 54768fb71ce4fe63b276d7e127e1d4ae6f10f818
Showing with 169 additions and 15 deletions.
  1. +39 −15 src/app/main.cpp
  2. +38 −0 src/app/qgsoptions.cpp
  3. +3 −0 src/app/qgsoptions.h
  4. +89 −0 src/ui/qgsoptionsbase.ui
@@ -24,7 +24,7 @@
#include <QFont>
#include <QMessageBox>
#include <QPixmap>
#include <QPixmap>
#include <QLocale>
#include <QSettings>
#include <QSplashScreen>
#include <QString>
@@ -258,7 +258,7 @@ int main(int argc, char *argv[])

// This behaviour will allow you to force the use of a translation file
// which is useful for testing
QString myTranslationCode="";
QString myTranslationCode;

#ifndef WIN32
if ( !bundleclicked(argc, argv) )
@@ -418,15 +418,49 @@ int main(int argc, char *argv[])
// a.setFont(QFont("helvetica", 11));

QString i18nPath = QgsApplication::i18nPath();
if (myTranslationCode.isEmpty())


/* Translation file for QGIS.
*/
QSettings mySettings;
QString mySystemLocale = QLocale::languageToString(QLocale::system().language());
QString myUserLocale = mySettings.value("locale/userLocale", "").toString();
bool myLocaleOverrideFlag = mySettings.value("locale/overrideFlag",false).toBool();
QString myLocale;
//
// Priority of translation is:
// - command line
// - user secified in options dialog (with group checked on)
// - system locale
//
// When specifying from the command line it will change the user
// specified user locale
//
if (!myTranslationCode.isNull() && !myTranslationCode.isEmpty())
{
myTranslationCode = QTextCodec::locale();
mySettings.setValue("locale/userLocale", myTranslationCode);
}
else
{
if (!myLocaleOverrideFlag || myUserLocale.isEmpty())
{
myTranslationCode = QTextCodec::locale();
}
else
{
myTranslationCode = myUserLocale;
}
}

#ifdef QGISDEBUG
std::cout << "Setting translation to "
<< i18nPath.toLocal8Bit().data() << "/qgis_" << myTranslationCode.toLocal8Bit().data() << std::endl;
#endif

QTranslator qgistor(0);
if (qgistor.load(QString("qgis_") + myTranslationCode, i18nPath))
{
a.installTranslator(&qgistor);
}
/* Translation file for Qt.
* The strings from the QMenuBar context section are used by Qt/Mac to shift
* the About, Preferences and Quit items to the Mac Application menu.
@@ -438,19 +472,10 @@ int main(int argc, char *argv[])
a.installTranslator(&qttor);
}

/* Translation file for QGIS.
*/
QTranslator qgistor(0);
if (qgistor.load(QString("qgis_") + myTranslationCode, i18nPath))
{
a.installTranslator(&qgistor);
}

//set up splash screen
QString mySplashPath(QgsApplication::splashPath());
QPixmap myPixmap(mySplashPath+QString("splash.png"));
QSplashScreen *mypSplash = new QSplashScreen(myPixmap);
QSettings mySettings;
if (mySettings.value("/qgis/hideSplash").toBool())
{
//splash screen hidden
@@ -460,7 +485,6 @@ int main(int argc, char *argv[])
#if defined(Q_OS_MACX) && QT_VERSION < 0x040300
//on mac automasking as done below does not work (as of qt 4.2.1)
//so we do it the old way see bug #387
qDebug("setting mask for mac");
QPixmap myMaskPixmap(mySplashPath+QString("splash_mask.png"), 0, Qt::ThresholdDither | Qt::ThresholdAlphaDither | Qt::AvoidDither );
mypSplash->setMask( myMaskPixmap.createHeuristicMask() );
#else
@@ -26,6 +26,8 @@
#include <QFileDialog>
#include <QSettings>
#include <QColorDialog>
#include <QLocale>
#include <QTextCodec>

#include <cassert>
#include <iostream>
@@ -139,6 +141,21 @@ QgsOptions::QgsOptions(QWidget *parent, Qt::WFlags fl) :
spinZoomFactor->setValue(settings.value("/qgis/zoom_factor", 2).toDouble());

cbxSplitterRedraw->setChecked(settings.value("/qgis/splitterRedraw", QVariant(true)).toBool());

//
// Locale settings
//
QString mySystemLocale = QTextCodec::locale();
lblSystemLocale->setText(tr("Detected active locale on your system: ") + mySystemLocale);
QString myUserLocale = settings.value("locale/userLocale", "").toString();
QStringList myI18nList = i18nList();
cboLocale->addItems(myI18nList);
if (myI18nList.contains(myUserLocale))
{
cboLocale->setCurrentText(myUserLocale);
}
bool myLocaleOverrideFlag = settings.value("locale/overrideFlag",false).toBool();
grpLocale->setChecked(myLocaleOverrideFlag);
}

//! Destructor
@@ -245,6 +262,11 @@ void QgsOptions::saveOptions()
settings.writeEntry("/qgis/zoom_factor", spinZoomFactor->value());

settings.setValue("/qgis/splitterRedraw", cbxSplitterRedraw->isChecked());
//
// Locale settings
//
settings.setValue("locale/userLocale", cboLocale->currentText());
settings.setValue("locale/overrideFlag", grpLocale->isChecked());
}


@@ -425,3 +447,19 @@ QString QgsOptions::getEllipsoidName(QString theEllipsoidAcronym)
return myName;

}

QStringList QgsOptions::i18nList()
{
QStringList myList;
myList << "en_US"; //there is no qm file for this so we add it manually
QString myI18nPath = QgsApplication::i18nPath();
QDir myDir(myI18nPath,"*.qm");
QStringList myFileList = myDir.entryList();
QStringListIterator myIterator(myFileList);
while (myIterator.hasNext())
{
QString myFileName = myIterator.next();
myList << myFileName.replace("qgis_","").replace(".qm","");
}
return myList;
}
@@ -85,6 +85,9 @@ class QgsOptions :public QDialog, private Ui::QgsOptionsBase
QString getEllipsoidName(QString theEllipsoidAcronym);

private:
//
QStringList i18nList();

//! Pointer to our parent
QWidget *qparent;

@@ -723,6 +723,95 @@ p, li { white-space: pre-wrap; }
</item>
</layout>
</widget>
<widget class="QWidget" name="tabLocale" >
<attribute name="title" >
<string>Locale</string>
</attribute>
<layout class="QGridLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="0" column="0" >
<widget class="QGroupBox" name="grpLocale" >
<property name="title" >
<string>Force Override System Locale</string>
</property>
<property name="checkable" >
<bool>true</bool>
</property>
<layout class="QGridLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="0" column="0" >
<widget class="QLabel" name="label_5" >
<property name="text" >
<string>Locale to use instead</string>
</property>
<property name="buddy" >
<cstring>cboLocale</cstring>
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="QComboBox" name="cboLocale" />
</item>
<item row="1" column="0" colspan="2" >
<widget class="QLabel" name="label_7" >
<property name="text" >
<string>Note: Enabling / changing overide on local requires an application restart.</string>
</property>
<property name="wordWrap" >
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="2" column="0" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<size>
<width>501</width>
<height>51</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0" >
<widget class="QGroupBox" name="groupBox_12" >
<property name="title" >
<string>Additional Info</string>
</property>
<layout class="QGridLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="0" column="0" >
<widget class="QLabel" name="lblSystemLocale" >
<property name="text" >
<string>Detected active locale on your system:</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabHelpBrowser" >
<attribute name="title" >
<string>Help &amp;Browser</string>

0 comments on commit 54768fb

Please sign in to comment.
You can’t perform that action at this time.