]> git.sesse.net Git - kdenlive/blob - src/clipproperties.cpp
Fix image sequence clips
[kdenlive] / src / clipproperties.cpp
1 /***************************************************************************
2  *   Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
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.                                   *
8  *                                                                         *
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.                          *
13  *                                                                         *
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  ***************************************************************************/
19
20
21 #include "clipproperties.h"
22 #include "kdenlivesettings.h"
23 #include "kthumb.h"
24 #include "markerdialog.h"
25
26 #include <KStandardDirs>
27 #include <KDebug>
28 #include <KFileItem>
29
30 #include <QDir>
31
32 static const int VIDEOTAB = 0;
33 static const int AUDIOTAB = 1;
34 static const int COLORTAB = 2;
35 static const int SLIDETAB = 3;
36 static const int IMAGETAB = 4;
37 static const int MARKERTAB = 5;
38 static const int METATAB = 6;
39 static const int ADVANCEDTAB = 7;
40
41 ClipProperties::ClipProperties(DocClipBase *clip, Timecode tc, double fps, QWidget * parent) :
42         QDialog(parent),
43         m_clip(clip),
44         m_tc(tc),
45         m_fps(fps),
46         m_count(0),
47         m_clipNeedsRefresh(false),
48         m_clipNeedsReLoad(false)
49 {
50     setFont(KGlobalSettings::toolBarFont());
51     m_view.setupUi(this);
52     KUrl url = m_clip->fileURL();
53     m_view.clip_path->setText(url.path());
54     m_view.clip_description->setText(m_clip->description());
55     QMap <QString, QString> props = m_clip->properties();
56
57     m_view.clip_force_out->setHidden(true);
58     m_view.clip_out->setHidden(true);
59
60     if (props.contains("force_aspect_ratio") && props.value("force_aspect_ratio").toDouble() > 0) {
61         m_view.clip_force_ar->setChecked(true);
62         m_view.clip_ar->setEnabled(true);
63         m_view.clip_ar->setValue(props.value("force_aspect_ratio").toDouble());
64     }
65
66     if (props.contains("force_fps") && props.value("force_fps").toDouble() > 0) {
67         m_view.clip_force_framerate->setChecked(true);
68         m_view.clip_framerate->setEnabled(true);
69         m_view.clip_framerate->setValue(props.value("force_fps").toDouble());
70     }
71
72     if (props.contains("force_progressive")) {
73         m_view.clip_force_progressive->setChecked(true);
74         m_view.clip_progressive->setEnabled(true);
75         m_view.clip_progressive->setValue(props.value("force_progressive").toInt());
76     }
77
78     if (props.contains("threads") && props.value("threads").toInt() != 1) {
79         m_view.clip_force_threads->setChecked(true);
80         m_view.clip_threads->setEnabled(true);
81         m_view.clip_threads->setValue(props.value("threads").toInt());
82     }
83
84     if (props.contains("video_index") && props.value("video_index").toInt() != 0) {
85         m_view.clip_force_vindex->setChecked(true);
86         m_view.clip_vindex->setEnabled(true);
87         m_view.clip_vindex->setValue(props.value("video_index").toInt());
88     }
89
90     if (props.contains("audio_index") && props.value("audio_index").toInt() != 0) {
91         m_view.clip_force_aindex->setChecked(true);
92         m_view.clip_aindex->setEnabled(true);
93         m_view.clip_aindex->setValue(props.value("audio_index").toInt());
94     }
95
96     if (props.contains("audio_max")) {
97         m_view.clip_aindex->setMaximum(props.value("audio_max").toInt());
98     }
99
100     if (props.contains("video_max")) {
101         m_view.clip_vindex->setMaximum(props.value("video_max").toInt());
102     }
103
104     // Check for Metadata
105     QMap<QString, QString> meta = m_clip->metadata();
106     QMap<QString, QString>::const_iterator i = meta.constBegin();
107     while (i != meta.constEnd()) {
108         QTreeWidgetItem *metaitem = new QTreeWidgetItem(m_view.metadata_list);
109         metaitem->setText(0, i.key()); //i18n(i.key().section('.', 2, 3).toUtf8().data()));
110         metaitem->setText(1, i.value());
111         ++i;
112     }
113
114     connect(m_view.clip_force_ar, SIGNAL(toggled(bool)), m_view.clip_ar, SLOT(setEnabled(bool)));
115     connect(m_view.clip_force_framerate, SIGNAL(toggled(bool)), m_view.clip_framerate, SLOT(setEnabled(bool)));
116     connect(m_view.clip_force_progressive, SIGNAL(toggled(bool)), m_view.clip_progressive, SLOT(setEnabled(bool)));
117     connect(m_view.clip_force_threads, SIGNAL(toggled(bool)), m_view.clip_threads, SLOT(setEnabled(bool)));
118     connect(m_view.clip_force_vindex, SIGNAL(toggled(bool)), m_view.clip_vindex, SLOT(setEnabled(bool)));
119     connect(m_view.clip_force_aindex, SIGNAL(toggled(bool)), m_view.clip_aindex, SLOT(setEnabled(bool)));
120
121     if (props.contains("audiocodec"))
122         m_view.clip_acodec->setText(props.value("audiocodec"));
123     if (props.contains("frequency"))
124         m_view.clip_frequency->setText(props.value("frequency"));
125     if (props.contains("channels"))
126         m_view.clip_channels->setText(props.value("channels"));
127
128     CLIPTYPE t = m_clip->clipType();
129     if (t != AUDIO && t != AV) {
130         m_view.clip_force_aindex->setEnabled(false);
131     }
132
133     if (t != VIDEO && t != AV) {
134         m_view.clip_force_vindex->setEnabled(false);
135     }
136
137     if (t == IMAGE) {
138         m_view.tabWidget->removeTab(SLIDETAB);
139         m_view.tabWidget->removeTab(COLORTAB);
140         m_view.tabWidget->removeTab(AUDIOTAB);
141         m_view.tabWidget->removeTab(VIDEOTAB);
142         if (props.contains("frame_size"))
143             m_view.image_size->setText(props.value("frame_size"));
144         if (props.contains("transparency"))
145             m_view.image_transparency->setChecked(props.value("transparency").toInt());
146         int width = 180.0 * KdenliveSettings::project_display_ratio();
147         if (width % 2 == 1) width++;
148         m_view.clip_thumb->setPixmap(QPixmap(url.path()).scaled(QSize(width, 180), Qt::KeepAspectRatio));
149     } else if (t == COLOR) {
150         m_view.clip_path->setEnabled(false);
151         m_view.tabWidget->removeTab(METATAB);
152         m_view.tabWidget->removeTab(IMAGETAB);
153         m_view.tabWidget->removeTab(SLIDETAB);
154         m_view.tabWidget->removeTab(AUDIOTAB);
155         m_view.tabWidget->removeTab(VIDEOTAB);
156         m_view.clip_thumb->setHidden(true);
157         m_view.clip_color->setColor(QColor('#' + props.value("colour").right(8).left(6)));
158     } else if (t == SLIDESHOW) {
159         bool isMime = true;
160         if (url.fileName().startsWith(".all.")) {
161             // the image sequence is defined by mimetype
162             m_view.clip_path->setText(url.directory());
163         } else {
164             // the image sequence is defined by pattern
165             m_view.slide_type_label->setHidden(true);
166             m_view.image_type->setHidden(true);
167             m_view.clip_path->setText(url.path());
168             isMime = false;
169         }
170
171         m_view.tabWidget->removeTab(METATAB);
172         m_view.tabWidget->removeTab(IMAGETAB);
173         m_view.tabWidget->removeTab(COLORTAB);
174         m_view.tabWidget->removeTab(AUDIOTAB);
175         m_view.tabWidget->removeTab(VIDEOTAB);
176
177         //WARNING: Keep in sync with slideshowclip.cpp
178         m_view.image_type->addItem("JPG (*.jpg)", "jpg");
179         m_view.image_type->addItem("JPEG (*.jpeg)", "jpeg");
180         m_view.image_type->addItem("PNG (*.png)", "png");
181         m_view.image_type->addItem("BMP (*.bmp)", "bmp");
182         m_view.image_type->addItem("GIF (*.gif)", "gif");
183         m_view.image_type->addItem("TGA (*.tga)", "tga");
184         m_view.image_type->addItem("TIFF (*.tiff)", "tiff");
185         m_view.image_type->addItem("Open EXR (*.exr)", "exr");
186
187         m_view.slide_loop->setChecked(props.value("loop").toInt());
188         m_view.slide_fade->setChecked(props.value("fade").toInt());
189         m_view.luma_softness->setValue(props.value("softness").toInt());
190         QString path = props.value("resource");
191         QString ext = path.section('.', -1);
192         for (int i = 0; i < m_view.image_type->count(); i++) {
193             if (m_view.image_type->itemData(i).toString() == ext) {
194                 m_view.image_type->setCurrentIndex(i);
195                 break;
196             }
197         }
198         m_view.slide_duration->setText(tc.getTimecodeFromFrames(props.value("ttl").toInt()));
199
200         m_view.slide_duration_format->addItem(i18n("hh:mm:ss::ff"));
201         m_view.slide_duration_format->addItem(i18n("Frames"));
202         connect(m_view.slide_duration_format, SIGNAL(activated(int)), this, SLOT(slotUpdateDurationFormat(int)));
203         m_view.slide_duration_frames->setHidden(true);
204         m_view.luma_duration_frames->setHidden(true);
205
206         parseFolder();
207
208         m_view.luma_duration->setText(tc.getTimecodeFromFrames(props.value("luma_duration").toInt()));
209         QString lumaFile = props.value("luma_file");
210
211         // Check for Kdenlive installed luma files
212         QStringList filters;
213         filters << "*.pgm" << "*.png";
214
215         QStringList customLumas = KGlobal::dirs()->findDirs("appdata", "lumas");
216         foreach(const QString &folder, customLumas) {
217             QStringList filesnames = QDir(folder).entryList(filters, QDir::Files);
218             foreach(const QString &fname, filesnames) {
219                 QString filePath = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
220                 m_view.luma_file->addItem(KIcon(filePath), fname, filePath);
221             }
222         }
223
224         // Check for MLT lumas
225         QString profilePath = KdenliveSettings::mltpath();
226         QString folder = profilePath.section('/', 0, -3);
227         folder.append("/lumas/PAL"); // TODO: cleanup the PAL / NTSC mess in luma files
228         QDir lumafolder(folder);
229         QStringList filesnames = lumafolder.entryList(filters, QDir::Files);
230         foreach(const QString &fname, filesnames) {
231             QString filePath = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
232             m_view.luma_file->addItem(KIcon(filePath), fname, filePath);
233         }
234
235         if (!lumaFile.isEmpty()) {
236             m_view.slide_luma->setChecked(true);
237             m_view.luma_file->setCurrentIndex(m_view.luma_file->findData(lumaFile));
238         } else m_view.luma_file->setEnabled(false);
239         slotEnableLuma(m_view.slide_fade->checkState());
240         slotEnableLumaFile(m_view.slide_luma->checkState());
241         connect(m_view.slide_fade, SIGNAL(stateChanged(int)), this, SLOT(slotEnableLuma(int)));
242         connect(m_view.slide_luma, SIGNAL(stateChanged(int)), this, SLOT(slotEnableLumaFile(int)));
243
244         connect(m_view.image_type, SIGNAL(currentIndexChanged(int)), this, SLOT(parseFolder()));
245     } else if (t != AUDIO) {
246         m_view.tabWidget->removeTab(IMAGETAB);
247         m_view.tabWidget->removeTab(SLIDETAB);
248         m_view.tabWidget->removeTab(COLORTAB);
249         if (props.contains("frame_size"))
250             m_view.clip_size->setText(props.value("frame_size"));
251         if (props.contains("videocodec"))
252             m_view.clip_vcodec->setText(props.value("videocodec"));
253         if (props.contains("fps")) {
254             m_view.clip_fps->setText(props.value("fps"));
255             if (!m_view.clip_framerate->isEnabled()) m_view.clip_framerate->setValue(props.value("fps").toDouble());
256         }
257         if (props.contains("aspect_ratio"))
258             m_view.clip_ratio->setText(props.value("aspect_ratio"));
259         int width = 180.0 * KdenliveSettings::project_display_ratio();
260         if (width % 2 == 1) width++;
261         QPixmap pix = m_clip->thumbProducer()->getImage(url, m_clip->getClipThumbFrame(), width, 180);
262         m_view.clip_thumb->setPixmap(pix);
263         if (t == IMAGE || t == VIDEO) m_view.tabWidget->removeTab(AUDIOTAB);
264     } else {
265         m_view.tabWidget->removeTab(IMAGETAB);
266         m_view.tabWidget->removeTab(SLIDETAB);
267         m_view.tabWidget->removeTab(COLORTAB);
268         m_view.tabWidget->removeTab(VIDEOTAB);
269         m_view.clip_thumb->setHidden(true);
270     }
271
272     if (t != SLIDESHOW && t != COLOR) {
273         KFileItem f(KFileItem::Unknown, KFileItem::Unknown, url, true);
274         m_view.clip_filesize->setText(KIO::convertSize(f.size()));
275     } else {
276         m_view.clip_filesize->setHidden(true);
277         m_view.label_size->setHidden(true);
278     }
279     m_view.clip_duration->setInputMask("");
280     m_view.clip_duration->setValidator(tc.validator());
281     m_view.clip_duration->setText(tc.getTimecode(m_clip->duration()));
282     if (t != IMAGE && t != COLOR && t != TEXT) m_view.clip_duration->setReadOnly(true);
283     else connect(m_view.clip_duration, SIGNAL(editingFinished()), this, SLOT(slotCheckMaxLength()));
284
285     // markers
286     m_view.marker_new->setIcon(KIcon("document-new"));
287     m_view.marker_new->setToolTip(i18n("Add marker"));
288     m_view.marker_edit->setIcon(KIcon("document-properties"));
289     m_view.marker_edit->setToolTip(i18n("Edit marker"));
290     m_view.marker_delete->setIcon(KIcon("trash-empty"));
291     m_view.marker_delete->setToolTip(i18n("Delete marker"));
292
293     slotFillMarkersList();
294     connect(m_view.marker_new, SIGNAL(clicked()), this, SLOT(slotAddMarker()));
295     connect(m_view.marker_edit, SIGNAL(clicked()), this, SLOT(slotEditMarker()));
296     connect(m_view.marker_delete, SIGNAL(clicked()), this, SLOT(slotDeleteMarker()));
297     connect(m_view.markers_list, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(slotEditMarker()));
298
299     //adjustSize();
300 }
301
302
303 // Used for multiple clips editing
304 ClipProperties::ClipProperties(QList <DocClipBase *>cliplist, Timecode tc, QMap <QString, QString> commonproperties, QWidget * parent) :
305         QDialog(parent),
306         m_clip(NULL),
307         m_tc(tc),
308         m_fps(0),
309         m_count(0),
310         m_clipNeedsRefresh(false),
311         m_clipNeedsReLoad(false)
312 {
313     setFont(KGlobalSettings::toolBarFont());
314     m_view.setupUi(this);
315     QMap <QString, QString> props = cliplist.at(0)->properties();
316     m_old_props = commonproperties;
317
318     if (commonproperties.contains("force_aspect_ratio") && !commonproperties.value("force_aspect_ratio").isEmpty() && commonproperties.value("force_aspect_ratio").toDouble() > 0) {
319         m_view.clip_force_ar->setChecked(true);
320         m_view.clip_ar->setEnabled(true);
321         m_view.clip_ar->setValue(commonproperties.value("force_aspect_ratio").toDouble());
322     }
323
324     if (commonproperties.contains("force_fps") && !commonproperties.value("force_fps").isEmpty() && commonproperties.value("force_fps").toDouble() > 0) {
325         m_view.clip_force_framerate->setChecked(true);
326         m_view.clip_framerate->setEnabled(true);
327         m_view.clip_framerate->setValue(commonproperties.value("force_fps").toDouble());
328     }
329
330     if (commonproperties.contains("force_progressive") && !commonproperties.value("force_progressive").isEmpty()) {
331         m_view.clip_force_progressive->setChecked(true);
332         m_view.clip_progressive->setEnabled(true);
333         m_view.clip_progressive->setValue(commonproperties.value("force_progressive").toInt());
334     }
335
336     if (commonproperties.contains("threads") && !commonproperties.value("threads").isEmpty() && commonproperties.value("threads").toInt() != 1) {
337         m_view.clip_force_threads->setChecked(true);
338         m_view.clip_threads->setEnabled(true);
339         m_view.clip_threads->setValue(commonproperties.value("threads").toInt());
340     }
341
342     if (commonproperties.contains("video_index") && !commonproperties.value("video_index").isEmpty() && commonproperties.value("video_index").toInt() != 0) {
343         m_view.clip_force_vindex->setChecked(true);
344         m_view.clip_vindex->setEnabled(true);
345         m_view.clip_vindex->setValue(commonproperties.value("video_index").toInt());
346     }
347
348     if (commonproperties.contains("audio_index") && !commonproperties.value("audio_index").isEmpty() && commonproperties.value("audio_index").toInt() != 0) {
349         m_view.clip_force_aindex->setChecked(true);
350         m_view.clip_aindex->setEnabled(true);
351         m_view.clip_aindex->setValue(commonproperties.value("audio_index").toInt());
352     }
353
354     if (props.contains("audio_max")) {
355         m_view.clip_aindex->setMaximum(props.value("audio_max").toInt());
356     }
357
358     if (props.contains("video_max")) {
359         m_view.clip_vindex->setMaximum(props.value("video_max").toInt());
360     }
361
362     connect(m_view.clip_force_ar, SIGNAL(toggled(bool)), m_view.clip_ar, SLOT(setEnabled(bool)));
363     connect(m_view.clip_force_progressive, SIGNAL(toggled(bool)), m_view.clip_progressive, SLOT(setEnabled(bool)));
364     connect(m_view.clip_force_threads, SIGNAL(toggled(bool)), m_view.clip_threads, SLOT(setEnabled(bool)));
365     connect(m_view.clip_force_vindex, SIGNAL(toggled(bool)), m_view.clip_vindex, SLOT(setEnabled(bool)));
366     connect(m_view.clip_force_aindex, SIGNAL(toggled(bool)), m_view.clip_aindex, SLOT(setEnabled(bool)));
367     connect(m_view.clip_force_out, SIGNAL(toggled(bool)), m_view.clip_out, SLOT(setEnabled(bool)));
368
369     m_view.tabWidget->removeTab(METATAB);
370     m_view.tabWidget->removeTab(MARKERTAB);
371     m_view.tabWidget->removeTab(IMAGETAB);
372     m_view.tabWidget->removeTab(SLIDETAB);
373     m_view.tabWidget->removeTab(COLORTAB);
374     m_view.tabWidget->removeTab(AUDIOTAB);
375     m_view.tabWidget->removeTab(VIDEOTAB);
376
377     m_view.clip_path->setHidden(true);
378     m_view.label_path->setHidden(true);
379     m_view.label_description->setHidden(true);
380     m_view.label_size->setHidden(true);
381     m_view.clip_filesize->setHidden(true);
382     m_view.clip_filesize->setHidden(true);
383     m_view.clip_path->setHidden(true);
384     m_view.clip_description->setHidden(true);
385     m_view.clip_thumb->setHidden(true);
386     m_view.label_duration->setHidden(true);
387     m_view.clip_duration->setHidden(true);
388
389     if (commonproperties.contains("out")) {
390         if (commonproperties.value("out").toInt() > 0) {
391             m_view.clip_force_out->setChecked(true);
392             m_view.clip_out->setText(m_tc.getTimecodeFromFrames(commonproperties.value("out").toInt()));
393         } else m_view.clip_out->setText(KdenliveSettings::image_duration());
394     } else {
395         m_view.clip_force_out->setHidden(true);
396         m_view.clip_out->setHidden(true);
397     }
398 }
399
400
401
402 void ClipProperties::slotEnableLuma(int state)
403 {
404     bool enable = false;
405     if (state == Qt::Checked) enable = true;
406     m_view.luma_duration->setEnabled(enable);
407     m_view.luma_duration_frames->setEnabled(enable);
408     m_view.slide_luma->setEnabled(enable);
409     if (enable) {
410         m_view.luma_file->setEnabled(m_view.slide_luma->isChecked());
411     } else m_view.luma_file->setEnabled(false);
412     m_view.label_softness->setEnabled(m_view.slide_luma->isChecked() && enable);
413     m_view.luma_softness->setEnabled(m_view.label_softness->isEnabled());
414 }
415
416 void ClipProperties::slotEnableLumaFile(int state)
417 {
418     bool enable = false;
419     if (state == Qt::Checked) enable = true;
420     m_view.luma_file->setEnabled(enable);
421     m_view.luma_softness->setEnabled(enable);
422     m_view.label_softness->setEnabled(enable);
423 }
424
425 void ClipProperties::slotFillMarkersList()
426 {
427     m_view.markers_list->clear();
428     QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
429     for (int count = 0; count < marks.count(); ++count) {
430         QString time = m_tc.getTimecode(marks[count].time());
431         QStringList itemtext;
432         itemtext << time << marks[count].comment();
433         (void) new QTreeWidgetItem(m_view.markers_list, itemtext);
434     }
435 }
436
437 void ClipProperties::slotAddMarker()
438 {
439     CommentedTime marker(GenTime(), i18n("Marker"));
440     MarkerDialog d(m_clip, marker, m_tc, i18n("Add Marker"), this);
441     if (d.exec() == QDialog::Accepted) {
442         emit addMarker(m_clip->getId(), d.newMarker().time(), d.newMarker().comment());
443     }
444     QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
445 }
446
447 void ClipProperties::slotEditMarker()
448 {
449     QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
450     int pos = m_view.markers_list->currentIndex().row();
451     if (pos < 0 || pos > marks.count() - 1) return;
452     MarkerDialog d(m_clip, marks.at(pos), m_tc, i18n("Edit Marker"), this);
453     if (d.exec() == QDialog::Accepted) {
454         emit addMarker(m_clip->getId(), d.newMarker().time(), d.newMarker().comment());
455     }
456     QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
457 }
458
459 void ClipProperties::slotDeleteMarker()
460 {
461     QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
462     int pos = m_view.markers_list->currentIndex().row();
463     if (pos < 0 || pos > marks.count() - 1) return;
464     emit addMarker(m_clip->getId(), marks.at(pos).time(), QString());
465
466     QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
467 }
468
469 const QString &ClipProperties::clipId() const
470 {
471     return m_clip->getId();
472 }
473
474
475 QMap <QString, QString> ClipProperties::properties()
476 {
477     QMap <QString, QString> props;
478     CLIPTYPE t = UNKNOWN;
479     if (m_clip != NULL) {
480         t = m_clip->clipType();
481         m_old_props = m_clip->properties();
482     }
483
484     double aspect = m_view.clip_ar->value();
485     if (m_view.clip_force_ar->isChecked()) {
486         if (aspect != m_old_props.value("force_aspect_ratio").toDouble()) {
487             props["force_aspect_ratio"] = QString::number(aspect);
488             m_clipNeedsRefresh = true;
489         }
490     } else if (m_old_props.contains("force_aspect_ratio")) {
491         props["force_aspect_ratio"].clear();
492         m_clipNeedsRefresh = true;
493     }
494
495     double fps = m_view.clip_framerate->value();
496     if (m_view.clip_force_framerate->isChecked()) {
497         if (fps != m_old_props.value("force_fps").toDouble()) {
498             props["force_fps"] = QString::number(fps);
499             m_clipNeedsRefresh = true;
500         }
501     } else if (m_old_props.contains("force_fps")) {
502         props["force_fps"].clear();
503         m_clipNeedsRefresh = true;
504     }
505
506     int progressive = m_view.clip_progressive->value();
507     if (m_view.clip_force_progressive->isChecked()) {
508         if (progressive != m_old_props.value("force_progressive").toInt()) {
509             props["force_progressive"] = QString::number(progressive);
510         }
511     } else if (m_old_props.contains("force_progressive")) {
512         props["force_progressive"].clear();
513     }
514
515     int threads = m_view.clip_threads->value();
516     if (m_view.clip_force_threads->isChecked()) {
517         if (threads != m_old_props.value("threads").toInt()) {
518             props["threads"] = QString::number(threads);
519         }
520     } else if (m_old_props.contains("threads")) {
521         props["threads"].clear();
522     }
523
524     int vindex = m_view.clip_vindex->value();
525     if (m_view.clip_force_vindex->isChecked()) {
526         if (vindex != m_old_props.value("video_index").toInt()) {
527             props["video_index"] = QString::number(vindex);
528         }
529     } else if (m_old_props.contains("video_index")) {
530         props["video_index"].clear();
531     }
532
533     int aindex = m_view.clip_aindex->value();
534     if (m_view.clip_force_aindex->isChecked()) {
535         if (aindex != m_old_props.value("audio_index").toInt()) {
536             props["audio_index"] = QString::number(aindex);
537         }
538     } else if (m_old_props.contains("audio_index")) {
539         props["audio_index"].clear();
540     }
541
542     // If we adjust several clips, return now
543     if (m_clip == NULL) {
544         if (m_view.clip_out->isEnabled()) {
545             int duration = m_tc.getFrameCount(m_view.clip_out->text());
546             if (duration != m_old_props.value("out").toInt()) {
547                 props["out"] = QString::number(duration - 1);
548             }
549         }
550         return props;
551     }
552
553     if (m_old_props.value("description") != m_view.clip_description->text())
554         props["description"] = m_view.clip_description->text();
555
556     if (t == COLOR) {
557         QString new_color = m_view.clip_color->color().name();
558         if (new_color != QString('#' + m_old_props.value("colour").right(8).left(6))) {
559             m_clipNeedsRefresh = true;
560             props["colour"] = "0x" + new_color.right(6) + "ff";
561         }
562         int duration = m_tc.getFrameCount(m_view.clip_duration->text());
563         if (duration != m_clip->duration().frames(m_fps)) {
564             props["out"] = QString::number(duration - 1);
565         }
566     } else if (t == IMAGE) {
567         if ((int) m_view.image_transparency->isChecked() != m_old_props.value("transparency").toInt()) {
568             props["transparency"] = QString::number((int)m_view.image_transparency->isChecked());
569             //m_clipNeedsRefresh = true;
570         }
571         int duration = m_tc.getFrameCount(m_view.clip_duration->text());
572         if (duration != m_clip->duration().frames(m_fps)) {
573             props["out"] = QString::number(duration - 1);
574         }
575     } else if (t == SLIDESHOW) {
576         QString value = QString::number((int) m_view.slide_loop->isChecked());
577         if (m_old_props.value("loop") != value) props["loop"] = value;
578         value = QString::number((int) m_view.slide_fade->isChecked());
579         if (m_old_props.value("fade") != value) props["fade"] = value;
580         value = QString::number((int) m_view.luma_softness->value());
581         if (m_old_props.value("softness") != value) props["softness"] = value;
582         
583         bool isMime = !(m_view.clip_path->text().contains('%'));
584         if (isMime) {
585             QString extension = "/.all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
586             QString new_path = m_view.clip_path->text() + extension;
587             if (new_path != m_old_props.value("resource")) {
588                 m_clipNeedsReLoad = true;
589                 props["resource"] = new_path;
590                 kDebug() << "////  SLIDE EDIT, NEW:" << new_path << ", OLD; " << m_old_props.value("resource");
591             }
592         }
593         int duration;
594         if (m_view.slide_duration_format->currentIndex() == 1) {
595             // we are in frames mode
596             duration = m_view.slide_duration_frames->value();
597         } else duration = m_tc.getFrameCount(m_view.slide_duration->text());
598         if (duration != m_old_props.value("ttl").toInt()) {
599             m_clipNeedsRefresh = true;
600             props["ttl"] = QString::number(duration);
601             props["out"] = QString::number(duration * m_count);
602         }
603
604         if (duration * m_count - 1 != m_old_props.value("out").toInt()) {
605             m_clipNeedsRefresh = true;
606             props["out"] = QString::number(duration * m_count - 1);
607         }
608         if (m_view.slide_fade->isChecked()) {
609             int luma_duration;
610             if (m_view.slide_duration_format->currentIndex() == 1) {
611                 // we are in frames mode
612                 luma_duration = m_view.luma_duration_frames->value();
613             } else luma_duration = m_tc.getFrameCount(m_view.luma_duration->text());
614             if (luma_duration != m_old_props.value("luma_duration").toInt()) {
615                 m_clipNeedsRefresh = true;
616                 props["luma_duration"] = QString::number(luma_duration);
617             }
618             QString lumaFile;
619             if (m_view.slide_luma->isChecked())
620                 lumaFile = m_view.luma_file->itemData(m_view.luma_file->currentIndex()).toString();
621             if (lumaFile != m_old_props.value("luma_file")) {
622                 m_clipNeedsRefresh = true;
623                 props["luma_file"] = lumaFile;
624             }
625         } else {
626             if (!m_old_props.value("luma_file").isEmpty()) {
627                 props["luma_file"].clear();
628             }
629         }
630
631     }
632     return props;
633 }
634
635 bool ClipProperties::needsTimelineRefresh() const
636 {
637     return m_clipNeedsRefresh;
638 }
639
640 bool ClipProperties::needsTimelineReload() const
641 {
642     return m_clipNeedsReLoad;
643 }
644
645
646 void ClipProperties::parseFolder()
647 {
648     QString path = m_view.clip_path->text();
649     bool isMime = !(path.contains('%'));
650     if (!isMime) path = KUrl(path).directory();
651     QDir dir(path);
652
653     QStringList filters;
654     QString extension;
655
656     if (isMime) {
657         // TODO: improve jpeg image detection with extension like jpeg, requires change in MLT image producers
658         filters << "*." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
659         extension = "/.all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
660         dir.setNameFilters(filters);
661     }
662
663     QStringList result = dir.entryList(QDir::Files);
664
665     if (!isMime) {
666         // find pattern
667         QString filter = KUrl(m_view.clip_path->text()).fileName();
668         QString ext = filter.section('.', -1);
669         filter = filter.section('%', 0, -2);
670         QString regexp = "^" + filter + "\\d+\\." + ext + "$";
671         QRegExp rx(regexp);
672         QStringList entries;
673         foreach(const QString &path, result) {
674             if (rx.exactMatch(path)) entries << path;
675         }
676         result = entries;
677     }
678
679     m_count = result.count();
680     if (m_count == 0) {
681         // no images, do not accept that
682         m_view.slide_info->setText(i18n("No image found"));
683         m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
684         return;
685     }
686     m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
687     m_view.slide_info->setText(i18np("1 image found", "%1 images found", m_count));
688     QDomElement xml = m_clip->toXML();
689     xml.setAttribute("resource", m_view.clip_path->text() + extension);
690     int width = 180.0 * KdenliveSettings::project_display_ratio();
691     if (width % 2 == 1) width++;
692     QString filePath = m_view.clip_path->text();
693     if (isMime) filePath.append(extension);
694     QPixmap pix = m_clip->thumbProducer()->getImage(KUrl(filePath), 1, width, 180);
695     QMap <QString, QString> props = m_clip->properties();
696     m_view.clip_duration->setText(m_tc.getTimecodeFromFrames(props.value("ttl").toInt() * m_count));
697     m_view.clip_thumb->setPixmap(pix);
698 }
699
700 void ClipProperties::slotCheckMaxLength()
701 {
702     if (m_clip->maxDuration() == GenTime()) return;
703     int duration = m_tc.getFrameCount(m_view.clip_duration->text());
704     if (duration > m_clip->maxDuration().frames(m_fps)) {
705         m_view.clip_duration->setText(m_tc.getTimecode(m_clip->maxDuration()));
706     }
707 }
708
709 void ClipProperties::slotUpdateDurationFormat(int ix)
710 {
711     bool framesFormat = ix == 1;
712     if (framesFormat) {
713         // switching to frames count, update widget
714         m_view.slide_duration_frames->setValue(m_tc.getFrameCount(m_view.slide_duration->text()));
715         m_view.luma_duration_frames->setValue(m_tc.getFrameCount(m_view.luma_duration->text()));
716         m_view.slide_duration->setHidden(true);
717         m_view.luma_duration->setHidden(true);
718         m_view.slide_duration_frames->setHidden(false);
719         m_view.luma_duration_frames->setHidden(false);
720     } else {
721         // switching to timecode format
722         m_view.slide_duration->setText(m_tc.getTimecodeFromFrames(m_view.slide_duration_frames->value()));
723         m_view.luma_duration->setText(m_tc.getTimecodeFromFrames(m_view.luma_duration_frames->value()));
724         m_view.slide_duration_frames->setHidden(true);
725         m_view.luma_duration_frames->setHidden(true);
726         m_view.slide_duration->setHidden(false);
727         m_view.luma_duration->setHidden(false);
728     }
729 }
730
731 #include "clipproperties.moc"
732
733