diff --git a/src/iconthemesmodel.cpp b/src/iconthemesmodel.cpp index a6a4be0..2fe9bf3 100644 --- a/src/iconthemesmodel.cpp +++ b/src/iconthemesmodel.cpp @@ -1,127 +1,133 @@ /* 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 done; QList paths = installedThemesPaths(); Q_FOREACH(const QDir& dir, paths) { KIconTheme theme(dir.dirName()); if (!theme.isValid()) { qWarning() << "invalid theme" << dir.dirName(); continue; } + if (done.contains(dir.dirName())) + continue; + + done << dir.dirName(); + 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); }