Commit 4f72a61b authored by Halla Rempt's avatar Halla Rempt
Browse files

Clean up the create bundle dialog

Pre-fill the fields with the documentinfo settings or the previously
used settings and keep the meta object local to the resource bundle.
parent 51646664
......@@ -2,16 +2,19 @@
#include "ui_KoBundleCreationWidget.h"
#include "KoXmlResourceBundleMeta.h"
#include <KoDocumentInfo.h>
#include <QProcessEnvironment>
#include <QFileInfo>
#include <QMessageBox>
#include <kis_config.h>
#include <resourcemanager.h>
KoBundleCreationWidget::KoBundleCreationWidget(KoXmlResourceBundleMeta* newMeta, QWidget *parent)
KoBundleCreationWidget::KoBundleCreationWidget(QWidget *parent)
: KDialog(parent)
, m_ui(new Ui::KoBundleCreationWidget)
, m_newMeta(newMeta)
{
m_page = new QWidget();
m_ui->setupUi(m_page);
......@@ -20,8 +23,15 @@ KoBundleCreationWidget::KoBundleCreationWidget(KoXmlResourceBundleMeta* newMeta,
setButtons(Ok | Cancel);
setDefaultButton(Ok);
connect(this, SIGNAL(okClicked()), SLOT(createBundle()));
connect(this, SIGNAL(cancelClicked()), SLOT(reject()));
KoDocumentInfo info;
info.updateParameters();
KisConfig cfg;
m_ui->editAuthor->setText(cfg.readEntry<QString>("BundleAuthorName", info.authorInfo("creator")));
m_ui->editEmail->setText(cfg.readEntry<QString>("BundleAuthorEmail", info.authorInfo("email")));
m_ui->editWebsite->setText(cfg.readEntry<QString>("BundleWebsite", "http://"));
m_ui->editLicense->setText(cfg.readEntry<QString>("BunleLicense", "CC-BY-SA"));
}
KoBundleCreationWidget::~KoBundleCreationWidget()
......@@ -29,31 +39,65 @@ KoBundleCreationWidget::~KoBundleCreationWidget()
delete m_ui;
}
QString KoBundleCreationWidget::bundleName() const
{
return m_ui->editBundleName->text().replace(" ", "_");
}
QString KoBundleCreationWidget::authorName() const
{
return m_ui->editAuthor->text();
}
QString KoBundleCreationWidget::email() const
{
return m_ui->editEmail->text();
}
QString KoBundleCreationWidget::website() const
{
return m_ui->editWebsite->text();
}
QString KoBundleCreationWidget::license() const
{
return m_ui->editLicense->text();
}
QString KoBundleCreationWidget::description() const
{
return m_ui->editDescription->document()->toPlainText();
}
//TODO Vérifier la présence de caractères invalides dans le nom du paquet (exemple : *"')
//Même s'ils semblent acceptés par le système
void KoBundleCreationWidget::createBundle()
void KoBundleCreationWidget::accept()
{
QString name = m_ui->editBundleName->text().remove(" ");
if (name.isEmpty()) {
m_ui->editBundleName->setStyleSheet(QString(" border: 1px solid red"));
emit status("Empty bundle name...");
QMessageBox::warning(this, "Krita", i18n("The resource bundle name cannot be empty."));
return;
}
else {
KoResourceServer<KoResourceBundle> *rServer = ResourceBundleServerProvider::instance()->resourceBundleServer();
QFileInfo fileInfo(rServer->saveLocation() + name + ".bundle");
if (fileInfo.exists()) {
m_ui->editBundleName->setStyleSheet("border: 1px solid red");
emit status("Bundle already exists : choose another name...");
QMessageBox::warning(this, "Krita", i18n("A bundle with this name already exists."));
return;
}
else {
m_newMeta->setMeta(name, m_ui->editAuthor->text(), m_ui->editLicense->text(),
m_ui->editWebsite->text(),
m_ui->editDescription->document()->toPlainText());
accept();
KisConfig cfg;
cfg.writeEntry<QString>("BundleAuthorName", m_ui->editAuthor->text());
cfg.writeEntry<QString>("BundleAuthorEmail", m_ui->editEmail->text());
cfg.writeEntry<QString>("BundleWebsite", m_ui->editWebsite->text());
cfg.writeEntry<QString>("BunleLicense", m_ui->editLicense->text());
KDialog::accept();
}
}
}
......
......@@ -3,8 +3,6 @@
#include <kdialog.h>
class KoXmlResourceBundleMeta;
namespace Ui
{
class KoBundleCreationWidget;
......@@ -15,19 +13,23 @@ class KoBundleCreationWidget : public KDialog
Q_OBJECT
public:
explicit KoBundleCreationWidget(KoXmlResourceBundleMeta* m_newMeta, QWidget *parent = 0);
explicit KoBundleCreationWidget(QWidget *parent = 0);
~KoBundleCreationWidget();
signals:
void status(QString text, int timeout = 0);
QString bundleName() const;
QString authorName() const;
QString email() const;
QString website() const;
QString license() const;
QString description() const;
private slots:
void createBundle();
void accept();
private:
QWidget *m_page;
Ui::KoBundleCreationWidget *m_ui;
KoXmlResourceBundleMeta *m_newMeta;
};
#endif // KOBUNDLECREATIONWIDGET_H
......@@ -26,7 +26,7 @@
<item row="0" column="0">
<widget class="QLabel" name="bundleName">
<property name="text">
<string>Bundle Name </string>
<string>Bundle Name:</string>
</property>
</widget>
</item>
......@@ -36,7 +36,7 @@
<item row="1" column="0">
<widget class="QLabel" name="author">
<property name="text">
<string>Author</string>
<string>Author:</string>
</property>
<property name="scaledContents">
<bool>false</bool>
......@@ -53,44 +53,54 @@
</property>
</widget>
</item>
<item row="2" column="0">
<item row="4" column="0">
<widget class="QLabel" name="website">
<property name="text">
<string>Website</string>
<string>Website:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="4" column="1">
<widget class="QLineEdit" name="editWebsite">
<property name="text">
<string/>
<string>http://</string>
</property>
</widget>
</item>
<item row="3" column="0">
<item row="5" column="0">
<widget class="QLabel" name="license">
<property name="text">
<string>License</string>
<string>License:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<item row="5" column="1">
<widget class="QLineEdit" name="editLicense">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="4" column="0">
<item row="6" column="0">
<widget class="QLabel" name="description">
<property name="text">
<string>Description</string>
<string>Description:</string>
</property>
</widget>
</item>
<item row="4" column="1">
<item row="6" column="1">
<widget class="QPlainTextEdit" name="editDescription"/>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="editEmail"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Email:</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
......
......@@ -37,7 +37,9 @@
//TODO Voir s'il ne vaut pas mieux faire un constructeur avec un xmlmeta plutot qu'un setmeta (cf control createPack)
KoResourceBundle::KoResourceBundle(QString const& fileName)
: KoResource(fileName)
: KoResource(fileName)\
, m_manifest(new KoXmlResourceBundleManifest())
, m_meta(new KoXmlResourceBundleMeta())
{
m_kritaPath = fileName.section('/', 0, fileName.count('/') - 2);
if (!m_kritaPath.isEmpty() && m_kritaPath.at(m_kritaPath.size() - 1) != '/') {
......@@ -74,12 +76,12 @@ bool KoResourceBundle::load()
m_packName = filename();
if (m_resourceStore->bad()) {
m_manifest = new KoXmlResourceBundleManifest();
m_meta = new KoXmlResourceBundleMeta();
m_installed = false;
} else {
//TODO Vérifier si on peut éviter de recréer manifest et meta à chaque load
//A optimiser si possible
delete m_manifest;
delete m_meta;
m_manifest = new KoXmlResourceBundleManifest(getFile("manifest.xml"));
m_meta = new KoXmlResourceBundleMeta(getFile("meta.xml"));
m_thumbnail.load(getFile("thumbnail.jpg"), "JPG");
......
......@@ -19,7 +19,6 @@
#include "KoResourceManagerControl.h"
#include "KoXmlResourceBundleManifest.h"
#include "KoXmlResourceBundleMeta.h"
#include "KoResourceTableModel.h"
#include "KoBundleCreationWidget.h"
......@@ -87,55 +86,54 @@ bool KoResourceManagerControl::createPack(int type)
else {
emit status("Creating new bundle...");
KoXmlResourceBundleMeta* newMeta = new KoXmlResourceBundleMeta();
KoBundleCreationWidget *bundleCreationWidget = new KoBundleCreationWidget(newMeta);
connect(bundleCreationWidget, SIGNAL(status(QString, int)), this, SLOT(toStatus(QString, int)));
if (bundleCreationWidget->exec() == 0 || newMeta == 0) {
KoBundleCreationWidget bundleCreationWidget;
if (bundleCreationWidget.exec() != QDialog::Accepted) {
emit status("Creation cancelled", 3000);
return false;
}
else {
QString bundlePath = ResourceBundleServerProvider::instance()->resourceBundleServer()->saveLocation() + newMeta->getPackName() + ".bundle";
KoResourceBundle* newBundle = new KoResourceBundle(bundlePath);
bool isEmpty = true;
newBundle->load();
newBundle->setMeta(newMeta);
for (int i = 0; i < selected.size(); i++) {
QString currentFileName = selected.at(i);
KoResource* currentResource = currentModel->getResourceFromFilename(selected.at(i));
KoResourceBundle* currentBundle = dynamic_cast<KoResourceBundle*>(currentResource);
if (currentFileName.contains('/') && !currentBundle) {
isEmpty = false;
newBundle->addFile(currentFileName.section('/', currentFileName.count("/") - 1, currentFileName.count("/") - 1), currentFileName,
currentModel->assignedTagsList(currentResource));
}
}
QString bundlePath = ResourceBundleServerProvider::instance()->resourceBundleServer()->saveLocation() + bundleCreationWidget.bundleName() + ".bundle";
KoResourceBundle* newBundle = new KoResourceBundle(bundlePath);
bool isEmpty = true;
newBundle->addMeta("name", bundleCreationWidget.bundleName());
newBundle->addMeta("author", bundleCreationWidget.authorName());
newBundle->addMeta("email", bundleCreationWidget.email());
newBundle->addMeta("license", bundleCreationWidget.license());
newBundle->addMeta("website", bundleCreationWidget.website());
newBundle->addMeta("description", bundleCreationWidget.description());
if (isEmpty) {
delete newBundle;
emit status("No valid content to be added to a new bundle...Creation Cancelled", 3000);
return false;
for (int i = 0; i < selected.size(); i++) {
QString currentFileName = selected.at(i);
KoResource* currentResource = currentModel->getResourceFromFilename(selected.at(i));
KoResourceBundle* currentBundle = dynamic_cast<KoResourceBundle*>(currentResource);
if (currentFileName.contains('/') && !currentBundle) {
isEmpty = false;
newBundle->addFile(currentFileName.section('/', currentFileName.count("/") - 1, currentFileName.count("/") - 1), currentFileName,
currentModel->assignedTagsList(currentResource));
}
}
newBundle->addMeta("fileName", bundlePath);
newBundle->addMeta("created", QDate::currentDate().toString("dd/MM/yyyy"));
if (isEmpty) {
delete newBundle;
emit status("No valid content to be added to a new bundle...Creation Cancelled", 3000);
return false;
}
ResourceBundleServerProvider::instance()->resourceBundleServer()->addResource(newBundle);
newBundle->addMeta("fileName", bundlePath);
newBundle->addMeta("created", QDate::currentDate().toString("dd/MM/yyyy"));
QStringList tagsList = newBundle->getTagsList();
ResourceBundleServerProvider::instance()->resourceBundleServer()->addResource(newBundle);
for (int i = 0; i < tagsList.size(); i++) {
ResourceBundleServerProvider::instance()->resourceBundleServer()->addTag(newBundle, tagsList.at(i));
}
QStringList tagsList = newBundle->getTagsList();
currentModel->tagCategoryMembersChanged();
currentModel->clearSelected();
return true;
for (int i = 0; i < tagsList.size(); i++) {
ResourceBundleServerProvider::instance()->resourceBundleServer()->addTag(newBundle, tagsList.at(i));
}
currentModel->tagCategoryMembersChanged();
currentModel->clearSelected();
return true;
}
}
......
......@@ -57,6 +57,8 @@ KoXmlResourceBundleMeta::TagEnum KoXmlResourceBundleMeta::getTagEnumValue(QStrin
return Filename;
} else if (tagName == "author") {
return Author;
} else if (tagName == "email") {
return Email;
} else if (tagName == "created") {
return Created;
} else if (tagName == "license") {
......
......@@ -29,7 +29,17 @@ private:
* @description Allows to sort correctly the XML document.
* @details Other means all other values that are not listed before.
*/
enum TagEnum {Name = 0, Filename, Author, Created, License, Updated, Description, Website, Tag, Other};
enum TagEnum {Name = 0,
Filename,
Author,
Created,
License,
Updated,
Description,
Website,
Tag,
Email,
Other};
public:
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment