mediamanager: cleaned up use of medium name map.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
pull/38/head
Michele Calgaro 5 years ago
parent 1cf8018d1c
commit c393eecadb
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -69,38 +69,22 @@ TQString MediaList::addMedium(Medium *medium, bool allowNotification)
{
kdDebug(1219) << "MediaList::addMedium(@" << medium->id() << ")" << endl;
TQString id = medium->id();
if ( m_idMap.contains(id) ) return TQString::null;
m_media.append( medium );
m_idMap[id] = medium;
TQString name = medium->name();
if ( !m_nameMap.contains(name) )
if (!m_nameMap.contains(name))
{
m_nameMap[name] = medium;
kdDebug(1219) << "MediaList emits mediumAdded(" << id << ", "
<< name << ")" << endl;
emit mediumAdded(id, name, allowNotification);
return name;
}
TQString base_name = name+"_";
int i = 1;
while ( m_nameMap.contains(base_name+TQString::number(i)) )
TQString id = medium->id();
if (m_idMap.contains(id))
{
i++;
return TQString::null;
}
name = base_name+TQString::number(i);
medium->setName(name);
m_nameMap[name] = medium;
m_media.append(medium);
m_idMap[id] = medium;
kdDebug(1219) << "MediaList emits mediumAdded(" << id << ", "
<< name << ")" << endl;
kdDebug(1219) << "MediaList emits mediumAdded(" << id << ", " << name << ")" << endl;
emit mediumAdded(id, name, allowNotification);
return name;
}
@ -109,14 +93,17 @@ bool MediaList::removeMedium(const TQString &id, bool allowNotification)
{
kdDebug(1219) << "MediaList::removeMedium(" << id << ")" << endl;
if ( !m_idMap.contains(id) ) return false;
if (!m_idMap.contains(id))
{
return false;
}
Medium *medium = m_idMap[id];
TQString name = medium->name();
m_idMap.remove(id);
m_nameMap.remove( medium->name() );
m_media.remove( medium );
m_nameMap.remove(medium->name());
TQString name = medium->name();
m_media.remove(medium);
emit mediumRemoved(id, name, allowNotification);
return true;

Loading…
Cancel
Save