+ if (url != 0) {
+ QListWidgetItem *item = m_view.size_list->currentItem();
+ QString extension = item->data(ExtensionRole).toString();
+ url = filenameWithExtension(url, extension);
+ m_view.out_file->setUrl(url);
+ }
+}
+
+// Will be called when the user changes the output file path in the text line.
+// File extension must NOT be added, would make editing impossible!
+void RenderWidget::slotUpdateButtons()
+{
+ if (m_view.out_file->url().isEmpty()) m_view.buttonStart->setEnabled(false);
+ else m_view.buttonStart->setEnabled(true);
+}
+
+void RenderWidget::slotSaveProfile()
+{
+ //TODO: update to correctly use metagroups
+ Ui::SaveProfile_UI ui;
+ QDialog *d = new QDialog(this);
+ ui.setupUi(d);
+
+ 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());
+ ui.profile_name->setFocus();
+ if (d->exec() == QDialog::Accepted && !ui.profile_name->text().simplified().isEmpty()) {
+ QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
+ QDomDocument doc;
+ QFile file(exportFile);
+ doc.setContent(&file, false);
+ file.close();
+ QDomElement documentElement;
+ 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->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++;
+ }
+
+ 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());
+ profiles.appendChild(profileElement);
+
+ //QCString save = doc.toString().utf8();
+
+ if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
+ KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
+ delete d;
+ return;
+ }
+ QTextStream out(&file);
+ out << doc.toString();
+ if (file.error() != QFile::NoError) {
+ KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
+ file.close();
+ return;
+ }
+ file.close();
+ parseProfiles(newMetaGroupId, newGroupName, newProfileName);
+ }
+ delete d;
+}
+
+void RenderWidget::slotEditProfile()
+{
+ QListWidgetItem *item = m_view.size_list->currentItem();
+ if (!item) return;
+ QString currentGroup = m_view.format_list->currentItem()->text();
+
+ QString params = item->data(ParamsRole).toString();
+ QString extension = item->data(ExtensionRole).toString();
+ QString currentProfile = item->text();
+
+ Ui::SaveProfile_UI ui;
+ QDialog *d = new QDialog(this);
+ ui.setupUi(d);
+
+ 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(false);
+ QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
+ QDomDocument doc;
+ QFile file(exportFile);
+ doc.setContent(&file, false);
+ file.close();
+ QDomElement documentElement;
+ 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->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++;
+ }
+
+ 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());
+ profiles.appendChild(profileElement);
+
+ //QCString save = doc.toString().utf8();
+ delete d;
+ if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
+ KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
+ return;
+ }
+ QTextStream out(&file);
+ out << doc.toString();
+ if (file.error() != QFile::NoError) {
+ KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
+ file.close();
+ return;
+ }
+ file.close();
+ parseProfiles(newMetaGroupId, newGroupName, newProfileName);
+ } else delete d;
+}
+
+void RenderWidget::slotDeleteProfile(bool refresh)
+{
+ //TODO: delete a profile installed by KNewStuff the easy way
+ /*
+ QString edit = m_view.size_list->currentItem()->data(EditableRole).toString();
+ if (!edit.endsWith("customprofiles.xml")) {
+ // This is a KNewStuff installed file, process through KNS
+ KNS::Engine engine(0);
+ if (engine.init("kdenlive_render.knsrc")) {
+ KNS::Entry::List entries;
+ }
+ return;
+ }*/
+ 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;
+ QFile file(exportFile);
+ doc.setContent(&file, false);
+ file.close();
+
+ QDomElement documentElement;
+ QDomNodeList profiles = doc.elementsByTagName("profile");
+ int i = 0;
+ QString groupName;
+ QString profileName;
+ QString destination;
+
+ 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++;
+ }
+
+ if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
+ KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
+ return;
+ }
+ QTextStream out(&file);
+ out << doc.toString();
+ if (file.error() != QFile::NoError) {
+ KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
+ file.close();
+ return;
+ }
+ file.close();
+ if (refresh) {
+ parseProfiles(metaGroupId, currentGroup);
+ focusFirstVisibleItem();
+ }
+}
+
+void RenderWidget::updateButtons()
+{
+ if (!m_view.size_list->currentItem() || m_view.size_list->currentItem()->isHidden()) {
+ m_view.buttonSave->setEnabled(false);
+ m_view.buttonDelete->setEnabled(false);
+ m_view.buttonEdit->setEnabled(false);
+ m_view.buttonStart->setEnabled(false);
+ } else {
+ m_view.buttonSave->setEnabled(true);
+ m_view.buttonStart->setEnabled(m_view.size_list->currentItem()->flags() & Qt::ItemIsEnabled);
+ QString edit = m_view.size_list->currentItem()->data(EditableRole).toString();
+ if (edit.isEmpty() || !edit.endsWith("customprofiles.xml")) {
+ m_view.buttonDelete->setEnabled(false);
+ m_view.buttonEdit->setEnabled(false);
+ } else {
+ m_view.buttonDelete->setEnabled(true);
+ m_view.buttonEdit->setEnabled(true);
+ }
+ }
+}
+
+
+void RenderWidget::focusFirstVisibleItem()
+{
+ if (m_view.size_list->currentItem() && !m_view.size_list->currentItem()->isHidden()) {
+ updateButtons();
+ return;
+ }
+ for (uint ix = 0; ix < m_view.size_list->count(); ix++) {
+ QListWidgetItem *item = m_view.size_list->item(ix);
+ if (item && !item->isHidden()) {
+ m_view.size_list->setCurrentRow(ix);
+ break;
+ }
+ }
+ if (!m_view.size_list->currentItem()) m_view.size_list->setCurrentRow(0);
+ updateButtons();