Branch: master

ae35100d 2015-08-25 00:26:06 Timothy Pearson
Add preliminary cryptographic card support to the TDE hardware device manager
M kcontrol/hwmanager/devicepropsdlg.cpp
M kcontrol/hwmanager/devicepropsdlg.h
M kcontrol/hwmanager/devicepropsdlgbase.ui
M kcontrol/hwmanager/hwmanager.cpp
diff --git a/kcontrol/hwmanager/devicepropsdlg.cpp b/kcontrol/hwmanager/devicepropsdlg.cpp
index 12de8ce..b14177c 100644
--- a/kcontrol/hwmanager/devicepropsdlg.cpp
+++ b/kcontrol/hwmanager/devicepropsdlg.cpp
@@ -283,6 +283,9 @@
 		if (m_device->type() != TDEGenericDeviceType::Event) {
 			base->tabBarWidget->removePage(base->tabEvent);
 		}
+		if (m_device->type() != TDEGenericDeviceType::CryptographicCard) {
+			base->tabBarWidget->removePage(base->tabCryptographicCard);
+		}
 
 		if (m_device->type() == TDEGenericDeviceType::CPU) {
 			connect(base->comboCPUGovernor, TQT_SIGNAL(activated(const TQString &)), this, TQT_SLOT(setCPUGovernor(const TQString &)));
@@ -753,6 +756,38 @@
 			}
 			base->labelEventSwitchActive->setText(activeSwitches);
 		}
+
+		if (m_device->type() == TDEGenericDeviceType::CryptographicCard) {
+			TDECryptographicCardDevice* cdevice = static_cast<TDECryptographicCardDevice*>(m_device);
+
+			connect(cdevice, TQT_SIGNAL(cardInserted()), this, TQT_SLOT(cryptographicCardInserted()));
+			connect(cdevice, TQT_SIGNAL(cardRemoved()), this, TQT_SLOT(cryptographicCardRemoved()));
+
+			updateCryptographicCardStatusDisplay();
+		}
+	}
+}
+
+void DevicePropertiesDialog::cryptographicCardInserted() {
+	updateCryptographicCardStatusDisplay();
+}
+
+void DevicePropertiesDialog::cryptographicCardRemoved() {
+	updateCryptographicCardStatusDisplay();
+}
+
+void DevicePropertiesDialog::updateCryptographicCardStatusDisplay() {
+	TDECryptographicCardDevice* cdevice = static_cast<TDECryptographicCardDevice*>(m_device);
+
+	int status = cdevice->cardPresent();
+	if ((status < 0) ||(status > 1)) {
+		base->labelCardStatus->setText(i18n("Unknown"));
+	}
+	else if (status == 0) {
+		base->labelCardStatus->setText(i18n("Empty"));
+	}
+	else if (status == 1) {
+		base->labelCardStatus->setText(i18n("Inserted") + TQString("<br>") + i18n("ATR: %1").arg(cdevice->cardATR()));
 	}
 }
 
diff --git a/kcontrol/hwmanager/devicepropsdlg.h b/kcontrol/hwmanager/devicepropsdlg.h
index bbff439..0b8553c 100644
--- a/kcontrol/hwmanager/devicepropsdlg.h
+++ b/kcontrol/hwmanager/devicepropsdlg.h
@@ -191,6 +191,10 @@
 	void mountDisk();
 	void unmountDisk();
 
+	void cryptographicCardInserted();
+	void cryptographicCardRemoved();
+	void updateCryptographicCardStatusDisplay();
+
 private:
 	TDEGenericDevice* m_device;
 	DevicePropertiesDialogBase* base;
diff --git a/kcontrol/hwmanager/devicepropsdlgbase.ui b/kcontrol/hwmanager/devicepropsdlgbase.ui
index 74afdf5..1be078c 100644
--- a/kcontrol/hwmanager/devicepropsdlgbase.ui
+++ b/kcontrol/hwmanager/devicepropsdlgbase.ui
@@ -1528,6 +1528,60 @@
 			    </spacer>
 		    </grid>
             </widget>
