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 <KStartupInfo>
36 #include <QDomDocument>
37 #include <QItemDelegate>
38 #include <QTreeWidgetItem>
39 #include <QListWidgetItem>
40 #include <QHeaderView>
42 #include <QInputDialog>
44 #include <QDBusConnectionInterface>
45 #include <QDBusInterface>
47 const int GroupRole = Qt::UserRole;
48 const int ExtensionRole = GroupRole + 1;
49 const int StandardRole = GroupRole + 2;
50 const int RenderRole = GroupRole + 3;
51 const int ParamsRole = GroupRole + 4;
52 const int EditableRole = GroupRole + 5;
53 const int MetaGroupRole = GroupRole + 6;
54 const int ExtraRole = GroupRole + 7;
57 const int WAITINGJOB = 0;
58 const int RUNNINGJOB = 1;
59 const int FINISHEDJOB = 2;
62 RenderWidget::RenderWidget(const QString &projectfolder, QWidget * parent) :
64 m_projectFolder(projectfolder),
65 m_blockProcessing(false)
68 setWindowTitle(i18n("Rendering"));
69 m_view.buttonDelete->setIcon(KIcon("trash-empty"));
70 m_view.buttonDelete->setToolTip(i18n("Delete profile"));
71 m_view.buttonDelete->setEnabled(false);
73 m_view.buttonEdit->setIcon(KIcon("document-properties"));
74 m_view.buttonEdit->setToolTip(i18n("Edit profile"));
75 m_view.buttonEdit->setEnabled(false);
77 m_view.buttonSave->setIcon(KIcon("document-new"));
78 m_view.buttonSave->setToolTip(i18n("Create new profile"));
80 m_view.buttonInfo->setIcon(KIcon("help-about"));
81 m_view.hide_log->setIcon(KIcon("go-down"));
83 m_view.buttonFavorite->setIcon(KIcon("favorites"));
84 m_view.buttonFavorite->setToolTip(i18n("Copy profile to favorites"));
86 if (KdenliveSettings::showrenderparams()) {
87 m_view.buttonInfo->setDown(true);
88 } else m_view.advanced_params->hide();
90 m_view.rescale_keep->setChecked(KdenliveSettings::rescalekeepratio());
91 connect(m_view.rescale_width, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateRescaleWidth(int)));
92 connect(m_view.rescale_height, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateRescaleHeight(int)));
93 m_view.rescale_keep->setIcon(KIcon("insert-link"));
94 m_view.rescale_keep->setToolTip(i18n("Preserve aspect ratio"));
95 connect(m_view.rescale_keep, SIGNAL(clicked()), this, SLOT(slotSwitchAspectRatio()));
97 connect(m_view.buttonRender, SIGNAL(clicked()), this, SLOT(slotPrepareExport()));
98 connect(m_view.buttonGenerateScript, SIGNAL(clicked()), this, SLOT(slotGenerateScript()));
100 m_view.abort_job->setEnabled(false);
101 m_view.start_script->setEnabled(false);
102 m_view.delete_script->setEnabled(false);
104 m_view.format_list->setAlternatingRowColors(true);
105 m_view.size_list->setAlternatingRowColors(true);
107 KColorScheme scheme(palette().currentColorGroup(), KColorScheme::Window, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
108 QColor bg = scheme.background(KColorScheme::NegativeBackground).color();
109 m_view.errorBox->setStyleSheet(QString("QGroupBox { background-color: rgb(%1, %2, %3); border-radius: 5px;}; ").arg(bg.red()).arg(bg.green()).arg(bg.blue()));
110 int height = QFontInfo(font()).pixelSize();
111 m_view.errorIcon->setPixmap(KIcon("dialog-warning").pixmap(height, height));
112 m_view.errorBox->setHidden(true);
114 connect(m_view.export_audio, SIGNAL(stateChanged(int)), this, SLOT(slotUpdateAudioLabel(int)));
115 m_view.export_audio->setCheckState(Qt::PartiallyChecked);
119 m_view.running_jobs->setUniformRowHeights(false);
120 m_view.scripts_list->setUniformRowHeights(false);
121 connect(m_view.start_script, SIGNAL(clicked()), this, SLOT(slotStartScript()));
122 connect(m_view.delete_script, SIGNAL(clicked()), this, SLOT(slotDeleteScript()));
123 connect(m_view.scripts_list, SIGNAL(itemSelectionChanged()), this, SLOT(slotCheckScript()));
124 connect(m_view.running_jobs, SIGNAL(itemSelectionChanged()), this, SLOT(slotCheckJob()));
125 connect(m_view.running_jobs, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(slotPlayRendering(QTreeWidgetItem *, int)));
127 connect(m_view.buttonInfo, SIGNAL(clicked()), this, SLOT(showInfoPanel()));
129 connect(m_view.buttonSave, SIGNAL(clicked()), this, SLOT(slotSaveProfile()));
130 connect(m_view.buttonEdit, SIGNAL(clicked()), this, SLOT(slotEditProfile()));
131 connect(m_view.buttonDelete, SIGNAL(clicked()), this, SLOT(slotDeleteProfile()));
132 connect(m_view.buttonFavorite, SIGNAL(clicked()), this, SLOT(slotCopyToFavorites()));
134 connect(m_view.abort_job, SIGNAL(clicked()), this, SLOT(slotAbortCurrentJob()));
135 connect(m_view.start_job, SIGNAL(clicked()), this, SLOT(slotStartCurrentJob()));
136 connect(m_view.clean_up, SIGNAL(clicked()), this, SLOT(slotCLeanUpJobs()));
137 connect(m_view.hide_log, SIGNAL(clicked()), this, SLOT(slotHideLog()));
139 connect(m_view.buttonClose, SIGNAL(clicked()), this, SLOT(hide()));
140 connect(m_view.buttonClose2, SIGNAL(clicked()), this, SLOT(hide()));
141 connect(m_view.buttonClose3, SIGNAL(clicked()), this, SLOT(hide()));
142 connect(m_view.rescale, SIGNAL(toggled(bool)), m_view.rescale_box, SLOT(setEnabled(bool)));
143 connect(m_view.destination_list, SIGNAL(activated(int)), this, SLOT(refreshCategory()));
144 connect(m_view.out_file, SIGNAL(textChanged(const QString &)), this, SLOT(slotUpdateButtons()));
145 connect(m_view.out_file, SIGNAL(urlSelected(const KUrl &)), this, SLOT(slotUpdateButtons(const KUrl &)));
146 connect(m_view.format_list, SIGNAL(currentRowChanged(int)), this, SLOT(refreshView()));
147 connect(m_view.size_list, SIGNAL(currentRowChanged(int)), this, SLOT(refreshParams()));
149 connect(m_view.size_list, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(slotEditItem(QListWidgetItem *)));
151 connect(m_view.render_guide, SIGNAL(clicked(bool)), this, SLOT(slotUpdateGuideBox()));
152 connect(m_view.render_zone, SIGNAL(clicked(bool)), this, SLOT(slotUpdateGuideBox()));
153 connect(m_view.render_full, SIGNAL(clicked(bool)), this, SLOT(slotUpdateGuideBox()));
155 connect(m_view.guide_end, SIGNAL(activated(int)), this, SLOT(slotCheckStartGuidePosition()));
156 connect(m_view.guide_start, SIGNAL(activated(int)), this, SLOT(slotCheckEndGuidePosition()));
158 connect(m_view.format_selection, SIGNAL(activated(int)), this, SLOT(refreshView()));
160 m_view.buttonRender->setEnabled(false);
161 m_view.buttonGenerateScript->setEnabled(false);
162 m_view.rescale_box->setEnabled(false);
163 m_view.guides_box->setVisible(false);
164 m_view.open_dvd->setVisible(false);
165 m_view.create_chapter->setVisible(false);
166 m_view.open_browser->setVisible(false);
167 m_view.error_box->setVisible(false);
169 m_view.splitter->setStretchFactor(1, 5);
170 m_view.splitter->setStretchFactor(0, 2);
172 m_view.out_file->setMode(KFile::File);
174 m_view.running_jobs->setHeaderLabels(QStringList() << QString() << i18n("File") << i18n("Progress"));
175 m_jobsDelegate = new RenderViewDelegate(this);
176 m_view.running_jobs->setItemDelegate(m_jobsDelegate);
178 QHeaderView *header = m_view.running_jobs->header();
179 header->setResizeMode(0, QHeaderView::Fixed);
180 header->resizeSection(0, 30);
181 header->setResizeMode(1, QHeaderView::Interactive);
182 header->setResizeMode(2, QHeaderView::Fixed);
183 header->resizeSection(1, width() * 2 / 3 - 15);
184 header->setResizeMode(2, QHeaderView::Interactive);
185 //header->setResizeMode(1, QHeaderView::Fixed);
188 m_view.scripts_list->setHeaderLabels(QStringList() << QString() << i18n("Script Files"));
189 m_scriptsDelegate = new RenderViewDelegate(this);
190 m_view.scripts_list->setItemDelegate(m_scriptsDelegate);
191 header = m_view.scripts_list->header();
192 header->setResizeMode(0, QHeaderView::Fixed);
193 header->resizeSection(0, 30);
195 // Find path for Kdenlive renderer
196 m_renderer = QCoreApplication::applicationDirPath() + QString("/kdenlive_render");
197 if (!QFile::exists(m_renderer)) {
198 m_renderer = KStandardDirs::findExe("kdenlive_render");
199 if (m_renderer.isEmpty()) m_renderer = KStandardDirs::locate("exe", "kdenlive_render");
200 if (m_renderer.isEmpty()) m_renderer = "kdenlive_render";
203 QDBusConnectionInterface* interface = QDBusConnection::sessionBus().interface();
204 if (!interface || (!interface->isServiceRegistered("org.kde.ksmserver") && !interface->isServiceRegistered("org.gnome.SessionManager")))
205 m_view.shutdown->setEnabled(false);
207 focusFirstVisibleItem();
210 RenderWidget::~RenderWidget()
212 m_view.running_jobs->blockSignals(true);
213 m_view.scripts_list->blockSignals(true);
214 m_view.running_jobs->clear();
215 m_view.scripts_list->clear();
216 delete m_jobsDelegate;
217 delete m_scriptsDelegate;
220 void RenderWidget::slotEditItem(QListWidgetItem *item)
222 QString edit = item->data(EditableRole).toString();
223 if (edit.isEmpty() || !edit.endsWith("customprofiles.xml")) slotSaveProfile();
224 else slotEditProfile();
227 void RenderWidget::showInfoPanel()
229 if (m_view.advanced_params->isVisible()) {
230 m_view.advanced_params->setVisible(false);
231 m_view.buttonInfo->setDown(false);
232 KdenliveSettings::setShowrenderparams(false);
234 m_view.advanced_params->setVisible(true);
235 m_view.buttonInfo->setDown(true);
236 KdenliveSettings::setShowrenderparams(true);
240 void RenderWidget::setDocumentPath(const QString path)
242 if (m_view.out_file->url().directory() == KUrl(m_projectFolder).directory()) {
243 const QString fileName = m_view.out_file->url().fileName();
244 m_view.out_file->setUrl(KUrl(path + fileName));
246 m_projectFolder = path;
251 void RenderWidget::slotUpdateGuideBox()
253 m_view.guides_box->setVisible(m_view.render_guide->isChecked());
256 void RenderWidget::slotCheckStartGuidePosition()
258 if (m_view.guide_start->currentIndex() > m_view.guide_end->currentIndex())
259 m_view.guide_start->setCurrentIndex(m_view.guide_end->currentIndex());
262 void RenderWidget::slotCheckEndGuidePosition()
264 if (m_view.guide_end->currentIndex() < m_view.guide_start->currentIndex())
265 m_view.guide_end->setCurrentIndex(m_view.guide_start->currentIndex());
268 void RenderWidget::setGuides(QDomElement guidesxml, double duration)
270 m_view.guide_start->clear();
271 m_view.guide_end->clear();
272 QDomNodeList nodes = guidesxml.elementsByTagName("guide");
273 if (nodes.count() > 0) {
274 m_view.guide_start->addItem(i18n("Beginning"), "0");
275 m_view.render_guide->setEnabled(true);
276 m_view.create_chapter->setEnabled(true);
278 m_view.render_guide->setEnabled(false);
279 m_view.create_chapter->setEnabled(false);
281 double fps = (double) m_profile.frame_rate_num / m_profile.frame_rate_den;
282 for (int i = 0; i < nodes.count(); i++) {
283 QDomElement e = nodes.item(i).toElement();
285 GenTime pos = GenTime(e.attribute("time").toDouble());
286 const QString guidePos = Timecode::getStringTimecode(pos.frames(fps), fps);
287 m_view.guide_start->addItem(e.attribute("comment") + '/' + guidePos, e.attribute("time").toDouble());
288 m_view.guide_end->addItem(e.attribute("comment") + '/' + guidePos, e.attribute("time").toDouble());
291 if (nodes.count() > 0)
292 m_view.guide_end->addItem(i18n("End"), QString::number(duration));
296 * Will be called when the user selects an output file via the file dialog.
297 * File extension will be added automatically.
299 void RenderWidget::slotUpdateButtons(KUrl url)
301 if (m_view.out_file->url().isEmpty()) {
302 m_view.buttonGenerateScript->setEnabled(false);
303 m_view.buttonRender->setEnabled(false);
305 updateButtons(); // This also checks whether the selected format is available
308 QListWidgetItem *item = m_view.size_list->currentItem();
310 m_view.buttonRender->setEnabled(false);
311 m_view.buttonGenerateScript->setEnabled(false);
314 QString extension = item->data(ExtensionRole).toString();
315 url = filenameWithExtension(url, extension);
316 m_view.out_file->setUrl(url);
321 * Will be called when the user changes the output file path in the text line.
322 * File extension must NOT be added, would make editing impossible!
324 void RenderWidget::slotUpdateButtons()
326 if (m_view.out_file->url().isEmpty()) {
327 m_view.buttonRender->setEnabled(false);
328 m_view.buttonGenerateScript->setEnabled(false);
330 updateButtons(); // This also checks whether the selected format is available
334 void RenderWidget::slotSaveProfile()
336 //TODO: update to correctly use metagroups
337 Ui::SaveProfile_UI ui;
338 QDialog *d = new QDialog(this);
341 for (int i = 0; i < m_view.destination_list->count(); i++)
342 ui.destination_list->addItem(m_view.destination_list->itemIcon(i), m_view.destination_list->itemText(i), m_view.destination_list->itemData(i, Qt::UserRole));
344 ui.destination_list->setCurrentIndex(m_view.destination_list->currentIndex());
345 QString dest = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
347 QString customGroup = m_view.format_list->currentItem()->text();
348 if (customGroup.isEmpty()) customGroup = i18nc("Group Name", "Custom");
349 ui.group_name->setText(customGroup);
351 ui.parameters->setText(m_view.advanced_params->toPlainText());
352 ui.extension->setText(m_view.size_list->currentItem()->data(ExtensionRole).toString());
353 ui.profile_name->setFocus();
355 if (d->exec() == QDialog::Accepted && !ui.profile_name->text().simplified().isEmpty()) {
356 QString newProfileName = ui.profile_name->text().simplified();
357 QString newGroupName = ui.group_name->text().simplified();
358 if (newGroupName.isEmpty()) newGroupName = i18nc("Group Name", "Custom");
359 QString newMetaGroupId = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
362 QDomElement profileElement = doc.createElement("profile");
363 profileElement.setAttribute("name", newProfileName);
364 profileElement.setAttribute("category", newGroupName);
365 profileElement.setAttribute("destinationid", newMetaGroupId);
366 profileElement.setAttribute("extension", ui.extension->text().simplified());
367 profileElement.setAttribute("args", ui.parameters->toPlainText().simplified());
368 doc.appendChild(profileElement);
369 saveProfile(doc.documentElement());
371 parseProfiles(newMetaGroupId, newGroupName, newProfileName);
377 void RenderWidget::saveProfile(QDomElement newprofile)
379 QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
381 QFile file(exportFile);
382 doc.setContent(&file, false);
384 QDomElement documentElement;
385 QDomElement profiles = doc.documentElement();
386 if (profiles.isNull() || profiles.tagName() != "profiles") {
388 profiles = doc.createElement("profiles");
389 profiles.setAttribute("version", 1);
390 doc.appendChild(profiles);
392 int version = profiles.attribute("version", 0).toInt();
394 kDebug() << "// OLD profile version";
396 profiles = doc.createElement("profiles");
397 profiles.setAttribute("version", 1);
398 doc.appendChild(profiles);
402 QDomNodeList profilelist = doc.elementsByTagName("profile");
404 while (!profilelist.item(i).isNull()) {
405 // make sure a profile with same name doesn't exist
406 documentElement = profilelist.item(i).toElement();
407 QString profileName = documentElement.attribute("name");
408 if (profileName == newprofile.attribute("name")) {
409 // a profile with that same name already exists
411 QString 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, profileName, &ok);
413 if (profileName == newProfileName) {
414 profiles.removeChild(profilelist.item(i));
421 profiles.appendChild(newprofile);
423 //QCString save = doc.toString().utf8();
425 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
426 KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
429 QTextStream out(&file);
430 out << doc.toString();
431 if (file.error() != QFile::NoError) {
432 KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
439 void RenderWidget::slotCopyToFavorites()
441 QListWidgetItem *item = m_view.size_list->currentItem();
443 QString currentGroup = m_view.format_list->currentItem()->text();
445 QString params = item->data(ParamsRole).toString();
446 QString extension = item->data(ExtensionRole).toString();
447 QString currentProfile = item->text();
449 QDomElement profileElement = doc.createElement("profile");
450 profileElement.setAttribute("name", currentProfile);
451 profileElement.setAttribute("category", i18nc("Category Name", "Custom"));
452 profileElement.setAttribute("destinationid", "favorites");
453 profileElement.setAttribute("extension", extension);
454 profileElement.setAttribute("args", params);
455 doc.appendChild(profileElement);
456 saveProfile(doc.documentElement());
457 parseProfiles(m_view.destination_list->itemData(m_view.destination_list->currentIndex(), Qt::UserRole).toString(), currentGroup, currentProfile);
460 void RenderWidget::slotEditProfile()
462 QListWidgetItem *item = m_view.size_list->currentItem();
464 QString currentGroup = m_view.format_list->currentItem()->text();
466 QString params = item->data(ParamsRole).toString();
467 QString extension = item->data(ExtensionRole).toString();
468 QString currentProfile = item->text();
470 Ui::SaveProfile_UI ui;
471 QDialog *d = new QDialog(this);
474 for (int i = 0; i < m_view.destination_list->count(); i++)
475 ui.destination_list->addItem(m_view.destination_list->itemIcon(i), m_view.destination_list->itemText(i), m_view.destination_list->itemData(i, Qt::UserRole));
477 ui.destination_list->setCurrentIndex(m_view.destination_list->currentIndex());
478 QString dest = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
480 QString customGroup = m_view.format_list->currentItem()->text();
481 if (customGroup.isEmpty()) customGroup = i18nc("Group Name", "Custom");
482 ui.group_name->setText(customGroup);
484 ui.profile_name->setText(currentProfile);
485 ui.extension->setText(extension);
486 ui.parameters->setText(params);
487 ui.profile_name->setFocus();
488 d->setWindowTitle(i18n("Edit Profile"));
489 if (d->exec() == QDialog::Accepted) {
490 slotDeleteProfile(false);
491 QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
493 QFile file(exportFile);
494 doc.setContent(&file, false);
496 QDomElement documentElement;
497 QDomElement profiles = doc.documentElement();
499 if (profiles.isNull() || profiles.tagName() != "profiles") {
501 profiles = doc.createElement("profiles");
502 profiles.setAttribute("version", 1);
503 doc.appendChild(profiles);
506 int version = profiles.attribute("version", 0).toInt();
508 kDebug() << "// OLD profile version";
510 profiles = doc.createElement("profiles");
511 profiles.setAttribute("version", 1);
512 doc.appendChild(profiles);
515 QString newProfileName = ui.profile_name->text().simplified();
516 QString newGroupName = ui.group_name->text().simplified();
517 if (newGroupName.isEmpty()) newGroupName = i18nc("Group Name", "Custom");
518 QString newMetaGroupId = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
519 QDomNodeList profilelist = doc.elementsByTagName("profile");
521 while (!profilelist.item(i).isNull()) {
522 // make sure a profile with same name doesn't exist
523 documentElement = profilelist.item(i).toElement();
524 QString profileName = documentElement.attribute("name");
525 if (profileName == newProfileName) {
526 // a profile with that same name already exists
528 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);
530 if (profileName == newProfileName) {
531 profiles.removeChild(profilelist.item(i));
538 QDomElement profileElement = doc.createElement("profile");
539 profileElement.setAttribute("name", newProfileName);
540 profileElement.setAttribute("category", newGroupName);
541 profileElement.setAttribute("destinationid", newMetaGroupId);
542 profileElement.setAttribute("extension", ui.extension->text().simplified());
543 profileElement.setAttribute("args", ui.parameters->toPlainText().simplified());
544 profiles.appendChild(profileElement);
546 //QCString save = doc.toString().utf8();
548 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
549 KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
552 QTextStream out(&file);
553 out << doc.toString();
554 if (file.error() != QFile::NoError) {
555 KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
560 parseProfiles(newMetaGroupId, newGroupName, newProfileName);
564 void RenderWidget::slotDeleteProfile(bool refresh)
566 //TODO: delete a profile installed by KNewStuff the easy way
568 QString edit = m_view.size_list->currentItem()->data(EditableRole).toString();
569 if (!edit.endsWith("customprofiles.xml")) {
570 // This is a KNewStuff installed file, process through KNS
571 KNS::Engine engine(0);
572 if (engine.init("kdenlive_render.knsrc")) {
573 KNS::Entry::List entries;
577 QString currentGroup = m_view.format_list->currentItem()->text();
578 QString currentProfile = m_view.size_list->currentItem()->text();
579 QString metaGroupId = m_view.destination_list->itemData(m_view.destination_list->currentIndex(), Qt::UserRole).toString();
581 QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
583 QFile file(exportFile);
584 doc.setContent(&file, false);
587 QDomElement documentElement;
588 QDomNodeList profiles = doc.elementsByTagName("profile");
594 while (!profiles.item(i).isNull()) {
595 documentElement = profiles.item(i).toElement();
596 profileName = documentElement.attribute("name");
597 groupName = documentElement.attribute("category");
598 destination = documentElement.attribute("destinationid");
600 if (profileName == currentProfile && groupName == currentGroup && destination == metaGroupId) {
601 kDebug() << "// GOT it: " << profileName;
602 doc.documentElement().removeChild(profiles.item(i));
608 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
609 KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
612 QTextStream out(&file);
613 out << doc.toString();
614 if (file.error() != QFile::NoError) {
615 KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
621 parseProfiles(metaGroupId, currentGroup);
622 focusFirstVisibleItem();
626 void RenderWidget::updateButtons()
628 if (!m_view.size_list->currentItem() || m_view.size_list->currentItem()->isHidden()) {
629 m_view.buttonSave->setEnabled(false);
630 m_view.buttonDelete->setEnabled(false);
631 m_view.buttonEdit->setEnabled(false);
632 m_view.buttonRender->setEnabled(false);
633 m_view.buttonGenerateScript->setEnabled(false);
635 m_view.buttonSave->setEnabled(true);
636 m_view.buttonRender->setEnabled(m_view.size_list->currentItem()->toolTip().isEmpty());
637 m_view.buttonGenerateScript->setEnabled(m_view.size_list->currentItem()->toolTip().isEmpty());
638 QString edit = m_view.size_list->currentItem()->data(EditableRole).toString();
639 if (edit.isEmpty() || !edit.endsWith("customprofiles.xml")) {
640 m_view.buttonDelete->setEnabled(false);
641 m_view.buttonEdit->setEnabled(false);
643 m_view.buttonDelete->setEnabled(true);
644 m_view.buttonEdit->setEnabled(true);
650 void RenderWidget::focusFirstVisibleItem()
652 if (m_view.size_list->currentItem()) {
656 m_view.size_list->setCurrentRow(0);
660 void RenderWidget::slotPrepareExport(bool scriptExport)
662 if (!QFile::exists(KdenliveSettings::rendererpath())) {
663 KMessageBox::sorry(this, i18n("Cannot find the melt program required for rendering (part of Mlt)"));
666 if (m_view.play_after->isChecked() && KdenliveSettings::defaultplayerapp().isEmpty()) {
667 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."));
670 if (m_view.create_chapter->isChecked()) chapterFile = m_view.out_file->url().path() + ".dvdchapter";
673 if (!KStandardDirs::makeDir(m_view.out_file->url().directory())) {
674 KMessageBox::sorry(this, i18n("The directory %1, could not be created.\nPlease make sure you have the required permissions.", m_view.out_file->url().directory()));
678 emit prepareRenderingData(scriptExport, m_view.render_zone->isChecked(), chapterFile);
682 void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const QString &playlistPath, const QString &scriptPath, bool exportAudio)
684 QListWidgetItem *item = m_view.size_list->currentItem();
687 QString dest = m_view.out_file->url().path();
688 if (dest.isEmpty()) return;
690 // Check whether target file has an extension.
691 // If not, ask whether extension should be added or not.
692 QString extension = item->data(ExtensionRole).toString();
693 if (!dest.endsWith(extension, Qt::CaseInsensitive)) {
694 if (KMessageBox::questionYesNo(this, i18n("File has no extension. Add extension (%1)?", extension)) == KMessageBox::Yes) {
695 dest.append("." + extension);
701 if (KMessageBox::warningYesNo(this, i18n("Output file already exists. Do you want to overwrite it?")) != KMessageBox::Yes)
705 QStringList overlayargs;
706 if (m_view.tc_overlay->isChecked()) {
707 QString filterFile = KStandardDirs::locate("appdata", "metadata.properties");
708 overlayargs << "meta.attr.timecode=1" << "meta.attr.timecode.markup=#timecode";
709 overlayargs << "-attach" << "data_feed:attr_check" << "-attach";
710 overlayargs << "data_show:" + filterFile << "_loader=1" << "dynamic=1";
713 QStringList render_process_args;
715 if (!scriptExport) render_process_args << "-erase";
716 if (KdenliveSettings::usekuiserver()) render_process_args << "-kuiserver";
718 double guideStart = 0;
721 if (m_view.render_zone->isChecked()) render_process_args << "in=" + QString::number(zoneIn) << "out=" + QString::number(zoneOut);
722 else if (m_view.render_guide->isChecked()) {
723 double fps = (double) m_profile.frame_rate_num / m_profile.frame_rate_den;
724 guideStart = m_view.guide_start->itemData(m_view.guide_start->currentIndex()).toDouble();
725 guideEnd = m_view.guide_end->itemData(m_view.guide_end->currentIndex()).toDouble();
726 render_process_args << "in=" + QString::number(GenTime(guideStart).frames(fps)) << "out=" + QString::number(GenTime(guideEnd).frames(fps));
729 if (!overlayargs.isEmpty()) render_process_args << "preargs=" + overlayargs.join(" ");
731 render_process_args << KdenliveSettings::rendererpath() << m_profile.path << item->data(RenderRole).toString();
732 if (m_view.play_after->isChecked()) render_process_args << KdenliveSettings::KdenliveSettings::defaultplayerapp();
733 else render_process_args << "-";
735 QString renderArgs = m_view.advanced_params->toPlainText().simplified();
737 // Adjust frame scale
740 if (m_view.rescale->isChecked() && m_view.rescale->isEnabled()) {
741 width = m_view.rescale_width->value();
742 height = m_view.rescale_height->value();
744 width = m_profile.width;
745 height = m_profile.height;
747 renderArgs.replace("%dar", '@' + QString::number(m_profile.display_aspect_num) + '/' + QString::number(m_profile.display_aspect_den));
750 if (m_view.scanning_list->currentIndex() == 1) renderArgs.append(" progressive=1");
751 else if (m_view.scanning_list->currentIndex() == 2) renderArgs.append(" progressive=0");
753 // disable audio if requested
754 if (!exportAudio) renderArgs.append(" an=1 ");
756 // Check if the rendering profile is different from project profile,
757 // in which case we need to use the producer_comsumer from MLT
758 QString std = renderArgs;
759 QString destination = m_view.destination_list->itemData(m_view.destination_list->currentIndex()).toString();
760 const QString currentSize = QString::number(width) + 'x' + QString::number(height);
761 QString subsize = currentSize;
762 if (std.startsWith("s=")) {
763 subsize = std.section(' ', 0, 0).toLower();
764 subsize = subsize.section('=', 1, 1);
765 } else if (std.contains(" s=")) {
766 subsize = std.section(" s=", 1, 1);
767 subsize = subsize.section(' ', 0, 0).toLower();
768 } else if (destination != "audioonly" && m_view.rescale->isChecked() && m_view.rescale->isEnabled()) {
769 subsize = QString(" s=%1x%2").arg(width).arg(height);
770 // Add current size parameter
771 renderArgs.append(subsize);
773 bool resizeProfile = (subsize != currentSize);
774 QStringList paramsList = renderArgs.split(" ", QString::SkipEmptyParts);
775 for (int i = 0; i < paramsList.count(); i++) {
776 if (paramsList.at(i).startsWith("profile=")) {
777 if (paramsList.at(i).section('=', 1) != m_profile.path) resizeProfile = true;
783 render_process_args << "consumer:" + (scriptExport ? "$SOURCE" : playlistPath);
785 render_process_args << (scriptExport ? "$SOURCE" : playlistPath);
786 render_process_args << (scriptExport ? "$TARGET" : dest);
787 render_process_args << paramsList;
789 QString group = m_view.size_list->currentItem()->data(MetaGroupRole).toString();
791 QStringList renderParameters;
792 renderParameters << dest << item->data(RenderRole).toString() << renderArgs.simplified();
793 renderParameters << QString::number(zoneIn) << QString::number(zoneOut) << QString::number(m_view.play_after->isChecked());
794 renderParameters << QString::number(guideStart) << QString::number(guideEnd) << QString::number(resizeProfile);
798 // Generate script file
799 QFile file(scriptPath);
800 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
801 KMessageBox::error(this, i18n("Cannot write to file %1", scriptPath));
804 QTextStream outStream(&file);
805 outStream << "#! /bin/sh" << "\n" << "\n";
806 outStream << "SOURCE=" << "\"" + playlistPath + "\"" << "\n";
807 outStream << "TARGET=" << "\"" + dest + "\"" << "\n";
808 outStream << "RENDERER=" << "\"" + m_renderer + "\"" << "\n";
809 outStream << "MELT=" << "\"" + render_process_args.takeFirst() + "\"" << "\n";
810 outStream << "PARAMETERS=" << "\"" + render_process_args.join(" ") + "\"" << "\n";
811 outStream << "$RENDERER $MELT $PARAMETERS" << "\n" << "\n";
812 if (file.error() != QFile::NoError) {
813 KMessageBox::error(this, i18n("Cannot write to file %1", scriptPath));
818 QFile::setPermissions(scriptPath, file.permissions() | QFile::ExeUser);
820 QTimer::singleShot(400, this, SLOT(parseScriptFiles()));
821 m_view.tabWidget->setCurrentIndex(2);
824 renderParameters << scriptName;
826 // Save rendering profile to document
827 QMap <QString, QString> renderProps;
828 renderProps.insert("renderdestination", m_view.size_list->currentItem()->data(MetaGroupRole).toString());
829 renderProps.insert("rendercategory", m_view.size_list->currentItem()->data(GroupRole).toString());
830 renderProps.insert("renderprofile", m_view.size_list->currentItem()->text());
831 renderProps.insert("renderurl", dest);
832 renderProps.insert("renderzone", QString::number(m_view.render_zone->isChecked()));
833 renderProps.insert("renderguide", QString::number(m_view.render_guide->isChecked()));
834 renderProps.insert("renderstartguide", QString::number(m_view.guide_start->currentIndex()));
835 renderProps.insert("renderendguide", QString::number(m_view.guide_end->currentIndex()));
836 renderProps.insert("renderendguide", QString::number(m_view.guide_end->currentIndex()));
837 renderProps.insert("renderscanning", QString::number(m_view.scanning_list->currentIndex()));
838 int export_audio = 0;
839 if (m_view.export_audio->checkState() == Qt::Checked) export_audio = 2;
840 else if (m_view.export_audio->checkState() == Qt::Unchecked) export_audio = 1;
841 renderProps.insert("renderexportaudio", QString::number(export_audio));
842 renderProps.insert("renderrescale", QString::number(m_view.rescale->isChecked()));
843 renderProps.insert("renderrescalewidth", QString::number(m_view.rescale_width->value()));
844 renderProps.insert("renderrescaleheight", QString::number(m_view.rescale_height->value()));
845 renderProps.insert("rendertcoverlay", QString::number(m_view.tc_overlay->isChecked()));
846 renderProps.insert("renderratio", QString::number(m_view.rescale_keep->isChecked()));
847 renderProps.insert("renderplay", QString::number(m_view.play_after->isChecked()));
849 emit selectedRenderProfile(renderProps);
851 // insert item in running jobs list
852 QTreeWidgetItem *renderItem;
853 QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(dest, Qt::MatchExactly, 1);
854 if (!existing.isEmpty()) {
855 renderItem = existing.at(0);
856 if (renderItem->data(1, Qt::UserRole + 2).toInt() == RUNNINGJOB) {
857 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"));
860 renderItem->setData(1, Qt::UserRole + 4, QString());
862 renderItem = new QTreeWidgetItem(m_view.running_jobs, QStringList() << QString() << dest << QString());
864 renderItem->setData(1, Qt::UserRole + 2, WAITINGJOB);
865 renderItem->setIcon(0, KIcon("media-playback-pause"));
866 renderItem->setData(1, Qt::UserRole, i18n("Waiting..."));
867 renderItem->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
868 renderItem->setData(1, Qt::UserRole + 1, QTime::currentTime());
870 // Set rendering type
871 if (group == "dvd") {
872 if (m_view.open_dvd->isChecked()) {
873 renderItem->setData(0, Qt::UserRole, group);
874 if (renderArgs.contains("profile=")) {
875 // rendering profile contains an MLT profile, so pass it to the running jog item, useful for dvd
876 QString prof = renderArgs.section("profile=", 1, 1);
877 prof = prof.section(' ', 0, 0);
878 kDebug() << "// render profile: " << prof;
879 renderItem->setData(0, Qt::UserRole + 1, prof);
883 if (group == "websites" && m_view.open_browser->isChecked()) {
884 renderItem->setData(0, Qt::UserRole, group);
886 QString url = m_view.size_list->currentItem()->data(ExtraRole).toString();
887 renderItem->setData(0, Qt::UserRole + 1, url);
890 renderItem->setData(1, Qt::UserRole + 3, render_process_args);
891 if (exportAudio == false) renderItem->setData(1, Qt::UserRole + 5, i18n("Video without audio track"));
892 else renderItem->setData(1, Qt::UserRole + 5, QString());
893 m_view.running_jobs->setCurrentItem(renderItem);
894 m_view.tabWidget->setCurrentIndex(1);
898 void RenderWidget::checkRenderStatus()
900 // check if we have a job waiting to render
901 if (m_blockProcessing) return;
902 QTreeWidgetItem *item = m_view.running_jobs->topLevelItem(0);
904 if (item->data(1, Qt::UserRole + 2).toInt() == RUNNINGJOB) return;
905 item = m_view.running_jobs->itemBelow(item);
907 item = m_view.running_jobs->topLevelItem(0);
908 bool waitingJob = false;
910 if (item->data(1, Qt::UserRole + 2).toInt() == WAITINGJOB) {
911 item->setData(1, Qt::UserRole + 1, QTime::currentTime());
913 startRendering(item);
916 item = m_view.running_jobs->itemBelow(item);
918 if (waitingJob == false && m_view.shutdown->isChecked()) emit shutdown();
921 void RenderWidget::startRendering(QTreeWidgetItem *item)
923 if (item->data(1, Qt::UserRole + 4).isNull()) {
924 // Normal render process
925 if (QProcess::startDetached(m_renderer, item->data(1, Qt::UserRole + 3).toStringList()) == false) {
926 item->setData(1, Qt::UserRole + 2, FINISHEDJOB);
927 item->setData(1, Qt::UserRole, i18n("Rendering crashed"));
928 item->setIcon(0, KIcon("dialog-close"));
929 item->setData(2, Qt::UserRole, 100);
930 } else KNotification::event("RenderStarted", i18n("Rendering <i>%1</i> started", item->text(1)), QPixmap(), this);
933 if (QProcess::startDetached(item->data(1, Qt::UserRole + 3).toString()) == false) {
934 item->setData(1, Qt::UserRole + 2, FINISHEDJOB);
935 item->setData(1, Qt::UserRole, i18n("Rendering crashed"));
936 item->setIcon(0, KIcon("dialog-close"));
937 item->setData(2, Qt::UserRole, 100);
942 int RenderWidget::waitingJobsCount() const
945 QTreeWidgetItem *item = m_view.running_jobs->topLevelItem(0);
947 if (item->data(1, Qt::UserRole + 2).toInt() == WAITINGJOB) count++;
948 item = m_view.running_jobs->itemBelow(item);
953 void RenderWidget::setProfile(MltVideoProfile profile)
956 //WARNING: this way to tell the video standard is a bit hackish...
957 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);
958 else m_view.format_selection->setCurrentIndex(1);
959 m_view.scanning_list->setCurrentIndex(0);
960 m_view.rescale_width->setValue(KdenliveSettings::defaultrescalewidth());
961 if (!m_view.rescale_keep->isChecked()) {
962 m_view.rescale_height->blockSignals(true);
963 m_view.rescale_height->setValue(KdenliveSettings::defaultrescaleheight());
964 m_view.rescale_height->blockSignals(false);
969 void RenderWidget::refreshCategory()
971 m_view.format_list->blockSignals(true);
972 m_view.format_list->clear();
973 QListWidgetItem *sizeItem;
976 if (m_view.destination_list->currentIndex() > 0)
977 destination = m_view.destination_list->itemData(m_view.destination_list->currentIndex()).toString();
980 if (destination == "dvd") {
981 m_view.open_dvd->setVisible(true);
982 m_view.create_chapter->setVisible(true);
984 m_view.open_dvd->setVisible(false);
985 m_view.create_chapter->setVisible(false);
988 if (destination == "websites")
989 m_view.open_browser->setVisible(true);
991 m_view.open_browser->setVisible(false);
993 // hide groups that are not in the correct destination
994 for (int i = 0; i < m_renderCategory.count(); i++) {
995 sizeItem = m_renderCategory.at(i);
996 if (sizeItem->data(MetaGroupRole).toString() == destination) {
997 m_view.format_list->addItem(sizeItem->clone());
998 //kDebug() << "// SET GRP:: " << sizeItem->text() << ", METY:" << sizeItem->data(MetaGroupRole).toString();
1002 // activate first visible item
1003 QListWidgetItem * item = m_view.format_list->currentItem();
1005 m_view.format_list->setCurrentRow(0);
1006 item = m_view.format_list->currentItem();
1009 m_view.format_list->setEnabled(false);
1010 m_view.size_list->setEnabled(false);
1011 m_view.size_list->blockSignals(false);
1012 m_view.format_list->blockSignals(false);
1015 m_view.format_list->setEnabled(true);
1016 m_view.size_list->setEnabled(true);
1019 if (m_view.format_list->count() > 1)
1020 m_view.format_list->setVisible(true);
1022 m_view.format_list->setVisible(false);
1026 void RenderWidget::refreshView()
1028 if (!m_view.format_list->currentItem()) return;
1029 m_view.size_list->blockSignals(true);
1030 m_view.size_list->clear();
1031 QListWidgetItem *sizeItem;
1033 QString group = m_view.format_list->currentItem()->text();
1034 QString destination;
1035 if (m_view.destination_list->currentIndex() > 0)
1036 destination = m_view.destination_list->itemData(m_view.destination_list->currentIndex()).toString();
1037 KIcon brokenIcon("dialog-close");
1039 const QStringList formatsList = KdenliveSettings::supportedformats();
1040 const QStringList vcodecsList = KdenliveSettings::videocodecs();
1041 const QStringList acodecsList = KdenliveSettings::audiocodecs();
1043 KColorScheme scheme(palette().currentColorGroup(), KColorScheme::Window);
1044 const QColor disabled = scheme.foreground(KColorScheme::InactiveText).color();
1045 const QColor disabledbg = scheme.background(KColorScheme::NegativeBackground).color();
1048 for (int i = 0; i < m_renderItems.count(); i++) {
1049 sizeItem = m_renderItems.at(i);
1050 QListWidgetItem *dupItem = NULL;
1051 if ((sizeItem->data(GroupRole).toString() == group || sizeItem->data(GroupRole).toString().isEmpty()) && sizeItem->data(MetaGroupRole).toString() == destination) {
1052 std = sizeItem->data(StandardRole).toString();
1053 if (!std.isEmpty()) {
1054 if (std.contains("PAL", Qt::CaseInsensitive) && m_view.format_selection->currentIndex() == 0) dupItem = sizeItem->clone();
1055 else if (std.contains("NTSC", Qt::CaseInsensitive) && m_view.format_selection->currentIndex() == 1) dupItem = sizeItem->clone();
1057 dupItem = sizeItem->clone();
1061 m_view.size_list->addItem(dupItem);
1062 // Make sure the selected profile uses an installed avformat codec / format
1063 std = dupItem->data(ParamsRole).toString();
1064 if (!formatsList.isEmpty()) {
1066 if (std.startsWith("f=")) format = std.section("f=", 1, 1);
1067 else if (std.contains(" f=")) format = std.section(" f=", 1, 1);
1068 if (!format.isEmpty()) {
1069 format = format.section(' ', 0, 0).toLower();
1070 if (!formatsList.contains(format)) {
1071 kDebug() << "***** UNSUPPORTED F: " << format;
1072 //sizeItem->setHidden(true);
1073 //sizeItem->setFlags(Qt::ItemIsSelectable);
1074 dupItem->setToolTip(i18n("Unsupported video format: %1", format));
1075 dupItem->setIcon(brokenIcon);
1076 dupItem->setForeground(disabled);
1080 if (!acodecsList.isEmpty()) {
1082 if (std.startsWith("acodec=")) format = std.section("acodec=", 1, 1);
1083 else if (std.contains(" acodec=")) format = std.section(" acodec=", 1, 1);
1084 if (!format.isEmpty()) {
1085 format = format.section(' ', 0, 0).toLower();
1086 if (!acodecsList.contains(format)) {
1087 kDebug() << "***** UNSUPPORTED ACODEC: " << format;
1088 //sizeItem->setHidden(true);
1089 //sizeItem->setFlags(Qt::ItemIsSelectable);
1090 dupItem->setToolTip(i18n("Unsupported audio codec: %1", format));
1091 dupItem->setIcon(brokenIcon);
1092 dupItem->setForeground(disabled);
1093 dupItem->setBackground(disabledbg);
1097 if (!vcodecsList.isEmpty()) {
1099 if (std.startsWith("vcodec=")) format = std.section("vcodec=", 1, 1);
1100 else if (std.contains(" vcodec=")) format = std.section(" vcodec=", 1, 1);
1101 if (!format.isEmpty()) {
1102 format = format.section(' ', 0, 0).toLower();
1103 if (!vcodecsList.contains(format)) {
1104 kDebug() << "***** UNSUPPORTED VCODEC: " << format;
1105 //sizeItem->setHidden(true);
1106 //sizeItem->setFlags(Qt::ItemIsSelectable);
1107 dupItem->setToolTip(i18n("Unsupported video codec: %1", format));
1108 dupItem->setIcon(brokenIcon);
1109 dupItem->setForeground(disabled);
1116 // m_view.size_list->sortItems();
1117 focusFirstVisibleItem();
1118 m_view.size_list->blockSignals(false);
1119 m_view.format_list->blockSignals(false);
1123 KUrl RenderWidget::filenameWithExtension(KUrl url, QString extension)
1125 if (url.isEmpty()) url = KUrl(m_projectFolder);
1126 QString directory = url.directory(KUrl::AppendTrailingSlash | KUrl::ObeyTrailingSlash);
1127 QString filename = url.fileName(KUrl::ObeyTrailingSlash);
1130 if (extension.at(0) == '.') ext = extension;
1131 else ext = '.' + extension;
1133 if (filename.isEmpty()) filename = i18n("untitled");
1135 int pos = filename.lastIndexOf('.');
1136 if (pos == 0) filename.append(ext);
1138 if (!filename.endsWith(ext, Qt::CaseInsensitive)) {
1139 filename = filename.left(pos) + ext;
1143 return KUrl(directory + filename);
1146 void RenderWidget::refreshParams()
1148 // Format not available (e.g. codec not installed); Disable start button
1149 QListWidgetItem *item = m_view.size_list->currentItem();
1150 if (!item || item->isHidden()) {
1151 m_view.advanced_params->clear();
1152 m_view.buttonRender->setEnabled(false);
1153 m_view.buttonGenerateScript->setEnabled(false);
1156 QString params = item->data(ParamsRole).toString();
1157 QString extension = item->data(ExtensionRole).toString();
1158 m_view.advanced_params->setPlainText(params);
1159 QString destination = m_view.destination_list->itemData(m_view.destination_list->currentIndex()).toString();
1160 if (params.contains(" s=") || params.startsWith("s=") || destination == "audioonly") {
1161 // profile has a fixed size, do not allow resize
1162 m_view.rescale->setEnabled(false);
1163 m_view.rescale_box->setEnabled(false);
1165 m_view.rescale->setEnabled(true);
1166 m_view.rescale_box->setEnabled(m_view.rescale->isChecked());
1168 KUrl url = filenameWithExtension(m_view.out_file->url(), extension);
1169 m_view.out_file->setUrl(url);
1170 // if (!url.isEmpty()) {
1171 // QString path = url.path();
1172 // int pos = path.lastIndexOf('.') + 1;
1173 // if (pos == 0) path.append('.' + extension);
1174 // else path = path.left(pos) + extension;
1175 // m_view.out_file->setUrl(KUrl(path));
1177 // m_view.out_file->setUrl(KUrl(QDir::homePath() + "/untitled." + extension));
1179 m_view.out_file->setFilter("*." + extension);
1180 QString edit = item->data(EditableRole).toString();
1181 if (edit.isEmpty() || !edit.endsWith("customprofiles.xml")) {
1182 m_view.buttonDelete->setEnabled(false);
1183 m_view.buttonEdit->setEnabled(false);
1185 m_view.buttonDelete->setEnabled(true);
1186 m_view.buttonEdit->setEnabled(true);
1189 m_view.buttonRender->setEnabled(m_view.size_list->currentItem()->toolTip().isEmpty());
1190 m_view.buttonGenerateScript->setEnabled(m_view.size_list->currentItem()->toolTip().isEmpty());
1193 void RenderWidget::reloadProfiles()
1198 void RenderWidget::parseProfiles(QString meta, QString group, QString profile)
1200 m_view.size_list->blockSignals(true);
1201 m_view.format_list->blockSignals(true);
1202 m_view.size_list->clear();
1203 m_view.format_list->clear();
1204 m_view.destination_list->clear();
1205 qDeleteAll(m_renderItems);
1206 qDeleteAll(m_renderCategory);
1207 m_renderItems.clear();
1208 m_renderCategory.clear();
1209 m_view.destination_list->addItem(KIcon("video-x-generic"), i18n("File rendering"));
1210 m_view.destination_list->addItem(KIcon("favorites"), i18n("Favorites"), "favorites");
1211 m_view.destination_list->addItem(KIcon("media-optical"), i18n("DVD"), "dvd");
1212 m_view.destination_list->addItem(KIcon("audio-x-generic"), i18n("Audio only"), "audioonly");
1213 m_view.destination_list->addItem(KIcon("applications-internet"), i18n("Web sites"), "websites");
1214 m_view.destination_list->addItem(KIcon("applications-multimedia"), i18n("Media players"), "mediaplayers");
1215 m_view.destination_list->addItem(KIcon("drive-harddisk"), i18n("Lossless / HQ"), "lossless");
1216 m_view.destination_list->addItem(KIcon("pda"), i18n("Mobile devices"), "mobile");
1218 QString exportFile = KStandardDirs::locate("appdata", "export/profiles.xml");
1219 parseFile(exportFile, false);
1222 QString exportFolder = KStandardDirs::locateLocal("appdata", "export/");
1223 QDir directory = QDir(exportFolder);
1226 QStringList fileList = directory.entryList(filter, QDir::Files);
1227 // We should parse customprofiles.xml in last position, so that user profiles
1228 // can also override profiles installed by KNewStuff
1229 fileList.removeAll("customprofiles.xml");
1230 foreach(const QString &filename, fileList)
1231 parseFile(exportFolder + filename, true);
1232 if (QFile::exists(exportFolder + "customprofiles.xml")) parseFile(exportFolder + "customprofiles.xml", true);
1234 if (!meta.isEmpty()) {
1235 m_view.destination_list->blockSignals(true);
1236 m_view.destination_list->setCurrentIndex(m_view.destination_list->findData(meta));
1237 m_view.destination_list->blockSignals(false);
1240 QList<QListWidgetItem *> child;
1241 if (!group.isEmpty()) child = m_view.format_list->findItems(group, Qt::MatchExactly);
1242 if (!child.isEmpty()) {
1243 for (int i = 0; i < child.count(); i++) {
1244 if (child.at(i)->data(MetaGroupRole).toString() == meta) {
1245 m_view.format_list->setCurrentItem(child.at(i));
1251 m_view.size_list->blockSignals(false);
1252 m_view.format_list->blockSignals(false);
1253 if (!profile.isEmpty()) child = m_view.size_list->findItems(profile, Qt::MatchExactly);
1254 if (!child.isEmpty()) m_view.size_list->setCurrentItem(child.at(0));
1257 void RenderWidget::parseFile(QString exportFile, bool editable)
1259 kDebug() << "// Parsing file: " << exportFile;
1260 kDebug() << "------------------------------";
1262 QFile file(exportFile);
1263 doc.setContent(&file, false);
1265 QDomElement documentElement;
1266 QDomElement profileElement;
1268 QDomNodeList groups = doc.elementsByTagName("group");
1269 QListWidgetItem *item = NULL;
1270 const QStringList acodecsList = KdenliveSettings::audiocodecs();
1271 bool replaceVorbisCodec = false;
1272 if (acodecsList.contains("libvorbis")) replaceVorbisCodec = true;
1273 bool replaceLibfaacCodec = false;
1274 if (!acodecsList.contains("aac") && acodecsList.contains("libfaac")) replaceLibfaacCodec = true;
1277 if (editable || groups.count() == 0) {
1278 QDomElement profiles = doc.documentElement();
1279 if (editable && profiles.attribute("version", 0).toInt() < 1) {
1280 kDebug() << "// OLD profile version";
1281 // this is an old profile version, update it
1282 QDomDocument newdoc;
1283 QDomElement newprofiles = newdoc.createElement("profiles");
1284 newprofiles.setAttribute("version", 1);
1285 newdoc.appendChild(newprofiles);
1286 QDomNodeList profilelist = doc.elementsByTagName("profile");
1287 for (int i = 0; i < profilelist.count(); i++) {
1288 QString category = i18nc("Category Name", "Custom");
1290 QDomNode parent = profilelist.at(i).parentNode();
1291 if (!parent.isNull()) {
1292 QDomElement parentNode = parent.toElement();
1293 if (parentNode.hasAttribute("name")) category = parentNode.attribute("name");
1294 extension = parentNode.attribute("extension");
1296 profilelist.at(i).toElement().setAttribute("category", category);
1297 if (!extension.isEmpty()) profilelist.at(i).toElement().setAttribute("extension", extension);
1298 QDomNode n = profilelist.at(i).cloneNode();
1299 newprofiles.appendChild(newdoc.importNode(n, true));
1301 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1302 KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
1305 QTextStream out(&file);
1306 out << newdoc.toString();
1308 parseFile(exportFile, editable);
1312 QDomNode node = doc.elementsByTagName("profile").at(0);
1313 if (node.isNull()) {
1314 kDebug() << "// Export file: " << exportFile << " IS BROKEN";
1318 while (!node.isNull()) {
1319 QDomElement profile = node.toElement();
1320 QString profileName = profile.attribute("name");
1321 QString standard = profile.attribute("standard");
1322 QString params = profile.attribute("args");
1324 if (replaceVorbisCodec && params.contains("acodec=vorbis")) {
1325 // replace vorbis with libvorbis
1326 params = params.replace("vorbis", "libvorbis");
1328 if (replaceLibfaacCodec && params.contains("acodec=aac")) {
1329 // replace libfaac with aac
1330 params = params.replace("aac", "libfaac");
1333 QString category = profile.attribute("category", i18nc("Category Name", "Custom"));
1334 QString dest = profile.attribute("destinationid");
1335 QString prof_extension = profile.attribute("extension");
1336 if (!prof_extension.isEmpty()) extension = prof_extension;
1337 bool exists = false;
1338 for (int j = 0; j < m_renderCategory.count(); j++) {
1339 if (m_renderCategory.at(j)->text() == category && m_renderCategory.at(j)->data(MetaGroupRole) == dest) {
1346 QListWidgetItem *itemcat = new QListWidgetItem(category);
1347 itemcat->setData(MetaGroupRole, dest);
1348 m_renderCategory.append(itemcat);
1351 // Check if item with same name already exists and replace it,
1352 // allowing to override default profiles
1355 for (int j = 0; j < m_renderItems.count(); j++) {
1356 if (m_renderItems.at(j)->text() == profileName && m_renderItems.at(j)->data(MetaGroupRole) == dest) {
1357 QListWidgetItem *duplicate = m_renderItems.takeAt(j);
1363 item = new QListWidgetItem(profileName); // , m_view.size_list
1364 //kDebug() << "// ADDINg item with name: " << profileName << ", GRP" << category << ", DEST:" << dest ;
1365 item->setData(GroupRole, category);
1366 item->setData(MetaGroupRole, dest);
1367 item->setData(ExtensionRole, extension);
1368 item->setData(RenderRole, "avformat");
1369 item->setData(StandardRole, standard);
1370 item->setData(ParamsRole, params);
1371 if (profile.hasAttribute("url")) item->setData(ExtraRole, profile.attribute("url"));
1373 item->setData(EditableRole, exportFile);
1374 if (exportFile.endsWith("customprofiles.xml")) item->setIcon(KIcon("emblem-favorite"));
1375 else item->setIcon(KIcon("applications-internet"));
1377 m_renderItems.append(item);
1378 node = doc.elementsByTagName("profile").at(count);
1386 QString profileName;
1388 QString prof_extension;
1394 while (!groups.item(i).isNull()) {
1395 documentElement = groups.item(i).toElement();
1396 QDomNode gname = documentElement.elementsByTagName("groupname").at(0);
1397 QString metagroupName;
1398 QString metagroupId;
1399 if (!gname.isNull()) {
1400 metagroupName = gname.firstChild().nodeValue();
1401 metagroupId = gname.toElement().attribute("id");
1403 if (!metagroupName.isEmpty() && m_view.destination_list->findData(metagroupId) == -1) {
1404 if (metagroupId == "dvd") icon = KIcon("media-optical");
1405 else if (metagroupId == "audioonly") icon = KIcon("audio-x-generic");
1406 else if (metagroupId == "websites") icon = KIcon("applications-internet");
1407 else if (metagroupId == "mediaplayers") icon = KIcon("applications-multimedia");
1408 else if (metagroupId == "lossless") icon = KIcon("drive-harddisk");
1409 else if (metagroupId == "mobile") icon = KIcon("pda");
1410 m_view.destination_list->addItem(icon, i18n(metagroupName.toUtf8().data()), metagroupId);
1413 groupName = documentElement.attribute("name", i18nc("Attribute Name", "Custom"));
1414 extension = documentElement.attribute("extension", QString());
1415 renderer = documentElement.attribute("renderer", QString());
1416 bool exists = false;
1417 for (int j = 0; j < m_renderCategory.count(); j++) {
1418 if (m_renderCategory.at(j)->text() == groupName && m_renderCategory.at(j)->data(MetaGroupRole) == metagroupId) {
1424 QListWidgetItem *itemcat = new QListWidgetItem(groupName); //, m_view.format_list);
1425 itemcat->setData(MetaGroupRole, metagroupId);
1426 m_renderCategory.append(itemcat);
1429 QDomNode n = groups.item(i).firstChild();
1430 while (!n.isNull()) {
1431 if (n.toElement().tagName() != "profile") {
1432 n = n.nextSibling();
1435 profileElement = n.toElement();
1436 profileName = profileElement.attribute("name");
1437 standard = profileElement.attribute("standard");
1438 params = profileElement.attribute("args");
1440 if (replaceVorbisCodec && params.contains("acodec=vorbis")) {
1441 // replace vorbis with libvorbis
1442 params = params.replace("vorbis", "libvorbis");
1444 if (replaceLibfaacCodec && params.contains("acodec=aac")) {
1445 // replace libfaac with aac
1446 params = params.replace("aac", "libfaac");
1449 prof_extension = profileElement.attribute("extension");
1450 if (!prof_extension.isEmpty()) extension = prof_extension;
1451 item = new QListWidgetItem(profileName); //, m_view.size_list);
1452 item->setData(GroupRole, groupName);
1453 item->setData(MetaGroupRole, metagroupId);
1454 item->setData(ExtensionRole, extension);
1455 item->setData(RenderRole, renderer);
1456 item->setData(StandardRole, standard);
1457 item->setData(ParamsRole, params);
1458 if (profileElement.hasAttribute("url")) item->setData(ExtraRole, profileElement.attribute("url"));
1459 if (editable) item->setData(EditableRole, exportFile);
1460 m_renderItems.append(item);
1461 n = n.nextSibling();
1468 void RenderWidget::setRenderJob(const QString &dest, int progress)
1470 QTreeWidgetItem *item;
1471 QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(dest, Qt::MatchExactly, 1);
1472 if (!existing.isEmpty()) item = existing.at(0);
1474 item = new QTreeWidgetItem(m_view.running_jobs, QStringList() << QString() << dest << QString());
1475 item->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
1476 if (progress == 0) {
1477 item->setData(1, Qt::UserRole + 2, WAITINGJOB);
1478 item->setIcon(0, KIcon("media-playback-pause"));
1479 item->setData(1, Qt::UserRole, i18n("Waiting..."));
1482 item->setData(2, Qt::UserRole, progress);
1483 item->setData(1, Qt::UserRole + 2, RUNNINGJOB);
1484 if (progress == 0) {
1485 item->setIcon(0, KIcon("system-run"));
1486 item->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
1487 item->setData(1, Qt::UserRole + 1, QTime::currentTime());
1490 QTime startTime = item->data(1, Qt::UserRole + 1).toTime();
1491 int seconds = startTime.secsTo(QTime::currentTime());;
1492 const QString t = i18n("Estimated time %1", QTime().addSecs(seconds * (100 - progress) / progress).toString("hh:mm:ss"));
1493 item->setData(1, Qt::UserRole, t);
1497 void RenderWidget::setRenderStatus(const QString &dest, int status, const QString &error)
1499 QTreeWidgetItem *item;
1500 QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(dest, Qt::MatchExactly, 1);
1501 if (!existing.isEmpty()) item = existing.at(0);
1503 item = new QTreeWidgetItem(m_view.running_jobs, QStringList() << QString() << dest << QString());
1504 item->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
1506 item->setData(1, Qt::UserRole + 2, FINISHEDJOB);
1508 // Job finished successfully
1509 item->setIcon(0, KIcon("dialog-ok"));
1510 item->setData(2, Qt::UserRole, 100);
1511 QTime startTime = item->data(1, Qt::UserRole + 1).toTime();
1512 int seconds = startTime.secsTo(QTime::currentTime());
1513 const QTime tm = QTime().addSecs(seconds);
1514 const QString t = i18n("Rendering finished in %1", tm.toString("hh:mm:ss"));
1515 item->setData(1, Qt::UserRole, t);
1516 QString itemGroup = item->data(0, Qt::UserRole).toString();
1517 if (itemGroup == "dvd") {
1518 emit openDvdWizard(item->text(1), item->data(0, Qt::UserRole + 1).toString());
1519 } else if (itemGroup == "websites") {
1520 QString url = item->data(0, Qt::UserRole + 1).toString();
1521 if (!url.isEmpty()) new KRun(url, this);
1523 } else if (status == -2) {
1524 // Rendering crashed
1525 item->setData(1, Qt::UserRole, i18n("Rendering crashed"));
1526 item->setIcon(0, KIcon("dialog-close"));
1527 item->setData(2, Qt::UserRole, 100);
1528 m_view.error_log->append(i18n("<strong>Rendering of %1 crashed</strong><br />", dest));
1529 m_view.error_log->append(error);
1530 m_view.error_log->append("<hr />");
1531 m_view.error_box->setVisible(true);
1532 } else if (status == -3) {
1534 item->setData(1, Qt::UserRole, i18n("Rendering aborted"));
1535 item->setIcon(0, KIcon("dialog-cancel"));
1536 item->setData(2, Qt::UserRole, 100);
1539 checkRenderStatus();
1542 void RenderWidget::slotAbortCurrentJob()
1544 QTreeWidgetItem *current = m_view.running_jobs->currentItem();
1546 if (current->data(1, Qt::UserRole + 2).toInt() == RUNNINGJOB)
1547 emit abortProcess(current->text(1));
1551 checkRenderStatus();
1556 void RenderWidget::slotStartCurrentJob()
1558 QTreeWidgetItem *current = m_view.running_jobs->currentItem();
1559 if (current && current->data(1, Qt::UserRole + 2).toInt() == WAITINGJOB)
1560 startRendering(current);
1561 m_view.start_job->setEnabled(false);
1564 void RenderWidget::slotCheckJob()
1566 bool activate = false;
1567 QTreeWidgetItem *current = m_view.running_jobs->currentItem();
1569 if (current->data(1, Qt::UserRole + 2).toInt() == RUNNINGJOB) {
1570 m_view.abort_job->setText(i18n("Abort Job"));
1571 m_view.start_job->setEnabled(false);
1573 m_view.abort_job->setText(i18n("Remove Job"));
1574 m_view.start_job->setEnabled(current->data(1, Qt::UserRole + 2).toInt() == WAITINGJOB);
1578 m_view.abort_job->setEnabled(activate);
1579 for (int i = 0; i < m_view.running_jobs->topLevelItemCount(); i++) {
1580 current = m_view.running_jobs->topLevelItem(i);
1581 if (current == m_view.running_jobs->currentItem()) {
1582 current->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 3));
1583 } else current->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
1587 void RenderWidget::slotCLeanUpJobs()
1590 QTreeWidgetItem *current = m_view.running_jobs->topLevelItem(ix);
1592 if (current->data(1, Qt::UserRole + 2).toInt() == FINISHEDJOB)
1595 current = m_view.running_jobs->topLevelItem(ix);
1600 void RenderWidget::parseScriptFiles()
1602 QStringList scriptsFilter;
1603 scriptsFilter << "*.sh";
1604 m_view.scripts_list->clear();
1606 QTreeWidgetItem *item;
1607 // List the project scripts
1608 QStringList scriptFiles = QDir(m_projectFolder + "scripts").entryList(scriptsFilter, QDir::Files);
1609 for (int i = 0; i < scriptFiles.size(); ++i) {
1610 KUrl scriptpath(m_projectFolder + "scripts/" + scriptFiles.at(i));
1614 QFile file(scriptpath.path());
1615 if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
1616 QTextStream stream(&file);
1617 while (!stream.atEnd()) {
1618 QString line = stream.readLine();
1619 if (line.startsWith("TARGET=")) {
1620 target = line.section("TARGET=", 1).simplified();
1621 target.remove(QChar('"'));
1622 } else if (line.startsWith("RENDERER=")) {
1623 renderer = line.section("RENDERER=", 1).simplified();
1624 renderer.remove(QChar('"'));
1625 } else if (line.startsWith("MELT=")) {
1626 melt = line.section("MELT=", 1).simplified();
1627 melt.remove(QChar('"'));
1632 if (target.isEmpty()) continue;
1633 item = new QTreeWidgetItem(m_view.scripts_list, QStringList() << QString() << scriptpath.fileName());
1634 if (!renderer.isEmpty() && renderer.contains('/') && !QFile::exists(renderer)) {
1635 item->setIcon(0, KIcon("dialog-cancel"));
1636 item->setToolTip(1, i18n("Script contains wrong command: %1", renderer));
1637 item->setData(0, Qt::UserRole, '1');
1638 } else if (!melt.isEmpty() && melt.contains('/') && !QFile::exists(melt)) {
1639 item->setIcon(0, KIcon("dialog-cancel"));
1640 item->setToolTip(1, i18n("Script contains wrong command: %1", melt));
1641 item->setData(0, Qt::UserRole, '1');
1642 } else item->setIcon(0, KIcon("application-x-executable-script"));
1643 item->setSizeHint(0, QSize(m_view.scripts_list->columnWidth(0), fontMetrics().height() * 2));
1644 item->setData(1, Qt::UserRole, target.simplified());
1645 item->setData(1, Qt::UserRole + 1, scriptpath.path());
1647 bool activate = false;
1648 QTreeWidgetItem *script = m_view.scripts_list->topLevelItem(0);
1650 script->setSelected(true);
1651 m_view.scripts_list->setCurrentItem(script);
1654 // m_view.start_script->setEnabled(activate);
1655 // m_view.delete_script->setEnabled(activate);
1658 void RenderWidget::slotCheckScript()
1660 QTreeWidgetItem *current = m_view.scripts_list->currentItem();
1661 if (current == NULL) return;
1662 m_view.start_script->setEnabled(current->data(0, Qt::UserRole).toString().isEmpty());
1663 m_view.delete_script->setEnabled(true);
1664 for (int i = 0; i < m_view.scripts_list->topLevelItemCount(); i++) {
1665 current = m_view.scripts_list->topLevelItem(i);
1666 if (current == m_view.scripts_list->currentItem()) {
1667 current->setSizeHint(1, QSize(m_view.scripts_list->columnWidth(1), fontMetrics().height() * 3));
1668 } else current->setSizeHint(1, QSize(m_view.scripts_list->columnWidth(1), fontMetrics().height() * 2));
1672 void RenderWidget::slotStartScript()
1674 QTreeWidgetItem *item = m_view.scripts_list->currentItem();
1676 QString destination = item->data(1, Qt::UserRole).toString();
1677 QString path = item->data(1, Qt::UserRole + 1).toString();
1678 // Insert new job in queue
1679 QTreeWidgetItem *renderItem;
1680 QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(destination, Qt::MatchExactly, 1);
1681 kDebug() << "------ START SCRIPT";
1682 if (!existing.isEmpty()) {
1683 renderItem = existing.at(0);
1684 if (renderItem->data(1, Qt::UserRole + 2).toInt() == RUNNINGJOB) {
1685 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"));
1688 } else renderItem = new QTreeWidgetItem(m_view.running_jobs, QStringList() << QString() << destination << QString());
1689 kDebug() << "------ START SCRIPT 2";
1690 renderItem->setData(2, Qt::UserRole, 0);
1691 renderItem->setData(1, Qt::UserRole + 2, WAITINGJOB);
1692 renderItem->setIcon(0, KIcon("media-playback-pause"));
1693 renderItem->setData(1, Qt::UserRole, i18n("Waiting..."));
1694 renderItem->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
1695 renderItem->setData(1, Qt::UserRole + 1, QTime::currentTime());
1696 renderItem->setData(1, Qt::UserRole + 3, path);
1697 renderItem->setData(1, Qt::UserRole + 4, '1');
1698 checkRenderStatus();
1699 m_view.tabWidget->setCurrentIndex(1);
1703 void RenderWidget::slotDeleteScript()
1705 QTreeWidgetItem *item = m_view.scripts_list->currentItem();
1707 QString path = item->data(1, Qt::UserRole + 1).toString();
1708 KIO::NetAccess::del(path + ".mlt", this);
1709 KIO::NetAccess::del(path, this);
1714 void RenderWidget::slotGenerateScript()
1716 slotPrepareExport(true);
1719 void RenderWidget::slotHideLog()
1721 m_view.error_box->setVisible(false);
1724 void RenderWidget::setRenderProfile(QMap <QString, QString> props)
1726 m_view.destination_list->blockSignals(true);
1727 m_view.format_list->blockSignals(true);
1728 m_view.scanning_list->setCurrentIndex(props.value("renderscanning").toInt());
1729 int exportAudio = props.value("renderexportaudio").toInt();
1730 switch (exportAudio) {
1732 m_view.export_audio->setCheckState(Qt::Unchecked);
1735 m_view.export_audio->setCheckState(Qt::Checked);
1738 m_view.export_audio->setCheckState(Qt::PartiallyChecked);
1740 if (props.contains("renderrescale")) m_view.rescale->setChecked(props.value("renderrescale").toInt());
1741 if (props.contains("renderrescalewidth")) m_view.rescale_width->setValue(props.value("renderrescalewidth").toInt());
1742 if (props.contains("renderrescaleheight")) m_view.rescale_height->setValue(props.value("renderrescaleheight").toInt());
1743 if (props.contains("rendertcoverlay")) m_view.tc_overlay->setChecked(props.value("rendertcoverlay").toInt());
1744 if (props.contains("renderratio")) m_view.rescale_keep->setChecked(props.value("renderratio").toInt());
1745 if (props.contains("renderplay")) m_view.play_after->setChecked(props.value("renderplay").toInt());
1747 if (props.value("renderzone") == "1") m_view.render_zone->setChecked(true);
1748 else if (props.value("renderguide") == "1") {
1749 m_view.render_guide->setChecked(true);
1750 m_view.guide_start->setCurrentIndex(props.value("renderstartguide").toInt());
1751 m_view.guide_end->setCurrentIndex(props.value("renderendguide").toInt());
1752 } else m_view.render_full->setChecked(true);
1753 slotUpdateGuideBox();
1755 QString url = props.value("renderurl");
1756 if (!url.isEmpty()) m_view.out_file->setUrl(KUrl(url));
1759 for (int i = 0; i < m_view.destination_list->count(); i++) {
1760 if (m_view.destination_list->itemData(i, Qt::UserRole) == props.value("renderdestination")) {
1761 m_view.destination_list->setCurrentIndex(i);
1768 QString group = props.value("rendercategory");
1769 if (!group.isEmpty()) {
1770 QList<QListWidgetItem *> childs = m_view.format_list->findItems(group, Qt::MatchExactly);
1771 if (!childs.isEmpty()) {
1772 m_view.format_list->setCurrentItem(childs.at(0));
1773 m_view.format_list->scrollToItem(childs.at(0));
1779 QList<QListWidgetItem *> childs = m_view.size_list->findItems(props.value("renderprofile"), Qt::MatchExactly);
1780 if (!childs.isEmpty()) {
1781 m_view.size_list->setCurrentItem(childs.at(0));
1782 m_view.size_list->scrollToItem(childs.at(0));
1785 m_view.destination_list->blockSignals(false);
1786 m_view.format_list->blockSignals(false);
1790 bool RenderWidget::startWaitingRenderJobs()
1792 m_blockProcessing = true;
1793 QString autoscriptFile = getFreeScriptName("auto");
1794 QFile file(autoscriptFile);
1795 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1796 kWarning() << "////// ERROR writing to file: " << autoscriptFile;
1797 KMessageBox::error(0, i18n("Cannot write to file %1", autoscriptFile));
1801 QTextStream outStream(&file);
1802 outStream << "#! /bin/sh" << "\n" << "\n";
1803 QTreeWidgetItem *item = m_view.running_jobs->topLevelItem(0);
1805 if (item->data(1, Qt::UserRole + 2).toInt() == WAITINGJOB) {
1806 if (item->data(1, Qt::UserRole + 4).isNull()) {
1807 // Add render process for item
1808 const QString params = item->data(1, Qt::UserRole + 3).toStringList().join(" ");
1809 outStream << m_renderer << " " << params << "\n";
1812 outStream << item->data(1, Qt::UserRole + 3).toString() << "\n";
1815 item = m_view.running_jobs->itemBelow(item);
1817 // erase itself when rendering is finished
1818 outStream << "rm " << autoscriptFile << "\n" << "\n";
1819 if (file.error() != QFile::NoError) {
1820 KMessageBox::error(0, i18n("Cannot write to file %1", autoscriptFile));
1822 m_blockProcessing = false;
1826 QFile::setPermissions(autoscriptFile, file.permissions() | QFile::ExeUser);
1827 QProcess::startDetached(autoscriptFile, QStringList());
1831 QString RenderWidget::getFreeScriptName(const QString &prefix)
1834 QString scriptsFolder = m_projectFolder + "scripts/";
1835 KStandardDirs::makeDir(scriptsFolder);
1837 while (path.isEmpty() || QFile::exists(path)) {
1839 path = scriptsFolder + prefix + i18n("script") + QString::number(ix).rightJustified(3, '0', false) + ".sh";
1844 void RenderWidget::slotPlayRendering(QTreeWidgetItem *item, int)
1846 if (KdenliveSettings::defaultplayerapp().isEmpty() || item->data(1, Qt::UserRole + 2).toInt() != FINISHEDJOB) return;
1847 const QByteArray startId = KStartupInfo::createNewStartupId();
1848 const QString command = KdenliveSettings::defaultplayerapp() + ' ' + item->text(1);
1849 KRun::runCommand(command, KdenliveSettings::defaultplayerapp(), KdenliveSettings::defaultplayerapp(), this, startId);
1852 void RenderWidget::missingClips(bool hasMissing)
1855 m_view.errorLabel->setText(i18n("Check missing clips"));
1856 m_view.errorBox->setHidden(false);
1857 } else m_view.errorBox->setHidden(true);
1860 void RenderWidget::slotUpdateRescaleWidth(int val)
1862 KdenliveSettings::setDefaultrescalewidth(val);
1863 if (!m_view.rescale_keep->isChecked()) return;
1864 m_view.rescale_height->blockSignals(true);
1865 m_view.rescale_height->setValue(val * m_profile.height / m_profile.width + 0.5);
1866 KdenliveSettings::setDefaultrescaleheight(m_view.rescale_height->value());
1867 m_view.rescale_height->blockSignals(false);
1870 void RenderWidget::slotUpdateRescaleHeight(int val)
1872 KdenliveSettings::setDefaultrescaleheight(val);
1873 if (!m_view.rescale_keep->isChecked()) return;
1874 m_view.rescale_width->blockSignals(true);
1875 m_view.rescale_width->setValue(val * m_profile.width / m_profile.height + 0.5);
1876 KdenliveSettings::setDefaultrescaleheight(m_view.rescale_width->value());
1877 m_view.rescale_width->blockSignals(false);
1880 void RenderWidget::slotSwitchAspectRatio()
1882 KdenliveSettings::setRescalekeepratio(m_view.rescale_keep->isChecked());
1883 if (m_view.rescale_keep->isChecked()) slotUpdateRescaleWidth(m_view.rescale_width->value());
1886 void RenderWidget::slotUpdateAudioLabel(int ix)
1888 if (ix == Qt::PartiallyChecked)
1889 m_view.export_audio->setText(i18n("Export audio (automatic)"));
1891 m_view.export_audio->setText(i18n("Export audio"));
1894 bool RenderWidget::automaticAudioExport() const
1896 return (m_view.export_audio->checkState() == Qt::PartiallyChecked);
1899 bool RenderWidget::selectedAudioExport() const
1901 return (m_view.export_audio->checkState() != Qt::Unchecked);