From 1e72f355aa946b2519827722e84992546867069d Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Sat, 13 Dec 2008 03:22:29 +0000 Subject: [PATCH] Initial support for changing project folder svn path=/branches/KDE4/; revision=2782 --- src/docclipbase.cpp | 6 +++++- src/docclipbase.h | 1 + src/kdenlivedoc.cpp | 40 ++++++++++++++++++++++++++++++++++++++-- src/kdenlivedoc.h | 4 +++- src/kthumb.cpp | 7 ++++++- src/kthumb.h | 3 ++- src/mainwindow.cpp | 1 + 7 files changed, 56 insertions(+), 6 deletions(-) diff --git a/src/docclipbase.cpp b/src/docclipbase.cpp index c73c952b..2b147d9c 100644 --- a/src/docclipbase.cpp +++ b/src/docclipbase.cpp @@ -556,11 +556,15 @@ QString DocClipBase::getClipHash() const { return hash; } +void DocClipBase::refreshThumbUrl() { + if (m_thumbProd) m_thumbProd->updateThumbUrl(m_properties.value("file_hash")); +} + void DocClipBase::setProperty(const QString &key, const QString &value) { m_properties.insert(key, value); if (key == "resource") { - m_thumbProd->updateClipUrl(KUrl(value)); getFileHash(value); + if (m_thumbProd) m_thumbProd->updateClipUrl(KUrl(value), m_properties.value("file_hash")); } else if (key == "out") setDuration(GenTime(value.toInt(), KdenliveSettings::project_fps())); //else if (key == "transparency") m_clipProducer->set("transparency", value.toInt()); else if (key == "colour") { diff --git a/src/docclipbase.h b/src/docclipbase.h index 8e83242e..36433da5 100644 --- a/src/docclipbase.h +++ b/src/docclipbase.h @@ -166,6 +166,7 @@ Q_OBJECT public: void slotClearAudioCache(); void askForAudioThumbs(); QString getClipHash() const; + void refreshThumbUrl(); private: // Private attributes /** The name of this clip */ diff --git a/src/kdenlivedoc.cpp b/src/kdenlivedoc.cpp index 77899a60..32814f36 100644 --- a/src/kdenlivedoc.cpp +++ b/src/kdenlivedoc.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include @@ -864,6 +865,43 @@ KUrl KdenliveDoc::projectFolder() const { return m_projectFolder; } +void KdenliveDoc::setProjectFolder(KUrl url) { + if (url == m_projectFolder) return; + setModified(true); + KStandardDirs::makeDir(url.path()); + KStandardDirs::makeDir(url.path() + "/titles/"); + KStandardDirs::makeDir(url.path() + "/thumbs/"); + if (KMessageBox::questionYesNo(kapp->activeWindow(), i18n("You have changed the project folder. Do you want to copy the cached data from %1 to the new folder %2 ?").arg(m_projectFolder.path(), url.path())) == KMessageBox::Yes) moveProjectData(url); + m_projectFolder = url; +} + +void KdenliveDoc::moveProjectData(KUrl url) { + QList list = m_clipManager->documentClipList(); + for (int i = 0; i < list.count(); i++) { + DocClipBase *clip = list.at(i); + if (clip->clipType() == TEXT) { + // the image for title clip must be moved + KUrl oldUrl = clip->fileURL(); + KUrl newUrl = KUrl(url.path() + "/titles/" + oldUrl.fileName()); + KIO::Job *job = KIO::copy(oldUrl, newUrl); + if (KIO::NetAccess::synchronousRun(job, 0)) clip->setProperty("resource", newUrl.path()); + } + QString hash = clip->getClipHash(); + KUrl oldVideoThumbUrl = KUrl(m_projectFolder.path() + "/thumbs/" + hash + ".png"); + KUrl oldAudioThumbUrl = KUrl(m_projectFolder.path() + "/thumbs/" + hash + ".thumb"); + if (KIO::NetAccess::exists(oldVideoThumbUrl, KIO::NetAccess::SourceSide, 0)) { + KUrl newUrl = KUrl(url.path() + "/thumbs/" + hash + ".png"); + KIO::Job *job = KIO::copy(oldVideoThumbUrl, newUrl); + KIO::NetAccess::synchronousRun(job, 0); + } + if (KIO::NetAccess::exists(oldAudioThumbUrl, KIO::NetAccess::SourceSide, 0)) { + KUrl newUrl = KUrl(url.path() + "/thumbs/" + hash + ".thumb"); + KIO::Job *job = KIO::copy(oldAudioThumbUrl, newUrl); + if (KIO::NetAccess::synchronousRun(job, 0)) clip->refreshThumbUrl(); + } + } +} + QString KdenliveDoc::profilePath() const { return m_profile.path; } @@ -925,10 +963,8 @@ void KdenliveDoc::checkProjectClips() { id = prods.at(i)->get("id"); prodId = id.section('_', 0, 0); prodTrack = id.section('_', 1, 1); - kDebug() << "CHECK PRO CLIP, ID: " << id; DocClipBase *clip = m_clipManager->getClipById(prodId); if (clip) clip->setProducer(prods.at(i)); - kDebug() << "CHECK PRO CLIP, ID: " << id << " DONE"; if (clip && clip->clipType() == TEXT && !QFile::exists(clip->fileURL().path())) { // regenerate text clip image if required kDebug() << "// TITLE: " << clip->getProperty("titlename") << " Preview file: " << clip->getProperty("resource") << " DOES NOT EXIST"; diff --git a/src/kdenlivedoc.h b/src/kdenlivedoc.h index 66693c23..24f145d1 100644 --- a/src/kdenlivedoc.h +++ b/src/kdenlivedoc.h @@ -92,7 +92,7 @@ Q_OBJECT public: QString description() const; void setUrl(KUrl url); void setProfilePath(QString path); - const QString&getFreeClipId(); + const QString &getFreeClipId(); /** does the document need saving */ bool isModified() const; /** Returns project folder, used to store project files (titles, effects,...) */ @@ -116,6 +116,7 @@ Q_OBJECT public: void switchTrackVideo(int ix, bool hide); void switchTrackAudio(int ix, bool hide); void cachePixmap(const QString &fileId, const QPixmap &pix) const; + void setProjectFolder(KUrl url); private: KUrl m_url; @@ -151,6 +152,7 @@ private: void checkProjectClips(); void setNewClipResource(const QString &id, const QString &path); QString searchFileRecursively(const QDir &dir, const QString &matchSize, const QString &matchHash) const; + void moveProjectData(KUrl url); public slots: void slotCreateTextClip(QString group, const QString &groupId); diff --git a/src/kthumb.cpp b/src/kthumb.cpp index 88aa4492..a7e12e10 100644 --- a/src/kthumb.cpp +++ b/src/kthumb.cpp @@ -144,13 +144,18 @@ bool KThumb::hasProducer() const { return m_producer != NULL; } -void KThumb::updateClipUrl(KUrl url) { +void KThumb::updateThumbUrl(const QString &hash) { + m_thumbFile = m_clipManager->projectFolder() + "/thumbs/" + hash + ".thumb"; +} + +void KThumb::updateClipUrl(KUrl url, const QString &hash) { m_url = url; if (m_producer) { char *tmp = Render::decodedString(url.path()); m_producer->set("resource", tmp); delete[] tmp; } + m_thumbFile = m_clipManager->projectFolder() + "/thumbs/" + hash + ".thumb"; } //static diff --git a/src/kthumb.h b/src/kthumb.h index cb24b9b3..892f4d6c 100644 --- a/src/kthumb.h +++ b/src/kthumb.h @@ -83,11 +83,12 @@ Q_OBJECT public: void setProducer(Mlt::Producer *producer); void askForAudioThumbs(const QString &id); bool hasProducer() const; + void updateThumbUrl(const QString &hash); public slots: void extractImage(int frame, int frame2); QPixmap extractImage(int frame, int width, int height); - void updateClipUrl(KUrl url); + void updateClipUrl(KUrl url, const QString &hash); static QPixmap getImage(KUrl url, int width, int height); // static QPixmap getImage(QDomElement xml, int frame, int width, int height); /* void getImage(KUrl url, int frame, int width, int height); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index dd160b45..9147dc9a 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1201,6 +1201,7 @@ void MainWindow::slotEditProjectSettings() { m_activeDocument->setProfilePath(profile); KdenliveSettings::setCurrent_profile(profile); KdenliveSettings::setProject_fps(m_activeDocument->fps()); + m_activeDocument->setProjectFolder(w->selectedFolder()); setCaption(m_activeDocument->description(), m_activeDocument->isModified()); m_monitorManager->resetProfiles(m_activeDocument->timecode()); if (m_renderWidget) m_renderWidget->setProfile(m_activeDocument->mltProfile()); -- 2.39.2