locale_dialog.h 2.47 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
/***********************************************************************
 *
 * Copyright (C) 2010, 2011, 2012, 2013 Graeme Gott <graeme@gottcode.org>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 ***********************************************************************/

#ifndef TETZLE_LOCALE_DIALOG_H
#define TETZLE_LOCALE_DIALOG_H

#include <QDialog>
class QComboBox;

/**
 * Dialog to set application language.
 *
 * This class handles setting the application language when the application is
 * launched, as well as allowing the user to choose a different language for
 * future launches.
 */
class LocaleDialog : public QDialog
{
	Q_OBJECT

public:
	/**
	 * Construct a dialog to choose application language.
	 *
	 * @param parent the parent widget of the dialog
	 */
	LocaleDialog(QWidget* parent = 0);

	/**
	 * Load the stored language into the application; defaults to system language.
	 *
	 * @param appname application name to prepend to translation filenames
	 * @param datadirs locations to search for directory containing translations
	 */
	static void loadTranslator(const QString& appname, const QStringList& datadirs = QStringList());

	/**
	 * Fetch native language name for QLocale name.
	 *
	 * @param language QLocale name to look up
	 * @return translated language name
	 */
	static QString languageName(const QString& language);

public slots:
	/** Override parent function to store application language. */
	void accept();

private:
	/**
	 * Fetch list of application translations.
	 *
	 * @return list of QLocale names
	 */
	static QStringList findTranslations();

private:
	QComboBox* m_translations; /**< list of found translations */

	static QString m_current; /**< stored application language */
	static QString m_path; /**< location of translations; found in loadTranslator() */
	static QString m_appname; /**< application name passed to loadTranslator() */
};

#endif // TETZLE_LOCALE_DIALOG_H