#include <QDomDocument>
#include <QItemDelegate>
#include <QTreeWidgetItem>
+#include <QListWidgetItem>
#include <QHeaderView>
+#include <QMenu>
+#include <QProcess>
+#include <QInputDialog>
#include <KStandardDirs>
#include <KDebug>
#include <KMessageBox>
#include <KComboBox>
#include <KRun>
+#include <KIO/NetAccess>
#include "kdenlivesettings.h"
#include "renderwidget.h"
const int MetaGroupRole = GroupRole + 6;
const int ExtraRole = GroupRole + 7;
-RenderWidget::RenderWidget(QWidget * parent): QDialog(parent) {
+RenderWidget::RenderWidget(const QString &projectfolder, QWidget * parent): QDialog(parent), m_projectFolder(projectfolder) {
m_view.setupUi(this);
setWindowTitle(i18n("Rendering"));
m_view.buttonDelete->setIcon(KIcon("trash-empty"));
m_view.buttonInfo->setDown(true);
} else m_view.advanced_params->hide();
- m_view.rescale_size->setInputMask("0099*0099");
- m_view.rescale_size->setText("320*240");
+ m_view.rescale_size->setInputMask("0099\\x0099");
+ m_view.rescale_size->setText("320x240");
+
+
+ QMenu *renderMenu = new QMenu(i18n("Start Rendering"), this);
+ QAction *renderAction = renderMenu->addAction(KIcon("file-new"), i18n("Render to File"));
+ connect(renderAction, SIGNAL(triggered()), this, SLOT(slotExport()));
+ QAction *scriptAction = renderMenu->addAction(KIcon("file-new"), i18n("Generate Script"));
+ connect(scriptAction, SIGNAL(triggered()), this, SLOT(slotGenerateScript()));
+
+ m_view.buttonStart->setMenu(renderMenu);
+ m_view.buttonStart->setPopupMode(QToolButton::MenuButtonPopup);
+ m_view.buttonStart->setDefaultAction(renderAction);
+ m_view.buttonStart->setToolButtonStyle(Qt::ToolButtonTextOnly);
+ m_view.abort_job->setEnabled(false);
+ m_view.start_script->setEnabled(false);
+ m_view.delete_script->setEnabled(false);
+
parseProfiles();
+ parseScriptFiles();
+
+ connect(m_view.start_script, SIGNAL(clicked()), this, SLOT(slotStartScript()));
+ connect(m_view.delete_script, SIGNAL(clicked()), this, SLOT(slotDeleteScript()));
+ connect(m_view.scripts_list, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(slotCheckScript()));
+ connect(m_view.running_jobs, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(slotCheckJob()));
connect(m_view.buttonInfo, SIGNAL(clicked()), this, SLOT(showInfoPanel()));
connect(m_view.buttonSave, SIGNAL(clicked()), this, SLOT(slotSaveProfile()));
connect(m_view.buttonEdit, SIGNAL(clicked()), this, SLOT(slotEditProfile()));
connect(m_view.buttonDelete, SIGNAL(clicked()), this, SLOT(slotDeleteProfile()));
- connect(m_view.buttonStart, SIGNAL(clicked()), this, SLOT(slotExport()));
connect(m_view.abort_job, SIGNAL(clicked()), this, SLOT(slotAbortCurrentJob()));
connect(m_view.buttonClose, SIGNAL(clicked()), this, SLOT(hide()));
connect(m_view.buttonClose2, SIGNAL(clicked()), this, SLOT(hide()));
+ connect(m_view.buttonClose3, SIGNAL(clicked()), this, SLOT(hide()));
connect(m_view.rescale, SIGNAL(toggled(bool)), m_view.rescale_size, SLOT(setEnabled(bool)));
connect(m_view.destination_list, SIGNAL(activated(int)), this, SLOT(refreshView()));
connect(m_view.out_file, SIGNAL(textChanged(const QString &)), this, SLOT(slotUpdateButtons()));
connect(m_view.format_list, SIGNAL(currentRowChanged(int)), this, SLOT(refreshView()));
connect(m_view.size_list, SIGNAL(currentRowChanged(int)), this, SLOT(refreshParams()));
+ connect(m_view.size_list, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(slotEditItem(QListWidgetItem *)));
+
connect(m_view.render_guide, SIGNAL(clicked(bool)), this, SLOT(slotUpdateGuideBox()));
connect(m_view.render_zone, SIGNAL(clicked(bool)), this, SLOT(slotUpdateGuideBox()));
connect(m_view.render_full, SIGNAL(clicked(bool)), this, SLOT(slotUpdateGuideBox()));
m_view.running_jobs->setHeaderLabels(QStringList() << QString() << i18n("File") << i18n("Progress"));
m_view.running_jobs->setItemDelegate(new RenderViewDelegate(this));
+
QHeaderView *header = m_view.running_jobs->header();
QFontMetrics fm = fontMetrics();
//header->resizeSection(0, fm.width("typical-name-for-a-torrent.torrent"));
header->setResizeMode(2, QHeaderView::Interactive);
//header->setResizeMode(1, QHeaderView::Fixed);
+ m_view.scripts_list->setHeaderLabels(QStringList() << i18n("Script Files"));
+ m_view.scripts_list->setItemDelegate(new RenderScriptDelegate(this));
+
+
focusFirstVisibleItem();
}
+void RenderWidget::slotEditItem(QListWidgetItem *item) {
+ if (item->data(EditableRole).toString().isEmpty()) slotSaveProfile();
+ else slotEditProfile();
+}
+
void RenderWidget::showInfoPanel() {
if (m_view.advanced_params->isVisible()) {
m_view.advanced_params->setVisible(false);
}
}
+void RenderWidget::setDocumentPath(const QString path) {
+ m_projectFolder = path;
+ const QString fileName = m_view.out_file->url().fileName();
+ m_view.out_file->setUrl(KUrl(m_projectFolder + '/' + fileName));
+ parseScriptFiles();
+}
+
void RenderWidget::slotUpdateGuideBox() {
m_view.guides_box->setVisible(m_view.render_guide->isChecked());
}
}
void RenderWidget::slotSaveProfile() {
+ //TODO: update to correctly use metagroups
Ui::SaveProfile_UI ui;
QDialog *d = new QDialog(this);
ui.setupUi(d);
- QString customGroup = i18n("Custom");
- QStringList groupNames;
- for (int i = 0; i < m_view.format_list->count(); i++)
- groupNames.append(m_view.format_list->item(i)->text());
- if (!groupNames.contains(customGroup)) groupNames.prepend(customGroup);
- ui.group_name->addItems(groupNames);
- int pos = ui.group_name->findText(customGroup);
- ui.group_name->setCurrentIndex(pos);
+
+ for (int i = 0; i < m_view.destination_list->count(); i++)
+ ui.destination_list->addItem(m_view.destination_list->itemIcon(i), m_view.destination_list->itemText(i), m_view.destination_list->itemData(i, Qt::UserRole));
+
+ ui.destination_list->setCurrentIndex(m_view.destination_list->currentIndex());
+ QString dest = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
+
+ QString customGroup = m_view.format_list->currentItem()->text();
+ if (customGroup.isEmpty()) customGroup = i18n("Custom");
+ ui.group_name->setText(customGroup);
ui.parameters->setText(m_view.advanced_params->toPlainText());
ui.extension->setText(m_view.size_list->currentItem()->data(ExtensionRole).toString());
QFile file(exportFile);
doc.setContent(&file, false);
file.close();
-
QDomElement documentElement;
- bool groupExists = false;
- QString groupName;
+ QDomElement profiles = doc.documentElement();
+ if (profiles.isNull() || profiles.tagName() != "profiles") {
+ doc.clear();
+ profiles = doc.createElement("profiles");
+ profiles.setAttribute("version", 1);
+ doc.appendChild(profiles);
+ }
+ int version = profiles.attribute("version", 0).toInt();
+ if (version < 1) {
+ kDebug() << "// OLD profile version";
+ doc.clear();
+ profiles = doc.createElement("profiles");
+ profiles.setAttribute("version", 1);
+ doc.appendChild(profiles);
+ }
+
QString newProfileName = ui.profile_name->text().simplified();
- QString newGroupName = ui.group_name->currentText();
- QDomNodeList groups = doc.elementsByTagName("group");
+ QString newGroupName = ui.group_name->text().simplified();
+ if (newGroupName.isEmpty()) newGroupName = i18n("Custom");
+ QString newMetaGroupId = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
+ QDomNodeList profilelist = doc.elementsByTagName("profile");
int i = 0;
- if (groups.count() == 0) {
- QDomElement profiles = doc.createElement("profiles");
- doc.appendChild(profiles);
- } else while (!groups.item(i).isNull()) {
- documentElement = groups.item(i).toElement();
- groupName = documentElement.attribute("name");
- kDebug() << "// SAVE, PARSING FROUP: " << i << ", name: " << groupName << ", LOOK FR: " << newGroupName;
- if (groupName == newGroupName) {
- groupExists = true;
+ while (!profilelist.item(i).isNull()) {
+ // make sure a profile with same name doesn't exist
+ documentElement = profilelist.item(i).toElement();
+ QString profileName = documentElement.attribute("name");
+ if (profileName == newProfileName) {
+ // a profile with that same name already exists
+ bool ok;
+ 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);
+ if (!ok) return;
+ if (profileName == newProfileName) {
+ profiles.removeChild(profilelist.item(i));
break;
}
- i++;
}
- if (!groupExists) {
- documentElement = doc.createElement("group");
- documentElement.setAttribute("name", ui.group_name->currentText());
- documentElement.setAttribute("renderer", "avformat");
- doc.documentElement().appendChild(documentElement);
+ i++;
}
+
QDomElement profileElement = doc.createElement("profile");
profileElement.setAttribute("name", newProfileName);
+ profileElement.setAttribute("category", newGroupName);
+ profileElement.setAttribute("destinationid", newMetaGroupId);
profileElement.setAttribute("extension", ui.extension->text().simplified());
profileElement.setAttribute("args", ui.parameters->toPlainText().simplified());
- documentElement.appendChild(profileElement);
+ profiles.appendChild(profileElement);
//QCString save = doc.toString().utf8();
QTextStream out(&file);
out << doc.toString();
file.close();
- parseProfiles(newGroupName, newProfileName);
+ parseProfiles(newMetaGroupId, newGroupName, newProfileName);
}
delete d;
}
Ui::SaveProfile_UI ui;
QDialog *d = new QDialog(this);
ui.setupUi(d);
- QStringList groupNames;
- for (int i = 0; i < m_view.format_list->count(); i++)
- groupNames.append(m_view.format_list->item(i)->text());
- if (!groupNames.contains(currentGroup)) groupNames.prepend(currentGroup);
- ui.group_name->addItems(groupNames);
- int pos = ui.group_name->findText(currentGroup);
- ui.group_name->setCurrentIndex(pos);
+
+ for (int i = 0; i < m_view.destination_list->count(); i++)
+ ui.destination_list->addItem(m_view.destination_list->itemIcon(i), m_view.destination_list->itemText(i), m_view.destination_list->itemData(i, Qt::UserRole));
+
+ ui.destination_list->setCurrentIndex(m_view.destination_list->currentIndex());
+ QString dest = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
+
+ QString customGroup = m_view.format_list->currentItem()->text();
+ if (customGroup.isEmpty()) customGroup = i18n("Custom");
+ ui.group_name->setText(customGroup);
+
ui.profile_name->setText(currentProfile);
ui.extension->setText(extension);
ui.parameters->setText(params);
ui.profile_name->setFocus();
-
+ d->setWindowTitle(i18n("Edit Profile"));
if (d->exec() == QDialog::Accepted) {
- slotDeleteProfile();
+ slotDeleteProfile(false);
QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
QDomDocument doc;
QFile file(exportFile);
doc.setContent(&file, false);
file.close();
-
QDomElement documentElement;
- bool groupExists = false;
- QString groupName;
- QString newProfileName = ui.profile_name->text();
- QString newGroupName = ui.group_name->currentText();
- QDomNodeList groups = doc.elementsByTagName("group");
- int i = 0;
- if (groups.count() == 0) {
- QDomElement profiles = doc.createElement("profiles");
+ QDomElement profiles = doc.documentElement();
+
+ if (profiles.isNull() || profiles.tagName() != "profiles") {
+ doc.clear();
+ profiles = doc.createElement("profiles");
+ profiles.setAttribute("version", 1);
+ doc.appendChild(profiles);
+ }
+
+ int version = profiles.attribute("version", 0).toInt();
+ if (version < 1) {
+ kDebug() << "// OLD profile version";
+ doc.clear();
+ profiles = doc.createElement("profiles");
+ profiles.setAttribute("version", 1);
doc.appendChild(profiles);
- } else while (!groups.item(i).isNull()) {
- documentElement = groups.item(i).toElement();
- groupName = documentElement.attribute("name");
- kDebug() << "// SAVE, PARSING FROUP: " << i << ", name: " << groupName << ", LOOK FR: " << newGroupName;
- if (groupName == newGroupName) {
- groupExists = true;
+ }
+
+ QString newProfileName = ui.profile_name->text().simplified();
+ QString newGroupName = ui.group_name->text().simplified();
+ if (newGroupName.isEmpty()) newGroupName = i18n("Custom");
+ QString newMetaGroupId = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
+ QDomNodeList profilelist = doc.elementsByTagName("profile");
+ int i = 0;
+ while (!profilelist.item(i).isNull()) {
+ // make sure a profile with same name doesn't exist
+ documentElement = profilelist.item(i).toElement();
+ QString profileName = documentElement.attribute("name");
+ if (profileName == newProfileName) {
+ // a profile with that same name already exists
+ bool ok;
+ 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);
+ if (!ok) return;
+ if (profileName == newProfileName) {
+ profiles.removeChild(profilelist.item(i));
break;
}
- i++;
}
- if (!groupExists) {
- documentElement = doc.createElement("group");
- documentElement.setAttribute("name", ui.group_name->currentText());
- documentElement.setAttribute("renderer", "avformat");
- doc.documentElement().appendChild(documentElement);
+ i++;
}
+
QDomElement profileElement = doc.createElement("profile");
profileElement.setAttribute("name", newProfileName);
+ profileElement.setAttribute("category", newGroupName);
+ profileElement.setAttribute("destinationid", newMetaGroupId);
profileElement.setAttribute("extension", ui.extension->text().simplified());
profileElement.setAttribute("args", ui.parameters->toPlainText().simplified());
- documentElement.appendChild(profileElement);
+ profiles.appendChild(profileElement);
//QCString save = doc.toString().utf8();
QTextStream out(&file);
out << doc.toString();
file.close();
- parseProfiles(newGroupName, newProfileName);
+ parseProfiles(newMetaGroupId, newGroupName, newProfileName);
}
delete d;
}
-void RenderWidget::slotDeleteProfile() {
+void RenderWidget::slotDeleteProfile(bool refresh) {
QString currentGroup = m_view.format_list->currentItem()->text();
QString currentProfile = m_view.size_list->currentItem()->text();
+ QString metaGroupId = m_view.destination_list->itemData(m_view.destination_list->currentIndex(), Qt::UserRole).toString();
QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
QDomDocument doc;
file.close();
QDomElement documentElement;
- bool groupExists = false;
- QString groupName;
- QDomNodeList groups = doc.elementsByTagName("group");
+ QDomNodeList profiles = doc.elementsByTagName("profile");
int i = 0;
+ QString groupName;
+ QString profileName;
+ QString destination;
- while (!groups.item(i).isNull()) {
- documentElement = groups.item(i).toElement();
- groupName = documentElement.attribute("name");
- if (groupName == currentGroup) {
- QDomNodeList children = documentElement.childNodes();
- for (int j = 0; j < children.count(); j++) {
- QDomElement pro = children.at(j).toElement();
- if (pro.attribute("name") == currentProfile) {
- groups.item(i).removeChild(children.at(j));
- if (groups.item(i).childNodes().isEmpty())
- doc.documentElement().removeChild(groups.item(i));
- break;
- }
- }
+ while (!profiles.item(i).isNull()) {
+ documentElement = profiles.item(i).toElement();
+ profileName = documentElement.attribute("name");
+ groupName = documentElement.attribute("category");
+ destination = documentElement.attribute("destinationid");
+
+ if (profileName == currentProfile && groupName == currentGroup && destination == metaGroupId) {
+ kDebug() << "// GOT it: " << profileName;
+ doc.documentElement().removeChild(profiles.item(i));
break;
}
i++;
QTextStream out(&file);
out << doc.toString();
file.close();
- parseProfiles(currentGroup);
- focusFirstVisibleItem();
+ if (refresh) {
+ parseProfiles(metaGroupId, currentGroup);
+ focusFirstVisibleItem();
+ }
}
void RenderWidget::updateButtons() {
updateButtons();
}
-void RenderWidget::slotExport() {
+void RenderWidget::slotExport(bool scriptExport) {
QListWidgetItem *item = m_view.size_list->currentItem();
if (!item) return;
+
const QString dest = m_view.out_file->url().path();
if (dest.isEmpty()) return;
QFile f(dest);
if (f.exists()) {
- if (KMessageBox::warningYesNo(this, i18n("File already exists. Do you want to overwrite it ?")) != KMessageBox::Yes)
+ if (KMessageBox::warningYesNo(this, i18n("Output file already exists. Do you want to overwrite it ?")) != KMessageBox::Yes)
return;
}
+
+ QString scriptName;
+ if (scriptExport) {
+ bool ok;
+ int ix = 0;
+ QString scriptsFolder = m_projectFolder + "/scripts/";
+ KStandardDirs::makeDir(scriptsFolder);
+ QString path = scriptsFolder + i18n("script") + QString::number(ix).rightJustified(3, '0', false) + ".sh";
+ while (QFile::exists(path)) {
+ ix++;
+ path = scriptsFolder + i18n("script") + QString::number(ix).rightJustified(3, '0', false) + ".sh";
+ }
+ scriptName = QInputDialog::getText(this, i18n("Create Render Script"), i18n("Script name (will be saved in: %1)", scriptsFolder), QLineEdit::Normal, KUrl(path).fileName(), &ok);
+ if (!ok || scriptName.isEmpty()) return;
+ scriptName.prepend(scriptsFolder);
+ QFile f(scriptName);
+ if (f.exists()) {
+ if (KMessageBox::warningYesNo(this, i18n("Script file already exists. Do you want to overwrite it ?")) != KMessageBox::Yes)
+ return;
+ }
+ }
+
QStringList overlayargs;
if (m_view.tc_overlay->isChecked()) {
QString filterFile = KStandardDirs::locate("appdata", "metadata.properties");
const QString currentSize = QString::number(width) + 'x' + QString::number(height);
if (subsize != currentSize) resizeProfile = true;
} else if (destination != "audioonly") {
- // Add current site parametrer
+ // Add current size parametrer
renderArgs.append(QString(" s=%1x%2").arg(width).arg(height));
}
renderItem->setData(0, Qt::UserRole + 1, url);
}
- emit doRender(dest, item->data(RenderRole).toString(), overlayargs, renderArgs.simplified().split(' '), m_view.render_zone->isChecked(), m_view.play_after->isChecked(), startPos, endPos, resizeProfile);
- m_view.tabWidget->setCurrentIndex(1);
+ 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);
+ if (scriptName.isEmpty()) m_view.tabWidget->setCurrentIndex(1);
+ else {
+ QTimer::singleShot(400, this, SLOT(parseScriptFiles()));
+ m_view.tabWidget->setCurrentIndex(2);
+ }
}
void RenderWidget::setProfile(MltVideoProfile profile) {
QListWidgetItem *sizeItem;
QString destination;
+ KIcon brokenIcon("dialog-close");
if (m_view.destination_list->currentIndex() > 0)
destination = m_view.destination_list->itemData(m_view.destination_list->currentIndex()).toString();
+
if (destination == "dvd") m_view.open_dvd->setVisible(true);
else m_view.open_dvd->setVisible(false);
if (destination == "websites") m_view.open_browser->setVisible(true);
// hide groups that are not in the correct destination
for (int i = 0; i < m_view.format_list->count(); i++) {
sizeItem = m_view.format_list->item(i);
- if (sizeItem->data(MetaGroupRole).toString() == destination)
+ if (sizeItem->data(MetaGroupRole).toString() == destination) {
sizeItem->setHidden(false);
- else sizeItem->setHidden(true);
+ //kDebug() << "// SET GRP:: " << sizeItem->text() << ", METY:" << sizeItem->data(MetaGroupRole).toString();
+ } else sizeItem->setHidden(true);
}
// activate first visible item
}
item = m_view.format_list->currentItem();
}
- if (!item) return;
+ if (!item || item->isHidden()) {
+ m_view.format_list->setEnabled(false);
+ m_view.size_list->setEnabled(false);
+ return;
+ } else {
+ m_view.format_list->setEnabled(true);
+ m_view.size_list->setEnabled(true);
+ }
int count = 0;
for (int i = 0; i < m_view.format_list->count() && count < 2; i++) {
if (!m_view.format_list->isRowHidden(i)) count++;
for (int i = 0; i < m_view.size_list->count(); i++) {
sizeItem = m_view.size_list->item(i);
- if (sizeItem->data(GroupRole) == group) {
+ if ((sizeItem->data(GroupRole) == group || sizeItem->data(GroupRole).toString().isEmpty()) && sizeItem->data(MetaGroupRole) == destination) {
std = sizeItem->data(StandardRole).toString();
if (!std.isEmpty()) {
if (std.contains("PAL", Qt::CaseInsensitive)) sizeItem->setHidden(m_view.format_selection->currentIndex() != 0);
format = format.section(' ', 0, 0).toLower();
if (!formatsList.contains(format)) {
kDebug() << "***** UNSUPPORTED F: " << format;
- sizeItem->setHidden(true);
+ //sizeItem->setHidden(true);
+ sizeItem->setFlags(Qt::NoItemFlags);
+ sizeItem->setToolTip(i18n("Unsupported video format: %1", format));
+ sizeItem->setIcon(brokenIcon);
}
}
}
format = format.section(' ', 0, 0).toLower();
if (!acodecsList.contains(format)) {
kDebug() << "***** UNSUPPORTED ACODEC: " << format;
- sizeItem->setHidden(true);
+ //sizeItem->setHidden(true);
+ sizeItem->setFlags(Qt::NoItemFlags);
+ sizeItem->setToolTip(i18n("Unsupported audio codec: %1", format));
+ sizeItem->setIcon(brokenIcon);
}
}
}
format = format.section(' ', 0, 0).toLower();
if (!vcodecsList.contains(format)) {
kDebug() << "***** UNSUPPORTED VCODEC: " << format;
- sizeItem->setHidden(true);
+ //sizeItem->setHidden(true);
+ sizeItem->setFlags(Qt::NoItemFlags);
+ sizeItem->setToolTip(i18n("Unsupported video codec: %1", format));
+ sizeItem->setIcon(brokenIcon);
}
}
}
else path = path.left(pos) + extension;
} else {
- path = QDir::homePath() + "/untitled." + extension;
+ path = m_projectFolder + "/untitled." + extension;
}
return KUrl(path);
}
m_view.buttonStart->setEnabled(true);
}
-void RenderWidget::parseProfiles(QString group, QString profile) {
+void RenderWidget::reloadProfiles() {
+ parseProfiles();
+}
+
+void RenderWidget::parseProfiles(QString meta, QString group, QString profile) {
m_view.size_list->clear();
m_view.format_list->clear();
m_view.destination_list->clear();
m_view.destination_list->addItem(KIcon("video-x-generic"), i18n("File rendering"));
+ m_view.destination_list->addItem(KIcon("media-optical"), i18n("DVD"), "dvd");
+ m_view.destination_list->addItem(KIcon("audio-x-generic"), i18n("Audio only"), "audioonly");
+ m_view.destination_list->addItem(KIcon("applications-internet"), i18n("Web sites"), "websites");
+ m_view.destination_list->addItem(KIcon("applications-multimedia"), i18n("Media players"), "mediaplayers");
+ m_view.destination_list->addItem(KIcon("drive-harddisk"), i18n("Lossless / HQ"), "lossless");
+ m_view.destination_list->addItem(KIcon("pda"), i18n("Mobile devices"), "mobile");
+
QString exportFile = KStandardDirs::locate("appdata", "export/profiles.xml");
parseFile(exportFile, false);
- exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
- if (QFile::exists(exportFile)) parseFile(exportFile, true);
+
+
+ QString exportFolder = KStandardDirs::locateLocal("appdata", "export/");
+ QDir directory = QDir(exportFolder);
+ QStringList filter;
+ filter << "*.xml";
+ const QStringList fileList = directory.entryList(filter, QDir::Files);
+ foreach(const QString filename, fileList)
+ parseFile(exportFolder + '/' + filename, filename == "customprofiles.xml");
+
+ 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);
+ }
refreshView();
QList<QListWidgetItem *> child;
- child = m_view.format_list->findItems(group, Qt::MatchExactly);
- if (!child.isEmpty()) m_view.format_list->setCurrentItem(child.at(0));
- child = m_view.size_list->findItems(profile, Qt::MatchExactly);
+ 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();
+ 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;
+ QListWidgetItem *item;
QDomNodeList groups = doc.elementsByTagName("group");
- if (groups.count() == 0) {
- kDebug() << "// Export file: " << exportFile << " IS BROKEN";
+ 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 = i18n("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");
+ QString category = profile.attribute("category", i18n("Custom"));
+ QString dest = profile.attribute("destinationid");
+ QString prof_extension = profile.attribute("extension");
+ if (!prof_extension.isEmpty()) extension = prof_extension;
+
+ QList <QListWidgetItem *> list = m_view.format_list->findItems(category, Qt::MatchExactly);
+ bool exists = false;
+ for (int j = 0; j < list.count(); j++) {
+ if (list.at(j)->data(MetaGroupRole) == dest) {
+ exists = true;
+ break;
+ }
+ }
+ if (!exists) {
+ item = new QListWidgetItem(category, m_view.format_list);
+ item->setData(MetaGroupRole, dest);
+ }
+
+ 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, "true");
+ node = doc.elementsByTagName("profile").at(count);
+ count++;
+ }
return;
}
int i = 0;
QString groupName;
QString profileName;
- QString extension;
+
QString prof_extension;
QString renderer;
QString params;
QString standard;
KIcon icon;
- QListWidgetItem *item;
+
while (!groups.item(i).isNull()) {
documentElement = groups.item(i).toElement();
QDomNode gname = documentElement.elementsByTagName("groupname").at(0);
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", QString::null);
+ groupName = documentElement.attribute("name", i18n("Custom"));
extension = documentElement.attribute("extension", QString::null);
renderer = documentElement.attribute("renderer", QString::null);
- if (m_view.format_list->findItems(groupName, Qt::MatchExactly).isEmpty()) {
+ QList <QListWidgetItem *> list = m_view.format_list->findItems(groupName, Qt::MatchExactly);
+ bool exists = false;
+ for (int j = 0; j < list.count(); j++) {
+ if (list.at(j)->data(MetaGroupRole) == metagroupId) {
+ exists = true;
+ break;
+ }
+ }
+ if (!exists) {
item = new QListWidgetItem(groupName, m_view.format_list);
item->setData(MetaGroupRole, metagroupId);
}
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());;
// Rendering crashed
item->setData(1, Qt::UserRole, i18n("Rendering crashed"));
item->setIcon(0, KIcon("dialog-close"));
- item->setData(2, Qt::UserRole, 0);
+ 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 />");
item->setIcon(0, KIcon("dialog-cancel"));
item->setData(2, Qt::UserRole, 100);
}
+ slotCheckJob();
}
void RenderWidget::slotAbortCurrentJob() {
if (current) emit abortProcess(current->text(1));
}
-#include "renderwidget.moc"
+void RenderWidget::slotCheckJob() {
+ bool activate = false;
+ QTreeWidgetItem *current = m_view.running_jobs->currentItem();
+ if (current) {
+ int percent = current->data(2, Qt::UserRole).toInt();
+ if (percent < 100) activate = true;
+ }
+ m_view.abort_job->setEnabled(activate);
+}
+
+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));
+ item = new QTreeWidgetItem(m_view.scripts_list, QStringList() << scriptpath.fileName());
+ QString target;
+ QFile file(scriptpath.path());
+ if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ while (!file.atEnd()) {
+ QByteArray line = file.readLine();
+ if (line.startsWith("TARGET=")) {
+ target = QString(line).section("TARGET=", 1);
+ target.remove(QChar('"'));
+ break;
+ }
+ }
+ file.close();
+ }
+ item->setSizeHint(0, QSize(m_view.scripts_list->columnWidth(0), fontMetrics().height() * 2));
+ item->setData(0, Qt::UserRole, target);
+ item->setData(0, Qt::UserRole + 1, scriptpath.path());
+ }
+ bool activate = false;
+ QTreeWidgetItemIterator it(m_view.scripts_list);
+ if (*it) {
+ kDebug() << "// FOUND SCRIPT ITEM:" << (*it)->text(0);
+ // Selecting item does not work, why ???
+ m_view.scripts_list->setCurrentItem(*it);
+ (*it)->setSelected(true);
+ activate = true;
+ }
+ kDebug() << "SELECTED SCRIPTS: " << m_view.scripts_list->selectedItems().count();
+ m_view.start_script->setEnabled(activate);
+ m_view.delete_script->setEnabled(activate);
+}
+
+void RenderWidget::slotCheckScript() {
+ bool activate = false;
+ QTreeWidgetItemIterator it(m_view.scripts_list);
+ if (*it) activate = true;
+ m_view.start_script->setEnabled(activate);
+ m_view.delete_script->setEnabled(activate);
+}
+
+void RenderWidget::slotStartScript() {
+ QTreeWidgetItem *item = m_view.scripts_list->currentItem();
+ if (item) {
+ QString path = item->data(0, Qt::UserRole + 1).toString();
+ QProcess::startDetached(path);
+ m_view.tabWidget->setCurrentIndex(1);
+ }
+}
+
+void RenderWidget::slotDeleteScript() {
+ QTreeWidgetItem *item = m_view.scripts_list->currentItem();
+ if (item) {
+ QString path = item->data(0, Qt::UserRole + 1).toString();
+ KIO::NetAccess::del(path + ".westley", this);
+ KIO::NetAccess::del(path, this);
+ parseScriptFiles();
+ }
+}
+
+void RenderWidget::slotGenerateScript() {
+ slotExport(true);
+}
\ No newline at end of file