File indexing completed on 2024-04-28 16:08:29

0001 /***************************************************************************
0002  *   Copyright (C) 2005-2008 by Bjoern Erik Nilsen & Fredrik Berg Kjoelstad*
0003  *   bjoern.nilsen@bjoernen.com & fredrikbk@hotmail.com                    *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
0019  ***************************************************************************/
0020 #ifndef LANGUAGEHANDLER_H
0021 #define LANGUAGEHANDLER_H
0022 
0023 #include "src/config.h"
0024 
0025 #include <QObject>
0026 #include <QApplication>
0027 #include <QMenu>
0028 #include <QTranslator>
0029 #include <QHash>
0030 #include <QAction>
0031 
0032 
0033 /**
0034  * This class handles the loading of the different languages which are supported
0035  * by the program.
0036  *
0037  * @author Bjoern Erik Nilsen & Fredrik Berg Kjoelstad
0038  */
0039 class LanguageHandler : public QObject
0040 {
0041     Q_OBJECT
0042 public:
0043     /**
0044      * Creates and initializes the LanguageHandler.
0045      * @param parent the parent of the LanguageHandler.
0046      * @param stApp the main window
0047      * @param name the name of the LanguageHandler
0048      */
0049     LanguageHandler ( QObject *parent = 0, QApplication *stApp = 0, const char *name = 0 );
0050     
0051     /**
0052      * Creates the languagesMenu.
0053      * @param parent the parent menu.
0054      * @return a populated language menu.
0055      */
0056     QMenu* createLanguagesMenu(QMenu *parent);
0057     
0058 private:
0059     QTranslator *translator;
0060     QMenu *languagesMenu;
0061     QString qmPath;
0062     QAction *activeAction;
0063     QHash<QAction*, QString> locales;
0064     
0065 private slots:
0066     /**
0067      * Switch to the language in location menuID in the languages menu.
0068      * @param menuID the ide of the menu options with the language to
0069      * switch to.
0070      */
0071     void changeLanguage(QAction *activeAction);
0072     
0073 signals:
0074     /**
0075      * Called when the user has changed the language.
0076      */
0077     void languageChanged();
0078 };
0079 
0080 #endif