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