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 "slideshowclip.h"
21 #include "kdenlivesettings.h"
23 #include <KStandardDirs>
28 #include <QtConcurrentRun>
29 #include <QFutureWatcher>
32 SlideshowClip::SlideshowClip(Timecode tc, QWidget * parent) :
37 setFont(KGlobalSettings::toolBarFont());
38 setWindowTitle(i18n("Add Slideshow Clip"));
40 m_view.clip_name->setText(i18n("Slideshow Clip"));
41 m_view.folder_url->setMode(KFile::Directory);
42 m_view.icon_list->setIconSize(QSize(50, 50));
43 m_view.show_thumbs->setChecked(KdenliveSettings::showslideshowthumbs());
45 connect(m_view.folder_url, SIGNAL(textChanged(const QString &)), this, SLOT(parseFolder()));
46 connect(m_view.image_type, SIGNAL(currentIndexChanged(int)), this, SLOT(parseFolder()));
48 connect(m_view.show_thumbs, SIGNAL(stateChanged(int)), this, SLOT(slotEnableThumbs(int)));
49 connect(m_view.slide_fade, SIGNAL(stateChanged(int)), this, SLOT(slotEnableLuma(int)));
50 connect(m_view.luma_fade, SIGNAL(stateChanged(int)), this, SLOT(slotEnableLumaFile(int)));
52 //WARNING: keep in sync with clipproperties.cpp
53 m_view.image_type->addItem("JPG (*.jpg)", "jpg");
54 m_view.image_type->addItem("JPEG (*.jpeg)", "jpeg");
55 m_view.image_type->addItem("PNG (*.png)", "png");
56 m_view.image_type->addItem("BMP (*.bmp)", "bmp");
57 m_view.image_type->addItem("GIF (*.gif)", "gif");
58 m_view.image_type->addItem("TGA (*.tga)", "tga");
59 m_view.image_type->addItem("TIFF (*.tiff)", "tiff");
60 m_view.image_type->addItem("Open EXR (*.exr)", "exr");
62 m_view.clip_duration->setInputMask(m_timecode.inputMask());
63 m_view.clip_duration->setText(m_timecode.reformatSeparators(KdenliveSettings::image_duration()));
64 m_view.luma_duration->setInputMask(m_timecode.inputMask());
65 m_view.luma_duration->setText(m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))));
66 m_view.folder_url->setUrl(QDir::homePath());
68 m_view.clip_duration_format->addItem(i18n("hh:mm:ss::ff"));
69 m_view.clip_duration_format->addItem(i18n("Frames"));
70 connect(m_view.clip_duration_format, SIGNAL(activated(int)), this, SLOT(slotUpdateDurationFormat(int)));
71 m_view.clip_duration_frames->setHidden(true);
72 m_view.luma_duration_frames->setHidden(true);
74 // Check for Kdenlive installed luma files
76 filters << "*.pgm" << "*.png";
78 QStringList customLumas = KGlobal::dirs()->findDirs("appdata", "lumas");
79 foreach(const QString &folder, customLumas) {
80 QStringList filesnames = QDir(folder).entryList(filters, QDir::Files);
81 foreach(const QString &fname, filesnames) {
82 QString filePath = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
83 m_view.luma_file->addItem(KIcon(filePath), fname, filePath);
87 // Check for MLT lumas
88 QString profilePath = KdenliveSettings::mltpath();
89 QString folder = profilePath.section('/', 0, -3);
90 folder.append("/lumas/PAL"); // TODO: cleanup the PAL / NTSC mess in luma files
91 QDir lumafolder(folder);
92 QStringList filesnames = lumafolder.entryList(filters, QDir::Files);
93 foreach(const QString &fname, filesnames) {
94 QString filePath = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
95 m_view.luma_file->addItem(KIcon(filePath), fname, filePath);
101 void SlideshowClip::slotEnableLuma(int state)
104 if (state == Qt::Checked) enable = true;
105 m_view.luma_duration->setEnabled(enable);
106 m_view.luma_duration_frames->setEnabled(enable);
107 m_view.luma_fade->setEnabled(enable);
109 m_view.luma_file->setEnabled(m_view.luma_fade->isChecked());
110 } else m_view.luma_file->setEnabled(false);
111 m_view.label_softness->setEnabled(m_view.luma_fade->isChecked() && enable);
112 m_view.luma_softness->setEnabled(m_view.label_softness->isEnabled());
115 void SlideshowClip::slotEnableThumbs(int state)
117 if (state == Qt::Checked) {
118 KdenliveSettings::setShowslideshowthumbs(true);
119 slotGenerateThumbs();
121 KdenliveSettings::setShowslideshowthumbs(false);
126 void SlideshowClip::slotEnableLumaFile(int state)
129 if (state == Qt::Checked) enable = true;
130 m_view.luma_file->setEnabled(enable);
131 m_view.luma_softness->setEnabled(enable);
132 m_view.label_softness->setEnabled(enable);
135 void SlideshowClip::parseFolder()
137 m_view.icon_list->clear();
138 QDir dir(m_view.folder_url->url().path());
141 QString filter = m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
142 filters << "*." + filter;
143 // TODO: improve jpeg image detection with extension like jpeg, requires change in MLT image producers
146 dir.setNameFilters(filters);
147 const QStringList result = dir.entryList(QDir::Files);
148 m_count = result.count();
149 if (m_count == 0) m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
150 else m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
151 m_view.label_info->setText(i18np("1 image found", "%1 images found", m_count));
152 QListWidgetItem *item;
154 KIcon unknownicon("unknown");
155 foreach(const QString &path, result) {
157 item = new QListWidgetItem(unknownicon, KUrl(path).fileName());
158 item->setData(Qt::UserRole, dir.filePath(path));
159 m_view.icon_list->addItem(item);
161 if (m_view.show_thumbs->isChecked()) slotGenerateThumbs();
162 m_view.icon_list->setCurrentRow(0);
165 void SlideshowClip::slotGenerateThumbs()
167 if (!m_future.isRunning()) {
168 connect(&m_watcher, SIGNAL(finished()), this, SLOT(slotCheckGenerateThumbs()));
169 m_future = QtConcurrent::run(this, &SlideshowClip::doGetThumbs);
170 m_watcher.setFuture(m_future);
174 void SlideshowClip::slotCheckGenerateThumbs()
176 QListWidgetItem* item = m_view.icon_list->item(m_view.icon_list->count() - 1);
177 if (!item || item->data(Qt::UserRole).toString().isEmpty() || m_view.show_thumbs->isChecked() == false) return;
178 QTimer::singleShot(300, this, SLOT(slotGenerateThumbs()));
181 void SlideshowClip::doGetThumbs()
183 for (int i = 0; i < m_view.icon_list->count(); i++) {
184 QListWidgetItem* item = m_view.icon_list->item(i);
185 if (item && m_view.show_thumbs->isChecked()) {
186 QString path = item->data(Qt::UserRole).toString();
187 if (path.isEmpty()) continue;
189 item->setIcon(KIcon(path));
190 item->setData(Qt::UserRole, QString());
197 QString SlideshowClip::selectedPath() const
199 QString extension = "/.all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
200 return m_view.folder_url->url().path() + extension;
204 QString SlideshowClip::clipName() const
206 return m_view.clip_name->text();
209 QString SlideshowClip::clipDuration() const
211 if (m_view.clip_duration_format->currentIndex() == 1) {
212 // we are in frames mode
213 return m_timecode.getTimecodeFromFrames(m_view.clip_duration_frames->value());
215 return m_view.clip_duration->text();
218 int SlideshowClip::imageCount() const
223 int SlideshowClip::softness() const
225 return m_view.luma_softness->value();
228 bool SlideshowClip::loop() const
230 return m_view.slide_loop->isChecked();
233 bool SlideshowClip::fade() const
235 return m_view.slide_fade->isChecked();
238 QString SlideshowClip::lumaDuration() const
240 if (m_view.clip_duration_format->currentIndex() == 1) {
241 // we are in frames mode
242 return m_timecode.getTimecodeFromFrames(m_view.luma_duration_frames->value());
244 return m_view.luma_duration->text();
247 QString SlideshowClip::lumaFile() const
249 if (!m_view.luma_fade->isChecked() || !m_view.luma_file->isEnabled()) return QString();
250 return m_view.luma_file->itemData(m_view.luma_file->currentIndex()).toString();
253 void SlideshowClip::slotUpdateDurationFormat(int ix)
255 bool framesFormat = ix == 1;
257 // switching to frames count, update widget
258 m_view.clip_duration_frames->setValue(m_timecode.getFrameCount(m_view.clip_duration->text()));
259 m_view.luma_duration_frames->setValue(m_timecode.getFrameCount(m_view.luma_duration->text()));
261 // switching to timecode format
262 m_view.clip_duration->setInputMask(m_timecode.inputMask());
263 m_view.clip_duration->setText(m_timecode.getTimecodeFromFrames(m_view.clip_duration_frames->value()));
264 m_view.luma_duration->setInputMask(m_timecode.inputMask());
265 m_view.luma_duration->setText(m_timecode.getTimecodeFromFrames(m_view.luma_duration_frames->value()));
267 m_view.clip_duration_frames->setHidden(!framesFormat);
268 m_view.clip_duration->setHidden(framesFormat);
269 m_view.luma_duration_frames->setHidden(!framesFormat);
270 m_view.luma_duration->setHidden(framesFormat);
273 #include "slideshowclip.moc"