Commit 5ce4e575 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle

Merge branch 'vivekkde/kdenlive-master'

parents 4f51bc3e c75ac2a8
Pipeline #37321 passed with stage
in 32 minutes and 51 seconds
......@@ -88,6 +88,7 @@ QString AssetTreeModel::getDescription(bool isEffect, const QModelIndex &index)
return QString();
}
QVariant AssetTreeModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid()) {
......
......@@ -49,6 +49,7 @@ public:
virtual void reloadAssetMenu(QMenu *effectsMenu, KActionCategory *effectActions) = 0;
virtual void setFavorite(const QModelIndex &index, bool favorite, bool isEffect) = 0;
virtual void deleteEffect(const QModelIndex &index) = 0;
virtual void editCustomAsset( const QString newName,const QString newDescription,const QModelIndex &index) = 0;
// for convenience, we store the column of each data field
static int nameCol, idCol, favCol, typeCol, preferredCol;
......
......@@ -55,7 +55,7 @@ public:
/* @brief Delete a custom effect */
void deleteCustomEffect(const QModelIndex &index);
virtual void reloadCustomEffectIx(const QModelIndex &index) = 0;
virtual void editCustomAsset(const QModelIndex &index) = 0;
/* @brief Returns the description of the asset given its model index */
QString getDescription(bool isEffect, const QModelIndex &index) const;
......
......@@ -338,6 +338,14 @@ Rectangle {
assetlist.reloadCustomEffectIx(sel.currentIndex)
}
}
MenuItem {
id: editMenu
text: i18n("Edit Info")
visible: isEffectList && assetContextMenu.isCustom
onTriggered: {
assetlist.editCustomEffectInfo(sel.currentIndex)
}
}
}
TableViewColumn { role: "identifier"; title: i18n("Name"); }
......
......@@ -32,6 +32,7 @@
#include <KActionCategory>
#include <QDebug>
#include <QMenu>
#include <QMessageBox>
EffectTreeModel::EffectTreeModel(QObject *parent)
: AssetTreeModel(parent)
......@@ -196,3 +197,76 @@ void EffectTreeModel::setFavorite(const QModelIndex &index, bool favorite, bool
KdenliveSettings::setFavorite_effects(favs);
}
void EffectTreeModel::editCustomAsset(const QString newName,const QString newDescription, const QModelIndex &index)
{
std::shared_ptr<TreeItem> item = getItemById((int)index.internalId());
QString currentName = item->dataColumn(AssetTreeModel::nameCol).toString();
QDomDocument doc;
QDomElement effect = EffectsRepository::get()->getXml(currentName);
QDir dir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/effects/"));
QString oldpath = dir.absoluteFilePath(currentName + QStringLiteral(".xml"));
doc.appendChild(doc.importNode(effect, true));
if(!newDescription.trimmed().isEmpty()){
QDomElement root = doc.documentElement();
QDomElement nodelist = root.firstChildElement("description");
QDomElement newNodeTag = doc.createElement(QString("description"));
QDomText text = doc.createTextNode(newDescription);
newNodeTag.appendChild(text);
root.replaceChild(newNodeTag, nodelist);
}
if(!newName.trimmed().isEmpty() && newName != currentName)
{
QDir dir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/effects/"));
if (!dir.exists()) {
dir.mkpath(QStringLiteral("."));
}
if (dir.exists(newName + QStringLiteral(".xml"))){
QMessageBox message;
message.critical(0, i18n("Error"), i18n("Effect name %1 already exists.\n Try another name?", newName));
message.setFixedSize(400, 200);
return;
}
QFile file(dir.absoluteFilePath(newName + QStringLiteral(".xml")));
QDomElement root = doc.documentElement();
QDomElement nodelist = root.firstChildElement("name");
QDomElement newNodeTag = doc.createElement(QString("name"));
QDomText text = doc.createTextNode(newName);
newNodeTag.appendChild(text);
root.replaceChild(newNodeTag, nodelist);
QDomElement e = doc.documentElement();
e.setAttribute("id", newName);
if (file.open(QFile::WriteOnly | QFile::Truncate)) {
QTextStream out(&file);
out << doc.toString();
}
file.close();
deleteEffect(index);
reloadEffect(dir.absoluteFilePath(newName + QStringLiteral(".xml")));
}
else
{
QFile file(dir.absoluteFilePath(currentName + QStringLiteral(".xml")));
if (file.open(QFile::WriteOnly | QFile::Truncate)) {
QTextStream out(&file);
out << doc.toString();
}
file.close();
reloadEffect(oldpath);
}
}
......@@ -42,6 +42,7 @@ public:
void reloadAssetMenu(QMenu *effectsMenu, KActionCategory *effectActions) override;
void setFavorite(const QModelIndex &index, bool favorite, bool isEffect) override;
void deleteEffect(const QModelIndex &index) override;
void editCustomAsset(const QString newName, const QString newDescription, const QModelIndex &index) override;
protected:
std::shared_ptr<TreeItem> m_customCategory;
......
......@@ -29,6 +29,12 @@
#include <QQmlContext>
#include <QStandardPaths>
#include <memory>
#include <QFormLayout>
#include <QDialog>
#include <QDialogButtonBox>
#include <QLineEdit>
#include <QTextEdit>
EffectListWidget::EffectListWidget(QWidget *parent)
: AssetListWidget(parent)
{
......@@ -101,3 +107,26 @@ void EffectListWidget::reloadEffectMenu(QMenu *effectsMenu, KActionCategory *eff
{
m_model->reloadAssetMenu(effectsMenu, effectActions);
}
void EffectListWidget::editCustomAsset(const QModelIndex &index)
{
QDialog dialog(this);
QFormLayout form(&dialog);
QLineEdit *effectName = new QLineEdit(getName(index), &dialog);
QTextEdit *descriptionBox = new QTextEdit(getDescription(true, index), &dialog);
form.addRow(i18n("Name : "), effectName);
form.addRow(i18n("Comments : "), descriptionBox);
QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &dialog);
form.addRow(&buttonBox);
QObject::connect(&buttonBox, SIGNAL(accepted()), &dialog, SLOT(accept()));
QObject::connect(&buttonBox, SIGNAL(rejected()), &dialog, SLOT(reject()));
if(dialog.exec() == QDialog::Accepted) {
QString name = effectName->text();
QString enteredDescription = descriptionBox->toPlainText();
if (name.trimmed().isEmpty() && enteredDescription.trimmed().isEmpty()) {
return;
}
m_model->editCustomAsset(name, enteredDescription, m_proxyModel->mapToSource(index));
}
}
......@@ -48,7 +48,7 @@ public:
void updateFavorite(const QModelIndex &index);
void reloadEffectMenu(QMenu *effectsMenu, KActionCategory *effectActions);
void reloadCustomEffectIx(const QModelIndex &index) override;
void editCustomAsset(const QModelIndex &index) override;
public slots:
void reloadCustomEffect(const QString &path);
......@@ -81,6 +81,7 @@ public:
}
Q_INVOKABLE void deleteCustomEffect(const QModelIndex &index) { q->deleteCustomEffect(index); }
Q_INVOKABLE QString getDescription(const QModelIndex &index) const { return q->getDescription(true, index); }
Q_INVOKABLE void editCustomEffectInfo(const QModelIndex &index){ q->editCustomAsset(index); }
Q_INVOKABLE QVariantMap getMimeData(const QString &assetId) const { return q->getMimeData(assetId); }
Q_INVOKABLE void activate(const QModelIndex &ix) { q->activate(ix); }
......
......@@ -111,3 +111,6 @@ void TransitionTreeModel::deleteEffect(const QModelIndex &)
{
}
void TransitionTreeModel::editCustomAsset(const QString newName, const QString newDescription, const QModelIndex &index)
{
}
......@@ -40,7 +40,7 @@ public:
void reloadAssetMenu(QMenu *effectsMenu, KActionCategory *effectActions) override;
void setFavorite(const QModelIndex &index, bool favorite, bool isEffect) override;
void deleteEffect(const QModelIndex &index) override;
void editCustomAsset(const QString newName, const QString newDescription, const QModelIndex &index) override;
protected:
};
......
......@@ -107,3 +107,8 @@ void TransitionListWidget::downloadNewLumas()
void TransitionListWidget::reloadCustomEffectIx(const QModelIndex &path)
{
}
void TransitionListWidget::editCustomAsset(const QModelIndex &index)
{
}
......@@ -44,7 +44,7 @@ public:
void updateFavorite(const QModelIndex &index);
void downloadNewLumas();
void reloadCustomEffectIx(const QModelIndex &path) override;
void editCustomAsset(const QModelIndex &index) override;
private:
TransitionListWidgetProxy *m_proxy;
int getNewStuff(const QString &configFile);
......
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