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"
25 #include <KStandardDirs>
26 #include <KMessageBox>
28 #include <kio/directorysizejob.h>
29 #include <KIO/NetAccess>
32 #include <kmessagebox.h>
34 ProjectSettings::ProjectSettings(ClipManager *manager, int videotracks, int audiotracks, const QString projectPath, bool readOnlyTracks, bool savedProject, QWidget * parent) :
35 QDialog(parent), m_savedProject(savedProject), m_clipManager(manager), m_deleteUnused(false)
39 QMap <QString, QString> profilesInfo = ProfilesDialog::getProfilesInfo();
40 QMapIterator<QString, QString> i(profilesInfo);
43 profiles_list->addItem(i.key(), i.value());
45 project_folder->setMode(KFile::Directory);
46 project_folder->setUrl(KUrl(projectPath));
47 QString currentProf = KdenliveSettings::current_profile();
49 for (int i = 0; i < profiles_list->count(); i++) {
50 if (profiles_list->itemData(i).toString() == currentProf) {
51 profiles_list->setCurrentIndex(i);
56 m_buttonOk = buttonBox->button(QDialogButtonBox::Ok);
57 //buttonOk->setEnabled(false);
58 audio_thumbs->setChecked(KdenliveSettings::audiothumbnails());
59 video_thumbs->setChecked(KdenliveSettings::videothumbnails());
60 audio_tracks->setValue(audiotracks);
61 video_tracks->setValue(videotracks);
63 video_tracks->setEnabled(false);
64 audio_tracks->setEnabled(false);
67 if (manager != NULL) {
69 connect(clear_cache, SIGNAL(clicked()), this, SLOT(slotClearCache()));
70 connect(delete_unused, SIGNAL(clicked()), this, SLOT(slotDeleteUnused()));
71 } else tabWidget->widget(1)->setEnabled(false);
72 connect(profiles_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDisplay()));
73 connect(project_folder, SIGNAL(textChanged(const QString &)), this, SLOT(slotUpdateButton(const QString &)));
76 void ProjectSettings::slotDeleteUnused()
79 QList <DocClipBase*> list = m_clipManager->documentClipList();
80 for (int i = 0; i < list.count(); i++) {
81 DocClipBase *clip = list.at(i);
82 if (clip->numReferences() == 0) {
83 KUrl url = clip->fileURL();
84 if (!url.isEmpty()) toDelete << url.path();
88 // make sure our urls are not used in another clip
89 for (int i = 0; i < list.count(); i++) {
90 DocClipBase *clip = list.at(i);
91 if (clip->numReferences() > 0) {
92 KUrl url = clip->fileURL();
93 if (!url.isEmpty() && toDelete.contains(url.path())) toDelete.removeAll(url.path());
97 if (toDelete.count() == 0) {
98 KMessageBox::sorry(this, i18n("No clip to delete"));
101 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;
102 m_deleteUnused = true;
103 delete_unused->setEnabled(false);
106 bool ProjectSettings::deleteUnused() const
108 return m_deleteUnused;
111 void ProjectSettings::slotClearCache()
113 buttonBox->setEnabled(false);
114 KIO::NetAccess::del(KUrl(project_folder->url().path(KUrl::AddTrailingSlash) + "thumbs/"), this);
115 KStandardDirs::makeDir(project_folder->url().path(KUrl::AddTrailingSlash) + "thumbs/");
116 buttonBox->setEnabled(true);
117 slotUpdateFiles(true);
120 void ProjectSettings::slotUpdateFiles(bool cacheOnly)
122 KIO::DirectorySizeJob * job = KIO::directorySize(project_folder->url().path(KUrl::AddTrailingSlash) + "thumbs/");
124 thumbs_count->setText(QString::number(job->totalFiles()));
125 thumbs_size->setText(KIO::convertSize(job->totalSize()));
127 if (cacheOnly) return;
130 KIO::filesize_t usedSize = 0;
131 KIO::filesize_t unUsedSize = 0;
132 QList <DocClipBase*> list = m_clipManager->documentClipList();
134 for (int i = 0; i < list.count(); i++) {
135 DocClipBase *clip = list.at(i);
136 if (clip->numReferences() == 0) {
138 unUsedSize += clip->fileSize();
141 usedSize += clip->fileSize();
144 used_count->setText(QString::number(used));
145 used_size->setText(KIO::convertSize(usedSize));
146 unused_count->setText(QString::number(unused));
147 unused_size->setText(KIO::convertSize(unUsedSize));
148 if (!m_deleteUnused) delete_unused->setEnabled(unused > 0);
151 void ProjectSettings::accept()
153 if (!m_savedProject && selectedProfile() != KdenliveSettings::current_profile())
154 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;
158 void ProjectSettings::slotUpdateDisplay()
160 QString currentProfile = profiles_list->itemData(profiles_list->currentIndex()).toString();
161 QMap< QString, QString > values = ProfilesDialog::getSettingsFromFile(currentProfile);
162 p_size->setText(values.value("width") + 'x' + values.value("height"));
163 p_fps->setText(values.value("frame_rate_num") + '/' + values.value("frame_rate_den"));
164 p_aspect->setText(values.value("sample_aspect_num") + '/' + values.value("sample_aspect_den"));
165 p_display->setText(values.value("display_aspect_num") + '/' + values.value("display_aspect_den"));
166 if (values.value("progressive").toInt() == 0) p_progressive->setText(i18n("Interlaced"));
167 else p_progressive->setText(i18n("Progressive"));
170 void ProjectSettings::slotUpdateButton(const QString &path)
172 if (path.isEmpty()) m_buttonOk->setEnabled(false);
174 m_buttonOk->setEnabled(true);
175 slotUpdateFiles(true);
179 QString ProjectSettings::selectedProfile() const
181 return profiles_list->itemData(profiles_list->currentIndex()).toString();
184 KUrl ProjectSettings::selectedFolder() const
186 return project_folder->url();
189 QPoint ProjectSettings::tracks()
192 p.setX(video_tracks->value());
193 p.setY(audio_tracks->value());
197 bool ProjectSettings::enableVideoThumbs() const
199 return video_thumbs->isChecked();
202 bool ProjectSettings::enableAudioThumbs() const
204 return audio_thumbs->isChecked();
207 #include "projectsettings.moc"