]> git.sesse.net Git - kdenlive/blob - src/clipproperties.cpp
Extract clip metadata (camcorder name, aperture, exposure, ...) with exiftool if...
[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 #include "profilesdialog.h"
26
27 #include <KStandardDirs>
28 #include <KDebug>
29 #include <KFileItem>
30 #include <KFileDialog>
31 #include <kdeversion.h>
32 #include <KUrlLabel>
33 #include <KRun>
34
35 #ifdef USE_NEPOMUK
36 #if KDE_IS_VERSION(4,6,0)
37 #include <Nepomuk/Variant>
38 #include <Nepomuk/Resource>
39 #include <Nepomuk/ResourceManager>
40 #include <Nepomuk/Vocabulary/NIE>
41 #endif
42 #endif
43
44
45 #include <QDir>
46 #include <QPainter>
47
48
49 static const int VIDEOTAB = 0;
50 static const int AUDIOTAB = 1;
51 static const int COLORTAB = 2;
52 static const int SLIDETAB = 3;
53 static const int IMAGETAB = 4;
54 static const int MARKERTAB = 5;
55 static const int METATAB = 6;
56 static const int ADVANCEDTAB = 7;
57
58
59 ClipProperties::ClipProperties(DocClipBase *clip, Timecode tc, double fps, QWidget * parent) :
60     QDialog(parent),
61     m_clip(clip),
62     m_tc(tc),
63     m_fps(fps),
64     m_count(0),
65     m_clipNeedsRefresh(false),
66     m_clipNeedsReLoad(false)
67 {
68     setAttribute(Qt::WA_DeleteOnClose, true);
69     setFont(KGlobalSettings::toolBarFont());
70     m_view.setupUi(this);
71     
72     // force transparency is only for group properties, so hide it
73     m_view.clip_force_transparency->setHidden(true);
74     m_view.clip_transparency->setHidden(true);
75     
76     KUrl url = m_clip->fileURL();
77     m_view.clip_path->setText(url.path());
78     m_view.clip_description->setText(m_clip->description());
79     connect(m_view.clip_description, SIGNAL(textChanged(QString)), this, SLOT(slotModified()));
80
81     QMap <QString, QString> props = m_clip->properties();
82     m_view.clip_force_out->setHidden(true);
83     m_view.clip_out->setHidden(true);
84     
85     // New display aspect ratio support
86     if (props.contains("force_aspect_num") && props.value("force_aspect_num").toInt() > 0 &&
87         props.contains("force_aspect_den") && props.value("force_aspect_den").toInt() > 0) {
88         m_view.clip_force_ar->setChecked(true);
89         m_view.clip_ar_num->setEnabled(true);
90         m_view.clip_ar_den->setEnabled(true);
91         m_view.clip_ar_num->setValue(props.value("force_aspect_num").toInt());
92         m_view.clip_ar_den->setValue(props.value("force_aspect_den").toInt());
93     }
94     // Legacy support for pixel aspect ratio
95     else if (props.contains("force_aspect_ratio") && props.value("force_aspect_ratio").toDouble() > 0) {
96         m_view.clip_force_ar->setChecked(true);
97         m_view.clip_ar_num->setEnabled(true);
98         m_view.clip_ar_den->setEnabled(true);
99         if (props.contains("frame_size")) {
100             int width = props.value("force_aspect_ratio").toDouble() * props.value("frame_size").section('x', 0, 0).toInt();
101             int height = props.value("frame_size").section('x', 1, 1).toInt();
102             if (width > 0 && height > 0) {
103                 if ((width / height * 100) == 133) {
104                     width = 4;
105                     height = 3;
106                 }
107                 else if (int(width / height * 100) == 177) {
108                     width = 16;
109                     height = 9;
110                 }
111                 m_view.clip_ar_num->setValue(width);
112                 m_view.clip_ar_den->setValue(height);
113             }
114         }
115     }
116     connect(m_view.clip_force_ar, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
117     connect(m_view.clip_ar_num, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
118     connect(m_view.clip_ar_den, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
119
120     if (props.contains("force_fps") && props.value("force_fps").toDouble() > 0) {
121         m_view.clip_force_framerate->setChecked(true);
122         m_view.clip_framerate->setEnabled(true);
123         m_view.clip_framerate->setValue(props.value("force_fps").toDouble());
124     }
125     connect(m_view.clip_force_framerate, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
126     connect(m_view.clip_framerate, SIGNAL(valueChanged(double)), this, SLOT(slotModified()));
127
128     if (props.contains("force_progressive")) {
129         m_view.clip_force_progressive->setChecked(true);
130         m_view.clip_progressive->setEnabled(true);
131         m_view.clip_progressive->setValue(props.value("force_progressive").toInt());
132     }
133     connect(m_view.clip_force_progressive, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
134     connect(m_view.clip_progressive, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
135
136     m_view.clip_fieldorder->addItem(i18n("Bottom first"), 0);
137     m_view.clip_fieldorder->addItem(i18n("Top first"), 1);
138     if (props.contains("force_tff")) {
139         m_view.clip_force_fieldorder->setChecked(true);
140         m_view.clip_fieldorder->setEnabled(true);
141         m_view.clip_fieldorder->setCurrentIndex(props.value("force_tff").toInt());
142     }
143     connect(m_view.clip_force_fieldorder, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
144     connect(m_view.clip_fieldorder, SIGNAL(currentIndexChanged(int)), this, SLOT(slotModified()));
145     
146     if (props.contains("threads") && props.value("threads").toInt() != 1) {
147         m_view.clip_force_threads->setChecked(true);
148         m_view.clip_threads->setEnabled(true);
149         m_view.clip_threads->setValue(props.value("threads").toInt());
150     }
151     connect(m_view.clip_force_threads, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
152     connect(m_view.clip_threads, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
153
154     if (props.contains("video_index") && props.value("video_index").toInt() != 0) {
155         m_view.clip_force_vindex->setChecked(true);
156         m_view.clip_vindex->setEnabled(true);
157         m_view.clip_vindex->setValue(props.value("video_index").toInt());
158     }
159     connect(m_view.clip_force_vindex, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
160     connect(m_view.clip_vindex, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
161
162     if (props.contains("audio_index") && props.value("audio_index").toInt() != 0) {
163         m_view.clip_force_aindex->setChecked(true);
164         m_view.clip_aindex->setEnabled(true);
165         m_view.clip_aindex->setValue(props.value("audio_index").toInt());
166     }
167     connect(m_view.clip_force_aindex, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
168     connect(m_view.clip_aindex, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
169
170     if (props.contains("audio_max")) {
171         m_view.clip_aindex->setMaximum(props.value("audio_max").toInt());
172     }
173
174     if (props.contains("video_max")) {
175         m_view.clip_vindex->setMaximum(props.value("video_max").toInt());
176     }
177     
178     m_view.clip_colorspace->addItem(ProfilesDialog::getColorspaceDescription(601), 601);
179     m_view.clip_colorspace->addItem(ProfilesDialog::getColorspaceDescription(709), 709);
180     m_view.clip_colorspace->addItem(ProfilesDialog::getColorspaceDescription(240), 240);
181     if (props.contains("force_colorspace")) {
182         m_view.clip_force_colorspace->setChecked(true);
183         m_view.clip_colorspace->setEnabled(true);
184         m_view.clip_colorspace->setCurrentIndex(m_view.clip_colorspace->findData(props.value("force_colorspace").toInt()));
185     } else if (props.contains("colorspace")) {
186         m_view.clip_colorspace->setCurrentIndex(m_view.clip_colorspace->findData(props.value("colorspace").toInt()));
187     }
188     connect(m_view.clip_force_colorspace, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
189     connect(m_view.clip_colorspace, SIGNAL(currentIndexChanged(int)), this, SLOT(slotModified()));
190     
191     if (props.contains("full_luma")) {
192         m_view.clip_full_luma->setChecked(true);
193     }
194     connect(m_view.clip_full_luma, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
195
196     // Check for Metadata
197     QMap<QString, QString> meta = m_clip->metadata();
198     QMap<QString, QString>::const_iterator i = meta.constBegin();
199     while (i != meta.constEnd()) {
200         QTreeWidgetItem *metaitem = new QTreeWidgetItem(m_view.metadata_list);
201         metaitem->setText(0, i.key()); //i18n(i.key().section('.', 2, 3).toUtf8().data()));
202         metaitem->setText(1, i.value());
203         ++i;
204     }
205
206     connect(m_view.clip_force_ar, SIGNAL(toggled(bool)), m_view.clip_ar_num, SLOT(setEnabled(bool)));
207     connect(m_view.clip_force_ar, SIGNAL(toggled(bool)), m_view.clip_ar_den, SLOT(setEnabled(bool)));
208     connect(m_view.clip_force_framerate, SIGNAL(toggled(bool)), m_view.clip_framerate, SLOT(setEnabled(bool)));
209     connect(m_view.clip_force_progressive, SIGNAL(toggled(bool)), m_view.clip_progressive, SLOT(setEnabled(bool)));
210     connect(m_view.clip_force_fieldorder, SIGNAL(toggled(bool)), m_view.clip_fieldorder, SLOT(setEnabled(bool)));
211     connect(m_view.clip_force_threads, SIGNAL(toggled(bool)), m_view.clip_threads, SLOT(setEnabled(bool)));
212     connect(m_view.clip_force_vindex, SIGNAL(toggled(bool)), m_view.clip_vindex, SLOT(setEnabled(bool)));
213     connect(m_view.clip_force_aindex, SIGNAL(toggled(bool)), m_view.clip_aindex, SLOT(setEnabled(bool)));
214     connect(m_view.clip_force_colorspace, SIGNAL(toggled(bool)), m_view.clip_colorspace, SLOT(setEnabled(bool)));
215
216     if (props.contains("audiocodec"))
217         new QTreeWidgetItem(m_view.clip_aproperties, QStringList() << i18n("Audio codec") << props.value("audiocodec"));
218
219     if (props.contains("channels"))
220         new QTreeWidgetItem(m_view.clip_aproperties, QStringList() << i18n("Channels") << props.value("channels"));
221
222     if (props.contains("frequency"))
223         new QTreeWidgetItem(m_view.clip_aproperties, QStringList() << i18n("Frequency") << props.value("frequency"));
224     
225
226     CLIPTYPE t = m_clip->clipType();
227     
228     if (props.contains("proxy") && props.value("proxy") != "-") {
229         KFileItem f(KFileItem::Unknown, KFileItem::Unknown, KUrl(props.value("proxy")), true);
230         QFrame* line = new QFrame();
231         line->setFrameShape(QFrame::HLine);
232         line->setFrameShadow(QFrame::Sunken);
233         m_proxyContainer = new QFrame();
234         m_proxyContainer->setFrameShape(QFrame::NoFrame);
235         QHBoxLayout *l = new QHBoxLayout;
236         l->addWidget(new QLabel(i18n("Proxy clip: %1", KIO::convertSize(f.size()))));
237         l->addStretch(5);
238         QPushButton *pb = new QPushButton(i18n("Delete proxy"));
239         l->addWidget(pb);
240         connect(pb, SIGNAL(clicked()), this, SLOT(slotDeleteProxy()));
241         m_proxyContainer->setLayout(l);
242         if (t == IMAGE) {
243             m_view.tab_image->layout()->addWidget(line);
244             m_view.tab_image->layout()->addWidget(m_proxyContainer);
245         }
246         else if (t == AUDIO) {
247             m_view.tab_audio->layout()->addWidget(line);
248             m_view.tab_audio->layout()->addWidget(m_proxyContainer);
249         }
250         else {
251             m_view.tab_video->layout()->addWidget(line);
252             m_view.tab_video->layout()->addWidget(m_proxyContainer);
253         }
254     }
255     
256     if (t != AUDIO && t != AV) {
257         m_view.clip_force_aindex->setEnabled(false);
258     }
259
260     if (t != VIDEO && t != AV) {
261         m_view.clip_force_vindex->setEnabled(false);
262     }
263
264     if (t == PLAYLIST)
265         m_view.tabWidget->setTabText(VIDEOTAB, i18n("Playlist"));
266
267     if (t == IMAGE) {
268         m_view.tabWidget->removeTab(SLIDETAB);
269         m_view.tabWidget->removeTab(COLORTAB);
270         m_view.tabWidget->removeTab(AUDIOTAB);
271         m_view.tabWidget->removeTab(VIDEOTAB);
272         if (props.contains("frame_size"))
273             m_view.image_size->setText(props.value("frame_size"));
274         if (props.contains("transparency"))
275             m_view.image_transparency->setChecked(props.value("transparency").toInt());
276         connect(m_view.image_transparency, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
277         int width = 180.0 * KdenliveSettings::project_display_ratio();
278         if (width % 2 == 1) width++;
279         m_view.clip_thumb->setPixmap(QPixmap(url.path()).scaled(QSize(width, 180), Qt::KeepAspectRatio));
280     } else if (t == COLOR) {
281         m_view.clip_path->setEnabled(false);
282         m_view.tabWidget->removeTab(METATAB);
283         m_view.tabWidget->removeTab(IMAGETAB);
284         m_view.tabWidget->removeTab(SLIDETAB);
285         m_view.tabWidget->removeTab(AUDIOTAB);
286         m_view.tabWidget->removeTab(VIDEOTAB);
287         m_view.clip_thumb->setHidden(true);
288         m_view.clip_color->setColor(QColor('#' + props.value("colour").right(8).left(6)));
289         connect(m_view.clip_color, SIGNAL(changed(QColor)), this, SLOT(slotModified()));
290     } else if (t == SLIDESHOW) {
291         if (url.fileName().startsWith(".all.")) {
292             // the image sequence is defined by mimetype
293             m_view.clip_path->setText(url.directory());
294         } else {
295             // the image sequence is defined by pattern
296             m_view.slide_type_label->setHidden(true);
297             m_view.image_type->setHidden(true);
298             m_view.clip_path->setText(url.path());
299         }
300
301         m_view.tabWidget->removeTab(METATAB);
302         m_view.tabWidget->removeTab(IMAGETAB);
303         m_view.tabWidget->removeTab(COLORTAB);
304         m_view.tabWidget->removeTab(AUDIOTAB);
305         m_view.tabWidget->removeTab(VIDEOTAB);
306
307         //WARNING: Keep in sync with slideshowclip.cpp
308         m_view.image_type->addItem("JPG (*.jpg)", "jpg");
309         m_view.image_type->addItem("JPEG (*.jpeg)", "jpeg");
310         m_view.image_type->addItem("PNG (*.png)", "png");
311         m_view.image_type->addItem("BMP (*.bmp)", "bmp");
312         m_view.image_type->addItem("GIF (*.gif)", "gif");
313         m_view.image_type->addItem("TGA (*.tga)", "tga");
314         m_view.image_type->addItem("TIF (*.tif)", "tif");
315         m_view.image_type->addItem("TIFF (*.tiff)", "tiff");
316         m_view.image_type->addItem("Open EXR (*.exr)", "exr");
317         m_view.animation->addItem(i18n("None"), QString());
318         m_view.animation->addItem(i18n("Pan"), "Pan");
319         m_view.animation->addItem(i18n("Pan, low-pass"), "Pan, low-pass");
320         m_view.animation->addItem(i18n("Pan and zoom"), "Pan and zoom");
321         m_view.animation->addItem(i18n("Pan and zoom, low-pass"), "Pan and zoom, low-pass");
322         m_view.animation->addItem(i18n("Zoom"), "Zoom");
323         m_view.animation->addItem(i18n("Zoom, low-pass"), "Zoom, low-pass");
324
325         m_view.slide_loop->setChecked(props.value("loop").toInt());
326         m_view.slide_crop->setChecked(props.value("crop").toInt());
327         m_view.slide_fade->setChecked(props.value("fade").toInt());
328         m_view.luma_softness->setValue(props.value("softness").toInt());
329         if (!props.value("animation").isEmpty())
330             m_view.animation->setCurrentItem(props.value("animation"));
331         else
332             m_view.animation->setCurrentIndex(0);
333         QString path = props.value("resource");
334         QString ext = path.section('.', -1);
335         for (int i = 0; i < m_view.image_type->count(); i++) {
336             if (m_view.image_type->itemData(i).toString() == ext) {
337                 m_view.image_type->setCurrentIndex(i);
338                 break;
339             }
340         }
341         m_view.slide_duration->setText(tc.getTimecodeFromFrames(props.value("ttl").toInt()));
342
343         m_view.slide_duration_format->addItem(i18n("hh:mm:ss:ff"));
344         m_view.slide_duration_format->addItem(i18n("Frames"));
345         connect(m_view.slide_duration_format, SIGNAL(activated(int)), this, SLOT(slotUpdateDurationFormat(int)));
346         m_view.slide_duration_frames->setHidden(true);
347         m_view.luma_duration_frames->setHidden(true);
348
349         parseFolder(false);
350
351         m_view.luma_duration->setText(tc.getTimecodeFromFrames(props.value("luma_duration").toInt()));
352         QString lumaFile = props.value("luma_file");
353
354         // Check for Kdenlive installed luma files
355         QStringList filters;
356         filters << "*.pgm" << "*.png";
357
358         QStringList customLumas = KGlobal::dirs()->findDirs("appdata", "lumas");
359         foreach(const QString & folder, customLumas) {
360             QStringList filesnames = QDir(folder).entryList(filters, QDir::Files);
361             foreach(const QString & fname, filesnames) {
362                 QString filePath = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
363                 m_view.luma_file->addItem(KIcon(filePath), fname, filePath);
364             }
365         }
366
367         // Check for MLT lumas
368         QString profilePath = KdenliveSettings::mltpath();
369         QString folder = profilePath.section('/', 0, -3);
370         folder.append("/lumas/PAL"); // TODO: cleanup the PAL / NTSC mess in luma files
371         QDir lumafolder(folder);
372         QStringList filesnames = lumafolder.entryList(filters, QDir::Files);
373         foreach(const QString & fname, filesnames) {
374             QString filePath = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
375             m_view.luma_file->addItem(KIcon(filePath), fname, filePath);
376         }
377
378         if (!lumaFile.isEmpty()) {
379             m_view.slide_luma->setChecked(true);
380             m_view.luma_file->setCurrentIndex(m_view.luma_file->findData(lumaFile));
381         } else m_view.luma_file->setEnabled(false);
382         slotEnableLuma(m_view.slide_fade->checkState());
383         slotEnableLumaFile(m_view.slide_luma->checkState());
384
385         connect(m_view.slide_fade, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
386         connect(m_view.slide_luma, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
387         connect(m_view.slide_loop, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
388         connect(m_view.slide_crop, SIGNAL(toggled(bool)), this, SLOT(slotModified()));
389         connect(m_view.slide_duration, SIGNAL(textChanged(QString)), this, SLOT(slotModified()));
390         connect(m_view.slide_duration_frames, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
391         connect(m_view.luma_duration, SIGNAL(textChanged(QString)), this, SLOT(slotModified()));
392         connect(m_view.luma_softness, SIGNAL(valueChanged(int)), this, SLOT(slotModified()));
393         connect(m_view.luma_file, SIGNAL(currentIndexChanged(int)), this, SLOT(slotModified()));
394         connect(m_view.animation, SIGNAL(currentIndexChanged(int)), this, SLOT(slotModified()));
395
396
397         connect(m_view.slide_fade, SIGNAL(stateChanged(int)), this, SLOT(slotEnableLuma(int)));
398         connect(m_view.slide_luma, SIGNAL(stateChanged(int)), this, SLOT(slotEnableLumaFile(int)));
399         connect(m_view.image_type, SIGNAL(currentIndexChanged(int)), this, SLOT(parseFolder()));
400
401     } else if (t != AUDIO) {
402         m_view.tabWidget->removeTab(IMAGETAB);
403         m_view.tabWidget->removeTab(SLIDETAB);
404         m_view.tabWidget->removeTab(COLORTAB);
405
406         PropertiesViewDelegate *del1 = new PropertiesViewDelegate(this);
407         PropertiesViewDelegate *del2 = new PropertiesViewDelegate(this);
408         m_view.clip_vproperties->setItemDelegate(del1);
409         m_view.clip_aproperties->setItemDelegate(del2);
410         m_view.clip_aproperties->setStyleSheet(QString("QTreeWidget { background-color: transparent;}"));
411         m_view.clip_vproperties->setStyleSheet(QString("QTreeWidget { background-color: transparent;}"));
412
413         if (props.contains("videocodec"))
414             new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Video codec") << props.value("videocodec"));
415         else if (props.contains("videocodecid"))
416             new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Video codec") << props.value("videocodecid"));
417
418         if (props.contains("frame_size"))
419             new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Frame size") << props.value("frame_size"));
420
421         if (props.contains("fps")) {
422             new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Frame rate") << props.value("fps"));
423             if (!m_view.clip_framerate->isEnabled()) m_view.clip_framerate->setValue(props.value("fps").toDouble());
424         }
425
426         if (props.contains("progressive")) {
427             int scanning = props.value("progressive").toInt();
428             QString txt = scanning == 1 ? i18n("Progressive") : i18n("Interlaced");
429             new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Scanning") << txt);
430         }
431         
432         if (props.contains("aspect_ratio"))
433             new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Pixel aspect ratio") << props.value("aspect_ratio"));
434
435         if (props.contains("pix_fmt"))
436             new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Pixel format") << props.value("pix_fmt"));
437
438         if (props.contains("colorspace"))
439             new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Colorspace") << ProfilesDialog::getColorspaceDescription(props.value("colorspace").toInt()));
440         
441         m_view.clip_thumb->setMinimumSize(180 * KdenliveSettings::project_display_ratio(), 180);
442         
443         if (t == IMAGE || t == VIDEO || t == PLAYLIST) m_view.tabWidget->removeTab(AUDIOTAB);
444     } else {
445         m_view.tabWidget->removeTab(IMAGETAB);
446         m_view.tabWidget->removeTab(SLIDETAB);
447         m_view.tabWidget->removeTab(COLORTAB);
448         m_view.tabWidget->removeTab(VIDEOTAB);
449         m_view.clip_thumb->setHidden(true);
450     }
451
452     if (t != SLIDESHOW && t != COLOR) {
453         KFileItem f(KFileItem::Unknown, KFileItem::Unknown, url, true);
454         m_view.clip_filesize->setText(KIO::convertSize(f.size()));
455     } else {
456         m_view.clip_filesize->setHidden(true);
457         m_view.label_size->setHidden(true);
458     }
459     m_view.clip_duration->setInputMask(tc.mask());
460     m_view.clip_duration->setText(tc.getTimecode(m_clip->duration()));
461     if (t != IMAGE && t != COLOR && t != TEXT) m_view.clip_duration->setReadOnly(true);
462     else {
463         connect(m_view.clip_duration, SIGNAL(editingFinished()), this, SLOT(slotCheckMaxLength()));
464         connect(m_view.clip_duration, SIGNAL(textChanged(QString)), this, SLOT(slotModified()));
465     }
466
467     // markers
468     m_view.marker_new->setIcon(KIcon("document-new"));
469     m_view.marker_new->setToolTip(i18n("Add marker"));
470     m_view.marker_edit->setIcon(KIcon("document-properties"));
471     m_view.marker_edit->setToolTip(i18n("Edit marker"));
472     m_view.marker_delete->setIcon(KIcon("trash-empty"));
473     m_view.marker_delete->setToolTip(i18n("Delete marker"));
474     m_view.marker_save->setIcon(KIcon("document-save-as"));
475     m_view.marker_save->setToolTip(i18n("Save markers"));
476     m_view.marker_load->setIcon(KIcon("document-open"));
477     m_view.marker_load->setToolTip(i18n("Load markers"));
478     m_view.analysis_delete->setIcon(KIcon("trash-empty"));
479     m_view.analysis_delete->setToolTip(i18n("Delete analysis data"));
480     m_view.analysis_load->setIcon(KIcon("document-open"));
481     m_view.analysis_load->setToolTip(i18n("Load analysis data"));
482     m_view.analysis_save->setIcon(KIcon("document-save-as"));
483     m_view.analysis_save->setToolTip(i18n("Save analysis data"));
484
485         // Check for Nepomuk metadata
486 #ifdef USE_NEPOMUK
487 #if KDE_IS_VERSION(4,6,0)
488     if (!url.isEmpty()) {
489         Nepomuk::ResourceManager::instance()->init();
490         Nepomuk::Resource res( url.path() );
491         // Check if file has a license
492         if (res.hasProperty(Nepomuk::Vocabulary::NIE::license())) {
493             QString ltype = res.property(Nepomuk::Vocabulary::NIE::licenseType()).toString();
494             m_view.clip_license->setText(i18n("License: %1", res.property(Nepomuk::Vocabulary::NIE::license()).toString()));
495             if (ltype.startsWith("http")) {
496                 m_view.clip_license->setUrl(ltype);
497                 connect(m_view.clip_license, SIGNAL(leftClickedUrl(const QString &)), this, SLOT(slotOpenUrl(const QString &)));
498             }
499         }
500         else m_view.clip_license->setHidden(true);
501     }
502     else m_view.clip_license->setHidden(true);
503 #else
504     m_view.clip_license->setHidden(true);
505 #endif
506 #else
507     m_view.clip_license->setHidden(true);
508 #endif
509     
510     slotFillMarkersList(m_clip);
511     slotUpdateAnalysisData(m_clip);
512     
513     connect(m_view.marker_new, SIGNAL(clicked()), this, SLOT(slotAddMarker()));
514     connect(m_view.marker_edit, SIGNAL(clicked()), this, SLOT(slotEditMarker()));
515     connect(m_view.marker_delete, SIGNAL(clicked()), this, SLOT(slotDeleteMarker()));
516     connect(m_view.marker_save, SIGNAL(clicked()), this, SLOT(slotSaveMarkers()));
517     connect(m_view.marker_load, SIGNAL(clicked()), this, SLOT(slotLoadMarkers()));
518     connect(m_view.markers_list, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(slotEditMarker()));
519     
520     connect(m_view.analysis_delete, SIGNAL(clicked()), this, SLOT(slotDeleteAnalysis()));
521     connect(m_view.analysis_save, SIGNAL(clicked()), this, SLOT(slotSaveAnalysis()));
522     connect(m_view.analysis_load, SIGNAL(clicked()), this, SLOT(slotLoadAnalysis()));
523     
524     connect(this, SIGNAL(accepted()), this, SLOT(slotApplyProperties()));
525     connect(m_view.buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(slotApplyProperties()));
526     m_view.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
527     adjustSize();
528 }
529
530
531 // Used for multiple clips editing
532 ClipProperties::ClipProperties(QList <DocClipBase *>cliplist, Timecode tc, QMap <QString, QString> commonproperties, QWidget * parent) :
533     QDialog(parent),
534     m_clip(NULL),
535     m_tc(tc),
536     m_fps(0),
537     m_count(0),
538     m_clipNeedsRefresh(false),
539     m_clipNeedsReLoad(false)
540 {
541     setFont(KGlobalSettings::toolBarFont());
542     m_view.setupUi(this);
543     QString title = windowTitle();
544     title.append(' ' + i18np("(%1 clip)", "(%1 clips)", cliplist.count()));
545     setWindowTitle(title);
546     QMap <QString, QString> props = cliplist.at(0)->properties();
547     m_old_props = commonproperties;
548
549     if (commonproperties.contains("force_aspect_num") && !commonproperties.value("force_aspect_num").isEmpty() && commonproperties.value("force_aspect_den").toInt() > 0) {
550         m_view.clip_force_ar->setChecked(true);
551         m_view.clip_ar_num->setEnabled(true);
552         m_view.clip_ar_den->setEnabled(true);
553         m_view.clip_ar_num->setValue(commonproperties.value("force_aspect_num").toInt());
554         m_view.clip_ar_den->setValue(commonproperties.value("force_aspect_den").toInt());
555     }
556
557     if (commonproperties.contains("force_fps") && !commonproperties.value("force_fps").isEmpty() && commonproperties.value("force_fps").toDouble() > 0) {
558         m_view.clip_force_framerate->setChecked(true);
559         m_view.clip_framerate->setEnabled(true);
560         m_view.clip_framerate->setValue(commonproperties.value("force_fps").toDouble());
561     }
562
563     if (commonproperties.contains("force_progressive") && !commonproperties.value("force_progressive").isEmpty()) {
564         m_view.clip_force_progressive->setChecked(true);
565         m_view.clip_progressive->setEnabled(true);
566         m_view.clip_progressive->setValue(commonproperties.value("force_progressive").toInt());
567     }
568
569     if (commonproperties.contains("force_tff") && !commonproperties.value("force_tff").isEmpty()) {
570         m_view.clip_force_fieldorder->setChecked(true);
571         m_view.clip_fieldorder->setEnabled(true);
572         m_view.clip_fieldorder->setCurrentIndex(commonproperties.value("force_tff").toInt());
573     }
574     
575     if (commonproperties.contains("threads") && !commonproperties.value("threads").isEmpty() && commonproperties.value("threads").toInt() != 1) {
576         m_view.clip_force_threads->setChecked(true);
577         m_view.clip_threads->setEnabled(true);
578         m_view.clip_threads->setValue(commonproperties.value("threads").toInt());
579     }
580
581     if (commonproperties.contains("video_index") && !commonproperties.value("video_index").isEmpty() && commonproperties.value("video_index").toInt() != 0) {
582         m_view.clip_force_vindex->setChecked(true);
583         m_view.clip_vindex->setEnabled(true);
584         m_view.clip_vindex->setValue(commonproperties.value("video_index").toInt());
585     }
586
587     if (commonproperties.contains("audio_index") && !commonproperties.value("audio_index").isEmpty() && commonproperties.value("audio_index").toInt() != 0) {
588         m_view.clip_force_aindex->setChecked(true);
589         m_view.clip_aindex->setEnabled(true);
590         m_view.clip_aindex->setValue(commonproperties.value("audio_index").toInt());
591     }
592
593     if (props.contains("audio_max")) {
594         m_view.clip_aindex->setMaximum(props.value("audio_max").toInt());
595     }
596
597     if (props.contains("video_max")) {
598         m_view.clip_vindex->setMaximum(props.value("video_max").toInt());
599     }
600     
601     m_view.clip_colorspace->addItem(ProfilesDialog::getColorspaceDescription(601), 601);
602     m_view.clip_colorspace->addItem(ProfilesDialog::getColorspaceDescription(709), 709);
603     m_view.clip_colorspace->addItem(ProfilesDialog::getColorspaceDescription(240), 240);
604     
605     if (commonproperties.contains("force_colorspace") && !commonproperties.value("force_colorspace").isEmpty() && commonproperties.value("force_colorspace").toInt() != 0) {
606         m_view.clip_force_colorspace->setChecked(true);
607         m_view.clip_colorspace->setEnabled(true);
608         m_view.clip_colorspace->setCurrentIndex(m_view.clip_colorspace->findData(commonproperties.value("force_colorspace").toInt()));
609     }
610     
611     if (commonproperties.contains("full_luma") && !commonproperties.value("full_luma").isEmpty()) {
612         m_view.clip_full_luma->setChecked(true);
613     }
614     
615     if (commonproperties.contains("transparency")) {
616         // image transparency checkbox
617         int transparency = commonproperties.value("transparency").toInt();
618         if (transparency == 0) {
619             m_view.clip_force_transparency->setChecked(true);
620         }
621         else if (transparency == 1) {
622             m_view.clip_force_transparency->setChecked(true);
623             m_view.clip_transparency->setCurrentIndex(1);
624         }
625     }
626     else {
627         m_view.clip_force_transparency->setHidden(true);
628         m_view.clip_transparency->setHidden(true);
629     }
630     
631
632     connect(m_view.clip_force_transparency, SIGNAL(toggled(bool)), m_view.clip_transparency, SLOT(setEnabled(bool)));
633     connect(m_view.clip_force_ar, SIGNAL(toggled(bool)), m_view.clip_ar_num, SLOT(setEnabled(bool)));
634     connect(m_view.clip_force_ar, SIGNAL(toggled(bool)), m_view.clip_ar_den, SLOT(setEnabled(bool)));
635     connect(m_view.clip_force_progressive, SIGNAL(toggled(bool)), m_view.clip_progressive, SLOT(setEnabled(bool)));
636     connect(m_view.clip_force_threads, SIGNAL(toggled(bool)), m_view.clip_threads, SLOT(setEnabled(bool)));
637     connect(m_view.clip_force_vindex, SIGNAL(toggled(bool)), m_view.clip_vindex, SLOT(setEnabled(bool)));
638     connect(m_view.clip_force_aindex, SIGNAL(toggled(bool)), m_view.clip_aindex, SLOT(setEnabled(bool)));
639     connect(m_view.clip_force_out, SIGNAL(toggled(bool)), m_view.clip_out, SLOT(setEnabled(bool)));
640     connect(m_view.clip_force_colorspace, SIGNAL(toggled(bool)), m_view.clip_colorspace, SLOT(setEnabled(bool)));
641
642     m_view.tabWidget->removeTab(METATAB);
643     m_view.tabWidget->removeTab(MARKERTAB);
644     m_view.tabWidget->removeTab(IMAGETAB);
645     m_view.tabWidget->removeTab(SLIDETAB);
646     m_view.tabWidget->removeTab(COLORTAB);
647     m_view.tabWidget->removeTab(AUDIOTAB);
648     m_view.tabWidget->removeTab(VIDEOTAB);
649
650     m_view.clip_path->setHidden(true);
651     m_view.label_path->setHidden(true);
652     m_view.label_description->setHidden(true);
653     m_view.label_size->setHidden(true);
654     m_view.clip_filesize->setHidden(true);
655     m_view.clip_filesize->setHidden(true);
656     m_view.clip_path->setHidden(true);
657     m_view.clip_description->setHidden(true);
658     m_view.clip_thumb->setHidden(true);
659     m_view.label_duration->setHidden(true);
660     m_view.clip_duration->setHidden(true);
661
662     if (commonproperties.contains("out")) {
663         if (commonproperties.value("out").toInt() > 0) {
664             m_view.clip_force_out->setChecked(true);
665             m_view.clip_out->setText(m_tc.getTimecodeFromFrames(commonproperties.value("out").toInt()));
666         } else m_view.clip_out->setText(KdenliveSettings::image_duration());
667     } else {
668         m_view.clip_force_out->setHidden(true);
669         m_view.clip_out->setHidden(true);
670     }
671 }
672
673 ClipProperties::~ClipProperties()
674 {
675     QAbstractItemDelegate *del1 = m_view.clip_vproperties->itemDelegate();
676     if (del1) delete del1;
677     QAbstractItemDelegate *del2 = m_view.clip_aproperties->itemDelegate();
678     if (del2) delete del2;
679 }
680
681 void ClipProperties::slotGotThumbnail(const QString &id, QImage img)
682 {
683     if (id != m_clip->getId()) return;
684     QPixmap framedPix(img.width(), img.height());
685     framedPix.fill(Qt::transparent);
686     QPainter p(&framedPix);
687     p.setRenderHint(QPainter::Antialiasing, true);
688     QPainterPath path;
689     path.addRoundedRect(0.5, 0.5, framedPix.width() - 1, framedPix.height() - 1, 4, 4);
690     p.setClipPath(path);
691     p.drawImage(0, 0, img);
692     p.end();
693     m_view.clip_thumb->setPixmap(framedPix);
694 }
695
696 void ClipProperties::slotApplyProperties()
697 {
698     if (m_clip != NULL) {
699         QMap <QString, QString> props = properties();
700         emit applyNewClipProperties(m_clip->getId(), m_clip->currentProperties(props), props, needsTimelineRefresh(), needsTimelineReload());
701     }
702     m_view.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
703 }
704
705 void ClipProperties::disableClipId(const QString &id)
706 {
707     if (m_clip && m_view.buttonBox->button(QDialogButtonBox::Ok)->isEnabled()) {
708         if (m_clip->getId() == id) {
709             // clip was removed from project, close this properties dialog
710             close();
711         }
712     }
713 }
714
715 void ClipProperties::slotModified()
716 {
717     m_view.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(true);
718 }
719
720
721 void ClipProperties::slotEnableLuma(int state)
722 {
723     bool enable = false;
724     if (state == Qt::Checked) enable = true;
725     m_view.luma_duration->setEnabled(enable);
726     m_view.luma_duration_frames->setEnabled(enable);
727     m_view.slide_luma->setEnabled(enable);
728     if (enable) {
729         m_view.luma_file->setEnabled(m_view.slide_luma->isChecked());
730     } else m_view.luma_file->setEnabled(false);
731     m_view.label_softness->setEnabled(m_view.slide_luma->isChecked() && enable);
732     m_view.luma_softness->setEnabled(m_view.label_softness->isEnabled());
733 }
734
735 void ClipProperties::slotEnableLumaFile(int state)
736 {
737     bool enable = false;
738     if (state == Qt::Checked) enable = true;
739     m_view.luma_file->setEnabled(enable);
740     m_view.luma_softness->setEnabled(enable);
741     m_view.label_softness->setEnabled(enable);
742 }
743
744 void ClipProperties::slotUpdateAnalysisData(DocClipBase *clip)
745 {
746     if (m_clip != clip) return;
747     m_view.analysis_list->clear();
748     QMap <QString, QString> analysis = clip->analysisData();
749     m_view.analysis_box->setHidden(analysis.isEmpty());
750     QMap<QString, QString>::const_iterator i = analysis.constBegin();
751     while (i != analysis.constEnd()) {
752         QStringList itemtext;
753         itemtext << i.key() << i.value();
754         (void) new QTreeWidgetItem(m_view.analysis_list, itemtext);
755         ++i;
756     }
757 }
758
759 void ClipProperties::slotFillMarkersList(DocClipBase *clip)
760 {
761     if (m_clip != clip) return;
762     m_view.markers_list->clear();
763     QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
764     for (int count = 0; count < marks.count(); ++count) {
765         QString time = m_tc.getTimecode(marks[count].time());
766         QStringList itemtext;
767         itemtext << time << marks.at(count).comment();
768         QTreeWidgetItem *item = new QTreeWidgetItem(m_view.markers_list, itemtext);
769         item->setData(0, Qt::DecorationRole, CommentedTime::markerColor(marks.at(count).markerType()));
770     }
771 }
772
773 void ClipProperties::slotAddMarker()
774 {
775     CommentedTime marker(GenTime(), i18n("Marker"));
776     QPointer<MarkerDialog> d = new MarkerDialog(m_clip, marker,
777                                           m_tc, i18n("Add Marker"), this);
778     if (d->exec() == QDialog::Accepted) {
779         QList <CommentedTime> markers;
780         markers << d->newMarker();
781         emit addMarkers(m_clip->getId(), markers);
782     }
783     delete d;
784 }
785
786 void ClipProperties::slotSaveMarkers()
787 {
788     emit saveMarkers(m_clip->getId());
789 }
790
791 void ClipProperties::slotLoadMarkers()
792 {
793     emit loadMarkers(m_clip->getId());
794 }
795
796 void ClipProperties::slotEditMarker()
797 {
798     QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
799     int pos = m_view.markers_list->currentIndex().row();
800     if (pos < 0 || pos > marks.count() - 1) return;
801     MarkerDialog d(m_clip, marks.at(pos), m_tc, i18n("Edit Marker"), this);
802     if (d.exec() == QDialog::Accepted) {
803         QList <CommentedTime> markers;
804         markers << d.newMarker();
805         emit addMarkers(m_clip->getId(), markers);
806     }
807 }
808
809 void ClipProperties::slotDeleteMarker()
810 {
811     QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
812     QList < CommentedTime > toDelete;
813     for (int i = 0; i < marks.count(); i++) {
814         if (m_view.markers_list->topLevelItem(i)->isSelected()) {
815             CommentedTime marker = marks.at(i);
816             marker.setMarkerType(-1);
817             toDelete << marker;
818         }
819     }
820     emit addMarkers(m_clip->getId(), toDelete);
821 }
822
823 void ClipProperties::slotDeleteAnalysis()
824 {
825     QTreeWidgetItem *current = m_view.analysis_list->currentItem();
826     if (current) emit editAnalysis(m_clip->getId(), current->text(0), QString());
827 }
828
829 void ClipProperties::slotSaveAnalysis()
830 {
831     QString url = KFileDialog::getSaveFileName(KUrl("kfiledialog:///projectfolder"), "text/plain", this, i18n("Save Analysis Data"));
832     if (url.isEmpty()) return;
833     KSharedConfigPtr config = KSharedConfig::openConfig(url, KConfig::SimpleConfig);
834     KConfigGroup analysisConfig(config, "Analysis");
835     QTreeWidgetItem *current = m_view.analysis_list->currentItem();
836     analysisConfig.writeEntry(current->text(0), current->text(1));
837 }
838
839 void ClipProperties::slotLoadAnalysis()
840 {
841     QString url = KFileDialog::getOpenFileName(KUrl("kfiledialog:///projectfolder"), "text/plain", this, i18n("Open Analysis Data"));
842     if (url.isEmpty()) return;
843     KSharedConfigPtr config = KSharedConfig::openConfig(url, KConfig::SimpleConfig);
844     KConfigGroup transConfig(config, "Analysis");
845     // read the entries
846     QMap< QString, QString > profiles = transConfig.entryMap();
847     QMapIterator<QString, QString> i(profiles);
848     while (i.hasNext()) {
849         i.next();
850         emit editAnalysis(m_clip->getId(), i.key(), i.value());
851     }
852 }
853
854 const QString &ClipProperties::clipId() const
855 {
856     return m_clip->getId();
857 }
858
859
860 QMap <QString, QString> ClipProperties::properties()
861 {
862     QMap <QString, QString> props;
863     QLocale locale;
864     CLIPTYPE t = UNKNOWN;
865     if (m_clip != NULL) {
866         t = m_clip->clipType();
867         m_old_props = m_clip->properties();
868     }
869
870     int aspectNumerator = m_view.clip_ar_num->value();
871     int aspectDenominator = m_view.clip_ar_den->value();
872     if (m_view.clip_force_ar->isChecked()) {
873         if (aspectNumerator != m_old_props.value("force_aspect_num").toInt() ||
874             aspectDenominator != m_old_props.value("force_aspect_den").toInt()) {
875             props["force_aspect_num"] = QString::number(aspectNumerator);
876             props["force_aspect_den"] = QString::number(aspectDenominator);
877             props["force_aspect_ratio"].clear();
878             m_clipNeedsRefresh = true;
879         }
880     } else {
881         if (m_old_props.contains("force_aspect_num") && !m_old_props.value("force_aspect_num").isEmpty()) {
882             props["force_aspect_num"].clear();
883             m_clipNeedsRefresh = true;
884         }
885         if (m_old_props.contains("force_aspect_den") && !m_old_props.value("force_aspect_den").isEmpty()) {
886             props["force_aspect_den"].clear();
887             m_clipNeedsRefresh = true;
888         }
889     }
890
891     double fps = m_view.clip_framerate->value();
892     if (m_view.clip_force_framerate->isChecked()) {
893         if (fps != m_old_props.value("force_fps").toDouble()) {
894             props["force_fps"] = locale.toString(fps);
895             m_clipNeedsRefresh = true;
896         }
897     } else if (m_old_props.contains("force_fps") && !m_old_props.value("force_fps").isEmpty()) {
898         props["force_fps"].clear();
899         m_clipNeedsRefresh = true;
900     }
901
902     int progressive = m_view.clip_progressive->value();
903     if (m_view.clip_force_progressive->isChecked()) {
904         if (progressive != m_old_props.value("force_progressive").toInt()) {
905             props["force_progressive"] = QString::number(progressive);
906         }
907     } else if (m_old_props.contains("force_progressive") && !m_old_props.value("force_progressive").isEmpty()) {
908         props["force_progressive"].clear();
909     }
910
911     int fieldOrder = m_view.clip_fieldorder->currentIndex();
912     if (m_view.clip_force_fieldorder->isChecked()) {
913         if (fieldOrder != m_old_props.value("force_tff").toInt()) {
914             props["force_tff"] = QString::number(fieldOrder);
915         }
916     } else if (m_old_props.contains("force_tff") && !m_old_props.value("force_tff").isEmpty()) {
917         props["force_tff"].clear();
918     }
919
920     int threads = m_view.clip_threads->value();
921     if (m_view.clip_force_threads->isChecked()) {
922         if (threads != m_old_props.value("threads").toInt()) {
923             props["threads"] = QString::number(threads);
924         }
925     } else if (m_old_props.contains("threads") && !m_old_props.value("threads").isEmpty()) {
926         props["threads"].clear();
927     }
928
929     int vindex = m_view.clip_vindex->value();
930     if (m_view.clip_force_vindex->isChecked()) {
931         if (vindex != m_old_props.value("video_index").toInt()) {
932             props["video_index"] = QString::number(vindex);
933         }
934     } else if (m_old_props.contains("video_index") && !m_old_props.value("video_index").isEmpty()) {
935         props["video_index"].clear();
936     }
937
938     int aindex = m_view.clip_aindex->value();
939     if (m_view.clip_force_aindex->isChecked()) {
940         if (aindex != m_old_props.value("audio_index").toInt()) {
941             props["audio_index"] = QString::number(aindex);
942         }
943     } else if (m_old_props.contains("audio_index") && !m_old_props.value("audio_index").isEmpty()) {
944         props["audio_index"].clear();
945     }
946     
947     int colorspace = m_view.clip_colorspace->itemData(m_view.clip_colorspace->currentIndex()).toInt();
948     if (m_view.clip_force_colorspace->isChecked()) {
949         if (colorspace != m_old_props.value("force_colorspace").toInt()) {
950             props["force_colorspace"] = QString::number(colorspace);
951             m_clipNeedsRefresh = true;
952         }
953     } else if (m_old_props.contains("force_colorspace") && !m_old_props.value("force_colorspace").isEmpty()) {
954         props["force_colorspace"].clear();
955         m_clipNeedsRefresh = true;
956     }
957
958     if (m_view.clip_full_luma->isChecked()) {
959         props["full_luma"] = QString::number(1);
960         m_clipNeedsRefresh = true;
961     } else if (m_old_props.contains("full_luma") && !m_old_props.value("full_luma").isEmpty()) {
962         props["full_luma"].clear();
963         m_clipNeedsRefresh = true;
964     }
965     
966     if (m_view.clip_force_transparency->isChecked()) {
967         QString transp = QString::number(m_view.clip_transparency->currentIndex());
968         if (transp != m_old_props.value("transparency")) props["transparency"] = transp;
969     }
970
971     // If we adjust several clips, return now
972     if (m_clip == NULL) {
973         if (m_view.clip_out->isEnabled()) {
974             int duration = m_tc.getFrameCount(m_view.clip_out->text());
975             if (duration != m_old_props.value("out").toInt()) {
976                 props["out"] = QString::number(duration - 1);
977             }
978         }
979         return props;
980     }
981
982     if (m_old_props.value("description") != m_view.clip_description->text())
983         props["description"] = m_view.clip_description->text();
984
985     if (t == COLOR) {
986         QString new_color = m_view.clip_color->color().name();
987         if (new_color != QString('#' + m_old_props.value("colour").right(8).left(6))) {
988             m_clipNeedsRefresh = true;
989             props["colour"] = "0x" + new_color.right(6) + "ff";
990         }
991         int duration = m_tc.getFrameCount(m_view.clip_duration->text());
992         if (duration != m_clip->duration().frames(m_fps)) {
993             props["out"] = QString::number(duration - 1);
994         }
995     } else if (t == IMAGE) {
996         if ((int) m_view.image_transparency->isChecked() != m_old_props.value("transparency").toInt()) {
997             props["transparency"] = QString::number((int)m_view.image_transparency->isChecked());
998             //m_clipNeedsRefresh = true;
999         }
1000         int duration = m_tc.getFrameCount(m_view.clip_duration->text());
1001         if (duration != m_clip->duration().frames(m_fps)) {
1002             props["out"] = QString::number(duration - 1);
1003         }
1004     } else if (t == SLIDESHOW) {
1005         QString value = QString::number((int) m_view.slide_loop->isChecked());
1006         if (m_old_props.value("loop") != value) props["loop"] = value;
1007         value = QString::number((int) m_view.slide_crop->isChecked());
1008         if (m_old_props.value("crop") != value) props["crop"] = value;
1009         value = QString::number((int) m_view.slide_fade->isChecked());
1010         if (m_old_props.value("fade") != value) props["fade"] = value;
1011         value = QString::number((int) m_view.luma_softness->value());
1012         if (m_old_props.value("softness") != value) props["softness"] = value;
1013
1014         bool isMime = !(m_view.clip_path->text().contains('%'));
1015         if (isMime) {
1016             QString extension = "/.all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
1017             QString new_path = m_view.clip_path->text() + extension;
1018             if (new_path != m_old_props.value("resource")) {
1019                 m_clipNeedsReLoad = true;
1020                 props["resource"] = new_path;
1021                 kDebug() << "////  SLIDE EDIT, NEW:" << new_path << ", OLD; " << m_old_props.value("resource");
1022             }
1023         }
1024         int duration;
1025         if (m_view.slide_duration_format->currentIndex() == 1) {
1026             // we are in frames mode
1027             duration = m_view.slide_duration_frames->value();
1028         } else duration = m_tc.getFrameCount(m_view.slide_duration->text());
1029         if (duration != m_old_props.value("ttl").toInt()) {
1030             m_clipNeedsRefresh = true;
1031             props["ttl"] = QString::number(duration);
1032             props["length"] = QString::number(duration * m_count);
1033         }
1034
1035         if (duration * m_count - 1 != m_old_props.value("out").toInt()) {
1036             m_clipNeedsRefresh = true;
1037             props["out"] = QString::number(duration * m_count - 1);
1038         }
1039         if (m_view.slide_fade->isChecked()) {
1040             int luma_duration;
1041             if (m_view.slide_duration_format->currentIndex() == 1) {
1042                 // we are in frames mode
1043                 luma_duration = m_view.luma_duration_frames->value();
1044             } else luma_duration = m_tc.getFrameCount(m_view.luma_duration->text());
1045             if (luma_duration != m_old_props.value("luma_duration").toInt()) {
1046                 m_clipNeedsRefresh = true;
1047                 props["luma_duration"] = QString::number(luma_duration);
1048             }
1049             QString lumaFile;
1050             if (m_view.slide_luma->isChecked())
1051                 lumaFile = m_view.luma_file->itemData(m_view.luma_file->currentIndex()).toString();
1052             if (lumaFile != m_old_props.value("luma_file")) {
1053                 m_clipNeedsRefresh = true;
1054                 props["luma_file"] = lumaFile;
1055             }
1056         } else {
1057             if (!m_old_props.value("luma_file").isEmpty()) {
1058                 props["luma_file"].clear();
1059             }
1060         }
1061
1062         QString animation = m_view.animation->itemData(m_view.animation->currentIndex()).toString();
1063         if (animation != m_old_props.value("animation")) {
1064             if (animation.isEmpty()) {
1065                 props["animation"].clear();
1066             } else {
1067                 props["animation"] = animation;
1068             }
1069             m_clipNeedsRefresh = true;
1070         }
1071     }
1072     return props;
1073 }
1074
1075 bool ClipProperties::needsTimelineRefresh() const
1076 {
1077     return m_clipNeedsRefresh;
1078 }
1079
1080 bool ClipProperties::needsTimelineReload() const
1081 {
1082     return m_clipNeedsReLoad;
1083 }
1084
1085
1086 void ClipProperties::parseFolder(bool reloadThumb)
1087 {
1088     QString path = m_view.clip_path->text();
1089     bool isMime = !(path.contains('%'));
1090     if (!isMime) path = KUrl(path).directory();
1091     QDir dir(path);
1092
1093     QStringList filters;
1094     QString extension;
1095
1096     if (isMime) {
1097         // TODO: improve jpeg image detection with extension like jpeg, requires change in MLT image producers
1098         filters << "*." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
1099         extension = "/.all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
1100         dir.setNameFilters(filters);
1101     }
1102
1103     QStringList result = dir.entryList(QDir::Files);
1104
1105     if (!isMime) {
1106         int offset = 0;
1107         QString path = m_view.clip_path->text();
1108         if (path.contains('?')) {
1109             // New MLT syntax
1110             offset = m_view.clip_path->text().section(':', -1).toInt();
1111             path = path.section('?', 0, 0);
1112         }
1113         QString filter = KUrl(path).fileName();
1114         QString ext = filter.section('.', -1);
1115         filter = filter.section('%', 0, -2);
1116         QString regexp = '^' + filter + "\\d+\\." + ext + '$';
1117         QRegExp rx(regexp);
1118         QStringList entries;
1119         int ix;
1120         foreach(const QString & path, result) {
1121             if (rx.exactMatch(path)) {
1122                 if (offset > 0) {
1123                     // make sure our image is in the range we want (> begin)
1124                     ix = path.section(filter, 1).section('.', 0, 0).toInt();
1125                     if (ix < offset) continue;
1126                 }
1127                 entries << path;
1128             }
1129         }
1130         result = entries;
1131     }
1132
1133     m_count = result.count();
1134     m_view.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(m_count > 0);
1135     if (m_count == 0) {
1136         // no images, do not accept that
1137         m_view.slide_info->setText(i18n("No image found"));
1138         m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
1139         return;
1140     }
1141     m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
1142     m_view.slide_info->setText(i18np("1 image found", "%1 images found", m_count));
1143     QMap <QString, QString> props = m_clip->properties();
1144     m_view.clip_duration->setText(m_tc.getTimecodeFromFrames(props.value("ttl").toInt() * m_count));
1145     if (reloadThumb) {
1146         int width = 180.0 * KdenliveSettings::project_display_ratio();
1147         if (width % 2 == 1) width++;
1148         QString filePath = m_view.clip_path->text();
1149         if (isMime) filePath.append(extension);
1150         QPixmap pix = m_clip->thumbProducer()->getImage(KUrl(filePath), 1, width, 180);
1151         m_view.clip_thumb->setPixmap(pix);
1152     }
1153 }
1154
1155 void ClipProperties::slotCheckMaxLength()
1156 {
1157     if (m_clip->maxDuration() == GenTime()) return;
1158     int duration = m_tc.getFrameCount(m_view.clip_duration->text());
1159     if (duration > m_clip->maxDuration().frames(m_fps)) {
1160         m_view.clip_duration->setText(m_tc.getTimecode(m_clip->maxDuration()));
1161     }
1162 }
1163
1164 void ClipProperties::slotUpdateDurationFormat(int ix)
1165 {
1166     bool framesFormat = ix == 1;
1167     if (framesFormat) {
1168         // switching to frames count, update widget
1169         m_view.slide_duration_frames->setValue(m_tc.getFrameCount(m_view.slide_duration->text()));
1170         m_view.luma_duration_frames->setValue(m_tc.getFrameCount(m_view.luma_duration->text()));
1171         m_view.slide_duration->setHidden(true);
1172         m_view.luma_duration->setHidden(true);
1173         m_view.slide_duration_frames->setHidden(false);
1174         m_view.luma_duration_frames->setHidden(false);
1175     } else {
1176         // switching to timecode format
1177         m_view.slide_duration->setText(m_tc.getTimecodeFromFrames(m_view.slide_duration_frames->value()));
1178         m_view.luma_duration->setText(m_tc.getTimecodeFromFrames(m_view.luma_duration_frames->value()));
1179         m_view.slide_duration_frames->setHidden(true);
1180         m_view.luma_duration_frames->setHidden(true);
1181         m_view.slide_duration->setHidden(false);
1182         m_view.luma_duration->setHidden(false);
1183     }
1184 }
1185
1186 void ClipProperties::slotDeleteProxy()
1187 {
1188       QString proxy = m_clip->getProperty("proxy");
1189       if (proxy.isEmpty()) return;
1190       emit deleteProxy(proxy);
1191       if (m_proxyContainer) delete m_proxyContainer;
1192 }
1193
1194 void ClipProperties::slotOpenUrl(const QString &url)
1195 {
1196     new KRun(KUrl(url), this);
1197 }
1198
1199 #include "clipproperties.moc"
1200
1201
1202