void Ut_NotificationPreviewPresenter::testNotificationNotShownIfNoSummaryOrBody()
{
    QFETCH(QString, previewSummary);
    QFETCH(QString, previewBody);
    QFETCH(int, changedSignalCount);
    QFETCH(int, presentedSignalCount);
    QFETCH(bool, windowVisible);

    NotificationPreviewPresenter presenter;
    QSignalSpy changedSpy(&presenter, SIGNAL(notificationChanged()));
    QSignalSpy presentedSpy(&presenter, SIGNAL(notificationPresented(uint)));

    // Create notification
    LipstickNotification *notification = new LipstickNotification;
    QVariantHash hints;
    hints.insert(NotificationManager::HINT_PREVIEW_SUMMARY, previewSummary);
    hints.insert(NotificationManager::HINT_PREVIEW_BODY, previewBody);
    notification->setHints(hints);
    notificationManagerNotification.insert(1, notification);
    presenter.updateNotification(1);

    // Check whether the expected notification is signaled onwards
    QCOMPARE(changedSpy.count(), changedSignalCount);
    QCOMPARE(presentedSpy.count(), presentedSignalCount);

    QCOMPARE(homeWindowVisible.isEmpty(), !windowVisible);
    if (windowVisible) {
        // Check whether the window was shown
        QCOMPARE(homeWindowVisible[homeWindows.first()], windowVisible);
    }
}
Ejemplo n.º 2
0
Menu *FileEnginePrivate::createMenu(const QString &id, QObject *parent)
{
    settings->beginGroup(id);

    Menu *menu = new Menu(id);

    menu->setName(settings->value(QStringLiteral("Name")).toString());
    menu->setLocations(settings->value(QStringLiteral("Locations")).toStringList());
    menu->setAutoAddPages(settings->value(QStringLiteral("AutoAddPages")).toBool());

    QList<QVariantHash> urls;

    int size = settings->beginReadArray(QStringLiteral("urls"));
    for (int i = 0; i < size; ++i) {
        settings->setArrayIndex(i);
        QVariantHash data;
        // TODO read all data
        data.insert(QStringLiteral("id"), i);
        data.insert(QStringLiteral("text"), settings->value(QStringLiteral("text")));
        data.insert(QStringLiteral("url"), settings->value(QStringLiteral("url")));
        data.insert(QStringLiteral("attr"), settings->value(QStringLiteral("attr")));
        urls.append(data);
    }
    settings->endArray();

    menu->setEntries(urls);

    settings->endGroup(); // menu name

    return menu;
}
Ejemplo n.º 3
0
QVariantHash FSTReader::parseMapping(QIODevice* device) {
    QVariantHash properties;
    
    QByteArray line;
    while (!(line = device->readLine()).isEmpty()) {
        if ((line = line.trimmed()).startsWith('#')) {
            continue; // comment
        }
        QList<QByteArray> sections = line.split('=');
        if (sections.size() < 2) {
            continue;
        }
        QByteArray name = sections.at(0).trimmed();
        if (sections.size() == 2) {
            properties.insertMulti(name, sections.at(1).trimmed());
            
        } else if (sections.size() == 3) {
            QVariantHash heading = properties.value(name).toHash();
            heading.insertMulti(sections.at(1).trimmed(), sections.at(2).trimmed());
            properties.insert(name, heading);
            
        } else if (sections.size() >= 4) {
            QVariantHash heading = properties.value(name).toHash();
            QVariantList contents;
            for (int i = 2; i < sections.size(); i++) {
                contents.append(sections.at(i).trimmed());
            }
            heading.insertMulti(sections.at(1).trimmed(), contents);
            properties.insert(name, heading);
        }
    }
    
    return properties;
}
Ejemplo n.º 4
0
QVariantHash WeatherWidget::getCurrentData()
{
    QVariantHash data;
    data.insert("weatherCurrent", weatherDataWidget->getCurrentData());
    data.insert("weatherForecast", forecastDataWidget->getCurrentData());
    return data;
}
Ejemplo n.º 5
0
void JMUCUser::setMUCAffiliationAndRole(MUCRoom::Affiliation affiliation, MUCRoom::Role role)
{
	int oldPriority = priority();
	d_func()->affiliation = affiliation;
	d_func()->role = role;
	int newPriority = priority();
	emit priorityChanged(oldPriority, newPriority);
	
	QString iconName;
	if (affiliation == MUCRoom::AffiliationOwner)
		iconName = QStringLiteral("user-role-owner");
	else if (affiliation == MUCRoom::AffiliationAdmin)
		iconName = QStringLiteral("user-role-admin");
	else if (role == MUCRoom::RoleModerator)
		iconName = QStringLiteral("user-role-moderator");
	else if (role == MUCRoom::RoleVisitor)
		iconName = QStringLiteral("user-role-visitor");
	else if (affiliation == MUCRoom::AffiliationMember)
		iconName = QStringLiteral("user-role-member");
	else
		iconName = QStringLiteral("user-role-participant");
	
	QVariantHash clientInfo;
	ExtensionIcon extIcon(iconName);
	clientInfo.insert("id", "mucRole");
	clientInfo.insert("icon", QVariant::fromValue(extIcon));
	clientInfo.insert("priorityInContactList", 30);
	setExtendedInfo("mucRole", clientInfo);
}
Ejemplo n.º 6
0
QString TemplateLayout::generate()
{
	int progress = 0;
	int totalWork = getTotalWork(PrintOptions);
	QString templateName;

	QString htmlContent;
	m_engine = new Grantlee::Engine(this);

	QSharedPointer<Grantlee::FileSystemTemplateLoader> m_templateLoader =
		QSharedPointer<Grantlee::FileSystemTemplateLoader>(new Grantlee::FileSystemTemplateLoader());
	m_templateLoader->setTemplateDirs(QStringList() << getSubsurfaceDataPath("printing_templates"));
	m_engine->addTemplateLoader(m_templateLoader);

	Grantlee::registerMetaType<Dive>();
	Grantlee::registerMetaType<template_options>();
	Grantlee::registerMetaType<print_options>();

	QVariantHash mapping;
	QVariantList diveList;

	struct dive *dive;
	int i;
	for_each_dive (i, dive) {
		//TODO check for exporting selected dives only
		if (!dive->selected && PrintOptions->print_selected)
			continue;
		Dive d(dive);
		diveList.append(QVariant::fromValue(d));
		progress++;
		emit progressUpdated(progress * 100.0 / totalWork);
	}
	mapping.insert("dives", diveList);
	mapping.insert("template_options", QVariant::fromValue(*templateOptions));
	mapping.insert("print_options", QVariant::fromValue(*PrintOptions));

	Grantlee::Context c(mapping);

	if (PrintOptions->p_template == print_options::ONE_DIVE) {
		templateName = "one_dive.html";
	} else if (PrintOptions->p_template == print_options::TWO_DIVE) {
		templateName = "two_dives.html";
	} else if (PrintOptions->p_template == print_options::CUSTOM) {
		templateName = "custom.html";
	}
	Grantlee::Template t = m_engine->loadByName(templateName);
	if (!t || t->error()) {
		qDebug() << "Can't load template";
		return htmlContent;
	}

	htmlContent = t->render(&c);

	if (t->error()) {
		qDebug() << "Can't render template";
		return htmlContent;
	}
	return htmlContent;
}
Ejemplo n.º 7
0
void TestMustache::testHelpers()
{
	QVariantHash args;
	args.insert("name", "Jim Smith");
	args.insert("age", 42);

	QString output = Mustache::renderTemplate("Hello {{name}}, you are {{age}}", args);
	QCOMPARE(output, QString("Hello Jim Smith, you are 42"));
}
Ejemplo n.º 8
0
 foreach (const QString& lib, Toolkit::librariesWithExamples())
 {
     QVariantHash libDescription;
     libDescription.insert("name", lib);
     QVariantList examples;
     foreach (const QString &example, Toolkit::findLibraryExamples(lib))
         examples.append(example);
     libDescription.insert("examples", examples);
     librariesWithExamples << libDescription;
 }
