1/*
2 * Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17#include "customfileiconprovider.h"
18#include "iconsmanager.h"
19#include "vcs/gitrepository.h"
20
21CustomFileIconProvider::CustomFileIconProvider()
22{
23 mVCSRepository = new GitRepository("");
24}
25
26CustomFileIconProvider::~CustomFileIconProvider()
27{
28 delete mVCSRepository;
29}
30
31void CustomFileIconProvider::setRootFolder(const QString &folder)
32{
33 mVCSRepository->setFolder(folder);
34}
35
36void CustomFileIconProvider::update()
37{
38 mVCSRepository->update();
39}
40
41GitRepository *CustomFileIconProvider::VCSRepository() const
42{
43 return mVCSRepository;
44}
45
46QIcon CustomFileIconProvider::icon(IconType type) const
47{
48 if (type == IconType::Folder) {
49 QIcon icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_FOLDER);
50 if (!icon.isNull())
51 return icon;
52 }
53 return QFileIconProvider::icon(type);
54
55}
56
57QIcon CustomFileIconProvider::icon(const QFileInfo &info) const
58{
59 QIcon icon;
60 if (info.isDir()) {
61 if (mVCSRepository->isFileInRepository(info)) {
62 if (mVCSRepository->isFileConflicting(info))
63 icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_FOLDER_VCS_CONFLICT);
64 else if (mVCSRepository->isFileStaged(info))
65 icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_FOLDER_VCS_STAGED);
66 else if (mVCSRepository->isFileChanged(info))
67 icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_FOLDER_VCS_CHANGED);
68 else
69 icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_FOLDER_VCS_NOCHANGE);
70 } else
71 icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_FOLDER);
72 } else if (!info.exists()) {
73 icon = pIconsManager->getIcon(IconsManager::ACTION_MISC_CROSS);
74 } else if (isHFile(info.fileName())) {
75 if (mVCSRepository->isFileInRepository(info)) {
76 if (mVCSRepository->isFileConflicting(info))
77 icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_HFILE_VCS_CONFLICT);
78 else if (mVCSRepository->isFileStaged(info))
79 icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_HFILE_VCS_STAGED);
80 else if (mVCSRepository->isFileChanged(info))
81 icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_HFILE_VCS_CHANGED);
82 else
83 icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_HFILE_VCS_NOCHANGE);
84 } else
85 icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_HFILE);
86 } else if (isCppFile(info.fileName())) {
87 if (mVCSRepository->isFileInRepository(info)) {
88 if (mVCSRepository->isFileConflicting(info))
89 icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_CPPFILE_VCS_CONFLICT);
90 else if (mVCSRepository->isFileStaged(info))
91 icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_CPPFILE_VCS_STAGED);
92 else if (mVCSRepository->isFileChanged(info))
93 icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_CPPFILE_VCS_CHANGED);
94 else
95 icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_CPPFILE_VCS_NOCHANGE);
96 } else
97 icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_CPPFILE);
98 } else if (isCFile(info.fileName())) {
99 if (mVCSRepository->isFileInRepository(info)) {
100 if (mVCSRepository->isFileConflicting(info))
101 icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_CFILE_VCS_CONFLICT);
102 else if (mVCSRepository->isFileStaged(info))
103 icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_CFILE_VCS_STAGED);
104 else if (mVCSRepository->isFileChanged(info))
105 icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_CFILE_VCS_CHANGED);
106 else
107 icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_CFILE_VCS_NOCHANGE);
108 } else
109 icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_CFILE);
110 } else if (info.suffix()=="dev") {
111 if (mVCSRepository->isFileInRepository(info)) {
112 if (mVCSRepository->isFileConflicting(info))
113 icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_PROJECTFILE_VCS_CONFLICT);
114 else if (mVCSRepository->isFileStaged(info))
115 icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_PROJECTFILE_VCS_STAGED);
116 else if (mVCSRepository->isFileChanged(info))
117 icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_PROJECTFILE_VCS_CHANGED);
118 else
119 icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_PROJECTFILE_VCS_NOCHANGE);
120 } else
121 icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_PROJECTFILE);
122 } else {
123 if (mVCSRepository->isFileInRepository(info)) {
124 if (mVCSRepository->isFileConflicting(info))
125 icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_FILE_VCS_CONFLICT);
126 else if (mVCSRepository->isFileStaged(info))
127 icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_FILE_VCS_STAGED);
128 else if (mVCSRepository->isFileChanged(info))
129 icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_FILE_VCS_CHANGED);
130 else
131 icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_FILE_VCS_NOCHANGE);
132 } //use default system icon
133 }
134 if (!icon.isNull())
135 return icon;
136 return QFileIconProvider::icon(info);
137}
138