]> git.sesse.net Git - kdenlive/blob - src/renderwidget.cpp
New export profiles file format, export is now working as expected
[kdenlive] / src / renderwidget.cpp
1 /***************************************************************************
2  *   Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
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.                                   *
8  *                                                                         *
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.                          *
13  *                                                                         *
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  ***************************************************************************/
19
20
21 #include <QDomDocument>
22
23 #include <KStandardDirs>
24 #include <KDebug>
25 #include <KMessageBox>
26
27 #include "kdenlivesettings.h"
28 #include "renderwidget.h"
29
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;
35
36 RenderWidget::RenderWidget(QWidget * parent): QDialog(parent), m_standard("PAL") {
37     m_view.setupUi(this);
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);
43     parseProfiles();
44 }
45
46 void RenderWidget::slotUpdateButtons() {
47     if (m_view.out_file->url().isEmpty()) m_view.buttonStart->setEnabled(false);
48     else m_view.buttonStart->setEnabled(true);
49 }
50
51 void RenderWidget::slotExport() {
52     QFile f(m_view.out_file->url().path());
53     if (f.exists()) {
54         if (KMessageBox::warningYesNo(this, i18n("File already exists. Doy you want to overwrite it ?")) != KMessageBox::Yes)
55             return;
56     }
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());
58 }
59
60 void RenderWidget::setDocumentStandard(QString std) {
61     m_standard = std;
62     refreshView();
63 }
64
65 void RenderWidget::refreshView() {
66     QListWidgetItem *item = m_view.format_list->currentItem();
67     if (!item) {
68         m_view.format_list->setCurrentRow(0);
69         item = m_view.format_list->currentItem();
70     }
71     if (!item) return;
72     QString std;
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);
83             firstSelected = true;
84         } else sizeItem->setHidden(true);
85     }
86
87 }
88
89 void RenderWidget::refreshParams() {
90     QListWidgetItem *item = m_view.size_list->currentItem();
91     if (!item) return;
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();
97     if (!url.isEmpty()) {
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));
103     } else {
104         m_view.out_file->setUrl(KUrl(QDir::homePath() + "/untitled." + extension));
105     }
106 }
107
108 void RenderWidget::parseProfiles() {
109     QString exportFile = KStandardDirs::locate("data", "kdenlive/export/profiles.xml");
110     QDomDocument doc;
111     QFile file(exportFile);
112     doc.setContent(&file, false);
113     QDomElement documentElement;
114     QDomElement profileElement;
115
116     QDomNodeList groups = doc.elementsByTagName("group");
117
118     if (groups.count() == 0) {
119         kDebug() << "// Export file: " << exportFile << " IS BROKEN";
120         return;
121     }
122     kDebug() << "// FOUND FFECT GROUP: " << groups.count() << " IS BROKEN";
123     int i = 0;
124     QString groupName;
125     QString profileName;
126     QString extension;
127     QString prof_extension;
128     QString renderer;
129     QString params;
130     QString standard;
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);
138
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);
153             n = n.nextSibling();
154         }
155
156         i++;
157         /*
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;
162                 }
163
164                 // Parse effect file
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();
170         */
171     }
172     refreshView();
173 }
174
175
176 #include "renderwidget.moc"
177
178