]> git.sesse.net Git - kdenlive/blob - src/projectlist.cpp
Add field order override in advanced clip properties.
[kdenlive] / src / projectlist.cpp
1 /***************************************************************************
2  *   Copyright (C) 2007 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 #include "projectlist.h"
21 #include "projectitem.h"
22 #include "addfoldercommand.h"
23 #include "kdenlivesettings.h"
24 #include "slideshowclip.h"
25 #include "ui_colorclip_ui.h"
26 #include "titlewidget.h"
27 #include "definitions.h"
28 #include "clipmanager.h"
29 #include "docclipbase.h"
30 #include "kdenlivedoc.h"
31 #include "renderer.h"
32 #include "kthumb.h"
33 #include "projectlistview.h"
34 #include "timecodedisplay.h"
35 #include "profilesdialog.h"
36 #include "editclipcommand.h"
37 #include "editclipcutcommand.h"
38 #include "editfoldercommand.h"
39 #include "addclipcutcommand.h"
40
41 #include "ui_templateclip_ui.h"
42
43 #include <KDebug>
44 #include <KAction>
45 #include <KLocale>
46 #include <KFileDialog>
47 #include <KInputDialog>
48 #include <KMessageBox>
49 #include <KIO/NetAccess>
50 #include <KFileItem>
51 #include <KApplication>
52 #ifdef NEPOMUK
53 #include <nepomuk/global.h>
54 #include <nepomuk/resourcemanager.h>
55 //#include <nepomuk/tag.h>
56 #endif
57
58 #include <QMouseEvent>
59 #include <QStylePainter>
60 #include <QPixmap>
61 #include <QIcon>
62 #include <QMenu>
63 #include <QProcess>
64 #include <QHeaderView>
65 #include <QInputDialog>
66
67 ProjectList::ProjectList(QWidget *parent) :
68     QWidget(parent),
69     m_render(NULL),
70     m_fps(-1),
71     m_commandStack(NULL),
72     m_openAction(NULL),
73     m_reloadAction(NULL),
74     m_transcodeAction(NULL),
75     m_doc(NULL),
76     m_refreshed(false),
77     m_infoQueue(),
78     m_thumbnailQueue()
79 {
80     QVBoxLayout *layout = new QVBoxLayout;
81     layout->setContentsMargins(0, 0, 0, 0);
82     layout->setSpacing(0);
83
84     // setup toolbar
85     QFrame *frame = new QFrame;
86     frame->setFrameStyle(QFrame::NoFrame);
87     QHBoxLayout *box = new QHBoxLayout;
88     KTreeWidgetSearchLine *searchView = new KTreeWidgetSearchLine;
89
90     box->addWidget(searchView);
91     //int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
92     //m_toolbar->setIconSize(QSize(s, s));
93
94     m_addButton = new QToolButton;
95     m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
96     m_addButton->setAutoRaise(true);
97     box->addWidget(m_addButton);
98
99     m_editButton = new QToolButton;
100     m_editButton->setAutoRaise(true);
101     box->addWidget(m_editButton);
102
103     m_deleteButton = new QToolButton;
104     m_deleteButton->setAutoRaise(true);
105     box->addWidget(m_deleteButton);
106     frame->setLayout(box);
107     layout->addWidget(frame);
108
109     m_listView = new ProjectListView;
110     layout->addWidget(m_listView);
111     setLayout(layout);
112     searchView->setTreeWidget(m_listView);
113
114     m_queueTimer.setInterval(100);
115     connect(&m_queueTimer, SIGNAL(timeout()), this, SLOT(slotProcessNextClipInQueue()));
116     m_queueTimer.setSingleShot(true);
117
118
119     connect(m_listView, SIGNAL(projectModified()), this, SIGNAL(projectModified()));
120     connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
121     connect(m_listView, SIGNAL(focusMonitor()), this, SLOT(slotClipSelected()));
122     connect(m_listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
123     connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
124     connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
125     connect(m_listView, SIGNAL(addClip(const QList <QUrl>, const QString &, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &, const QString &)));
126     connect(m_listView, SIGNAL(addClipCut(const QString &, int, int)), this, SLOT(slotAddClipCut(const QString &, int, int)));
127     connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
128     connect(m_listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
129
130     m_listViewDelegate = new ItemDelegate(m_listView);
131     m_listView->setItemDelegate(m_listViewDelegate);
132 #ifdef NEPOMUK
133     if (KdenliveSettings::activate_nepomuk()) {
134         Nepomuk::ResourceManager::instance()->init();
135         if (!Nepomuk::ResourceManager::instance()->initialized()) {
136             kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
137             KdenliveSettings::setActivate_nepomuk(false);
138         }
139     }
140 #endif
141 }
142
143 ProjectList::~ProjectList()
144 {
145     delete m_menu;
146     m_listView->blockSignals(true);
147     m_listView->clear();
148     delete m_listViewDelegate;
149 }
150
151 void ProjectList::focusTree() const
152 {
153     m_listView->setFocus();
154 }
155
156 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
157 {
158     QList <QAction *> actions = addMenu->actions();
159     for (int i = 0; i < actions.count(); i++) {
160         if (actions.at(i)->data().toString() == "clip_properties") {
161             m_editButton->setDefaultAction(actions.at(i));
162             actions.removeAt(i);
163             i--;
164         } else if (actions.at(i)->data().toString() == "delete_clip") {
165             m_deleteButton->setDefaultAction(actions.at(i));
166             actions.removeAt(i);
167             i--;
168         } else if (actions.at(i)->data().toString() == "edit_clip") {
169             m_openAction = actions.at(i);
170             actions.removeAt(i);
171             i--;
172         } else if (actions.at(i)->data().toString() == "reload_clip") {
173             m_reloadAction = actions.at(i);
174             actions.removeAt(i);
175             i--;
176         }
177     }
178
179     QMenu *m = new QMenu();
180     m->addActions(actions);
181     m_addButton->setMenu(m);
182     m_addButton->setDefaultAction(defaultAction);
183     m_menu = new QMenu();
184     m_menu->addActions(addMenu->actions());
185 }
186
187 void ProjectList::setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu, QMenu *inTimelineMenu)
188 {
189     if (!addMenu)
190         return;
191     QMenu *menu = m_addButton->menu();
192     menu->addMenu(addMenu);
193     m_addButton->setMenu(menu);
194
195     m_menu->addMenu(addMenu);
196     if (addMenu->isEmpty())
197         addMenu->setEnabled(false);
198     m_menu->addMenu(transcodeMenu);
199     if (transcodeMenu->isEmpty())
200         transcodeMenu->setEnabled(false);
201     m_transcodeAction = transcodeMenu;
202     m_menu->addAction(m_reloadAction);
203     m_menu->addMenu(inTimelineMenu);
204     inTimelineMenu->setEnabled(false);
205     m_menu->addAction(m_editButton->defaultAction());
206     m_menu->addAction(m_openAction);
207     m_menu->addAction(m_deleteButton->defaultAction());
208     m_menu->insertSeparator(m_deleteButton->defaultAction());
209 }
210
211
212 QByteArray ProjectList::headerInfo() const
213 {
214     return m_listView->header()->saveState();
215 }
216
217 void ProjectList::setHeaderInfo(const QByteArray &state)
218 {
219     m_listView->header()->restoreState(state);
220 }
221
222 void ProjectList::updateProjectFormat(Timecode t)
223 {
224     m_timecode = t;
225 }
226
227 void ProjectList::slotEditClip()
228 {
229     QList<QTreeWidgetItem *> list = m_listView->selectedItems();
230     if (list.count() > 1) {
231         editClipSelection(list);
232         return;
233     }
234     ProjectItem *item;
235     if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
236         return;
237     if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE)
238         item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
239     else
240         item = static_cast <ProjectItem*>(m_listView->currentItem());
241     if (item && (item->flags() & Qt::ItemIsDragEnabled)) {
242         emit clipSelected(item->referencedClip());
243         emit showClipProperties(item->referencedClip());
244     }
245 }
246
247 void ProjectList::editClipSelection(QList<QTreeWidgetItem *> list)
248 {
249     // Gather all common properties
250     QMap <QString, QString> commonproperties;
251     QList <DocClipBase *> clipList;
252     commonproperties.insert("force_aspect_num", "-");
253     commonproperties.insert("force_aspect_den", "-");
254     commonproperties.insert("force_fps", "-");
255     commonproperties.insert("force_progressive", "-");
256     commonproperties.insert("force_tff", "-");
257     commonproperties.insert("threads", "-");
258     commonproperties.insert("video_index", "-");
259     commonproperties.insert("audio_index", "-");
260     commonproperties.insert("force_colorspace", "-");
261     commonproperties.insert("full_luma", "-");
262
263     bool allowDurationChange = true;
264     int commonDuration = -1;
265     ProjectItem *item;
266     for (int i = 0; i < list.count(); i++) {
267         item = NULL;
268         if (list.at(i)->type() == PROJECTFOLDERTYPE)
269             continue;
270         if (list.at(i)->type() == PROJECTSUBCLIPTYPE)
271             item = static_cast <ProjectItem*>(list.at(i)->parent());
272         else
273             item = static_cast <ProjectItem*>(list.at(i));
274         if (!(item->flags() & Qt::ItemIsDragEnabled))
275             continue;
276         if (item) {
277             // check properties
278             DocClipBase *clip = item->referencedClip();
279             if (clipList.contains(clip)) continue;
280             if (clip->clipType() != COLOR && clip->clipType() != IMAGE && clip->clipType() != TEXT)
281                 allowDurationChange = false;
282             if (allowDurationChange && commonDuration != 0) {
283                 if (commonDuration == -1)
284                     commonDuration = clip->duration().frames(m_fps);
285                 else if (commonDuration != clip->duration().frames(m_fps))
286                     commonDuration = 0;
287             }
288             clipList.append(clip);
289             QMap <QString, QString> clipprops = clip->properties();
290             QMapIterator<QString, QString> p(commonproperties);
291             while (p.hasNext()) {
292                 p.next();
293                 if (p.value().isEmpty()) continue;
294                 if (clipprops.contains(p.key())) {
295                     if (p.value() == "-")
296                         commonproperties.insert(p.key(), clipprops.value(p.key()));
297                     else if (p.value() != clipprops.value(p.key()))
298                         commonproperties.insert(p.key(), QString());
299                 } else {
300                     commonproperties.insert(p.key(), QString());
301                 }
302             }
303         }
304     }
305     if (allowDurationChange)
306         commonproperties.insert("out", QString::number(commonDuration));
307     QMapIterator<QString, QString> p(commonproperties);
308     while (p.hasNext()) {
309         p.next();
310         kDebug() << "Result: " << p.key() << " = " << p.value();
311     }
312     emit showClipProperties(clipList, commonproperties);
313 }
314
315 void ProjectList::slotOpenClip()
316 {
317     ProjectItem *item;
318     if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
319         return;
320     if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1)
321         item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
322     else
323         item = static_cast <ProjectItem*>(m_listView->currentItem());
324     if (item) {
325         if (item->clipType() == IMAGE) {
326             if (KdenliveSettings::defaultimageapp().isEmpty())
327                 KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open images in the Settings dialog"));
328             else
329                 QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
330         }
331         if (item->clipType() == AUDIO) {
332             if (KdenliveSettings::defaultaudioapp().isEmpty())
333                 KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open audio files in the Settings dialog"));
334             else
335                 QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
336         }
337     }
338 }
339
340 void ProjectList::cleanup()
341 {
342     m_listView->clearSelection();
343     QTreeWidgetItemIterator it(m_listView);
344     ProjectItem *item;
345     while (*it) {
346         if ((*it)->type() != PROJECTCLIPTYPE) {
347             it++;
348             continue;
349         }
350         item = static_cast <ProjectItem *>(*it);
351         if (item->numReferences() == 0)
352             item->setSelected(true);
353         it++;
354     }
355     slotRemoveClip();
356 }
357
358 void ProjectList::trashUnusedClips()
359 {
360     QTreeWidgetItemIterator it(m_listView);
361     ProjectItem *item;
362     QStringList ids;
363     QStringList urls;
364     while (*it) {
365         if ((*it)->type() != PROJECTCLIPTYPE) {
366             it++;
367             continue;
368         }
369         item = static_cast <ProjectItem *>(*it);
370         if (item->numReferences() == 0) {
371             ids << item->clipId();
372             KUrl url = item->clipUrl();
373             if (!url.isEmpty() && !urls.contains(url.path()))
374                 urls << url.path();
375         }
376         it++;
377     }
378
379     // Check that we don't use the URL in another clip
380     QTreeWidgetItemIterator it2(m_listView);
381     while (*it2) {
382         if ((*it2)->type() != PROJECTCLIPTYPE) {
383             it2++;
384             continue;
385         }
386         item = static_cast <ProjectItem *>(*it2);
387         if (item->numReferences() > 0) {
388             KUrl url = item->clipUrl();
389             if (!url.isEmpty() && urls.contains(url.path())) urls.removeAll(url.path());
390         }
391         it2++;
392     }
393
394     emit deleteProjectClips(ids, QMap <QString, QString>());
395     for (int i = 0; i < urls.count(); i++)
396         KIO::NetAccess::del(KUrl(urls.at(i)), this);
397 }
398
399 void ProjectList::slotReloadClip(const QString &id)
400 {
401     QList<QTreeWidgetItem *> selected;
402     if (id.isEmpty())
403         selected = m_listView->selectedItems();
404     else
405         selected.append(getItemById(id));
406     ProjectItem *item;
407     for (int i = 0; i < selected.count(); i++) {
408         if (selected.at(i)->type() != PROJECTCLIPTYPE) {
409             if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
410                 for (int j = 0; j < selected.at(i)->childCount(); j++)
411                     selected.append(selected.at(i)->child(j));
412             }
413             continue;
414         }
415         item = static_cast <ProjectItem *>(selected.at(i));
416         if (item) {
417             if (item->clipType() == TEXT) {
418                 if (!item->referencedClip()->getProperty("xmltemplate").isEmpty())
419                     regenerateTemplate(item);
420             } else if (item->clipType() != COLOR && item->clipType() != SLIDESHOW && item->referencedClip() &&  item->referencedClip()->checkHash() == false) {
421                 item->referencedClip()->setPlaceHolder(true);
422                 item->setProperty("file_hash", QString());
423             } else if (item->clipType() == IMAGE) {
424                 item->referencedClip()->producer()->set("force_reload", 1);
425             }
426             //requestClipInfo(item->toXml(), item->clipId(), true);
427             // Clear the file_hash value, which will cause a complete reload of the clip
428             emit getFileProperties(item->toXml(), item->clipId(), m_listView->iconSize().height(), true);
429         }
430     }
431 }
432
433 void ProjectList::slotModifiedClip(const QString &id)
434 {
435     ProjectItem *item = getItemById(id);
436     if (item) {
437         QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
438         if (!pixmap.isNull()) {
439             QPainter p(&pixmap);
440             p.fillRect(0, 0, pixmap.width(), pixmap.height(), QColor(255, 255, 255, 200));
441             p.drawPixmap(0, 0, KIcon("view-refresh").pixmap(m_listView->iconSize()));
442             p.end();
443         } else {
444             pixmap = KIcon("view-refresh").pixmap(m_listView->iconSize());
445         }
446         item->setData(0, Qt::DecorationRole, pixmap);
447     }
448 }
449
450 void ProjectList::slotMissingClip(const QString &id)
451 {
452     ProjectItem *item = getItemById(id);
453     if (item) {
454         item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
455         if (item->referencedClip()) {
456             item->referencedClip()->setPlaceHolder(true);
457             if (m_render == NULL) kDebug() << "*********  ERROR, NULL RENDR";
458             item->referencedClip()->setProducer(m_render->invalidProducer(id), true);
459             item->slotSetToolTip();
460             emit clipNeedsReload(id, true);
461         }
462     }
463     update();
464     emit displayMessage(i18n("Check missing clips"), -2);
465     emit updateRenderStatus();
466 }
467
468 void ProjectList::slotAvailableClip(const QString &id)
469 {
470     ProjectItem *item = getItemById(id);
471     if (item == NULL)
472         return;
473     item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
474     if (item->referencedClip()) { // && item->referencedClip()->checkHash() == false) {
475         item->setProperty("file_hash", QString());
476         slotReloadClip(id);
477     }
478     /*else {
479     item->referencedClip()->setValid();
480     item->slotSetToolTip();
481     }
482     update();*/
483     emit updateRenderStatus();
484 }
485
486 bool ProjectList::hasMissingClips()
487 {
488     bool missing = false;
489     QTreeWidgetItemIterator it(m_listView);
490     while (*it) {
491         if ((*it)->type() == PROJECTCLIPTYPE && !((*it)->flags() & Qt::ItemIsDragEnabled)) {
492             missing = true;
493             break;
494         }
495         it++;
496     }
497     return missing;
498 }
499
500 void ProjectList::setRenderer(Render *projectRender)
501 {
502     m_render = projectRender;
503     m_listView->setIconSize(QSize((ProjectItem::itemDefaultHeight() - 2) * m_render->dar(), ProjectItem::itemDefaultHeight() - 2));
504 }
505
506 void ProjectList::slotClipSelected()
507 {
508     if (!m_listView->isEnabled()) return;
509     if (m_listView->currentItem()) {
510         if (m_listView->currentItem()->type() == PROJECTFOLDERTYPE) {
511             emit clipSelected(NULL);
512             m_editButton->defaultAction()->setEnabled(false);
513             m_deleteButton->defaultAction()->setEnabled(true);
514             m_openAction->setEnabled(false);
515             m_reloadAction->setEnabled(false);
516             m_transcodeAction->setEnabled(false);
517         } else {
518             ProjectItem *clip;
519             if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
520                 // this is a sub item, use base clip
521                 m_deleteButton->defaultAction()->setEnabled(true);
522                 clip = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
523                 if (clip == NULL) kDebug() << "-----------ERROR";
524                 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
525                 emit clipSelected(clip->referencedClip(), sub->zone());
526                 m_transcodeAction->setEnabled(false);
527                 return;
528             }
529             clip = static_cast <ProjectItem*>(m_listView->currentItem());
530             if (clip)
531                 emit clipSelected(clip->referencedClip());
532             m_editButton->defaultAction()->setEnabled(true);
533             m_deleteButton->defaultAction()->setEnabled(true);
534             m_reloadAction->setEnabled(true);
535             m_transcodeAction->setEnabled(true);
536             if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
537                 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
538                 m_openAction->setEnabled(true);
539             } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
540                 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
541                 m_openAction->setEnabled(true);
542             } else {
543                 m_openAction->setEnabled(false);
544             }
545             // Display relevant transcoding actions only
546             adjustTranscodeActions(clip);
547             // Display uses in timeline
548             emit findInTimeline(clip->clipId());
549         }
550     } else {
551         emit clipSelected(NULL);
552         m_editButton->defaultAction()->setEnabled(false);
553         m_deleteButton->defaultAction()->setEnabled(false);
554         m_openAction->setEnabled(false);
555         m_reloadAction->setEnabled(false);
556         m_transcodeAction->setEnabled(false);
557     }
558 }
559
560 void ProjectList::adjustTranscodeActions(ProjectItem *clip) const
561 {
562     if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW) {
563         m_transcodeAction->setEnabled(false);
564         return;
565     }
566     m_transcodeAction->setEnabled(true);
567     QList<QAction *> transcodeActions = m_transcodeAction->actions();
568     QStringList data;
569     QString condition;
570     for (int i = 0; i < transcodeActions.count(); i++) {
571         data = transcodeActions.at(i)->data().toStringList();
572         if (data.count() > 2) {
573             condition = data.at(2);
574             if (condition.startsWith("vcodec"))
575                 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
576             else if (condition.startsWith("acodec"))
577                 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
578         }
579     }
580
581 }
582
583 void ProjectList::slotPauseMonitor()
584 {
585     if (m_render)
586         m_render->pause();
587 }
588
589 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
590 {
591     ProjectItem *item = getItemById(id);
592     if (item) {
593         slotUpdateClipProperties(item, properties);
594         if (properties.contains("out") || properties.contains("force_fps") || properties.contains("resource")) {
595             slotReloadClip(id);
596         } else if (properties.contains("colour") ||
597                    properties.contains("xmldata") ||
598                    properties.contains("force_aspect_num") ||
599                    properties.contains("force_aspect_den") ||
600                    properties.contains("templatetext")) {
601             slotRefreshClipThumbnail(item);
602             emit refreshClip();
603         } else if (properties.contains("full_luma") || properties.contains("force_colorspace")) {
604             emit refreshClip();
605         }
606     }
607 }
608
609 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
610 {
611     if (!clip)
612         return;
613     clip->setProperties(properties);
614     if (properties.contains("name")) {
615         m_listView->blockSignals(true);
616         clip->setText(0, properties.value("name"));
617         m_listView->blockSignals(false);
618         emit clipNameChanged(clip->clipId(), properties.value("name"));
619     }
620     if (properties.contains("description")) {
621         CLIPTYPE type = clip->clipType();
622         m_listView->blockSignals(true);
623         clip->setText(1, properties.value("description"));
624         m_listView->blockSignals(false);
625 #ifdef NEPOMUK
626         if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
627             // Use Nepomuk system to store clip description
628             Nepomuk::Resource f(clip->clipUrl().path());
629             f.setDescription(properties.value("description"));
630         }
631 #endif
632         emit projectModified();
633     }
634 }
635
636 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
637 {
638     if (item->type() == PROJECTSUBCLIPTYPE) {
639         // this is a sub-item
640         if (column == 1) {
641             // user edited description
642             SubProjectItem *sub = static_cast <SubProjectItem*>(item);
643             ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
644             EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), sub->zone(), sub->description(), sub->text(1), true);
645             m_commandStack->push(command);
646             //slotUpdateCutClipProperties(sub->clipId(), sub->zone(), sub->text(1), sub->text(1));
647         }
648         return;
649     }
650     if (item->type() == PROJECTFOLDERTYPE) {
651         if (column == 0) {
652             FolderProjectItem *folder = static_cast <FolderProjectItem*>(item);
653             editFolder(item->text(0), folder->groupName(), folder->clipId());
654             folder->setGroupName(item->text(0));
655             m_doc->clipManager()->addFolder(folder->clipId(), item->text(0));
656             const int children = item->childCount();
657             for (int i = 0; i < children; i++) {
658                 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
659                 child->setProperty("groupname", item->text(0));
660             }
661         }
662         return;
663     }
664
665     ProjectItem *clip = static_cast <ProjectItem*>(item);
666     if (column == 1) {
667         if (clip->referencedClip()) {
668             QMap <QString, QString> oldprops;
669             QMap <QString, QString> newprops;
670             oldprops["description"] = clip->referencedClip()->getProperty("description");
671             newprops["description"] = item->text(1);
672
673             if (clip->clipType() == TEXT) {
674                 // This is a text template clip, update the image
675                 /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
676                 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/
677                 oldprops.insert("templatetext", clip->referencedClip()->getProperty("templatetext"));
678                 newprops.insert("templatetext", item->text(1));
679             }
680             slotUpdateClipProperties(clip->clipId(), newprops);
681             EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
682             m_commandStack->push(command);
683         }
684     } else if (column == 0) {
685         if (clip->referencedClip()) {
686             QMap <QString, QString> oldprops;
687             QMap <QString, QString> newprops;
688             oldprops["name"] = clip->referencedClip()->getProperty("name");
689             newprops["name"] = item->text(0);
690             slotUpdateClipProperties(clip, newprops);
691             emit projectModified();
692             EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
693             m_commandStack->push(command);
694         }
695     }
696 }
697
698 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
699 {
700     bool enable = item ? true : false;
701     m_editButton->defaultAction()->setEnabled(enable);
702     m_deleteButton->defaultAction()->setEnabled(enable);
703     m_reloadAction->setEnabled(enable);
704     m_transcodeAction->setEnabled(enable);
705     if (enable) {
706         ProjectItem *clip = NULL;
707         if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
708             clip = static_cast <ProjectItem*>(item->parent());
709             m_transcodeAction->setEnabled(false);
710         } else if (m_listView->currentItem()->type() == PROJECTCLIPTYPE) {
711             clip = static_cast <ProjectItem*>(item);
712             // Display relevant transcoding actions only
713             adjustTranscodeActions(clip);
714             // Display uses in timeline
715             emit findInTimeline(clip->clipId());
716         } else {
717             m_transcodeAction->setEnabled(false);
718         }
719         if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
720             m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
721             m_openAction->setEnabled(true);
722         } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
723             m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
724             m_openAction->setEnabled(true);
725         } else {
726             m_openAction->setEnabled(false);
727         }
728
729     } else {
730         m_openAction->setEnabled(false);
731     }
732     m_menu->popup(pos);
733 }
734
735 void ProjectList::slotRemoveClip()
736 {
737     if (!m_listView->currentItem())
738         return;
739     QStringList ids;
740     QMap <QString, QString> folderids;
741     QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
742
743     QUndoCommand *delCommand = new QUndoCommand();
744     delCommand->setText(i18n("Delete Clip Zone"));
745     for (int i = 0; i < selected.count(); i++) {
746         if (selected.at(i)->type() == PROJECTSUBCLIPTYPE) {
747             // subitem
748             SubProjectItem *sub = static_cast <SubProjectItem *>(selected.at(i));
749             ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
750             new AddClipCutCommand(this, item->clipId(), sub->zone().x(), sub->zone().y(), sub->description(), false, true, delCommand);
751         } else if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
752             // folder
753             FolderProjectItem *folder = static_cast <FolderProjectItem *>(selected.at(i));
754             folderids[folder->groupName()] = folder->clipId();
755             int children = folder->childCount();
756
757             if (children > 0 && KMessageBox::questionYesNo(kapp->activeWindow(), i18np("Delete folder <b>%2</b>?<br />This will also remove the clip in that folder", "Delete folder <b>%2</b>?<br />This will also remove the %1 clips in that folder",  children, folder->text(1)), i18n("Delete Folder")) != KMessageBox::Yes)
758                 return;
759             for (int i = 0; i < children; ++i) {
760                 ProjectItem *child = static_cast <ProjectItem *>(folder->child(i));
761                 ids << child->clipId();
762             }
763         } else {
764             ProjectItem *item = static_cast <ProjectItem *>(selected.at(i));
765             ids << item->clipId();
766             if (item->numReferences() > 0 && KMessageBox::questionYesNo(kapp->activeWindow(), i18np("Delete clip <b>%2</b>?<br />This will also remove the clip in timeline", "Delete clip <b>%2</b>?<br />This will also remove its %1 clips in timeline", item->numReferences(), item->names().at(1)), i18n("Delete Clip"), KStandardGuiItem::yes(), KStandardGuiItem::no(), "DeleteAll") == KMessageBox::No) {
767                 KMessageBox::enableMessage("DeleteAll");
768                 return;
769             }
770         }
771     }
772     KMessageBox::enableMessage("DeleteAll");
773     if (delCommand->childCount() == 0)
774         delete delCommand;
775     else
776         m_commandStack->push(delCommand);
777     emit deleteProjectClips(ids, folderids);
778 }
779
780 void ProjectList::updateButtons() const
781 {
782     if (m_listView->topLevelItemCount() == 0) {
783         m_deleteButton->defaultAction()->setEnabled(false);
784     } else {
785         m_deleteButton->defaultAction()->setEnabled(true);
786         if (!m_listView->currentItem())
787             m_listView->setCurrentItem(m_listView->topLevelItem(0));
788         QTreeWidgetItem *item = m_listView->currentItem();
789         if (item && item->type() == PROJECTCLIPTYPE) {
790             m_editButton->defaultAction()->setEnabled(true);
791             m_openAction->setEnabled(true);
792             m_reloadAction->setEnabled(true);
793             m_transcodeAction->setEnabled(true);
794             return;
795         }
796     }
797
798     m_editButton->defaultAction()->setEnabled(false);
799     m_openAction->setEnabled(false);
800     m_reloadAction->setEnabled(false);
801     m_transcodeAction->setEnabled(false);
802 }
803
804 void ProjectList::selectItemById(const QString &clipId)
805 {
806     ProjectItem *item = getItemById(clipId);
807     if (item)
808         m_listView->setCurrentItem(item);
809 }
810
811
812 void ProjectList::slotDeleteClip(const QString &clipId)
813 {
814     ProjectItem *item = getItemById(clipId);
815     if (!item) {
816         kDebug() << "/// Cannot find clip to delete";
817         return;
818     }
819     m_listView->blockSignals(true);
820     QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
821     if (!newSelectedItem)
822         newSelectedItem = m_listView->itemBelow(item);
823     delete item;
824     m_doc->clipManager()->deleteClip(clipId);
825     m_listView->blockSignals(false);
826     if (newSelectedItem) {
827         m_listView->setCurrentItem(newSelectedItem);
828     } else {
829         updateButtons();
830         emit clipSelected(NULL);
831     }
832 }
833
834
835 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
836 {
837     EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
838     m_commandStack->push(command);
839     m_doc->setModified(true);
840 }
841
842 void ProjectList::slotAddFolder()
843 {
844     AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
845     m_commandStack->push(command);
846 }
847
848 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
849 {
850     if (remove) {
851         FolderProjectItem *item = getFolderItemById(clipId);
852         if (item) {
853             m_doc->clipManager()->deleteFolder(clipId);
854             QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
855             if (!newSelectedItem)
856                 newSelectedItem = m_listView->itemBelow(item);
857             delete item;
858             if (newSelectedItem)
859                 m_listView->setCurrentItem(newSelectedItem);
860             else
861                 updateButtons();
862         }
863     } else {
864         if (edit) {
865             FolderProjectItem *item = getFolderItemById(clipId);
866             if (item) {
867                 m_listView->blockSignals(true);
868                 item->setGroupName(foldername);
869                 m_listView->blockSignals(false);
870                 m_doc->clipManager()->addFolder(clipId, foldername);
871                 const int children = item->childCount();
872                 for (int i = 0; i < children; i++) {
873                     ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
874                     child->setProperty("groupname", foldername);
875                 }
876             }
877         } else {
878             m_listView->blockSignals(true);
879             m_listView->setCurrentItem(new FolderProjectItem(m_listView, QStringList() << foldername, clipId));
880             m_doc->clipManager()->addFolder(clipId, foldername);
881             m_listView->blockSignals(false);
882             m_listView->editItem(m_listView->currentItem(), 0);
883         }
884         updateButtons();
885     }
886     m_doc->setModified(true);
887 }
888
889
890
891 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
892 {
893     QMapIterator<QString, QString> i(map);
894     QUndoCommand *delCommand = new QUndoCommand();
895     delCommand->setText(i18n("Delete Folder"));
896     while (i.hasNext()) {
897         i.next();
898         new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
899     }
900     m_commandStack->push(delCommand);
901 }
902
903 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
904 {
905     m_listView->setEnabled(false);
906     if (getProperties) {
907         m_listView->blockSignals(true);
908         m_refreshed = false;
909         // remove file_hash so that we load all properties for the clip
910         QDomElement e = clip->toXML().cloneNode().toElement();
911         e.removeAttribute("file_hash");
912         m_infoQueue.insert(clip->getId(), e);
913         //m_render->getFileProperties(clip->toXML(), clip->getId(), true);
914     }
915     clip->askForAudioThumbs();
916     const QString parent = clip->getProperty("groupid");
917     ProjectItem *item = NULL;
918     if (!parent.isEmpty()) {
919         FolderProjectItem *parentitem = getFolderItemById(parent);
920         if (!parentitem) {
921             QStringList text;
922             QString groupName = clip->getProperty("groupname");
923             //kDebug() << "Adding clip to new group: " << groupName;
924             if (groupName.isEmpty()) groupName = i18n("Folder");
925             text << groupName;
926             parentitem = new FolderProjectItem(m_listView, text, parent);
927         }
928
929         if (parentitem)
930             item = new ProjectItem(parentitem, clip);
931     }
932     if (item == NULL)
933         item = new ProjectItem(m_listView, clip);
934     KUrl url = clip->fileURL();
935
936     if (getProperties == false && !clip->getClipHash().isEmpty()) {
937         QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
938         if (QFile::exists(cachedPixmap)) {
939             QPixmap pix(cachedPixmap);
940             if (pix.isNull())
941                 KIO::NetAccess::del(KUrl(cachedPixmap), this);
942             item->setData(0, Qt::DecorationRole, pix);
943         }
944     }
945 #ifdef NEPOMUK
946     if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
947         // if file has Nepomuk comment, use it
948         Nepomuk::Resource f(url.path());
949         QString annotation = f.description();
950         if (!annotation.isEmpty()) item->setText(1, annotation);
951         item->setText(2, QString::number(f.rating()));
952     }
953 #endif
954     // Add cut zones
955     QList <CutZoneInfo> cuts = clip->cutZones();
956     if (!cuts.isEmpty()) {
957         for (int i = 0; i < cuts.count(); i++) {
958             SubProjectItem *sub = new SubProjectItem(item, cuts.at(i).zone.x(), cuts.at(i).zone.y(), cuts.at(i).description);
959             if (!clip->getClipHash().isEmpty()) {
960                 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(cuts.at(i).zone.x()) + ".png";
961                 if (QFile::exists(cachedPixmap)) {
962                     QPixmap pix(cachedPixmap);
963                     if (pix.isNull())
964                         KIO::NetAccess::del(KUrl(cachedPixmap), this);
965                     sub->setData(0, Qt::DecorationRole, pix);
966                 }
967             }
968         }
969     }
970     if (m_listView->isEnabled()) {
971         updateButtons();
972         if (getProperties)
973             m_listView->blockSignals(false);
974     }
975     if (getProperties && !m_queueTimer.isActive())
976         slotProcessNextClipInQueue();
977 }
978
979 void ProjectList::slotResetProjectList()
980 {
981     m_listView->clear();
982     emit clipSelected(NULL);
983     m_thumbnailQueue.clear();
984     m_infoQueue.clear();
985     m_refreshed = false;
986 }
987
988 void ProjectList::requestClipInfo(const QDomElement xml, const QString id)
989 {
990     m_refreshed = false;
991     m_infoQueue.insert(id, xml);
992     //if (m_infoQueue.count() == 1 || ) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
993 }
994
995 void ProjectList::slotProcessNextClipInQueue()
996 {
997     if (m_infoQueue.isEmpty()) {
998         slotProcessNextThumbnail();
999         return;
1000     }
1001
1002     QMap<QString, QDomElement>::const_iterator j = m_infoQueue.constBegin();
1003     if (j != m_infoQueue.constEnd()) {
1004         const QDomElement dom = j.value();
1005         const QString id = j.key();
1006         m_infoQueue.remove(j.key());
1007         emit getFileProperties(dom, id, m_listView->iconSize().height(), false);
1008     }
1009     if (!m_infoQueue.isEmpty()) m_queueTimer.start();
1010 }
1011
1012 void ProjectList::slotUpdateClip(const QString &id)
1013 {
1014     ProjectItem *item = getItemById(id);
1015     m_listView->blockSignals(true);
1016     if (item) item->setData(0, UsageRole, QString::number(item->numReferences()));
1017     m_listView->blockSignals(false);
1018 }
1019
1020 void ProjectList::updateAllClips()
1021 {
1022     m_listView->setSortingEnabled(false);
1023     kDebug() << "// UPDATE ALL CLPY";
1024
1025     QTreeWidgetItemIterator it(m_listView);
1026     DocClipBase *clip;
1027     ProjectItem *item;
1028     m_listView->blockSignals(true);
1029     while (*it) {
1030         if ((*it)->type() == PROJECTSUBCLIPTYPE) {
1031             // subitem
1032             SubProjectItem *sub = static_cast <SubProjectItem *>(*it);
1033             if (sub->data(0, Qt::DecorationRole).isNull()) {
1034                 item = static_cast <ProjectItem *>((*it)->parent());
1035                 requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x()));
1036             }
1037             ++it;
1038             continue;
1039         } else if ((*it)->type() == PROJECTFOLDERTYPE) {
1040             // folder
1041             ++it;
1042             continue;
1043         } else {
1044             item = static_cast <ProjectItem *>(*it);
1045             clip = item->referencedClip();
1046             if (item->referencedClip()->producer() == NULL) {
1047                 if (clip->isPlaceHolder() == false)
1048                     requestClipInfo(clip->toXML(), clip->getId());
1049                 else if (!clip->isPlaceHolder())
1050                     item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
1051             } else {
1052                 if (item->data(0, Qt::DecorationRole).isNull())
1053                     requestClipThumbnail(clip->getId());
1054                 if (item->data(0, DurationRole).toString().isEmpty())
1055                     item->changeDuration(item->referencedClip()->producer()->get_playtime());
1056             }
1057             item->setData(0, UsageRole, QString::number(item->numReferences()));
1058         }
1059         //qApp->processEvents();
1060         ++it;
1061     }
1062     if (!m_queueTimer.isActive())
1063         m_queueTimer.start();
1064     if (m_listView->isEnabled())
1065         m_listView->blockSignals(false);
1066     m_listView->setSortingEnabled(true);
1067     if (m_infoQueue.isEmpty())
1068         slotProcessNextThumbnail();
1069 }
1070
1071 // static
1072 QString ProjectList::getExtensions()
1073 {
1074     // Build list of mime types
1075     QStringList mimeTypes = QStringList() << "application/x-kdenlive" << "application/x-kdenlivetitle" << "video/mlt-playlist" << "text/plain"
1076                             << "video/x-flv" << "application/vnd.rn-realmedia" << "video/x-dv" << "video/dv" << "video/x-msvideo" << "video/x-matroska" << "video/mpeg" << "video/ogg" << "video/x-ms-wmv" << "video/mp4" << "video/quicktime"
1077                             << "audio/x-flac" << "audio/x-matroska" << "audio/mp4" << "audio/mpeg" << "audio/x-mp3" << "audio/ogg" << "audio/x-wav" << "application/ogg" << "application/mxf"
1078                             << "image/gif" << "image/jpeg" << "image/png" << "image/x-tga" << "image/x-bmp" << "image/svg+xml" << "image/tiff" << "image/x-xcf" << "image/x-xcf-gimp" << "image/x-vnd.adobe.photoshop" << "image/x-pcx" << "image/x-exr";
1079
1080     QString allExtensions;
1081     foreach(const QString & mimeType, mimeTypes) {
1082         KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
1083         if (mime) {
1084             allExtensions.append(mime->patterns().join(" "));
1085             allExtensions.append(' ');
1086         }
1087     }
1088     return allExtensions.simplified();
1089 }
1090
1091 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
1092 {
1093     if (!m_commandStack)
1094         kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1095
1096     KUrl::List list;
1097     if (givenList.isEmpty()) {
1098         QString allExtensions = getExtensions();
1099         const QString dialogFilter = allExtensions + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
1100         QCheckBox *b = new QCheckBox(i18n("Import image sequence"));
1101         b->setChecked(KdenliveSettings::autoimagesequence());
1102         KFileDialog *d = new KFileDialog(KUrl("kfiledialog:///clipfolder"), dialogFilter, kapp->activeWindow(), b);
1103         d->setOperationMode(KFileDialog::Opening);
1104         d->setMode(KFile::Files);
1105         d->exec();
1106         list = d->selectedUrls();
1107         if (b->isChecked() && list.count() == 1) {
1108             // Check for image sequence
1109             KUrl url = list.at(0);
1110             QString fileName = url.fileName().section('.', 0, -2);
1111             if (fileName.at(fileName.size() - 1).isDigit()) {
1112                 KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
1113                 if (item.mimetype().startsWith("image")) {
1114                     // import as sequence if we found more than one image in the sequence
1115                     QStringList list;
1116                     QString pattern = SlideshowClip::selectedPath(url.path(), false, QString(), &list);
1117                     int count = list.count();
1118                     if (count > 1) {
1119                         delete d;
1120                         QStringList groupInfo = getGroup();
1121
1122                         // get image sequence base name
1123                         while (fileName.at(fileName.size() - 1).isDigit()) {
1124                             fileName.chop(1);
1125                         }
1126
1127                         m_doc->slotCreateSlideshowClipFile(fileName, pattern, count, m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()),
1128                                                            false, false, false,
1129                                                            m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))), QString(), 0,
1130                                                            QString(), groupInfo.at(0), groupInfo.at(1));
1131                         return;
1132                     }
1133                 }
1134             }
1135         }
1136         delete d;
1137     } else {
1138         for (int i = 0; i < givenList.count(); i++)
1139             list << givenList.at(i);
1140     }
1141
1142     foreach(const KUrl & file, list) {
1143         // Check there is no folder here
1144         KMimeType::Ptr type = KMimeType::findByUrl(file);
1145         if (type->is("inode/directory")) {
1146             // user dropped a folder
1147             list.removeAll(file);
1148         }
1149     }
1150
1151     if (list.isEmpty())
1152         return;
1153
1154     if (givenList.isEmpty()) {
1155         QStringList groupInfo = getGroup();
1156         m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1));
1157     } else {
1158         m_doc->slotAddClipList(list, groupName, groupId);
1159     }
1160 }
1161
1162 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
1163 {
1164     ProjectItem *item = getItemById(id);
1165     QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
1166     if (item) {
1167         const QString path = item->referencedClip()->fileURL().path();
1168         if (item->referencedClip()->isPlaceHolder()) replace = false;
1169         if (!path.isEmpty()) {
1170             if (replace)
1171                 KMessageBox::sorry(kapp->activeWindow(), i18n("Clip <b>%1</b><br />is invalid, will be removed from project.", path));
1172             else if (KMessageBox::questionYesNo(kapp->activeWindow(), i18n("Clip <b>%1</b><br />is missing or invalid. Remove it from project?", path), i18n("Invalid clip")) == KMessageBox::Yes)
1173                 replace = true;
1174         }
1175         if (replace)
1176             emit deleteProjectClips(QStringList() << id, QMap <QString, QString>());
1177     }
1178 }
1179
1180 void ProjectList::slotAddColorClip()
1181 {
1182     if (!m_commandStack)
1183         kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1184
1185     QDialog *dia = new QDialog(this);
1186     Ui::ColorClip_UI dia_ui;
1187     dia_ui.setupUi(dia);
1188     dia->setWindowTitle(i18n("Color Clip"));
1189     dia_ui.clip_name->setText(i18n("Color Clip"));
1190
1191     TimecodeDisplay *t = new TimecodeDisplay(m_timecode);
1192     t->setValue(KdenliveSettings::color_duration());
1193     t->setTimeCodeFormat(false);
1194     dia_ui.clip_durationBox->addWidget(t);
1195     dia_ui.clip_color->setColor(KdenliveSettings::colorclipcolor());
1196
1197     if (dia->exec() == QDialog::Accepted) {
1198         QString color = dia_ui.clip_color->color().name();
1199         KdenliveSettings::setColorclipcolor(color);
1200         color = color.replace(0, 1, "0x") + "ff";
1201         QStringList groupInfo = getGroup();
1202         m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, m_timecode.getTimecode(t->gentime()), groupInfo.at(0), groupInfo.at(1));
1203     }
1204     delete t;
1205     delete dia;
1206 }
1207
1208
1209 void ProjectList::slotAddSlideshowClip()
1210 {
1211     if (!m_commandStack)
1212         kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1213
1214     SlideshowClip *dia = new SlideshowClip(m_timecode, this);
1215
1216     if (dia->exec() == QDialog::Accepted) {
1217         QStringList groupInfo = getGroup();
1218         m_doc->slotCreateSlideshowClipFile(dia->clipName(), dia->selectedPath(), dia->imageCount(), dia->clipDuration(),
1219                                            dia->loop(), dia->crop(), dia->fade(),
1220                                            dia->lumaDuration(), dia->lumaFile(), dia->softness(),
1221                                            dia->animation(), groupInfo.at(0), groupInfo.at(1));
1222     }
1223     delete dia;
1224 }
1225
1226 void ProjectList::slotAddTitleClip()
1227 {
1228     QStringList groupInfo = getGroup();
1229     m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
1230 }
1231
1232 void ProjectList::slotAddTitleTemplateClip()
1233 {
1234     if (!m_commandStack)
1235         kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1236
1237     QStringList groupInfo = getGroup();
1238
1239     // Get the list of existing templates
1240     QStringList filter;
1241     filter << "*.kdenlivetitle";
1242     const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
1243     QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
1244
1245     QDialog *dia = new QDialog(this);
1246     Ui::TemplateClip_UI dia_ui;
1247     dia_ui.setupUi(dia);
1248     for (int i = 0; i < templateFiles.size(); ++i)
1249         dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
1250
1251     if (!templateFiles.isEmpty())
1252         dia_ui.buttonBox->button(QDialogButtonBox::Ok)->setFocus();
1253     dia_ui.template_list->fileDialog()->setFilter("application/x-kdenlivetitle");
1254     //warning: setting base directory doesn't work??
1255     KUrl startDir(path);
1256     dia_ui.template_list->fileDialog()->setUrl(startDir);
1257     dia_ui.text_box->setHidden(true);
1258     if (dia->exec() == QDialog::Accepted) {
1259         QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
1260         if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
1261         // Create a cloned template clip
1262         m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
1263     }
1264     delete dia;
1265 }
1266
1267 QStringList ProjectList::getGroup() const
1268 {
1269     QStringList result;
1270     QTreeWidgetItem *item = m_listView->currentItem();
1271     while (item && item->type() != PROJECTFOLDERTYPE)
1272         item = item->parent();
1273
1274     if (item) {
1275         FolderProjectItem *folder = static_cast <FolderProjectItem *>(item);
1276         result << folder->groupName() << folder->clipId();
1277     } else {
1278         result << QString() << QString();
1279     }
1280     return result;
1281 }
1282
1283 void ProjectList::setDocument(KdenliveDoc *doc)
1284 {
1285     m_listView->blockSignals(true);
1286     m_listView->clear();
1287     m_listView->setSortingEnabled(false);
1288     emit clipSelected(NULL);
1289     m_thumbnailQueue.clear();
1290     m_infoQueue.clear();
1291     m_refreshed = false;
1292     m_fps = doc->fps();
1293     m_timecode = doc->timecode();
1294     m_commandStack = doc->commandStack();
1295     m_doc = doc;
1296
1297     QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
1298     QMapIterator<QString, QString> f(flist);
1299     while (f.hasNext()) {
1300         f.next();
1301         (void) new FolderProjectItem(m_listView, QStringList() << f.value(), f.key());
1302     }
1303
1304     QList <DocClipBase*> list = doc->clipManager()->documentClipList();
1305     for (int i = 0; i < list.count(); i++)
1306         slotAddClip(list.at(i), false);
1307
1308     m_listView->blockSignals(false);
1309     connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
1310     connect(m_doc->clipManager(), SIGNAL(modifiedClip(const QString &)), this, SLOT(slotModifiedClip(const QString &)));
1311     connect(m_doc->clipManager(), SIGNAL(missingClip(const QString &)), this, SLOT(slotMissingClip(const QString &)));
1312     connect(m_doc->clipManager(), SIGNAL(availableClip(const QString &)), this, SLOT(slotAvailableClip(const QString &)));
1313     connect(m_doc->clipManager(), SIGNAL(checkAllClips()), this, SLOT(updateAllClips()));
1314 }
1315
1316 QList <DocClipBase*> ProjectList::documentClipList() const
1317 {
1318     if (m_doc == NULL)
1319         return QList <DocClipBase*> ();
1320
1321     return m_doc->clipManager()->documentClipList();
1322 }
1323
1324 QDomElement ProjectList::producersList()
1325 {
1326     QDomDocument doc;
1327     QDomElement prods = doc.createElement("producerlist");
1328     doc.appendChild(prods);
1329     kDebug() << "////////////  PRO LIST BUILD PRDSLIST ";
1330     QTreeWidgetItemIterator it(m_listView);
1331     while (*it) {
1332         if ((*it)->type() != PROJECTCLIPTYPE) {
1333             // subitem
1334             ++it;
1335             continue;
1336         }
1337         prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
1338         ++it;
1339     }
1340     return prods;
1341 }
1342
1343 void ProjectList::slotCheckForEmptyQueue()
1344 {
1345     if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
1346         m_refreshed = true;
1347         emit loadingIsOver();
1348         emit displayMessage(QString(), -1);
1349         m_listView->blockSignals(false);
1350         m_listView->setEnabled(true);
1351         updateButtons();
1352     } else if (!m_refreshed) {
1353         QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
1354     }
1355 }
1356
1357 void ProjectList::reloadClipThumbnails()
1358 {
1359     kDebug() << "//////////////  RELOAD CLIPS THUMBNAILS!!!";
1360     m_thumbnailQueue.clear();
1361     QTreeWidgetItemIterator it(m_listView);
1362     while (*it) {
1363         if ((*it)->type() != PROJECTCLIPTYPE) {
1364             // subitem
1365             ++it;
1366             continue;
1367         }
1368         m_thumbnailQueue << ((ProjectItem *)(*it))->clipId();
1369         ++it;
1370     }
1371     QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
1372 }
1373
1374 void ProjectList::requestClipThumbnail(const QString id)
1375 {
1376     if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id);
1377 }
1378
1379 void ProjectList::slotProcessNextThumbnail()
1380 {
1381     if (m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
1382         slotCheckForEmptyQueue();
1383         return;
1384     }
1385     if (!m_infoQueue.isEmpty()) {
1386         //QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
1387         return;
1388     }
1389     if (m_thumbnailQueue.count() > 1) {
1390         int max = m_doc->clipManager()->clipsCount();
1391         emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - m_thumbnailQueue.count()) / max));
1392     }
1393     slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
1394 }
1395
1396 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
1397 {
1398     QTreeWidgetItem *item = getAnyItemById(clipId);
1399     if (item)
1400         slotRefreshClipThumbnail(item, update);
1401     else
1402         slotProcessNextThumbnail();
1403 }
1404
1405 void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
1406 {
1407     if (it == NULL) return;
1408     ProjectItem *item = NULL;
1409     bool isSubItem = false;
1410     int frame;
1411     if (it->type() == PROJECTFOLDERTYPE) return;
1412     if (it->type() == PROJECTSUBCLIPTYPE) {
1413         item = static_cast <ProjectItem *>(it->parent());
1414         frame = static_cast <SubProjectItem *>(it)->zone().x();
1415         isSubItem = true;
1416     } else {
1417         item = static_cast <ProjectItem *>(it);
1418         frame = item->referencedClip()->getClipThumbFrame();
1419     }
1420
1421     if (item) {
1422         DocClipBase *clip = item->referencedClip();
1423         if (!clip) {
1424             slotProcessNextThumbnail();
1425             return;
1426         }
1427         QPixmap pix;
1428         int height = m_listView->iconSize().height();
1429         int width = (int)(height  * m_render->dar());
1430         if (clip->clipType() == AUDIO)
1431             pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
1432         else if (clip->clipType() == IMAGE)
1433             pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->producer(), 0, width, height));
1434         else
1435             pix = item->referencedClip()->thumbProducer()->extractImage(frame, width, height);
1436
1437         if (!pix.isNull()) {
1438             m_listView->blockSignals(true);
1439             it->setData(0, Qt::DecorationRole, pix);
1440             if (m_listView->isEnabled())
1441                 m_listView->blockSignals(false);
1442             if (!isSubItem)
1443                 m_doc->cachePixmap(item->getClipHash(), pix);
1444             else
1445                 m_doc->cachePixmap(item->getClipHash() + '#' + QString::number(frame), pix);
1446         }
1447         if (update)
1448             emit projectModified();
1449         QTimer::singleShot(30, this, SLOT(slotProcessNextThumbnail()));
1450     }
1451 }
1452
1453 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace)
1454 {
1455     QString toReload;
1456     ProjectItem *item = getItemById(clipId);
1457     if (item && producer) {
1458         m_listView->blockSignals(true);
1459         item->setProperties(properties, metadata);
1460         if (item->referencedClip()->isPlaceHolder() && producer->is_valid()) {
1461             item->referencedClip()->setValid();
1462             item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1463             toReload = clipId;
1464         }
1465         //Q_ASSERT_X(item->referencedClip(), "void ProjectList::slotReplyGetFileProperties", QString("Item with groupName %1 does not have a clip associated").arg(item->groupName()).toLatin1());
1466         item->referencedClip()->setProducer(producer, replace);
1467         item->referencedClip()->askForAudioThumbs();
1468         if (!replace && item->data(0, Qt::DecorationRole).isNull())
1469             requestClipThumbnail(clipId);
1470         if (!toReload.isEmpty())
1471             item->slotSetToolTip();
1472
1473         //emit receivedClipDuration(clipId);
1474         if (m_listView->isEnabled() && replace) {
1475             // update clip in clip monitor
1476             emit clipSelected(NULL);
1477             emit clipSelected(item->referencedClip());
1478             //TODO: Make sure the line below has no side effect
1479             toReload = clipId;
1480         }
1481         /*else {
1482             // Check if duration changed.
1483             emit receivedClipDuration(clipId);
1484             delete producer;
1485         }*/
1486         if (m_listView->isEnabled())
1487             m_listView->blockSignals(false);
1488         /*if (item->icon(0).isNull()) {
1489             requestClipThumbnail(clipId);
1490         }*/
1491     } else kDebug() << "////////  COULD NOT FIND CLIP TO UPDATE PRPS...";
1492     int max = m_doc->clipManager()->clipsCount();
1493     if (item && m_infoQueue.isEmpty() && m_thumbnailQueue.isEmpty()) {
1494         m_listView->setCurrentItem(item);
1495         bool updatedProfile = false;
1496         if (item->parent()) {
1497             if (item->parent()->type() == PROJECTFOLDERTYPE)
1498                 static_cast <FolderProjectItem *>(item->parent())->switchIcon();
1499         } else if (KdenliveSettings::checkfirstprojectclip() &&  m_listView->topLevelItemCount() == 1) {
1500             // this is the first clip loaded in project, check if we want to adjust project settings to the clip
1501             updatedProfile = adjustProjectProfileToItem(item);
1502         }
1503         if (updatedProfile == false) emit clipSelected(item->referencedClip());
1504     } else {
1505         emit displayMessage(i18n("Loading clips"), (int)(100 *(max - m_infoQueue.count()) / max));
1506     }
1507     if (!toReload.isEmpty())
1508         emit clipNeedsReload(toReload, true);
1509     // small delay so that the app can display the progress info
1510     QTimer::singleShot(30, this, SLOT(slotProcessNextClipInQueue()));
1511 }
1512
1513 bool ProjectList::adjustProjectProfileToItem(ProjectItem *item)
1514 {
1515     if (item == NULL) {
1516         if (m_listView->currentItem() && m_listView->currentItem()->type() != PROJECTFOLDERTYPE)
1517             item = static_cast <ProjectItem*>(m_listView->currentItem());
1518     }
1519     if (item == NULL || item->referencedClip() == NULL) {
1520         KMessageBox::information(kapp->activeWindow(), i18n("Cannot find profile from current clip"));
1521         return false;
1522     }
1523     bool profileUpdated = false;
1524     QString size = item->referencedClip()->getProperty("frame_size");
1525     int width = size.section('x', 0, 0).toInt();
1526     int height = size.section('x', -1).toInt();
1527     double fps = item->referencedClip()->getProperty("fps").toDouble();
1528     double par = item->referencedClip()->getProperty("aspect_ratio").toDouble();
1529     if (item->clipType() == IMAGE || item->clipType() == AV || item->clipType() == VIDEO) {
1530         if (ProfilesDialog::matchProfile(width, height, fps, par, item->clipType() == IMAGE, m_doc->mltProfile()) == false) {
1531             // get a list of compatible profiles
1532             QMap <QString, QString> suggestedProfiles = ProfilesDialog::getProfilesFromProperties(width, height, fps, par, item->clipType() == IMAGE);
1533             if (!suggestedProfiles.isEmpty()) {
1534                 KDialog *dialog = new KDialog(this);
1535                 dialog->setCaption(i18n("Change project profile"));
1536                 dialog->setButtons(KDialog::Ok | KDialog::Cancel);
1537
1538                 QWidget container;
1539                 QVBoxLayout *l = new QVBoxLayout;
1540                 QLabel *label = new QLabel(i18n("Your clip does not match current project's profile.\nDo you want to change the project profile?\n\nThe following profiles match the clip (size: %1, fps: %2)", size, fps));
1541                 l->addWidget(label);
1542                 QListWidget *list = new QListWidget;
1543                 list->setAlternatingRowColors(true);
1544                 QMapIterator<QString, QString> i(suggestedProfiles);
1545                 while (i.hasNext()) {
1546                     i.next();
1547                     QListWidgetItem *item = new QListWidgetItem(i.value(), list);
1548                     item->setData(Qt::UserRole, i.key());
1549                     item->setToolTip(i.key());
1550                 }
1551                 list->setCurrentRow(0);
1552                 l->addWidget(list);
1553                 container.setLayout(l);
1554                 dialog->setButtonText(KDialog::Ok, i18n("Update profile"));
1555                 dialog->setMainWidget(&container);
1556                 if (dialog->exec() == QDialog::Accepted) {
1557                     //Change project profile
1558                     profileUpdated = true;
1559                     if (list->currentItem())
1560                         emit updateProfile(list->currentItem()->data(Qt::UserRole).toString());
1561                 }
1562                 delete list;
1563                 delete label;
1564             } else if (fps > 0) {
1565                 KMessageBox::information(kapp->activeWindow(), i18n("Your clip does not match current project's profile.\nNo existing profile found to match the clip's properties.\nClip size: %1\nFps: %2\n", size, fps));
1566             }
1567         }
1568     }
1569     return profileUpdated;
1570 }
1571
1572 void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
1573 {
1574     ProjectItem *item = getItemById(clipId);
1575     if (item && !pix.isNull()) {
1576         m_listView->blockSignals(true);
1577         item->setData(0, Qt::DecorationRole, pix);
1578         m_doc->cachePixmap(item->getClipHash(), pix);
1579         if (m_listView->isEnabled())
1580             m_listView->blockSignals(false);
1581     }
1582 }
1583
1584 QTreeWidgetItem *ProjectList::getAnyItemById(const QString &id)
1585 {
1586     QTreeWidgetItemIterator it(m_listView);
1587     QString lookId = id;
1588     if (id.contains('#'))
1589         lookId = id.section('#', 0, 0);
1590
1591     ProjectItem *result = NULL;
1592     while (*it) {
1593         if ((*it)->type() != PROJECTCLIPTYPE) {
1594             // subitem
1595             ++it;
1596             continue;
1597         }
1598         ProjectItem *item = static_cast<ProjectItem *>(*it);
1599         if (item->clipId() == lookId) {
1600             result = item;
1601             break;
1602         }
1603         ++it;
1604     }
1605     if (result == NULL || !id.contains('#')) {
1606         return result;
1607     } else {
1608         for (int i = 0; i < result->childCount(); i++) {
1609             SubProjectItem *sub = static_cast <SubProjectItem *>(result->child(i));
1610             if (sub && sub->zone().x() == id.section('#', 1, 1).toInt())
1611                 return sub;
1612         }
1613     }
1614
1615     return NULL;
1616 }
1617
1618
1619 ProjectItem *ProjectList::getItemById(const QString &id)
1620 {
1621     ProjectItem *item;
1622     QTreeWidgetItemIterator it(m_listView);
1623     while (*it) {
1624         if ((*it)->type() != PROJECTCLIPTYPE) {
1625             // subitem
1626             ++it;
1627             continue;
1628         }
1629         item = static_cast<ProjectItem *>(*it);
1630         if (item->clipId() == id)
1631             return item;
1632         ++it;
1633     }
1634     return NULL;
1635 }
1636
1637 FolderProjectItem *ProjectList::getFolderItemById(const QString &id)
1638 {
1639     FolderProjectItem *item;
1640     QTreeWidgetItemIterator it(m_listView);
1641     while (*it) {
1642         if ((*it)->type() == PROJECTFOLDERTYPE) {
1643             item = static_cast<FolderProjectItem *>(*it);
1644             if (item->clipId() == id)
1645                 return item;
1646         }
1647         ++it;
1648     }
1649     return NULL;
1650 }
1651
1652 void ProjectList::slotSelectClip(const QString &ix)
1653 {
1654     ProjectItem *clip = getItemById(ix);
1655     if (clip) {
1656         m_listView->setCurrentItem(clip);
1657         m_listView->scrollToItem(clip);
1658         m_editButton->defaultAction()->setEnabled(true);
1659         m_deleteButton->defaultAction()->setEnabled(true);
1660         m_reloadAction->setEnabled(true);
1661         m_transcodeAction->setEnabled(true);
1662         if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
1663             m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
1664             m_openAction->setEnabled(true);
1665         } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
1666             m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
1667             m_openAction->setEnabled(true);
1668         } else {
1669             m_openAction->setEnabled(false);
1670         }
1671     }
1672 }
1673
1674 QString ProjectList::currentClipUrl() const
1675 {
1676     ProjectItem *item;
1677     if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return QString();
1678     if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
1679         // subitem
1680         item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
1681     } else {
1682         item = static_cast <ProjectItem*>(m_listView->currentItem());
1683     }
1684     if (item == NULL)
1685         return QString();
1686     return item->clipUrl().path();
1687 }
1688
1689 KUrl::List ProjectList::getConditionalUrls(const QString &condition) const
1690 {
1691     KUrl::List result;
1692     ProjectItem *item;
1693     QList<QTreeWidgetItem *> list = m_listView->selectedItems();
1694     for (int i = 0; i < list.count(); i++) {
1695         if (list.at(i)->type() == PROJECTFOLDERTYPE)
1696             continue;
1697         if (list.at(i)->type() == PROJECTSUBCLIPTYPE) {
1698             // subitem
1699             item = static_cast <ProjectItem*>(list.at(i)->parent());
1700         } else {
1701             item = static_cast <ProjectItem*>(list.at(i));
1702         }
1703         if (item == NULL || item->type() == COLOR || item->type() == SLIDESHOW || item->type() == TEXT)
1704             continue;
1705         DocClipBase *clip = item->referencedClip();
1706         if (!condition.isEmpty()) {
1707             if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section('=', 1, 1)))
1708                 continue;
1709             else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section('=', 1, 1)))
1710                 continue;
1711         }
1712         result.append(item->clipUrl());
1713     }
1714     return result;
1715 }
1716
1717 void ProjectList::regenerateTemplate(const QString &id)
1718 {
1719     ProjectItem *clip = getItemById(id);
1720     if (clip)
1721         regenerateTemplate(clip);
1722 }
1723
1724 void ProjectList::regenerateTemplate(ProjectItem *clip)
1725 {
1726     //TODO: remove this unused method, only force_reload is necessary
1727     clip->referencedClip()->producer()->set("force_reload", 1);
1728 }
1729
1730 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
1731 {
1732     QDomDocument doc;
1733     QFile file(path);
1734     if (!file.open(QIODevice::ReadOnly)) {
1735         kWarning() << "ERROR, CANNOT READ: " << path;
1736         return doc;
1737     }
1738     if (!doc.setContent(&file)) {
1739         kWarning() << "ERROR, CANNOT READ: " << path;
1740         file.close();
1741         return doc;
1742     }
1743     file.close();
1744     QDomNodeList texts = doc.elementsByTagName("content");
1745     for (int i = 0; i < texts.count(); i++) {
1746         QString data = texts.item(i).firstChild().nodeValue();
1747         data.replace("%s", replaceString);
1748         texts.item(i).firstChild().setNodeValue(data);
1749     }
1750     return doc;
1751 }
1752
1753
1754 void ProjectList::slotAddClipCut(const QString &id, int in, int out)
1755 {
1756     ProjectItem *clip = getItemById(id);
1757     if (clip == NULL || clip->referencedClip()->hasCutZone(QPoint(in, out)))
1758         return;
1759     AddClipCutCommand *command = new AddClipCutCommand(this, id, in, out, QString(), true, false);
1760     m_commandStack->push(command);
1761 }
1762
1763 void ProjectList::addClipCut(const QString &id, int in, int out, const QString desc, bool newItem)
1764 {
1765     ProjectItem *clip = getItemById(id);
1766     if (clip) {
1767         DocClipBase *base = clip->referencedClip();
1768         base->addCutZone(in, out);
1769         m_listView->blockSignals(true);
1770         SubProjectItem *sub = new SubProjectItem(clip, in, out, desc);
1771         if (newItem && desc.isEmpty() && !m_listView->isColumnHidden(1)) {
1772             if (!clip->isExpanded())
1773                 clip->setExpanded(true);
1774             m_listView->scrollToItem(sub);
1775             m_listView->editItem(sub, 1);
1776         }
1777         QPixmap p = clip->referencedClip()->thumbProducer()->extractImage(in, (int)(sub->sizeHint(0).height()  * m_render->dar()), sub->sizeHint(0).height() - 2);
1778         sub->setData(0, Qt::DecorationRole, p);
1779         m_doc->cachePixmap(clip->getClipHash() + '#' + QString::number(in), p);
1780         m_listView->blockSignals(false);
1781     }
1782     emit projectModified();
1783 }
1784
1785 void ProjectList::removeClipCut(const QString &id, int in, int out)
1786 {
1787     ProjectItem *clip = getItemById(id);
1788     if (clip) {
1789         DocClipBase *base = clip->referencedClip();
1790         base->removeCutZone(in, out);
1791         SubProjectItem *sub = getSubItem(clip, QPoint(in, out));
1792         if (sub) {
1793             m_listView->blockSignals(true);
1794             delete sub;
1795             m_listView->blockSignals(false);
1796         }
1797     }
1798     emit projectModified();
1799 }
1800
1801 SubProjectItem *ProjectList::getSubItem(ProjectItem *clip, QPoint zone)
1802 {
1803     SubProjectItem *sub = NULL;
1804     if (clip) {
1805         for (int i = 0; i < clip->childCount(); i++) {
1806             QTreeWidgetItem *it = clip->child(i);
1807             if (it->type() == PROJECTSUBCLIPTYPE) {
1808                 sub = static_cast <SubProjectItem*>(it);
1809                 if (sub->zone() == zone)
1810                     break;
1811                 else
1812                     sub = NULL;
1813             }
1814         }
1815     }
1816     return sub;
1817 }
1818
1819 void ProjectList::slotUpdateClipCut(QPoint p)
1820 {
1821     if (!m_listView->currentItem() || m_listView->currentItem()->type() != PROJECTSUBCLIPTYPE)
1822         return;
1823     SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
1824     ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
1825     EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), p, sub->text(1), sub->text(1), true);
1826     m_commandStack->push(command);
1827 }
1828
1829 void ProjectList::doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment)
1830 {
1831     ProjectItem *clip = getItemById(id);
1832     SubProjectItem *sub = getSubItem(clip, oldzone);
1833     if (sub == NULL || clip == NULL)
1834         return;
1835     DocClipBase *base = clip->referencedClip();
1836     base->updateCutZone(oldzone.x(), oldzone.y(), zone.x(), zone.y(), comment);
1837     m_listView->blockSignals(true);
1838     sub->setZone(zone);
1839     sub->setDescription(comment);
1840     m_listView->blockSignals(false);
1841     emit projectModified();
1842 }
1843
1844 void ProjectList::slotForceProcessing(const QString &id)
1845 {
1846     while (m_infoQueue.contains(id)) {
1847         slotProcessNextClipInQueue();
1848     }
1849 }
1850
1851 void ProjectList::slotAddOrUpdateSequence(const QString frameName)
1852 {
1853     QString fileName = KUrl(frameName).fileName().section('_', 0, -2);
1854     QStringList list;
1855     QString pattern = SlideshowClip::selectedPath(frameName, false, QString(), &list);
1856     int count = list.count();
1857     if (count > 1) {
1858         const QList <DocClipBase *> existing = m_doc->clipManager()->getClipByResource(pattern);
1859         if (!existing.isEmpty()) {
1860             // Sequence already exists, update
1861             QString id = existing.at(0)->getId();
1862             //ProjectItem *item = getItemById(id);
1863             QMap <QString, QString> oldprops;
1864             QMap <QString, QString> newprops;
1865             int ttl = existing.at(0)->getProperty("ttl").toInt();
1866             oldprops["out"] = existing.at(0)->getProperty("out");
1867             newprops["out"] = QString::number(ttl * count - 1);
1868             slotUpdateClipProperties(id, newprops);
1869             EditClipCommand *command = new EditClipCommand(this, id, oldprops, newprops, false);
1870             m_commandStack->push(command);
1871         } else {
1872             // Create sequence
1873             QStringList groupInfo = getGroup();
1874             m_doc->slotCreateSlideshowClipFile(fileName, pattern, count, m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()),
1875                                                false, false, false,
1876                                                m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))), QString(), 0,
1877                                                QString(), groupInfo.at(0), groupInfo.at(1));
1878         }
1879     } else emit displayMessage(i18n("Sequence not found"), -2);
1880 }
1881
1882 #include "projectlist.moc"