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) :
53 m_projectFolder(projectfolder)
56 setWindowTitle(i18n("Rendering"));
57 m_view.buttonDelete->setIcon(KIcon("trash-empty"));
58 m_view.buttonDelete->setToolTip(i18n("Delete profile"));
59 m_view.buttonDelete->setEnabled(false);
61 m_view.buttonEdit->setIcon(KIcon("document-properties"));
62 m_view.buttonEdit->setToolTip(i18n("Edit profile"));
63 m_view.buttonEdit->setEnabled(false);
65 m_view.buttonSave->setIcon(KIcon("document-new"));
66 m_view.buttonSave->setToolTip(i18n("Create new profile"));
68 m_view.buttonInfo->setIcon(KIcon("help-about"));
70 if (KdenliveSettings::showrenderparams()) {
71 m_view.buttonInfo->setDown(true);
72 } else m_view.advanced_params->hide();
74 m_view.rescale_size->setInputMask("0099\\x0099");
75 m_view.rescale_size->setText("320x240");
78 QMenu *renderMenu = new QMenu(i18n("Start Rendering"), this);
79 QAction *renderAction = renderMenu->addAction(KIcon("video-x-generic"), i18n("Render to File"));
80 connect(renderAction, SIGNAL(triggered()), this, SLOT(slotExport()));
81 QAction *scriptAction = renderMenu->addAction(KIcon("application-x-shellscript"), i18n("Generate Script"));
82 connect(scriptAction, SIGNAL(triggered()), this, SLOT(slotGenerateScript()));
84 m_view.buttonStart->setMenu(renderMenu);
85 m_view.buttonStart->setPopupMode(QToolButton::MenuButtonPopup);
86 m_view.buttonStart->setDefaultAction(renderAction);
87 m_view.buttonStart->setToolButtonStyle(Qt::ToolButtonTextOnly);
88 m_view.abort_job->setEnabled(false);
89 m_view.start_script->setEnabled(false);
90 m_view.delete_script->setEnabled(false);
92 m_view.format_list->setAlternatingRowColors(true);
93 m_view.size_list->setAlternatingRowColors(true);
98 connect(m_view.start_script, SIGNAL(clicked()), this, SLOT(slotStartScript()));
99 connect(m_view.delete_script, SIGNAL(clicked()), this, SLOT(slotDeleteScript()));
100 connect(m_view.scripts_list, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(slotCheckScript()));
101 connect(m_view.running_jobs, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(slotCheckJob()));
103 connect(m_view.buttonInfo, SIGNAL(clicked()), this, SLOT(showInfoPanel()));
105 connect(m_view.buttonSave, SIGNAL(clicked()), this, SLOT(slotSaveProfile()));
106 connect(m_view.buttonEdit, SIGNAL(clicked()), this, SLOT(slotEditProfile()));
107 connect(m_view.buttonDelete, SIGNAL(clicked()), this, SLOT(slotDeleteProfile()));
108 connect(m_view.abort_job, SIGNAL(clicked()), this, SLOT(slotAbortCurrentJob()));
109 connect(m_view.buttonClose, SIGNAL(clicked()), this, SLOT(hide()));
110 connect(m_view.buttonClose2, SIGNAL(clicked()), this, SLOT(hide()));
111 connect(m_view.buttonClose3, SIGNAL(clicked()), this, SLOT(hide()));
112 connect(m_view.rescale, SIGNAL(toggled(bool)), m_view.rescale_size, SLOT(setEnabled(bool)));
113 connect(m_view.destination_list, SIGNAL(activated(int)), this, SLOT(refreshView()));
114 connect(m_view.out_file, SIGNAL(textChanged(const QString &)), this, SLOT(slotUpdateButtons()));
115 connect(m_view.out_file, SIGNAL(urlSelected(const KUrl &)), this, SLOT(slotUpdateButtons(const KUrl &)));
116 connect(m_view.format_list, SIGNAL(currentRowChanged(int)), this, SLOT(refreshView()));
117 connect(m_view.size_list, SIGNAL(currentRowChanged(int)), this, SLOT(refreshParams()));
119 connect(m_view.size_list, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(slotEditItem(QListWidgetItem *)));
121 connect(m_view.render_guide, SIGNAL(clicked(bool)), this, SLOT(slotUpdateGuideBox()));
122 connect(m_view.render_zone, SIGNAL(clicked(bool)), this, SLOT(slotUpdateGuideBox()));
123 connect(m_view.render_full, SIGNAL(clicked(bool)), this, SLOT(slotUpdateGuideBox()));
125 connect(m_view.guide_end, SIGNAL(activated(int)), this, SLOT(slotCheckStartGuidePosition()));
126 connect(m_view.guide_start, SIGNAL(activated(int)), this, SLOT(slotCheckEndGuidePosition()));
128 connect(m_view.format_selection, SIGNAL(activated(int)), this, SLOT(refreshView()));
130 m_view.buttonStart->setEnabled(false);
131 m_view.rescale_size->setEnabled(false);
132 m_view.guides_box->setVisible(false);
133 m_view.open_dvd->setVisible(false);
134 m_view.open_browser->setVisible(false);
135 m_view.error_box->setVisible(false);
137 m_view.splitter->setStretchFactor(1, 5);
138 m_view.splitter->setStretchFactor(0, 2);
140 m_view.out_file->setMode(KFile::File);
142 m_view.running_jobs->setHeaderLabels(QStringList() << QString() << i18n("File") << i18n("Progress"));
143 m_view.running_jobs->setItemDelegate(new RenderViewDelegate(this));
145 QHeaderView *header = m_view.running_jobs->header();
146 QFontMetrics fm = fontMetrics();
147 //header->resizeSection(0, fm.width("typical-name-for-a-torrent.torrent"));
148 header->setResizeMode(0, QHeaderView::Fixed);
149 header->resizeSection(0, 30);
150 header->setResizeMode(1, QHeaderView::Interactive);
151 header->resizeSection(1, fm.width("typical-name-for-a-file.torrent"));
152 header->setResizeMode(2, QHeaderView::Fixed);
153 header->resizeSection(1, width() * 2 / 3);
154 header->setResizeMode(2, QHeaderView::Interactive);
155 //header->setResizeMode(1, QHeaderView::Fixed);
157 m_view.scripts_list->setHeaderLabels(QStringList() << i18n("Script Files"));
158 m_view.scripts_list->setItemDelegate(new RenderScriptDelegate(this));
161 focusFirstVisibleItem();
164 void RenderWidget::slotEditItem(QListWidgetItem *item)
166 QString edit = item->data(EditableRole).toString();
167 if (edit.isEmpty() || !edit.endsWith("customprofiles.xml")) slotSaveProfile();
168 else slotEditProfile();
171 void RenderWidget::showInfoPanel()
173 if (m_view.advanced_params->isVisible()) {
174 m_view.advanced_params->setVisible(false);
175 m_view.buttonInfo->setDown(false);
176 KdenliveSettings::setShowrenderparams(false);
178 m_view.advanced_params->setVisible(true);
179 m_view.buttonInfo->setDown(true);
180 KdenliveSettings::setShowrenderparams(true);
184 void RenderWidget::setDocumentPath(const QString path)
186 m_projectFolder = path;
187 const QString fileName = m_view.out_file->url().fileName();
188 m_view.out_file->setUrl(KUrl(m_projectFolder + '/' + fileName));
192 void RenderWidget::slotUpdateGuideBox()
194 m_view.guides_box->setVisible(m_view.render_guide->isChecked());
197 void RenderWidget::slotCheckStartGuidePosition()
199 if (m_view.guide_start->currentIndex() > m_view.guide_end->currentIndex())
200 m_view.guide_start->setCurrentIndex(m_view.guide_end->currentIndex());
203 void RenderWidget::slotCheckEndGuidePosition()
205 if (m_view.guide_end->currentIndex() < m_view.guide_start->currentIndex())
206 m_view.guide_end->setCurrentIndex(m_view.guide_start->currentIndex());
209 void RenderWidget::setGuides(QDomElement guidesxml, double duration)
211 m_view.guide_start->clear();
212 m_view.guide_end->clear();
213 QDomNodeList nodes = guidesxml.elementsByTagName("guide");
214 if (nodes.count() > 0) {
215 m_view.guide_start->addItem(i18n("Render"), "0");
216 m_view.render_guide->setEnabled(true);
217 } else m_view.render_guide->setEnabled(false);
218 for (int i = 0; i < nodes.count(); i++) {
219 QDomElement e = nodes.item(i).toElement();
221 m_view.guide_start->addItem(e.attribute("comment"), e.attribute("time").toDouble());
222 m_view.guide_end->addItem(e.attribute("comment"), e.attribute("time").toDouble());
225 if (nodes.count() > 0)
226 m_view.guide_end->addItem(i18n("End"), QString::number(duration));
229 // Will be called when the user selects an output file via the file dialog.
230 // File extension will be added automatically.
231 void RenderWidget::slotUpdateButtons(KUrl url)
233 if (m_view.out_file->url().isEmpty()) m_view.buttonStart->setEnabled(false);
234 else m_view.buttonStart->setEnabled(true);
236 QListWidgetItem *item = m_view.size_list->currentItem();
237 QString extension = item->data(ExtensionRole).toString();
238 url = filenameWithExtension(url, extension);
239 m_view.out_file->setUrl(url);
243 // Will be called when the user changes the output file path in the text line.
244 // File extension must NOT be added, would make editing impossible!
245 void RenderWidget::slotUpdateButtons()
247 if (m_view.out_file->url().isEmpty()) m_view.buttonStart->setEnabled(false);
248 else m_view.buttonStart->setEnabled(true);
251 void RenderWidget::slotSaveProfile()
253 //TODO: update to correctly use metagroups
254 Ui::SaveProfile_UI ui;
255 QDialog *d = new QDialog(this);
258 for (int i = 0; i < m_view.destination_list->count(); i++)
259 ui.destination_list->addItem(m_view.destination_list->itemIcon(i), m_view.destination_list->itemText(i), m_view.destination_list->itemData(i, Qt::UserRole));
261 ui.destination_list->setCurrentIndex(m_view.destination_list->currentIndex());
262 QString dest = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
264 QString customGroup = m_view.format_list->currentItem()->text();
265 if (customGroup.isEmpty()) customGroup = i18n("Custom");
266 ui.group_name->setText(customGroup);
268 ui.parameters->setText(m_view.advanced_params->toPlainText());
269 ui.extension->setText(m_view.size_list->currentItem()->data(ExtensionRole).toString());
270 ui.profile_name->setFocus();
271 if (d->exec() == QDialog::Accepted && !ui.profile_name->text().simplified().isEmpty()) {
272 QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
274 QFile file(exportFile);
275 doc.setContent(&file, false);
277 QDomElement documentElement;
278 QDomElement profiles = doc.documentElement();
279 if (profiles.isNull() || profiles.tagName() != "profiles") {
281 profiles = doc.createElement("profiles");
282 profiles.setAttribute("version", 1);
283 doc.appendChild(profiles);
285 int version = profiles.attribute("version", 0).toInt();
287 kDebug() << "// OLD profile version";
289 profiles = doc.createElement("profiles");
290 profiles.setAttribute("version", 1);
291 doc.appendChild(profiles);
294 QString newProfileName = ui.profile_name->text().simplified();
295 QString newGroupName = ui.group_name->text().simplified();
296 if (newGroupName.isEmpty()) newGroupName = i18n("Custom");
297 QString newMetaGroupId = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
298 QDomNodeList profilelist = doc.elementsByTagName("profile");
300 while (!profilelist.item(i).isNull()) {
301 // make sure a profile with same name doesn't exist
302 documentElement = profilelist.item(i).toElement();
303 QString profileName = documentElement.attribute("name");
304 if (profileName == newProfileName) {
305 // a profile with that same name already exists
307 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);
309 if (profileName == newProfileName) {
310 profiles.removeChild(profilelist.item(i));
317 QDomElement profileElement = doc.createElement("profile");
318 profileElement.setAttribute("name", newProfileName);
319 profileElement.setAttribute("category", newGroupName);
320 profileElement.setAttribute("destinationid", newMetaGroupId);
321 profileElement.setAttribute("extension", ui.extension->text().simplified());
322 profileElement.setAttribute("args", ui.parameters->toPlainText().simplified());
323 profiles.appendChild(profileElement);
325 //QCString save = doc.toString().utf8();
327 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
328 KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
332 QTextStream out(&file);
333 out << doc.toString();
334 if (file.error() != QFile::NoError) {
335 KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
340 parseProfiles(newMetaGroupId, newGroupName, newProfileName);
345 void RenderWidget::slotEditProfile()
347 QListWidgetItem *item = m_view.size_list->currentItem();
349 QString currentGroup = m_view.format_list->currentItem()->text();
351 QString params = item->data(ParamsRole).toString();
352 QString extension = item->data(ExtensionRole).toString();
353 QString currentProfile = item->text();
355 Ui::SaveProfile_UI ui;
356 QDialog *d = new QDialog(this);
359 for (int i = 0; i < m_view.destination_list->count(); i++)
360 ui.destination_list->addItem(m_view.destination_list->itemIcon(i), m_view.destination_list->itemText(i), m_view.destination_list->itemData(i, Qt::UserRole));
362 ui.destination_list->setCurrentIndex(m_view.destination_list->currentIndex());
363 QString dest = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
365 QString customGroup = m_view.format_list->currentItem()->text();
366 if (customGroup.isEmpty()) customGroup = i18n("Custom");
367 ui.group_name->setText(customGroup);
369 ui.profile_name->setText(currentProfile);
370 ui.extension->setText(extension);
371 ui.parameters->setText(params);
372 ui.profile_name->setFocus();
373 d->setWindowTitle(i18n("Edit Profile"));
374 if (d->exec() == QDialog::Accepted) {
375 slotDeleteProfile(false);
376 QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
378 QFile file(exportFile);
379 doc.setContent(&file, false);
381 QDomElement documentElement;
382 QDomElement profiles = doc.documentElement();
384 if (profiles.isNull() || profiles.tagName() != "profiles") {
386 profiles = doc.createElement("profiles");
387 profiles.setAttribute("version", 1);
388 doc.appendChild(profiles);
391 int version = profiles.attribute("version", 0).toInt();
393 kDebug() << "// OLD profile version";
395 profiles = doc.createElement("profiles");
396 profiles.setAttribute("version", 1);
397 doc.appendChild(profiles);
400 QString newProfileName = ui.profile_name->text().simplified();
401 QString newGroupName = ui.group_name->text().simplified();
402 if (newGroupName.isEmpty()) newGroupName = i18n("Custom");
403 QString newMetaGroupId = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
404 QDomNodeList profilelist = doc.elementsByTagName("profile");
406 while (!profilelist.item(i).isNull()) {
407 // make sure a profile with same name doesn't exist
408 documentElement = profilelist.item(i).toElement();
409 QString profileName = documentElement.attribute("name");
410 if (profileName == newProfileName) {
411 // a profile with that same name already exists
413 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);
415 if (profileName == newProfileName) {
416 profiles.removeChild(profilelist.item(i));
423 QDomElement profileElement = doc.createElement("profile");
424 profileElement.setAttribute("name", newProfileName);
425 profileElement.setAttribute("category", newGroupName);
426 profileElement.setAttribute("destinationid", newMetaGroupId);
427 profileElement.setAttribute("extension", ui.extension->text().simplified());
428 profileElement.setAttribute("args", ui.parameters->toPlainText().simplified());
429 profiles.appendChild(profileElement);
431 //QCString save = doc.toString().utf8();
433 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
434 KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
437 QTextStream out(&file);
438 out << doc.toString();
439 if (file.error() != QFile::NoError) {
440 KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
445 parseProfiles(newMetaGroupId, newGroupName, newProfileName);
449 void RenderWidget::slotDeleteProfile(bool refresh)
451 //TODO: delete a profile installed by KNewStuff the easy way
453 QString edit = m_view.size_list->currentItem()->data(EditableRole).toString();
454 if (!edit.endsWith("customprofiles.xml")) {
455 // This is a KNewStuff installed file, process through KNS
456 KNS::Engine engine(0);
457 if (engine.init("kdenlive_render.knsrc")) {
458 KNS::Entry::List entries;
462 QString currentGroup = m_view.format_list->currentItem()->text();
463 QString currentProfile = m_view.size_list->currentItem()->text();
464 QString metaGroupId = m_view.destination_list->itemData(m_view.destination_list->currentIndex(), Qt::UserRole).toString();
466 QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
468 QFile file(exportFile);
469 doc.setContent(&file, false);
472 QDomElement documentElement;
473 QDomNodeList profiles = doc.elementsByTagName("profile");
479 while (!profiles.item(i).isNull()) {
480 documentElement = profiles.item(i).toElement();
481 profileName = documentElement.attribute("name");
482 groupName = documentElement.attribute("category");
483 destination = documentElement.attribute("destinationid");
485 if (profileName == currentProfile && groupName == currentGroup && destination == metaGroupId) {
486 kDebug() << "// GOT it: " << profileName;
487 doc.documentElement().removeChild(profiles.item(i));
493 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
494 KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
497 QTextStream out(&file);
498 out << doc.toString();
499 if (file.error() != QFile::NoError) {
500 KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
506 parseProfiles(metaGroupId, currentGroup);
507 focusFirstVisibleItem();
511 void RenderWidget::updateButtons()
513 if (!m_view.size_list->currentItem() || m_view.size_list->currentItem()->isHidden()) {
514 m_view.buttonSave->setEnabled(false);
515 m_view.buttonDelete->setEnabled(false);
516 m_view.buttonEdit->setEnabled(false);
517 m_view.buttonStart->setEnabled(false);
519 m_view.buttonSave->setEnabled(true);
520 m_view.buttonStart->setEnabled(m_view.size_list->currentItem()->flags() & Qt::ItemIsEnabled);
521 QString edit = m_view.size_list->currentItem()->data(EditableRole).toString();
522 if (edit.isEmpty() || !edit.endsWith("customprofiles.xml")) {
523 m_view.buttonDelete->setEnabled(false);
524 m_view.buttonEdit->setEnabled(false);
526 m_view.buttonDelete->setEnabled(true);
527 m_view.buttonEdit->setEnabled(true);
533 void RenderWidget::focusFirstVisibleItem()
535 if (m_view.size_list->currentItem() && !m_view.size_list->currentItem()->isHidden()) {
539 for (int ix = 0; ix < m_view.size_list->count(); ix++) {
540 QListWidgetItem *item = m_view.size_list->item(ix);
541 if (item && !item->isHidden()) {
542 m_view.size_list->setCurrentRow(ix);
546 if (!m_view.size_list->currentItem()) m_view.size_list->setCurrentRow(0);
550 void RenderWidget::slotExport(bool scriptExport)
552 QListWidgetItem *item = m_view.size_list->currentItem();
555 const QString dest = m_view.out_file->url().path();
556 if (dest.isEmpty()) return;
559 if (KMessageBox::warningYesNo(this, i18n("Output file already exists. Do you want to overwrite it ?")) != KMessageBox::Yes)
567 QString scriptsFolder = m_projectFolder + "/scripts/";
568 KStandardDirs::makeDir(scriptsFolder);
569 QString path = scriptsFolder + i18n("script") + QString::number(ix).rightJustified(3, '0', false) + ".sh";
570 while (QFile::exists(path)) {
572 path = scriptsFolder + i18n("script") + QString::number(ix).rightJustified(3, '0', false) + ".sh";
574 scriptName = QInputDialog::getText(this, i18n("Create Render Script"), i18n("Script name (will be saved in: %1)", scriptsFolder), QLineEdit::Normal, KUrl(path).fileName(), &ok);
575 if (!ok || scriptName.isEmpty()) return;
576 scriptName.prepend(scriptsFolder);
579 if (KMessageBox::warningYesNo(this, i18n("Script file already exists. Do you want to overwrite it ?")) != KMessageBox::Yes)
584 QStringList overlayargs;
585 if (m_view.tc_overlay->isChecked()) {
586 QString filterFile = KStandardDirs::locate("appdata", "metadata.properties");
587 overlayargs << "meta.attr.timecode=1" << "meta.attr.timecode.markup=#timecode";
588 overlayargs << "-attach" << "data_feed:attr_check" << "-attach";
589 overlayargs << "data_show:" + filterFile << "_fezzik=1" << "dynamic=1";
591 double startPos = -1;
593 if (m_view.render_guide->isChecked()) {
594 startPos = m_view.guide_start->itemData(m_view.guide_start->currentIndex()).toDouble();
595 endPos = m_view.guide_end->itemData(m_view.guide_end->currentIndex()).toDouble();
597 QString renderArgs = m_view.advanced_params->toPlainText().simplified();
599 // Adjust frame scale
602 if (m_view.rescale->isChecked() && m_view.rescale->isEnabled()) {
603 width = m_view.rescale_size->text().section('x', 0, 0).toInt();
604 height = m_view.rescale_size->text().section('x', 1, 1).toInt();
606 width = m_profile.width;
607 height = m_profile.height;
609 renderArgs.replace("%dar", '@' + QString::number(m_profile.display_aspect_num) + '/' + QString::number(m_profile.display_aspect_den));
612 if (m_view.scanning_list->currentIndex() == 1) renderArgs.append(" progressive=1");
613 else if (m_view.scanning_list->currentIndex() == 2) renderArgs.append(" progressive=0");
615 // disable audio if requested
616 if (!m_view.export_audio->isChecked())
617 renderArgs.append(" an=1 ");
619 // Check if the rendering profile is different from project profile,
620 // in which case we need to use the producer_comsumer from MLT
621 bool resizeProfile = false;
623 QString std = renderArgs;
624 QString destination = m_view.destination_list->itemData(m_view.destination_list->currentIndex()).toString();
625 if (std.startsWith("s=")) {
626 QString subsize = std.section(' ', 0, 0).toLower();
627 subsize = subsize.section("=", 1, 1);
628 const QString currentSize = QString::number(width) + 'x' + QString::number(height);
629 if (subsize != currentSize) resizeProfile = true;
630 } else if (std.contains(" s=")) {
631 QString subsize = std.section(" s=", 1, 1);
632 subsize = subsize.section(' ', 0, 0).toLower();
633 const QString currentSize = QString::number(width) + 'x' + QString::number(height);
634 if (subsize != currentSize) resizeProfile = true;
635 } else if (destination != "audioonly") {
636 // Add current size parametrer
637 renderArgs.append(QString(" s=%1x%2").arg(width).arg(height));
640 // insert item in running jobs list
641 QTreeWidgetItem *renderItem;
642 QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(dest, Qt::MatchExactly, 1);
643 if (!existing.isEmpty()) renderItem = existing.at(0);
644 else renderItem = new QTreeWidgetItem(m_view.running_jobs, QStringList() << QString() << dest << QString());
645 renderItem->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
646 renderItem->setData(1, Qt::UserRole + 1, QTime::currentTime());
648 // Set rendering type
649 QString group = m_view.size_list->currentItem()->data(MetaGroupRole).toString();
650 if (group == "dvd" && m_view.open_dvd->isChecked()) {
651 renderItem->setData(0, Qt::UserRole, group);
652 if (renderArgs.contains("profile=")) {
653 // rendering profile contains an MLT profile, so pass it to the running jog item, useful for dvd
654 QString prof = renderArgs.section("profile=", 1, 1);
655 prof = prof.section(' ', 0, 0);
656 kDebug() << "// render profile: " << prof;
657 renderItem->setData(0, Qt::UserRole + 1, prof);
659 } else if (group == "websites" && m_view.open_browser->isChecked()) {
660 renderItem->setData(0, Qt::UserRole, group);
662 QString url = m_view.size_list->currentItem()->data(ExtraRole).toString();
663 renderItem->setData(0, Qt::UserRole + 1, url);
666 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);
667 if (scriptName.isEmpty()) m_view.tabWidget->setCurrentIndex(1);
669 QTimer::singleShot(400, this, SLOT(parseScriptFiles()));
670 m_view.tabWidget->setCurrentIndex(2);
674 void RenderWidget::setProfile(MltVideoProfile profile)
677 //WARNING: this way to tell the video standard is a bit hackish...
678 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);
679 else m_view.format_selection->setCurrentIndex(1);
680 m_view.scanning_list->setCurrentIndex(0);
684 void RenderWidget::refreshView()
686 m_view.size_list->blockSignals(true);
687 QListWidgetItem *sizeItem;
690 KIcon brokenIcon("dialog-close");
691 if (m_view.destination_list->currentIndex() > 0)
692 destination = m_view.destination_list->itemData(m_view.destination_list->currentIndex()).toString();
695 if (destination == "dvd") m_view.open_dvd->setVisible(true);
696 else m_view.open_dvd->setVisible(false);
697 if (destination == "websites") m_view.open_browser->setVisible(true);
698 else m_view.open_browser->setVisible(false);
699 if (!destination.isEmpty() && QString("dvd websites audioonly").contains(destination))
700 m_view.rescale->setEnabled(false);
701 else m_view.rescale->setEnabled(true);
702 // hide groups that are not in the correct destination
703 for (int i = 0; i < m_view.format_list->count(); i++) {
704 sizeItem = m_view.format_list->item(i);
705 if (sizeItem->data(MetaGroupRole).toString() == destination) {
706 sizeItem->setHidden(false);
707 //kDebug() << "// SET GRP:: " << sizeItem->text() << ", METY:" << sizeItem->data(MetaGroupRole).toString();
708 } else sizeItem->setHidden(true);
711 // activate first visible item
712 QListWidgetItem * item = m_view.format_list->currentItem();
713 if (!item || item->isHidden()) {
714 for (int i = 0; i < m_view.format_list->count(); i++) {
715 if (!m_view.format_list->item(i)->isHidden()) {
716 m_view.format_list->setCurrentRow(i);
720 item = m_view.format_list->currentItem();
722 if (!item || item->isHidden()) {
723 m_view.format_list->setEnabled(false);
724 m_view.size_list->setEnabled(false);
727 m_view.format_list->setEnabled(true);
728 m_view.size_list->setEnabled(true);
731 for (int i = 0; i < m_view.format_list->count() && count < 2; i++) {
732 if (!m_view.format_list->isRowHidden(i)) count++;
734 if (count > 1) m_view.format_list->setVisible(true);
735 else m_view.format_list->setVisible(false);
737 QString group = item->text();
738 bool firstSelected = false;
739 const QStringList formatsList = KdenliveSettings::supportedformats();
740 const QStringList vcodecsList = KdenliveSettings::videocodecs();
741 const QStringList acodecsList = KdenliveSettings::audiocodecs();
743 for (int i = 0; i < m_view.size_list->count(); i++) {
744 sizeItem = m_view.size_list->item(i);
745 if ((sizeItem->data(GroupRole) == group || sizeItem->data(GroupRole).toString().isEmpty()) && sizeItem->data(MetaGroupRole) == destination) {
746 std = sizeItem->data(StandardRole).toString();
747 if (!std.isEmpty()) {
748 if (std.contains("PAL", Qt::CaseInsensitive)) sizeItem->setHidden(m_view.format_selection->currentIndex() != 0);
749 else if (std.contains("NTSC", Qt::CaseInsensitive)) sizeItem->setHidden(m_view.format_selection->currentIndex() != 1);
751 sizeItem->setHidden(false);
752 if (!firstSelected) m_view.size_list->setCurrentItem(sizeItem);
753 firstSelected = true;
756 if (!sizeItem->isHidden()) {
757 // Make sure the selected profile uses an installed avformat codec / format
758 std = sizeItem->data(ParamsRole).toString();
760 if (!formatsList.isEmpty()) {
762 if (std.startsWith("f=")) format = std.section("f=", 1, 1);
763 else if (std.contains(" f=")) format = std.section(" f=", 1, 1);
764 if (!format.isEmpty()) {
765 format = format.section(' ', 0, 0).toLower();
766 if (!formatsList.contains(format)) {
767 kDebug() << "***** UNSUPPORTED F: " << format;
768 //sizeItem->setHidden(true);
769 sizeItem->setFlags(Qt::ItemIsSelectable);
770 sizeItem->setToolTip(i18n("Unsupported video format: %1", format));
771 sizeItem->setIcon(brokenIcon);
775 if (!acodecsList.isEmpty() && !sizeItem->isHidden()) {
777 if (std.startsWith("acodec=")) format = std.section("acodec=", 1, 1);
778 else if (std.contains(" acodec=")) format = std.section(" acodec=", 1, 1);
779 if (!format.isEmpty()) {
780 format = format.section(' ', 0, 0).toLower();
781 if (!acodecsList.contains(format)) {
782 kDebug() << "***** UNSUPPORTED ACODEC: " << format;
783 //sizeItem->setHidden(true);
784 sizeItem->setFlags(Qt::ItemIsSelectable);
785 sizeItem->setToolTip(i18n("Unsupported audio codec: %1", format));
786 sizeItem->setIcon(brokenIcon);
790 if (!vcodecsList.isEmpty() && !sizeItem->isHidden()) {
792 if (std.startsWith("vcodec=")) format = std.section("vcodec=", 1, 1);
793 else if (std.contains(" vcodec=")) format = std.section(" vcodec=", 1, 1);
794 if (!format.isEmpty()) {
795 format = format.section(' ', 0, 0).toLower();
796 if (!vcodecsList.contains(format)) {
797 kDebug() << "***** UNSUPPORTED VCODEC: " << format;
798 //sizeItem->setHidden(true);
799 sizeItem->setFlags(Qt::ItemIsSelectable);
800 sizeItem->setToolTip(i18n("Unsupported video codec: %1", format));
801 sizeItem->setIcon(brokenIcon);
806 } else sizeItem->setHidden(true);
808 focusFirstVisibleItem();
809 m_view.size_list->blockSignals(false);
813 KUrl RenderWidget::filenameWithExtension(KUrl url, QString extension)
816 if (!url.isEmpty()) {
818 int pos = path.lastIndexOf('.') + 1;
819 if (pos == 0) path.append('.' + extension);
820 else path = path.left(pos) + extension;
823 path = m_projectFolder + "/untitled." + extension;
829 void RenderWidget::refreshParams()
831 QListWidgetItem *item = m_view.size_list->currentItem();
832 if (!item || item->isHidden()) {
833 m_view.advanced_params->clear();
834 m_view.buttonStart->setEnabled(false);
837 QString params = item->data(ParamsRole).toString();
838 QString extension = item->data(ExtensionRole).toString();
839 m_view.advanced_params->setPlainText(params);
840 QString destination = m_view.destination_list->itemData(m_view.destination_list->currentIndex()).toString();
841 if (params.contains(" s=") || destination == "audioonly") {
842 // profile has a fixed size, do not allow resize
843 m_view.rescale->setEnabled(false);
844 m_view.rescale_size->setEnabled(false);
846 m_view.rescale->setEnabled(true);
847 m_view.rescale_size->setEnabled(true);
849 KUrl url = filenameWithExtension(m_view.out_file->url(), extension);
850 m_view.out_file->setUrl(url);
851 // if (!url.isEmpty()) {
852 // QString path = url.path();
853 // int pos = path.lastIndexOf('.') + 1;
854 // if (pos == 0) path.append('.' + extension);
855 // else path = path.left(pos) + extension;
856 // m_view.out_file->setUrl(KUrl(path));
858 // m_view.out_file->setUrl(KUrl(QDir::homePath() + "/untitled." + extension));
860 m_view.out_file->setFilter("*." + extension);
861 QString edit = item->data(EditableRole).toString();
862 if (edit.isEmpty() || !edit.endsWith("customprofiles.xml")) {
863 m_view.buttonDelete->setEnabled(false);
864 m_view.buttonEdit->setEnabled(false);
866 m_view.buttonDelete->setEnabled(true);
867 m_view.buttonEdit->setEnabled(true);
870 m_view.buttonStart->setEnabled(m_view.size_list->currentItem()->flags() & Qt::ItemIsEnabled);
873 void RenderWidget::reloadProfiles()
878 void RenderWidget::parseProfiles(QString meta, QString group, QString profile)
880 m_view.size_list->clear();
881 m_view.format_list->clear();
882 m_view.destination_list->clear();
883 m_view.destination_list->addItem(KIcon("video-x-generic"), i18n("File rendering"));
884 m_view.destination_list->addItem(KIcon("media-optical"), i18n("DVD"), "dvd");
885 m_view.destination_list->addItem(KIcon("audio-x-generic"), i18n("Audio only"), "audioonly");
886 m_view.destination_list->addItem(KIcon("applications-internet"), i18n("Web sites"), "websites");
887 m_view.destination_list->addItem(KIcon("applications-multimedia"), i18n("Media players"), "mediaplayers");
888 m_view.destination_list->addItem(KIcon("drive-harddisk"), i18n("Lossless / HQ"), "lossless");
889 m_view.destination_list->addItem(KIcon("pda"), i18n("Mobile devices"), "mobile");
891 QString exportFile = KStandardDirs::locate("appdata", "export/profiles.xml");
892 parseFile(exportFile, false);
895 QString exportFolder = KStandardDirs::locateLocal("appdata", "export/");
896 QDir directory = QDir(exportFolder);
899 QStringList fileList = directory.entryList(filter, QDir::Files);
900 // We should parse customprofiles.xml in last position, so that user profiles
901 // can also override profiles installed by KNewStuff
902 fileList.removeAll("customprofiles.xml");
903 foreach(const QString &filename, fileList)
904 parseFile(exportFolder + '/' + filename, true);
905 if (QFile::exists(exportFolder + "/customprofiles.xml")) parseFile(exportFolder + "/customprofiles.xml", true);
907 if (!meta.isEmpty()) {
908 m_view.destination_list->blockSignals(true);
909 m_view.destination_list->setCurrentIndex(m_view.destination_list->findData(meta));
910 m_view.destination_list->blockSignals(false);
913 QList<QListWidgetItem *> child;
914 if (!group.isEmpty()) child = m_view.format_list->findItems(group, Qt::MatchExactly);
915 if (!child.isEmpty()) {
916 for (int i = 0; i < child.count(); i++) {
917 if (child.at(i)->data(MetaGroupRole).toString() == meta) {
918 m_view.format_list->setCurrentItem(child.at(i));
924 if (!profile.isEmpty()) child = m_view.size_list->findItems(profile, Qt::MatchExactly);
925 if (!child.isEmpty()) m_view.size_list->setCurrentItem(child.at(0));
928 void RenderWidget::parseFile(QString exportFile, bool editable)
930 kDebug() << "// Parsing file: " << exportFile;
931 kDebug() << "------------------------------";
933 QFile file(exportFile);
934 doc.setContent(&file, false);
936 QDomElement documentElement;
937 QDomElement profileElement;
939 QListWidgetItem *item;
940 QDomNodeList groups = doc.elementsByTagName("group");
942 if (editable || groups.count() == 0) {
943 QDomElement profiles = doc.documentElement();
944 if (editable && profiles.attribute("version", 0).toInt() < 1) {
945 kDebug() << "// OLD profile version";
946 // this is an old profile version, update it
948 QDomElement newprofiles = newdoc.createElement("profiles");
949 newprofiles.setAttribute("version", 1);
950 newdoc.appendChild(newprofiles);
951 QDomNodeList profilelist = doc.elementsByTagName("profile");
952 for (int i = 0; i < profilelist.count(); i++) {
953 QString category = i18n("Custom");
955 QDomNode parent = profilelist.at(i).parentNode();
956 if (!parent.isNull()) {
957 QDomElement parentNode = parent.toElement();
958 if (parentNode.hasAttribute("name")) category = parentNode.attribute("name");
959 extension = parentNode.attribute("extension");
961 profilelist.at(i).toElement().setAttribute("category", category);
962 if (!extension.isEmpty()) profilelist.at(i).toElement().setAttribute("extension", extension);
963 QDomNode n = profilelist.at(i).cloneNode();
964 newprofiles.appendChild(newdoc.importNode(n, true));
966 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
967 KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
970 QTextStream out(&file);
971 out << newdoc.toString();
973 parseFile(exportFile, editable);
977 QDomNode node = doc.elementsByTagName("profile").at(0);
979 kDebug() << "// Export file: " << exportFile << " IS BROKEN";
983 while (!node.isNull()) {
984 QDomElement profile = node.toElement();
985 QString profileName = profile.attribute("name");
986 QString standard = profile.attribute("standard");
987 QString params = profile.attribute("args");
988 QString category = profile.attribute("category", i18n("Custom"));
989 QString dest = profile.attribute("destinationid");
990 QString prof_extension = profile.attribute("extension");
991 if (!prof_extension.isEmpty()) extension = prof_extension;
993 QList <QListWidgetItem *> list = m_view.format_list->findItems(category, Qt::MatchExactly);
995 for (int j = 0; j < list.count(); j++) {
996 if (list.at(j)->data(MetaGroupRole) == dest) {
1002 item = new QListWidgetItem(category, m_view.format_list);
1003 item->setData(MetaGroupRole, dest);
1006 // Check if item with same name already exists and replace it,
1007 // allowing to override default profiles
1009 list = m_view.size_list->findItems(profileName, Qt::MatchExactly);
1011 for (int j = 0; j < list.count(); j++) {
1012 if (list.at(j)->data(MetaGroupRole) == dest) {
1013 QListWidgetItem *duplicate = list.takeAt(j);
1019 item = new QListWidgetItem(profileName, m_view.size_list);
1020 //kDebug() << "// ADDINg item with name: " << profileName << ", GRP" << category << ", DEST:" << dest ;
1021 item->setData(GroupRole, category);
1022 item->setData(MetaGroupRole, dest);
1023 item->setData(ExtensionRole, extension);
1024 item->setData(RenderRole, "avformat");
1025 item->setData(StandardRole, standard);
1026 item->setData(ParamsRole, params);
1027 if (profile.hasAttribute("url")) item->setData(ExtraRole, profile.attribute("url"));
1029 item->setData(EditableRole, exportFile);
1030 if (exportFile.endsWith("customprofiles.xml")) item->setIcon(KIcon("emblem-favorite"));
1031 else item->setIcon(KIcon("applications-internet"));
1033 node = doc.elementsByTagName("profile").at(count);
1041 QString profileName;
1043 QString prof_extension;
1049 while (!groups.item(i).isNull()) {
1050 documentElement = groups.item(i).toElement();
1051 QDomNode gname = documentElement.elementsByTagName("groupname").at(0);
1052 QString metagroupName;
1053 QString metagroupId;
1054 if (!gname.isNull()) {
1055 metagroupName = gname.firstChild().nodeValue();
1056 metagroupId = gname.toElement().attribute("id");
1057 if (!metagroupName.isEmpty() && !m_view.destination_list->contains(metagroupName)) {
1058 if (metagroupId == "dvd") icon = KIcon("media-optical");
1059 else if (metagroupId == "audioonly") icon = KIcon("audio-x-generic");
1060 else if (metagroupId == "websites") icon = KIcon("applications-internet");
1061 else if (metagroupId == "mediaplayers") icon = KIcon("applications-multimedia");
1062 else if (metagroupId == "lossless") icon = KIcon("drive-harddisk");
1063 else if (metagroupId == "mobile") icon = KIcon("pda");
1064 m_view.destination_list->addItem(icon, i18n(metagroupName.toUtf8().data()), metagroupId);
1067 groupName = documentElement.attribute("name", i18n("Custom"));
1068 extension = documentElement.attribute("extension", QString());
1069 renderer = documentElement.attribute("renderer", QString());
1070 QList <QListWidgetItem *> list = m_view.format_list->findItems(groupName, Qt::MatchExactly);
1071 bool exists = false;
1072 for (int j = 0; j < list.count(); j++) {
1073 if (list.at(j)->data(MetaGroupRole) == metagroupId) {
1079 item = new QListWidgetItem(groupName, m_view.format_list);
1080 item->setData(MetaGroupRole, metagroupId);
1083 QDomNode n = groups.item(i).firstChild();
1084 while (!n.isNull()) {
1085 if (n.toElement().tagName() != "profile") {
1086 n = n.nextSibling();
1089 profileElement = n.toElement();
1090 profileName = profileElement.attribute("name");
1091 standard = profileElement.attribute("standard");
1092 params = profileElement.attribute("args");
1093 prof_extension = profileElement.attribute("extension");
1094 if (!prof_extension.isEmpty()) extension = prof_extension;
1095 item = new QListWidgetItem(profileName, m_view.size_list);
1096 item->setData(GroupRole, groupName);
1097 item->setData(MetaGroupRole, metagroupId);
1098 item->setData(ExtensionRole, extension);
1099 item->setData(RenderRole, renderer);
1100 item->setData(StandardRole, standard);
1101 item->setData(ParamsRole, params);
1102 if (profileElement.hasAttribute("url")) item->setData(ExtraRole, profileElement.attribute("url"));
1103 if (editable) item->setData(EditableRole, exportFile);
1104 n = n.nextSibling();
1111 void RenderWidget::setRenderJob(const QString &dest, int progress)
1113 QTreeWidgetItem *item;
1114 QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(dest, Qt::MatchExactly, 1);
1115 if (!existing.isEmpty()) item = existing.at(0);
1116 else item = new QTreeWidgetItem(m_view.running_jobs, QStringList() << QString() << dest << QString());
1117 item->setData(2, Qt::UserRole, progress);
1118 if (progress == 0) {
1119 item->setIcon(0, KIcon("system-run"));
1120 item->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
1121 item->setData(1, Qt::UserRole + 1, QTime::currentTime());
1124 QTime startTime = item->data(1, Qt::UserRole + 1).toTime();
1125 int seconds = startTime.secsTo(QTime::currentTime());;
1126 const QString t = i18n("Estimated time %1", QTime().addSecs(seconds * (100 - progress) / progress).toString("hh:mm:ss"));
1127 item->setData(1, Qt::UserRole, t);
1131 void RenderWidget::setRenderStatus(const QString &dest, int status, const QString &error)
1133 QTreeWidgetItem *item;
1134 QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(dest, Qt::MatchExactly, 1);
1135 if (!existing.isEmpty()) item = existing.at(0);
1136 else item = new QTreeWidgetItem(m_view.running_jobs, QStringList() << QString() << dest << QString());
1138 // Job finished successfully
1139 item->setIcon(0, KIcon("dialog-ok"));
1140 item->setData(2, Qt::UserRole, 100);
1141 QTime startTime = item->data(1, Qt::UserRole + 1).toTime();
1142 int seconds = startTime.secsTo(QTime::currentTime());
1143 const QTime tm = QTime().addSecs(seconds);
1144 const QString t = i18n("Rendering finished in %1", tm.toString("hh:mm:ss"));
1145 item->setData(1, Qt::UserRole, t);
1146 QString itemGroup = item->data(0, Qt::UserRole).toString();
1147 if (itemGroup == "dvd") {
1148 emit openDvdWizard(item->text(1), item->data(0, Qt::UserRole + 1).toString());
1149 } else if (itemGroup == "websites") {
1150 QString url = item->data(0, Qt::UserRole + 1).toString();
1151 if (!url.isEmpty()) new KRun(url, this);
1153 } else if (status == -2) {
1154 // Rendering crashed
1155 item->setData(1, Qt::UserRole, i18n("Rendering crashed"));
1156 item->setIcon(0, KIcon("dialog-close"));
1157 item->setData(2, Qt::UserRole, 100);
1158 m_view.error_log->append(i18n("<strong>Rendering of %1 crashed</strong><br />", dest));
1159 m_view.error_log->append(error);
1160 m_view.error_log->append("<hr />");
1161 m_view.error_box->setVisible(true);
1162 } else if (status == -3) {
1164 item->setData(1, Qt::UserRole, i18n("Rendering aborted"));
1165 item->setIcon(0, KIcon("dialog-cancel"));
1166 item->setData(2, Qt::UserRole, 100);
1171 void RenderWidget::slotAbortCurrentJob()
1173 QTreeWidgetItem *current = m_view.running_jobs->currentItem();
1174 if (current) emit abortProcess(current->text(1));
1177 void RenderWidget::slotCheckJob()
1179 bool activate = false;
1180 QTreeWidgetItem *current = m_view.running_jobs->currentItem();
1182 int percent = current->data(2, Qt::UserRole).toInt();
1183 if (percent < 100) activate = true;
1185 m_view.abort_job->setEnabled(activate);
1188 void RenderWidget::parseScriptFiles()
1190 QStringList scriptsFilter;
1191 scriptsFilter << "*.sh";
1192 m_view.scripts_list->clear();
1194 QTreeWidgetItem *item;
1195 // List the project scripts
1196 QStringList scriptFiles = QDir(m_projectFolder + "/scripts").entryList(scriptsFilter, QDir::Files);
1197 for (int i = 0; i < scriptFiles.size(); ++i) {
1198 KUrl scriptpath(m_projectFolder + "/scripts/" + scriptFiles.at(i));
1199 item = new QTreeWidgetItem(m_view.scripts_list, QStringList() << scriptpath.fileName());
1201 QFile file(scriptpath.path());
1202 if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
1203 while (!file.atEnd()) {
1204 QByteArray line = file.readLine();
1205 if (line.startsWith("TARGET=")) {
1206 target = QString(line).section("TARGET=", 1);
1207 target.remove(QChar('"'));
1213 item->setSizeHint(0, QSize(m_view.scripts_list->columnWidth(0), fontMetrics().height() * 2));
1214 item->setData(0, Qt::UserRole, target);
1215 item->setData(0, Qt::UserRole + 1, scriptpath.path());
1217 bool activate = false;
1218 QTreeWidgetItemIterator it(m_view.scripts_list);
1220 kDebug() << "// FOUND SCRIPT ITEM:" << (*it)->text(0);
1221 // Selecting item does not work, why ???
1222 m_view.scripts_list->setCurrentItem(*it);
1223 (*it)->setSelected(true);
1226 kDebug() << "SELECTED SCRIPTS: " << m_view.scripts_list->selectedItems().count();
1227 m_view.start_script->setEnabled(activate);
1228 m_view.delete_script->setEnabled(activate);
1231 void RenderWidget::slotCheckScript()
1233 bool activate = false;
1234 QTreeWidgetItemIterator it(m_view.scripts_list);
1235 if (*it) activate = true;
1236 m_view.start_script->setEnabled(activate);
1237 m_view.delete_script->setEnabled(activate);
1240 void RenderWidget::slotStartScript()
1242 QTreeWidgetItem *item = m_view.scripts_list->currentItem();
1244 QString path = item->data(0, Qt::UserRole + 1).toString();
1245 QProcess::startDetached(path);
1246 m_view.tabWidget->setCurrentIndex(1);
1250 void RenderWidget::slotDeleteScript()
1252 QTreeWidgetItem *item = m_view.scripts_list->currentItem();
1254 QString path = item->data(0, Qt::UserRole + 1).toString();
1255 KIO::NetAccess::del(path + ".westley", this);
1256 KIO::NetAccess::del(path, this);
1261 void RenderWidget::slotGenerateScript()