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