UBPlatformUtils.h 5.39 KB
Newer Older
Claudio Valerio's avatar
Claudio Valerio committed
1 2 3
/*
 * 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
Claudio Valerio's avatar
Claudio Valerio committed
4
 * the Free Software Foundation, either version 2 of the License, or
Claudio Valerio's avatar
Claudio Valerio committed
5 6 7 8 9 10 11 12 13 14
 * (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/>.
 */
15 16 17 18 19 20 21 22 23 24 25

#ifndef UBPLATFORMUTILS_H_
#define UBPLATFORMUTILS_H_

#include <QtCore>
#include <QIcon>

class QMainWindow;

#define SYMBOL_KEYS_COUNT 47

Anatoly Mihalchenko's avatar
Anatoly Mihalchenko committed
26 27 28 29 30 31 32 33 34 35

/*
    Declaration for single keycode (code, which will be sent to output after pressing of button)
    Each button has several codes, associated with shift state and modifier

    symbol - (Windows only) Unide symbol to send
    code - (LINUX, MAC) - code of key to press. Phisical keycode on MAC, position in keys table on LINUX
    modifier (LINUX) - offset in keys table
*/

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
struct KEYCODE{
    KEYCODE()
        :symbol(0)
        ,code(0)
        ,modifier(0)
    {}

    KEYCODE(int _symbol)
        :symbol(_symbol)
        ,code(0)
        ,modifier(0)
    {}

    KEYCODE(int _symbol,
            unsigned char _code,
            int _modifier)
        :symbol(_symbol)
        ,code(_code)
        ,modifier(_modifier)
    {}


    bool empty() const
    {
        return symbol == 0;
    }

    int symbol;
    unsigned char code;
    int modifier;
};

Anatoly Mihalchenko's avatar
Anatoly Mihalchenko committed
68 69 70 71 72 73 74 75 76 77 78 79 80
/*
    Declaration of single button. Properties:
    symbol1, symbol2 - symbols to display under obscreen keyboard on normal/shifted modes
    capsLockSwitch - if true, CapsLock button switched keystate to "shifted"
    modifier1/modifier2 - if >0 means modified symbol for next press (modifier * 2 + shiststate index in codes array)
                        If this code dedined (not empty), this symbol will sent to output. For French keyboard layout
    codes[i] - code for pressed symbol.
        code[0] - normal symbol
        code[1] - shifted symbol
        code[2] - modifier = 1, normal symbol
        code[3] - modifier = 1, shifted symbol
        ...
*/
81 82
struct KEYBT
{
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
    QChar symbol1;
	QChar symbol2;
    bool capsLockSwitch;
    int modifier1;
    int modifier2;
    KEYCODE codes[8];

    KEYBT(  QChar _symbol1,
		    QChar _symbol2,
            bool _capsLockSwitch,
            int _modifier1,
            int _modifier2,
            KEYCODE c1 = 0,
            KEYCODE c2 = 0,
            KEYCODE c3 = 0,
            KEYCODE c4 = 0,
            KEYCODE c5 = 0,
            KEYCODE c6 = 0,
            KEYCODE c7 = 0,
            KEYCODE c8 = 0)
                :symbol1(_symbol1)
                ,symbol2(_symbol2)
                ,capsLockSwitch(_capsLockSwitch)
                ,modifier1(_modifier1)
                ,modifier2(_modifier2)
    {
        codes[0] = c1;
        codes[1] = c2;
        codes[2] = c3;
        codes[3] = c4;
        codes[4] = c5;
        codes[5] = c6;
        codes[6] = c7;
        codes[7] = c8;
    }

    ~KEYBT()
    {}
};
    
    
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139

	class UBKeyboardLocale
	{
	public:
		UBKeyboardLocale(const QString& _fullName,
			const QString& _name,
			const QString& _id,
			QIcon* _icon,
			KEYBT** _symbols)
			:fullName(_fullName),name(_name), id(_id), icon(_icon),
                        constSymbols(NULL), varSymbols(_symbols)
		{}
		UBKeyboardLocale(const QString& _fullName,
			const QString& _name,
			const QString& _id,
			QIcon* _icon,
140
            KEYBT _symbols[])
141 142 143 144 145 146 147 148 149 150
			:fullName(_fullName),name(_name),  id(_id), icon(_icon),
                        constSymbols(_symbols), varSymbols(NULL)
		{}

		~UBKeyboardLocale();

		const QString fullName;
		const QString name;
		const QString id;
		QIcon* icon;
151
        KEYBT* operator[] (int index) const
152 153 154 155
		{
			return (varSymbols==NULL)? constSymbols + index : varSymbols[index];
		}
	private:
156
        KEYBT* constSymbols;
157 158 159 160 161 162
		KEYBT** varSymbols;
	};


class UBPlatformUtils
{
163 164
    Q_DECLARE_TR_FUNCTIONS(UBPlatformUtils)

165 166 167 168 169 170 171 172 173
    private:
        UBPlatformUtils();
        virtual ~UBPlatformUtils();

        static void initializeKeyboardLayouts();
        static void destroyKeyboardLayouts();
        static int nKeyboardLayouts;
        static UBKeyboardLocale** keyboardLayouts;

174
public:
175 176 177 178 179 180 181
        static void init();
        static void destroy();
        static QString applicationResourcesDirectory();
        static void hideFile(const QString &filePath);
        static void setFileType(const QString &filePath, unsigned long fileType);
        static void fadeDisplayOut();
        static void fadeDisplayIn();
182 183
        static QString translationPath(QString pFilePrefix, QString pLanguage);
        static QString systemLanguage();
184 185 186 187 188 189 190 191 192 193
        static bool hasVirtualKeyboard();
        //static void showVirtualKeyboard();
        static void runInstaller(const QString &installerFilePath);
        static void bringPreviousProcessToFront();
        static QString osUserLoginName();
        static void setDesktopMode(bool desktop);
        static void setWindowNonActivableFlag(QWidget* widget, bool nonAcivable);
        static QString computerName();
        static UBKeyboardLocale** getKeyboardLayouts(int& nCount);
        static QString urlFromClipboard();
194
        static QStringList availableTranslations();
195 196 197 198 199
};



#endif /* UBPLATFORMUTILS_H_ */