1 /***************************************************************************
2 * Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
21 #include <QDomDocument>
23 #include <KStandardDirs>
25 #include <KMessageBox>
27 #include "kdenlivesettings.h"
28 #include "renderwidget.h"
30 const int GroupRole = Qt::UserRole;
31 const int ExtensionRole = GroupRole + 1;
32 const int StandardRole = GroupRole + 2;
33 const int RenderRole = GroupRole + 3;
34 const int ParamsRole = GroupRole + 4;
36 RenderWidget::RenderWidget(QWidget * parent): QDialog(parent), m_standard("PAL") {
38 connect(m_view.buttonStart, SIGNAL(clicked()), this, SLOT(slotExport()));
39 connect(m_view.out_file, SIGNAL(textChanged(const QString &)), this, SLOT(slotUpdateButtons()));
40 connect(m_view.format_list, SIGNAL(currentRowChanged(int)), this, SLOT(refreshView()));
41 connect(m_view.size_list, SIGNAL(currentRowChanged(int)), this, SLOT(refreshParams()));
42 m_view.buttonStart->setEnabled(false);
46 void RenderWidget::slotUpdateButtons() {
47 if (m_view.out_file->url().isEmpty()) m_view.buttonStart->setEnabled(false);
48 else m_view.buttonStart->setEnabled(true);
51 void RenderWidget::slotExport() {
52 QFile f(m_view.out_file->url().path());
54 if (KMessageBox::warningYesNo(this, i18n("File already exists. Doy you want to overwrite it ?")) != KMessageBox::Yes)
57 emit doRender(m_view.out_file->url().path(), m_view.advanced_params->text().split(' '), m_view.zone_only->isChecked(), m_view.play_after->isChecked());
60 void RenderWidget::setDocumentStandard(QString std) {
65 void RenderWidget::refreshView() {
66 QListWidgetItem *item = m_view.format_list->currentItem();
68 m_view.format_list->setCurrentRow(0);
69 item = m_view.format_list->currentItem();
73 QString group = item->text();
74 QListWidgetItem *sizeItem;
75 bool firstSelected = false;
76 for (int i = 0; i < m_view.size_list->count(); i++) {
77 sizeItem = m_view.size_list->item(i);
78 std = sizeItem->data(StandardRole).toString();
79 if (!std.isEmpty() && !std.contains(m_standard, Qt::CaseInsensitive)) sizeItem->setHidden(true);
80 else if (sizeItem->data(GroupRole) == group) {
81 sizeItem->setHidden(false);
82 if (!firstSelected) m_view.size_list->setCurrentItem(sizeItem);
84 } else sizeItem->setHidden(true);
89 void RenderWidget::refreshParams() {
90 QListWidgetItem *item = m_view.size_list->currentItem();
92 QString params = item->data(ParamsRole).toString();
93 QString extension = item->data(ExtensionRole).toString();
94 m_view.advanced_params->setText(params);
95 m_view.advanced_params->setToolTip(params);
96 KUrl url = m_view.out_file->url();
98 QString path = url.path();
99 int pos = path.lastIndexOf('.') + 1;
100 if (pos == 0) path.append('.') + extension;
101 else path = path.left(pos) + extension;
102 m_view.out_file->setUrl(KUrl(path));
104 m_view.out_file->setUrl(KUrl(QDir::homePath() + "/untitled." + extension));
108 void RenderWidget::parseProfiles() {
109 QString exportFile = KStandardDirs::locate("data", "kdenlive/export/profiles.xml");
111 QFile file(exportFile);
112 doc.setContent(&file, false);
113 QDomElement documentElement;
114 QDomElement profileElement;
116 QDomNodeList groups = doc.elementsByTagName("group");
118 if (groups.count() == 0) {
119 kDebug() << "// Export file: " << exportFile << " IS BROKEN";
122 kDebug() << "// FOUND FFECT GROUP: " << groups.count() << " IS BROKEN";
127 QString prof_extension;
131 QListWidgetItem *item;
132 while (!groups.item(i).isNull()) {
133 documentElement = groups.item(i).toElement();
134 groupName = documentElement.attribute("name", QString::null);
135 extension = documentElement.attribute("extension", QString::null);
136 renderer = documentElement.attribute("renderer", QString::null);
137 new QListWidgetItem(groupName, m_view.format_list);
139 QDomNode n = groups.item(i).firstChild();
140 while (!n.isNull()) {
141 profileElement = n.toElement();
142 profileName = profileElement.attribute("name");
143 standard = profileElement.attribute("standard");
144 params = profileElement.attribute("args");
145 prof_extension = profileElement.attribute("extension");
146 if (!prof_extension.isEmpty()) extension = prof_extension;
147 item = new QListWidgetItem(profileName, m_view.size_list);
148 item->setData(GroupRole, groupName);
149 item->setData(ExtensionRole, extension);
150 item->setData(RenderRole, renderer);
151 item->setData(StandardRole, standard);
152 item->setData(ParamsRole, params);
158 bool ladspaOk = true;
159 if (tag == "ladspa") {
160 QString library = documentElement.attribute("library", QString::null);
161 if (KStandardDirs::locate("ladspa_plugin", library).isEmpty()) ladspaOk = false;
165 if ((filtersList.contains(tag) || producersList.contains(tag)) && ladspaOk) {
166 bool isAudioEffect = false;
167 QDomNode propsnode = documentElement.elementsByTagName("properties").item(0);
168 if (!propsnode.isNull()) {
169 QDomElement propselement = propsnode.toElement();
176 #include "renderwidget.moc"