Example #1
0
void Utility::sortFilenames(QStringList& fileNames)
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
    QCollator collator;
    collator.setNumericMode(true);
    collator.setCaseSensitivity(Qt::CaseInsensitive);
    qSort(fileNames.begin(), fileNames.end(), collator);
#else
    fileNames.sort(Qt::CaseInsensitive);
#endif
}
Example #2
0
static PyObject *meth_QCollator_setCaseSensitivity(PyObject *sipSelf, PyObject *sipArgs)
{
    PyObject *sipParseErr = NULL;

    {
        Qt::CaseSensitivity a0;
        QCollator *sipCpp;

        if (sipParseArgs(&sipParseErr, sipArgs, "BE", &sipSelf, sipType_QCollator, &sipCpp, sipType_Qt_CaseSensitivity, &a0))
        {
            sipCpp->setCaseSensitivity(a0);

            Py_INCREF(Py_None);
            return Py_None;
        }
    }

    /* Raise an exception if the arguments couldn't be parsed. */
    sipNoMethod(sipParseErr, sipName_QCollator, sipName_setCaseSensitivity, doc_QCollator_setCaseSensitivity);

    return NULL;
}
Example #3
0
AcceptLanguageDialog::AcceptLanguageDialog(const QString &languages, QWidget *parent) : Dialog(parent),
	m_ui(new Ui::AcceptLanguageDialog)
{
	m_ui->setupUi(this);

	m_model = new QStandardItemModel(this);
	m_model->setHorizontalHeaderLabels(QStringList({tr("Name"), tr("Code")}));

	m_ui->languagesViewWidget->setModel(m_model);

	QStringList chosenLanguages(languages.split(QLatin1Char(','), QString::SkipEmptyParts));

	for (int i = 0; i < chosenLanguages.count(); ++i)
	{
		addLanguage(chosenLanguages.at(i).section(QLatin1Char(';'), 0, 0));
	}

	const QList<QLocale> locales(QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry));
	QVector<QPair<QString, QString> > entries;

	for (int i = 0; i < locales.count(); ++i)
	{
		const QLocale locale(locales.at(i));

		if (locale != QLocale::c())
		{
			if (locale.nativeCountryName().isEmpty() || locale.nativeLanguageName().isEmpty())
			{
				entries.append({tr("Unknown [%1]").arg(locale.bcp47Name()), locale.bcp47Name()});
			}
			else
			{
				entries.append({QStringLiteral("%1 - %2 [%3]").arg(locale.nativeLanguageName()).arg(locale.nativeCountryName()).arg(locale.bcp47Name()), locale.bcp47Name()});
			}
		}
	}

	QCollator collator;
	collator.setCaseSensitivity(Qt::CaseInsensitive);

	qSort(entries.begin(), entries.end(), [&](const QPair<QString, QString> &first, const QPair<QString, QString> &second)
	{
		return (collator.compare(first.first, second.first) < 0);
	});

	entries.prepend(QPair<QString, QString>(tr("Any other"), QLatin1String("*")));
	entries.prepend(QPair<QString, QString>(tr("System language (%1 - %2)").arg(QLocale::system().nativeLanguageName()).arg(QLocale::system().nativeCountryName()), QString("system")));

	for (int i = 0; i < entries.count(); ++i)
	{
		m_ui->languagesComboBox->addItem(entries.at(i).first, entries.at(i).second);
	}

	m_ui->moveDownButton->setIcon(ThemesManager::createIcon(QLatin1String("arrow-down")));
	m_ui->moveUpButton->setIcon(ThemesManager::createIcon(QLatin1String("arrow-up")));
	m_ui->languagesComboBox->installEventFilter(this);

	connect(m_ui->moveDownButton, &QToolButton::clicked, m_ui->languagesViewWidget, &ItemViewWidget::moveDownRow);
	connect(m_ui->moveUpButton, &QToolButton::clicked, m_ui->languagesViewWidget, &ItemViewWidget::moveUpRow);
	connect(m_ui->removeButton, &QToolButton::clicked, m_ui->languagesViewWidget, &ItemViewWidget::removeRow);
	connect(m_ui->addButton, &QToolButton::clicked, this, &AcceptLanguageDialog::addNewLanguage);
	connect(m_ui->languagesViewWidget, &ItemViewWidget::canMoveDownChanged, m_ui->moveDownButton, &QToolButton::setEnabled);
	connect(m_ui->languagesViewWidget, &ItemViewWidget::canMoveUpChanged, m_ui->moveUpButton, &QToolButton::setEnabled);
	connect(m_ui->languagesViewWidget, &ItemViewWidget::needsActionsUpdate, this, &AcceptLanguageDialog::updateActions);
}
Example #4
0
void JsonParser::parseAndSet(const QByteArray &data, const QString label)
{
    //qDebug() << "parseAndSet data:" << data;
    QJsonDocument jsonDocument = QJsonDocument::fromJson(data);
    QJsonObject jsonObject = jsonDocument.object();

    // get project versions (7.0, 8.0, ...)
    for (QJsonObject::Iterator itProjectVersions  = jsonObject.begin();
                               itProjectVersions != jsonObject.end();
                               itProjectVersions++)
    {
        QString project = itProjectVersions.key();
        QString projectUrl = itProjectVersions.value().toObject()["url"].toString();

        // get projects (imx6, Wetek, ...)
        QJsonObject val = itProjectVersions.value().toObject()["project"].toObject();
        for (QJsonObject::Iterator itProjects  = val.begin();
                                   itProjects != val.end();
                                   itProjects++)
        {
            QString projectId = itProjects.key();
            QString projectName = itProjects.value().toObject()["displayName"].toString();

            // skip Virtual
            if (projectId == "Virtual.x86_64")
                continue;

            if (label != "")
                projectName = projectName + " - " + label;

            QVariantMap projectData;
            projectData.insert("name", projectName);
            projectData.insert("id", projectId);
            projectData.insert("url", projectUrl);

            // get releases
            QJsonObject val1 = itProjects.value().toObject();
            for (QJsonObject::Iterator itReleasesNode  = val1.begin();
                                       itReleasesNode != val1.end();
                                       itReleasesNode++)
            {
                QList<QVariantMap> images;
                JsonData projectCheck;
                projectCheck.name = projectName;
                int projectIx = dataList.indexOf(projectCheck);

                QJsonObject val2 = itReleasesNode.value().toObject();
                for (QJsonObject::Iterator itReleases  = val2.begin();
                                           itReleases != val2.end();
                                           itReleases++)
                {
                    QJsonObject projectReleasesList = itReleases.value().toObject();
                    for (QJsonObject::Iterator itImageFile  = projectReleasesList.begin();
                                               itImageFile != projectReleasesList.end();
                                               itImageFile++)
                    {
                        QString imageName = itImageFile.value().toObject().toVariantMap()["name"].toString();

                        if (! imageName.endsWith(".img.gz"))
                            continue;   // we want to see only image files

                        if (projectIx < 0) {
                            // new project
                            images.append(itImageFile.value().toObject().toVariantMap());
                        } else {
                            // old project
                            dataList[projectIx].images.append(itImageFile.value().toObject().toVariantMap());
                        }
                    }
                }


                if (projectIx < 0) {
                  // new project
                  JsonData projectData(projectName, projectId, projectUrl, images);
                  dataList.append(projectData);
                }
            }
        }
    }

    QCollator collator;
    collator.setNumericMode(true);
    collator.setCaseSensitivity(Qt::CaseSensitive);

    std::sort(dataList.begin(), dataList.end(),
              [&collator](const JsonData &proj1, const JsonData &proj2)
         {return collator.compare(proj1.name, proj2.name) > 0;});

    for (int ix = 0; ix < dataList.size(); ix++)
        std::sort(dataList[ix].images.begin(), dataList[ix].images.end(), compareVersion);
}