45 #include <conn_settings.h> 49 #define QSTRING_TO_CONST_CSTR(str) \ 50 str.toUtf8().constData() 65 ConnSettingsValue *value = conn_settings_value_new();
67 qWarning(
"IAPConf: Unable to create new ConnSettingsValue");
71 switch(variant.
type()) {
74 value->type = CONN_SETTINGS_VALUE_INVALID;
79 value->type = CONN_SETTINGS_VALUE_STRING;
80 value->value.string_val = valueStr;
85 value->type = CONN_SETTINGS_VALUE_INT;
86 value->value.int_val = variant.
toInt();
91 value->type = CONN_SETTINGS_VALUE_DOUBLE;
92 value->value.double_val = variant.
toDouble();
96 value->type = CONN_SETTINGS_VALUE_BOOL;
97 value->value.bool_val = variant.
toBool() ? 1 : 0;
102 value->type = CONN_SETTINGS_VALUE_BYTE_ARRAY;
103 value->value.byte_array.len = array.
size();
104 value->value.byte_array.val = (
unsigned char *)malloc(array.
size());
105 memcpy(value->value.byte_array.val, array.
constData(), array.
size());
111 ConnSettingsValue **list_val = (ConnSettingsValue **)malloc(
112 (list.
size() + 1) *
sizeof(ConnSettingsValue *));
114 for (
int idx = 0; idx < list.
size(); idx++) {
117 list_val[list.
size()] = 0;
119 value->type = CONN_SETTINGS_VALUE_LIST;
120 value->value.list_val = list_val;
125 qWarning(
"IAPConf: Can not handle QVariant of type %d",
127 conn_settings_value_destroy(value);
136 if (value == 0 || value->type == CONN_SETTINGS_VALUE_INVALID) {
140 switch(value->type) {
142 case CONN_SETTINGS_VALUE_BOOL:
143 return QVariant(value->value.bool_val ?
true :
false);
145 case CONN_SETTINGS_VALUE_STRING:
148 case CONN_SETTINGS_VALUE_DOUBLE:
149 return QVariant(value->value.double_val);
151 case CONN_SETTINGS_VALUE_INT:
152 return QVariant(value->value.int_val);
154 case CONN_SETTINGS_VALUE_LIST: {
157 if (value->value.list_val && value->value.list_val[0]) {
158 bool canBeConvertedToByteArray =
true;
159 for (
int idx = 0; value->value.list_val[idx]; idx++) {
160 ConnSettingsValue *val = value->value.list_val[idx];
161 if (val->type != CONN_SETTINGS_VALUE_INT
162 || val->value.int_val > 255
163 || val->value.int_val < 0) {
164 canBeConvertedToByteArray =
false;
169 if (canBeConvertedToByteArray) {
171 for (
int idx = 0; value->value.list_val[idx]; idx++) {
172 array.
append(value->value.list_val[idx]->value.int_val);
179 for (
int idx = 0; value->value.list_val[idx]; idx++) {
186 case CONN_SETTINGS_VALUE_BYTE_ARRAY:
188 value->value.byte_array.len);
200 d_ptr->
settings = conn_settings_open(CONN_SETTINGS_CONNECTION,
203 qWarning(
"IAPConf: Unable to open ConnSettings for %s",
221 conn_settings_value_destroy(val);
231 char **ids = conn_settings_list_ids(CONN_SETTINGS_CONNECTION);
237 for (
int idx = 0; ids[idx]; idx++) {
The QVariant class acts like a union for the most common Qt data types.
QVariant valueToVariant(ConnSettingsValue *value)
QByteArray & append(char c)
Appends the character ch to this byte array.
The QByteArray class provides an array of bytes.
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
QList< QVariant > toList() const
Returns the variant as a QVariantList if the variant has type() List or StringList ; otherwise return...
bool toBool() const
Returns the variant as a bool if the variant has type() Bool.
The QString class provides a Unicode character string.
QByteArray toByteArray() const
Returns the variant as a QByteArray if the variant has type() ByteArray or String (converted using QS...
IAPConf(const QString &iap_id)
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
void append(const T &t)
Inserts value at the end of the list.
ConnSettingsValue * variantToValue(const QVariant &variant)
const T & at(int i) const
Returns the item at index position i in the list.
static QByteArray fromRawData(const char *, int size)
Constructs a QByteArray that uses the first size bytes of the data array.
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Q_CORE_EXPORT void qWarning(const char *,...)
#define QSTRING_TO_CONST_CSTR(str)
const char * constData() const
Returns a pointer to the data stored in the byte array.
Type type() const
Returns the storage type of the value stored in the variant.
int size() const
Returns the number of items in the list.
static void getAll(QList< QString > &all_iaps, bool return_path=false)
int size() const
Returns the number of bytes in this byte array.
double toDouble(bool *ok=0) const
Returns the variant as a double if the variant has type() Double , QMetaType::Float ...
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
QVariant value(const QString &key) const