From fef13c17861a7510ef4564550fc041ba62f3f0a2 Mon Sep 17 00:00:00 2001
From: Timothy Pearson <kb9vqf@pearsoncomputing.net>
Date: Sat, 14 Apr 2012 16:50:36 -0500
Subject: Show system properties

---
 kcontrol/hwmanager/devicepropsdlg.cpp    | 102 +++++++++++++++++++
 kcontrol/hwmanager/devicepropsdlg.h      |   4 +
 kcontrol/hwmanager/devicepropsdlgbase.ui | 163 +++++++++++++++++++++++++++++++
 kcontrol/hwmanager/hwmanager.cpp         |   6 +-
 4 files changed, 271 insertions(+), 4 deletions(-)

diff --git a/kcontrol/hwmanager/devicepropsdlg.cpp b/kcontrol/hwmanager/devicepropsdlg.cpp
index f5747c1c5..14810318a 100644
--- a/kcontrol/hwmanager/devicepropsdlg.cpp
+++ b/kcontrol/hwmanager/devicepropsdlg.cpp
@@ -276,6 +276,9 @@ DevicePropertiesDialog::DevicePropertiesDialog(TDEGenericDevice* device, TQWidge
 		if (m_device->type() != TDEGenericDeviceType::Monitor) {
 			base->tabBarWidget->removePage(base->tabMonitor);
 		}
+		if (m_device->type() != TDEGenericDeviceType::RootSystem) {
+			base->tabBarWidget->removePage(base->tabRootSystem);
+		}
 
 		if (m_device->type() == TDEGenericDeviceType::CPU) {
 			connect(base->comboCPUGovernor, TQT_SIGNAL(activated(const TQString &)), this, TQT_SLOT(setCPUGovernor(const TQString &)));
@@ -291,6 +294,9 @@ DevicePropertiesDialog::DevicePropertiesDialog(TDEGenericDevice* device, TQWidge
 		if (m_device->type() == TDEGenericDeviceType::Backlight) {
 			connect(base->sliderBacklightBrightness, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(setBacklightBrightness(int)));
 		}
+		if (m_device->type() == TDEGenericDeviceType::RootSystem) {
+			connect(base->comboSystemHibernationMethod, TQT_SIGNAL(activated(int)), this, TQT_SLOT(setHibernationMethod(int)));
+		}
 
 		TQGridLayout *mainGrid = new TQGridLayout(plainPage(), 1, 1, 0, spacingHint());
 		mainGrid->setRowStretch(1, 1);
@@ -579,6 +585,95 @@ void DevicePropertiesDialog::populateDeviceInformation() {
 			// RandR warning
 			base->labelRandrWarning->setText("<qt><b>NOTE: Any further integration of displays into TDE <i>REQUIRES</i> multi GPU support and other features slated for RandR 2.0.</b><p>Development on such features has been sorely lacking for well over a year as of 2012; if you want to see Linux come up to Windows and Macintosh standards in this area <i>please tell the Xorg developers</i> at http://www.x.org/wiki/XorgMailingLists<p>The TDE project badly needs these features before it can proceed with graphical monitor configuration tools:<br> * GPU object support<br> * The ability to query the active driver name for any Xorg output<p><b>To recap, this is <i>not a TDE shortcoming</i>, but rather is the result of a lack of fundamental Linux support for graphics configuration!</b></qt>");
 		}
+
+		if (m_device->type() == TDEGenericDeviceType::RootSystem) {
+			TDERootSystemDevice* rdevice = static_cast<TDERootSystemDevice*>(m_device);
+
+			TQString formFactorString;
+			TDESystemFormFactor::TDESystemFormFactor formFactor = rdevice->formFactor();
+			if (formFactor == TDESystemFormFactor::Unclassified) {
+				formFactorString = i18n("Unknown");
+			}
+			else if (formFactor == TDESystemFormFactor::Desktop) {
+				formFactorString = i18n("Desktop");
+			}
+			else if (formFactor == TDESystemFormFactor::Laptop) {
+				formFactorString = i18n("Laptop");
+			}
+			else if (formFactor == TDESystemFormFactor::Server) {
+				formFactorString = i18n("Server");
+			}
+			base->labelSystemFormFactor->setText(formFactorString);
+
+			TQString powerStatesString;
+			TDESystemPowerStateList powerStates = rdevice->powerStates();
+			if (powerStates.count() > 0) {
+				powerStatesString = "<qt>";
+				TDESystemPowerStateList::iterator it;
+				for (it = powerStates.begin(); it != powerStates.end(); ++it) {
+					if ((*it) == TDESystemPowerState::Active) {
+						powerStatesString += i18n("Active<br>");
+					}
+					if ((*it) == TDESystemPowerState::Standby) {
+						powerStatesString += i18n("Standby<br>");
+					}
+					if ((*it) == TDESystemPowerState::Suspend) {
+						powerStatesString += i18n("Suspend<br>");
+					}
+					if ((*it) == TDESystemPowerState::Hibernate) {
+						powerStatesString += i18n("Hibernate<br>");
+					}
+					if ((*it) == TDESystemPowerState::PowerOff) {
+						powerStatesString += i18n("Power Off<br>");
+					}
+				}
+				powerStatesString += "</qt>";
+			}
+			else {
+				powerStatesString += i18n("<unknown>");
+			}
+			base->labelSystemPowerStates->setText(powerStatesString);
+
+			base->comboSystemHibernationMethod->setEnabled(rdevice->canSetHibernationMethod());
+			TDESystemHibernationMethodList hibernationMethods = rdevice->hibernationMethods();
+			if ((uint)hibernationMethods.count() != (uint)base->comboSystemHibernationMethod->count()) {
+				base->comboSystemHibernationMethod->clear();
+				m_hibernationComboMap.clear();
+				int i=0;
+				TQString label;
+				for (TDESystemHibernationMethodList::Iterator it = hibernationMethods.begin(); it != hibernationMethods.end(); ++it) {
+					if ((*it) == TDESystemHibernationMethod::None) {
+						label = i18n("<none>");
+					}
+					if ((*it) == TDESystemHibernationMethod::Platform) {
+						label = i18n("Platform");
+					}
+					if ((*it) == TDESystemHibernationMethod::Shutdown) {
+						label = i18n("Shutdown");
+					}
+					if ((*it) == TDESystemHibernationMethod::Reboot) {
+						label = i18n("Reboot");
+					}
+					if ((*it) == TDESystemHibernationMethod::TestProc) {
+						label = i18n("Test Procedure");
+					}
+					if ((*it) == TDESystemHibernationMethod::Test) {
+						label = i18n("Test");
+					}
+					base->comboSystemHibernationMethod->insertItem(label, i);
+					m_hibernationComboMap[*it] = i;
+					i++;
+				}
+			}
+			base->comboSystemHibernationMethod->setCurrentItem(m_hibernationComboMap[rdevice->hibernationMethod()]);
+
+			base->labelSystemUserCanStandby->setText((rdevice->canStandby())?i18n("Yes"):i18n("No"));
+			base->labelSystemUserCanSuspend->setText((rdevice->canSuspend())?i18n("Yes"):i18n("No"));
+			base->labelSystemUserCanHibernate->setText((rdevice->canHibernate())?i18n("Yes"):i18n("No"));
+			base->labelSystemUserCanPowerOff->setText((rdevice->canPowerOff())?i18n("Yes"):i18n("No"));
+
+			base->labelSystemHibernationSpace->setText((rdevice->diskSpaceNeededForHibernation()<0)?i18n("<unknown>"):TDEHardwareDevices::bytesToFriendlySizeString(rdevice->diskSpaceNeededForHibernation()));
+		}
 	}
 }
 
@@ -595,6 +690,13 @@ void DevicePropertiesDialog::setBacklightBrightness(int value) {
 	bdevice->setRawBrightness(value);
 }
 
+void DevicePropertiesDialog::setHibernationMethod(int value) {
+	TDERootSystemDevice* rdevice = static_cast<TDERootSystemDevice*>(m_device);
+
+	rdevice->setHibernationMethod(m_hibernationComboMap.keys()[value]);
+	populateDeviceInformation();
+}
+
 void DevicePropertiesDialog::virtual_hook( int id, void* data )
 { KDialogBase::virtual_hook( id, data ); }
 
diff --git a/kcontrol/hwmanager/devicepropsdlg.h b/kcontrol/hwmanager/devicepropsdlg.h
index 4a70da5c2..192ebffd4 100644
--- a/kcontrol/hwmanager/devicepropsdlg.h
+++ b/kcontrol/hwmanager/devicepropsdlg.h
@@ -155,6 +155,7 @@ private:
 };
 
 typedef TQPtrList<SensorDisplayWidget> SensorDisplayWidgetList;
