aboutsummaryrefslogtreecommitdiff
path: root/launcher/icons/IconList.cpp
diff options
context:
space:
mode:
authorTrial97 <alexandru.tripon97@gmail.com>2023-07-28 01:15:21 +0300
committerTrial97 <alexandru.tripon97@gmail.com>2023-07-28 01:20:05 +0300
commit7e58b965b770ab75c14f2265b7bd7ded081c66b5 (patch)
treee0f15642e591bc87be380922a869f7c4d4251987 /launcher/icons/IconList.cpp
parent1ca7e5efe946d24f3898c8623ff1af3ef9dd96e6 (diff)
downloadPrismLauncher-7e58b965b770ab75c14f2265b7bd7ded081c66b5.tar.gz
PrismLauncher-7e58b965b770ab75c14f2265b7bd7ded081c66b5.tar.bz2
PrismLauncher-7e58b965b770ab75c14f2265b7bd7ded081c66b5.zip
refactor icon list
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
Diffstat (limited to 'launcher/icons/IconList.cpp')
-rw-r--r--launcher/icons/IconList.cpp92
1 files changed, 36 insertions, 56 deletions
diff --git a/launcher/icons/IconList.cpp b/launcher/icons/IconList.cpp
index 50aef790..a1026e83 100644
--- a/launcher/icons/IconList.cpp
+++ b/launcher/icons/IconList.cpp
@@ -43,6 +43,7 @@
#include <QMimeData>
#include <QSet>
#include <QUrl>
+#include "icons/IconUtils.h"
#define MAX_SIZE 1024
@@ -129,7 +130,7 @@ void IconList::directoryChanged(const QString& path)
QString suffix = rmfile.suffix();
// The icon doesnt have a suffix, but it can have other .s in the name, so we account for those as well
- if (suffix != "jpeg" && suffix != "png" && suffix != "jpg" && suffix != "ico" && suffix != "svg" && suffix != "gif")
+ if (!IconUtils::isIconSuffix(suffix))
key = rmfile.fileName();
int idx = getIconIndex(key);
@@ -156,7 +157,7 @@ void IconList::directoryChanged(const QString& path)
QString suffix = addfile.suffix();
// The icon doesnt have a suffix, but it can have other .s in the name, so we account for those as well
- if (suffix != "jpeg" && suffix != "png" && suffix != "jpg" && suffix != "ico" && suffix != "svg" && suffix != "gif")
+ if (!IconUtils::isIconSuffix(suffix))
key = addfile.fileName();
if (addIcon(key, QString(), addfile.filePath(), IconType::FileBased)) {
@@ -258,8 +259,7 @@ Qt::ItemFlags IconList::flags(const QModelIndex& index) const
Qt::ItemFlags defaultFlags = QAbstractListModel::flags(index);
if (index.isValid())
return Qt::ItemIsDropEnabled | defaultFlags;
- else
- return Qt::ItemIsDropEnabled | defaultFlags;
+ return Qt::ItemIsDropEnabled | defaultFlags;
}
QVariant IconList::data(const QModelIndex& index, int role) const
@@ -291,19 +291,8 @@ int IconList::rowCount(const QModelIndex& parent) const
void IconList::installIcons(const QStringList& iconFiles)
{
- for (QString file : iconFiles) {
- QFileInfo fileinfo(file);
- if (!fileinfo.isReadable() || !fileinfo.isFile())
- continue;
- QString target = FS::PathCombine(getDirectory(), fileinfo.fileName());
-
- QString suffix = fileinfo.suffix();
- if (suffix != "jpeg" && suffix != "png" && suffix != "jpg" && suffix != "ico" && suffix != "svg" && suffix != "gif")
- continue;
-
- if (!QFile::copy(file, target))
- continue;
- }
+ for (QString file : iconFiles)
+ installIcon(file, {});
}
void IconList::installIcon(const QString& file, const QString& name)
@@ -312,18 +301,17 @@ void IconList::installIcon(const QString& file, const QString& name)
if (!fileinfo.isReadable() || !fileinfo.isFile())
return;
- QString target = FS::PathCombine(getDirectory(), name);
+ if (!IconUtils::isIconSuffix(fileinfo.suffix()))
+ return;
+ QString target = FS::PathCombine(getDirectory(), name.isEmpty() ? fileinfo.fileName() : name);
QFile::copy(file, target);
}
bool IconList::iconFileExists(const QString& key) const
{
auto iconEntry = icon(key);
- if (!iconEntry) {
- return false;
- }
- return iconEntry->has(IconType::FileBased);
+ return iconEntry && iconEntry->has(IconType::FileBased);
}
const MMCIcon* IconList::icon(const QString& key) const
@@ -336,18 +324,12 @@ const MMCIcon* IconList::icon(const QString& key) const
bool IconList::deleteIcon(const QString& key)
{
- if (!iconFileExists(key))
- return false;
-
- return QFile::remove(icon(key)->getFilePath());
+ return iconFileExists(key) && QFile::remove(icon(key)->getFilePath());
}
bool IconList::trashIcon(const QString& key)
{
- if (!iconFileExists(key))
- return false;
-
- return FS::trash(icon(key)->getFilePath(), nullptr);
+ return iconFileExists(key) && FS::trash(icon(key)->getFilePath(), nullptr);
}
bool IconList::addThemeIcon(const QString& key)
@@ -358,20 +340,19 @@ bool IconList::addThemeIcon(const QString& key)
oldOne.replace(Builtin, key);
dataChanged(index(*iter), index(*iter));
return true;
- } else {
- // add a new icon
- beginInsertRows(QModelIndex(), icons.size(), icons.size());
- {
- MMCIcon mmc_icon;
- mmc_icon.m_name = key;
- mmc_icon.m_key = key;
- mmc_icon.replace(Builtin, key);
- icons.push_back(mmc_icon);
- name_index[key] = icons.size() - 1;
- }
- endInsertRows();
- return true;
}
+ // add a new icon
+ beginInsertRows(QModelIndex(), icons.size(), icons.size());
+ {
+ MMCIcon mmc_icon;
+ mmc_icon.m_name = key;
+ mmc_icon.m_key = key;
+ mmc_icon.replace(Builtin, key);
+ icons.push_back(mmc_icon);
+ name_index[key] = icons.size() - 1;
+ }
+ endInsertRows();
+ return true;
}
bool IconList::addIcon(const QString& key, const QString& name, const QString& path, const IconType type)
@@ -386,20 +367,19 @@ bool IconList::addIcon(const QString& key, const QString& name, const QString& p
oldOne.replace(type, icon, path);
dataChanged(index(*iter), index(*iter));
return true;
- } else {
- // add a new icon
- beginInsertRows(QModelIndex(), icons.size(), icons.size());
- {
- MMCIcon mmc_icon;
- mmc_icon.m_name = name;
- mmc_icon.m_key = key;
- mmc_icon.replace(type, icon, path);
- icons.push_back(mmc_icon);
- name_index[key] = icons.size() - 1;
- }
- endInsertRows();
- return true;
}
+ // add a new icon
+ beginInsertRows(QModelIndex(), icons.size(), icons.size());
+ {
+ MMCIcon mmc_icon;
+ mmc_icon.m_name = name;
+ mmc_icon.m_key = key;
+ mmc_icon.replace(type, icon, path);
+ icons.push_back(mmc_icon);
+ name_index[key] = icons.size() - 1;
+ }
+ endInsertRows();
+ return true;
}
void IconList::saveIcon(const QString& key, const QString& path, const char* format) const