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