]> git.sesse.net Git - kdenlive/blob - src/renderwidget.cpp
Only display available codecs in rendering dialog
[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 #include <KComboBox>
27
28 #include "kdenlivesettings.h"
29 #include "renderwidget.h"
30 #include "ui_saveprofile_ui.h"
31
32 const int GroupRole = Qt::UserRole;
33 const int ExtensionRole = GroupRole + 1;
34 const int StandardRole = GroupRole + 2;
35 const int RenderRole = GroupRole + 3;
36 const int ParamsRole = GroupRole + 4;
37 const int EditableRole = GroupRole + 5;
38
39 RenderWidget::RenderWidget(QWidget * parent): QDialog(parent) {
40     m_view.setupUi(this);
41     m_view.buttonDelete->setIcon(KIcon("trash-empty"));
42     m_view.buttonDelete->setToolTip(i18n("Delete profile"));
43     m_view.buttonDelete->setEnabled(false);
44
45     m_view.buttonEdit->setIcon(KIcon("document-properties"));
46     m_view.buttonEdit->setToolTip(i18n("Edit profile"));
47     m_view.buttonEdit->setEnabled(false);
48
49     m_view.buttonSave->setIcon(KIcon("document-new"));
50     m_view.buttonSave->setToolTip(i18n("Create new profile"));
51
52     m_view.buttonInfo->setIcon(KIcon("help-about"));
53
54     if (KdenliveSettings::showrenderparams()) {
55         m_view.buttonInfo->setDown(true);
56     } else m_view.advanced_params->hide();
57
58     m_view.experimentalrender->setChecked(KdenliveSettings::experimentalrender());
59
60     m_view.experimentalrender->setToolTip(i18n("Changing the size of video when rendering\nis not fully supported, you may have problems\nwith some effects or title clips, so the export\nprofiles that resize your video are marked as\nexperimental"));
61
62     connect(m_view.buttonInfo, SIGNAL(clicked()), this, SLOT(showInfoPanel()));
63
64     connect(m_view.buttonSave, SIGNAL(clicked()), this, SLOT(slotSaveProfile()));
65     connect(m_view.buttonEdit, SIGNAL(clicked()), this, SLOT(slotEditProfile()));
66     connect(m_view.buttonDelete, SIGNAL(clicked()), this, SLOT(slotDeleteProfile()));
67     connect(m_view.buttonStart, SIGNAL(clicked()), this, SLOT(slotExport()));
68     connect(m_view.out_file, SIGNAL(textChanged(const QString &)), this, SLOT(slotUpdateButtons()));
69     connect(m_view.format_list, SIGNAL(currentRowChanged(int)), this, SLOT(refreshView()));
70     connect(m_view.size_list, SIGNAL(currentRowChanged(int)), this, SLOT(refreshParams()));
71
72     connect(m_view.render_guide, SIGNAL(clicked(bool)), this, SLOT(slotUpdateGuideBox()));
73     connect(m_view.render_zone, SIGNAL(clicked(bool)), this, SLOT(slotUpdateGuideBox()));
74     connect(m_view.render_full, SIGNAL(clicked(bool)), this, SLOT(slotUpdateGuideBox()));
75
76     connect(m_view.guide_end, SIGNAL(activated(int)), this, SLOT(slotCheckStartGuidePosition()));
77     connect(m_view.guide_start, SIGNAL(activated(int)), this, SLOT(slotCheckEndGuidePosition()));
78
79     connect(m_view.format_selection, SIGNAL(activated(int)), this, SLOT(refreshView()));
80     connect(m_view.experimentalrender, SIGNAL(stateChanged(int)), this, SLOT(slotUpdateExperimentalRendering()));
81
82     m_view.buttonStart->setEnabled(false);
83     m_view.guides_box->setVisible(false);
84     parseProfiles();
85     m_view.splitter->setStretchFactor(1, 5);
86     m_view.splitter->setStretchFactor(0, 2);
87
88     m_view.out_file->setMode(KFile::File);
89     focusFirstVisibleItem();
90 }
91
92 void RenderWidget::slotUpdateExperimentalRendering() {
93     KdenliveSettings::setExperimentalrender(m_view.experimentalrender->isChecked());
94     refreshView();
95 }
96
97
98 void RenderWidget::showInfoPanel() {
99     if (m_view.advanced_params->isVisible()) {
100         m_view.advanced_params->setVisible(false);
101         m_view.buttonInfo->setDown(false);
102         KdenliveSettings::setShowrenderparams(false);
103     } else {
104         m_view.advanced_params->setVisible(true);
105         m_view.buttonInfo->setDown(true);
106         KdenliveSettings::setShowrenderparams(true);
107     }
108 }
109
110 void RenderWidget::slotUpdateGuideBox() {
111     m_view.guides_box->setVisible(m_view.render_guide->isChecked());
112 }
113
114 void RenderWidget::slotCheckStartGuidePosition() {
115     if (m_view.guide_start->currentIndex() > m_view.guide_end->currentIndex())
116         m_view.guide_start->setCurrentIndex(m_view.guide_end->currentIndex());
117 }
118
119 void RenderWidget::slotCheckEndGuidePosition() {
120     if (m_view.guide_end->currentIndex() < m_view.guide_start->currentIndex())
121         m_view.guide_end->setCurrentIndex(m_view.guide_start->currentIndex());
122 }
123
124 void RenderWidget::setGuides(QDomElement guidesxml, double duration) {
125     m_view.guide_start->clear();
126     m_view.guide_end->clear();
127     QDomNodeList nodes = guidesxml.elementsByTagName("guide");
128     if (nodes.count() > 0) {
129         m_view.guide_start->addItem(i18n("Render"), "0");
130         m_view.render_guide->setEnabled(true);
131     } else m_view.render_guide->setEnabled(false);
132     for (int i = 0; i < nodes.count(); i++) {
133         QDomElement e = nodes.item(i).toElement();
134         if (!e.isNull()) {
135             m_view.guide_start->addItem(e.attribute("comment"), e.attribute("time").toDouble());
136             m_view.guide_end->addItem(e.attribute("comment"), e.attribute("time").toDouble());
137         }
138     }
139     if (nodes.count() > 0)
140         m_view.guide_end->addItem(i18n("End"), QString::number(duration));
141 }
142
143 void RenderWidget::slotUpdateButtons() {
144     if (m_view.out_file->url().isEmpty()) m_view.buttonStart->setEnabled(false);
145     else m_view.buttonStart->setEnabled(true);
146 }
147
148 void RenderWidget::slotSaveProfile() {
149     Ui::SaveProfile_UI ui;
150     QDialog *d = new QDialog(this);
151     ui.setupUi(d);
152     QString customGroup = i18n("Custom");
153     QStringList groupNames;
154     for (int i = 0; i < m_view.format_list->count(); i++)
155         groupNames.append(m_view.format_list->item(i)->text());
156     if (!groupNames.contains(customGroup)) groupNames.prepend(customGroup);
157     ui.group_name->addItems(groupNames);
158     int pos = ui.group_name->findText(customGroup);
159     ui.group_name->setCurrentIndex(pos);
160
161     ui.parameters->setText(m_view.advanced_params->toPlainText());
162     ui.extension->setText(m_view.size_list->currentItem()->data(ExtensionRole).toString());
163     ui.profile_name->setFocus();
164     if (d->exec() == QDialog::Accepted && !ui.profile_name->text().simplified().isEmpty()) {
165         QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
166         QDomDocument doc;
167         QFile file(exportFile);
168         doc.setContent(&file, false);
169         file.close();
170
171         QDomElement documentElement;
172         bool groupExists = false;
173         QString groupName;
174         QString newProfileName = ui.profile_name->text().simplified();
175         QString newGroupName = ui.group_name->currentText();
176         QDomNodeList groups = doc.elementsByTagName("group");
177         int i = 0;
178         if (groups.count() == 0) {
179             QDomElement profiles = doc.createElement("profiles");
180             doc.appendChild(profiles);
181         } else while (!groups.item(i).isNull()) {
182                 documentElement = groups.item(i).toElement();
183                 groupName = documentElement.attribute("name");
184                 kDebug() << "// SAVE, PARSING FROUP: " << i << ", name: " << groupName << ", LOOK FR: " << newGroupName;
185                 if (groupName == newGroupName) {
186                     groupExists = true;
187                     break;
188                 }
189                 i++;
190             }
191         if (!groupExists) {
192             documentElement = doc.createElement("group");
193             documentElement.setAttribute("name", ui.group_name->currentText());
194             documentElement.setAttribute("renderer", "avformat");
195             doc.documentElement().appendChild(documentElement);
196         }
197         QDomElement profileElement = doc.createElement("profile");
198         profileElement.setAttribute("name", newProfileName);
199         profileElement.setAttribute("extension", ui.extension->text().simplified());
200         profileElement.setAttribute("args", ui.parameters->toPlainText().simplified());
201         documentElement.appendChild(profileElement);
202
203         //QCString save = doc.toString().utf8();
204
205         if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
206             KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
207             delete d;
208             return;
209         }
210         QTextStream out(&file);
211         out << doc.toString();
212         file.close();
213         parseProfiles(newGroupName, newProfileName);
214     }
215     delete d;
216 }
217
218 void RenderWidget::slotEditProfile() {
219     QListWidgetItem *item = m_view.size_list->currentItem();
220     if (!item) return;
221     QString currentGroup = m_view.format_list->currentItem()->text();
222
223     QString params = item->data(ParamsRole).toString();
224     QString extension = item->data(ExtensionRole).toString();
225     QString currentProfile = item->text();
226
227     Ui::SaveProfile_UI ui;
228     QDialog *d = new QDialog(this);
229     ui.setupUi(d);
230     QStringList groupNames;
231     for (int i = 0; i < m_view.format_list->count(); i++)
232         groupNames.append(m_view.format_list->item(i)->text());
233     if (!groupNames.contains(currentGroup)) groupNames.prepend(currentGroup);
234     ui.group_name->addItems(groupNames);
235     int pos = ui.group_name->findText(currentGroup);
236     ui.group_name->setCurrentIndex(pos);
237     ui.profile_name->setText(currentProfile);
238     ui.extension->setText(extension);
239     ui.parameters->setText(params);
240     ui.profile_name->setFocus();
241
242     if (d->exec() == QDialog::Accepted) {
243         slotDeleteProfile();
244         QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
245         QDomDocument doc;
246         QFile file(exportFile);
247         doc.setContent(&file, false);
248         file.close();
249
250         QDomElement documentElement;
251         bool groupExists = false;
252         QString groupName;
253         QString newProfileName = ui.profile_name->text();
254         QString newGroupName = ui.group_name->currentText();
255         QDomNodeList groups = doc.elementsByTagName("group");
256         int i = 0;
257         if (groups.count() == 0) {
258             QDomElement profiles = doc.createElement("profiles");
259             doc.appendChild(profiles);
260         } else while (!groups.item(i).isNull()) {
261                 documentElement = groups.item(i).toElement();
262                 groupName = documentElement.attribute("name");
263                 kDebug() << "// SAVE, PARSING FROUP: " << i << ", name: " << groupName << ", LOOK FR: " << newGroupName;
264                 if (groupName == newGroupName) {
265                     groupExists = true;
266                     break;
267                 }
268                 i++;
269             }
270         if (!groupExists) {
271             documentElement = doc.createElement("group");
272             documentElement.setAttribute("name", ui.group_name->currentText());
273             documentElement.setAttribute("renderer", "avformat");
274             doc.documentElement().appendChild(documentElement);
275         }
276         QDomElement profileElement = doc.createElement("profile");
277         profileElement.setAttribute("name", newProfileName);
278         profileElement.setAttribute("extension", ui.extension->text().simplified());
279         profileElement.setAttribute("args", ui.parameters->toPlainText().simplified());
280         documentElement.appendChild(profileElement);
281
282         //QCString save = doc.toString().utf8();
283
284         if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
285             KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
286             delete d;
287             return;
288         }
289         QTextStream out(&file);
290         out << doc.toString();
291         file.close();
292         parseProfiles(newGroupName, newProfileName);
293     }
294     delete d;
295 }
296
297 void RenderWidget::slotDeleteProfile() {
298     QString currentGroup = m_view.format_list->currentItem()->text();
299     QString currentProfile = m_view.size_list->currentItem()->text();
300
301     QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
302     QDomDocument doc;
303     QFile file(exportFile);
304     doc.setContent(&file, false);
305     file.close();
306
307     QDomElement documentElement;
308     bool groupExists = false;
309     QString groupName;
310     QDomNodeList groups = doc.elementsByTagName("group");
311     int i = 0;
312
313     while (!groups.item(i).isNull()) {
314         documentElement = groups.item(i).toElement();
315         groupName = documentElement.attribute("name");
316         if (groupName == currentGroup) {
317             QDomNodeList children = documentElement.childNodes();
318             for (int j = 0; j < children.count(); j++) {
319                 QDomElement pro = children.at(j).toElement();
320                 if (pro.attribute("name") == currentProfile) {
321                     groups.item(i).removeChild(children.at(j));
322                     if (groups.item(i).childNodes().isEmpty())
323                         doc.documentElement().removeChild(groups.item(i));
324                     break;
325                 }
326             }
327             break;
328         }
329         i++;
330     }
331
332     if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
333         KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
334         return;
335     }
336     QTextStream out(&file);
337     out << doc.toString();
338     file.close();
339     parseProfiles(currentGroup);
340     focusFirstVisibleItem();
341 }
342
343 void RenderWidget::updateButtons() {
344     if (!m_view.size_list->currentItem() || m_view.size_list->currentItem()->isHidden()) {
345         m_view.buttonSave->setEnabled(false);
346         m_view.buttonDelete->setEnabled(false);
347         m_view.buttonEdit->setEnabled(false);
348     } else {
349         m_view.buttonSave->setEnabled(true);
350         if (m_view.size_list->currentItem()->data(EditableRole).toString().isEmpty()) {
351             m_view.buttonDelete->setEnabled(false);
352             m_view.buttonEdit->setEnabled(false);
353         } else {
354             m_view.buttonDelete->setEnabled(true);
355             m_view.buttonEdit->setEnabled(true);
356         }
357     }
358 }
359
360
361 void RenderWidget::focusFirstVisibleItem() {
362     if (m_view.size_list->currentItem() && !m_view.size_list->currentItem()->isHidden()) {
363         updateButtons();
364         return;
365     }
366     for (uint ix = 0; ix < m_view.size_list->count(); ix++) {
367         QListWidgetItem *item = m_view.size_list->item(ix);
368         if (item && !item->isHidden()) {
369             m_view.size_list->setCurrentRow(ix);
370             break;
371         }
372     }
373     if (!m_view.size_list->currentItem()) m_view.size_list->setCurrentRow(0);
374     updateButtons();
375 }
376
377 void RenderWidget::slotExport() {
378     QListWidgetItem *item = m_view.size_list->currentItem();
379     if (!item) return;
380     QFile f(m_view.out_file->url().path());
381     if (f.exists()) {
382         if (KMessageBox::warningYesNo(this, i18n("File already exists. Do you want to overwrite it ?")) != KMessageBox::Yes)
383             return;
384     }
385     QStringList overlayargs;
386     if (m_view.tc_overlay->isChecked()) {
387         QString filterFile = KStandardDirs::locate("appdata", "metadata.properties");
388         overlayargs << "meta.attr.timecode=1" << "meta.attr.timecode.markup=#timecode";
389         overlayargs << "-attach" << "data_feed:attr_check" << "-attach";
390         overlayargs << "data_show:" + filterFile << "_fezzik=1" << "dynamic=1";
391     }
392     double startPos = -1;
393     double endPos = -1;
394     if (m_view.render_guide->isChecked()) {
395         startPos = m_view.guide_start->itemData(m_view.guide_start->currentIndex()).toDouble();
396         endPos = m_view.guide_end->itemData(m_view.guide_end->currentIndex()).toDouble();
397     }
398     QString renderArgs = m_view.advanced_params->toPlainText();
399     renderArgs.replace("%width", QString::number(m_profile.width));
400     renderArgs.replace("%height", QString::number(m_profile.height));
401     renderArgs.replace("%dar", "@" + QString::number(m_profile.display_aspect_num) + "/" + QString::number(m_profile.display_aspect_den));
402     if (m_view.force_progressive->checkState() == Qt::Checked) renderArgs.append(" progressive=1");
403     else if (m_view.force_progressive->checkState() == Qt::Unchecked) renderArgs.append(" progressive=0");
404
405     // Check if the rendering profile is different from project profile,
406     // in which case we need to use the producer_comsumer from MLT
407     bool resizeProfile = false;
408
409     QString std = item->data(ParamsRole).toString();
410     if (resizeProfile == false && std.contains(" s=")) {
411         QString subsize = std.section(" s=", 1, 1);
412         subsize = subsize.section(' ', 0, 0).toLower();
413         if (subsize != "%widthx%height") {
414             const QString currentSize = QString::number(m_profile.width) + 'x' + QString::number(m_profile.height);
415             if (subsize != currentSize) resizeProfile = true;
416         }
417     }
418
419     emit doRender(m_view.out_file->url().path(), item->data(RenderRole).toString(), overlayargs, renderArgs.simplified().split(' '), m_view.render_zone->isChecked(), m_view.play_after->isChecked(), startPos, endPos, resizeProfile);
420 }
421
422 void RenderWidget::setProfile(MltVideoProfile profile) {
423     m_profile = profile;
424     //WARNING: this way to tell the video standard is a bit hackish...
425     if (m_profile.description.contains("pal", Qt::CaseInsensitive) || m_profile.description.contains("25", Qt::CaseInsensitive) || m_profile.description.contains("50", Qt::CaseInsensitive)) m_view.format_selection->setCurrentIndex(0);
426     else m_view.format_selection->setCurrentIndex(1);
427     m_view.force_progressive->setCheckState(Qt::PartiallyChecked);
428     refreshView();
429 }
430
431 void RenderWidget::refreshView() {
432     m_view.size_list->blockSignals(true);
433     QListWidgetItem *item = m_view.format_list->currentItem();
434     if (!item) {
435         m_view.format_list->setCurrentRow(0);
436         item = m_view.format_list->currentItem();
437     }
438     if (!item) return;
439     QString std;
440     QString group = item->text();
441     QListWidgetItem *sizeItem;
442     bool firstSelected = false;
443     const QStringList formatsList = KdenliveSettings::supportedformats();
444     const QStringList vcodecsList = KdenliveSettings::videocodecs();
445     const QStringList acodecsList = KdenliveSettings::audiocodecs();
446     for (int i = 0; i < m_view.size_list->count(); i++) {
447         sizeItem = m_view.size_list->item(i);
448         if (sizeItem->data(GroupRole) == group) {
449             std = sizeItem->data(StandardRole).toString();
450             if (!std.isEmpty()) {
451                 if (std.contains("PAL", Qt::CaseInsensitive)) sizeItem->setHidden(m_view.format_selection->currentIndex() != 0);
452                 else if (std.contains("NTSC", Qt::CaseInsensitive)) sizeItem->setHidden(m_view.format_selection->currentIndex() != 1);
453             } else {
454                 sizeItem->setHidden(false);
455                 if (!firstSelected) m_view.size_list->setCurrentItem(sizeItem);
456                 firstSelected = true;
457             }
458             if (!KdenliveSettings::experimentalrender() && !sizeItem->isHidden()) {
459                 // hide experimental codecs (which do resize the video)
460                 std = sizeItem->data(ParamsRole).toString();
461                 if (std.contains(" s=")) {
462                     QString subsize = std.section(" s=", 1, 1);
463                     subsize = subsize.section(' ', 0, 0).toLower();
464                     if (subsize != "%widthx%height") {
465                         const QString currentSize = QString::number(m_profile.width) + 'x' + QString::number(m_profile.height);
466                         if (subsize != currentSize) sizeItem->setHidden(true);
467                     }
468                 }
469             }
470             if (!sizeItem->isHidden()) {
471                 // Make sure the selected profile uses an installed avformat codec / format
472                 std = sizeItem->data(ParamsRole).toString();
473
474                 if (!formatsList.isEmpty()) {
475                     QString format;
476                     if (std.startsWith("f=")) format = std.section("f=", 1, 1);
477                     else if (std.contains(" f=")) format = std.section(" f=", 1, 1);
478                     if (!format.isEmpty()) {
479                         format = format.section(' ', 0, 0).toLower();
480                         if (!formatsList.contains(format)) {
481                             kDebug() << "*****  UNSUPPORTED F: " << format;
482                             sizeItem->setHidden(true);
483                         }
484                     }
485                 }
486                 if (!acodecsList.isEmpty() && !sizeItem->isHidden()) {
487                     QString format;
488                     if (std.startsWith("acodec=")) format = std.section("acodec=", 1, 1);
489                     else if (std.contains(" acodec=")) format = std.section(" acodec=", 1, 1);
490                     if (!format.isEmpty()) {
491                         format = format.section(' ', 0, 0).toLower();
492                         if (!acodecsList.contains(format)) {
493                             kDebug() << "*****  UNSUPPORTED ACODEC: " << format;
494                             sizeItem->setHidden(true);
495                         }
496                     }
497                 }
498                 if (!vcodecsList.isEmpty() && !sizeItem->isHidden()) {
499                     QString format;
500                     if (std.startsWith("vcodec=")) format = std.section("vcodec=", 1, 1);
501                     else if (std.contains(" vcodec=")) format = std.section(" vcodec=", 1, 1);
502                     if (!format.isEmpty()) {
503                         format = format.section(' ', 0, 0).toLower();
504                         if (!vcodecsList.contains(format)) {
505                             kDebug() << "*****  UNSUPPORTED VCODEC: " << format;
506                             sizeItem->setHidden(true);
507                         }
508                     }
509                 }
510             }
511         } else sizeItem->setHidden(true);
512     }
513     focusFirstVisibleItem();
514     m_view.size_list->blockSignals(false);
515     refreshParams();
516 }
517
518 void RenderWidget::refreshParams() {
519     QListWidgetItem *item = m_view.size_list->currentItem();
520     if (!item || item->isHidden()) {
521         m_view.advanced_params->clear();
522         m_view.buttonStart->setEnabled(false);
523         return;
524     }
525     QString params = item->data(ParamsRole).toString();
526     QString extension = item->data(ExtensionRole).toString();
527     m_view.advanced_params->setPlainText(params);
528     m_view.advanced_params->setToolTip(params);
529     KUrl url = m_view.out_file->url();
530     if (!url.isEmpty()) {
531         QString path = url.path();
532         int pos = path.lastIndexOf('.') + 1;
533         if (pos == 0) path.append('.') + extension;
534         else path = path.left(pos) + extension;
535         m_view.out_file->setUrl(KUrl(path));
536     } else {
537         m_view.out_file->setUrl(KUrl(QDir::homePath() + "/untitled." + extension));
538     }
539     m_view.out_file->setFilter("*." + extension);
540
541     if (item->data(EditableRole).toString().isEmpty()) {
542         m_view.buttonDelete->setEnabled(false);
543         m_view.buttonEdit->setEnabled(false);
544     } else {
545         m_view.buttonDelete->setEnabled(true);
546         m_view.buttonEdit->setEnabled(true);
547     }
548     m_view.buttonStart->setEnabled(true);
549 }
550
551 void RenderWidget::parseProfiles(QString group, QString profile) {
552     m_view.size_list->clear();
553     m_view.format_list->clear();
554     QString exportFile = KStandardDirs::locate("appdata", "export/profiles.xml");
555     parseFile(exportFile, false);
556     exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
557     if (QFile::exists(exportFile)) parseFile(exportFile, true);
558     refreshView();
559     QList<QListWidgetItem *> child;
560     child = m_view.format_list->findItems(group, Qt::MatchExactly);
561     if (!child.isEmpty()) m_view.format_list->setCurrentItem(child.at(0));
562     child = m_view.size_list->findItems(profile, Qt::MatchExactly);
563     if (!child.isEmpty()) m_view.size_list->setCurrentItem(child.at(0));
564 }
565
566 void RenderWidget::parseFile(QString exportFile, bool editable) {
567     QDomDocument doc;
568     QFile file(exportFile);
569     doc.setContent(&file, false);
570     file.close();
571     QDomElement documentElement;
572     QDomElement profileElement;
573     QDomNodeList groups = doc.elementsByTagName("group");
574
575     if (groups.count() == 0) {
576         kDebug() << "// Export file: " << exportFile << " IS BROKEN";
577         return;
578     }
579
580     int i = 0;
581     QString groupName;
582     QString profileName;
583     QString extension;
584     QString prof_extension;
585     QString renderer;
586     QString params;
587     QString standard;
588     QListWidgetItem *item;
589     while (!groups.item(i).isNull()) {
590         documentElement = groups.item(i).toElement();
591         groupName = documentElement.attribute("name", QString::null);
592         extension = documentElement.attribute("extension", QString::null);
593         renderer = documentElement.attribute("renderer", QString::null);
594         if (m_view.format_list->findItems(groupName, Qt::MatchExactly).isEmpty())
595             new QListWidgetItem(groupName, m_view.format_list);
596
597         QDomNode n = groups.item(i).firstChild();
598         while (!n.isNull()) {
599             profileElement = n.toElement();
600             profileName = profileElement.attribute("name");
601             standard = profileElement.attribute("standard");
602             params = profileElement.attribute("args");
603             prof_extension = profileElement.attribute("extension");
604             if (!prof_extension.isEmpty()) extension = prof_extension;
605             item = new QListWidgetItem(profileName, m_view.size_list);
606             item->setData(GroupRole, groupName);
607             item->setData(ExtensionRole, extension);
608             item->setData(RenderRole, renderer);
609             item->setData(StandardRole, standard);
610             item->setData(ParamsRole, params);
611             if (editable) item->setData(EditableRole, "true");
612             n = n.nextSibling();
613         }
614
615         i++;
616     }
617 }
618
619
620
621 #include "renderwidget.moc"
622
623