summaryrefslogtreecommitdiffstats
path: root/kxkb/layoutunit.h
blob: f4d82f73f767b7518638630a20ce5254a6237c09 (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
//
//
// Author: Andriy Rysin <[email protected]>, (C) 2006
//
// Copyright: See COPYING file that comes with this distribution
//
//

#ifndef _LAYOUTUNIT_H
#define _LAYOUTUNIT_H

#include <tqstring.h>

inline TQString createPair(TQString key, TQString value)
{
	if (value.isEmpty()) return key;
	return TQString("%1(%2)").arg(key, value);
}

struct LayoutUnit {
	TQString layout;
	TQString variant;
	TQString displayName;

	LayoutUnit() {}

	LayoutUnit(TQString layout_, TQString variant_):
		layout(layout_),
		variant(variant_)
	{}

	LayoutUnit(TQString pair) {
		setFromPair( pair );
	}

	void setFromPair(const TQString& pair) {
		layout = parseLayout(pair);
		variant = parseVariant(pair);
	}

	TQString toPair() const {
		return createPair(layout, variant);
	}

	bool operator<(const LayoutUnit& lu) const {
		return layout<lu.layout ||
				(layout==lu.layout && variant<lu.variant);
	}

	bool operator!=(const LayoutUnit& lu) const {
		return layout!=lu.layout || variant!=lu.variant;
	}

	bool operator==(const LayoutUnit& lu) const {
// 		kdDebug() << layout << "==" << lu.layout << "&&" << variant << "==" << lu.variant << endl;
		return layout==lu.layout && variant==lu.variant;
	}

//private:
	static const TQString parseLayout(const TQString &layvar);
	static const TQString parseVariant(const TQString &layvar);
};

#endif // _LAYOUTUNIT_H