summaryrefslogtreecommitdiff
path: root/indra/llinventory/llinventorysettings.cpp
blob: 8887c23a6cf7845c476d3a9b5f25310c4d4e8936 (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
* @file llinventorysettings.cpp
* @author optional
* @brief A base class for asset based settings groups.
*
* $LicenseInfo:2011&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2017, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
* $/LicenseInfo$
*/

#include "linden_common.h"
#include "llinventorysettings.h"
#include "llinventorytype.h"
#include "llinventorydefines.h"
#include "lldictionary.h"
#include "llsingleton.h"
#include "llinvtranslationbrdg.h"

//=========================================================================
namespace {
    LLTranslationBridge::ptr_t sTranslator;
}

//=========================================================================
struct SettingsEntry : public LLDictionaryEntry
{
    SettingsEntry(const std::string &name,
        const std::string& default_new_name,
        LLInventoryType::EIconName iconName) :
        LLDictionaryEntry(name),
        mDefaultNewName(default_new_name),
        mLabel(name),
        mIconName(iconName)
    {
        std::string transdname = sTranslator->getString(mLabel);
        if (!transdname.empty())
        {
            mLabel = transdname;
        }
    }

    std::string mLabel;
    std::string mDefaultNewName; //keep mLabel for backward compatibility
    LLInventoryType::EIconName mIconName;
};

class LLSettingsDictionary : public LLSingleton<LLSettingsDictionary>,
    public LLDictionary<LLSettingsType::type_e, SettingsEntry>
{
    LLSINGLETON(LLSettingsDictionary);

    void initSingleton();
};

LLSettingsDictionary::LLSettingsDictionary() 
{
}

void LLSettingsDictionary::initSingleton()
{
    addEntry(LLSettingsType::ST_SKY,        new SettingsEntry("sky",        "New Sky",      LLInventoryType::ICONNAME_SETTINGS_SKY));
    addEntry(LLSettingsType::ST_WATER,      new SettingsEntry("water",      "New Water",    LLInventoryType::ICONNAME_SETTINGS_WATER));
    addEntry(LLSettingsType::ST_DAYCYCLE,   new SettingsEntry("day",        "New Day",      LLInventoryType::ICONNAME_SETTINGS_DAY));
    addEntry(LLSettingsType::ST_NONE,       new SettingsEntry("none",       "New Settings", LLInventoryType::ICONNAME_SETTINGS));
    addEntry(LLSettingsType::ST_INVALID,    new SettingsEntry("invalid",    "New Settings", LLInventoryType::ICONNAME_SETTINGS));
}

//=========================================================================

LLSettingsType::type_e LLSettingsType::fromInventoryFlags(U32 flags)
{
    return  (LLSettingsType::type_e)(flags & LLInventoryItemFlags::II_FLAGS_SUBTYPE_MASK);
}


LLInventoryType::EIconName LLSettingsType::getIconName(LLSettingsType::type_e type)
{
    const SettingsEntry *entry = LLSettingsDictionary::instance().lookup(type);
    if (!entry) 
        return getIconName(ST_INVALID);
    return entry->mIconName;
}


void LLSettingsType::initClass(LLTranslationBridge::ptr_t &trans)
{
    sTranslator = trans;
}

void LLSettingsType::cleanupClass()
{
    sTranslator.reset();
}