]> git.sesse.net Git - kdenlive/commitdiff
New file management tab in project settings dialog, fixes:
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Wed, 16 Sep 2009 16:12:48 +0000 (16:12 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Wed, 16 Sep 2009 16:12:48 +0000 (16:12 +0000)
http://www.kdenlive.org/mantis/view.php?id=1140

svn path=/trunk/kdenlive/; revision=3900

src/docclipbase.cpp
src/docclipbase.h
src/mainwindow.cpp
src/projectlist.cpp
src/projectlist.h
src/projectsettings.cpp
src/projectsettings.h

index b1d5d1c9efbbdca29bcfefdafe74967a4d9db7d4..66e5c7795925257d9688b3284568f3cd9015e624 100644 (file)
@@ -245,6 +245,10 @@ bool DocClipBase::hasFileSize() const
     return true;
 }
 
+qulonglong DocClipBase::fileSize() const
+{
+    return m_properties.value("file_size").toULongLong();
+}
 
 // virtual
 QDomElement DocClipBase::toXML() const
index 3714f1aa6d29de5e75d0a1203fa59b56293bb437..907af5330462cfd7384e0dca01fb85b5c656bcc8 100644 (file)
@@ -147,7 +147,7 @@ Q_OBJECT public:
     bool hasFileSize() const;
 
     /** Returns the filesize, or 0 if there is no appropriate filesize. */
-    uint fileSize() const;
+    qulonglong fileSize() const;
 
     /** Returns true if this clip refers to the clip passed in. A clip refers to another clip if
      * it uses it as part of it's own composition. */
index a6019f7feb55850242fcf0b28769ecfefdcda1e0..e64bc63436b968038c2be83b937e4ea72a18e518 100644 (file)
@@ -52,6 +52,7 @@
 #include "kdenlive-config.h"
 #include "cliptranscode.h"
 #include "ui_templateclip_ui.h"
+#include "ui_projectfiles_ui.h"
 
 #include <KApplication>
 #include <KAction>