+	    <widget class="TQWidget">
+		    <property name="name">
+			    <cstring>tabCryptographicCard</cstring>
+		    </property>
+		    <attribute name="title">
+			    <string>Cryptographic Card</string>
+		    </attribute>
+		    <grid>
+			    <property name="name">
+				    <cstring>unnamed</cstring>
+			    </property>
+			    <widget class="TQGroupBox" row="0" column="0">
+				    <property name="name">
+					    <cstring>groupInput</cstring>
+				    </property>
+				    <property name="title">
+					    <string>Card Status</string>
+				    </property>
+				    <grid>
+					    <property name="name">
+						    <cstring>unnamed</cstring>
+					    </property>
+					    <widget class="TQLabel" row="0" column="0" colspan="1">
+						    <property name="name">
+							    <cstring>labelCardStatus</cstring>
+						    </property>
+						    <property name="text">
+							    <string></string>
+						    </property>
+						    <property name="alignment">
+							    <set>AlignTop|AlignLeft</set>
+						    </property>
+					    </widget>
+				    </grid>
+			    </widget>
+			    <spacer row="8" column="0">
+				    <property name="name" stdset="0">
+					    <cstring>Spacer4</cstring>
+				    </property>
+				    <property name="orientation">
+					    <enum>Vertical</enum>
+				    </property>
+				    <property name="sizeType">
+					    <enum>Expanding</enum>
+				    </property>
+				    <property name="sizeHint">
+					    <size>
+						    <width>20</width>
+						    <height>20</height>
+					    </size>
+				    </property>
+			    </spacer>
+		    </grid>
+            </widget>
         </widget>
     </grid>
 </widget>
diff --git a/kcontrol/hwmanager/hwmanager.cpp b/kcontrol/hwmanager/hwmanager.cpp
index a82daf1..00b5143 100644
--- a/kcontrol/hwmanager/hwmanager.cpp
+++ b/kcontrol/hwmanager/hwmanager.cpp
@@ -47,6 +47,8 @@
 #include <stdio.h>
 #include <tqstring.h>
 
+#include <tdecryptographiccarddevice.h>
+
 #include "hwmanager.h"
 
 using namespace std;
@@ -144,6 +146,9 @@
 		TDEGenericHardwareList hwlist = hwdevices->listByDeviceClass(TDEGenericDeviceType::RootSystem);
 		TDEGenericDevice *hwdevice;
 		for ( hwdevice = hwlist.first(); hwdevice; hwdevice = hwlist.next() ) {
+			if (hwdevice->type() == TDEGenericDeviceType::CryptographicCard) {
+				static_cast<TDECryptographicCardDevice*>(hwdevice)->enableCardMonitoring(true);
+			}
 			DeviceIconItem* item = new DeviceIconItem(base->deviceTree, hwdevice->detailedFriendlyName(), hwdevice->icon(base->deviceTree->iconSize()), hwdevice);
 			if ((!selected_syspath.isNull()) && (hwdevice->systemPath() == selected_syspath)) {
 				base->deviceTree->ensureItemVisible(item);
@@ -160,6 +165,9 @@
 				TDEGenericDevice *hwdevice;
 				TDEGenericHardwareList hwlist = hwdevices->listByDeviceClass((TDEGenericDeviceType::TDEGenericDeviceType)i);
 				for ( hwdevice = hwlist.first(); hwdevice; hwdevice = hwlist.next() ) {
+					if (hwdevice->type() == TDEGenericDeviceType::CryptographicCard) {
+						static_cast<TDECryptographicCardDevice*>(hwdevice)->enableCardMonitoring(true);
+					}
 					DeviceIconItem* item = new DeviceIconItem(rootitem, hwdevice->detailedFriendlyName(), hwdevice->icon(base->deviceTree->iconSize()), hwdevice);
 					if ((!selected_syspath.isNull()) && (hwdevice->systemPath() == selected_syspath)) {
 						base->deviceTree->ensureItemVisible(item);
@@ -177,6 +185,9 @@
 		TDEGenericHardwareList hwlist = hwdevices->listAllPhysicalDevices();
 		TDEGenericDevice *hwdevice;
 		for ( hwdevice = hwlist.first(); hwdevice; hwdevice = hwlist.next() ) {
+			if (hwdevice->type() == TDEGenericDeviceType::CryptographicCard) {
+				static_cast<TDECryptographicCardDevice*>(hwdevice)->enableCardMonitoring(true);
+			}
 			if (hwdevice->parentDevice() == parent->device()) {
 				DeviceIconItem* item = new DeviceIconItem(parent, hwdevice->detailedFriendlyName(), hwdevice->icon(base->deviceTree->iconSize()), hwdevice);
 				if ((!selected_syspath.isNull()) && (hwdevice->systemPath() == selected_syspath)) {