Branch: master

fd0de2b5 2015-09-30 13:33:19 Timothy Pearson
Fix hardware class file matching algorithm
Fix overly broad floppy device matching rules
This resolves Bug 2534
M tdecore/tdehw/hwlibdata/classrules/floppydisk-platform.hwclass
M tdecore/tdehw/hwlibdata/classrules/floppydisk-udev.hwclass
M tdecore/tdehw/tdehardwaredevices.cpp
diff --git a/tdecore/tdehw/hwlibdata/classrules/floppydisk-platform.hwclass b/tdecore/tdehw/hwlibdata/classrules/floppydisk-platform.hwclass
index b3ccab6..54368d4 100644
--- a/tdecore/tdehw/hwlibdata/classrules/floppydisk-platform.hwclass
+++ b/tdecore/tdehw/hwlibdata/classrules/floppydisk-platform.hwclass
@@ -1,6 +1,7 @@
 [Conditions]
 SUBSYSTEM=block
 DRIVER=floppy
+MatchType=All
 
 [DeviceType]
 GENTYPE=Disk
diff --git a/tdecore/tdehw/hwlibdata/classrules/floppydisk-udev.hwclass b/tdecore/tdehw/hwlibdata/classrules/floppydisk-udev.hwclass
index 6c76d3c..07b2e43 100644
--- a/tdecore/tdehw/hwlibdata/classrules/floppydisk-udev.hwclass
+++ b/tdecore/tdehw/hwlibdata/classrules/floppydisk-udev.hwclass
@@ -1,5 +1,6 @@
 [Conditions]
 ID_TYPE=floppy
+MatchType=All
 
 [DeviceType]
 GENTYPE=Disk
diff --git a/tdecore/tdehw/tdehardwaredevices.cpp b/tdecore/tdehw/tdehardwaredevices.cpp
index 3c08cfc..bb1318a 100644
--- a/tdecore/tdehw/tdehardwaredevices.cpp
+++ b/tdecore/tdehw/tdehardwaredevices.cpp
@@ -1656,27 +1656,61 @@
 						for (cndit = conditionmap.begin(); cndit != conditionmap.end(); ++cndit) {
 							TQStringList conditionList = TQStringList::split(',', cndit.data(), false);
 							bool atleastonematch = false;
-							for ( TQStringList::Iterator paramit = conditionList.begin(); paramit != conditionList.end(); ++paramit ) {
-								if (cndit.key() == "VENDOR_ID") {
-									if (device->vendorID() == (*paramit)) {
-										atleastonematch = true;
+							bool allmatch = true;
+							TQString matchtype = rulesFile.readEntry("MATCH_TYPE", "All");
+							if (conditionList.count() < 1) {
+								allmatch = false;
+							}
+							else {
+								for ( TQStringList::Iterator paramit = conditionList.begin(); paramit != conditionList.end(); ++paramit ) {
+									if ((*paramit) == "MatchType") {
+										continue;
 									}
-								}
-								else if (cndit.key() == "MODEL_ID") {
-									if (device->modelID() == (*paramit)) {
-										atleastonematch = true;
+									if (cndit.key() == "VENDOR_ID") {
+										if (device->vendorID() == (*paramit)) {
+											atleastonematch = true;
+										}
+										else {
+											allmatch = false;
+										}
 									}
-								}
-								else if (cndit.key() == "DRIVER") {
-									if (device->deviceDriver() == (*paramit)) {
-										atleastonematch = true;
+									else if (cndit.key() == "MODEL_ID") {
+										if (device->modelID() == (*paramit)) {
+											atleastonematch = true;
+										}
+										else {
+											allmatch = false;
+										}
 									}
-								}
-								else if (readUdevAttribute(dev, cndit.key()) == (*paramit)) {
-									atleastonematch = true;
+									else if (cndit.key() == "DRIVER") {
+										if (device->deviceDriver() == (*paramit)) {
+											atleastonematch = true;
+										}
+										else {
+											allmatch = false;
+										}
+									}
+									else {
+										if (readUdevAttribute(dev, cndit.key()) == (*paramit)) {
+											atleastonematch = true;
+										}
+										else {
+											allmatch = false;
+										}
+									}
 								}
 							}
-							if (!atleastonematch) {
+							if (matchtype == "All") {
+								if (!allmatch) {
+									match = false;
+								}
+							}
+							else if (matchtype == "Any") {
+								if (!atleastonematch) {
+									match = false;
+								}
+							}
+							else {
 								match = false;
 							}
 						}