<commit_before>//===========================================
//  PC-BSD source code
//  Copyright (c) 2015, PC-BSD Software/iXsystems
//  Available under the 3-clause BSD license
//  See the LICENSE file for full details
//===========================================
#include "sysadm-general.h"
#include "sysadm-systeminfo.h"
#include "sysadm-global.h"

using namespace sysadm;

//PLEASE: Keep the functions in the same order as listed in pcbsd-general.h


//Battery Availability
QJsonObject SysInfo::batteryInfo(){
  QJsonObject retObject;
  bool ok;

  int val = General::RunCommand("apm -l").toInt(&ok);
  if ( ok && (val >= 0 && val <= 100) ) {
    retObject.insert("battery", "true");
  } else {
    retObject.insert("battery", "false");
    return retObject;
  }

  // We have a battery, return info about it
  //Battery Charge Level
  QString tmp;
  tmp.setNum(val);
  retObject.insert("level", tmp);

  //Battery Charging State
  int state = General::RunCommand("apm -a").toInt(&ok);
  if ( ok && state == 0 )
    retObject.insert("status", "offline");
  else if ( ok && state == 1 )
    retObject.insert("status", "charging");
  else if ( ok && state == 2 )
    retObject.insert("status", "backup");
  else
    retObject.insert("status", "unknown");

  return retObject;
}

// ==== ExternalDevicePaths() ====
QJsonObject SysInfo::externalDevicePaths() {
  QJsonObject retObject;

  //Returns: QStringList[<type>::::<filesystem>::::<path>]
  //Note: <type> = [USB, HDRIVE, DVD, SDCARD, UNKNOWN]
  QStringList devs = General::RunCommand("mount").split("\n");

  //Now check the output
  for(int i=0; i<devs.length(); i++){
    if(devs[i].startsWith("/dev/")){
      devs[i].replace("\t"," ");<commit_msg>Add the "timeleft":"<seconds>" to the battery info<commit_after>//===========================================
//  PC-BSD source code
//  Copyright (c) 2015, PC-BSD Software/iXsystems
//  Available under the 3-clause BSD license
//  See the LICENSE file for full details
//===========================================
#include "sysadm-general.h"
#include "sysadm-systeminfo.h"
#include "sysadm-global.h"

using namespace sysadm;

//PLEASE: Keep the functions in the same order as listed in pcbsd-general.h


//Battery Availability
QJsonObject SysInfo::batteryInfo(){
  QJsonObject retObject;
  bool ok;

  int val = General::RunCommand("apm -l").toInt(&ok);
  if ( ok && (val >= 0 && val <= 100) ) {
    retObject.insert("battery", "true");
  } else {
    retObject.insert("battery", "false");
    return retObject;
  }

  // We have a battery, return info about it
  //Battery Charge Level
  QString tmp;
  tmp.setNum(val);
  retObject.insert("level", tmp);

  //Battery Charging State
  int state = General::RunCommand("apm -a").toInt(&ok);
  if ( ok && state == 0 )
    retObject.insert("status", "offline");
  else if ( ok && state == 1 )
    retObject.insert("status", "charging");
  else if ( ok && state == 2 )
    retObject.insert("status", "backup");
  else
    retObject.insert("status", "unknown");

  int timeleft = General::RunCommand("apm -t").toInt(&ok);
  if ( ok ) {
    tmp.setNum(timeleft);
    retObject.insert("timeleft", tmp);
  } else {
    retObject.insert("timeleft", "-1");
  }


  return retObject;
}

// ==== ExternalDevicePaths() ====
QJsonObject SysInfo::externalDevicePaths() {
  QJsonObject retObject;

  //Returns: QStringList[<type>::::<filesystem>::::<path>]
  //Note: <type> = [USB, HDRIVE, DVD, SDCARD, UNKNOWN]
  QStringList devs = General::RunCommand("mount").split("\n");

  //Now check the output
  for(int i=0; i<devs.length(); i++){
    if(devs[i].startsWith("/dev/")){
      devs[i].replace("\t"," ");
{'fraction_non_alphanumeric': 0.21811713191023535, 'fraction_numerical': 0.007389162561576354, 'mean_word_length': 3.939189189189189, 'pattern_counts': {'":': 1, '<': 16, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5540950', 'n_tokens_mistral': 1246, 'n_tokens_neox': 1179, 'n_words': 304}