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 <KColorScheme>
32 // #include <knewstuff2/engine.h>
34 #include <QDomDocument>
35 #include <QItemDelegate>
36 #include <QTreeWidgetItem>
37 #include <QListWidgetItem>
38 #include <QHeaderView>
41 #include <QInputDialog>
43 const int GroupRole = Qt::UserRole;
44 const int ExtensionRole = GroupRole + 1;
45 const int StandardRole = GroupRole + 2;
46 const int RenderRole = GroupRole + 3;
47 const int ParamsRole = GroupRole + 4;
48 const int EditableRole = GroupRole + 5;
49 const int MetaGroupRole = GroupRole + 6;
50 const int ExtraRole = GroupRole + 7;
53 const int WAITINGJOB = 0;
54 const int RUNNINGJOB = 1;
55 const int FINISHEDJOB = 2;
58 RenderWidget::RenderWidget(const QString &projectfolder, QWidget * parent) :
60 m_projectFolder(projectfolder)
63 setWindowTitle(i18n("Rendering"));
64 m_view.buttonDelete->setIcon(KIcon("trash-empty"));
65 m_view.buttonDelete->setToolTip(i18n("Delete profile"));
66 m_view.buttonDelete->setEnabled(false);
68 m_view.buttonEdit->setIcon(KIcon("document-properties"));
69 m_view.buttonEdit->setToolTip(i18n("Edit profile"));
70 m_view.buttonEdit->setEnabled(false);
72 m_view.buttonSave->setIcon(KIcon("document-new"));
73 m_view.buttonSave->setToolTip(i18n("Create new profile"));
75 m_view.buttonInfo->setIcon(KIcon("help-about"));
76 m_view.hide_log->setIcon(KIcon("go-down"));
78 if (KdenliveSettings::showrenderparams()) {
79 m_view.buttonInfo->setDown(true);
80 } else m_view.advanced_params->hide();
82 m_view.rescale_size->setInputMask("0099\\x0099");
83 m_view.rescale_size->setText("320x240");
86 QMenu *renderMenu = new QMenu(i18n("Start Rendering"), this);
87 QAction *renderAction = renderMenu->addAction(KIcon("video-x-generic"), i18n("Render to File"));
88 connect(renderAction, SIGNAL(triggered()), this, SLOT(slotExport()));
89 QAction *scriptAction = renderMenu->addAction(KIcon("application-x-shellscript"), i18n("Generate Script"));
90 connect(scriptAction, SIGNAL(triggered()), this, SLOT(slotGenerateScript()));
92 m_view.buttonStart->setMenu(renderMenu);
93 m_view.buttonStart->setPopupMode(QToolButton::MenuButtonPopup);
94 m_view.buttonStart->setDefaultAction(renderAction);
95 m_view.buttonStart->setToolButtonStyle(Qt::ToolButtonTextOnly);
96 m_view.abort_job->setEnabled(false);
97 m_view.start_script->setEnabled(false);
98 m_view.delete_script->setEnabled(false);
100 m_view.format_list->setAlternatingRowColors(true);
101 m_view.size_list->setAlternatingRowColors(true);
106 connect(m_view.start_script, SIGNAL(clicked()), this, SLOT(slotStartScript()));
107 connect(m_view.delete_script, SIGNAL(clicked()), this, SLOT(slotDeleteScript()));
108 connect(m_view.scripts_list, SIGNAL(itemSelectionChanged()), this, SLOT(slotCheckScript()));
109 connect(m_view.running_jobs, SIGNAL(itemSelectionChanged()), this, SLOT(slotCheckJob()));
111 connect(m_view.buttonInfo, SIGNAL(clicked()), this, SLOT(showInfoPanel()));
113 connect(m_view.buttonSave, SIGNAL(clicked()), this, SLOT(slotSaveProfile()));
114 connect(m_view.buttonEdit, SIGNAL(clicked()), this, SLOT(slotEditProfile()));
115 connect(m_view.buttonDelete, SIGNAL(clicked()), this, SLOT(slotDeleteProfile()));
116 connect(m_view.abort_job, SIGNAL(clicked()), this, SLOT(slotAbortCurrentJob()));
117 connect(m_view.clean_up, SIGNAL(clicked()), this, SLOT(slotCLeanUpJobs()));
118 connect(m_view.hide_log, SIGNAL(clicked()), this, SLOT(slotHideLog()));
120 connect(m_view.buttonClose, SIGNAL(clicked()), this, SLOT(hide()));
121 connect(m_view.buttonClose2, SIGNAL(clicked()), this, SLOT(hide()));
122 connect(m_view.buttonClose3, SIGNAL(clicked()), this, SLOT(hide()));
123 connect(m_view.rescale, SIGNAL(toggled(bool)), m_view.rescale_size, SLOT(setEnabled(bool)));
124 connect(m_view.destination_list, SIGNAL(activated(int)), this, SLOT(refreshView()));
125 connect(m_view.out_file, SIGNAL(textChanged(const QString &)), this, SLOT(slotUpdateButtons()));
126 connect(m_view.out_file, SIGNAL(urlSelected(const KUrl &)), this, SLOT(slotUpdateButtons(const KUrl &)));
127 connect(m_view.format_list, SIGNAL(currentRowChanged(int)), this, SLOT(refreshView()));
128 connect(m_view.size_list, SIGNAL(currentRowChanged(int)), this, SLOT(refreshParams()));
130 connect(m_view.size_list, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(slotEditItem(QListWidgetItem *)));
132 connect(m_view.render_guide, SIGNAL(clicked(bool)), this, SLOT(slotUpdateGuideBox()));
133 connect(m_view.render_zone, SIGNAL(clicked(bool)), this, SLOT(slotUpdateGuideBox()));
134 connect(m_view.render_full, SIGNAL(clicked(bool)), this, SLOT(slotUpdateGuideBox()));
136 connect(m_view.guide_end, SIGNAL(activated(int)), this, SLOT(slotCheckStartGuidePosition()));
137 connect(m_view.guide_start, SIGNAL(activated(int)), this, SLOT(slotCheckEndGuidePosition()));
139 connect(m_view.format_selection, SIGNAL(activated(int)), this, SLOT(refreshView()));
141 m_view.buttonStart->setEnabled(false);
142 m_view.rescale_size->setEnabled(false);
143 m_view.guides_box->setVisible(false);
144 m_view.open_dvd->setVisible(false);
145 m_view.create_chapter->setVisible(false);
146 m_view.open_browser->setVisible(false);
147 m_view.error_box->setVisible(false);
149 m_view.splitter->setStretchFactor(1, 5);
150 m_view.splitter->setStretchFactor(0, 2);
152 m_view.out_file->setMode(KFile::File);
154 m_view.running_jobs->setHeaderLabels(QStringList() << QString() << i18n("File") << i18n("Progress"));
155 m_view.running_jobs->setItemDelegate(new RenderViewDelegate(this));
157 QHeaderView *header = m_view.running_jobs->header();
158 QFontMetrics fm = fontMetrics();
159 //header->resizeSection(0, fm.width("typical-name-for-a-torrent.torrent"));
160 header->setResizeMode(0, QHeaderView::Fixed);
161 header->resizeSection(0, 30);
162 header->setResizeMode(1, QHeaderView::Interactive);
163 header->resizeSection(1, fm.width("typical-name-for-a-file.torrent"));
164 header->setResizeMode(2, QHeaderView::Fixed);
165 header->resizeSection(1, width() * 2 / 3);
166 header->setResizeMode(2, QHeaderView::Interactive);
167 //header->setResizeMode(1, QHeaderView::Fixed);
169 m_view.scripts_list->setHeaderLabels(QStringList() << i18n("Script Files"));
170 m_view.scripts_list->setItemDelegate(new RenderScriptDelegate(this));
173 focusFirstVisibleItem();
176 void RenderWidget::slotEditItem(QListWidgetItem *item)
178 QString edit = item->data(EditableRole).toString();
179 if (edit.isEmpty() || !edit.endsWith("customprofiles.xml")) slotSaveProfile();
180 else slotEditProfile();
183 void RenderWidget::showInfoPanel()
185 if (m_view.advanced_params->isVisible()) {
186 m_view.advanced_params->setVisible(false);
187 m_view.buttonInfo->setDown(false);
188 KdenliveSettings::setShowrenderparams(false);
190 m_view.advanced_params->setVisible(true);
191 m_view.buttonInfo->setDown(true);
192 KdenliveSettings::setShowrenderparams(true);
196 void RenderWidget::setDocumentPath(const QString path)
198 m_projectFolder = path;
199 const QString fileName = m_view.out_file->url().fileName();
200 m_view.out_file->setUrl(KUrl(m_projectFolder + '/' + fileName));
204 void RenderWidget::slotUpdateGuideBox()
206 m_view.guides_box->setVisible(m_view.render_guide->isChecked());
209 void RenderWidget::slotCheckStartGuidePosition()
211 if (m_view.guide_start->currentIndex() > m_view.guide_end->currentIndex())
212 m_view.guide_start->setCurrentIndex(m_view.guide_end->currentIndex());
215 void RenderWidget::slotCheckEndGuidePosition()
217 if (m_view.guide_end->currentIndex() < m_view.guide_start->currentIndex())
218 m_view.guide_end->setCurrentIndex(m_view.guide_start->currentIndex());
221 void RenderWidget::setGuides(QDomElement guidesxml, double duration)
223 m_view.guide_start->clear();
224 m_view.guide_end->clear();
225 QDomNodeList nodes = guidesxml.elementsByTagName("guide");
226 if (nodes.count() > 0) {
227 m_view.guide_start->addItem(i18n("Beginning"), "0");
228 m_view.render_guide->setEnabled(true);
229 m_view.create_chapter->setEnabled(true);
231 m_view.render_guide->setEnabled(false);
232 m_view.create_chapter->setEnabled(false);
234 for (int i = 0; i < nodes.count(); i++) {
235 QDomElement e = nodes.item(i).toElement();
237 m_view.guide_start->addItem(e.attribute("comment"), e.attribute("time").toDouble());
238 m_view.guide_end->addItem(e.attribute("comment"), e.attribute("time").toDouble());
241 if (nodes.count() > 0)
242 m_view.guide_end->addItem(i18n("End"), QString::number(duration));
246 * Will be called when the user selects an output file via the file dialog.
247 * File extension will be added automatically.
249 void RenderWidget::slotUpdateButtons(KUrl url)
251 if (m_view.out_file->url().isEmpty()) m_view.buttonStart->setEnabled(false);
253 updateButtons(); // This also checks whether the selected format is available
254 //m_view.buttonStart->setEnabled(true);
257 QListWidgetItem *item = m_view.size_list->currentItem();
258 QString extension = item->data(ExtensionRole).toString();
259 url = filenameWithExtension(url, extension);
260 m_view.out_file->setUrl(url);
265 * Will be called when the user changes the output file path in the text line.
266 * File extension must NOT be added, would make editing impossible!
268 void RenderWidget::slotUpdateButtons()
270 if (m_view.out_file->url().isEmpty()) m_view.buttonStart->setEnabled(false);
271 else updateButtons(); // This also checks whether the selected format is available
272 //else m_view.buttonStart->setEnabled(true);
275 void RenderWidget::slotSaveProfile()
277 //TODO: update to correctly use metagroups
278 Ui::SaveProfile_UI ui;
279 QDialog *d = new QDialog(this);
282 for (int i = 0; i < m_view.destination_list->count(); i++)
283 ui.destination_list->addItem(m_view.destination_list->itemIcon(i), m_view.destination_list->itemText(i), m_view.destination_list->itemData(i, Qt::UserRole));
285 ui.destination_list->setCurrentIndex(m_view.destination_list->currentIndex());
286 QString dest = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
288 QString customGroup = m_view.format_list->currentItem()->text();
289 if (customGroup.isEmpty()) customGroup = i18n("Custom");
290 ui.group_name->setText(customGroup);
292 ui.parameters->setText(m_view.advanced_params->toPlainText());
293 ui.extension->setText(m_view.size_list->currentItem()->data(ExtensionRole).toString());
294 ui.profile_name->setFocus();
296 if (d->exec() == QDialog::Accepted && !ui.profile_name->text().simplified().isEmpty()) {
297 QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
299 QFile file(exportFile);
300 doc.setContent(&file, false);
302 QDomElement documentElement;
303 QDomElement profiles = doc.documentElement();
304 if (profiles.isNull() || profiles.tagName() != "profiles") {
306 profiles = doc.createElement("profiles");
307 profiles.setAttribute("version", 1);
308 doc.appendChild(profiles);
310 int version = profiles.attribute("version", 0).toInt();
312 kDebug() << "// OLD profile version";
314 profiles = doc.createElement("profiles");
315 profiles.setAttribute("version", 1);
316 doc.appendChild(profiles);
319 QString newProfileName = ui.profile_name->text().simplified();
320 QString newGroupName = ui.group_name->text().simplified();
321 if (newGroupName.isEmpty()) newGroupName = i18n("Custom");
322 QString newMetaGroupId = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
323 QDomNodeList profilelist = doc.elementsByTagName("profile");
325 while (!profilelist.item(i).isNull()) {
326 // make sure a profile with same name doesn't exist
327 documentElement = profilelist.item(i).toElement();
328 QString profileName = documentElement.attribute("name");
329 if (profileName == newProfileName) {
330 // a profile with that same name already exists
332 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);
334 if (profileName == newProfileName) {
335 profiles.removeChild(profilelist.item(i));
342 QDomElement profileElement = doc.createElement("profile");
343 profileElement.setAttribute("name", newProfileName);
344 profileElement.setAttribute("category", newGroupName);
345 profileElement.setAttribute("destinationid", newMetaGroupId);
346 profileElement.setAttribute("extension", ui.extension->text().simplified());
347 profileElement.setAttribute("args", ui.parameters->toPlainText().simplified());
348 profiles.appendChild(profileElement);
350 //QCString save = doc.toString().utf8();
352 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
353 KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
357 QTextStream out(&file);
358 out << doc.toString();
359 if (file.error() != QFile::NoError) {
360 KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
366 parseProfiles(newMetaGroupId, newGroupName, newProfileName);
371 void RenderWidget::slotEditProfile()
373 QListWidgetItem *item = m_view.size_list->currentItem();
375 QString currentGroup = m_view.format_list->currentItem()->text();
377 QString params = item->data(ParamsRole).toString();
378 QString extension = item->data(ExtensionRole).toString();
379 QString currentProfile = item->text();
381 Ui::SaveProfile_UI ui;
382 QDialog *d = new QDialog(this);
385 for (int i = 0; i < m_view.destination_list->count(); i++)
386 ui.destination_list->addItem(m_view.destination_list->itemIcon(i), m_view.destination_list->itemText(i), m_view.destination_list->itemData(i, Qt::UserRole));
388 ui.destination_list->setCurrentIndex(m_view.destination_list->currentIndex());
389 QString dest = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
391 QString customGroup = m_view.format_list->currentItem()->text();
392 if (customGroup.isEmpty()) customGroup = i18n("Custom");
393 ui.group_name->setText(customGroup);
395 ui.profile_name->setText(currentProfile);
396 ui.extension->setText(extension);
397 ui.parameters->setText(params);
398 ui.profile_name->setFocus();
399 d->setWindowTitle(i18n("Edit Profile"));
400 if (d->exec() == QDialog::Accepted) {
401 slotDeleteProfile(false);
402 QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
404 QFile file(exportFile);
405 doc.setContent(&file, false);
407 QDomElement documentElement;
408 QDomElement profiles = doc.documentElement();
410 if (profiles.isNull() || profiles.tagName() != "profiles") {
412 profiles = doc.createElement("profiles");
413 profiles.setAttribute("version", 1);
414 doc.appendChild(profiles);
417 int version = profiles.attribute("version", 0).toInt();
419 kDebug() << "// OLD profile version";
421 profiles = doc.createElement("profiles");
422 profiles.setAttribute("version", 1);
423 doc.appendChild(profiles);
426 QString newProfileName = ui.profile_name->text().simplified();
427 QString newGroupName = ui.group_name->text().simplified();
428 if (newGroupName.isEmpty()) newGroupName = i18n("Custom");
429 QString newMetaGroupId = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
430 QDomNodeList profilelist = doc.elementsByTagName("profile");
432 while (!profilelist.item(i).isNull()) {
433 // make sure a profile with same name doesn't exist
434 documentElement = profilelist.item(i).toElement();
435 QString profileName = documentElement.attribute("name");
436 if (profileName == newProfileName) {
437 // a profile with that same name already exists
439 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);
441 if (profileName == newProfileName) {
442 profiles.removeChild(profilelist.item(i));
449 QDomElement profileElement = doc.createElement("profile");
450 profileElement.setAttribute("name", newProfileName);
451 profileElement.setAttribute("category", newGroupName);
452 profileElement.setAttribute("destinationid", newMetaGroupId);
453 profileElement.setAttribute("extension", ui.extension->text().simplified());
454 profileElement.setAttribute("args", ui.parameters->toPlainText().simplified());
455 profiles.appendChild(profileElement);
457 //QCString save = doc.toString().utf8();
459 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
460 KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
463 QTextStream out(&file);
464 out << doc.toString();
465 if (file.error() != QFile::NoError) {
466 KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
471 parseProfiles(newMetaGroupId, newGroupName, newProfileName);
475 void RenderWidget::slotDeleteProfile(bool refresh)
477 //TODO: delete a profile installed by KNewStuff the easy way
479 QString edit = m_view.size_list->currentItem()->data(EditableRole).toString();
480 if (!edit.endsWith("customprofiles.xml")) {
481 // This is a KNewStuff installed file, process through KNS
482 KNS::Engine engine(0);
483 if (engine.init("kdenlive_render.knsrc")) {
484 KNS::Entry::List entries;
488 QString currentGroup = m_view.format_list->currentItem()->text();
489 QString currentProfile = m_view.size_list->currentItem()->text();
490 QString metaGroupId = m_view.destination_list->itemData(m_view.destination_list->currentIndex(), Qt::UserRole).toString();
492 QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
494 QFile file(exportFile);
495 doc.setContent(&file, false);
498 QDomElement documentElement;
499 QDomNodeList profiles = doc.elementsByTagName("profile");
505 while (!profiles.item(i).isNull()) {
506 documentElement = profiles.item(i).toElement();
507 profileName = documentElement.attribute("name");
508 groupName = documentElement.attribute("category");
509 destination = documentElement.attribute("destinationid");
511 if (profileName == currentProfile && groupName == currentGroup && destination == metaGroupId) {
512 kDebug() << "// GOT it: " << profileName;
513 doc.documentElement().removeChild(profiles.item(i));
519 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
520 KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
523 QTextStream out(&file);
524 out << doc.toString();
525 if (file.error() != QFile::NoError) {
526 KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
532 parseProfiles(metaGroupId, currentGroup);
533 focusFirstVisibleItem();
537 void RenderWidget::updateButtons()
539 if (!m_view.size_list->currentItem() || m_view.size_list->currentItem()->isHidden()) {
540 m_view.buttonSave->setEnabled(false);
541 m_view.buttonDelete->setEnabled(false);
542 m_view.buttonEdit->setEnabled(false);
543 m_view.buttonStart->setEnabled(false);
545 m_view.buttonSave->setEnabled(true);
546 m_view.buttonStart->setEnabled(m_view.size_list->currentItem()->toolTip().isEmpty());
547 QString edit = m_view.size_list->currentItem()->data(EditableRole).toString();
548 if (edit.isEmpty() || !edit.endsWith("customprofiles.xml")) {
549 m_view.buttonDelete->setEnabled(false);
550 m_view.buttonEdit->setEnabled(false);
552 m_view.buttonDelete->setEnabled(true);
553 m_view.buttonEdit->setEnabled(true);
559 void RenderWidget::focusFirstVisibleItem()
561 if (m_view.size_list->currentItem() && !m_view.size_list->currentItem()->isHidden()) {
565 for (int ix = 0; ix < m_view.size_list->count(); ix++) {
566 QListWidgetItem *item = m_view.size_list->item(ix);
567 if (item && !item->isHidden()) {
568 m_view.size_list->setCurrentRow(ix);
572 if (!m_view.size_list->currentItem()) m_view.size_list->setCurrentRow(0);
576 void RenderWidget::slotExport(bool scriptExport)
578 QListWidgetItem *item = m_view.size_list->currentItem();
581 QString dest = m_view.out_file->url().path();
582 if (dest.isEmpty()) return;
584 // Check whether target file has an extension.
585 // If not, ask whether extension should be added or not.
586 QString extension = item->data(ExtensionRole).toString();
587 if (!dest.endsWith(extension)) {
588 if (KMessageBox::questionYesNo(this, i18n("File has no extension. Add extension (%1)?", extension)) == KMessageBox::Yes) {
589 dest.append("." + extension);
595 if (KMessageBox::warningYesNo(this, i18n("Output file already exists. Do you want to overwrite it?")) != KMessageBox::Yes)
600 QStringList overlayargs;
601 if (m_view.tc_overlay->isChecked()) {
602 QString filterFile = KStandardDirs::locate("appdata", "metadata.properties");
603 overlayargs << "meta.attr.timecode=1" << "meta.attr.timecode.markup=#timecode";
604 overlayargs << "-attach" << "data_feed:attr_check" << "-attach";
605 overlayargs << "data_show:" + filterFile << "_loader=1" << "dynamic=1";
607 double startPos = -1;
609 if (m_view.render_guide->isChecked()) {
610 startPos = m_view.guide_start->itemData(m_view.guide_start->currentIndex()).toDouble();
611 endPos = m_view.guide_end->itemData(m_view.guide_end->currentIndex()).toDouble();
613 QString renderArgs = m_view.advanced_params->toPlainText().simplified();
615 // Adjust frame scale
618 if (m_view.rescale->isChecked() && m_view.rescale->isEnabled()) {
619 width = m_view.rescale_size->text().section('x', 0, 0).toInt();
620 height = m_view.rescale_size->text().section('x', 1, 1).toInt();
622 width = m_profile.width;
623 height = m_profile.height;
625 renderArgs.replace("%dar", '@' + QString::number(m_profile.display_aspect_num) + '/' + QString::number(m_profile.display_aspect_den));
628 if (m_view.scanning_list->currentIndex() == 1) renderArgs.append(" progressive=1");
629 else if (m_view.scanning_list->currentIndex() == 2) renderArgs.append(" progressive=0");
631 // disable audio if requested
632 if (!m_view.export_audio->isChecked())
633 renderArgs.append(" an=1 ");
635 // Check if the rendering profile is different from project profile,
636 // in which case we need to use the producer_comsumer from MLT
637 QString std = renderArgs;
638 QString destination = m_view.destination_list->itemData(m_view.destination_list->currentIndex()).toString();
639 const QString currentSize = QString::number(width) + 'x' + QString::number(height);
640 QString subsize = currentSize;
641 if (std.startsWith("s=")) {
642 subsize = std.section(' ', 0, 0).toLower();
643 subsize = subsize.section("=", 1, 1);
644 } else if (std.contains(" s=")) {
645 subsize = std.section(" s=", 1, 1);
646 subsize = subsize.section(' ', 0, 0).toLower();
647 } else if (destination != "audioonly" && m_view.rescale->isChecked() && m_view.rescale->isEnabled()) {
648 subsize = QString(" s=%1x%2").arg(width).arg(height);
649 // Add current size parameter
650 renderArgs.append(subsize);
652 bool resizeProfile = (subsize != currentSize);
654 QString group = m_view.size_list->currentItem()->data(MetaGroupRole).toString();
656 QStringList renderParameters;
657 renderParameters << dest << item->data(RenderRole).toString() << renderArgs.simplified();
658 renderParameters << QString::number(m_view.render_zone->isChecked()) << QString::number(m_view.play_after->isChecked());
659 renderParameters << QString::number(startPos) << QString::number(endPos) << QString::number(resizeProfile);
665 QString scriptsFolder = m_projectFolder + "/scripts/";
666 KStandardDirs::makeDir(scriptsFolder);
667 QString path = scriptsFolder + i18n("script") + QString::number(ix).rightJustified(3, '0', false) + ".sh";
668 while (QFile::exists(path)) {
670 path = scriptsFolder + i18n("script") + QString::number(ix).rightJustified(3, '0', false) + ".sh";
672 scriptName = QInputDialog::getText(this, i18n("Create Render Script"), i18n("Script name (will be saved in: %1)", scriptsFolder), QLineEdit::Normal, KUrl(path).fileName(), &ok);
673 if (!ok || scriptName.isEmpty()) return;
674 scriptName.prepend(scriptsFolder);
677 if (KMessageBox::warningYesNo(this, i18n("Script file already exists. Do you want to overwrite it?")) != KMessageBox::Yes)
680 renderParameters << scriptName;
681 if (group == "dvd") renderParameters << QString::number(m_view.create_chapter->isChecked());
682 else renderParameters << QString::number(false);
683 emit doRender(renderParameters, overlayargs);
684 QTimer::singleShot(400, this, SLOT(parseScriptFiles()));
685 m_view.tabWidget->setCurrentIndex(2);
688 renderParameters << scriptName;
689 m_view.tabWidget->setCurrentIndex(1);
691 // insert item in running jobs list
692 QTreeWidgetItem *renderItem;
693 QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(dest, Qt::MatchExactly, 1);
694 if (!existing.isEmpty()) {
695 renderItem = existing.at(0);
696 if (renderItem->data(1, Qt::UserRole + 2).toInt() == RUNNINGJOB) {
697 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"));
700 renderItem->setData(1, Qt::UserRole + 4, QString());
702 renderItem = new QTreeWidgetItem(m_view.running_jobs, QStringList() << QString() << dest << QString());
703 renderItem->setData(1, Qt::UserRole + 2, WAITINGJOB);
704 renderItem->setIcon(0, KIcon("media-playback-pause"));
705 renderItem->setData(1, Qt::UserRole, i18n("Waiting..."));
707 renderItem->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
708 renderItem->setData(1, Qt::UserRole + 1, QTime::currentTime());
709 renderItem->setData(1, Qt::UserRole + 2, overlayargs);
711 // Set rendering type
712 if (group == "dvd") {
713 renderParameters << QString::number(m_view.create_chapter->isChecked());
714 if (m_view.open_dvd->isChecked()) {
715 renderItem->setData(0, Qt::UserRole, group);
716 if (renderArgs.contains("profile=")) {
717 //Â rendering profile contains an MLT profile, so pass it to the running jog item, useful for dvd
718 QString prof = renderArgs.section("profile=", 1, 1);
719 prof = prof.section(' ', 0, 0);
720 kDebug() << "// render profile: " << prof;
721 renderItem->setData(0, Qt::UserRole + 1, prof);
725 renderParameters << QString::number(false);
726 if (group == "websites" && m_view.open_browser->isChecked()) {
727 renderItem->setData(0, Qt::UserRole, group);
729 QString url = m_view.size_list->currentItem()->data(ExtraRole).toString();
730 renderItem->setData(0, Qt::UserRole + 1, url);
735 renderItem->setData(1, Qt::UserRole + 3, renderParameters);
739 void RenderWidget::checkRenderStatus()
741 QTreeWidgetItem *item = m_view.running_jobs->topLevelItem(0);
743 if (item->data(1, Qt::UserRole + 2).toInt() == RUNNINGJOB) break;
744 else if (item->data(1, Qt::UserRole + 2).toInt() == WAITINGJOB) {
745 item->setData(1, Qt::UserRole + 1, QTime::currentTime());
746 if (item->data(1, Qt::UserRole + 4).isNull()) {
747 emit doRender(item->data(1, Qt::UserRole + 3).toStringList(), item->data(1, Qt::UserRole + 2).toStringList());
750 QProcess::startDetached(item->data(1, Qt::UserRole + 3).toString());
754 item = m_view.running_jobs->itemBelow(item);
758 void RenderWidget::setProfile(MltVideoProfile profile)
761 //WARNING: this way to tell the video standard is a bit hackish...
762 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);
763 else m_view.format_selection->setCurrentIndex(1);
764 m_view.scanning_list->setCurrentIndex(0);
768 void RenderWidget::refreshView()
770 m_view.size_list->blockSignals(true);
771 QListWidgetItem *sizeItem;
774 KIcon brokenIcon("dialog-close");
775 if (m_view.destination_list->currentIndex() > 0)
776 destination = m_view.destination_list->itemData(m_view.destination_list->currentIndex()).toString();
779 if (destination == "dvd") {
780 m_view.open_dvd->setVisible(true);
781 m_view.create_chapter->setVisible(true);
783 m_view.open_dvd->setVisible(false);
784 m_view.create_chapter->setVisible(false);
786 if (destination == "websites") m_view.open_browser->setVisible(true);
787 else m_view.open_browser->setVisible(false);
788 if (!destination.isEmpty() && QString("dvd websites audioonly").contains(destination))
789 m_view.rescale->setEnabled(false);
790 else m_view.rescale->setEnabled(true);
791 // hide groups that are not in the correct destination
792 for (int i = 0; i < m_view.format_list->count(); i++) {
793 sizeItem = m_view.format_list->item(i);
794 if (sizeItem->data(MetaGroupRole).toString() == destination) {
795 sizeItem->setHidden(false);
796 //kDebug() << "// SET GRP:: " << sizeItem->text() << ", METY:" << sizeItem->data(MetaGroupRole).toString();
797 } else sizeItem->setHidden(true);
800 // activate first visible item
801 QListWidgetItem * item = m_view.format_list->currentItem();
802 if (!item || item->isHidden()) {
803 for (int i = 0; i < m_view.format_list->count(); i++) {
804 if (!m_view.format_list->item(i)->isHidden()) {
805 m_view.format_list->setCurrentRow(i);
809 item = m_view.format_list->currentItem();
811 if (!item || item->isHidden()) {
812 m_view.format_list->setEnabled(false);
813 m_view.size_list->setEnabled(false);
816 m_view.format_list->setEnabled(true);
817 m_view.size_list->setEnabled(true);
820 for (int i = 0; i < m_view.format_list->count() && count < 2; i++) {
821 if (!m_view.format_list->isRowHidden(i)) count++;
823 if (count > 1) m_view.format_list->setVisible(true);
824 else m_view.format_list->setVisible(false);
826 QString group = item->text();
827 bool firstSelected = false;
828 const QStringList formatsList = KdenliveSettings::supportedformats();
829 const QStringList vcodecsList = KdenliveSettings::videocodecs();
830 const QStringList acodecsList = KdenliveSettings::audiocodecs();
832 KColorScheme scheme(palette().currentColorGroup(), KColorScheme::Window);
833 const QColor disabled = scheme.foreground(KColorScheme::InactiveText).color();
834 const QColor disabledbg = scheme.background(KColorScheme::NegativeBackground).color();
836 for (int i = 0; i < m_view.size_list->count(); i++) {
837 sizeItem = m_view.size_list->item(i);
838 if ((sizeItem->data(GroupRole) == group || sizeItem->data(GroupRole).toString().isEmpty()) && sizeItem->data(MetaGroupRole) == destination) {
839 std = sizeItem->data(StandardRole).toString();
840 if (!std.isEmpty()) {
841 if (std.contains("PAL", Qt::CaseInsensitive)) sizeItem->setHidden(m_view.format_selection->currentIndex() != 0);
842 else if (std.contains("NTSC", Qt::CaseInsensitive)) sizeItem->setHidden(m_view.format_selection->currentIndex() != 1);
844 sizeItem->setHidden(false);
845 if (!firstSelected) m_view.size_list->setCurrentItem(sizeItem);
846 firstSelected = true;
849 if (!sizeItem->isHidden()) {
850 // Make sure the selected profile uses an installed avformat codec / format
851 std = sizeItem->data(ParamsRole).toString();
853 if (!formatsList.isEmpty()) {
855 if (std.startsWith("f=")) format = std.section("f=", 1, 1);
856 else if (std.contains(" f=")) format = std.section(" f=", 1, 1);
857 if (!format.isEmpty()) {
858 format = format.section(' ', 0, 0).toLower();
859 if (!formatsList.contains(format)) {
860 kDebug() << "***** UNSUPPORTED F: " << format;
861 //sizeItem->setHidden(true);
862 //sizeItem->setFlags(Qt::ItemIsSelectable);
863 sizeItem->setToolTip(i18n("Unsupported video format: %1", format));
864 sizeItem->setIcon(brokenIcon);
865 sizeItem->setForeground(disabled);
869 if (!acodecsList.isEmpty() && !sizeItem->isHidden()) {
871 if (std.startsWith("acodec=")) format = std.section("acodec=", 1, 1);
872 else if (std.contains(" acodec=")) format = std.section(" acodec=", 1, 1);
873 if (!format.isEmpty()) {
874 format = format.section(' ', 0, 0).toLower();
875 if (!acodecsList.contains(format)) {
876 kDebug() << "***** UNSUPPORTED ACODEC: " << format;
877 //sizeItem->setHidden(true);
878 //sizeItem->setFlags(Qt::ItemIsSelectable);
879 sizeItem->setToolTip(i18n("Unsupported audio codec: %1", format));
880 sizeItem->setIcon(brokenIcon);
881 sizeItem->setForeground(disabled);
882 sizeItem->setBackground(disabledbg);
886 if (!vcodecsList.isEmpty() && !sizeItem->isHidden()) {
888 if (std.startsWith("vcodec=")) format = std.section("vcodec=", 1, 1);
889 else if (std.contains(" vcodec=")) format = std.section(" vcodec=", 1, 1);
890 if (!format.isEmpty()) {
891 format = format.section(' ', 0, 0).toLower();
892 if (!vcodecsList.contains(format)) {
893 kDebug() << "***** UNSUPPORTED VCODEC: " << format;
894 //sizeItem->setHidden(true);
895 //sizeItem->setFlags(Qt::ItemIsSelectable);
896 sizeItem->setToolTip(i18n("Unsupported video codec: %1", format));
897 sizeItem->setIcon(brokenIcon);
898 sizeItem->setForeground(disabled);
903 } else sizeItem->setHidden(true);
905 focusFirstVisibleItem();
906 m_view.size_list->blockSignals(false);
910 KUrl RenderWidget::filenameWithExtension(KUrl url, QString extension)
913 if (!url.isEmpty()) {
915 int pos = path.lastIndexOf('.') + 1;
916 if (pos == 0) path.append('.' + extension);
917 else path = path.left(pos) + extension;
920 path = m_projectFolder + "/untitled." + extension;
927 * Called when a new format or size has been selected.
929 void RenderWidget::refreshParams()
931 // Format not available (e.g. codec not installed); Disable start button
932 QListWidgetItem *item = m_view.size_list->currentItem();
933 if (!item || item->isHidden()) {
934 m_view.advanced_params->clear();
935 m_view.buttonStart->setEnabled(false);
938 QString params = item->data(ParamsRole).toString();
939 QString extension = item->data(ExtensionRole).toString();
940 m_view.advanced_params->setPlainText(params);
941 QString destination = m_view.destination_list->itemData(m_view.destination_list->currentIndex()).toString();
942 if (params.contains(" s=") || destination == "audioonly") {
943 // profile has a fixed size, do not allow resize
944 m_view.rescale->setEnabled(false);
945 m_view.rescale_size->setEnabled(false);
947 m_view.rescale->setEnabled(true);
948 m_view.rescale_size->setEnabled(true);
950 KUrl url = filenameWithExtension(m_view.out_file->url(), extension);
951 m_view.out_file->setUrl(url);
952 // if (!url.isEmpty()) {
953 // QString path = url.path();
954 // int pos = path.lastIndexOf('.') + 1;
955 // if (pos == 0) path.append('.' + extension);
956 // else path = path.left(pos) + extension;
957 // m_view.out_file->setUrl(KUrl(path));
959 // m_view.out_file->setUrl(KUrl(QDir::homePath() + "/untitled." + extension));
961 m_view.out_file->setFilter("*." + extension);
962 QString edit = item->data(EditableRole).toString();
963 if (edit.isEmpty() || !edit.endsWith("customprofiles.xml")) {
964 m_view.buttonDelete->setEnabled(false);
965 m_view.buttonEdit->setEnabled(false);
967 m_view.buttonDelete->setEnabled(true);
968 m_view.buttonEdit->setEnabled(true);
971 m_view.buttonStart->setEnabled(m_view.size_list->currentItem()->toolTip().isEmpty());
974 void RenderWidget::reloadProfiles()
979 void RenderWidget::parseProfiles(QString meta, QString group, QString profile)
981 m_view.size_list->clear();
982 m_view.format_list->clear();
983 m_view.destination_list->clear();
984 m_view.destination_list->addItem(KIcon("video-x-generic"), i18n("File rendering"));
985 m_view.destination_list->addItem(KIcon("media-optical"), i18n("DVD"), "dvd");
986 m_view.destination_list->addItem(KIcon("audio-x-generic"), i18n("Audio only"), "audioonly");
987 m_view.destination_list->addItem(KIcon("applications-internet"), i18n("Web sites"), "websites");
988 m_view.destination_list->addItem(KIcon("applications-multimedia"), i18n("Media players"), "mediaplayers");
989 m_view.destination_list->addItem(KIcon("drive-harddisk"), i18n("Lossless / HQ"), "lossless");
990 m_view.destination_list->addItem(KIcon("pda"), i18n("Mobile devices"), "mobile");
992 QString exportFile = KStandardDirs::locate("appdata", "export/profiles.xml");
993 parseFile(exportFile, false);
996 QString exportFolder = KStandardDirs::locateLocal("appdata", "export/");
997 QDir directory = QDir(exportFolder);
1000 QStringList fileList = directory.entryList(filter, QDir::Files);
1001 // We should parse customprofiles.xml in last position, so that user profiles
1002 // can also override profiles installed by KNewStuff
1003 fileList.removeAll("customprofiles.xml");
1004 foreach(const QString &filename, fileList)
1005 parseFile(exportFolder + '/' + filename, true);
1006 if (QFile::exists(exportFolder + "/customprofiles.xml")) parseFile(exportFolder + "/customprofiles.xml", true);
1008 if (!meta.isEmpty()) {
1009 m_view.destination_list->blockSignals(true);
1010 m_view.destination_list->setCurrentIndex(m_view.destination_list->findData(meta));
1011 m_view.destination_list->blockSignals(false);
1014 QList<QListWidgetItem *> child;
1015 if (!group.isEmpty()) child = m_view.format_list->findItems(group, Qt::MatchExactly);
1016 if (!child.isEmpty()) {
1017 for (int i = 0; i < child.count(); i++) {
1018 if (child.at(i)->data(MetaGroupRole).toString() == meta) {
1019 m_view.format_list->setCurrentItem(child.at(i));
1025 if (!profile.isEmpty()) child = m_view.size_list->findItems(profile, Qt::MatchExactly);
1026 if (!child.isEmpty()) m_view.size_list->setCurrentItem(child.at(0));
1029 void RenderWidget::parseFile(QString exportFile, bool editable)
1031 kDebug() << "// Parsing file: " << exportFile;
1032 kDebug() << "------------------------------";
1034 QFile file(exportFile);
1035 doc.setContent(&file, false);
1037 QDomElement documentElement;
1038 QDomElement profileElement;
1040 QListWidgetItem *item;
1041 QDomNodeList groups = doc.elementsByTagName("group");
1043 if (editable || groups.count() == 0) {
1044 QDomElement profiles = doc.documentElement();
1045 if (editable && profiles.attribute("version", 0).toInt() < 1) {
1046 kDebug() << "// OLD profile version";
1047 // this is an old profile version, update it
1048 QDomDocument newdoc;
1049 QDomElement newprofiles = newdoc.createElement("profiles");
1050 newprofiles.setAttribute("version", 1);
1051 newdoc.appendChild(newprofiles);
1052 QDomNodeList profilelist = doc.elementsByTagName("profile");
1053 for (int i = 0; i < profilelist.count(); i++) {
1054 QString category = i18n("Custom");
1056 QDomNode parent = profilelist.at(i).parentNode();
1057 if (!parent.isNull()) {
1058 QDomElement parentNode = parent.toElement();
1059 if (parentNode.hasAttribute("name")) category = parentNode.attribute("name");
1060 extension = parentNode.attribute("extension");
1062 profilelist.at(i).toElement().setAttribute("category", category);
1063 if (!extension.isEmpty()) profilelist.at(i).toElement().setAttribute("extension", extension);
1064 QDomNode n = profilelist.at(i).cloneNode();
1065 newprofiles.appendChild(newdoc.importNode(n, true));
1067 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1068 KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
1071 QTextStream out(&file);
1072 out << newdoc.toString();
1074 parseFile(exportFile, editable);
1078 QDomNode node = doc.elementsByTagName("profile").at(0);
1079 if (node.isNull()) {
1080 kDebug() << "// Export file: " << exportFile << " IS BROKEN";
1084 while (!node.isNull()) {
1085 QDomElement profile = node.toElement();
1086 QString profileName = profile.attribute("name");
1087 QString standard = profile.attribute("standard");
1088 QString params = profile.attribute("args");
1089 QString category = profile.attribute("category", i18n("Custom"));
1090 QString dest = profile.attribute("destinationid");
1091 QString prof_extension = profile.attribute("extension");
1092 if (!prof_extension.isEmpty()) extension = prof_extension;
1094 QList <QListWidgetItem *> list = m_view.format_list->findItems(category, Qt::MatchExactly);
1095 bool exists = false;
1096 for (int j = 0; j < list.count(); j++) {
1097 if (list.at(j)->data(MetaGroupRole) == dest) {
1103 item = new QListWidgetItem(category, m_view.format_list);
1104 item->setData(MetaGroupRole, dest);
1107 // Check if item with same name already exists and replace it,
1108 // allowing to override default profiles
1110 list = m_view.size_list->findItems(profileName, Qt::MatchExactly);
1112 for (int j = 0; j < list.count(); j++) {
1113 if (list.at(j)->data(MetaGroupRole) == dest) {
1114 QListWidgetItem *duplicate = list.takeAt(j);
1120 item = new QListWidgetItem(profileName, m_view.size_list);
1121 //kDebug() << "// ADDINg item with name: " << profileName << ", GRP" << category << ", DEST:" << dest ;
1122 item->setData(GroupRole, category);
1123 item->setData(MetaGroupRole, dest);
1124 item->setData(ExtensionRole, extension);
1125 item->setData(RenderRole, "avformat");
1126 item->setData(StandardRole, standard);
1127 item->setData(ParamsRole, params);
1128 if (profile.hasAttribute("url")) item->setData(ExtraRole, profile.attribute("url"));
1130 item->setData(EditableRole, exportFile);
1131 if (exportFile.endsWith("customprofiles.xml")) item->setIcon(KIcon("emblem-favorite"));
1132 else item->setIcon(KIcon("applications-internet"));
1134 node = doc.elementsByTagName("profile").at(count);
1142 QString profileName;
1144 QString prof_extension;
1150 while (!groups.item(i).isNull()) {
1151 documentElement = groups.item(i).toElement();
1152 QDomNode gname = documentElement.elementsByTagName("groupname").at(0);
1153 QString metagroupName;
1154 QString metagroupId;
1155 if (!gname.isNull()) {
1156 metagroupName = gname.firstChild().nodeValue();
1157 metagroupId = gname.toElement().attribute("id");
1158 if (!metagroupName.isEmpty() && !m_view.destination_list->contains(metagroupName)) {
1159 if (metagroupId == "dvd") icon = KIcon("media-optical");
1160 else if (metagroupId == "audioonly") icon = KIcon("audio-x-generic");
1161 else if (metagroupId == "websites") icon = KIcon("applications-internet");
1162 else if (metagroupId == "mediaplayers") icon = KIcon("applications-multimedia");
1163 else if (metagroupId == "lossless") icon = KIcon("drive-harddisk");
1164 else if (metagroupId == "mobile") icon = KIcon("pda");
1165 m_view.destination_list->addItem(icon, i18n(metagroupName.toUtf8().data()), metagroupId);
1168 groupName = documentElement.attribute("name", i18n("Custom"));
1169 extension = documentElement.attribute("extension", QString());
1170 renderer = documentElement.attribute("renderer", QString());
1171 QList <QListWidgetItem *> list = m_view.format_list->findItems(groupName, Qt::MatchExactly);
1172 bool exists = false;
1173 for (int j = 0; j < list.count(); j++) {
1174 if (list.at(j)->data(MetaGroupRole) == metagroupId) {
1180 item = new QListWidgetItem(groupName, m_view.format_list);
1181 item->setData(MetaGroupRole, metagroupId);
1184 QDomNode n = groups.item(i).firstChild();
1185 while (!n.isNull()) {
1186 if (n.toElement().tagName() != "profile") {
1187 n = n.nextSibling();
1190 profileElement = n.toElement();
1191 profileName = profileElement.attribute("name");
1192 standard = profileElement.attribute("standard");
1193 params = profileElement.attribute("args");
1194 prof_extension = profileElement.attribute("extension");
1195 if (!prof_extension.isEmpty()) extension = prof_extension;
1196 item = new QListWidgetItem(profileName, m_view.size_list);
1197 item->setData(GroupRole, groupName);
1198 item->setData(MetaGroupRole, metagroupId);
1199 item->setData(ExtensionRole, extension);
1200 item->setData(RenderRole, renderer);
1201 item->setData(StandardRole, standard);
1202 item->setData(ParamsRole, params);
1203 if (profileElement.hasAttribute("url")) item->setData(ExtraRole, profileElement.attribute("url"));
1204 if (editable) item->setData(EditableRole, exportFile);
1205 n = n.nextSibling();
1212 void RenderWidget::setRenderJob(const QString &dest, int progress)
1214 QTreeWidgetItem *item;
1215 QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(dest, Qt::MatchExactly, 1);
1216 if (!existing.isEmpty()) item = existing.at(0);
1218 item = new QTreeWidgetItem(m_view.running_jobs, QStringList() << QString() << dest << QString());
1219 item->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
1220 if (progress == 0) {
1221 item->setData(1, Qt::UserRole + 2, WAITINGJOB);
1222 item->setIcon(0, KIcon("media-playback-pause"));
1223 item->setData(1, Qt::UserRole, i18n("Waiting..."));
1226 item->setData(2, Qt::UserRole, progress);
1227 item->setData(1, Qt::UserRole + 2, RUNNINGJOB);
1228 if (progress == 0) {
1229 item->setIcon(0, KIcon("system-run"));
1230 item->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
1231 item->setData(1, Qt::UserRole + 1, QTime::currentTime());
1234 QTime startTime = item->data(1, Qt::UserRole + 1).toTime();
1235 int seconds = startTime.secsTo(QTime::currentTime());;
1236 const QString t = i18n("Estimated time %1", QTime().addSecs(seconds * (100 - progress) / progress).toString("hh:mm:ss"));
1237 item->setData(1, Qt::UserRole, t);
1241 void RenderWidget::setRenderStatus(const QString &dest, int status, const QString &error)
1243 QTreeWidgetItem *item;
1244 QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(dest, Qt::MatchExactly, 1);
1245 if (!existing.isEmpty()) item = existing.at(0);
1247 item = new QTreeWidgetItem(m_view.running_jobs, QStringList() << QString() << dest << QString());
1248 item->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
1250 item->setData(1, Qt::UserRole + 2, FINISHEDJOB);
1252 // Job finished successfully
1253 item->setIcon(0, KIcon("dialog-ok"));
1254 item->setData(2, Qt::UserRole, 100);
1255 QTime startTime = item->data(1, Qt::UserRole + 1).toTime();
1256 int seconds = startTime.secsTo(QTime::currentTime());
1257 const QTime tm = QTime().addSecs(seconds);
1258 const QString t = i18n("Rendering finished in %1", tm.toString("hh:mm:ss"));
1259 item->setData(1, Qt::UserRole, t);
1260 QString itemGroup = item->data(0, Qt::UserRole).toString();
1261 if (itemGroup == "dvd") {
1262 emit openDvdWizard(item->text(1), item->data(0, Qt::UserRole + 1).toString());
1263 } else if (itemGroup == "websites") {
1264 QString url = item->data(0, Qt::UserRole + 1).toString();
1265 if (!url.isEmpty()) new KRun(url, this);
1267 } else if (status == -2) {
1268 // Rendering crashed
1269 item->setData(1, Qt::UserRole, i18n("Rendering crashed"));
1270 item->setIcon(0, KIcon("dialog-close"));
1271 item->setData(2, Qt::UserRole, 100);
1272 m_view.error_log->append(i18n("<strong>Rendering of %1 crashed</strong><br />", dest));
1273 m_view.error_log->append(error);
1274 m_view.error_log->append("<hr />");
1275 m_view.error_box->setVisible(true);
1276 } else if (status == -3) {
1278 item->setData(1, Qt::UserRole, i18n("Rendering aborted"));
1279 item->setIcon(0, KIcon("dialog-cancel"));
1280 item->setData(2, Qt::UserRole, 100);
1283 checkRenderStatus();
1286 void RenderWidget::slotAbortCurrentJob()
1288 QTreeWidgetItem *current = m_view.running_jobs->currentItem();
1290 if (current->data(1, Qt::UserRole + 2).toInt() == RUNNINGJOB)
1291 emit abortProcess(current->text(1));
1299 void RenderWidget::slotCheckJob()
1301 bool activate = false;
1302 QTreeWidgetItem *current = m_view.running_jobs->currentItem();
1304 if (current->data(1, Qt::UserRole + 2).toInt() == RUNNINGJOB)
1305 m_view.abort_job->setText(i18n("Abort Job"));
1306 else m_view.abort_job->setText(i18n("Remove Job"));
1309 m_view.abort_job->setEnabled(activate);
1312 void RenderWidget::slotCLeanUpJobs()
1315 QTreeWidgetItem *current = m_view.running_jobs->topLevelItem(ix);
1317 if (current->data(1, Qt::UserRole + 2).toInt() == FINISHEDJOB)
1320 current = m_view.running_jobs->topLevelItem(ix);
1325 void RenderWidget::parseScriptFiles()
1327 QStringList scriptsFilter;
1328 scriptsFilter << "*.sh";
1329 m_view.scripts_list->clear();
1331 QTreeWidgetItem *item;
1332 // List the project scripts
1333 QStringList scriptFiles = QDir(m_projectFolder + "/scripts").entryList(scriptsFilter, QDir::Files);
1334 for (int i = 0; i < scriptFiles.size(); ++i) {
1335 KUrl scriptpath(m_projectFolder + "/scripts/" + scriptFiles.at(i));
1336 item = new QTreeWidgetItem(m_view.scripts_list, QStringList() << scriptpath.fileName());
1338 QFile file(scriptpath.path());
1339 if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
1340 while (!file.atEnd()) {
1341 QByteArray line = file.readLine();
1342 if (line.startsWith("TARGET=")) {
1343 target = QString(line).section("TARGET=", 1);
1344 target.remove(QChar('"'));
1350 item->setSizeHint(0, QSize(m_view.scripts_list->columnWidth(0), fontMetrics().height() * 2));
1351 item->setData(0, Qt::UserRole, target.simplified());
1352 item->setData(0, Qt::UserRole + 1, scriptpath.path());
1354 bool activate = false;
1355 QTreeWidgetItem *script = m_view.scripts_list->topLevelItem(0);
1357 script->setSelected(true);
1358 m_view.scripts_list->setCurrentItem(script);
1361 // m_view.start_script->setEnabled(activate);
1362 // m_view.delete_script->setEnabled(activate);
1365 void RenderWidget::slotCheckScript()
1367 bool activate = false;
1368 QTreeWidgetItemIterator it(m_view.scripts_list);
1369 if (*it) activate = true;
1370 m_view.start_script->setEnabled(activate);
1371 m_view.delete_script->setEnabled(activate);
1374 void RenderWidget::slotStartScript()
1376 QTreeWidgetItem *item = m_view.scripts_list->currentItem();
1378 QString destination = item->data(0, Qt::UserRole).toString();
1379 QString path = item->data(0, Qt::UserRole + 1).toString();
1380 // Insert new job in queue
1381 QTreeWidgetItem *renderItem;
1382 QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(destination, Qt::MatchExactly, 1);
1383 kDebug() << "------ START SCRIPT";
1384 if (!existing.isEmpty()) {
1385 renderItem = existing.at(0);
1386 if (renderItem->data(1, Qt::UserRole + 2).toInt() == RUNNINGJOB) {
1387 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"));
1390 } else renderItem = new QTreeWidgetItem(m_view.running_jobs, QStringList() << QString() << destination << QString());
1391 kDebug() << "------ START SCRIPT 2";
1392 renderItem->setData(2, Qt::UserRole, 0);
1393 renderItem->setData(1, Qt::UserRole + 2, WAITINGJOB);
1394 renderItem->setIcon(0, KIcon("media-playback-pause"));
1395 renderItem->setData(1, Qt::UserRole, i18n("Waiting..."));
1396 renderItem->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
1397 renderItem->setData(1, Qt::UserRole + 1, QTime::currentTime());
1398 renderItem->setData(1, Qt::UserRole + 3, path);
1399 renderItem->setData(1, Qt::UserRole + 4, '1');
1400 checkRenderStatus();
1401 m_view.tabWidget->setCurrentIndex(1);
1405 void RenderWidget::slotDeleteScript()
1407 QTreeWidgetItem *item = m_view.scripts_list->currentItem();
1409 QString path = item->data(0, Qt::UserRole + 1).toString();
1410 KIO::NetAccess::del(path + ".mlt", this);
1411 KIO::NetAccess::del(path, this);
1416 void RenderWidget::slotGenerateScript()
1421 void RenderWidget::slotHideLog()
1423 m_view.error_box->setVisible(false);