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