src/systeminfo/qsysteminfo_maemo.cpp
changeset 0 876b1a06bc25
child 5 603d3f8b6302
equal deleted inserted replaced
-1:000000000000 0:876b1a06bc25
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Mobility Components.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 #include "qsysteminfo.h"
       
    42 #include "qsysteminfo_maemo_p.h"
       
    43 
       
    44 #include <QStringList>
       
    45 #include <QSize>
       
    46 #include <QFile>
       
    47 #include <QTextStream>
       
    48 #include <QLocale>
       
    49 #include <QLibraryInfo>
       
    50 //#include <QtGui>
       
    51 #include <QDesktopWidget>
       
    52 #include <QDebug>
       
    53 #include <QTimer>
       
    54 #include <QDir>
       
    55 #include <QTimer>
       
    56 #include <QMapIterator>
       
    57 
       
    58 #if !defined(QT_NO_DBUS)
       
    59 #include "gconfitem_p.h" // Temporarily here.
       
    60 #endif
       
    61 
       
    62 #ifdef Q_WS_X11
       
    63 #include <QX11Info>
       
    64 #include <X11/Xlib.h>
       
    65 
       
    66 #endif
       
    67 
       
    68 #include <QDBusInterface>
       
    69 
       
    70 #if !defined(QT_NO_DBUS)
       
    71 QDBusArgument &operator<<(QDBusArgument &argument, const ProfileDataValue &value)
       
    72 {
       
    73   argument.beginStructure();
       
    74   argument << value.key << value.val << value.type;
       
    75   argument.endStructure();
       
    76   return argument;
       
    77 }
       
    78 
       
    79 const QDBusArgument &operator>>(const QDBusArgument &argument, ProfileDataValue &value)
       
    80 {
       
    81   argument.beginStructure();
       
    82   argument >> value.key >> value.val >> value.type;
       
    83   argument.endStructure();
       
    84   return argument;
       
    85 }
       
    86 #endif
       
    87 
       
    88 QTM_BEGIN_NAMESPACE
       
    89 
       
    90 QSystemInfoPrivate::QSystemInfoPrivate(QSystemInfoLinuxCommonPrivate *parent)
       
    91  : QSystemInfoLinuxCommonPrivate(parent)
       
    92 {
       
    93 }
       
    94 
       
    95 QSystemInfoPrivate::~QSystemInfoPrivate()
       
    96 {
       
    97 }
       
    98 
       
    99 QStringList QSystemInfoPrivate::availableLanguages() const
       
   100 {
       
   101     QStringList languages;
       
   102 
       
   103     GConfItem languagesItem("/apps/osso/inputmethod/available_languages");
       
   104     const QStringList locales = languagesItem.value().toStringList();
       
   105 
       
   106     foreach(const QString locale, locales) {
       
   107         languages << locale.mid(0,2);
       
   108     }
       
   109     languages << currentLanguage();
       
   110     languages.removeDuplicates();
       
   111 
       
   112     return languages;
       
   113 }
       
   114 
       
   115 QString QSystemInfoPrivate::version(QSystemInfo::Version type,
       
   116                                     const QString &parameter)
       
   117 {
       
   118     QString errorStr = "Not Available";
       
   119 
       
   120     switch(type) {
       
   121         case QSystemInfo::Firmware :
       
   122         {
       
   123             QDBusInterface connectionInterface("com.nokia.SystemInfo",
       
   124                                                "/com/nokia/SystemInfo",
       
   125                                                "com.nokia.SystemInfo",
       
   126                                                QDBusConnection::systemBus());
       
   127             if(!connectionInterface.isValid()) {
       
   128                 qWarning() << "interfacenot valid";
       
   129             } else {
       
   130                 QDBusReply< QByteArray > reply =
       
   131                     connectionInterface.call("GetConfigValue",
       
   132                                              "/device/sw-release-ver");
       
   133                 if(reply.isValid())
       
   134                     return reply.value();
       
   135             }
       
   136             break;
       
   137         }
       
   138         default:
       
   139             return QSystemInfoLinuxCommonPrivate::version(type, parameter);
       
   140             break;
       
   141     };
       
   142     return errorStr;
       
   143 }
       
   144 
       
   145 bool QSystemInfoPrivate::hasFeatureSupported(QSystemInfo::Feature feature)
       
   146 {
       
   147     bool featureSupported = false;
       
   148     switch (feature) {
       
   149     case QSystemInfo::SimFeature :
       
   150         {
       
   151             QSystemDeviceInfoPrivate d;
       
   152             featureSupported = (d.simStatus() != QSystemDeviceInfo::SimNotAvailable);
       
   153         }
       
   154         break;
       
   155     case QSystemInfo::LocationFeature :
       
   156         {
       
   157 #if defined(Q_WS_MAEMO_6)
       
   158             GConfItem satellitePositioning("/system/osso/location/settings/satellitePositioning");
       
   159             GConfItem networkPositioning("/system/osso/location/settings/networkPositioning");
       
   160 
       
   161             bool satellitePositioningAvailable = satellitePositioning.value(false).toBool();
       
   162             bool networkPositioningAvailable   = networkPositioning.value(false).toBool();
       
   163 
       
   164             featureSupported = (satellitePositioningAvailable || networkPositioningAvailable);
       
   165 #else /* Maemo 5 */
       
   166             GConfItem locationValues("/system/nokia/location");
       
   167             const QStringList locationKeys = locationValues.listEntries();
       
   168             if(locationKeys.count()) {
       
   169                 featureSupported = true;
       
   170             }
       
   171 #endif /* Maemo 5 */
       
   172         }
       
   173         break;
       
   174     case QSystemInfo::HapticsFeature:
       
   175         {
       
   176            // if(halIsAvailable) {
       
   177                 QHalInterface iface;
       
   178                 const QStringList touchSupport =
       
   179                         iface.findDeviceByCapability("input.touchpad");
       
   180                 if(touchSupport.count()) {
       
   181                     featureSupported = true;
       
   182                 } else {
       
   183                     featureSupported = false;
       
   184                 }
       
   185             }
       
   186       //  }
       
   187         break;
       
   188     default:
       
   189         featureSupported = QSystemInfoLinuxCommonPrivate::hasFeatureSupported(feature);
       
   190         break;
       
   191     };
       
   192     return featureSupported;
       
   193 }
       
   194 
       
   195 QSystemNetworkInfoPrivate::QSystemNetworkInfoPrivate(QSystemNetworkInfoLinuxCommonPrivate *parent)
       
   196         : QSystemNetworkInfoLinuxCommonPrivate(parent)
       
   197 {
       
   198     csStatusMaemo6["Unknown"]    = -1;  // Current registration status is unknown.
       
   199     csStatusMaemo6["Home"]       = 0;   // Registered with the home network.
       
   200     csStatusMaemo6["Roaming"]    = 1;   // Registered with a roaming network.
       
   201     csStatusMaemo6["Offline"]    = 3;   // Not registered.
       
   202     csStatusMaemo6["Searching"]  = 4;   // Offline, but currently searching for network.
       
   203     csStatusMaemo6["NoSim"]      = 6;   // Offline because no SIM is present.
       
   204     csStatusMaemo6["PowerOff"]   = 8;   // Offline because the CS is powered off.
       
   205     csStatusMaemo6["PowerSave"]  = 9;   // Offline and in power save mode.
       
   206     csStatusMaemo6["NoCoverage"] = 10;  // Offline and in power save mode because of poor coverage.
       
   207     csStatusMaemo6["Rejected"]   = 11;  // Offline because SIM was rejected by the network.
       
   208 
       
   209     setupNetworkInfo();
       
   210 }
       
   211 
       
   212 QSystemNetworkInfoPrivate::~QSystemNetworkInfoPrivate()
       
   213 {
       
   214     if(wlanSignalStrengthTimer->isActive())
       
   215         wlanSignalStrengthTimer->stop();
       
   216 }
       
   217 
       
   218 
       
   219 QSystemNetworkInfo::NetworkStatus QSystemNetworkInfoPrivate::networkStatus(QSystemNetworkInfo::NetworkMode mode)
       
   220 {
       
   221     switch(mode) {
       
   222     case QSystemNetworkInfo::GsmMode:
       
   223     case QSystemNetworkInfo::CdmaMode:
       
   224     case QSystemNetworkInfo::WcdmaMode:
       
   225         {    
       
   226             switch(currentCellNetworkStatus) {
       
   227                 case 0: return QSystemNetworkInfo::HomeNetwork; // CS is registered to home network
       
   228                 case 1: return QSystemNetworkInfo::Roaming; // CS is registered to some other network than home network
       
   229                 case 2: return QSystemNetworkInfo::Roaming; // CS is registered to non-home system in a non-home area
       
   230                 case 3: return QSystemNetworkInfo::NoNetworkAvailable; // CS is not in service
       
   231                 case 4: return QSystemNetworkInfo::Searching; // CS is not in service, but is currently searching for service
       
   232                 case 5: return QSystemNetworkInfo::NoNetworkAvailable; // CS is not in service and it is not currently searching for service
       
   233                 case 6: return QSystemNetworkInfo::NoNetworkAvailable; // CS is not in service due to missing SIM or missing subscription
       
   234                 case 8: return QSystemNetworkInfo::NoNetworkAvailable; // CS is in power off state
       
   235                 case 9: return QSystemNetworkInfo::NoNetworkAvailable; // CS is in No Service Power Save State (currently not listening to any cell)
       
   236                 case 10: return QSystemNetworkInfo::NoNetworkAvailable; // CS is in No Service Power Save State (CS is entered to this state
       
   237                                                                         // because there is no network coverage)
       
   238                 case 11: return QSystemNetworkInfo::Denied; // CS is not in service due to missing subscription
       
   239                 default:
       
   240                     break;
       
   241             };
       
   242         }
       
   243         break;
       
   244     case QSystemNetworkInfo::EthernetMode:
       
   245         if(currentEthernetState == "up") {
       
   246             return QSystemNetworkInfo::Connected;
       
   247         } else {
       
   248             return QSystemNetworkInfo::NoNetworkAvailable;
       
   249         }
       
   250         break;
       
   251     case QSystemNetworkInfo::WlanMode:
       
   252     case QSystemNetworkInfo::BluetoothMode:
       
   253         {
       
   254             return QSystemNetworkInfoLinuxCommonPrivate::networkStatus(mode);
       
   255         }
       
   256         break;
       
   257     default:
       
   258         break;
       
   259     };
       
   260     return QSystemNetworkInfo::UndefinedStatus;
       
   261 }
       
   262 
       
   263 qint32 QSystemNetworkInfoPrivate::networkSignalStrength(QSystemNetworkInfo::NetworkMode mode)
       
   264 { 
       
   265     switch(mode) {
       
   266     case QSystemNetworkInfo::GsmMode:
       
   267     case QSystemNetworkInfo::CdmaMode:
       
   268     case QSystemNetworkInfo::WcdmaMode:
       
   269     {
       
   270             return cellSignalStrength;
       
   271     }
       
   272     case QSystemNetworkInfo::EthernetMode: {
       
   273         QString result;
       
   274         QString baseSysDir = "/sys/class/net/";
       
   275         QString interface = QSystemNetworkInfoLinuxCommonPrivate::interfaceForMode(mode).humanReadableName();
       
   276         if (interface == "usb0") {
       
   277             QString dir = QSystemNetworkInfoLinuxCommonPrivate::interfaceForMode(mode).name();
       
   278             QString devFile = baseSysDir + dir;
       
   279             QFileInfo fi(devFile + "/carrier");
       
   280             if(fi.exists()) {
       
   281                 QFile rx(fi.absoluteFilePath());
       
   282                 if(rx.exists() && rx.open(QIODevice::ReadOnly | QIODevice::Text)) {
       
   283                     QTextStream stream(&rx);
       
   284                     stream >> result;
       
   285                     rx.close();
       
   286                     return result.toInt() * 100;
       
   287                     break;
       
   288                 }
       
   289             }
       
   290         }
       
   291         return QSystemNetworkInfoLinuxCommonPrivate::networkSignalStrength(mode);
       
   292         break;
       
   293     }
       
   294     case QSystemNetworkInfo::WlanMode:
       
   295     case QSystemNetworkInfo::BluetoothMode:
       
   296         return QSystemNetworkInfoLinuxCommonPrivate::networkSignalStrength(mode);
       
   297         break;
       
   298     default:
       
   299         break;
       
   300     };
       
   301 
       
   302     return -1;
       
   303 }
       
   304 
       
   305 int QSystemNetworkInfoPrivate::cellId()
       
   306 {
       
   307     return currentCellId;
       
   308 }
       
   309 
       
   310 int QSystemNetworkInfoPrivate::locationAreaCode()
       
   311 {
       
   312     return currentLac;
       
   313 }
       
   314 
       
   315 QString QSystemNetworkInfoPrivate::currentMobileCountryCode()
       
   316 {
       
   317     return currentMCC;
       
   318 }
       
   319 
       
   320 QString QSystemNetworkInfoPrivate::currentMobileNetworkCode()
       
   321 {
       
   322     return currentMNC;
       
   323 }
       
   324 
       
   325 QString QSystemNetworkInfoPrivate::homeMobileCountryCode()
       
   326 {
       
   327     QSystemDeviceInfoPrivate d;
       
   328     QString imsi = d.imsi();
       
   329     if (imsi.length() >= 3) {
       
   330         return imsi.left(3);
       
   331     }
       
   332     return "";
       
   333 }
       
   334 
       
   335 QString QSystemNetworkInfoPrivate::homeMobileNetworkCode()
       
   336 {
       
   337 #if !defined(QT_NO_DBUS)
       
   338     #if defined(Q_WS_MAEMO_6)
       
   339     QDBusInterface connectionInterface("com.nokia.csd.SIM",
       
   340                                        "/com/nokia/csd/sim",
       
   341                                        "com.nokia.csd.SIM.Identity",
       
   342                                        QDBusConnection::systemBus());
       
   343     QDBusMessage reply = connectionInterface.call(QLatin1String("GetHPLMN"));
       
   344     if (reply.errorName().isEmpty()) {
       
   345         QList<QVariant> args = reply.arguments();
       
   346         // The first attribute should be MCC and the 2nd one MNC
       
   347         if (args.size() == 2) {
       
   348             return args.at(1).toString();
       
   349         }
       
   350     }
       
   351     #else
       
   352     /* Maemo 5 */
       
   353     QDBusInterface connectionInterface("com.nokia.phone.SIM",
       
   354                                        "/com/nokia/phone/SIM",
       
   355                                        "Phone.Sim",
       
   356                                        QDBusConnection::systemBus());
       
   357     if (!connectionInterface.isValid()) {
       
   358         qWarning() << "interface not valid";
       
   359         return QString();
       
   360     }
       
   361     QDBusReply<QByteArray> reply = connectionInterface.call(QLatin1String("read_hplmn"));
       
   362 
       
   363     // The MNC and MCC are split into Hex numbers in the received byte array.
       
   364     // The MNC can be 2 or 3 digits long. If it is 2 digits long, it ends with 0xF.
       
   365     // The order of the Hex numbers in the reply is:
       
   366     // mcc2 mcc1 mnc3 mcc3 mnc2 mnc1
       
   367 
       
   368     QString homeMobileNetworkCode;
       
   369     if (reply.isValid()) {
       
   370         QString temp = reply.value().toHex();
       
   371         QString mnc1 = temp.right(1);
       
   372         temp.chop(1);
       
   373         QString mnc2 = temp.right(1);
       
   374         temp.chop(2);
       
   375         QString mnc3 = temp.right(1);
       
   376         if (mnc3 != "f") {
       
   377             homeMobileNetworkCode.prepend(mnc3);
       
   378         }
       
   379         homeMobileNetworkCode.prepend(mnc2);
       
   380         homeMobileNetworkCode.prepend(mnc1);
       
   381         return homeMobileNetworkCode;
       
   382     }
       
   383     #endif
       
   384 #endif
       
   385     return "";
       
   386 }
       
   387 
       
   388 QString QSystemNetworkInfoPrivate::networkName(QSystemNetworkInfo::NetworkMode mode)
       
   389 {
       
   390     QString netname = "";
       
   391 
       
   392     switch(mode) {
       
   393 
       
   394     case QSystemNetworkInfo::CdmaMode:
       
   395     case QSystemNetworkInfo::GsmMode:
       
   396     case QSystemNetworkInfo::WcdmaMode:
       
   397         return currentOperatorName;
       
   398         break;
       
   399     case QSystemNetworkInfo::WimaxMode:
       
   400         break;
       
   401     default:
       
   402         return QSystemNetworkInfoLinuxCommonPrivate::networkName(mode);
       
   403         break;
       
   404     };
       
   405     return netname;
       
   406 }
       
   407 
       
   408 QString QSystemNetworkInfoPrivate::macAddress(QSystemNetworkInfo::NetworkMode mode)
       
   409 {
       
   410     switch(mode) {
       
   411 
       
   412     case QSystemNetworkInfo::CdmaMode:
       
   413     case QSystemNetworkInfo::GsmMode:
       
   414     case QSystemNetworkInfo::WcdmaMode:
       
   415     case QSystemNetworkInfo::WimaxMode:
       
   416         break;
       
   417     case QSystemNetworkInfo::EthernetMode: {
       
   418         QString address;
       
   419         QString baseSysDir = "/sys/class/net/";
       
   420         QString interface = QSystemNetworkInfoLinuxCommonPrivate::interfaceForMode(mode).humanReadableName();
       
   421         if (interface == "usb0") {
       
   422             QString dir = QSystemNetworkInfoLinuxCommonPrivate::interfaceForMode(mode).name();
       
   423             QString devFile = baseSysDir + dir;
       
   424             QFileInfo fi(devFile + "/address");
       
   425             if(fi.exists()) {
       
   426                 QFile rx(fi.absoluteFilePath());
       
   427                 if(rx.exists() && rx.open(QIODevice::ReadOnly | QIODevice::Text)) {
       
   428                     QTextStream stream(&rx);
       
   429                     stream >> address;
       
   430                     rx.close();
       
   431                     return address;
       
   432                     break;
       
   433                 }
       
   434             }
       
   435         }
       
   436         return QSystemNetworkInfoLinuxCommonPrivate::macAddress(mode);
       
   437         break;
       
   438     }
       
   439     default:
       
   440         return QSystemNetworkInfoLinuxCommonPrivate::macAddress(mode);
       
   441         break;
       
   442     };
       
   443     return QString();
       
   444 }
       
   445 
       
   446 QNetworkInterface QSystemNetworkInfoPrivate::interfaceForMode(QSystemNetworkInfo::NetworkMode mode)
       
   447 {
       
   448 #if !defined(QT_NO_DBUS)
       
   449     switch(mode) {
       
   450     case QSystemNetworkInfo::CdmaMode:
       
   451     case QSystemNetworkInfo::GsmMode:
       
   452     case QSystemNetworkInfo::WcdmaMode:
       
   453     case QSystemNetworkInfo::WimaxMode:
       
   454         break;
       
   455     default:
       
   456         return QSystemNetworkInfoLinuxCommonPrivate::interfaceForMode(mode);
       
   457         break;
       
   458     };
       
   459 #endif
       
   460     return QNetworkInterface();
       
   461 }
       
   462 
       
   463 void QSystemNetworkInfoPrivate::setupNetworkInfo()
       
   464 {
       
   465     currentCellNetworkStatus = -1;
       
   466     currentBluetoothNetworkStatus = networkStatus(QSystemNetworkInfo::BluetoothMode);
       
   467     currentEthernetState = "down";
       
   468     currentEthernetSignalStrength = networkSignalStrength(QSystemNetworkInfo::EthernetMode);
       
   469     currentWlanSignalStrength = networkSignalStrength(QSystemNetworkInfo::WlanMode);
       
   470     currentLac = -1;
       
   471     currentCellId = -1;
       
   472     currentMCC = "";
       
   473     currentMNC = "";
       
   474     cellSignalStrength = 0;
       
   475     currentOperatorName = "";
       
   476     radioAccessTechnology = 0;
       
   477     iWlanStrengthCheckEnabled = 0;
       
   478     wlanSignalStrengthTimer = new QTimer(this);
       
   479 
       
   480     connect(wlanSignalStrengthTimer, SIGNAL(timeout()), this, SLOT(wlanSignalStrengthCheck()));
       
   481 
       
   482     QString devFile = "/sys/class/net/usb0/operstate";
       
   483     QFileInfo fi(devFile);
       
   484     if (fi.exists()) {
       
   485         QFile rx(fi.absoluteFilePath());
       
   486         if (rx.exists() && rx.open(QIODevice::ReadOnly | QIODevice::Text)) {
       
   487             QTextStream stream(&rx);
       
   488             stream >> currentEthernetState;
       
   489             rx.close();
       
   490         }
       
   491     }
       
   492 #if !defined(QT_NO_DBUS)
       
   493     QDBusConnection systemDbusConnection = QDBusConnection::systemBus();
       
   494 
       
   495     #if defined(Q_WS_MAEMO_6)
       
   496         const QString service = "com.nokia.csd.CSNet";
       
   497         const QString servicePath = "/com/nokia/csd/csnet";
       
   498 
       
   499         /* CSD: network cell */
       
   500         QDBusInterface ifc(service, servicePath, "com.nokia.csd.CSNet.NetworkCell", systemDbusConnection);
       
   501 
       
   502         QVariant cellLac = ifc.property("CellLac");
       
   503         currentLac = cellLac.isValid() ? cellLac.value<int>() : -1;
       
   504 
       
   505         QVariant cellId = ifc.property("CellId");
       
   506         currentCellId =  cellId.isValid() ? cellId.value<int>() : -1;
       
   507 
       
   508         QVariant cellType = ifc.property("CellType");
       
   509         QString currentCellType = cellType.isValid() ? cellType.value<QString>() : "";
       
   510 
       
   511         if (currentCellType == "GSM")
       
   512             radioAccessTechnology = 1;
       
   513         else if (currentCellType == "WCDMA")
       
   514             radioAccessTechnology = 2;
       
   515 
       
   516         /* CSD: network operator */
       
   517         QDBusInterface ifc2(service, servicePath, "com.nokia.csd.CSNet.NetworkOperator", systemDbusConnection);
       
   518 
       
   519         QVariant mcc = ifc2.property("OperatorMCC");
       
   520         currentMCC = mcc.isValid() ? mcc.value<QString>() : "";
       
   521 
       
   522         QVariant mnc = ifc2.property("OperatorMNC");
       
   523         currentMNC = mnc.isValid() ? mnc.value<QString>() : "";
       
   524 
       
   525         QVariant operatorName = ifc2.property("OperatorName");
       
   526         currentOperatorName = operatorName.isValid() ? operatorName.value<QString>() : "";
       
   527 
       
   528         /* CSD: signal strength */
       
   529         QDBusInterface ifc3(service, servicePath, "com.nokia.csd.CSNet.SignalStrength", systemDbusConnection);
       
   530 
       
   531         QVariant signalStrength = ifc3.property("SignalPercent");
       
   532         cellSignalStrength = signalStrength.isValid() ? signalStrength.value<int>() : -1;
       
   533 
       
   534         /* CSD: network registration */
       
   535         QDBusInterface ifc4(service, servicePath, "com.nokia.csd.CSNet.NetworkRegistration", systemDbusConnection);
       
   536 
       
   537         QVariant registrationStatus = ifc4.property("RegistrationStatus");
       
   538         QString status = registrationStatus.isValid() ? registrationStatus.value<QString>() : "";
       
   539 
       
   540         currentCellNetworkStatus = csStatusMaemo6.value(status, -1);
       
   541 
       
   542         /* Signal handlers */
       
   543         if (!systemDbusConnection.connect(service, servicePath, "com.nokia.csd.CSNet.SignalStrength", "SignalStrengthChanged",
       
   544                                          this, SLOT(slotSignalStrengthChanged(int, int)))) {
       
   545             qDebug() << "unable to connect SignalStrengthChanged";
       
   546         }
       
   547         if (!systemDbusConnection.connect(service, servicePath, "com.nokia.csd.CSNet.NetworkOperator", "OperatorChanged",
       
   548                                          this, SLOT(slotOperatorChanged(const QString&,const QString&)))) {
       
   549             qDebug() << "unable to connect (OperatorChanged";
       
   550         }
       
   551         if (!systemDbusConnection.connect(service, servicePath, "com.nokia.csd.CSNet.NetworkOperator", "OperatorNameChanged",
       
   552                                          this, SLOT(slotOperatorNameChanged(const QString&)))) {
       
   553             qDebug() << "unable to connect OperatorNameChanged";
       
   554         }
       
   555         if (!systemDbusConnection.connect(service, servicePath, "com.nokia.csd.CSNet.NetworkRegistration", "RegistrationChanged",
       
   556                                          this, SLOT(slotRegistrationChanged(const QString&)))) {
       
   557             qDebug() << "unable to connect RegistrationChanged";
       
   558         }
       
   559         if (!systemDbusConnection.connect(service, servicePath, "com.nokia.csd.CSNet.NetworkCell", "CellChanged",
       
   560                                          this, SLOT(slotCellChanged(const QString&,int,int)))) {
       
   561             qDebug() << "unable to connect CellChanged";
       
   562         }
       
   563     #else
       
   564     /* Maemo 5 */
       
   565     QDBusInterface connectionInterface("com.nokia.phone.net",
       
   566                                        "/com/nokia/phone/net",
       
   567                                        "Phone.Net",
       
   568                                        systemDbusConnection);
       
   569     if (!connectionInterface.isValid()) {
       
   570         qWarning() << "setupNetworkInfo(): interface not valid";
       
   571         return;
       
   572     }
       
   573     QDBusMessage reply = connectionInterface.call(QLatin1String("get_registration_status"));
       
   574     if (reply.type() == QDBusMessage::ReplyMessage) {
       
   575         QList<QVariant> argList = reply.arguments();
       
   576         currentCellNetworkStatus = argList.at(STATUS_INDEX).toInt();
       
   577         currentLac = argList.at(LAC_INDEX).value<ushort>();
       
   578         currentCellId = argList.at(CELLID_INDEX).value<uint>();
       
   579         currentMCC.setNum(argList.at(MCC_INDEX).value<uint>());
       
   580         currentMNC.setNum(argList.at(MNC_INDEX).value<uint>());
       
   581     } else {
       
   582         qWarning() << reply.errorMessage();
       
   583     }
       
   584     if (!systemDbusConnection.connect("com.nokia.phone.net",
       
   585                        "/com/nokia/phone/net",
       
   586                        "Phone.Net",
       
   587                        "registration_status_change",
       
   588                        this, SLOT(registrationStatusChanged(uchar,ushort,uint,uint,uint,uchar,uchar)))) {
       
   589         qWarning() << "unable to connect to registration_status_change";
       
   590     }
       
   591     reply = connectionInterface.call(QLatin1String("get_signal_strength"));
       
   592     if (reply.type() == QDBusMessage::ReplyMessage) {
       
   593         QList<QVariant> argList = reply.arguments();
       
   594         cellSignalStrength = argList.at(0).toInt();
       
   595     } else {
       
   596         qWarning() << reply.errorMessage();
       
   597     }
       
   598     if (!systemDbusConnection.connect("com.nokia.phone.net",
       
   599                        "/com/nokia/phone/net",
       
   600                        "Phone.Net",
       
   601                        "signal_strength_change",
       
   602                        this, SLOT(cellNetworkSignalStrengthChanged(uchar,uchar)))) {
       
   603         qWarning() << "unable to connect to signal_strength_change";
       
   604     }
       
   605     uchar type = 0;
       
   606     QList<QVariant> argumentList;
       
   607     argumentList << qVariantFromValue(type) << qVariantFromValue(currentMNC.toUInt()) << qVariantFromValue(currentMCC.toUInt());
       
   608     reply = connectionInterface.callWithArgumentList(QDBus::Block, QLatin1String("get_operator_name"), argumentList);
       
   609 
       
   610     if (reply.type() == QDBusMessage::ReplyMessage) {
       
   611         QList<QVariant> argList = reply.arguments();
       
   612         currentOperatorName = argList.at(0).toString();
       
   613     } else {
       
   614         qWarning() << reply.errorMessage();
       
   615     }
       
   616     if (!systemDbusConnection.connect("com.nokia.phone.net",
       
   617                        "/com/nokia/phone/net",
       
   618                        "Phone.Net",
       
   619                        "operator_name_change",
       
   620                        this, SLOT(operatorNameChanged(uchar,QString,QString,uint,uint)))) {
       
   621         qWarning() << "unable to connect to operator_name_change";
       
   622     }
       
   623 
       
   624     reply = connectionInterface.call(QLatin1String("get_radio_access_technology"));
       
   625     if (reply.type() == QDBusMessage::ReplyMessage) {
       
   626         QList<QVariant> argList = reply.arguments();
       
   627         radioAccessTechnology = argList.at(0).toInt();
       
   628     } else {
       
   629         qWarning() << reply.errorMessage();
       
   630     }
       
   631     if (!systemDbusConnection.connect("com.nokia.phone.net",
       
   632                        "/com/nokia/phone/net",
       
   633                        "Phone.Net",
       
   634                        "radio_access_technology_change",
       
   635                        this, SLOT(networkModeChanged(int)))) {
       
   636         qWarning() << "unable to connect to radio_access_technology_change";
       
   637     }   
       
   638     if(!systemDbusConnection.connect("com.nokia.icd",
       
   639                               "/com/nokia/icd",
       
   640                               "com.nokia.icd",
       
   641                               QLatin1String("status_changed"),
       
   642                               this, SLOT(icdStatusChanged(QString,QString,QString,QString))) ) {
       
   643         qWarning() << "unable to connect to icdStatusChanged";
       
   644     }
       
   645     #endif /* Maemo 5 */
       
   646 
       
   647     if(!systemDbusConnection.connect("com.nokia.bme",
       
   648                               "/com/nokia/bme/signal",
       
   649                               "com.nokia.bme.signal",
       
   650                               QLatin1String("charger_connected"),
       
   651                               this, SLOT(usbCableAction())) ) {
       
   652         qWarning() << "unable to connect to usbCableAction (connect)";
       
   653     }
       
   654     if(!systemDbusConnection.connect("com.nokia.bme",
       
   655                               "/com/nokia/bme/signal",
       
   656                               "com.nokia.bme.signal",
       
   657                               QLatin1String("charger_disconnected"),
       
   658                               this, SLOT(usbCableAction())) ) {
       
   659         qWarning() << "unable to connect to usbCableAction (disconnect)";
       
   660     }
       
   661     if(!systemDbusConnection.connect("org.freedesktop.Hal",
       
   662                               "/org/freedesktop/Hal/Manager",
       
   663                               "org.freedesktop.Hal.Manager",
       
   664                               QLatin1String("DeviceAdded"),
       
   665                               this, SLOT(bluetoothNetworkStatusCheck())) ) {
       
   666         qWarning() << "unable to connect to bluetoothNetworkStatusCheck (1)";
       
   667     }
       
   668     if(!systemDbusConnection.connect("org.freedesktop.Hal",
       
   669                               "/org/freedesktop/Hal/Manager",
       
   670                               "org.freedesktop.Hal.Manager",
       
   671                               QLatin1String("DeviceRemoved"),
       
   672                               this, SLOT(bluetoothNetworkStatusCheck())) ) {
       
   673         qWarning() << "unable to connect to bluetoothNetworkStatusCheck (2)";
       
   674     }
       
   675 #endif
       
   676 }
       
   677 
       
   678 #if defined(Q_WS_MAEMO_6)
       
   679 // Slots only available in Maemo6
       
   680 
       
   681 void QSystemNetworkInfoPrivate::slotSignalStrengthChanged(int percent, int /*dbm*/)
       
   682 {
       
   683     QSystemNetworkInfo::NetworkMode mode = QSystemNetworkInfo::UnknownMode;
       
   684     cellSignalStrength = percent;
       
   685 
       
   686     if (radioAccessTechnology == 1)
       
   687         mode = QSystemNetworkInfo::GsmMode;
       
   688     if (radioAccessTechnology == 2)
       
   689         mode = QSystemNetworkInfo::WcdmaMode;
       
   690 
       
   691     if (mode != QSystemNetworkInfo::UnknownMode)
       
   692         emit networkSignalStrengthChanged(mode, cellSignalStrength);
       
   693 }
       
   694 
       
   695 void QSystemNetworkInfoPrivate::slotOperatorChanged(const QString &mnc, const QString &mcc)
       
   696 {
       
   697     if (currentMCC != mcc) {
       
   698         currentMCC = mcc;
       
   699         emit currentMobileCountryCodeChanged(currentMCC);
       
   700     }
       
   701     if (currentMNC != mnc) {
       
   702         currentMNC = mnc;
       
   703         emit currentMobileNetworkCodeChanged(currentMNC);
       
   704     }
       
   705 }
       
   706 
       
   707 void QSystemNetworkInfoPrivate::slotOperatorNameChanged(const QString &name)
       
   708 {
       
   709     currentOperatorName = name;
       
   710     if (radioAccessTechnology == 1)
       
   711         emit networkNameChanged(QSystemNetworkInfo::GsmMode, currentOperatorName);
       
   712     if (radioAccessTechnology == 2)
       
   713         emit networkNameChanged(QSystemNetworkInfo::WcdmaMode, currentOperatorName);
       
   714 }
       
   715 
       
   716 void QSystemNetworkInfoPrivate::slotRegistrationChanged(const QString &status)
       
   717 {
       
   718     int newCellNetworkStatus = csStatusMaemo6.value(status, -1);
       
   719 
       
   720     if (currentCellNetworkStatus != newCellNetworkStatus) {
       
   721         currentCellNetworkStatus = newCellNetworkStatus;
       
   722         if (radioAccessTechnology == 1)
       
   723             emit networkStatusChanged(QSystemNetworkInfo::GsmMode,
       
   724                                       networkStatus(QSystemNetworkInfo::GsmMode));
       
   725         if (radioAccessTechnology == 2)
       
   726             emit networkStatusChanged(QSystemNetworkInfo::WcdmaMode,
       
   727                                       networkStatus(QSystemNetworkInfo::WcdmaMode));
       
   728     }
       
   729 }
       
   730 
       
   731 void QSystemNetworkInfoPrivate::slotCellChanged(const QString &type, int id, int lac)
       
   732 {
       
   733     QSystemNetworkInfo::NetworkMode mode = QSystemNetworkInfo::UnknownMode;
       
   734     int newRadioAccessTechnology = 0;
       
   735     if (type == "GSM") {
       
   736         mode = QSystemNetworkInfo::GsmMode;
       
   737         newRadioAccessTechnology = 1;
       
   738     } else if (type == "WCDMA") {
       
   739         mode = QSystemNetworkInfo::WcdmaMode;
       
   740         newRadioAccessTechnology = 2;
       
   741     }
       
   742 
       
   743     if (newRadioAccessTechnology != radioAccessTechnology) {
       
   744         radioAccessTechnology = newRadioAccessTechnology;
       
   745         emit networkModeChanged(mode);
       
   746     }
       
   747     if (currentCellId != id) {
       
   748         currentCellId = id;
       
   749     }
       
   750     if (currentLac != lac) {
       
   751         currentLac = lac;
       
   752     }
       
   753 }
       
   754 
       
   755 #endif /* Maemo 6 */
       
   756 
       
   757 #if defined(Q_WS_MAEMO_5)
       
   758 // Slots only available in Maemo5
       
   759 
       
   760 void QSystemNetworkInfoPrivate::cellNetworkSignalStrengthChanged(uchar var1, uchar)
       
   761 {
       
   762     QSystemNetworkInfo::NetworkMode mode = QSystemNetworkInfo::UnknownMode;
       
   763     cellSignalStrength = var1;
       
   764 
       
   765     if (radioAccessTechnology == 1)
       
   766         mode = QSystemNetworkInfo::GsmMode;
       
   767     if (radioAccessTechnology == 2)
       
   768         mode = QSystemNetworkInfo::WcdmaMode;
       
   769 
       
   770     if (mode != QSystemNetworkInfo::UnknownMode)
       
   771         emit networkSignalStrengthChanged(mode, cellSignalStrength);
       
   772 }
       
   773 
       
   774 void QSystemNetworkInfoPrivate::networkModeChanged(int newRadioAccessTechnology)
       
   775 {
       
   776     QSystemNetworkInfo::NetworkMode newMode = QSystemNetworkInfo::UnknownMode;
       
   777     radioAccessTechnology = newRadioAccessTechnology;
       
   778 
       
   779     if (radioAccessTechnology == 1)
       
   780         newMode = QSystemNetworkInfo::GsmMode;
       
   781     if (radioAccessTechnology == 2)
       
   782         newMode = QSystemNetworkInfo::WcdmaMode;
       
   783 
       
   784     if (newMode != QSystemNetworkInfo::UnknownMode)
       
   785         emit networkModeChanged(newMode);
       
   786 }
       
   787 
       
   788 void QSystemNetworkInfoPrivate::operatorNameChanged(uchar, QString name, QString, uint, uint)
       
   789 {
       
   790     currentOperatorName = name;
       
   791     if (radioAccessTechnology == 1)
       
   792         emit networkNameChanged(QSystemNetworkInfo::GsmMode, currentOperatorName);
       
   793     if (radioAccessTechnology == 2)
       
   794         emit networkNameChanged(QSystemNetworkInfo::WcdmaMode, currentOperatorName);
       
   795 }
       
   796 
       
   797 void QSystemNetworkInfoPrivate::registrationStatusChanged(uchar var1, ushort var2, uint var3, uint var4, uint var5, uchar, uchar)
       
   798 {
       
   799     int newCellNetworkStatus = var1;
       
   800     int newLac = var2;
       
   801     int newCellId = var3;
       
   802     QString newMobileCountryCode;
       
   803     QString newMobileNetworkCode;
       
   804     newMobileCountryCode.setNum(var4);
       
   805     newMobileNetworkCode.setNum(var5);
       
   806 
       
   807     if (currentCellNetworkStatus != newCellNetworkStatus) {
       
   808         currentCellNetworkStatus = newCellNetworkStatus;
       
   809         if (radioAccessTechnology == 1)
       
   810             emit networkStatusChanged(QSystemNetworkInfo::GsmMode,
       
   811                                       networkStatus(QSystemNetworkInfo::GsmMode));
       
   812         if (radioAccessTechnology == 2)
       
   813             emit networkStatusChanged(QSystemNetworkInfo::WcdmaMode,
       
   814                                       networkStatus(QSystemNetworkInfo::WcdmaMode));
       
   815     }
       
   816     if (currentLac != newLac) {
       
   817         currentLac = newLac;
       
   818     }
       
   819     if (currentCellId != newCellId) {
       
   820         currentCellId = newCellId;
       
   821     }
       
   822     if (currentMCC != newMobileCountryCode) {
       
   823         currentMCC = newMobileCountryCode;
       
   824         emit currentMobileCountryCodeChanged(currentMCC);
       
   825     }
       
   826     if (currentMNC != newMobileNetworkCode) {
       
   827         currentMNC = newMobileNetworkCode;
       
   828         emit currentMobileNetworkCodeChanged(currentMNC);
       
   829     }
       
   830 }
       
   831 
       
   832 void QSystemNetworkInfoPrivate::icdStatusChanged(QString, QString var2, QString, QString)
       
   833 {
       
   834     if (var2 == "WLAN_INFRA") {
       
   835         emit networkStatusChanged(QSystemNetworkInfo::WlanMode,
       
   836                                   networkStatus(QSystemNetworkInfo::WlanMode));
       
   837     }
       
   838 }
       
   839 
       
   840 #endif /* Maemo 5 */
       
   841 
       
   842 void QSystemNetworkInfoPrivate::usbCableAction()
       
   843 {
       
   844     if (currentEthernetSignalStrength != networkSignalStrength(QSystemNetworkInfo::EthernetMode)) {
       
   845         currentEthernetSignalStrength = networkSignalStrength(QSystemNetworkInfo::EthernetMode);
       
   846         emit networkSignalStrengthChanged(QSystemNetworkInfo::EthernetMode,
       
   847                                   currentEthernetSignalStrength);
       
   848     }
       
   849     QString newEthernetState;
       
   850     QString devFile = "/sys/class/net/usb0/operstate";
       
   851     QFileInfo fi(devFile);
       
   852     if (fi.exists()) {
       
   853         QFile rx(fi.absoluteFilePath());
       
   854         if (rx.exists() && rx.open(QIODevice::ReadOnly | QIODevice::Text)) {
       
   855             QTextStream stream(&rx);
       
   856             stream >> newEthernetState;
       
   857             rx.close();
       
   858             if (currentEthernetState != newEthernetState) {
       
   859                 currentEthernetState = newEthernetState;
       
   860                 emit networkStatusChanged(QSystemNetworkInfo::EthernetMode,
       
   861                                           networkStatus(QSystemNetworkInfo::EthernetMode));
       
   862             }
       
   863         }
       
   864     }
       
   865 }
       
   866 
       
   867 QSystemNetworkInfo::NetworkMode QSystemNetworkInfoPrivate::currentMode()
       
   868 {
       
   869     if (radioAccessTechnology == 1)
       
   870         return QSystemNetworkInfo::GsmMode;
       
   871     if (radioAccessTechnology == 2)
       
   872         return QSystemNetworkInfo::WcdmaMode;
       
   873 
       
   874     return QSystemNetworkInfo::UnknownMode;
       
   875 }
       
   876 
       
   877 void QSystemNetworkInfoPrivate::wlanSignalStrengthCheck()
       
   878 {
       
   879     if (currentWlanSignalStrength != networkSignalStrength(QSystemNetworkInfo::WlanMode)) {
       
   880         currentWlanSignalStrength = networkSignalStrength(QSystemNetworkInfo::WlanMode);
       
   881         emit networkSignalStrengthChanged(QSystemNetworkInfo::WlanMode, currentWlanSignalStrength);
       
   882     }
       
   883 }
       
   884 
       
   885 void QSystemNetworkInfoPrivate::bluetoothNetworkStatusCheck()
       
   886 {
       
   887     if (currentBluetoothNetworkStatus != networkStatus(QSystemNetworkInfo::BluetoothMode)) {
       
   888         currentBluetoothNetworkStatus = networkStatus(QSystemNetworkInfo::BluetoothMode);
       
   889         emit networkStatusChanged(QSystemNetworkInfo::BluetoothMode, currentBluetoothNetworkStatus);
       
   890     }
       
   891 }
       
   892 
       
   893 
       
   894 void QSystemNetworkInfoPrivate::setWlanSignalStrengthCheckEnabled(bool enabled)
       
   895 {
       
   896     if (enabled) {
       
   897         iWlanStrengthCheckEnabled++;
       
   898         if (!wlanSignalStrengthTimer->isActive())
       
   899             wlanSignalStrengthTimer->start(5000); //5 seconds interval
       
   900     } else {
       
   901         iWlanStrengthCheckEnabled--;
       
   902         if (iWlanStrengthCheckEnabled <= 0) {
       
   903             if(wlanSignalStrengthTimer->isActive())
       
   904                 wlanSignalStrengthTimer->stop();
       
   905         }
       
   906     }
       
   907 }
       
   908 
       
   909 QSystemDisplayInfoPrivate::QSystemDisplayInfoPrivate(QSystemDisplayInfoLinuxCommonPrivate *parent)
       
   910         : QSystemDisplayInfoLinuxCommonPrivate(parent)
       
   911 {
       
   912 }
       
   913 
       
   914 QSystemDisplayInfoPrivate::~QSystemDisplayInfoPrivate()
       
   915 {
       
   916 }
       
   917 
       
   918 int QSystemDisplayInfoPrivate::displayBrightness(int screen)
       
   919 {
       
   920     Q_UNUSED(screen);
       
   921     GConfItem currentBrightness("/system/osso/dsm/display/display_brightness");
       
   922     GConfItem maxBrightness("/system/osso/dsm/display/max_display_brightness_levels");
       
   923     if(maxBrightness.value().toInt()) {
       
   924         float retVal = 100 * (currentBrightness.value().toFloat() /
       
   925                               maxBrightness.value().toFloat());
       
   926         return retVal;
       
   927     }
       
   928 
       
   929     return -1;
       
   930 }
       
   931 
       
   932 QSystemStorageInfoPrivate::QSystemStorageInfoPrivate(QSystemStorageInfoLinuxCommonPrivate *parent)
       
   933         : QSystemStorageInfoLinuxCommonPrivate(parent)
       
   934 {
       
   935 }
       
   936 
       
   937 QSystemStorageInfoPrivate::~QSystemStorageInfoPrivate()
       
   938 {
       
   939 }
       
   940 
       
   941 QSystemDeviceInfoPrivate::QSystemDeviceInfoPrivate(QSystemDeviceInfoLinuxCommonPrivate *parent)
       
   942         : QSystemDeviceInfoLinuxCommonPrivate(parent)
       
   943 {
       
   944     setConnection();
       
   945     flightMode = false;
       
   946  #if !defined(QT_NO_DBUS)
       
   947     previousPowerState = QSystemDeviceInfo::UnknownPower;
       
   948     setupBluetooth();
       
   949     setupProfile();
       
   950 #endif
       
   951 }
       
   952 
       
   953 QSystemDeviceInfoPrivate::~QSystemDeviceInfoPrivate()
       
   954 {
       
   955 }
       
   956 
       
   957 #if !defined(QT_NO_DBUS)
       
   958 void QSystemDeviceInfoPrivate::halChanged(int,QVariantList map)
       
   959 {
       
   960     for(int i=0; i < map.count(); i++) {
       
   961 //       qWarning() << __FUNCTION__ << map.at(i).toString();
       
   962        if(map.at(i).toString() == "battery.charge_level.percentage") {
       
   963             int level = batteryLevel();
       
   964             emit batteryLevelChanged(level);
       
   965             if(level < 4) {
       
   966                 emit batteryStatusChanged(QSystemDeviceInfo::BatteryCritical);
       
   967             } else if(level < 11) {
       
   968                 emit batteryStatusChanged(QSystemDeviceInfo::BatteryVeryLow);
       
   969             } else if(level < 41) {
       
   970                 emit batteryStatusChanged(QSystemDeviceInfo::BatteryLow);
       
   971             } else if(level > 40) {
       
   972                 emit batteryStatusChanged(QSystemDeviceInfo::BatteryNormal);
       
   973             }
       
   974             else {
       
   975                 emit batteryStatusChanged(QSystemDeviceInfo::NoBatteryLevel);
       
   976             }
       
   977         }
       
   978         if((map.at(i).toString() == "maemo.charger.connection_status")
       
   979         || (map.at(i).toString() == "maemo.rechargeable.charging_status")) {
       
   980             QSystemDeviceInfo::PowerState state = currentPowerState();
       
   981             if (previousPowerState != state)
       
   982                 emit powerStateChanged(state);
       
   983             previousPowerState = state;
       
   984        }} //end map
       
   985 }
       
   986 #endif
       
   987 
       
   988 QSystemDeviceInfo::Profile QSystemDeviceInfoPrivate::currentProfile()
       
   989 {
       
   990 #if !defined(QT_NO_DBUS)
       
   991     if (flightMode)
       
   992         return QSystemDeviceInfo::OfflineProfile;
       
   993 
       
   994     if (silentProfile )
       
   995         return vibratingAlertEnabled ? QSystemDeviceInfo::VibProfile : QSystemDeviceInfo::SilentProfile;
       
   996 
       
   997     if (ringingAlertVolume > 75)
       
   998         return QSystemDeviceInfo::LoudProfile;
       
   999 
       
  1000     return QSystemDeviceInfo::NormalProfile;
       
  1001 #endif
       
  1002 
       
  1003     return QSystemDeviceInfo::UnknownProfile;
       
  1004 }
       
  1005 
       
  1006 QString QSystemDeviceInfoPrivate::imei()
       
  1007 {
       
  1008 #if !defined(QT_NO_DBUS)
       
  1009     #if defined(Q_WS_MAEMO_6)
       
  1010         QString dBusService = "com.nokia.csd.Info";
       
  1011     #else
       
  1012         /* Maemo 5 */
       
  1013         QString dBusService = "com.nokia.phone.SIM";
       
  1014     #endif
       
  1015     QDBusInterface connectionInterface(dBusService,
       
  1016                                        "/com/nokia/csd/info",
       
  1017                                        "com.nokia.csd.Info",
       
  1018                                         QDBusConnection::systemBus());
       
  1019     QDBusReply< QString > reply = connectionInterface.call("GetIMEINumber");
       
  1020     return reply.value();
       
  1021 #endif
       
  1022     return "";
       
  1023 }
       
  1024 
       
  1025 QString QSystemDeviceInfoPrivate::imsi()
       
  1026 {
       
  1027 #if defined(Q_WS_MAEMO_6)
       
  1028     /* Maemo 6 */
       
  1029     #if !defined(QT_NO_DBUS)
       
  1030         QDBusInterface connectionInterface("com.nokia.csd.SIM",
       
  1031                                            "/com/nokia/csd/sim",
       
  1032                                            "com.nokia.csd.SIM.Identity",
       
  1033                                            QDBusConnection::systemBus());
       
  1034         QDBusReply< QString > reply = connectionInterface.call("GetIMSI");
       
  1035         return reply.value();
       
  1036     #endif
       
  1037     return "";
       
  1038 #else
       
  1039     /* Maemo 5 */
       
  1040     return GConfItem("/system/nokia/location/sim_imsi").value().toString();
       
  1041 #endif
       
  1042 }
       
  1043 
       
  1044 QSystemDeviceInfo::SimStatus QSystemDeviceInfoPrivate::simStatus()
       
  1045 {
       
  1046     QSystemDeviceInfo::SimStatus simStatus = QSystemDeviceInfo::SimNotAvailable;
       
  1047     QString imsi = QSystemDeviceInfoPrivate::imsi();
       
  1048     if (imsi.length() > 0) {
       
  1049         simStatus = QSystemDeviceInfo::SingleSimAvailable;
       
  1050     }
       
  1051     return simStatus;
       
  1052 }
       
  1053 
       
  1054 bool QSystemDeviceInfoPrivate::isDeviceLocked()
       
  1055 {
       
  1056 #if !defined(QT_NO_DBUS)
       
  1057     QDBusConnection systemDbusConnection = QDBusConnection::systemBus();
       
  1058 
       
  1059     QDBusInterface mceConnectionInterface("com.nokia.mce",
       
  1060                                       "/com/nokia/mce/request",
       
  1061                                       "com.nokia.mce.request",
       
  1062                                       systemDbusConnection);
       
  1063     if (mceConnectionInterface.isValid()) {
       
  1064         QDBusReply<QString> tkLockModeReply = mceConnectionInterface.call("get_tklock_mode");
       
  1065         return tkLockModeReply.value() == "locked";
       
  1066     }
       
  1067 
       
  1068     qWarning() << "mce interface not valid";
       
  1069 #endif
       
  1070     return false;
       
  1071 }
       
  1072 
       
  1073 QSystemDeviceInfo::PowerState QSystemDeviceInfoPrivate::currentPowerState()
       
  1074 {
       
  1075 #if !defined(QT_NO_DBUS)
       
  1076         QHalInterface iface;
       
  1077         const QStringList list = iface.findDeviceByCapability("battery");
       
  1078         if(!list.isEmpty()) {
       
  1079             foreach(const QString dev, list) {
       
  1080                 QHalDeviceInterface ifaceDevice(dev);
       
  1081                 if (iface.isValid()) {
       
  1082                     if (ifaceDevice.getPropertyString("maemo.charger.connection_status") == "connected") {
       
  1083                         if (ifaceDevice.getPropertyString("maemo.rechargeable.charging_status") == "full")
       
  1084                             return QSystemDeviceInfo::WallPower;
       
  1085                         return QSystemDeviceInfo::WallPowerChargingBattery;
       
  1086                     }
       
  1087                     return QSystemDeviceInfo::BatteryPower;
       
  1088                 }
       
  1089             }
       
  1090         }
       
  1091 #endif
       
  1092     return QSystemDeviceInfo::UnknownPower;
       
  1093 }
       
  1094 
       
  1095 #if !defined(QT_NO_DBUS)
       
  1096  void QSystemDeviceInfoPrivate::setupBluetooth()
       
  1097  {
       
  1098      QDBusConnection dbusConnection = QDBusConnection::systemBus();
       
  1099      QDBusInterface *connectionInterface;
       
  1100      connectionInterface = new QDBusInterface("org.bluez",
       
  1101                                               "/",
       
  1102                                               "org.bluez.Manager",
       
  1103                                               dbusConnection);
       
  1104      if (connectionInterface->isValid()) {
       
  1105 
       
  1106          QDBusReply<  QDBusObjectPath > reply = connectionInterface->call("DefaultAdapter");
       
  1107          if (reply.isValid()) {
       
  1108              QDBusInterface *adapterInterface;
       
  1109              adapterInterface = new QDBusInterface("org.bluez",
       
  1110                                                    reply.value().path(),
       
  1111                                                    "org.bluez.Adapter",
       
  1112                                                    dbusConnection);
       
  1113              if (adapterInterface->isValid()) {
       
  1114                  if (!dbusConnection.connect("org.bluez",
       
  1115                                            reply.value().path(),
       
  1116                                             "org.bluez.Adapter",
       
  1117                                             "PropertyChanged",
       
  1118                                             this,SLOT(bluezPropertyChanged(QString, QDBusVariant)))) {
       
  1119                      qWarning() << "bluez could not connect signal";
       
  1120                  }
       
  1121              }
       
  1122          }
       
  1123      }
       
  1124  }
       
  1125 #endif
       
  1126 
       
  1127 #if !defined(QT_NO_DBUS)
       
  1128  void QSystemDeviceInfoPrivate::bluezPropertyChanged(const QString &str, QDBusVariant v)
       
  1129  {
       
  1130      //qWarning() << str << v.variant().toBool();
       
  1131      emit bluetoothStateChanged(v.variant().toBool());
       
  1132  }
       
  1133 #endif
       
  1134 
       
  1135 #if !defined(QT_NO_DBUS)
       
  1136 
       
  1137 void QSystemDeviceInfoPrivate::setupProfile()
       
  1138 {
       
  1139     QDBusConnection systemDbusConnection = QDBusConnection::systemBus();
       
  1140 
       
  1141     QDBusInterface mceConnectionInterface("com.nokia.mce",
       
  1142                                       "/com/nokia/mce/request",
       
  1143                                       "com.nokia.mce.request",
       
  1144                                       systemDbusConnection);
       
  1145     if (!mceConnectionInterface.isValid()) {
       
  1146         qWarning() << "mce interface not valid";
       
  1147         return;
       
  1148     } else {
       
  1149         QDBusReply<QString> deviceModeReply = mceConnectionInterface.call("get_device_mode");
       
  1150         flightMode = deviceModeReply.value() == "flight";
       
  1151     }
       
  1152 
       
  1153     if (!systemDbusConnection.connect("com.nokia.mce",
       
  1154                            "/com/nokia/mce/signal",
       
  1155                            "com.nokia.mce.signal",
       
  1156                            "sig_device_mode_ind",
       
  1157                            this, SLOT(deviceModeChanged(QString)))) {
       
  1158         qWarning() << "unable to connect to sig_device_mode_ind";
       
  1159     }
       
  1160 
       
  1161 
       
  1162     QDBusInterface connectionInterface("com.nokia.profiled",
       
  1163                                       "/com/nokia/profiled",
       
  1164                                       "com.nokia.profiled",
       
  1165                                       QDBusConnection::sessionBus());
       
  1166     if(!connectionInterface.isValid()) {
       
  1167        qWarning() << "profiled interface not valid";
       
  1168        return;
       
  1169     }
       
  1170 
       
  1171     QDBusReply<QString> profileNameReply = connectionInterface.call("get_profile");
       
  1172     if (profileNameReply.isValid())
       
  1173         profileName = profileNameReply.value();
       
  1174 
       
  1175     QDBusReply<QString> ringingAlertTypeReply = connectionInterface.call("get_value", profileName, "ringing.alert.type");
       
  1176     if (ringingAlertTypeReply.isValid())
       
  1177         silentProfile = ringingAlertTypeReply.value() == "silent";
       
  1178 
       
  1179     QDBusReply<QString> vibratingAlertEnabledReply = connectionInterface.call("get_value", profileName, "vibrating.alert.enabled");
       
  1180     if (vibratingAlertEnabledReply.isValid())
       
  1181         vibratingAlertEnabled = vibratingAlertEnabledReply.value() == "On";
       
  1182 
       
  1183     QDBusReply<QString> ringingAlertVolumeReply = connectionInterface.call("get_value", profileName, "ringing.alert.volume");
       
  1184     if (ringingAlertVolumeReply.isValid())
       
  1185         ringingAlertVolume = ringingAlertVolumeReply.value().toInt();
       
  1186 
       
  1187     qDBusRegisterMetaType<ProfileDataValue>();
       
  1188     qDBusRegisterMetaType<QList<ProfileDataValue> >();
       
  1189 
       
  1190     QDBusConnection sessionDbusConnection = QDBusConnection::sessionBus();
       
  1191     if (!sessionDbusConnection.connect("com.nokia.profiled",
       
  1192                            "/com/nokia/profiled",
       
  1193                            "com.nokia.profiled",
       
  1194                            "profile_changed",
       
  1195                            this, SLOT(profileChanged(bool, bool, QString, QList<ProfileDataValue>)))) {
       
  1196         qWarning() << "unable to connect to profile_changed";
       
  1197     }
       
  1198 
       
  1199 }
       
  1200 
       
  1201 void QSystemDeviceInfoPrivate::deviceModeChanged(QString newMode)
       
  1202 {
       
  1203     bool previousFlightMode = flightMode;
       
  1204     flightMode = newMode == "flight";
       
  1205     if (previousFlightMode != flightMode)
       
  1206         emit currentProfileChanged(currentProfile());
       
  1207 }
       
  1208 
       
  1209 void QSystemDeviceInfoPrivate::profileChanged(bool changed, bool active, QString profile, QList<ProfileDataValue> values)
       
  1210 {
       
  1211     if (active) {
       
  1212         const QSystemDeviceInfo::Profile previousProfile = currentProfile();
       
  1213         profileName = profile;
       
  1214         foreach (const ProfileDataValue value, values) {
       
  1215             if (value.key == "ringing.alert.type")
       
  1216                 silentProfile = value.val == "silent";
       
  1217             else if (value.key == "vibrating.alert.enabled")
       
  1218                 vibratingAlertEnabled = value.val == "On";
       
  1219             else if (value.key == "ringing.alert.volume")
       
  1220                 ringingAlertVolume = value.val.toInt();
       
  1221         }
       
  1222         QSystemDeviceInfo::Profile newProfile = currentProfile();
       
  1223         if (previousProfile != newProfile)
       
  1224            emit currentProfileChanged(newProfile);
       
  1225     }
       
  1226 }
       
  1227 
       
  1228 #endif
       
  1229 
       
  1230 //////////////
       
  1231 ///////
       
  1232 QSystemScreenSaverPrivate::QSystemScreenSaverPrivate(QObject *parent)
       
  1233         : QSystemScreenSaverLinuxCommonPrivate(parent)
       
  1234 {
       
  1235     ssTimer = new QTimer(this);
       
  1236 #if !defined(QT_NO_DBUS)
       
  1237     mceConnectionInterface = new QDBusInterface("com.nokia.mce",
       
  1238                                                 "/com/nokia/mce/request",
       
  1239                                                 "com.nokia.mce.request",
       
  1240                                                 QDBusConnection::systemBus());
       
  1241 #endif
       
  1242 }
       
  1243 
       
  1244 QSystemScreenSaverPrivate::~QSystemScreenSaverPrivate()
       
  1245 {
       
  1246     if (ssTimer->isActive()) {
       
  1247         ssTimer->stop();
       
  1248     }
       
  1249 #if !defined(QT_NO_DBUS)
       
  1250     delete mceConnectionInterface, mceConnectionInterface = 0;
       
  1251 #endif
       
  1252 }
       
  1253 
       
  1254 bool QSystemScreenSaverPrivate::setScreenSaverInhibit()
       
  1255 {
       
  1256     wakeUpDisplay();
       
  1257     if (!ssTimer->isActive()) {
       
  1258         connect(ssTimer, SIGNAL(timeout()), this, SLOT(wakeUpDisplay()));
       
  1259         // Set a wake up interval of 30 seconds.
       
  1260         // The reason for this is to avoid the situation where
       
  1261         // a crashed/hung application keeps the display on.
       
  1262         ssTimer->start(30000);
       
  1263      }
       
  1264      return screenSaverInhibited();
       
  1265 }
       
  1266 
       
  1267 void QSystemScreenSaverPrivate::wakeUpDisplay()
       
  1268 {
       
  1269 #if !defined(QT_NO_DBUS)
       
  1270     if (mceConnectionInterface->isValid()) {
       
  1271         mceConnectionInterface->call("req_tklock_mode_change", "unlocked");
       
  1272         mceConnectionInterface->call("req_display_blanking_pause");
       
  1273     }
       
  1274 #endif
       
  1275 }
       
  1276 
       
  1277 bool QSystemScreenSaverPrivate::screenSaverInhibited()
       
  1278 {
       
  1279     bool displayOn = false;
       
  1280 #if !defined(QT_NO_DBUS)
       
  1281     if (mceConnectionInterface->isValid()) {
       
  1282         // The most educated guess for the screen saver being inhibited is to determine
       
  1283         // whether the display is on. That is because the QSystemScreenSaver cannot
       
  1284         // prevent other processes from blanking the screen (like, if
       
  1285         // MCE decides to blank the screen for some reason).
       
  1286         QDBusReply<QString> reply = mceConnectionInterface->call("get_display_status");
       
  1287         displayOn = ("on" == reply.value());
       
  1288     }
       
  1289 #endif
       
  1290     return displayOn;
       
  1291 }
       
  1292 
       
  1293 #include "moc_qsysteminfo_maemo_p.cpp"
       
  1294 
       
  1295 QTM_END_NAMESPACE