2022-05-21 10:44:39 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2022-02-13 20:08:18 +08:00
|
|
|
#include "customfileiconprovider.h"
|
|
|
|
#include "iconsmanager.h"
|
2022-02-15 00:01:50 +08:00
|
|
|
#include "vcs/gitrepository.h"
|
2022-02-13 20:08:18 +08:00
|
|
|
|
|
|
|
CustomFileIconProvider::CustomFileIconProvider()
|
|
|
|
{
|
2022-10-10 18:05:18 +08:00
|
|
|
//provider delete it in the destructor
|
2022-02-15 00:01:50 +08:00
|
|
|
mVCSRepository = new GitRepository("");
|
2022-02-14 00:13:00 +08:00
|
|
|
}
|
2022-02-13 20:08:18 +08:00
|
|
|
|
2022-02-14 00:13:00 +08:00
|
|
|
CustomFileIconProvider::~CustomFileIconProvider()
|
|
|
|
{
|
2022-02-15 00:01:50 +08:00
|
|
|
delete mVCSRepository;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CustomFileIconProvider::setRootFolder(const QString &folder)
|
|
|
|
{
|
|
|
|
mVCSRepository->setFolder(folder);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CustomFileIconProvider::update()
|
|
|
|
{
|
|
|
|
mVCSRepository->update();
|
2022-02-13 20:08:18 +08:00
|
|
|
}
|
|
|
|
|
2022-02-15 21:39:17 +08:00
|
|
|
GitRepository *CustomFileIconProvider::VCSRepository() const
|
|
|
|
{
|
|
|
|
return mVCSRepository;
|
|
|
|
}
|
|
|
|
|
2022-02-13 20:08:18 +08:00
|
|
|
QIcon CustomFileIconProvider::icon(IconType type) const
|
|
|
|
{
|
|
|
|
if (type == IconType::Folder) {
|
|
|
|
QIcon icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_FOLDER);
|
|
|
|
if (!icon.isNull())
|
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
return QFileIconProvider::icon(type);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
QIcon CustomFileIconProvider::icon(const QFileInfo &info) const
|
|
|
|
{
|
|
|
|
QIcon icon;
|
2022-02-14 00:13:00 +08:00
|
|
|
if (info.isDir()) {
|
2022-02-15 00:01:50 +08:00
|
|
|
if (mVCSRepository->isFileInRepository(info)) {
|
2022-02-21 11:37:29 +08:00
|
|
|
if (mVCSRepository->isFileConflicting(info))
|
|
|
|
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_FOLDER_VCS_CONFLICT);
|
|
|
|
else if (mVCSRepository->isFileStaged(info))
|
2022-02-14 00:13:00 +08:00
|
|
|
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_FOLDER_VCS_STAGED);
|
2022-02-15 00:01:50 +08:00
|
|
|
else if (mVCSRepository->isFileChanged(info))
|
2022-02-14 00:13:00 +08:00
|
|
|
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_FOLDER_VCS_CHANGED);
|
|
|
|
else
|
|
|
|
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_FOLDER_VCS_NOCHANGE);
|
|
|
|
} else
|
|
|
|
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_FOLDER);
|
2022-03-28 16:57:58 +08:00
|
|
|
} else if (!info.exists()) {
|
|
|
|
icon = pIconsManager->getIcon(IconsManager::ACTION_MISC_CROSS);
|
|
|
|
} else if (isHFile(info.fileName())) {
|
2022-02-15 00:01:50 +08:00
|
|
|
if (mVCSRepository->isFileInRepository(info)) {
|
2022-02-21 11:37:29 +08:00
|
|
|
if (mVCSRepository->isFileConflicting(info))
|
|
|
|
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_HFILE_VCS_CONFLICT);
|
|
|
|
else if (mVCSRepository->isFileStaged(info))
|
2022-02-14 00:13:00 +08:00
|
|
|
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_HFILE_VCS_STAGED);
|
2022-02-15 00:01:50 +08:00
|
|
|
else if (mVCSRepository->isFileChanged(info))
|
2022-02-14 00:13:00 +08:00
|
|
|
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_HFILE_VCS_CHANGED);
|
|
|
|
else
|
|
|
|
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_HFILE_VCS_NOCHANGE);
|
|
|
|
} else
|
|
|
|
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_HFILE);
|
|
|
|
} else if (isCppFile(info.fileName())) {
|
2022-02-15 00:01:50 +08:00
|
|
|
if (mVCSRepository->isFileInRepository(info)) {
|
2022-02-21 11:37:29 +08:00
|
|
|
if (mVCSRepository->isFileConflicting(info))
|
|
|
|
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_CPPFILE_VCS_CONFLICT);
|
|
|
|
else if (mVCSRepository->isFileStaged(info))
|
2022-02-14 00:13:00 +08:00
|
|
|
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_CPPFILE_VCS_STAGED);
|
2022-02-15 00:01:50 +08:00
|
|
|
else if (mVCSRepository->isFileChanged(info))
|
2022-02-14 00:13:00 +08:00
|
|
|
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_CPPFILE_VCS_CHANGED);
|
|
|
|
else
|
|
|
|
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_CPPFILE_VCS_NOCHANGE);
|
|
|
|
} else
|
|
|
|
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_CPPFILE);
|
2022-02-13 20:08:18 +08:00
|
|
|
} else if (isCFile(info.fileName())) {
|
2022-02-15 00:01:50 +08:00
|
|
|
if (mVCSRepository->isFileInRepository(info)) {
|
2022-02-21 11:37:29 +08:00
|
|
|
if (mVCSRepository->isFileConflicting(info))
|
|
|
|
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_CFILE_VCS_CONFLICT);
|
|
|
|
else if (mVCSRepository->isFileStaged(info))
|
2022-02-14 00:13:00 +08:00
|
|
|
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_CFILE_VCS_STAGED);
|
2022-02-15 00:01:50 +08:00
|
|
|
else if (mVCSRepository->isFileChanged(info))
|
2022-02-14 00:13:00 +08:00
|
|
|
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_CFILE_VCS_CHANGED);
|
|
|
|
else
|
|
|
|
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_CFILE_VCS_NOCHANGE);
|
|
|
|
} else
|
|
|
|
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_CFILE);
|
2022-02-13 20:12:20 +08:00
|
|
|
} else if (info.suffix()=="dev") {
|
2022-02-15 00:01:50 +08:00
|
|
|
if (mVCSRepository->isFileInRepository(info)) {
|
2022-02-21 11:37:29 +08:00
|
|
|
if (mVCSRepository->isFileConflicting(info))
|
|
|
|
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_PROJECTFILE_VCS_CONFLICT);
|
|
|
|
else if (mVCSRepository->isFileStaged(info))
|
2022-02-14 00:13:00 +08:00
|
|
|
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_PROJECTFILE_VCS_STAGED);
|
2022-02-15 00:01:50 +08:00
|
|
|
else if (mVCSRepository->isFileChanged(info))
|
2022-02-14 00:13:00 +08:00
|
|
|
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_PROJECTFILE_VCS_CHANGED);
|
|
|
|
else
|
|
|
|
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_PROJECTFILE_VCS_NOCHANGE);
|
|
|
|
} else
|
|
|
|
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_PROJECTFILE);
|
2022-02-15 21:39:17 +08:00
|
|
|
} else {
|
|
|
|
if (mVCSRepository->isFileInRepository(info)) {
|
2022-02-21 11:37:29 +08:00
|
|
|
if (mVCSRepository->isFileConflicting(info))
|
|
|
|
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_FILE_VCS_CONFLICT);
|
|
|
|
else if (mVCSRepository->isFileStaged(info))
|
2022-02-15 21:39:17 +08:00
|
|
|
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_FILE_VCS_STAGED);
|
|
|
|
else if (mVCSRepository->isFileChanged(info))
|
|
|
|
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_FILE_VCS_CHANGED);
|
|
|
|
else
|
|
|
|
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_FILE_VCS_NOCHANGE);
|
|
|
|
} //use default system icon
|
2022-02-13 20:08:18 +08:00
|
|
|
}
|
|
|
|
if (!icon.isNull())
|
|
|
|
return icon;
|
|
|
|
return QFileIconProvider::icon(info);
|
|
|
|
}
|