Subversion Repositories spk

Rev

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