qtmobility/src/systeminfo/qsysteminfo_linux_common.cpp
changeset 8 71781823f776
parent 5 453da2cfceef
child 11 06b8e2af4411
equal deleted inserted replaced
5:453da2cfceef 8:71781823f776
   111         if (reply.isValid() && reply.value()) {
   111         if (reply.isValid() && reply.value()) {
   112             return reply.value();
   112             return reply.value();
   113         }
   113         }
   114     }
   114     }
   115 #endif
   115 #endif
   116   //  qDebug() << "Hal is not running";
       
   117     return false;
   116     return false;
   118 }
   117 }
   119 
   118 
   120 
   119 
   121 bool halIsAvailable;
   120 bool halIsAvailable;
   355             }
   354             }
   356 #endif
   355 #endif
   357             const QString versionPath = QLatin1String("/proc/version");
   356             const QString versionPath = QLatin1String("/proc/version");
   358             QFile versionFile(versionPath);
   357             QFile versionFile(versionPath);
   359             if(!versionFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
   358             if(!versionFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
   360                 qWarning() << "File not opened";
   359                 qDebug() << "File not opened";
   361             } else {
   360             } else {
   362                 QString  strvalue;
   361                 QString  strvalue;
   363                 strvalue = QLatin1String(versionFile.readAll().trimmed());
   362                 strvalue = QLatin1String(versionFile.readAll().trimmed());
   364                 strvalue = strvalue.split(QLatin1String(" ")).at(2);
   363                 strvalue = strvalue.split(QLatin1String(" ")).at(2);
   365                 versionFile.close();
   364                 versionFile.close();
   505                 if (ioctl(sock, SIOCGIWESSID, &wifiExchange) == 0) {
   504                 if (ioctl(sock, SIOCGIWESSID, &wifiExchange) == 0) {
   506                     const char *ssid = (const char *)wifiExchange.u.essid.pointer;
   505                     const char *ssid = (const char *)wifiExchange.u.essid.pointer;
   507                     netname = ssid;
   506                     netname = ssid;
   508                 }
   507                 }
   509             } else {
   508             } else {
   510                 qWarning() << "no socket";
   509                 qDebug() << "no socket";
   511             }
   510             }
   512             close(sock);
   511             close(sock);
   513         }
   512         }
   514         break;
   513         break;
   515     case QSystemNetworkInfo::EthernetMode:
   514     case QSystemNetworkInfo::EthernetMode:
   603 
   602 
   604 QSystemNetworkInfo::NetworkStatus QSystemNetworkInfoLinuxCommonPrivate::getBluetoothNetStatus()
   603 QSystemNetworkInfo::NetworkStatus QSystemNetworkInfoLinuxCommonPrivate::getBluetoothNetStatus()
   605 {
   604 {
   606     int ctl = socket(PF_BLUETOOTH,SOCK_RAW,BTPROTO_BNEP);
   605     int ctl = socket(PF_BLUETOOTH,SOCK_RAW,BTPROTO_BNEP);
   607     if (ctl < 0) {
   606     if (ctl < 0) {
   608         qWarning() << "Cannot open bnep socket";
   607         qDebug() << "Cannot open bnep socket";
   609         return QSystemNetworkInfo::UndefinedStatus;
   608         return QSystemNetworkInfo::UndefinedStatus;
   610     }
   609     }
   611 
   610 
   612     struct bnep_conninfo info[36];
   611     struct bnep_conninfo info[36];
   613     struct bnep_connlist_req req;
   612     struct bnep_connlist_req req;
   614 
   613 
   615     req.ci = info;
   614     req.ci = info;
   616     req.cnum = 36;
   615     req.cnum = 36;
   617 
   616 
   618     if (ioctl(ctl,BNEPGETCONNLIST,&req) < 0) {
   617     if (ioctl(ctl,BNEPGETCONNLIST,&req) < 0) {
   619         qWarning() << "Cannot get bnep connection list.";
   618         qDebug() << "Cannot get bnep connection list.";
   620         return QSystemNetworkInfo::UndefinedStatus;
   619         return QSystemNetworkInfo::UndefinedStatus;
   621     }
   620     }
   622     for (uint j = 0; j< req.cnum; j++) {
   621     for (uint j = 0; j< req.cnum; j++) {
   623         if(info[j].state == BT_CONNECTED) {
   622         if(info[j].state == BT_CONNECTED) {
   624             return QSystemNetworkInfo::Connected;
   623             return QSystemNetworkInfo::Connected;
   915         foreach(const QString brightnessFileName, brightnessList) {
   914         foreach(const QString brightnessFileName, brightnessList) {
   916             float numLevels = 0.0;
   915             float numLevels = 0.0;
   917             float curLevel = 0.0;
   916             float curLevel = 0.0;
   918             QFile curBrightnessFile(backlightPath+brightnessFileName+"/LCD/brightness");
   917             QFile curBrightnessFile(backlightPath+brightnessFileName+"/LCD/brightness");
   919             if(!curBrightnessFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
   918             if(!curBrightnessFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
   920                 qWarning()<<"File not opened";
   919                 qDebug()<<"File not opened";
   921             } else {
   920             } else {
   922                 const QString strvalue = curBrightnessFile.readAll().trimmed();
   921                 const QString strvalue = curBrightnessFile.readAll().trimmed();
   923                 if(strvalue.contains("levels")) {
   922                 if(strvalue.contains("levels")) {
   924                     QStringList list = strvalue.split(" ");
   923                     QStringList list = strvalue.split(" ");
   925                     numLevels = list.at(2).toFloat();
   924                     numLevels = list.at(2).toFloat();
   945     foreach(QString brightnessFileName, brightnessList) {
   944     foreach(QString brightnessFileName, brightnessList) {
   946         float numLevels = 0.0;
   945         float numLevels = 0.0;
   947         float curLevel = 0.0;
   946         float curLevel = 0.0;
   948         QFile curBrightnessFile(backlightPath+brightnessFileName+"/brightness");
   947         QFile curBrightnessFile(backlightPath+brightnessFileName+"/brightness");
   949         if(!curBrightnessFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
   948         if(!curBrightnessFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
   950             qWarning()<<"File not opened";
   949             qDebug()<<"File not opened";
   951         } else {
   950         } else {
   952             QString strvalue;
   951             QString strvalue;
   953             strvalue = curBrightnessFile.readLine().trimmed();
   952             strvalue = curBrightnessFile.readLine().trimmed();
   954             curBrightnessFile.close();
   953             curBrightnessFile.close();
   955             curLevel = strvalue.toFloat();
   954             curLevel = strvalue.toFloat();
   956 
   955 
   957             QFile maxBrightnessFile(backlightPath+brightnessFileName+"/max_brightness");
   956             QFile maxBrightnessFile(backlightPath+brightnessFileName+"/max_brightness");
   958             if(!maxBrightnessFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
   957             if(!maxBrightnessFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
   959                 qWarning()<<"File not opened";
   958                 qDebug()<<"File not opened";
   960             } else {
   959             } else {
   961                 QString strvalue;
   960                 QString strvalue;
   962                 strvalue = maxBrightnessFile.readLine().trimmed();
   961                 strvalue = maxBrightnessFile.readLine().trimmed();
   963                 maxBrightnessFile.close();
   962                 maxBrightnessFile.close();
   964                 numLevels = strvalue.toFloat();
   963                 numLevels = strvalue.toFloat();
  1059             dmFile = "/sys/block/"+dmFile+"/removable";
  1058             dmFile = "/sys/block/"+dmFile+"/removable";
  1060         }
  1059         }
  1061 
  1060 
  1062         QFile file(dmFile);
  1061         QFile file(dmFile);
  1063         if (!file.open(QIODevice::ReadOnly)) {
  1062         if (!file.open(QIODevice::ReadOnly)) {
  1064             qWarning() << "Could not open sys file";
  1063             qDebug() << "Could not open sys file";
  1065         } else {
  1064         } else {
  1066             QTextStream sysinfo(&file);
  1065             QTextStream sysinfo(&file);
  1067             QString line = sysinfo.readAll();
  1066             QString line = sysinfo.readAll();
  1068             if(line.contains("1")) {
  1067             if(line.contains("1")) {
  1069                 return QSystemStorageInfo::RemovableDrive;
  1068                 return QSystemStorageInfo::RemovableDrive;
  1153                     const QString batType = halIfaceDevice->getPropertyString("battery.type");
  1152                     const QString batType = halIfaceDevice->getPropertyString("battery.type");
  1154                     if(batType == "primary" || batType == "pda") {
  1153                     if(batType == "primary" || batType == "pda") {
  1155                         if(halIfaceDevice->setConnections() ) {
  1154                         if(halIfaceDevice->setConnections() ) {
  1156                             if(!connect(halIfaceDevice,SIGNAL(propertyModified(int, QVariantList)),
  1155                             if(!connect(halIfaceDevice,SIGNAL(propertyModified(int, QVariantList)),
  1157                                         this,SLOT(halChanged(int,QVariantList)))) {
  1156                                         this,SLOT(halChanged(int,QVariantList)))) {
  1158                                 qWarning() << "connection malfunction";
  1157                                 qDebug() << "connection malfunction";
  1159                             }
  1158                             }
  1160                         }
  1159                         }
  1161                         break;
  1160                         break;
  1162                     }
  1161                     }
  1163                 }
  1162                 }
  1170                 halIfaceDevice = new QHalDeviceInterface(dev);
  1169                 halIfaceDevice = new QHalDeviceInterface(dev);
  1171                 if (halIfaceDevice->isValid()) {
  1170                 if (halIfaceDevice->isValid()) {
  1172                     if(halIfaceDevice->setConnections() ) {
  1171                     if(halIfaceDevice->setConnections() ) {
  1173                         if(!connect(halIfaceDevice,SIGNAL(propertyModified(int, QVariantList)),
  1172                         if(!connect(halIfaceDevice,SIGNAL(propertyModified(int, QVariantList)),
  1174                                     this,SLOT(halChanged(int,QVariantList)))) {
  1173                                     this,SLOT(halChanged(int,QVariantList)))) {
  1175                             qWarning() << "connection malfunction";
  1174                             qDebug() << "connection malfunction";
  1176                         }
  1175                         }
  1177                     }
  1176                     }
  1178                     break;
  1177                     break;
  1179                 }
  1178                 }
  1180             }
  1179             }
  1186                 halIfaceDevice = new QHalDeviceInterface(dev);
  1185                 halIfaceDevice = new QHalDeviceInterface(dev);
  1187                 if (halIfaceDevice->isValid()) {
  1186                 if (halIfaceDevice->isValid()) {
  1188                     if(halIfaceDevice->setConnections()) {
  1187                     if(halIfaceDevice->setConnections()) {
  1189                         if(!connect(halIfaceDevice,SIGNAL(propertyModified(int, QVariantList)),
  1188                         if(!connect(halIfaceDevice,SIGNAL(propertyModified(int, QVariantList)),
  1190                                     this,SLOT(halChanged(int,QVariantList)))) {
  1189                                     this,SLOT(halChanged(int,QVariantList)))) {
  1191                             qWarning() << "connection malfunction";
  1190                             qDebug() << "connection malfunction";
  1192                         }
  1191                         }
  1193                     }
  1192                     }
  1194                     break;
  1193                     break;
  1195                 }
  1194                 }
  1196             }
  1195             }
  1249     QFile vendorId("/sys/devices/virtual/dmi/id/board_vendor");
  1248     QFile vendorId("/sys/devices/virtual/dmi/id/board_vendor");
  1250     if (vendorId.open(QIODevice::ReadOnly)) {
  1249     if (vendorId.open(QIODevice::ReadOnly)) {
  1251         QTextStream cpuinfo(&vendorId);
  1250         QTextStream cpuinfo(&vendorId);
  1252         return cpuinfo.readLine().trimmed();
  1251         return cpuinfo.readLine().trimmed();
  1253     } else {
  1252     } else {
  1254         //        qWarning() << "Could not open /sys/devices/virtual/dmi/id/board_vendor";
       
  1255         QFile file("/proc/cpuinfo");
  1253         QFile file("/proc/cpuinfo");
  1256         if (!file.open(QIODevice::ReadOnly)) {
  1254         if (!file.open(QIODevice::ReadOnly)) {
  1257             qWarning() << "Could not open /proc/cpuinfo";
  1255             qDebug() << "Could not open /proc/cpuinfo";
  1258         } else {
  1256         } else {
  1259             QTextStream cpuinfo(&file);
  1257             QTextStream cpuinfo(&file);
  1260             QString line = cpuinfo.readLine();
  1258             QString line = cpuinfo.readLine();
  1261             while (!line.isNull()) {
  1259             while (!line.isNull()) {
  1262                 line = cpuinfo.readLine();
  1260                 line = cpuinfo.readLine();
  1285         }
  1283         }
  1286 #endif
  1284 #endif
  1287     }
  1285     }
  1288     QFile file("/proc/cpuinfo");
  1286     QFile file("/proc/cpuinfo");
  1289     if (!file.open(QIODevice::ReadOnly)) {
  1287     if (!file.open(QIODevice::ReadOnly)) {
  1290         qWarning() << "Could not open /proc/cpuinfo";
  1288         qDebug() << "Could not open /proc/cpuinfo";
  1291     } else {
  1289     } else {
  1292         QTextStream cpuinfo(&file);
  1290         QTextStream cpuinfo(&file);
  1293         QString line = cpuinfo.readLine();
  1291         QString line = cpuinfo.readLine();
  1294         while (!line.isNull()) {
  1292         while (!line.isNull()) {
  1295             line = cpuinfo.readLine();
  1293             line = cpuinfo.readLine();
  1345         } //end foreach
  1343         } //end foreach
  1346     }
  1344     }
  1347 
  1345 
  1348     QFile file("/etc/issue");
  1346     QFile file("/etc/issue");
  1349     if (!file.open(QIODevice::ReadOnly)) {
  1347     if (!file.open(QIODevice::ReadOnly)) {
  1350         qWarning() << "Could not open /proc/cpuinfo";
  1348         qDebug() << "Could not open /proc/cpuinfo";
  1351     } else {
  1349     } else {
  1352         QTextStream prodinfo(&file);
  1350         QTextStream prodinfo(&file);
  1353         QString line = prodinfo.readLine();
  1351         QString line = prodinfo.readLine();
  1354         while (!line.isNull()) {
  1352         while (!line.isNull()) {
  1355             line = prodinfo.readLine();
  1353             line = prodinfo.readLine();
  1372     if(halIsAvailable) {
  1370     if(halIsAvailable) {
  1373 #if !defined(QT_NO_DBUS)
  1371 #if !defined(QT_NO_DBUS)
  1374         QHalInterface iface2;
  1372         QHalInterface iface2;
  1375         if (iface2.isValid()) {
  1373         if (iface2.isValid()) {
  1376             QStringList capList;
  1374             QStringList capList;
  1377             capList << QLatin1String("input.keyboard") 
  1375             capList << QLatin1String("input.keyboard")
  1378                     << QLatin1String("input.keys")
  1376                     << QLatin1String("input.keys")
  1379                     << QLatin1String("input.keypad") 
  1377                     << QLatin1String("input.keypad")
  1380                     << QLatin1String("input.mouse") 
  1378                     << QLatin1String("input.mouse")
  1381                     << QLatin1String("input.tablet")
  1379                     << QLatin1String("input.tablet")
  1382                     << QLatin1String("input.touchpad");
  1380                     << QLatin1String("input.touchpad");
  1383             for(int i = 0; i < capList.count(); i++) {
  1381             for(int i = 0; i < capList.count(); i++) {
  1384                 QStringList list = iface2.findDeviceByCapability(capList.at(i));
  1382                 QStringList list = iface2.findDeviceByCapability(capList.at(i));
  1385                 if(!list.isEmpty()) {
  1383                 if(!list.isEmpty()) {
  1416     filters << "event*";
  1414     filters << "event*";
  1417     const QStringList inputList = inputDir.entryList( filters ,QDir::Dirs, QDir::Name);
  1415     const QStringList inputList = inputDir.entryList( filters ,QDir::Dirs, QDir::Name);
  1418     foreach(const QString inputFileName, inputList) {
  1416     foreach(const QString inputFileName, inputList) {
  1419         QFile file(inputsPath+inputFileName+"/device/name");
  1417         QFile file(inputsPath+inputFileName+"/device/name");
  1420         if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
  1418         if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
  1421             qWarning()<<"File not opened";
  1419             qDebug()<<"File not opened";
  1422         } else {
  1420         } else {
  1423             QString strvalue;
  1421             QString strvalue;
  1424             strvalue = file.readLine();
  1422             strvalue = file.readLine();
  1425             file.close();
  1423             file.close();
  1426             if(strvalue.contains("keyboard",Qt::CaseInsensitive)) {
  1424             if(strvalue.contains("keyboard",Qt::CaseInsensitive)) {
  1459         const QStringList list = iface.findDeviceByCapability("battery");
  1457         const QStringList list = iface.findDeviceByCapability("battery");
  1460         if(!list.isEmpty()) {
  1458         if(!list.isEmpty()) {
  1461             foreach(const QString dev, list) {
  1459             foreach(const QString dev, list) {
  1462                 QHalDeviceInterface ifaceDevice(dev);
  1460                 QHalDeviceInterface ifaceDevice(dev);
  1463                 if (ifaceDevice.isValid()) {
  1461                 if (ifaceDevice.isValid()) {
  1464 //                    qWarning() << ifaceDevice.getPropertyString("battery.type")
       
  1465 //                            << ifaceDevice.getPropertyInt("battery.charge_level.percentage");
       
  1466                     if(!ifaceDevice.getPropertyBool("battery.present")
  1462                     if(!ifaceDevice.getPropertyBool("battery.present")
  1467                         && (ifaceDevice.getPropertyString("battery.type") != "pda"
  1463                         && (ifaceDevice.getPropertyString("battery.type") != "pda"
  1468                              || ifaceDevice.getPropertyString("battery.type") != "primary")) {
  1464                              || ifaceDevice.getPropertyString("battery.type") != "primary")) {
  1469                         qWarning() << "XXXXXXXXXXXXX";
       
  1470                         return 0;
  1465                         return 0;
  1471                     } else {
  1466                     } else {
  1472                         level = ifaceDevice.getPropertyInt("battery.charge_level.percentage");
  1467                         level = ifaceDevice.getPropertyInt("battery.charge_level.percentage");
  1473                         return level;
  1468                         return level;
  1474                     }
  1469                     }
  1477         }
  1472         }
  1478 #endif
  1473 #endif
  1479     } else {
  1474     } else {
  1480         QFile infofile("/proc/acpi/battery/BAT0/info");
  1475         QFile infofile("/proc/acpi/battery/BAT0/info");
  1481         if (!infofile.open(QIODevice::ReadOnly)) {
  1476         if (!infofile.open(QIODevice::ReadOnly)) {
  1482             //   qWarning() << "Could not open /proc/acpi/battery/BAT0/info";
       
  1483             return QSystemDeviceInfo::NoBatteryLevel;
  1477             return QSystemDeviceInfo::NoBatteryLevel;
  1484         } else {
  1478         } else {
  1485             QTextStream batinfo(&infofile);
  1479             QTextStream batinfo(&infofile);
  1486             QString line = batinfo.readLine();
  1480             QString line = batinfo.readLine();
  1487             while (!line.isNull()) {
  1481             while (!line.isNull()) {
  1488                 if(line.contains("design capacity")) {
  1482                 if(line.contains("design capacity")) {
  1489                     levelWhenFull = line.split(" ").at(1).trimmed().toFloat();
  1483                     levelWhenFull = line.split(" ").at(1).trimmed().toFloat();
  1490                     //qWarning() << levelWhenFull;
       
  1491                     infofile.close();
  1484                     infofile.close();
  1492                     break;
  1485                     break;
  1493                 }
  1486                 }
  1494                 line = batinfo.readLine();
  1487                 line = batinfo.readLine();
  1495             }
  1488             }
  1496             infofile.close();
  1489             infofile.close();
  1497         }
  1490         }
  1498 
  1491 
  1499         QFile statefile("/proc/acpi/battery/BAT0/state");
  1492         QFile statefile("/proc/acpi/battery/BAT0/state");
  1500         if (!statefile.open(QIODevice::ReadOnly)) {
  1493         if (!statefile.open(QIODevice::ReadOnly)) {
  1501             //     qWarning() << "Could not open /proc/acpi/battery/BAT0/state";
       
  1502             return QSystemDeviceInfo::NoBatteryLevel;
  1494             return QSystemDeviceInfo::NoBatteryLevel;
  1503         } else {
  1495         } else {
  1504             QTextStream batstate(&statefile);
  1496             QTextStream batstate(&statefile);
  1505             QString line = batstate.readLine();
  1497             QString line = batstate.readLine();
  1506             while (!line.isNull()) {
  1498             while (!line.isNull()) {
  1507                 if(line.contains("remaining capacity")) {
  1499                 if(line.contains("remaining capacity")) {
  1508                     level = line.split(" ").at(1).trimmed().toFloat();
  1500                     level = line.split(" ").at(1).trimmed().toFloat();
  1509                     //qWarning() << level;
       
  1510                     statefile.close();
  1501                     statefile.close();
  1511                     break;
  1502                     break;
  1512                 }
  1503                 }
  1513                 line = batstate.readLine();
  1504                 line = batstate.readLine();
  1514             }
  1505             }
  1552        }
  1543        }
  1553 
  1544 
  1554 #else
  1545 #else
  1555        QFile statefile("/proc/acpi/battery/BAT0/state");
  1546        QFile statefile("/proc/acpi/battery/BAT0/state");
  1556        if (!statefile.open(QIODevice::ReadOnly)) {
  1547        if (!statefile.open(QIODevice::ReadOnly)) {
  1557            //  qWarning() << "Could not open /proc/acpi/battery/BAT0/state";
       
  1558        } else {
  1548        } else {
  1559            QTextStream batstate(&statefile);
  1549            QTextStream batstate(&statefile);
  1560            QString line = batstate.readLine();
  1550            QString line = batstate.readLine();
  1561            while (!line.isNull()) {
  1551            while (!line.isNull()) {
  1562                if(line.contains("charging state")) {
  1552                if(line.contains("charging state")) {
  1595                  if (!dbusConnection.connect("org.bluez",
  1585                  if (!dbusConnection.connect("org.bluez",
  1596                                            reply.value().path(),
  1586                                            reply.value().path(),
  1597                                             "org.bluez.Adapter",
  1587                                             "org.bluez.Adapter",
  1598                                             "PropertyChanged",
  1588                                             "PropertyChanged",
  1599                                             this,SLOT(bluezPropertyChanged(QString, QDBusVariant)))) {
  1589                                             this,SLOT(bluezPropertyChanged(QString, QDBusVariant)))) {
  1600                      qWarning() << "bluez could not connect signal";
  1590                      qDebug() << "bluez could not connect signal";
  1601                  }
  1591                  }
  1602              }
  1592              }
  1603          }
  1593          }
  1604      }
  1594      }
  1605  }
  1595  }