LipstickNotification *createNotification(uint id, Urgency urgency = Normal)
{
    QVariantHash hints;
    hints.insert(NotificationManager::HINT_PREVIEW_SUMMARY, "summary");
    hints.insert(NotificationManager::HINT_PREVIEW_BODY, "body");
    hints.insert(NotificationManager::HINT_URGENCY, static_cast<int>(urgency));
    LipstickNotification *notification = new LipstickNotification("ut_notificationpreviewpresenter", id, "", "", "", QStringList(), hints, -1);
    notificationManagerNotification.insert(id, notification);
    return notification;
}
LipstickNotification *createNotification(uint id, int urgency = 0)
{
    LipstickNotification *notification = new LipstickNotification;
    QVariantHash hints;
    hints.insert(NotificationManager::HINT_PREVIEW_SUMMARY, "summary");
    hints.insert(NotificationManager::HINT_PREVIEW_BODY, "body");
    hints.insert(NotificationManager::HINT_URGENCY, urgency);
    notification->setHints(hints);
    notificationManagerNotification.insert(id, notification);
    return notification;
}
Ejemplo n.º 11
0
void JSoftwareDetection::setClientInfo(JContactResource *resource, const QString &client, const QString &icon)
{
	QVariantHash clientInfo;
	ExtensionIcon extIcon(icon);
	clientInfo.insert("id", "client");
	clientInfo.insert("title", tr("Possible client"));
	clientInfo.insert("icon", QVariant::fromValue(extIcon));
	clientInfo.insert("description", client);
	clientInfo.insert("priority", 85);
	resource->setExtendedInfo("client", clientInfo);
}
Ejemplo n.º 12
0
QVariantHash WeatherDataWidget::getCurrentData()
{
    QVariantHash data;
    if(m_data)
    {
        data.insert("currentTemp", formatTemperatureString(m_data->currentTemp(), m_globalSettings->temperatureFormat()));
        data.insert("currentCity", m_data->currentCity());
        data.insert("currentImage", iconNameToPixmap(m_data->icon()).mid(1));
    }
    return data;
}
LipstickNotification *createNotification(uint id, int urgency = 0)
{
    LipstickNotification *notification = new LipstickNotification;
    QVariantHash hints;
    hints.insert(NotificationManager::HINT_FEEDBACK, "feedback");
    hints.insert(NotificationManager::HINT_URGENCY, urgency);
    notification->setHints(hints);
    notificationManagerNotification.insert(id, notification);
    gNotificationPreviewPresenterStub->stubSetReturnValue("notification", notification);
    return notification;
}
Ejemplo n.º 14
0
void ScanFoldersModel::makePersistent()
{
    QVariantHash dirs;

    for (const PathData *pathData : asConst(m_pathList)) {
        if (pathData->downloadType == CUSTOM_LOCATION)
            dirs.insert(Utils::Fs::fromNativePath(pathData->watchPath), Utils::Fs::fromNativePath(pathData->downloadPath));
        else
            dirs.insert(Utils::Fs::fromNativePath(pathData->watchPath), pathData->downloadType);
    }

    Preferences::instance()->setScanDirs(dirs);
}
Ejemplo n.º 15
0
	bool JPersonTuneRegistrator::eventFilter(QObject *obj, QEvent *ev)
	{
		if (ev->type() == ExtendedInfosEvent::eventType() && obj == JProtocol::instance()) {
			ExtendedInfosEvent *event = static_cast<ExtendedInfosEvent*>(ev);
			QVariantHash extStatus;
			extStatus.insert("id", "tune");
			extStatus.insert("name", QT_TRANSLATE_NOOP("Tune", "Tune").toString());
			extStatus.insert("settingsDescription",
							 QT_TRANSLATE_NOOP("Tune", "Show tune icon").toString());
			event->addInfo("tune", extStatus);
		}
		return false;
	}
