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