+typedef TQMap<TDESystemHibernationMethod::TDESystemHibernationMethod, int> HibernationComboMap;
 
 /**
  *
@@ -185,6 +186,7 @@ private slots:
 
 	void setCPUGovernor(const TQString &);
 	void setBacklightBrightness(int);
+	void setHibernationMethod(int);
 
 private:
 	TDEGenericDevice* m_device;
@@ -195,6 +197,8 @@ private:
 
 	TQGridLayout* m_sensorDataGrid;
 	SensorDisplayWidgetList m_sensorDataGridWidgets;
+
+	HibernationComboMap m_hibernationComboMap;
 };
 
 #endif
diff --git a/kcontrol/hwmanager/devicepropsdlgbase.ui b/kcontrol/hwmanager/devicepropsdlgbase.ui
index cd4aaf03d..d1cda0007 100644
--- a/kcontrol/hwmanager/devicepropsdlgbase.ui
+++ b/kcontrol/hwmanager/devicepropsdlgbase.ui
@@ -1217,6 +1217,169 @@
 			    </spacer>
 		    </grid>
             </widget>
+	    <widget class="TQWidget">
+		    <property name="name">
+			    <cstring>tabRootSystem</cstring>
+		    </property>
+		    <attribute name="title">
+			    <string>System</string>
+		    </attribute>
+		    <grid>
+			    <property name="name">
+				    <cstring>unnamed</cstring>
+			    </property>
+			    <widget class="TQGroupBox" row="0" column="0">
+				    <property name="name">
+					    <cstring>groupSysinfo</cstring>
+				    </property>
+				    <property name="title">
+					    <string>System Information</string>
+				    </property>
+				    <grid>
+					    <property name="name">
+						    <cstring>unnamed</cstring>
+					    </property>
+					    <widget class="TQLabel" row="0" column="0" colspan="1">
+						    <property name="name">
+							    <cstring>unnamed</cstring>
+						    </property>
+						    <property name="text">
+							    <string>Form Factor</string>
+						    </property>
+					    </widget>
+					    <widget class="TQLabel" row="0" column="1" colspan="1">
+						    <property name="name">
+							    <cstring>labelSystemFormFactor</cstring>
+						    </property>
+					    </widget>
+				    </grid>
+			    </widget>
+			    <widget class="TQGroupBox" row="1" column="0">
+				    <property name="name">
+					    <cstring>groupSystemPower</cstring>
+				    </property>
+				    <property name="title">
+					    <string>Power Management</string>
+				    </property>
+				    <grid>
+					    <widget class="TQLabel" row="0" column="0" colspan="1">
+						    <property name="name">
+							    <cstring>unnamed</cstring>
+						    </property>
+						    <property name="text">
+							    <string>Available Power States</string>
+						    </property>
+						    <property name="alignment">
+							    <set>AlignTop|AlignLeft</set>
+						    </property>
+					    </widget>
+					    <widget class="TQLabel" row="0" column="1" colspan="1">
+						    <property name="name">
+							    <cstring>labelSystemPowerStates</cstring>
+						    </property>
+					    </widget>
+					    <widget class="TQLabel" row="1" column="0" colspan="1">
+						    <property name="name">
+							    <cstring>unnamed</cstring>
+						    </property>
+						    <property name="text">
+							    <string>Hibernation Method</string>
+						    </property>
+						    <property name="alignment">
+							    <set>AlignTop|AlignLeft</set>
+						    </property>
+					    </widget>
+					    <widget class="KComboBox" row="1" column="1" colspan="1">
+						    <property name="name">
+							    <cstring>comboSystemHibernationMethod</cstring>
+						    </property>
+					    </widget>
+					    <widget class="TQLabel" row="2" column="0" colspan="1">
+						    <property name="name">
+							    <cstring>unnamed</cstring>
+						    </property>
+						    <property name="text">
+							    <string>Disk Space Needed to Hibernate</string>
+						    </property>
+					    </widget>
+					    <widget class="TQLabel" row="2" column="1" colspan="1">
+						    <property name="name">
+							    <cstring>labelSystemHibernationSpace</cstring>
+						    </property>
+					    </widget>
+					    <widget class="TQLabel" row="3" column="0" colspan="1">
+						    <property name="name">
+							    <cstring>unnamed</cstring>
+						    </property>
+						    <property name="text">
+							    <string>User Can Request Standby</string>
+						    </property>
+					    </widget>
+					    <widget class="TQLabel" row="3" column="1" colspan="1">
+						    <property name="name">
+							    <cstring>labelSystemUserCanStandby</cstring>
+						    </property>
+					    </widget>
+					    <widget class="TQLabel" row="4" column="0" colspan="1">
+						    <property name="name">
+							    <cstring>unnamed</cstring>
+						    </property>
+						    <property name="text">
+							    <string>User Can Request Suspend</string>
+						    </property>
+					    </widget>
+					    <widget class="TQLabel" row="4" column="1" colspan="1">
+						    <property name="name">
+							    <cstring>labelSystemUserCanSuspend</cstring>
+						    </property>
+					    </widget>
+					    <widget class="TQLabel" row="5" column="0" colspan="1">
+						    <property name="name">
+							    <cstring>unnamed</cstring>
+						    </property>
+						    <property name="text">
+							    <string>User Can Request Hibernation</string>
+						    </property>
+					    </widget>
+					    <widget class="TQLabel" row="5" column="1" colspan="1">
+						    <property name="name">
+							    <cstring>labelSystemUserCanHibernate</cstring>
+						    </property>
+					    </widget>
+					    <widget class="TQLabel" row="6" column="0" colspan="1">
+						    <property name="name">
+							    <cstring>unnamed</cstring>
+						    </property>
+						    <property name="text">
+							    <string>User Can Request Shutdown</string>
+						    </property>
+					    </widget>
+					    <widget class="TQLabel" row="6" column="1" colspan="1">
+						    <property name="name">
+							    <cstring>labelSystemUserCanPowerOff</cstring>
+						    </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 71b47aac0..055425154 100644
--- a/kcontrol/hwmanager/hwmanager.cpp
+++ b/kcontrol/hwmanager/hwmanager.cpp
@@ -139,13 +139,11 @@ void TDEHWManager::populateTreeView()
 	base->deviceTree->clear();
 
 	if (show_by_connection) {
-		DeviceIconItem* rootitem = new DeviceIconItem(base->deviceTree, "Linux System", DesktopIcon("misc", base->deviceTree->iconSize()), 0);
-
 		TDEHardwareDevices *hwdevices = KGlobal::hardwareDevices();
-		TDEGenericHardwareList hwlist = hwdevices->listByDeviceClass(TDEGenericDeviceType::Root);
+		TDEGenericHardwareList hwlist = hwdevices->listByDeviceClass(TDEGenericDeviceType::RootSystem);
 		TDEGenericDevice *hwdevice;
 		for ( hwdevice = hwlist.first(); hwdevice; hwdevice = hwlist.next() ) {
-			DeviceIconItem* item = new DeviceIconItem(rootitem, hwdevice->friendlyName(), hwdevice->icon(base->deviceTree->iconSize()), hwdevice);
+			DeviceIconItem* item = new DeviceIconItem(base->deviceTree, hwdevice->friendlyName(), hwdevice->icon(base->deviceTree->iconSize()), hwdevice);
 			if ((!selected_syspath.isNull()) && (hwdevice->systemPath() == selected_syspath)) {
 				base->deviceTree->ensureItemVisible(item);
 				base->deviceTree->setSelected(item, true);
-- 
cgit v1.2.3

