qtmobility/src/systeminfo/qsysteminfo_maemo.cpp
changeset 1 2b40d63a9c3d
child 4 90517678cc4f
equal deleted inserted replaced
0:cfcbf08528c4 1:2b40d63a9c3d
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 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.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     QStringList locales = languagesItem.value().toStringList();
       
   105 
       
   106     foreach(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             GConfItem locationValues("/system/nokia/location");
       
   152             QStringList locationKeys = locationValues.listEntries();
       
   153 
       
   154             foreach (QString str, locationKeys) {
       
   155                 if (str.contains("sim_imsi"))
       
   156                     featureSupported = true;
       
   157                 break;
       
   158             }
       
   159         }
       
   160         break;
       
   161     case QSystemInfo::LocationFeature :
       
   162         {
       
   163             GConfItem locationValues("/system/nokia/location");
       
   164             QStringList locationKeys = locationValues.listEntries();
       
   165             if(locationKeys.count()) {
       
   166                 featureSupported = true;
       
   167             }
       
   168         }
       
   169         break;
       
   170     case QSystemInfo::VideoOutFeature :
       
   171         {
       
   172             QString sysPath = "/sys/class/video4linux/";
       
   173             QDir sysDir(sysPath);
       
   174             QStringList filters;
       
   175             filters << "*";
       
   176             QStringList sysList = sysDir.entryList( filters ,QDir::Dirs, QDir::Name);
       
   177             if(sysList.contains("video0")) {
       
   178                 featureSupported = true;
       
   179             }
       
   180         }
       
   181         break;
       
   182     case QSystemInfo::HapticsFeature:
       
   183         {
       
   184            // if(halIsAvailable) {
       
   185                 QHalInterface iface;
       
   186                 QStringList touchSupport =
       
   187                         iface.findDeviceByCapability("input.touchpad");
       
   188                 if(touchSupport.count()) {
       
   189                     featureSupported = true;
       
   190                 } else {
       
   191                     featureSupported = false;
       
   192                 }
       
   193             }
       
   194       //  }
       
   195         break;
       
   196     default:
       
   197         featureSupported = QSystemInfoLinuxCommonPrivate::hasFeatureSupported(feature);
       
   198         break;
       
   199     };
       
   200     return featureSupported;
       
   201 }
       
   202 
       
   203 QSystemNetworkInfoPrivate::QSystemNetworkInfoPrivate(QSystemNetworkInfoLinuxCommonPrivate *parent)
       
   204         : QSystemNetworkInfoLinuxCommonPrivate(parent)
       
   205 {
       
   206 }
       
   207 
       
   208 QSystemNetworkInfoPrivate::~QSystemNetworkInfoPrivate()
       
   209 {
       
   210 }
       
   211 
       
   212 
       
   213 QSystemNetworkInfo::NetworkStatus QSystemNetworkInfoPrivate::networkStatus(QSystemNetworkInfo::NetworkMode mode)
       
   214 {
       
   215     qWarning() << __PRETTY_FUNCTION__ << mode;
       
   216 
       
   217     switch(mode) {
       
   218     case QSystemNetworkInfo::GsmMode:
       
   219     case QSystemNetworkInfo::CdmaMode:
       
   220     case QSystemNetworkInfo::WcdmaMode:
       
   221         {
       
   222             qWarning() << __FUNCTION__<< "GSM" << mode;
       
   223 //#if 0
       
   224 //#if !defined(QT_NO_DBUS)
       
   225 //            QDBusInterface connectionInterface("com.nokia.phone.net",
       
   226 //                                               "/com/nokia/phone/net",
       
   227 //                                               "com.nokia.SystemInfo",
       
   228 //                                                QDBusConnection::systemBus());
       
   229 //            if(!connectionInterface.isValid()) {
       
   230 //                qWarning() << "interfacenot valid";
       
   231 //            }
       
   232 //            QDBusReply< QByteArray > reply = connectionInterface.call("GetConfigValue", "/device/sw-release-ver");
       
   233 //            return reply.value();
       
   234 //#endif
       
   235 //#endif
       
   236         }
       
   237         break;
       
   238     case QSystemNetworkInfo::EthernetMode:
       
   239     case QSystemNetworkInfo::WlanMode:
       
   240     case QSystemNetworkInfo::BluetoothMode:
       
   241         {
       
   242             return QSystemNetworkInfoLinuxCommonPrivate::networkStatus(mode);
       
   243         }
       
   244         break;
       
   245     };
       
   246     return QSystemNetworkInfo::UndefinedStatus;
       
   247 }
       
   248 
       
   249 int QSystemNetworkInfoPrivate::networkSignalStrength(QSystemNetworkInfo::NetworkMode mode)
       
   250 {
       
   251     switch(mode) {
       
   252     case QSystemNetworkInfo::GsmMode:
       
   253     case QSystemNetworkInfo::CdmaMode:
       
   254     case QSystemNetworkInfo::WcdmaMode:
       
   255         break;
       
   256     case QSystemNetworkInfo::EthernetMode:
       
   257     case QSystemNetworkInfo::WlanMode:
       
   258     case QSystemNetworkInfo::BluetoothMode:
       
   259         return QSystemNetworkInfoLinuxCommonPrivate::networkSignalStrength(mode);
       
   260         break;
       
   261     };
       
   262 
       
   263     return -1;
       
   264 }
       
   265 
       
   266 int QSystemNetworkInfoPrivate::cellId()
       
   267 {
       
   268     return -1;
       
   269 }
       
   270 
       
   271 int QSystemNetworkInfoPrivate::locationAreaCode()
       
   272 {
       
   273     return -1;
       
   274 }
       
   275 
       
   276 QString QSystemNetworkInfoPrivate::currentMobileCountryCode()
       
   277 {
       
   278     return QString();
       
   279 }
       
   280 
       
   281 QString QSystemNetworkInfoPrivate::currentMobileNetworkCode()
       
   282 {
       
   283     return QString();
       
   284 }
       
   285 
       
   286 QString QSystemNetworkInfoPrivate::homeMobileCountryCode()
       
   287 {
       
   288     return QString();
       
   289 }
       
   290 
       
   291 QString QSystemNetworkInfoPrivate::homeMobileNetworkCode()
       
   292 {
       
   293     return QString();
       
   294 }
       
   295 
       
   296 QString QSystemNetworkInfoPrivate::networkName(QSystemNetworkInfo::NetworkMode mode)
       
   297 {
       
   298     QString netname = "";
       
   299 
       
   300     switch(mode) {
       
   301 
       
   302     case QSystemNetworkInfo::CdmaMode:
       
   303     case QSystemNetworkInfo::GsmMode:
       
   304     case QSystemNetworkInfo::WcdmaMode:
       
   305     case QSystemNetworkInfo::WimaxMode:
       
   306         break;
       
   307         break;
       
   308     default:
       
   309         return QSystemNetworkInfoLinuxCommonPrivate::networkName(mode);
       
   310         break;
       
   311     };
       
   312     return netname;
       
   313 }
       
   314 
       
   315 QString QSystemNetworkInfoPrivate::macAddress(QSystemNetworkInfo::NetworkMode mode)
       
   316 {
       
   317     switch(mode) {
       
   318 
       
   319     case QSystemNetworkInfo::CdmaMode:
       
   320     case QSystemNetworkInfo::GsmMode:
       
   321     case QSystemNetworkInfo::WcdmaMode:
       
   322     case QSystemNetworkInfo::WimaxMode:
       
   323         break;
       
   324     default:
       
   325         return QSystemNetworkInfoLinuxCommonPrivate::networkName(mode);
       
   326         break;
       
   327     };
       
   328     return QString();
       
   329 }
       
   330 
       
   331 QNetworkInterface QSystemNetworkInfoPrivate::interfaceForMode(QSystemNetworkInfo::NetworkMode mode)
       
   332 {
       
   333 #if !defined(QT_NO_DBUS)
       
   334     switch(mode) {
       
   335     case QSystemNetworkInfo::CdmaMode:
       
   336     case QSystemNetworkInfo::GsmMode:
       
   337     case QSystemNetworkInfo::WcdmaMode:
       
   338     case QSystemNetworkInfo::WimaxMode:
       
   339         break;
       
   340     default:
       
   341         return QSystemNetworkInfoLinuxCommonPrivate::interfaceForMode(mode);
       
   342         break;
       
   343     };
       
   344 #endif
       
   345     return QNetworkInterface();
       
   346 }
       
   347 
       
   348 QSystemDisplayInfoPrivate::QSystemDisplayInfoPrivate(QSystemDisplayInfoLinuxCommonPrivate *parent)
       
   349         : QSystemDisplayInfoLinuxCommonPrivate(parent)
       
   350 {
       
   351 }
       
   352 
       
   353 QSystemDisplayInfoPrivate::~QSystemDisplayInfoPrivate()
       
   354 {
       
   355 }
       
   356 
       
   357 int QSystemDisplayInfoPrivate::displayBrightness(int screen)
       
   358 {
       
   359     Q_UNUSED(screen);
       
   360     GConfItem currentBrightness("/system/osso/dsm/display/display_brightness");
       
   361     GConfItem maxBrightness("/system/osso/dsm/display/max_display_brightness_levels");
       
   362     if(maxBrightness.value().toInt()) {
       
   363         float retVal = 100 * (currentBrightness.value().toFloat() /
       
   364                               maxBrightness.value().toFloat());
       
   365         return retVal;
       
   366     }
       
   367 
       
   368     return -1;
       
   369 }
       
   370 
       
   371 QSystemStorageInfoPrivate::QSystemStorageInfoPrivate(QSystemStorageInfoLinuxCommonPrivate *parent)
       
   372         : QSystemStorageInfoLinuxCommonPrivate(parent)
       
   373 {
       
   374 }
       
   375 
       
   376 QSystemStorageInfoPrivate::~QSystemStorageInfoPrivate()
       
   377 {
       
   378 }
       
   379 
       
   380 QSystemDeviceInfoPrivate::QSystemDeviceInfoPrivate(QSystemDeviceInfoLinuxCommonPrivate *parent)
       
   381         : QSystemDeviceInfoLinuxCommonPrivate(parent)
       
   382 {
       
   383     setConnection();
       
   384     flightMode = false;
       
   385  #if !defined(QT_NO_DBUS)
       
   386     previousPowerState = QSystemDeviceInfo::UnknownPower;
       
   387     setupBluetooth();
       
   388     setupProfile();
       
   389 #endif
       
   390 }
       
   391 
       
   392 QSystemDeviceInfoPrivate::~QSystemDeviceInfoPrivate()
       
   393 {
       
   394 }
       
   395 
       
   396 #if !defined(QT_NO_DBUS)
       
   397 void QSystemDeviceInfoPrivate::halChanged(int,QVariantList map)
       
   398 {
       
   399     for(int i=0; i < map.count(); i++) {
       
   400 //       qWarning() << __FUNCTION__ << map.at(i).toString();
       
   401        if(map.at(i).toString() == "battery.charge_level.percentage") {
       
   402             int level = batteryLevel();
       
   403             emit batteryLevelChanged(level);
       
   404             if(level < 4) {
       
   405                 emit batteryStatusChanged(QSystemDeviceInfo::BatteryCritical);
       
   406             } else if(level < 11) {
       
   407                 emit batteryStatusChanged(QSystemDeviceInfo::BatteryVeryLow);
       
   408             } else if(level < 41) {
       
   409                 emit batteryStatusChanged(QSystemDeviceInfo::BatteryLow);
       
   410             } else if(level > 40) {
       
   411                 emit batteryStatusChanged(QSystemDeviceInfo::BatteryNormal);
       
   412             }
       
   413             else {
       
   414                 emit batteryStatusChanged(QSystemDeviceInfo::NoBatteryLevel);
       
   415             }
       
   416         }
       
   417         if((map.at(i).toString() == "maemo.charger.connection_status")
       
   418         || (map.at(i).toString() == "maemo.rechargeable.charging_status")) {
       
   419             QSystemDeviceInfo::PowerState state = currentPowerState();
       
   420             if (previousPowerState != state)
       
   421                 emit powerStateChanged(state);
       
   422             previousPowerState = state;
       
   423        }} //end map
       
   424 }
       
   425 #endif
       
   426 
       
   427 QSystemDeviceInfo::Profile QSystemDeviceInfoPrivate::currentProfile()
       
   428 {
       
   429 #if !defined(QT_NO_DBUS)
       
   430     if (flightMode)
       
   431         return QSystemDeviceInfo::OfflineProfile;
       
   432 
       
   433     if (silentProfile )
       
   434         return vibratingAlertEnabled ? QSystemDeviceInfo::VibProfile : QSystemDeviceInfo::SilentProfile;
       
   435 
       
   436     if (ringingAlertVolume > 75)
       
   437         return QSystemDeviceInfo::LoudProfile;
       
   438 
       
   439     return QSystemDeviceInfo::NormalProfile;
       
   440 #endif
       
   441 
       
   442     return QSystemDeviceInfo::UnknownProfile;
       
   443 }
       
   444 
       
   445 QString QSystemDeviceInfoPrivate::imei()
       
   446 {
       
   447  #if !defined(QT_NO_DBUS)
       
   448     QDBusInterface connectionInterface("com.nokia.phone.SIM",
       
   449                                        "/com/nokia/csd/info",
       
   450                                        "com.nokia.csd.Info",
       
   451                                         QDBusConnection::systemBus());
       
   452     if(!connectionInterface.isValid()) {
       
   453         qWarning() << "interfacenot valid";
       
   454     }
       
   455 
       
   456     QDBusReply< QString > reply = connectionInterface.call("GetIMEINumber");
       
   457     return reply.value();
       
   458 
       
   459 #endif
       
   460         return "Not Available";
       
   461 }
       
   462 
       
   463 QString QSystemDeviceInfoPrivate::imsi()
       
   464 {
       
   465     return GConfItem("/system/nokia/location/sim_imsi").value().toString();
       
   466 }
       
   467 
       
   468 QSystemDeviceInfo::SimStatus QSystemDeviceInfoPrivate::simStatus()
       
   469 {
       
   470     GConfItem locationValues("/system/nokia/location");
       
   471     QStringList locationKeys = locationValues.listEntries();
       
   472     QStringList result;
       
   473     int count = 0;
       
   474     foreach (QString str, locationKeys) {
       
   475         if (str.contains("sim_imsi"))
       
   476             count++;
       
   477     }
       
   478 
       
   479     if(count == 1) {
       
   480         return QSystemDeviceInfo::SingleSimAvailable;
       
   481     } else if (count == 2) {
       
   482         return QSystemDeviceInfo::DualSimAvailable;
       
   483     }
       
   484     return QSystemDeviceInfo::SimNotAvailable;
       
   485 }
       
   486 
       
   487 bool QSystemDeviceInfoPrivate::isDeviceLocked()
       
   488 {
       
   489 #if !defined(QT_NO_DBUS)
       
   490     QDBusConnection systemDbusConnection = QDBusConnection::systemBus();
       
   491 
       
   492     QDBusInterface mceConnectionInterface("com.nokia.mce",
       
   493                                       "/com/nokia/mce/request",
       
   494                                       "com.nokia.mce.request",
       
   495                                       systemDbusConnection);
       
   496     if (mceConnectionInterface.isValid()) {
       
   497         QDBusReply<QString> tkLockModeReply = mceConnectionInterface.call("get_tklock_mode");
       
   498         return tkLockModeReply.value() == "locked";
       
   499     }
       
   500 
       
   501     qWarning() << "mce interface not valid";
       
   502 #endif
       
   503     return false;
       
   504 }
       
   505 
       
   506 QSystemDeviceInfo::PowerState QSystemDeviceInfoPrivate::currentPowerState()
       
   507 {
       
   508 #if !defined(QT_NO_DBUS)
       
   509         QHalInterface iface;
       
   510         QStringList list = iface.findDeviceByCapability("battery");
       
   511         if(!list.isEmpty()) {
       
   512             foreach(QString dev, list) {
       
   513                 QHalDeviceInterface ifaceDevice(dev);
       
   514                 if (iface.isValid()) {
       
   515                     if (ifaceDevice.getPropertyString("maemo.charger.connection_status") == "connected") {
       
   516                         if (ifaceDevice.getPropertyString("maemo.rechargeable.charging_status") == "full")
       
   517                             return QSystemDeviceInfo::WallPower;
       
   518                         return QSystemDeviceInfo::WallPowerChargingBattery;
       
   519                     }
       
   520                     return QSystemDeviceInfo::BatteryPower;
       
   521                 }
       
   522             }
       
   523         }
       
   524 #endif
       
   525     return QSystemDeviceInfo::UnknownPower;
       
   526 }
       
   527 
       
   528 #if !defined(QT_NO_DBUS)
       
   529  void QSystemDeviceInfoPrivate::setupBluetooth()
       
   530  {
       
   531      QDBusConnection dbusConnection = QDBusConnection::systemBus();
       
   532      QDBusInterface *connectionInterface;
       
   533      connectionInterface = new QDBusInterface("org.bluez",
       
   534                                               "/",
       
   535                                               "org.bluez.Manager",
       
   536                                               dbusConnection);
       
   537      if (connectionInterface->isValid()) {
       
   538 
       
   539          QDBusReply<  QDBusObjectPath > reply = connectionInterface->call("DefaultAdapter");
       
   540          if (reply.isValid()) {
       
   541              QDBusInterface *adapterInterface;
       
   542              adapterInterface = new QDBusInterface("org.bluez",
       
   543                                                    reply.value().path(),
       
   544                                                    "org.bluez.Adapter",
       
   545                                                    dbusConnection);
       
   546              if (adapterInterface->isValid()) {
       
   547                  if (!dbusConnection.connect("org.bluez",
       
   548                                            reply.value().path(),
       
   549                                             "org.bluez.Adapter",
       
   550                                             "PropertyChanged",
       
   551                                             this,SLOT(bluezPropertyChanged(QString, QDBusVariant)))) {
       
   552                      qWarning() << "bluez could not connect signal";
       
   553                  }
       
   554              }
       
   555          }
       
   556      }
       
   557  }
       
   558 #endif
       
   559 
       
   560 #if !defined(QT_NO_DBUS)
       
   561  void QSystemDeviceInfoPrivate::bluezPropertyChanged(const QString &str, QDBusVariant v)
       
   562  {
       
   563      qWarning() << str << v.variant().toBool();
       
   564      emit bluetoothStateChanged(v.variant().toBool());
       
   565  }
       
   566 #endif
       
   567 
       
   568 #if !defined(QT_NO_DBUS)
       
   569 
       
   570 void QSystemDeviceInfoPrivate::setupProfile()
       
   571 {
       
   572     QDBusConnection systemDbusConnection = QDBusConnection::systemBus();
       
   573 
       
   574     QDBusInterface mceConnectionInterface("com.nokia.mce",
       
   575                                       "/com/nokia/mce/request",
       
   576                                       "com.nokia.mce.request",
       
   577                                       systemDbusConnection);
       
   578     if (!mceConnectionInterface.isValid()) {
       
   579         qWarning() << "mce interface not valid";
       
   580         return;
       
   581     } else {
       
   582         QDBusReply<QString> deviceModeReply = mceConnectionInterface.call("get_device_mode");
       
   583         flightMode = deviceModeReply.value() == "flight";
       
   584     }
       
   585 
       
   586     if (!systemDbusConnection.connect("com.nokia.mce",
       
   587                            "/com/nokia/mce/signal",
       
   588                            "com.nokia.mce.signal",
       
   589                            "sig_device_mode_ind",
       
   590                            this, SLOT(deviceModeChanged(QString)))) {
       
   591         qWarning() << "unable to connect to sig_device_mode_ind";
       
   592     }
       
   593 
       
   594 
       
   595     QDBusInterface connectionInterface("com.nokia.profiled",
       
   596                                       "/com/nokia/profiled",
       
   597                                       "com.nokia.profiled",
       
   598                                       QDBusConnection::sessionBus());
       
   599     if(!connectionInterface.isValid()) {
       
   600        qWarning() << "profiled interface not valid";
       
   601        return;
       
   602     }
       
   603 
       
   604     QDBusReply<QString> profileNameReply = connectionInterface.call("get_profile");
       
   605     if (profileNameReply.isValid())
       
   606         profileName = profileNameReply.value();
       
   607 
       
   608     QDBusReply<QString> ringingAlertTypeReply = connectionInterface.call("get_value", profileName, "ringing.alert.type");
       
   609     if (ringingAlertTypeReply.isValid())
       
   610         silentProfile = ringingAlertTypeReply.value() == "silent";
       
   611 
       
   612     QDBusReply<QString> vibratingAlertEnabledReply = connectionInterface.call("get_value", profileName, "vibrating.alert.enabled");
       
   613     if (vibratingAlertEnabledReply.isValid())
       
   614         vibratingAlertEnabled = vibratingAlertEnabledReply.value() == "On";
       
   615 
       
   616     QDBusReply<QString> ringingAlertVolumeReply = connectionInterface.call("get_value", profileName, "ringing.alert.volume");
       
   617     if (ringingAlertVolumeReply.isValid())
       
   618         ringingAlertVolume = ringingAlertVolumeReply.value().toInt();
       
   619 
       
   620     qDBusRegisterMetaType<ProfileDataValue>();
       
   621     qDBusRegisterMetaType<QList<ProfileDataValue> >();
       
   622 
       
   623     QDBusConnection sessionDbusConnection = QDBusConnection::sessionBus();
       
   624     if (!sessionDbusConnection.connect("com.nokia.profiled",
       
   625                            "/com/nokia/profiled",
       
   626                            "com.nokia.profiled",
       
   627                            "profile_changed",
       
   628                            this, SLOT(profileChanged(bool, bool, QString, QList<ProfileDataValue>)))) {
       
   629         qWarning() << "unable to connect to profile_changed";
       
   630     }
       
   631 
       
   632 }
       
   633 
       
   634 void QSystemDeviceInfoPrivate::deviceModeChanged(QString newMode)
       
   635 {
       
   636     bool previousFlightMode = flightMode;
       
   637     flightMode = newMode == "flight";
       
   638     if (previousFlightMode != flightMode)
       
   639         emit currentProfileChanged(currentProfile());
       
   640 }
       
   641 
       
   642 void QSystemDeviceInfoPrivate::profileChanged(bool changed, bool active, QString profile, QList<ProfileDataValue> values)
       
   643 {
       
   644     QSystemDeviceInfo::Profile previousProfile = currentProfile();
       
   645 
       
   646     profileName = profile;
       
   647     foreach (ProfileDataValue value, values) {
       
   648         if (value.key == "ringing.alert.type")
       
   649             silentProfile = value.val == "silent";
       
   650         else if (value.key == "vibrating.alert.enabled")
       
   651             vibratingAlertEnabled = value.val == "On";
       
   652         else if (value.key == "ringing.alert.volume")
       
   653             ringingAlertVolume = value.val.toInt();
       
   654     }
       
   655 
       
   656     QSystemDeviceInfo::Profile newProfile = currentProfile();
       
   657     if (previousProfile != newProfile)
       
   658         emit currentProfileChanged(newProfile);
       
   659 }
       
   660 
       
   661 #endif
       
   662 
       
   663 //////////////
       
   664 ///////
       
   665 QSystemScreenSaverPrivate::QSystemScreenSaverPrivate(QObject *parent)
       
   666         : QSystemScreenSaverLinuxCommonPrivate(parent), m_screenSaverInhibited(false)
       
   667 
       
   668 {
       
   669     ssTimer = new QTimer(this);
       
   670 }
       
   671 
       
   672 QSystemScreenSaverPrivate::~QSystemScreenSaverPrivate()
       
   673 {
       
   674      if(ssTimer->isActive())
       
   675          ssTimer->stop();
       
   676 
       
   677      m_screenSaverInhibited = false;
       
   678 }
       
   679 
       
   680 bool QSystemScreenSaverPrivate::screenSaverInhibited()
       
   681 {
       
   682     return m_screenSaverInhibited;
       
   683 }
       
   684 
       
   685 bool QSystemScreenSaverPrivate::setScreenSaverInhibit()
       
   686 {
       
   687     if (m_screenSaverInhibited)
       
   688         return true;
       
   689 
       
   690      m_screenSaverInhibited = true;
       
   691      display_blanking_pause();
       
   692      connect(ssTimer, SIGNAL(timeout()), this, SLOT(display_blanking_pause()));
       
   693      ssTimer->start(3000); //3 seconds interval
       
   694      return true;
       
   695 }
       
   696 
       
   697 void QSystemScreenSaverPrivate::display_blanking_pause()
       
   698 {
       
   699 #if !defined(QT_NO_DBUS)
       
   700     QDBusInterface connectionInterface("com.nokia.mce",
       
   701                                        "/com/nokia/mce/request",
       
   702                                        "com.nokia.mce.request",
       
   703                                        QDBusConnection::systemBus());
       
   704     if (!connectionInterface.isValid()) {
       
   705         qWarning() << "interface not valid";
       
   706         return;
       
   707     }
       
   708     connectionInterface.call("req_display_blanking_pause");
       
   709 #endif
       
   710 }
       
   711 
       
   712 bool QSystemScreenSaverPrivate::isScreenLockEnabled()
       
   713 {
       
   714    return false;
       
   715 }
       
   716 
       
   717 bool QSystemScreenSaverPrivate::isScreenSaverActive()
       
   718 {
       
   719     return false;
       
   720 }
       
   721 
       
   722 #include "moc_qsysteminfo_maemo_p.cpp"
       
   723 
       
   724 QTM_END_NAMESPACE