+
+ // Get the list of existing templates
+ QStringList filter;
+ filter << "*.kdenlivetitle";
+ QStringList templateFiles = QDir(titlepath).entryList(filter, QDir::Files);
+
+ QDialog *dia = new QDialog(this);
+ Ui::TemplateClip_UI dia_ui;
+ dia_ui.setupUi(dia);
+ int ix = -1;
+ const QString templatePath = clip->getProperty("xmltemplate");
+ for (int i = 0; i < templateFiles.size(); ++i) {
+ dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), titlepath + templateFiles.at(i));
+ if (templatePath == KUrl(titlepath + templateFiles.at(i)).path()) ix = i;
+ }
+ if (ix != -1) dia_ui.template_list->comboBox()->setCurrentIndex(ix);
+ else dia_ui.template_list->comboBox()->insertItem(0, templatePath);
+ dia_ui.template_list->fileDialog()->setFilter("*.kdenlivetitle");
+ //warning: setting base directory doesn't work??
+ KUrl startDir(titlepath);
+ dia_ui.template_list->fileDialog()->setUrl(startDir);
+ dia_ui.description->setText(clip->getProperty("description"));
+ dia_ui.clone_clip->setChecked(true);
+ if (dia->exec() == QDialog::Accepted) {
+ QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
+ if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
+
+ QMap <QString, QString> newprops;
+
+ if (KUrl(textTemplate).path() != templatePath) {
+ // The template was changed
+ newprops.insert("xmltemplate", textTemplate);
+ }
+
+ if (dia_ui.description->toPlainText() != clip->getProperty("description")) {
+ newprops.insert("description", dia_ui.description->toPlainText());
+ }
+
+ QString newtemplate = newprops.value("xmltemplate");
+ if (newtemplate.isEmpty()) newtemplate = templatePath;
+
+ // template modified we need to update xmldata
+ QString description = newprops.value("description");
+ if (description.isEmpty()) description = clip->getProperty("description");
+ newprops.insert("xmldata", m_projectList->generateTemplateXml(newtemplate, description).toString());
+ if (dia_ui.normal_clip->isChecked()) {
+ // Switch clip to normal clip
+ newprops.insert("xmltemplate", QString());
+ }
+ EditClipCommand *command = new EditClipCommand(m_projectList, clip->getId(), clip->properties(), newprops, true);
+ m_activeDocument->commandStack()->push(command);