diff --git a/src/cursorthemesmodel.cpp b/src/cursorthemesmodel.cpp index 926a666..c1ba1f2 100644 --- a/src/cursorthemesmodel.cpp +++ b/src/cursorthemesmodel.cpp @@ -1,87 +1,89 @@ /* KDE GTK Configuration Module * * Copyright 2016 Jason A. Donenfeld * Copyright 2016 Andrey Bondrov * Copyright 2011 Aleix Pol Gonzalez * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "cursorthemesmodel.h" #include #include #include #include #include #include #include CursorThemesModel::CursorThemesModel(QObject* parent) : IconThemesModel(parent) { reload(); } QList CursorThemesModel::installedThemesPaths() { QList availableIcons; QStringList dirs(QString(XcursorLibraryPath()).split(':', QString::SkipEmptyParts)); std::transform(dirs.begin(), dirs.end(), dirs.begin(), KShell::tildeExpand); dirs.removeDuplicates(); foreach(const QString& dir, dirs) { QDir userIconsDir(dir); QDirIterator it(userIconsDir.path(), QDir::NoDotAndDotDot|QDir::AllDirs|QDir::NoSymLinks); while(it.hasNext()) { QString currentPath = it.next(); QDir dir(currentPath); if(dir.exists() && dir.exists("cursors")) availableIcons << dir; } } return availableIcons; } void CursorThemesModel::fillItem(const QDir& dir, QStandardItem* item) { KIconTheme theme(dir.dirName()); if(!theme.name().isEmpty()) item->setText(theme.name()); else item->setText(dir.dirName()); item->setToolTip(theme.description()); item->setData(theme.inherits(), CursorThemesModel::InheritsRole); } void CursorThemesModel::reload() { clear(); QList paths = installedThemesPaths(); Q_FOREACH(const QDir& dir, paths) { QStandardItem* themeit = new QStandardItem(dir.dirName()); themeit->setData(dir.path(), PathRole); themeit->setData(dir.dirName(), DirNameRole); fillItem(dir, themeit); appendRow(themeit); } + + sort(0); } diff --git a/src/iconthemesmodel.cpp b/src/iconthemesmodel.cpp index 7f4473b..a6a4be0 100644 --- a/src/iconthemesmodel.cpp +++ b/src/iconthemesmodel.cpp @@ -1,125 +1,127 @@ /* KDE GTK Configuration Module * * Copyright 2011 José Antonio Sanchez Reynaga * Copyright 2011 Aleix Pol Gonzalez * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "iconthemesmodel.h" #include #include #include #include #include #include IconThemesModel::IconThemesModel(bool onlyHome, QObject* parent) : QStandardItemModel(parent) , m_onlyHome(onlyHome) { + setSortRole(Qt::DisplayRole); reload(); } QList IconThemesModel::installedThemesPaths() { QList availableIcons; QSet dirs; dirs += QDir::home().filePath(".icons"); if(!m_onlyHome) { dirs += QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, "icons", QStandardPaths::LocateDirectory).toSet(); } foreach(const QString& dir, dirs) { QDir userIconsDir(dir); QDirIterator it(userIconsDir.path(), QDir::NoDotAndDotDot|QDir::AllDirs|QDir::NoSymLinks); while(it.hasNext()) { QString currentPath = it.next(); QDir dir(currentPath); if(dir.exists() && dir.exists("index.theme")) { availableIcons << dir; } } } return availableIcons; } bool greatSizeIs48(const QString& a, const QString& b) { bool a48=a.contains("48"), b48=b.contains("48"); if((a48 && b48) || (!a48 && !b48)) return a paths = installedThemesPaths(); Q_FOREACH(const QDir& dir, paths) { KIconTheme theme(dir.dirName()); if (!theme.isValid()) { qWarning() << "invalid theme" << dir.dirName(); continue; } QStandardItem* item = new QStandardItem(dir.dirName()); item->setData(dir.path(), PathRole); item->setData(dir.dirName(), DirNameRole); item->setText(theme.name()); item->setToolTip(theme.description()); item->setData(theme.inherits(), IconThemesModel::InheritsRole); QString iconName = theme.example(); if (iconName.isEmpty()) iconName = QStringLiteral("folder"); QString path = theme.iconPathByName(iconName, 16, KIconLoader::MatchBest); item->setIcon(QIcon(path)); appendRow(item); } + sort(0); }