void QbsManager::addProfile(const QString &name, const QVariantMap &data)
{
    const QString base = QLatin1String(PROFILES_PREFIX) + name;
    const QVariantMap::ConstIterator cend = data.constEnd();
    for (QVariantMap::ConstIterator it = data.constBegin(); it != cend; ++it)
        m_settings->setValue(base + it.key(), it.value());
}
void QOfonoRadioSettings::setModemPath(const QString &path)
{
    if (path == d_ptr->modemPath ||
            path.isEmpty())
        return;

    QStringList removedProperties = d_ptr->properties.keys();

    delete d_ptr->radioSettings;
    d_ptr->radioSettings = new OfonoRadioSettings("org.ofono", path, QDBusConnection::systemBus(),this);

    if (d_ptr->radioSettings->isValid()) {
        d_ptr->modemPath = path;

        connect(d_ptr->radioSettings,SIGNAL(PropertyChanged(QString,QDBusVariant)),
                this,SLOT(propertyChanged(QString,QDBusVariant)));

        QVariantMap properties = d_ptr->radioSettings->GetProperties().value();
        for (QVariantMap::ConstIterator it = properties.constBegin();
             it != properties.constEnd(); ++it) {
            updateProperty(it.key(), it.value());
            removedProperties.removeOne(it.key());
        }

        Q_EMIT modemPathChanged(path);
    }

    foreach (const QString &p, removedProperties)
        updateProperty(p, QVariant());
}
void QOfonoMessageWaiting::connectOfono()
{
    bool wasReady = isReady();
    // FIXME: Clearing properties here results in false *Changed signal
    // emissions. Ideally ready() should not be derived from
    // properties.isEmpty(). Also compare with QOfonoSimManager.
    if (d_ptr->messageWaiting) {
        delete d_ptr->messageWaiting;
        d_ptr->messageWaiting = 0;
        d_ptr->properties.clear();
    }

    d_ptr->messageWaiting = new OfonoMessageWaiting("org.ofono", d_ptr->modemPath, QDBusConnection::systemBus(),this);

    if (d_ptr->messageWaiting->isValid()) {
        connect(d_ptr->messageWaiting,SIGNAL(PropertyChanged(QString,QDBusVariant)),
                this,SLOT(propertyChanged(QString,QDBusVariant)));

        QDBusPendingReply<QVariantMap> reply;
        reply = d_ptr->messageWaiting->GetProperties();
        reply.waitForFinished();
        if (reply.isError()) {
            Q_EMIT getPropertiesFailed();
        } else {
            QVariantMap properties = reply.value();
            for (QVariantMap::ConstIterator it = properties.constBegin();
                    it != properties.constEnd(); ++it) {
                updateProperty(it.key(), it.value());
            }
        }
    }

    if (wasReady != isReady())
        Q_EMIT readyChanged();
}
void JsonDbSortingListModelPrivate::fetchPartition(int index, bool reset)
{
    Q_Q(JsonDbSortingListModel);
    if (index >= partitionObjects.count())
        return;

    if (state != JsonDbSortingListModel::Querying) {
        state =  JsonDbSortingListModel::Querying;
        emit q->stateChanged(state);
    }
    RequestInfo &r = partitionObjectDetails[index];
    QPointer<JsonDbPartition> p = partitionObjects[index];
    Q_ASSERT(p);
    if (reset) {
        r.lastSize = -1;
        r.lastOffset = 0;
    } else {
        r.lastOffset += chunkSize;
    }
    QJsonDbReadRequest *request = valueRequests[index]->newRequest(index);
    request->setQuery(query);
    QVariantMap::ConstIterator i = queryBindings.constBegin();
    while (i != queryBindings.constEnd()) {
        request->bindValue(i.key(), QJsonValue::fromVariant(i.value()));
        ++i;
    }
    request->setProperty("queryOffset", r.lastOffset);
    request->setQueryLimit(chunkSize);
    request->setPartition(p->name());
    JsonDatabase::sharedConnection().send(request);
}
Esempio n. 5
0
void QbsManager::addProfile(const QString &name, const QVariantMap &data)
{
    qbs::Profile profile(name, settings());
    const QVariantMap::ConstIterator cend = data.constEnd();
    for (QVariantMap::ConstIterator it = data.constBegin(); it != cend; ++it)
        profile.setValue(it.key(), it.value());
}
// unite two QVariantMaps, but don't generate duplicate keys
static QVariantMap &operator+=(QVariantMap &lhs, const QVariantMap &rhs)
{
    QVariantMap::ConstIterator it = rhs.constBegin(),
                              end = rhs.constEnd();
    for ( ; it != end; ++it)
        lhs.insert(it.key(), it.value());
    return lhs;
}
Esempio n. 7
0
//метод конвертирует QVariant в DataManager,
// а также определяет и устанавливает тип узла объекта
DataManager DataManager::fromVariant(QVariant qvar)
{
    DataManager temp;
    if(qvar.type() == QVariant::Map)
    {
        QVariantMap qmap = qvar.toMap();
        temp.setType(T_MAP);
        temp.setParent(&object);
        //qDebug() << "map this: " << ;
        QVariantMap::ConstIterator i = qmap.constBegin();
        while(i != qmap.constEnd())
        {
            temp.append(fromVariant(i.value()), i.key());
            i++;
        }
    }
    else if(qvar.type() == QVariant::List)
    {
        QVariantList qlist = qvar.toList();
        temp.setType(T_LIST);
        temp.setParent(&array);
        //qDebug() << "list this: " << &array;
        for(int i=0; i<qlist.size(); i++)
        {
            temp.append(fromVariant(qlist.at(i)), "");
        }
    }
    else if(qvar.type() == QVariant::String)
    {
        //qDebug() << "string this: " << &stringValue;
        temp.setType(T_STRING);
        temp.setValue(qvar.toString());
        //temp.setParent(this);
    }
    else if(qvar.type() == QVariant::Int)
    {
        //qDebug() << "int this: " << &intValue;
        temp.setType(T_INT);
        temp.setValue(qvar.toInt());
        //temp.setParent(this);
    }
    else if(qvar.type() == QVariant::Double)
    {
        //qDebug() << "double this: " << &doubleValue;
        temp.setType(T_DOUBLE);
        temp.setValue(qvar.toDouble());
        //temp.setParent(this);
    }
    else if(qvar.type() == QVariant::Bool)
    {
        qDebug() << "bool this: " << &boolValue;
        temp.setType(T_BOOL);
        temp.setValue(qvar.toBool());
        //temp.setParent(this);
    }
    return temp;
}
Esempio n. 8
0
int HyvesAPI::doMethodJson(const QString &method, const QString &jsonParameters) {
	
	QVariantMap variantMap = Util::jsonToVariantMap(jsonParameters);
	GenusApis::OAuthUtil::ParameterMap parameterMap;
	for (QVariantMap::ConstIterator it = variantMap.begin();
	     it != variantMap.end(); ++it) {
		parameterMap[it.key()] = it.value().toString();
	}
	
	int id = m_d->genusApis->doMethod(method, parameterMap, m_d->accessToken);
	m_d->log->debug(QString("Calling method '%1' (request #%2)").arg(method).arg(id));
	return id;
}
Esempio n. 9
0
void StatisticsHelperPrivate::sendInfo()
{
	QUrl url(QLatin1String("http://qutim.org/stats"));
	Config config = Profile::instance()->config();
	config.beginGroup(QLatin1String("statistics"));
	url.addQueryItem(QLatin1String("api"), QString::number(2));
	QString id = config.value(QLatin1String("key"), QString());
	if (!id.isEmpty())
		url.addQueryItem(QLatin1String("key"), id);
	for (QVariantMap::ConstIterator it = systemInfo.constBegin();
	     it != systemInfo.constEnd(); ++it) {
		url.addQueryItem(it.key(), it.value().toString());
	}
	QObject::connect(manager.get(QNetworkRequest(url)), SIGNAL(finished()),
	                 q_func(), SLOT(_q_on_finished()));
}
void
ImporterSqlConnection::slotQuery( const QString &query, const QVariantMap &bindValues,
                                  bool* const ok )
{
    Q_ASSERT( this->thread() == ThreadWeaver::Thread::currentThread() );

    if( ok != 0 )
        *ok = false;

    QSqlDatabase db = connection();
    if( !db.isOpen() )
        return;

    QSqlQuery q( db );
    q.setForwardOnly( true );
    q.prepare( query );
    for( QVariantMap::ConstIterator bindValue = bindValues.constBegin();
            bindValue != bindValues.constEnd(); ++bindValue )
        q.bindValue( bindValue.key(), bindValue.value() );

    if( q.exec() )
    {
        if( ok != 0 )
            *ok = true;

        m_result.reserve( q.size() );
        while( q.next() )
        {
            const int fields = q.record().count();

            QVariantList row;
            row.reserve( fields );
            for( int field = 0; field < fields; ++field )
                row.append( q.value( field ) );

            m_result.append( row );
        }
    }
    else
        warning() << __PRETTY_FUNCTION__ << q.lastError().text();

    // This is a stupid QSqlDatabase connection manager; we don't want to leave connection
    // open unless we're inside a transaction.
    if( !isTransaction() )
        db.close();
}
Esempio n. 11
0
void QgsValueMapConfigDlg::setConfig( const QVariantMap &config )
{
  tableWidget->clearContents();
  for ( int i = tableWidget->rowCount() - 1; i > 0; i-- )
  {
    tableWidget->removeRow( i );
  }

  int row = 0;
  QVariantMap values = config.value( QStringLiteral( "map" ) ).toMap();
  for ( QVariantMap::ConstIterator mit = values.constBegin(); mit != values.constEnd(); mit++, row++ )
  {
    if ( mit.value().isNull() )
      setRow( row, mit.key(), QString() );
    else
      setRow( row, mit.value().toString(), mit.key() );
  }
}
Esempio n. 12
0
void StatisticsHelperPrivate::_q_on_finished()
{
	QNetworkReply *reply = qobject_cast<QNetworkReply*>(q_func()->sender());
	Q_ASSERT(reply);
	if (reply->error() == QNetworkReply::NoError) {
		QString key = QLatin1String(reply->readAll());
		if (!key.isEmpty()) {
			Config config = Profile::instance()->config();
			config.beginGroup(QLatin1String("statistics"));
			config.setValue(QLatin1String("key"), key);
			for (QVariantMap::ConstIterator it = systemInfo.constBegin();
			     it != systemInfo.constEnd(); ++it) {
				config.setValue(it.key(), it.value());
			}
		}
	}
//	q_func()->deleteLater();
}
void QgsValueMapSearchWidgetWrapper::initWidget( QWidget *editor )
{
  mComboBox = qobject_cast<QComboBox *>( editor );

  if ( mComboBox )
  {
    const QVariantMap cfg = config();
    QVariantMap::ConstIterator it = cfg.constBegin();
    mComboBox->addItem( tr( "Please select" ), "" );

    while ( it != cfg.constEnd() )
    {
      if ( it.value() != QgsValueMapFieldFormatter::NULL_VALUE )
        mComboBox->addItem( it.key(), it.value() );
      ++it;
    }
    connect( mComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsValueMapSearchWidgetWrapper::comboBoxIndexChanged );
  }
}
Esempio n. 14
0
void StatisticsHelperPrivate::init()
{
	QRect size = qApp->desktop()->screenGeometry();
	systemInfo.insert(QLatin1String("os"), SystemInfo::getVersion());
	systemInfo.insert(QLatin1String("short"), SystemInfo::getName());
	systemInfo.insert(QLatin1String("full"), SystemInfo::getFullName());
	systemInfo.insert(QLatin1String("version"), versionString());
	systemInfo.insert(QLatin1String("qt"), QLatin1String(qVersion()));
	systemInfo.insert(QLatin1String("wordSize"), QString::number(QSysInfo::WordSize));
	systemInfo.insert(QLatin1String("width"), QString::number(size.width()));
	systemInfo.insert(QLatin1String("height"), QString::number(size.height()));
	systemInfo.insert(QLatin1String("locale"), QLocale::system().name());
	
	Config config = Profile::instance()->config();
	config.beginGroup(QLatin1String("statistics"));
	bool denied = config.value(QLatin1String("denied"), false);
	bool automatic = config.value(QLatin1String("automatic"), false);
	if (denied && automatic) {
		action = StatisticsHelper::DeniedToSend;
		return;
	}
	QString key = config.value(QLatin1String("key"), QString());
	if (key.isEmpty()) {
		action = StatisticsHelper::NeedToAskInit;
		return;
	}
	for (QVariantMap::ConstIterator it = systemInfo.constBegin();
	     it != systemInfo.constEnd(); ++it) {
		if (config.value(it.key(), QString()) != it.value().toString()) {
			if (automatic) {
				sendInfo();
				action = StatisticsHelper::NothingToAsk;
				return;
			}
			action = StatisticsHelper::NeedToAskUpdate;
			return;
		}
	}
	action = StatisticsHelper::NothingToAsk;
}
void JsonDbSortingListModelPrivate::createOrUpdateNotification(int index)
{
    Q_Q(JsonDbSortingListModel);
    if (index >= partitionObjects.count())
        return;
    clearNotification(index);
    QJsonDbWatcher *watcher = new QJsonDbWatcher();
    watcher->setQuery(query);
    watcher->setWatchedActions(QJsonDbWatcher::Created | QJsonDbWatcher::Updated |QJsonDbWatcher::Removed);
    watcher->setPartition(partitionObjects[index]->name());
    QVariantMap::ConstIterator i = queryBindings.constBegin();
    while (i != queryBindings.constEnd()) {
        watcher->bindValue(i.key(), QJsonValue::fromVariant(i.value()));
        ++i;
    }
    QObject::connect(watcher, SIGNAL(notificationsAvailable(int)),
                     q, SLOT(_q_notificationsAvailable()));
    QObject::connect(watcher, SIGNAL(error(QtJsonDb::QJsonDbWatcher::ErrorCode,QString)),
                     q, SLOT(_q_notificationError(QtJsonDb::QJsonDbWatcher::ErrorCode,QString)));
    JsonDatabase::sharedConnection().addWatcher(watcher);
    partitionObjectDetails[index].watcher = watcher;
}
Esempio n. 16
0
int main(int argc, char **argv)
{
    QCoreApplication app(argc, argv);
    QStringList args = app.arguments();
    QFile vcf, xml;

    if (args.count() > 1) {
        vcf.setFileName(args[1]);

        if (not vcf.open(QFile::ReadOnly)) {
            qWarning("Cannot open %s for reading: %s",
                     qPrintable(vcf.fileName()),
                     qPrintable(vcf.errorString()));
            return 1;
        }
    } else {
        if (not vcf.open(stdin, QFile::ReadOnly)) {
            qWarning("Cannot open STDIN for reading: %s",
                     qPrintable(vcf.errorString()));
            return 1;
        }
    }

    QVersitReader reader(&vcf);

    if (not reader.startReading() ||
        not reader.waitForFinished() ||
        QVersitReader::NoError != reader.error()) {
        qWarning("Cannot read vcard: rc=%d", reader.error());
        return 1;
    }

    QVersitContactImporter importer;

    if (not importer.importDocuments(reader.results())) {
        typedef QMap<int, QVersitContactImporter::Error> ErrorMap;
        const ErrorMap errors = importer.errors();

        for(ErrorMap::ConstIterator it = errors.constBegin(); it != errors.constEnd(); ++it) {
            qWarning("Cannot convert contact #%d: %d", it.key(), it.value());
        }

        return 1;
    }

    if (args.count() > 2) {
        xml.setFileName(args[2]);

        if (not xml.open(QFile::WriteOnly)) {
            qWarning("Cannot open %s for writing: %s",
                     qPrintable(xml.fileName()),
                     qPrintable(xml.errorString()));
            return 1;
        }
    } else {
        if (not xml.open(stdout, QFile::WriteOnly)) {
            qWarning("Cannot open STDIN for writing: %s",
                     qPrintable(xml.errorString()));
            return 1;
        }
    }

    QTextStream out(&xml);
    out << "<Contacts>\n";

    foreach(const QContact &contact, importer.contacts()) {
        out << "  <Contact id=\"" << makeIri(contact) << "\">\n";

        foreach(const QContactDetail &detail, contact.details()) {
            QVariantMap fields = detail.variantValues();

            out << "    <" << detail.definitionName();

            if (not detail.detailUri().isEmpty()) {
                out << " id=\"" << detail.detailUri() << "\"";
            }

            out << ">";

            if (fields.count() > 1 || fields.keys().first() != detail.definitionName()) {
                QVariantMap::ConstIterator it;

                for(it = fields.constBegin(); it != fields.constEnd(); ++it) {
                    out << "\n      ";
                    out << "<" << it.key() << ">";
                    out << toString(it.value());
                    out << "</" << it.key() << ">";
                }

                out << "\n    ";
            } else {
                out << toString(fields.values().first());
            }

            out << "</" << detail.definitionName() << ">\n";
        }

        out << "  </Contact>\n";
    }

    out << "</Contacts>\n";

    return 0;
}