110{
111
113
114 if (startPath.isEmpty()) {
115 startPath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
116 }
117
119 dialog.setDefaultDir(startPath);
120 dialog.setCaption(i18nc(
"Resource Importer file dialog title",
"Import Resources and Resource Libraries"));
123
124
125 if (debug) qCritical() << "All filenames: " << filenames;
126
127
128 QMap<QString, QString> troublesomeFiles;
130
131 QMap<QString, QStringList> troublesomeFilesPerMimetype;
132
133
134
135 QMap<QString, QString> resourceTypePerFile;
136
138 QMap<ImportFailureReason, QStringList> failedFiles;
143
144
145 for (int i = 0; i < filenames.count(); i++) {
148 if (debug) qCritical() << "We're loading a storage here: " << filenames[i];
149
150
151
153 if (debug) qCritical() << "checking for storage" << filenames[i] << QFileInfo(filenames[i]).fileName();
154
155
156 bool skip = false;
158 skip = true;
159
160
161
162
163
164
165
166
167
168
169 }
172 } else {
173 successfullyImportedFiles << filenames[i];
174 }
175
177
180 if (differentResourceTypes) {
181 if (debug) qCritical() << "We have a difficult situation here!" << filenames[i];
182
183 troublesomeFiles.insert(filenames[i], mimetype);
184 if (!troublesomeMimetypes.contains(mimetype)) {
185 troublesomeMimetypes.append(mimetype);
186 }
187
188 if (!troublesomeFilesPerMimetype.contains(mimetype)) {
189 troublesomeFilesPerMimetype.insert(mimetype,
QStringList());
190 }
191 troublesomeFilesPerMimetype[mimetype] = troublesomeFilesPerMimetype[mimetype] << filenames[i];
192
193 } else {
194 if (debug) qCritical() << "We're loading a" << mimetype << " here: " << filenames[i];
196 }
197 } else {
199 }
200
201 }
202
203 QMap<QString, QStringList> troublesomeResourceTypesPerMimetype;
204 for (int i = 0; i < troublesomeMimetypes.size(); i++) {
206 }
207
208 if (troublesomeMimetypes.count() > 0) {
210 if (dlg.exec() == QDialog::Accepted) {
211 for (int i = 0; i < troublesomeMimetypes.count(); i++) {
212 QString resourceType = dlg.getResourceTypeForMimetype(troublesomeMimetypes[i]);
213 QString mimetype = troublesomeMimetypes[i];
214 if (troublesomeFilesPerMimetype.contains(mimetype)) {
215 for (int j = 0; j < troublesomeFilesPerMimetype[mimetype].size(); j++) {
216 resourceTypePerFile.insert(troublesomeFilesPerMimetype[mimetype][j], resourceType);
217 }
218 }
219 }
220 } else {
221 for (int i = 0; i < troublesomeMimetypes.count(); i++) {
222 for (int j = 0; j < troublesomeFilesPerMimetype[troublesomeMimetypes[i]].size(); j++) {
223 failedFiles[
CancelledByTheUser] << troublesomeFilesPerMimetype[troublesomeMimetypes[i]][j];
224 }
225 }
226 }
227 }
228
229
230
231
232 if (debug) qCritical() << "Resource types for mimetype: ";
233
237 }
238 }
239
241
242 QStringList resourceFiles = resourceTypePerFile.keys();
243 for (int i = 0; i < resourceFiles.count(); i++) {
244 QString resourceType = resourceTypePerFile[resourceFiles[i]];
245 if (debug) qCritical() << "Loading " << resourceFiles[i] << "as" << resourceType;
247 if (debug) qCritical() << "We do have a resource model for that!";
249
250 bool allowOverwrite = false;
251
252
255 continue;
256 } else {
257 allowOverwrite = true;
258 }
259 }
260
262 if (res.isNull()) {
263 if (debug) qCritical() << "But the resource is null :( ";
265 } else {
266 if (debug) qCritical() << "The resource isn't null, great!";
267 successfullyImportedFiles << resourceFiles[i];
268 }
269 } else {
271 }
272 }
273
274 if (debug) qCritical() << "Failed files: " << failedFiles;
275 if (debug) qCritical() << "Successfully imported files: " << successfullyImportedFiles;
276
278 int failedFilesCount = 0;
279 for (int i = 0; i < keys.size(); i++) {
280 failedFilesCount += failedFiles[keys[i]].size();
281 }
282 if (failedFilesCount > 0) {
284 dlg.exec();
285 }
286
287}
QList< QString > QStringList
static QString mimeTypeForFile(const QString &file, bool checkExistingFiles=true)
Find the mimetype for the given filename. The filename must include a suffix.
QString resourceLocationBase() const
resourceLocationBase is the place where all resource storages (folder, bundles etc....
static KisResourceLocator * instance()
The KisResourceModel class provides the main access to resources. It is possible to filter the resour...
KoResourceSP importResourceFile(const QString &filename, const bool allowOverwrite, const QString &storageId=QString("")) override
importResourceFile
bool importWillOverwriteResource(const QString &fileName, const QString &storageLocation=QString()) const override
importWillOverwriteResource checks is importing a resource with this filename will overwrite anything
static bool userAllowsOverwrite(QWidget *widgetParent, QString resourceFilepath)
static KisStorageModel * instance()
QStringList m_storagesMimetypes
QStringList m_zipMimetypes
QMap< QString, QStringList > m_resourceTypesForMimetype
QStringList m_allMimetypes
int size(const Forest< T > &forest)
PyObject * debug(PyObject *, PyObject *args)