~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kcontrol/keyboard/xkb_rules.h

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (C) 2010 Andriy Rysin (rysin@kde.org)
 
3
 *
 
4
 *  This program is free software; you can redistribute it and/or modify
 
5
 *  it under the terms of the GNU General Public License as published by
 
6
 *  the Free Software Foundation; either version 2 of the License, or
 
7
 *  (at your option) any later version.
 
8
 *
 
9
 *  This program is distributed in the hope that it will be useful,
 
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 *  GNU General Public License for more details.
 
13
 *
 
14
 *  You should have received a copy of the GNU General Public License
 
15
 *  along with this program; if not, write to the Free Software
 
16
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
17
 */
 
18
 
 
19
 
 
20
#ifndef XKB_RULES_H_
 
21
#define XKB_RULES_H_
 
22
 
 
23
#include <QtXml/QXmlDefaultHandler>
 
24
#include <QtCore/QList>
 
25
#include <QtCore/QStringList>
 
26
 
 
27
 
 
28
struct ConfigItem {
 
29
        QString name;
 
30
        QString description;
 
31
};
 
32
 
 
33
template <class T>
 
34
inline T* findByName(QList<T*> list, QString name) {
 
35
        foreach(T* info, list) {
 
36
                if( info->name == name )
 
37
                        return info;
 
38
        }
 
39
        return NULL;
 
40
}
 
41
 
 
42
struct VariantInfo: public ConfigItem {
 
43
        QList<QString> languages;
 
44
        const bool fromExtras;
 
45
 
 
46
        VariantInfo(bool fromExtras_):
 
47
                fromExtras(fromExtras_) {}
 
48
};
 
49
 
 
50
struct LayoutInfo: public ConfigItem {
 
51
        QList<VariantInfo*> variantInfos;
 
52
        QList<QString> languages;
 
53
        const bool fromExtras;
 
54
 
 
55
//      LayoutInfo() {}
 
56
        LayoutInfo(bool fromExtras_):
 
57
                fromExtras(fromExtras_) {}
 
58
        ~LayoutInfo() { foreach(VariantInfo* variantInfo, variantInfos) delete variantInfo; }
 
59
 
 
60
        VariantInfo* getVariantInfo(const QString& variantName) const {
 
61
                return findByName(variantInfos, variantName);
 
62
        }
 
63
};
 
64
 
 
65
struct ModelInfo: public ConfigItem {
 
66
        QString vendor;
 
67
};
 
68
 
 
69
struct OptionInfo: public ConfigItem {
 
70
};
 
71
 
 
72
struct OptionGroupInfo: public ConfigItem {
 
73
        QList<OptionInfo*> optionInfos;
 
74
        bool exclusive;
 
75
 
 
76
        ~OptionGroupInfo() { foreach(OptionInfo* opt, optionInfos) delete opt; }
 
77
 
 
78
        const OptionInfo* getOptionInfo(const QString& optionName) const {
 
79
        return findByName(optionInfos, optionName);
 
80
    }
 
81
};
 
82
 
 
83
struct Rules {
 
84
    enum ExtrasFlag { NO_EXTRAS, READ_EXTRAS };
 
85
 
 
86
        static const char XKB_OPTION_GROUP_SEPARATOR;
 
87
 
 
88
        QList<LayoutInfo*> layoutInfos;
 
89
    QList<ModelInfo*> modelInfos;
 
90
    QList<OptionGroupInfo*> optionGroupInfos;
 
91
    QString version;
 
92
 
 
93
    Rules();
 
94
 
 
95
        ~Rules() {
 
96
                foreach(LayoutInfo* layoutInfo, layoutInfos) delete layoutInfo;
 
97
                foreach(ModelInfo* modelInfo, modelInfos) delete modelInfo;
 
98
                foreach(OptionGroupInfo* optionGroupInfo, optionGroupInfos) delete optionGroupInfo;
 
99
        }
 
100
 
 
101
    const LayoutInfo* getLayoutInfo(const QString& layoutName) const {
 
102
        return findByName(layoutInfos, layoutName);
 
103
    }
 
104
 
 
105
    const OptionGroupInfo* getOptionGroupInfo(const QString& optionGroupName) const {
 
106
        return findByName(optionGroupInfos, optionGroupName);
 
107
    }
 
108
 
 
109
    static Rules* readRules(ExtrasFlag extrasFlag);
 
110
    static Rules* readRules(Rules* rules, const QString& filename, bool fromExtras);
 
111
    static QString getRulesName();
 
112
};
 
113
 
 
114
#endif /* XKB_RULES_H_ */