From: Jean-Baptiste Mardelle Date: Wed, 16 Sep 2009 16:12:48 +0000 (+0000) Subject: New file management tab in project settings dialog, fixes: X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=60f013649272d3c1342caa19ca6ecddb0652dc1c;p=kdenlive New file management tab in project settings dialog, fixes: http://www.kdenlive.org/mantis/view.php?id=1140 svn path=/trunk/kdenlive/; revision=3900 --- diff --git a/src/docclipbase.cpp b/src/docclipbase.cpp index b1d5d1c9..66e5c779 100644 --- a/src/docclipbase.cpp +++ b/src/docclipbase.cpp @@ -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 diff --git a/src/docclipbase.h b/src/docclipbase.h index 3714f1aa..907af533 100644 --- a/src/docclipbase.h +++ b/src/docclipbase.h @@ -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. */ diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index a6019f7f..e64bc634 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -52,6 +52,7 @@ #include "kdenlive-config.h" #include "cliptranscode.h" #include "ui_templateclip_ui.h" +#include "ui_projectfiles_ui.h" #include #include @@ -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) { diff --git a/src/projectlist.cpp b/src/projectlist.cpp index a8f76657..e534180c 100644 --- a/src/projectlist.cpp +++ b/src/projectlist.cpp @@ -41,6 +41,8 @@ #include #include #include +#include +#include #include #include @@ -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 (*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 selected; diff --git a/src/projectlist.h b/src/projectlist.h index 319437a8..f7389a24 100644 --- a/src/projectlist.h +++ b/src/projectlist.h @@ -134,6 +134,7 @@ public: void reloadClipThumbnails(); QDomDocument generateTemplateXml(QString data, const QString &replaceString); void cleanup(); + void trashUnusedClips(); public slots: void setDocument(KdenliveDoc *doc); diff --git a/src/projectsettings.cpp b/src/projectsettings.cpp index bfd839da..bbbda12e 100644 --- a/src/projectsettings.cpp +++ b/src/projectsettings.cpp @@ -20,16 +20,19 @@ #include "projectsettings.h" #include "kdenlivesettings.h" #include "profilesdialog.h" +#include "docclipbase.h" #include #include #include +#include +#include #include #include -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 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 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 diff --git a/src/projectsettings.h b/src/projectsettings.h index b86e2a73..5e9aba26 100644 --- a/src/projectsettings.h +++ b/src/projectsettings.h @@ -24,6 +24,7 @@ #include #include +#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; };