summaryrefslogtreecommitdiffstats
path: root/kxkb/rules.cpp
blob: ab89b4f17936642c6e1ce0ed60a2655c12820b6d (plain)
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
82
83
84
85
86
87
88
89
#include <tqwindowdefs.h>
#include <tqfile.h>
#include <tqtextstream.h>
#include <tqregexp.h>
#include <tqstringlist.h>
#include <tqdir.h>

#include <kstandarddirs.h>
#include <tdeglobal.h>
#include <tdelocale.h>
#include <kdebug.h>
#include <config.h>

#include "x11helper.h"
#include "rules.h"


XkbRules::XkbRules(bool layoutsOnly):
    m_layouts(90)
{
	X11_DIR = X11Helper::findX11Dir();

   	if( X11_DIR == NULL ) {
        kdError() << "Cannot find X11 directory!" << endl;
//        throw Exception();
		return;
   	}

	TQString rulesFile = X11Helper::findXkbRulesFile(X11_DIR, tqt_xdisplay());
	
	if( rulesFile.isEmpty() ) {
  		kdError() << "Cannot find rules file in " << X11_DIR << endl;
//		throw Exception();
		return;
	}

	loadRules(rulesFile, layoutsOnly);
}


void XkbRules::loadRules(TQString file, bool layoutsOnly)
{
	RulesInfo* rules = X11Helper::loadRules(file, layoutsOnly);

	if (rules == NULL) {
		kdDebug() << "Unable to load rules" << endl;
		return;
	}

	m_layouts= rules->layouts;
	if( layoutsOnly == false ) {
		m_models = rules->models;
		m_options = rules->options;
	}

	//  fixLayouts();
}

TQStringList
XkbRules::getAvailableVariants(const TQString& layout)
{
    if( layout.isEmpty() || !layouts().find(layout) )
	return TQStringList();

    TQStringList* result1 = m_varLists[layout];
    if( result1 )
        return *result1;

    TQStringList* result = X11Helper::getVariants(layout, X11_DIR);

    m_varLists.insert(layout, result);

    return *result;
}

TQString XkbRules::getLayoutName(LayoutUnit layout) const {
	TQString fullName = i18n(m_layouts[layout.layout]);
	if (!layout.variant.isEmpty()) {
		fullName += " (" + layout.variant + ")";
	}
	return fullName;
}

TQString XkbRules::trOpt(TQString opt) {
    // xkeyboard-config's translation is generated directly from the xml and has some querks
    // like sustitution for the '<' and '>'. We will have to workaroung those manually:
    TQString translated = i18n(opt.replace("<", "&lt;").replace(">", "&gt;").utf8());
    return translated.replace("&lt;", "<").replace("&gt;", ">");
}