source: src-qt4/PCDM/src/dialogLocale.cpp @ a5bc020

9.2-releasereleng/10.0releng/10.0.1releng/10.0.2
Last change on this file since a5bc020 was a5bc020, checked in by Ken Moore <ken@…>, 12 months ago

Fix up the PCDM locale switcher. It should now work properly once the translations are finished.

  • Property mode set to 100644
File size: 2.4 KB
Line 
1/* PCDM Login Manager:
2*  Written by Ken Moore (ken@pcbsd.org) 2012/2013
3*  Copyright(c) 2013 by the PC-BSD Project
4*  Available under the 3-clause BSD license
5*
6* Note: This file initially copied from the graphical PC-BSD installer
7*/
8
9#include <QDebug>
10#include <QFile>
11#include "dialogLocale.h"
12#include "ui_dialogLocale.h"
13
14widgetLocale::widgetLocale(QWidget *parent) : QWidget(parent), ui(new Ui::widgetLocale)
15{
16  //Initialize the Interface
17  ui->setupUi(this);
18 
19  //Connect the signals/slots
20  connect(ui->pushCancel, SIGNAL(clicked()), this, SLOT(slotClose()) );
21  connect(ui->pushApply, SIGNAL(clicked()), this, SLOT(slotApply()) );
22  //Get all the available languages
23  locCodeL = getLanguages(); //get language codes
24  locL.clear();
25  for(int i=0; i<locCodeL.length(); i++){
26    QLocale locale(locCodeL[i]);
27    locL << QLocale::languageToString(locale.language());
28  }
29  //Get the current language
30  QLocale mylocale;
31  QString cLocale = QLocale::languageToString(mylocale.language()) + " ("+mylocale.name()+")";
32  qDebug() << "Default Locale:" << cLocale;
33  //Setup the interface
34  ui->lineCurrentLocale->setText(cLocale); //current language
35  for(int i=0; i< locL.length(); i++){
36    ui->localeListWidget->addItem(locL[i] + " ("+locCodeL[i]+")"); //Available languages
37  }
38}
39
40widgetLocale::~widgetLocale(){
41}
42
43void widgetLocale::setCurrentLocale(QString localeCode){
44  QLocale locale(localeCode);
45  //Change the widget Locale
46  this->setLocale(locale);
47  //Setup the interface 
48  QString cLocale = QLocale::languageToString(locale.language()) + " ("+locale.name()+")";
49  ui->lineCurrentLocale->setText(cLocale); //current language
50  ui->retranslateUi(this);
51}
52
53void widgetLocale::slotClose()
54{
55  close();
56}
57
58void widgetLocale::slotApply()
59{
60  // Figure out the language code
61  QString langCode = ui->localeListWidget->currentItem()->text();
62   
63  // Grab the language code
64  langCode.truncate(langCode.lastIndexOf(")"));
65  langCode.remove(0, langCode.lastIndexOf("(") + 1); 
66
67  emit languageChanged(langCode);
68  close();
69}
70
71QStringList widgetLocale::getLanguages(){
72  //Detect all the available localizations
73  QString str = "/usr/local/share/PCDM/i18n";
74  QDir dir(str);
75  QStringList stL = dir.entryList(QDir::Files);
76  stL = stL.filter(".qm"); 
77  //Get the localization codes from the filenames
78  for(int i=0; i<stL.length(); i++){
79    stL[i] = stL[i].section("_",1,50).section(".qm",0,0).simplified(); 
80  }
81  return stL;
82}
83
Note: See TracBrowser for help on using the repository browser.