Ejemplo n.º 16
0
void SessionPrivate::_q_saveSession(Context *c)
{
    // fix cookie before we send headers
    saveSessionExpires(c);

    // Force extension of session_expires before finalizing headers, so a pos
    // up to date. First call to session_expires will extend the expiry, methods
    // just return the previously extended value.
    Session::expires(c);

    // Persist data
    static Session *session = c->plugin<Session*>();
    if (!session) {
        qCCritical(C_SESSION) << "Session plugin not registered";
        return;
    }
    saveSessionExpires(c);

    if (!c->property(SESSION_UPDATED).toBool()) {
        return;
    }
    SessionStore *store = session->d_ptr->store;
    QVariantHash sessionData = c->property(SESSION_VALUES).toHash();
    sessionData.insert(QStringLiteral("__updated"), QDateTime::currentMSecsSinceEpoch() / 1000);

    const QString sid = c->property(SESSION_ID).toString();
    store->storeSessionData(c, sid,  QStringLiteral("session"), sessionData);
}
Ejemplo n.º 17
0
// Convert a Python object to a QVariantHash and return true if there was no
// error.
bool Chimera::to_QVariantHash(PyObject *py, QVariantHash &cpp) const
{
    Q_ASSERT(PyDict_CheckExact(py));

    PyObject *key_obj, *val_obj;
    SIP_SSIZE_T i;

    i = 0;
    while (PyDict_Next(py, &i, &key_obj, &val_obj))
    {
        int key_state, val_state, iserr = 0;

        QString *key = reinterpret_cast<QString *>(sipForceConvertToType(
                key_obj, sipType_QString, NULL, SIP_NOT_NONE, &key_state,
                &iserr));

        QVariant *val = reinterpret_cast<QVariant *>(sipForceConvertToType(
                val_obj, sipType_QVariant, NULL, SIP_NOT_NONE, &val_state,
                &iserr));

        if (iserr)
            return false;

        cpp.insert(*key, *val);

        sipReleaseType(key, sipType_QString, key_state);
        sipReleaseType(val, sipType_QVariant, val_state);
    }

    return true;
}
Ejemplo n.º 18
0
  void TabEdit::changePOTCAR(QListWidgetItem *item)
  {
    QSettings settings; // Already set up in avogadro/src/main.cpp

    // Get symbol and filename
    QStringList strl = item->text().split(":");
    QString symbol   = strl.at(0).trimmed();
    QString filename = strl.at(1).trimmed();

    QStringList files;
    QString path = settings.value("xtalopt/templates/potcarPath", "").toString();
    QFileDialog dialog (NULL, QString("Select pot file for atom %1").arg(symbol), path);
    dialog.selectFile(filename);
    dialog.setFileMode(QFileDialog::ExistingFile);
    if (dialog.exec()) {
      files = dialog.selectedFiles();
      if (files.size() != 1) { return;} // Only one file per element
      filename = files.first();
      settings.setValue("xtalopt/templates/potcarPath", dialog.directory().absolutePath());
    }
    else { return;} // User cancel file selection.
    // "POTCAR info" is of type
    // QList<QHash<QString, QString> >
    // e.g. a list of hashes containing
    // [atomic symbol : pseudopotential file] pairs
    QVariantList potcarInfo = m_opt->optimizer()->getData("POTCAR info").toList();
    QVariantHash hash = potcarInfo.at(ui_list_optStep->currentRow()).toHash();
    hash.insert(symbol,QVariant(filename));
    potcarInfo.replace(ui_list_optStep->currentRow(), hash);
    m_opt->optimizer()->setData("POTCAR info", potcarInfo);
    qobject_cast<VASPOptimizer*>(m_opt->optimizer())->buildPOTCARs();
    updateEditWidget();
  }
