+ QString exportFile = KStandardDirs::locate("appdata", "export/profiles.xml");
+ parseFile(exportFile, false);
+
+
+ QString exportFolder = KStandardDirs::locateLocal("appdata", "export/");
+ QDir directory = QDir(exportFolder);
+ QStringList filter;
+ filter << "*.xml";
+ QStringList fileList = directory.entryList(filter, QDir::Files);
+ // We should parse customprofiles.xml in last position, so that user profiles
+ // can also override profiles installed by KNewStuff
+ fileList.removeAll("customprofiles.xml");
+ foreach(const QString &filename, fileList)
+ parseFile(exportFolder + filename, true);
+ if (QFile::exists(exportFolder + "customprofiles.xml")) parseFile(exportFolder + "customprofiles.xml", true);
+
+ if (!meta.isEmpty()) {
+ m_view.destination_list->blockSignals(true);
+ m_view.destination_list->setCurrentIndex(m_view.destination_list->findData(meta));
+ m_view.destination_list->blockSignals(false);
+ }
+ refreshCategory();
+ QList<QListWidgetItem *> child;
+ if (!group.isEmpty()) child = m_view.format_list->findItems(group, Qt::MatchExactly);
+ if (!child.isEmpty()) {
+ for (int i = 0; i < child.count(); i++) {
+ if (child.at(i)->data(MetaGroupRole).toString() == meta) {
+ m_view.format_list->setCurrentItem(child.at(i));
+ break;
+ }
+ }
+ }
+ child.clear();
+ m_view.size_list->blockSignals(false);
+ m_view.format_list->blockSignals(false);
+ if (!profile.isEmpty()) child = m_view.size_list->findItems(profile, Qt::MatchExactly);
+ if (!child.isEmpty()) m_view.size_list->setCurrentItem(child.at(0));
+}
+
+void RenderWidget::parseFile(QString exportFile, bool editable)
+{
+ kDebug() << "// Parsing file: " << exportFile;
+ kDebug() << "------------------------------";
+ QDomDocument doc;
+ QFile file(exportFile);
+ doc.setContent(&file, false);
+ file.close();
+ QDomElement documentElement;
+ QDomElement profileElement;
+ QString extension;
+ QDomNodeList groups = doc.elementsByTagName("group");
+ QListWidgetItem *item = NULL;
+ const QStringList acodecsList = KdenliveSettings::audiocodecs();
+ bool replaceVorbisCodec = false;
+ if (acodecsList.contains("libvorbis")) replaceVorbisCodec = true;
+ bool replaceLibfaacCodec = false;
+ if (!acodecsList.contains("aac") && acodecsList.contains("libfaac")) replaceLibfaacCodec = true;
+
+
+ if (editable || groups.count() == 0) {
+ QDomElement profiles = doc.documentElement();
+ if (editable && profiles.attribute("version", 0).toInt() < 1) {
+ kDebug() << "// OLD profile version";
+ // this is an old profile version, update it
+ QDomDocument newdoc;
+ QDomElement newprofiles = newdoc.createElement("profiles");
+ newprofiles.setAttribute("version", 1);
+ newdoc.appendChild(newprofiles);
+ QDomNodeList profilelist = doc.elementsByTagName("profile");
+ for (int i = 0; i < profilelist.count(); i++) {
+ QString category = i18nc("Category Name", "Custom");
+ QString extension;
+ QDomNode parent = profilelist.at(i).parentNode();
+ if (!parent.isNull()) {
+ QDomElement parentNode = parent.toElement();
+ if (parentNode.hasAttribute("name")) category = parentNode.attribute("name");
+ extension = parentNode.attribute("extension");
+ }
+ profilelist.at(i).toElement().setAttribute("category", category);
+ if (!extension.isEmpty()) profilelist.at(i).toElement().setAttribute("extension", extension);
+ QDomNode n = profilelist.at(i).cloneNode();
+ newprofiles.appendChild(newdoc.importNode(n, true));
+ }
+ if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
+ KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
+ return;
+ }
+ QTextStream out(&file);
+ out << newdoc.toString();
+ file.close();
+ parseFile(exportFile, editable);
+ return;
+ }
+
+ QDomNode node = doc.elementsByTagName("profile").at(0);
+ if (node.isNull()) {
+ kDebug() << "// Export file: " << exportFile << " IS BROKEN";
+ return;
+ }
+ int count = 1;
+ while (!node.isNull()) {
+ QDomElement profile = node.toElement();
+ QString profileName = profile.attribute("name");
+ QString standard = profile.attribute("standard");
+ QString params = profile.attribute("args");
+
+ if (replaceVorbisCodec && params.contains("acodec=vorbis")) {
+ // replace vorbis with libvorbis
+ params = params.replace("vorbis", "libvorbis");
+ }
+ if (replaceLibfaacCodec && params.contains("acodec=aac")) {
+ // replace libfaac with aac
+ params = params.replace("aac", "libfaac");
+ }
+
+ QString category = profile.attribute("category", i18nc("Category Name", "Custom"));
+ QString dest = profile.attribute("destinationid");
+ QString prof_extension = profile.attribute("extension");
+ if (!prof_extension.isEmpty()) extension = prof_extension;
+ bool exists = false;
+ for (int j = 0; j < m_renderCategory.count(); j++) {
+ if (m_renderCategory.at(j)->text() == category && m_renderCategory.at(j)->data(MetaGroupRole) == dest) {
+ exists = true;
+ break;
+ }
+ }
+
+ if (!exists) {
+ QListWidgetItem *itemcat = new QListWidgetItem(category);
+ itemcat->setData(MetaGroupRole, dest);
+ m_renderCategory.append(itemcat);
+ }
+
+ // Check if item with same name already exists and replace it,
+ // allowing to override default profiles
+
+
+ for (int j = 0; j < m_renderItems.count(); j++) {
+ if (m_renderItems.at(j)->text() == profileName && m_renderItems.at(j)->data(MetaGroupRole) == dest) {
+ QListWidgetItem *duplicate = m_renderItems.takeAt(j);
+ delete duplicate;
+ j--;
+ }
+ }
+
+ item = new QListWidgetItem(profileName); // , m_view.size_list
+ //kDebug() << "// ADDINg item with name: " << profileName << ", GRP" << category << ", DEST:" << dest ;
+ item->setData(GroupRole, category);
+ item->setData(MetaGroupRole, dest);
+ item->setData(ExtensionRole, extension);
+ item->setData(RenderRole, "avformat");
+ item->setData(StandardRole, standard);
+ item->setData(ParamsRole, params);
+ if (profile.hasAttribute("url")) item->setData(ExtraRole, profile.attribute("url"));
+ if (editable) {
+ item->setData(EditableRole, exportFile);
+ if (exportFile.endsWith("customprofiles.xml")) item->setIcon(KIcon("emblem-favorite"));
+ else item->setIcon(KIcon("applications-internet"));
+ }
+ m_renderItems.append(item);
+ node = doc.elementsByTagName("profile").at(count);
+ count++;
+ }
+ return;
+ }
+
+ int i = 0;
+ QString groupName;
+ QString profileName;
+
+ QString prof_extension;
+ QString renderer;
+ QString params;
+ QString standard;
+ KIcon icon;
+
+ while (!groups.item(i).isNull()) {
+ documentElement = groups.item(i).toElement();
+ QDomNode gname = documentElement.elementsByTagName("groupname").at(0);
+ QString metagroupName;
+ QString metagroupId;
+ if (!gname.isNull()) {
+ metagroupName = gname.firstChild().nodeValue();
+ metagroupId = gname.toElement().attribute("id");
+
+ if (!metagroupName.isEmpty() && m_view.destination_list->findData(metagroupId) == -1) {
+ if (metagroupId == "dvd") icon = KIcon("media-optical");
+ else if (metagroupId == "audioonly") icon = KIcon("audio-x-generic");
+ else if (metagroupId == "websites") icon = KIcon("applications-internet");
+ else if (metagroupId == "mediaplayers") icon = KIcon("applications-multimedia");
+ else if (metagroupId == "lossless") icon = KIcon("drive-harddisk");
+ else if (metagroupId == "mobile") icon = KIcon("pda");
+ m_view.destination_list->addItem(icon, i18n(metagroupName.toUtf8().data()), metagroupId);
+ }
+ }
+ groupName = documentElement.attribute("name", i18nc("Attribute Name", "Custom"));
+ extension = documentElement.attribute("extension", QString());
+ renderer = documentElement.attribute("renderer", QString());
+ bool exists = false;
+ for (int j = 0; j < m_renderCategory.count(); j++) {
+ if (m_renderCategory.at(j)->text() == groupName && m_renderCategory.at(j)->data(MetaGroupRole) == metagroupId) {
+ exists = true;
+ break;
+ }
+ }
+ if (!exists) {
+ QListWidgetItem *itemcat = new QListWidgetItem(groupName); //, m_view.format_list);
+ itemcat->setData(MetaGroupRole, metagroupId);
+ m_renderCategory.append(itemcat);
+ }
+
+ QDomNode n = groups.item(i).firstChild();
+ while (!n.isNull()) {
+ if (n.toElement().tagName() != "profile") {
+ n = n.nextSibling();
+ continue;
+ }
+ profileElement = n.toElement();
+ profileName = profileElement.attribute("name");
+ standard = profileElement.attribute("standard");
+ params = profileElement.attribute("args");
+
+ if (replaceVorbisCodec && params.contains("acodec=vorbis")) {
+ // replace vorbis with libvorbis
+ params = params.replace("vorbis", "libvorbis");
+ }
+ if (replaceLibfaacCodec && params.contains("acodec=aac")) {
+ // replace libfaac with aac
+ params = params.replace("aac", "libfaac");
+ }
+
+ prof_extension = profileElement.attribute("extension");
+ if (!prof_extension.isEmpty()) extension = prof_extension;
+ item = new QListWidgetItem(profileName); //, m_view.size_list);
+ item->setData(GroupRole, groupName);
+ item->setData(MetaGroupRole, metagroupId);
+ item->setData(ExtensionRole, extension);
+ item->setData(RenderRole, renderer);
+ item->setData(StandardRole, standard);
+ item->setData(ParamsRole, params);
+ if (profileElement.hasAttribute("url")) item->setData(ExtraRole, profileElement.attribute("url"));
+ if (editable) item->setData(EditableRole, exportFile);
+ m_renderItems.append(item);
+ n = n.nextSibling();
+ }
+
+ i++;
+ }
+}
+
+void RenderWidget::setRenderJob(const QString &dest, int progress)
+{
+ QTreeWidgetItem *item;
+ QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(dest, Qt::MatchExactly, 1);
+ if (!existing.isEmpty()) item = existing.at(0);
+ else {
+ item = new QTreeWidgetItem(m_view.running_jobs, QStringList() << QString() << dest << QString());
+ item->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
+ if (progress == 0) {
+ item->setData(1, Qt::UserRole + 2, WAITINGJOB);
+ item->setIcon(0, KIcon("media-playback-pause"));
+ item->setData(1, Qt::UserRole, i18n("Waiting..."));
+ }
+ }
+ item->setData(2, Qt::UserRole, progress);
+ item->setData(1, Qt::UserRole + 2, RUNNINGJOB);
+ if (progress == 0) {
+ item->setIcon(0, KIcon("system-run"));
+ item->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
+ item->setData(1, Qt::UserRole + 1, QTime::currentTime());
+ slotCheckJob();
+ } else {
+ QTime startTime = item->data(1, Qt::UserRole + 1).toTime();
+ int seconds = startTime.secsTo(QTime::currentTime());;
+ const QString t = i18n("Estimated time %1", QTime().addSecs(seconds * (100 - progress) / progress).toString("hh:mm:ss"));
+ item->setData(1, Qt::UserRole, t);
+ }
+}
+
+void RenderWidget::setRenderStatus(const QString &dest, int status, const QString &error)
+{
+ QTreeWidgetItem *item;
+ QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(dest, Qt::MatchExactly, 1);
+ if (!existing.isEmpty()) item = existing.at(0);
+ else {
+ item = new QTreeWidgetItem(m_view.running_jobs, QStringList() << QString() << dest << QString());
+ item->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
+ }
+ item->setData(1, Qt::UserRole + 2, FINISHEDJOB);
+ if (status == -1) {
+ // Job finished successfully
+ item->setIcon(0, KIcon("dialog-ok"));
+ item->setData(2, Qt::UserRole, 100);
+ QTime startTime = item->data(1, Qt::UserRole + 1).toTime();
+ int seconds = startTime.secsTo(QTime::currentTime());
+ const QTime tm = QTime().addSecs(seconds);
+ const QString t = i18n("Rendering finished in %1", tm.toString("hh:mm:ss"));
+ item->setData(1, Qt::UserRole, t);
+ QString itemGroup = item->data(0, Qt::UserRole).toString();
+ if (itemGroup == "dvd") {
+ emit openDvdWizard(item->text(1), item->data(0, Qt::UserRole + 1).toString());
+ } else if (itemGroup == "websites") {
+ QString url = item->data(0, Qt::UserRole + 1).toString();
+ if (!url.isEmpty()) new KRun(url, this);
+ }
+ } else if (status == -2) {
+ // Rendering crashed
+ item->setData(1, Qt::UserRole, i18n("Rendering crashed"));
+ item->setIcon(0, KIcon("dialog-close"));
+ item->setData(2, Qt::UserRole, 100);
+ m_view.error_log->append(i18n("<strong>Rendering of %1 crashed</strong><br />", dest));
+ m_view.error_log->append(error);
+ m_view.error_log->append("<hr />");
+ m_view.error_box->setVisible(true);
+ } else if (status == -3) {
+ // User aborted job
+ item->setData(1, Qt::UserRole, i18n("Rendering aborted"));
+ item->setIcon(0, KIcon("dialog-cancel"));
+ item->setData(2, Qt::UserRole, 100);
+ }
+ slotCheckJob();
+ checkRenderStatus();
+}
+
+void RenderWidget::slotAbortCurrentJob()
+{
+ QTreeWidgetItem *current = m_view.running_jobs->currentItem();
+ if (current) {
+ if (current->data(1, Qt::UserRole + 2).toInt() == RUNNINGJOB)
+ emit abortProcess(current->text(1));
+ else {
+ delete current;
+ slotCheckJob();
+ checkRenderStatus();
+ }
+ }
+}
+
+void RenderWidget::slotStartCurrentJob()
+{
+ QTreeWidgetItem *current = m_view.running_jobs->currentItem();
+ if (current && current->data(1, Qt::UserRole + 2).toInt() == WAITINGJOB)
+ startRendering(current);
+ m_view.start_job->setEnabled(false);
+}
+
+void RenderWidget::slotCheckJob()
+{
+ bool activate = false;
+ QTreeWidgetItem *current = m_view.running_jobs->currentItem();
+ if (current) {
+ if (current->data(1, Qt::UserRole + 2).toInt() == RUNNINGJOB) {
+ m_view.abort_job->setText(i18n("Abort Job"));
+ m_view.start_job->setEnabled(false);
+ } else {
+ m_view.abort_job->setText(i18n("Remove Job"));
+ m_view.start_job->setEnabled(current->data(1, Qt::UserRole + 2).toInt() == WAITINGJOB);
+ }
+ activate = true;
+ }
+ m_view.abort_job->setEnabled(activate);
+ for (int i = 0; i < m_view.running_jobs->topLevelItemCount(); i++) {
+ current = m_view.running_jobs->topLevelItem(i);
+ if (current == m_view.running_jobs->currentItem()) {
+ current->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 3));
+ } else current->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
+ }
+}
+
+void RenderWidget::slotCLeanUpJobs()
+{
+ int ix = 0;
+ QTreeWidgetItem *current = m_view.running_jobs->topLevelItem(ix);
+ while (current) {
+ if (current->data(1, Qt::UserRole + 2).toInt() == FINISHEDJOB)
+ delete current;
+ else ix++;
+ current = m_view.running_jobs->topLevelItem(ix);
+ }
+ slotCheckJob();
+}
+
+void RenderWidget::parseScriptFiles()
+{
+ QStringList scriptsFilter;
+ scriptsFilter << "*.sh";
+ m_view.scripts_list->clear();
+
+ QTreeWidgetItem *item;
+ // List the project scripts
+ QStringList scriptFiles = QDir(m_projectFolder + "scripts").entryList(scriptsFilter, QDir::Files);
+ for (int i = 0; i < scriptFiles.size(); ++i) {
+ KUrl scriptpath(m_projectFolder + "scripts/" + scriptFiles.at(i));
+ QString target;
+ QString renderer;
+ QString melt;
+ QFile file(scriptpath.path());
+ if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ QTextStream stream(&file);
+ while (!stream.atEnd()) {
+ QString line = stream.readLine();
+ if (line.startsWith("TARGET=")) {
+ target = line.section("TARGET=", 1).simplified();
+ target.remove(QChar('"'));
+ } else if (line.startsWith("RENDERER=")) {
+ renderer = line.section("RENDERER=", 1).simplified();
+ renderer.remove(QChar('"'));
+ } else if (line.startsWith("MELT=")) {
+ melt = line.section("MELT=", 1).simplified();
+ melt.remove(QChar('"'));
+ }
+ }
+ file.close();
+ }
+ if (target.isEmpty()) continue;
+ item = new QTreeWidgetItem(m_view.scripts_list, QStringList() << QString() << scriptpath.fileName());
+ if (!renderer.isEmpty() && renderer.contains('/') && !QFile::exists(renderer)) {
+ item->setIcon(0, KIcon("dialog-cancel"));
+ item->setToolTip(1, i18n("Script contains wrong command: %1", renderer));
+ item->setData(0, Qt::UserRole, '1');
+ } else if (!melt.isEmpty() && melt.contains('/') && !QFile::exists(melt)) {
+ item->setIcon(0, KIcon("dialog-cancel"));
+ item->setToolTip(1, i18n("Script contains wrong command: %1", melt));
+ item->setData(0, Qt::UserRole, '1');
+ } else item->setIcon(0, KIcon("application-x-executable-script"));
+ item->setSizeHint(0, QSize(m_view.scripts_list->columnWidth(0), fontMetrics().height() * 2));
+ item->setData(1, Qt::UserRole, target.simplified());
+ item->setData(1, Qt::UserRole + 1, scriptpath.path());
+ }
+ bool activate = false;
+ QTreeWidgetItem *script = m_view.scripts_list->topLevelItem(0);
+ if (script) {
+ m_view.scripts_list->setCurrentItem(script);
+ script->setSelected(true);
+ activate = true;
+ }
+// m_view.start_script->setEnabled(activate);
+// m_view.delete_script->setEnabled(activate);
+}
+
+void RenderWidget::slotCheckScript()
+{
+ QTreeWidgetItem *current = m_view.scripts_list->currentItem();
+ if (current == NULL) return;
+ m_view.start_script->setEnabled(current->data(0, Qt::UserRole).toString().isEmpty());
+ m_view.delete_script->setEnabled(true);
+ for (int i = 0; i < m_view.scripts_list->topLevelItemCount(); i++) {
+ current = m_view.scripts_list->topLevelItem(i);
+ if (current == m_view.scripts_list->currentItem()) {
+ current->setSizeHint(1, QSize(m_view.scripts_list->columnWidth(1), fontMetrics().height() * 3));
+ } else current->setSizeHint(1, QSize(m_view.scripts_list->columnWidth(1), fontMetrics().height() * 2));
+ }
+}
+
+void RenderWidget::slotStartScript()
+{
+ QTreeWidgetItem *item = m_view.scripts_list->currentItem();
+ if (item) {
+ QString destination = item->data(1, Qt::UserRole).toString();
+ QString path = item->data(1, Qt::UserRole + 1).toString();
+ // Insert new job in queue
+ QTreeWidgetItem *renderItem;
+ QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(destination, Qt::MatchExactly, 1);
+ kDebug() << "------ START SCRIPT";
+ if (!existing.isEmpty()) {
+ renderItem = existing.at(0);
+ if (renderItem->data(1, Qt::UserRole + 2).toInt() == RUNNINGJOB) {
+ KMessageBox::information(this, i18n("There is already a job writing file:<br /><b>%1</b><br />Abort the job if you want to overwrite it...", destination), i18n("Already running"));
+ return;
+ }
+ } else renderItem = new QTreeWidgetItem(m_view.running_jobs, QStringList() << QString() << destination << QString());
+ kDebug() << "------ START SCRIPT 2";
+ renderItem->setData(2, Qt::UserRole, 0);
+ renderItem->setData(1, Qt::UserRole + 2, WAITINGJOB);
+ renderItem->setIcon(0, KIcon("media-playback-pause"));
+ renderItem->setData(1, Qt::UserRole, i18n("Waiting..."));
+ renderItem->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
+ renderItem->setData(1, Qt::UserRole + 1, QTime::currentTime());
+ renderItem->setData(1, Qt::UserRole + 3, path);
+ renderItem->setData(1, Qt::UserRole + 4, '1');
+ checkRenderStatus();
+ m_view.tabWidget->setCurrentIndex(1);
+ }
+}
+
+void RenderWidget::slotDeleteScript()
+{
+ QTreeWidgetItem *item = m_view.scripts_list->currentItem();
+ if (item) {
+ QString path = item->data(1, Qt::UserRole + 1).toString();
+ KIO::NetAccess::del(path + ".mlt", this);
+ KIO::NetAccess::del(path, this);
+ parseScriptFiles();
+ }
+}
+
+void RenderWidget::slotGenerateScript()
+{
+ slotPrepareExport(true);
+}
+
+void RenderWidget::slotHideLog()
+{
+ m_view.error_box->setVisible(false);
+}
+
+void RenderWidget::setRenderProfile(QMap <QString, QString> props)
+{
+ m_view.destination_list->blockSignals(true);
+ m_view.format_list->blockSignals(true);
+ m_view.scanning_list->setCurrentIndex(props.value("renderscanning").toInt());
+ int exportAudio = props.value("renderexportaudio").toInt();
+ switch (exportAudio) {
+ case 1:
+ m_view.export_audio->setCheckState(Qt::Unchecked);
+ break;
+ case 2:
+ m_view.export_audio->setCheckState(Qt::Checked);
+ break;
+ default:
+ m_view.export_audio->setCheckState(Qt::PartiallyChecked);
+ }
+ if (props.contains("renderrescale")) m_view.rescale->setChecked(props.value("renderrescale").toInt());
+ if (props.contains("renderrescalewidth")) m_view.rescale_width->setValue(props.value("renderrescalewidth").toInt());
+ if (props.contains("renderrescaleheight")) m_view.rescale_height->setValue(props.value("renderrescaleheight").toInt());
+ if (props.contains("rendertcoverlay")) m_view.tc_overlay->setChecked(props.value("rendertcoverlay").toInt());
+ if (props.contains("rendertctype")) m_view.tc_type->setCurrentIndex(props.value("rendertctype").toInt());
+ if (props.contains("renderratio")) m_view.rescale_keep->setChecked(props.value("renderratio").toInt());
+ if (props.contains("renderplay")) m_view.play_after->setChecked(props.value("renderplay").toInt());
+
+ if (props.value("renderzone") == "1") m_view.render_zone->setChecked(true);
+ else if (props.value("renderguide") == "1") {
+ m_view.render_guide->setChecked(true);
+ m_view.guide_start->setCurrentIndex(props.value("renderstartguide").toInt());
+ m_view.guide_end->setCurrentIndex(props.value("renderendguide").toInt());
+ } else m_view.render_full->setChecked(true);
+ slotUpdateGuideBox();
+
+ QString url = props.value("renderurl");
+ if (!url.isEmpty()) m_view.out_file->setUrl(KUrl(url));
+
+ // set destination
+ for (int i = 0; i < m_view.destination_list->count(); i++) {
+ if (m_view.destination_list->itemData(i, Qt::UserRole) == props.value("renderdestination")) {
+ m_view.destination_list->setCurrentIndex(i);
+ break;
+ }
+ }
+ refreshCategory();
+
+ // set category
+ QString group = props.value("rendercategory");
+ if (!group.isEmpty()) {
+ QList<QListWidgetItem *> childs = m_view.format_list->findItems(group, Qt::MatchExactly);
+ if (!childs.isEmpty()) {
+ m_view.format_list->setCurrentItem(childs.at(0));
+ m_view.format_list->scrollToItem(childs.at(0));
+ }
+ refreshView();
+ }
+
+ // set profile
+ QList<QListWidgetItem *> childs = m_view.size_list->findItems(props.value("renderprofile"), Qt::MatchExactly);
+ if (!childs.isEmpty()) {
+ m_view.size_list->setCurrentItem(childs.at(0));
+ m_view.size_list->scrollToItem(childs.at(0));
+ }
+ //refreshView();
+ m_view.destination_list->blockSignals(false);
+ m_view.format_list->blockSignals(false);
+
+}
+
+bool RenderWidget::startWaitingRenderJobs()
+{
+ m_blockProcessing = true;
+ QString autoscriptFile = getFreeScriptName("auto");
+ QFile file(autoscriptFile);
+ if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
+ kWarning() << "////// ERROR writing to file: " << autoscriptFile;
+ KMessageBox::error(0, i18n("Cannot write to file %1", autoscriptFile));
+ return false;
+ }
+
+ QTextStream outStream(&file);
+ outStream << "#! /bin/sh" << "\n" << "\n";
+ QTreeWidgetItem *item = m_view.running_jobs->topLevelItem(0);
+ while (item) {
+ if (item->data(1, Qt::UserRole + 2).toInt() == WAITINGJOB) {
+ if (item->data(1, Qt::UserRole + 4).isNull()) {
+ // Add render process for item
+ const QString params = item->data(1, Qt::UserRole + 3).toStringList().join(" ");
+ outStream << m_renderer << " " << params << "\n";
+ } else {
+ // Script item
+ outStream << item->data(1, Qt::UserRole + 3).toString() << "\n";
+ }
+ }
+ item = m_view.running_jobs->itemBelow(item);
+ }
+ // erase itself when rendering is finished
+ outStream << "rm " << autoscriptFile << "\n" << "\n";
+ if (file.error() != QFile::NoError) {
+ KMessageBox::error(0, i18n("Cannot write to file %1", autoscriptFile));
+ file.close();
+ m_blockProcessing = false;
+ return false;
+ }
+ file.close();
+ QFile::setPermissions(autoscriptFile, file.permissions() | QFile::ExeUser);
+ QProcess::startDetached(autoscriptFile, QStringList());
+ return true;
+}
+
+QString RenderWidget::getFreeScriptName(const QString &prefix)
+{
+ int ix = 0;
+ QString scriptsFolder = m_projectFolder + "scripts/";
+ KStandardDirs::makeDir(scriptsFolder);
+ QString path;
+ while (path.isEmpty() || QFile::exists(path)) {
+ ix++;
+ path = scriptsFolder + prefix + i18n("script") + QString::number(ix).rightJustified(3, '0', false) + ".sh";
+ }
+ return path;
+}
+
+void RenderWidget::slotPlayRendering(QTreeWidgetItem *item, int)
+{
+ if (KdenliveSettings::defaultplayerapp().isEmpty() || item->data(1, Qt::UserRole + 2).toInt() != FINISHEDJOB) return;
+ const QByteArray startId = KStartupInfo::createNewStartupId();
+ const QString command = KdenliveSettings::defaultplayerapp() + ' ' + item->text(1);
+ KRun::runCommand(command, KdenliveSettings::defaultplayerapp(), KdenliveSettings::defaultplayerapp(), this, startId);
+}
+
+void RenderWidget::missingClips(bool hasMissing)
+{
+ if (hasMissing) {
+ m_view.errorLabel->setText(i18n("Check missing clips"));
+ m_view.errorBox->setHidden(false);
+ } else m_view.errorBox->setHidden(true);
+}
+
+void RenderWidget::slotUpdateEncodeThreads(int val)
+{
+ KdenliveSettings::setEncodethreads(val);
+}
+
+void RenderWidget::slotUpdateRescaleWidth(int val)
+{
+ KdenliveSettings::setDefaultrescalewidth(val);
+ if (!m_view.rescale_keep->isChecked()) return;
+ m_view.rescale_height->blockSignals(true);
+ m_view.rescale_height->setValue(val * m_profile.height / m_profile.width + 0.5);
+ KdenliveSettings::setDefaultrescaleheight(m_view.rescale_height->value());
+ m_view.rescale_height->blockSignals(false);
+}
+
+void RenderWidget::slotUpdateRescaleHeight(int val)
+{
+ KdenliveSettings::setDefaultrescaleheight(val);
+ if (!m_view.rescale_keep->isChecked()) return;
+ m_view.rescale_width->blockSignals(true);
+ m_view.rescale_width->setValue(val * m_profile.width / m_profile.height + 0.5);
+ KdenliveSettings::setDefaultrescaleheight(m_view.rescale_width->value());
+ m_view.rescale_width->blockSignals(false);
+}
+
+void RenderWidget::slotSwitchAspectRatio()
+{
+ KdenliveSettings::setRescalekeepratio(m_view.rescale_keep->isChecked());
+ if (m_view.rescale_keep->isChecked()) slotUpdateRescaleWidth(m_view.rescale_width->value());
+}
+
+void RenderWidget::slotUpdateAudioLabel(int ix)
+{
+ if (ix == Qt::PartiallyChecked)
+ m_view.export_audio->setText(i18n("Export audio (automatic)"));
+ else
+ m_view.export_audio->setText(i18n("Export audio"));
+}
+
+bool RenderWidget::automaticAudioExport() const
+{
+ return (m_view.export_audio->checkState() == Qt::PartiallyChecked);
+}
+
+bool RenderWidget::selectedAudioExport() const
+{
+ return (m_view.export_audio->checkState() != Qt::Unchecked);
+}
+
+void RenderWidget::updateProxyConfig(bool enable)
+{
+ m_view.proxy_render->setHidden(!enable);
+}
+
+bool RenderWidget::proxyRendering()
+{
+ return m_view.proxy_render->isChecked();
+}