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 <QDomDocument>
22 #include <QItemDelegate>
23 #include <QTreeWidgetItem>
24 #include <QListWidgetItem>
25 #include <QHeaderView>
28 #include <QInputDialog>
30 #include <KStandardDirs>
32 #include <KMessageBox>
35 #include <KIO/NetAccess>
37 #include "kdenlivesettings.h"
38 #include "renderwidget.h"
39 #include "ui_saveprofile_ui.h"
41 const int GroupRole = Qt::UserRole;
42 const int ExtensionRole = GroupRole + 1;
43 const int StandardRole = GroupRole + 2;
44 const int RenderRole = GroupRole + 3;
45 const int ParamsRole = GroupRole + 4;
46 const int EditableRole = GroupRole + 5;
47 const int MetaGroupRole = GroupRole + 6;
48 const int ExtraRole = GroupRole + 7;
50 RenderWidget::RenderWidget(const QString &projectfolder, QWidget * parent): QDialog(parent), m_projectFolder(projectfolder) {
52 setWindowTitle(i18n("Rendering"));
53 m_view.buttonDelete->setIcon(KIcon("trash-empty"));
54 m_view.buttonDelete->setToolTip(i18n("Delete profile"));
55 m_view.buttonDelete->setEnabled(false);
57 m_view.buttonEdit->setIcon(KIcon("document-properties"));
58 m_view.buttonEdit->setToolTip(i18n("Edit profile"));
59 m_view.buttonEdit->setEnabled(false);
61 m_view.buttonSave->setIcon(KIcon("document-new"));
62 m_view.buttonSave->setToolTip(i18n("Create new profile"));
64 m_view.buttonInfo->setIcon(KIcon("help-about"));
66 if (KdenliveSettings::showrenderparams()) {
67 m_view.buttonInfo->setDown(true);
68 } else m_view.advanced_params->hide();
70 m_view.rescale_size->setInputMask("0099\\x0099");
71 m_view.rescale_size->setText("320x240");
74 QMenu *renderMenu = new QMenu(i18n("Start Rendering"), this);
75 QAction *renderAction = renderMenu->addAction(KIcon("file-new"), i18n("Render to File"));
76 connect(renderAction, SIGNAL(triggered()), this, SLOT(slotExport()));
77 QAction *scriptAction = renderMenu->addAction(KIcon("file-new"), i18n("Generate Script"));
78 connect(scriptAction, SIGNAL(triggered()), this, SLOT(slotGenerateScript()));
80 m_view.buttonStart->setMenu(renderMenu);
81 m_view.buttonStart->setPopupMode(QToolButton::MenuButtonPopup);
82 m_view.buttonStart->setDefaultAction(renderAction);
83 m_view.buttonStart->setToolButtonStyle(Qt::ToolButtonTextOnly);
84 m_view.abort_job->setEnabled(false);
85 m_view.start_script->setEnabled(false);
86 m_view.delete_script->setEnabled(false);
92 connect(m_view.start_script, SIGNAL(clicked()), this, SLOT(slotStartScript()));
93 connect(m_view.delete_script, SIGNAL(clicked()), this, SLOT(slotDeleteScript()));
94 connect(m_view.scripts_list, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(slotCheckScript()));
95 connect(m_view.running_jobs, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(slotCheckJob()));
97 connect(m_view.buttonInfo, SIGNAL(clicked()), this, SLOT(showInfoPanel()));
99 connect(m_view.buttonSave, SIGNAL(clicked()), this, SLOT(slotSaveProfile()));
100 connect(m_view.buttonEdit, SIGNAL(clicked()), this, SLOT(slotEditProfile()));
101 connect(m_view.buttonDelete, SIGNAL(clicked()), this, SLOT(slotDeleteProfile()));
102 connect(m_view.abort_job, SIGNAL(clicked()), this, SLOT(slotAbortCurrentJob()));
103 connect(m_view.buttonClose, SIGNAL(clicked()), this, SLOT(hide()));
104 connect(m_view.buttonClose2, SIGNAL(clicked()), this, SLOT(hide()));
105 connect(m_view.buttonClose3, SIGNAL(clicked()), this, SLOT(hide()));
106 connect(m_view.rescale, SIGNAL(toggled(bool)), m_view.rescale_size, SLOT(setEnabled(bool)));
107 connect(m_view.destination_list, SIGNAL(activated(int)), this, SLOT(refreshView()));
108 connect(m_view.out_file, SIGNAL(textChanged(const QString &)), this, SLOT(slotUpdateButtons()));
109 connect(m_view.out_file, SIGNAL(urlSelected(const KUrl &)), this, SLOT(slotUpdateButtons(const KUrl &)));
110 connect(m_view.format_list, SIGNAL(currentRowChanged(int)), this, SLOT(refreshView()));
111 connect(m_view.size_list, SIGNAL(currentRowChanged(int)), this, SLOT(refreshParams()));
113 connect(m_view.size_list, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(slotEditItem(QListWidgetItem *)));
115 connect(m_view.render_guide, SIGNAL(clicked(bool)), this, SLOT(slotUpdateGuideBox()));
116 connect(m_view.render_zone, SIGNAL(clicked(bool)), this, SLOT(slotUpdateGuideBox()));
117 connect(m_view.render_full, SIGNAL(clicked(bool)), this, SLOT(slotUpdateGuideBox()));
119 connect(m_view.guide_end, SIGNAL(activated(int)), this, SLOT(slotCheckStartGuidePosition()));
120 connect(m_view.guide_start, SIGNAL(activated(int)), this, SLOT(slotCheckEndGuidePosition()));
122 connect(m_view.format_selection, SIGNAL(activated(int)), this, SLOT(refreshView()));
124 m_view.buttonStart->setEnabled(false);
125 m_view.rescale_size->setEnabled(false);
126 m_view.guides_box->setVisible(false);
127 m_view.open_dvd->setVisible(false);
128 m_view.open_browser->setVisible(false);
129 m_view.error_box->setVisible(false);
131 m_view.splitter->setStretchFactor(1, 5);
132 m_view.splitter->setStretchFactor(0, 2);
134 m_view.out_file->setMode(KFile::File);
136 m_view.running_jobs->setHeaderLabels(QStringList() << QString() << i18n("File") << i18n("Progress"));
137 m_view.running_jobs->setItemDelegate(new RenderViewDelegate(this));
139 QHeaderView *header = m_view.running_jobs->header();
140 QFontMetrics fm = fontMetrics();
141 //header->resizeSection(0, fm.width("typical-name-for-a-torrent.torrent"));
142 header->setResizeMode(0, QHeaderView::Fixed);
143 header->resizeSection(0, 30);
144 header->setResizeMode(1, QHeaderView::Interactive);
145 header->resizeSection(1, fm.width("typical-name-for-a-file.torrent"));
146 header->setResizeMode(2, QHeaderView::Fixed);
147 header->resizeSection(1, width() * 2 / 3);
148 header->setResizeMode(2, QHeaderView::Interactive);
149 //header->setResizeMode(1, QHeaderView::Fixed);
151 m_view.scripts_list->setHeaderLabels(QStringList() << i18n("Script Files"));
152 m_view.scripts_list->setItemDelegate(new RenderScriptDelegate(this));
155 focusFirstVisibleItem();
158 void RenderWidget::slotEditItem(QListWidgetItem *item) {
159 if (item->data(EditableRole).toString().isEmpty()) slotSaveProfile();
160 else slotEditProfile();
163 void RenderWidget::showInfoPanel() {
164 if (m_view.advanced_params->isVisible()) {
165 m_view.advanced_params->setVisible(false);
166 m_view.buttonInfo->setDown(false);
167 KdenliveSettings::setShowrenderparams(false);
169 m_view.advanced_params->setVisible(true);
170 m_view.buttonInfo->setDown(true);
171 KdenliveSettings::setShowrenderparams(true);
175 void RenderWidget::setDocumentPath(const QString path) {
176 m_projectFolder = path;
177 const QString fileName = m_view.out_file->url().fileName();
178 m_view.out_file->setUrl(KUrl(m_projectFolder + '/' + fileName));
182 void RenderWidget::slotUpdateGuideBox() {
183 m_view.guides_box->setVisible(m_view.render_guide->isChecked());
186 void RenderWidget::slotCheckStartGuidePosition() {
187 if (m_view.guide_start->currentIndex() > m_view.guide_end->currentIndex())
188 m_view.guide_start->setCurrentIndex(m_view.guide_end->currentIndex());
191 void RenderWidget::slotCheckEndGuidePosition() {
192 if (m_view.guide_end->currentIndex() < m_view.guide_start->currentIndex())
193 m_view.guide_end->setCurrentIndex(m_view.guide_start->currentIndex());
196 void RenderWidget::setGuides(QDomElement guidesxml, double duration) {
197 m_view.guide_start->clear();
198 m_view.guide_end->clear();
199 QDomNodeList nodes = guidesxml.elementsByTagName("guide");
200 if (nodes.count() > 0) {
201 m_view.guide_start->addItem(i18n("Render"), "0");
202 m_view.render_guide->setEnabled(true);
203 } else m_view.render_guide->setEnabled(false);
204 for (int i = 0; i < nodes.count(); i++) {
205 QDomElement e = nodes.item(i).toElement();
207 m_view.guide_start->addItem(e.attribute("comment"), e.attribute("time").toDouble());
208 m_view.guide_end->addItem(e.attribute("comment"), e.attribute("time").toDouble());
211 if (nodes.count() > 0)
212 m_view.guide_end->addItem(i18n("End"), QString::number(duration));
215 // Will be called when the user selects an output file via the file dialog.
216 // File extension will be added automatically.
217 void RenderWidget::slotUpdateButtons(KUrl url) {
218 if (m_view.out_file->url().isEmpty()) m_view.buttonStart->setEnabled(false);
219 else m_view.buttonStart->setEnabled(true);
221 QListWidgetItem *item = m_view.size_list->currentItem();
222 QString extension = item->data(ExtensionRole).toString();
223 url = filenameWithExtension(url, extension);
224 m_view.out_file->setUrl(url);
228 // Will be called when the user changes the output file path in the text line.
229 // File extension must NOT be added, would make editing impossible!
230 void RenderWidget::slotUpdateButtons() {
231 if (m_view.out_file->url().isEmpty()) m_view.buttonStart->setEnabled(false);
232 else m_view.buttonStart->setEnabled(true);
235 void RenderWidget::slotSaveProfile() {
236 //TODO: update to correctly use metagroups
237 Ui::SaveProfile_UI ui;
238 QDialog *d = new QDialog(this);
241 for (int i = 0; i < m_view.destination_list->count(); i++)
242 ui.destination_list->addItem(m_view.destination_list->itemIcon(i), m_view.destination_list->itemText(i), m_view.destination_list->itemData(i, Qt::UserRole));
244 ui.destination_list->setCurrentIndex(m_view.destination_list->currentIndex());
245 QString dest = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
247 QString customGroup = m_view.format_list->currentItem()->text();
248 if (customGroup.isEmpty()) customGroup = i18n("Custom");
249 ui.group_name->setText(customGroup);
251 ui.parameters->setText(m_view.advanced_params->toPlainText());
252 ui.extension->setText(m_view.size_list->currentItem()->data(ExtensionRole).toString());
253 ui.profile_name->setFocus();
254 if (d->exec() == QDialog::Accepted && !ui.profile_name->text().simplified().isEmpty()) {
255 QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
257 QFile file(exportFile);
258 doc.setContent(&file, false);
260 QDomElement documentElement;
261 QDomElement profiles = doc.documentElement();
262 if (profiles.isNull() || profiles.tagName() != "profiles") {
264 profiles = doc.createElement("profiles");
265 profiles.setAttribute("version", 1);
266 doc.appendChild(profiles);
268 int version = profiles.attribute("version", 0).toInt();
270 kDebug() << "// OLD profile version";
272 profiles = doc.createElement("profiles");
273 profiles.setAttribute("version", 1);
274 doc.appendChild(profiles);
277 QString newProfileName = ui.profile_name->text().simplified();
278 QString newGroupName = ui.group_name->text().simplified();
279 if (newGroupName.isEmpty()) newGroupName = i18n("Custom");
280 QString newMetaGroupId = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
281 QDomNodeList profilelist = doc.elementsByTagName("profile");
283 while (!profilelist.item(i).isNull()) {
284 // make sure a profile with same name doesn't exist
285 documentElement = profilelist.item(i).toElement();
286 QString profileName = documentElement.attribute("name");
287 if (profileName == newProfileName) {
288 // a profile with that same name already exists
290 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);
292 if (profileName == newProfileName) {
293 profiles.removeChild(profilelist.item(i));
300 QDomElement profileElement = doc.createElement("profile");
301 profileElement.setAttribute("name", newProfileName);
302 profileElement.setAttribute("category", newGroupName);
303 profileElement.setAttribute("destinationid", newMetaGroupId);
304 profileElement.setAttribute("extension", ui.extension->text().simplified());
305 profileElement.setAttribute("args", ui.parameters->toPlainText().simplified());
306 profiles.appendChild(profileElement);
308 //QCString save = doc.toString().utf8();
310 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
311 KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
315 QTextStream out(&file);
316 out << doc.toString();
318 parseProfiles(newMetaGroupId, newGroupName, newProfileName);
323 void RenderWidget::slotEditProfile() {
324 QListWidgetItem *item = m_view.size_list->currentItem();
326 QString currentGroup = m_view.format_list->currentItem()->text();
328 QString params = item->data(ParamsRole).toString();
329 QString extension = item->data(ExtensionRole).toString();
330 QString currentProfile = item->text();
332 Ui::SaveProfile_UI ui;
333 QDialog *d = new QDialog(this);
336 for (int i = 0; i < m_view.destination_list->count(); i++)
337 ui.destination_list->addItem(m_view.destination_list->itemIcon(i), m_view.destination_list->itemText(i), m_view.destination_list->itemData(i, Qt::UserRole));
339 ui.destination_list->setCurrentIndex(m_view.destination_list->currentIndex());
340 QString dest = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
342 QString customGroup = m_view.format_list->currentItem()->text();
343 if (customGroup.isEmpty()) customGroup = i18n("Custom");
344 ui.group_name->setText(customGroup);
346 ui.profile_name->setText(currentProfile);
347 ui.extension->setText(extension);
348 ui.parameters->setText(params);
349 ui.profile_name->setFocus();
350 d->setWindowTitle(i18n("Edit Profile"));
351 if (d->exec() == QDialog::Accepted) {
352 slotDeleteProfile(false);
353 QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
355 QFile file(exportFile);
356 doc.setContent(&file, false);
358 QDomElement documentElement;
359 QDomElement profiles = doc.documentElement();
361 if (profiles.isNull() || profiles.tagName() != "profiles") {
363 profiles = doc.createElement("profiles");
364 profiles.setAttribute("version", 1);
365 doc.appendChild(profiles);
368 int version = profiles.attribute("version", 0).toInt();
370 kDebug() << "// OLD profile version";
372 profiles = doc.createElement("profiles");
373 profiles.setAttribute("version", 1);
374 doc.appendChild(profiles);
377 QString newProfileName = ui.profile_name->text().simplified();
378 QString newGroupName = ui.group_name->text().simplified();
379 if (newGroupName.isEmpty()) newGroupName = i18n("Custom");
380 QString newMetaGroupId = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
381 QDomNodeList profilelist = doc.elementsByTagName("profile");
383 while (!profilelist.item(i).isNull()) {
384 // make sure a profile with same name doesn't exist
385 documentElement = profilelist.item(i).toElement();
386 QString profileName = documentElement.attribute("name");
387 if (profileName == newProfileName) {
388 // a profile with that same name already exists
390 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);
392 if (profileName == newProfileName) {
393 profiles.removeChild(profilelist.item(i));
400 QDomElement profileElement = doc.createElement("profile");
401 profileElement.setAttribute("name", newProfileName);
402 profileElement.setAttribute("category", newGroupName);
403 profileElement.setAttribute("destinationid", newMetaGroupId);
404 profileElement.setAttribute("extension", ui.extension->text().simplified());
405 profileElement.setAttribute("args", ui.parameters->toPlainText().simplified());
406 profiles.appendChild(profileElement);
408 //QCString save = doc.toString().utf8();
410 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
411 KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
415 QTextStream out(&file);
416 out << doc.toString();
418 parseProfiles(newMetaGroupId, newGroupName, newProfileName);
423 void RenderWidget::slotDeleteProfile(bool refresh) {
424 QString currentGroup = m_view.format_list->currentItem()->text();
425 QString currentProfile = m_view.size_list->currentItem()->text();
426 QString metaGroupId = m_view.destination_list->itemData(m_view.destination_list->currentIndex(), Qt::UserRole).toString();
428 QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
430 QFile file(exportFile);
431 doc.setContent(&file, false);
434 QDomElement documentElement;
435 QDomNodeList profiles = doc.elementsByTagName("profile");
441 while (!profiles.item(i).isNull()) {
442 documentElement = profiles.item(i).toElement();
443 profileName = documentElement.attribute("name");
444 groupName = documentElement.attribute("category");
445 destination = documentElement.attribute("destinationid");
447 if (profileName == currentProfile && groupName == currentGroup && destination == metaGroupId) {
448 kDebug() << "// GOT it: " << profileName;
449 doc.documentElement().removeChild(profiles.item(i));
455 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
456 KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
459 QTextStream out(&file);
460 out << doc.toString();
463 parseProfiles(metaGroupId, currentGroup);
464 focusFirstVisibleItem();
468 void RenderWidget::updateButtons() {
469 if (!m_view.size_list->currentItem() || m_view.size_list->currentItem()->isHidden()) {
470 m_view.buttonSave->setEnabled(false);
471 m_view.buttonDelete->setEnabled(false);
472 m_view.buttonEdit->setEnabled(false);
473 m_view.buttonStart->setEnabled(false);
475 m_view.buttonSave->setEnabled(true);
476 kDebug() << "BUTT: " << m_view.size_list->currentItem()->flags();
477 m_view.buttonStart->setEnabled(m_view.size_list->currentItem()->flags() & Qt::ItemIsEnabled);
478 if (m_view.size_list->currentItem()->data(EditableRole).toString().isEmpty()) {
479 m_view.buttonDelete->setEnabled(false);
480 m_view.buttonEdit->setEnabled(false);
482 m_view.buttonDelete->setEnabled(true);
483 m_view.buttonEdit->setEnabled(true);
489 void RenderWidget::focusFirstVisibleItem() {
490 if (m_view.size_list->currentItem() && !m_view.size_list->currentItem()->isHidden()) {
494 for (uint ix = 0; ix < m_view.size_list->count(); ix++) {
495 QListWidgetItem *item = m_view.size_list->item(ix);
496 if (item && !item->isHidden()) {
497 m_view.size_list->setCurrentRow(ix);
501 if (!m_view.size_list->currentItem()) m_view.size_list->setCurrentRow(0);
505 void RenderWidget::slotExport(bool scriptExport) {
506 QListWidgetItem *item = m_view.size_list->currentItem();
509 const QString dest = m_view.out_file->url().path();
510 if (dest.isEmpty()) return;
513 if (KMessageBox::warningYesNo(this, i18n("Output file already exists. Do you want to overwrite it ?")) != KMessageBox::Yes)
521 QString scriptsFolder = m_projectFolder + "/scripts/";
522 KStandardDirs::makeDir(scriptsFolder);
523 QString path = scriptsFolder + i18n("script") + QString::number(ix).rightJustified(3, '0', false) + ".sh";
524 while (QFile::exists(path)) {
526 path = scriptsFolder + i18n("script") + QString::number(ix).rightJustified(3, '0', false) + ".sh";
528 scriptName = QInputDialog::getText(this, i18n("Create Render Script"), i18n("Script name (will be saved in: %1)", scriptsFolder), QLineEdit::Normal, KUrl(path).fileName(), &ok);
529 if (!ok || scriptName.isEmpty()) return;
530 scriptName.prepend(scriptsFolder);
533 if (KMessageBox::warningYesNo(this, i18n("Script file already exists. Do you want to overwrite it ?")) != KMessageBox::Yes)
538 QStringList overlayargs;
539 if (m_view.tc_overlay->isChecked()) {
540 QString filterFile = KStandardDirs::locate("appdata", "metadata.properties");
541 overlayargs << "meta.attr.timecode=1" << "meta.attr.timecode.markup=#timecode";
542 overlayargs << "-attach" << "data_feed:attr_check" << "-attach";
543 overlayargs << "data_show:" + filterFile << "_fezzik=1" << "dynamic=1";
545 double startPos = -1;
547 if (m_view.render_guide->isChecked()) {
548 startPos = m_view.guide_start->itemData(m_view.guide_start->currentIndex()).toDouble();
549 endPos = m_view.guide_end->itemData(m_view.guide_end->currentIndex()).toDouble();
551 QString renderArgs = m_view.advanced_params->toPlainText();
553 // Adjust frame scale
556 if (m_view.rescale->isChecked() && m_view.rescale->isEnabled()) {
557 width = m_view.rescale_size->text().section('x', 0, 0).toInt();
558 height = m_view.rescale_size->text().section('x', 1, 1).toInt();
560 width = m_profile.width;
561 height = m_profile.height;
563 renderArgs.replace("%dar", "@" + QString::number(m_profile.display_aspect_num) + "/" + QString::number(m_profile.display_aspect_den));
566 if (m_view.scanning_list->currentIndex() == 1) renderArgs.append(" progressive=1");
567 else if (m_view.scanning_list->currentIndex() == 2) renderArgs.append(" progressive=0");
569 // disable audio if requested
570 if (!m_view.export_audio->isChecked())
571 renderArgs.append(" an=1 ");
573 // Check if the rendering profile is different from project profile,
574 // in which case we need to use the producer_comsumer from MLT
575 bool resizeProfile = false;
577 QString std = renderArgs;
578 QString destination = m_view.destination_list->itemData(m_view.destination_list->currentIndex()).toString();
579 if (std.contains(" s=")) {
580 QString subsize = std.section(" s=", 1, 1);
581 subsize = subsize.section(' ', 0, 0).toLower();
582 const QString currentSize = QString::number(width) + 'x' + QString::number(height);
583 if (subsize != currentSize) resizeProfile = true;
584 } else if (destination != "audioonly") {
585 // Add current size parametrer
586 renderArgs.append(QString(" s=%1x%2").arg(width).arg(height));
589 // insert item in running jobs list
590 QTreeWidgetItem *renderItem;
591 QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(dest, Qt::MatchExactly, 1);
592 if (!existing.isEmpty()) renderItem = existing.at(0);
593 else renderItem = new QTreeWidgetItem(m_view.running_jobs, QStringList() << QString() << dest << QString());
594 renderItem->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
595 renderItem->setData(1, Qt::UserRole + 1, QTime::currentTime());
597 // Set rendering type
598 QString group = m_view.size_list->currentItem()->data(MetaGroupRole).toString();
599 if (group == "dvd" && m_view.open_dvd->isChecked()) {
600 renderItem->setData(0, Qt::UserRole, group);
601 if (renderArgs.contains("profile=")) {
602 // rendering profile contains an MLT profile, so pass it to the running jog item, usefull for dvd
603 QString prof = renderArgs.section("profile=", 1, 1);
604 prof = prof.section(' ', 0, 0);
605 kDebug() << "// render profile: " << prof;
606 renderItem->setData(0, Qt::UserRole + 1, prof);
608 } else if (group == "websites" && m_view.open_browser->isChecked()) {
609 renderItem->setData(0, Qt::UserRole, group);
611 QString url = m_view.size_list->currentItem()->data(ExtraRole).toString();
612 renderItem->setData(0, Qt::UserRole + 1, url);
615 emit doRender(dest, item->data(RenderRole).toString(), overlayargs, renderArgs.simplified().split(' '), m_view.render_zone->isChecked(), m_view.play_after->isChecked(), startPos, endPos, resizeProfile, scriptName);
616 if (scriptName.isEmpty()) m_view.tabWidget->setCurrentIndex(1);
618 QTimer::singleShot(400, this, SLOT(parseScriptFiles()));
619 m_view.tabWidget->setCurrentIndex(2);
623 void RenderWidget::setProfile(MltVideoProfile profile) {
625 //WARNING: this way to tell the video standard is a bit hackish...
626 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);
627 else m_view.format_selection->setCurrentIndex(1);
628 m_view.scanning_list->setCurrentIndex(0);
632 void RenderWidget::refreshView() {
633 m_view.size_list->blockSignals(true);
634 QListWidgetItem *sizeItem;
637 KIcon brokenIcon("dialog-close");
638 if (m_view.destination_list->currentIndex() > 0)
639 destination = m_view.destination_list->itemData(m_view.destination_list->currentIndex()).toString();
642 if (destination == "dvd") m_view.open_dvd->setVisible(true);
643 else m_view.open_dvd->setVisible(false);
644 if (destination == "websites") m_view.open_browser->setVisible(true);
645 else m_view.open_browser->setVisible(false);
646 if (!destination.isEmpty() && QString("dvd websites audioonly").contains(destination))
647 m_view.rescale->setEnabled(false);
648 else m_view.rescale->setEnabled(true);
649 // hide groups that are not in the correct destination
650 for (int i = 0; i < m_view.format_list->count(); i++) {
651 sizeItem = m_view.format_list->item(i);
652 if (sizeItem->data(MetaGroupRole).toString() == destination) {
653 sizeItem->setHidden(false);
654 //kDebug() << "// SET GRP:: " << sizeItem->text() << ", METY:" << sizeItem->data(MetaGroupRole).toString();
655 } else sizeItem->setHidden(true);
658 // activate first visible item
659 QListWidgetItem * item = m_view.format_list->currentItem();
660 if (!item || item->isHidden()) {
661 for (int i = 0; i < m_view.format_list->count(); i++) {
662 if (!m_view.format_list->item(i)->isHidden()) {
663 m_view.format_list->setCurrentRow(i);
667 item = m_view.format_list->currentItem();
669 if (!item || item->isHidden()) {
670 m_view.format_list->setEnabled(false);
671 m_view.size_list->setEnabled(false);
674 m_view.format_list->setEnabled(true);
675 m_view.size_list->setEnabled(true);
678 for (int i = 0; i < m_view.format_list->count() && count < 2; i++) {
679 if (!m_view.format_list->isRowHidden(i)) count++;
681 if (count > 1) m_view.format_list->setVisible(true);
682 else m_view.format_list->setVisible(false);
684 QString group = item->text();
685 bool firstSelected = false;
686 const QStringList formatsList = KdenliveSettings::supportedformats();
687 const QStringList vcodecsList = KdenliveSettings::videocodecs();
688 const QStringList acodecsList = KdenliveSettings::audiocodecs();
690 for (int i = 0; i < m_view.size_list->count(); i++) {
691 sizeItem = m_view.size_list->item(i);
692 if ((sizeItem->data(GroupRole) == group || sizeItem->data(GroupRole).toString().isEmpty()) && sizeItem->data(MetaGroupRole) == destination) {
693 std = sizeItem->data(StandardRole).toString();
694 if (!std.isEmpty()) {
695 if (std.contains("PAL", Qt::CaseInsensitive)) sizeItem->setHidden(m_view.format_selection->currentIndex() != 0);
696 else if (std.contains("NTSC", Qt::CaseInsensitive)) sizeItem->setHidden(m_view.format_selection->currentIndex() != 1);
698 sizeItem->setHidden(false);
699 if (!firstSelected) m_view.size_list->setCurrentItem(sizeItem);
700 firstSelected = true;
703 if (!sizeItem->isHidden()) {
704 // Make sure the selected profile uses an installed avformat codec / format
705 std = sizeItem->data(ParamsRole).toString();
707 if (!formatsList.isEmpty()) {
709 if (std.startsWith("f=")) format = std.section("f=", 1, 1);
710 else if (std.contains(" f=")) format = std.section(" f=", 1, 1);
711 if (!format.isEmpty()) {
712 format = format.section(' ', 0, 0).toLower();
713 if (!formatsList.contains(format)) {
714 kDebug() << "***** UNSUPPORTED F: " << format;
715 //sizeItem->setHidden(true);
716 sizeItem->setFlags(Qt::ItemIsSelectable);
717 sizeItem->setToolTip(i18n("Unsupported video format: %1", format));
718 sizeItem->setIcon(brokenIcon);
722 if (!acodecsList.isEmpty() && !sizeItem->isHidden()) {
724 if (std.startsWith("acodec=")) format = std.section("acodec=", 1, 1);
725 else if (std.contains(" acodec=")) format = std.section(" acodec=", 1, 1);
726 if (!format.isEmpty()) {
727 format = format.section(' ', 0, 0).toLower();
728 if (!acodecsList.contains(format)) {
729 kDebug() << "***** UNSUPPORTED ACODEC: " << format;
730 //sizeItem->setHidden(true);
731 sizeItem->setFlags(Qt::ItemIsSelectable);
732 sizeItem->setToolTip(i18n("Unsupported audio codec: %1", format));
733 sizeItem->setIcon(brokenIcon);
737 if (!vcodecsList.isEmpty() && !sizeItem->isHidden()) {
739 if (std.startsWith("vcodec=")) format = std.section("vcodec=", 1, 1);
740 else if (std.contains(" vcodec=")) format = std.section(" vcodec=", 1, 1);
741 if (!format.isEmpty()) {
742 format = format.section(' ', 0, 0).toLower();
743 if (!vcodecsList.contains(format)) {
744 kDebug() << "***** UNSUPPORTED VCODEC: " << format;
745 //sizeItem->setHidden(true);
746 sizeItem->setFlags(Qt::ItemIsSelectable);
747 sizeItem->setToolTip(i18n("Unsupported video codec: %1", format));
748 sizeItem->setIcon(brokenIcon);
753 } else sizeItem->setHidden(true);
755 focusFirstVisibleItem();
756 m_view.size_list->blockSignals(false);
760 KUrl RenderWidget::filenameWithExtension(KUrl url, QString extension) {
762 if (!url.isEmpty()) {
764 int pos = path.lastIndexOf('.') + 1;
765 if (pos == 0) path.append('.' + extension);
766 else path = path.left(pos) + extension;
769 path = m_projectFolder + "/untitled." + extension;
775 void RenderWidget::refreshParams() {
776 QListWidgetItem *item = m_view.size_list->currentItem();
777 if (!item || item->isHidden()) {
778 m_view.advanced_params->clear();
779 m_view.buttonStart->setEnabled(false);
782 QString params = item->data(ParamsRole).toString();
783 QString extension = item->data(ExtensionRole).toString();
784 m_view.advanced_params->setPlainText(params);
785 QString destination = m_view.destination_list->itemData(m_view.destination_list->currentIndex()).toString();
786 if (params.contains(" s=") || destination == "audioonly") {
787 // profile has a fixed size, do not allow resize
788 m_view.rescale->setEnabled(false);
789 m_view.rescale_size->setEnabled(false);
791 m_view.rescale->setEnabled(true);
792 m_view.rescale_size->setEnabled(true);
794 KUrl url = filenameWithExtension(m_view.out_file->url(), extension);
795 m_view.out_file->setUrl(url);
796 // if (!url.isEmpty()) {
797 // QString path = url.path();
798 // int pos = path.lastIndexOf('.') + 1;
799 // if (pos == 0) path.append('.' + extension);
800 // else path = path.left(pos) + extension;
801 // m_view.out_file->setUrl(KUrl(path));
803 // m_view.out_file->setUrl(KUrl(QDir::homePath() + "/untitled." + extension));
805 m_view.out_file->setFilter("*." + extension);
807 if (item->data(EditableRole).toString().isEmpty()) {
808 m_view.buttonDelete->setEnabled(false);
809 m_view.buttonEdit->setEnabled(false);
811 m_view.buttonDelete->setEnabled(true);
812 m_view.buttonEdit->setEnabled(true);
815 m_view.buttonStart->setEnabled(m_view.size_list->currentItem()->flags() & Qt::ItemIsEnabled);
818 void RenderWidget::reloadProfiles() {
822 void RenderWidget::parseProfiles(QString meta, QString group, QString profile) {
823 m_view.size_list->clear();
824 m_view.format_list->clear();
825 m_view.destination_list->clear();
826 m_view.destination_list->addItem(KIcon("video-x-generic"), i18n("File rendering"));
827 m_view.destination_list->addItem(KIcon("media-optical"), i18n("DVD"), "dvd");
828 m_view.destination_list->addItem(KIcon("audio-x-generic"), i18n("Audio only"), "audioonly");
829 m_view.destination_list->addItem(KIcon("applications-internet"), i18n("Web sites"), "websites");
830 m_view.destination_list->addItem(KIcon("applications-multimedia"), i18n("Media players"), "mediaplayers");
831 m_view.destination_list->addItem(KIcon("drive-harddisk"), i18n("Lossless / HQ"), "lossless");
832 m_view.destination_list->addItem(KIcon("pda"), i18n("Mobile devices"), "mobile");
834 QString exportFile = KStandardDirs::locate("appdata", "export/profiles.xml");
835 parseFile(exportFile, false);
838 QString exportFolder = KStandardDirs::locateLocal("appdata", "export/");
839 QDir directory = QDir(exportFolder);
842 const QStringList fileList = directory.entryList(filter, QDir::Files);
843 foreach(const QString filename, fileList)
844 parseFile(exportFolder + '/' + filename, filename == "customprofiles.xml");
846 if (!meta.isEmpty()) {
847 m_view.destination_list->blockSignals(true);
848 m_view.destination_list->setCurrentIndex(m_view.destination_list->findData(meta));
849 m_view.destination_list->blockSignals(false);
852 QList<QListWidgetItem *> child;
853 if (!group.isEmpty()) child = m_view.format_list->findItems(group, Qt::MatchExactly);
854 if (!child.isEmpty()) {
855 for (int i = 0; i < child.count(); i++) {
856 if (child.at(i)->data(MetaGroupRole).toString() == meta) {
857 m_view.format_list->setCurrentItem(child.at(i));
863 if (!profile.isEmpty()) child = m_view.size_list->findItems(profile, Qt::MatchExactly);
864 if (!child.isEmpty()) m_view.size_list->setCurrentItem(child.at(0));
867 void RenderWidget::parseFile(QString exportFile, bool editable) {
868 kDebug() << "// Parsing file: " << exportFile;
869 kDebug() << "------------------------------";
871 QFile file(exportFile);
872 doc.setContent(&file, false);
874 QDomElement documentElement;
875 QDomElement profileElement;
877 QListWidgetItem *item;
878 QDomNodeList groups = doc.elementsByTagName("group");
880 if (editable || groups.count() == 0) {
881 QDomElement profiles = doc.documentElement();
882 if (editable && profiles.attribute("version", 0).toInt() < 1) {
883 kDebug() << "// OLD profile version";
884 // this is an old profile version, update it
886 QDomElement newprofiles = newdoc.createElement("profiles");
887 newprofiles.setAttribute("version", 1);
888 newdoc.appendChild(newprofiles);
889 QDomNodeList profilelist = doc.elementsByTagName("profile");
890 for (int i = 0; i < profilelist.count(); i++) {
891 QString category = i18n("Custom");
893 QDomNode parent = profilelist.at(i).parentNode();
894 if (!parent.isNull()) {
895 QDomElement parentNode = parent.toElement();
896 if (parentNode.hasAttribute("name")) category = parentNode.attribute("name");
897 extension = parentNode.attribute("extension");
899 profilelist.at(i).toElement().setAttribute("category", category);
900 if (!extension.isEmpty()) profilelist.at(i).toElement().setAttribute("extension", extension);
901 QDomNode n = profilelist.at(i).cloneNode();
902 newprofiles.appendChild(newdoc.importNode(n, true));
904 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
905 KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
908 QTextStream out(&file);
909 out << newdoc.toString();
911 parseFile(exportFile, editable);
915 QDomNode node = doc.elementsByTagName("profile").at(0);
917 kDebug() << "// Export file: " << exportFile << " IS BROKEN";
921 while (!node.isNull()) {
922 QDomElement profile = node.toElement();
923 QString profileName = profile.attribute("name");
924 QString standard = profile.attribute("standard");
925 QString params = profile.attribute("args");
926 QString category = profile.attribute("category", i18n("Custom"));
927 QString dest = profile.attribute("destinationid");
928 QString prof_extension = profile.attribute("extension");
929 if (!prof_extension.isEmpty()) extension = prof_extension;
931 QList <QListWidgetItem *> list = m_view.format_list->findItems(category, Qt::MatchExactly);
933 for (int j = 0; j < list.count(); j++) {
934 if (list.at(j)->data(MetaGroupRole) == dest) {
940 item = new QListWidgetItem(category, m_view.format_list);
941 item->setData(MetaGroupRole, dest);
944 item = new QListWidgetItem(profileName, m_view.size_list);
945 //kDebug() << "// ADDINg item with name: " << profileName << ", GRP" << category << ", DEST:" << dest ;
946 item->setData(GroupRole, category);
947 item->setData(MetaGroupRole, dest);
948 item->setData(ExtensionRole, extension);
949 item->setData(RenderRole, "avformat");
950 item->setData(StandardRole, standard);
951 item->setData(ParamsRole, params);
952 if (profile.hasAttribute("url")) item->setData(ExtraRole, profile.attribute("url"));
953 if (editable) item->setData(EditableRole, "true");
954 node = doc.elementsByTagName("profile").at(count);
964 QString prof_extension;
970 while (!groups.item(i).isNull()) {
971 documentElement = groups.item(i).toElement();
972 QDomNode gname = documentElement.elementsByTagName("groupname").at(0);
973 QString metagroupName;
975 if (!gname.isNull()) {
976 metagroupName = gname.firstChild().nodeValue();
977 metagroupId = gname.toElement().attribute("id");
978 if (!metagroupName.isEmpty() && !m_view.destination_list->contains(metagroupName)) {
979 if (metagroupId == "dvd") icon = KIcon("media-optical");
980 else if (metagroupId == "audioonly") icon = KIcon("audio-x-generic");
981 else if (metagroupId == "websites") icon = KIcon("applications-internet");
982 else if (metagroupId == "mediaplayers") icon = KIcon("applications-multimedia");
983 else if (metagroupId == "lossless") icon = KIcon("drive-harddisk");
984 else if (metagroupId == "mobile") icon = KIcon("pda");
985 m_view.destination_list->addItem(icon, i18n(metagroupName.toUtf8().data()), metagroupId);
988 groupName = documentElement.attribute("name", i18n("Custom"));
989 extension = documentElement.attribute("extension", QString::null);
990 renderer = documentElement.attribute("renderer", QString::null);
991 QList <QListWidgetItem *> list = m_view.format_list->findItems(groupName, Qt::MatchExactly);
993 for (int j = 0; j < list.count(); j++) {
994 if (list.at(j)->data(MetaGroupRole) == metagroupId) {
1000 item = new QListWidgetItem(groupName, m_view.format_list);
1001 item->setData(MetaGroupRole, metagroupId);
1004 QDomNode n = groups.item(i).firstChild();
1005 while (!n.isNull()) {
1006 if (n.toElement().tagName() != "profile") {
1007 n = n.nextSibling();
1010 profileElement = n.toElement();
1011 profileName = profileElement.attribute("name");
1012 standard = profileElement.attribute("standard");
1013 params = profileElement.attribute("args");
1014 prof_extension = profileElement.attribute("extension");
1015 if (!prof_extension.isEmpty()) extension = prof_extension;
1016 item = new QListWidgetItem(profileName, m_view.size_list);
1017 item->setData(GroupRole, groupName);
1018 item->setData(MetaGroupRole, metagroupId);
1019 item->setData(ExtensionRole, extension);
1020 item->setData(RenderRole, renderer);
1021 item->setData(StandardRole, standard);
1022 item->setData(ParamsRole, params);
1023 if (profileElement.hasAttribute("url")) item->setData(ExtraRole, profileElement.attribute("url"));
1024 if (editable) item->setData(EditableRole, "true");
1025 n = n.nextSibling();
1032 void RenderWidget::setRenderJob(const QString &dest, int progress) {
1033 QTreeWidgetItem *item;
1034 QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(dest, Qt::MatchExactly, 1);
1035 if (!existing.isEmpty()) item = existing.at(0);
1036 else item = new QTreeWidgetItem(m_view.running_jobs, QStringList() << QString() << dest << QString());
1037 item->setData(2, Qt::UserRole, progress);
1038 if (progress == 0) {
1039 item->setIcon(0, KIcon("system-run"));
1040 item->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
1041 item->setData(1, Qt::UserRole + 1, QTime::currentTime());
1044 QTime startTime = item->data(1, Qt::UserRole + 1).toTime();
1045 int seconds = startTime.secsTo(QTime::currentTime());;
1046 const QString t = i18n("Estimated time %1", QTime().addSecs(seconds * (100 - progress) / progress).toString("hh:mm:ss"));
1047 item->setData(1, Qt::UserRole, t);
1051 void RenderWidget::setRenderStatus(const QString &dest, int status, const QString &error) {
1052 QTreeWidgetItem *item;
1053 QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(dest, Qt::MatchExactly, 1);
1054 if (!existing.isEmpty()) item = existing.at(0);
1055 else item = new QTreeWidgetItem(m_view.running_jobs, QStringList() << QString() << dest << QString());
1057 // Job finished successfully
1058 item->setIcon(0, KIcon("dialog-ok"));
1059 item->setData(2, Qt::UserRole, 100);
1060 QTime startTime = item->data(1, Qt::UserRole + 1).toTime();
1061 int seconds = startTime.secsTo(QTime::currentTime());
1062 const QTime tm = QTime().addSecs(seconds);
1063 const QString t = i18n("Rendering finished in %1", tm.toString("hh:mm:ss"));
1064 item->setData(1, Qt::UserRole, t);
1065 QString itemGroup = item->data(0, Qt::UserRole).toString();
1066 if (itemGroup == "dvd") {
1067 emit openDvdWizard(item->text(1), item->data(0, Qt::UserRole + 1).toString());
1068 } else if (itemGroup == "websites") {
1069 QString url = item->data(0, Qt::UserRole + 1).toString();
1070 if (!url.isEmpty()) KRun *openBrowser = new KRun(url, this);
1072 } else if (status == -2) {
1073 // Rendering crashed
1074 item->setData(1, Qt::UserRole, i18n("Rendering crashed"));
1075 item->setIcon(0, KIcon("dialog-close"));
1076 item->setData(2, Qt::UserRole, 100);
1077 m_view.error_log->append(i18n("<strong>Rendering of %1 crashed</strong><br />", dest));
1078 m_view.error_log->append(error);
1079 m_view.error_log->append("<hr />");
1080 m_view.error_box->setVisible(true);
1081 } else if (status == -3) {
1083 item->setData(1, Qt::UserRole, i18n("Rendering aborted"));
1084 item->setIcon(0, KIcon("dialog-cancel"));
1085 item->setData(2, Qt::UserRole, 100);
1090 void RenderWidget::slotAbortCurrentJob() {
1091 QTreeWidgetItem *current = m_view.running_jobs->currentItem();
1092 if (current) emit abortProcess(current->text(1));
1095 void RenderWidget::slotCheckJob() {
1096 bool activate = false;
1097 QTreeWidgetItem *current = m_view.running_jobs->currentItem();
1099 int percent = current->data(2, Qt::UserRole).toInt();
1100 if (percent < 100) activate = true;
1102 m_view.abort_job->setEnabled(activate);
1105 void RenderWidget::parseScriptFiles() {
1106 QStringList scriptsFilter;
1107 scriptsFilter << "*.sh";
1108 m_view.scripts_list->clear();
1110 QTreeWidgetItem *item;
1111 // List the project scripts
1112 QStringList scriptFiles = QDir(m_projectFolder + "/scripts").entryList(scriptsFilter, QDir::Files);
1113 for (int i = 0; i < scriptFiles.size(); ++i) {
1114 KUrl scriptpath(m_projectFolder + "/scripts/" + scriptFiles.at(i));
1115 item = new QTreeWidgetItem(m_view.scripts_list, QStringList() << scriptpath.fileName());
1117 QFile file(scriptpath.path());
1118 if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
1119 while (!file.atEnd()) {
1120 QByteArray line = file.readLine();
1121 if (line.startsWith("TARGET=")) {
1122 target = QString(line).section("TARGET=", 1);
1123 target.remove(QChar('"'));
1129 item->setSizeHint(0, QSize(m_view.scripts_list->columnWidth(0), fontMetrics().height() * 2));
1130 item->setData(0, Qt::UserRole, target);
1131 item->setData(0, Qt::UserRole + 1, scriptpath.path());
1133 bool activate = false;
1134 QTreeWidgetItemIterator it(m_view.scripts_list);
1136 kDebug() << "// FOUND SCRIPT ITEM:" << (*it)->text(0);
1137 // Selecting item does not work, why ???
1138 m_view.scripts_list->setCurrentItem(*it);
1139 (*it)->setSelected(true);
1142 kDebug() << "SELECTED SCRIPTS: " << m_view.scripts_list->selectedItems().count();
1143 m_view.start_script->setEnabled(activate);
1144 m_view.delete_script->setEnabled(activate);
1147 void RenderWidget::slotCheckScript() {
1148 bool activate = false;
1149 QTreeWidgetItemIterator it(m_view.scripts_list);
1150 if (*it) activate = true;
1151 m_view.start_script->setEnabled(activate);
1152 m_view.delete_script->setEnabled(activate);
1155 void RenderWidget::slotStartScript() {
1156 QTreeWidgetItem *item = m_view.scripts_list->currentItem();
1158 QString path = item->data(0, Qt::UserRole + 1).toString();
1159 QProcess::startDetached(path);
1160 m_view.tabWidget->setCurrentIndex(1);
1164 void RenderWidget::slotDeleteScript() {
1165 QTreeWidgetItem *item = m_view.scripts_list->currentItem();
1167 QString path = item->data(0, Qt::UserRole + 1).toString();
1168 KIO::NetAccess::del(path + ".westley", this);
1169 KIO::NetAccess::del(path, this);
1174 void RenderWidget::slotGenerateScript() {