]> git.sesse.net Git - kdenlive/commitdiff
Initial support for changing project folder
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Sat, 13 Dec 2008 03:22:29 +0000 (03:22 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Sat, 13 Dec 2008 03:22:29 +0000 (03:22 +0000)
svn path=/branches/KDE4/; revision=2782

src/docclipbase.cpp
src/docclipbase.h
src/kdenlivedoc.cpp
src/kdenlivedoc.h
src/kthumb.cpp
src/kthumb.h
src/mainwindow.cpp

index c73c952bd5bcd71e035a834e9c1bba83c797cbb3..2b147d9c95663dfca12e1c8fff7270a447c3abea 100644 (file)
@@ -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") {
index 8e83242e9e43753d4ba81a32d969704a88aa017e..36433da5501aec5bfeebf31fc35cb06708b03b6c 100644 (file)
@@ -166,6 +166,7 @@ Q_OBJECT public:
     void slotClearAudioCache();
     void askForAudioThumbs();
     QString getClipHash() const;
+    void refreshThumbUrl();
 
 private:   // Private attributes
     /** The name of this clip */
index 77899a60e334f0aea8e280e4f54ad5bf01ac6e67..32814f369b8ce35533dbae7e3ff13d5d12fd396d 100644 (file)
@@ -26,6 +26,7 @@
 #include <KLocale>
 #include <KFileDialog>
 #include <KIO/NetAccess>
+#include <KIO/CopyJob>
 #include <KApplication>
 
 
@@ -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 <DocClipBase*> 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";
index 66693c235b1764141083bf12d82fd0d2bb284b5d..24f145d1311ddf9848753be709ea35da5fac9fc9 100644 (file)
@@ -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);
index 88aa4492857a10158eeae35e81085461059fce7d..a7e12e10ac23721042cc6ed26c82c0341c3f1f6e 100644 (file)
@@ -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
index cb24b9b30bd09bff7b65db5d2012dbcb065b19f0..892f4d6c7b34bab08cf0a45b8b8a73029c9ebbd1 100644 (file)
@@ -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);
index dd160b45692feeea401ec6586fb49d63644db2f9..9147dc9ad8b5c41840040dc910b7de8904562cbb 100644 (file)
@@ -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());