Subversion Repositories spk

Rev

Rev 46 | Rev 53 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
46 cycrow 1
 
2
#include "InstallText.h"
3
 
4
namespace SPK {
5
namespace Package {
6
 
7
CInstallText::CInstallText(void)
8
{
9
}
10
 
11
CInstallText::~CInstallText(void)
12
{
48 cycrow 13
	for ( TextNode node = _lTexts.Front(); node; node = node->next() ) {
46 cycrow 14
		delete node->Data();
15
	}
16
	_lTexts.clear();
17
}
18
 
19
void CInstallText::add(int iLang, const Utils::String &sBefore, const Utils::String &sAfter)
20
{
21
	SInstallText *text = _find(iLang);
22
	if ( !text ) {
23
	}
24
 
25
	text->sBefore = sBefore;
26
	text->sAfter = sAfter;
27
}
28
 
29
void CInstallText::addBefore(int iLang, const Utils::String &sBefore)
30
{
31
	SInstallText *text = _find(iLang);
32
	if ( !text ) text = _new(iLang);
33
	text->sBefore = sBefore;
34
}
35
 
36
void CInstallText::addAfter(int iLang, const Utils::String &sAfter)
37
{
38
	SInstallText *text = _find(iLang);
39
	if ( !text ) text = _new(iLang);
40
	text->sAfter = sAfter;
41
}
42
 
43
void CInstallText::remove(int iLang)
44
{
45
	SInstallText *text = _find(iLang);
46
	if ( text ) remove(iLang);
47
}
48
 
49
void CInstallText::removeBefore(int iLang)
50
{
51
	SInstallText *text = _find(iLang);
52
	if ( text ) {
53
		if ( text->sAfter.empty() ) remove(iLang);
54
		else text->sBefore = "";
55
	}
56
}
57
 
58
void CInstallText::removeAfter(int iLang)
59
{
60
	SInstallText *text = _find(iLang);
61
	if ( text ) {
62
		if ( text->sBefore.empty() ) remove(iLang);
63
		else text->sAfter = "";
64
	}
65
}
66
 
67
Utils::String CInstallText::getBefore(int iLang, bool bIncludeDefault) const
68
{
69
	SInstallText *text = _find(iLang);
70
	if ( !text && bIncludeDefault ) text = _default();
71
	if ( text ) return text->sBefore;
72
	return "";
73
}
74
 
75
Utils::String CInstallText::getAfter(int iLang, bool bIncludeDefault) const
76
{
77
	SInstallText *text = _find(iLang);
78
	if ( !text && bIncludeDefault ) text = _default();
79
	if ( text ) return text->sAfter;
80
	return "";
81
}
82
 
83
bool CInstallText::any() const
84
{
85
	return !_lTexts.empty();
86
}
87
 
88
int CInstallText::language(unsigned int iPos) const
89
{
90
	SInstallText *pT = _getAt(iPos);
91
	return (pT) ? pT->iLanguage : -1;
92
}
93
 
94
void CInstallText::merge(const CInstallText *pText)
95
{
96
	for ( unsigned int i = 0; i < pText->count(); i++ ) {
97
		SInstallText *p = pText->_getAt(i);
98
		if ( p ) this->add(p->iLanguage, p->sBefore, p->sAfter);
99
	}
100
}
101
 
102
CInstallText::SInstallText *CInstallText::_find(int iLang) const
103
{
48 cycrow 104
	for ( TextNode node = _lTexts.Front(); node; node = node->next() ) {
46 cycrow 105
		if ( node->Data()->iLanguage == iLang ) {
106
			return node->Data();
107
		}
108
	}
109
 
110
	return NULL;
111
}
112
 
113
CInstallText::SInstallText *CInstallText::_new(int iLang)
114
{
115
	SInstallText *text = new SInstallText;
116
	text->iLanguage = iLang;
117
	_lTexts.push_back(text);
118
	return text;
119
}
120
 
121
void CInstallText::_purge()
122
{
123
}
124
 
125
CInstallText::SInstallText *CInstallText::_default() const
126
{
127
	return _find(0);
128
}
129
 
130
CInstallText::SInstallText *CInstallText::_getAt(int iIdx) const
131
{
132
	if ( iIdx < 0 || iIdx >= _lTexts.size() ) return NULL;
133
	return _lTexts.Get(iIdx);
134
}
135
 
136
unsigned int CInstallText::count() const
137
{
138
	return _lTexts.size();
139
}
140
 
141
 
142
}}//NAMESPACE