src/systeminfo/qsysteminfo_maemo.cpp
changeset 5 603d3f8b6302
parent 0 876b1a06bc25
--- a/src/systeminfo/qsysteminfo_maemo.cpp	Fri Sep 17 08:34:34 2010 +0300
+++ b/src/systeminfo/qsysteminfo_maemo.cpp	Mon Oct 04 01:37:06 2010 +0300
@@ -917,7 +917,10 @@
 
 int QSystemDisplayInfoPrivate::displayBrightness(int screen)
 {
-    Q_UNUSED(screen);
+    QDesktopWidget wid;
+    if(wid.screenCount() - 1 < screen) {
+        return -1;
+    }
     GConfItem currentBrightness("/system/osso/dsm/display/display_brightness");
     GConfItem maxBrightness("/system/osso/dsm/display/max_display_brightness_levels");
     if(maxBrightness.value().toInt()) {
@@ -1225,12 +1228,43 @@
     }
 }
 
+QString QSystemDeviceInfoPrivate::model()
+{
+    QString name;
+    if(productName()== "RX-51")
+        return "N900";
+
+    name = "Harmattan"; //fake this for now
+
+    return name;
+
+}
+
+QString QSystemDeviceInfoPrivate::productName()
+{
+#if !defined(QT_NO_DBUS)
+#if defined(Q_WS_MAEMO_6)
+    QString dBusService = "com.nokia.SystemInfo";
+#else
+    /* Maemo 5 */
+    QString dBusService = "com.nokia.SystemInfo";
+#endif
+    QDBusInterface connectionInterface(dBusService,
+                                       "/com/nokia/SystemInfo",
+                                       "com.nokia.SystemInfo",
+                                       QDBusConnection::systemBus());
+
+    QDBusReply< QByteArray > reply = connectionInterface.call("GetConfigValue","/component/product");
+    return reply.value();
+#endif
+}
+
 #endif
 
 //////////////
 ///////
 QSystemScreenSaverPrivate::QSystemScreenSaverPrivate(QObject *parent)
-        : QSystemScreenSaverLinuxCommonPrivate(parent)
+        : QSystemScreenSaverLinuxCommonPrivate(parent),isInhibited(0)
 {
     ssTimer = new QTimer(this);
 #if !defined(QT_NO_DBUS)
@@ -1260,7 +1294,10 @@
         // The reason for this is to avoid the situation where
         // a crashed/hung application keeps the display on.
         ssTimer->start(30000);
-     }
+        isInhibited = true;
+    } else {
+        isInhibited = false;
+    }
      return screenSaverInhibited();
 }
 
@@ -1277,17 +1314,37 @@
 bool QSystemScreenSaverPrivate::screenSaverInhibited()
 {
     bool displayOn = false;
+    GConfItem screenBlankItem("/system/osso/dsm/display/inhibit_blank_mode");
+    /* 0 - no inhibit
+       1 - inhibit dim with charger
+       2 - inhibit blank with charger (display still dims)
+       3 - inhibit dim (always)
+       4 - inhibit blank (always; display still dims)
+*/
+    int blankingItem = screenBlankItem.value().toInt();
+
+    bool isBlankingInhibited = false;
+    QSystemDeviceInfo devInfo(this);
+    QSystemDeviceInfo::PowerState batState = devInfo.currentPowerState();
+
+    if( ((batState == QSystemDeviceInfo::WallPower || batState == QSystemDeviceInfo::WallPowerChargingBattery)
+       && blankingItem == 2) || blankingItem == 4) {
+        isBlankingInhibited = true;
+    }
+
 #if !defined(QT_NO_DBUS)
     if (mceConnectionInterface->isValid()) {
         // The most educated guess for the screen saver being inhibited is to determine
         // whether the display is on. That is because the QSystemScreenSaver cannot
         // prevent other processes from blanking the screen (like, if
         // MCE decides to blank the screen for some reason).
+        // but that means it reports to be inhibited when display is on. meaning
+        // effectly always inhibited by default. so we try a bit harder
         QDBusReply<QString> reply = mceConnectionInterface->call("get_display_status");
         displayOn = ("on" == reply.value());
     }
 #endif
-    return displayOn;
+    return (displayOn && isBlankingInhibited && isInhibited);
 }
 
 #include "moc_qsysteminfo_maemo_p.cpp"