Skip to content

Commit

Permalink
libdoomsday|GameProfiles: Profile names are case insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Mar 8, 2016
1 parent 694fe4a commit 7f8ec2c
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions doomsday/sdk/libcore/src/data/profiles.cpp
Expand Up @@ -25,6 +25,11 @@

namespace de {

static String nameToKey(String const &name)
{
return name.toLower();
}

DENG2_PIMPL(Profiles)
{
typedef QMap<String, AbstractProfile *> Profiles;
Expand All @@ -41,11 +46,12 @@ DENG2_PIMPL(Profiles)

void add(AbstractProfile *profile)
{
if(profiles.contains(profile->name()))
String const key = nameToKey(profile->name());
if(profiles.contains(nameToKey(key)))
{
delete profiles[profile->name()];
delete profiles[key];
}
profiles.insert(profile->name(), profile);
profiles.insert(key, profile);
profile->setOwner(thisPublic);
}

Expand Down Expand Up @@ -112,7 +118,9 @@ Profiles::Profiles()

StringList Profiles::profiles() const
{
return d->profiles.keys();
StringList names;
for(auto const *p : d->profiles.values()) names << p->name();
return names;
}

int Profiles::count() const
Expand All @@ -122,7 +130,7 @@ int Profiles::count() const

Profiles::AbstractProfile *Profiles::tryFind(String const &name) const
{
auto found = d->profiles.constFind(name);
auto found = d->profiles.constFind(nameToKey(name));
if(found != d->profiles.constEnd())
{
return found.value();
Expand Down Expand Up @@ -180,7 +188,7 @@ void Profiles::remove(AbstractProfile &profile)
{
DENG2_ASSERT(&profile.owner() == this);

d->profiles.remove(profile.name());
d->profiles.remove(nameToKey(profile.name()));
profile.setOwner(nullptr);
}

Expand Down

0 comments on commit 7f8ec2c

Please sign in to comment.