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