qtmobility/src/systeminfo/qsysteminfo_linux_common.cpp
changeset 4 90517678cc4f
parent 1 2b40d63a9c3d
child 5 453da2cfceef
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
   165 {
   165 {
   166      bool featureSupported = false;
   166      bool featureSupported = false;
   167      switch (feature) {
   167      switch (feature) {
   168      case QSystemInfo::BluetoothFeature :
   168      case QSystemInfo::BluetoothFeature :
   169          {
   169          {
   170              QString sysPath = "/sys/class/bluetooth/";
   170              const QString sysPath = "/sys/class/bluetooth/";
   171              QDir sysDir(sysPath);
   171              const QDir sysDir(sysPath);
   172              QStringList filters;
   172              QStringList filters;
   173              filters << "*";
   173              filters << "*";
   174              QStringList sysList = sysDir.entryList( filters ,QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
   174              const QStringList sysList = sysDir.entryList( filters ,QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
   175              foreach(QString dir, sysList) {
   175              foreach(const QString dir, sysList) {
   176                  QFileInfo btFile(sysPath + dir+"/address");
   176                  const QFileInfo btFile(sysPath + dir+"/address");
   177                  if(btFile.exists()) {
   177                  if(btFile.exists()) {
   178                      return true;
   178                      return true;
   179                  }
   179                  }
   180              }
   180              }
   181          }
   181          }
   190              featureSupported = hasSysFeature("video");
   190              featureSupported = hasSysFeature("video");
   191          }
   191          }
   192          break;
   192          break;
   193      case QSystemInfo::FmradioFeature :
   193      case QSystemInfo::FmradioFeature :
   194          {
   194          {
   195              QString sysPath = "/sys/class/video4linux/";
   195              const QString sysPath = "/sys/class/video4linux/";
   196              QDir sysDir(sysPath);
   196              const QDir sysDir(sysPath);
   197              QStringList filters;
   197              QStringList filters;
   198              filters << "*";
   198              filters << "*";
   199              QStringList sysList = sysDir.entryList( filters ,QDir::Dirs, QDir::Name);
   199              QStringList sysList = sysDir.entryList( filters ,QDir::Dirs, QDir::Name);
   200              if(sysList.contains("radio")) {
   200              foreach(const QString dir, sysList) {
   201                  featureSupported = true;
   201                 if (dir.contains("radio")) {
   202              }
   202                     featureSupported = true;
       
   203                 }
       
   204             }
   203          }
   205          }
   204          break;
   206          break;
   205      case QSystemInfo::IrFeature :
   207      case QSystemInfo::IrFeature :
   206          {
   208          {
   207  #if !defined(QT_NO_DBUS)
   209  #if !defined(QT_NO_DBUS)
   221          {
   223          {
   222  #if !defined(QT_NO_DBUS)
   224  #if !defined(QT_NO_DBUS)
   223              QHalInterface iface;
   225              QHalInterface iface;
   224              if (iface.isValid()) {
   226              if (iface.isValid()) {
   225                  QHalInterface halIface;
   227                  QHalInterface halIface;
   226                  QStringList halDevices = halIface.getAllDevices();
   228                  const QStringList halDevices = halIface.getAllDevices();
   227                  foreach(QString device, halDevices) {
   229                  foreach(const QString device, halDevices) {
   228                      QHalDeviceInterface ifaceDevice(device);
   230                      QHalDeviceInterface ifaceDevice(device);
   229                      if (ifaceDevice.isValid()) {
   231                      if (ifaceDevice.isValid()) {
   230                          if(ifaceDevice.getPropertyString("info.subsystem") == "mmc_host") {
   232                          if(ifaceDevice.getPropertyString("info.subsystem") == "mmc_host") {
   231                              return true;
   233                              return true;
   232                          }
   234                          }
   259      case QSystemInfo::WlanFeature :
   261      case QSystemInfo::WlanFeature :
   260          {
   262          {
   261  #if !defined(QT_NO_DBUS)
   263  #if !defined(QT_NO_DBUS)
   262              QHalInterface iface;
   264              QHalInterface iface;
   263              if (iface.isValid()) {
   265              if (iface.isValid()) {
   264                  QStringList list = iface.findDeviceByCapability("net.80211");
   266                  const QStringList list = iface.findDeviceByCapability("net.80211");
   265                  if(!list.isEmpty()) {
   267                  if(!list.isEmpty()) {
   266                      featureSupported = true;
   268                      featureSupported = true;
   267                      break;
   269                      break;
   268                  }
   270                  }
   269              }
   271              }
   281 
   283 
   282  #endif
   284  #endif
   283          break;
   285          break;
   284      case QSystemInfo::VideoOutFeature :
   286      case QSystemInfo::VideoOutFeature :
   285          {
   287          {
   286              QString sysPath = "/sys/class/video4linux/";
   288              const QString sysPath = "/sys/class/video4linux/";
   287              QDir sysDir(sysPath);
   289              const QDir sysDir(sysPath);
   288              QStringList filters;
   290              QStringList filters;
   289              filters << "*";
   291              filters << "*";
   290              QStringList sysList = sysDir.entryList( filters ,QDir::Dirs, QDir::Name);
   292              const QStringList sysList = sysDir.entryList( filters ,QDir::Dirs, QDir::Name);
   291              if(sysList.contains("video")) {
   293              if(sysList.contains("video")) {
   292                  featureSupported = true;
   294                  featureSupported = true;
   293              }
   295              }
   294          }
   296          }
   295          break;
   297          break;
   304 
   306 
   305  #if !defined(QT_NO_DBUS)
   307  #if !defined(QT_NO_DBUS)
   306  bool QSystemInfoLinuxCommonPrivate::hasHalDeviceFeature(const QString &param)
   308  bool QSystemInfoLinuxCommonPrivate::hasHalDeviceFeature(const QString &param)
   307  {
   309  {
   308      QHalInterface halIface;
   310      QHalInterface halIface;
   309      QStringList halDevices = halIface.getAllDevices();
   311      const QStringList halDevices = halIface.getAllDevices();
   310      foreach(QString device, halDevices) {
   312      foreach(const QString device, halDevices) {
   311          if(device.contains(param)) {
   313          if(device.contains(param)) {
   312              return true;
   314              return true;
   313          }
   315          }
   314      }
   316      }
   315      return false;
   317      return false;
   316  }
   318  }
   317 
   319 
   318  bool QSystemInfoLinuxCommonPrivate::hasHalUsbFeature(qint32 usbClass)
   320  bool QSystemInfoLinuxCommonPrivate::hasHalUsbFeature(qint32 usbClass)
   319  {
   321  {
   320      QHalInterface halIface;
   322      QHalInterface halIface;
   321      QStringList halDevices = halIface.getAllDevices();
   323      const QStringList halDevices = halIface.getAllDevices();
   322      foreach(QString device, halDevices) {
   324      foreach(const QString device, halDevices) {
   323          QHalDeviceInterface ifaceDevice(device);
   325          QHalDeviceInterface ifaceDevice(device);
   324          if (ifaceDevice.isValid()) {
   326          if (ifaceDevice.isValid()) {
   325              if(ifaceDevice.getPropertyString("info.subsystem") == "usb_device") {
   327              if(ifaceDevice.getPropertyString("info.subsystem") == "usb_device") {
   326                  if(ifaceDevice.getPropertyInt("usb.interface.class") == usbClass) {
   328                  if(ifaceDevice.getPropertyInt("usb.interface.class") == usbClass) {
   327                      return true;
   329                      return true;
   350                 if(!str.isEmpty()) {
   352                 if(!str.isEmpty()) {
   351                     return str;
   353                     return str;
   352                 }
   354                 }
   353             }
   355             }
   354 #endif
   356 #endif
   355             QString versionPath = QLatin1String("/proc/version");
   357             const QString versionPath = QLatin1String("/proc/version");
   356             QFile versionFile(versionPath);
   358             QFile versionFile(versionPath);
   357             if(!versionFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
   359             if(!versionFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
   358                 qWarning() << "File not opened";
   360                 qWarning() << "File not opened";
   359             } else {
   361             } else {
   360                 QString  strvalue;
   362                 QString  strvalue;
   379     return QLocale::system().name().mid(3,2);
   381     return QLocale::system().name().mid(3,2);
   380 }
   382 }
   381 
   383 
   382 bool QSystemInfoLinuxCommonPrivate::hasSysFeature(const QString &featureStr)
   384 bool QSystemInfoLinuxCommonPrivate::hasSysFeature(const QString &featureStr)
   383 {
   385 {
   384     QString sysPath = QLatin1String("/sys/class/");
   386     const QString sysPath = QLatin1String("/sys/class/");
   385     QDir sysDir(sysPath);
   387     const QDir sysDir(sysPath);
   386     QStringList filters;
   388     QStringList filters;
   387     filters << QLatin1String("*");
   389     filters << QLatin1String("*");
   388     QStringList sysList = sysDir.entryList( filters ,QDir::Dirs, QDir::Name);
   390     const QStringList sysList = sysDir.entryList( filters ,QDir::Dirs, QDir::Name);
   389     foreach(QString dir, sysList) {
   391     foreach(const QString dir, sysList) {
   390         QDir sysDir2(sysPath + dir);
   392         const QDir sysDir2(sysPath + dir);
   391         if(dir.contains(featureStr)) {
   393         if(dir.contains(featureStr)) {
   392             QStringList sysList2 = sysDir2.entryList( filters ,QDir::Dirs, QDir::Name);
   394             const QStringList sysList2 = sysDir2.entryList( filters ,QDir::Dirs, QDir::Name);
   393             if(!sysList2.isEmpty()) {
   395             if(!sysList2.isEmpty()) {
   394                 return true;
   396                 return true;
   395             }
   397             }
   396         }
   398         }
   397     }
   399     }
   398     return false;
   400     return false;
   399 }
   401 }
   400 
   402 
   401 QSystemNetworkInfoLinuxCommonPrivate::QSystemNetworkInfoLinuxCommonPrivate(QObject *parent) : QObject(parent)
   403 QSystemNetworkInfoLinuxCommonPrivate::QSystemNetworkInfoLinuxCommonPrivate(QObject *parent) : QObject(parent)
   402 {
   404 {
   403    // QTimer::singleShot(200, this,SLOT(getPrimaryMode()));
       
   404 }
   405 }
   405 
   406 
   406 QSystemNetworkInfoLinuxCommonPrivate::~QSystemNetworkInfoLinuxCommonPrivate()
   407 QSystemNetworkInfoLinuxCommonPrivate::~QSystemNetworkInfoLinuxCommonPrivate()
   407 {
   408 {
   408 }
   409 }
   409 
       
   410 //void QSystemNetworkInfoLinuxCommonPrivate::getPrimaryMode()
       
   411 //{
       
   412 //    // try to see if there are any default route
       
   413 ////    bool anyDefaultRoute = false;
       
   414 //
       
   415 //    QFileInfo fi("/proc/net/route");
       
   416 //    if(fi.exists()) {
       
   417 //        QFile rx(fi.absoluteFilePath());
       
   418 //        if(rx.exists() && rx.open(QIODevice::ReadOnly | QIODevice::Text)) {
       
   419 //            QString result;
       
   420 //            QTextStream out(&rx);
       
   421 //            do {
       
   422 //                result = out.readLine().simplified();
       
   423 //                if(!result.isEmpty()) {
       
   424 //                    QStringList tokens = result.split(" ");
       
   425 //
       
   426 //                    if(tokens.at(2).toLocal8Bit() != "Gateway"
       
   427 //                       && tokens.at(2).toLocal8Bit() != "00000000") {
       
   428 //
       
   429 //                        qWarning() <<"found default!" << tokens.at(0);
       
   430 //           //             emit networkModeChanged(tokens.at(0)));
       
   431 //                    }
       
   432 //                }
       
   433 //            } while (!result.isNull());
       
   434 //        }
       
   435 //    }
       
   436 //    //    QMapIterator<QString, QString> i(activePaths);
       
   437 ////    QString devicepath;
       
   438 ////    while (i.hasNext()) {
       
   439 ////        i.next();
       
   440 ////        QScopedPointer<QNetworkManagerConnectionActive> activeCon;
       
   441 ////        activeCon.reset(new QNetworkManagerConnectionActive(i.key()));
       
   442 ////
       
   443 ////        if(activeCon->defaultRoute()) {
       
   444 ////            anyDefaultRoute = activeCon->defaultRoute();
       
   445 ////            QNetworkManagerInterfaceDevice *devIface = new QNetworkManagerInterfaceDevice(i.value());
       
   446 ////            emit networkModeChanged(deviceTypeToMode(devIface->deviceType()));
       
   447 ////        }
       
   448 ////        devicepath = i.value();
       
   449 ////    }
       
   450 ////
       
   451 ////    if(!anyDefaultRoute) {
       
   452 ////        emit networkModeChanged(QSystemNetworkInfo::UnknownMode);
       
   453 ////    }
       
   454 //}
       
   455 
       
   456 QSystemNetworkInfo::NetworkStatus QSystemNetworkInfoLinuxCommonPrivate::networkStatus(QSystemNetworkInfo::NetworkMode mode)
   410 QSystemNetworkInfo::NetworkStatus QSystemNetworkInfoLinuxCommonPrivate::networkStatus(QSystemNetworkInfo::NetworkMode mode)
   457 {
   411 {
   458     switch(mode) {
   412     switch(mode) {
   459     case QSystemNetworkInfo::WlanMode:
   413     case QSystemNetworkInfo::WlanMode:
   460         {
   414         {
   461             qWarning() << __PRETTY_FUNCTION__ << "WLAN";
   415             const QString baseSysDir = "/sys/class/net/";
   462 
   416             const QDir wDir(baseSysDir);
   463             QString baseSysDir = "/sys/class/net/";
   417             const QStringList dirs = wDir.entryList(QStringList() << "*", QDir::AllDirs | QDir::NoDotAndDotDot);
   464             QDir wDir(baseSysDir);
   418             foreach(const QString dir, dirs) {
   465             QStringList dirs = wDir.entryList(QStringList() << "*", QDir::AllDirs | QDir::NoDotAndDotDot);
   419                 const QString devFile = baseSysDir + dir;
   466             foreach(QString dir, dirs) {
   420                 const QFileInfo wiFi(devFile + "/wireless");
   467                 QString devFile = baseSysDir + dir;
   421                 const QFileInfo fi("/proc/net/route");
   468                 QFileInfo wiFi(devFile + "/wireless");
       
   469                 QFileInfo fi("/proc/net/route");
       
   470                 if(wiFi.exists() && fi.exists()) {
   422                 if(wiFi.exists() && fi.exists()) {
   471                     QFile rx(fi.absoluteFilePath());
   423                     QFile rx(fi.absoluteFilePath());
   472                     if(rx.exists() && rx.open(QIODevice::ReadOnly | QIODevice::Text)) {
   424                     if(rx.exists() && rx.open(QIODevice::ReadOnly | QIODevice::Text)) {
   473                         QString result = rx.readAll();
   425                         const QString result = rx.readAll();
   474                         if(result.contains(dir)) {
   426                         if(result.contains(dir)) {
   475                             return QSystemNetworkInfo::Connected;
   427                             return QSystemNetworkInfo::Connected;
   476                         } else {
   428                         } else {
   477                             return QSystemNetworkInfo::NoNetworkAvailable;
   429                             return QSystemNetworkInfo::NoNetworkAvailable;
   478                         }
   430                         }
   481             }
   433             }
   482         }
   434         }
   483         break;
   435         break;
   484     case QSystemNetworkInfo::EthernetMode:
   436     case QSystemNetworkInfo::EthernetMode:
   485         {
   437         {
   486             qWarning() << __PRETTY_FUNCTION__ << "Ethernet";
   438             const QString baseSysDir = "/sys/class/net/";
   487             QString baseSysDir = "/sys/class/net/";
   439             const QDir eDir(baseSysDir);
   488             QDir eDir(baseSysDir);
   440             const QString dir = QSystemNetworkInfoLinuxCommonPrivate::interfaceForMode(mode).name();
   489             QString dir = QSystemNetworkInfoLinuxCommonPrivate::interfaceForMode(mode).name();
   441 
   490 
   442             const QString devFile = baseSysDir + dir;
   491             QString devFile = baseSysDir + dir;
   443             const QFileInfo fi("/proc/net/route");
   492             qWarning() << devFile;
       
   493             QFileInfo fi("/proc/net/route");
       
   494             if(fi.exists()) {
   444             if(fi.exists()) {
   495                 QFile rx(fi.absoluteFilePath());
   445                 QFile rx(fi.absoluteFilePath());
   496                 if(rx.exists() && rx.open(QIODevice::ReadOnly | QIODevice::Text)) {
   446                 if(rx.exists() && rx.open(QIODevice::ReadOnly | QIODevice::Text)) {
   497                     QString result = rx.readAll();
   447                     const QString result = rx.readAll();
   498                     if(result.contains(dir)) {
   448                     if(result.contains(dir)) {
   499                         return QSystemNetworkInfo::Connected;
   449                         return QSystemNetworkInfo::Connected;
   500                     } else {
   450                     } else {
   501                         return QSystemNetworkInfo::NoNetworkAvailable;
   451                         return QSystemNetworkInfo::NoNetworkAvailable;
   502                     }
   452                     }
   521 
   471 
   522     switch(mode) {
   472     switch(mode) {
   523     case QSystemNetworkInfo::WlanMode:
   473     case QSystemNetworkInfo::WlanMode:
   524         {
   474         {
   525             if(networkStatus(mode) != QSystemNetworkInfo::Connected) {
   475             if(networkStatus(mode) != QSystemNetworkInfo::Connected) {
   526                 qWarning() << "not connected";
       
   527                 return netname;
   476                 return netname;
   528             }
   477             }
   529 
   478 
   530             QString wlanInterface;
   479             QString wlanInterface;
   531             QString baseSysDir = "/sys/class/net/";
   480             const QString baseSysDir = "/sys/class/net/";
   532             QDir wDir(baseSysDir);
   481             const QDir wDir(baseSysDir);
   533             QStringList dirs = wDir.entryList(QStringList() << "*", QDir::AllDirs | QDir::NoDotAndDotDot);
   482             const QStringList dirs = wDir.entryList(QStringList() << "*", QDir::AllDirs | QDir::NoDotAndDotDot);
   534             foreach(QString dir, dirs) {
   483             foreach(const QString dir, dirs) {
   535                 QString devFile = baseSysDir + dir;
   484                 const QString devFile = baseSysDir + dir;
   536                 QFileInfo fi(devFile + "/wireless");
   485                 const QFileInfo fi(devFile + "/wireless");
   537                 if(fi.exists()) {
   486                 if(fi.exists()) {
   538                     wlanInterface = dir;
   487                     wlanInterface = dir;
   539                     qWarning() << "interface is" << wlanInterface;
       
   540                 }
   488                 }
   541             }
   489             }
   542             int sock = socket(PF_INET, SOCK_DGRAM, 0);
   490             int sock = socket(PF_INET, SOCK_DGRAM, 0);
   543             if (sock > 0) {
   491             if (sock > 0) {
   544                 const char* someRandomBuffer[IW_ESSID_MAX_SIZE + 1];
   492                 const char* someRandomBuffer[IW_ESSID_MAX_SIZE + 1];
   599 {
   547 {
   600     switch(mode) {
   548     switch(mode) {
   601         case QSystemNetworkInfo::WlanMode:
   549         case QSystemNetworkInfo::WlanMode:
   602         {
   550         {
   603             QString result;
   551             QString result;
   604             QString baseSysDir = "/sys/class/net/";
   552             const QString baseSysDir = "/sys/class/net/";
   605             QDir wDir(baseSysDir);
   553             const QDir wDir(baseSysDir);
   606             QStringList dirs = wDir.entryList(QStringList() << "*", QDir::AllDirs | QDir::NoDotAndDotDot);
   554             const QStringList dirs = wDir.entryList(QStringList() << "*", QDir::AllDirs | QDir::NoDotAndDotDot);
   607             foreach(QString dir, dirs) {
   555             foreach(const QString dir, dirs) {
   608                 QString devFile = baseSysDir + dir;
   556                 const QString devFile = baseSysDir + dir;
   609                 QFileInfo fi(devFile + "/wireless");
   557                 const QFileInfo fi(devFile + "/wireless");
   610                 if(fi.exists()) {
   558                 if(fi.exists()) {
   611                     QFile rx(devFile + "/address");
   559                     QFile rx(devFile + "/address");
   612                     if(rx.exists() && rx.open(QIODevice::ReadOnly | QIODevice::Text)) {
   560                     if(rx.exists() && rx.open(QIODevice::ReadOnly | QIODevice::Text)) {
   613                         QTextStream in(&rx);
   561                         QTextStream in(&rx);
   614                         in >> result;
   562                         in >> result;
   620         }
   568         }
   621         break;
   569         break;
   622         case QSystemNetworkInfo::EthernetMode:
   570         case QSystemNetworkInfo::EthernetMode:
   623         {
   571         {
   624             QString result;
   572             QString result;
   625             QString baseSysDir = "/sys/class/net/";
   573             const QString baseSysDir = "/sys/class/net/";
   626             QDir eDir(baseSysDir);
   574             const QDir eDir(baseSysDir);
   627             QStringList dirs = eDir.entryList(QStringList() << "eth*", QDir::AllDirs | QDir::NoDotAndDotDot);
   575             const QStringList dirs = eDir.entryList(QStringList() << "eth*", QDir::AllDirs | QDir::NoDotAndDotDot);
   628             foreach(QString dir, dirs) {
   576             foreach(const QString dir, dirs) {
   629                 QString devFile = baseSysDir + dir;
   577                 const QString devFile = baseSysDir + dir;
   630                 QFileInfo fi(devFile + "/address");
   578                 const QFileInfo fi(devFile + "/address");
   631                 if(fi.exists()) {
   579                 if(fi.exists()) {
   632                     QFile rx(fi.absoluteFilePath());
   580                     QFile rx(fi.absoluteFilePath());
   633                     if(rx.exists() && rx.open(QIODevice::ReadOnly | QIODevice::Text)) {
   581                     if(rx.exists() && rx.open(QIODevice::ReadOnly | QIODevice::Text)) {
   634                         QTextStream in(&rx);
   582                         QTextStream in(&rx);
   635                         in >> result;
   583                         in >> result;
   669 
   617 
   670     if (ioctl(ctl,BNEPGETCONNLIST,&req) < 0) {
   618     if (ioctl(ctl,BNEPGETCONNLIST,&req) < 0) {
   671         qWarning() << "Cannot get bnep connection list.";
   619         qWarning() << "Cannot get bnep connection list.";
   672         return QSystemNetworkInfo::UndefinedStatus;
   620         return QSystemNetworkInfo::UndefinedStatus;
   673     }
   621     }
   674 
       
   675     qWarning() << req.cnum;
       
   676     for (uint j = 0; j< req.cnum; j++) {
   622     for (uint j = 0; j< req.cnum; j++) {
   677         qWarning() << info[j].state;
       
   678         if(info[j].state == BT_CONNECTED) {
   623         if(info[j].state == BT_CONNECTED) {
   679             return QSystemNetworkInfo::Connected;
   624             return QSystemNetworkInfo::Connected;
   680         }
   625         }
   681     }
   626     }
   682     close(ctl);
   627     close(ctl);
   688 {
   633 {
   689     switch(mode) {
   634     switch(mode) {
   690     case QSystemNetworkInfo::WlanMode:
   635     case QSystemNetworkInfo::WlanMode:
   691         {
   636         {
   692             QString result;
   637             QString result;
   693             QString baseSysDir = "/sys/class/net/";
   638             const QString baseSysDir = "/sys/class/net/";
   694             QDir wDir(baseSysDir);
   639             const QDir wDir(baseSysDir);
   695             QStringList dirs = wDir.entryList(QStringList() << "*", QDir::AllDirs | QDir::NoDotAndDotDot);
   640             const QStringList dirs = wDir.entryList(QStringList() << "*", QDir::AllDirs | QDir::NoDotAndDotDot);
   696             foreach(QString dir, dirs) {
   641             foreach(const QString dir, dirs) {
   697                 QString devFile = baseSysDir + dir;
   642                 const QString devFile = baseSysDir + dir;
   698                 QFileInfo fi(devFile + "/wireless/link");
   643                 const QFileInfo fi(devFile + "/wireless/link");
   699                 if(fi.exists()) {
   644                 if(fi.exists()) {
   700                     QFile rx(fi.absoluteFilePath());
   645                     QFile rx(fi.absoluteFilePath());
   701                     if(rx.exists() && rx.open(QIODevice::ReadOnly | QIODevice::Text)) {
   646                     if(rx.exists() && rx.open(QIODevice::ReadOnly | QIODevice::Text)) {
   702                         QTextStream in(&rx);
   647                         QTextStream in(&rx);
   703                         in >> result;
   648                         in >> result;
   710         }
   655         }
   711         break;
   656         break;
   712     case QSystemNetworkInfo::EthernetMode:
   657     case QSystemNetworkInfo::EthernetMode:
   713         {
   658         {
   714             QString result;
   659             QString result;
   715             QString baseSysDir = "/sys/class/net/";
   660             const QString baseSysDir = "/sys/class/net/";
   716             QDir eDir(baseSysDir);
   661             const QDir eDir(baseSysDir);
   717             QStringList dirs = eDir.entryList(QStringList() << "eth*", QDir::AllDirs | QDir::NoDotAndDotDot);
   662             const QStringList dirs = eDir.entryList(QStringList() << "eth*", QDir::AllDirs | QDir::NoDotAndDotDot);
   718             foreach(QString dir, dirs) {
   663             foreach(const QString dir, dirs) {
   719                 QString devFile = baseSysDir + dir;
   664                 const QString devFile = baseSysDir + dir;
   720                 QFileInfo fi(devFile + "/carrier");
   665                 const QFileInfo fi(devFile + "/carrier");
   721                 if(fi.exists()) {
   666                 if(fi.exists()) {
   722                     QFile rx(fi.absoluteFilePath());
   667                     QFile rx(fi.absoluteFilePath());
   723                     if(rx.exists() && rx.open(QIODevice::ReadOnly | QIODevice::Text)) {
   668                     if(rx.exists() && rx.open(QIODevice::ReadOnly | QIODevice::Text)) {
   724                         QTextStream in(&rx);
   669                         QTextStream in(&rx);
   725                         in >> result;
   670                         in >> result;
   751     switch(mode) {
   696     switch(mode) {
   752     case QSystemNetworkInfo::WlanMode:
   697     case QSystemNetworkInfo::WlanMode:
   753         {
   698         {
   754             QHalInterface iface;
   699             QHalInterface iface;
   755             if (iface.isValid()) {
   700             if (iface.isValid()) {
   756                 QStringList list = iface.findDeviceByCapability("net.80211");
   701                 const QStringList list = iface.findDeviceByCapability("net.80211");
   757                 if(!list.isEmpty()) {
   702                 if(!list.isEmpty()) {
   758                     foreach(QString netDev, list) {
   703                     foreach(const QString netDev, list) {
   759                         QString deviceName ;
       
   760                         QHalDeviceInterface ifaceDevice(netDev);
   704                         QHalDeviceInterface ifaceDevice(netDev);
   761                         deviceName  = ifaceDevice.getPropertyString("net.interface");
   705                         const QString deviceName  = ifaceDevice.getPropertyString("net.interface");
   762                         if(list.count() > 1) {
   706                         if(list.count() > 1) {
   763                             QString baseFIle = "/sys/class/net/" + deviceName+"/operstate";
   707                             const QString baseFIle = "/sys/class/net/" + deviceName+"/operstate";
   764                             QFile rx(baseFIle);
   708                             QFile rx(baseFIle);
   765                             if(rx.exists() && rx.open(QIODevice::ReadOnly | QIODevice::Text)) {
   709                             if(rx.exists() && rx.open(QIODevice::ReadOnly | QIODevice::Text)) {
   766                                 QString operatingState;
   710                                 QString operatingState;
   767                                 QTextStream in(&rx);
   711                                 QTextStream in(&rx);
   768                                 in >> operatingState;
   712                                 in >> operatingState;
   783         break;
   727         break;
   784     case QSystemNetworkInfo::EthernetMode:
   728     case QSystemNetworkInfo::EthernetMode:
   785         {
   729         {
   786             QHalInterface iface;
   730             QHalInterface iface;
   787             if (iface.isValid()) {
   731             if (iface.isValid()) {
   788                 QStringList list = iface.findDeviceByCapability("net.80203");
   732                 const QStringList list = iface.findDeviceByCapability("net.80203");
   789                 if(!list.isEmpty()) {
   733                 if(!list.isEmpty()) {
   790                     foreach(QString netDev, list) {
   734                     foreach(const QString netDev, list) {
   791                         QString deviceName ;
       
   792                         QHalDeviceInterface ifaceDevice(netDev);
   735                         QHalDeviceInterface ifaceDevice(netDev);
   793                         deviceName  = ifaceDevice.getPropertyString("net.interface");
   736                         const QString deviceName  = ifaceDevice.getPropertyString("net.interface");
   794                         if(list.count() > 1) {
   737                         if(list.count() > 1) {
   795                             QString baseFIle = "/sys/class/net/" + deviceName+"/operstate";
   738                             const QString baseFIle = "/sys/class/net/" + deviceName+"/operstate";
   796                             QFile rx(baseFIle);
   739                             QFile rx(baseFIle);
   797                             if(rx.exists() && rx.open(QIODevice::ReadOnly | QIODevice::Text)) {
   740                             if(rx.exists() && rx.open(QIODevice::ReadOnly | QIODevice::Text)) {
   798                                 QString operatingState;
   741                                 QString operatingState;
   799                                 QTextStream in(&rx);
   742                                 QTextStream in(&rx);
   800                                 in >> operatingState;
   743                                 in >> operatingState;
   820     default:
   763     default:
   821         break;
   764         break;
   822     };
   765     };
   823 #else
   766 #else
   824     QString result;
   767     QString result;
   825     QString baseSysDir = "/sys/class/net/";
   768     const QString baseSysDir = "/sys/class/net/";
   826     QDir eDir(baseSysDir);
   769     const QDir eDir(baseSysDir);
   827     QStringList dirs = eDir.entryList(QStringList() << "*", QDir::AllDirs | QDir::NoDotAndDotDot);
   770     const QStringList dirs = eDir.entryList(QStringList() << "*", QDir::AllDirs | QDir::NoDotAndDotDot);
   828     foreach(QString dir, dirs) {
   771     foreach(const QString dir, dirs) {
   829         QString devFile = baseSysDir + dir;
   772         const QString devFile = baseSysDir + dir;
   830         QFileInfo devfi(devFile + "/device");
   773         const QFileInfo devfi(devFile + "/device");
   831         if(!devfi.exists()) {
   774         if(!devfi.exists()) {
   832             continue;
   775             continue;
   833         }
   776         }
   834         QString baseFIle = "/sys/class/net/" + devFile+"/operstate";
   777         const QString baseFIle = "/sys/class/net/" + devFile+"/operstate";
   835         QFile rx(baseFIle);
   778         QFile rx(baseFIle);
   836         if(rx.exists() && rx.open(QIODevice::ReadOnly | QIODevice::Text)) {
   779         if(rx.exists() && rx.open(QIODevice::ReadOnly | QIODevice::Text)) {
   837             QString operatingState;
   780             QString operatingState;
   838             QTextStream in(&rx);
   781             QTextStream in(&rx);
   839             in >> operatingState;
   782             in >> operatingState;
   843             }
   786             }
   844         }
   787         }
   845         switch(mode) {
   788         switch(mode) {
   846         case QSystemNetworkInfo::WlanMode:
   789         case QSystemNetworkInfo::WlanMode:
   847             {
   790             {
   848                 QFileInfo fi(devFile + "/wireless");
   791                 const QFileInfo fi(devFile + "/wireless");
   849                 if(fi.exists()) {
   792                 if(fi.exists()) {
   850                     return QNetworkInterface::interfaceFromName(dir);
   793                     return QNetworkInterface::interfaceFromName(dir);
   851                 }
   794                 }
   852             }
   795             }
   853             break;
   796             break;
   854             case QSystemNetworkInfo::EthernetMode:
   797             case QSystemNetworkInfo::EthernetMode:
   855                 {
   798             {
   856                 QFileInfo fi(devFile + "/wireless");
   799                 const QFileInfo fi(devFile + "/wireless");
   857                 if(!fi.exists()) {
   800                 if(!fi.exists()) {
   858                     return QNetworkInterface::interfaceFromName(dir);
   801                     return QNetworkInterface::interfaceFromName(dir);
   859                 }
   802                 }
   860             }
   803             }
   861             break;
   804             break;
   880     if(routeFilex.exists() && routeFilex.open(QIODevice::ReadOnly
   823     if(routeFilex.exists() && routeFilex.open(QIODevice::ReadOnly
   881                                               | QIODevice::Text)) {
   824                                               | QIODevice::Text)) {
   882         QTextStream rin(&routeFilex);
   825         QTextStream rin(&routeFilex);
   883         QString line = rin.readLine();
   826         QString line = rin.readLine();
   884         while (!line.isNull()) {
   827         while (!line.isNull()) {
   885             QString lineSection = line.section("\t",2,2,QString::SectionSkipEmpty);
   828             const QString lineSection = line.section("\t",2,2,QString::SectionSkipEmpty);
   886             if(lineSection != "00000000" && lineSection!="Gateway")
   829             if(lineSection != "00000000" && lineSection!="Gateway")
   887                 if(line.section("\t",0,0,QString::SectionSkipEmpty) == deviceName) {
   830                 if(line.section("\t",0,0,QString::SectionSkipEmpty) == deviceName) {
   888                 routeFilex.close();
   831                 routeFilex.close();
   889                 return true;
   832                 return true;
   890             }
   833             }
   900     return 0;
   843     return 0;
   901 }
   844 }
   902 
   845 
   903 QString QSystemNetworkInfoLinuxCommonPrivate::getBluetoothInfo(const QString &file)
   846 QString QSystemNetworkInfoLinuxCommonPrivate::getBluetoothInfo(const QString &file)
   904 {
   847 {
   905     QString sysPath = "/sys/class/bluetooth/";
   848     const QString sysPath = "/sys/class/bluetooth/";
   906     QDir sysDir(sysPath);
   849     const QDir sysDir(sysPath);
   907     QStringList filters;
   850     QStringList filters;
   908     filters << "*";
   851     filters << "*";
   909     QStringList sysList = sysDir.entryList( filters ,QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
   852     const QStringList sysList = sysDir.entryList( filters ,QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
   910     foreach(QString dir, sysList) {
   853     foreach(const QString dir, sysList) {
   911         QFile btFile(sysPath + dir+"/"+file);
   854         QFile btFile(sysPath + dir+"/"+file);
   912         if(btFile.exists()) {
   855         if(btFile.exists()) {
   913             if (btFile.open(QIODevice::ReadOnly)) {
   856             if (btFile.open(QIODevice::ReadOnly)) {
   914                 QTextStream btFileStream(&btFile);
   857                 QTextStream btFileStream(&btFile);
   915                 QString line = btFileStream.readAll();
   858                 QString line = btFileStream.readAll();
   946     Q_UNUSED(screen);
   889     Q_UNUSED(screen);
   947     if(halIsAvailable) {
   890     if(halIsAvailable) {
   948 #if !defined(QT_NO_DBUS)
   891 #if !defined(QT_NO_DBUS)
   949         QHalInterface iface;
   892         QHalInterface iface;
   950         if (iface.isValid()) {
   893         if (iface.isValid()) {
   951             QStringList list = iface.findDeviceByCapability("laptop_panel");
   894             const QStringList list = iface.findDeviceByCapability("laptop_panel");
   952             if(!list.isEmpty()) {
   895             if(!list.isEmpty()) {
   953                 foreach(QString lapDev, list) {
   896                 foreach(const QString lapDev, list) {
   954                     QHalDeviceInterface ifaceDevice(lapDev);
   897                     QHalDeviceInterface ifaceDevice(lapDev);
   955                     QHalDeviceLaptopPanelInterface lapIface(lapDev);
   898                     QHalDeviceLaptopPanelInterface lapIface(lapDev);
   956                     float numLevels = ifaceDevice.getPropertyInt("laptop_panel.num_levels") - 1;
   899                     const float numLevels = ifaceDevice.getPropertyInt("laptop_panel.num_levels") - 1;
   957                     float curLevel = lapIface.getBrightness();
   900                     const float curLevel = lapIface.getBrightness();
   958                     return curLevel / numLevels * 100;
   901                     return curLevel / numLevels * 100;
   959                 }
   902                 }
   960             }
   903             }
   961         }
   904         }
   962 #endif
   905 #endif
   963     } else {
   906     } else {
   964         QString backlightPath = "/proc/acpi/video/";
   907         const QString backlightPath = "/proc/acpi/video/";
   965         QDir videoDir(backlightPath);
   908         const QDir videoDir(backlightPath);
   966         QStringList filters;
   909         QStringList filters;
   967         filters << "*";
   910         filters << "*";
   968         QStringList brightnessList = videoDir.entryList(filters,
   911         const QStringList brightnessList = videoDir.entryList(filters,
   969                                                         QDir::Dirs
   912                                                         QDir::Dirs
   970                                                         | QDir::NoDotAndDotDot,
   913                                                         | QDir::NoDotAndDotDot,
   971                                                         QDir::Name);
   914                                                         QDir::Name);
   972         foreach(QString brightnessFileName, brightnessList) {
   915         foreach(const QString brightnessFileName, brightnessList) {
   973             float numLevels = 0.0;
   916             float numLevels = 0.0;
   974             float curLevel = 0.0;
   917             float curLevel = 0.0;
   975             QFile curBrightnessFile(backlightPath+brightnessFileName+"/LCD/brightness");
   918             QFile curBrightnessFile(backlightPath+brightnessFileName+"/LCD/brightness");
   976             if(!curBrightnessFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
   919             if(!curBrightnessFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
   977                 qWarning()<<"File not opened";
   920                 qWarning()<<"File not opened";
   978             } else {
   921             } else {
   979                 QString  strvalue;
   922                 const QString strvalue = curBrightnessFile.readAll().trimmed();
   980                 strvalue = curBrightnessFile.readAll().trimmed();
       
   981                 if(strvalue.contains("levels")) {
   923                 if(strvalue.contains("levels")) {
   982                     QStringList list = strvalue.split(" ");
   924                     QStringList list = strvalue.split(" ");
   983                     numLevels = list.at(2).toFloat();
   925                     numLevels = list.at(2).toFloat();
   984                 }
   926                 }
   985                 if(strvalue.contains("current")) {
   927                 if(strvalue.contains("current")) {
  1059         return 0;
  1001         return 0;
  1060     }
  1002     }
  1061     mountEntries();
  1003     mountEntries();
  1062     struct statfs fs;
  1004     struct statfs fs;
  1063     if(statfs(mountEntriesMap[driveVolume].toLatin1(), &fs ) == 0 ) {
  1005     if(statfs(mountEntriesMap[driveVolume].toLatin1(), &fs ) == 0 ) {
  1064         long blockSize = fs.f_bsize;
  1006         const long blockSize = fs.f_bsize;
  1065         long totalBlocks = fs.f_blocks;
  1007         const long totalBlocks = fs.f_blocks;
  1066         return (double)totalBlocks * blockSize;
  1008         return (double)totalBlocks * blockSize;
  1067     }
  1009     }
  1068     return 0;
  1010     return 0;
  1069 }
  1011 }
  1070 
  1012 
  1072 {
  1014 {
  1073     if(halIsAvailable) {
  1015     if(halIsAvailable) {
  1074 #if !defined(QT_NO_DBUS)
  1016 #if !defined(QT_NO_DBUS)
  1075         QStringList mountedVol;
  1017         QStringList mountedVol;
  1076         QHalInterface iface;
  1018         QHalInterface iface;
  1077         QStringList list = iface.findDeviceByCapability("volume");
  1019         const QStringList list = iface.findDeviceByCapability("volume");
  1078         if(!list.isEmpty()) {
  1020         if(!list.isEmpty()) {
  1079             foreach(QString vol, list) {
  1021             foreach(const QString vol, list) {
  1080                 QHalDeviceInterface ifaceDevice(vol);
  1022                 QHalDeviceInterface ifaceDevice(vol);
  1081                 if(driveVolume == ifaceDevice.getPropertyString("block.device")) {
  1023                 if(driveVolume == ifaceDevice.getPropertyString("block.device")) {
  1082                     QHalDeviceInterface ifaceDeviceParent(ifaceDevice.getPropertyString("info.parent"), this);
  1024                     QHalDeviceInterface ifaceDeviceParent(ifaceDevice.getPropertyString("info.parent"), this);
  1083 
  1025 
  1084                     if(ifaceDeviceParent.getPropertyBool("storage.removable")
  1026                     if(ifaceDeviceParent.getPropertyBool("storage.removable")
  1203 #if !defined(QT_NO_DBUS)
  1145 #if !defined(QT_NO_DBUS)
  1204         QHalInterface iface;
  1146         QHalInterface iface;
  1205 
  1147 
  1206         QStringList list = iface.findDeviceByCapability("battery");
  1148         QStringList list = iface.findDeviceByCapability("battery");
  1207         if(!list.isEmpty()) {
  1149         if(!list.isEmpty()) {
  1208             foreach(QString dev, list) {
  1150             foreach(const QString dev, list) {
  1209                 halIfaceDevice = new QHalDeviceInterface(dev);
  1151                 halIfaceDevice = new QHalDeviceInterface(dev);
  1210                 if (halIfaceDevice->isValid()) {
  1152                 if (halIfaceDevice->isValid()) {
  1211                     QString batType = halIfaceDevice->getPropertyString("battery.type");
  1153                     const QString batType = halIfaceDevice->getPropertyString("battery.type");
  1212                     if(batType == "primary" || batType == "pda") {
  1154                     if(batType == "primary" || batType == "pda") {
  1213                         if(halIfaceDevice->setConnections() ) {
  1155                         if(halIfaceDevice->setConnections() ) {
  1214                             if(!connect(halIfaceDevice,SIGNAL(propertyModified(int, QVariantList)),
  1156                             if(!connect(halIfaceDevice,SIGNAL(propertyModified(int, QVariantList)),
  1215                                         this,SLOT(halChanged(int,QVariantList)))) {
  1157                                         this,SLOT(halChanged(int,QVariantList)))) {
  1216                                 qWarning() << "connection malfunction";
  1158                                 qWarning() << "connection malfunction";
  1222             }
  1164             }
  1223         }
  1165         }
  1224 
  1166 
  1225         list = iface.findDeviceByCapability("ac_adapter");
  1167         list = iface.findDeviceByCapability("ac_adapter");
  1226         if(!list.isEmpty()) {
  1168         if(!list.isEmpty()) {
  1227             foreach(QString dev, list) {
  1169             foreach(const QString dev, list) {
  1228                 halIfaceDevice = new QHalDeviceInterface(dev);
  1170                 halIfaceDevice = new QHalDeviceInterface(dev);
  1229                 if (halIfaceDevice->isValid()) {
  1171                 if (halIfaceDevice->isValid()) {
  1230                     if(halIfaceDevice->setConnections() ) {
  1172                     if(halIfaceDevice->setConnections() ) {
  1231                         if(!connect(halIfaceDevice,SIGNAL(propertyModified(int, QVariantList)),
  1173                         if(!connect(halIfaceDevice,SIGNAL(propertyModified(int, QVariantList)),
  1232                                     this,SLOT(halChanged(int,QVariantList)))) {
  1174                                     this,SLOT(halChanged(int,QVariantList)))) {
  1238             }
  1180             }
  1239         }
  1181         }
  1240 
  1182 
  1241         list = iface.findDeviceByCapability("battery");
  1183         list = iface.findDeviceByCapability("battery");
  1242         if(!list.isEmpty()) {
  1184         if(!list.isEmpty()) {
  1243             foreach(QString dev, list) {
  1185             foreach(const QString dev, list) {
  1244                 halIfaceDevice = new QHalDeviceInterface(dev);
  1186                 halIfaceDevice = new QHalDeviceInterface(dev);
  1245                 if (halIfaceDevice->isValid()) {
  1187                 if (halIfaceDevice->isValid()) {
  1246                     if(halIfaceDevice->setConnections()) {
  1188                     if(halIfaceDevice->setConnections()) {
  1247                         if(!connect(halIfaceDevice,SIGNAL(propertyModified(int, QVariantList)),
  1189                         if(!connect(halIfaceDevice,SIGNAL(propertyModified(int, QVariantList)),
  1248                                     this,SLOT(halChanged(int,QVariantList)))) {
  1190                                     this,SLOT(halChanged(int,QVariantList)))) {
  1261 
  1203 
  1262 #if !defined(QT_NO_DBUS)
  1204 #if !defined(QT_NO_DBUS)
  1263 void QSystemDeviceInfoLinuxCommonPrivate::halChanged(int,QVariantList map)
  1205 void QSystemDeviceInfoLinuxCommonPrivate::halChanged(int,QVariantList map)
  1264 {
  1206 {
  1265     for(int i=0; i < map.count(); i++) {
  1207     for(int i=0; i < map.count(); i++) {
  1266 //       qWarning() << __FUNCTION__ << map.at(i).toString();
       
  1267        if(map.at(i).toString() == "battery.charge_level.percentage") {
  1208        if(map.at(i).toString() == "battery.charge_level.percentage") {
  1268             int level = batteryLevel();
  1209             const int level = batteryLevel();
  1269             emit batteryLevelChanged(level);
  1210             emit batteryLevelChanged(level);
  1270             if(level < 4) {
  1211             if(level < 4) {
  1271                 emit batteryStatusChanged(QSystemDeviceInfo::BatteryCritical);
  1212                 emit batteryStatusChanged(QSystemDeviceInfo::BatteryCritical);
  1272             } else if(level < 11) {
  1213             } else if(level < 11) {
  1273                 emit batteryStatusChanged(QSystemDeviceInfo::BatteryVeryLow);
  1214                 emit batteryStatusChanged(QSystemDeviceInfo::BatteryVeryLow);
  1376                 return productName;
  1317                 return productName;
  1377             }
  1318             }
  1378         }
  1319         }
  1379 #endif
  1320 #endif
  1380     }
  1321     }
  1381     QDir dir("/etc");
  1322     const QDir dir("/etc");
  1382     if(dir.exists()) {
  1323     if(dir.exists()) {
  1383         QStringList langList;
  1324         QStringList langList;
  1384         QFileInfoList localeList = dir.entryInfoList(QStringList() << "*release",
  1325         QFileInfoList localeList = dir.entryInfoList(QStringList() << "*release",
  1385                                                      QDir::Files | QDir::NoDotAndDotDot,
  1326                                                      QDir::Files | QDir::NoDotAndDotDot,
  1386                                                      QDir::Name);
  1327                                                      QDir::Name);
  1387         foreach(QFileInfo fileInfo, localeList) {
  1328         foreach(const QFileInfo fileInfo, localeList) {
  1388             QString filepath = fileInfo.filePath();
  1329             const QString filepath = fileInfo.filePath();
  1389             QFile file(filepath);
  1330             QFile file(filepath);
  1390             if (file.open(QIODevice::ReadOnly)) {
  1331             if (file.open(QIODevice::ReadOnly)) {
  1391                 QTextStream prodinfo(&file);
  1332                 QTextStream prodinfo(&file);
  1392                 QString line = prodinfo.readLine();
  1333                 QString line = prodinfo.readLine();
  1393                 while (!line.isNull()) {
  1334                 while (!line.isNull()) {
  1431     if(halIsAvailable) {
  1372     if(halIsAvailable) {
  1432 #if !defined(QT_NO_DBUS)
  1373 #if !defined(QT_NO_DBUS)
  1433         QHalInterface iface2;
  1374         QHalInterface iface2;
  1434         if (iface2.isValid()) {
  1375         if (iface2.isValid()) {
  1435             QStringList capList;
  1376             QStringList capList;
  1436             capList << "input.keyboard" << "input.keys" << "input.keypad" << "input.mouse" << "input.tablet";
  1377             capList << QLatin1String("input.keyboard") 
       
  1378                     << QLatin1String("input.keys")
       
  1379                     << QLatin1String("input.keypad") 
       
  1380                     << QLatin1String("input.mouse") 
       
  1381                     << QLatin1String("input.tablet")
       
  1382                     << QLatin1String("input.touchpad");
  1437             for(int i = 0; i < capList.count(); i++) {
  1383             for(int i = 0; i < capList.count(); i++) {
  1438                 QStringList list = iface2.findDeviceByCapability(capList.at(i));
  1384                 QStringList list = iface2.findDeviceByCapability(capList.at(i));
  1439                 if(!list.isEmpty()) {
  1385                 if(!list.isEmpty()) {
  1440                     switch(i) {
  1386                     switch(i) {
  1441                     case 0:
  1387                     case 0:
  1451                         methods = (methods | QSystemDeviceInfo::Mouse);
  1397                         methods = (methods | QSystemDeviceInfo::Mouse);
  1452                         break;
  1398                         break;
  1453                     case 4:
  1399                     case 4:
  1454                         methods = (methods | QSystemDeviceInfo::SingleTouch);
  1400                         methods = (methods | QSystemDeviceInfo::SingleTouch);
  1455                         break;
  1401                         break;
  1456                     };
  1402                     case 5:
       
  1403                         methods = (methods | QSystemDeviceInfo::SingleTouch);
       
  1404                         break;
       
  1405                     }
  1457                 }
  1406                 }
  1458             }
  1407             }
  1459             if(methods != 0)
  1408             if(methods != 0)
  1460                 return methods;
  1409                 return methods;
  1461         }
  1410         }
  1462 #endif
  1411 #endif
  1463     }
  1412     }
  1464     QString inputsPath = "/sys/class/input/";
  1413     const QString inputsPath = "/sys/class/input/";
  1465     QDir inputDir(inputsPath);
  1414     const QDir inputDir(inputsPath);
  1466     QStringList filters;
  1415     QStringList filters;
  1467     filters << "event*";
  1416     filters << "event*";
  1468     QStringList inputList = inputDir.entryList( filters ,QDir::Dirs, QDir::Name);
  1417     const QStringList inputList = inputDir.entryList( filters ,QDir::Dirs, QDir::Name);
  1469     foreach(QString inputFileName, inputList) {
  1418     foreach(const QString inputFileName, inputList) {
  1470         QFile file(inputsPath+inputFileName+"/device/name");
  1419         QFile file(inputsPath+inputFileName+"/device/name");
  1471         if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
  1420         if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
  1472             qWarning()<<"File not opened";
  1421             qWarning()<<"File not opened";
  1473         } else {
  1422         } else {
  1474             QString strvalue;
  1423             QString strvalue;
  1505     float levelWhenFull = 0.0;
  1454     float levelWhenFull = 0.0;
  1506     float level = 0.0;
  1455     float level = 0.0;
  1507     if(halIsAvailable) {
  1456     if(halIsAvailable) {
  1508 #if !defined(QT_NO_DBUS)
  1457 #if !defined(QT_NO_DBUS)
  1509         QHalInterface iface;
  1458         QHalInterface iface;
  1510         QStringList list = iface.findDeviceByCapability("battery");
  1459         const QStringList list = iface.findDeviceByCapability("battery");
  1511         if(!list.isEmpty()) {
  1460         if(!list.isEmpty()) {
  1512             foreach(QString dev, list) {
  1461             foreach(const QString dev, list) {
  1513                 QHalDeviceInterface ifaceDevice(dev);
  1462                 QHalDeviceInterface ifaceDevice(dev);
  1514                 if (ifaceDevice.isValid()) {
  1463                 if (ifaceDevice.isValid()) {
  1515 //                    qWarning() << ifaceDevice.getPropertyString("battery.type")
  1464 //                    qWarning() << ifaceDevice.getPropertyString("battery.type")
  1516 //                            << ifaceDevice.getPropertyInt("battery.charge_level.percentage");
  1465 //                            << ifaceDevice.getPropertyInt("battery.charge_level.percentage");
  1517                     if(!ifaceDevice.getPropertyBool("battery.present")
  1466                     if(!ifaceDevice.getPropertyBool("battery.present")
  1536             QTextStream batinfo(&infofile);
  1485             QTextStream batinfo(&infofile);
  1537             QString line = batinfo.readLine();
  1486             QString line = batinfo.readLine();
  1538             while (!line.isNull()) {
  1487             while (!line.isNull()) {
  1539                 if(line.contains("design capacity")) {
  1488                 if(line.contains("design capacity")) {
  1540                     levelWhenFull = line.split(" ").at(1).trimmed().toFloat();
  1489                     levelWhenFull = line.split(" ").at(1).trimmed().toFloat();
  1541                     qWarning() << levelWhenFull;
  1490                     //qWarning() << levelWhenFull;
  1542                     infofile.close();
  1491                     infofile.close();
  1543                     break;
  1492                     break;
  1544                 }
  1493                 }
  1545                 line = batinfo.readLine();
  1494                 line = batinfo.readLine();
  1546             }
  1495             }
  1555             QTextStream batstate(&statefile);
  1504             QTextStream batstate(&statefile);
  1556             QString line = batstate.readLine();
  1505             QString line = batstate.readLine();
  1557             while (!line.isNull()) {
  1506             while (!line.isNull()) {
  1558                 if(line.contains("remaining capacity")) {
  1507                 if(line.contains("remaining capacity")) {
  1559                     level = line.split(" ").at(1).trimmed().toFloat();
  1508                     level = line.split(" ").at(1).trimmed().toFloat();
  1560                     qWarning() << level;
  1509                     //qWarning() << level;
  1561                     statefile.close();
  1510                     statefile.close();
  1562                     break;
  1511                     break;
  1563                 }
  1512                 }
  1564                 line = batstate.readLine();
  1513                 line = batstate.readLine();
  1565             }
  1514             }
  1576 {
  1525 {
  1577 #if !defined(QT_NO_DBUS)
  1526 #if !defined(QT_NO_DBUS)
  1578        QHalInterface iface;
  1527        QHalInterface iface;
  1579        QStringList list = iface.findDeviceByCapability("battery");
  1528        QStringList list = iface.findDeviceByCapability("battery");
  1580        if(!list.isEmpty()) {
  1529        if(!list.isEmpty()) {
  1581            foreach(QString dev, list) {
  1530            foreach(const QString dev, list) {
  1582                QHalDeviceInterface ifaceDevice(dev);
  1531                QHalDeviceInterface ifaceDevice(dev);
  1583                if (iface.isValid()) {
  1532                if (iface.isValid()) {
  1584                    if (ifaceDevice.getPropertyBool("battery.rechargeable.is_charging")) {
  1533                    if (ifaceDevice.getPropertyBool("battery.rechargeable.is_charging")) {
  1585                        return QSystemDeviceInfo::WallPowerChargingBattery;
  1534                        return QSystemDeviceInfo::WallPowerChargingBattery;
  1586                    }
  1535                    }
  1588            }
  1537            }
  1589        }
  1538        }
  1590 
  1539 
  1591        list = iface.findDeviceByCapability("ac_adapter");
  1540        list = iface.findDeviceByCapability("ac_adapter");
  1592        if(!list.isEmpty()) {
  1541        if(!list.isEmpty()) {
  1593            foreach(QString dev, list) {
  1542            foreach(const QString dev, list) {
  1594                QHalDeviceInterface ifaceDevice(dev);
  1543                QHalDeviceInterface ifaceDevice(dev);
  1595                if (ifaceDevice.isValid()) {
  1544                if (ifaceDevice.isValid()) {
  1596                    if(ifaceDevice.getPropertyBool("ac_adapter.present")) {
  1545                    if(ifaceDevice.getPropertyBool("ac_adapter.present")) {
  1597                        return QSystemDeviceInfo::WallPower;
  1546                        return QSystemDeviceInfo::WallPower;
  1598                    } else {
  1547                    } else {