Ejemplo n.º 19
0
void BookWindow::renderBooks() const
{
    int rows = model->rowCount();
    QVariantHash mapping;
    QVariantList bookList;
    for (int row = 0; row < rows; ++row)
    {
      QString title = model->index(row, 1).data().toString();
      QString author = model->index(row, 2).data().toString();
      QString genre = model->index(row, 3).data().toString();
      int rating = model->index(row, 5).data().toInt();
      QObject *book = new BookWrapper(author, title, genre, rating, this);
      QVariant var = QVariant::fromValue(book);
      bookList.append(var);
    }
    mapping.insert("books", bookList);

    QString themeName = ui.exportTheme->currentText();

    Grantlee::Context c(mapping);

    Grantlee::Template t = m_engine->loadByName( themeName + ".html" );
    if (!t)
    {
      QMessageBox::critical(this, "Unable to load template",
                QString( "Error loading template: %1" ).arg( themeName + ".html" ) );
      return;
    }

    if ( t->error() )
    {
      QMessageBox::critical(this, "Unable to load template",
                QString( "Error loading template: %1" ).arg( t->errorString() ) );
      return;
    }

    bool ok;
    QString text = QInputDialog::getText(this, tr("Export Location"),
                                         tr("file name:"), QLineEdit::Normal,
                                         QDir::home().absolutePath() + "/book_export.html", &ok);
    if (!ok || text.isEmpty())
      return;

    QFile file( text );
    if ( !file.open( QIODevice::WriteOnly | QIODevice::Text ) )
      return;

    QString content = t->render(&c);

    if ( t->error() )
    {
      QMessageBox::critical(this, "Unable render template",
                QString( "Error rendering template: %1" ).arg( t->errorString() ) );
      return;
    }

    file.write(content.toLocal8Bit());
    file.close();

}
/*!
  \~english
  Returns the rendering data of the partial template given by \a templateName.

  \~japanese
  部分テンプレート \a templateName に変数 \a vars を設定した描画データを返す
*/
QString TActionController::getRenderingData(const QString &templateName, const QVariantHash &vars)
{
    T_TRACEFUNC("templateName: %s", qPrintable(templateName));

    // Creates view-object
    QStringList names = templateName.split("/");
    if (names.count() != 2) {
        tError("Invalid patameter: %s", qPrintable(templateName));
        return QString();
    }

    TDispatcher<TActionView> viewDispatcher(viewClassName(names[0], names[1]));
    TActionView *view = viewDispatcher.object();
    if (!view) {
        return QString();
    }

    QVariantHash hash = allVariants();
    for (QHashIterator<QString, QVariant> i(vars); i.hasNext(); ) {
        i.next();
        hash.insert(i.key(), i.value()); // item's value of same key is replaced
    }

    view->setController(this);
    view->setVariantHash(hash);
    return view->toString();  
}
Ejemplo n.º 21
0
void Tohkbd::notificationSend(QString summary, QString body)
{

    QDBusInterface notifyCall("org.freedesktop.Notifications", "/org/freedesktop/Notifications", "");

    QVariantHash hints;
    hints.insert("x-nemo-preview-summary", summary);

    QList<QVariant> args;
    args.append("tohkbd2");
    args.append(ssNotifyReplacesId);
    args.append("icon-m-notifications");
    args.append(summary);
    args.append(body);
    args.append((QStringList() << "default" << ""));
    args.append(hints);
    args.append(-1);

    QDBusMessage notifyCallReply = notifyCall.callWithArgumentList(QDBus::AutoDetect, "Notify", args);

    QList<QVariant> outArgs = notifyCallReply.arguments();

    ssNotifyReplacesId = outArgs.at(0).toInt();

    printf("Notification sent, got id %d\n", ssNotifyReplacesId);
}
Ejemplo n.º 22
0
void IfChangedNode::render( OutputStream *stream, Context *c ) const
{
    if ( c->lookup( QLatin1String( "forloop" ) ).isValid() && ( !c->lookup( QLatin1String( "forloop" ) ).toHash().contains( m_id ) ) ) {
        m_lastSeen = QVariant();
        QVariantHash hash = c->lookup( QLatin1String( "forloop" ) ).toHash();
        hash.insert( m_id, 1 );
        c->insert( QLatin1String( "forloop" ), hash );
    }

    QString watchedString;
    QTextStream watchedTextStream( &watchedString );
    QSharedPointer<OutputStream> watchedStream = stream->clone( &watchedTextStream );
    if ( m_filterExpressions.size() == 0 ) {
        m_trueList.render( watchedStream.data(), c );
    }
    QListIterator<FilterExpression> i( m_filterExpressions );
    QVariantList watchedVars;
    while ( i.hasNext() ) {
        QVariant var = i.next().resolve( c );
        if ( !var.isValid() ) {
            // silent error
            return;
        }
        watchedVars.append( var );
    }

    // At first glance it looks like m_last_seen will always be invalid,
    // But it will change because render is called multiple times by the parent
    // {% for %} loop in the template.
    if (( watchedVars != m_lastSeen.toList() )
            || ( !watchedString.isEmpty() && ( watchedString != m_lastSeen.toString() ) ) ) {
        bool firstLoop = !m_lastSeen.isValid();
        if ( !watchedString.isNull() )
            m_lastSeen = watchedString;
        else
            m_lastSeen = watchedVars;
        c->push();
        QVariantHash hash;
        // TODO: Document this.
        hash.insert( QLatin1String( "firstloop" ), firstLoop );
        c->insert( QLatin1String( "ifchanged" ), hash );
        m_trueList.render( stream, c );
        c->pop();
    } else if ( !m_falseList.isEmpty() ) {
        m_falseList.render( stream, c );
    }
}
Ejemplo n.º 23
0
void RegroupNode::render( OutputStream *stream, Context *c ) const
{
  Q_UNUSED( stream )
  QVariantList objList = m_target.toList( c );
  if ( objList.isEmpty() ) {
    c->insert( m_varName, QVariantHash() );
    return;
  }

  // What's going on?
  //
  // objList is a flat list of objects with a common parameter. For example, Person objects with
  // a name parameter. The list is already sorted.
  // Say the objList contains ["David Beckham", "David Blain", "Keira Nightly"] etc.
  // We want to regroup the list into separate lists of people with the same first name.
  // ie objHash should be: {"David": ["David Beckham", "David Blain"], "Keira": ["Keira Nightly"]}
  //
  // We then insert the objHash into the Context ready for rendering later in a for loop.

  QVariantList contextList;
  const QString keyName = getSafeString( m_expression.resolve( c ) );
  QListIterator<QVariant> i( objList );
  while ( i.hasNext() ) {
    const QVariant var = i.next();
    c->push();
    c->insert( QLatin1String( "var" ), var );
    const QString key = getSafeString( FilterExpression( QLatin1String( "var." ) + keyName, 0 ).resolve( c ) );
    c->pop();
    QVariantHash hash;
    if ( contextList.size() > 0 ) {
      QVariant hashVar = contextList.last();
      hash = hashVar.toHash();
    }
    if ( !hash.contains( QLatin1String( "grouper" ) ) || hash.value( QLatin1String( "grouper" ) ) != key ) {
      QVariantHash newHash;
      hash.insert( QLatin1String( "grouper" ), key );
      hash.insert( QLatin1String( "list" ), QVariantList() );
      contextList.append( newHash );
    }

    QVariantList list = hash.value( QLatin1String( "list" ) ).toList();
    list.append( var );
    hash.insert( QLatin1String( "list" ), list );
    contextList[contextList.size() - 1] = hash;
  }
  c->insert( m_varName, contextList );
}
Ejemplo n.º 24
0
void ShutdownScreen::createAndPublishNotification(const QString &category, const QString &body)
{
    NotificationManager *manager = NotificationManager::instance();
    QVariantHash hints;
    hints.insert(NotificationManager::HINT_CATEGORY, category);
    hints.insert(NotificationManager::HINT_PREVIEW_BODY, body);
    manager->Notify(qApp->applicationName(), 0, QString(), QString(), QString(), QStringList(), hints, -1);
}
Ejemplo n.º 25
0
QVariant SessionPrivate::initializeSessionData(Session *session, Context *c)
{
    QVariantHash ret;
    const quint64 now = QDateTime::currentMSecsSinceEpoch() / 1000;
    ret.insert(QStringLiteral("__created"), now);
    ret.insert(QStringLiteral("__updated"), now);

    if (session->d_ptr->verifyAddress) {
        ret.insert(QStringLiteral("__address"), c->request()->address().toString());
    }

    if (session->d_ptr->verifyUserAgent) {
        ret.insert(QStringLiteral("__user_agent"), c->request()->userAgent());
    }

    return ret;
}
Ejemplo n.º 26
0
void Browser::quickstart_p(bool updateHistory)
{
    // generate the quickstart page
    QVariantHash mapping;
    initializeContext(mapping);

    QVariantList exampleCategories;
    foreach (const QString& cat, Toolkit::findExampleCategories())
    {
        QVariantHash catDescription;
        catDescription.insert("name", cat);
        QVariantList examples;
        foreach (const QString &example, Toolkit::findExamples(cat))
            examples.append(example);
        catDescription.insert("examples", examples);
        exampleCategories << catDescription;
    }
Ejemplo n.º 27
0
QVariantHash ForecastDataWidget::getCurrentData()
{
    QVariantHash data;
    if(m_data.size()>0)
    {
        for(int a = 0;a<m_data.size();a++)
        {
            ForecastData* forecastData = m_data.at(a);
            QVariantHash forecastDataHash;
            forecastDataHash.insert("day", forecastData->day());
            forecastDataHash.insert("high", formatTemperatureString(m_data[a]->highTemp(), m_globalSettings->temperatureFormat()));
            forecastDataHash.insert("low", formatTemperatureString(m_data[a]->lowTemp(), m_globalSettings->temperatureFormat()));
            forecastDataHash.insert("image", iconNameToPixmap(forecastData->icon()).mid(1));
            data.insert("day"+QString::number(a), forecastDataHash);
        }
    }
    return data;
}
Ejemplo n.º 28
0
void
CredentialsManager::keychainJobFinished( QKeychain::Job* j )
{
    tDebug() << Q_FUNC_INFO;
    if ( QKeychain::ReadPasswordJob* readJob = qobject_cast< QKeychain::ReadPasswordJob* >( j ) )
    {
        if ( readJob->error() == QKeychain::NoError )
        {
            tDebug() << "QtKeychain readJob for" << readJob->service() << "/"
                     << readJob->key() << "finished without errors";

            QVariant creds;
            QJson::Parser parser;
            bool ok;

            creds = parser.parse( readJob->textData().toLatin1(), &ok );

            QVariantMap map = creds.toMap();
            QVariantHash hash;
            for ( QVariantMap::const_iterator it = map.constBegin();
                  it != map.constEnd(); ++it )
            {
                hash.insert( it.key(), it.value() );
            }
            creds = QVariant( hash );

            if ( !ok || creds.toHash().isEmpty() )
            {
                creds = QVariant( readJob->textData() );
            }

            m_credentials.insert( CredentialsStorageKey( readJob->service(), readJob->key() ), creds );
        }
        else
        {
            tDebug() << "QtKeychain readJob for" << readJob->service() << "/" << readJob->key() << "finished with error:" << j->error() << j->errorString();
        }

        m_readJobs[ readJob->service() ].removeOne( readJob );

        if ( m_readJobs[ readJob->service() ].isEmpty() )
        {
            emit serviceReady( readJob->service() );
        }
    }
    else if ( QKeychain::WritePasswordJob* writeJob = qobject_cast< QKeychain::WritePasswordJob* >( j ) )
    {
        tLog() << Q_FUNC_INFO << "QtKeychain writeJob for" << writeJob->service() << "/" << writeJob->key() << "finished"
               << ( ( j->error() == QKeychain::NoError ) ? "without error" : j->errorString() );
    }
    else if ( QKeychain::DeletePasswordJob* deleteJob = qobject_cast< QKeychain::DeletePasswordJob* >( j ) )
    {
        tLog() << Q_FUNC_INFO << "QtKeychain deleteJob for" << deleteJob->service() << "/" << deleteJob->key() << "finished"
               << ( ( j->error() == QKeychain::NoError ) ? "without error" : j->errorString() );
    }
    j->deleteLater();
}
Ejemplo n.º 29
0
const QVariantHash AbstractParam::attributes() const {
    QVariantHash a;
    const QMetaObject *mo = metaObject();
    for (int k = AbstractParam::staticMetaObject.propertyOffset(); k < mo->propertyCount(); ++k) {
        const QMetaProperty mp = mo->property(k);
        a.insert(mp.name(), this->property(mp.name()));
    }
    return a;
}
/*!
  Use the validate(const QVariantHash &) function instead.
  Obsolete function. 
 */
bool TFormValidator::validate(const QHash<QString, QString> &hash)
{
    QVariantHash vhash;
    for (QHashIterator<QString, QString> it(hash); it.hasNext(); ) {
        it.next();
        vhash.insert(it.key(), it.value());
    }
    return validate(vhash);
}