language is now changable (settings -> appearance -> general). default is still the...
authorMarcus Eggenberger <egs@quassel-irc.org>
Sat, 19 Jul 2008 19:05:18 +0000 (21:05 +0200)
committerMarcus Eggenberger <egs@quassel-irc.org>
Sat, 19 Jul 2008 19:05:18 +0000 (21:05 +0200)
src/common/main.cpp
src/common/util.cpp
src/common/util.h
src/qtui/mainwin.cpp
src/qtui/settingspages/appearancesettingspage.cpp
src/qtui/settingspages/appearancesettingspage.h
src/qtui/settingspages/appearancesettingspage.ui
src/uisupport/uisettings.cpp
src/uisupport/uisettings.h

index bac4308..d7cd4e5 100644 (file)
@@ -106,11 +106,13 @@ int main(int argc, char **argv) {
   // Set up i18n support
   QLocale locale = QLocale::system();
 
   // Set up i18n support
   QLocale locale = QLocale::system();
 
-  QTranslator qtTranslator;
+  QTranslator qtTranslator(&app);
+  qtTranslator.setObjectName("QtTr");
   qtTranslator.load(QString(":i18n/qt_%1").arg(locale.name()));
   app.installTranslator(&qtTranslator);
 
   qtTranslator.load(QString(":i18n/qt_%1").arg(locale.name()));
   app.installTranslator(&qtTranslator);
 
-  QTranslator quasselTranslator;
+  QTranslator quasselTranslator(&app);
+  quasselTranslator.setObjectName("QuasselTr");
   quasselTranslator.load(QString(":i18n/quassel_%1").arg(locale.name()));
   app.installTranslator(&quasselTranslator);
 
   quasselTranslator.load(QString(":i18n/quassel_%1").arg(locale.name()));
   app.installTranslator(&quasselTranslator);
 
index 4c1a22f..9bd17d9 100644 (file)
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
+#include "util.h"
+
 #include <QCoreApplication>
 #include <QDebug>
 #include <QTextCodec>
 #include <QCoreApplication>
 #include <QDebug>
 #include <QTextCodec>
-
-#include "util.h"
+#include <QTranslator>
 
 class QMetaMethod;
 
 
 class QMetaMethod;
 
@@ -104,7 +105,6 @@ bool readDataFromDevice(QIODevice *dev, quint32 &blockSize, QVariant &item) {
 uint editingDistance(const QString &s1, const QString &s2) {
   uint n = s1.size()+1;
   uint m = s2.size()+1;
 uint editingDistance(const QString &s1, const QString &s2) {
   uint n = s1.size()+1;
   uint m = s2.size()+1;
-  //uint matrix[n][m];
   QVector< QVector< uint > >matrix(n,QVector<uint>(m,0));
 
   for(uint i = 0; i < n; i++)
   QVector< QVector< uint > >matrix(n,QVector<uint>(m,0));
 
   for(uint i = 0; i < n; i++)
@@ -159,6 +159,26 @@ QDir quasselDir() {
   return qDir;
 }
 
   return qDir;
 }
 
+void loadTranslation(const QLocale &locale) {
+  QTranslator *qtTranslator = QCoreApplication::instance()->findChild<QTranslator *>("QtTr");
+  QTranslator *quasselTranslator = QCoreApplication::instance()->findChild<QTranslator *>("QuasselTr");
+  Q_ASSERT(qtTranslator);
+  Q_ASSERT(quasselTranslator);
+
+  QLocale::setDefault(locale);
+
+  QCoreApplication::removeTranslator(qtTranslator);
+  QCoreApplication::removeTranslator(quasselTranslator);
+
+  if(locale.language() == QLocale::C)
+    return;
+  
+  qtTranslator->load(QString(":i18n/qt_%1").arg(locale.name()));
+  quasselTranslator->load(QString(":i18n/quassel_%1").arg(locale.name()));
+
+  QCoreApplication::installTranslator(qtTranslator);
+  QCoreApplication::installTranslator(quasselTranslator);
+}
 
 QString secondsToString(int timeInSeconds) {
     QList< QPair<int, QString> > timeUnit;
 
 QString secondsToString(int timeInSeconds) {
     QList< QPair<int, QString> > timeUnit;
index 5c954b2..36ef813 100644 (file)
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
-#ifndef _UTIL_H_
-#define _UTIL_H_
+#ifndef UTIL_H
+#define UTIL_H
 
 #include <QDir>
 
 #include <QDir>
-#include <QIODevice>
+#include <QLocale>
 #include <QVariant>
 #include <QString>
 #include <QMetaMethod>
 #include <QVariant>
 #include <QString>
 #include <QMetaMethod>
@@ -46,14 +46,12 @@ QString secondsToString(int timeInSeconds);
  */
 QString decodeString(const QByteArray &input, QTextCodec *codec = 0);
 
  */
 QString decodeString(const QByteArray &input, QTextCodec *codec = 0);
 
-// NOTE: We have static copies of these in SignalProxy...
-//void writeDataToDevice(QIODevice *, const QVariant &);
-//bool readDataFromDevice(QIODevice *, quint32 &, QVariant &);
-
 uint editingDistance(const QString &s1, const QString &s2);
 
 QByteArray methodName(const QMetaMethod &method);
 
 QDir quasselDir();
 
 uint editingDistance(const QString &s1, const QString &s2);
 
 QByteArray methodName(const QMetaMethod &method);
 
 QDir quasselDir();
 
+void loadTranslation(const QLocale &locale);
+
 #endif
 #endif
index 9b73d55..c1af8b0 100644 (file)
@@ -41,6 +41,7 @@
 #include "irclistmodel.h"
 #include "verticaldock.h"
 #include "uisettings.h"
 #include "irclistmodel.h"
 #include "verticaldock.h"
 #include "uisettings.h"
+#include "util.h"
 #include "qtuisettings.h"
 #include "jumpkeyhandler.h"
 
 #include "qtuisettings.h"
 #include "jumpkeyhandler.h"
 
@@ -79,6 +80,14 @@ MainWin::MainWin(QtUi *_gui, QWidget *parent)
     settingsDlg(new SettingsDlg(this)),
     debugConsole(new DebugConsole(this))
 {
     settingsDlg(new SettingsDlg(this)),
     debugConsole(new DebugConsole(this))
 {
+  UiSettings uiSettings;
+  loadTranslation(uiSettings.value("Locale", QLocale::system()).value<QLocale>());
+  
+  QString style = uiSettings.value("Style", QString("")).toString();
+  if(style != "") {
+    QApplication::setStyle(style);
+  }
+  
   ui.setupUi(this);
   setWindowTitle("Quassel IRC");
   setWindowIcon(offlineTrayIcon);
   ui.setupUi(this);
   setWindowTitle("Quassel IRC");
   setWindowIcon(offlineTrayIcon);
@@ -90,11 +99,6 @@ MainWin::MainWin(QtUi *_gui, QWidget *parent)
 
   installEventFilter(new JumpKeyHandler(this));
 
 
   installEventFilter(new JumpKeyHandler(this));
 
-  UiSettings uiSettings;
-  QString style = uiSettings.value("Style", QString("")).toString();
-  if(style != "") {
-    QApplication::setStyle(style);
-  }
 }
 
 void MainWin::init() {
 }
 
 void MainWin::init() {
index 14c7924..4fcaa0d 100644 (file)
@@ -3,16 +3,16 @@
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU Appearance Public License as published by  *
+ *   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         *
  *   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 Appearance Public License for more details.                          *
+ *   GNU General Public License for more details.                          *
  *                                                                         *
  *                                                                         *
- *   You should have received a copy of the GNU Appearance Public License     *
+ *   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.             *
  *   along with this program; if not, write to the                         *
  *   Free Software Foundation, Inc.,                                       *
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 
 #include "qtui.h"
 #include "uisettings.h"
 
 #include "qtui.h"
 #include "uisettings.h"
+#include "util.h"
 
 
+#include <QDir>
 #include <QStyleFactory>
 
 AppearanceSettingsPage::AppearanceSettingsPage(QWidget *parent)
   : SettingsPage(tr("Appearance"), tr("General"), parent) {
   ui.setupUi(this);
   initStyleComboBox();
 #include <QStyleFactory>
 
 AppearanceSettingsPage::AppearanceSettingsPage(QWidget *parent)
   : SettingsPage(tr("Appearance"), tr("General"), parent) {
   ui.setupUi(this);
   initStyleComboBox();
+  initLanguageComboBox();
 
   connect(ui.styleComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(widgetHasChanged())); 
 
   connect(ui.styleComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(widgetHasChanged())); 
+  connect(ui.languageComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(widgetHasChanged())); 
 }
 
 void AppearanceSettingsPage::initStyleComboBox() {
 }
 
 void AppearanceSettingsPage::initStyleComboBox() {
@@ -41,8 +45,17 @@ void AppearanceSettingsPage::initStyleComboBox() {
   }
 }
 
   }
 }
 
-bool AppearanceSettingsPage::hasDefaults() const {
-  return true;
+void AppearanceSettingsPage::initLanguageComboBox() {
+  QDir i18nDir(":/i18n", "quassel_*.qm");
+
+  foreach(QString translationFile, i18nDir.entryList()) {
+    QString localeName(translationFile.mid(8));
+    localeName.chop(3);
+    QLocale locale(localeName);
+    _locales << locale;
+    ui.languageComboBox->addItem(QLocale::languageToString(locale.language()));
+  }
+
 }
 
 void AppearanceSettingsPage::defaults() {
 }
 
 void AppearanceSettingsPage::defaults() {
@@ -62,6 +75,15 @@ void AppearanceSettingsPage::load() {
     QApplication::setStyle(settings["Style"].toString());
   }
 
     QApplication::setStyle(settings["Style"].toString());
   }
 
+  QLocale locale = uiSettings.value("Locale", QLocale::system()).value<QLocale>();
+  if(locale == QLocale::system())
+    ui.languageComboBox->setCurrentIndex(0);
+  else if(locale.language() == QLocale::C)
+    ui.languageComboBox->setCurrentIndex(1);
+  else
+    ui.languageComboBox->setCurrentIndex(ui.languageComboBox->findText(QLocale::languageToString(locale.language()), Qt::MatchExactly));
+  loadTranslation(selectedLocale());
+
   setChangedState(false);
 }
 
   setChangedState(false);
 }
 
@@ -74,17 +96,36 @@ void AppearanceSettingsPage::save() {
     uiSettings.setValue("Style", ui.styleComboBox->currentText());
   }
 
     uiSettings.setValue("Style", ui.styleComboBox->currentText());
   }
 
+  if(ui.languageComboBox->currentIndex() == 0) {
+    uiSettings.remove("Locale"); // force the default (QLocale::system())
+  } else {
+    uiSettings.setValue("Locale", selectedLocale());
+  }
+  
   load();
   setChangedState(false);
 }
 
   load();
   setChangedState(false);
 }
 
+QLocale AppearanceSettingsPage::selectedLocale() const {
+  QLocale locale;
+  int index = ui.languageComboBox->currentIndex();
+  if(index == 0)
+    locale = QLocale::system();
+  else if(index == 1)
+    locale = QLocale::c();
+  else if(index > 1)
+    locale = _locales[index - 2];
+
+  return locale;
+}
+
 void AppearanceSettingsPage::widgetHasChanged() {
 void AppearanceSettingsPage::widgetHasChanged() {
-  bool changed = testHasChanged();
-  if(changed != hasChanged()) setChangedState(changed);
+  setChangedState(testHasChanged());
 }
 
 bool AppearanceSettingsPage::testHasChanged() {
   if(settings["Style"].toString() != ui.styleComboBox->currentText()) return true;
 }
 
 bool AppearanceSettingsPage::testHasChanged() {
   if(settings["Style"].toString() != ui.styleComboBox->currentText()) return true;
+  if(selectedLocale() != QLocale()) return true; // QLocale() returns the default locale (manipulated via loadTranslation())
 
   return false;
 }
 
   return false;
 }
index 6a4071f..96b5cf5 100644 (file)
@@ -3,25 +3,27 @@
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU Appearance Public License as published by  *
+ *   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         *
  *   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 Appearance Public License for more details.                          *
+ *   GNU General Public License for more details.                          *
  *                                                                         *
  *                                                                         *
- *   You should have received a copy of the GNU Appearance Public License     *
+ *   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.             *
  ***************************************************************************/
 
  *   along with this program; if not, write to the                         *
  *   Free Software Foundation, Inc.,                                       *
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
-#ifndef _APPEARANCESETTINGSPAGE_H_
-#define _APPEARANCESETTINGSPAGE_H_
+#ifndef APPEARANCESETTINGSPAGE_H
+#define APPEARANCESETTINGSPAGE_H
 
 #include <QHash>
 
 #include <QHash>
+#include <QList>
+#include <QLocale>
 
 #include "settingspage.h"
 #include "ui_appearancesettingspage.h"
 
 #include "settingspage.h"
 #include "ui_appearancesettingspage.h"
 class AppearanceSettingsPage : public SettingsPage {
   Q_OBJECT
 
 class AppearanceSettingsPage : public SettingsPage {
   Q_OBJECT
 
-  public:
-    AppearanceSettingsPage(QWidget *parent = 0);
-
-    bool hasDefaults() const;
-
-  public slots:
-    void save();
-    void load();
-    void defaults();
-
-  private slots:
-    void widgetHasChanged();
-
-  private:
-    Ui::AppearanceSettingsPage ui;
-    QHash<QString, QVariant> settings;
-
-    bool testHasChanged();
-    void initStyleComboBox();
+public:
+  AppearanceSettingsPage(QWidget *parent = 0);
+
+  inline bool hasDefaults() const { return true; }
+
+public slots:
+  void save();
+  void load();
+  void defaults();
+                
+private slots:
+  void widgetHasChanged();
+  
+private:
+  Ui::AppearanceSettingsPage ui;
+  QHash<QString, QVariant> settings;
+  QList<QLocale> _locales;
+
+  bool testHasChanged();
+  void initStyleComboBox();
+  void initLanguageComboBox();
+  QLocale selectedLocale() const;
 };
 
 #endif
 };
 
 #endif
index 3a9478f..ba01cb1 100644 (file)
@@ -5,14 +5,14 @@
    <rect>
     <x>0</x>
     <y>0</y>
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>400</width>
-    <height>300</height>
+    <width>331</width>
+    <height>269</height>
    </rect>
   </property>
   <property name="windowTitle" >
    <string>Form</string>
   </property>
    </rect>
   </property>
   <property name="windowTitle" >
    <string>Form</string>
   </property>
-  <layout class="QVBoxLayout" >
+  <layout class="QVBoxLayout" name="verticalLayout_2" >
    <item>
     <widget class="QGroupBox" name="groupBox" >
      <property name="title" >
    <item>
     <widget class="QGroupBox" name="groupBox" >
      <property name="title" >
      </layout>
     </widget>
    </item>
      </layout>
     </widget>
    </item>
+   <item>
+    <widget class="QGroupBox" name="groupBox_2" >
+     <property name="title" >
+      <string>Language:</string>
+     </property>
+     <layout class="QVBoxLayout" name="verticalLayout" >
+      <item>
+       <widget class="QComboBox" name="languageComboBox" >
+        <item>
+         <property name="text" >
+          <string>&lt;System></string>
+         </property>
+        </item>
+        <item>
+         <property name="text" >
+          <string>&lt;Original></string>
+         </property>
+        </item>
+       </widget>
+      </item>
+      <item>
+       <widget class="QLabel" name="label" >
+        <property name="text" >
+         <string>Note: needs client restart for full effect!</string>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
    <item>
     <spacer>
      <property name="orientation" >
       <enum>Qt::Vertical</enum>
      </property>
    <item>
     <spacer>
      <property name="orientation" >
       <enum>Qt::Vertical</enum>
      </property>
-     <property name="sizeHint" >
+     <property name="sizeHint" stdset="0" >
       <size>
        <width>20</width>
        <height>40</height>
       <size>
        <width>20</width>
        <height>40</height>
index 2b1a0b8..b923a4f 100644 (file)
@@ -20,9 +20,9 @@
 
 #include "uisettings.h"
 
 
 #include "uisettings.h"
 
-UiSettings::UiSettings(const QString &group) : ClientSettings(group) {
-
-
+UiSettings::UiSettings(const QString &group)
+  : ClientSettings(group)
+{
 }
 
 void UiSettings::setValue(const QString &key, const QVariant &data) {
 }
 
 void UiSettings::setValue(const QString &key, const QVariant &data) {
@@ -32,3 +32,7 @@ void UiSettings::setValue(const QString &key, const QVariant &data) {
 QVariant UiSettings::value(const QString &key, const QVariant &def) {
   return localValue(key, def);
 }
 QVariant UiSettings::value(const QString &key, const QVariant &def) {
   return localValue(key, def);
 }
+
+void UiSettings::remove(const QString &key) {
+  removeLocalKey(key);
+}
index b4d653b..0f0f52e 100644 (file)
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
-#ifndef _UISETTINGS_H_
-#define _UISETTINGS_H_
+#ifndef UISETTINGS_H
+#define UISETTINGS_H
 
 #include "clientsettings.h"
 
 class UiSettings : public ClientSettings {
 
 #include "clientsettings.h"
 
 class UiSettings : public ClientSettings {
-
-  public:
-    UiSettings(const QString &group = "Ui");
-
-    void setValue(const QString &key, const QVariant &data);
-    QVariant value(const QString &key, const QVariant &def = QVariant());
-
-
+public:
+  UiSettings(const QString &group = "Ui");
+  
+  void setValue(const QString &key, const QVariant &data);
+  QVariant value(const QString &key, const QVariant &def = QVariant());
+  void remove(const QString &key);
 };
 
 };
 
-/*
-class GuiProfile : public ClientSettings {
-
-  public:
-    GuiProfile();
-
-    static QStringList availableProfiles();
-    static GuiProfile *profile(QString name);
-
-    
-
-};
-*/
 #endif
 #endif