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"
25 #include <KStandardDirs>
27 #include <KMessageBox>
30 #include <KIO/NetAccess>
31 // #include <knewstuff2/engine.h>
33 #include <QDomDocument>
34 #include <QItemDelegate>
35 #include <QTreeWidgetItem>
36 #include <QListWidgetItem>
37 #include <QHeaderView>
40 #include <QInputDialog>
42 const int GroupRole = Qt::UserRole;
43 const int ExtensionRole = GroupRole + 1;
44 const int StandardRole = GroupRole + 2;
45 const int RenderRole = GroupRole + 3;
46 const int ParamsRole = GroupRole + 4;
47 const int EditableRole = GroupRole + 5;
48 const int MetaGroupRole = GroupRole + 6;
49 const int ExtraRole = GroupRole + 7;
52 const int WAITINGJOB = 0;
53 const int RUNNINGJOB = 1;
54 const int FINISHEDJOB = 2;
57 RenderWidget::RenderWidget(const QString &projectfolder, QWidget * parent) :
59 m_projectFolder(projectfolder)
62 setWindowTitle(i18n("Rendering"));
63 m_view.buttonDelete->setIcon(KIcon("trash-empty"));
64 m_view.buttonDelete->setToolTip(i18n("Delete profile"));
65 m_view.buttonDelete->setEnabled(false);
67 m_view.buttonEdit->setIcon(KIcon("document-properties"));
68 m_view.buttonEdit->setToolTip(i18n("Edit profile"));
69 m_view.buttonEdit->setEnabled(false);
71 m_view.buttonSave->setIcon(KIcon("document-new"));
72 m_view.buttonSave->setToolTip(i18n("Create new profile"));
74 m_view.buttonInfo->setIcon(KIcon("help-about"));
75 m_view.hide_log->setIcon(KIcon("go-down"));
77 if (KdenliveSettings::showrenderparams()) {
78 m_view.buttonInfo->setDown(true);
79 } else m_view.advanced_params->hide();
81 m_view.rescale_size->setInputMask("0099\\x0099");
82 m_view.rescale_size->setText("320x240");
85 QMenu *renderMenu = new QMenu(i18n("Start Rendering"), this);
86 QAction *renderAction = renderMenu->addAction(KIcon("video-x-generic"), i18n("Render to File"));
87 connect(renderAction, SIGNAL(triggered()), this, SLOT(slotExport()));
88 QAction *scriptAction = renderMenu->addAction(KIcon("application-x-shellscript"), i18n("Generate Script"));
89 connect(scriptAction, SIGNAL(triggered()), this, SLOT(slotGenerateScript()));
91 m_view.buttonStart->setMenu(renderMenu);
92 m_view.buttonStart->setPopupMode(QToolButton::MenuButtonPopup);
93 m_view.buttonStart->setDefaultAction(renderAction);
94 m_view.buttonStart->setToolButtonStyle(Qt::ToolButtonTextOnly);
95 m_view.abort_job->setEnabled(false);
96 m_view.start_script->setEnabled(false);
97 m_view.delete_script->setEnabled(false);
99 m_view.format_list->setAlternatingRowColors(true);
100 m_view.size_list->setAlternatingRowColors(true);
105 connect(m_view.start_script, SIGNAL(clicked()), this, SLOT(slotStartScript()));
106 connect(m_view.delete_script, SIGNAL(clicked()), this, SLOT(slotDeleteScript()));
107 connect(m_view.scripts_list, SIGNAL(itemSelectionChanged()), this, SLOT(slotCheckScript()));
108 connect(m_view.running_jobs, SIGNAL(itemSelectionChanged()), this, SLOT(slotCheckJob()));
110 connect(m_view.buttonInfo, SIGNAL(clicked()), this, SLOT(showInfoPanel()));
112 connect(m_view.buttonSave, SIGNAL(clicked()), this, SLOT(slotSaveProfile()));
113 connect(m_view.buttonEdit, SIGNAL(clicked()), this, SLOT(slotEditProfile()));
114 connect(m_view.buttonDelete, SIGNAL(clicked()), this, SLOT(slotDeleteProfile()));
115 connect(m_view.abort_job, SIGNAL(clicked()), this, SLOT(slotAbortCurrentJob()));
116 connect(m_view.clean_up, SIGNAL(clicked()), this, SLOT(slotCLeanUpJobs()));
117 connect(m_view.hide_log, SIGNAL(clicked()), this, SLOT(slotHideLog()));
119 connect(m_view.buttonClose, SIGNAL(clicked()), this, SLOT(hide()));
120 connect(m_view.buttonClose2, SIGNAL(clicked()), this, SLOT(hide()));
121 connect(m_view.buttonClose3, SIGNAL(clicked()), this, SLOT(hide()));
122 connect(m_view.rescale, SIGNAL(toggled(bool)), m_view.rescale_size, SLOT(setEnabled(bool)));
123 connect(m_view.destination_list, SIGNAL(activated(int)), this, SLOT(refreshView()));
124 connect(m_view.out_file, SIGNAL(textChanged(const QString &)), this, SLOT(slotUpdateButtons()));
125 connect(m_view.out_file, SIGNAL(urlSelected(const KUrl &)), this, SLOT(slotUpdateButtons(const KUrl &)));
126 connect(m_view.format_list, SIGNAL(currentRowChanged(int)), this, SLOT(refreshView()));
127 connect(m_view.size_list, SIGNAL(currentRowChanged(int)), this, SLOT(refreshParams()));
129 connect(m_view.size_list, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(slotEditItem(QListWidgetItem *)));
131 connect(m_view.render_guide, SIGNAL(clicked(bool)), this, SLOT(slotUpdateGuideBox()));
132 connect(m_view.render_zone, SIGNAL(clicked(bool)), this, SLOT(slotUpdateGuideBox()));
133 connect(m_view.render_full, SIGNAL(clicked(bool)), this, SLOT(slotUpdateGuideBox()));
135 connect(m_view.guide_end, SIGNAL(activated(int)), this, SLOT(slotCheckStartGuidePosition()));
136 connect(m_view.guide_start, SIGNAL(activated(int)), this, SLOT(slotCheckEndGuidePosition()));
138 connect(m_view.format_selection, SIGNAL(activated(int)), this, SLOT(refreshView()));
140 m_view.buttonStart->setEnabled(false);
141 m_view.rescale_size->setEnabled(false);
142 m_view.guides_box->setVisible(false);
143 m_view.open_dvd->setVisible(false);
144 m_view.create_chapter->setVisible(false);
145 m_view.open_browser->setVisible(false);
146 m_view.error_box->setVisible(false);
148 m_view.splitter->setStretchFactor(1, 5);
149 m_view.splitter->setStretchFactor(0, 2);
151 m_view.out_file->setMode(KFile::File);
153 m_view.running_jobs->setHeaderLabels(QStringList() << QString() << i18n("File") << i18n("Progress"));
154 m_view.running_jobs->setItemDelegate(new RenderViewDelegate(this));
156 QHeaderView *header = m_view.running_jobs->header();
157 QFontMetrics fm = fontMetrics();
158 //header->resizeSection(0, fm.width("typical-name-for-a-torrent.torrent"));
159 header->setResizeMode(0, QHeaderView::Fixed);
160 header->resizeSection(0, 30);
161 header->setResizeMode(1, QHeaderView::Interactive);
162 header->resizeSection(1, fm.width("typical-name-for-a-file.torrent"));
163 header->setResizeMode(2, QHeaderView::Fixed);
164 header->resizeSection(1, width() * 2 / 3);
165 header->setResizeMode(2, QHeaderView::Interactive);
166 //header->setResizeMode(1, QHeaderView::Fixed);
168 m_view.scripts_list->setHeaderLabels(QStringList() << i18n("Script Files"));
169 m_view.scripts_list->setItemDelegate(new RenderScriptDelegate(this));
172 focusFirstVisibleItem();
175 void RenderWidget::slotEditItem(QListWidgetItem *item)
177 QString edit = item->data(EditableRole).toString();
178 if (edit.isEmpty() || !edit.endsWith("customprofiles.xml")) slotSaveProfile();
179 else slotEditProfile();
182 void RenderWidget::showInfoPanel()
184 if (m_view.advanced_params->isVisible()) {
185 m_view.advanced_params->setVisible(false);
186 m_view.buttonInfo->setDown(false);
187 KdenliveSettings::setShowrenderparams(false);
189 m_view.advanced_params->setVisible(true);
190 m_view.buttonInfo->setDown(true);
191 KdenliveSettings::setShowrenderparams(true);
195 void RenderWidget::setDocumentPath(const QString path)
197 m_projectFolder = path;
198 const QString fileName = m_view.out_file->url().fileName();
199 m_view.out_file->setUrl(KUrl(m_projectFolder + '/' + fileName));
203 void RenderWidget::slotUpdateGuideBox()
205 m_view.guides_box->setVisible(m_view.render_guide->isChecked());
208 void RenderWidget::slotCheckStartGuidePosition()
210 if (m_view.guide_start->currentIndex() > m_view.guide_end->currentIndex())
211 m_view.guide_start->setCurrentIndex(m_view.guide_end->currentIndex());
214 void RenderWidget::slotCheckEndGuidePosition()
216 if (m_view.guide_end->currentIndex() < m_view.guide_start->currentIndex())
217 m_view.guide_end->setCurrentIndex(m_view.guide_start->currentIndex());
220 void RenderWidget::setGuides(QDomElement guidesxml, double duration)
222 m_view.guide_start->clear();
223 m_view.guide_end->clear();
224 QDomNodeList nodes = guidesxml.elementsByTagName("guide");
225 if (nodes.count() > 0) {
226 m_view.guide_start->addItem(i18n("Beginning"), "0");
227 m_view.render_guide->setEnabled(true);
228 m_view.create_chapter->setEnabled(true);
230 m_view.render_guide->setEnabled(false);
231 m_view.create_chapter->setEnabled(false);
233 for (int i = 0; i < nodes.count(); i++) {
234 QDomElement e = nodes.item(i).toElement();
236 m_view.guide_start->addItem(e.attribute("comment"), e.attribute("time").toDouble());
237 m_view.guide_end->addItem(e.attribute("comment"), e.attribute("time").toDouble());
240 if (nodes.count() > 0)
241 m_view.guide_end->addItem(i18n("End"), QString::number(duration));
245 * Will be called when the user selects an output file via the file dialog.
246 * File extension will be added automatically.
248 void RenderWidget::slotUpdateButtons(KUrl url)
250 if (m_view.out_file->url().isEmpty()) m_view.buttonStart->setEnabled(false);
252 updateButtons(); // This also checks whether the selected format is available
253 //m_view.buttonStart->setEnabled(true);
256 QListWidgetItem *item = m_view.size_list->currentItem();
257 QString extension = item->data(ExtensionRole).toString();
258 url = filenameWithExtension(url, extension);
259 m_view.out_file->setUrl(url);
264 * Will be called when the user changes the output file path in the text line.
265 * File extension must NOT be added, would make editing impossible!
267 void RenderWidget::slotUpdateButtons()
269 if (m_view.out_file->url().isEmpty()) m_view.buttonStart->setEnabled(false);
270 else updateButtons(); // This also checks whether the selected format is available
271 //else m_view.buttonStart->setEnabled(true);
274 void RenderWidget::slotSaveProfile()
276 //TODO: update to correctly use metagroups
277 Ui::SaveProfile_UI ui;
278 QDialog *d = new QDialog(this);
281 for (int i = 0; i < m_view.destination_list->count(); i++)
282 ui.destination_list->addItem(m_view.destination_list->itemIcon(i), m_view.destination_list->itemText(i), m_view.destination_list->itemData(i, Qt::UserRole));
284 ui.destination_list->setCurrentIndex(m_view.destination_list->currentIndex());
285 QString dest = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
287 QString customGroup = m_view.format_list->currentItem()->text();
288 if (customGroup.isEmpty()) customGroup = i18n("Custom");
289 ui.group_name->setText(customGroup);
291 ui.parameters->setText(m_view.advanced_params->toPlainText());
292 ui.extension->setText(m_view.size_list->currentItem()->data(ExtensionRole).toString());
293 ui.profile_name->setFocus();
294 if (d->exec() == QDialog::Accepted && !ui.profile_name->text().simplified().isEmpty()) {
295 QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
297 QFile file(exportFile);
298 doc.setContent(&file, false);
300 QDomElement documentElement;
301 QDomElement profiles = doc.documentElement();
302 if (profiles.isNull() || profiles.tagName() != "profiles") {
304 profiles = doc.createElement("profiles");
305 profiles.setAttribute("version", 1);
306 doc.appendChild(profiles);
308 int version = profiles.attribute("version", 0).toInt();
310 kDebug() << "// OLD profile version";
312 profiles = doc.createElement("profiles");
313 profiles.setAttribute("version", 1);
314 doc.appendChild(profiles);
317 QString newProfileName = ui.profile_name->text().simplified();
318 QString newGroupName = ui.group_name->text().simplified();
319 if (newGroupName.isEmpty()) newGroupName = i18n("Custom");
320 QString newMetaGroupId = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
321 QDomNodeList profilelist = doc.elementsByTagName("profile");
323 while (!profilelist.item(i).isNull()) {
324 // make sure a profile with same name doesn't exist
325 documentElement = profilelist.item(i).toElement();
326 QString profileName = documentElement.attribute("name");
327 if (profileName == newProfileName) {
328 // a profile with that same name already exists
330 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);
332 if (profileName == newProfileName) {
333 profiles.removeChild(profilelist.item(i));
340 QDomElement profileElement = doc.createElement("profile");
341 profileElement.setAttribute("name", newProfileName);
342 profileElement.setAttribute("category", newGroupName);
343 profileElement.setAttribute("destinationid", newMetaGroupId);
344 profileElement.setAttribute("extension", ui.extension->text().simplified());
345 profileElement.setAttribute("args", ui.parameters->toPlainText().simplified());
346 profiles.appendChild(profileElement);
348 //QCString save = doc.toString().utf8();
350 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
351 KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
355 QTextStream out(&file);
356 out << doc.toString();
357 if (file.error() != QFile::NoError) {
358 KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
364 parseProfiles(newMetaGroupId, newGroupName, newProfileName);
369 void RenderWidget::slotEditProfile()
371 QListWidgetItem *item = m_view.size_list->currentItem();
373 QString currentGroup = m_view.format_list->currentItem()->text();
375 QString params = item->data(ParamsRole).toString();
376 QString extension = item->data(ExtensionRole).toString();
377 QString currentProfile = item->text();
379 Ui::SaveProfile_UI ui;
380 QDialog *d = new QDialog(this);
383 for (int i = 0; i < m_view.destination_list->count(); i++)
384 ui.destination_list->addItem(m_view.destination_list->itemIcon(i), m_view.destination_list->itemText(i), m_view.destination_list->itemData(i, Qt::UserRole));
386 ui.destination_list->setCurrentIndex(m_view.destination_list->currentIndex());
387 QString dest = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
389 QString customGroup = m_view.format_list->currentItem()->text();
390 if (customGroup.isEmpty()) customGroup = i18n("Custom");
391 ui.group_name->setText(customGroup);
393 ui.profile_name->setText(currentProfile);
394 ui.extension->setText(extension);
395 ui.parameters->setText(params);
396 ui.profile_name->setFocus();
397 d->setWindowTitle(i18n("Edit Profile"));
398 if (d->exec() == QDialog::Accepted) {
399 slotDeleteProfile(false);
400 QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
402 QFile file(exportFile);
403 doc.setContent(&file, false);
405 QDomElement documentElement;
406 QDomElement profiles = doc.documentElement();
408 if (profiles.isNull() || profiles.tagName() != "profiles") {
410 profiles = doc.createElement("profiles");
411 profiles.setAttribute("version", 1);
412 doc.appendChild(profiles);
415 int version = profiles.attribute("version", 0).toInt();
417 kDebug() << "// OLD profile version";
419 profiles = doc.createElement("profiles");
420 profiles.setAttribute("version", 1);
421 doc.appendChild(profiles);
424 QString newProfileName = ui.profile_name->text().simplified();
425 QString newGroupName = ui.group_name->text().simplified();
426 if (newGroupName.isEmpty()) newGroupName = i18n("Custom");
427 QString newMetaGroupId = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
428 QDomNodeList profilelist = doc.elementsByTagName("profile");
430 while (!profilelist.item(i).isNull()) {
431 // make sure a profile with same name doesn't exist
432 documentElement = profilelist.item(i).toElement();
433 QString profileName = documentElement.attribute("name");
434 if (profileName == newProfileName) {
435 // a profile with that same name already exists
437 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);
439 if (profileName == newProfileName) {
440 profiles.removeChild(profilelist.item(i));
447 QDomElement profileElement = doc.createElement("profile");
448 profileElement.setAttribute("name", newProfileName);
449 profileElement.setAttribute("category", newGroupName);
450 profileElement.setAttribute("destinationid", newMetaGroupId);
451 profileElement.setAttribute("extension", ui.extension->text().simplified());
452 profileElement.setAttribute("args", ui.parameters->toPlainText().simplified());
453 profiles.appendChild(profileElement);
455 //QCString save = doc.toString().utf8();
457 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
458 KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
461 QTextStream out(&file);
462 out << doc.toString();
463 if (file.error() != QFile::NoError) {
464 KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
469 parseProfiles(newMetaGroupId, newGroupName, newProfileName);
473 void RenderWidget::slotDeleteProfile(bool refresh)
475 //TODO: delete a profile installed by KNewStuff the easy way
477 QString edit = m_view.size_list->currentItem()->data(EditableRole).toString();
478 if (!edit.endsWith("customprofiles.xml")) {
479 // This is a KNewStuff installed file, process through KNS
480 KNS::Engine engine(0);
481 if (engine.init("kdenlive_render.knsrc")) {
482 KNS::Entry::List entries;
486 QString currentGroup = m_view.format_list->currentItem()->text();
487 QString currentProfile = m_view.size_list->currentItem()->text();
488 QString metaGroupId = m_view.destination_list->itemData(m_view.destination_list->currentIndex(), Qt::UserRole).toString();
490 QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
492 QFile file(exportFile);
493 doc.setContent(&file, false);
496 QDomElement documentElement;
497 QDomNodeList profiles = doc.elementsByTagName("profile");
503 while (!profiles.item(i).isNull()) {
504 documentElement = profiles.item(i).toElement();
505 profileName = documentElement.attribute("name");
506 groupName = documentElement.attribute("category");
507 destination = documentElement.attribute("destinationid");
509 if (profileName == currentProfile && groupName == currentGroup && destination == metaGroupId) {
510 kDebug() << "// GOT it: " << profileName;
511 doc.documentElement().removeChild(profiles.item(i));
517 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
518 KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
521 QTextStream out(&file);
522 out << doc.toString();
523 if (file.error() != QFile::NoError) {
524 KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
530 parseProfiles(metaGroupId, currentGroup);
531 focusFirstVisibleItem();
535 void RenderWidget::updateButtons()
537 if (!m_view.size_list->currentItem() || m_view.size_list->currentItem()->isHidden()) {
538 m_view.buttonSave->setEnabled(false);
539 m_view.buttonDelete->setEnabled(false);
540 m_view.buttonEdit->setEnabled(false);
541 m_view.buttonStart->setEnabled(false);
543 m_view.buttonSave->setEnabled(true);
544 m_view.buttonStart->setEnabled(m_view.size_list->currentItem()->toolTip().isEmpty());
545 QString edit = m_view.size_list->currentItem()->data(EditableRole).toString();
546 if (edit.isEmpty() || !edit.endsWith("customprofiles.xml")) {
547 m_view.buttonDelete->setEnabled(false);
548 m_view.buttonEdit->setEnabled(false);
550 m_view.buttonDelete->setEnabled(true);
551 m_view.buttonEdit->setEnabled(true);
557 void RenderWidget::focusFirstVisibleItem()
559 if (m_view.size_list->currentItem() && !m_view.size_list->currentItem()->isHidden()) {
563 for (int ix = 0; ix < m_view.size_list->count(); ix++) {
564 QListWidgetItem *item = m_view.size_list->item(ix);
565 if (item && !item->isHidden()) {
566 m_view.size_list->setCurrentRow(ix);
570 if (!m_view.size_list->currentItem()) m_view.size_list->setCurrentRow(0);
574 void RenderWidget::slotExport(bool scriptExport)
576 QListWidgetItem *item = m_view.size_list->currentItem();
579 QString dest = m_view.out_file->url().path();
580 if (dest.isEmpty()) return;
582 // Check whether target file has an extension.
583 // If not, ask whether extension should be added or not.
584 QString extension = item->data(ExtensionRole).toString();
585 if (!dest.endsWith(extension)) {
586 if (KMessageBox::questionYesNo(this, i18n("File has no extension. Add extension (%1)?", extension)) == KMessageBox::Yes) {
587 dest.append("." + extension);
593 if (KMessageBox::warningYesNo(this, i18n("Output file already exists. Do you want to overwrite it?")) != KMessageBox::Yes)
598 QStringList overlayargs;
599 if (m_view.tc_overlay->isChecked()) {
600 QString filterFile = KStandardDirs::locate("appdata", "metadata.properties");
601 overlayargs << "meta.attr.timecode=1" << "meta.attr.timecode.markup=#timecode";
602 overlayargs << "-attach" << "data_feed:attr_check" << "-attach";
603 overlayargs << "data_show:" + filterFile << "_loader=1" << "dynamic=1";
605 double startPos = -1;
607 if (m_view.render_guide->isChecked()) {
608 startPos = m_view.guide_start->itemData(m_view.guide_start->currentIndex()).toDouble();
609 endPos = m_view.guide_end->itemData(m_view.guide_end->currentIndex()).toDouble();
611 QString renderArgs = m_view.advanced_params->toPlainText().simplified();
613 // Adjust frame scale
616 if (m_view.rescale->isChecked() && m_view.rescale->isEnabled()) {
617 width = m_view.rescale_size->text().section('x', 0, 0).toInt();
618 height = m_view.rescale_size->text().section('x', 1, 1).toInt();
620 width = m_profile.width;
621 height = m_profile.height;
623 renderArgs.replace("%dar", '@' + QString::number(m_profile.display_aspect_num) + '/' + QString::number(m_profile.display_aspect_den));
626 if (m_view.scanning_list->currentIndex() == 1) renderArgs.append(" progressive=1");
627 else if (m_view.scanning_list->currentIndex() == 2) renderArgs.append(" progressive=0");
629 // disable audio if requested
630 if (!m_view.export_audio->isChecked())
631 renderArgs.append(" an=1 ");
633 // Check if the rendering profile is different from project profile,
634 // in which case we need to use the producer_comsumer from MLT
635 QString std = renderArgs;
636 QString destination = m_view.destination_list->itemData(m_view.destination_list->currentIndex()).toString();
637 const QString currentSize = QString::number(width) + 'x' + QString::number(height);
638 QString subsize = currentSize;
639 if (std.startsWith("s=")) {
640 subsize = std.section(' ', 0, 0).toLower();
641 subsize = subsize.section("=", 1, 1);
642 } else if (std.contains(" s=")) {
643 subsize = std.section(" s=", 1, 1);
644 subsize = subsize.section(' ', 0, 0).toLower();
645 } else if (destination != "audioonly" && m_view.rescale->isChecked() && m_view.rescale->isEnabled()) {
646 subsize = QString(" s=%1x%2").arg(width).arg(height);
647 // Add current size parameter
648 renderArgs.append(subsize);
650 bool resizeProfile = (subsize != currentSize);
652 QString group = m_view.size_list->currentItem()->data(MetaGroupRole).toString();
654 QStringList renderParameters;
655 renderParameters << dest << item->data(RenderRole).toString() << renderArgs.simplified();
656 renderParameters << QString::number(m_view.render_zone->isChecked()) << QString::number(m_view.play_after->isChecked());
657 renderParameters << QString::number(startPos) << QString::number(endPos) << QString::number(resizeProfile);
663 QString scriptsFolder = m_projectFolder + "/scripts/";
664 KStandardDirs::makeDir(scriptsFolder);
665 QString path = scriptsFolder + i18n("script") + QString::number(ix).rightJustified(3, '0', false) + ".sh";
666 while (QFile::exists(path)) {
668 path = scriptsFolder + i18n("script") + QString::number(ix).rightJustified(3, '0', false) + ".sh";
670 scriptName = QInputDialog::getText(this, i18n("Create Render Script"), i18n("Script name (will be saved in: %1)", scriptsFolder), QLineEdit::Normal, KUrl(path).fileName(), &ok);
671 if (!ok || scriptName.isEmpty()) return;
672 scriptName.prepend(scriptsFolder);
675 if (KMessageBox::warningYesNo(this, i18n("Script file already exists. Do you want to overwrite it?")) != KMessageBox::Yes)
678 renderParameters << scriptName;
679 if (group == "dvd") renderParameters << QString::number(m_view.create_chapter->isChecked());
680 else renderParameters << QString::number(false);
681 emit doRender(renderParameters, overlayargs);
682 QTimer::singleShot(400, this, SLOT(parseScriptFiles()));
683 m_view.tabWidget->setCurrentIndex(2);
686 renderParameters << scriptName;
687 m_view.tabWidget->setCurrentIndex(1);
689 // insert item in running jobs list
690 QTreeWidgetItem *renderItem;
691 QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(dest, Qt::MatchExactly, 1);
692 if (!existing.isEmpty()) {
693 renderItem = existing.at(0);
694 if (renderItem->data(1, Qt::UserRole + 2).toInt() == RUNNINGJOB) {
695 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"));
698 renderItem->setData(1, Qt::UserRole + 4, QString());
700 renderItem = new QTreeWidgetItem(m_view.running_jobs, QStringList() << QString() << dest << QString());
701 renderItem->setData(1, Qt::UserRole + 2, WAITINGJOB);
702 renderItem->setIcon(0, KIcon("media-playback-pause"));
703 renderItem->setData(1, Qt::UserRole, i18n("Waiting..."));
705 renderItem->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
706 renderItem->setData(1, Qt::UserRole + 1, QTime::currentTime());
707 renderItem->setData(1, Qt::UserRole + 2, overlayargs);
709 // Set rendering type
710 if (group == "dvd") {
711 renderParameters << QString::number(m_view.create_chapter->isChecked());
712 if (m_view.open_dvd->isChecked()) {
713 renderItem->setData(0, Qt::UserRole, group);
714 if (renderArgs.contains("profile=")) {
715 //Â rendering profile contains an MLT profile, so pass it to the running jog item, useful for dvd
716 QString prof = renderArgs.section("profile=", 1, 1);
717 prof = prof.section(' ', 0, 0);
718 kDebug() << "// render profile: " << prof;
719 renderItem->setData(0, Qt::UserRole + 1, prof);
723 renderParameters << QString::number(false);
724 if (group == "websites" && m_view.open_browser->isChecked()) {
725 renderItem->setData(0, Qt::UserRole, group);
727 QString url = m_view.size_list->currentItem()->data(ExtraRole).toString();
728 renderItem->setData(0, Qt::UserRole + 1, url);
733 renderItem->setData(1, Qt::UserRole + 3, renderParameters);
737 void RenderWidget::checkRenderStatus()
739 QTreeWidgetItem *item = m_view.running_jobs->topLevelItem(0);
741 if (item->data(1, Qt::UserRole + 2).toInt() == RUNNINGJOB) break;
742 else if (item->data(1, Qt::UserRole + 2).toInt() == WAITINGJOB) {
743 item->setData(1, Qt::UserRole + 1, QTime::currentTime());
744 if (item->data(1, Qt::UserRole + 4).isNull()) {
745 emit doRender(item->data(1, Qt::UserRole + 3).toStringList(), item->data(1, Qt::UserRole + 2).toStringList());
748 QProcess::startDetached(item->data(1, Qt::UserRole + 3).toString());
752 item = m_view.running_jobs->itemBelow(item);
756 void RenderWidget::setProfile(MltVideoProfile profile)
759 //WARNING: this way to tell the video standard is a bit hackish...
760 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);
761 else m_view.format_selection->setCurrentIndex(1);
762 m_view.scanning_list->setCurrentIndex(0);
766 void RenderWidget::refreshView()
768 m_view.size_list->blockSignals(true);
769 QListWidgetItem *sizeItem;
772 KIcon brokenIcon("dialog-close");
773 if (m_view.destination_list->currentIndex() > 0)
774 destination = m_view.destination_list->itemData(m_view.destination_list->currentIndex()).toString();
777 if (destination == "dvd") {
778 m_view.open_dvd->setVisible(true);
779 m_view.create_chapter->setVisible(true);
781 m_view.open_dvd->setVisible(false);
782 m_view.create_chapter->setVisible(false);
784 if (destination == "websites") m_view.open_browser->setVisible(true);
785 else m_view.open_browser->setVisible(false);
786 if (!destination.isEmpty() && QString("dvd websites audioonly").contains(destination))
787 m_view.rescale->setEnabled(false);
788 else m_view.rescale->setEnabled(true);
789 // hide groups that are not in the correct destination
790 for (int i = 0; i < m_view.format_list->count(); i++) {
791 sizeItem = m_view.format_list->item(i);
792 if (sizeItem->data(MetaGroupRole).toString() == destination) {
793 sizeItem->setHidden(false);
794 //kDebug() << "// SET GRP:: " << sizeItem->text() << ", METY:" << sizeItem->data(MetaGroupRole).toString();
795 } else sizeItem->setHidden(true);
798 // activate first visible item
799 QListWidgetItem * item = m_view.format_list->currentItem();
800 if (!item || item->isHidden()) {
801 for (int i = 0; i < m_view.format_list->count(); i++) {
802 if (!m_view.format_list->item(i)->isHidden()) {
803 m_view.format_list->setCurrentRow(i);
807 item = m_view.format_list->currentItem();
809 if (!item || item->isHidden()) {
810 m_view.format_list->setEnabled(false);
811 m_view.size_list->setEnabled(false);
814 m_view.format_list->setEnabled(true);
815 m_view.size_list->setEnabled(true);
818 for (int i = 0; i < m_view.format_list->count() && count < 2; i++) {
819 if (!m_view.format_list->isRowHidden(i)) count++;
821 if (count > 1) m_view.format_list->setVisible(true);
822 else m_view.format_list->setVisible(false);
824 QString group = item->text();
825 bool firstSelected = false;
826 const QStringList formatsList = KdenliveSettings::supportedformats();
827 const QStringList vcodecsList = KdenliveSettings::videocodecs();
828 const QStringList acodecsList = KdenliveSettings::audiocodecs();
830 for (int i = 0; i < m_view.size_list->count(); i++) {
831 sizeItem = m_view.size_list->item(i);
832 if ((sizeItem->data(GroupRole) == group || sizeItem->data(GroupRole).toString().isEmpty()) && sizeItem->data(MetaGroupRole) == destination) {
833 std = sizeItem->data(StandardRole).toString();
834 if (!std.isEmpty()) {
835 if (std.contains("PAL", Qt::CaseInsensitive)) sizeItem->setHidden(m_view.format_selection->currentIndex() != 0);
836 else if (std.contains("NTSC", Qt::CaseInsensitive)) sizeItem->setHidden(m_view.format_selection->currentIndex() != 1);
838 sizeItem->setHidden(false);
839 if (!firstSelected) m_view.size_list->setCurrentItem(sizeItem);
840 firstSelected = true;
843 if (!sizeItem->isHidden()) {
844 // Make sure the selected profile uses an installed avformat codec / format
845 std = sizeItem->data(ParamsRole).toString();
847 if (!formatsList.isEmpty()) {
849 if (std.startsWith("f=")) format = std.section("f=", 1, 1);
850 else if (std.contains(" f=")) format = std.section(" f=", 1, 1);
851 if (!format.isEmpty()) {
852 format = format.section(' ', 0, 0).toLower();
853 if (!formatsList.contains(format)) {
854 kDebug() << "***** UNSUPPORTED F: " << format;
855 //sizeItem->setHidden(true);
856 //sizeItem->setFlags(Qt::ItemIsSelectable);
857 sizeItem->setToolTip(i18n("Unsupported video format: %1", format));
858 sizeItem->setIcon(brokenIcon);
862 if (!acodecsList.isEmpty() && !sizeItem->isHidden()) {
864 if (std.startsWith("acodec=")) format = std.section("acodec=", 1, 1);
865 else if (std.contains(" acodec=")) format = std.section(" acodec=", 1, 1);
866 if (!format.isEmpty()) {
867 format = format.section(' ', 0, 0).toLower();
868 if (!acodecsList.contains(format)) {
869 kDebug() << "***** UNSUPPORTED ACODEC: " << format;
870 //sizeItem->setHidden(true);
871 //sizeItem->setFlags(Qt::ItemIsSelectable);
872 sizeItem->setToolTip(i18n("Unsupported audio codec: %1", format));
873 sizeItem->setIcon(brokenIcon);
877 if (!vcodecsList.isEmpty() && !sizeItem->isHidden()) {
879 if (std.startsWith("vcodec=")) format = std.section("vcodec=", 1, 1);
880 else if (std.contains(" vcodec=")) format = std.section(" vcodec=", 1, 1);
881 if (!format.isEmpty()) {
882 format = format.section(' ', 0, 0).toLower();
883 if (!vcodecsList.contains(format)) {
884 kDebug() << "***** UNSUPPORTED VCODEC: " << format;
885 //sizeItem->setHidden(true);
886 //sizeItem->setFlags(Qt::ItemIsSelectable);
887 sizeItem->setToolTip(i18n("Unsupported video codec: %1", format));
888 sizeItem->setIcon(brokenIcon);
893 } else sizeItem->setHidden(true);
895 focusFirstVisibleItem();
896 m_view.size_list->blockSignals(false);
900 KUrl RenderWidget::filenameWithExtension(KUrl url, QString extension)
903 if (!url.isEmpty()) {
905 int pos = path.lastIndexOf('.') + 1;
906 if (pos == 0) path.append('.' + extension);
907 else path = path.left(pos) + extension;
910 path = m_projectFolder + "/untitled." + extension;
917 * Called when a new format or size has been selected.
919 void RenderWidget::refreshParams()
921 // Format not available (e.g. codec not installed); Disable start button
922 QListWidgetItem *item = m_view.size_list->currentItem();
923 if (!item || item->isHidden()) {
924 m_view.advanced_params->clear();
925 m_view.buttonStart->setEnabled(false);
928 QString params = item->data(ParamsRole).toString();
929 QString extension = item->data(ExtensionRole).toString();
930 m_view.advanced_params->setPlainText(params);
931 QString destination = m_view.destination_list->itemData(m_view.destination_list->currentIndex()).toString();
932 if (params.contains(" s=") || destination == "audioonly") {
933 // profile has a fixed size, do not allow resize
934 m_view.rescale->setEnabled(false);
935 m_view.rescale_size->setEnabled(false);
937 m_view.rescale->setEnabled(true);
938 m_view.rescale_size->setEnabled(true);
940 KUrl url = filenameWithExtension(m_view.out_file->url(), extension);
941 m_view.out_file->setUrl(url);
942 // if (!url.isEmpty()) {
943 // QString path = url.path();
944 // int pos = path.lastIndexOf('.') + 1;
945 // if (pos == 0) path.append('.' + extension);
946 // else path = path.left(pos) + extension;
947 // m_view.out_file->setUrl(KUrl(path));
949 // m_view.out_file->setUrl(KUrl(QDir::homePath() + "/untitled." + extension));
951 m_view.out_file->setFilter("*." + extension);
952 QString edit = item->data(EditableRole).toString();
953 if (edit.isEmpty() || !edit.endsWith("customprofiles.xml")) {
954 m_view.buttonDelete->setEnabled(false);
955 m_view.buttonEdit->setEnabled(false);
957 m_view.buttonDelete->setEnabled(true);
958 m_view.buttonEdit->setEnabled(true);
961 m_view.buttonStart->setEnabled(m_view.size_list->currentItem()->toolTip().isEmpty());
964 void RenderWidget::reloadProfiles()
969 void RenderWidget::parseProfiles(QString meta, QString group, QString profile)
971 m_view.size_list->clear();
972 m_view.format_list->clear();
973 m_view.destination_list->clear();
974 m_view.destination_list->addItem(KIcon("video-x-generic"), i18n("File rendering"));
975 m_view.destination_list->addItem(KIcon("media-optical"), i18n("DVD"), "dvd");
976 m_view.destination_list->addItem(KIcon("audio-x-generic"), i18n("Audio only"), "audioonly");
977 m_view.destination_list->addItem(KIcon("applications-internet"), i18n("Web sites"), "websites");
978 m_view.destination_list->addItem(KIcon("applications-multimedia"), i18n("Media players"), "mediaplayers");
979 m_view.destination_list->addItem(KIcon("drive-harddisk"), i18n("Lossless / HQ"), "lossless");
980 m_view.destination_list->addItem(KIcon("pda"), i18n("Mobile devices"), "mobile");
982 QString exportFile = KStandardDirs::locate("appdata", "export/profiles.xml");
983 parseFile(exportFile, false);
986 QString exportFolder = KStandardDirs::locateLocal("appdata", "export/");
987 QDir directory = QDir(exportFolder);
990 QStringList fileList = directory.entryList(filter, QDir::Files);
991 // We should parse customprofiles.xml in last position, so that user profiles
992 // can also override profiles installed by KNewStuff
993 fileList.removeAll("customprofiles.xml");
994 foreach(const QString &filename, fileList)
995 parseFile(exportFolder + '/' + filename, true);
996 if (QFile::exists(exportFolder + "/customprofiles.xml")) parseFile(exportFolder + "/customprofiles.xml", true);
998 if (!meta.isEmpty()) {
999 m_view.destination_list->blockSignals(true);
1000 m_view.destination_list->setCurrentIndex(m_view.destination_list->findData(meta));
1001 m_view.destination_list->blockSignals(false);
1004 QList<QListWidgetItem *> child;
1005 if (!group.isEmpty()) child = m_view.format_list->findItems(group, Qt::MatchExactly);
1006 if (!child.isEmpty()) {
1007 for (int i = 0; i < child.count(); i++) {
1008 if (child.at(i)->data(MetaGroupRole).toString() == meta) {
1009 m_view.format_list->setCurrentItem(child.at(i));
1015 if (!profile.isEmpty()) child = m_view.size_list->findItems(profile, Qt::MatchExactly);
1016 if (!child.isEmpty()) m_view.size_list->setCurrentItem(child.at(0));
1019 void RenderWidget::parseFile(QString exportFile, bool editable)
1021 kDebug() << "// Parsing file: " << exportFile;
1022 kDebug() << "------------------------------";
1024 QFile file(exportFile);
1025 doc.setContent(&file, false);
1027 QDomElement documentElement;
1028 QDomElement profileElement;
1030 QListWidgetItem *item;
1031 QDomNodeList groups = doc.elementsByTagName("group");
1033 if (editable || groups.count() == 0) {
1034 QDomElement profiles = doc.documentElement();
1035 if (editable && profiles.attribute("version", 0).toInt() < 1) {
1036 kDebug() << "// OLD profile version";
1037 // this is an old profile version, update it
1038 QDomDocument newdoc;
1039 QDomElement newprofiles = newdoc.createElement("profiles");
1040 newprofiles.setAttribute("version", 1);
1041 newdoc.appendChild(newprofiles);
1042 QDomNodeList profilelist = doc.elementsByTagName("profile");
1043 for (int i = 0; i < profilelist.count(); i++) {
1044 QString category = i18n("Custom");
1046 QDomNode parent = profilelist.at(i).parentNode();
1047 if (!parent.isNull()) {
1048 QDomElement parentNode = parent.toElement();
1049 if (parentNode.hasAttribute("name")) category = parentNode.attribute("name");
1050 extension = parentNode.attribute("extension");
1052 profilelist.at(i).toElement().setAttribute("category", category);
1053 if (!extension.isEmpty()) profilelist.at(i).toElement().setAttribute("extension", extension);
1054 QDomNode n = profilelist.at(i).cloneNode();
1055 newprofiles.appendChild(newdoc.importNode(n, true));
1057 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1058 KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
1061 QTextStream out(&file);
1062 out << newdoc.toString();
1064 parseFile(exportFile, editable);
1068 QDomNode node = doc.elementsByTagName("profile").at(0);
1069 if (node.isNull()) {
1070 kDebug() << "// Export file: " << exportFile << " IS BROKEN";
1074 while (!node.isNull()) {
1075 QDomElement profile = node.toElement();
1076 QString profileName = profile.attribute("name");
1077 QString standard = profile.attribute("standard");
1078 QString params = profile.attribute("args");
1079 QString category = profile.attribute("category", i18n("Custom"));
1080 QString dest = profile.attribute("destinationid");
1081 QString prof_extension = profile.attribute("extension");
1082 if (!prof_extension.isEmpty()) extension = prof_extension;
1084 QList <QListWidgetItem *> list = m_view.format_list->findItems(category, Qt::MatchExactly);
1085 bool exists = false;
1086 for (int j = 0; j < list.count(); j++) {
1087 if (list.at(j)->data(MetaGroupRole) == dest) {
1093 item = new QListWidgetItem(category, m_view.format_list);
1094 item->setData(MetaGroupRole, dest);
1097 // Check if item with same name already exists and replace it,
1098 // allowing to override default profiles
1100 list = m_view.size_list->findItems(profileName, Qt::MatchExactly);
1102 for (int j = 0; j < list.count(); j++) {
1103 if (list.at(j)->data(MetaGroupRole) == dest) {
1104 QListWidgetItem *duplicate = list.takeAt(j);
1110 item = new QListWidgetItem(profileName, m_view.size_list);
1111 //kDebug() << "// ADDINg item with name: " << profileName << ", GRP" << category << ", DEST:" << dest ;
1112 item->setData(GroupRole, category);
1113 item->setData(MetaGroupRole, dest);
1114 item->setData(ExtensionRole, extension);
1115 item->setData(RenderRole, "avformat");
1116 item->setData(StandardRole, standard);
1117 item->setData(ParamsRole, params);
1118 if (profile.hasAttribute("url")) item->setData(ExtraRole, profile.attribute("url"));
1120 item->setData(EditableRole, exportFile);
1121 if (exportFile.endsWith("customprofiles.xml")) item->setIcon(KIcon("emblem-favorite"));
1122 else item->setIcon(KIcon("applications-internet"));
1124 node = doc.elementsByTagName("profile").at(count);
1132 QString profileName;
1134 QString prof_extension;
1140 while (!groups.item(i).isNull()) {
1141 documentElement = groups.item(i).toElement();
1142 QDomNode gname = documentElement.elementsByTagName("groupname").at(0);
1143 QString metagroupName;
1144 QString metagroupId;
1145 if (!gname.isNull()) {
1146 metagroupName = gname.firstChild().nodeValue();
1147 metagroupId = gname.toElement().attribute("id");
1148 if (!metagroupName.isEmpty() && !m_view.destination_list->contains(metagroupName)) {
1149 if (metagroupId == "dvd") icon = KIcon("media-optical");
1150 else if (metagroupId == "audioonly") icon = KIcon("audio-x-generic");
1151 else if (metagroupId == "websites") icon = KIcon("applications-internet");
1152 else if (metagroupId == "mediaplayers") icon = KIcon("applications-multimedia");
1153 else if (metagroupId == "lossless") icon = KIcon("drive-harddisk");
1154 else if (metagroupId == "mobile") icon = KIcon("pda");
1155 m_view.destination_list->addItem(icon, i18n(metagroupName.toUtf8().data()), metagroupId);
1158 groupName = documentElement.attribute("name", i18n("Custom"));
1159 extension = documentElement.attribute("extension", QString());
1160 renderer = documentElement.attribute("renderer", QString());
1161 QList <QListWidgetItem *> list = m_view.format_list->findItems(groupName, Qt::MatchExactly);
1162 bool exists = false;
1163 for (int j = 0; j < list.count(); j++) {
1164 if (list.at(j)->data(MetaGroupRole) == metagroupId) {
1170 item = new QListWidgetItem(groupName, m_view.format_list);
1171 item->setData(MetaGroupRole, metagroupId);
1174 QDomNode n = groups.item(i).firstChild();
1175 while (!n.isNull()) {
1176 if (n.toElement().tagName() != "profile") {
1177 n = n.nextSibling();
1180 profileElement = n.toElement();
1181 profileName = profileElement.attribute("name");
1182 standard = profileElement.attribute("standard");
1183 params = profileElement.attribute("args");
1184 prof_extension = profileElement.attribute("extension");
1185 if (!prof_extension.isEmpty()) extension = prof_extension;
1186 item = new QListWidgetItem(profileName, m_view.size_list);
1187 item->setData(GroupRole, groupName);
1188 item->setData(MetaGroupRole, metagroupId);
1189 item->setData(ExtensionRole, extension);
1190 item->setData(RenderRole, renderer);
1191 item->setData(StandardRole, standard);
1192 item->setData(ParamsRole, params);
1193 if (profileElement.hasAttribute("url")) item->setData(ExtraRole, profileElement.attribute("url"));
1194 if (editable) item->setData(EditableRole, exportFile);
1195 n = n.nextSibling();
1202 void RenderWidget::setRenderJob(const QString &dest, int progress)
1204 QTreeWidgetItem *item;
1205 QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(dest, Qt::MatchExactly, 1);
1206 if (!existing.isEmpty()) item = existing.at(0);
1208 item = new QTreeWidgetItem(m_view.running_jobs, QStringList() << QString() << dest << QString());
1209 item->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
1210 if (progress == 0) {
1211 item->setData(1, Qt::UserRole + 2, WAITINGJOB);
1212 item->setIcon(0, KIcon("media-playback-pause"));
1213 item->setData(1, Qt::UserRole, i18n("Waiting..."));
1216 item->setData(2, Qt::UserRole, progress);
1217 item->setData(1, Qt::UserRole + 2, RUNNINGJOB);
1218 if (progress == 0) {
1219 item->setIcon(0, KIcon("system-run"));
1220 item->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
1221 item->setData(1, Qt::UserRole + 1, QTime::currentTime());
1224 QTime startTime = item->data(1, Qt::UserRole + 1).toTime();
1225 int seconds = startTime.secsTo(QTime::currentTime());;
1226 const QString t = i18n("Estimated time %1", QTime().addSecs(seconds * (100 - progress) / progress).toString("hh:mm:ss"));
1227 item->setData(1, Qt::UserRole, t);
1231 void RenderWidget::setRenderStatus(const QString &dest, int status, const QString &error)
1233 QTreeWidgetItem *item;
1234 QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(dest, Qt::MatchExactly, 1);
1235 if (!existing.isEmpty()) item = existing.at(0);
1237 item = new QTreeWidgetItem(m_view.running_jobs, QStringList() << QString() << dest << QString());
1238 item->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
1240 item->setData(1, Qt::UserRole + 2, FINISHEDJOB);
1242 // Job finished successfully
1243 item->setIcon(0, KIcon("dialog-ok"));
1244 item->setData(2, Qt::UserRole, 100);
1245 QTime startTime = item->data(1, Qt::UserRole + 1).toTime();
1246 int seconds = startTime.secsTo(QTime::currentTime());
1247 const QTime tm = QTime().addSecs(seconds);
1248 const QString t = i18n("Rendering finished in %1", tm.toString("hh:mm:ss"));
1249 item->setData(1, Qt::UserRole, t);
1250 QString itemGroup = item->data(0, Qt::UserRole).toString();
1251 if (itemGroup == "dvd") {
1252 emit openDvdWizard(item->text(1), item->data(0, Qt::UserRole + 1).toString());
1253 } else if (itemGroup == "websites") {
1254 QString url = item->data(0, Qt::UserRole + 1).toString();
1255 if (!url.isEmpty()) new KRun(url, this);
1257 } else if (status == -2) {
1258 // Rendering crashed
1259 item->setData(1, Qt::UserRole, i18n("Rendering crashed"));
1260 item->setIcon(0, KIcon("dialog-close"));
1261 item->setData(2, Qt::UserRole, 100);
1262 m_view.error_log->append(i18n("<strong>Rendering of %1 crashed</strong><br />", dest));
1263 m_view.error_log->append(error);
1264 m_view.error_log->append("<hr />");
1265 m_view.error_box->setVisible(true);
1266 } else if (status == -3) {
1268 item->setData(1, Qt::UserRole, i18n("Rendering aborted"));
1269 item->setIcon(0, KIcon("dialog-cancel"));
1270 item->setData(2, Qt::UserRole, 100);
1273 checkRenderStatus();
1276 void RenderWidget::slotAbortCurrentJob()
1278 QTreeWidgetItem *current = m_view.running_jobs->currentItem();
1280 if (current->data(1, Qt::UserRole + 2).toInt() == RUNNINGJOB)
1281 emit abortProcess(current->text(1));
1289 void RenderWidget::slotCheckJob()
1291 bool activate = false;
1292 QTreeWidgetItem *current = m_view.running_jobs->currentItem();
1294 if (current->data(1, Qt::UserRole + 2).toInt() == RUNNINGJOB)
1295 m_view.abort_job->setText(i18n("Abort Job"));
1296 else m_view.abort_job->setText(i18n("Remove Job"));
1299 m_view.abort_job->setEnabled(activate);
1302 void RenderWidget::slotCLeanUpJobs()
1305 QTreeWidgetItem *current = m_view.running_jobs->topLevelItem(ix);
1307 if (current->data(1, Qt::UserRole + 2).toInt() == FINISHEDJOB)
1310 current = m_view.running_jobs->topLevelItem(ix);
1315 void RenderWidget::parseScriptFiles()
1317 QStringList scriptsFilter;
1318 scriptsFilter << "*.sh";
1319 m_view.scripts_list->clear();
1321 QTreeWidgetItem *item;
1322 // List the project scripts
1323 QStringList scriptFiles = QDir(m_projectFolder + "/scripts").entryList(scriptsFilter, QDir::Files);
1324 for (int i = 0; i < scriptFiles.size(); ++i) {
1325 KUrl scriptpath(m_projectFolder + "/scripts/" + scriptFiles.at(i));
1326 item = new QTreeWidgetItem(m_view.scripts_list, QStringList() << scriptpath.fileName());
1328 QFile file(scriptpath.path());
1329 if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
1330 while (!file.atEnd()) {
1331 QByteArray line = file.readLine();
1332 if (line.startsWith("TARGET=")) {
1333 target = QString(line).section("TARGET=", 1);
1334 target.remove(QChar('"'));
1340 item->setSizeHint(0, QSize(m_view.scripts_list->columnWidth(0), fontMetrics().height() * 2));
1341 item->setData(0, Qt::UserRole, target.simplified());
1342 item->setData(0, Qt::UserRole + 1, scriptpath.path());
1344 bool activate = false;
1345 QTreeWidgetItem *script = m_view.scripts_list->topLevelItem(0);
1347 script->setSelected(true);
1348 m_view.scripts_list->setCurrentItem(script);
1351 // m_view.start_script->setEnabled(activate);
1352 // m_view.delete_script->setEnabled(activate);
1355 void RenderWidget::slotCheckScript()
1357 bool activate = false;
1358 QTreeWidgetItemIterator it(m_view.scripts_list);
1359 if (*it) activate = true;
1360 m_view.start_script->setEnabled(activate);
1361 m_view.delete_script->setEnabled(activate);
1364 void RenderWidget::slotStartScript()
1366 QTreeWidgetItem *item = m_view.scripts_list->currentItem();
1368 QString destination = item->data(0, Qt::UserRole).toString();
1369 QString path = item->data(0, Qt::UserRole + 1).toString();
1370 // Insert new job in queue
1371 QTreeWidgetItem *renderItem;
1372 QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(destination, Qt::MatchExactly, 1);
1373 kDebug() << "------ START SCRIPT";
1374 if (!existing.isEmpty()) {
1375 renderItem = existing.at(0);
1376 if (renderItem->data(1, Qt::UserRole + 2).toInt() == RUNNINGJOB) {
1377 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"));
1380 } else renderItem = new QTreeWidgetItem(m_view.running_jobs, QStringList() << QString() << destination << QString());
1381 kDebug() << "------ START SCRIPT 2";
1382 renderItem->setData(2, Qt::UserRole, 0);
1383 renderItem->setData(1, Qt::UserRole + 2, WAITINGJOB);
1384 renderItem->setIcon(0, KIcon("media-playback-pause"));
1385 renderItem->setData(1, Qt::UserRole, i18n("Waiting..."));
1386 renderItem->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
1387 renderItem->setData(1, Qt::UserRole + 1, QTime::currentTime());
1388 renderItem->setData(1, Qt::UserRole + 3, path);
1389 renderItem->setData(1, Qt::UserRole + 4, '1');
1390 checkRenderStatus();
1391 m_view.tabWidget->setCurrentIndex(1);
1395 void RenderWidget::slotDeleteScript()
1397 QTreeWidgetItem *item = m_view.scripts_list->currentItem();
1399 QString path = item->data(0, Qt::UserRole + 1).toString();
1400 KIO::NetAccess::del(path + ".mlt", this);
1401 KIO::NetAccess::del(path, this);
1406 void RenderWidget::slotGenerateScript()
1411 void RenderWidget::slotHideLog()
1413 m_view.error_box->setVisible(false);