167{
170
172
173 if (resource->resourceId() < 0) {
174
175
176 if (QFileInfo(resource->storageLocation()).isRelative()) {
177 QString storageLocation = resource->storageLocation();
179 }
180
181 int outResourceId;
182
183
186 if (!result) {
187 qWarning() << "Could not get resource id from versioned filename"
188 << resource->filename()
189 << resource->resourceType().first;
190 }
192 if (outResourceId >= 0) {
193 cachedPointer = resourceModel.resourceForId(outResourceId);
194 }
195
196 if (!cachedPointer || !resource->isSerializable() || !cachedPointer->isSerializable()) {
197 QMessageBox::warning(widgetParent, i18nc("@title:window", "Failed to overwrite the resource"), i18nc("Warning message", "Failed to overwrite the resource."));
198 return false;
199 }
200
201 QBuffer buffer;
202 buffer.open(QIODevice::ReadWrite);
203
204 resource->saveToDevice(&buffer);
205 buffer.close();
206 buffer.open(QIODevice::ReadWrite);
207
209 buffer.close();
210 resource = cachedPointer;
211 }
212
213 QString oldName = resourceModel.data(resourceModel.indexForResourceId(resource->resourceId()), Qt::UserRole +
KisAllResourcesModel::Name).toString();
214 if (resource->name() != oldName) {
215
217 bool userWantsRename = QMessageBox::question(widgetParent, i18nc("@title:window", "Rename the resource?"),
218 i18nc("Question in a dialog/messagebox", "This name is already used for another resource. Do you want to overwrite "
219 "and use the same name for multiple resources?"
220 "\nIf you cancel, your changes won't be saved."),
221 QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel) != QMessageBox::Cancel;
222 if (!userWantsRename) {
223 return false;
224 }
225 }
226 }
227
228 bool res = resourceModel.updateResource(resource);
229 if (!res) {
230 QMessageBox::warning(widgetParent, i18nc("@title:window", "Failed to overwrite the resource"), i18nc("Warning message", "Failed to overwrite the resource."));
231 }
232 return res;
233}
static KisResourcesInterfaceSP instance()
QString makeStorageLocationRelative(QString location) const
static KisResourceLocator * instance()