]> git.sesse.net Git - kdenlive/commitdiff
Cleanup physical clip deletion:
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 18 Oct 2009 10:44:54 +0000 (10:44 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 18 Oct 2009 10:44:54 +0000 (10:44 +0000)
http://kdenlive.org/mantis/view.php?id=1215

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

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

index 207492aca8a70c46b27b58e118486999247e7b4c..71b4b76bde44c22cc2d95166487b4dab95d4297b 100644 (file)
@@ -1680,13 +1680,9 @@ void MainWindow::slotDetectAudioDriver()
 void MainWindow::slotEditProjectSettings()
 {
     QPoint p = m_activeDocument->getTracksCount();
-    ProjectSettings *w = new ProjectSettings(m_activeDocument->clipManager(), p.x(), p.y(), m_activeDocument->projectFolder().path(), true, !m_activeDocument->isModified(), this);
+    ProjectSettings *w = new ProjectSettings(m_projectList, 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));
index 638c34c260fd4d0f989bd6bd3e6774d6fbb17b8b..9f02425b13bbaf829d0ed411ca346ec86b346860 100644 (file)
@@ -66,6 +66,7 @@ ProjectList::ProjectList(QWidget *parent) :
         m_openAction(NULL),
         m_reloadAction(NULL),
         m_transcodeAction(NULL),
+        m_doc(NULL),
         m_selectedItem(NULL),
         m_refreshed(false),
         m_infoQueue(),
@@ -232,30 +233,31 @@ void ProjectList::trashUnusedClips()
     QTreeWidgetItemIterator it(m_listView);
     ProjectItem *item;
     QStringList ids;
-    KUrl::List urls;
+    QStringList urls;
     while (*it) {
         item = static_cast <ProjectItem *>(*it);
         if (!item->isGroup() && item->numReferences() == 0) {
             ids << item->clipId();
             KUrl url = item->clipUrl();
-            if (!url.isEmpty()) urls << url;
+            if (!url.isEmpty()) urls << url.path();
         }
         it++;
     }
+    urls.removeDuplicates();
     // Check that we don't use the URL in another clip
     QTreeWidgetItemIterator it2(m_listView);
     while (*it2) {
         item = static_cast <ProjectItem *>(*it2);
         if (item->numReferences() > 0) {
             KUrl url = item->clipUrl();
-            if (!url.isEmpty() && urls.contains(url)) urls.removeAll(url);
+            if (!url.isEmpty() && urls.contains(url.path())) urls.removeAll(url.path());
         }
         it2++;
     }
 
     m_doc->deleteProjectClip(ids);
     for (int i = 0; i < urls.count(); i++) {
-        KIO::NetAccess::del(urls.at(i), this);
+        KIO::NetAccess::del(KUrl(urls.at(i)), this);
     }
 }
 
@@ -843,6 +845,12 @@ void ProjectList::setDocument(KdenliveDoc *doc)
     connect(m_doc->clipManager(), SIGNAL(checkAllClips()), this, SLOT(updateAllClips()));
 }
 
