1 /*********************************************************************** 2 * 3 * Copyright (C) 2010, 2011, 2012, 2013 Graeme Gott <graeme@gottcode.org> 4 * 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * 18 ***********************************************************************/ 19 20 #ifndef CUTEMAZE_LOCALE_DIALOG_H 21 #define CUTEMAZE_LOCALE_DIALOG_H 22 23 #include <QDialog> 24 class QComboBox; 25 26 /** 27 * Dialog to set application language. 28 * 29 * This class handles setting the application language when the application is 30 * launched, as well as allowing the user to choose a different language for 31 * future launches. 32 */ 33 class LocaleDialog : public QDialog 34 { 35 Q_OBJECT 36 37 public: 38 /** 39 * Construct a dialog to choose application language. 40 * 41 * @param parent the parent widget of the dialog 42 */ 43 LocaleDialog(QWidget* parent = 0); 44 45 /** 46 * Load the stored language into the application; defaults to system language. 47 * 48 * @param appname application name to prepend to translation filenames 49 * @param datadirs locations to search for directory containing translations 50 */ 51 static void loadTranslator(const QString& appname, const QStringList& datadirs = QStringList()); 52 53 /** 54 * Fetch native language name for QLocale name. 55 * 56 * @param language QLocale name to look up 57 * @return translated language name 58 */ 59 static QString languageName(const QString& language); 60 61 public slots: 62 /** Override parent function to store application language. */ 63 void accept(); 64 65 private: 66 /** 67 * Fetch list of application translations. 68 * 69 * @return list of QLocale names 70 */ 71 static QStringList findTranslations(); 72 73 private: 74 QComboBox* m_translations; /**< list of found translations */ 75 76 static QString m_current; /**< stored application language */ 77 static QString m_path; /**< location of translations; found in loadTranslator() */ 78 static QString m_appname; /**< application name passed to loadTranslator() */ 79 }; 80 81 #endif // CUTEMAZE_LOCALE_DIALOG_H 82