diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2019-07-05 13:23:08 +0900 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2019-07-05 18:39:19 +0900 |
commit | 0f7cda9d52c90a780716915547f479eaa43b909a (patch) | |
tree | bd407d94b7c589295ac1ab376b745d90d887f336 /tdecore/tdehw | |
parent | 7d87c23620f9346447d7306b90c5bd0fa9844e59 (diff) | |
download | tdelibs-0f7cda9d52c90a780716915547f479eaa43b909a.tar.gz tdelibs-0f7cda9d52c90a780716915547f479eaa43b909a.zip |
tdehw: improved code for mount table.
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
(cherry picked from commit 09835dceb73b0e814fb7b2e915b8055d67fa83c9)
Diffstat (limited to 'tdecore/tdehw')
-rw-r--r-- | tdecore/tdehw/tdehardwaredevices.cpp | 36 | ||||
-rw-r--r-- | tdecore/tdehw/tdehardwaredevices.h | 2 |
2 files changed, 18 insertions, 20 deletions
diff --git a/tdecore/tdehw/tdehardwaredevices.cpp b/tdecore/tdehw/tdehardwaredevices.cpp index ac00037b1..8eafe96e9 100644 --- a/tdecore/tdehw/tdehardwaredevices.cpp +++ b/tdecore/tdehw/tdehardwaredevices.cpp @@ -167,7 +167,10 @@ TDEHardwareDevices::TDEHardwareDevices() { if ( file.open( IO_ReadOnly ) ) { TQTextStream stream( &file ); while ( !stream.atEnd() ) { - m_mountTable.append(stream.readLine()); + TQString line = stream.readLine(); + if (!line.isEmpty()) { + m_mountTable[line] = true; + } } file.close(); } @@ -934,7 +937,7 @@ void TDEHardwareDevices::processModifiedMounts() { // Detect what changed between the old mount table and the new one, // and emit appropriate events - TQStringList deletedEntries = m_mountTable; + TQMap<TQString, bool> deletedEntries = m_mountTable; // Read in the new mount table m_mountTable.clear(); @@ -942,31 +945,26 @@ void TDEHardwareDevices::processModifiedMounts() { if ( file.open( IO_ReadOnly ) ) { TQTextStream stream( &file ); while ( !stream.atEnd() ) { - m_mountTable.append(stream.readLine()); + TQString line = stream.readLine(); + if (!line.isEmpty()) { + m_mountTable[line] = true; + } } file.close(); } - - TQStringList addedEntries = m_mountTable; + TQMap<TQString, bool> addedEntries = m_mountTable; // Remove all entries that are identical in both tables - processModifiedMounts_removeagain: - for ( TQStringList::Iterator delit = deletedEntries.begin(); delit != deletedEntries.end(); ++delit ) { - for ( TQStringList::Iterator addit = addedEntries.begin(); addit != addedEntries.end(); ++addit ) { - if ((*delit) == (*addit)) { - deletedEntries.remove(delit); - addedEntries.remove(addit); - // Reset iterators to prevent bugs/crashes - // FIXME - // Is there any way to completely reset both loops without using goto? - goto processModifiedMounts_removeagain; - } + for ( TQMap<TQString, bool>::ConstIterator mtIt = m_mountTable.begin(); mtIt != m_mountTable.end(); ++mtIt ) { + if (deletedEntries.contains(mtIt.key())) { + deletedEntries.remove(mtIt.key()); + addedEntries.remove(mtIt.key()); } } - TQStringList::Iterator it; + TQMap<TQString, bool>::Iterator it; for ( it = addedEntries.begin(); it != addedEntries.end(); ++it ) { - TQStringList mountInfo = TQStringList::split(" ", (*it), true); + TQStringList mountInfo = TQStringList::split(" ", it.key(), true); // Try to find a device that matches the altered node TDEGenericDevice* hwdevice = findByDeviceNode(*mountInfo.at(0)); if (hwdevice) { @@ -987,7 +985,7 @@ void TDEHardwareDevices::processModifiedMounts() { } } for ( it = deletedEntries.begin(); it != deletedEntries.end(); ++it ) { - TQStringList mountInfo = TQStringList::split(" ", (*it), true); + TQStringList mountInfo = TQStringList::split(" ", it.key(), true); // Try to find a device that matches the altered node TDEGenericDevice* hwdevice = findByDeviceNode(*mountInfo.at(0)); if (hwdevice) { diff --git a/tdecore/tdehw/tdehardwaredevices.h b/tdecore/tdehw/tdehardwaredevices.h index 6592b8b10..b4781baf7 100644 --- a/tdecore/tdehw/tdehardwaredevices.h +++ b/tdecore/tdehw/tdehardwaredevices.h @@ -304,7 +304,7 @@ class TDECORE_EXPORT TDEHardwareDevices : public TQObject TQSocketNotifier* m_devScanNotifier; TQSocketNotifier* m_mountScanNotifier; - TQStringList m_mountTable; + TQMap<TQString, bool> m_mountTable; TQStringList m_cpuInfo; TDEDeviceIDMap* pci_id_map; |