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));
341 parseProfiles(newMetaGroupId, newGroupName, newProfileName);
346 void RenderWidget::slotEditProfile()
348 QListWidgetItem *item = m_view.size_list->currentItem();
350 QString currentGroup = m_view.format_list->currentItem()->text();
352 QString params = item->data(ParamsRole).toString();
353 QString extension = item->data(ExtensionRole).toString();
354 QString currentProfile = item->text();
356 Ui::SaveProfile_UI ui;
357 QDialog *d = new QDialog(this);
360 for (int i = 0; i < m_view.destination_list->count(); i++)
361 ui.destination_list->addItem(m_view.destination_list->itemIcon(i), m_view.destination_list->itemText(i), m_view.destination_list->itemData(i, Qt::UserRole));
363 ui.destination_list->setCurrentIndex(m_view.destination_list->currentIndex());
364 QString dest = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
366 QString customGroup = m_view.format_list->currentItem()->text();
367 if (customGroup.isEmpty()) customGroup = i18n("Custom");
368 ui.group_name->setText(customGroup);
370 ui.profile_name->setText(currentProfile);
371 ui.extension->setText(extension);
372 ui.parameters->setText(params);
373 ui.profile_name->setFocus();
374 d->setWindowTitle(i18n("Edit Profile"));
375 if (d->exec() == QDialog::Accepted) {
376 slotDeleteProfile(false);
377 QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
379 QFile file(exportFile);
380 doc.setContent(&file, false);
382 QDomElement documentElement;
383 QDomElement profiles = doc.documentElement();
385 if (profiles.isNull() || profiles.tagName() != "profiles") {
387 profiles = doc.createElement("profiles");
388 profiles.setAttribute("version", 1);
389 doc.appendChild(profiles);
392 int version = profiles.attribute("version", 0).toInt();
394 kDebug() << "// OLD profile version";
396 profiles = doc.createElement("profiles");
397 profiles.setAttribute("version", 1);
398 doc.appendChild(profiles);
401 QString newProfileName = ui.profile_name->text().simplified();
402 QString newGroupName = ui.group_name->text().simplified();
403 if (newGroupName.isEmpty()) newGroupName = i18n("Custom");
404 QString newMetaGroupId = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
405 QDomNodeList profilelist = doc.elementsByTagName("profile");
407 while (!profilelist.item(i).isNull()) {
408 // make sure a profile with same name doesn't exist
409 documentElement = profilelist.item(i).toElement();
410 QString profileName = documentElement.attribute("name");
411 if (profileName == newProfileName) {
412 // a profile with that same name already exists
414 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);
416 if (profileName == newProfileName) {
417 profiles.removeChild(profilelist.item(i));
424 QDomElement profileElement = doc.createElement("profile");
425 profileElement.setAttribute("name", newProfileName);
426 profileElement.setAttribute("category", newGroupName);
427 profileElement.setAttribute("destinationid", newMetaGroupId);
428 profileElement.setAttribute("extension", ui.extension->text().simplified());
429 profileElement.setAttribute("args", ui.parameters->toPlainText().simplified());
430 profiles.appendChild(profileElement);
432 //QCString save = doc.toString().utf8();
434 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
435 KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
438 QTextStream out(&file);
439 out << doc.toString();
440 if (file.error() != QFile::NoError) {
441 KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
446 parseProfiles(newMetaGroupId, newGroupName, newProfileName);
450 void RenderWidget::slotDeleteProfile(bool refresh)
452 //TODO: delete a profile installed by KNewStuff the easy way
454 QString edit = m_view.size_list->currentItem()->data(EditableRole).toString();
455 if (!edit.endsWith("customprofiles.xml")) {
456 // This is a KNewStuff installed file, process through KNS
457 KNS::Engine engine(0);
458 if (engine.init("kdenlive_render.knsrc")) {
459 KNS::Entry::List entries;
463 QString currentGroup = m_view.format_list->currentItem()->text();
464 QString currentProfile = m_view.size_list->currentItem()->text();
465 QString metaGroupId = m_view.destination_list->itemData(m_view.destination_list->currentIndex(), Qt::UserRole).toString();
467 QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
469 QFile file(exportFile);
470 doc.setContent(&file, false);
473 QDomElement documentElement;
474 QDomNodeList profiles = doc.elementsByTagName("profile");
480 while (!profiles.item(i).isNull()) {
481 documentElement = profiles.item(i).toElement();
482 profileName = documentElement.attribute("name");
483 groupName = documentElement.attribute("category");
484 destination = documentElement.attribute("destinationid");
486 if (profileName == currentProfile && groupName == currentGroup && destination == metaGroupId) {
487 kDebug() << "// GOT it: " << profileName;
488 doc.documentElement().removeChild(profiles.item(i));
494 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
495 KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
498 QTextStream out(&file);
499 out << doc.toString();
500 if (file.error() != QFile::NoError) {
501 KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
507 parseProfiles(metaGroupId, currentGroup);
508 focusFirstVisibleItem();
512 void RenderWidget::updateButtons()
514 if (!m_view.size_list->currentItem() || m_view.size_list->currentItem()->isHidden()) {
515 m_view.buttonSave->setEnabled(false);
516 m_view.buttonDelete->setEnabled(false);
517 m_view.buttonEdit->setEnabled(false);
518 m_view.buttonStart->setEnabled(false);
520 m_view.buttonSave->setEnabled(true);
521 m_view.buttonStart->setEnabled(m_view.size_list->currentItem()->flags() & Qt::ItemIsEnabled);
522 QString edit = m_view.size_list->currentItem()->data(EditableRole).toString();
523 if (edit.isEmpty() || !edit.endsWith("customprofiles.xml")) {
524 m_view.buttonDelete->setEnabled(false);
525 m_view.buttonEdit->setEnabled(false);
527 m_view.buttonDelete->setEnabled(true);
528 m_view.buttonEdit->setEnabled(true);
534 void RenderWidget::focusFirstVisibleItem()
536 if (m_view.size_list->currentItem() && !m_view.size_list->currentItem()->isHidden()) {
540 for (int ix = 0; ix < m_view.size_list->count(); ix++) {
541 QListWidgetItem *item = m_view.size_list->item(ix);
542 if (item && !item->isHidden()) {
543 m_view.size_list->setCurrentRow(ix);
547 if (!m_view.size_list->currentItem()) m_view.size_list->setCurrentRow(0);
551 void RenderWidget::slotExport(bool scriptExport)
553 QListWidgetItem *item = m_view.size_list->currentItem();
556 const QString dest = m_view.out_file->url().path();
557 if (dest.isEmpty()) return;
560 if (KMessageBox::warningYesNo(this, i18n("Output file already exists. Do you want to overwrite it?")) != KMessageBox::Yes)
568 QString scriptsFolder = m_projectFolder + "/scripts/";
569 KStandardDirs::makeDir(scriptsFolder);
570 QString path = scriptsFolder + i18n("script") + QString::number(ix).rightJustified(3, '0', false) + ".sh";
571 while (QFile::exists(path)) {
573 path = scriptsFolder + i18n("script") + QString::number(ix).rightJustified(3, '0', false) + ".sh";
575 scriptName = QInputDialog::getText(this, i18n("Create Render Script"), i18n("Script name (will be saved in: %1)", scriptsFolder), QLineEdit::Normal, KUrl(path).fileName(), &ok);
576 if (!ok || scriptName.isEmpty()) return;
577 scriptName.prepend(scriptsFolder);
580 if (KMessageBox::warningYesNo(this, i18n("Script file already exists. Do you want to overwrite it?")) != KMessageBox::Yes)
585 QStringList overlayargs;
586 if (m_view.tc_overlay->isChecked()) {
587 QString filterFile = KStandardDirs::locate("appdata", "metadata.properties");
588 overlayargs << "meta.attr.timecode=1" << "meta.attr.timecode.markup=#timecode";
589 overlayargs << "-attach" << "data_feed:attr_check" << "-attach";
590 overlayargs << "data_show:" + filterFile << "_fezzik=1" << "dynamic=1";
592 double startPos = -1;
594 if (m_view.render_guide->isChecked()) {
595 startPos = m_view.guide_start->itemData(m_view.guide_start->currentIndex()).toDouble();
596 endPos = m_view.guide_end->itemData(m_view.guide_end->currentIndex()).toDouble();
598 QString renderArgs = m_view.advanced_params->toPlainText().simplified();
600 // Adjust frame scale
603 if (m_view.rescale->isChecked() && m_view.rescale->isEnabled()) {
604 width = m_view.rescale_size->text().section('x', 0, 0).toInt();
605 height = m_view.rescale_size->text().section('x', 1, 1).toInt();
607 width = m_profile.width;
608 height = m_profile.height;
610 renderArgs.replace("%dar", '@' + QString::number(m_profile.display_aspect_num) + '/' + QString::number(m_profile.display_aspect_den));
613 if (m_view.scanning_list->currentIndex() == 1) renderArgs.append(" progressive=1");
614 else if (m_view.scanning_list->currentIndex() == 2) renderArgs.append(" progressive=0");
616 // disable audio if requested
617 if (!m_view.export_audio->isChecked())
618 renderArgs.append(" an=1 ");
620 // Check if the rendering profile is different from project profile,
621 // in which case we need to use the producer_comsumer from MLT
622 bool resizeProfile = false;
624 QString std = renderArgs;
625 QString destination = m_view.destination_list->itemData(m_view.destination_list->currentIndex()).toString();
626 if (std.startsWith("s=")) {
627 QString subsize = std.section(' ', 0, 0).toLower();
628 subsize = subsize.section("=", 1, 1);
629 const QString currentSize = QString::number(width) + 'x' + QString::number(height);
630 if (subsize != currentSize) resizeProfile = true;
631 } else if (std.contains(" s=")) {
632 QString subsize = std.section(" s=", 1, 1);
633 subsize = subsize.section(' ', 0, 0).toLower();
634 const QString currentSize = QString::number(width) + 'x' + QString::number(height);
635 if (subsize != currentSize) resizeProfile = true;
636 } else if (destination != "audioonly") {
637 // Add current size parametrer
638 renderArgs.append(QString(" s=%1x%2").arg(width).arg(height));
641 // insert item in running jobs list
642 QTreeWidgetItem *renderItem;
643 QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(dest, Qt::MatchExactly, 1);
644 if (!existing.isEmpty()) renderItem = existing.at(0);
645 else renderItem = new QTreeWidgetItem(m_view.running_jobs, QStringList() << QString() << dest << QString());
646 renderItem->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
647 renderItem->setData(1, Qt::UserRole + 1, QTime::currentTime());
649 // Set rendering type
650 QString group = m_view.size_list->currentItem()->data(MetaGroupRole).toString();
651 if (group == "dvd" && m_view.open_dvd->isChecked()) {
652 renderItem->setData(0, Qt::UserRole, group);
653 if (renderArgs.contains("profile=")) {
654 // rendering profile contains an MLT profile, so pass it to the running jog item, useful for dvd
655 QString prof = renderArgs.section("profile=", 1, 1);
656 prof = prof.section(' ', 0, 0);
657 kDebug() << "// render profile: " << prof;
658 renderItem->setData(0, Qt::UserRole + 1, prof);
660 } else if (group == "websites" && m_view.open_browser->isChecked()) {
661 renderItem->setData(0, Qt::UserRole, group);
663 QString url = m_view.size_list->currentItem()->data(ExtraRole).toString();
664 renderItem->setData(0, Qt::UserRole + 1, url);
667 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);
668 if (scriptName.isEmpty()) m_view.tabWidget->setCurrentIndex(1);
670 QTimer::singleShot(400, this, SLOT(parseScriptFiles()));
671 m_view.tabWidget->setCurrentIndex(2);
675 void RenderWidget::setProfile(MltVideoProfile profile)
678 //WARNING: this way to tell the video standard is a bit hackish...
679 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);
680 else m_view.format_selection->setCurrentIndex(1);
681 m_view.scanning_list->setCurrentIndex(0);
685 void RenderWidget::refreshView()
687 m_view.size_list->blockSignals(true);
688 QListWidgetItem *sizeItem;
691 KIcon brokenIcon("dialog-close");
692 if (m_view.destination_list->currentIndex() > 0)
693 destination = m_view.destination_list->itemData(m_view.destination_list->currentIndex()).toString();
696 if (destination == "dvd") m_view.open_dvd->setVisible(true);
697 else m_view.open_dvd->setVisible(false);
698 if (destination == "websites") m_view.open_browser->setVisible(true);
699 else m_view.open_browser->setVisible(false);
700 if (!destination.isEmpty() && QString("dvd websites audioonly").contains(destination))
701 m_view.rescale->setEnabled(false);
702 else m_view.rescale->setEnabled(true);
703 // hide groups that are not in the correct destination
704 for (int i = 0; i < m_view.format_list->count(); i++) {
705 sizeItem = m_view.format_list->item(i);
706 if (sizeItem->data(MetaGroupRole).toString() == destination) {
707 sizeItem->setHidden(false);
708 //kDebug() << "// SET GRP:: " << sizeItem->text() << ", METY:" << sizeItem->data(MetaGroupRole).toString();
709 } else sizeItem->setHidden(true);
712 // activate first visible item
713 QListWidgetItem * item = m_view.format_list->currentItem();
714 if (!item || item->isHidden()) {
715 for (int i = 0; i < m_view.format_list->count(); i++) {
716 if (!m_view.format_list->item(i)->isHidden()) {
717 m_view.format_list->setCurrentRow(i);
721 item = m_view.format_list->currentItem();
723 if (!item || item->isHidden()) {
724 m_view.format_list->setEnabled(false);
725 m_view.size_list->setEnabled(false);
728 m_view.format_list->setEnabled(true);
729 m_view.size_list->setEnabled(true);
732 for (int i = 0; i < m_view.format_list->count() && count < 2; i++) {
733 if (!m_view.format_list->isRowHidden(i)) count++;
735 if (count > 1) m_view.format_list->setVisible(true);
736 else m_view.format_list->setVisible(false);
738 QString group = item->text();
739 bool firstSelected = false;
740 const QStringList formatsList = KdenliveSettings::supportedformats();
741 const QStringList vcodecsList = KdenliveSettings::videocodecs();
742 const QStringList acodecsList = KdenliveSettings::audiocodecs();
744 for (int i = 0; i < m_view.size_list->count(); i++) {
745 sizeItem = m_view.size_list->item(i);
746 if ((sizeItem->data(GroupRole) == group || sizeItem->data(GroupRole).toString().isEmpty()) && sizeItem->data(MetaGroupRole) == destination) {
747 std = sizeItem->data(StandardRole).toString();
748 if (!std.isEmpty()) {
749 if (std.contains("PAL", Qt::CaseInsensitive)) sizeItem->setHidden(m_view.format_selection->currentIndex() != 0);
750 else if (std.contains("NTSC", Qt::CaseInsensitive)) sizeItem->setHidden(m_view.format_selection->currentIndex() != 1);
752 sizeItem->setHidden(false);
753 if (!firstSelected) m_view.size_list->setCurrentItem(sizeItem);
754 firstSelected = true;
757 if (!sizeItem->isHidden()) {
758 // Make sure the selected profile uses an installed avformat codec / format
759 std = sizeItem->data(ParamsRole).toString();
761 if (!formatsList.isEmpty()) {
763 if (std.startsWith("f=")) format = std.section("f=", 1, 1);
764 else if (std.contains(" f=")) format = std.section(" f=", 1, 1);
765 if (!format.isEmpty()) {
766 format = format.section(' ', 0, 0).toLower();
767 if (!formatsList.contains(format)) {
768 kDebug() << "***** UNSUPPORTED F: " << format;
769 //sizeItem->setHidden(true);
770 sizeItem->setFlags(Qt::ItemIsSelectable);
771 sizeItem->setToolTip(i18n("Unsupported video format: %1", format));
772 sizeItem->setIcon(brokenIcon);
776 if (!acodecsList.isEmpty() && !sizeItem->isHidden()) {
778 if (std.startsWith("acodec=")) format = std.section("acodec=", 1, 1);
779 else if (std.contains(" acodec=")) format = std.section(" acodec=", 1, 1);
780 if (!format.isEmpty()) {
781 format = format.section(' ', 0, 0).toLower();
782 if (!acodecsList.contains(format)) {
783 kDebug() << "***** UNSUPPORTED ACODEC: " << format;
784 //sizeItem->setHidden(true);
785 sizeItem->setFlags(Qt::ItemIsSelectable);
786 sizeItem->setToolTip(i18n("Unsupported audio codec: %1", format));
787 sizeItem->setIcon(brokenIcon);
791 if (!vcodecsList.isEmpty() && !sizeItem->isHidden()) {
793 if (std.startsWith("vcodec=")) format = std.section("vcodec=", 1, 1);
794 else if (std.contains(" vcodec=")) format = std.section(" vcodec=", 1, 1);
795 if (!format.isEmpty()) {
796 format = format.section(' ', 0, 0).toLower();
797 if (!vcodecsList.contains(format)) {
798 kDebug() << "***** UNSUPPORTED VCODEC: " << format;
799 //sizeItem->setHidden(true);
800 sizeItem->setFlags(Qt::ItemIsSelectable);
801 sizeItem->setToolTip(i18n("Unsupported video codec: %1", format));
802 sizeItem->setIcon(brokenIcon);
807 } else sizeItem->setHidden(true);
809 focusFirstVisibleItem();
810 m_view.size_list->blockSignals(false);
814 KUrl RenderWidget::filenameWithExtension(KUrl url, QString extension)
817 if (!url.isEmpty()) {
819 int pos = path.lastIndexOf('.') + 1;
820 if (pos == 0) path.append('.' + extension);
821 else path = path.left(pos) + extension;
824 path = m_projectFolder + "/untitled." + extension;
830 void RenderWidget::refreshParams()
832 QListWidgetItem *item = m_view.size_list->currentItem();
833 if (!item || item->isHidden()) {
834 m_view.advanced_params->clear();
835 m_view.buttonStart->setEnabled(false);
838 QString params = item->data(ParamsRole).toString();
839 QString extension = item->data(ExtensionRole).toString();
840 m_view.advanced_params->setPlainText(params);
841 QString destination = m_view.destination_list->itemData(m_view.destination_list->currentIndex()).toString();
842 if (params.contains(" s=") || destination == "audioonly") {
843 // profile has a fixed size, do not allow resize
844 m_view.rescale->setEnabled(false);
845 m_view.rescale_size->setEnabled(false);
847 m_view.rescale->setEnabled(true);
848 m_view.rescale_size->setEnabled(true);
850 KUrl url = filenameWithExtension(m_view.out_file->url(), extension);
851 m_view.out_file->setUrl(url);
852 // if (!url.isEmpty()) {
853 // QString path = url.path();
854 // int pos = path.lastIndexOf('.') + 1;
855 // if (pos == 0) path.append('.' + extension);
856 // else path = path.left(pos) + extension;
857 // m_view.out_file->setUrl(KUrl(path));
859 // m_view.out_file->setUrl(KUrl(QDir::homePath() + "/untitled." + extension));
861 m_view.out_file->setFilter("*." + extension);
862 QString edit = item->data(EditableRole).toString();
863 if (edit.isEmpty() || !edit.endsWith("customprofiles.xml")) {
864 m_view.buttonDelete->setEnabled(false);
865 m_view.buttonEdit->setEnabled(false);
867 m_view.buttonDelete->setEnabled(true);
868 m_view.buttonEdit->setEnabled(true);
871 m_view.buttonStart->setEnabled(m_view.size_list->currentItem()->flags() & Qt::ItemIsEnabled);
874 void RenderWidget::reloadProfiles()
879 void RenderWidget::parseProfiles(QString meta, QString group, QString profile)
881 m_view.size_list->clear();
882 m_view.format_list->clear();
883 m_view.destination_list->clear();
884 m_view.destination_list->addItem(KIcon("video-x-generic"), i18n("File rendering"));
885 m_view.destination_list->addItem(KIcon("media-optical"), i18n("DVD"), "dvd");
886 m_view.destination_list->addItem(KIcon("audio-x-generic"), i18n("Audio only"), "audioonly");
887 m_view.destination_list->addItem(KIcon("applications-internet"), i18n("Web sites"), "websites");
888 m_view.destination_list->addItem(KIcon("applications-multimedia"), i18n("Media players"), "mediaplayers");
889 m_view.destination_list->addItem(KIcon("drive-harddisk"), i18n("Lossless / HQ"), "lossless");
890 m_view.destination_list->addItem(KIcon("pda"), i18n("Mobile devices"), "mobile");
892 QString exportFile = KStandardDirs::locate("appdata", "export/profiles.xml");
893 parseFile(exportFile, false);
896 QString exportFolder = KStandardDirs::locateLocal("appdata", "export/");
897 QDir directory = QDir(exportFolder);
900 QStringList fileList = directory.entryList(filter, QDir::Files);
901 // We should parse customprofiles.xml in last position, so that user profiles
902 // can also override profiles installed by KNewStuff
903 fileList.removeAll("customprofiles.xml");
904 foreach(const QString &filename, fileList)
905 parseFile(exportFolder + '/' + filename, true);
906 if (QFile::exists(exportFolder + "/customprofiles.xml")) parseFile(exportFolder + "/customprofiles.xml", true);
908 if (!meta.isEmpty()) {
909 m_view.destination_list->blockSignals(true);
910 m_view.destination_list->setCurrentIndex(m_view.destination_list->findData(meta));
911 m_view.destination_list->blockSignals(false);
914 QList<QListWidgetItem *> child;
915 if (!group.isEmpty()) child = m_view.format_list->findItems(group, Qt::MatchExactly);
916 if (!child.isEmpty()) {
917 for (int i = 0; i < child.count(); i++) {
918 if (child.at(i)->data(MetaGroupRole).toString() == meta) {
919 m_view.format_list->setCurrentItem(child.at(i));
925 if (!profile.isEmpty()) child = m_view.size_list->findItems(profile, Qt::MatchExactly);
926 if (!child.isEmpty()) m_view.size_list->setCurrentItem(child.at(0));
929 void RenderWidget::parseFile(QString exportFile, bool editable)
931 kDebug() << "// Parsing file: " << exportFile;
932 kDebug() << "------------------------------";
934 QFile file(exportFile);
935 doc.setContent(&file, false);
937 QDomElement documentElement;
938 QDomElement profileElement;
940 QListWidgetItem *item;
941 QDomNodeList groups = doc.elementsByTagName("group");
943 if (editable || groups.count() == 0) {
944 QDomElement profiles = doc.documentElement();
945 if (editable && profiles.attribute("version", 0).toInt() < 1) {
946 kDebug() << "// OLD profile version";
947 // this is an old profile version, update it
949 QDomElement newprofiles = newdoc.createElement("profiles");
950 newprofiles.setAttribute("version", 1);
951 newdoc.appendChild(newprofiles);
952 QDomNodeList profilelist = doc.elementsByTagName("profile");
953 for (int i = 0; i < profilelist.count(); i++) {
954 QString category = i18n("Custom");
956 QDomNode parent = profilelist.at(i).parentNode();
957 if (!parent.isNull()) {
958 QDomElement parentNode = parent.toElement();
959 if (parentNode.hasAttribute("name")) category = parentNode.attribute("name");
960 extension = parentNode.attribute("extension");
962 profilelist.at(i).toElement().setAttribute("category", category);
963 if (!extension.isEmpty()) profilelist.at(i).toElement().setAttribute("extension", extension);
964 QDomNode n = profilelist.at(i).cloneNode();
965 newprofiles.appendChild(newdoc.importNode(n, true));
967 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
968 KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
971 QTextStream out(&file);
972 out << newdoc.toString();
974 parseFile(exportFile, editable);
978 QDomNode node = doc.elementsByTagName("profile").at(0);
980 kDebug() << "// Export file: " << exportFile << " IS BROKEN";
984 while (!node.isNull()) {
985 QDomElement profile = node.toElement();
986 QString profileName = profile.attribute("name");
987 QString standard = profile.attribute("standard");
988 QString params = profile.attribute("args");
989 QString category = profile.attribute("category", i18n("Custom"));
990 QString dest = profile.attribute("destinationid");
991 QString prof_extension = profile.attribute("extension");
992 if (!prof_extension.isEmpty()) extension = prof_extension;
994 QList <QListWidgetItem *> list = m_view.format_list->findItems(category, Qt::MatchExactly);
996 for (int j = 0; j < list.count(); j++) {
997 if (list.at(j)->data(MetaGroupRole) == dest) {
1003 item = new QListWidgetItem(category, m_view.format_list);
1004 item->setData(MetaGroupRole, dest);
1007 // Check if item with same name already exists and replace it,
1008 // allowing to override default profiles
1010 list = m_view.size_list->findItems(profileName, Qt::MatchExactly);
1012 for (int j = 0; j < list.count(); j++) {
1013 if (list.at(j)->data(MetaGroupRole) == dest) {
1014 QListWidgetItem *duplicate = list.takeAt(j);
1020 item = new QListWidgetItem(profileName, m_view.size_list);
1021 //kDebug() << "// ADDINg item with name: " << profileName << ", GRP" << category << ", DEST:" << dest ;
1022 item->setData(GroupRole, category);
1023 item->setData(MetaGroupRole, dest);
1024 item->setData(ExtensionRole, extension);
1025 item->setData(RenderRole, "avformat");
1026 item->setData(StandardRole, standard);
1027 item->setData(ParamsRole, params);
1028 if (profile.hasAttribute("url")) item->setData(ExtraRole, profile.attribute("url"));
1030 item->setData(EditableRole, exportFile);
1031 if (exportFile.endsWith("customprofiles.xml")) item->setIcon(KIcon("emblem-favorite"));
1032 else item->setIcon(KIcon("applications-internet"));
1034 node = doc.elementsByTagName("profile").at(count);
1042 QString profileName;
1044 QString prof_extension;
1050 while (!groups.item(i).isNull()) {
1051 documentElement = groups.item(i).toElement();
1052 QDomNode gname = documentElement.elementsByTagName("groupname").at(0);
1053 QString metagroupName;
1054 QString metagroupId;
1055 if (!gname.isNull()) {
1056 metagroupName = gname.firstChild().nodeValue();
1057 metagroupId = gname.toElement().attribute("id");
1058 if (!metagroupName.isEmpty() && !m_view.destination_list->contains(metagroupName)) {
1059 if (metagroupId == "dvd") icon = KIcon("media-optical");
1060 else if (metagroupId == "audioonly") icon = KIcon("audio-x-generic");
1061 else if (metagroupId == "websites") icon = KIcon("applications-internet");
1062 else if (metagroupId == "mediaplayers") icon = KIcon("applications-multimedia");
1063 else if (metagroupId == "lossless") icon = KIcon("drive-harddisk");
1064 else if (metagroupId == "mobile") icon = KIcon("pda");
1065 m_view.destination_list->addItem(icon, i18n(metagroupName.toUtf8().data()), metagroupId);
1068 groupName = documentElement.attribute("name", i18n("Custom"));
1069 extension = documentElement.attribute("extension", QString());
1070 renderer = documentElement.attribute("renderer", QString());
1071 QList <QListWidgetItem *> list = m_view.format_list->findItems(groupName, Qt::MatchExactly);
1072 bool exists = false;
1073 for (int j = 0; j < list.count(); j++) {
1074 if (list.at(j)->data(MetaGroupRole) == metagroupId) {
1080 item = new QListWidgetItem(groupName, m_view.format_list);
1081 item->setData(MetaGroupRole, metagroupId);
1084 QDomNode n = groups.item(i).firstChild();
1085 while (!n.isNull()) {
1086 if (n.toElement().tagName() != "profile") {
1087 n = n.nextSibling();
1090 profileElement = n.toElement();
1091 profileName = profileElement.attribute("name");
1092 standard = profileElement.attribute("standard");
1093 params = profileElement.attribute("args");
1094 prof_extension = profileElement.attribute("extension");
1095 if (!prof_extension.isEmpty()) extension = prof_extension;
1096 item = new QListWidgetItem(profileName, m_view.size_list);
1097 item->setData(GroupRole, groupName);
1098 item->setData(MetaGroupRole, metagroupId);
1099 item->setData(ExtensionRole, extension);
1100 item->setData(RenderRole, renderer);
1101 item->setData(StandardRole, standard);
1102 item->setData(ParamsRole, params);
1103 if (profileElement.hasAttribute("url")) item->setData(ExtraRole, profileElement.attribute("url"));
1104 if (editable) item->setData(EditableRole, exportFile);
1105 n = n.nextSibling();
1112 void RenderWidget::setRenderJob(const QString &dest, int progress)
1114 QTreeWidgetItem *item;
1115 QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(dest, Qt::MatchExactly, 1);
1116 if (!existing.isEmpty()) item = existing.at(0);
1117 else item = new QTreeWidgetItem(m_view.running_jobs, QStringList() << QString() << dest << QString());
1118 item->setData(2, Qt::UserRole, progress);
1119 if (progress == 0) {
1120 item->setIcon(0, KIcon("system-run"));
1121 item->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
1122 item->setData(1, Qt::UserRole + 1, QTime::currentTime());
1125 QTime startTime = item->data(1, Qt::UserRole + 1).toTime();
1126 int seconds = startTime.secsTo(QTime::currentTime());;
1127 const QString t = i18n("Estimated time %1", QTime().addSecs(seconds * (100 - progress) / progress).toString("hh:mm:ss"));
1128 item->setData(1, Qt::UserRole, t);
1132 void RenderWidget::setRenderStatus(const QString &dest, int status, const QString &error)
1134 QTreeWidgetItem *item;
1135 QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(dest, Qt::MatchExactly, 1);
1136 if (!existing.isEmpty()) item = existing.at(0);
1137 else item = new QTreeWidgetItem(m_view.running_jobs, QStringList() << QString() << dest << QString());
1139 // Job finished successfully
1140 item->setIcon(0, KIcon("dialog-ok"));
1141 item->setData(2, Qt::UserRole, 100);
1142 QTime startTime = item->data(1, Qt::UserRole + 1).toTime();
1143 int seconds = startTime.secsTo(QTime::currentTime());
1144 const QTime tm = QTime().addSecs(seconds);
1145 const QString t = i18n("Rendering finished in %1", tm.toString("hh:mm:ss"));
1146 item->setData(1, Qt::UserRole, t);
1147 QString itemGroup = item->data(0, Qt::UserRole).toString();
1148 if (itemGroup == "dvd") {
1149 emit openDvdWizard(item->text(1), item->data(0, Qt::UserRole + 1).toString());
1150 } else if (itemGroup == "websites") {
1151 QString url = item->data(0, Qt::UserRole + 1).toString();
1152 if (!url.isEmpty()) new KRun(url, this);
1154 } else if (status == -2) {
1155 // Rendering crashed
1156 item->setData(1, Qt::UserRole, i18n("Rendering crashed"));
1157 item->setIcon(0, KIcon("dialog-close"));
1158 item->setData(2, Qt::UserRole, 100);
1159 m_view.error_log->append(i18n("<strong>Rendering of %1 crashed</strong><br />", dest));
1160 m_view.error_log->append(error);
1161 m_view.error_log->append("<hr />");
1162 m_view.error_box->setVisible(true);
1163 } else if (status == -3) {
1165 item->setData(1, Qt::UserRole, i18n("Rendering aborted"));
1166 item->setIcon(0, KIcon("dialog-cancel"));
1167 item->setData(2, Qt::UserRole, 100);
1172 void RenderWidget::slotAbortCurrentJob()
1174 QTreeWidgetItem *current = m_view.running_jobs->currentItem();
1175 if (current) emit abortProcess(current->text(1));
1178 void RenderWidget::slotCheckJob()
1180 bool activate = false;
1181 QTreeWidgetItem *current = m_view.running_jobs->currentItem();
1183 int percent = current->data(2, Qt::UserRole).toInt();
1184 if (percent < 100) activate = true;
1186 m_view.abort_job->setEnabled(activate);
1189 void RenderWidget::parseScriptFiles()
1191 QStringList scriptsFilter;
1192 scriptsFilter << "*.sh";
1193 m_view.scripts_list->clear();
1195 QTreeWidgetItem *item;
1196 // List the project scripts
1197 QStringList scriptFiles = QDir(m_projectFolder + "/scripts").entryList(scriptsFilter, QDir::Files);
1198 for (int i = 0; i < scriptFiles.size(); ++i) {
1199 KUrl scriptpath(m_projectFolder + "/scripts/" + scriptFiles.at(i));
1200 item = new QTreeWidgetItem(m_view.scripts_list, QStringList() << scriptpath.fileName());
1202 QFile file(scriptpath.path());
1203 if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
1204 while (!file.atEnd()) {
1205 QByteArray line = file.readLine();
1206 if (line.startsWith("TARGET=")) {
1207 target = QString(line).section("TARGET=", 1);
1208 target.remove(QChar('"'));
1214 item->setSizeHint(0, QSize(m_view.scripts_list->columnWidth(0), fontMetrics().height() * 2));
1215 item->setData(0, Qt::UserRole, target);
1216 item->setData(0, Qt::UserRole + 1, scriptpath.path());
1218 bool activate = false;
1219 QTreeWidgetItemIterator it(m_view.scripts_list);
1221 kDebug() << "// FOUND SCRIPT ITEM:" << (*it)->text(0);
1222 // Selecting item does not work, why???
1223 m_view.scripts_list->setCurrentItem(*it);
1224 (*it)->setSelected(true);
1227 kDebug() << "SELECTED SCRIPTS: " << m_view.scripts_list->selectedItems().count();
1228 m_view.start_script->setEnabled(activate);
1229 m_view.delete_script->setEnabled(activate);
1232 void RenderWidget::slotCheckScript()
1234 bool activate = false;
1235 QTreeWidgetItemIterator it(m_view.scripts_list);
1236 if (*it) activate = true;
1237 m_view.start_script->setEnabled(activate);
1238 m_view.delete_script->setEnabled(activate);
1241 void RenderWidget::slotStartScript()
1243 QTreeWidgetItem *item = m_view.scripts_list->currentItem();
1245 QString path = item->data(0, Qt::UserRole + 1).toString();
1246 QProcess::startDetached(path);
1247 m_view.tabWidget->setCurrentIndex(1);
1251 void RenderWidget::slotDeleteScript()
1253 QTreeWidgetItem *item = m_view.scripts_list->currentItem();
1255 QString path = item->data(0, Qt::UserRole + 1).toString();
1256 KIO::NetAccess::del(path + ".westley", this);
1257 KIO::NetAccess::del(path, this);
1262 void RenderWidget::slotGenerateScript()