From c393eecadbc73e8db1d63fdc29c907d0340bb80c Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Fri, 7 Jun 2019 17:54:36 +0900 Subject: [PATCH] mediamanager: cleaned up use of medium name map. Signed-off-by: Michele Calgaro --- tdeioslave/media/mediamanager/medialist.cpp | 43 +++++++-------------- 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/tdeioslave/media/mediamanager/medialist.cpp b/tdeioslave/media/mediamanager/medialist.cpp index 09ff198d9..d9c4f0eb3 100644 --- a/tdeioslave/media/mediamanager/medialist.cpp +++ b/tdeioslave/media/mediamanager/medialist.cpp @@ -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;