diff options
author | Lorn Potter <lorn.potter@nokia.com> | 2009-07-23 09:24:35 +1000 |
---|---|---|
committer | Lorn Potter <lorn.potter@nokia.com> | 2009-07-23 09:24:35 +1000 |
commit | ba73ac25fb87d6307adabbd4d0cfd8de16ddc0b9 (patch) | |
tree | d27def29368a5b61799c8947a02aa1fd5548411e | |
parent | 39dcaa3cb095df1f3e0a59193a3a96c4f8257ae8 (diff) |
add display stuff and tests.
-rwxr-xr-x[-rw-r--r--] | systeminfo/qhalservice.cpp | 58 | ||||
-rwxr-xr-x[-rw-r--r--] | systeminfo/qhalservice.h | 18 | ||||
-rwxr-xr-x[-rw-r--r--] | systeminfo/qsysteminfo_linux.cpp | 119 | ||||
-rw-r--r-- | tests/auto/auto.pro | 4 | ||||
-rw-r--r-- | tests/auto/qsystemdisplayinfo/qsystemdisplayinfo.pro | 16 | ||||
-rw-r--r-- | tests/auto/qsystemdisplayinfo/tst_qsystemdisplayinfo.cpp | 81 |
6 files changed, 280 insertions, 16 deletions
diff --git a/systeminfo/qhalservice.cpp b/systeminfo/qhalservice.cpp index 0fe961173e..8eedc68a9c 100644..100755 --- a/systeminfo/qhalservice.cpp +++ b/systeminfo/qhalservice.cpp @@ -51,6 +51,7 @@ #include <QDBusObjectPath> #include "qhalservice.h" + static QDBusConnection dbusConnection = QDBusConnection::systemBus(); class QHalInterfacePrivate @@ -218,3 +219,60 @@ bool QHalDeviceInterface::queryCapability(const QString &cap) return false; } +///////// + +class QHalDeviceLaptopPanelInterfacePrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + bool valid; +}; + +QHalDeviceLaptopPanelInterface::QHalDeviceLaptopPanelInterface(const QString &devicePathName, QObject *parent ) + : QObject(parent) +{ + d = new QHalDeviceLaptopPanelInterfacePrivate(); + d->path = devicePathName; + d->connectionInterface = new QDBusInterface(HAL_DBUS_SERVICE, + d->path, + HAL_DEVICES_LAPTOPPANEL_INTERFACE, + dbusConnection); + if (!d->connectionInterface->isValid()) { + d->valid = false; + qWarning() << "Could not find HalDeviceLaptopPanelInterface"; + return; + } else { + d->valid = true; + } +} + +QHalDeviceLaptopPanelInterface::~QHalDeviceLaptopPanelInterface() +{ + delete d->connectionInterface; + delete d; +} + +bool QHalDeviceLaptopPanelInterface::isValid() +{ + return d->valid; +} + +quint32 QHalDeviceLaptopPanelInterface::getBrightness() +{ + QDBusReply< qint32 > reply = d->connectionInterface->call("GetBrightness"); + if ( reply.isValid() ) { + qWarning() << __FUNCTION__ << reply.value(); + return reply.value(); + } + return -1; +} + +void QHalDeviceLaptopPanelInterface::setBrightness(quint32 brightness) +{ + QDBusReply< qint32 > reply = d->connectionInterface->call("SetBrightness", brightness); + if ( reply.isValid() ) { + qWarning() << __FUNCTION__ << reply.value(); + } +} + diff --git a/systeminfo/qhalservice.h b/systeminfo/qhalservice.h index 9381d348d7..ab7675196f 100644..100755 --- a/systeminfo/qhalservice.h +++ b/systeminfo/qhalservice.h @@ -66,6 +66,7 @@ #define HAL_DEVICES_PATH "/org/freedesktop/Hal/devices" +#define HAL_DEVICES_LAPTOPPANEL_INTERFACE "org.freedesktop.Hal.Device.LaptopPanel" class QHalInterfacePrivate; class QHalInterface : public QObject @@ -112,4 +113,21 @@ private: }; +class QHalDeviceLaptopPanelInterfacePrivate; +class QHalDeviceLaptopPanelInterface : public QObject +{ + Q_OBJECT + +public: + QHalDeviceLaptopPanelInterface(const QString &devicePathName, QObject *parent = 0); + ~QHalDeviceLaptopPanelInterface(); + bool isValid(); +public: + quint32 getBrightness(); + void setBrightness(quint32); + +private: + QHalDeviceLaptopPanelInterfacePrivate *d; +}; + #endif // diff --git a/systeminfo/qsysteminfo_linux.cpp b/systeminfo/qsysteminfo_linux.cpp index 05028d1385..1a2b9e16de 100644..100755 --- a/systeminfo/qsysteminfo_linux.cpp +++ b/systeminfo/qsysteminfo_linux.cpp @@ -44,6 +44,8 @@ #include <QDesktopWidget> #include <QDebug> +#include <QLibraryInfo> + #if !defined(QT_NO_DBUS) #include <QtDBus> #include <QDBusConnection> @@ -90,8 +92,36 @@ QString QSystemInfoPrivate::currentLanguage() const // 2 letter ISO 639-1 QStringList QSystemInfoPrivate::availableLanguages() const { - // /usr/lib/locale - // locale -a +#if 0 + // Qt translations + QDir localeDir(QLibraryInfo::location(QLibraryInfo::TranslationsPath)); + if(localeDir.exists()) { + QStringList langList; + QFileInfoList localeList = localeDir.entryInfoList(QStringList() << "qt_*.qm", QDir::Files | QDir::NoDotAndDotDot, QDir::Name); + foreach(QFileInfo trFileInfo, localeList) { + QString lang = trFileInfo.baseName(); + if(!lang.contains("help")) { + lang = lang.mid(lang.indexOf("_")+1,2); + if(!langList.contains(lang)) { + langList << lang; + } + } + } + return langList; + } +#endif + QDir localeDir("/usr/lib/locale"); + if(localeDir.exists()) { + QStringList langList; + QStringList localeList = localeDir.entryList( QStringList() ,QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name); + foreach(QString localeName, localeList) { + QString lang = localeName.left(2); + if(!langList.contains(lang) && !lang.isEmpty()) { + langList <<lang; + } + } + return langList; + } return QStringList() << currentLanguage(); } @@ -266,25 +296,86 @@ QSystemDisplayInfoPrivate::~QSystemDisplayInfoPrivate() qint32 QSystemDisplayInfoPrivate::displayBrightness() { - // laptop_panel - // org.freedesktop.Hal.Device.LaptopPanel - // SetBrightness - // GetBrightness #if !defined(QT_NO_DBUS) QHalInterface iface; if (iface.isValid()) { - QStringList list = iface.findDeviceByCapability("laptop_panel"); - if(!list.isEmpty()) { -// QHalDeviceInterface *ifaceDevice; -// ifaceDevice = new QHalDeviceInterface(vol); -// if (ifaceDevice->isValid() && ifaceDevice->getPropertyBool("volume.is_mounted")) { -// qWarning() << ifaceDevice->getPropertyString("volume.mount_point"); -// } - + QStringList list = iface.findDeviceByCapability("laptop_panel"); + if(!list.isEmpty()) { + foreach(QString lapDev, list) { + QHalDeviceInterface ifaceDevice(lapDev); + QHalDeviceLaptopPanelInterface lapIface(lapDev); + float numLevels = ifaceDevice.getPropertyInt("laptop_panel.num_levels"); + float curLevel = lapIface.getBrightness(); + return curLevel / numLevels * 100; } + } } #else + + QString backlightPath = "/proc/acpi/video/"; + QDir videoDir(backlightPath); + QStringList filters; + filters << "*"; + QStringList brightnessList = videoDir.entryList(filters, + QDir::Dirs + | QDir::NoDotAndDotDot, + QDir::Name); + foreach(QString brightnessFileName, brightnessList) { + float numLevels = 0.0; + float curLevel = 0.0; + QFile curBrightnessFile(backlightPath+brightnessFileName+"/LCD/brightness"); + if(!curBrightnessFile.open(QIODevice::ReadOnly | QIODevice::Text)) { + qWarning()<<"File not opened"; + } else { + QString strvalue; + strvalue = curBrightnessFile.readAll().trimmed(); + if(strvalue.contains("levels")) { + QStringList list = strvalue.split(" "); + numLevels = list.at(2).toFloat(); + } + if(strvalue.contains("current")) { + QStringList list = strvalue.split(": "); + curLevel = list.at(list.count()-1).toFloat(); + } + curBrightnessFile.close(); + return curLevel / numLevels * 100; + } + } +#if 0 + QString backlightPath = "/sys/devices/virtual/backlight/"; + QDir videoDir(backlightPath); + QStringList filters; + filters << "*"; + QStringList brightnessList = videoDir.entryList(filters, + QDir::Dirs + | QDir::NoDotAndDotDot, + QDir::Name); + foreach(QString brightnessFileName, brightnessList) { + float numLevels = 0.0; + float curLevel = 0.0; + QFile curBrightnessFile(backlightPath+brightnessFileName+"/brightness"); + if(!curBrightnessFile.open(QIODevice::ReadOnly | QIODevice::Text)) { + qWarning()<<"File not opened"; + } else { + QString strvalue; + strvalue = curBrightnessFile.readLine().trimmed(); + curBrightnessFile.close(); + curLevel = strvalue.toFloat(); + + QFile maxBrightnessFile(backlightPath+brightnessFileName+"/max_brightness"); + if(!maxBrightnessFile.open(QIODevice::ReadOnly | QIODevice::Text)) { + qWarning()<<"File not opened"; + } else { + QString strvalue; + strvalue = maxBrightnessFile.readLine().trimmed(); + maxBrightnessFile.close(); + numLevels = strvalue.toFloat(); + } + return curLevel / numLevels * 100; + } + } +#endif #endif return -1; } diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index bea06755a5..b0dbfc8efc 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -1,8 +1,8 @@ TEMPLATE = subdirs SUBDIRS = qsysteminfo \ qsystemdeviceinfo \ + qsystemdisplayinfo \ qsystemmemoryinfo -# qsystemnetworkinfo -# qsystemdisplayinfo \ +# qsystemnetworkinfo diff --git a/tests/auto/qsystemdisplayinfo/qsystemdisplayinfo.pro b/tests/auto/qsystemdisplayinfo/qsystemdisplayinfo.pro new file mode 100644 index 0000000000..a3b50d32b9 --- /dev/null +++ b/tests/auto/qsystemdisplayinfo/qsystemdisplayinfo.pro @@ -0,0 +1,16 @@ +SOURCES += tst_qsystemdisplayinfo.cpp +HEADERS += +TARGET = tst_qsystemdisplayinfo +CONFIG+=testcase +QT += testlib +QT -= gui +QT = core network + +INCLUDEPATH += ../../../systeminfo + +include(../../../common.pri) +LIBS += -lQtSystemInfo + +symbian { + TARGET.CAPABILITY = All -TCB -DRM +} diff --git a/tests/auto/qsystemdisplayinfo/tst_qsystemdisplayinfo.cpp b/tests/auto/qsystemdisplayinfo/tst_qsystemdisplayinfo.cpp new file mode 100644 index 0000000000..9ad257944a --- /dev/null +++ b/tests/auto/qsystemdisplayinfo/tst_qsystemdisplayinfo.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** If you have questions regarding the use of this file, please +** contact Nokia at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <QtTest/QtTest> +#include "qsysteminfo.h" + +class tst_QSystemDisplayInfo : public QObject +{ + Q_OBJECT + +private slots: + void tst_displayBrightness(); + void tst_colorDepth(); + void tst_setScreenSaverEnabled(); + void tst_setScreenBlankingEnabled(); + void tst_isScreenLockOn(); + +}; + +void tst_QSystemDisplayInfo::tst_displayBrightness() +{ + QSystemDisplayInfo di; + +qWarning() << di.displayBrightness(); +} + +void tst_QSystemDisplayInfo::tst_colorDepth() +{ + QSystemDisplayInfo di; + qWarning() << di.colorDepth(0); +} + +void tst_QSystemDisplayInfo::tst_setScreenSaverEnabled() +{ + QSystemDisplayInfo di; +} + +void tst_QSystemDisplayInfo::tst_setScreenBlankingEnabled() +{ + QSystemDisplayInfo di; +} + +void tst_QSystemDisplayInfo::tst_isScreenLockOn() +{ + QSystemDisplayInfo di; + qWarning() << di.isScreenLockOn(); +} + + + +QTEST_MAIN(tst_QSystemDisplayInfo) +#include "tst_qsystemdisplayinfo.moc" |