1 /***************************************************************************
2 * Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
21 #include "renderwidget.h"
22 #include "kdenlivesettings.h"
23 #include "ui_saveprofile_ui.h"
26 #include <KStandardDirs>
28 #include <KMessageBox>
31 #include <KIO/NetAccess>
32 #include <KColorScheme>
33 #include <KNotification>
34 // #include <knewstuff2/engine.h>
36 #include <QDomDocument>
37 #include <QItemDelegate>
38 #include <QTreeWidgetItem>
39 #include <QListWidgetItem>
40 #include <QHeaderView>
43 #include <QInputDialog>
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;
55 const int WAITINGJOB = 0;
56 const int RUNNINGJOB = 1;
57 const int FINISHEDJOB = 2;
60 RenderWidget::RenderWidget(const QString &projectfolder, QWidget * parent) :
62 m_projectFolder(projectfolder),
63 m_blockProcessing(false)
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);
71 m_view.buttonEdit->setIcon(KIcon("document-properties"));
72 m_view.buttonEdit->setToolTip(i18n("Edit profile"));
73 m_view.buttonEdit->setEnabled(false);
75 m_view.buttonSave->setIcon(KIcon("document-new"));
76 m_view.buttonSave->setToolTip(i18n("Create new profile"));
78 m_view.buttonInfo->setIcon(KIcon("help-about"));
79 m_view.hide_log->setIcon(KIcon("go-down"));
81 if (KdenliveSettings::showrenderparams()) {
82 m_view.buttonInfo->setDown(true);
83 } else m_view.advanced_params->hide();
85 m_view.rescale_size->setInputMask("0099\\x0099");
86 m_view.rescale_size->setText("320x240");
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()));
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);
103 m_view.format_list->setAlternatingRowColors(true);
104 m_view.size_list->setAlternatingRowColors(true);
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)));
115 connect(m_view.buttonInfo, SIGNAL(clicked()), this, SLOT(showInfoPanel()));
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()));
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()));
134 connect(m_view.size_list, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(slotEditItem(QListWidgetItem *)));
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()));
140 connect(m_view.guide_end, SIGNAL(activated(int)), this, SLOT(slotCheckStartGuidePosition()));
141 connect(m_view.guide_start, SIGNAL(activated(int)), this, SLOT(slotCheckEndGuidePosition()));
143 connect(m_view.format_selection, SIGNAL(activated(int)), this, SLOT(refreshView()));
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);
153 m_view.splitter->setStretchFactor(1, 5);
154 m_view.splitter->setStretchFactor(0, 2);
156 m_view.out_file->setMode(KFile::File);
158 m_view.running_jobs->setHeaderLabels(QStringList() << QString() << i18n("File") << i18n("Progress"));
159 m_view.running_jobs->setItemDelegate(new RenderViewDelegate(this));
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);
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);
178 focusFirstVisibleItem();
181 void RenderWidget::slotEditItem(QListWidgetItem *item)
183 QString edit = item->data(EditableRole).toString();
184 if (edit.isEmpty() || !edit.endsWith("customprofiles.xml")) slotSaveProfile();
185 else slotEditProfile();
188 void RenderWidget::showInfoPanel()
190 if (m_view.advanced_params->isVisible()) {
191 m_view.advanced_params->setVisible(false);
192 m_view.buttonInfo->setDown(false);
193 KdenliveSettings::setShowrenderparams(false);
195 m_view.advanced_params->setVisible(true);
196 m_view.buttonInfo->setDown(true);
197 KdenliveSettings::setShowrenderparams(true);
201 void RenderWidget::setDocumentPath(const QString path)
203 if (m_view.out_file->url().directory() == KUrl(m_projectFolder).directory()) {
204 const QString fileName = m_view.out_file->url().fileName();
205 m_view.out_file->setUrl(KUrl(path + fileName));
207 m_projectFolder = path;
212 void RenderWidget::slotUpdateGuideBox()
214 m_view.guides_box->setVisible(m_view.render_guide->isChecked());
217 void RenderWidget::slotCheckStartGuidePosition()
219 if (m_view.guide_start->currentIndex() > m_view.guide_end->currentIndex())
220 m_view.guide_start->setCurrentIndex(m_view.guide_end->currentIndex());
223 void RenderWidget::slotCheckEndGuidePosition()
225 if (m_view.guide_end->currentIndex() < m_view.guide_start->currentIndex())
226 m_view.guide_end->setCurrentIndex(m_view.guide_start->currentIndex());
229 void RenderWidget::setGuides(QDomElement guidesxml, double duration)
231 m_view.guide_start->clear();
232 m_view.guide_end->clear();
233 QDomNodeList nodes = guidesxml.elementsByTagName("guide");
234 if (nodes.count() > 0) {
235 m_view.guide_start->addItem(i18n("Beginning"), "0");
236 m_view.render_guide->setEnabled(true);
237 m_view.create_chapter->setEnabled(true);
239 m_view.render_guide->setEnabled(false);
240 m_view.create_chapter->setEnabled(false);
242 double fps = (double) m_profile.frame_rate_num / m_profile.frame_rate_den;
243 for (int i = 0; i < nodes.count(); i++) {
244 QDomElement e = nodes.item(i).toElement();
246 GenTime pos = GenTime(e.attribute("time").toDouble());
247 const QString guidePos = Timecode::getStringTimecode(pos.frames(fps), fps);
248 m_view.guide_start->addItem(e.attribute("comment") + '/' + guidePos, e.attribute("time").toDouble());
249 m_view.guide_end->addItem(e.attribute("comment") + '/' + guidePos, e.attribute("time").toDouble());
252 if (nodes.count() > 0)
253 m_view.guide_end->addItem(i18n("End"), QString::number(duration));
257 * Will be called when the user selects an output file via the file dialog.
258 * File extension will be added automatically.
260 void RenderWidget::slotUpdateButtons(KUrl url)
262 if (m_view.out_file->url().isEmpty()) m_view.buttonStart->setEnabled(false);
264 updateButtons(); // This also checks whether the selected format is available
265 //m_view.buttonStart->setEnabled(true);
268 QListWidgetItem *item = m_view.size_list->currentItem();
269 QString extension = item->data(ExtensionRole).toString();
270 url = filenameWithExtension(url, extension);
271 m_view.out_file->setUrl(url);
276 * Will be called when the user changes the output file path in the text line.
277 * File extension must NOT be added, would make editing impossible!
279 void RenderWidget::slotUpdateButtons()
281 if (m_view.out_file->url().isEmpty()) m_view.buttonStart->setEnabled(false);
282 else updateButtons(); // This also checks whether the selected format is available
283 //else m_view.buttonStart->setEnabled(true);
286 void RenderWidget::slotSaveProfile()
288 //TODO: update to correctly use metagroups
289 Ui::SaveProfile_UI ui;
290 QDialog *d = new QDialog(this);
293 for (int i = 0; i < m_view.destination_list->count(); i++)
294 ui.destination_list->addItem(m_view.destination_list->itemIcon(i), m_view.destination_list->itemText(i), m_view.destination_list->itemData(i, Qt::UserRole));
296 ui.destination_list->setCurrentIndex(m_view.destination_list->currentIndex());
297 QString dest = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
299 QString customGroup = m_view.format_list->currentItem()->text();
300 if (customGroup.isEmpty()) customGroup = i18n("Custom");
301 ui.group_name->setText(customGroup);
303 ui.parameters->setText(m_view.advanced_params->toPlainText());
304 ui.extension->setText(m_view.size_list->currentItem()->data(ExtensionRole).toString());
305 ui.profile_name->setFocus();
307 if (d->exec() == QDialog::Accepted && !ui.profile_name->text().simplified().isEmpty()) {
308 QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
310 QFile file(exportFile);
311 doc.setContent(&file, false);
313 QDomElement documentElement;
314 QDomElement profiles = doc.documentElement();
315 if (profiles.isNull() || profiles.tagName() != "profiles") {
317 profiles = doc.createElement("profiles");
318 profiles.setAttribute("version", 1);
319 doc.appendChild(profiles);
321 int version = profiles.attribute("version", 0).toInt();
323 kDebug() << "// OLD profile version";
325 profiles = doc.createElement("profiles");
326 profiles.setAttribute("version", 1);
327 doc.appendChild(profiles);
330 QString newProfileName = ui.profile_name->text().simplified();
331 QString newGroupName = ui.group_name->text().simplified();
332 if (newGroupName.isEmpty()) newGroupName = i18n("Custom");
333 QString newMetaGroupId = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
334 QDomNodeList profilelist = doc.elementsByTagName("profile");
336 while (!profilelist.item(i).isNull()) {
337 // make sure a profile with same name doesn't exist
338 documentElement = profilelist.item(i).toElement();
339 QString profileName = documentElement.attribute("name");
340 if (profileName == newProfileName) {
341 // a profile with that same name already exists
343 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);
345 if (profileName == newProfileName) {
346 profiles.removeChild(profilelist.item(i));
353 QDomElement profileElement = doc.createElement("profile");
354 profileElement.setAttribute("name", newProfileName);
355 profileElement.setAttribute("category", newGroupName);
356 profileElement.setAttribute("destinationid", newMetaGroupId);
357 profileElement.setAttribute("extension", ui.extension->text().simplified());
358 profileElement.setAttribute("args", ui.parameters->toPlainText().simplified());
359 profiles.appendChild(profileElement);
361 //QCString save = doc.toString().utf8();
363 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
364 KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
368 QTextStream out(&file);
369 out << doc.toString();
370 if (file.error() != QFile::NoError) {
371 KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
377 parseProfiles(newMetaGroupId, newGroupName, newProfileName);
382 void RenderWidget::slotEditProfile()
384 QListWidgetItem *item = m_view.size_list->currentItem();
386 QString currentGroup = m_view.format_list->currentItem()->text();
388 QString params = item->data(ParamsRole).toString();
389 QString extension = item->data(ExtensionRole).toString();
390 QString currentProfile = item->text();
392 Ui::SaveProfile_UI ui;
393 QDialog *d = new QDialog(this);
396 for (int i = 0; i < m_view.destination_list->count(); i++)
397 ui.destination_list->addItem(m_view.destination_list->itemIcon(i), m_view.destination_list->itemText(i), m_view.destination_list->itemData(i, Qt::UserRole));
399 ui.destination_list->setCurrentIndex(m_view.destination_list->currentIndex());
400 QString dest = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
402 QString customGroup = m_view.format_list->currentItem()->text();
403 if (customGroup.isEmpty()) customGroup = i18n("Custom");
404 ui.group_name->setText(customGroup);
406 ui.profile_name->setText(currentProfile);
407 ui.extension->setText(extension);
408 ui.parameters->setText(params);
409 ui.profile_name->setFocus();
410 d->setWindowTitle(i18n("Edit Profile"));
411 if (d->exec() == QDialog::Accepted) {
412 slotDeleteProfile(false);
413 QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
415 QFile file(exportFile);
416 doc.setContent(&file, false);
418 QDomElement documentElement;
419 QDomElement profiles = doc.documentElement();
421 if (profiles.isNull() || profiles.tagName() != "profiles") {
423 profiles = doc.createElement("profiles");
424 profiles.setAttribute("version", 1);
425 doc.appendChild(profiles);
428 int version = profiles.attribute("version", 0).toInt();
430 kDebug() << "// OLD profile version";
432 profiles = doc.createElement("profiles");
433 profiles.setAttribute("version", 1);
434 doc.appendChild(profiles);
437 QString newProfileName = ui.profile_name->text().simplified();
438 QString newGroupName = ui.group_name->text().simplified();
439 if (newGroupName.isEmpty()) newGroupName = i18n("Custom");
440 QString newMetaGroupId = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
441 QDomNodeList profilelist = doc.elementsByTagName("profile");
443 while (!profilelist.item(i).isNull()) {
444 // make sure a profile with same name doesn't exist
445 documentElement = profilelist.item(i).toElement();
446 QString profileName = documentElement.attribute("name");
447 if (profileName == newProfileName) {
448 // a profile with that same name already exists
450 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);
452 if (profileName == newProfileName) {
453 profiles.removeChild(profilelist.item(i));
460 QDomElement profileElement = doc.createElement("profile");
461 profileElement.setAttribute("name", newProfileName);
462 profileElement.setAttribute("category", newGroupName);
463 profileElement.setAttribute("destinationid", newMetaGroupId);
464 profileElement.setAttribute("extension", ui.extension->text().simplified());
465 profileElement.setAttribute("args", ui.parameters->toPlainText().simplified());
466 profiles.appendChild(profileElement);
468 //QCString save = doc.toString().utf8();
470 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
471 KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
474 QTextStream out(&file);
475 out << doc.toString();
476 if (file.error() != QFile::NoError) {
477 KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
482 parseProfiles(newMetaGroupId, newGroupName, newProfileName);
486 void RenderWidget::slotDeleteProfile(bool refresh)
488 //TODO: delete a profile installed by KNewStuff the easy way
490 QString edit = m_view.size_list->currentItem()->data(EditableRole).toString();
491 if (!edit.endsWith("customprofiles.xml")) {
492 // This is a KNewStuff installed file, process through KNS
493 KNS::Engine engine(0);
494 if (engine.init("kdenlive_render.knsrc")) {
495 KNS::Entry::List entries;
499 QString currentGroup = m_view.format_list->currentItem()->text();
500 QString currentProfile = m_view.size_list->currentItem()->text();
501 QString metaGroupId = m_view.destination_list->itemData(m_view.destination_list->currentIndex(), Qt::UserRole).toString();
503 QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
505 QFile file(exportFile);
506 doc.setContent(&file, false);
509 QDomElement documentElement;
510 QDomNodeList profiles = doc.elementsByTagName("profile");
516 while (!profiles.item(i).isNull()) {
517 documentElement = profiles.item(i).toElement();
518 profileName = documentElement.attribute("name");
519 groupName = documentElement.attribute("category");
520 destination = documentElement.attribute("destinationid");
522 if (profileName == currentProfile && groupName == currentGroup && destination == metaGroupId) {
523 kDebug() << "// GOT it: " << profileName;
524 doc.documentElement().removeChild(profiles.item(i));
530 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
531 KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
534 QTextStream out(&file);
535 out << doc.toString();
536 if (file.error() != QFile::NoError) {
537 KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
543 parseProfiles(metaGroupId, currentGroup);
544 focusFirstVisibleItem();
548 void RenderWidget::updateButtons()
550 if (!m_view.size_list->currentItem() || m_view.size_list->currentItem()->isHidden()) {
551 m_view.buttonSave->setEnabled(false);
552 m_view.buttonDelete->setEnabled(false);
553 m_view.buttonEdit->setEnabled(false);
554 m_view.buttonStart->setEnabled(false);
556 m_view.buttonSave->setEnabled(true);
557 m_view.buttonStart->setEnabled(m_view.size_list->currentItem()->toolTip().isEmpty());
558 QString edit = m_view.size_list->currentItem()->data(EditableRole).toString();
559 if (edit.isEmpty() || !edit.endsWith("customprofiles.xml")) {
560 m_view.buttonDelete->setEnabled(false);
561 m_view.buttonEdit->setEnabled(false);
563 m_view.buttonDelete->setEnabled(true);
564 m_view.buttonEdit->setEnabled(true);
570 void RenderWidget::focusFirstVisibleItem()
572 if (m_view.size_list->currentItem() && !m_view.size_list->currentItem()->isHidden()) {
576 for (int ix = 0; ix < m_view.size_list->count(); ix++) {
577 QListWidgetItem *item = m_view.size_list->item(ix);
578 if (item && !item->isHidden()) {
579 m_view.size_list->setCurrentRow(ix);
583 if (!m_view.size_list->currentItem()) m_view.size_list->setCurrentRow(0);
587 void RenderWidget::slotPrepareExport(bool scriptExport)
589 if (!QFile::exists(KdenliveSettings::rendererpath())) {
590 KMessageBox::sorry(this, i18n("Cannot find the melt program required for rendering (part of Mlt)"));
593 if (m_view.play_after->isChecked() && KdenliveSettings::defaultplayerapp().isEmpty())
594 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."));
596 if (m_view.create_chapter->isChecked()) chapterFile = m_view.out_file->url().path() + ".dvdchapter";
599 KStandardDirs::makeDir(m_view.out_file->url().directory());
601 emit prepareRenderingData(scriptExport, m_view.render_zone->isChecked(), chapterFile);
605 void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const QString &playlistPath, const QString &scriptPath)
607 QListWidgetItem *item = m_view.size_list->currentItem();
610 QString dest = m_view.out_file->url().path();
611 if (dest.isEmpty()) return;
613 // Check whether target file has an extension.
614 // If not, ask whether extension should be added or not.
615 QString extension = item->data(ExtensionRole).toString();
616 if (!dest.endsWith(extension, Qt::CaseInsensitive)) {
617 if (KMessageBox::questionYesNo(this, i18n("File has no extension. Add extension (%1)?", extension)) == KMessageBox::Yes) {
618 dest.append("." + extension);
624 if (KMessageBox::warningYesNo(this, i18n("Output file already exists. Do you want to overwrite it?")) != KMessageBox::Yes)
628 QStringList overlayargs;
629 if (m_view.tc_overlay->isChecked()) {
630 QString filterFile = KStandardDirs::locate("appdata", "metadata.properties");
631 overlayargs << "meta.attr.timecode=1" << "meta.attr.timecode.markup=#timecode";
632 overlayargs << "-attach" << "data_feed:attr_check" << "-attach";
633 overlayargs << "data_show:" + filterFile << "_loader=1" << "dynamic=1";
636 QStringList render_process_args;
638 if (!scriptExport) render_process_args << "-erase";
639 if (KdenliveSettings::usekuiserver()) render_process_args << "-kuiserver";
641 double guideStart = 0;
644 if (m_view.render_zone->isChecked()) render_process_args << "in=" + QString::number(zoneIn) << "out=" + QString::number(zoneOut);
645 else if (m_view.render_guide->isChecked()) {
646 double fps = (double) m_profile.frame_rate_num / m_profile.frame_rate_den;
647 guideStart = m_view.guide_start->itemData(m_view.guide_start->currentIndex()).toDouble();
648 guideEnd = m_view.guide_end->itemData(m_view.guide_end->currentIndex()).toDouble();
649 render_process_args << "in=" + QString::number(GenTime(guideStart).frames(fps)) << "out=" + QString::number(GenTime(guideEnd).frames(fps));
652 if (!overlayargs.isEmpty()) render_process_args << "preargs=" + overlayargs.join(" ");
654 render_process_args << KdenliveSettings::rendererpath() << m_profile.path << item->data(RenderRole).toString();
655 if (m_view.play_after->isChecked()) render_process_args << KdenliveSettings::KdenliveSettings::defaultplayerapp();
656 else render_process_args << "-";
658 QString renderArgs = m_view.advanced_params->toPlainText().simplified();
660 // Adjust frame scale
663 if (m_view.rescale->isChecked() && m_view.rescale->isEnabled()) {
664 width = m_view.rescale_size->text().section('x', 0, 0).toInt();
665 height = m_view.rescale_size->text().section('x', 1, 1).toInt();
667 width = m_profile.width;
668 height = m_profile.height;
670 renderArgs.replace("%dar", '@' + QString::number(m_profile.display_aspect_num) + '/' + QString::number(m_profile.display_aspect_den));
673 if (m_view.scanning_list->currentIndex() == 1) renderArgs.append(" progressive=1");
674 else if (m_view.scanning_list->currentIndex() == 2) renderArgs.append(" progressive=0");
676 // disable audio if requested
677 if (!m_view.export_audio->isChecked())
678 renderArgs.append(" an=1 ");
680 // Check if the rendering profile is different from project profile,
681 // in which case we need to use the producer_comsumer from MLT
682 QString std = renderArgs;
683 QString destination = m_view.destination_list->itemData(m_view.destination_list->currentIndex()).toString();
684 const QString currentSize = QString::number(width) + 'x' + QString::number(height);
685 QString subsize = currentSize;
686 if (std.startsWith("s=")) {
687 subsize = std.section(' ', 0, 0).toLower();
688 subsize = subsize.section("=", 1, 1);
689 } else if (std.contains(" s=")) {
690 subsize = std.section(" s=", 1, 1);
691 subsize = subsize.section(' ', 0, 0).toLower();
692 } else if (destination != "audioonly" && m_view.rescale->isChecked() && m_view.rescale->isEnabled()) {
693 subsize = QString(" s=%1x%2").arg(width).arg(height);
694 // Add current size parameter
695 renderArgs.append(subsize);
697 bool resizeProfile = (subsize != currentSize);
698 QStringList paramsList = renderArgs.split(" ", QString::SkipEmptyParts);
699 for (int i = 0; i < paramsList.count(); i++) {
700 if (paramsList.at(i).startsWith("profile=")) {
701 if (paramsList.at(i).section('=', 1) != m_profile.path) resizeProfile = true;
706 if (resizeProfile) render_process_args << "consumer:" + playlistPath;
707 else render_process_args << playlistPath;
708 render_process_args << dest;
709 render_process_args << paramsList;
711 QString group = m_view.size_list->currentItem()->data(MetaGroupRole).toString();
713 QStringList renderParameters;
714 renderParameters << dest << item->data(RenderRole).toString() << renderArgs.simplified();
715 renderParameters << QString::number(zoneIn) << QString::number(zoneOut) << QString::number(m_view.play_after->isChecked());
716 renderParameters << QString::number(guideStart) << QString::number(guideEnd) << QString::number(resizeProfile);
720 // Generate script file
721 QFile file(scriptPath);
722 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
723 KMessageBox::error(this, i18n("Cannot write to file %1", scriptPath));
726 QString renderer = QCoreApplication::applicationDirPath() + QString("/kdenlive_render");
727 if (!QFile::exists(renderer)) renderer = "kdenlive_render";
728 QTextStream outStream(&file);
729 outStream << "#! /bin/sh" << "\n" << "\n";
730 outStream << "SOURCE=" << "\"" + playlistPath + "\"" << "\n";
731 outStream << "TARGET=" << "\"" + dest + "\"" << "\n";
732 outStream << "RENDERER=" << "\"" + renderer + "\"" << "\n";
733 outStream << "MELT=" << "\"" + render_process_args.takeFirst() + "\"" << "\n";
734 outStream << "PARAMETERS=" << "\"" + render_process_args.join(" ") + "\"" << "\n";
735 outStream << "$RENDERER $MELT $PARAMETERS" << "\n" << "\n";
736 if (file.error() != QFile::NoError) {
737 KMessageBox::error(this, i18n("Cannot write to file %1", scriptPath));
742 QFile::setPermissions(scriptPath, file.permissions() | QFile::ExeUser);
744 QTimer::singleShot(400, this, SLOT(parseScriptFiles()));
745 m_view.tabWidget->setCurrentIndex(2);
748 renderParameters << scriptName;
749 m_view.tabWidget->setCurrentIndex(1);
751 // Save rendering profile to document
752 emit selectedRenderProfile(m_view.size_list->currentItem()->data(MetaGroupRole).toString(), m_view.size_list->currentItem()->text(), dest);
754 // insert item in running jobs list
755 QTreeWidgetItem *renderItem;
756 QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(dest, Qt::MatchExactly, 1);
757 if (!existing.isEmpty()) {
758 renderItem = existing.at(0);
759 if (renderItem->data(1, Qt::UserRole + 2).toInt() == RUNNINGJOB) {
760 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"));
763 renderItem->setData(1, Qt::UserRole + 4, QString());
765 renderItem = new QTreeWidgetItem(m_view.running_jobs, QStringList() << QString() << dest << QString());
767 renderItem->setData(1, Qt::UserRole + 2, WAITINGJOB);
768 renderItem->setIcon(0, KIcon("media-playback-pause"));
769 renderItem->setData(1, Qt::UserRole, i18n("Waiting..."));
770 renderItem->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
771 renderItem->setData(1, Qt::UserRole + 1, QTime::currentTime());
773 // Set rendering type
774 if (group == "dvd") {
775 if (m_view.open_dvd->isChecked()) {
776 renderItem->setData(0, Qt::UserRole, group);
777 if (renderArgs.contains("profile=")) {
778 //Â rendering profile contains an MLT profile, so pass it to the running jog item, useful for dvd
779 QString prof = renderArgs.section("profile=", 1, 1);
780 prof = prof.section(' ', 0, 0);
781 kDebug() << "// render profile: " << prof;
782 renderItem->setData(0, Qt::UserRole + 1, prof);
786 if (group == "websites" && m_view.open_browser->isChecked()) {
787 renderItem->setData(0, Qt::UserRole, group);
789 QString url = m_view.size_list->currentItem()->data(ExtraRole).toString();
790 renderItem->setData(0, Qt::UserRole + 1, url);
793 renderItem->setData(1, Qt::UserRole + 3, render_process_args);
797 void RenderWidget::checkRenderStatus()
799 if (m_blockProcessing) return;
800 QTreeWidgetItem *item = m_view.running_jobs->topLevelItem(0);
802 if (item->data(1, Qt::UserRole + 2).toInt() == RUNNINGJOB) return;
803 item = m_view.running_jobs->itemBelow(item);
805 item = m_view.running_jobs->topLevelItem(0);
807 if (item->data(1, Qt::UserRole + 2).toInt() == WAITINGJOB) {
808 item->setData(1, Qt::UserRole + 1, QTime::currentTime());
809 if (item->data(1, Qt::UserRole + 4).isNull()) {
810 // Normal render process
811 QString renderer = QCoreApplication::applicationDirPath() + QString("/kdenlive_render");
812 if (!QFile::exists(renderer)) renderer = "kdenlive_render";
813 if (QProcess::startDetached(renderer, item->data(1, Qt::UserRole + 3).toStringList()) == 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 } else KNotification::event("RenderStarted", i18n("Rendering <i>%1</i> started", item->text(1)), QPixmap(), this);
821 if (QProcess::startDetached(item->data(1, Qt::UserRole + 3).toString()) == false) {
822 item->setData(1, Qt::UserRole + 2, FINISHEDJOB);
823 item->setData(1, Qt::UserRole, i18n("Rendering crashed"));
824 item->setIcon(0, KIcon("dialog-close"));
825 item->setData(2, Qt::UserRole, 100);
830 item = m_view.running_jobs->itemBelow(item);
834 int RenderWidget::waitingJobsCount() const
837 QTreeWidgetItem *item = m_view.running_jobs->topLevelItem(0);
839 if (item->data(1, Qt::UserRole + 2).toInt() == WAITINGJOB) count++;
840 item = m_view.running_jobs->itemBelow(item);
845 void RenderWidget::setProfile(MltVideoProfile profile)
848 //WARNING: this way to tell the video standard is a bit hackish...
849 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);
850 else m_view.format_selection->setCurrentIndex(1);
851 m_view.scanning_list->setCurrentIndex(0);
855 void RenderWidget::refreshView()
857 m_view.size_list->blockSignals(true);
858 QListWidgetItem *sizeItem;
861 KIcon brokenIcon("dialog-close");
862 if (m_view.destination_list->currentIndex() > 0)
863 destination = m_view.destination_list->itemData(m_view.destination_list->currentIndex()).toString();
866 if (destination == "dvd") {
867 m_view.open_dvd->setVisible(true);
868 m_view.create_chapter->setVisible(true);
870 m_view.open_dvd->setVisible(false);
871 m_view.create_chapter->setVisible(false);
873 if (destination == "websites") m_view.open_browser->setVisible(true);
874 else m_view.open_browser->setVisible(false);
875 if (!destination.isEmpty() && QString("dvd websites audioonly").contains(destination))
876 m_view.rescale->setEnabled(false);
877 else m_view.rescale->setEnabled(true);
878 // hide groups that are not in the correct destination
879 for (int i = 0; i < m_view.format_list->count(); i++) {
880 sizeItem = m_view.format_list->item(i);
881 if (sizeItem->data(MetaGroupRole).toString() == destination) {
882 sizeItem->setHidden(false);
883 //kDebug() << "// SET GRP:: " << sizeItem->text() << ", METY:" << sizeItem->data(MetaGroupRole).toString();
884 } else sizeItem->setHidden(true);
887 // activate first visible item
888 QListWidgetItem * item = m_view.format_list->currentItem();
889 if (!item || item->isHidden()) {
890 for (int i = 0; i < m_view.format_list->count(); i++) {
891 if (!m_view.format_list->item(i)->isHidden()) {
892 m_view.format_list->setCurrentRow(i);
896 item = m_view.format_list->currentItem();
898 if (!item || item->isHidden()) {
899 m_view.format_list->setEnabled(false);
900 m_view.size_list->setEnabled(false);
903 m_view.format_list->setEnabled(true);
904 m_view.size_list->setEnabled(true);
907 for (int i = 0; i < m_view.format_list->count() && count < 2; i++) {
908 if (!m_view.format_list->isRowHidden(i)) count++;
910 if (count > 1) m_view.format_list->setVisible(true);
911 else m_view.format_list->setVisible(false);
913 QString group = item->text();
914 bool firstSelected = false;
915 const QStringList formatsList = KdenliveSettings::supportedformats();
916 const QStringList vcodecsList = KdenliveSettings::videocodecs();
917 const QStringList acodecsList = KdenliveSettings::audiocodecs();
919 KColorScheme scheme(palette().currentColorGroup(), KColorScheme::Window);
920 const QColor disabled = scheme.foreground(KColorScheme::InactiveText).color();
921 const QColor disabledbg = scheme.background(KColorScheme::NegativeBackground).color();
923 for (int i = 0; i < m_view.size_list->count(); i++) {
924 sizeItem = m_view.size_list->item(i);
925 if ((sizeItem->data(GroupRole).toString() == group || sizeItem->data(GroupRole).toString().isEmpty()) && sizeItem->data(MetaGroupRole).toString() == destination) {
926 std = sizeItem->data(StandardRole).toString();
927 if (!std.isEmpty()) {
928 if (std.contains("PAL", Qt::CaseInsensitive)) sizeItem->setHidden(m_view.format_selection->currentIndex() != 0);
929 else if (std.contains("NTSC", Qt::CaseInsensitive)) sizeItem->setHidden(m_view.format_selection->currentIndex() != 1);
931 sizeItem->setHidden(false);
932 if (!firstSelected) m_view.size_list->setCurrentItem(sizeItem);
933 firstSelected = true;
936 if (!sizeItem->isHidden()) {
937 // Make sure the selected profile uses an installed avformat codec / format
938 std = sizeItem->data(ParamsRole).toString();
939 if (!formatsList.isEmpty()) {
941 if (std.startsWith("f=")) format = std.section("f=", 1, 1);
942 else if (std.contains(" f=")) format = std.section(" f=", 1, 1);
943 if (!format.isEmpty()) {
944 format = format.section(' ', 0, 0).toLower();
945 if (!formatsList.contains(format)) {
946 kDebug() << "***** UNSUPPORTED F: " << format;
947 //sizeItem->setHidden(true);
948 //sizeItem->setFlags(Qt::ItemIsSelectable);
949 sizeItem->setToolTip(i18n("Unsupported video format: %1", format));
950 sizeItem->setIcon(brokenIcon);
951 sizeItem->setForeground(disabled);
955 if (!acodecsList.isEmpty() && !sizeItem->isHidden()) {
957 if (std.startsWith("acodec=")) format = std.section("acodec=", 1, 1);
958 else if (std.contains(" acodec=")) format = std.section(" acodec=", 1, 1);
959 if (!format.isEmpty()) {
960 format = format.section(' ', 0, 0).toLower();
961 if (!acodecsList.contains(format)) {
962 kDebug() << "***** UNSUPPORTED ACODEC: " << format;
963 //sizeItem->setHidden(true);
964 //sizeItem->setFlags(Qt::ItemIsSelectable);
965 sizeItem->setToolTip(i18n("Unsupported audio codec: %1", format));
966 sizeItem->setIcon(brokenIcon);
967 sizeItem->setForeground(disabled);
968 sizeItem->setBackground(disabledbg);
972 if (!vcodecsList.isEmpty() && !sizeItem->isHidden()) {
974 if (std.startsWith("vcodec=")) format = std.section("vcodec=", 1, 1);
975 else if (std.contains(" vcodec=")) format = std.section(" vcodec=", 1, 1);
976 if (!format.isEmpty()) {
977 format = format.section(' ', 0, 0).toLower();
978 if (!vcodecsList.contains(format)) {
979 kDebug() << "***** UNSUPPORTED VCODEC: " << format;
980 //sizeItem->setHidden(true);
981 //sizeItem->setFlags(Qt::ItemIsSelectable);
982 sizeItem->setToolTip(i18n("Unsupported video codec: %1", format));
983 sizeItem->setIcon(brokenIcon);
984 sizeItem->setForeground(disabled);
989 } else sizeItem->setHidden(true);
991 focusFirstVisibleItem();
992 m_view.size_list->blockSignals(false);
996 KUrl RenderWidget::filenameWithExtension(KUrl url, QString extension)
998 QString directory = url.directory(KUrl::AppendTrailingSlash | KUrl::ObeyTrailingSlash);
999 QString filename = url.fileName(KUrl::ObeyTrailingSlash);
1002 if (extension.at(0) == '.') ext = extension;
1003 else ext = '.' + extension;
1005 if (filename.isEmpty()) filename = i18n("untitled");
1007 int pos = filename.lastIndexOf('.');
1008 if (pos == 0) filename.append(ext);
1010 if (!filename.endsWith(ext, Qt::CaseInsensitive)) {
1011 filename = filename.left(pos) + ext;
1015 return KUrl(directory + filename);
1020 * Called when a new format or size has been selected.
1022 void RenderWidget::refreshParams()
1024 // Format not available (e.g. codec not installed); Disable start button
1025 QListWidgetItem *item = m_view.size_list->currentItem();
1026 if (!item || item->isHidden()) {
1027 m_view.advanced_params->clear();
1028 m_view.buttonStart->setEnabled(false);
1031 QString params = item->data(ParamsRole).toString();
1032 QString extension = item->data(ExtensionRole).toString();
1033 m_view.advanced_params->setPlainText(params);
1034 QString destination = m_view.destination_list->itemData(m_view.destination_list->currentIndex()).toString();
1035 if (params.contains(" s=") || destination == "audioonly") {
1036 // profile has a fixed size, do not allow resize
1037 m_view.rescale->setEnabled(false);
1038 m_view.rescale_size->setEnabled(false);
1040 m_view.rescale->setEnabled(true);
1041 m_view.rescale_size->setEnabled(true);
1043 KUrl url = filenameWithExtension(m_view.out_file->url(), extension);
1044 m_view.out_file->setUrl(url);
1045 // if (!url.isEmpty()) {
1046 // QString path = url.path();
1047 // int pos = path.lastIndexOf('.') + 1;
1048 // if (pos == 0) path.append('.' + extension);
1049 // else path = path.left(pos) + extension;
1050 // m_view.out_file->setUrl(KUrl(path));
1052 // m_view.out_file->setUrl(KUrl(QDir::homePath() + "/untitled." + extension));
1054 m_view.out_file->setFilter("*." + extension);
1055 QString edit = item->data(EditableRole).toString();
1056 if (edit.isEmpty() || !edit.endsWith("customprofiles.xml")) {
1057 m_view.buttonDelete->setEnabled(false);
1058 m_view.buttonEdit->setEnabled(false);
1060 m_view.buttonDelete->setEnabled(true);
1061 m_view.buttonEdit->setEnabled(true);
1064 m_view.buttonStart->setEnabled(m_view.size_list->currentItem()->toolTip().isEmpty());
1067 void RenderWidget::reloadProfiles()
1072 void RenderWidget::parseProfiles(QString meta, QString group, QString profile)
1074 m_view.size_list->clear();
1075 m_view.format_list->clear();
1076 m_view.destination_list->clear();
1077 m_view.destination_list->addItem(KIcon("video-x-generic"), i18n("File rendering"));
1078 m_view.destination_list->addItem(KIcon("media-optical"), i18n("DVD"), "dvd");
1079 m_view.destination_list->addItem(KIcon("audio-x-generic"), i18n("Audio only"), "audioonly");
1080 m_view.destination_list->addItem(KIcon("applications-internet"), i18n("Web sites"), "websites");
1081 m_view.destination_list->addItem(KIcon("applications-multimedia"), i18n("Media players"), "mediaplayers");
1082 m_view.destination_list->addItem(KIcon("drive-harddisk"), i18n("Lossless / HQ"), "lossless");
1083 m_view.destination_list->addItem(KIcon("pda"), i18n("Mobile devices"), "mobile");
1085 QString exportFile = KStandardDirs::locate("appdata", "export/profiles.xml");
1086 parseFile(exportFile, false);
1089 QString exportFolder = KStandardDirs::locateLocal("appdata", "export/");
1090 QDir directory = QDir(exportFolder);
1093 QStringList fileList = directory.entryList(filter, QDir::Files);
1094 // We should parse customprofiles.xml in last position, so that user profiles
1095 // can also override profiles installed by KNewStuff
1096 fileList.removeAll("customprofiles.xml");
1097 foreach(const QString &filename, fileList)
1098 parseFile(exportFolder + filename, true);
1099 if (QFile::exists(exportFolder + "customprofiles.xml")) parseFile(exportFolder + "customprofiles.xml", true);
1101 if (!meta.isEmpty()) {
1102 m_view.destination_list->blockSignals(true);
1103 m_view.destination_list->setCurrentIndex(m_view.destination_list->findData(meta));
1104 m_view.destination_list->blockSignals(false);
1107 QList<QListWidgetItem *> child;
1108 if (!group.isEmpty()) child = m_view.format_list->findItems(group, Qt::MatchExactly);
1109 if (!child.isEmpty()) {
1110 for (int i = 0; i < child.count(); i++) {
1111 if (child.at(i)->data(MetaGroupRole).toString() == meta) {
1112 m_view.format_list->setCurrentItem(child.at(i));
1118 if (!profile.isEmpty()) child = m_view.size_list->findItems(profile, Qt::MatchExactly);
1119 if (!child.isEmpty()) m_view.size_list->setCurrentItem(child.at(0));
1122 void RenderWidget::parseFile(QString exportFile, bool editable)
1124 kDebug() << "// Parsing file: " << exportFile;
1125 kDebug() << "------------------------------";
1127 QFile file(exportFile);
1128 doc.setContent(&file, false);
1130 QDomElement documentElement;
1131 QDomElement profileElement;
1133 QListWidgetItem *item;
1134 QDomNodeList groups = doc.elementsByTagName("group");
1136 const QStringList acodecsList = KdenliveSettings::audiocodecs();
1137 bool replaceVorbisCodec = false;
1138 if (!acodecsList.contains("vorbis") && acodecsList.contains("libvorbis")) replaceVorbisCodec = true;
1141 if (editable || groups.count() == 0) {
1142 QDomElement profiles = doc.documentElement();
1143 if (editable && profiles.attribute("version", 0).toInt() < 1) {
1144 kDebug() << "// OLD profile version";
1145 // this is an old profile version, update it
1146 QDomDocument newdoc;
1147 QDomElement newprofiles = newdoc.createElement("profiles");
1148 newprofiles.setAttribute("version", 1);
1149 newdoc.appendChild(newprofiles);
1150 QDomNodeList profilelist = doc.elementsByTagName("profile");
1151 for (int i = 0; i < profilelist.count(); i++) {
1152 QString category = i18n("Custom");
1154 QDomNode parent = profilelist.at(i).parentNode();
1155 if (!parent.isNull()) {
1156 QDomElement parentNode = parent.toElement();
1157 if (parentNode.hasAttribute("name")) category = parentNode.attribute("name");
1158 extension = parentNode.attribute("extension");
1160 profilelist.at(i).toElement().setAttribute("category", category);
1161 if (!extension.isEmpty()) profilelist.at(i).toElement().setAttribute("extension", extension);
1162 QDomNode n = profilelist.at(i).cloneNode();
1163 newprofiles.appendChild(newdoc.importNode(n, true));
1165 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1166 KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
1169 QTextStream out(&file);
1170 out << newdoc.toString();
1172 parseFile(exportFile, editable);
1176 QDomNode node = doc.elementsByTagName("profile").at(0);
1177 if (node.isNull()) {
1178 kDebug() << "// Export file: " << exportFile << " IS BROKEN";
1182 while (!node.isNull()) {
1183 QDomElement profile = node.toElement();
1184 QString profileName = profile.attribute("name");
1185 QString standard = profile.attribute("standard");
1186 QString params = profile.attribute("args");
1188 if (replaceVorbisCodec && params.contains("acodec=vorbis")) {
1189 // replace vorbis with libvorbis
1190 params = params.replace("vorbis", "libvorbis");
1194 QString category = profile.attribute("category", i18n("Custom"));
1195 QString dest = profile.attribute("destinationid");
1196 QString prof_extension = profile.attribute("extension");
1197 if (!prof_extension.isEmpty()) extension = prof_extension;
1199 QList <QListWidgetItem *> list = m_view.format_list->findItems(category, Qt::MatchExactly);
1200 bool exists = false;
1201 for (int j = 0; j < list.count(); j++) {
1202 if (list.at(j)->data(MetaGroupRole) == dest) {
1208 item = new QListWidgetItem(category, m_view.format_list);
1209 item->setData(MetaGroupRole, dest);
1212 // Check if item with same name already exists and replace it,
1213 // allowing to override default profiles
1215 list = m_view.size_list->findItems(profileName, Qt::MatchExactly);
1217 for (int j = 0; j < list.count(); j++) {
1218 if (list.at(j)->data(MetaGroupRole) == dest) {
1219 QListWidgetItem *duplicate = list.takeAt(j);
1225 item = new QListWidgetItem(profileName, m_view.size_list);
1226 //kDebug() << "// ADDINg item with name: " << profileName << ", GRP" << category << ", DEST:" << dest ;
1227 item->setData(GroupRole, category);
1228 item->setData(MetaGroupRole, dest);
1229 item->setData(ExtensionRole, extension);
1230 item->setData(RenderRole, "avformat");
1231 item->setData(StandardRole, standard);
1232 item->setData(ParamsRole, params);
1233 if (profile.hasAttribute("url")) item->setData(ExtraRole, profile.attribute("url"));
1235 item->setData(EditableRole, exportFile);
1236 if (exportFile.endsWith("customprofiles.xml")) item->setIcon(KIcon("emblem-favorite"));
1237 else item->setIcon(KIcon("applications-internet"));
1239 node = doc.elementsByTagName("profile").at(count);
1247 QString profileName;
1249 QString prof_extension;
1255 while (!groups.item(i).isNull()) {
1256 documentElement = groups.item(i).toElement();
1257 QDomNode gname = documentElement.elementsByTagName("groupname").at(0);
1258 QString metagroupName;
1259 QString metagroupId;
1260 if (!gname.isNull()) {
1261 metagroupName = gname.firstChild().nodeValue();
1262 metagroupId = gname.toElement().attribute("id");
1264 if (!metagroupName.isEmpty() && m_view.destination_list->findData(metagroupId) == -1) {
1265 if (metagroupId == "dvd") icon = KIcon("media-optical");
1266 else if (metagroupId == "audioonly") icon = KIcon("audio-x-generic");
1267 else if (metagroupId == "websites") icon = KIcon("applications-internet");
1268 else if (metagroupId == "mediaplayers") icon = KIcon("applications-multimedia");
1269 else if (metagroupId == "lossless") icon = KIcon("drive-harddisk");
1270 else if (metagroupId == "mobile") icon = KIcon("pda");
1271 m_view.destination_list->addItem(icon, i18n(metagroupName.toUtf8().data()), metagroupId);
1274 groupName = documentElement.attribute("name", i18n("Custom"));
1275 extension = documentElement.attribute("extension", QString());
1276 renderer = documentElement.attribute("renderer", QString());
1277 QList <QListWidgetItem *> list = m_view.format_list->findItems(groupName, Qt::MatchExactly);
1278 bool exists = false;
1279 for (int j = 0; j < list.count(); j++) {
1280 if (list.at(j)->data(MetaGroupRole) == metagroupId) {
1286 item = new QListWidgetItem(groupName, m_view.format_list);
1287 item->setData(MetaGroupRole, metagroupId);
1290 QDomNode n = groups.item(i).firstChild();
1291 while (!n.isNull()) {
1292 if (n.toElement().tagName() != "profile") {
1293 n = n.nextSibling();
1296 profileElement = n.toElement();
1297 profileName = profileElement.attribute("name");
1298 standard = profileElement.attribute("standard");
1299 params = profileElement.attribute("args");
1301 if (replaceVorbisCodec && params.contains("acodec=vorbis")) {
1302 // replace vorbis with libvorbis
1303 params = params.replace("vorbis", "libvorbis");
1305 prof_extension = profileElement.attribute("extension");
1306 if (!prof_extension.isEmpty()) extension = prof_extension;
1307 item = new QListWidgetItem(profileName, m_view.size_list);
1308 item->setData(GroupRole, groupName);
1309 item->setData(MetaGroupRole, metagroupId);
1310 item->setData(ExtensionRole, extension);
1311 item->setData(RenderRole, renderer);
1312 item->setData(StandardRole, standard);
1313 item->setData(ParamsRole, params);
1314 if (profileElement.hasAttribute("url")) item->setData(ExtraRole, profileElement.attribute("url"));
1315 if (editable) item->setData(EditableRole, exportFile);
1316 n = n.nextSibling();
1323 void RenderWidget::setRenderJob(const QString &dest, int progress)
1325 QTreeWidgetItem *item;
1326 QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(dest, Qt::MatchExactly, 1);
1327 if (!existing.isEmpty()) item = existing.at(0);
1329 item = new QTreeWidgetItem(m_view.running_jobs, QStringList() << QString() << dest << QString());
1330 item->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
1331 if (progress == 0) {
1332 item->setData(1, Qt::UserRole + 2, WAITINGJOB);
1333 item->setIcon(0, KIcon("media-playback-pause"));
1334 item->setData(1, Qt::UserRole, i18n("Waiting..."));
1337 item->setData(2, Qt::UserRole, progress);
1338 item->setData(1, Qt::UserRole + 2, RUNNINGJOB);
1339 if (progress == 0) {
1340 item->setIcon(0, KIcon("system-run"));
1341 item->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
1342 item->setData(1, Qt::UserRole + 1, QTime::currentTime());
1345 QTime startTime = item->data(1, Qt::UserRole + 1).toTime();
1346 int seconds = startTime.secsTo(QTime::currentTime());;
1347 const QString t = i18n("Estimated time %1", QTime().addSecs(seconds * (100 - progress) / progress).toString("hh:mm:ss"));
1348 item->setData(1, Qt::UserRole, t);
1352 void RenderWidget::setRenderStatus(const QString &dest, int status, const QString &error)
1354 QTreeWidgetItem *item;
1355 QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(dest, Qt::MatchExactly, 1);
1356 if (!existing.isEmpty()) item = existing.at(0);
1358 item = new QTreeWidgetItem(m_view.running_jobs, QStringList() << QString() << dest << QString());
1359 item->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
1361 item->setData(1, Qt::UserRole + 2, FINISHEDJOB);
1363 // Job finished successfully
1364 item->setIcon(0, KIcon("dialog-ok"));
1365 item->setData(2, Qt::UserRole, 100);
1366 QTime startTime = item->data(1, Qt::UserRole + 1).toTime();
1367 int seconds = startTime.secsTo(QTime::currentTime());
1368 const QTime tm = QTime().addSecs(seconds);
1369 const QString t = i18n("Rendering finished in %1", tm.toString("hh:mm:ss"));
1370 item->setData(1, Qt::UserRole, t);
1371 QString itemGroup = item->data(0, Qt::UserRole).toString();
1372 if (itemGroup == "dvd") {
1373 emit openDvdWizard(item->text(1), item->data(0, Qt::UserRole + 1).toString());
1374 } else if (itemGroup == "websites") {
1375 QString url = item->data(0, Qt::UserRole + 1).toString();
1376 if (!url.isEmpty()) new KRun(url, this);
1378 } else if (status == -2) {
1379 // Rendering crashed
1380 item->setData(1, Qt::UserRole, i18n("Rendering crashed"));
1381 item->setIcon(0, KIcon("dialog-close"));
1382 item->setData(2, Qt::UserRole, 100);
1383 m_view.error_log->append(i18n("<strong>Rendering of %1 crashed</strong><br />", dest));
1384 m_view.error_log->append(error);
1385 m_view.error_log->append("<hr />");
1386 m_view.error_box->setVisible(true);
1387 } else if (status == -3) {
1389 item->setData(1, Qt::UserRole, i18n("Rendering aborted"));
1390 item->setIcon(0, KIcon("dialog-cancel"));
1391 item->setData(2, Qt::UserRole, 100);
1394 checkRenderStatus();
1397 void RenderWidget::slotAbortCurrentJob()
1399 QTreeWidgetItem *current = m_view.running_jobs->currentItem();
1401 if (current->data(1, Qt::UserRole + 2).toInt() == RUNNINGJOB)
1402 emit abortProcess(current->text(1));
1406 checkRenderStatus();
1411 void RenderWidget::slotCheckJob()
1413 bool activate = false;
1414 QTreeWidgetItem *current = m_view.running_jobs->currentItem();
1416 if (current->data(1, Qt::UserRole + 2).toInt() == RUNNINGJOB)
1417 m_view.abort_job->setText(i18n("Abort Job"));
1418 else m_view.abort_job->setText(i18n("Remove Job"));
1421 m_view.abort_job->setEnabled(activate);
1424 void RenderWidget::slotCLeanUpJobs()
1427 QTreeWidgetItem *current = m_view.running_jobs->topLevelItem(ix);
1429 if (current->data(1, Qt::UserRole + 2).toInt() == FINISHEDJOB)
1432 current = m_view.running_jobs->topLevelItem(ix);
1437 void RenderWidget::parseScriptFiles()
1439 QStringList scriptsFilter;
1440 scriptsFilter << "*.sh";
1441 m_view.scripts_list->clear();
1443 QTreeWidgetItem *item;
1444 // List the project scripts
1445 QStringList scriptFiles = QDir(m_projectFolder + "scripts").entryList(scriptsFilter, QDir::Files);
1446 for (int i = 0; i < scriptFiles.size(); ++i) {
1447 KUrl scriptpath(m_projectFolder + "scripts/" + scriptFiles.at(i));
1451 QFile file(scriptpath.path());
1452 if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
1453 while (!file.atEnd()) {
1454 QByteArray line = file.readLine();
1455 if (line.startsWith("TARGET=")) {
1456 target = QString(line).section("TARGET=", 1).simplified();
1457 target.remove(QChar('"'));
1458 } else if (line.startsWith("RENDERER=")) {
1459 renderer = QString(line).section("RENDERER=", 1).simplified();
1460 renderer.remove(QChar('"'));
1461 } else if (line.startsWith("MELT=")) {
1462 melt = QString(line).section("MELT=", 1).simplified();
1463 melt.remove(QChar('"'));
1468 if (target.isEmpty()) continue;
1469 item = new QTreeWidgetItem(m_view.scripts_list, QStringList() << QString() << scriptpath.fileName());
1470 if (!renderer.isEmpty() && renderer.contains('/') && !QFile::exists(renderer)) {
1471 item->setIcon(0, KIcon("dialog-cancel"));
1472 item->setToolTip(1, i18n("Script contains wrong command: %1", renderer));
1473 item->setData(0, Qt::UserRole, '1');
1474 } else if (!melt.isEmpty() && melt.contains('/') && !QFile::exists(melt)) {
1475 item->setIcon(0, KIcon("dialog-cancel"));
1476 item->setToolTip(1, i18n("Script contains wrong command: %1", melt));
1477 item->setData(0, Qt::UserRole, '1');
1478 } else item->setIcon(0, KIcon("application-x-executable-script"));
1479 item->setSizeHint(0, QSize(m_view.scripts_list->columnWidth(0), fontMetrics().height() * 2));
1480 item->setData(1, Qt::UserRole, target.simplified());
1481 item->setData(1, Qt::UserRole + 1, scriptpath.path());
1483 bool activate = false;
1484 QTreeWidgetItem *script = m_view.scripts_list->topLevelItem(0);
1486 script->setSelected(true);
1487 m_view.scripts_list->setCurrentItem(script);
1490 // m_view.start_script->setEnabled(activate);
1491 // m_view.delete_script->setEnabled(activate);
1494 void RenderWidget::slotCheckScript()
1496 QTreeWidgetItem *item = m_view.scripts_list->currentItem();
1497 if (item == NULL) return;
1498 m_view.start_script->setEnabled(item->data(0, Qt::UserRole).toString().isEmpty());
1499 m_view.delete_script->setEnabled(true);
1502 void RenderWidget::slotStartScript()
1504 QTreeWidgetItem *item = m_view.scripts_list->currentItem();
1506 QString destination = item->data(1, Qt::UserRole).toString();
1507 QString path = item->data(1, Qt::UserRole + 1).toString();
1508 // Insert new job in queue
1509 QTreeWidgetItem *renderItem;
1510 QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(destination, Qt::MatchExactly, 1);
1511 kDebug() << "------ START SCRIPT";
1512 if (!existing.isEmpty()) {
1513 renderItem = existing.at(0);
1514 if (renderItem->data(1, Qt::UserRole + 2).toInt() == RUNNINGJOB) {
1515 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"));
1518 } else renderItem = new QTreeWidgetItem(m_view.running_jobs, QStringList() << QString() << destination << QString());
1519 kDebug() << "------ START SCRIPT 2";
1520 renderItem->setData(2, Qt::UserRole, 0);
1521 renderItem->setData(1, Qt::UserRole + 2, WAITINGJOB);
1522 renderItem->setIcon(0, KIcon("media-playback-pause"));
1523 renderItem->setData(1, Qt::UserRole, i18n("Waiting..."));
1524 renderItem->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
1525 renderItem->setData(1, Qt::UserRole + 1, QTime::currentTime());
1526 renderItem->setData(1, Qt::UserRole + 3, path);
1527 renderItem->setData(1, Qt::UserRole + 4, '1');
1528 checkRenderStatus();
1529 m_view.tabWidget->setCurrentIndex(1);
1533 void RenderWidget::slotDeleteScript()
1535 QTreeWidgetItem *item = m_view.scripts_list->currentItem();
1537 QString path = item->data(1, Qt::UserRole + 1).toString();
1538 KIO::NetAccess::del(path + ".mlt", this);
1539 KIO::NetAccess::del(path, this);
1544 void RenderWidget::slotGenerateScript()
1546 slotPrepareExport(true);
1549 void RenderWidget::slotHideLog()
1551 m_view.error_box->setVisible(false);
1554 void RenderWidget::setRenderProfile(const QString &dest, const QString &name, const QString &url)
1556 m_view.destination_list->blockSignals(true);
1557 m_view.format_list->blockSignals(true);
1558 m_view.size_list->blockSignals(true);
1560 if (!url.isEmpty()) m_view.out_file->setUrl(KUrl(url));
1562 for (int i = 0; i < m_view.destination_list->count(); i++) {
1563 if (m_view.destination_list->itemData(i, Qt::UserRole) == dest) {
1564 m_view.destination_list->setCurrentIndex(i);
1568 QList<QListWidgetItem *> childs = m_view.size_list->findItems(name, Qt::MatchExactly);
1569 if (!childs.isEmpty()) {
1570 QListWidgetItem *profile = childs.at(0);
1571 if (profile->isHidden()) {
1572 QString group = profile->data(GroupRole).toString();
1573 childs = m_view.format_list->findItems(group, Qt::MatchExactly);
1574 if (!childs.isEmpty()) {
1575 m_view.format_list->setCurrentItem(childs.at(0));
1579 m_view.size_list->blockSignals(false);
1580 m_view.size_list->setCurrentItem(profile);
1581 } else m_view.size_list->blockSignals(false);
1582 m_view.destination_list->blockSignals(false);
1583 m_view.format_list->blockSignals(false);
1587 bool RenderWidget::startWaitingRenderJobs()
1589 m_blockProcessing = true;
1590 QString autoscriptFile = getFreeScriptName("auto");
1591 QFile file(autoscriptFile);
1592 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1593 kWarning() << "////// ERROR writing to file: " << autoscriptFile;
1594 KMessageBox::error(0, i18n("Cannot write to file %1", autoscriptFile));
1598 QString renderer = QCoreApplication::applicationDirPath() + QString("/kdenlive_render");
1599 if (!QFile::exists(renderer)) renderer = "kdenlive_render";
1600 QTextStream outStream(&file);
1601 outStream << "#! /bin/sh" << "\n" << "\n";
1602 QTreeWidgetItem *item = m_view.running_jobs->topLevelItem(0);
1604 if (item->data(1, Qt::UserRole + 2).toInt() == WAITINGJOB) {
1605 if (item->data(1, Qt::UserRole + 4).isNull()) {
1606 // Add render process for item
1607 const QString params = item->data(1, Qt::UserRole + 3).toStringList().join(" ");
1608 outStream << renderer << " " << params << "\n";
1611 outStream << item->data(1, Qt::UserRole + 3).toString() << "\n";
1614 item = m_view.running_jobs->itemBelow(item);
1616 // erase itself when rendering is finished
1617 outStream << "rm " << autoscriptFile << "\n" << "\n";
1618 if (file.error() != QFile::NoError) {
1619 KMessageBox::error(0, i18n("Cannot write to file %1", autoscriptFile));
1621 m_blockProcessing = false;
1625 QFile::setPermissions(autoscriptFile, file.permissions() | QFile::ExeUser);
1626 QProcess::startDetached(autoscriptFile, QStringList());
1630 QString RenderWidget::getFreeScriptName(const QString &prefix)
1633 QString scriptsFolder = m_projectFolder + "scripts/";
1634 KStandardDirs::makeDir(scriptsFolder);
1636 while (path.isEmpty() || QFile::exists(path)) {
1638 path = scriptsFolder + prefix + i18n("script") + QString::number(ix).rightJustified(3, '0', false) + ".sh";
1643 void RenderWidget::slotPlayRendering(QTreeWidgetItem *item, int)
1645 if (KdenliveSettings::defaultplayerapp().isEmpty() || item->data(1, Qt::UserRole + 2).toInt() != FINISHEDJOB) return;
1646 QProcess::startDetached(KdenliveSettings::defaultplayerapp(), QStringList() << item->text(1));