+void KdenliveDoc::addClip(QDomElement elem, QString clipId, bool createClipItem)
+{
+ const QString producerId = clipId.section('_', 0, 0);
+ DocClipBase *clip = m_clipManager->getClipById(producerId);
+
+ if (clip == NULL) {
+ elem.setAttribute("id", producerId);
+ QString path = elem.attribute("resource");
+ QString extension;
+ if (elem.attribute("type").toInt() == SLIDESHOW) {
+ extension = KUrl(path).fileName();
+ path = KUrl(path).directory();
+ } else if (elem.attribute("type").toInt() == TEXT && QFile::exists(path) == false) {
+ kDebug() << "// TITLE: " << elem.attribute("name") << " Preview file: " << elem.attribute("resource") << " DOES NOT EXIST";
+ QString titlename = elem.attribute("name");
+ QString titleresource;
+ if (titlename.isEmpty()) {
+ QStringList titleInfo = TitleWidget::getFreeTitleInfo(projectFolder());
+ titlename = titleInfo.at(0);
+ titleresource = titleInfo.at(1);
+ elem.setAttribute("name", titlename);
+ kDebug() << "// New title set to: " << titlename;
+ } else {
+ titleresource = TitleWidget::getFreeTitleInfo(projectFolder()).at(1);
+ //titleresource = TitleWidget::getTitleResourceFromName(projectFolder(), titlename);
+ }
+ TitleWidget *dia_ui = new TitleWidget(KUrl(), KUrl(titleresource).directory(), m_render, kapp->activeWindow());
+ QDomDocument doc;
+ doc.setContent(elem.attribute("xmldata"));
+ dia_ui->setXml(doc);
+ QImage pix = dia_ui->renderedPixmap();
+ pix.save(titleresource);
+ elem.setAttribute("resource", titleresource);
+ setNewClipResource(clipId, titleresource);
+ delete dia_ui;
+ }
+
+ if (path.isEmpty() == false && QFile::exists(path) == false && elem.attribute("type").toInt() != TEXT && !elem.hasAttribute("placeholder")) {
+ kDebug() << "// FOUND MISSING CLIP: " << path << ", TYPE: " << elem.attribute("type").toInt();
+ const QString size = elem.attribute("file_size");
+ const QString hash = elem.attribute("file_hash");
+ QString newpath;
+ int action = KMessageBox::No;
+ if (!size.isEmpty() && !hash.isEmpty()) {
+ if (!m_searchFolder.isEmpty()) newpath = searchFileRecursively(m_searchFolder, size, hash);
+ else action = (KMessageBox::ButtonCode) KMessageBox::questionYesNoCancel(kapp->activeWindow(), i18n("Clip <b>%1</b><br>is invalid, what do you want to do?", path), i18n("File not found"), KGuiItem(i18n("Search automatically")), KGuiItem(i18n("Keep as placeholder")));
+ } else {
+ if (elem.attribute("type").toInt() == SLIDESHOW) {
+ int res = KMessageBox::questionYesNoCancel(kapp->activeWindow(), i18n("Clip <b>%1</b><br>is invalid or missing, what do you want to do?", path), i18n("File not found"), KGuiItem(i18n("Search manually")), KGuiItem(i18n("Keep as placeholder")));
+ if (res == KMessageBox::Yes)
+ newpath = KFileDialog::getExistingDirectory(KUrl("kfiledialog:///clipfolder"), kapp->activeWindow(), i18n("Looking for %1", path));
+ else {
+ // Abort project loading
+ action = res;
+ }
+ } else {
+ int res = KMessageBox::questionYesNoCancel(kapp->activeWindow(), i18n("Clip <b>%1</b><br>is invalid or missing, what do you want to do?", path), i18n("File not found"), KGuiItem(i18n("Search manually")), KGuiItem(i18n("Keep as placeholder")));
+ if (res == KMessageBox::Yes)
+ newpath = KFileDialog::getOpenFileName(KUrl("kfiledialog:///clipfolder"), QString(), kapp->activeWindow(), i18n("Looking for %1", path));
+ else {
+ // Abort project loading
+ action = res;
+ }
+ }
+ }
+ if (action == KMessageBox::Yes) {
+ kDebug() << "// ASKED FOR SRCH CLIP: " << clipId;
+ m_searchFolder = KFileDialog::getExistingDirectory(KUrl("kfiledialog:///clipfolder"), kapp->activeWindow());
+ if (!m_searchFolder.isEmpty()) {
+ newpath = searchFileRecursively(QDir(m_searchFolder), size, hash);
+ }
+ } else if (action == KMessageBox::Cancel) {
+ m_abortLoading = true;
+ return;
+ } else if (action == KMessageBox::No) {
+ // Keep clip as placeHolder
+ elem.setAttribute("placeholder", '1');
+ }
+ if (!newpath.isEmpty()) {
+ if (elem.attribute("type").toInt() == SLIDESHOW) newpath.append('/' + extension);
+ elem.setAttribute("resource", newpath);
+ setNewClipResource(clipId, newpath);
+ setModified(true);
+ }
+ }
+ clip = new DocClipBase(m_clipManager, elem, producerId);
+ m_clipManager->addClip(clip);
+ }
+
+ if (createClipItem) {
+ emit addProjectClip(clip);
+ qApp->processEvents();
+ m_render->getFileProperties(clip->toXML(), clip->getId());
+ }