1 /***************************************************************************
2 * Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
21 #include <QDomDocument>
22 #include <QItemDelegate>
23 #include <QTreeWidgetItem>
24 #include <QHeaderView>
26 #include <KStandardDirs>
28 #include <KMessageBox>
31 #include "kdenlivesettings.h"
32 #include "renderwidget.h"
33 #include "ui_saveprofile_ui.h"
35 const int GroupRole = Qt::UserRole;
36 const int ExtensionRole = GroupRole + 1;
37 const int StandardRole = GroupRole + 2;
38 const int RenderRole = GroupRole + 3;
39 const int ParamsRole = GroupRole + 4;
40 const int EditableRole = GroupRole + 5;
41 const int MetaGroupRole = GroupRole + 6;
43 RenderWidget::RenderWidget(QWidget * parent): QDialog(parent) {
45 setWindowTitle(i18n("Rendering"));
46 m_view.buttonDelete->setIcon(KIcon("trash-empty"));
47 m_view.buttonDelete->setToolTip(i18n("Delete profile"));
48 m_view.buttonDelete->setEnabled(false);
50 m_view.buttonEdit->setIcon(KIcon("document-properties"));
51 m_view.buttonEdit->setToolTip(i18n("Edit profile"));
52 m_view.buttonEdit->setEnabled(false);
54 m_view.buttonSave->setIcon(KIcon("document-new"));
55 m_view.buttonSave->setToolTip(i18n("Create new profile"));
57 m_view.buttonInfo->setIcon(KIcon("help-about"));
59 if (KdenliveSettings::showrenderparams()) {
60 m_view.buttonInfo->setDown(true);
61 } else m_view.advanced_params->hide();
65 connect(m_view.buttonInfo, SIGNAL(clicked()), this, SLOT(showInfoPanel()));
67 connect(m_view.buttonSave, SIGNAL(clicked()), this, SLOT(slotSaveProfile()));
68 connect(m_view.buttonEdit, SIGNAL(clicked()), this, SLOT(slotEditProfile()));
69 connect(m_view.buttonDelete, SIGNAL(clicked()), this, SLOT(slotDeleteProfile()));
70 connect(m_view.buttonStart, SIGNAL(clicked()), this, SLOT(slotExport()));
71 connect(m_view.abort_job, SIGNAL(clicked()), this, SLOT(slotAbortCurrentJob()));
72 connect(m_view.buttonClose, SIGNAL(clicked()), this, SLOT(hide()));
73 connect(m_view.buttonClose2, SIGNAL(clicked()), this, SLOT(hide()));
74 connect(m_view.rescale, SIGNAL(toggled(bool)), m_view.rescale_size, SLOT(setEnabled(bool)));
75 connect(m_view.destination_list, SIGNAL(activated(int)), this, SLOT(refreshView()));
76 connect(m_view.out_file, SIGNAL(textChanged(const QString &)), this, SLOT(slotUpdateButtons()));
77 connect(m_view.out_file, SIGNAL(urlSelected(const KUrl &)), this, SLOT(slotUpdateButtons(const KUrl &)));
78 connect(m_view.format_list, SIGNAL(currentRowChanged(int)), this, SLOT(refreshView()));
79 connect(m_view.size_list, SIGNAL(currentRowChanged(int)), this, SLOT(refreshParams()));
81 connect(m_view.render_guide, SIGNAL(clicked(bool)), this, SLOT(slotUpdateGuideBox()));
82 connect(m_view.render_zone, SIGNAL(clicked(bool)), this, SLOT(slotUpdateGuideBox()));
83 connect(m_view.render_full, SIGNAL(clicked(bool)), this, SLOT(slotUpdateGuideBox()));
85 connect(m_view.guide_end, SIGNAL(activated(int)), this, SLOT(slotCheckStartGuidePosition()));
86 connect(m_view.guide_start, SIGNAL(activated(int)), this, SLOT(slotCheckEndGuidePosition()));
88 connect(m_view.format_selection, SIGNAL(activated(int)), this, SLOT(refreshView()));
90 m_view.buttonStart->setEnabled(false);
91 m_view.rescale_size->setEnabled(false);
92 m_view.guides_box->setVisible(false);
93 m_view.open_dvd->setVisible(false);
94 m_view.open_browser->setVisible(false);
95 m_view.error_box->setVisible(false);
97 m_view.splitter->setStretchFactor(1, 5);
98 m_view.splitter->setStretchFactor(0, 2);
100 m_view.out_file->setMode(KFile::File);
102 m_view.running_jobs->setItemDelegate(new RenderViewDelegate(this));
103 QHeaderView *header = m_view.running_jobs->header();
104 QFontMetrics fm = fontMetrics();
105 //header->resizeSection(0, fm.width("typical-name-for-a-torrent.torrent"));
106 header->setResizeMode(0, QHeaderView::Interactive);
107 header->resizeSection(0, fm.width("typical-name-for-a-file.torrent"));
108 header->setResizeMode(1, QHeaderView::Fixed);
109 header->resizeSection(0, width() * 2 / 3);
110 header->setResizeMode(1, QHeaderView::Interactive);
111 //header->setResizeMode(1, QHeaderView::Fixed);
113 focusFirstVisibleItem();
116 void RenderWidget::showInfoPanel() {
117 if (m_view.advanced_params->isVisible()) {
118 m_view.advanced_params->setVisible(false);
119 m_view.buttonInfo->setDown(false);
120 KdenliveSettings::setShowrenderparams(false);
122 m_view.advanced_params->setVisible(true);
123 m_view.buttonInfo->setDown(true);
124 KdenliveSettings::setShowrenderparams(true);
128 void RenderWidget::slotUpdateGuideBox() {
129 m_view.guides_box->setVisible(m_view.render_guide->isChecked());
132 void RenderWidget::slotCheckStartGuidePosition() {
133 if (m_view.guide_start->currentIndex() > m_view.guide_end->currentIndex())
134 m_view.guide_start->setCurrentIndex(m_view.guide_end->currentIndex());
137 void RenderWidget::slotCheckEndGuidePosition() {
138 if (m_view.guide_end->currentIndex() < m_view.guide_start->currentIndex())
139 m_view.guide_end->setCurrentIndex(m_view.guide_start->currentIndex());
142 void RenderWidget::setGuides(QDomElement guidesxml, double duration) {
143 m_view.guide_start->clear();
144 m_view.guide_end->clear();
145 QDomNodeList nodes = guidesxml.elementsByTagName("guide");
146 if (nodes.count() > 0) {
147 m_view.guide_start->addItem(i18n("Render"), "0");
148 m_view.render_guide->setEnabled(true);
149 } else m_view.render_guide->setEnabled(false);
150 for (int i = 0; i < nodes.count(); i++) {
151 QDomElement e = nodes.item(i).toElement();
153 m_view.guide_start->addItem(e.attribute("comment"), e.attribute("time").toDouble());
154 m_view.guide_end->addItem(e.attribute("comment"), e.attribute("time").toDouble());
157 if (nodes.count() > 0)
158 m_view.guide_end->addItem(i18n("End"), QString::number(duration));
161 // Will be called when the user selects an output file via the file dialog.
162 // File extension will be added automatically.
163 void RenderWidget::slotUpdateButtons(KUrl url) {
164 if (m_view.out_file->url().isEmpty()) m_view.buttonStart->setEnabled(false);
165 else m_view.buttonStart->setEnabled(true);
167 QListWidgetItem *item = m_view.size_list->currentItem();
168 QString extension = item->data(ExtensionRole).toString();
169 url = filenameWithExtension(url, extension);
170 m_view.out_file->setUrl(url);
174 // Will be called when the user changes the output file path in the text line.
175 // File extension must NOT be added, would make editing impossible!
176 void RenderWidget::slotUpdateButtons() {
177 if (m_view.out_file->url().isEmpty()) m_view.buttonStart->setEnabled(false);
178 else m_view.buttonStart->setEnabled(true);
181 void RenderWidget::slotSaveProfile() {
182 Ui::SaveProfile_UI ui;
183 QDialog *d = new QDialog(this);
185 QString customGroup = i18n("Custom");
186 QStringList groupNames;
187 for (int i = 0; i < m_view.format_list->count(); i++)
188 groupNames.append(m_view.format_list->item(i)->text());
189 if (!groupNames.contains(customGroup)) groupNames.prepend(customGroup);
190 ui.group_name->addItems(groupNames);
191 int pos = ui.group_name->findText(customGroup);
192 ui.group_name->setCurrentIndex(pos);
194 ui.parameters->setText(m_view.advanced_params->toPlainText());
195 ui.extension->setText(m_view.size_list->currentItem()->data(ExtensionRole).toString());
196 ui.profile_name->setFocus();
197 if (d->exec() == QDialog::Accepted && !ui.profile_name->text().simplified().isEmpty()) {
198 QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
200 QFile file(exportFile);
201 doc.setContent(&file, false);
204 QDomElement documentElement;
205 bool groupExists = false;
207 QString newProfileName = ui.profile_name->text().simplified();
208 QString newGroupName = ui.group_name->currentText();
209 QDomNodeList groups = doc.elementsByTagName("group");
211 if (groups.count() == 0) {
212 QDomElement profiles = doc.createElement("profiles");
213 doc.appendChild(profiles);
214 } else while (!groups.item(i).isNull()) {
215 documentElement = groups.item(i).toElement();
216 groupName = documentElement.attribute("name");
217 kDebug() << "// SAVE, PARSING FROUP: " << i << ", name: " << groupName << ", LOOK FR:Â " << newGroupName;
218 if (groupName == newGroupName) {
225 documentElement = doc.createElement("group");
226 documentElement.setAttribute("name", ui.group_name->currentText());
227 documentElement.setAttribute("renderer", "avformat");
228 doc.documentElement().appendChild(documentElement);
230 QDomElement profileElement = doc.createElement("profile");
231 profileElement.setAttribute("name", newProfileName);
232 profileElement.setAttribute("extension", ui.extension->text().simplified());
233 profileElement.setAttribute("args", ui.parameters->toPlainText().simplified());
234 documentElement.appendChild(profileElement);
236 //QCString save = doc.toString().utf8();
238 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
239 KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
243 QTextStream out(&file);
244 out << doc.toString();
246 parseProfiles(newGroupName, newProfileName);
251 void RenderWidget::slotEditProfile() {
252 QListWidgetItem *item = m_view.size_list->currentItem();
254 QString currentGroup = m_view.format_list->currentItem()->text();
256 QString params = item->data(ParamsRole).toString();
257 QString extension = item->data(ExtensionRole).toString();
258 QString currentProfile = item->text();
260 Ui::SaveProfile_UI ui;
261 QDialog *d = new QDialog(this);
263 QStringList groupNames;
264 for (int i = 0; i < m_view.format_list->count(); i++)
265 groupNames.append(m_view.format_list->item(i)->text());
266 if (!groupNames.contains(currentGroup)) groupNames.prepend(currentGroup);
267 ui.group_name->addItems(groupNames);
268 int pos = ui.group_name->findText(currentGroup);
269 ui.group_name->setCurrentIndex(pos);
270 ui.profile_name->setText(currentProfile);
271 ui.extension->setText(extension);
272 ui.parameters->setText(params);
273 ui.profile_name->setFocus();
275 if (d->exec() == QDialog::Accepted) {
277 QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
279 QFile file(exportFile);
280 doc.setContent(&file, false);
283 QDomElement documentElement;
284 bool groupExists = false;
286 QString newProfileName = ui.profile_name->text();
287 QString newGroupName = ui.group_name->currentText();
288 QDomNodeList groups = doc.elementsByTagName("group");
290 if (groups.count() == 0) {
291 QDomElement profiles = doc.createElement("profiles");
292 doc.appendChild(profiles);
293 } else while (!groups.item(i).isNull()) {
294 documentElement = groups.item(i).toElement();
295 groupName = documentElement.attribute("name");
296 kDebug() << "// SAVE, PARSING FROUP: " << i << ", name: " << groupName << ", LOOK FR:Â " << newGroupName;
297 if (groupName == newGroupName) {
304 documentElement = doc.createElement("group");
305 documentElement.setAttribute("name", ui.group_name->currentText());
306 documentElement.setAttribute("renderer", "avformat");
307 doc.documentElement().appendChild(documentElement);
309 QDomElement profileElement = doc.createElement("profile");
310 profileElement.setAttribute("name", newProfileName);
311 profileElement.setAttribute("extension", ui.extension->text().simplified());
312 profileElement.setAttribute("args", ui.parameters->toPlainText().simplified());
313 documentElement.appendChild(profileElement);
315 //QCString save = doc.toString().utf8();
317 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
318 KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
322 QTextStream out(&file);
323 out << doc.toString();
325 parseProfiles(newGroupName, newProfileName);
330 void RenderWidget::slotDeleteProfile() {
331 QString currentGroup = m_view.format_list->currentItem()->text();
332 QString currentProfile = m_view.size_list->currentItem()->text();
334 QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
336 QFile file(exportFile);
337 doc.setContent(&file, false);
340 QDomElement documentElement;
341 bool groupExists = false;
343 QDomNodeList groups = doc.elementsByTagName("group");
346 while (!groups.item(i).isNull()) {
347 documentElement = groups.item(i).toElement();
348 groupName = documentElement.attribute("name");
349 if (groupName == currentGroup) {
350 QDomNodeList children = documentElement.childNodes();
351 for (int j = 0; j < children.count(); j++) {
352 QDomElement pro = children.at(j).toElement();
353 if (pro.attribute("name") == currentProfile) {
354 groups.item(i).removeChild(children.at(j));
355 if (groups.item(i).childNodes().isEmpty())
356 doc.documentElement().removeChild(groups.item(i));
365 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
366 KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
369 QTextStream out(&file);
370 out << doc.toString();
372 parseProfiles(currentGroup);
373 focusFirstVisibleItem();
376 void RenderWidget::updateButtons() {
377 if (!m_view.size_list->currentItem() || m_view.size_list->currentItem()->isHidden()) {
378 m_view.buttonSave->setEnabled(false);
379 m_view.buttonDelete->setEnabled(false);
380 m_view.buttonEdit->setEnabled(false);
382 m_view.buttonSave->setEnabled(true);
383 if (m_view.size_list->currentItem()->data(EditableRole).toString().isEmpty()) {
384 m_view.buttonDelete->setEnabled(false);
385 m_view.buttonEdit->setEnabled(false);
387 m_view.buttonDelete->setEnabled(true);
388 m_view.buttonEdit->setEnabled(true);
394 void RenderWidget::focusFirstVisibleItem() {
395 if (m_view.size_list->currentItem() && !m_view.size_list->currentItem()->isHidden()) {
399 for (uint ix = 0; ix < m_view.size_list->count(); ix++) {
400 QListWidgetItem *item = m_view.size_list->item(ix);
401 if (item && !item->isHidden()) {
402 m_view.size_list->setCurrentRow(ix);
406 if (!m_view.size_list->currentItem()) m_view.size_list->setCurrentRow(0);
410 void RenderWidget::slotExport() {
411 QListWidgetItem *item = m_view.size_list->currentItem();
413 const QString dest = m_view.out_file->url().path();
414 if (dest.isEmpty()) return;
417 if (KMessageBox::warningYesNo(this, i18n("File already exists. Do you want to overwrite it ?")) != KMessageBox::Yes)
420 QStringList overlayargs;
421 if (m_view.tc_overlay->isChecked()) {
422 QString filterFile = KStandardDirs::locate("appdata", "metadata.properties");
423 overlayargs << "meta.attr.timecode=1" << "meta.attr.timecode.markup=#timecode";
424 overlayargs << "-attach" << "data_feed:attr_check" << "-attach";
425 overlayargs << "data_show:" + filterFile << "_fezzik=1" << "dynamic=1";
427 double startPos = -1;
429 if (m_view.render_guide->isChecked()) {
430 startPos = m_view.guide_start->itemData(m_view.guide_start->currentIndex()).toDouble();
431 endPos = m_view.guide_end->itemData(m_view.guide_end->currentIndex()).toDouble();
433 QString renderArgs = m_view.advanced_params->toPlainText();
435 // Adjust frame scale
438 if (m_view.rescale->isChecked() && m_view.rescale->isEnabled()) {
439 width = m_view.rescale_size->text().section('x', 0, 0).toInt();
440 height = m_view.rescale_size->text().section('x', 1, 1).toInt();
442 width = m_profile.width;
443 height = m_profile.height;
445 renderArgs.replace("%width", QString::number(width));
446 renderArgs.replace("%height", QString::number(height));
447 renderArgs.replace("%dar", "@" + QString::number(m_profile.display_aspect_num) + "/" + QString::number(m_profile.display_aspect_den));
450 if (m_view.scanning_list->currentIndex() == 1) renderArgs.append(" progressive=1");
451 else if (m_view.scanning_list->currentIndex() == 2) renderArgs.append(" progressive=0");
453 // disable audio if requested
454 if (!m_view.export_audio->isChecked())
455 renderArgs.append(" an=1 ");
457 // Check if the rendering profile is different from project profile,
458 // in which case we need to use the producer_comsumer from MLT
459 bool resizeProfile = false;
461 QString std = renderArgs;
462 if (resizeProfile == false && std.contains(" s=")) {
463 QString subsize = std.section(" s=", 1, 1);
464 subsize = subsize.section(' ', 0, 0).toLower();
465 const QString currentSize = QString::number(m_profile.width) + 'x' + QString::number(m_profile.height);
466 if (subsize != currentSize) resizeProfile = true;
469 // insert item in running jobs list
470 QTreeWidgetItem *renderItem;
471 QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(dest, Qt::MatchExactly);
472 if (!existing.isEmpty()) renderItem = existing.at(0);
473 else renderItem = new QTreeWidgetItem(m_view.running_jobs, QStringList() << dest << QString());
474 // Set rendering type
475 QString group = m_view.size_list->currentItem()->data(MetaGroupRole).toString();
476 if (group == "dvd" && m_view.open_dvd->isChecked()) {
477 renderItem->setData(0, Qt::UserRole, group);
478 if (renderArgs.contains("profile=")) {
479 //Â rendering profile contains an MLT profile, so pass it to the running jog item, usefull for dvd
480 QString prof = renderArgs.section("profile=", 1, 1);
481 prof = prof.section(' ', 0, 0);
482 kDebug() << "// render profile: " << prof;
483 renderItem->setData(0, Qt::UserRole + 1, prof);
487 emit doRender(dest, item->data(RenderRole).toString(), overlayargs, renderArgs.simplified().split(' '), m_view.render_zone->isChecked(), m_view.play_after->isChecked(), startPos, endPos, resizeProfile);
488 m_view.tabWidget->setCurrentIndex(1);
491 void RenderWidget::setProfile(MltVideoProfile profile) {
493 //WARNING: this way to tell the video standard is a bit hackish...
494 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);
495 else m_view.format_selection->setCurrentIndex(1);
496 m_view.scanning_list->setCurrentIndex(0);
500 void RenderWidget::refreshView() {
501 m_view.size_list->blockSignals(true);
502 QListWidgetItem *sizeItem;
505 if (m_view.destination_list->currentIndex() > 0)
506 destination = m_view.destination_list->itemData(m_view.destination_list->currentIndex()).toString();
508 if (destination == "dvd") m_view.open_dvd->setVisible(true);
509 else m_view.open_dvd->setVisible(false);
510 if (destination == "websites") m_view.open_browser->setVisible(true);
511 else m_view.open_browser->setVisible(false);
512 if (!destination.isEmpty() && QString("dvd websites audioonly").contains(destination))
513 m_view.rescale->setEnabled(false);
514 else m_view.rescale->setEnabled(true);
515 // hide groups that are not in the correct destination
516 for (int i = 0; i < m_view.format_list->count(); i++) {
517 sizeItem = m_view.format_list->item(i);
518 if (sizeItem->data(MetaGroupRole).toString() == destination)
519 sizeItem->setHidden(false);
520 else sizeItem->setHidden(true);
523 // activate first visible item
524 QListWidgetItem * item = m_view.format_list->currentItem();
525 if (!item || item->isHidden()) {
526 for (int i = 0; i < m_view.format_list->count(); i++) {
527 if (!m_view.format_list->item(i)->isHidden()) {
528 m_view.format_list->setCurrentRow(i);
532 item = m_view.format_list->currentItem();
536 for (int i = 0; i < m_view.format_list->count() && count < 2; i++) {
537 if (!m_view.format_list->isRowHidden(i)) count++;
539 if (count > 1) m_view.format_list->setVisible(true);
540 else m_view.format_list->setVisible(false);
542 QString group = item->text();
543 bool firstSelected = false;
544 const QStringList formatsList = KdenliveSettings::supportedformats();
545 const QStringList vcodecsList = KdenliveSettings::videocodecs();
546 const QStringList acodecsList = KdenliveSettings::audiocodecs();
548 for (int i = 0; i < m_view.size_list->count(); i++) {
549 sizeItem = m_view.size_list->item(i);
550 if (sizeItem->data(GroupRole) == group) {
551 std = sizeItem->data(StandardRole).toString();
552 if (!std.isEmpty()) {
553 if (std.contains("PAL", Qt::CaseInsensitive)) sizeItem->setHidden(m_view.format_selection->currentIndex() != 0);
554 else if (std.contains("NTSC", Qt::CaseInsensitive)) sizeItem->setHidden(m_view.format_selection->currentIndex() != 1);
556 sizeItem->setHidden(false);
557 if (!firstSelected) m_view.size_list->setCurrentItem(sizeItem);
558 firstSelected = true;
561 if (!sizeItem->isHidden()) {
562 // Make sure the selected profile uses an installed avformat codec / format
563 std = sizeItem->data(ParamsRole).toString();
565 if (!formatsList.isEmpty()) {
567 if (std.startsWith("f=")) format = std.section("f=", 1, 1);
568 else if (std.contains(" f=")) format = std.section(" f=", 1, 1);
569 if (!format.isEmpty()) {
570 format = format.section(' ', 0, 0).toLower();
571 if (!formatsList.contains(format)) {
572 kDebug() << "***** UNSUPPORTED F: " << format;
573 sizeItem->setHidden(true);
577 if (!acodecsList.isEmpty() && !sizeItem->isHidden()) {
579 if (std.startsWith("acodec=")) format = std.section("acodec=", 1, 1);
580 else if (std.contains(" acodec=")) format = std.section(" acodec=", 1, 1);
581 if (!format.isEmpty()) {
582 format = format.section(' ', 0, 0).toLower();
583 if (!acodecsList.contains(format)) {
584 kDebug() << "***** UNSUPPORTED ACODEC: " << format;
585 sizeItem->setHidden(true);
589 if (!vcodecsList.isEmpty() && !sizeItem->isHidden()) {
591 if (std.startsWith("vcodec=")) format = std.section("vcodec=", 1, 1);
592 else if (std.contains(" vcodec=")) format = std.section(" vcodec=", 1, 1);
593 if (!format.isEmpty()) {
594 format = format.section(' ', 0, 0).toLower();
595 if (!vcodecsList.contains(format)) {
596 kDebug() << "***** UNSUPPORTED VCODEC: " << format;
597 sizeItem->setHidden(true);
602 } else sizeItem->setHidden(true);
604 focusFirstVisibleItem();
605 m_view.size_list->blockSignals(false);
609 KUrl RenderWidget::filenameWithExtension(KUrl url, QString extension) {
611 if (!url.isEmpty()) {
613 int pos = path.lastIndexOf('.') + 1;
614 if (pos == 0) path.append('.' + extension);
615 else path = path.left(pos) + extension;
618 path = QDir::homePath() + "/untitled." + extension;
624 void RenderWidget::refreshParams() {
625 QListWidgetItem *item = m_view.size_list->currentItem();
626 if (!item || item->isHidden()) {
627 m_view.advanced_params->clear();
628 m_view.buttonStart->setEnabled(false);
631 QString params = item->data(ParamsRole).toString();
632 QString extension = item->data(ExtensionRole).toString();
633 m_view.advanced_params->setPlainText(params);
634 m_view.advanced_params->setToolTip(params);
635 KUrl url = filenameWithExtension(m_view.out_file->url(), extension);
636 m_view.out_file->setUrl(url);
637 // if (!url.isEmpty()) {
638 // QString path = url.path();
639 // int pos = path.lastIndexOf('.') + 1;
640 // if (pos == 0) path.append('.' + extension);
641 // else path = path.left(pos) + extension;
642 // m_view.out_file->setUrl(KUrl(path));
644 // m_view.out_file->setUrl(KUrl(QDir::homePath() + "/untitled." + extension));
646 m_view.out_file->setFilter("*." + extension);
648 if (item->data(EditableRole).toString().isEmpty()) {
649 m_view.buttonDelete->setEnabled(false);
650 m_view.buttonEdit->setEnabled(false);
652 m_view.buttonDelete->setEnabled(true);
653 m_view.buttonEdit->setEnabled(true);
655 m_view.buttonStart->setEnabled(true);
658 void RenderWidget::parseProfiles(QString group, QString profile) {
659 m_view.size_list->clear();
660 m_view.format_list->clear();
661 m_view.destination_list->clear();
662 m_view.destination_list->addItem(KIcon("video-x-generic"), i18n("File rendering"));
663 QString exportFile = KStandardDirs::locate("appdata", "export/profiles.xml");
664 parseFile(exportFile, false);
665 exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
666 if (QFile::exists(exportFile)) parseFile(exportFile, true);
668 QList<QListWidgetItem *> child;
669 child = m_view.format_list->findItems(group, Qt::MatchExactly);
670 if (!child.isEmpty()) m_view.format_list->setCurrentItem(child.at(0));
671 child = m_view.size_list->findItems(profile, Qt::MatchExactly);
672 if (!child.isEmpty()) m_view.size_list->setCurrentItem(child.at(0));
675 void RenderWidget::parseFile(QString exportFile, bool editable) {
677 QFile file(exportFile);
678 doc.setContent(&file, false);
680 QDomElement documentElement;
681 QDomElement profileElement;
682 QDomNodeList groups = doc.elementsByTagName("group");
684 if (groups.count() == 0) {
685 kDebug() << "// Export file: " << exportFile << " IS BROKEN";
693 QString prof_extension;
698 QListWidgetItem *item;
699 while (!groups.item(i).isNull()) {
700 documentElement = groups.item(i).toElement();
701 QDomNode gname = documentElement.elementsByTagName("groupname").at(0);
702 QString metagroupName;
704 if (!gname.isNull()) {
705 metagroupName = gname.firstChild().nodeValue();
706 metagroupId = gname.toElement().attribute("id");
707 if (!metagroupName.isEmpty() && !m_view.destination_list->contains(metagroupName)) {
708 if (metagroupId == "dvd") icon = KIcon("media-optical");
709 else if (metagroupId == "audioonly") icon = KIcon("audio-x-generic");
710 else if (metagroupId == "websites") icon = KIcon("applications-internet");
711 else if (metagroupId == "mediaplayers") icon = KIcon("applications-multimedia");
712 else if (metagroupId == "lossless") icon = KIcon("drive-harddisk");
713 m_view.destination_list->addItem(icon, i18n(metagroupName.toUtf8().data()), metagroupId);
716 groupName = documentElement.attribute("name", QString::null);
717 extension = documentElement.attribute("extension", QString::null);
718 renderer = documentElement.attribute("renderer", QString::null);
719 if (m_view.format_list->findItems(groupName, Qt::MatchExactly).isEmpty()) {
720 item = new QListWidgetItem(groupName, m_view.format_list);
721 item->setData(MetaGroupRole, metagroupId);
724 QDomNode n = groups.item(i).firstChild();
725 while (!n.isNull()) {
726 if (n.toElement().tagName() != "profile") {
730 profileElement = n.toElement();
731 profileName = profileElement.attribute("name");
732 standard = profileElement.attribute("standard");
733 params = profileElement.attribute("args");
734 prof_extension = profileElement.attribute("extension");
735 if (!prof_extension.isEmpty()) extension = prof_extension;
736 item = new QListWidgetItem(profileName, m_view.size_list);
737 item->setData(GroupRole, groupName);
738 item->setData(MetaGroupRole, metagroupId);
739 item->setData(ExtensionRole, extension);
740 item->setData(RenderRole, renderer);
741 item->setData(StandardRole, standard);
742 item->setData(ParamsRole, params);
743 if (editable) item->setData(EditableRole, "true");
751 void RenderWidget::setRenderJob(const QString &dest, int progress) {
752 QTreeWidgetItem *item;
753 QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(dest, Qt::MatchExactly);
754 if (!existing.isEmpty()) item = existing.at(0);
755 else item = new QTreeWidgetItem(m_view.running_jobs, QStringList() << dest << QString());
756 item->setData(1, Qt::UserRole, progress);
757 if (progress == 0) item->setIcon(0, KIcon("system-run"));
760 void RenderWidget::setRenderStatus(const QString &dest, int status, const QString &error) {
761 QTreeWidgetItem *item;
762 QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(dest, Qt::MatchExactly);
763 if (!existing.isEmpty()) item = existing.at(0);
764 else item = new QTreeWidgetItem(m_view.running_jobs, QStringList() << dest << QString());
766 // Job finished successfully
767 item->setIcon(0, KIcon("dialog-ok"));
768 item->setData(1, Qt::UserRole, 100);
769 QString itemGroup = item->data(0, Qt::UserRole).toString();
770 if (itemGroup == "dvd") {
771 emit openDvdWizard(item->text(0), item->data(0, Qt::UserRole + 1).toString());
774 } else if (status == -2) {
776 item->setIcon(0, KIcon("dialog-close"));
777 item->setData(1, Qt::UserRole, 0);
778 m_view.error_log->append(i18n("<strong>Rendering of %1 crashed</strong><br />", dest));
779 m_view.error_log->append(error);
780 m_view.error_log->append("<hr />");
781 m_view.error_box->setVisible(true);
782 } else if (status == -3) {
784 item->setIcon(0, KIcon("dialog-cancel"));
785 item->setData(1, Qt::UserRole, 100);
786 item->setData(1, Qt::UserRole + 1, i18n("Aborted by user"));
790 void RenderWidget::slotAbortCurrentJob() {
791 QTreeWidgetItem *current = m_view.running_jobs->currentItem();
792 if (current) emit abortProcess(current->text(0));
795 #include "renderwidget.moc"