Exemplo n.º 1
0
QVariant IAPConfPrivate::valueToVariant(ConnSettingsValue *value)
{
    if (value == 0 || value->type == CONN_SETTINGS_VALUE_INVALID) {
        return QVariant();
    }

    switch(value->type) {
    
    case CONN_SETTINGS_VALUE_BOOL:
        return QVariant(value->value.bool_val ? true : false);
    
    case CONN_SETTINGS_VALUE_STRING:
        return QVariant(QString::fromUtf8(value->value.string_val));
    
    case CONN_SETTINGS_VALUE_DOUBLE:
        return QVariant(value->value.double_val);
    
    case CONN_SETTINGS_VALUE_INT:
        return QVariant(value->value.int_val);
    
    case CONN_SETTINGS_VALUE_LIST: {
        // At least with GConf backend connsettings returns byte array as list
        // of ints, first check for that case
        if (value->value.list_val && value->value.list_val[0]) {
            bool canBeConvertedToByteArray = true;
            for (int idx = 0; value->value.list_val[idx]; idx++) {
                ConnSettingsValue *val = value->value.list_val[idx];
                if (val->type != CONN_SETTINGS_VALUE_INT
                     || val->value.int_val > 255
                     || val->value.int_val < 0) {
                    canBeConvertedToByteArray = false;
                    break;
                }
            }

            if (canBeConvertedToByteArray) {
                QByteArray array;
                for (int idx = 0; value->value.list_val[idx]; idx++) {
                    array.append(value->value.list_val[idx]->value.int_val);
                }
                return array;
            }

	    // Create normal list
	    QVariantList list;
	    for (int idx = 0; value->value.list_val[idx]; idx++) {
	      list.append(valueToVariant(value->value.list_val[idx]));
	    }
	    return list;
        }
    }
    
    case CONN_SETTINGS_VALUE_BYTE_ARRAY:
        return QByteArray::fromRawData((char *)value->value.byte_array.val, 
                                       value->value.byte_array.len);
    
    default:
        return QVariant();
    }
}
Exemplo n.º 2
0
void LInputDevice::readProperties(){
  QList<int> props = devProps.keys();
  //XINPUT UTILITY USAGE (alternative to XCB which actually works right now)
  QStringList info = LUtils::getCmdOutput("xinput list-props "+QString::number(devID));
  for(int i=0; i<props.length(); i++){
    propData PROP = devProps[props[i]];
    QStringList filter = info.filter(" ("+QString::number(PROP.id)+"):");
    if(filter.length()==1){
      QString val = filter.first().section("):",1,-1).simplified();
      //Now figure out what type of value this is and save it into the QVariant
      QVariant variant;
      if(val.split(", ").length()>1){
        //some kind of array
        QList<QVariant> list;
        QStringList valList = val.split(", ");
        for(int j=0; j<valList.length(); j++){ list << valueToVariant(valList[j]); }
        variant = QVariant(list);
      }else{
	variant = valueToVariant(val);
      }
      PROP.value = variant;
    }
    devProps.insert(props[i], PROP);
  }

//XCB Code (non-functional - issue with library itself? 12/6/16 - Ken Moore)
  /*QVariant result;
  if(!devProps.contains(prop)){qDebug() << "Invalid Property"; return result; }
  //Now generate the property request
  xcb_input_get_device_property_cookie_t cookie = xcb_input_get_device_property_unchecked( QX11Info::connection(), devProps.value(prop).atom, \
		XCB_ATOM_ATOM, 0, 1000, devID, 0);
  xcb_input_get_device_property_reply_t *reply = xcb_input_get_device_property_reply(QX11Info::connection(), cookie, NULL);
  if(reply==0){ qDebug() << "Could not get reply!"; return result; }
  //Now read off the value of the property
  if(ATOM_FLOAT==0){
    xcb_intern_atom_reply_t *ar = xcb_intern_atom_reply(QX11Info::connection(), \
			xcb_intern_atom(QX11Info::connection(), 0, 1, "FLOAT"), NULL);
    if(ar!=0){
      ATOM_FLOAT = ar->atom;
      free(ar);
    }
  }
  //Turn the reply into the proper items array (depends on format of the return data)
  xcb_input_get_device_property_items_t items;
  qDebug() <<QByteArray::fromRawData( (char*)(xcb_input_get_device_property_items(reply) ) , reply->num_items);
  void *buffer = xcb_input_get_device_property_items(reply);
  xcb_input_get_device_property_items_serialize( &buffer, reply->num_items, reply->format, &items);

  //if(reply->num_items > 0){
  //qDebug() << "Format:" << reply->format << "Length:" << length;
  //qDebug() << "Response Type:" << reply->response_type << "Pads:" << reply->pad0 << reply->pad1;
    switch(reply->type){
	case XCB_ATOM_INTEGER:
	  //qDebug() << "Got Integer";

	  break;
	case XCB_ATOM_CARDINAL:
	  //qDebug() << "Got Cardinal";

	  break;
	case XCB_ATOM_STRING:
	  qDebug() << "Got String:";
	  if(reply->format==8){
	    result.setValue( QByteArray::fromRawData( (char*) xcb_input_get_device_property_items_data_8(&items), sizeof(xcb_input_get_device_property_items_data_8(&items))/sizeof(char)) );
	  }
	  break;
	case XCB_ATOM_ATOM:
	  //qDebug() << "Got Atom";

	  break;
	default:
	    qDebug() << "Other Type:" << reply->type;
    }
  //}
  free(reply); //done with this structure
  return result;*/
}