tdehardwaredevices.h
00001 /* This file is part of the TDE libraries 00002 Copyright (C) 2012-2014 Timothy Pearson <kb9vqf@pearsoncomputing.net> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License version 2 as published by the Free Software Foundation. 00007 00008 This library is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 Library General Public License for more details. 00012 00013 You should have received a copy of the GNU Library General Public License 00014 along with this library; see the file COPYING.LIB. If not, write to 00015 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00016 Boston, MA 02110-1301, USA. 00017 */ 00018 #ifndef _TDEHARDWAREDEVICES_H 00019 #define _TDEHARDWAREDEVICES_H 00020 00021 00022 // TDE includes 00023 #include <tqobject.h> 00024 #include <tqptrlist.h> 00025 #include <tqmap.h> 00026 #include <tqdict.h> 00027 #include <tqstring.h> 00028 #include <tqstringlist.h> 00029 00030 #include "tdelibs_export.h" 00031 #include "kicontheme.h" 00032 00033 #include "tdehwcommontypes.h" 00034 00035 // FIXME delete those headers after complete fixing everything in over modules 00036 #include "tdegenericdevice.h" 00037 #include "kiconloader.h" 00038 extern "C" { 00039 #include <libudev.h> 00040 } 00041 #include <stdio.h> 00042 #include <stdlib.h> 00043 #include <locale.h> 00044 #include <unistd.h> 00045 #include "tdestoragedevice.h" 00046 #include "tdecpudevice.h" 00047 #include "tdebatterydevice.h" 00048 #include "tdemainspowerdevice.h" 00049 #include "tdenetworkdevice.h" 00050 #include "tdebacklightdevice.h" 00051 #include "tdemonitordevice.h" 00052 #include "tdesensordevice.h" 00053 #include "tderootsystemdevice.h" 00054 #include "tdeeventdevice.h" 00055 #include "tdeinputdevice.h" 00056 00062 struct udev_device; 00063 00064 class KSimpleDirWatch; 00065 00066 class TDEGenericDevice; 00067 class TDEStorageDevice; 00068 class TDENetworkDevice; 00069 class TDEBacklightDevice; 00070 class TDEMonitorDevice; 00071 class TDESensorDevice; 00072 class TDERootSystemDevice; 00073 class TDEEventDevice; 00074 class TDEInputDevice; 00075 class TQSocketNotifier; 00076 00077 typedef TQPtrList<TDEGenericDevice> TDEGenericHardwareList; 00078 typedef TQMap<TQString, TQString> TDEDeviceIDMap; 00079 typedef TQDict<TDECPUDevice> TDECPUDeviceCache; 00080 00081 class TDECORE_EXPORT TDEHardwareDevices : public TQObject 00082 { 00083 Q_OBJECT 00084 00085 public: 00089 TDEHardwareDevices(); 00090 00094 ~TDEHardwareDevices(); 00095 00106 bool queryHardwareInformation(); 00107 00112 TDEGenericHardwareList listAllPhysicalDevices(); 00113 00119 TDEGenericHardwareList listByDeviceClass(TDEGenericDeviceType::TDEGenericDeviceType cl); 00120 00125 TDEGenericDevice* findBySystemPath(TQString syspath); 00126 00131 TDEGenericDevice* findByUniqueID(TQString uid); 00132 00137 TDEGenericDevice* findByDeviceNode(TQString devnode); 00138 00143 TDEStorageDevice* findDiskByUID(TQString uid); 00144 00149 TDECPUDevice* findCPUBySystemPath(TQString syspath, bool inCache); 00150 00159 TQString findPCIDeviceName(TQString vendorid, TQString modelid, TQString subvendorid, TQString submodelid); 00160 00169 TQString findUSBDeviceName(TQString vendorid, TQString modelid, TQString subvendorid, TQString submodelid); 00170 00176 TQString findPNPDeviceName(TQString pnpid); 00177 00183 TQString findMonitorManufacturerName(TQString dpyid); 00184 00190 TQString getFriendlyDeviceTypeStringFromType(TDEGenericDeviceType::TDEGenericDeviceType query); 00191 00198 TQPixmap getDeviceTypeIconFromType(TDEGenericDeviceType::TDEGenericDeviceType query, TDEIcon::StdSizes size); 00199 00204 TDERootSystemDevice* rootSystemDevice(); 00205 00211 void rescanDeviceInformation(TDEGenericDevice* hwdevice); 00212 00221 void rescanDeviceInformation(TDEGenericDevice* hwdevice, bool regenerateDeviceTree); 00222 00230 void setTriggerlessHardwareUpdatesEnabled(bool enable); 00231 00239 void setBatteryUpdatesEnabled(bool enable); 00240 00246 static TQString bytesToFriendlySizeString(double bytes); 00247 00248 signals: 00249 void hardwareAdded(TDEGenericDevice*); 00250 void hardwareRemoved(TDEGenericDevice*); 00251 void hardwareUpdated(TDEGenericDevice*); 00252 void mountTableModified(); 00253 void hardwareEvent(TDEHardwareEvent::TDEHardwareEvent, TQString uuid); 00254 00260 void eventDeviceKeyPressed(unsigned int keycode, TDEEventDevice* device); 00261 00262 private slots: 00263 void processHotPluggedHardware(); 00264 void processModifiedMounts(); 00265 void processModifiedCPUs(); 00266 void processBatteryDevices(); 00267 void processStatelessDevices(); 00268 void processEventDeviceKeyPressed(unsigned int keycode, TDEEventDevice* edevice); 00269 00270 private: 00271 void updateBlacklists(TDEGenericDevice* hwdevice, udev_device* dev); 00272 00273 private: 00274 TDEGenericDevice *classifyUnknownDevice(udev_device* dev, TDEGenericDevice* existingdevice=0, bool force_full_classification=true); 00275 TDEGenericDevice *classifyUnknownDeviceByExternalRules(udev_device* dev, TDEGenericDevice* existingdevice=0, bool classifySubDevices=false); 00276 void updateExistingDeviceInformation(TDEGenericDevice* existingdevice, udev_device* dev=NULL); 00277 00278 void updateParentDeviceInformation(); 00279 void updateParentDeviceInformation(TDEGenericDevice* hwdevice); 00280 00281 void addCoreSystemDevices(); 00282 00287 TQByteArray getEDID(TQString path); 00288 00293 TQPair<TQString,TQString> getEDIDMonitorName(TQString path); 00294 00295 struct udev *m_udevStruct; 00296 struct udev_monitor *m_udevMonitorStruct; 00297 TDEGenericHardwareList m_deviceList; 00298 int m_procMountsFd; 00299 KSimpleDirWatch* m_cpuWatch; 00300 TQTimer* m_cpuWatchTimer; 00301 TQTimer* m_batteryWatchTimer; 00302 TQTimer* m_deviceWatchTimer; 00303 00304 TQSocketNotifier* m_devScanNotifier; 00305 TQSocketNotifier* m_mountScanNotifier; 00306 00307 TQMap<TQString, bool> m_mountTable; 00308 TQStringList m_cpuInfo; 00309 00310 TDEDeviceIDMap* pci_id_map; 00311 TDEDeviceIDMap* usb_id_map; 00312 TDEDeviceIDMap* pnp_id_map; 00313 TDEDeviceIDMap* dpy_id_map; 00314 00315 TDECPUDeviceCache m_cpuByPathCache; 00316 00317 friend class TDEGenericDevice; 00318 friend class TDEStorageDevice; 00319 friend class TDECPUDevice; 00320 }; 00321 00322 #endif // _TDEHARDWAREDEVICES_H