QString KBalooRolesProvider::tagsFromValues(const QStringList& values) const { QStringList alphabeticalOrderTags = values; QCollator coll; coll.setNumericMode(true); std::sort(alphabeticalOrderTags.begin(), alphabeticalOrderTags.end(), [&](const QString& s1, const QString& s2){ return coll.compare(s1, s2) < 0; }); return alphabeticalOrderTags.join(QStringLiteral(", ")); }
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 }
void BrowserWindow::createEncodingSubMenu(const QString &name, QStringList &codecNames, QMenu* menu) { if (codecNames.isEmpty()) { return; } QCollator collator; collator.setNumericMode(true); std::sort(codecNames.begin(), codecNames.end(), [collator](const QString &a, const QString &b) { return collator.compare(a, b) < 0; }); QMenu* subMenu = new QMenu(name, menu); const QString activeCodecName = QWebEngineSettings::defaultSettings()->defaultTextEncoding(); foreach (const QString &codecName, codecNames) { subMenu->addAction(createEncodingAction(codecName, activeCodecName, subMenu)); }
static PyObject *meth_QCollator_setLocale(PyObject *sipSelf, PyObject *sipArgs) { PyObject *sipParseErr = NULL; { const QLocale* a0; QCollator *sipCpp; if (sipParseArgs(&sipParseErr, sipArgs, "BJ9", &sipSelf, sipType_QCollator, &sipCpp, sipType_QLocale, &a0)) { sipCpp->setLocale(*a0); Py_INCREF(Py_None); return Py_None; } } /* Raise an exception if the arguments couldn't be parsed. */ sipNoMethod(sipParseErr, sipName_QCollator, sipName_setLocale, doc_QCollator_setLocale); return NULL; }
static PyObject *meth_QCollator_setIgnorePunctuation(PyObject *sipSelf, PyObject *sipArgs) { PyObject *sipParseErr = NULL; { bool a0; QCollator *sipCpp; if (sipParseArgs(&sipParseErr, sipArgs, "Bb", &sipSelf, sipType_QCollator, &sipCpp, &a0)) { sipCpp->setIgnorePunctuation(a0); Py_INCREF(Py_None); return Py_None; } } /* Raise an exception if the arguments couldn't be parsed. */ sipNoMethod(sipParseErr, sipName_QCollator, sipName_setIgnorePunctuation, doc_QCollator_setIgnorePunctuation); return NULL; }
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; }
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); }
void FriendWidget::contextMenuEvent(QContextMenuEvent * event) { if (!active) setBackgroundRole(QPalette::Highlight); installEventFilter(this); // Disable leave event. QPoint pos = event->globalPos(); ToxId id = FriendList::findFriend(friendId)->getToxId(); QString dir = Settings::getInstance().getAutoAcceptDir(id); QMenu menu; QAction* openChatWindow = nullptr; QAction* removeChatWindow = nullptr; ContentDialog* contentDialog = ContentDialog::getFriendDialog(friendId); bool notAlone = contentDialog != nullptr && contentDialog->chatroomWidgetCount() > 1; if (contentDialog == nullptr || notAlone) openChatWindow = menu.addAction(tr("Open chat in new window")); if (contentDialog != nullptr && contentDialog->hasFriendWidget(friendId, this)) removeChatWindow = menu.addAction(tr("Remove chat from this window")); menu.addSeparator(); QMenu* inviteMenu = menu.addMenu(tr("Invite to group","Menu to invite a friend to a groupchat")); QAction* newGroupAction = inviteMenu->addAction(tr("To new group")); inviteMenu->addSeparator(); QMap<QAction*, Group*> groupActions; for (Group* group : GroupList::getAllGroups()) { int maxNameLen = 30; QString name = group->getGroupWidget()->getName(); if ( name.length() > maxNameLen ) { name = name.left(maxNameLen).trimmed() + ".."; } QAction* groupAction = inviteMenu->addAction(tr("Invite to group '%1'").arg(name)); groupActions[groupAction] = group; } int circleId = Settings::getInstance().getFriendCircleID(FriendList::findFriend(friendId)->getToxId()); CircleWidget *circleWidget = CircleWidget::getFromID(circleId); QMenu* circleMenu = nullptr; QAction* newCircleAction = nullptr; QAction *removeCircleAction = nullptr; QMap<QAction*, int> circleActions; FriendListWidget *friendList; if (circleWidget == nullptr) friendList = qobject_cast<FriendListWidget*>(FriendList::findFriend(friendId)->getFriendWidget()->parentWidget()); else friendList = qobject_cast<FriendListWidget*>(circleWidget->parentWidget()); circleMenu = menu.addMenu(tr("Move to circle...", "Menu to move a friend into a different circle")); newCircleAction = circleMenu->addAction(tr("To new circle")); if (circleId != -1) removeCircleAction = circleMenu->addAction(tr("Remove from circle '%1'").arg(Settings::getInstance().getCircleName(circleId))); circleMenu->addSeparator(); QList<QAction*> circleActionList; for (int i = 0; i < Settings::getInstance().getCircleCount(); ++i) { if (i != circleId) { circleActionList.push_back(new QAction(tr("Move to circle \"%1\"").arg(Settings::getInstance().getCircleName(i)), circleMenu)); circleActions[circleActionList.back()] = i; } } std::sort(circleActionList.begin(), circleActionList.end(), [](const QAction* lhs, const QAction* rhs) -> bool { QCollator collator; collator.setNumericMode(true); return collator.compare(lhs->text(), rhs->text()) < 0; }); circleMenu->addActions(circleActionList); QAction* setAlias = menu.addAction(tr("Set alias...")); menu.addSeparator(); QAction* autoAccept = menu.addAction(tr("Auto accept files from this friend", "context menu entry")); autoAccept->setCheckable(true); autoAccept->setChecked(!dir.isEmpty()); menu.addSeparator(); QAction* removeFriendAction = nullptr; if (contentDialog == nullptr || !contentDialog->hasFriendWidget(friendId, this)) removeFriendAction = menu.addAction(tr("Remove friend", "Menu to remove the friend from our friendlist")); menu.addSeparator(); QAction* aboutWindow = menu.addAction(tr("Show details")); QAction* selectedItem = menu.exec(pos); removeEventFilter(this); if (!active) setBackgroundRole(QPalette::Window); if (selectedItem) { if (selectedItem == setAlias) { nameLabel->editBegin(); } else if (selectedItem == removeFriendAction) { emit removeFriend(friendId); return; } else if (selectedItem == openChatWindow) { emit chatroomWidgetClicked(this, true); return; } else if (selectedItem == removeChatWindow) { ContentDialog* contentDialog = ContentDialog::getFriendDialog(friendId); contentDialog->removeFriend(friendId); return; } else if (selectedItem == autoAccept) { if (!autoAccept->isChecked()) { qDebug() << "not checked"; dir = QDir::homePath(); autoAccept->setChecked(false); Settings::getInstance().setAutoAcceptDir(id, ""); } else if (autoAccept->isChecked()) { dir = QFileDialog::getExistingDirectory(0, tr("Choose an auto accept directory","popup title"), dir, QFileDialog::DontUseNativeDialog); autoAccept->setChecked(true); qDebug() << "setting auto accept dir for" << friendId << "to" << dir; Settings::getInstance().setAutoAcceptDir(id, dir); } } else if (selectedItem == aboutWindow) { AboutUser *aboutUser = new AboutUser(id, Widget::getInstance()); aboutUser->setFriend(FriendList::findFriend(friendId)); aboutUser->show(); } else if (selectedItem == newGroupAction) { int groupId = Core::getInstance()->createGroup(); Core::getInstance()->groupInviteFriend(friendId, groupId); } else if (selectedItem == newCircleAction) { if (circleWidget != nullptr) circleWidget->updateStatus(); if (friendList != nullptr) friendList->addCircleWidget(FriendList::findFriend(friendId)->getFriendWidget()); else Settings::getInstance().setFriendCircleID(id, Settings::getInstance().addCircle()); } else if (groupActions.contains(selectedItem)) { Group* group = groupActions[selectedItem]; Core::getInstance()->groupInviteFriend(friendId, group->getGroupId()); } else if (removeCircleAction != nullptr && selectedItem == removeCircleAction) { if (friendList != nullptr) friendList->moveWidget(FriendList::findFriend(friendId)->getFriendWidget(), FriendList::findFriend(friendId)->getStatus(), true); else Settings::getInstance().setFriendCircleID(id, -1); if (circleWidget) { circleWidget->updateStatus(); Widget::getInstance()->searchCircle(circleWidget); } } else if (circleActions.contains(selectedItem)) { CircleWidget* circle = CircleWidget::getFromID(circleActions[selectedItem]); if (circle != nullptr) { circle->addFriendWidget(FriendList::findFriend(friendId)->getFriendWidget(), FriendList::findFriend(friendId)->getStatus()); circle->setExpanded(true); Widget::getInstance()->searchCircle(circle); Settings::getInstance().savePersonal(); } else Settings::getInstance().setFriendCircleID(id, circleActions[selectedItem]); if (circleWidget != nullptr) { circleWidget->updateStatus(); Widget::getInstance()->searchCircle(circleWidget); } } } }
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); }
void RootModel::refresh() { if (!m_complete) { return; } beginResetModel(); AppsModel::refreshInternal(); AppsModel *allModel = nullptr; m_recentAppsModel = nullptr; m_recentDocsModel = nullptr; m_recentContactsModel = nullptr; if (m_showAllApps) { QList<AbstractEntry *> groups; if (m_paginate) { QHash<QString, AppEntry *> appsHash; QList<AppEntry *> apps; foreach (const AbstractEntry *groupEntry, m_entryList) { AbstractModel *model = groupEntry->childModel(); for (int i = 0; i < model->count(); ++i) { GroupEntry *subGroupEntry = static_cast<GroupEntry*>(model->index(i, 0).internalPointer()); AbstractModel *subModel = subGroupEntry->childModel(); for (int j = 0; j < subModel->count(); ++j) { AppEntry *appEntry = static_cast<AppEntry*>(subModel->index(j, 0).internalPointer()); if (appEntry->name().isEmpty()) { continue; } appsHash.insert(appEntry->service()->menuId(), appEntry); } } } apps = appsHash.values(); QCollator c; std::sort(apps.begin(), apps.end(), [&c](AbstractEntry* a, AbstractEntry* b) { if (a->type() != b->type()) { return a->type() > b->type(); } else { return c.compare(a->name(), b->name()) < 0; } }); int at = 0; QList<AbstractEntry *> page; page.reserve(m_pageSize); foreach(AppEntry *app, apps) { page.append(app); if (at == (m_pageSize - 1)) { at = 0; AppsModel *model = new AppsModel(page, false, this); groups.append(new GroupEntry(this, QString(), QString(), model)); page.clear(); } else { ++at; } } if (!page.isEmpty()) { AppsModel *model = new AppsModel(page, false, this); groups.append(new GroupEntry(this, QString(), QString(), model)); } groups.prepend(new GroupEntry(this, QString(), QString(), m_favorites)); } else {