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