1 /***************************************************************************
2 * Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include "projectsettings.h"
21 #include "kdenlivesettings.h"
22 #include "profilesdialog.h"
23 #include "docclipbase.h"
24 #include "titlewidget.h"
25 #include "effectslist.h"
27 #include <KStandardDirs>
28 #include <KMessageBox>
30 #include <kio/directorysizejob.h>
31 #include <KIO/NetAccess>
34 #include <kmessagebox.h>
36 ProjectSettings::ProjectSettings(ProjectList *projectlist, int videotracks, int audiotracks, const QString projectPath, bool readOnlyTracks, bool savedProject, QWidget * parent) :
37 QDialog(parent), m_savedProject(savedProject), m_projectList(projectlist)
41 list_search->setListWidget(files_list);
43 QMap <QString, QString> profilesInfo = ProfilesDialog::getProfilesInfo();
44 QMapIterator<QString, QString> i(profilesInfo);
47 profiles_list->addItem(i.key(), i.value());
49 project_folder->setMode(KFile::Directory);
50 project_folder->setUrl(KUrl(projectPath));
51 QString currentProf = KdenliveSettings::current_profile();
53 for (int i = 0; i < profiles_list->count(); i++) {
54 if (profiles_list->itemData(i).toString() == currentProf) {
55 profiles_list->setCurrentIndex(i);
60 m_buttonOk = buttonBox->button(QDialogButtonBox::Ok);
61 //buttonOk->setEnabled(false);
62 audio_thumbs->setChecked(KdenliveSettings::audiothumbnails());
63 video_thumbs->setChecked(KdenliveSettings::videothumbnails());
64 audio_tracks->setValue(audiotracks);
65 video_tracks->setValue(videotracks);
67 video_tracks->setEnabled(false);
68 audio_tracks->setEnabled(false);
71 if (m_projectList != NULL) {
73 connect(clear_cache, SIGNAL(clicked()), this, SLOT(slotClearCache()));
74 connect(delete_unused, SIGNAL(clicked()), this, SLOT(slotDeleteUnused()));
75 } else tabWidget->widget(1)->setEnabled(false);
76 connect(profiles_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDisplay()));
77 connect(project_folder, SIGNAL(textChanged(const QString &)), this, SLOT(slotUpdateButton(const QString &)));
80 void ProjectSettings::slotDeleteUnused()
83 QList <DocClipBase*> list = m_projectList->documentClipList();
84 for (int i = 0; i < list.count(); i++) {
85 DocClipBase *clip = list.at(i);
86 if (clip->numReferences() == 0 && clip->clipType() != SLIDESHOW) {
87 KUrl url = clip->fileURL();
88 if (!url.isEmpty()) toDelete << url.path();
91 toDelete.removeDuplicates();
93 // make sure our urls are not used in another clip
94 for (int i = 0; i < list.count(); i++) {
95 DocClipBase *clip = list.at(i);
96 if (clip->numReferences() > 0) {
97 KUrl url = clip->fileURL();
98 if (!url.isEmpty() && toDelete.contains(url.path())) toDelete.removeAll(url.path());
102 if (toDelete.count() == 0) {
103 // No physical url to delete, we only remove unused clips from project (color clips for example have no physical url)
104 if (KMessageBox::warningContinueCancel(this, i18n("This will remove all unused clips from your project."), i18n("Clean up project")) == KMessageBox::Cancel) return;
105 m_projectList->cleanup();
109 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;
110 m_projectList->trashUnusedClips();
114 void ProjectSettings::slotClearCache()
116 buttonBox->setEnabled(false);
117 KIO::NetAccess::del(KUrl(project_folder->url().path(KUrl::AddTrailingSlash) + "thumbs/"), this);
118 KStandardDirs::makeDir(project_folder->url().path(KUrl::AddTrailingSlash) + "thumbs/");
119 buttonBox->setEnabled(true);
120 slotUpdateFiles(true);
123 void ProjectSettings::slotUpdateFiles(bool cacheOnly)
125 KIO::DirectorySizeJob * job = KIO::directorySize(project_folder->url().path(KUrl::AddTrailingSlash) + "thumbs/");
127 thumbs_count->setText(QString::number(job->totalFiles()));
128 thumbs_size->setText(KIO::convertSize(job->totalSize()));
130 if (cacheOnly) return;
133 KIO::filesize_t usedSize = 0;
134 KIO::filesize_t unUsedSize = 0;
135 QList <DocClipBase*> list = m_projectList->documentClipList();
138 // List all files that are used in the project. That also means:
139 // images included in slideshow and titles, files in playlist clips
140 // TODO: images used in luma transitions, files used for LADSPA effects?
142 QStringList allFiles;
143 for (int i = 0; i < list.count(); i++) {
144 DocClipBase *clip = list.at(i);
145 if (clip->clipType() == SLIDESHOW) {
146 // special case, list all images
147 QString path = clip->fileURL().directory();
148 QString ext = clip->fileURL().path().section('.', -1);
151 filters << "*." + ext;
152 dir.setNameFilters(filters);
153 QStringList result = dir.entryList(QDir::Files);
154 for (int j = 0; j < result.count(); j++) {
155 allFiles.append(path + result.at(j));
157 } else if (!clip->fileURL().isEmpty()) allFiles.append(clip->fileURL().path());
158 if (clip->clipType() == TEXT) {
159 QStringList images = TitleWidget::extractImageList(clip->getProperty("xmldata"));
161 } else if (clip->clipType() == PLAYLIST) {
162 QStringList files = extractPlaylistUrls(clip->fileURL().path());
166 if (clip->numReferences() == 0) {
168 unUsedSize += clip->fileSize();
171 usedSize += clip->fileSize();
174 allFiles.removeDuplicates();
175 files_count->setText(QString::number(allFiles.count()));
176 files_list->addItems(allFiles);
177 used_count->setText(QString::number(used));
178 used_size->setText(KIO::convertSize(usedSize));
179 unused_count->setText(QString::number(unused));
180 unused_size->setText(KIO::convertSize(unUsedSize));
181 delete_unused->setEnabled(unused > 0);
184 void ProjectSettings::accept()
186 if (!m_savedProject && selectedProfile() != KdenliveSettings::current_profile())
187 if (KMessageBox::warningContinueCancel(this, i18n("Changing the profile of your project cannot be undone.\nIt is recommended to save your project before attempting this operation that might cause some corruption in transitions.\n Are you sure you want to proceed?"), i18n("Confirm profile change")) == KMessageBox::Cancel) return;
191 void ProjectSettings::slotUpdateDisplay()
193 QString currentProfile = profiles_list->itemData(profiles_list->currentIndex()).toString();
194 QMap< QString, QString > values = ProfilesDialog::getSettingsFromFile(currentProfile);
195 p_size->setText(values.value("width") + 'x' + values.value("height"));
196 p_fps->setText(values.value("frame_rate_num") + '/' + values.value("frame_rate_den"));
197 p_aspect->setText(values.value("sample_aspect_num") + '/' + values.value("sample_aspect_den"));
198 p_display->setText(values.value("display_aspect_num") + '/' + values.value("display_aspect_den"));
199 if (values.value("progressive").toInt() == 0) p_progressive->setText(i18n("Interlaced"));
200 else p_progressive->setText(i18n("Progressive"));
203 void ProjectSettings::slotUpdateButton(const QString &path)
205 if (path.isEmpty()) m_buttonOk->setEnabled(false);
207 m_buttonOk->setEnabled(true);
208 slotUpdateFiles(true);
212 QString ProjectSettings::selectedProfile() const
214 return profiles_list->itemData(profiles_list->currentIndex()).toString();
217 KUrl ProjectSettings::selectedFolder() const
219 return project_folder->url();
222 QPoint ProjectSettings::tracks()
225 p.setX(video_tracks->value());
226 p.setY(audio_tracks->value());
230 bool ProjectSettings::enableVideoThumbs() const
232 return video_thumbs->isChecked();
235 bool ProjectSettings::enableAudioThumbs() const
237 return audio_thumbs->isChecked();
241 QStringList ProjectSettings::extractPlaylistUrls(QString path)
246 if (!file.open(QIODevice::ReadOnly))
248 if (!doc.setContent(&file)) {
253 QString root = doc.documentElement().attribute("root");
254 QDomNodeList files = doc.elementsByTagName("producer");
255 for (int i = 0; i < files.count(); i++) {
256 QDomElement e = files.at(i).toElement();
257 QString type = EffectsList::property(e, "mlt_service");
258 if (type != "colour") {
259 //TODO: slideshows (.all.*)
260 QString url = EffectsList::property(e, "resource");
261 if (!url.isEmpty()) {
262 if (!url.startsWith('/')) url.prepend(root);
264 if (url.endsWith(".mlt") || url.endsWith(".kdenlive")) {
265 //TODO: Do something to avoid infinite loops if 2 files reference themselves...
266 urls << extractPlaylistUrls(url);
274 #include "projectsettings.moc"