+QList <DocClipBase*> ProjectList::documentClipList() const
+{
+    if (m_doc == NULL) return QList <DocClipBase*> ();
+    return m_doc->clipManager()->documentClipList();
+}
+
 QDomElement ProjectList::producersList()
 {
     QDomDocument doc;
index 53d62900c421bef06be5d7a4989c0fc6cf35bb1a..852904098bd2948ef722c259f8291250314cf129 100644 (file)
@@ -96,7 +96,7 @@ public:
             QString subText = index.data(DurationRole).toString();
             int usage = index.data(UsageRole).toInt();
             if (usage != 0) subText.append(QString(" (%1)").arg(usage));
-            painter->setPen(option.palette.color(QPalette::Mid));
+            if (option.state & (QStyle::State_Selected)) painter->setPen(option.palette.color(QPalette::Mid));
             painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , subText);
             painter->restore();
         } else if (index.column() == 3 && KdenliveSettings::activate_nepomuk()) {
@@ -135,6 +135,7 @@ public:
     QDomDocument generateTemplateXml(QString data, const QString &replaceString);
     void cleanup();
     void trashUnusedClips();
+    QList <DocClipBase*> documentClipList() const;
 
 public slots:
     void setDocument(KdenliveDoc *doc);
index 51d1bcd1f6c110a55b88611b685606952e0bdd12..acc4ed651979b82d76a25f757f1de5df5af0f4f8 100644 (file)
@@ -31,8 +31,8 @@
 #include <QDir>
 #include <kmessagebox.h>
 
-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)
+ProjectSettings::ProjectSettings(ProjectList *projectlist, int videotracks, int audiotracks, const QString projectPath, bool readOnlyTracks, bool savedProject, QWidget * parent) :
+        QDialog(parent), m_savedProject(savedProject), m_projectList(projectlist)
 {
     setupUi(this);
 
@@ -64,7 +64,7 @@ ProjectSettings::ProjectSettings(ClipManager *manager, int videotracks, int audi
         audio_tracks->setEnabled(false);
     }
     slotUpdateDisplay();
-    if (manager != NULL) {
+    if (m_projectList != NULL) {
         slotUpdateFiles();
         connect(clear_cache, SIGNAL(clicked()), this, SLOT(slotClearCache()));
         connect(delete_unused, SIGNAL(clicked()), this, SLOT(slotDeleteUnused()));
@@ -76,7 +76,7 @@ ProjectSettings::ProjectSettings(ClipManager *manager, int videotracks, int audi
 void ProjectSettings::slotDeleteUnused()
 {
     QStringList toDelete;
-    QList <DocClipBase*> list = m_clipManager->documentClipList();
+    QList <DocClipBase*> list = m_projectList->documentClipList();
     for (int i = 0; i < list.count(); i++) {
         DocClipBase *clip = list.at(i);
         if (clip->numReferences() == 0) {
@@ -84,6 +84,7 @@ void ProjectSettings::slotDeleteUnused()
             if (!url.isEmpty()) toDelete << url.path();
         }
     }
+    toDelete.removeDuplicates();
 
     // make sure our urls are not used in another clip
     for (int i = 0; i < list.count(); i++) {
@@ -95,17 +96,15 @@ void ProjectSettings::slotDeleteUnused()
     }
 
     if (toDelete.count() == 0) {
-        KMessageBox::sorry(this, i18n("No clip to delete"));
+        // No physical url to delete, we only remove unused clips from project (color clips for example have no physical url)
+        if (KMessageBox::warningContinueCancel(this, i18n("This will remove all unused clips from your project."), i18n("Clean up project")) == KMessageBox::Cancel) return;
+        m_projectList->cleanup();
+        slotUpdateFiles();
         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;
+    m_projectList->trashUnusedClips();
+    slotUpdateFiles();
 }
 
 void ProjectSettings::slotClearCache()
@@ -129,7 +128,7 @@ void ProjectSettings::slotUpdateFiles(bool cacheOnly)
     int used = 0;
     KIO::filesize_t usedSize = 0;
     KIO::filesize_t unUsedSize = 0;
-    QList <DocClipBase*> list = m_clipManager->documentClipList();
+    QList <DocClipBase*> list = m_projectList->documentClipList();
 
     for (int i = 0; i < list.count(); i++) {
         DocClipBase *clip = list.at(i);
@@ -145,7 +144,7 @@ void ProjectSettings::slotUpdateFiles(bool cacheOnly)
     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);
+    delete_unused->setEnabled(unused > 0);
 }
 
 void ProjectSettings::accept()
index 5e9aba2655a5a9104c7af688f45d5a30224dfb72..5b0344f44ea89874b1fa87fde98c2158fe5a2698 100644 (file)
@@ -24,7 +24,7 @@
 #include <QDialog>
 #include <QPushButton>
 
-#include "clipmanager.h"
+#include "projectlist.h"
 #include "ui_projectsettings_ui.h"
 
 class ProjectSettings : public QDialog, public Ui::ProjectSettings_UI
@@ -32,13 +32,12 @@ class ProjectSettings : public QDialog, public Ui::ProjectSettings_UI
     Q_OBJECT
 
 public:
-    ProjectSettings(ClipManager *manager, int videotracks, int audiotracks, const QString projectPath, bool readOnlyTracks, bool unsavedProject, QWidget * parent = 0);
+    ProjectSettings(ProjectList *projectlist, 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();
@@ -53,8 +52,7 @@ private slots:
 private:
     QPushButton *m_buttonOk;
     bool m_savedProject;
-    ClipManager *m_clipManager;
-    bool m_deleteUnused;
+    ProjectList *m_projectList;
 };