14#include "ui_wdgdlgcreatebundle.h"
23#include <QProcessEnvironment>
25#include <QStandardPaths>
26#include <QTableWidget>
38#include <kstandardguiitem.h>
55 , m_ui(new
Ui::WdgDlgCreateBundle)
57 , m_storageAdded(false)
60 setWizardStyle(QWizard::ClassicStyle);
74 setSideWidget(wdgSide);
75 setButtonText(QWizard::FinishButton, i18n(
"Save"));
77 connect(
this, SIGNAL(currentIdChanged(
int)), wdgSide, SLOT(focusLabel(
int)));
81 for (
int i = 0; i < resourceTypesModel.
rowCount(); i++) {
82 QModelIndex idx = resourceTypesModel.index(i, 0);
84 m_count.insert(resourceType, 0);
94 #if defined HAVE_SEEXPR
99 for (
int i = 0; i < resourceTypes.size(); i++) {
102 while (iter->hasNext()) {
106 m_count[resourceTypes[i]] = count;
109 while (tagIter->hasNext()) {
111 m_tags.insert(tagIter->tag()->name());
124 QString title = i18n(
"Create Resource Bundle");
127 case 1: title = i18n(
"Choose Resources");
break;
128 case 2: title = i18n(
"Choose Tags");
break;
129 case 3: title = i18n(
"Enter Bundle Details");
break;
130 case 4: title = i18n(
"Enter Save Location");
break;
133 setWindowTitle(title);
135 QString title = i18n(
"Edit Resource Bundle");
138 case 1: title = i18n(
"Edit Resources");
break;
139 case 2: title = i18n(
"Edit Tags");
break;
140 case 3: title = i18n(
"Edit Bundle Details");
break;
141 case 4: title = i18n(
"Edit Save Location");
break;
144 setWindowTitle(title);
158 for (
int i = 0; i < tagModel->rowCount(); i++) {
159 QModelIndex idx = tagModel->index(i, 0);
173 QMap<QString, QSharedPointer<KisResourceModel>> modelsPerResourceType;
175 for (
int i = 0; i < resourceTypesModel.
rowCount(); i++) {
176 QModelIndex idx = resourceTypesModel.index(i, 0);
181 modelsPerResourceType.insert(resourceType, model);
184 QStringList resourceTypes = modelsPerResourceType.keys();
188 Q_FOREACH(
int id, selectedResourcesIds) {
189 allResourcesIds << id;
193 QHash<QPair<QString, QString>, std::size_t> usedFilenames;
195 while(!allResourcesIds.isEmpty()) {
196 const int id = allResourcesIds.takeFirst();
198 QString resourceTypeHere =
"";
200 for (
const auto &type: resourceTypes) {
201 res = modelsPerResourceType[type]->resourceForId(
id);
203 resModel = modelsPerResourceType[type];
204 resourceTypeHere = type;
209 warnKrita <<
"No resource for id " << id;
214 if (usedFilenames.value({res->resourceType().first, prettyFilename}, 0) > 0) {
215 QMessageBox::warning(
217 i18nc(
"@title:window",
"Krita"),
218 i18nc(
"Warning message",
"More than one resource share the same file name '%1'. Please export them in separate bundles.", prettyFilename));
222 usedFilenames[{res->resourceType().first, prettyFilename}]+= 1;
227 bundle->addResource(res->resourceType().first, res->filename(), tags, res->md5Sum(), res->resourceId(), prettyFilename);
238 qWarning() <<
"WARNING: DlgCreateBundle::putResourcesInTheBundle couldn't fetch a linked resource" << linkedResource.
signature();
242 if (!allResourcesIds.contains(resource->resourceId())) {
243 allResourcesIds.append(resource->resourceId());
274 QString resourceType = resource->resourceType().first;
279 return resource->filename();
285 const auto fileInfo = QFileInfo(resource->filename());
286 const auto prefix = fileInfo.dir();
288 const auto nameWithoutSuffix = QFileInfo(resource->name()).completeBaseName();
289 const auto suffix = fileInfo.suffix();
290 return QDir::cleanPath(prefix.filePath(nameWithoutSuffix +
"." + suffix));
302 cfg.
writeEntry<QString>(
"BundleDescription",
"");
317 if (name.isEmpty()) {
319 QMessageBox::warning(
this, i18nc(
"@title:window",
"Krita"), i18n(
"The resource bundle name cannot be empty."));
326 QMessageBox::warning(
this, i18nc(
"@title:window",
"Krita"), i18n(
"The save location cannot be empty."));
330 QFileInfo fileInfo(filename);
332 if (fileInfo.exists()) {
335 QMessageBox msgBox(
this);
336 msgBox.setIcon(QMessageBox::Question);
337 msgBox.setText(i18nc(
"In a dialog asking whether to overwrite a bundle (resource pack)",
"A bundle with this name already exists."));
338 msgBox.setInformativeText(i18nc(
"In a dialog regarding overwriting a bundle (resource pack)",
"Do you want to overwrite the existing bundle?"));
339 msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Cancel);
340 msgBox.setDefaultButton(QMessageBox::Cancel);
341 int ret = msgBox.exec();
342 if (ret == QMessageBox::Cancel) {
357 QMessageBox::critical(
this,
358 i18nc(
"@title:window",
"Krita"),
359 i18n(
"Could not open '%1' for saving.", filename));
373 QMessageBox::critical(
this,
374 i18nc(
"@title:window",
"Krita"),
375 i18n(
"Could not open '%1' for saving.", filename));
QList< QString > QStringList
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
bool putResourcesInTheBundle(KoResourceBundleSP bundle)
~DlgCreateBundle() override
QList< int > m_selectedTagIds
PageMetadataInfo * m_pageMetadataInfo
Ui::WdgDlgCreateBundle * m_ui
PageTagChooser * m_pageTagChooser
QString createPrettyFilenameFromName(KoResourceSP resource) const
void putMetaDataInTheBundle(KoResourceBundleSP bundle) const
PageBundleSaver * m_pageBundleSaver
KoResourceBundleSP m_bundle
QVector< KisTagSP > getTagsForEmbeddingInResource(QVector< KisTagSP > resourceTags, QString resourceType) const
PageResourceChooser * m_pageResourceChooser
QMap< QString, int > m_count
QString m_bundleCreaterMode
void saveToConfiguration(bool full)
DlgCreateBundle(KoResourceBundleSP bundle=nullptr, QWidget *parent=0)
KisBundleStorage * m_bundleStorage
QSharedPointer< KisResourceStorage::ResourceIterator > resources(const QString &resourceType) override
QSharedPointer< KisResourceStorage::TagIterator > tags(const QString &resourceType) override
void writeEntry(const QString &name, const T &value)
static KisResourcesInterfaceSP instance()
The KisResourceModel class provides the main access to resources. It is possible to filter the resour...
static const QString s_meta_author
static const QString s_meta_title
static const QString s_meta_email
static const QString s_meta_license
static const QString s_meta_description
static const QString s_meta_website
static const QString s_meta_initial_creator
static const QString s_meta_creator
QVariant data(const QModelIndex &index, int role) const override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
KisTagSP tagForUrl(const QString &url) const override
Retrieve a tag by url.
A KoResourceBundle is a zip file that contains resources, some metadata about the creator of the bund...
KoResourceSP resource() const noexcept
KoResourceSignature signature() const
QString saveLocation() const
QString bundleName() const
QString previewImage() const
QString authorName() const
QString description() const
QList< int > selectedTagIds()
#define KIS_SAFE_ASSERT_RECOVER(cond)
const QString SeExprScripts
const QString PaintOpPresets