Commit 9aaf43a1 authored by Julius Künzel's avatar Julius Künzel
Browse files

Make it possible to export custom effect xmls

The is possible through the context menu of a custom effect in the effect
list
parent aea5c36e
Pipeline #98253 canceled with stage
......@@ -41,6 +41,18 @@ QString AssetTreeModel::getName(const QModelIndex &index) const
return item->dataColumn(AssetTreeModel::nameCol).toString();
}
QString AssetTreeModel::getAssetId(const QModelIndex &index) const
{
if (!index.isValid()) {
return QString();
}
std::shared_ptr<TreeItem> item = getItemById(int(index.internalId()));
if (item->depth() == 1) {
return QString();
}
return item->dataColumn(AssetTreeModel::idCol).toString();
}
bool AssetTreeModel::isFavorite(const QModelIndex &index) const
{
if (!index.isValid()) {
......
......@@ -22,11 +22,13 @@ public:
enum { IdRole = Qt::UserRole + 1, NameRole, FavoriteRole, TypeRole };
// Helper function to retrieve name
/** @brief Helper function to retrieve name */
QString getName(const QModelIndex &index) const;
// Helper function to retrieve description
/** @brief Helper function to retrieve asset id */
QString getAssetId(const QModelIndex &index) const;
/** @brief Helper function to retrieve description */
QString getDescription(bool isEffect, const QModelIndex &index) const;
// Helper function to retrieve if an effect is categorized as favorite
/** @brief Helper function to retrieve if an effect is categorized as favorite */
bool isFavorite(const QModelIndex &index) const;
QHash<int, QByteArray> roleNames() const override;
QVariant data(const QModelIndex &index, int role) const override;
......
......@@ -50,6 +50,11 @@ QString AssetListWidget::getName(const QModelIndex &index) const
return m_model->getName(m_proxyModel->mapToSource(index));
}
QString AssetListWidget::getAssetId(const QModelIndex &index) const
{
return m_model->getName(m_proxyModel->mapToSource(index));
}
bool AssetListWidget::isFavorite(const QModelIndex &index) const
{
return m_model->isFavorite(m_proxyModel->mapToSource(index));
......
......@@ -31,6 +31,9 @@ public:
/** @brief Returns the name of the asset given its model index */
QString getName(const QModelIndex &index) const;
/** @brief Returns the asset id of the asset given its model index */
QString getAssetId(const QModelIndex &index) const;
/** @brief Returns true if this effect belongs to favorites */
bool isFavorite(const QModelIndex &index) const;
......
......@@ -341,6 +341,14 @@ Rectangle {
assetlist.editCustomEffectInfo(sel.currentIndex)
}
}
MenuItem {
id: exportMenu
text: i18n("Export XML…")
visible: isEffectList && assetContextMenu.isCustom
onTriggered: {
assetlist.exportCustomEffect(sel.currentIndex)
}
}
}
TableViewColumn { role: "identifier"; title: i18n("Name"); }
......
......@@ -18,6 +18,10 @@
#include <QDialogButtonBox>
#include <QLineEdit>
#include <QTextEdit>
#include <QFileDialog>
#include <KIO/FileCopyJob>
#include <KRecentDirs>
#include <KMessageBox>
EffectListWidget::EffectListWidget(QWidget *parent)
: AssetListWidget(parent)
......@@ -123,3 +127,25 @@ void EffectListWidget::editCustomAsset(const QModelIndex &index)
m_model->editCustomAsset(name, enteredDescription, m_proxyModel->mapToSource(index));
}
}
void EffectListWidget::exportCustomEffect(const QModelIndex &index) {
QString id = getAssetId(index);
if (id.isEmpty()) {
return;
}
QString filter = QString("%1 (*.xml);;%2 (*)").arg(i18n("Kdenlive Effect definitions"), i18n("All Files"));
QFileDialog dialog(this, i18n("Export Custom Effect"));
QString startFolder = KRecentDirs::dir(QStringLiteral(":KdenliveExportCustomEffect"));
QUrl source = QUrl::fromLocalFile(EffectsRepository::get()->getCustomPath(id));
startFolder.append(source.fileName());
QString filename = QFileDialog::getSaveFileName(this, i18n("Export Custom Effect"), startFolder, filter);
QUrl target = QUrl::fromLocalFile(filename);
if (source.isValid() && target.isValid()) {
KRecentDirs::add(QStringLiteral(":KdenliveExportCustomEffect"), target.adjusted(QUrl::RemoveFilename).toLocalFile());
KIO::FileCopyJob *copyjob = KIO::file_copy(source, target);
if (!copyjob->exec()) {
KMessageBox::sorry(this, i18n("Unable to write to file %1", target.toLocalFile()));
}
}
}
......@@ -33,6 +33,7 @@ public:
void reloadEffectMenu(QMenu *effectsMenu, KActionCategory *effectActions);
void reloadCustomEffectIx(const QModelIndex &index) override;
void editCustomAsset(const QModelIndex &index) override;
void exportCustomEffect(const QModelIndex &index);
public slots:
void reloadCustomEffect(const QString &path);
......@@ -66,6 +67,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 void exportCustomEffect(const QModelIndex &index){ q->exportCustomEffect(index); }
Q_INVOKABLE QVariantMap getMimeData(const QString &assetId) const { return q->getMimeData(assetId); }
Q_INVOKABLE void activate(const QModelIndex &ix) { q->activate(ix); }
......
Supports Markdown
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