Subversion Repositories spk

Rev

Rev 53 | Blame | Compare with Previous | Last modification | View Log | RSS feed


#include "InstallText.h"

namespace SPK {
namespace Package {

CInstallText::CInstallText(void)
{
}

CInstallText::~CInstallText(void)
{
        _lTexts.clear(true);
}

void CInstallText::add(int iLang, const Utils::WString &sBefore, const Utils::WString &sAfter)
{
        SInstallText *text = _find(iLang);
        if ( !text ) {
        }

        text->sBefore = sBefore;
        text->sAfter = sAfter;
}

void CInstallText::addBefore(int iLang, const Utils::WString &sBefore)
{
        SInstallText *text = _find(iLang);
        if ( !text ) text = _new(iLang);
        text->sBefore = sBefore;
}

void CInstallText::addAfter(int iLang, const Utils::WString &sAfter)
{
        SInstallText *text = _find(iLang);
        if ( !text ) text = _new(iLang);
        text->sAfter = sAfter;
}

void CInstallText::remove(int iLang)
{
        SInstallText *text = _find(iLang);
        if ( text ) remove(iLang);
}

void CInstallText::removeBefore(int iLang)
{
        SInstallText *text = _find(iLang);
        if ( text ) {
                if ( text->sAfter.empty() ) remove(iLang);
                else text->sBefore = L"";
        }
}

void CInstallText::removeAfter(int iLang)
{
        SInstallText *text = _find(iLang);
        if ( text ) {
                if ( text->sBefore.empty() ) remove(iLang);
                else text->sAfter = L"";
        }
}

Utils::WString CInstallText::getBefore(int iLang, bool bIncludeDefault) const
{
        SInstallText *text = _find(iLang);
        if ( !text && bIncludeDefault ) text = _default();
        if ( text ) return text->sBefore;
        return L"";
}

Utils::WString CInstallText::getAfter(int iLang, bool bIncludeDefault) const
{
        SInstallText *text = _find(iLang);
        if ( !text && bIncludeDefault ) text = _default();
        if ( text ) return text->sAfter;
        return L"";
}

bool CInstallText::any() const
{
        return !_lTexts.empty();
}

int CInstallText::language(unsigned int iPos) const
{
        SInstallText *pT = _getAt(iPos);
        return (pT) ? pT->iLanguage : -1;
}

void CInstallText::merge(const CInstallText *pText)
{
        for ( unsigned int i = 0; i < pText->count(); i++ ) {
                SInstallText *p = pText->_getAt(i);
                if ( p ) this->add(p->iLanguage, p->sBefore, p->sAfter);
        }
}

CInstallText::SInstallText *CInstallText::_find(int iLang) const
{
        for ( TextNode node = _lTexts.Front(); node; node = node->next() ) {
                if ( node->Data()->iLanguage == iLang ) {
                        return node->Data();
                }
        }

        return NULL;
}

CInstallText::SInstallText *CInstallText::_new(int iLang)
{
        SInstallText *text = new SInstallText;
        text->iLanguage = iLang;
        _lTexts.push_back(text);
        return text;
}

void CInstallText::_purge()
{
}

CInstallText::SInstallText *CInstallText::_default() const
{
        return _find(0);
}

CInstallText::SInstallText *CInstallText::_getAt(int iIdx) const
{
        if ( iIdx < 0 || iIdx >= _lTexts.size() ) return NULL;
        return _lTexts.Get(iIdx);
}

unsigned int CInstallText::count() const
{
        return _lTexts.size();
}


}}//NAMESPACE