mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-05-09 11:04:39 +02:00
Code style conventions (camelCase, m_ prefix)
Signed-off-by: QazCetelic <qaz.cetelic@protonmail.com>
This commit is contained in:
parent
abbebff400
commit
e74592fa09
@ -53,10 +53,10 @@ IconList::IconList(const QStringList& builtinPaths, const QString& path, QObject
|
|||||||
|
|
||||||
// add builtin icons
|
// add builtin icons
|
||||||
for (const auto& builtinPath : builtinPaths) {
|
for (const auto& builtinPath : builtinPaths) {
|
||||||
QDir instance_icons(builtinPath);
|
QDir instanceIcons(builtinPath);
|
||||||
auto file_info_list = instance_icons.entryInfoList(QDir::Files, QDir::Name);
|
auto fileInfoList = instanceIcons.entryInfoList(QDir::Files, QDir::Name);
|
||||||
for (const auto& file_info : file_info_list) {
|
for (const auto& fileInfo : fileInfoList) {
|
||||||
builtinNames.insert(file_info.baseName());
|
builtinNames.insert(fileInfo.baseName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (const auto& builtinName : builtinNames) {
|
for (const auto& builtinName : builtinNames) {
|
||||||
@ -64,7 +64,7 @@ IconList::IconList(const QStringList& builtinPaths, const QString& path, QObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_watcher.reset(new QFileSystemWatcher());
|
m_watcher.reset(new QFileSystemWatcher());
|
||||||
is_watching = false;
|
m_is_watching = false;
|
||||||
connect(m_watcher.get(), &QFileSystemWatcher::directoryChanged, this, &IconList::directoryChanged);
|
connect(m_watcher.get(), &QFileSystemWatcher::directoryChanged, this, &IconList::directoryChanged);
|
||||||
connect(m_watcher.get(), &QFileSystemWatcher::fileChanged, this, &IconList::fileChanged);
|
connect(m_watcher.get(), &QFileSystemWatcher::fileChanged, this, &IconList::fileChanged);
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ IconList::IconList(const QStringList& builtinPaths, const QString& path, QObject
|
|||||||
void IconList::sortIconList()
|
void IconList::sortIconList()
|
||||||
{
|
{
|
||||||
qDebug() << "Sorting icon list...";
|
qDebug() << "Sorting icon list...";
|
||||||
std::sort(icons.begin(), icons.end(), [](const MMCIcon& a, const MMCIcon& b) {
|
std::sort(m_icons.begin(), m_icons.end(), [](const MMCIcon& a, const MMCIcon& b) {
|
||||||
bool aIsSubdir = a.m_key.contains(QDir::separator());
|
bool aIsSubdir = a.m_key.contains(QDir::separator());
|
||||||
bool bIsSubdir = b.m_key.contains(QDir::separator());
|
bool bIsSubdir = b.m_key.contains(QDir::separator());
|
||||||
if (aIsSubdir != bIsSubdir) {
|
if (aIsSubdir != bIsSubdir) {
|
||||||
@ -175,7 +175,7 @@ void IconList::directoryChanged(const QString& path)
|
|||||||
if (!path.startsWith(m_dir.absolutePath()))
|
if (!path.startsWith(m_dir.absolutePath()))
|
||||||
m_dir.setPath(path);
|
m_dir.setPath(path);
|
||||||
m_dir.refresh();
|
m_dir.refresh();
|
||||||
if (is_watching)
|
if (m_is_watching)
|
||||||
stopWatching();
|
stopWatching();
|
||||||
startWatching();
|
startWatching();
|
||||||
}
|
}
|
||||||
@ -186,7 +186,7 @@ void IconList::directoryChanged(const QString& path)
|
|||||||
const QStringList newFileNamesList = getIconFilePaths();
|
const QStringList newFileNamesList = getIconFilePaths();
|
||||||
const QSet<QString> newSet = toStringSet(newFileNamesList);
|
const QSet<QString> newSet = toStringSet(newFileNamesList);
|
||||||
QSet<QString> currentSet;
|
QSet<QString> currentSet;
|
||||||
for (const MMCIcon& it : icons) {
|
for (const MMCIcon& it : m_icons) {
|
||||||
if (!it.has(IconType::FileBased))
|
if (!it.has(IconType::FileBased))
|
||||||
continue;
|
continue;
|
||||||
currentSet.insert(it.m_images[IconType::FileBased].filename);
|
currentSet.insert(it.m_images[IconType::FileBased].filename);
|
||||||
@ -202,10 +202,10 @@ void IconList::directoryChanged(const QString& path)
|
|||||||
int idx = getIconIndex(key);
|
int idx = getIconIndex(key);
|
||||||
if (idx == -1)
|
if (idx == -1)
|
||||||
continue;
|
continue;
|
||||||
icons[idx].remove(FileBased);
|
m_icons[idx].remove(FileBased);
|
||||||
if (icons[idx].type() == ToBeDeleted) {
|
if (m_icons[idx].type() == ToBeDeleted) {
|
||||||
beginRemoveRows(QModelIndex(), idx, idx);
|
beginRemoveRows(QModelIndex(), idx, idx);
|
||||||
icons.remove(idx);
|
m_icons.remove(idx);
|
||||||
reindex();
|
reindex();
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
} else {
|
} else {
|
||||||
@ -245,7 +245,7 @@ void IconList::fileChanged(const QString& path)
|
|||||||
if (icon.availableSizes().empty())
|
if (icon.availableSizes().empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
icons[idx].m_images[IconType::FileBased].icon = icon;
|
m_icons[idx].m_images[IconType::FileBased].icon = icon;
|
||||||
dataChanged(index(idx), index(idx));
|
dataChanged(index(idx), index(idx));
|
||||||
emit iconUpdated(key);
|
emit iconUpdated(key);
|
||||||
}
|
}
|
||||||
@ -262,8 +262,8 @@ void IconList::startWatching()
|
|||||||
{
|
{
|
||||||
auto abs_path = m_dir.absolutePath();
|
auto abs_path = m_dir.absolutePath();
|
||||||
FS::ensureFolderPathExists(abs_path);
|
FS::ensureFolderPathExists(abs_path);
|
||||||
is_watching = addPathRecursively(abs_path);
|
m_is_watching = addPathRecursively(abs_path);
|
||||||
if (is_watching) {
|
if (m_is_watching) {
|
||||||
qDebug() << "Started watching " << abs_path;
|
qDebug() << "Started watching " << abs_path;
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "Failed to start watching " << abs_path;
|
qDebug() << "Failed to start watching " << abs_path;
|
||||||
@ -274,7 +274,7 @@ void IconList::stopWatching()
|
|||||||
{
|
{
|
||||||
m_watcher->removePaths(m_watcher->files());
|
m_watcher->removePaths(m_watcher->files());
|
||||||
m_watcher->removePaths(m_watcher->directories());
|
m_watcher->removePaths(m_watcher->directories());
|
||||||
is_watching = false;
|
m_is_watching = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList IconList::mimeTypes() const
|
QStringList IconList::mimeTypes() const
|
||||||
@ -329,16 +329,16 @@ QVariant IconList::data(const QModelIndex& index, int role) const
|
|||||||
|
|
||||||
int row = index.row();
|
int row = index.row();
|
||||||
|
|
||||||
if (row < 0 || row >= icons.size())
|
if (row < 0 || row >= m_icons.size())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Qt::DecorationRole:
|
case Qt::DecorationRole:
|
||||||
return icons[row].icon();
|
return m_icons[row].icon();
|
||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
return icons[row].name();
|
return m_icons[row].name();
|
||||||
case Qt::UserRole:
|
case Qt::UserRole:
|
||||||
return icons[row].m_key;
|
return m_icons[row].m_key;
|
||||||
default:
|
default:
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -346,7 +346,7 @@ QVariant IconList::data(const QModelIndex& index, int role) const
|
|||||||
|
|
||||||
int IconList::rowCount(const QModelIndex& parent) const
|
int IconList::rowCount(const QModelIndex& parent) const
|
||||||
{
|
{
|
||||||
return parent.isValid() ? 0 : icons.size();
|
return parent.isValid() ? 0 : m_icons.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IconList::installIcons(const QStringList& iconFiles)
|
void IconList::installIcons(const QStringList& iconFiles)
|
||||||
@ -380,7 +380,7 @@ const MMCIcon* IconList::icon(const QString& key) const
|
|||||||
int iconIdx = getIconIndex(key);
|
int iconIdx = getIconIndex(key);
|
||||||
if (iconIdx == -1)
|
if (iconIdx == -1)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return &icons[iconIdx];
|
return &m_icons[iconIdx];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IconList::deleteIcon(const QString& key)
|
bool IconList::deleteIcon(const QString& key)
|
||||||
@ -395,22 +395,22 @@ bool IconList::trashIcon(const QString& key)
|
|||||||
|
|
||||||
bool IconList::addThemeIcon(const QString& key)
|
bool IconList::addThemeIcon(const QString& key)
|
||||||
{
|
{
|
||||||
auto iter = name_index.find(key);
|
auto iter = m_name_index.find(key);
|
||||||
if (iter != name_index.end()) {
|
if (iter != m_name_index.end()) {
|
||||||
auto& oldOne = icons[*iter];
|
auto& oldOne = m_icons[*iter];
|
||||||
oldOne.replace(Builtin, key);
|
oldOne.replace(Builtin, key);
|
||||||
dataChanged(index(*iter), index(*iter));
|
dataChanged(index(*iter), index(*iter));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// add a new icon
|
// add a new icon
|
||||||
beginInsertRows(QModelIndex(), icons.size(), icons.size());
|
beginInsertRows(QModelIndex(), m_icons.size(), m_icons.size());
|
||||||
{
|
{
|
||||||
MMCIcon mmc_icon;
|
MMCIcon mmc_icon;
|
||||||
mmc_icon.m_name = key;
|
mmc_icon.m_name = key;
|
||||||
mmc_icon.m_key = key;
|
mmc_icon.m_key = key;
|
||||||
mmc_icon.replace(Builtin, key);
|
mmc_icon.replace(Builtin, key);
|
||||||
icons.push_back(mmc_icon);
|
m_icons.push_back(mmc_icon);
|
||||||
name_index[key] = icons.size() - 1;
|
m_name_index[key] = m_icons.size() - 1;
|
||||||
}
|
}
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
return true;
|
return true;
|
||||||
@ -422,22 +422,22 @@ bool IconList::addIcon(const QString& key, const QString& name, const QString& p
|
|||||||
QIcon icon(path);
|
QIcon icon(path);
|
||||||
if (icon.isNull())
|
if (icon.isNull())
|
||||||
return false;
|
return false;
|
||||||
auto iter = name_index.find(key);
|
auto iter = m_name_index.find(key);
|
||||||
if (iter != name_index.end()) {
|
if (iter != m_name_index.end()) {
|
||||||
auto& oldOne = icons[*iter];
|
auto& oldOne = m_icons[*iter];
|
||||||
oldOne.replace(type, icon, path);
|
oldOne.replace(type, icon, path);
|
||||||
dataChanged(index(*iter), index(*iter));
|
dataChanged(index(*iter), index(*iter));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// add a new icon
|
// add a new icon
|
||||||
beginInsertRows(QModelIndex(), icons.size(), icons.size());
|
beginInsertRows(QModelIndex(), m_icons.size(), m_icons.size());
|
||||||
{
|
{
|
||||||
MMCIcon mmc_icon;
|
MMCIcon mmc_icon;
|
||||||
mmc_icon.m_name = name;
|
mmc_icon.m_name = name;
|
||||||
mmc_icon.m_key = key;
|
mmc_icon.m_key = key;
|
||||||
mmc_icon.replace(type, icon, path);
|
mmc_icon.replace(type, icon, path);
|
||||||
icons.push_back(mmc_icon);
|
m_icons.push_back(mmc_icon);
|
||||||
name_index[key] = icons.size() - 1;
|
m_name_index[key] = m_icons.size() - 1;
|
||||||
}
|
}
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
return true;
|
return true;
|
||||||
@ -452,10 +452,10 @@ void IconList::saveIcon(const QString& key, const QString& path, const char* for
|
|||||||
|
|
||||||
void IconList::reindex()
|
void IconList::reindex()
|
||||||
{
|
{
|
||||||
name_index.clear();
|
m_name_index.clear();
|
||||||
for (int i = 0; i < icons.size(); i++) {
|
for (int i = 0; i < m_icons.size(); i++) {
|
||||||
name_index[icons[i].m_key] = i;
|
m_name_index[m_icons[i].m_key] = i;
|
||||||
emit iconUpdated(icons[i].m_key); // prevents incorrect indices with proxy model
|
emit iconUpdated(m_icons[i].m_key); // prevents incorrect indices with proxy model
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -464,20 +464,20 @@ QIcon IconList::getIcon(const QString& key) const
|
|||||||
int iconIndex = getIconIndex(key);
|
int iconIndex = getIconIndex(key);
|
||||||
|
|
||||||
if (iconIndex != -1)
|
if (iconIndex != -1)
|
||||||
return icons[iconIndex].icon();
|
return m_icons[iconIndex].icon();
|
||||||
|
|
||||||
// Fallback for icons that don't exist.b
|
// Fallback for icons that don't exist.b
|
||||||
iconIndex = getIconIndex("grass");
|
iconIndex = getIconIndex("grass");
|
||||||
|
|
||||||
if (iconIndex != -1)
|
if (iconIndex != -1)
|
||||||
return icons[iconIndex].icon();
|
return m_icons[iconIndex].icon();
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
int IconList::getIconIndex(const QString& key) const
|
int IconList::getIconIndex(const QString& key) const
|
||||||
{
|
{
|
||||||
auto iter = name_index.find(key == "default" ? "grass" : key);
|
auto iter = m_name_index.find(key == "default" ? "grass" : key);
|
||||||
if (iter != name_index.end())
|
if (iter != m_name_index.end())
|
||||||
return *iter;
|
return *iter;
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
@ -491,7 +491,7 @@ QString IconList::getDirectory() const
|
|||||||
/// Returns the directory of the icon with the given key or the default directory if it's a builtin icon.
|
/// Returns the directory of the icon with the given key or the default directory if it's a builtin icon.
|
||||||
QString IconList::iconDirectory(const QString& key) const
|
QString IconList::iconDirectory(const QString& key) const
|
||||||
{
|
{
|
||||||
for (const auto& mmcIcon : icons) {
|
for (const auto& mmcIcon : m_icons) {
|
||||||
if (mmcIcon.m_key == key && mmcIcon.has(IconType::FileBased)) {
|
if (mmcIcon.m_key == key && mmcIcon.has(IconType::FileBased)) {
|
||||||
QFileInfo icon_file(mmcIcon.getFilePath());
|
QFileInfo icon_file(mmcIcon.getFilePath());
|
||||||
return icon_file.dir().path();
|
return icon_file.dir().path();
|
||||||
|
@ -105,8 +105,8 @@ class IconList : public QAbstractListModel {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
shared_qobject_ptr<QFileSystemWatcher> m_watcher;
|
shared_qobject_ptr<QFileSystemWatcher> m_watcher;
|
||||||
bool is_watching;
|
bool m_is_watching;
|
||||||
QMap<QString, int> name_index;
|
QMap<QString, int> m_name_index;
|
||||||
QVector<MMCIcon> icons;
|
QVector<MMCIcon> m_icons;
|
||||||
QDir m_dir;
|
QDir m_dir;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user