14#include <klocalizedstring.h>
25 return QMessageBox::question(widgetParent, i18nc(
"Dialog title",
"Overwrite the file?"),
26 i18nc(
"Question in a dialog/messagebox",
"This resource file already exists in the resource folder. "
27 "Do you want to overwrite it?\nResource filename: %1", QFileInfo(resourceFilepath).fileName()),
28 QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel) != QMessageBox::Cancel;
34#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
37 qsizetype sumHere = 0;
39 if (resourceIdToIgnore < 0) {
43 for (
int i = 0; i < list.size(); i++) {
44 if (list[i]->resourceId() != resourceIdToIgnore) {
52 if (sizeFilteredById(resourcesWithTheSameExactName) > 0) {
57 if (sizeFilteredById(resourcesWithSpacesReplacedByUnderlines) > 0) {
78 QMessageBox::warning(widgetParent, i18nc(
"@title:window",
"Failed to import the resource"), i18nc(
"Warning message",
"Failed to import the resource."));
90 bool userWantsRename = QMessageBox::question(widgetParent, i18nc(
"@title:window",
"Rename the resource?"),
91 i18nc(
"Question in a dialog/messagebox",
"This name is already used for another resource. "
92 "Do you want to use the same name for multiple resources?"
93 "(If you decline now, the resource won't be renamed)."),
94 QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel) != QMessageBox::Cancel;
95 if (!userWantsRename) {
101 QMessageBox::warning(widgetParent, i18nc(
"@title:window",
"Failed to rename the resource"), i18nc(
"Warning message",
"Failed to rename the resource."));
115 typedef enum {ADD, OVERWRITE, CANCEL} Action;
118 int resourceWithThatFilenameId;
123 bool userWantsOverwrite = QMessageBox::question(widgetParent, i18nc(
"@title:window",
"Overwrite the resource?"),
124 i18nc(
"Question in a dialog/messagebox",
"This filename is already used for another resource. "
125 "Do you want to overwrite that resource?\n"
126 "(If you decline now, nothing will be done)."),
127 QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel) != QMessageBox::Cancel;
128 if (userWantsOverwrite) {
137 bool userWantsAdd = QMessageBox::question(widgetParent, i18nc(
"@title:window",
"Add the resource?"),
138 i18nc(
"Question in a dialog/messagebox",
"This name is already used for another resource. "
139 "Do you want to use the same name for multiple resources? "
140 "(If you decline now, the resource won't be added)."),
141 QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel) != QMessageBox::Cancel;
152 bool res = resourceModel.
addResource(resource, storageLocation);
154 QMessageBox::warning(widgetParent, i18nc(
"@title:window",
"Failed to add resource"), i18nc(
"Warning message",
"Failed to add the resource."));
157 }
else if (action == OVERWRITE) {
173 if (resource->resourceId() < 0) {
176 if (QFileInfo(resource->storageLocation()).isRelative()) {
177 QString storageLocation = resource->storageLocation();
187 qWarning() <<
"Could not get resource id from versioned filename"
188 << resource->filename()
189 << resource->resourceType().first;
192 if (outResourceId >= 0) {
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."));
202 buffer.open(QIODevice::ReadWrite);
204 resource->saveToDevice(&buffer);
206 buffer.open(QIODevice::ReadWrite);
210 resource = cachedPointer;
214 if (resource->name() != oldName) {
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) {
230 QMessageBox::warning(widgetParent, i18nc(
"@title:window",
"Failed to overwrite the resource"), i18nc(
"Warning message",
"Failed to overwrite the resource."));
static KisResourcesInterfaceSP instance()
static bool getResourceIdFromVersionedFilename(QString filename, QString resourceType, QString storageLocation, int &outResourceId)
Note that here you can put even the original filename - any filename from the versioned_resources - a...
QString makeStorageLocationRelative(QString location) const
static KisResourceLocator * instance()
The KisResourceModel class provides the main access to resources. It is possible to filter the resour...
KoResourceSP resourceForId(int id) const
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
bool renameResource(KoResourceSP resource, const QString &name) override
renameResource name the given resource. The resource will have its name field reset,...
bool updateResource(KoResourceSP resource) override
updateResource creates a new version of the resource in the storage and in the database....
QVector< KoResourceSP > resourcesForName(QString name) const
bool addResource(KoResourceSP resource, const QString &storageId=QString("")) override
addResource adds the given resource to the database and storage. If the resource already exists in th...
void setResourceFilter(ResourceFilter filter) override
QModelIndex indexForResourceId(int resourceId) const override
indexFromResource
static KoResourceSP importResourceFileWithUserInput(QWidget *widgetParent, QString storageLocation, QString resourceType, QString resourceFilepath)
static bool userAllowsOverwrite(QWidget *widgetParent, QString resourceFilepath)
static bool renameResourceWithUserInput(QWidget *widgetParent, KoResourceSP resource, QString resourceName)
static bool resourceNameIsAlreadyUsed(KisResourceModel *resourceModel, QString resourceName, int resourceIdToIgnore=-1)
static bool addResourceWithUserInput(QWidget *widgetParent, KoResourceSP resource, QString storageLocation="")
static bool updateResourceWithUserInput(QWidget *widgetParent, KoResourceSP resource)
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)