From: Jean-Baptiste Mardelle Date: Mon, 10 Mar 2008 23:19:14 +0000 (+0000) Subject: User can now save & delete custom export profiles X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=f1981d1274474f4679e3fcd0ede56b9406fc7140;p=kdenlive User can now save & delete custom export profiles svn path=/branches/KDE4/; revision=2045 --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0efc4b97..0e4f61f1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -38,6 +38,7 @@ kde4_add_ui_files(kdenlive_UI widgets/titlewidget_ui.ui widgets/timelinebuttons_ui.ui widgets/renderwidget_ui.ui + widgets/saveprofile_ui.ui ) set(kdenlive_SRCS diff --git a/src/kdenlivedoc.cpp b/src/kdenlivedoc.cpp index 7f93841b..fa83913f 100644 --- a/src/kdenlivedoc.cpp +++ b/src/kdenlivedoc.cpp @@ -114,6 +114,12 @@ ClipManager *KdenliveDoc::clipManager() { return m_clipManager; } +QString KdenliveDoc::getDocumentStandard() { + //WARNING: this way to tell the video standard is a bit hackish... + if (m_profile.description.contains("pal", Qt::CaseInsensitive) || m_profile.description.contains("25", Qt::CaseInsensitive) || m_profile.description.contains("50", Qt::CaseInsensitive)) return "PAL"; + return "NTSC"; +} + QString KdenliveDoc::profilePath() const { return m_profile.path; } diff --git a/src/kdenlivedoc.h b/src/kdenlivedoc.h index af970bb2..738e3898 100644 --- a/src/kdenlivedoc.h +++ b/src/kdenlivedoc.h @@ -69,6 +69,8 @@ Q_OBJECT public: void setThumbsProgress(KUrl url, int progress); QString profilePath() const; QString description() const; + /** Returns the document format: PAL or NTSC */ + QString getDocumentStandard(); private: KUrl m_url; diff --git a/src/renderwidget.cpp b/src/renderwidget.cpp index 8cb2cfc1..bdccc0eb 100644 --- a/src/renderwidget.cpp +++ b/src/renderwidget.cpp @@ -23,22 +23,35 @@ #include #include #include +#include #include "kdenlivesettings.h" #include "renderwidget.h" +#include "ui_saveprofile_ui.h" const int GroupRole = Qt::UserRole; const int ExtensionRole = GroupRole + 1; const int StandardRole = GroupRole + 2; const int RenderRole = GroupRole + 3; const int ParamsRole = GroupRole + 4; +const int EditableRole = GroupRole + 5; RenderWidget::RenderWidget(QWidget * parent): QDialog(parent), m_standard("PAL") { m_view.setupUi(this); + m_view.buttonDelete->setIcon(KIcon("trash-empty")); + m_view.buttonDelete->setToolTip(i18n("Delete profile")); + m_view.buttonDelete->setEnabled(false); + + m_view.buttonSave->setIcon(KIcon("document-new")); + m_view.buttonSave->setToolTip(i18n("Create new profile")); + + connect(m_view.buttonSave, SIGNAL(clicked()), this, SLOT(slotSaveProfile())); + connect(m_view.buttonDelete, SIGNAL(clicked()), this, SLOT(slotDeleteProfile())); connect(m_view.buttonStart, SIGNAL(clicked()), this, SLOT(slotExport())); connect(m_view.out_file, SIGNAL(textChanged(const QString &)), this, SLOT(slotUpdateButtons())); connect(m_view.format_list, SIGNAL(currentRowChanged(int)), this, SLOT(refreshView())); connect(m_view.size_list, SIGNAL(currentRowChanged(int)), this, SLOT(refreshParams())); + m_view.buttonStart->setEnabled(false); parseProfiles(); } @@ -48,6 +61,121 @@ void RenderWidget::slotUpdateButtons() { else m_view.buttonStart->setEnabled(true); } +void RenderWidget::slotSaveProfile() { + Ui::SaveProfile_UI ui; + QDialog *d = new QDialog(this); + ui.setupUi(d); + QString customGroup = i18n("Custom"); + QStringList groupNames; + for (int i = 0; i < m_view.format_list->count(); i++) + groupNames.append(m_view.format_list->item(i)->text()); + if (!groupNames.contains(customGroup)) groupNames.prepend(customGroup); + ui.group_name->addItems(groupNames); + int pos = ui.group_name->findText(customGroup); + ui.group_name->setCurrentIndex(pos); + + ui.parameters->setText(m_view.advanced_params->text()); + ui.extension->setText(m_view.size_list->currentItem()->data(ExtensionRole).toString()); + ui.profile_name->setFocus(); + if (d->exec() == QDialog::Accepted) { + QString exportFile = KStandardDirs::locateLocal("data", "kdenlive/export/customprofiles.xml"); + QDomDocument doc; + QFile file(exportFile); + doc.setContent(&file, false); + file.close(); + + QDomElement documentElement; + bool groupExists = false; + QString groupName; + QString newProfileName = ui.profile_name->text(); + QString newGroupName = ui.group_name->currentText(); + QDomNodeList groups = doc.elementsByTagName("group"); + int i = 0; + if (groups.count() == 0) { + QDomElement profiles = doc.createElement("profiles"); + doc.appendChild(profiles); + } else while (!groups.item(i).isNull()) { + documentElement = groups.item(i).toElement(); + groupName = documentElement.attribute("name"); + kDebug() << "// SAVE, PARSING FROUP: " << i << ", name: " << groupName << ", LOOK FR: " << newGroupName; + if (groupName == newGroupName) { + groupExists = true; + break; + } + i++; + } + if (!groupExists) { + documentElement = doc.createElement("group"); + documentElement.setAttribute("name", ui.group_name->currentText()); + documentElement.setAttribute("renderer", "avformat"); + doc.documentElement().appendChild(documentElement); + } + QDomElement profileElement = doc.createElement("profile"); + profileElement.setAttribute("name", newProfileName); + profileElement.setAttribute("extension", ui.extension->text().simplified()); + profileElement.setAttribute("args", ui.parameters->text().simplified()); + documentElement.appendChild(profileElement); + + //QCString save = doc.toString().utf8(); + + if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { + KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile)); + delete d; + return; + } + QTextStream out(&file); + out << doc.toString(); + file.close(); + parseProfiles(); + } + delete d; +} + +void RenderWidget::slotDeleteProfile() { + QString currentGroup = m_view.format_list->currentItem()->text(); + QString currentProfile = m_view.size_list->currentItem()->text(); + + QString exportFile = KStandardDirs::locateLocal("data", "kdenlive/export/customprofiles.xml"); + QDomDocument doc; + QFile file(exportFile); + doc.setContent(&file, false); + file.close(); + + QDomElement documentElement; + bool groupExists = false; + QString groupName; + QDomNodeList groups = doc.elementsByTagName("group"); + int i = 0; + + while (!groups.item(i).isNull()) { + documentElement = groups.item(i).toElement(); + groupName = documentElement.attribute("name"); + if (groupName == currentGroup) { + QDomNodeList children = documentElement.childNodes(); + for (int j = 0; j < children.count(); j++) { + QDomElement pro = children.at(j).toElement(); + if (pro.attribute("name") == currentProfile) { + groups.item(i).removeChild(children.at(j)); + if (groups.item(i).childNodes().isEmpty()) + doc.documentElement().removeChild(groups.item(i)); + break; + } + } + break; + } + i++; + } + + if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { + KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile)); + return; + } + QTextStream out(&file); + out << doc.toString(); + file.close(); + parseProfiles(); +} + void RenderWidget::slotExport() { QFile f(m_view.out_file->url().path()); if (f.exists()) { @@ -103,23 +231,35 @@ void RenderWidget::refreshParams() { } else { m_view.out_file->setUrl(KUrl(QDir::homePath() + "/untitled." + extension)); } + + if (item->data(EditableRole).toString().isEmpty()) m_view.buttonDelete->setEnabled(false); + else m_view.buttonDelete->setEnabled(true); } void RenderWidget::parseProfiles() { + m_view.size_list->clear(); + m_view.format_list->clear(); QString exportFile = KStandardDirs::locate("data", "kdenlive/export/profiles.xml"); + parseFile(exportFile, false); + exportFile = KStandardDirs::locateLocal("data", "kdenlive/export/customprofiles.xml"); + parseFile(exportFile, true); + refreshView(); +} + +void RenderWidget::parseFile(QString exportFile, bool editable) { QDomDocument doc; QFile file(exportFile); doc.setContent(&file, false); + file.close(); QDomElement documentElement; QDomElement profileElement; - QDomNodeList groups = doc.elementsByTagName("group"); if (groups.count() == 0) { kDebug() << "// Export file: " << exportFile << " IS BROKEN"; return; } - kDebug() << "// FOUND FFECT GROUP: " << groups.count() << " IS BROKEN"; + int i = 0; QString groupName; QString profileName; @@ -134,7 +274,8 @@ void RenderWidget::parseProfiles() { groupName = documentElement.attribute("name", QString::null); extension = documentElement.attribute("extension", QString::null); renderer = documentElement.attribute("renderer", QString::null); - new QListWidgetItem(groupName, m_view.format_list); + if (m_view.format_list->findItems(groupName, Qt::MatchExactly).isEmpty()) + new QListWidgetItem(groupName, m_view.format_list); QDomNode n = groups.item(i).firstChild(); while (!n.isNull()) { @@ -150,29 +291,16 @@ void RenderWidget::parseProfiles() { item->setData(RenderRole, renderer); item->setData(StandardRole, standard); item->setData(ParamsRole, params); + if (editable) item->setData(EditableRole, "true"); n = n.nextSibling(); } i++; - /* - bool ladspaOk = true; - if (tag == "ladspa") { - QString library = documentElement.attribute("library", QString::null); - if (KStandardDirs::locate("ladspa_plugin", library).isEmpty()) ladspaOk = false; - } - - // Parse effect file - if ((filtersList.contains(tag) || producersList.contains(tag)) && ladspaOk) { - bool isAudioEffect = false; - QDomNode propsnode = documentElement.elementsByTagName("properties").item(0); - if (!propsnode.isNull()) { - QDomElement propselement = propsnode.toElement(); - */ } - refreshView(); } + #include "renderwidget.moc" diff --git a/src/renderwidget.h b/src/renderwidget.h index 2bbed5ff..105f84d0 100644 --- a/src/renderwidget.h +++ b/src/renderwidget.h @@ -32,16 +32,20 @@ class RenderWidget : public QDialog { public: RenderWidget(QWidget * parent = 0); void setDocumentStandard(QString std); + private slots: void slotUpdateButtons(); void slotExport(); void refreshView(); void refreshParams(); + void slotSaveProfile(); + void slotDeleteProfile(); private: Ui::RenderWidget_UI m_view; QString m_standard; void parseProfiles(); + void parseFile(QString exportFile, bool editable); signals: void doRender(const QString&, const QStringList &, bool, bool); diff --git a/src/widgets/renderwidget_ui.ui b/src/widgets/renderwidget_ui.ui index 6566530f..c4825fd2 100644 --- a/src/widgets/renderwidget_ui.ui +++ b/src/widgets/renderwidget_ui.ui @@ -112,7 +112,11 @@ - + + + true + + diff --git a/src/widgets/saveprofile_ui.ui b/src/widgets/saveprofile_ui.ui new file mode 100644 index 00000000..205bb9ec --- /dev/null +++ b/src/widgets/saveprofile_ui.ui @@ -0,0 +1,132 @@ + + SaveProfile_UI + + + + 0 + 0 + 400 + 225 + + + + Save Profile + + + + + + Group + + + + + + + + + + Profile name + + + + + + + + + + Extension + + + + + + + 4 + + + + + + + Parameters + + + + + + + + + + Qt::Vertical + + + + 20 + 17 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + KComboBox + QComboBox +
kcombobox.h
+
+ + KLineEdit + QLineEdit +
klineedit.h
+
+
+ + + + buttonBox + accepted() + SaveProfile_UI + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + SaveProfile_UI + reject() + + + 316 + 260 + + + 286 + 274 + + + + +