]> git.sesse.net Git - kdenlive/blob - src/renderwidget.cpp
Add guide positions in render 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 "renderwidget.h"
22 #include "kdenlivesettings.h"
23 #include "ui_saveprofile_ui.h"
24 #include "timecode.h"
25
26 #include <KStandardDirs>
27 #include <KDebug>
28 #include <KMessageBox>
29 #include <KComboBox>
30 #include <KRun>
31 #include <KIO/NetAccess>
32 #include <KColorScheme>
33 #include <KNotification>
34 // #include <knewstuff2/engine.h>
35
36 #include <QDomDocument>
37 #include <QItemDelegate>
38 #include <QTreeWidgetItem>
39 #include <QListWidgetItem>
40 #include <QHeaderView>
41 #include <QMenu>
42 #include <QProcess>
43 #include <QInputDialog>
44
45 const int GroupRole = Qt::UserRole;
46 const int ExtensionRole = GroupRole + 1;
47 const int StandardRole = GroupRole + 2;
48 const int RenderRole = GroupRole + 3;
49 const int ParamsRole = GroupRole + 4;
50 const int EditableRole = GroupRole + 5;
51 const int MetaGroupRole = GroupRole + 6;
52 const int ExtraRole = GroupRole + 7;
53
54 // Running job status
55 const int WAITINGJOB = 0;
56 const int RUNNINGJOB = 1;
57 const int FINISHEDJOB = 2;
58
59
60 RenderWidget::RenderWidget(const QString &projectfolder, QWidget * parent) :
61         QDialog(parent),
62         m_projectFolder(projectfolder),
63         m_blockProcessing(false)
64 {
65     m_view.setupUi(this);
66     setWindowTitle(i18n("Rendering"));
67     m_view.buttonDelete->setIcon(KIcon("trash-empty"));
68     m_view.buttonDelete->setToolTip(i18n("Delete profile"));
69     m_view.buttonDelete->setEnabled(false);
70
71     m_view.buttonEdit->setIcon(KIcon("document-properties"));
72     m_view.buttonEdit->setToolTip(i18n("Edit profile"));
73     m_view.buttonEdit->setEnabled(false);
74
75     m_view.buttonSave->setIcon(KIcon("document-new"));
76     m_view.buttonSave->setToolTip(i18n("Create new profile"));
77
78     m_view.buttonInfo->setIcon(KIcon("help-about"));
79     m_view.hide_log->setIcon(KIcon("go-down"));
80
81     if (KdenliveSettings::showrenderparams()) {
82         m_view.buttonInfo->setDown(true);
83     } else m_view.advanced_params->hide();
84
85     m_view.rescale_size->setInputMask("0099\\x0099");
86     m_view.rescale_size->setText("320x240");
87
88
89     QMenu *renderMenu = new QMenu(i18n("Start Rendering"), this);
90     QAction *renderAction = renderMenu->addAction(KIcon("video-x-generic"), i18n("Render to File"));
91     connect(renderAction, SIGNAL(triggered()), this, SLOT(slotPrepareExport()));
92     QAction *scriptAction = renderMenu->addAction(KIcon("application-x-shellscript"), i18n("Generate Script"));
93     connect(scriptAction, SIGNAL(triggered()), this, SLOT(slotGenerateScript()));
94
95     m_view.buttonStart->setMenu(renderMenu);
96     m_view.buttonStart->setPopupMode(QToolButton::MenuButtonPopup);
97     m_view.buttonStart->setDefaultAction(renderAction);
98     m_view.buttonStart->setToolButtonStyle(Qt::ToolButtonTextOnly);
99     m_view.abort_job->setEnabled(false);
100     m_view.start_script->setEnabled(false);
101     m_view.delete_script->setEnabled(false);
102
103     m_view.format_list->setAlternatingRowColors(true);
104     m_view.size_list->setAlternatingRowColors(true);
105
106     parseProfiles();
107     parseScriptFiles();
108
109     connect(m_view.start_script, SIGNAL(clicked()), this, SLOT(slotStartScript()));
110     connect(m_view.delete_script, SIGNAL(clicked()), this, SLOT(slotDeleteScript()));
111     connect(m_view.scripts_list, SIGNAL(itemSelectionChanged()), this, SLOT(slotCheckScript()));
112     connect(m_view.running_jobs, SIGNAL(itemSelectionChanged()), this, SLOT(slotCheckJob()));
113     connect(m_view.running_jobs, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(slotPlayRendering(QTreeWidgetItem *, int)));
114
115     connect(m_view.buttonInfo, SIGNAL(clicked()), this, SLOT(showInfoPanel()));
116
117     connect(m_view.buttonSave, SIGNAL(clicked()), this, SLOT(slotSaveProfile()));
118     connect(m_view.buttonEdit, SIGNAL(clicked()), this, SLOT(slotEditProfile()));
119     connect(m_view.buttonDelete, SIGNAL(clicked()), this, SLOT(slotDeleteProfile()));
120     connect(m_view.abort_job, SIGNAL(clicked()), this, SLOT(slotAbortCurrentJob()));
121     connect(m_view.clean_up, SIGNAL(clicked()), this, SLOT(slotCLeanUpJobs()));
122     connect(m_view.hide_log, SIGNAL(clicked()), this, SLOT(slotHideLog()));
123
124     connect(m_view.buttonClose, SIGNAL(clicked()), this, SLOT(hide()));
125     connect(m_view.buttonClose2, SIGNAL(clicked()), this, SLOT(hide()));
126     connect(m_view.buttonClose3, SIGNAL(clicked()), this, SLOT(hide()));
127     connect(m_view.rescale, SIGNAL(toggled(bool)), m_view.rescale_size, SLOT(setEnabled(bool)));
128     connect(m_view.destination_list, SIGNAL(activated(int)), this, SLOT(refreshView()));
129     connect(m_view.out_file, SIGNAL(textChanged(const QString &)), this, SLOT(slotUpdateButtons()));
130     connect(m_view.out_file, SIGNAL(urlSelected(const KUrl &)), this, SLOT(slotUpdateButtons(const KUrl &)));
131     connect(m_view.format_list, SIGNAL(currentRowChanged(int)), this, SLOT(refreshView()));
132     connect(m_view.size_list, SIGNAL(currentRowChanged(int)), this, SLOT(refreshParams()));
133
134     connect(m_view.size_list, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(slotEditItem(QListWidgetItem *)));
135
136     connect(m_view.render_guide, SIGNAL(clicked(bool)), this, SLOT(slotUpdateGuideBox()));
137     connect(m_view.render_zone, SIGNAL(clicked(bool)), this, SLOT(slotUpdateGuideBox()));
138     connect(m_view.render_full, SIGNAL(clicked(bool)), this, SLOT(slotUpdateGuideBox()));
139
140     connect(m_view.guide_end, SIGNAL(activated(int)), this, SLOT(slotCheckStartGuidePosition()));
141     connect(m_view.guide_start, SIGNAL(activated(int)), this, SLOT(slotCheckEndGuidePosition()));
142
143     connect(m_view.format_selection, SIGNAL(activated(int)), this, SLOT(refreshView()));
144
145     m_view.buttonStart->setEnabled(false);
146     m_view.rescale_size->setEnabled(false);
147     m_view.guides_box->setVisible(false);
148     m_view.open_dvd->setVisible(false);
149     m_view.create_chapter->setVisible(false);
150     m_view.open_browser->setVisible(false);
151     m_view.error_box->setVisible(false);
152
153     m_view.splitter->setStretchFactor(1, 5);
154     m_view.splitter->setStretchFactor(0, 2);
155
156     m_view.out_file->setMode(KFile::File);
157
158     m_view.running_jobs->setHeaderLabels(QStringList() << QString() << i18n("File") << i18n("Progress"));
159     m_view.running_jobs->setItemDelegate(new RenderViewDelegate(this));
160
161     QHeaderView *header = m_view.running_jobs->header();
162     QFontMetrics fm = fontMetrics();
163     header->setResizeMode(0, QHeaderView::Fixed);
164     header->resizeSection(0, 30);
165     header->setResizeMode(1, QHeaderView::Interactive);
166     header->setResizeMode(2, QHeaderView::Fixed);
167     header->resizeSection(1, width() * 2 / 3 - 15);
168     header->setResizeMode(2, QHeaderView::Interactive);
169     //header->setResizeMode(1, QHeaderView::Fixed);
170
171
172     m_view.scripts_list->setHeaderLabels(QStringList() << QString() << i18n("Script Files"));
173     m_view.scripts_list->setItemDelegate(new RenderViewDelegate(this));
174     header = m_view.scripts_list->header();
175     header->setResizeMode(0, QHeaderView::Fixed);
176     header->resizeSection(0, 30);
177
178     focusFirstVisibleItem();
179 }
180
181 void RenderWidget::slotEditItem(QListWidgetItem *item)
182 {
183     QString edit = item->data(EditableRole).toString();
184     if (edit.isEmpty() || !edit.endsWith("customprofiles.xml")) slotSaveProfile();
185     else slotEditProfile();
186 }
187
188 void RenderWidget::showInfoPanel()
189 {
190     if (m_view.advanced_params->isVisible()) {
191         m_view.advanced_params->setVisible(false);
192         m_view.buttonInfo->setDown(false);
193         KdenliveSettings::setShowrenderparams(false);
194     } else {
195         m_view.advanced_params->setVisible(true);
196         m_view.buttonInfo->setDown(true);
197         KdenliveSettings::setShowrenderparams(true);
198     }
199 }
200
201 void RenderWidget::setDocumentPath(const QString path)
202 {
203     m_projectFolder = path;
204     const QString fileName = m_view.out_file->url().fileName();
205     m_view.out_file->setUrl(KUrl(m_projectFolder + fileName));
206     parseScriptFiles();
207 }
208
209 void RenderWidget::slotUpdateGuideBox()
210 {
211     m_view.guides_box->setVisible(m_view.render_guide->isChecked());
212 }
213
214 void RenderWidget::slotCheckStartGuidePosition()
215 {
216     if (m_view.guide_start->currentIndex() > m_view.guide_end->currentIndex())
217         m_view.guide_start->setCurrentIndex(m_view.guide_end->currentIndex());
218 }
219
220 void RenderWidget::slotCheckEndGuidePosition()
221 {
222     if (m_view.guide_end->currentIndex() < m_view.guide_start->currentIndex())
223         m_view.guide_end->setCurrentIndex(m_view.guide_start->currentIndex());
224 }
225
226 void RenderWidget::setGuides(QDomElement guidesxml, double duration)
227 {
228     m_view.guide_start->clear();
229     m_view.guide_end->clear();
230     QDomNodeList nodes = guidesxml.elementsByTagName("guide");
231     if (nodes.count() > 0) {
232         m_view.guide_start->addItem(i18n("Beginning"), "0");
233         m_view.render_guide->setEnabled(true);
234         m_view.create_chapter->setEnabled(true);
235     } else {
236         m_view.render_guide->setEnabled(false);
237         m_view.create_chapter->setEnabled(false);
238     }
239     double fps = (double) m_profile.frame_rate_num / m_profile.frame_rate_den;
240     for (int i = 0; i < nodes.count(); i++) {
241         QDomElement e = nodes.item(i).toElement();
242         if (!e.isNull()) {
243             GenTime pos = GenTime(e.attribute("time").toDouble());
244             const QString guidePos = Timecode::getStringTimecode(pos.frames(fps), fps);
245             m_view.guide_start->addItem(e.attribute("comment") + '/' + guidePos, e.attribute("time").toDouble());
246             m_view.guide_end->addItem(e.attribute("comment") + '/' + guidePos, e.attribute("time").toDouble());
247         }
248     }
249     if (nodes.count() > 0)
250         m_view.guide_end->addItem(i18n("End"), QString::number(duration));
251 }
252
253 /**
254  * Will be called when the user selects an output file via the file dialog.
255  * File extension will be added automatically.
256  */
257 void RenderWidget::slotUpdateButtons(KUrl url)
258 {
259     if (m_view.out_file->url().isEmpty()) m_view.buttonStart->setEnabled(false);
260     else {
261         updateButtons(); // This also checks whether the selected format is available
262         //m_view.buttonStart->setEnabled(true);
263     }
264     if (url != 0) {
265         QListWidgetItem *item = m_view.size_list->currentItem();
266         QString extension = item->data(ExtensionRole).toString();
267         url = filenameWithExtension(url, extension);
268         m_view.out_file->setUrl(url);
269     }
270 }
271
272 /**
273  * Will be called when the user changes the output file path in the text line.
274  * File extension must NOT be added, would make editing impossible!
275  */
276 void RenderWidget::slotUpdateButtons()
277 {
278     if (m_view.out_file->url().isEmpty()) m_view.buttonStart->setEnabled(false);
279     else updateButtons(); // This also checks whether the selected format is available
280     //else m_view.buttonStart->setEnabled(true);
281 }
282
283 void RenderWidget::slotSaveProfile()
284 {
285     //TODO: update to correctly use metagroups
286     Ui::SaveProfile_UI ui;
287     QDialog *d = new QDialog(this);
288     ui.setupUi(d);
289
290     for (int i = 0; i < m_view.destination_list->count(); i++)
291         ui.destination_list->addItem(m_view.destination_list->itemIcon(i), m_view.destination_list->itemText(i), m_view.destination_list->itemData(i, Qt::UserRole));
292
293     ui.destination_list->setCurrentIndex(m_view.destination_list->currentIndex());
294     QString dest = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
295
296     QString customGroup = m_view.format_list->currentItem()->text();
297     if (customGroup.isEmpty()) customGroup = i18n("Custom");
298     ui.group_name->setText(customGroup);
299
300     ui.parameters->setText(m_view.advanced_params->toPlainText());
301     ui.extension->setText(m_view.size_list->currentItem()->data(ExtensionRole).toString());
302     ui.profile_name->setFocus();
303
304     if (d->exec() == QDialog::Accepted && !ui.profile_name->text().simplified().isEmpty()) {
305         QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
306         QDomDocument doc;
307         QFile file(exportFile);
308         doc.setContent(&file, false);
309         file.close();
310         QDomElement documentElement;
311         QDomElement profiles = doc.documentElement();
312         if (profiles.isNull() || profiles.tagName() != "profiles") {
313             doc.clear();
314             profiles = doc.createElement("profiles");
315             profiles.setAttribute("version", 1);
316             doc.appendChild(profiles);
317         }
318         int version = profiles.attribute("version", 0).toInt();
319         if (version < 1) {
320             kDebug() << "// OLD profile version";
321             doc.clear();
322             profiles = doc.createElement("profiles");
323             profiles.setAttribute("version", 1);
324             doc.appendChild(profiles);
325         }
326
327         QString newProfileName = ui.profile_name->text().simplified();
328         QString newGroupName = ui.group_name->text().simplified();
329         if (newGroupName.isEmpty()) newGroupName = i18n("Custom");
330         QString newMetaGroupId = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
331         QDomNodeList profilelist = doc.elementsByTagName("profile");
332         int i = 0;
333         while (!profilelist.item(i).isNull()) {
334             // make sure a profile with same name doesn't exist
335             documentElement = profilelist.item(i).toElement();
336             QString profileName = documentElement.attribute("name");
337             if (profileName == newProfileName) {
338                 // a profile with that same name already exists
339                 bool ok;
340                 newProfileName = QInputDialog::getText(this, i18n("Profile already exists"), i18n("This profile name already exists. Change the name if you don't want to overwrite it."), QLineEdit::Normal, newProfileName, &ok);
341                 if (!ok) return;
342                 if (profileName == newProfileName) {
343                     profiles.removeChild(profilelist.item(i));
344                     break;
345                 }
346             }
347             i++;
348         }
349
350         QDomElement profileElement = doc.createElement("profile");
351         profileElement.setAttribute("name", newProfileName);
352         profileElement.setAttribute("category", newGroupName);
353         profileElement.setAttribute("destinationid", newMetaGroupId);
354         profileElement.setAttribute("extension", ui.extension->text().simplified());
355         profileElement.setAttribute("args", ui.parameters->toPlainText().simplified());
356         profiles.appendChild(profileElement);
357
358         //QCString save = doc.toString().utf8();
359
360         if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
361             KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
362             delete d;
363             return;
364         }
365         QTextStream out(&file);
366         out << doc.toString();
367         if (file.error() != QFile::NoError) {
368             KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
369             file.close();
370             delete d;
371             return;
372         }
373         file.close();
374         parseProfiles(newMetaGroupId, newGroupName, newProfileName);
375     }
376     delete d;
377 }
378
379 void RenderWidget::slotEditProfile()
380 {
381     QListWidgetItem *item = m_view.size_list->currentItem();
382     if (!item) return;
383     QString currentGroup = m_view.format_list->currentItem()->text();
384
385     QString params = item->data(ParamsRole).toString();
386     QString extension = item->data(ExtensionRole).toString();
387     QString currentProfile = item->text();
388
389     Ui::SaveProfile_UI ui;
390     QDialog *d = new QDialog(this);
391     ui.setupUi(d);
392
393     for (int i = 0; i < m_view.destination_list->count(); i++)
394         ui.destination_list->addItem(m_view.destination_list->itemIcon(i), m_view.destination_list->itemText(i), m_view.destination_list->itemData(i, Qt::UserRole));
395
396     ui.destination_list->setCurrentIndex(m_view.destination_list->currentIndex());
397     QString dest = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
398
399     QString customGroup = m_view.format_list->currentItem()->text();
400     if (customGroup.isEmpty()) customGroup = i18n("Custom");
401     ui.group_name->setText(customGroup);
402
403     ui.profile_name->setText(currentProfile);
404     ui.extension->setText(extension);
405     ui.parameters->setText(params);
406     ui.profile_name->setFocus();
407     d->setWindowTitle(i18n("Edit Profile"));
408     if (d->exec() == QDialog::Accepted) {
409         slotDeleteProfile(false);
410         QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
411         QDomDocument doc;
412         QFile file(exportFile);
413         doc.setContent(&file, false);
414         file.close();
415         QDomElement documentElement;
416         QDomElement profiles = doc.documentElement();
417
418         if (profiles.isNull() || profiles.tagName() != "profiles") {
419             doc.clear();
420             profiles = doc.createElement("profiles");
421             profiles.setAttribute("version", 1);
422             doc.appendChild(profiles);
423         }
424
425         int version = profiles.attribute("version", 0).toInt();
426         if (version < 1) {
427             kDebug() << "// OLD profile version";
428             doc.clear();
429             profiles = doc.createElement("profiles");
430             profiles.setAttribute("version", 1);
431             doc.appendChild(profiles);
432         }
433
434         QString newProfileName = ui.profile_name->text().simplified();
435         QString newGroupName = ui.group_name->text().simplified();
436         if (newGroupName.isEmpty()) newGroupName = i18n("Custom");
437         QString newMetaGroupId = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
438         QDomNodeList profilelist = doc.elementsByTagName("profile");
439         int i = 0;
440         while (!profilelist.item(i).isNull()) {
441             // make sure a profile with same name doesn't exist
442             documentElement = profilelist.item(i).toElement();
443             QString profileName = documentElement.attribute("name");
444             if (profileName == newProfileName) {
445                 // a profile with that same name already exists
446                 bool ok;
447                 newProfileName = QInputDialog::getText(this, i18n("Profile already exists"), i18n("This profile name already exists. Change the name if you don't want to overwrite it."), QLineEdit::Normal, newProfileName, &ok);
448                 if (!ok) return;
449                 if (profileName == newProfileName) {
450                     profiles.removeChild(profilelist.item(i));
451                     break;
452                 }
453             }
454             i++;
455         }
456
457         QDomElement profileElement = doc.createElement("profile");
458         profileElement.setAttribute("name", newProfileName);
459         profileElement.setAttribute("category", newGroupName);
460         profileElement.setAttribute("destinationid", newMetaGroupId);
461         profileElement.setAttribute("extension", ui.extension->text().simplified());
462         profileElement.setAttribute("args", ui.parameters->toPlainText().simplified());
463         profiles.appendChild(profileElement);
464
465         //QCString save = doc.toString().utf8();
466         delete d;
467         if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
468             KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
469             return;
470         }
471         QTextStream out(&file);
472         out << doc.toString();
473         if (file.error() != QFile::NoError) {
474             KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
475             file.close();
476             return;
477         }
478         file.close();
479         parseProfiles(newMetaGroupId, newGroupName, newProfileName);
480     } else delete d;
481 }
482
483 void RenderWidget::slotDeleteProfile(bool refresh)
484 {
485     //TODO: delete a profile installed by KNewStuff the easy way
486     /*
487     QString edit = m_view.size_list->currentItem()->data(EditableRole).toString();
488     if (!edit.endsWith("customprofiles.xml")) {
489         // This is a KNewStuff installed file, process through KNS
490         KNS::Engine engine(0);
491         if (engine.init("kdenlive_render.knsrc")) {
492             KNS::Entry::List entries;
493         }
494         return;
495     }*/
496     QString currentGroup = m_view.format_list->currentItem()->text();
497     QString currentProfile = m_view.size_list->currentItem()->text();
498     QString metaGroupId = m_view.destination_list->itemData(m_view.destination_list->currentIndex(), Qt::UserRole).toString();
499
500     QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
501     QDomDocument doc;
502     QFile file(exportFile);
503     doc.setContent(&file, false);
504     file.close();
505
506     QDomElement documentElement;
507     QDomNodeList profiles = doc.elementsByTagName("profile");
508     int i = 0;
509     QString groupName;
510     QString profileName;
511     QString destination;
512
513     while (!profiles.item(i).isNull()) {
514         documentElement = profiles.item(i).toElement();
515         profileName = documentElement.attribute("name");
516         groupName = documentElement.attribute("category");
517         destination = documentElement.attribute("destinationid");
518
519         if (profileName == currentProfile && groupName == currentGroup && destination == metaGroupId) {
520             kDebug() << "// GOT it: " << profileName;
521             doc.documentElement().removeChild(profiles.item(i));
522             break;
523         }
524         i++;
525     }
526
527     if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
528         KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
529         return;
530     }
531     QTextStream out(&file);
532     out << doc.toString();
533     if (file.error() != QFile::NoError) {
534         KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
535         file.close();
536         return;
537     }
538     file.close();
539     if (refresh) {
540         parseProfiles(metaGroupId, currentGroup);
541         focusFirstVisibleItem();
542     }
543 }
544
545 void RenderWidget::updateButtons()
546 {
547     if (!m_view.size_list->currentItem() || m_view.size_list->currentItem()->isHidden()) {
548         m_view.buttonSave->setEnabled(false);
549         m_view.buttonDelete->setEnabled(false);
550         m_view.buttonEdit->setEnabled(false);
551         m_view.buttonStart->setEnabled(false);
552     } else {
553         m_view.buttonSave->setEnabled(true);
554         m_view.buttonStart->setEnabled(m_view.size_list->currentItem()->toolTip().isEmpty());
555         QString edit = m_view.size_list->currentItem()->data(EditableRole).toString();
556         if (edit.isEmpty() || !edit.endsWith("customprofiles.xml")) {
557             m_view.buttonDelete->setEnabled(false);
558             m_view.buttonEdit->setEnabled(false);
559         } else {
560             m_view.buttonDelete->setEnabled(true);
561             m_view.buttonEdit->setEnabled(true);
562         }
563     }
564 }
565
566
567 void RenderWidget::focusFirstVisibleItem()
568 {
569     if (m_view.size_list->currentItem() && !m_view.size_list->currentItem()->isHidden()) {
570         updateButtons();
571         return;
572     }
573     for (int ix = 0; ix < m_view.size_list->count(); ix++) {
574         QListWidgetItem *item = m_view.size_list->item(ix);
575         if (item && !item->isHidden()) {
576             m_view.size_list->setCurrentRow(ix);
577             break;
578         }
579     }
580     if (!m_view.size_list->currentItem()) m_view.size_list->setCurrentRow(0);
581     updateButtons();
582 }
583
584 void RenderWidget::slotPrepareExport(bool scriptExport)
585 {
586     if (!QFile::exists(KdenliveSettings::rendererpath())) {
587         KMessageBox::sorry(this, i18n("Cannot find the melt program required for rendering (part of Mlt)"));
588         return;
589     }
590     if (m_view.play_after->isChecked() && KdenliveSettings::defaultplayerapp().isEmpty())
591         KMessageBox::sorry(this, i18n("Cannot play video after rendering because the default video player application is not set.\nPlease define it in Kdenlive settings dialog."));
592     QString chapterFile;
593     if (m_view.create_chapter->isChecked()) chapterFile = m_view.out_file->url().path() + ".dvdchapter";
594     emit prepareRenderingData(scriptExport, m_view.render_zone->isChecked(), chapterFile);
595 }
596
597
598 void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const QString &playlistPath, const QString &scriptPath)
599 {
600     QListWidgetItem *item = m_view.size_list->currentItem();
601     if (!item) return;
602
603     QString dest = m_view.out_file->url().path();
604     if (dest.isEmpty()) return;
605
606     // Check whether target file has an extension.
607     // If not, ask whether extension should be added or not.
608     QString extension = item->data(ExtensionRole).toString();
609     if (!dest.endsWith(extension)) {
610         if (KMessageBox::questionYesNo(this, i18n("File has no extension. Add extension (%1)?", extension)) == KMessageBox::Yes) {
611             dest.append("." + extension);
612         }
613     }
614
615     QFile f(dest);
616     if (f.exists()) {
617         if (KMessageBox::warningYesNo(this, i18n("Output file already exists. Do you want to overwrite it?")) != KMessageBox::Yes)
618             return;
619     }
620
621     QStringList overlayargs;
622     if (m_view.tc_overlay->isChecked()) {
623         QString filterFile = KStandardDirs::locate("appdata", "metadata.properties");
624         overlayargs << "meta.attr.timecode=1" << "meta.attr.timecode.markup=#timecode";
625         overlayargs << "-attach" << "data_feed:attr_check" << "-attach";
626         overlayargs << "data_show:" + filterFile << "_loader=1" << "dynamic=1";
627     }
628
629     QStringList render_process_args;
630
631     if (!scriptExport) render_process_args << "-erase";
632     if (KdenliveSettings::usekuiserver()) render_process_args << "-kuiserver";
633
634     double guideStart = 0;
635     double guideEnd = 0;
636
637     if (m_view.render_zone->isChecked()) render_process_args << "in=" + QString::number(zoneIn) << "out=" + QString::number(zoneOut);
638     else if (m_view.render_guide->isChecked()) {
639         double fps = (double) m_profile.frame_rate_num / m_profile.frame_rate_den;
640         guideStart = m_view.guide_start->itemData(m_view.guide_start->currentIndex()).toDouble();
641         guideEnd = m_view.guide_end->itemData(m_view.guide_end->currentIndex()).toDouble();
642         render_process_args << "in=" + QString::number(GenTime(guideStart).frames(fps)) << "out=" + QString::number(GenTime(guideEnd).frames(fps));
643     }
644
645     render_process_args << overlayargs;
646     render_process_args << KdenliveSettings::rendererpath() << m_profile.path << item->data(RenderRole).toString();
647     if (m_view.play_after->isChecked()) render_process_args << KdenliveSettings::KdenliveSettings::defaultplayerapp();
648     else render_process_args << "-";
649
650     QString renderArgs = m_view.advanced_params->toPlainText().simplified();
651
652     // Adjust frame scale
653     int width;
654     int height;
655     if (m_view.rescale->isChecked() && m_view.rescale->isEnabled()) {
656         width = m_view.rescale_size->text().section('x', 0, 0).toInt();
657         height = m_view.rescale_size->text().section('x', 1, 1).toInt();
658     } else {
659         width = m_profile.width;
660         height = m_profile.height;
661     }
662     renderArgs.replace("%dar", '@' + QString::number(m_profile.display_aspect_num) + '/' + QString::number(m_profile.display_aspect_den));
663
664     // Adjust scanning
665     if (m_view.scanning_list->currentIndex() == 1) renderArgs.append(" progressive=1");
666     else if (m_view.scanning_list->currentIndex() == 2) renderArgs.append(" progressive=0");
667
668     // disable audio if requested
669     if (!m_view.export_audio->isChecked())
670         renderArgs.append(" an=1 ");
671
672     // Check if the rendering profile is different from project profile,
673     // in which case we need to use the producer_comsumer from MLT
674     QString std = renderArgs;
675     QString destination = m_view.destination_list->itemData(m_view.destination_list->currentIndex()).toString();
676     const QString currentSize = QString::number(width) + 'x' + QString::number(height);
677     QString subsize = currentSize;
678     if (std.startsWith("s=")) {
679         subsize = std.section(' ', 0, 0).toLower();
680         subsize = subsize.section("=", 1, 1);
681     } else if (std.contains(" s=")) {
682         subsize = std.section(" s=", 1, 1);
683         subsize = subsize.section(' ', 0, 0).toLower();
684     } else if (destination != "audioonly" && m_view.rescale->isChecked() && m_view.rescale->isEnabled()) {
685         subsize = QString(" s=%1x%2").arg(width).arg(height);
686         // Add current size parameter
687         renderArgs.append(subsize);
688     }
689     bool resizeProfile = (subsize != currentSize);
690     QStringList paramsList = renderArgs.split(" ", QString::SkipEmptyParts);
691     for (int i = 0; i < paramsList.count(); i++) {
692         if (paramsList.at(i).startsWith("profile=")) {
693             if (paramsList.at(i).section('=', 1) != m_profile.path) resizeProfile = true;
694             break;
695         }
696     }
697
698     if (resizeProfile) render_process_args << "consumer:" + playlistPath;
699     else render_process_args << playlistPath;
700     render_process_args << dest;
701     render_process_args << paramsList;
702
703     QString group = m_view.size_list->currentItem()->data(MetaGroupRole).toString();
704
705     QStringList renderParameters;
706     renderParameters << dest << item->data(RenderRole).toString() << renderArgs.simplified();
707     renderParameters << QString::number(zoneIn) << QString::number(zoneOut) << QString::number(m_view.play_after->isChecked());
708     renderParameters << QString::number(guideStart) << QString::number(guideEnd) << QString::number(resizeProfile);
709
710     QString scriptName;
711     if (scriptExport) {
712         // Generate script file
713         QFile file(scriptPath);
714         if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
715             KMessageBox::error(this, i18n("Cannot write to file %1", scriptPath));
716             return;
717         }
718         QString renderer = QCoreApplication::applicationDirPath() + QString("/kdenlive_render");
719         if (!QFile::exists(renderer)) renderer = "kdenlive_render";
720         QTextStream outStream(&file);
721         outStream << "#! /bin/sh" << "\n" << "\n";
722         outStream << "SOURCE=" << "\"" + playlistPath + "\"" << "\n";
723         outStream << "TARGET=" << "\"" + dest + "\"" << "\n";
724         outStream << "RENDERER=" << "\"" + renderer + "\"" << "\n";
725         outStream << "MELT=" << "\"" + render_process_args.takeFirst() + "\"" << "\n";
726         outStream << "PARAMETERS=" << "\"" + render_process_args.join(" ") + "\"" << "\n";
727         outStream << "$RENDERER $MELT $PARAMETERS" << "\n" << "\n";
728         if (file.error() != QFile::NoError) {
729             KMessageBox::error(this, i18n("Cannot write to file %1", scriptPath));
730             file.close();
731             return;
732         }
733         file.close();
734         QFile::setPermissions(scriptPath, file.permissions() | QFile::ExeUser);
735
736         QTimer::singleShot(400, this, SLOT(parseScriptFiles()));
737         m_view.tabWidget->setCurrentIndex(2);
738         return;
739     }
740     renderParameters << scriptName;
741     m_view.tabWidget->setCurrentIndex(1);
742
743     // Save rendering profile to document
744     emit selectedRenderProfile(m_view.size_list->currentItem()->data(MetaGroupRole).toString(), m_view.size_list->currentItem()->text());
745
746     // insert item in running jobs list
747     QTreeWidgetItem *renderItem;
748     QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(dest, Qt::MatchExactly, 1);
749     if (!existing.isEmpty()) {
750         renderItem = existing.at(0);
751         if (renderItem->data(1, Qt::UserRole + 2).toInt() == RUNNINGJOB) {
752             KMessageBox::information(this, i18n("There is already a job writing file:<br><b>%1</b><br>Abort the job if you want to overwrite it...", dest), i18n("Already running"));
753             return;
754         }
755         renderItem->setData(1, Qt::UserRole + 4, QString());
756     } else {
757         renderItem = new QTreeWidgetItem(m_view.running_jobs, QStringList() << QString() << dest << QString());
758     }
759     renderItem->setData(1, Qt::UserRole + 2, WAITINGJOB);
760     renderItem->setIcon(0, KIcon("media-playback-pause"));
761     renderItem->setData(1, Qt::UserRole, i18n("Waiting..."));
762     renderItem->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
763     renderItem->setData(1, Qt::UserRole + 1, QTime::currentTime());
764
765     // Set rendering type
766     if (group == "dvd") {
767         if (m_view.open_dvd->isChecked()) {
768             renderItem->setData(0, Qt::UserRole, group);
769             if (renderArgs.contains("profile=")) {
770                 // rendering profile contains an MLT profile, so pass it to the running jog item, useful for dvd
771                 QString prof = renderArgs.section("profile=", 1, 1);
772                 prof = prof.section(' ', 0, 0);
773                 kDebug() << "// render profile: " << prof;
774                 renderItem->setData(0, Qt::UserRole + 1, prof);
775             }
776         }
777     } else {
778         if (group == "websites" && m_view.open_browser->isChecked()) {
779             renderItem->setData(0, Qt::UserRole, group);
780             // pass the url
781             QString url = m_view.size_list->currentItem()->data(ExtraRole).toString();
782             renderItem->setData(0, Qt::UserRole + 1, url);
783         }
784     }
785     renderItem->setData(1, Qt::UserRole + 3, render_process_args);
786     checkRenderStatus();
787 }
788
789 void RenderWidget::checkRenderStatus()
790 {
791     if (m_blockProcessing) return;
792     QTreeWidgetItem *item = m_view.running_jobs->topLevelItem(0);
793     while (item) {
794         if (item->data(1, Qt::UserRole + 2).toInt() == RUNNINGJOB) return;
795         item = m_view.running_jobs->itemBelow(item);
796     }
797     item = m_view.running_jobs->topLevelItem(0);
798     while (item) {
799         if (item->data(1, Qt::UserRole + 2).toInt() == WAITINGJOB) {
800             item->setData(1, Qt::UserRole + 1, QTime::currentTime());
801             if (item->data(1, Qt::UserRole + 4).isNull()) {
802                 // Normal render process
803                 QString renderer = QCoreApplication::applicationDirPath() + QString("/kdenlive_render");
804                 if (!QFile::exists(renderer)) renderer = "kdenlive_render";
805                 if (QProcess::startDetached(renderer, item->data(1, Qt::UserRole + 3).toStringList()) == false) {
806                     item->setData(1, Qt::UserRole + 2, FINISHEDJOB);
807                     item->setData(1, Qt::UserRole, i18n("Rendering crashed"));
808                     item->setIcon(0, KIcon("dialog-close"));
809                     item->setData(2, Qt::UserRole, 100);
810                 } else KNotification::event("RenderStarted", i18n("Rendering <i>%1</i> started", item->text(1)), QPixmap(), this);
811             } else {
812                 // Script item
813                 if (QProcess::startDetached(item->data(1, Qt::UserRole + 3).toString()) == false) {
814                     item->setData(1, Qt::UserRole + 2, FINISHEDJOB);
815                     item->setData(1, Qt::UserRole, i18n("Rendering crashed"));
816                     item->setIcon(0, KIcon("dialog-close"));
817                     item->setData(2, Qt::UserRole, 100);
818                 }
819             }
820             break;
821         }
822         item = m_view.running_jobs->itemBelow(item);
823     }
824 }
825
826 int RenderWidget::waitingJobsCount() const
827 {
828     int count = 0;
829     QTreeWidgetItem *item = m_view.running_jobs->topLevelItem(0);
830     while (item) {
831         if (item->data(1, Qt::UserRole + 2).toInt() == WAITINGJOB) count++;
832         item = m_view.running_jobs->itemBelow(item);
833     }
834     return count;
835 }
836
837 void RenderWidget::setProfile(MltVideoProfile profile)
838 {
839     m_profile = profile;
840     //WARNING: this way to tell the video standard is a bit hackish...
841     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);
842     else m_view.format_selection->setCurrentIndex(1);
843     m_view.scanning_list->setCurrentIndex(0);
844     refreshView();
845 }
846
847 void RenderWidget::refreshView()
848 {
849     m_view.size_list->blockSignals(true);
850     QListWidgetItem *sizeItem;
851
852     QString destination;
853     KIcon brokenIcon("dialog-close");
854     if (m_view.destination_list->currentIndex() > 0)
855         destination = m_view.destination_list->itemData(m_view.destination_list->currentIndex()).toString();
856
857
858     if (destination == "dvd") {
859         m_view.open_dvd->setVisible(true);
860         m_view.create_chapter->setVisible(true);
861     } else {
862         m_view.open_dvd->setVisible(false);
863         m_view.create_chapter->setVisible(false);
864     }
865     if (destination == "websites") m_view.open_browser->setVisible(true);
866     else m_view.open_browser->setVisible(false);
867     if (!destination.isEmpty() && QString("dvd websites audioonly").contains(destination))
868         m_view.rescale->setEnabled(false);
869     else m_view.rescale->setEnabled(true);
870     // hide groups that are not in the correct destination
871     for (int i = 0; i < m_view.format_list->count(); i++) {
872         sizeItem = m_view.format_list->item(i);
873         if (sizeItem->data(MetaGroupRole).toString() == destination) {
874             sizeItem->setHidden(false);
875             //kDebug() << "// SET GRP:: " << sizeItem->text() << ", METY:" << sizeItem->data(MetaGroupRole).toString();
876         } else sizeItem->setHidden(true);
877     }
878
879     // activate first visible item
880     QListWidgetItem * item = m_view.format_list->currentItem();
881     if (!item || item->isHidden()) {
882         for (int i = 0; i < m_view.format_list->count(); i++) {
883             if (!m_view.format_list->item(i)->isHidden()) {
884                 m_view.format_list->setCurrentRow(i);
885                 break;
886             }
887         }
888         item = m_view.format_list->currentItem();
889     }
890     if (!item || item->isHidden()) {
891         m_view.format_list->setEnabled(false);
892         m_view.size_list->setEnabled(false);
893         return;
894     } else {
895         m_view.format_list->setEnabled(true);
896         m_view.size_list->setEnabled(true);
897     }
898     int count = 0;
899     for (int i = 0; i < m_view.format_list->count() && count < 2; i++) {
900         if (!m_view.format_list->isRowHidden(i)) count++;
901     }
902     if (count > 1) m_view.format_list->setVisible(true);
903     else m_view.format_list->setVisible(false);
904     QString std;
905     QString group = item->text();
906     bool firstSelected = false;
907     const QStringList formatsList = KdenliveSettings::supportedformats();
908     const QStringList vcodecsList = KdenliveSettings::videocodecs();
909     const QStringList acodecsList = KdenliveSettings::audiocodecs();
910
911     KColorScheme scheme(palette().currentColorGroup(), KColorScheme::Window);
912     const QColor disabled = scheme.foreground(KColorScheme::InactiveText).color();
913     const QColor disabledbg = scheme.background(KColorScheme::NegativeBackground).color();
914
915     for (int i = 0; i < m_view.size_list->count(); i++) {
916         sizeItem = m_view.size_list->item(i);
917         if ((sizeItem->data(GroupRole).toString() == group || sizeItem->data(GroupRole).toString().isEmpty()) && sizeItem->data(MetaGroupRole).toString() == destination) {
918             std = sizeItem->data(StandardRole).toString();
919             if (!std.isEmpty()) {
920                 if (std.contains("PAL", Qt::CaseInsensitive)) sizeItem->setHidden(m_view.format_selection->currentIndex() != 0);
921                 else if (std.contains("NTSC", Qt::CaseInsensitive)) sizeItem->setHidden(m_view.format_selection->currentIndex() != 1);
922             } else {
923                 sizeItem->setHidden(false);
924                 if (!firstSelected) m_view.size_list->setCurrentItem(sizeItem);
925                 firstSelected = true;
926             }
927
928             if (!sizeItem->isHidden()) {
929                 // Make sure the selected profile uses an installed avformat codec / format
930                 std = sizeItem->data(ParamsRole).toString();
931
932                 if (!formatsList.isEmpty()) {
933                     QString format;
934                     if (std.startsWith("f=")) format = std.section("f=", 1, 1);
935                     else if (std.contains(" f=")) format = std.section(" f=", 1, 1);
936                     if (!format.isEmpty()) {
937                         format = format.section(' ', 0, 0).toLower();
938                         if (!formatsList.contains(format)) {
939                             kDebug() << "***** UNSUPPORTED F: " << format;
940                             //sizeItem->setHidden(true);
941                             //sizeItem->setFlags(Qt::ItemIsSelectable);
942                             sizeItem->setToolTip(i18n("Unsupported video format: %1", format));
943                             sizeItem->setIcon(brokenIcon);
944                             sizeItem->setForeground(disabled);
945                         }
946                     }
947                 }
948                 if (!acodecsList.isEmpty() && !sizeItem->isHidden()) {
949                     QString format;
950                     if (std.startsWith("acodec=")) format = std.section("acodec=", 1, 1);
951                     else if (std.contains(" acodec=")) format = std.section(" acodec=", 1, 1);
952                     if (!format.isEmpty()) {
953                         format = format.section(' ', 0, 0).toLower();
954                         if (!acodecsList.contains(format)) {
955                             kDebug() << "*****  UNSUPPORTED ACODEC: " << format;
956                             //sizeItem->setHidden(true);
957                             //sizeItem->setFlags(Qt::ItemIsSelectable);
958                             sizeItem->setToolTip(i18n("Unsupported audio codec: %1", format));
959                             sizeItem->setIcon(brokenIcon);
960                             sizeItem->setForeground(disabled);
961                             sizeItem->setBackground(disabledbg);
962                         }
963                     }
964                 }
965                 if (!vcodecsList.isEmpty() && !sizeItem->isHidden()) {
966                     QString format;
967                     if (std.startsWith("vcodec=")) format = std.section("vcodec=", 1, 1);
968                     else if (std.contains(" vcodec=")) format = std.section(" vcodec=", 1, 1);
969                     if (!format.isEmpty()) {
970                         format = format.section(' ', 0, 0).toLower();
971                         if (!vcodecsList.contains(format)) {
972                             kDebug() << "*****  UNSUPPORTED VCODEC: " << format;
973                             //sizeItem->setHidden(true);
974                             //sizeItem->setFlags(Qt::ItemIsSelectable);
975                             sizeItem->setToolTip(i18n("Unsupported video codec: %1", format));
976                             sizeItem->setIcon(brokenIcon);
977                             sizeItem->setForeground(disabled);
978                         }
979                     }
980                 }
981             }
982         } else sizeItem->setHidden(true);
983     }
984     focusFirstVisibleItem();
985     m_view.size_list->blockSignals(false);
986     refreshParams();
987 }
988
989 KUrl RenderWidget::filenameWithExtension(KUrl url, QString extension)
990 {
991     QString path;
992     if (!url.isEmpty()) {
993         path = url.path();
994         int pos = path.lastIndexOf('.') + 1;
995         if (pos == 0) path.append('.' + extension);
996         else path = path.left(pos) + extension;
997
998     } else {
999         path = m_projectFolder + "untitled." + extension;
1000     }
1001     return KUrl(path);
1002 }
1003
1004
1005 /**
1006  * Called when a new format or size has been selected.
1007  */
1008 void RenderWidget::refreshParams()
1009 {
1010     // Format not available (e.g. codec not installed); Disable start button
1011     QListWidgetItem *item = m_view.size_list->currentItem();
1012     if (!item || item->isHidden()) {
1013         m_view.advanced_params->clear();
1014         m_view.buttonStart->setEnabled(false);
1015         return;
1016     }
1017     QString params = item->data(ParamsRole).toString();
1018     QString extension = item->data(ExtensionRole).toString();
1019     m_view.advanced_params->setPlainText(params);
1020     QString destination = m_view.destination_list->itemData(m_view.destination_list->currentIndex()).toString();
1021     if (params.contains(" s=") || destination == "audioonly") {
1022         // profile has a fixed size, do not allow resize
1023         m_view.rescale->setEnabled(false);
1024         m_view.rescale_size->setEnabled(false);
1025     } else {
1026         m_view.rescale->setEnabled(true);
1027         m_view.rescale_size->setEnabled(true);
1028     }
1029     KUrl url = filenameWithExtension(m_view.out_file->url(), extension);
1030     m_view.out_file->setUrl(url);
1031 //     if (!url.isEmpty()) {
1032 //         QString path = url.path();
1033 //         int pos = path.lastIndexOf('.') + 1;
1034 //  if (pos == 0) path.append('.' + extension);
1035 //         else path = path.left(pos) + extension;
1036 //         m_view.out_file->setUrl(KUrl(path));
1037 //     } else {
1038 //         m_view.out_file->setUrl(KUrl(QDir::homePath() + "/untitled." + extension));
1039 //     }
1040     m_view.out_file->setFilter("*." + extension);
1041     QString edit = item->data(EditableRole).toString();
1042     if (edit.isEmpty() || !edit.endsWith("customprofiles.xml")) {
1043         m_view.buttonDelete->setEnabled(false);
1044         m_view.buttonEdit->setEnabled(false);
1045     } else {
1046         m_view.buttonDelete->setEnabled(true);
1047         m_view.buttonEdit->setEnabled(true);
1048     }
1049
1050     m_view.buttonStart->setEnabled(m_view.size_list->currentItem()->toolTip().isEmpty());
1051 }
1052
1053 void RenderWidget::reloadProfiles()
1054 {
1055     parseProfiles();
1056 }
1057
1058 void RenderWidget::parseProfiles(QString meta, QString group, QString profile)
1059 {
1060     m_view.size_list->clear();
1061     m_view.format_list->clear();
1062     m_view.destination_list->clear();
1063     m_view.destination_list->addItem(KIcon("video-x-generic"), i18n("File rendering"));
1064     m_view.destination_list->addItem(KIcon("media-optical"), i18n("DVD"), "dvd");
1065     m_view.destination_list->addItem(KIcon("audio-x-generic"), i18n("Audio only"), "audioonly");
1066     m_view.destination_list->addItem(KIcon("applications-internet"), i18n("Web sites"), "websites");
1067     m_view.destination_list->addItem(KIcon("applications-multimedia"), i18n("Media players"), "mediaplayers");
1068     m_view.destination_list->addItem(KIcon("drive-harddisk"), i18n("Lossless / HQ"), "lossless");
1069     m_view.destination_list->addItem(KIcon("pda"), i18n("Mobile devices"), "mobile");
1070
1071     QString exportFile = KStandardDirs::locate("appdata", "export/profiles.xml");
1072     parseFile(exportFile, false);
1073
1074
1075     QString exportFolder = KStandardDirs::locateLocal("appdata", "export/");
1076     QDir directory = QDir(exportFolder);
1077     QStringList filter;
1078     filter << "*.xml";
1079     QStringList fileList = directory.entryList(filter, QDir::Files);
1080     // We should parse customprofiles.xml in last position, so that user profiles
1081     // can also override profiles installed by KNewStuff
1082     fileList.removeAll("customprofiles.xml");
1083     foreach(const QString &filename, fileList)
1084     parseFile(exportFolder + filename, true);
1085     if (QFile::exists(exportFolder + "customprofiles.xml")) parseFile(exportFolder + "customprofiles.xml", true);
1086
1087     if (!meta.isEmpty()) {
1088         m_view.destination_list->blockSignals(true);
1089         m_view.destination_list->setCurrentIndex(m_view.destination_list->findData(meta));
1090         m_view.destination_list->blockSignals(false);
1091     }
1092     refreshView();
1093     QList<QListWidgetItem *> child;
1094     if (!group.isEmpty()) child = m_view.format_list->findItems(group, Qt::MatchExactly);
1095     if (!child.isEmpty()) {
1096         for (int i = 0; i < child.count(); i++) {
1097             if (child.at(i)->data(MetaGroupRole).toString() == meta) {
1098                 m_view.format_list->setCurrentItem(child.at(i));
1099                 break;
1100             }
1101         }
1102     }
1103     child.clear();
1104     if (!profile.isEmpty()) child = m_view.size_list->findItems(profile, Qt::MatchExactly);
1105     if (!child.isEmpty()) m_view.size_list->setCurrentItem(child.at(0));
1106 }
1107
1108 void RenderWidget::parseFile(QString exportFile, bool editable)
1109 {
1110     kDebug() << "// Parsing file: " << exportFile;
1111     kDebug() << "------------------------------";
1112     QDomDocument doc;
1113     QFile file(exportFile);
1114     doc.setContent(&file, false);
1115     file.close();
1116     QDomElement documentElement;
1117     QDomElement profileElement;
1118     QString extension;
1119     QListWidgetItem *item;
1120     QDomNodeList groups = doc.elementsByTagName("group");
1121
1122     if (editable || groups.count() == 0) {
1123         QDomElement profiles = doc.documentElement();
1124         if (editable && profiles.attribute("version", 0).toInt() < 1) {
1125             kDebug() << "// OLD profile version";
1126             // this is an old profile version, update it
1127             QDomDocument newdoc;
1128             QDomElement newprofiles = newdoc.createElement("profiles");
1129             newprofiles.setAttribute("version", 1);
1130             newdoc.appendChild(newprofiles);
1131             QDomNodeList profilelist = doc.elementsByTagName("profile");
1132             for (int i = 0; i < profilelist.count(); i++) {
1133                 QString category = i18n("Custom");
1134                 QString extension;
1135                 QDomNode parent = profilelist.at(i).parentNode();
1136                 if (!parent.isNull()) {
1137                     QDomElement parentNode = parent.toElement();
1138                     if (parentNode.hasAttribute("name")) category = parentNode.attribute("name");
1139                     extension = parentNode.attribute("extension");
1140                 }
1141                 profilelist.at(i).toElement().setAttribute("category", category);
1142                 if (!extension.isEmpty()) profilelist.at(i).toElement().setAttribute("extension", extension);
1143                 QDomNode n = profilelist.at(i).cloneNode();
1144                 newprofiles.appendChild(newdoc.importNode(n, true));
1145             }
1146             if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1147                 KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
1148                 return;
1149             }
1150             QTextStream out(&file);
1151             out << newdoc.toString();
1152             file.close();
1153             parseFile(exportFile, editable);
1154             return;
1155         }
1156
1157         QDomNode node = doc.elementsByTagName("profile").at(0);
1158         if (node.isNull()) {
1159             kDebug() << "// Export file: " << exportFile << " IS BROKEN";
1160             return;
1161         }
1162         int count = 1;
1163         while (!node.isNull()) {
1164             QDomElement profile = node.toElement();
1165             QString profileName = profile.attribute("name");
1166             QString standard = profile.attribute("standard");
1167             QString params = profile.attribute("args");
1168             QString category = profile.attribute("category", i18n("Custom"));
1169             QString dest = profile.attribute("destinationid");
1170             QString prof_extension = profile.attribute("extension");
1171             if (!prof_extension.isEmpty()) extension = prof_extension;
1172
1173             QList <QListWidgetItem *> list = m_view.format_list->findItems(category, Qt::MatchExactly);
1174             bool exists = false;
1175             for (int j = 0; j < list.count(); j++) {
1176                 if (list.at(j)->data(MetaGroupRole) == dest) {
1177                     exists = true;
1178                     break;
1179                 }
1180             }
1181             if (!exists) {
1182                 item = new QListWidgetItem(category, m_view.format_list);
1183                 item->setData(MetaGroupRole, dest);
1184             }
1185
1186             // Check if item with same name already exists and replace it,
1187             // allowing to override default profiles
1188
1189             list = m_view.size_list->findItems(profileName, Qt::MatchExactly);
1190
1191             for (int j = 0; j < list.count(); j++) {
1192                 if (list.at(j)->data(MetaGroupRole) == dest) {
1193                     QListWidgetItem *duplicate = list.takeAt(j);
1194                     delete duplicate;
1195                     j--;
1196                 }
1197             }
1198
1199             item = new QListWidgetItem(profileName, m_view.size_list);
1200             //kDebug() << "// ADDINg item with name: " << profileName << ", GRP" << category << ", DEST:" << dest ;
1201             item->setData(GroupRole, category);
1202             item->setData(MetaGroupRole, dest);
1203             item->setData(ExtensionRole, extension);
1204             item->setData(RenderRole, "avformat");
1205             item->setData(StandardRole, standard);
1206             item->setData(ParamsRole, params);
1207             if (profile.hasAttribute("url")) item->setData(ExtraRole, profile.attribute("url"));
1208             if (editable) {
1209                 item->setData(EditableRole, exportFile);
1210                 if (exportFile.endsWith("customprofiles.xml")) item->setIcon(KIcon("emblem-favorite"));
1211                 else item->setIcon(KIcon("applications-internet"));
1212             }
1213             node = doc.elementsByTagName("profile").at(count);
1214             count++;
1215         }
1216         return;
1217     }
1218
1219     int i = 0;
1220     QString groupName;
1221     QString profileName;
1222
1223     QString prof_extension;
1224     QString renderer;
1225     QString params;
1226     QString standard;
1227     KIcon icon;
1228
1229     while (!groups.item(i).isNull()) {
1230         documentElement = groups.item(i).toElement();
1231         QDomNode gname = documentElement.elementsByTagName("groupname").at(0);
1232         QString metagroupName;
1233         QString metagroupId;
1234         if (!gname.isNull()) {
1235             metagroupName = gname.firstChild().nodeValue();
1236             metagroupId = gname.toElement().attribute("id");
1237             if (!metagroupName.isEmpty() && !m_view.destination_list->contains(metagroupName)) {
1238                 if (metagroupId == "dvd") icon = KIcon("media-optical");
1239                 else if (metagroupId == "audioonly") icon = KIcon("audio-x-generic");
1240                 else if (metagroupId == "websites") icon = KIcon("applications-internet");
1241                 else if (metagroupId == "mediaplayers") icon = KIcon("applications-multimedia");
1242                 else if (metagroupId == "lossless") icon = KIcon("drive-harddisk");
1243                 else if (metagroupId == "mobile") icon = KIcon("pda");
1244                 m_view.destination_list->addItem(icon, i18n(metagroupName.toUtf8().data()), metagroupId);
1245             }
1246         }
1247         groupName = documentElement.attribute("name", i18n("Custom"));
1248         extension = documentElement.attribute("extension", QString());
1249         renderer = documentElement.attribute("renderer", QString());
1250         QList <QListWidgetItem *> list = m_view.format_list->findItems(groupName, Qt::MatchExactly);
1251         bool exists = false;
1252         for (int j = 0; j < list.count(); j++) {
1253             if (list.at(j)->data(MetaGroupRole) == metagroupId) {
1254                 exists = true;
1255                 break;
1256             }
1257         }
1258         if (!exists) {
1259             item = new QListWidgetItem(groupName, m_view.format_list);
1260             item->setData(MetaGroupRole, metagroupId);
1261         }
1262
1263         QDomNode n = groups.item(i).firstChild();
1264         while (!n.isNull()) {
1265             if (n.toElement().tagName() != "profile") {
1266                 n = n.nextSibling();
1267                 continue;
1268             }
1269             profileElement = n.toElement();
1270             profileName = profileElement.attribute("name");
1271             standard = profileElement.attribute("standard");
1272             params = profileElement.attribute("args");
1273             prof_extension = profileElement.attribute("extension");
1274             if (!prof_extension.isEmpty()) extension = prof_extension;
1275             item = new QListWidgetItem(profileName, m_view.size_list);
1276             item->setData(GroupRole, groupName);
1277             item->setData(MetaGroupRole, metagroupId);
1278             item->setData(ExtensionRole, extension);
1279             item->setData(RenderRole, renderer);
1280             item->setData(StandardRole, standard);
1281             item->setData(ParamsRole, params);
1282             if (profileElement.hasAttribute("url")) item->setData(ExtraRole, profileElement.attribute("url"));
1283             if (editable) item->setData(EditableRole, exportFile);
1284             n = n.nextSibling();
1285         }
1286
1287         i++;
1288     }
1289 }
1290
1291 void RenderWidget::setRenderJob(const QString &dest, int progress)
1292 {
1293     QTreeWidgetItem *item;
1294     QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(dest, Qt::MatchExactly, 1);
1295     if (!existing.isEmpty()) item = existing.at(0);
1296     else {
1297         item = new QTreeWidgetItem(m_view.running_jobs, QStringList() << QString() << dest << QString());
1298         item->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
1299         if (progress == 0) {
1300             item->setData(1, Qt::UserRole + 2, WAITINGJOB);
1301             item->setIcon(0, KIcon("media-playback-pause"));
1302             item->setData(1, Qt::UserRole, i18n("Waiting..."));
1303         }
1304     }
1305     item->setData(2, Qt::UserRole, progress);
1306     item->setData(1, Qt::UserRole + 2, RUNNINGJOB);
1307     if (progress == 0) {
1308         item->setIcon(0, KIcon("system-run"));
1309         item->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
1310         item->setData(1, Qt::UserRole + 1, QTime::currentTime());
1311         slotCheckJob();
1312     } else {
1313         QTime startTime = item->data(1, Qt::UserRole + 1).toTime();
1314         int seconds = startTime.secsTo(QTime::currentTime());;
1315         const QString t = i18n("Estimated time %1", QTime().addSecs(seconds * (100 - progress) / progress).toString("hh:mm:ss"));
1316         item->setData(1, Qt::UserRole, t);
1317     }
1318 }
1319
1320 void RenderWidget::setRenderStatus(const QString &dest, int status, const QString &error)
1321 {
1322     QTreeWidgetItem *item;
1323     QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(dest, Qt::MatchExactly, 1);
1324     if (!existing.isEmpty()) item = existing.at(0);
1325     else {
1326         item = new QTreeWidgetItem(m_view.running_jobs, QStringList() << QString() << dest << QString());
1327         item->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
1328     }
1329     item->setData(1, Qt::UserRole + 2, FINISHEDJOB);
1330     if (status == -1) {
1331         // Job finished successfully
1332         item->setIcon(0, KIcon("dialog-ok"));
1333         item->setData(2, Qt::UserRole, 100);
1334         QTime startTime = item->data(1, Qt::UserRole + 1).toTime();
1335         int seconds = startTime.secsTo(QTime::currentTime());
1336         const QTime tm = QTime().addSecs(seconds);
1337         const QString t = i18n("Rendering finished in %1", tm.toString("hh:mm:ss"));
1338         item->setData(1, Qt::UserRole, t);
1339         QString itemGroup = item->data(0, Qt::UserRole).toString();
1340         if (itemGroup == "dvd") {
1341             emit openDvdWizard(item->text(1), item->data(0, Qt::UserRole + 1).toString());
1342         } else if (itemGroup == "websites") {
1343             QString url = item->data(0, Qt::UserRole + 1).toString();
1344             if (!url.isEmpty()) new KRun(url, this);
1345         }
1346     } else if (status == -2) {
1347         // Rendering crashed
1348         item->setData(1, Qt::UserRole, i18n("Rendering crashed"));
1349         item->setIcon(0, KIcon("dialog-close"));
1350         item->setData(2, Qt::UserRole, 100);
1351         m_view.error_log->append(i18n("<strong>Rendering of %1 crashed</strong><br />", dest));
1352         m_view.error_log->append(error);
1353         m_view.error_log->append("<hr />");
1354         m_view.error_box->setVisible(true);
1355     } else if (status == -3) {
1356         // User aborted job
1357         item->setData(1, Qt::UserRole, i18n("Rendering aborted"));
1358         item->setIcon(0, KIcon("dialog-cancel"));
1359         item->setData(2, Qt::UserRole, 100);
1360     }
1361     slotCheckJob();
1362     checkRenderStatus();
1363 }
1364
1365 void RenderWidget::slotAbortCurrentJob()
1366 {
1367     QTreeWidgetItem *current = m_view.running_jobs->currentItem();
1368     if (current) {
1369         if (current->data(1, Qt::UserRole + 2).toInt() == RUNNINGJOB)
1370             emit abortProcess(current->text(1));
1371         else {
1372             delete current;
1373             slotCheckJob();
1374             checkRenderStatus();
1375         }
1376     }
1377 }
1378
1379 void RenderWidget::slotCheckJob()
1380 {
1381     bool activate = false;
1382     QTreeWidgetItem *current = m_view.running_jobs->currentItem();
1383     if (current) {
1384         if (current->data(1, Qt::UserRole + 2).toInt() == RUNNINGJOB)
1385             m_view.abort_job->setText(i18n("Abort Job"));
1386         else m_view.abort_job->setText(i18n("Remove Job"));
1387         activate = true;
1388     }
1389     m_view.abort_job->setEnabled(activate);
1390 }
1391
1392 void RenderWidget::slotCLeanUpJobs()
1393 {
1394     int ix = 0;
1395     QTreeWidgetItem *current = m_view.running_jobs->topLevelItem(ix);
1396     while (current) {
1397         if (current->data(1, Qt::UserRole + 2).toInt() == FINISHEDJOB)
1398             delete current;
1399         else ix++;
1400         current = m_view.running_jobs->topLevelItem(ix);
1401     }
1402     slotCheckJob();
1403 }
1404
1405 void RenderWidget::parseScriptFiles()
1406 {
1407     QStringList scriptsFilter;
1408     scriptsFilter << "*.sh";
1409     m_view.scripts_list->clear();
1410
1411     QTreeWidgetItem *item;
1412     // List the project scripts
1413     QStringList scriptFiles = QDir(m_projectFolder + "scripts").entryList(scriptsFilter, QDir::Files);
1414     for (int i = 0; i < scriptFiles.size(); ++i) {
1415         KUrl scriptpath(m_projectFolder + "scripts/" + scriptFiles.at(i));
1416         QString target;
1417         QString renderer;
1418         QString melt;
1419         QFile file(scriptpath.path());
1420         if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
1421             while (!file.atEnd()) {
1422                 QByteArray line = file.readLine();
1423                 if (line.startsWith("TARGET=")) {
1424                     target = QString(line).section("TARGET=", 1).simplified();
1425                     target.remove(QChar('"'));
1426                 } else if (line.startsWith("RENDERER=")) {
1427                     renderer = QString(line).section("RENDERER=", 1).simplified();
1428                     renderer.remove(QChar('"'));
1429                 } else if (line.startsWith("MELT=")) {
1430                     melt = QString(line).section("MELT=", 1).simplified();
1431                     melt.remove(QChar('"'));
1432                 }
1433             }
1434             file.close();
1435         }
1436         if (target.isEmpty()) continue;
1437         item = new QTreeWidgetItem(m_view.scripts_list, QStringList() << QString() << scriptpath.fileName());
1438         if (!renderer.isEmpty() && renderer.contains('/') && !QFile::exists(renderer)) {
1439             item->setIcon(0, KIcon("dialog-cancel"));
1440             item->setToolTip(1, i18n("Script contains wrong command: %1", renderer));
1441             item->setData(0, Qt::UserRole, '1');
1442         } else if (!melt.isEmpty() && melt.contains('/') && !QFile::exists(melt)) {
1443             item->setIcon(0, KIcon("dialog-cancel"));
1444             item->setToolTip(1, i18n("Script contains wrong command: %1", melt));
1445             item->setData(0, Qt::UserRole, '1');
1446         } else item->setIcon(0, KIcon("application-x-executable-script"));
1447         item->setSizeHint(0, QSize(m_view.scripts_list->columnWidth(0), fontMetrics().height() * 2));
1448         item->setData(1, Qt::UserRole, target.simplified());
1449         item->setData(1, Qt::UserRole + 1, scriptpath.path());
1450     }
1451     bool activate = false;
1452     QTreeWidgetItem *script = m_view.scripts_list->topLevelItem(0);
1453     if (script) {
1454         script->setSelected(true);
1455         m_view.scripts_list->setCurrentItem(script);
1456         activate = true;
1457     }
1458 //    m_view.start_script->setEnabled(activate);
1459 //    m_view.delete_script->setEnabled(activate);
1460 }
1461
1462 void RenderWidget::slotCheckScript()
1463 {
1464     QTreeWidgetItem *item = m_view.scripts_list->currentItem();
1465     if (item == NULL) return;
1466     m_view.start_script->setEnabled(item->data(0, Qt::UserRole).toString().isEmpty());
1467     m_view.delete_script->setEnabled(true);
1468 }
1469
1470 void RenderWidget::slotStartScript()
1471 {
1472     QTreeWidgetItem *item = m_view.scripts_list->currentItem();
1473     if (item) {
1474         QString destination = item->data(1, Qt::UserRole).toString();
1475         QString path = item->data(1, Qt::UserRole + 1).toString();
1476         // Insert new job in queue
1477         QTreeWidgetItem *renderItem;
1478         QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(destination, Qt::MatchExactly, 1);
1479         kDebug() << "------  START SCRIPT";
1480         if (!existing.isEmpty()) {
1481             renderItem = existing.at(0);
1482             if (renderItem->data(1, Qt::UserRole + 2).toInt() == RUNNINGJOB) {
1483                 KMessageBox::information(this, i18n("There is already a job writing file:<br><b>%1</b><br>Abort the job if you want to overwrite it...", destination), i18n("Already running"));
1484                 return;
1485             }
1486         } else renderItem = new QTreeWidgetItem(m_view.running_jobs, QStringList() << QString() << destination << QString());
1487         kDebug() << "------  START SCRIPT 2";
1488         renderItem->setData(2, Qt::UserRole, 0);
1489         renderItem->setData(1, Qt::UserRole + 2, WAITINGJOB);
1490         renderItem->setIcon(0, KIcon("media-playback-pause"));
1491         renderItem->setData(1, Qt::UserRole, i18n("Waiting..."));
1492         renderItem->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
1493         renderItem->setData(1, Qt::UserRole + 1, QTime::currentTime());
1494         renderItem->setData(1, Qt::UserRole + 3, path);
1495         renderItem->setData(1, Qt::UserRole + 4, '1');
1496         checkRenderStatus();
1497         m_view.tabWidget->setCurrentIndex(1);
1498     }
1499 }
1500
1501 void RenderWidget::slotDeleteScript()
1502 {
1503     QTreeWidgetItem *item = m_view.scripts_list->currentItem();
1504     if (item) {
1505         QString path = item->data(1, Qt::UserRole + 1).toString();
1506         KIO::NetAccess::del(path + ".mlt", this);
1507         KIO::NetAccess::del(path, this);
1508         parseScriptFiles();
1509     }
1510 }
1511
1512 void RenderWidget::slotGenerateScript()
1513 {
1514     slotPrepareExport(true);
1515 }
1516
1517 void RenderWidget::slotHideLog()
1518 {
1519     m_view.error_box->setVisible(false);
1520 }
1521
1522 void RenderWidget::setRenderProfile(const QString &dest, const QString &name)
1523 {
1524     m_view.destination_list->blockSignals(true);
1525     m_view.format_list->blockSignals(true);
1526     m_view.size_list->blockSignals(true);
1527     for (int i = 0; i < m_view.destination_list->count(); i++) {
1528         if (m_view.destination_list->itemData(i, Qt::UserRole) == dest) {
1529             m_view.destination_list->setCurrentIndex(i);
1530             break;
1531         }
1532     }
1533     QList<QListWidgetItem *> childs = m_view.size_list->findItems(name, Qt::MatchExactly);
1534     if (!childs.isEmpty()) {
1535         QListWidgetItem *profile = childs.at(0);
1536         if (profile->isHidden()) {
1537             QString group = profile->data(GroupRole).toString();
1538             childs = m_view.format_list->findItems(group, Qt::MatchExactly);
1539             if (!childs.isEmpty()) {
1540                 m_view.format_list->setCurrentItem(childs.at(0));
1541             }
1542         }
1543         refreshView();
1544         m_view.size_list->blockSignals(false);
1545         m_view.size_list->setCurrentItem(profile);
1546     } else m_view.size_list->blockSignals(false);
1547     m_view.destination_list->blockSignals(false);
1548     m_view.format_list->blockSignals(false);
1549
1550 }
1551
1552 bool RenderWidget::startWaitingRenderJobs()
1553 {
1554     m_blockProcessing = true;
1555     QString autoscriptFile = getFreeScriptName("auto");
1556     QFile file(autoscriptFile);
1557     if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1558         kWarning() << "//////  ERROR writing to file: " << autoscriptFile;
1559         KMessageBox::error(0, i18n("Cannot write to file %1", autoscriptFile));
1560         return false;
1561     }
1562
1563     QString renderer = QCoreApplication::applicationDirPath() + QString("/kdenlive_render");
1564     if (!QFile::exists(renderer)) renderer = "kdenlive_render";
1565     QTextStream outStream(&file);
1566     outStream << "#! /bin/sh" << "\n" << "\n";
1567     QTreeWidgetItem *item = m_view.running_jobs->topLevelItem(0);
1568     while (item) {
1569         if (item->data(1, Qt::UserRole + 2).toInt() == WAITINGJOB) {
1570             if (item->data(1, Qt::UserRole + 4).isNull()) {
1571                 // Add render process for item
1572                 const QString params = item->data(1, Qt::UserRole + 3).toStringList().join(" ");
1573                 outStream << renderer << " " << params << "\n";
1574             } else {
1575                 // Script item
1576                 outStream << item->data(1, Qt::UserRole + 3).toString() << "\n";
1577             }
1578         }
1579         item = m_view.running_jobs->itemBelow(item);
1580     }
1581     // erase itself when rendering is finished
1582     outStream << "rm " << autoscriptFile << "\n" << "\n";
1583     if (file.error() != QFile::NoError) {
1584         KMessageBox::error(0, i18n("Cannot write to file %1", autoscriptFile));
1585         file.close();
1586         m_blockProcessing = false;
1587         return false;
1588     }
1589     file.close();
1590     QFile::setPermissions(autoscriptFile, file.permissions() | QFile::ExeUser);
1591     QProcess::startDetached(autoscriptFile, QStringList());
1592     return true;
1593 }
1594
1595 QString RenderWidget::getFreeScriptName(const QString &prefix)
1596 {
1597     int ix = 0;
1598     QString scriptsFolder = m_projectFolder + "scripts/";
1599     KStandardDirs::makeDir(scriptsFolder);
1600     QString path;
1601     while (path.isEmpty() || QFile::exists(path)) {
1602         ix++;
1603         path = scriptsFolder + prefix + i18n("script") + QString::number(ix).rightJustified(3, '0', false) + ".sh";
1604     }
1605     return path;
1606 }
1607
1608 void RenderWidget::slotPlayRendering(QTreeWidgetItem *item, int)
1609 {
1610     if (KdenliveSettings::defaultplayerapp().isEmpty() || item->data(1, Qt::UserRole + 2).toInt() != FINISHEDJOB) return;
1611     QProcess::startDetached(KdenliveSettings::defaultplayerapp(), QStringList() << item->text(1));
1612 }
1613
1614
1615