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"
26 #include <KStandardDirs>
27 #include <KMessageBox>
29 #include <kio/directorysizejob.h>
30 #include <KIO/NetAccess>
33 #include <kmessagebox.h>
35 ProjectSettings::ProjectSettings(ProjectList *projectlist, int videotracks, int audiotracks, const QString projectPath, bool readOnlyTracks, bool savedProject, QWidget * parent) :
36 QDialog(parent), m_savedProject(savedProject), m_projectList(projectlist)
40 list_search->setListWidget(files_list);
42 QMap <QString, QString> profilesInfo = ProfilesDialog::getProfilesInfo();
43 QMapIterator<QString, QString> i(profilesInfo);
46 profiles_list->addItem(i.key(), i.value());
48 project_folder->setMode(KFile::Directory);
49 project_folder->setUrl(KUrl(projectPath));
50 QString currentProf = KdenliveSettings::current_profile();
52 for (int i = 0; i < profiles_list->count(); i++) {
53 if (profiles_list->itemData(i).toString() == currentProf) {
54 profiles_list->setCurrentIndex(i);
59 m_buttonOk = buttonBox->button(QDialogButtonBox::Ok);
60 //buttonOk->setEnabled(false);
61 audio_thumbs->setChecked(KdenliveSettings::audiothumbnails());
62 video_thumbs->setChecked(KdenliveSettings::videothumbnails());
63 audio_tracks->setValue(audiotracks);
64 video_tracks->setValue(videotracks);
66 video_tracks->setEnabled(false);
67 audio_tracks->setEnabled(false);
70 if (m_projectList != NULL) {
72 connect(clear_cache, SIGNAL(clicked()), this, SLOT(slotClearCache()));
73 connect(delete_unused, SIGNAL(clicked()), this, SLOT(slotDeleteUnused()));
74 } else tabWidget->widget(1)->setEnabled(false);
75 connect(profiles_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDisplay()));
76 connect(project_folder, SIGNAL(textChanged(const QString &)), this, SLOT(slotUpdateButton(const QString &)));
79 void ProjectSettings::slotDeleteUnused()
82 QList <DocClipBase*> list = m_projectList->documentClipList();
83 for (int i = 0; i < list.count(); i++) {
84 DocClipBase *clip = list.at(i);
85 if (clip->numReferences() == 0 && clip->clipType() != SLIDESHOW) {
86 KUrl url = clip->fileURL();
87 if (!url.isEmpty()) toDelete << url.path();
90 toDelete.removeDuplicates();
92 // make sure our urls are not used in another clip
93 for (int i = 0; i < list.count(); i++) {
94 DocClipBase *clip = list.at(i);
95 if (clip->numReferences() > 0) {
96 KUrl url = clip->fileURL();
97 if (!url.isEmpty() && toDelete.contains(url.path())) toDelete.removeAll(url.path());
101 if (toDelete.count() == 0) {
102 // No physical url to delete, we only remove unused clips from project (color clips for example have no physical url)
103 if (KMessageBox::warningContinueCancel(this, i18n("This will remove all unused clips from your project."), i18n("Clean up project")) == KMessageBox::Cancel) return;
104 m_projectList->cleanup();
108 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;
109 m_projectList->trashUnusedClips();
113 void ProjectSettings::slotClearCache()
115 buttonBox->setEnabled(false);
116 KIO::NetAccess::del(KUrl(project_folder->url().path(KUrl::AddTrailingSlash) + "thumbs/"), this);
117 KStandardDirs::makeDir(project_folder->url().path(KUrl::AddTrailingSlash) + "thumbs/");
118 buttonBox->setEnabled(true);
119 slotUpdateFiles(true);
122 void ProjectSettings::slotUpdateFiles(bool cacheOnly)
124 KIO::DirectorySizeJob * job = KIO::directorySize(project_folder->url().path(KUrl::AddTrailingSlash) + "thumbs/");
126 thumbs_count->setText(QString::number(job->totalFiles()));
127 thumbs_size->setText(KIO::convertSize(job->totalSize()));
129 if (cacheOnly) return;
132 KIO::filesize_t usedSize = 0;
133 KIO::filesize_t unUsedSize = 0;
134 QList <DocClipBase*> list = m_projectList->documentClipList();
137 // List all files that are used in the project. That also means:
138 // images included in slideshow, titles
139 // TODO: images used in luma transitions, files used in playlist clips, files used for LADSPA effects
141 QStringList allFiles;
142 for (int i = 0; i < list.count(); i++) {
143 DocClipBase *clip = list.at(i);
144 if (clip->clipType() == SLIDESHOW) {
145 // special case, list all images
146 QString path = clip->fileURL().directory();
147 QString ext = clip->fileURL().path().section('.', -1);
150 filters << "*." + ext;
151 dir.setNameFilters(filters);
152 QStringList result = dir.entryList(QDir::Files);
153 for (int j = 0; j < result.count(); j++) {
154 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"));
163 if (clip->numReferences() == 0) {
165 unUsedSize += clip->fileSize();
168 usedSize += clip->fileSize();
171 allFiles.removeDuplicates();
172 files_count->setText(QString::number(allFiles.count()));
173 files_list->addItems(allFiles);
174 used_count->setText(QString::number(used));
175 used_size->setText(KIO::convertSize(usedSize));
176 unused_count->setText(QString::number(unused));
177 unused_size->setText(KIO::convertSize(unUsedSize));
178 delete_unused->setEnabled(unused > 0);
181 void ProjectSettings::accept()
183 if (!m_savedProject && selectedProfile() != KdenliveSettings::current_profile())
184 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;
188 void ProjectSettings::slotUpdateDisplay()
190 QString currentProfile = profiles_list->itemData(profiles_list->currentIndex()).toString();
191 QMap< QString, QString > values = ProfilesDialog::getSettingsFromFile(currentProfile);
192 p_size->setText(values.value("width") + 'x' + values.value("height"));
193 p_fps->setText(values.value("frame_rate_num") + '/' + values.value("frame_rate_den"));
194 p_aspect->setText(values.value("sample_aspect_num") + '/' + values.value("sample_aspect_den"));
195 p_display->setText(values.value("display_aspect_num") + '/' + values.value("display_aspect_den"));
196 if (values.value("progressive").toInt() == 0) p_progressive->setText(i18n("Interlaced"));
197 else p_progressive->setText(i18n("Progressive"));
200 void ProjectSettings::slotUpdateButton(const QString &path)
202 if (path.isEmpty()) m_buttonOk->setEnabled(false);
204 m_buttonOk->setEnabled(true);
205 slotUpdateFiles(true);
209 QString ProjectSettings::selectedProfile() const
211 return profiles_list->itemData(profiles_list->currentIndex()).toString();
214 KUrl ProjectSettings::selectedFolder() const
216 return project_folder->url();
219 QPoint ProjectSettings::tracks()
222 p.setX(video_tracks->value());
223 p.setY(audio_tracks->value());
227 bool ProjectSettings::enableVideoThumbs() const
229 return video_thumbs->isChecked();
232 bool ProjectSettings::enableAudioThumbs() const
234 return audio_thumbs->isChecked();
237 #include "projectsettings.moc"