83{
85
86 if (!md5.isEmpty()) {
88 int penalty = 0;
89
90 if (!res->active()) {
91 penalty += 100;
92 }
93
94 if (!filename.isEmpty() && filename != res->filename()) {
97 penalty += 2;
98 }
99
100 if (!
name.isEmpty() && name != res->name()) {
101 penalty++;
102 }
103
104 foundResources.append(qMakePair(res, penalty));
105 }
106
110 return {};
111 }
112 }
113
114#ifdef SANITY_CHECKS
121 const bool warnAboutIncorrectMd5Fetch =
122 foundResources.isEmpty() && !md5.isEmpty();
123#endif
124
125 if (foundResources.isEmpty()) {
126 if (!filename.isEmpty()) {
128 int penalty = 0;
129
130 if (!res->active()) {
131 penalty += 100;
132 }
133
134 if (!
name.isEmpty() && name != res->name()) {
135 penalty++;
136 }
137
138 foundResources.append(qMakePair(res, penalty));
139 }
140 }
else if (!
name.isEmpty()) {
142 int penalty = 0;
143
144 if (!res->active()) {
145 penalty += 100;
146 }
147
148 foundResources.append(qMakePair(res, penalty));
149 }
150 }
151 }
152
153 auto it = std::min_element(foundResources.begin(), foundResources.end(),
154 [] (const QPair<KoResourceSP, int> &lhs,
155 const QPair<KoResourceSP, int> &rhs) {return lhs.second < rhs.second;});
156
158
159#ifdef SANITY_CHECKS
160 if (warnAboutIncorrectMd5Fetch && result) {
161 qWarning() << "KisResourcesInterface::ResourceSourceAdapter::bestMatch: failed to fetch a resource using md5; falling back for filename...";
162 qWarning() <<
" requested:" <<
ppVar(md5) <<
ppVar(filename) <<
ppVar(name);
163 qWarning() << " found:" << result;
164 qWarning() << " candidates:" << foundResources;
165
166#ifdef CRASH_ON_SANITY_CHECK_FAILURE
167 qFatal("Exiting...");
168#endif
169 }
170#endif
171
172 return result;
173}
virtual QVector< KoResourceSP > resourcesForFilename(const QString &filename) const =0
virtual QVector< KoResourceSP > resourcesForMD5(const QString &md5) const =0
virtual QVector< KoResourceSP > resourcesForName(const QString &name) const =0
KoResourceSP exactMatch(const QString md5, const QString filename, const QString name)
exactMatch retrieves a resource, preferably by md5, but with filename and name as fallback for older ...
QSharedPointer< KoResource > KoResourceSP