void Session::setValue(Cutelyst::Context *c, const QString &key, const QVariant &value) { QVariantHash session = SessionPrivate::loadSession(c).toHash(); if (value.isNull()) { session.remove(key); } else { session.insert(key, value); } c->setProperty(SESSION_VALUES, session); c->setProperty(SESSION_SAVE, true); }
void SpotifyAccount::delayedInit() { connect( AtticaManager::instance(), SIGNAL( resolverInstalled( QString ) ), this, SLOT( resolverInstalled( QString ) ) ); const Attica::Content res = AtticaManager::instance()->resolverForId( s_resolverId ); const AtticaManager::ResolverState state = AtticaManager::instance()->resolverState( res ); const QString path = configuration().value( "path" ).toString(); // Manual path override if ( !checkForResolver() && state != AtticaManager::Uninstalled ) { // If the user manually deleted the resolver, mark it as uninstalled, so we re-fetch for the user QVariantHash conf = configuration(); conf.remove( "path" ); setConfiguration( conf ); sync(); AtticaManager::instance()->uninstallResolver( res ); } else if ( state == AtticaManager::Installed || !path.isEmpty() ) { if ( !path.isEmpty() ) { QFileInfo info( path ); // Resolver was deleted, so abort and remove our manual override, as it's no longer valid if ( !info.exists() ) { QVariantHash conf = configuration(); conf.remove( "path" ); setConfiguration( conf ); sync(); return; } } hookupResolver(); } }
void ModifyPrinter::save() { if (m_changes) { QVariantHash args = m_changedValues; QString fileName; qCDebug(PM_CONFIGURE_PRINTER) << args; if (args.contains("ppd-name") && args["ppd-name"].type() == QVariant::Bool) { fileName = ui->makeCB->itemData(ui->makeCB->currentIndex(), PPDFile).toString(); args.remove("ppd-name"); } qCDebug(PM_CONFIGURE_PRINTER) << fileName; QPointer<KCupsRequest> request = new KCupsRequest; if (m_isClass) { request->addOrModifyClass(m_destName, args); } else { request->addOrModifyPrinter(m_destName, args, fileName); } request->waitTillFinished(); if (request) { if (!request->hasError()) { if (m_changedValues.contains("ppd-name")) { emit ppdChanged(); } request->getPrinterAttributes(m_destName, m_isClass, neededValues()); request->waitTillFinished(); if (!request->hasError() && !request->printers().isEmpty()) { KCupsPrinter printer = request->printers().first(); setValues(printer); } } else { KMessageBox::detailedSorry(this, m_isClass ? i18nc("@info", "Failed to configure class") : i18nc("@info", "Failed to configure printer"), request->errorMsg(), i18nc("@title:window", "Failed")); } request->deleteLater(); } } }
void TemplatesPlugin::createActivity(const QDBusVariant &_values) { using namespace kamd::utils; QVariantHash values = _values.variant().toHash(); auto takeStringValue = [&values] (const QString &key) { auto result = values[key].toString(); values.remove(key); return result; }; const QString name = takeStringValue("activity.name"); const QString description = takeStringValue("activity.description"); const QString icon = takeStringValue("activity.icon"); // Creating the activity, and getting the id const QString id = Plugin::retrieve<QString>( m_activities, "AddActivity", "QString", Q_ARG(QString, name)); // Saving the provided data to the configuration file KConfigGroup pluginConfig(config()); KConfigGroup activityConfig(&pluginConfig, id); for_each_assoc(values, [&activityConfig] (const QString &key, const QVariant &value) { activityConfig.writeEntry(key, value); }); activityConfig.sync(); // Changing the icon and description of the activity Plugin::invoke<Qt::DirectConnection>( m_activities, "SetActivityDescription", Q_ARG(QString, id), Q_ARG(QString, description)); Plugin::invoke<Qt::DirectConnection>( m_activities, "SetActivityIcon", Q_ARG(QString, id), Q_ARG(QString, icon)); }
void Session::deleteValue(Context *c, const QString &key) { QVariant session = c->property(SESSION_VALUES); if (session.isNull()) { session = SessionPrivate::loadSession(c); if (session.isNull()) { static Session *plugin = c->plugin<Session*>(); if (!plugin) { qCCritical(C_SESSION) << "Session plugin not registered"; return; } SessionPrivate::createSessionIdIfNeeded(plugin, c, plugin->d_ptr->sessionExpires); session = SessionPrivate::initializeSessionData(plugin, c); } } QVariantHash data = session.toHash(); data.remove(key); c->setProperty(SESSION_VALUES, data); c->setProperty(SESSION_UPDATED, true); }
void TestMustache::testSections() { QVariantHash map = contactInfo("John Smith", "*****@*****.**"); QVariantList contacts; contacts << contactInfo("James Dee", "*****@*****.**"); contacts << contactInfo("Jim Jones", "*****@*****.**"); map["contacts"] = contacts; QString _template = "Name: {{name}}, Email: {{email}}\n" "{{#contacts}} {{name}} - {{email}}\n{{/contacts}}" "{{^contacts}} No contacts{{/contacts}}"; QString expectedOutput = "Name: John Smith, Email: [email protected]\n" " James Dee - [email protected]\n" " Jim Jones - [email protected]\n"; Mustache::Renderer renderer; Mustache::QtVariantContext context(map); QString output = renderer.render(_template, &context); QCOMPARE(output, expectedOutput); // test inverted sections map.remove("contacts"); context = Mustache::QtVariantContext(map); output = renderer.render(_template, &context); expectedOutput = "Name: John Smith, Email: [email protected]\n" " No contacts"; QCOMPARE(output, expectedOutput); // test with an empty list instead of an empty key map["contacts"] = QVariantHash(); context = Mustache::QtVariantContext(map); output = renderer.render(_template, &context); QCOMPARE(output, expectedOutput); }