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;
51 RenderWidget::RenderWidget(const QString &projectfolder, QWidget * parent): QDialog(parent), m_projectFolder(projectfolder)
54 setWindowTitle(i18n("Rendering"));
55 m_view.buttonDelete->setIcon(KIcon("trash-empty"));
56 m_view.buttonDelete->setToolTip(i18n("Delete profile"));
57 m_view.buttonDelete->setEnabled(false);
59 m_view.buttonEdit->setIcon(KIcon("document-properties"));
60 m_view.buttonEdit->setToolTip(i18n("Edit profile"));
61 m_view.buttonEdit->setEnabled(false);
63 m_view.buttonSave->setIcon(KIcon("document-new"));
64 m_view.buttonSave->setToolTip(i18n("Create new profile"));
66 m_view.buttonInfo->setIcon(KIcon("help-about"));
68 if (KdenliveSettings::showrenderparams()) {
69 m_view.buttonInfo->setDown(true);
70 } else m_view.advanced_params->hide();
72 m_view.rescale_size->setInputMask("0099\\x0099");
73 m_view.rescale_size->setText("320x240");
76 QMenu *renderMenu = new QMenu(i18n("Start Rendering"), this);
77 QAction *renderAction = renderMenu->addAction(KIcon("video-x-generic"), i18n("Render to File"));
78 connect(renderAction, SIGNAL(triggered()), this, SLOT(slotExport()));
79 QAction *scriptAction = renderMenu->addAction(KIcon("application-x-shellscript"), i18n("Generate Script"));
80 connect(scriptAction, SIGNAL(triggered()), this, SLOT(slotGenerateScript()));
82 m_view.buttonStart->setMenu(renderMenu);
83 m_view.buttonStart->setPopupMode(QToolButton::MenuButtonPopup);
84 m_view.buttonStart->setDefaultAction(renderAction);
85 m_view.buttonStart->setToolButtonStyle(Qt::ToolButtonTextOnly);
86 m_view.abort_job->setEnabled(false);
87 m_view.start_script->setEnabled(false);
88 m_view.delete_script->setEnabled(false);
90 m_view.format_list->setAlternatingRowColors(true);
91 m_view.size_list->setAlternatingRowColors(true);
96 connect(m_view.start_script, SIGNAL(clicked()), this, SLOT(slotStartScript()));
97 connect(m_view.delete_script, SIGNAL(clicked()), this, SLOT(slotDeleteScript()));
98 connect(m_view.scripts_list, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(slotCheckScript()));
99 connect(m_view.running_jobs, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(slotCheckJob()));
101 connect(m_view.buttonInfo, SIGNAL(clicked()), this, SLOT(showInfoPanel()));
103 connect(m_view.buttonSave, SIGNAL(clicked()), this, SLOT(slotSaveProfile()));
104 connect(m_view.buttonEdit, SIGNAL(clicked()), this, SLOT(slotEditProfile()));
105 connect(m_view.buttonDelete, SIGNAL(clicked()), this, SLOT(slotDeleteProfile()));
106 connect(m_view.abort_job, SIGNAL(clicked()), this, SLOT(slotAbortCurrentJob()));
107 connect(m_view.buttonClose, SIGNAL(clicked()), this, SLOT(hide()));
108 connect(m_view.buttonClose2, SIGNAL(clicked()), this, SLOT(hide()));
109 connect(m_view.buttonClose3, SIGNAL(clicked()), this, SLOT(hide()));
110 connect(m_view.rescale, SIGNAL(toggled(bool)), m_view.rescale_size, SLOT(setEnabled(bool)));
111 connect(m_view.destination_list, SIGNAL(activated(int)), this, SLOT(refreshView()));
112 connect(m_view.out_file, SIGNAL(textChanged(const QString &)), this, SLOT(slotUpdateButtons()));
113 connect(m_view.out_file, SIGNAL(urlSelected(const KUrl &)), this, SLOT(slotUpdateButtons(const KUrl &)));
114 connect(m_view.format_list, SIGNAL(currentRowChanged(int)), this, SLOT(refreshView()));
115 connect(m_view.size_list, SIGNAL(currentRowChanged(int)), this, SLOT(refreshParams()));
117 connect(m_view.size_list, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(slotEditItem(QListWidgetItem *)));
119 connect(m_view.render_guide, SIGNAL(clicked(bool)), this, SLOT(slotUpdateGuideBox()));
120 connect(m_view.render_zone, SIGNAL(clicked(bool)), this, SLOT(slotUpdateGuideBox()));
121 connect(m_view.render_full, SIGNAL(clicked(bool)), this, SLOT(slotUpdateGuideBox()));
123 connect(m_view.guide_end, SIGNAL(activated(int)), this, SLOT(slotCheckStartGuidePosition()));
124 connect(m_view.guide_start, SIGNAL(activated(int)), this, SLOT(slotCheckEndGuidePosition()));
126 connect(m_view.format_selection, SIGNAL(activated(int)), this, SLOT(refreshView()));
128 m_view.buttonStart->setEnabled(false);
129 m_view.rescale_size->setEnabled(false);
130 m_view.guides_box->setVisible(false);
131 m_view.open_dvd->setVisible(false);
132 m_view.open_browser->setVisible(false);
133 m_view.error_box->setVisible(false);
135 m_view.splitter->setStretchFactor(1, 5);
136 m_view.splitter->setStretchFactor(0, 2);
138 m_view.out_file->setMode(KFile::File);
140 m_view.running_jobs->setHeaderLabels(QStringList() << QString() << i18n("File") << i18n("Progress"));
141 m_view.running_jobs->setItemDelegate(new RenderViewDelegate(this));
143 QHeaderView *header = m_view.running_jobs->header();
144 QFontMetrics fm = fontMetrics();
145 //header->resizeSection(0, fm.width("typical-name-for-a-torrent.torrent"));
146 header->setResizeMode(0, QHeaderView::Fixed);
147 header->resizeSection(0, 30);
148 header->setResizeMode(1, QHeaderView::Interactive);
149 header->resizeSection(1, fm.width("typical-name-for-a-file.torrent"));
150 header->setResizeMode(2, QHeaderView::Fixed);
151 header->resizeSection(1, width() * 2 / 3);
152 header->setResizeMode(2, QHeaderView::Interactive);
153 //header->setResizeMode(1, QHeaderView::Fixed);
155 m_view.scripts_list->setHeaderLabels(QStringList() << i18n("Script Files"));
156 m_view.scripts_list->setItemDelegate(new RenderScriptDelegate(this));
159 focusFirstVisibleItem();
162 void RenderWidget::slotEditItem(QListWidgetItem *item)
164 QString edit = item->data(EditableRole).toString();
165 if (edit.isEmpty() || !edit.endsWith("customprofiles.xml")) slotSaveProfile();
166 else slotEditProfile();
169 void RenderWidget::showInfoPanel()
171 if (m_view.advanced_params->isVisible()) {
172 m_view.advanced_params->setVisible(false);
173 m_view.buttonInfo->setDown(false);
174 KdenliveSettings::setShowrenderparams(false);
176 m_view.advanced_params->setVisible(true);
177 m_view.buttonInfo->setDown(true);
178 KdenliveSettings::setShowrenderparams(true);
182 void RenderWidget::setDocumentPath(const QString path)
184 m_projectFolder = path;
185 const QString fileName = m_view.out_file->url().fileName();
186 m_view.out_file->setUrl(KUrl(m_projectFolder + '/' + fileName));
190 void RenderWidget::slotUpdateGuideBox()
192 m_view.guides_box->setVisible(m_view.render_guide->isChecked());
195 void RenderWidget::slotCheckStartGuidePosition()
197 if (m_view.guide_start->currentIndex() > m_view.guide_end->currentIndex())
198 m_view.guide_start->setCurrentIndex(m_view.guide_end->currentIndex());
201 void RenderWidget::slotCheckEndGuidePosition()
203 if (m_view.guide_end->currentIndex() < m_view.guide_start->currentIndex())
204 m_view.guide_end->setCurrentIndex(m_view.guide_start->currentIndex());
207 void RenderWidget::setGuides(QDomElement guidesxml, double duration)
209 m_view.guide_start->clear();
210 m_view.guide_end->clear();
211 QDomNodeList nodes = guidesxml.elementsByTagName("guide");
212 if (nodes.count() > 0) {
213 m_view.guide_start->addItem(i18n("Render"), "0");
214 m_view.render_guide->setEnabled(true);
215 } else m_view.render_guide->setEnabled(false);
216 for (int i = 0; i < nodes.count(); i++) {
217 QDomElement e = nodes.item(i).toElement();
219 m_view.guide_start->addItem(e.attribute("comment"), e.attribute("time").toDouble());
220 m_view.guide_end->addItem(e.attribute("comment"), e.attribute("time").toDouble());
223 if (nodes.count() > 0)
224 m_view.guide_end->addItem(i18n("End"), QString::number(duration));
227 // Will be called when the user selects an output file via the file dialog.
228 // File extension will be added automatically.
229 void RenderWidget::slotUpdateButtons(KUrl url)
231 if (m_view.out_file->url().isEmpty()) m_view.buttonStart->setEnabled(false);
232 else m_view.buttonStart->setEnabled(true);
234 QListWidgetItem *item = m_view.size_list->currentItem();
235 QString extension = item->data(ExtensionRole).toString();
236 url = filenameWithExtension(url, extension);
237 m_view.out_file->setUrl(url);
241 // Will be called when the user changes the output file path in the text line.
242 // File extension must NOT be added, would make editing impossible!
243 void RenderWidget::slotUpdateButtons()
245 if (m_view.out_file->url().isEmpty()) m_view.buttonStart->setEnabled(false);
246 else m_view.buttonStart->setEnabled(true);
249 void RenderWidget::slotSaveProfile()
251 //TODO: update to correctly use metagroups
252 Ui::SaveProfile_UI ui;
253 QDialog *d = new QDialog(this);
256 for (int i = 0; i < m_view.destination_list->count(); i++)
257 ui.destination_list->addItem(m_view.destination_list->itemIcon(i), m_view.destination_list->itemText(i), m_view.destination_list->itemData(i, Qt::UserRole));
259 ui.destination_list->setCurrentIndex(m_view.destination_list->currentIndex());
260 QString dest = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
262 QString customGroup = m_view.format_list->currentItem()->text();
263 if (customGroup.isEmpty()) customGroup = i18n("Custom");
264 ui.group_name->setText(customGroup);
266 ui.parameters->setText(m_view.advanced_params->toPlainText());
267 ui.extension->setText(m_view.size_list->currentItem()->data(ExtensionRole).toString());
268 ui.profile_name->setFocus();
269 if (d->exec() == QDialog::Accepted && !ui.profile_name->text().simplified().isEmpty()) {
270 QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
272 QFile file(exportFile);
273 doc.setContent(&file, false);
275 QDomElement documentElement;
276 QDomElement profiles = doc.documentElement();
277 if (profiles.isNull() || profiles.tagName() != "profiles") {
279 profiles = doc.createElement("profiles");
280 profiles.setAttribute("version", 1);
281 doc.appendChild(profiles);
283 int version = profiles.attribute("version", 0).toInt();
285 kDebug() << "// OLD profile version";
287 profiles = doc.createElement("profiles");
288 profiles.setAttribute("version", 1);
289 doc.appendChild(profiles);
292 QString newProfileName = ui.profile_name->text().simplified();
293 QString newGroupName = ui.group_name->text().simplified();
294 if (newGroupName.isEmpty()) newGroupName = i18n("Custom");
295 QString newMetaGroupId = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
296 QDomNodeList profilelist = doc.elementsByTagName("profile");
298 while (!profilelist.item(i).isNull()) {
299 // make sure a profile with same name doesn't exist
300 documentElement = profilelist.item(i).toElement();
301 QString profileName = documentElement.attribute("name");
302 if (profileName == newProfileName) {
303 // a profile with that same name already exists
305 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);
307 if (profileName == newProfileName) {
308 profiles.removeChild(profilelist.item(i));
315 QDomElement profileElement = doc.createElement("profile");
316 profileElement.setAttribute("name", newProfileName);
317 profileElement.setAttribute("category", newGroupName);
318 profileElement.setAttribute("destinationid", newMetaGroupId);
319 profileElement.setAttribute("extension", ui.extension->text().simplified());
320 profileElement.setAttribute("args", ui.parameters->toPlainText().simplified());
321 profiles.appendChild(profileElement);
323 //QCString save = doc.toString().utf8();
325 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
326 KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
330 QTextStream out(&file);
331 out << doc.toString();
332 if (file.error() != QFile::NoError) {
333 KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
338 parseProfiles(newMetaGroupId, newGroupName, newProfileName);
343 void RenderWidget::slotEditProfile()
345 QListWidgetItem *item = m_view.size_list->currentItem();
347 QString currentGroup = m_view.format_list->currentItem()->text();
349 QString params = item->data(ParamsRole).toString();
350 QString extension = item->data(ExtensionRole).toString();
351 QString currentProfile = item->text();
353 Ui::SaveProfile_UI ui;
354 QDialog *d = new QDialog(this);
357 for (int i = 0; i < m_view.destination_list->count(); i++)
358 ui.destination_list->addItem(m_view.destination_list->itemIcon(i), m_view.destination_list->itemText(i), m_view.destination_list->itemData(i, Qt::UserRole));
360 ui.destination_list->setCurrentIndex(m_view.destination_list->currentIndex());
361 QString dest = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
363 QString customGroup = m_view.format_list->currentItem()->text();
364 if (customGroup.isEmpty()) customGroup = i18n("Custom");
365 ui.group_name->setText(customGroup);
367 ui.profile_name->setText(currentProfile);
368 ui.extension->setText(extension);
369 ui.parameters->setText(params);
370 ui.profile_name->setFocus();
371 d->setWindowTitle(i18n("Edit Profile"));
372 if (d->exec() == QDialog::Accepted) {
373 slotDeleteProfile(false);
374 QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
376 QFile file(exportFile);
377 doc.setContent(&file, false);
379 QDomElement documentElement;
380 QDomElement profiles = doc.documentElement();
382 if (profiles.isNull() || profiles.tagName() != "profiles") {
384 profiles = doc.createElement("profiles");
385 profiles.setAttribute("version", 1);
386 doc.appendChild(profiles);
389 int version = profiles.attribute("version", 0).toInt();
391 kDebug() << "// OLD profile version";
393 profiles = doc.createElement("profiles");
394 profiles.setAttribute("version", 1);
395 doc.appendChild(profiles);
398 QString newProfileName = ui.profile_name->text().simplified();
399 QString newGroupName = ui.group_name->text().simplified();
400 if (newGroupName.isEmpty()) newGroupName = i18n("Custom");
401 QString newMetaGroupId = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
402 QDomNodeList profilelist = doc.elementsByTagName("profile");
404 while (!profilelist.item(i).isNull()) {
405 // make sure a profile with same name doesn't exist
406 documentElement = profilelist.item(i).toElement();
407 QString profileName = documentElement.attribute("name");
408 if (profileName == newProfileName) {
409 // a profile with that same name already exists
411 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);
413 if (profileName == newProfileName) {
414 profiles.removeChild(profilelist.item(i));
421 QDomElement profileElement = doc.createElement("profile");
422 profileElement.setAttribute("name", newProfileName);
423 profileElement.setAttribute("category", newGroupName);
424 profileElement.setAttribute("destinationid", newMetaGroupId);
425 profileElement.setAttribute("extension", ui.extension->text().simplified());
426 profileElement.setAttribute("args", ui.parameters->toPlainText().simplified());
427 profiles.appendChild(profileElement);
429 //QCString save = doc.toString().utf8();
431 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
432 KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
435 QTextStream out(&file);
436 out << doc.toString();
437 if (file.error() != QFile::NoError) {
438 KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
443 parseProfiles(newMetaGroupId, newGroupName, newProfileName);
447 void RenderWidget::slotDeleteProfile(bool refresh)
449 //TODO: delete a profile installed by KNewStuff the easy way
451 QString edit = m_view.size_list->currentItem()->data(EditableRole).toString();
452 if (!edit.endsWith("customprofiles.xml")) {
453 // This is a KNewStuff installed file, process through KNS
454 KNS::Engine engine(0);
455 if (engine.init("kdenlive_render.knsrc")) {
456 KNS::Entry::List entries;
460 QString currentGroup = m_view.format_list->currentItem()->text();
461 QString currentProfile = m_view.size_list->currentItem()->text();
462 QString metaGroupId = m_view.destination_list->itemData(m_view.destination_list->currentIndex(), Qt::UserRole).toString();
464 QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
466 QFile file(exportFile);
467 doc.setContent(&file, false);
470 QDomElement documentElement;
471 QDomNodeList profiles = doc.elementsByTagName("profile");
477 while (!profiles.item(i).isNull()) {
478 documentElement = profiles.item(i).toElement();
479 profileName = documentElement.attribute("name");
480 groupName = documentElement.attribute("category");
481 destination = documentElement.attribute("destinationid");
483 if (profileName == currentProfile && groupName == currentGroup && destination == metaGroupId) {
484 kDebug() << "// GOT it: " << profileName;
485 doc.documentElement().removeChild(profiles.item(i));
491 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
492 KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
495 QTextStream out(&file);
496 out << doc.toString();
497 if (file.error() != QFile::NoError) {
498 KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
504 parseProfiles(metaGroupId, currentGroup);
505 focusFirstVisibleItem();
509 void RenderWidget::updateButtons()
511 if (!m_view.size_list->currentItem() || m_view.size_list->currentItem()->isHidden()) {
512 m_view.buttonSave->setEnabled(false);
513 m_view.buttonDelete->setEnabled(false);
514 m_view.buttonEdit->setEnabled(false);
515 m_view.buttonStart->setEnabled(false);
517 m_view.buttonSave->setEnabled(true);
518 m_view.buttonStart->setEnabled(m_view.size_list->currentItem()->flags() & Qt::ItemIsEnabled);
519 QString edit = m_view.size_list->currentItem()->data(EditableRole).toString();
520 if (edit.isEmpty() || !edit.endsWith("customprofiles.xml")) {
521 m_view.buttonDelete->setEnabled(false);
522 m_view.buttonEdit->setEnabled(false);
524 m_view.buttonDelete->setEnabled(true);
525 m_view.buttonEdit->setEnabled(true);
531 void RenderWidget::focusFirstVisibleItem()
533 if (m_view.size_list->currentItem() && !m_view.size_list->currentItem()->isHidden()) {
537 for (uint ix = 0; ix < m_view.size_list->count(); ix++) {
538 QListWidgetItem *item = m_view.size_list->item(ix);
539 if (item && !item->isHidden()) {
540 m_view.size_list->setCurrentRow(ix);
544 if (!m_view.size_list->currentItem()) m_view.size_list->setCurrentRow(0);
548 void RenderWidget::slotExport(bool scriptExport)
550 QListWidgetItem *item = m_view.size_list->currentItem();
553 const QString dest = m_view.out_file->url().path();
554 if (dest.isEmpty()) return;
557 if (KMessageBox::warningYesNo(this, i18n("Output file already exists. Do you want to overwrite it ?")) != KMessageBox::Yes)
565 QString scriptsFolder = m_projectFolder + "/scripts/";
566 KStandardDirs::makeDir(scriptsFolder);
567 QString path = scriptsFolder + i18n("script") + QString::number(ix).rightJustified(3, '0', false) + ".sh";
568 while (QFile::exists(path)) {
570 path = scriptsFolder + i18n("script") + QString::number(ix).rightJustified(3, '0', false) + ".sh";
572 scriptName = QInputDialog::getText(this, i18n("Create Render Script"), i18n("Script name (will be saved in: %1)", scriptsFolder), QLineEdit::Normal, KUrl(path).fileName(), &ok);
573 if (!ok || scriptName.isEmpty()) return;
574 scriptName.prepend(scriptsFolder);
577 if (KMessageBox::warningYesNo(this, i18n("Script file already exists. Do you want to overwrite it ?")) != KMessageBox::Yes)
582 QStringList overlayargs;
583 if (m_view.tc_overlay->isChecked()) {
584 QString filterFile = KStandardDirs::locate("appdata", "metadata.properties");
585 overlayargs << "meta.attr.timecode=1" << "meta.attr.timecode.markup=#timecode";
586 overlayargs << "-attach" << "data_feed:attr_check" << "-attach";
587 overlayargs << "data_show:" + filterFile << "_fezzik=1" << "dynamic=1";
589 double startPos = -1;
591 if (m_view.render_guide->isChecked()) {
592 startPos = m_view.guide_start->itemData(m_view.guide_start->currentIndex()).toDouble();
593 endPos = m_view.guide_end->itemData(m_view.guide_end->currentIndex()).toDouble();
595 QString renderArgs = m_view.advanced_params->toPlainText();
597 // Adjust frame scale
600 if (m_view.rescale->isChecked() && m_view.rescale->isEnabled()) {
601 width = m_view.rescale_size->text().section('x', 0, 0).toInt();
602 height = m_view.rescale_size->text().section('x', 1, 1).toInt();
604 width = m_profile.width;
605 height = m_profile.height;
607 renderArgs.replace("%dar", '@' + QString::number(m_profile.display_aspect_num) + '/' + QString::number(m_profile.display_aspect_den));
610 if (m_view.scanning_list->currentIndex() == 1) renderArgs.append(" progressive=1");
611 else if (m_view.scanning_list->currentIndex() == 2) renderArgs.append(" progressive=0");
613 // disable audio if requested
614 if (!m_view.export_audio->isChecked())
615 renderArgs.append(" an=1 ");
617 // Check if the rendering profile is different from project profile,
618 // in which case we need to use the producer_comsumer from MLT
619 bool resizeProfile = false;
621 QString std = renderArgs;
622 QString destination = m_view.destination_list->itemData(m_view.destination_list->currentIndex()).toString();
623 if (std.contains(" s=")) {
624 QString subsize = std.section(" s=", 1, 1);
625 subsize = subsize.section(' ', 0, 0).toLower();
626 const QString currentSize = QString::number(width) + 'x' + QString::number(height);
627 if (subsize != currentSize) resizeProfile = true;
628 } else if (destination != "audioonly") {
629 // Add current size parametrer
630 renderArgs.append(QString(" s=%1x%2").arg(width).arg(height));
633 // insert item in running jobs list
634 QTreeWidgetItem *renderItem;
635 QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(dest, Qt::MatchExactly, 1);
636 if (!existing.isEmpty()) renderItem = existing.at(0);
637 else renderItem = new QTreeWidgetItem(m_view.running_jobs, QStringList() << QString() << dest << QString());
638 renderItem->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
639 renderItem->setData(1, Qt::UserRole + 1, QTime::currentTime());
641 // Set rendering type
642 QString group = m_view.size_list->currentItem()->data(MetaGroupRole).toString();
643 if (group == "dvd" && m_view.open_dvd->isChecked()) {
644 renderItem->setData(0, Qt::UserRole, group);
645 if (renderArgs.contains("profile=")) {
646 // rendering profile contains an MLT profile, so pass it to the running jog item, useful for dvd
647 QString prof = renderArgs.section("profile=", 1, 1);
648 prof = prof.section(' ', 0, 0);
649 kDebug() << "// render profile: " << prof;
650 renderItem->setData(0, Qt::UserRole + 1, prof);
652 } else if (group == "websites" && m_view.open_browser->isChecked()) {
653 renderItem->setData(0, Qt::UserRole, group);
655 QString url = m_view.size_list->currentItem()->data(ExtraRole).toString();
656 renderItem->setData(0, Qt::UserRole + 1, url);
659 emit doRender(dest, item->data(RenderRole).toString(), overlayargs, renderArgs.simplified().split(' '), m_view.render_zone->isChecked(), m_view.play_after->isChecked(), startPos, endPos, resizeProfile, scriptName);
660 if (scriptName.isEmpty()) m_view.tabWidget->setCurrentIndex(1);
662 QTimer::singleShot(400, this, SLOT(parseScriptFiles()));
663 m_view.tabWidget->setCurrentIndex(2);
667 void RenderWidget::setProfile(MltVideoProfile profile)
670 //WARNING: this way to tell the video standard is a bit hackish...
671 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);
672 else m_view.format_selection->setCurrentIndex(1);
673 m_view.scanning_list->setCurrentIndex(0);
677 void RenderWidget::refreshView()
679 m_view.size_list->blockSignals(true);
680 QListWidgetItem *sizeItem;
683 KIcon brokenIcon("dialog-close");
684 if (m_view.destination_list->currentIndex() > 0)
685 destination = m_view.destination_list->itemData(m_view.destination_list->currentIndex()).toString();
688 if (destination == "dvd") m_view.open_dvd->setVisible(true);
689 else m_view.open_dvd->setVisible(false);
690 if (destination == "websites") m_view.open_browser->setVisible(true);
691 else m_view.open_browser->setVisible(false);
692 if (!destination.isEmpty() && QString("dvd websites audioonly").contains(destination))
693 m_view.rescale->setEnabled(false);
694 else m_view.rescale->setEnabled(true);
695 // hide groups that are not in the correct destination
696 for (int i = 0; i < m_view.format_list->count(); i++) {
697 sizeItem = m_view.format_list->item(i);
698 if (sizeItem->data(MetaGroupRole).toString() == destination) {
699 sizeItem->setHidden(false);
700 //kDebug() << "// SET GRP:: " << sizeItem->text() << ", METY:" << sizeItem->data(MetaGroupRole).toString();
701 } else sizeItem->setHidden(true);
704 // activate first visible item
705 QListWidgetItem * item = m_view.format_list->currentItem();
706 if (!item || item->isHidden()) {
707 for (int i = 0; i < m_view.format_list->count(); i++) {
708 if (!m_view.format_list->item(i)->isHidden()) {
709 m_view.format_list->setCurrentRow(i);
713 item = m_view.format_list->currentItem();
715 if (!item || item->isHidden()) {
716 m_view.format_list->setEnabled(false);
717 m_view.size_list->setEnabled(false);
720 m_view.format_list->setEnabled(true);
721 m_view.size_list->setEnabled(true);
724 for (int i = 0; i < m_view.format_list->count() && count < 2; i++) {
725 if (!m_view.format_list->isRowHidden(i)) count++;
727 if (count > 1) m_view.format_list->setVisible(true);
728 else m_view.format_list->setVisible(false);
730 QString group = item->text();
731 bool firstSelected = false;
732 const QStringList formatsList = KdenliveSettings::supportedformats();
733 const QStringList vcodecsList = KdenliveSettings::videocodecs();
734 const QStringList acodecsList = KdenliveSettings::audiocodecs();
736 for (int i = 0; i < m_view.size_list->count(); i++) {
737 sizeItem = m_view.size_list->item(i);
738 if ((sizeItem->data(GroupRole) == group || sizeItem->data(GroupRole).toString().isEmpty()) && sizeItem->data(MetaGroupRole) == destination) {
739 std = sizeItem->data(StandardRole).toString();
740 if (!std.isEmpty()) {
741 if (std.contains("PAL", Qt::CaseInsensitive)) sizeItem->setHidden(m_view.format_selection->currentIndex() != 0);
742 else if (std.contains("NTSC", Qt::CaseInsensitive)) sizeItem->setHidden(m_view.format_selection->currentIndex() != 1);
744 sizeItem->setHidden(false);
745 if (!firstSelected) m_view.size_list->setCurrentItem(sizeItem);
746 firstSelected = true;
749 if (!sizeItem->isHidden()) {
750 // Make sure the selected profile uses an installed avformat codec / format
751 std = sizeItem->data(ParamsRole).toString();
753 if (!formatsList.isEmpty()) {
755 if (std.startsWith("f=")) format = std.section("f=", 1, 1);
756 else if (std.contains(" f=")) format = std.section(" f=", 1, 1);
757 if (!format.isEmpty()) {
758 format = format.section(' ', 0, 0).toLower();
759 if (!formatsList.contains(format)) {
760 kDebug() << "***** UNSUPPORTED F: " << format;
761 //sizeItem->setHidden(true);
762 sizeItem->setFlags(Qt::ItemIsSelectable);
763 sizeItem->setToolTip(i18n("Unsupported video format: %1", format));
764 sizeItem->setIcon(brokenIcon);
768 if (!acodecsList.isEmpty() && !sizeItem->isHidden()) {
770 if (std.startsWith("acodec=")) format = std.section("acodec=", 1, 1);
771 else if (std.contains(" acodec=")) format = std.section(" acodec=", 1, 1);
772 if (!format.isEmpty()) {
773 format = format.section(' ', 0, 0).toLower();
774 if (!acodecsList.contains(format)) {
775 kDebug() << "***** UNSUPPORTED ACODEC: " << format;
776 //sizeItem->setHidden(true);
777 sizeItem->setFlags(Qt::ItemIsSelectable);
778 sizeItem->setToolTip(i18n("Unsupported audio codec: %1", format));
779 sizeItem->setIcon(brokenIcon);
783 if (!vcodecsList.isEmpty() && !sizeItem->isHidden()) {
785 if (std.startsWith("vcodec=")) format = std.section("vcodec=", 1, 1);
786 else if (std.contains(" vcodec=")) format = std.section(" vcodec=", 1, 1);
787 if (!format.isEmpty()) {
788 format = format.section(' ', 0, 0).toLower();
789 if (!vcodecsList.contains(format)) {
790 kDebug() << "***** UNSUPPORTED VCODEC: " << format;
791 //sizeItem->setHidden(true);
792 sizeItem->setFlags(Qt::ItemIsSelectable);
793 sizeItem->setToolTip(i18n("Unsupported video codec: %1", format));
794 sizeItem->setIcon(brokenIcon);
799 } else sizeItem->setHidden(true);
801 focusFirstVisibleItem();
802 m_view.size_list->blockSignals(false);
806 KUrl RenderWidget::filenameWithExtension(KUrl url, QString extension)
809 if (!url.isEmpty()) {
811 int pos = path.lastIndexOf('.') + 1;
812 if (pos == 0) path.append('.' + extension);
813 else path = path.left(pos) + extension;
816 path = m_projectFolder + "/untitled." + extension;
822 void RenderWidget::refreshParams()
824 QListWidgetItem *item = m_view.size_list->currentItem();
825 if (!item || item->isHidden()) {
826 m_view.advanced_params->clear();
827 m_view.buttonStart->setEnabled(false);
830 QString params = item->data(ParamsRole).toString();
831 QString extension = item->data(ExtensionRole).toString();
832 m_view.advanced_params->setPlainText(params);
833 QString destination = m_view.destination_list->itemData(m_view.destination_list->currentIndex()).toString();
834 if (params.contains(" s=") || destination == "audioonly") {
835 // profile has a fixed size, do not allow resize
836 m_view.rescale->setEnabled(false);
837 m_view.rescale_size->setEnabled(false);
839 m_view.rescale->setEnabled(true);
840 m_view.rescale_size->setEnabled(true);
842 KUrl url = filenameWithExtension(m_view.out_file->url(), extension);
843 m_view.out_file->setUrl(url);
844 // if (!url.isEmpty()) {
845 // QString path = url.path();
846 // int pos = path.lastIndexOf('.') + 1;
847 // if (pos == 0) path.append('.' + extension);
848 // else path = path.left(pos) + extension;
849 // m_view.out_file->setUrl(KUrl(path));
851 // m_view.out_file->setUrl(KUrl(QDir::homePath() + "/untitled." + extension));
853 m_view.out_file->setFilter("*." + extension);
854 QString edit = item->data(EditableRole).toString();
855 if (edit.isEmpty() || !edit.endsWith("customprofiles.xml")) {
856 m_view.buttonDelete->setEnabled(false);
857 m_view.buttonEdit->setEnabled(false);
859 m_view.buttonDelete->setEnabled(true);
860 m_view.buttonEdit->setEnabled(true);
863 m_view.buttonStart->setEnabled(m_view.size_list->currentItem()->flags() & Qt::ItemIsEnabled);
866 void RenderWidget::reloadProfiles()
871 void RenderWidget::parseProfiles(QString meta, QString group, QString profile)
873 m_view.size_list->clear();
874 m_view.format_list->clear();
875 m_view.destination_list->clear();
876 m_view.destination_list->addItem(KIcon("video-x-generic"), i18n("File rendering"));
877 m_view.destination_list->addItem(KIcon("media-optical"), i18n("DVD"), "dvd");
878 m_view.destination_list->addItem(KIcon("audio-x-generic"), i18n("Audio only"), "audioonly");
879 m_view.destination_list->addItem(KIcon("applications-internet"), i18n("Web sites"), "websites");
880 m_view.destination_list->addItem(KIcon("applications-multimedia"), i18n("Media players"), "mediaplayers");
881 m_view.destination_list->addItem(KIcon("drive-harddisk"), i18n("Lossless / HQ"), "lossless");
882 m_view.destination_list->addItem(KIcon("pda"), i18n("Mobile devices"), "mobile");
884 QString exportFile = KStandardDirs::locate("appdata", "export/profiles.xml");
885 parseFile(exportFile, false);
888 QString exportFolder = KStandardDirs::locateLocal("appdata", "export/");
889 QDir directory = QDir(exportFolder);
892 QStringList fileList = directory.entryList(filter, QDir::Files);
893 // We should parse customprofiles.xml in last position, so that user profiles
894 // can also override profiles installed by KNewStuff
895 fileList.removeAll("customprofiles.xml");
896 foreach(const QString &filename, fileList)
897 parseFile(exportFolder + '/' + filename, true);
898 if (QFile::exists(exportFolder + "/customprofiles.xml")) parseFile(exportFolder + "/customprofiles.xml", true);
900 if (!meta.isEmpty()) {
901 m_view.destination_list->blockSignals(true);
902 m_view.destination_list->setCurrentIndex(m_view.destination_list->findData(meta));
903 m_view.destination_list->blockSignals(false);
906 QList<QListWidgetItem *> child;
907 if (!group.isEmpty()) child = m_view.format_list->findItems(group, Qt::MatchExactly);
908 if (!child.isEmpty()) {
909 for (int i = 0; i < child.count(); i++) {
910 if (child.at(i)->data(MetaGroupRole).toString() == meta) {
911 m_view.format_list->setCurrentItem(child.at(i));
917 if (!profile.isEmpty()) child = m_view.size_list->findItems(profile, Qt::MatchExactly);
918 if (!child.isEmpty()) m_view.size_list->setCurrentItem(child.at(0));
921 void RenderWidget::parseFile(QString exportFile, bool editable)
923 kDebug() << "// Parsing file: " << exportFile;
924 kDebug() << "------------------------------";
926 QFile file(exportFile);
927 doc.setContent(&file, false);
929 QDomElement documentElement;
930 QDomElement profileElement;
932 QListWidgetItem *item;
933 QDomNodeList groups = doc.elementsByTagName("group");
935 if (editable || groups.count() == 0) {
936 QDomElement profiles = doc.documentElement();
937 if (editable && profiles.attribute("version", 0).toInt() < 1) {
938 kDebug() << "// OLD profile version";
939 // this is an old profile version, update it
941 QDomElement newprofiles = newdoc.createElement("profiles");
942 newprofiles.setAttribute("version", 1);
943 newdoc.appendChild(newprofiles);
944 QDomNodeList profilelist = doc.elementsByTagName("profile");
945 for (int i = 0; i < profilelist.count(); i++) {
946 QString category = i18n("Custom");
948 QDomNode parent = profilelist.at(i).parentNode();
949 if (!parent.isNull()) {
950 QDomElement parentNode = parent.toElement();
951 if (parentNode.hasAttribute("name")) category = parentNode.attribute("name");
952 extension = parentNode.attribute("extension");
954 profilelist.at(i).toElement().setAttribute("category", category);
955 if (!extension.isEmpty()) profilelist.at(i).toElement().setAttribute("extension", extension);
956 QDomNode n = profilelist.at(i).cloneNode();
957 newprofiles.appendChild(newdoc.importNode(n, true));
959 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
960 KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
963 QTextStream out(&file);
964 out << newdoc.toString();
966 parseFile(exportFile, editable);
970 QDomNode node = doc.elementsByTagName("profile").at(0);
972 kDebug() << "// Export file: " << exportFile << " IS BROKEN";
976 while (!node.isNull()) {
977 QDomElement profile = node.toElement();
978 QString profileName = profile.attribute("name");
979 QString standard = profile.attribute("standard");
980 QString params = profile.attribute("args");
981 QString category = profile.attribute("category", i18n("Custom"));
982 QString dest = profile.attribute("destinationid");
983 QString prof_extension = profile.attribute("extension");
984 if (!prof_extension.isEmpty()) extension = prof_extension;
986 QList <QListWidgetItem *> list = m_view.format_list->findItems(category, Qt::MatchExactly);
988 for (int j = 0; j < list.count(); j++) {
989 if (list.at(j)->data(MetaGroupRole) == dest) {
995 item = new QListWidgetItem(category, m_view.format_list);
996 item->setData(MetaGroupRole, dest);
999 // Check if item with same name already exists and replace it,
1000 // allowing to override default profiles
1002 list = m_view.size_list->findItems(profileName, Qt::MatchExactly);
1004 for (int j = 0; j < list.count(); j++) {
1005 if (list.at(j)->data(MetaGroupRole) == dest) {
1006 QListWidgetItem *duplicate = list.takeAt(j);
1012 item = new QListWidgetItem(profileName, m_view.size_list);
1013 //kDebug() << "// ADDINg item with name: " << profileName << ", GRP" << category << ", DEST:" << dest ;
1014 item->setData(GroupRole, category);
1015 item->setData(MetaGroupRole, dest);
1016 item->setData(ExtensionRole, extension);
1017 item->setData(RenderRole, "avformat");
1018 item->setData(StandardRole, standard);
1019 item->setData(ParamsRole, params);
1020 if (profile.hasAttribute("url")) item->setData(ExtraRole, profile.attribute("url"));
1022 item->setData(EditableRole, exportFile);
1023 if (exportFile.endsWith("customprofiles.xml")) item->setIcon(KIcon("emblem-favorite"));
1024 else item->setIcon(KIcon("applications-internet"));
1026 node = doc.elementsByTagName("profile").at(count);
1034 QString profileName;
1036 QString prof_extension;
1042 while (!groups.item(i).isNull()) {
1043 documentElement = groups.item(i).toElement();
1044 QDomNode gname = documentElement.elementsByTagName("groupname").at(0);
1045 QString metagroupName;
1046 QString metagroupId;
1047 if (!gname.isNull()) {
1048 metagroupName = gname.firstChild().nodeValue();
1049 metagroupId = gname.toElement().attribute("id");
1050 if (!metagroupName.isEmpty() && !m_view.destination_list->contains(metagroupName)) {
1051 if (metagroupId == "dvd") icon = KIcon("media-optical");
1052 else if (metagroupId == "audioonly") icon = KIcon("audio-x-generic");
1053 else if (metagroupId == "websites") icon = KIcon("applications-internet");
1054 else if (metagroupId == "mediaplayers") icon = KIcon("applications-multimedia");
1055 else if (metagroupId == "lossless") icon = KIcon("drive-harddisk");
1056 else if (metagroupId == "mobile") icon = KIcon("pda");
1057 m_view.destination_list->addItem(icon, i18n(metagroupName.toUtf8().data()), metagroupId);
1060 groupName = documentElement.attribute("name", i18n("Custom"));
1061 extension = documentElement.attribute("extension", QString());
1062 renderer = documentElement.attribute("renderer", QString());
1063 QList <QListWidgetItem *> list = m_view.format_list->findItems(groupName, Qt::MatchExactly);
1064 bool exists = false;
1065 for (int j = 0; j < list.count(); j++) {
1066 if (list.at(j)->data(MetaGroupRole) == metagroupId) {
1072 item = new QListWidgetItem(groupName, m_view.format_list);
1073 item->setData(MetaGroupRole, metagroupId);
1076 QDomNode n = groups.item(i).firstChild();
1077 while (!n.isNull()) {
1078 if (n.toElement().tagName() != "profile") {
1079 n = n.nextSibling();
1082 profileElement = n.toElement();
1083 profileName = profileElement.attribute("name");
1084 standard = profileElement.attribute("standard");
1085 params = profileElement.attribute("args");
1086 prof_extension = profileElement.attribute("extension");
1087 if (!prof_extension.isEmpty()) extension = prof_extension;
1088 item = new QListWidgetItem(profileName, m_view.size_list);
1089 item->setData(GroupRole, groupName);
1090 item->setData(MetaGroupRole, metagroupId);
1091 item->setData(ExtensionRole, extension);
1092 item->setData(RenderRole, renderer);
1093 item->setData(StandardRole, standard);
1094 item->setData(ParamsRole, params);
1095 if (profileElement.hasAttribute("url")) item->setData(ExtraRole, profileElement.attribute("url"));
1096 if (editable) item->setData(EditableRole, exportFile);
1097 n = n.nextSibling();
1104 void RenderWidget::setRenderJob(const QString &dest, int progress)
1106 QTreeWidgetItem *item;
1107 QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(dest, Qt::MatchExactly, 1);
1108 if (!existing.isEmpty()) item = existing.at(0);
1109 else item = new QTreeWidgetItem(m_view.running_jobs, QStringList() << QString() << dest << QString());
1110 item->setData(2, Qt::UserRole, progress);
1111 if (progress == 0) {
1112 item->setIcon(0, KIcon("system-run"));
1113 item->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
1114 item->setData(1, Qt::UserRole + 1, QTime::currentTime());
1117 QTime startTime = item->data(1, Qt::UserRole + 1).toTime();
1118 int seconds = startTime.secsTo(QTime::currentTime());;
1119 const QString t = i18n("Estimated time %1", QTime().addSecs(seconds * (100 - progress) / progress).toString("hh:mm:ss"));
1120 item->setData(1, Qt::UserRole, t);
1124 void RenderWidget::setRenderStatus(const QString &dest, int status, const QString &error)
1126 QTreeWidgetItem *item;
1127 QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(dest, Qt::MatchExactly, 1);
1128 if (!existing.isEmpty()) item = existing.at(0);
1129 else item = new QTreeWidgetItem(m_view.running_jobs, QStringList() << QString() << dest << QString());
1131 // Job finished successfully
1132 item->setIcon(0, KIcon("dialog-ok"));
1133 item->setData(2, Qt::UserRole, 100);
1134 QTime startTime = item->data(1, Qt::UserRole + 1).toTime();
1135 int seconds = startTime.secsTo(QTime::currentTime());
1136 const QTime tm = QTime().addSecs(seconds);
1137 const QString t = i18n("Rendering finished in %1", tm.toString("hh:mm:ss"));
1138 item->setData(1, Qt::UserRole, t);
1139 QString itemGroup = item->data(0, Qt::UserRole).toString();
1140 if (itemGroup == "dvd") {
1141 emit openDvdWizard(item->text(1), item->data(0, Qt::UserRole + 1).toString());
1142 } else if (itemGroup == "websites") {
1143 QString url = item->data(0, Qt::UserRole + 1).toString();
1144 if (!url.isEmpty()) new KRun(url, this);
1146 } else if (status == -2) {
1147 // Rendering crashed
1148 item->setData(1, Qt::UserRole, i18n("Rendering crashed"));
1149 item->setIcon(0, KIcon("dialog-close"));
1150 item->setData(2, Qt::UserRole, 100);
1151 m_view.error_log->append(i18n("<strong>Rendering of %1 crashed</strong><br />", dest));
1152 m_view.error_log->append(error);
1153 m_view.error_log->append("<hr />");
1154 m_view.error_box->setVisible(true);
1155 } else if (status == -3) {
1157 item->setData(1, Qt::UserRole, i18n("Rendering aborted"));
1158 item->setIcon(0, KIcon("dialog-cancel"));
1159 item->setData(2, Qt::UserRole, 100);
1164 void RenderWidget::slotAbortCurrentJob()
1166 QTreeWidgetItem *current = m_view.running_jobs->currentItem();
1167 if (current) emit abortProcess(current->text(1));
1170 void RenderWidget::slotCheckJob()
1172 bool activate = false;
1173 QTreeWidgetItem *current = m_view.running_jobs->currentItem();
1175 int percent = current->data(2, Qt::UserRole).toInt();
1176 if (percent < 100) activate = true;
1178 m_view.abort_job->setEnabled(activate);
1181 void RenderWidget::parseScriptFiles()
1183 QStringList scriptsFilter;
1184 scriptsFilter << "*.sh";
1185 m_view.scripts_list->clear();
1187 QTreeWidgetItem *item;
1188 // List the project scripts
1189 QStringList scriptFiles = QDir(m_projectFolder + "/scripts").entryList(scriptsFilter, QDir::Files);
1190 for (int i = 0; i < scriptFiles.size(); ++i) {
1191 KUrl scriptpath(m_projectFolder + "/scripts/" + scriptFiles.at(i));
1192 item = new QTreeWidgetItem(m_view.scripts_list, QStringList() << scriptpath.fileName());
1194 QFile file(scriptpath.path());
1195 if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
1196 while (!file.atEnd()) {
1197 QByteArray line = file.readLine();
1198 if (line.startsWith("TARGET=")) {
1199 target = QString(line).section("TARGET=", 1);
1200 target.remove(QChar('"'));
1206 item->setSizeHint(0, QSize(m_view.scripts_list->columnWidth(0), fontMetrics().height() * 2));
1207 item->setData(0, Qt::UserRole, target);
1208 item->setData(0, Qt::UserRole + 1, scriptpath.path());
1210 bool activate = false;
1211 QTreeWidgetItemIterator it(m_view.scripts_list);
1213 kDebug() << "// FOUND SCRIPT ITEM:" << (*it)->text(0);
1214 // Selecting item does not work, why ???
1215 m_view.scripts_list->setCurrentItem(*it);
1216 (*it)->setSelected(true);
1219 kDebug() << "SELECTED SCRIPTS: " << m_view.scripts_list->selectedItems().count();
1220 m_view.start_script->setEnabled(activate);
1221 m_view.delete_script->setEnabled(activate);
1224 void RenderWidget::slotCheckScript()
1226 bool activate = false;
1227 QTreeWidgetItemIterator it(m_view.scripts_list);
1228 if (*it) activate = true;
1229 m_view.start_script->setEnabled(activate);
1230 m_view.delete_script->setEnabled(activate);
1233 void RenderWidget::slotStartScript()
1235 QTreeWidgetItem *item = m_view.scripts_list->currentItem();
1237 QString path = item->data(0, Qt::UserRole + 1).toString();
1238 QProcess::startDetached(path);
1239 m_view.tabWidget->setCurrentIndex(1);
1243 void RenderWidget::slotDeleteScript()
1245 QTreeWidgetItem *item = m_view.scripts_list->currentItem();
1247 QString path = item->data(0, Qt::UserRole + 1).toString();
1248 KIO::NetAccess::del(path + ".westley", this);
1249 KIO::NetAccess::del(path, this);
1254 void RenderWidget::slotGenerateScript()