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