@@ -1259,7 +1260,7 @@ void MainWindow::newFile(bool showProjectSettings)
         profileName = KdenliveSettings::default_profile();
         projectFolder = KdenliveSettings::defaultprojectfolder();
     } else {
-        ProjectSettings *w = new ProjectSettings(projectTracks.x(), projectTracks.y(), KdenliveSettings::defaultprojectfolder(), false, true, this);
+        ProjectSettings *w = new ProjectSettings(NULL, projectTracks.x(), projectTracks.y(), KdenliveSettings::defaultprojectfolder(), false, true, this);
         if (w->exec() != QDialog::Accepted) return;
         if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
         KdenliveSettings::setVideothumbnails(w->enableVideoThumbs());
@@ -1617,9 +1618,13 @@ void MainWindow::slotDetectAudioDriver()
 void MainWindow::slotEditProjectSettings()
 {
     QPoint p = m_activeDocument->getTracksCount();
-    ProjectSettings *w = new ProjectSettings(p.x(), p.y(), m_activeDocument->projectFolder().path(), true, !m_activeDocument->isModified(), this);
+    ProjectSettings *w = new ProjectSettings(m_activeDocument->clipManager(), p.x(), p.y(), m_activeDocument->projectFolder().path(), true, !m_activeDocument->isModified(), this);
 
     if (w->exec() == QDialog::Accepted) {
+        if (w->deleteUnused()) {
+            // we are going to trash the unused clips
+            m_projectList->trashUnusedClips();
+        }
         QString profile = w->selectedProfile();
         m_activeDocument->setProjectFolder(w->selectedFolder());
         if (m_renderWidget) m_renderWidget->setDocumentPath(w->selectedFolder().path(KUrl::AddTrailingSlash));
@@ -1655,6 +1660,7 @@ void MainWindow::slotEditProjectSettings()
     delete w;
 }
 
+
 void MainWindow::slotRenderProject()
 {
     if (!m_renderWidget) {
index a8f76657421fdd781cef7ed2b89e7ebc7eda29f9..e534180c6172f1108d45b1e9e97dd8bbd40d5a77 100644 (file)
@@ -41,6 +41,8 @@
 #include <KFileDialog>
 #include <KInputDialog>
 #include <KMessageBox>
+#include <KIO/NetAccess>
+#include <KFileItem>
 
 #include <nepomuk/global.h>
 #include <nepomuk/resourcemanager.h>
@@ -225,6 +227,27 @@ void ProjectList::cleanup()
     slotRemoveClip();
 }
 
+void ProjectList::trashUnusedClips()
+{
+    QTreeWidgetItemIterator it(m_listView);
+    ProjectItem *item;
+    QStringList ids;
+    KUrl::List urls;
+    while (*it) {
+        item = static_cast <ProjectItem *>(*it);
+        if (item->numReferences() == 0) {
+            ids << item->clipId();
+            KUrl url = item->clipUrl();
+            if (!url.isEmpty()) urls << url;
+        }
+        it++;
+    }
+    m_doc->deleteProjectClip(ids);
+    for (int i = 0; i < urls.count(); i++) {
+        KIO::NetAccess::del(urls.at(i), this);
+    }
+}
+
 void ProjectList::slotReloadClip(const QString &id)
 {
     QList<QTreeWidgetItem *> selected;
index 319437a8cb44c8fa7334d9c1134db5f504f8350f..f7389a24eb424ff235e4fe9e061ba9f3aa4a4643 100644 (file)
@@ -134,6 +134,7 @@ public:
     void reloadClipThumbnails();
     QDomDocument generateTemplateXml(QString data, const QString &replaceString);
     void cleanup();
+    void trashUnusedClips();
 
 public slots:
     void setDocument(KdenliveDoc *doc);
index bfd839da1ff3fada1bb2e874f6332623d66a1c6e..bbbda12e3f41f3626fd9b89d6ae3548ceb9fff8c 100644 (file)
 #include "projectsettings.h"
 #include "kdenlivesettings.h"
 #include "profilesdialog.h"
+#include "docclipbase.h"
 
 #include <KStandardDirs>
 #include <KMessageBox>
 #include <KDebug>
+#include <kio/directorysizejob.h>
+#include <KIO/NetAccess>
 
 #include <QDir>
 #include <kmessagebox.h>
 
-ProjectSettings::ProjectSettings(int videotracks, int audiotracks, const QString projectPath, bool readOnlyTracks, bool savedProject, QWidget * parent) :
-        QDialog(parent), m_savedProject(savedProject)
+ProjectSettings::ProjectSettings(ClipManager *manager, int videotracks, int audiotracks, const QString projectPath, bool readOnlyTracks, bool savedProject, QWidget * parent) :
+        QDialog(parent), m_savedProject(savedProject), m_clipManager(manager), m_deleteUnused(false)
 {
     setupUi(this);
 
@@ -61,10 +64,82 @@ ProjectSettings::ProjectSettings(int videotracks, int audiotracks, const QString
         audio_tracks->setEnabled(false);
     }
     slotUpdateDisplay();
+    if (manager != NULL) {
+        slotUpdateFiles();
+        connect(clear_cache, SIGNAL(clicked()), this, SLOT(slotClearCache()));
+        connect(delete_unused, SIGNAL(clicked()), this, SLOT(slotDeleteUnused()));
+    }
+    else tabWidget->widget(1)->setEnabled(false);
     connect(profiles_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDisplay()));
     connect(project_folder, SIGNAL(textChanged(const QString &)), this, SLOT(slotUpdateButton(const QString &)));
 }
 
+void ProjectSettings::slotDeleteUnused()
+{
+    QStringList toDelete;
+    QList <DocClipBase*> list = m_clipManager->documentClipList();
+    for (int i = 0; i < list.count(); i++) {
+        DocClipBase *clip = list.at(i);
+        if (clip->numReferences() == 0) {
+            KUrl url = clip->fileURL();
+            if (!url.isEmpty()) toDelete << url.path();
+        }
+    }
+    if (toDelete.count() == 0) {
+        KMessageBox::sorry(this, i18n("No clip to delete"));
+        return;
+    }
+    if (KMessageBox::warningYesNoList(this, i18n("This will remove the following files from your hard drive.\nThis action cannot be undone, only use if you know what you are doing.\nAre you sure you want to continue?"), toDelete, i18n("Delete unused clips")) != KMessageBox::Yes) return;
+    m_deleteUnused = true;
+    delete_unused->setEnabled(false);
+}
+
+bool ProjectSettings::deleteUnused() const
+{
+    return m_deleteUnused;
+}
+
+void ProjectSettings::slotClearCache()
+{
+    buttonBox->setEnabled(false);
+    KIO::NetAccess::del(KUrl(project_folder->url().path(KUrl::AddTrailingSlash) + "thumbs/"), this);
+    KStandardDirs::makeDir(project_folder->url().path(KUrl::AddTrailingSlash) + "thumbs/");
+    buttonBox->setEnabled(true);
+    slotUpdateFiles(true);
+}
+
+void ProjectSettings::slotUpdateFiles(bool cacheOnly)
+{   
+    KIO::DirectorySizeJob * job = KIO::directorySize( project_folder->url().path(KUrl::AddTrailingSlash) + "thumbs/" );
+    job->exec();
+    thumbs_count->setText(QString::number(job->totalFiles()));
+    thumbs_size->setText(KIO::convertSize(job->totalSize()));
+    delete job;
+    if (cacheOnly) return;
+    int unused = 0;
+    int used = 0;
+    KIO::filesize_t usedSize = 0;
+    KIO::filesize_t unUsedSize = 0;
+    QList <DocClipBase*> list = m_clipManager->documentClipList();
+
+    for (int i = 0; i < list.count(); i++) {
+        DocClipBase *clip = list.at(i);
+        if (clip->numReferences() == 0) {
+            unused++;
+            unUsedSize += clip->fileSize();
+        }
+        else {
+            used++;
+            usedSize += clip->fileSize();
+        }
+    }
+    used_count->setText(QString::number(used));
+    used_size->setText(KIO::convertSize(usedSize));
+    unused_count->setText(QString::number(unused));
+    unused_size->setText(KIO::convertSize(unUsedSize));
+    if (!m_deleteUnused) delete_unused->setEnabled(unused > 0);
+}
+
 void ProjectSettings::accept()
 {
     if (!m_savedProject && selectedProfile() != KdenliveSettings::current_profile())
@@ -87,7 +162,10 @@ void ProjectSettings::slotUpdateDisplay()
 void ProjectSettings::slotUpdateButton(const QString &path)
 {
     if (path.isEmpty()) m_buttonOk->setEnabled(false);
-    else m_buttonOk->setEnabled(true);
+    else {
+        m_buttonOk->setEnabled(true);
+        slotUpdateFiles(true);
+    }
 }
 
 QString ProjectSettings::selectedProfile() const
index b86e2a737e3200ec360d8f0560c03288c0a623f4..5e9aba2655a5a9104c7af688f45d5a30224dfb72 100644 (file)
@@ -24,6 +24,7 @@
 #include <QDialog>
 #include <QPushButton>
 
+#include "clipmanager.h"
 #include "ui_projectsettings_ui.h"
 
 class ProjectSettings : public QDialog, public Ui::ProjectSettings_UI
@@ -31,12 +32,13 @@ class ProjectSettings : public QDialog, public Ui::ProjectSettings_UI
     Q_OBJECT
 
 public:
-    ProjectSettings(int videotracks, int audiotracks, const QString projectPath, bool readOnlyTracks, bool unsavedProject, QWidget * parent = 0);
+    ProjectSettings(ClipManager *manager, int videotracks, int audiotracks, const QString projectPath, bool readOnlyTracks, bool unsavedProject, QWidget * parent = 0);
     QString selectedProfile() const;
     KUrl selectedFolder() const;
     QPoint tracks();
     bool enableVideoThumbs() const;
     bool enableAudioThumbs() const;
+    bool deleteUnused() const;
 
 public slots:
     virtual void accept();
@@ -44,10 +46,15 @@ public slots:
 private slots:
     void slotUpdateDisplay();
     void slotUpdateButton(const QString &path);
+    void slotUpdateFiles(bool cacheOnly = false);
+    void slotClearCache();
+    void slotDeleteUnused();
 
 private:
     QPushButton *m_buttonOk;
     bool m_savedProject;
+    ClipManager *m_clipManager;
+    bool m_deleteUnused;
 };