]> git.sesse.net Git - kdenlive/blob - src/projectlist.cpp
27ddda7ec18921045982c8fe3d7c43e8396d9e5d
[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 "commands/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 "commands/editclipcommand.h"
37 #include "commands/editclipcutcommand.h"
38 #include "commands/editfoldercommand.h"
39 #include "commands/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 #include <KStandardDirs>
53
54 #ifdef NEPOMUK
55 #include <nepomuk/global.h>
56 #include <nepomuk/resourcemanager.h>
57 //#include <nepomuk/tag.h>
58 #endif
59
60 #include <QMouseEvent>
61 #include <QStylePainter>
62 #include <QPixmap>
63 #include <QIcon>
64 #include <QMenu>
65 #include <QProcess>
66 #include <QHeaderView>
67 #include <QInputDialog>
68 #include <QtConcurrentRun>
69 #include <QVBoxLayout>
70
71 InvalidDialog::InvalidDialog(const QString &caption, const QString &message, bool infoOnly, QWidget *parent) : KDialog(parent)
72 {
73     setCaption(caption);
74     if (infoOnly) setButtons(KDialog::Ok);
75     else setButtons(KDialog::Yes | KDialog::No);
76     QWidget *w = new QWidget(this);
77     QVBoxLayout *l = new QVBoxLayout;
78     l->addWidget(new QLabel(message));
79     m_clipList = new QListWidget;
80     l->addWidget(m_clipList);
81     w->setLayout(l);
82     setMainWidget(w);
83 }
84
85 InvalidDialog::~InvalidDialog()
86 {
87     delete m_clipList;
88 }
89
90
91 void InvalidDialog::addClip(const QString &id, const QString &path)
92 {
93     QListWidgetItem *item = new QListWidgetItem(path);
94     item->setData(Qt::UserRole, id);
95     m_clipList->addItem(item);
96 }
97
98 QStringList InvalidDialog::getIds() const
99 {
100     QStringList ids;
101     for (int i = 0; i < m_clipList->count(); i++) {
102         ids << m_clipList->item(i)->data(Qt::UserRole).toString();
103     }
104     return ids;
105 }
106
107
108 ProjectList::ProjectList(QWidget *parent) :
109     QWidget(parent),
110     m_render(NULL),
111     m_fps(-1),
112     m_commandStack(NULL),
113     m_openAction(NULL),
114     m_reloadAction(NULL),
115     m_stabilizeAction(NULL),
116     m_transcodeAction(NULL),
117     m_doc(NULL),
118     m_refreshed(false),
119     m_allClipsProcessed(false),
120     m_thumbnailQueue(),
121     m_abortAllProxies(false),
122     m_invalidClipDialog(NULL)
123 {
124     QVBoxLayout *layout = new QVBoxLayout;
125     layout->setContentsMargins(0, 0, 0, 0);
126     layout->setSpacing(0);
127     qRegisterMetaType<QDomElement>("QDomElement");
128     // setup toolbar
129     QFrame *frame = new QFrame;
130     frame->setFrameStyle(QFrame::NoFrame);
131     QHBoxLayout *box = new QHBoxLayout;
132     KTreeWidgetSearchLine *searchView = new KTreeWidgetSearchLine;
133
134     box->addWidget(searchView);
135     //int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
136     //m_toolbar->setIconSize(QSize(s, s));
137
138     m_addButton = new QToolButton;
139     m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
140     m_addButton->setAutoRaise(true);
141     box->addWidget(m_addButton);
142
143     m_editButton = new QToolButton;
144     m_editButton->setAutoRaise(true);
145     box->addWidget(m_editButton);
146
147     m_deleteButton = new QToolButton;
148     m_deleteButton->setAutoRaise(true);
149     box->addWidget(m_deleteButton);
150     frame->setLayout(box);
151     layout->addWidget(frame);
152
153     m_listView = new ProjectListView;
154     layout->addWidget(m_listView);
155     setLayout(layout);
156     searchView->setTreeWidget(m_listView);
157
158     connect(this, SIGNAL(processNextThumbnail()), this, SLOT(slotProcessNextThumbnail()));
159     connect(m_listView, SIGNAL(projectModified()), this, SIGNAL(projectModified()));
160     connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
161     connect(m_listView, SIGNAL(focusMonitor()), this, SIGNAL(raiseClipMonitor()));
162     connect(m_listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
163     connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
164     connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
165     connect(m_listView, SIGNAL(addClip(const QList <QUrl>, const QString &, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &, const QString &)));
166     connect(m_listView, SIGNAL(addClipCut(const QString &, int, int)), this, SLOT(slotAddClipCut(const QString &, int, int)));
167     connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
168     connect(m_listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
169
170     m_listViewDelegate = new ItemDelegate(m_listView);
171     m_listView->setItemDelegate(m_listViewDelegate);
172 #ifdef NEPOMUK
173     if (KdenliveSettings::activate_nepomuk()) {
174         Nepomuk::ResourceManager::instance()->init();
175         if (!Nepomuk::ResourceManager::instance()->initialized()) {
176             kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
177             KdenliveSettings::setActivate_nepomuk(false);
178         }
179     }
180 #endif
181 }
182
183 ProjectList::~ProjectList()
184 {
185     m_abortAllProxies = true;
186     m_thumbnailQueue.clear();
187     delete m_menu;
188     m_listView->blockSignals(true);
189     m_listView->clear();
190     delete m_listViewDelegate;
191 }
192
193 void ProjectList::focusTree() const
194 {
195     m_listView->setFocus();
196 }
197
198 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
199 {
200     QList <QAction *> actions = addMenu->actions();
201     for (int i = 0; i < actions.count(); i++) {
202         if (actions.at(i)->data().toString() == "clip_properties") {
203             m_editButton->setDefaultAction(actions.at(i));
204             actions.removeAt(i);
205             i--;
206         } else if (actions.at(i)->data().toString() == "delete_clip") {
207             m_deleteButton->setDefaultAction(actions.at(i));
208             actions.removeAt(i);
209             i--;
210         } else if (actions.at(i)->data().toString() == "edit_clip") {
211             m_openAction = actions.at(i);
212             actions.removeAt(i);
213             i--;
214         } else if (actions.at(i)->data().toString() == "reload_clip") {
215             m_reloadAction = actions.at(i);
216             actions.removeAt(i);
217             i--;
218         } else if (actions.at(i)->data().toString() == "proxy_clip") {
219             m_proxyAction = actions.at(i);
220             actions.removeAt(i);
221             i--;
222         }
223     }
224
225     QMenu *m = new QMenu();
226     m->addActions(actions);
227     m_addButton->setMenu(m);
228     m_addButton->setDefaultAction(defaultAction);
229     m_menu = new QMenu();
230     m_menu->addActions(addMenu->actions());
231 }
232
233 void ProjectList::setupGeneratorMenu(const QHash<QString,QMenu*>& menus)
234 {
235     if (!menus.contains("addMenu") && ! menus.value("addMenu") )
236         return;
237     QMenu *menu = m_addButton->menu();
238         if (menus.contains("addMenu") && menus.value("addMenu")){ 
239                 QMenu* addMenu=menus.value("addMenu");
240                 menu->addMenu(addMenu);
241                 m_addButton->setMenu(menu);
242
243                 m_menu->addMenu(addMenu);
244                 if (addMenu->isEmpty())
245                         addMenu->setEnabled(false);
246         }
247         if (menus.contains("transcodeMenu") && menus.value("transcodeMenu") ){
248                 QMenu* transcodeMenu=menus.value("transcodeMenu");
249                 m_menu->addMenu(transcodeMenu);
250                 if (transcodeMenu->isEmpty())
251                         transcodeMenu->setEnabled(false);
252                 m_transcodeAction = transcodeMenu;
253         }
254         if (menus.contains("stabilizeMenu") && menus.value("stabilizeMenu") ){
255                 QMenu* stabilizeMenu=menus.value("stabilizeMenu");
256                 m_menu->addMenu(stabilizeMenu);
257                 if (stabilizeMenu->isEmpty())
258                         stabilizeMenu->setEnabled(false);
259                 m_stabilizeAction=stabilizeMenu;
260
261         }
262     m_menu->addAction(m_reloadAction);
263     m_menu->addAction(m_proxyAction);
264         if (menus.contains("inTimelineMenu") && menus.value("inTimelineMenu")){
265                 QMenu* inTimelineMenu=menus.value("inTimelineMenu");
266                 m_menu->addMenu(inTimelineMenu);
267                 inTimelineMenu->setEnabled(false);
268         }
269     m_menu->addAction(m_editButton->defaultAction());
270     m_menu->addAction(m_openAction);
271     m_menu->addAction(m_deleteButton->defaultAction());
272     m_menu->insertSeparator(m_deleteButton->defaultAction());
273 }
274
275 void ProjectList::clearSelection()
276 {
277     m_listView->clearSelection();
278 }
279
280 QByteArray ProjectList::headerInfo() const
281 {
282     return m_listView->header()->saveState();
283 }
284
285 void ProjectList::setHeaderInfo(const QByteArray &state)
286 {
287     m_listView->header()->restoreState(state);
288 }
289
290 void ProjectList::updateProjectFormat(Timecode t)
291 {
292     m_timecode = t;
293 }
294
295 void ProjectList::slotEditClip()
296 {
297     QList<QTreeWidgetItem *> list = m_listView->selectedItems();
298     if (list.isEmpty()) return;
299     if (list.count() > 1 || list.at(0)->type() == PROJECTFOLDERTYPE) {
300         editClipSelection(list);
301         return;
302     }
303     ProjectItem *item;
304     if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
305         return;
306     if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE)
307         item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
308     else
309         item = static_cast <ProjectItem*>(m_listView->currentItem());
310     if (item && (item->flags() & Qt::ItemIsDragEnabled)) {
311         emit clipSelected(item->referencedClip());
312         emit showClipProperties(item->referencedClip());
313     }
314 }
315
316 void ProjectList::editClipSelection(QList<QTreeWidgetItem *> list)
317 {
318     // Gather all common properties
319     QMap <QString, QString> commonproperties;
320     QList <DocClipBase *> clipList;
321     commonproperties.insert("force_aspect_num", "-");
322     commonproperties.insert("force_aspect_den", "-");
323     commonproperties.insert("force_fps", "-");
324     commonproperties.insert("force_progressive", "-");
325     commonproperties.insert("force_tff", "-");
326     commonproperties.insert("threads", "-");
327     commonproperties.insert("video_index", "-");
328     commonproperties.insert("audio_index", "-");
329     commonproperties.insert("force_colorspace", "-");
330     commonproperties.insert("full_luma", "-");
331     QString transparency = "-";
332
333     bool allowDurationChange = true;
334     int commonDuration = -1;
335     bool hasImages = false;;
336     ProjectItem *item;
337     for (int i = 0; i < list.count(); i++) {
338         item = NULL;
339         if (list.at(i)->type() == PROJECTFOLDERTYPE) {
340             // Add folder items to the list
341             int ct = list.at(i)->childCount();
342             for (int j = 0; j < ct; j++) {
343                 list.append(list.at(i)->child(j));
344             }
345             continue;
346         }
347         else if (list.at(i)->type() == PROJECTSUBCLIPTYPE)
348             item = static_cast <ProjectItem*>(list.at(i)->parent());
349         else
350             item = static_cast <ProjectItem*>(list.at(i));
351         if (!(item->flags() & Qt::ItemIsDragEnabled))
352             continue;
353         if (item) {
354             // check properties
355             DocClipBase *clip = item->referencedClip();
356             if (clipList.contains(clip)) continue;
357             if (clip->clipType() == IMAGE) {
358                 hasImages = true;
359                 if (clip->getProperty("transparency").isEmpty() || clip->getProperty("transparency").toInt() == 0) {
360                     if (transparency == "-") {
361                         // first non transparent image
362                         transparency = "0";
363                     }
364                     else if (transparency == "1") {
365                         // we have transparent and non transparent clips
366                         transparency = "-1";
367                     }
368                 }
369                 else {
370                     if (transparency == "-") {
371                         // first transparent image
372                         transparency = "1";
373                     }
374                     else if (transparency == "0") {
375                         // we have transparent and non transparent clips
376                         transparency = "-1";
377                     }
378                 }
379             }
380             if (clip->clipType() != COLOR && clip->clipType() != IMAGE && clip->clipType() != TEXT)
381                 allowDurationChange = false;
382             if (allowDurationChange && commonDuration != 0) {
383                 if (commonDuration == -1)
384                     commonDuration = clip->duration().frames(m_fps);
385                 else if (commonDuration != clip->duration().frames(m_fps))
386                     commonDuration = 0;
387             }
388             clipList.append(clip);
389             QMap <QString, QString> clipprops = clip->properties();
390             QMapIterator<QString, QString> p(commonproperties);
391             while (p.hasNext()) {
392                 p.next();
393                 if (p.value().isEmpty()) continue;
394                 if (clipprops.contains(p.key())) {
395                     if (p.value() == "-")
396                         commonproperties.insert(p.key(), clipprops.value(p.key()));
397                     else if (p.value() != clipprops.value(p.key()))
398                         commonproperties.insert(p.key(), QString());
399                 } else {
400                     commonproperties.insert(p.key(), QString());
401                 }
402             }
403         }
404     }
405     if (allowDurationChange)
406         commonproperties.insert("out", QString::number(commonDuration));
407     if (hasImages)
408         commonproperties.insert("transparency", transparency);
409     /*QMapIterator<QString, QString> p(commonproperties);
410     while (p.hasNext()) {
411         p.next();
412         kDebug() << "Result: " << p.key() << " = " << p.value();
413     }*/
414     emit showClipProperties(clipList, commonproperties);
415 }
416
417 void ProjectList::slotOpenClip()
418 {
419     ProjectItem *item;
420     if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
421         return;
422     if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1)
423         item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
424     else
425         item = static_cast <ProjectItem*>(m_listView->currentItem());
426     if (item) {
427         if (item->clipType() == IMAGE) {
428             if (KdenliveSettings::defaultimageapp().isEmpty())
429                 KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open images in the Settings dialog"));
430             else
431                 QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
432         }
433         if (item->clipType() == AUDIO) {
434             if (KdenliveSettings::defaultaudioapp().isEmpty())
435                 KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open audio files in the Settings dialog"));
436             else
437                 QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
438         }
439     }
440 }
441
442 void ProjectList::cleanup()
443 {
444     m_listView->clearSelection();
445     QTreeWidgetItemIterator it(m_listView);
446     ProjectItem *item;
447     while (*it) {
448         if ((*it)->type() != PROJECTCLIPTYPE) {
449             it++;
450             continue;
451         }
452         item = static_cast <ProjectItem *>(*it);
453         if (item->numReferences() == 0)
454             item->setSelected(true);
455         it++;
456     }
457     slotRemoveClip();
458 }
459
460 void ProjectList::trashUnusedClips()
461 {
462     QTreeWidgetItemIterator it(m_listView);
463     ProjectItem *item;
464     QStringList ids;
465     QStringList urls;
466     while (*it) {
467         if ((*it)->type() != PROJECTCLIPTYPE) {
468             it++;
469             continue;
470         }
471         item = static_cast <ProjectItem *>(*it);
472         if (item->numReferences() == 0) {
473             ids << item->clipId();
474             KUrl url = item->clipUrl();
475             if (!url.isEmpty() && !urls.contains(url.path()))
476                 urls << url.path();
477         }
478         it++;
479     }
480
481     // Check that we don't use the URL in another clip
482     QTreeWidgetItemIterator it2(m_listView);
483     while (*it2) {
484         if ((*it2)->type() != PROJECTCLIPTYPE) {
485             it2++;
486             continue;
487         }
488         item = static_cast <ProjectItem *>(*it2);
489         if (item->numReferences() > 0) {
490             KUrl url = item->clipUrl();
491             if (!url.isEmpty() && urls.contains(url.path())) urls.removeAll(url.path());
492         }
493         it2++;
494     }
495
496     emit deleteProjectClips(ids, QMap <QString, QString>());
497     for (int i = 0; i < urls.count(); i++)
498         KIO::NetAccess::del(KUrl(urls.at(i)), this);
499 }
500
501 void ProjectList::slotReloadClip(const QString &id)
502 {
503     QList<QTreeWidgetItem *> selected;
504     if (id.isEmpty())
505         selected = m_listView->selectedItems();
506     else {
507         ProjectItem *itemToReLoad = getItemById(id);
508         if (itemToReLoad) selected.append(itemToReLoad);
509     }
510     ProjectItem *item;
511     for (int i = 0; i < selected.count(); i++) {
512         if (selected.at(i)->type() != PROJECTCLIPTYPE) {
513             if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
514                 for (int j = 0; j < selected.at(i)->childCount(); j++)
515                     selected.append(selected.at(i)->child(j));
516             }
517             continue;
518         }
519         item = static_cast <ProjectItem *>(selected.at(i));
520         if (item && !item->isProxyRunning()) {
521             DocClipBase *clip = item->referencedClip();
522             if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
523                 kDebug()<<"//// TRYING TO RELOAD: "<<item->clipId()<<", but it is busy";
524                 continue;
525             }
526             CLIPTYPE t = item->clipType();
527             if (t == TEXT) {
528                 if (clip && !clip->getProperty("xmltemplate").isEmpty())
529                     regenerateTemplate(item);
530             } else if (t != COLOR && t != SLIDESHOW && clip && clip->checkHash() == false) {
531                 item->referencedClip()->setPlaceHolder(true);
532                 item->setProperty("file_hash", QString());
533             } else if (t == IMAGE) {
534                 clip->getProducer()->set("force_reload", 1);
535             }
536
537             QDomElement e = item->toXml();
538             // Make sure we get the correct producer length if it was adjusted in timeline
539             if (t == COLOR || t == IMAGE || t == SLIDESHOW || t == TEXT) {
540                 int length = QString(clip->producerProperty("length")).toInt();
541                 if (length > 0 && !e.hasAttribute("length")) {
542                     e.setAttribute("length", length);
543                 }
544             }
545             resetThumbsProducer(clip);
546             m_render->getFileProperties(e, item->clipId(), m_listView->iconSize().height(), true);
547         }
548     }
549 }
550
551 void ProjectList::slotModifiedClip(const QString &id)
552 {
553     ProjectItem *item = getItemById(id);
554     if (item) {
555         QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
556         if (!pixmap.isNull()) {
557             QPainter p(&pixmap);
558             p.fillRect(0, 0, pixmap.width(), pixmap.height(), QColor(255, 255, 255, 200));
559             p.drawPixmap(0, 0, KIcon("view-refresh").pixmap(m_listView->iconSize()));
560             p.end();
561         } else {
562             pixmap = KIcon("view-refresh").pixmap(m_listView->iconSize());
563         }
564         item->setData(0, Qt::DecorationRole, pixmap);
565     }
566 }
567
568 void ProjectList::slotMissingClip(const QString &id)
569 {
570     ProjectItem *item = getItemById(id);
571     if (item) {
572         item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
573         int height = m_listView->iconSize().height();
574         int width = (int)(height  * m_render->dar());
575         QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
576         if (pixmap.isNull()) {
577             pixmap = QPixmap(width, height);
578             pixmap.fill(Qt::transparent);
579         }
580         KIcon icon("dialog-close");
581         QPainter p(&pixmap);
582         p.drawPixmap(3, 3, icon.pixmap(width - 6, height - 6));
583         p.end();
584         item->setData(0, Qt::DecorationRole, pixmap);
585         if (item->referencedClip()) {
586             item->referencedClip()->setPlaceHolder(true);
587             if (m_render == NULL) {
588                 kDebug() << "*********  ERROR, NULL RENDR";
589                 return;
590             }
591             Mlt::Producer *newProd = m_render->invalidProducer(id);
592             if (item->referencedClip()->getProducer()) {
593                 Mlt::Properties props(newProd->get_properties());
594                 Mlt::Properties src_props(item->referencedClip()->getProducer()->get_properties());
595                 props.inherit(src_props);
596             }
597             item->referencedClip()->setProducer(newProd, true);
598             item->slotSetToolTip();
599             emit clipNeedsReload(id);
600         }
601     }
602     update();
603     emit displayMessage(i18n("Check missing clips"), -2);
604     emit updateRenderStatus();
605 }
606
607 void ProjectList::slotAvailableClip(const QString &id)
608 {
609     ProjectItem *item = getItemById(id);
610     if (item == NULL)
611         return;
612     item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
613     if (item->referencedClip()) { // && item->referencedClip()->checkHash() == false) {
614         item->setProperty("file_hash", QString());
615         slotReloadClip(id);
616     }
617     /*else {
618     item->referencedClip()->setValid();
619     item->slotSetToolTip();
620     }
621     update();*/
622     emit updateRenderStatus();
623 }
624
625 bool ProjectList::hasMissingClips()
626 {
627     bool missing = false;
628     QTreeWidgetItemIterator it(m_listView);
629     while (*it) {
630         if ((*it)->type() == PROJECTCLIPTYPE && !((*it)->flags() & Qt::ItemIsDragEnabled)) {
631             missing = true;
632             break;
633         }
634         it++;
635     }
636     return missing;
637 }
638
639 void ProjectList::setRenderer(Render *projectRender)
640 {
641     m_render = projectRender;
642     m_listView->setIconSize(QSize((ProjectItem::itemDefaultHeight() - 2) * m_render->dar(), ProjectItem::itemDefaultHeight() - 2));
643 }
644
645 void ProjectList::slotClipSelected()
646 {
647     QTreeWidgetItem *item = m_listView->currentItem();
648     ProjectItem *clip = NULL;
649     if (item) {
650         if (item->type() == PROJECTFOLDERTYPE) {
651             emit clipSelected(NULL);
652             m_editButton->defaultAction()->setEnabled(item->childCount() > 0);
653             m_deleteButton->defaultAction()->setEnabled(true);
654             m_openAction->setEnabled(false);
655             m_reloadAction->setEnabled(false);
656             m_transcodeAction->setEnabled(false);
657             m_stabilizeAction->setEnabled(false);
658         } else {
659             if (item->type() == PROJECTSUBCLIPTYPE) {
660                 // this is a sub item, use base clip
661                 m_deleteButton->defaultAction()->setEnabled(true);
662                 clip = static_cast <ProjectItem*>(item->parent());
663                 if (clip == NULL) kDebug() << "-----------ERROR";
664                 SubProjectItem *sub = static_cast <SubProjectItem*>(item);
665                 emit clipSelected(clip->referencedClip(), sub->zone());
666                 m_transcodeAction->setEnabled(false);
667                 m_stabilizeAction->setEnabled(false);
668                 m_reloadAction->setEnabled(false);
669                 adjustProxyActions(clip);
670                 return;
671             }
672             clip = static_cast <ProjectItem*>(item);
673             if (clip && clip->referencedClip())
674                 emit clipSelected(clip->referencedClip());
675             m_editButton->defaultAction()->setEnabled(true);
676             m_deleteButton->defaultAction()->setEnabled(true);
677             m_reloadAction->setEnabled(true);
678             m_transcodeAction->setEnabled(true);
679             m_stabilizeAction->setEnabled(true);
680             if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
681                 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
682                 m_openAction->setEnabled(true);
683             } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
684                 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
685                 m_openAction->setEnabled(true);
686             } else {
687                 m_openAction->setEnabled(false);
688             }
689             // Display relevant transcoding actions only
690             adjustTranscodeActions(clip);
691             adjustStabilizeActions(clip);
692             // Display uses in timeline
693             emit findInTimeline(clip->clipId());
694         }
695     } else {
696         emit clipSelected(NULL);
697         m_editButton->defaultAction()->setEnabled(false);
698         m_deleteButton->defaultAction()->setEnabled(false);
699         m_openAction->setEnabled(false);
700         m_reloadAction->setEnabled(false);
701         m_transcodeAction->setEnabled(false);
702         m_stabilizeAction->setEnabled(false);
703     }
704     adjustProxyActions(clip);
705 }
706
707 void ProjectList::adjustProxyActions(ProjectItem *clip) const
708 {
709     if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == SLIDESHOW || clip->clipType() == AUDIO) {
710         m_proxyAction->setEnabled(false);
711         return;
712     }
713     m_proxyAction->setEnabled(useProxy());
714     m_proxyAction->blockSignals(true);
715     m_proxyAction->setChecked(clip->hasProxy());
716     m_proxyAction->blockSignals(false);
717 }
718
719 void ProjectList::adjustStabilizeActions(ProjectItem *clip) const
720 {
721
722     if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW) {
723         m_stabilizeAction->setEnabled(false);
724         return;
725     }
726         m_stabilizeAction->setEnabled(true);
727
728 }
729
730 void ProjectList::adjustTranscodeActions(ProjectItem *clip) const
731 {
732     if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW) {
733         m_transcodeAction->setEnabled(false);
734         return;
735     }
736     m_transcodeAction->setEnabled(true);
737     QList<QAction *> transcodeActions = m_transcodeAction->actions();
738     QStringList data;
739     QString condition;
740     for (int i = 0; i < transcodeActions.count(); i++) {
741         data = transcodeActions.at(i)->data().toStringList();
742         if (data.count() > 2) {
743             condition = data.at(2);
744             if (condition.startsWith("vcodec"))
745                 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
746             else if (condition.startsWith("acodec"))
747                 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
748         }
749     }
750
751 }
752
753 void ProjectList::slotPauseMonitor()
754 {
755     if (m_render)
756         m_render->pause();
757 }
758
759 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
760 {
761     ProjectItem *item = getItemById(id);
762     if (item) {
763         slotUpdateClipProperties(item, properties);
764         if (properties.contains("out") || properties.contains("force_fps") || properties.contains("resource")) {
765             slotReloadClip(id);
766         } else if (properties.contains("colour") ||
767                    properties.contains("xmldata") ||
768                    properties.contains("force_aspect_num") ||
769                    properties.contains("force_aspect_den") ||
770                    properties.contains("templatetext")) {
771             slotRefreshClipThumbnail(item);
772             emit refreshClip(id, true);
773         } else if (properties.contains("full_luma") || properties.contains("force_colorspace") || properties.contains("loop")) {
774             emit refreshClip(id, false);
775         }
776     }
777 }
778
779 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
780 {
781     if (!clip)
782         return;
783     clip->setProperties(properties);
784     if (properties.contains("name")) {
785         monitorItemEditing(false);
786         clip->setText(0, properties.value("name"));
787         monitorItemEditing(true);
788         emit clipNameChanged(clip->clipId(), properties.value("name"));
789     }
790     if (properties.contains("description")) {
791         CLIPTYPE type = clip->clipType();
792         monitorItemEditing(false);
793         clip->setText(1, properties.value("description"));
794         monitorItemEditing(true);
795 #ifdef NEPOMUK
796         if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
797             // Use Nepomuk system to store clip description
798             Nepomuk::Resource f(clip->clipUrl().path());
799             f.setDescription(properties.value("description"));
800         }
801 #endif
802         emit projectModified();
803     }
804 }
805
806 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
807 {
808     if (item->type() == PROJECTSUBCLIPTYPE) {
809         // this is a sub-item
810         if (column == 1) {
811             // user edited description
812             SubProjectItem *sub = static_cast <SubProjectItem*>(item);
813             ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
814             EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), sub->zone(), sub->description(), sub->text(1), true);
815             m_commandStack->push(command);
816             //slotUpdateCutClipProperties(sub->clipId(), sub->zone(), sub->text(1), sub->text(1));
817         }
818         return;
819     }
820     if (item->type() == PROJECTFOLDERTYPE) {
821         if (column == 0) {
822             FolderProjectItem *folder = static_cast <FolderProjectItem*>(item);
823             editFolder(item->text(0), folder->groupName(), folder->clipId());
824             folder->setGroupName(item->text(0));
825             m_doc->clipManager()->addFolder(folder->clipId(), item->text(0));
826             const int children = item->childCount();
827             for (int i = 0; i < children; i++) {
828                 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
829                 child->setProperty("groupname", item->text(0));
830             }
831         }
832         return;
833     }
834
835     ProjectItem *clip = static_cast <ProjectItem*>(item);
836     if (column == 1) {
837         if (clip->referencedClip()) {
838             QMap <QString, QString> oldprops;
839             QMap <QString, QString> newprops;
840             oldprops["description"] = clip->referencedClip()->getProperty("description");
841             newprops["description"] = item->text(1);
842
843             if (clip->clipType() == TEXT) {
844                 // This is a text template clip, update the image
845                 /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
846                 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/
847                 oldprops.insert("templatetext", clip->referencedClip()->getProperty("templatetext"));
848                 newprops.insert("templatetext", item->text(1));
849             }
850             slotUpdateClipProperties(clip->clipId(), newprops);
851             EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
852             m_commandStack->push(command);
853         }
854     } else if (column == 0) {
855         if (clip->referencedClip()) {
856             QMap <QString, QString> oldprops;
857             QMap <QString, QString> newprops;
858             oldprops["name"] = clip->referencedClip()->getProperty("name");
859             if (oldprops.value("name") != item->text(0)) {
860                 newprops["name"] = item->text(0);
861                 slotUpdateClipProperties(clip, newprops);
862                 emit projectModified();
863                 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
864                 m_commandStack->push(command);
865             }
866         }
867     }
868 }
869
870 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
871 {
872     bool enable = item ? true : false;
873     m_editButton->defaultAction()->setEnabled(enable);
874     m_deleteButton->defaultAction()->setEnabled(enable);
875     m_reloadAction->setEnabled(enable);
876     m_transcodeAction->setEnabled(enable);
877     m_stabilizeAction->setEnabled(enable);
878     if (enable) {
879         ProjectItem *clip = NULL;
880         if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
881             clip = static_cast <ProjectItem*>(item->parent());
882             m_transcodeAction->setEnabled(false);
883             m_stabilizeAction->setEnabled(false);
884             adjustProxyActions(clip);
885         } else if (m_listView->currentItem()->type() == PROJECTCLIPTYPE) {
886             clip = static_cast <ProjectItem*>(item);
887             // Display relevant transcoding actions only
888             adjustTranscodeActions(clip);
889             adjustStabilizeActions(clip);
890             adjustProxyActions(clip);
891             // Display uses in timeline
892             emit findInTimeline(clip->clipId());
893         } else {
894             m_transcodeAction->setEnabled(false);
895             m_stabilizeAction->setEnabled(false);
896         }
897         if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
898             m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
899             m_openAction->setEnabled(true);
900         } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
901             m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
902             m_openAction->setEnabled(true);
903         } else {
904             m_openAction->setEnabled(false);
905         }
906
907     } else {
908         m_openAction->setEnabled(false);
909     }
910     m_menu->popup(pos);
911 }
912
913 void ProjectList::slotRemoveClip()
914 {
915     if (!m_listView->currentItem())
916         return;
917     QStringList ids;
918     QMap <QString, QString> folderids;
919     QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
920
921     QUndoCommand *delCommand = new QUndoCommand();
922     delCommand->setText(i18n("Delete Clip Zone"));
923     for (int i = 0; i < selected.count(); i++) {
924         if (selected.at(i)->type() == PROJECTSUBCLIPTYPE) {
925             // subitem
926             SubProjectItem *sub = static_cast <SubProjectItem *>(selected.at(i));
927             ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
928             new AddClipCutCommand(this, item->clipId(), sub->zone().x(), sub->zone().y(), sub->description(), false, true, delCommand);
929         } else if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
930             // folder
931             FolderProjectItem *folder = static_cast <FolderProjectItem *>(selected.at(i));
932             folderids[folder->groupName()] = folder->clipId();
933             int children = folder->childCount();
934
935             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)
936                 return;
937             for (int i = 0; i < children; ++i) {
938                 ProjectItem *child = static_cast <ProjectItem *>(folder->child(i));
939                 ids << child->clipId();
940             }
941         } else {
942             ProjectItem *item = static_cast <ProjectItem *>(selected.at(i));
943             ids << item->clipId();
944             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) {
945                 KMessageBox::enableMessage("DeleteAll");
946                 return;
947             }
948         }
949     }
950     KMessageBox::enableMessage("DeleteAll");
951     if (delCommand->childCount() == 0)
952         delete delCommand;
953     else
954         m_commandStack->push(delCommand);
955     emit deleteProjectClips(ids, folderids);
956 }
957
958 void ProjectList::updateButtons() const
959 {
960     if (m_listView->topLevelItemCount() == 0) {
961         m_deleteButton->defaultAction()->setEnabled(false);
962         m_editButton->defaultAction()->setEnabled(false);
963     } else {
964         m_deleteButton->defaultAction()->setEnabled(true);
965         if (!m_listView->currentItem())
966             m_listView->setCurrentItem(m_listView->topLevelItem(0));
967         QTreeWidgetItem *item = m_listView->currentItem();
968         if (item && item->type() == PROJECTCLIPTYPE) {
969             m_editButton->defaultAction()->setEnabled(true);
970             m_openAction->setEnabled(true);
971             m_reloadAction->setEnabled(true);
972             m_transcodeAction->setEnabled(true);
973             m_stabilizeAction->setEnabled(true);
974             return;
975         }
976         else if (item && item->type() == PROJECTFOLDERTYPE && item->childCount() > 0) {
977             m_editButton->defaultAction()->setEnabled(true);
978         }
979         else m_editButton->defaultAction()->setEnabled(false);
980     }
981     m_openAction->setEnabled(false);
982     m_reloadAction->setEnabled(false);
983     m_transcodeAction->setEnabled(false);
984     m_stabilizeAction->setEnabled(false);
985     m_proxyAction->setEnabled(false);
986 }
987
988 void ProjectList::selectItemById(const QString &clipId)
989 {
990     ProjectItem *item = getItemById(clipId);
991     if (item)
992         m_listView->setCurrentItem(item);
993 }
994
995
996 void ProjectList::slotDeleteClip(const QString &clipId)
997 {
998     ProjectItem *item = getItemById(clipId);
999     if (!item) {
1000         kDebug() << "/// Cannot find clip to delete";
1001         return;
1002     }
1003     if (item->isProxyRunning()) m_abortProxy.append(item->referencedClip()->getProperty("proxy"));
1004     m_listView->blockSignals(true);
1005     QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
1006     if (!newSelectedItem)
1007         newSelectedItem = m_listView->itemBelow(item);
1008     delete item;
1009     // Pause playing to prevent crash while deleting clip
1010     slotPauseMonitor();
1011     m_doc->clipManager()->deleteClip(clipId);
1012     m_listView->blockSignals(false);
1013     if (newSelectedItem) {
1014         m_listView->setCurrentItem(newSelectedItem);
1015     } else {
1016         updateButtons();
1017         emit clipSelected(NULL);
1018     }
1019 }
1020
1021
1022 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
1023 {
1024     EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
1025     m_commandStack->push(command);
1026     m_doc->setModified(true);
1027 }
1028
1029 void ProjectList::slotAddFolder()
1030 {
1031     AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
1032     m_commandStack->push(command);
1033 }
1034
1035 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
1036 {
1037     if (remove) {
1038         FolderProjectItem *item = getFolderItemById(clipId);
1039         if (item) {
1040             m_doc->clipManager()->deleteFolder(clipId);
1041             QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
1042             if (!newSelectedItem)
1043                 newSelectedItem = m_listView->itemBelow(item);
1044             delete item;
1045             if (newSelectedItem)
1046                 m_listView->setCurrentItem(newSelectedItem);
1047             else
1048                 updateButtons();
1049         }
1050     } else {
1051         if (edit) {
1052             FolderProjectItem *item = getFolderItemById(clipId);
1053             if (item) {
1054                 m_listView->blockSignals(true);
1055                 item->setGroupName(foldername);
1056                 m_listView->blockSignals(false);
1057                 m_doc->clipManager()->addFolder(clipId, foldername);
1058                 const int children = item->childCount();
1059                 for (int i = 0; i < children; i++) {
1060                     ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
1061                     child->setProperty("groupname", foldername);
1062                 }
1063             }
1064         } else {
1065             m_listView->blockSignals(true);
1066             m_listView->setCurrentItem(new FolderProjectItem(m_listView, QStringList() << foldername, clipId));
1067             m_doc->clipManager()->addFolder(clipId, foldername);
1068             m_listView->blockSignals(false);
1069             m_listView->editItem(m_listView->currentItem(), 0);
1070         }
1071         updateButtons();
1072     }
1073     m_doc->setModified(true);
1074 }
1075
1076
1077
1078 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
1079 {
1080     QMapIterator<QString, QString> i(map);
1081     QUndoCommand *delCommand = new QUndoCommand();
1082     delCommand->setText(i18n("Delete Folder"));
1083     while (i.hasNext()) {
1084         i.next();
1085         new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
1086     }
1087     if (delCommand->childCount() > 0) m_commandStack->push(delCommand);
1088     else delete delCommand;
1089 }
1090
1091 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
1092 {
1093     //m_listView->setEnabled(false);
1094     const QString parent = clip->getProperty("groupid");
1095     ProjectItem *item = NULL;
1096     monitorItemEditing(false);
1097     if (!parent.isEmpty()) {
1098         FolderProjectItem *parentitem = getFolderItemById(parent);
1099         if (!parentitem) {
1100             QStringList text;
1101             QString groupName = clip->getProperty("groupname");
1102             //kDebug() << "Adding clip to new group: " << groupName;
1103             if (groupName.isEmpty()) groupName = i18n("Folder");
1104             text << groupName;
1105             parentitem = new FolderProjectItem(m_listView, text, parent);
1106         }
1107
1108         if (parentitem)
1109             item = new ProjectItem(parentitem, clip);
1110     }
1111     if (item == NULL) {
1112         item = new ProjectItem(m_listView, clip);
1113     }
1114     if (item->data(0, DurationRole).isNull()) item->setData(0, DurationRole, i18n("Loading"));
1115     QString proxy = clip->getProperty("proxy");
1116     if (!proxy.isEmpty() && proxy != "-") slotCreateProxy(clip->getId());
1117     connect(clip, SIGNAL(createProxy(const QString &)), this, SLOT(slotCreateProxy(const QString &)));
1118     connect(clip, SIGNAL(abortProxy(const QString &, const QString &)), this, SLOT(slotAbortProxy(const QString, const QString)));
1119     if (getProperties) {
1120         int height = m_listView->iconSize().height();
1121         int width = (int)(height  * m_render->dar());
1122         QPixmap pix =  KIcon("video-x-generic").pixmap(QSize(width, height));
1123         item->setData(0, Qt::DecorationRole, pix);
1124         //item->setFlags(Qt::ItemIsSelectable);
1125         m_listView->processLayout();
1126         QDomElement e = clip->toXML().cloneNode().toElement();
1127         e.removeAttribute("file_hash");
1128         resetThumbsProducer(clip);
1129         m_render->getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true);
1130     }
1131     else if (item->hasProxy() && !item->isProxyRunning()) {
1132         slotCreateProxy(clip->getId());
1133     }
1134     
1135     KUrl url = clip->fileURL();
1136 #ifdef NEPOMUK
1137     if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
1138         // if file has Nepomuk comment, use it
1139         Nepomuk::Resource f(url.path());
1140         QString annotation = f.description();
1141         if (!annotation.isEmpty()) item->setText(1, annotation);
1142         item->setText(2, QString::number(f.rating()));
1143     }
1144 #endif
1145
1146     // Add info to date column
1147     QFileInfo fileInfo(url.path());
1148     if (fileInfo.exists()) {
1149         item->setText(3, fileInfo.lastModified().toString(QString("yyyy/MM/dd hh:mm:ss")));
1150     }
1151
1152     // Add cut zones
1153     QList <CutZoneInfo> cuts = clip->cutZones();
1154     if (!cuts.isEmpty()) {
1155         for (int i = 0; i < cuts.count(); i++) {
1156             SubProjectItem *sub = new SubProjectItem(item, cuts.at(i).zone.x(), cuts.at(i).zone.y(), cuts.at(i).description);
1157             if (!clip->getClipHash().isEmpty()) {
1158                 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(cuts.at(i).zone.x()) + ".png";
1159                 if (QFile::exists(cachedPixmap)) {
1160                     QPixmap pix(cachedPixmap);
1161                     if (pix.isNull())
1162                         KIO::NetAccess::del(KUrl(cachedPixmap), this);
1163                     sub->setData(0, Qt::DecorationRole, pix);
1164                 }
1165             }
1166         }
1167     }
1168     monitorItemEditing(true);
1169     updateButtons();
1170 }
1171
1172 void ProjectList::slotGotProxy(const QString &proxyPath)
1173 {
1174     if (proxyPath.isEmpty() || m_abortAllProxies) return;
1175     QTreeWidgetItemIterator it(m_listView);
1176     ProjectItem *item;
1177
1178     while (*it && !m_abortAllProxies) {
1179         if ((*it)->type() == PROJECTCLIPTYPE) {
1180             item = static_cast <ProjectItem *>(*it);
1181             if (item->referencedClip()->getProperty("proxy") == proxyPath)
1182                 slotGotProxy(item);
1183         }
1184         ++it;
1185     }
1186 }
1187
1188 void ProjectList::slotGotProxy(ProjectItem *item)
1189 {
1190     if (item == NULL) return;
1191     DocClipBase *clip = item->referencedClip();
1192     if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
1193         // Clip is being reprocessed, abort
1194         kDebug()<<"//// TRYING TO PROXY: "<<item->clipId()<<", but it is busy";
1195         return;
1196     }
1197     
1198     // Proxy clip successfully created
1199     QDomElement e = clip->toXML().cloneNode().toElement();
1200
1201     // Make sure we get the correct producer length if it was adjusted in timeline
1202     CLIPTYPE t = item->clipType();
1203     if (t == COLOR || t == IMAGE || t == SLIDESHOW || t == TEXT) {
1204         int length = QString(clip->producerProperty("length")).toInt();
1205         if (length > 0 && !e.hasAttribute("length")) {
1206             e.setAttribute("length", length);
1207         }
1208     }
1209     resetThumbsProducer(clip);
1210     m_render->getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true);
1211 }
1212
1213 void ProjectList::slotResetProjectList()
1214 {
1215     m_listView->blockSignals(true);
1216     m_abortAllProxies = true;
1217     m_proxyThreads.waitForFinished();
1218     m_proxyThreads.clearFutures();
1219     m_thumbnailQueue.clear();
1220     m_listView->clear();
1221     m_listView->setEnabled(true);
1222     emit clipSelected(NULL);
1223     m_refreshed = false;
1224     m_allClipsProcessed = false;
1225     m_abortAllProxies = false;
1226     m_listView->blockSignals(false);
1227 }
1228
1229 void ProjectList::slotUpdateClip(const QString &id)
1230 {
1231     ProjectItem *item = getItemById(id);
1232     monitorItemEditing(false);
1233     if (item) item->setData(0, UsageRole, QString::number(item->numReferences()));
1234     monitorItemEditing(true);
1235 }
1236
1237 void ProjectList::getCachedThumbnail(ProjectItem *item)
1238 {
1239     if (!item) return;
1240     DocClipBase *clip = item->referencedClip();
1241     if (!clip) return;
1242     QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
1243     if (QFile::exists(cachedPixmap)) {
1244         QPixmap pix(cachedPixmap);
1245         if (pix.isNull()) {
1246             KIO::NetAccess::del(KUrl(cachedPixmap), this);
1247             requestClipThumbnail(item->clipId());
1248         }
1249         else item->setData(0, Qt::DecorationRole, pix);
1250     }
1251     else {
1252         requestClipThumbnail(item->clipId());
1253     }
1254 }
1255
1256 void ProjectList::getCachedThumbnail(SubProjectItem *item)
1257 {
1258     if (!item) return;
1259     ProjectItem *parentItem = static_cast <ProjectItem *>(item->parent());
1260     if (!parentItem) return;
1261     DocClipBase *clip = parentItem->referencedClip();
1262     if (!clip) return;
1263     int pos = item->zone().x();
1264     QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + "#" + QString::number(pos) + ".png";
1265     if (QFile::exists(cachedPixmap)) {
1266         QPixmap pix(cachedPixmap);
1267         if (pix.isNull()) {
1268             KIO::NetAccess::del(KUrl(cachedPixmap), this);
1269             requestClipThumbnail(parentItem->clipId() + '#' + QString::number(pos));
1270         }
1271         else item->setData(0, Qt::DecorationRole, pix);
1272     }
1273     else requestClipThumbnail(parentItem->clipId() + '#' + QString::number(pos));
1274 }
1275
1276 void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged, QStringList brokenClips)
1277 {
1278     if (!m_allClipsProcessed) m_listView->setEnabled(false);
1279     m_listView->setSortingEnabled(false);
1280     QTreeWidgetItemIterator it(m_listView);
1281     DocClipBase *clip;
1282     ProjectItem *item;
1283     monitorItemEditing(false);
1284     int height = m_listView->iconSize().height();
1285     int width = (int)(height  * m_render->dar());
1286     QPixmap missingPixmap = QPixmap(width, height);
1287     missingPixmap.fill(Qt::transparent);
1288     KIcon icon("dialog-close");
1289     QPainter p(&missingPixmap);
1290     p.drawPixmap(3, 3, icon.pixmap(width - 6, height - 6));
1291     p.end();
1292     
1293     int max = m_doc->clipManager()->clipsCount();
1294     max = qMax(1, max);
1295     int ct = 0;
1296
1297     while (*it) {
1298         emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - ct++) / max));
1299         if ((*it)->type() == PROJECTSUBCLIPTYPE) {
1300             // subitem
1301             SubProjectItem *sub = static_cast <SubProjectItem *>(*it);
1302             if (displayRatioChanged) {
1303                 item = static_cast <ProjectItem *>((*it)->parent());
1304                 requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x()));
1305             }
1306             else if (sub->data(0, Qt::DecorationRole).isNull()) {
1307                 getCachedThumbnail(sub);
1308             }
1309             ++it;
1310             continue;
1311         } else if ((*it)->type() == PROJECTFOLDERTYPE) {
1312             // folder
1313             ++it;
1314             continue;
1315         } else {
1316             item = static_cast <ProjectItem *>(*it);
1317             clip = item->referencedClip();
1318             if (item->referencedClip()->getProducer() == NULL) {
1319                 bool replace = false;
1320                 if (brokenClips.contains(item->clipId())) {
1321                     // if this is a proxy clip, disable proxy
1322                     item->setProxyStatus(NOPROXY);
1323                     clip->setProperty("proxy", "-");
1324                     replace = true;
1325                 }
1326                 if (clip->isPlaceHolder() == false && !item->isProxyRunning()) {
1327                     QDomElement xml = clip->toXML();
1328                     if (fpsChanged) {
1329                         xml.removeAttribute("out");
1330                         xml.removeAttribute("file_hash");
1331                         xml.removeAttribute("proxy_out");
1332                     }
1333                     if (!replace) replace = xml.attribute("replace") == "1";
1334                     if (replace) resetThumbsProducer(clip);
1335                     m_render->getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), replace);
1336                 }
1337                 else if (clip->isPlaceHolder()) {
1338                     item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
1339                     if (item->data(0, Qt::DecorationRole).isNull()) {
1340                         item->setData(0, Qt::DecorationRole, missingPixmap);
1341                     }
1342                     else {
1343                         QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
1344                         QPainter p(&pixmap);
1345                         p.drawPixmap(3, 3, KIcon("dialog-close").pixmap(pixmap.width() - 6, pixmap.height() - 6));
1346                         p.end();
1347                         item->setData(0, Qt::DecorationRole, pixmap);
1348                     }
1349                 }
1350             } else {              
1351                 if (displayRatioChanged)
1352                     requestClipThumbnail(clip->getId());
1353                 else if (item->data(0, Qt::DecorationRole).isNull()) {
1354                     getCachedThumbnail(item);
1355                 }
1356                 if (item->data(0, DurationRole).toString().isEmpty()) {
1357                     item->changeDuration(item->referencedClip()->getProducer()->get_playtime());
1358                 }
1359                 if (clip->isPlaceHolder()) {
1360                     QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
1361                     if (pixmap.isNull()) {
1362                         pixmap = QPixmap(width, height);
1363                         pixmap.fill(Qt::transparent);
1364                     }
1365                     QPainter p(&pixmap);
1366                     p.drawPixmap(3, 3, KIcon("dialog-close").pixmap(pixmap.width() - 6, pixmap.height() - 6));
1367                     p.end();
1368                     item->setData(0, Qt::DecorationRole, pixmap);
1369                 }
1370             }
1371             item->setData(0, UsageRole, QString::number(item->numReferences()));
1372         }
1373         ++it;
1374     }
1375
1376     m_listView->setSortingEnabled(true);
1377     m_allClipsProcessed = true;
1378     if (m_render->processingItems() == 0) {
1379        monitorItemEditing(true);
1380        slotProcessNextThumbnail();
1381     }
1382 }
1383
1384 // static
1385 QString ProjectList::getExtensions()
1386 {
1387     // Build list of mime types
1388     QStringList mimeTypes = QStringList() << "application/x-kdenlive" << "application/x-kdenlivetitle" << "video/mlt-playlist" << "text/plain"
1389                             << "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"
1390                             << "audio/x-flac" << "audio/x-matroska" << "audio/mp4" << "audio/mpeg" << "audio/x-mp3" << "audio/ogg" << "audio/x-wav" << "audio/x-aiff" << "audio/aiff" << "application/ogg" << "application/mxf" << "application/x-shockwave-flash"
1391                             << "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";
1392
1393     QString allExtensions;
1394     foreach(const QString & mimeType, mimeTypes) {
1395         KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
1396         if (mime) {
1397             allExtensions.append(mime->patterns().join(" "));
1398             allExtensions.append(' ');
1399         }
1400     }
1401     return allExtensions.simplified();
1402 }
1403
1404 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
1405 {
1406     if (!m_commandStack)
1407         kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1408
1409     KUrl::List list;
1410     if (givenList.isEmpty()) {
1411         QString allExtensions = getExtensions();
1412         const QString dialogFilter = allExtensions + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
1413         QCheckBox *b = new QCheckBox(i18n("Import image sequence"));
1414         b->setChecked(KdenliveSettings::autoimagesequence());
1415         QCheckBox *c = new QCheckBox(i18n("Transparent background for images"));
1416         c->setChecked(KdenliveSettings::autoimagetransparency());
1417         QFrame *f = new QFrame;
1418         f->setFrameShape(QFrame::NoFrame);
1419         QHBoxLayout *l = new QHBoxLayout;
1420         l->addWidget(b);
1421         l->addWidget(c);
1422         l->addStretch(5);
1423         f->setLayout(l);
1424         KFileDialog *d = new KFileDialog(KUrl("kfiledialog:///clipfolder"), dialogFilter, kapp->activeWindow(), f);
1425         d->setOperationMode(KFileDialog::Opening);
1426         d->setMode(KFile::Files);
1427         if (d->exec() == QDialog::Accepted) {
1428             KdenliveSettings::setAutoimagetransparency(c->isChecked());
1429         }
1430         list = d->selectedUrls();
1431         if (b->isChecked() && list.count() == 1) {
1432             // Check for image sequence
1433             KUrl url = list.at(0);
1434             QString fileName = url.fileName().section('.', 0, -2);
1435             if (fileName.at(fileName.size() - 1).isDigit()) {
1436                 KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
1437                 if (item.mimetype().startsWith("image")) {
1438                     // import as sequence if we found more than one image in the sequence
1439                     QStringList list;
1440                     QString pattern = SlideshowClip::selectedPath(url.path(), false, QString(), &list);
1441                     int count = list.count();
1442                     if (count > 1) {
1443                         delete d;
1444                         QStringList groupInfo = getGroup();
1445
1446                         // get image sequence base name
1447                         while (fileName.at(fileName.size() - 1).isDigit()) {
1448                             fileName.chop(1);
1449                         }
1450
1451                         m_doc->slotCreateSlideshowClipFile(fileName, pattern, count, m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()),
1452                                                            false, false, false,
1453                                                            m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))), QString(), 0,
1454                                                            QString(), groupInfo.at(0), groupInfo.at(1));
1455                         return;
1456                     }
1457                 }
1458             }
1459         }
1460         delete d;
1461     } else {
1462         for (int i = 0; i < givenList.count(); i++)
1463             list << givenList.at(i);
1464     }
1465
1466     foreach(const KUrl & file, list) {
1467         // Check there is no folder here
1468         KMimeType::Ptr type = KMimeType::findByUrl(file);
1469         if (type->is("inode/directory")) {
1470             // user dropped a folder
1471             list.removeAll(file);
1472         }
1473     }
1474
1475     if (list.isEmpty())
1476         return;
1477
1478     if (givenList.isEmpty()) {
1479         QStringList groupInfo = getGroup();
1480         m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1));
1481     } else {
1482         m_doc->slotAddClipList(list, groupName, groupId);
1483     }
1484 }
1485
1486 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
1487 {
1488     ProjectItem *item = getItemById(id);
1489     m_processingClips.removeAll(id);
1490     m_thumbnailQueue.removeAll(id);
1491     if (item) {
1492         item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1493         const QString path = item->referencedClip()->fileURL().path();
1494         if (item->referencedClip()->isPlaceHolder()) replace = false;
1495         if (!path.isEmpty()) {
1496             if (m_invalidClipDialog) {
1497                 m_invalidClipDialog->addClip(id, path);
1498                 return;
1499             }
1500             else {
1501                 if (replace)
1502                     m_invalidClipDialog = new InvalidDialog(i18n("Invalid clip"),  i18n("Clip <b>%1</b><br />is invalid, will be removed from project.", QString()), replace, kapp->activeWindow());
1503                 else {
1504                     m_invalidClipDialog = new InvalidDialog(i18n("Invalid clip"),  i18n("Clip <b>%1</b><br />is missing or invalid. Remove it from project?", QString()), replace, kapp->activeWindow());
1505                 }
1506                 m_invalidClipDialog->addClip(id, path);
1507                 int result = m_invalidClipDialog->exec();
1508                 if (result == KDialog::Yes) replace = true;
1509             }
1510         }
1511         if (m_invalidClipDialog) {
1512             if (replace)
1513                 emit deleteProjectClips(m_invalidClipDialog->getIds(), QMap <QString, QString>());
1514             delete m_invalidClipDialog;
1515             m_invalidClipDialog = NULL;
1516         }
1517         
1518     }
1519 }
1520
1521 void ProjectList::slotRemoveInvalidProxy(const QString &id, bool durationError)
1522 {
1523     ProjectItem *item = getItemById(id);
1524     if (item) {
1525         kDebug()<<"// Proxy for clip "<<id<<" is invalid, delete";
1526         item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1527         if (durationError) {
1528             kDebug() << "Proxy duration is wrong, try changing transcoding parameters.";
1529             emit displayMessage(i18n("Proxy clip unusable (duration is different from original)."), -2);
1530         }
1531         item->setProxyStatus(PROXYCRASHED);
1532         QString path = item->referencedClip()->getProperty("proxy");
1533         KUrl proxyFolder(m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/");
1534
1535         //Security check: make sure the invalid proxy file is in the proxy folder
1536         if (proxyFolder.isParentOf(KUrl(path))) {
1537             QFile::remove(path);
1538         }
1539         if (item->referencedClip()->getProducer() == NULL) {
1540             // Clip has no valid producer, request it
1541             slotProxyCurrentItem(false, item);
1542         }
1543         else {
1544             // refresh thumbs producer
1545             item->referencedClip()->reloadThumbProducer();
1546         }
1547     }
1548     m_processingClips.removeAll(id);
1549     m_thumbnailQueue.removeAll(id);
1550 }
1551
1552 void ProjectList::slotAddColorClip()
1553 {
1554     if (!m_commandStack)
1555         kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1556
1557     QDialog *dia = new QDialog(this);
1558     Ui::ColorClip_UI dia_ui;
1559     dia_ui.setupUi(dia);
1560     dia->setWindowTitle(i18n("Color Clip"));
1561     dia_ui.clip_name->setText(i18n("Color Clip"));
1562
1563     TimecodeDisplay *t = new TimecodeDisplay(m_timecode);
1564     t->setValue(KdenliveSettings::color_duration());
1565     dia_ui.clip_durationBox->addWidget(t);
1566     dia_ui.clip_color->setColor(KdenliveSettings::colorclipcolor());
1567
1568     if (dia->exec() == QDialog::Accepted) {
1569         QString color = dia_ui.clip_color->color().name();
1570         KdenliveSettings::setColorclipcolor(color);
1571         color = color.replace(0, 1, "0x") + "ff";
1572         QStringList groupInfo = getGroup();
1573         m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, m_timecode.getTimecode(t->gentime()), groupInfo.at(0), groupInfo.at(1));
1574     }
1575     delete t;
1576     delete dia;
1577 }
1578
1579
1580 void ProjectList::slotAddSlideshowClip()
1581 {
1582     if (!m_commandStack)
1583         kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1584
1585     SlideshowClip *dia = new SlideshowClip(m_timecode, this);
1586
1587     if (dia->exec() == QDialog::Accepted) {
1588         QStringList groupInfo = getGroup();
1589         m_doc->slotCreateSlideshowClipFile(dia->clipName(), dia->selectedPath(), dia->imageCount(), dia->clipDuration(),
1590                                            dia->loop(), dia->crop(), dia->fade(),
1591                                            dia->lumaDuration(), dia->lumaFile(), dia->softness(),
1592                                            dia->animation(), groupInfo.at(0), groupInfo.at(1));
1593     }
1594     delete dia;
1595 }
1596
1597 void ProjectList::slotAddTitleClip()
1598 {
1599     QStringList groupInfo = getGroup();
1600     m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
1601 }
1602
1603 void ProjectList::slotAddTitleTemplateClip()
1604 {
1605     if (!m_commandStack)
1606         kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1607
1608     QStringList groupInfo = getGroup();
1609
1610     // Get the list of existing templates
1611     QStringList filter;
1612     filter << "*.kdenlivetitle";
1613     const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
1614     QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
1615
1616     QDialog *dia = new QDialog(this);
1617     Ui::TemplateClip_UI dia_ui;
1618     dia_ui.setupUi(dia);
1619     for (int i = 0; i < templateFiles.size(); ++i)
1620         dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
1621
1622     if (!templateFiles.isEmpty())
1623         dia_ui.buttonBox->button(QDialogButtonBox::Ok)->setFocus();
1624     dia_ui.template_list->fileDialog()->setFilter("application/x-kdenlivetitle");
1625     //warning: setting base directory doesn't work??
1626     KUrl startDir(path);
1627     dia_ui.template_list->fileDialog()->setUrl(startDir);
1628     dia_ui.text_box->setHidden(true);
1629     if (dia->exec() == QDialog::Accepted) {
1630         QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
1631         if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
1632         // Create a cloned template clip
1633         m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
1634     }
1635     delete dia;
1636 }
1637
1638 QStringList ProjectList::getGroup() const
1639 {
1640     QStringList result;
1641     QTreeWidgetItem *item = m_listView->currentItem();
1642     while (item && item->type() != PROJECTFOLDERTYPE)
1643         item = item->parent();
1644
1645     if (item) {
1646         FolderProjectItem *folder = static_cast <FolderProjectItem *>(item);
1647         result << folder->groupName() << folder->clipId();
1648     } else {
1649         result << QString() << QString();
1650     }
1651     return result;
1652 }
1653
1654 void ProjectList::setDocument(KdenliveDoc *doc)
1655 {
1656     m_listView->blockSignals(true);
1657     m_abortAllProxies = true;
1658     m_proxyThreads.waitForFinished();
1659     m_proxyThreads.clearFutures();
1660     m_thumbnailQueue.clear();
1661     m_listView->clear();
1662     m_processingClips.clear();
1663     
1664     m_listView->setSortingEnabled(false);
1665     emit clipSelected(NULL);
1666     m_refreshed = false;
1667     m_allClipsProcessed = false;
1668     m_fps = doc->fps();
1669     m_timecode = doc->timecode();
1670     m_commandStack = doc->commandStack();
1671     m_doc = doc;
1672     m_abortAllProxies = false;
1673
1674     QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
1675     QStringList openedFolders = doc->getExpandedFolders();
1676     QMapIterator<QString, QString> f(flist);
1677     while (f.hasNext()) {
1678         f.next();
1679         FolderProjectItem *folder = new FolderProjectItem(m_listView, QStringList() << f.value(), f.key());
1680         folder->setExpanded(openedFolders.contains(f.key()));
1681     }
1682
1683     QList <DocClipBase*> list = doc->clipManager()->documentClipList();
1684     if (list.isEmpty()) {
1685         // blank document
1686         m_refreshed = true;
1687         m_allClipsProcessed = true;
1688     }
1689     for (int i = 0; i < list.count(); i++)
1690         slotAddClip(list.at(i), false);
1691
1692     m_listView->blockSignals(false);
1693     connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
1694     connect(m_doc->clipManager(), SIGNAL(modifiedClip(const QString &)), this, SLOT(slotModifiedClip(const QString &)));
1695     connect(m_doc->clipManager(), SIGNAL(missingClip(const QString &)), this, SLOT(slotMissingClip(const QString &)));
1696     connect(m_doc->clipManager(), SIGNAL(availableClip(const QString &)), this, SLOT(slotAvailableClip(const QString &)));
1697     connect(m_doc->clipManager(), SIGNAL(checkAllClips(bool, bool, QStringList)), this, SLOT(updateAllClips(bool, bool, QStringList)));
1698 }
1699
1700 QList <DocClipBase*> ProjectList::documentClipList() const
1701 {
1702     if (m_doc == NULL)
1703         return QList <DocClipBase*> ();
1704
1705     return m_doc->clipManager()->documentClipList();
1706 }
1707
1708 QDomElement ProjectList::producersList()
1709 {
1710     QDomDocument doc;
1711     QDomElement prods = doc.createElement("producerlist");
1712     doc.appendChild(prods);
1713     QTreeWidgetItemIterator it(m_listView);
1714     while (*it) {
1715         if ((*it)->type() != PROJECTCLIPTYPE) {
1716             // subitem
1717             ++it;
1718             continue;
1719         }
1720         prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
1721         ++it;
1722     }
1723     return prods;
1724 }
1725
1726 void ProjectList::slotCheckForEmptyQueue()
1727 {
1728     if (m_render->processingItems() == 0 && m_thumbnailQueue.isEmpty()) {
1729         if (!m_refreshed && m_allClipsProcessed) {
1730             m_refreshed = true;
1731             m_listView->setEnabled(true);
1732             slotClipSelected();
1733             QTimer::singleShot(500, this, SIGNAL(loadingIsOver()));
1734             emit displayMessage(QString(), -1);
1735         }
1736         updateButtons();
1737     } else if (!m_refreshed) {
1738         QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
1739     }
1740 }
1741
1742
1743 void ProjectList::requestClipThumbnail(const QString id)
1744 {
1745     if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id);
1746     slotProcessNextThumbnail();
1747 }
1748
1749 void ProjectList::resetThumbsProducer(DocClipBase *clip)
1750 {
1751     if (!clip) return;
1752     clip->clearThumbProducer();
1753     QString id = clip->getId();
1754     m_thumbnailQueue.removeAll(id);
1755 }
1756
1757 void ProjectList::slotProcessNextThumbnail()
1758 {
1759     if (m_render->processingItems() > 0) {
1760         return;
1761     }
1762     if (m_thumbnailQueue.isEmpty()) {
1763         slotCheckForEmptyQueue();
1764         return;
1765     }
1766     int max = m_doc->clipManager()->clipsCount();
1767     emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - m_thumbnailQueue.count()) / max));
1768     slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
1769 }
1770
1771 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
1772 {
1773     QTreeWidgetItem *item = getAnyItemById(clipId);
1774     if (item)
1775         slotRefreshClipThumbnail(item, update);
1776     else {
1777         slotProcessNextThumbnail();
1778     }
1779 }
1780
1781 void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
1782 {
1783     if (it == NULL) return;
1784     ProjectItem *item = NULL;
1785     bool isSubItem = false;
1786     int frame;
1787     if (it->type() == PROJECTFOLDERTYPE) return;
1788     if (it->type() == PROJECTSUBCLIPTYPE) {
1789         item = static_cast <ProjectItem *>(it->parent());
1790         frame = static_cast <SubProjectItem *>(it)->zone().x();
1791         isSubItem = true;
1792     } else {
1793         item = static_cast <ProjectItem *>(it);
1794         frame = item->referencedClip()->getClipThumbFrame();
1795     }
1796
1797     if (item) {
1798         DocClipBase *clip = item->referencedClip();
1799         if (!clip) {
1800             slotProcessNextThumbnail();
1801             return;
1802         }
1803         QPixmap pix;
1804         QImage img;
1805         int height = m_listView->iconSize().height();
1806         int swidth = (int)(height  * m_render->frameRenderWidth() / m_render->renderHeight()+ 0.5);
1807         int dwidth = (int)(height  * m_render->dar() + 0.5);
1808         if (clip->clipType() == AUDIO)
1809             pix = KIcon("audio-x-generic").pixmap(QSize(dwidth, height));
1810         else if (clip->clipType() == IMAGE)
1811             img = KThumb::getFrame(item->referencedClip()->getProducer(), 0, swidth, dwidth, height);
1812         else {
1813             img = item->referencedClip()->extractImage(frame, dwidth, height);
1814         }
1815
1816         if (!pix.isNull() || !img.isNull()) {
1817             monitorItemEditing(false);
1818             if (!img.isNull()) pix = QPixmap::fromImage(img);
1819             it->setData(0, Qt::DecorationRole, pix);
1820             monitorItemEditing(true);
1821             
1822             QString hash = item->getClipHash();
1823             if (!hash.isEmpty() && !img.isNull()) {
1824                 if (!isSubItem)
1825                     m_doc->cacheImage(hash, img);
1826                 else
1827                     m_doc->cacheImage(hash + '#' + QString::number(frame), img);
1828             }
1829         }
1830         if (update)
1831             emit projectModified();
1832         slotProcessNextThumbnail();
1833     }
1834 }
1835
1836
1837 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const stringMap &properties, const stringMap &metadata, bool replace)
1838 {
1839     QString toReload;
1840     ProjectItem *item = getItemById(clipId);
1841
1842     int queue = m_render->processingItems();
1843     if (item && producer) {
1844         monitorItemEditing(false);
1845         DocClipBase *clip = item->referencedClip();
1846         if (producer->is_valid()) {
1847             if (clip->isPlaceHolder()) {
1848                 clip->setValid();
1849                 toReload = clipId;
1850             }
1851             item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1852         }
1853         item->setProperties(properties, metadata);
1854         clip->setProducer(producer, replace);
1855
1856         // Proxy stuff
1857         QString size = properties.value("frame_size");
1858         if (!useProxy() && clip->getProperty("proxy").isEmpty()) setProxyStatus(item, NOPROXY);
1859         if (useProxy() && generateProxy() && clip->getProperty("proxy") == "-") setProxyStatus(item, NOPROXY);
1860         else if (useProxy() && !item->hasProxy() && !item->isProxyRunning()) {
1861             // proxy video and image clips
1862             int maxSize;
1863             CLIPTYPE t = item->clipType();
1864             if (t == IMAGE) maxSize = m_doc->getDocumentProperty("proxyimageminsize").toInt();
1865             else maxSize = m_doc->getDocumentProperty("proxyminsize").toInt();
1866             if ((((t == AV || t == VIDEO || t == PLAYLIST) && generateProxy()) || (t == IMAGE && generateImageProxy())) && (size.section('x', 0, 0).toInt() > maxSize || size.section('x', 1, 1).toInt() > maxSize)) {
1867                 if (clip->getProperty("proxy").isEmpty()) {
1868                     KUrl proxyPath = m_doc->projectFolder();
1869                     proxyPath.addPath("proxy/");
1870                     proxyPath.addPath(clip->getClipHash() + "." + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension")));
1871                     QMap <QString, QString> newProps;
1872                     // insert required duration for proxy
1873                     if (t != IMAGE) newProps.insert("proxy_out", clip->producerProperty("out"));
1874                     newProps.insert("proxy", proxyPath.path());
1875                     QMap <QString, QString> oldProps = clip->properties();
1876                     oldProps.insert("proxy", QString());
1877                     EditClipCommand *command = new EditClipCommand(this, clipId, oldProps, newProps, true);
1878                     m_doc->commandStack()->push(command);
1879                 }
1880             }
1881         }
1882
1883         if (!replace && m_allClipsProcessed && item->data(0, Qt::DecorationRole).isNull()) {
1884             getCachedThumbnail(item);
1885         }
1886         if (!toReload.isEmpty())
1887             item->slotSetToolTip();
1888     } else kDebug() << "////////  COULD NOT FIND CLIP TO UPDATE PRPS...";
1889     if (queue == 0) {
1890         monitorItemEditing(true);
1891         if (item && m_thumbnailQueue.isEmpty()) {
1892             if (!item->hasProxy() || m_render->activeClipId() == item->clipId())
1893                 m_listView->setCurrentItem(item);
1894             bool updatedProfile = false;
1895             if (item->parent()) {
1896                 if (item->parent()->type() == PROJECTFOLDERTYPE)
1897                     static_cast <FolderProjectItem *>(item->parent())->switchIcon();
1898             } else if (KdenliveSettings::checkfirstprojectclip() &&  m_listView->topLevelItemCount() == 1 && m_refreshed && m_allClipsProcessed) {
1899                 // this is the first clip loaded in project, check if we want to adjust project settings to the clip
1900                 updatedProfile = adjustProjectProfileToItem(item);
1901             }
1902             if (updatedProfile == false) {
1903                 //emit clipSelected(item->referencedClip());
1904             }
1905         } else {
1906             int max = m_doc->clipManager()->clipsCount();
1907             if (max > 0) emit displayMessage(i18n("Loading clips"), (int)(100 *(max - queue) / max));
1908         }
1909         if (m_allClipsProcessed) emit processNextThumbnail();
1910     }
1911     if (!item) {
1912         // no item for producer, delete it
1913         delete producer;
1914         return;
1915     }
1916     if (replace) toReload = clipId;
1917     if (!toReload.isEmpty())
1918         emit clipNeedsReload(toReload);
1919 }
1920
1921 bool ProjectList::adjustProjectProfileToItem(ProjectItem *item)
1922 {
1923     if (item == NULL) {
1924         if (m_listView->currentItem() && m_listView->currentItem()->type() != PROJECTFOLDERTYPE)
1925             item = static_cast <ProjectItem*>(m_listView->currentItem());
1926     }
1927     if (item == NULL || item->referencedClip() == NULL) {
1928         KMessageBox::information(kapp->activeWindow(), i18n("Cannot find profile from current clip"));
1929         return false;
1930     }
1931     bool profileUpdated = false;
1932     QString size = item->referencedClip()->getProperty("frame_size");
1933     int width = size.section('x', 0, 0).toInt();
1934     int height = size.section('x', -1).toInt();
1935     double fps = item->referencedClip()->getProperty("fps").toDouble();
1936     double par = item->referencedClip()->getProperty("aspect_ratio").toDouble();
1937     if (item->clipType() == IMAGE || item->clipType() == AV || item->clipType() == VIDEO) {
1938         if (ProfilesDialog::matchProfile(width, height, fps, par, item->clipType() == IMAGE, m_doc->mltProfile()) == false) {
1939             // get a list of compatible profiles
1940             QMap <QString, QString> suggestedProfiles = ProfilesDialog::getProfilesFromProperties(width, height, fps, par, item->clipType() == IMAGE);
1941             if (!suggestedProfiles.isEmpty()) {
1942                 KDialog *dialog = new KDialog(this);
1943                 dialog->setCaption(i18n("Change project profile"));
1944                 dialog->setButtons(KDialog::Ok | KDialog::Cancel);
1945
1946                 QWidget container;
1947                 QVBoxLayout *l = new QVBoxLayout;
1948                 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));
1949                 l->addWidget(label);
1950                 QListWidget *list = new QListWidget;
1951                 list->setAlternatingRowColors(true);
1952                 QMapIterator<QString, QString> i(suggestedProfiles);
1953                 while (i.hasNext()) {
1954                     i.next();
1955                     QListWidgetItem *item = new QListWidgetItem(i.value(), list);
1956                     item->setData(Qt::UserRole, i.key());
1957                     item->setToolTip(i.key());
1958                 }
1959                 list->setCurrentRow(0);
1960                 l->addWidget(list);
1961                 container.setLayout(l);
1962                 dialog->setButtonText(KDialog::Ok, i18n("Update profile"));
1963                 dialog->setMainWidget(&container);
1964                 if (dialog->exec() == QDialog::Accepted) {
1965                     //Change project profile
1966                     profileUpdated = true;
1967                     if (list->currentItem())
1968                         emit updateProfile(list->currentItem()->data(Qt::UserRole).toString());
1969                 }
1970                 delete list;
1971                 delete label;
1972             } else if (fps > 0) {
1973                 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));
1974             }
1975         }
1976     }
1977     return profileUpdated;
1978 }
1979
1980 QString ProjectList::getDocumentProperty(const QString &key) const
1981 {
1982     return m_doc->getDocumentProperty(key);
1983 }
1984
1985 bool ProjectList::useProxy() const
1986 {
1987     return m_doc->getDocumentProperty("enableproxy").toInt();
1988 }
1989
1990 bool ProjectList::generateProxy() const
1991 {
1992     return m_doc->getDocumentProperty("generateproxy").toInt();
1993 }
1994
1995 bool ProjectList::generateImageProxy() const
1996 {
1997     return m_doc->getDocumentProperty("generateimageproxy").toInt();
1998 }
1999
2000 void ProjectList::slotReplyGetImage(const QString &clipId, const QImage &img)
2001 {
2002     ProjectItem *item = getItemById(clipId);
2003     if (item && !img.isNull()) {
2004         QPixmap pix = QPixmap::fromImage(img);
2005         monitorItemEditing(false);
2006         item->setData(0, Qt::DecorationRole, pix);
2007         monitorItemEditing(true);
2008         QString hash = item->getClipHash();
2009         if (!hash.isEmpty()) m_doc->cacheImage(hash, img);
2010     }
2011 }
2012
2013 void ProjectList::slotReplyGetImage(const QString &clipId, const QString &name, int width, int height)
2014 {
2015     // For clips that have a generic icon (like audio clips...)
2016     ProjectItem *item = getItemById(clipId);
2017     QPixmap pix =  KIcon(name).pixmap(QSize(width, height));
2018     if (item && !pix.isNull()) {
2019         monitorItemEditing(false);
2020         item->setData(0, Qt::DecorationRole, pix);
2021         monitorItemEditing(true);
2022     }
2023 }
2024
2025 QTreeWidgetItem *ProjectList::getAnyItemById(const QString &id)
2026 {
2027     QTreeWidgetItemIterator it(m_listView);
2028     QString lookId = id;
2029     if (id.contains('#'))
2030         lookId = id.section('#', 0, 0);
2031
2032     ProjectItem *result = NULL;
2033     while (*it) {
2034         if ((*it)->type() != PROJECTCLIPTYPE) {
2035             // subitem
2036             ++it;
2037             continue;
2038         }
2039         ProjectItem *item = static_cast<ProjectItem *>(*it);
2040         if (item->clipId() == lookId) {
2041             result = item;
2042             break;
2043         }
2044         ++it;
2045     }
2046     if (result == NULL || !id.contains('#')) {
2047         return result;
2048     } else {
2049         for (int i = 0; i < result->childCount(); i++) {
2050             SubProjectItem *sub = static_cast <SubProjectItem *>(result->child(i));
2051             if (sub && sub->zone().x() == id.section('#', 1, 1).toInt())
2052                 return sub;
2053         }
2054     }
2055
2056     return NULL;
2057 }
2058
2059
2060 ProjectItem *ProjectList::getItemById(const QString &id)
2061 {
2062     ProjectItem *item;
2063     QTreeWidgetItemIterator it(m_listView);
2064     while (*it) {
2065         if ((*it)->type() != PROJECTCLIPTYPE) {
2066             // subitem or folder
2067             ++it;
2068             continue;
2069         }
2070         item = static_cast<ProjectItem *>(*it);
2071         if (item->clipId() == id)
2072             return item;
2073         ++it;
2074     }
2075     return NULL;
2076 }
2077
2078 FolderProjectItem *ProjectList::getFolderItemById(const QString &id)
2079 {
2080     FolderProjectItem *item;
2081     QTreeWidgetItemIterator it(m_listView);
2082     while (*it) {
2083         if ((*it)->type() == PROJECTFOLDERTYPE) {
2084             item = static_cast<FolderProjectItem *>(*it);
2085             if (item->clipId() == id)
2086                 return item;
2087         }
2088         ++it;
2089     }
2090     return NULL;
2091 }
2092
2093 void ProjectList::slotSelectClip(const QString &ix)
2094 {
2095     ProjectItem *clip = getItemById(ix);
2096     if (clip) {
2097         m_listView->setCurrentItem(clip);
2098         m_listView->scrollToItem(clip);
2099         m_editButton->defaultAction()->setEnabled(true);
2100         m_deleteButton->defaultAction()->setEnabled(true);
2101         m_reloadAction->setEnabled(true);
2102         m_transcodeAction->setEnabled(true);
2103         m_stabilizeAction->setEnabled(true);
2104         if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
2105             m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
2106             m_openAction->setEnabled(true);
2107         } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
2108             m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
2109             m_openAction->setEnabled(true);
2110         } else {
2111             m_openAction->setEnabled(false);
2112         }
2113     }
2114 }
2115
2116 QString ProjectList::currentClipUrl() const
2117 {
2118     ProjectItem *item;
2119     if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return QString();
2120     if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
2121         // subitem
2122         item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
2123     } else {
2124         item = static_cast <ProjectItem*>(m_listView->currentItem());
2125     }
2126     if (item == NULL)
2127         return QString();
2128     return item->clipUrl().path();
2129 }
2130
2131 KUrl::List ProjectList::getConditionalUrls(const QString &condition) const
2132 {
2133     KUrl::List result;
2134     ProjectItem *item;
2135     QList<QTreeWidgetItem *> list = m_listView->selectedItems();
2136     for (int i = 0; i < list.count(); i++) {
2137         if (list.at(i)->type() == PROJECTFOLDERTYPE)
2138             continue;
2139         if (list.at(i)->type() == PROJECTSUBCLIPTYPE) {
2140             // subitem
2141             item = static_cast <ProjectItem*>(list.at(i)->parent());
2142         } else {
2143             item = static_cast <ProjectItem*>(list.at(i));
2144         }
2145         if (item == NULL || item->type() == COLOR || item->type() == SLIDESHOW || item->type() == TEXT)
2146             continue;
2147         DocClipBase *clip = item->referencedClip();
2148         if (!condition.isEmpty()) {
2149             if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section('=', 1, 1)))
2150                 continue;
2151             else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section('=', 1, 1)))
2152                 continue;
2153         }
2154         result.append(item->clipUrl());
2155     }
2156     return result;
2157 }
2158
2159 void ProjectList::regenerateTemplate(const QString &id)
2160 {
2161     ProjectItem *clip = getItemById(id);
2162     if (clip)
2163         regenerateTemplate(clip);
2164 }
2165
2166 void ProjectList::regenerateTemplate(ProjectItem *clip)
2167 {
2168     //TODO: remove this unused method, only force_reload is necessary
2169     clip->referencedClip()->getProducer()->set("force_reload", 1);
2170 }
2171
2172 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
2173 {
2174     QDomDocument doc;
2175     QFile file(path);
2176     if (!file.open(QIODevice::ReadOnly)) {
2177         kWarning() << "ERROR, CANNOT READ: " << path;
2178         return doc;
2179     }
2180     if (!doc.setContent(&file)) {
2181         kWarning() << "ERROR, CANNOT READ: " << path;
2182         file.close();
2183         return doc;
2184     }
2185     file.close();
2186     QDomNodeList texts = doc.elementsByTagName("content");
2187     for (int i = 0; i < texts.count(); i++) {
2188         QString data = texts.item(i).firstChild().nodeValue();
2189         data.replace("%s", replaceString);
2190         texts.item(i).firstChild().setNodeValue(data);
2191     }
2192     return doc;
2193 }
2194
2195
2196 void ProjectList::slotAddClipCut(const QString &id, int in, int out)
2197 {
2198     ProjectItem *clip = getItemById(id);
2199     if (clip == NULL || clip->referencedClip()->hasCutZone(QPoint(in, out)))
2200         return;
2201     AddClipCutCommand *command = new AddClipCutCommand(this, id, in, out, QString(), true, false);
2202     m_commandStack->push(command);
2203 }
2204
2205 void ProjectList::addClipCut(const QString &id, int in, int out, const QString desc, bool newItem)
2206 {
2207     ProjectItem *clip = getItemById(id);
2208     if (clip) {
2209         DocClipBase *base = clip->referencedClip();
2210         base->addCutZone(in, out);
2211         monitorItemEditing(false);
2212         SubProjectItem *sub = new SubProjectItem(clip, in, out, desc);
2213         if (newItem && desc.isEmpty() && !m_listView->isColumnHidden(1)) {
2214             if (!clip->isExpanded())
2215                 clip->setExpanded(true);
2216             m_listView->scrollToItem(sub);
2217             m_listView->editItem(sub, 1);
2218         }
2219         QImage img = clip->referencedClip()->extractImage(in, (int)(sub->sizeHint(0).height()  * m_render->dar()), sub->sizeHint(0).height() - 2);
2220         sub->setData(0, Qt::DecorationRole, QPixmap::fromImage(img));
2221         QString hash = clip->getClipHash();
2222         if (!hash.isEmpty()) m_doc->cacheImage(hash + '#' + QString::number(in), img);
2223         monitorItemEditing(true);
2224     }
2225     emit projectModified();
2226 }
2227
2228 void ProjectList::removeClipCut(const QString &id, int in, int out)
2229 {
2230     ProjectItem *clip = getItemById(id);
2231     if (clip) {
2232         DocClipBase *base = clip->referencedClip();
2233         base->removeCutZone(in, out);
2234         SubProjectItem *sub = getSubItem(clip, QPoint(in, out));
2235         if (sub) {
2236             monitorItemEditing(false);
2237             delete sub;
2238             monitorItemEditing(true);
2239         }
2240     }
2241     emit projectModified();
2242 }
2243
2244 SubProjectItem *ProjectList::getSubItem(ProjectItem *clip, QPoint zone)
2245 {
2246     SubProjectItem *sub = NULL;
2247     if (clip) {
2248         for (int i = 0; i < clip->childCount(); i++) {
2249             QTreeWidgetItem *it = clip->child(i);
2250             if (it->type() == PROJECTSUBCLIPTYPE) {
2251                 sub = static_cast <SubProjectItem*>(it);
2252                 if (sub->zone() == zone)
2253                     break;
2254                 else
2255                     sub = NULL;
2256             }
2257         }
2258     }
2259     return sub;
2260 }
2261
2262 void ProjectList::slotUpdateClipCut(QPoint p)
2263 {
2264     if (!m_listView->currentItem() || m_listView->currentItem()->type() != PROJECTSUBCLIPTYPE)
2265         return;
2266     SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
2267     ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
2268     EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), p, sub->text(1), sub->text(1), true);
2269     m_commandStack->push(command);
2270 }
2271
2272 void ProjectList::doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment)
2273 {
2274     ProjectItem *clip = getItemById(id);
2275     SubProjectItem *sub = getSubItem(clip, oldzone);
2276     if (sub == NULL || clip == NULL)
2277         return;
2278     DocClipBase *base = clip->referencedClip();
2279     base->updateCutZone(oldzone.x(), oldzone.y(), zone.x(), zone.y(), comment);
2280     monitorItemEditing(false);
2281     sub->setZone(zone);
2282     sub->setDescription(comment);
2283     monitorItemEditing(true);
2284     emit projectModified();
2285 }
2286
2287 void ProjectList::slotForceProcessing(const QString &id)
2288 {
2289     m_render->forceProcessing(id);
2290 }
2291
2292 void ProjectList::slotAddOrUpdateSequence(const QString frameName)
2293 {
2294     QString fileName = KUrl(frameName).fileName().section('_', 0, -2);
2295     QStringList list;
2296     QString pattern = SlideshowClip::selectedPath(frameName, false, QString(), &list);
2297     int count = list.count();
2298     if (count > 1) {
2299         const QList <DocClipBase *> existing = m_doc->clipManager()->getClipByResource(pattern);
2300         if (!existing.isEmpty()) {
2301             // Sequence already exists, update
2302             QString id = existing.at(0)->getId();
2303             //ProjectItem *item = getItemById(id);
2304             QMap <QString, QString> oldprops;
2305             QMap <QString, QString> newprops;
2306             int ttl = existing.at(0)->getProperty("ttl").toInt();
2307             oldprops["out"] = existing.at(0)->getProperty("out");
2308             newprops["out"] = QString::number(ttl * count - 1);
2309             slotUpdateClipProperties(id, newprops);
2310             EditClipCommand *command = new EditClipCommand(this, id, oldprops, newprops, false);
2311             m_commandStack->push(command);
2312         } else {
2313             // Create sequence
2314             QStringList groupInfo = getGroup();
2315             m_doc->slotCreateSlideshowClipFile(fileName, pattern, count, m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()),
2316                                                false, false, false,
2317                                                m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))), QString(), 0,
2318                                                QString(), groupInfo.at(0), groupInfo.at(1));
2319         }
2320     } else emit displayMessage(i18n("Sequence not found"), -2);
2321 }
2322
2323 QMap <QString, QString> ProjectList::getProxies()
2324 {
2325     QMap <QString, QString> list;
2326     ProjectItem *item;
2327     QTreeWidgetItemIterator it(m_listView);
2328     while (*it) {
2329         if ((*it)->type() != PROJECTCLIPTYPE) {
2330             ++it;
2331             continue;
2332         }
2333         item = static_cast<ProjectItem *>(*it);
2334         if (item && item->referencedClip() != NULL) {
2335             if (item->hasProxy()) {
2336                 QString proxy = item->referencedClip()->getProperty("proxy");
2337                 list.insert(proxy, item->clipUrl().path());
2338             }
2339         }
2340         ++it;
2341     }
2342     return list;
2343 }
2344
2345 void ProjectList::slotCreateProxy(const QString id)
2346 {
2347     ProjectItem *item = getItemById(id);
2348     if (!item || item->isProxyRunning() || item->referencedClip()->isPlaceHolder()) return;
2349     QString path = item->referencedClip()->getProperty("proxy");
2350     if (path.isEmpty()) {
2351         setProxyStatus(item, PROXYCRASHED);
2352         return;
2353     }
2354     setProxyStatus(item, PROXYWAITING);
2355     if (m_abortProxy.contains(path)) m_abortProxy.removeAll(path);
2356     if (m_processingProxy.contains(path)) {
2357         // Proxy is already being generated
2358         return;
2359     }
2360     if (QFileInfo(path).size() > 0) {
2361         // Proxy already created
2362         setProxyStatus(item, PROXYDONE);
2363         slotGotProxy(path);
2364         return;
2365     }
2366     m_processingProxy.append(path);
2367
2368     PROXYINFO info;
2369     info.dest = path;
2370     info.src = item->clipUrl().path();
2371     info.type = item->clipType();
2372     info.exif = QString(item->referencedClip()->producerProperty("_exif_orientation")).toInt();
2373     m_proxyList.append(info);
2374     if (!m_proxyThreads.futures().isEmpty()) {
2375         // Remove inactive threads
2376         QList <QFuture<void> > futures = m_proxyThreads.futures();
2377         m_proxyThreads.clearFutures();
2378         for (int i = 0; i < futures.count(); i++)
2379             if (!futures.at(i).isFinished()) {
2380                 m_proxyThreads.addFuture(futures.at(i));
2381             }
2382     }
2383     if (m_proxyThreads.futures().isEmpty() || m_proxyThreads.futures().count() < KdenliveSettings::proxythreads()) m_proxyThreads.addFuture(QtConcurrent::run(this, &ProjectList::slotGenerateProxy));
2384 }
2385
2386 void ProjectList::slotAbortProxy(const QString id, const QString path)
2387 {
2388     QTreeWidgetItemIterator it(m_listView);
2389     ProjectItem *item = getItemById(id);
2390     if (!path.isEmpty() && m_processingProxy.contains(path)) {
2391         m_abortProxy << path;
2392         setProxyStatus(item, NOPROXY);
2393     }
2394     else {
2395         setProxyStatus(item, NOPROXY);
2396         slotGotProxy(item);
2397     }
2398 }
2399
2400 void ProjectList::slotGenerateProxy()
2401 {
2402     while (!m_proxyList.isEmpty() && !m_abortAllProxies) {
2403         emit projectModified();
2404         PROXYINFO info = m_proxyList.takeFirst();
2405         if (m_abortProxy.contains(info.dest)) {
2406             m_abortProxy.removeAll(info.dest);
2407             continue;
2408         }
2409         // Get the list of clips that will need to get progress info
2410         QTreeWidgetItemIterator it(m_listView);
2411         QList <ProjectItem *> processingItems;
2412         while (*it && !m_abortAllProxies) {
2413             if ((*it)->type() == PROJECTCLIPTYPE) {
2414                 ProjectItem *item = static_cast <ProjectItem *>(*it);
2415                 if (item->referencedClip()->getProperty("proxy") == info.dest) {
2416                     processingItems.append(item);
2417                 }
2418             }
2419             ++it;
2420         }
2421
2422         // Make sure proxy path is writable
2423         QFile file(info.dest);
2424         if (!file.open(QIODevice::WriteOnly)) {
2425             for (int i = 0; i < processingItems.count(); i++)
2426                 setProxyStatus(processingItems.at(i), PROXYCRASHED);
2427             m_processingProxy.removeAll(info.dest);
2428             continue;
2429         }
2430         file.close();
2431         QFile::remove(info.dest);
2432     
2433         for (int i = 0; i < processingItems.count(); i++)
2434             setProxyStatus(processingItems.at(i), CREATINGPROXY);
2435
2436         // Special case: playlist clips (.mlt or .kdenlive project files)
2437         if (info.type == PLAYLIST) {
2438             // change FFmpeg params to MLT format
2439             QStringList parameters;
2440             parameters << info.src;
2441             parameters << "-consumer" << "avformat:" + info.dest;
2442             QStringList params = m_doc->getDocumentProperty("proxyparams").simplified().split('-', QString::SkipEmptyParts);
2443         
2444             foreach(QString s, params) {
2445                 s = s.simplified();
2446                 if (s.count(' ') == 0) {
2447                     s.append("=1");
2448                 }
2449                 else s.replace(' ', '=');
2450                 parameters << s;
2451             }
2452         
2453             parameters.append(QString("real_time=-%1").arg(KdenliveSettings::mltthreads()));
2454
2455             //TODO: currently, when rendering an xml file through melt, the display ration is lost, so we enforce it manualy
2456             double display_ratio = KdenliveDoc::getDisplayRatio(info.src);
2457             parameters << "aspect=" + QString::number(display_ratio);
2458
2459             //kDebug()<<"TRANSCOD: "<<parameters;
2460             QProcess myProcess;
2461             myProcess.setProcessChannelMode(QProcess::MergedChannels);
2462             myProcess.start(KdenliveSettings::rendererpath(), parameters);
2463             myProcess.waitForStarted();
2464             int result = -1;
2465             int duration = 0;
2466             while (myProcess.state() != QProcess::NotRunning) {
2467                 // building proxy file
2468                 if (m_abortProxy.contains(info.dest) || m_abortAllProxies) {
2469                     myProcess.close();
2470                     myProcess.waitForFinished();
2471                     QFile::remove(info.dest);
2472                     m_abortProxy.removeAll(info.dest);
2473                     m_processingProxy.removeAll(info.dest);
2474                     for (int i = 0; i < processingItems.count(); i++)
2475                         setProxyStatus(processingItems.at(i), NOPROXY);
2476                     result = -2;
2477                 }
2478                 else {
2479                     QString log = QString(myProcess.readAll());
2480                     processLogInfo(processingItems, &duration, log);
2481                 }
2482                 myProcess.waitForFinished(500);
2483             }
2484             myProcess.waitForFinished();
2485             m_processingProxy.removeAll(info.dest);
2486             if (result == -1) result = myProcess.exitStatus();
2487             if (result == 0) {
2488                 // proxy successfully created
2489                 for (int i = 0; i < processingItems.count(); i++)
2490                     setProxyStatus(processingItems.at(i), PROXYDONE);
2491                 slotGotProxy(info.dest);
2492             }
2493             else if (result == 1) {
2494                 // Proxy process crashed
2495                 QFile::remove(info.dest);
2496                 for (int i = 0; i < processingItems.count(); i++)
2497                     setProxyStatus(processingItems.at(i), PROXYCRASHED);
2498             }
2499             continue;
2500         }
2501     
2502         if (info.type == IMAGE) {
2503             // Image proxy
2504             QImage i(info.src);
2505             if (i.isNull()) {
2506                 // Cannot load image
2507                 for (int i = 0; i < processingItems.count(); i++)
2508                     setProxyStatus(processingItems.at(i), PROXYCRASHED);
2509                 continue;
2510             }
2511             QImage proxy;
2512             // Images are scaled to profile size. 
2513             //TODO: Make it be configurable?
2514             if (i.width() > i.height()) proxy = i.scaledToWidth(m_render->frameRenderWidth());
2515             else proxy = i.scaledToHeight(m_render->renderHeight());
2516             if (info.exif > 1) {
2517                 // Rotate image according to exif data
2518                 QImage processed;
2519                 QMatrix matrix;
2520
2521                 switch ( info.exif ) {
2522                     case 2:
2523                         matrix.scale( -1, 1 );
2524                         break;
2525                     case 3:
2526                         matrix.rotate( 180 );
2527                         break;
2528                     case 4:
2529                         matrix.scale( 1, -1 );
2530                         break;
2531                     case 5:
2532                         matrix.rotate( 270 );
2533                         matrix.scale( -1, 1 );
2534                         break;
2535                     case 6:
2536                         matrix.rotate( 90 );
2537                         break;
2538                     case 7:
2539                         matrix.rotate( 90 );
2540                         matrix.scale( -1, 1 );
2541                         break;
2542                     case 8:
2543                         matrix.rotate( 270 );
2544                         break;
2545                 }
2546                 processed = proxy.transformed( matrix );
2547                 processed.save(info.dest);
2548             }
2549             else proxy.save(info.dest);
2550             for (int i = 0; i < processingItems.count(); i++)
2551                 setProxyStatus(processingItems.at(i), PROXYDONE);
2552             slotGotProxy(info.dest);
2553             m_abortProxy.removeAll(info.dest);
2554             m_processingProxy.removeAll(info.dest);
2555             continue;
2556         }
2557
2558         QStringList parameters;
2559         parameters << "-i" << info.src;
2560         QString params = m_doc->getDocumentProperty("proxyparams").simplified();
2561         foreach(QString s, params.split(' '))
2562         parameters << s;
2563
2564         // Make sure we don't block when proxy file already exists
2565         parameters << "-y";
2566         parameters << info.dest;
2567         QProcess myProcess;
2568         myProcess.setProcessChannelMode(QProcess::MergedChannels);
2569         myProcess.start("ffmpeg", parameters);
2570         myProcess.waitForStarted();
2571         int result = -1;
2572         int duration = 0;
2573    
2574         while (myProcess.state() != QProcess::NotRunning) {
2575             // building proxy file
2576             if (m_abortProxy.contains(info.dest) || m_abortAllProxies) {
2577                 myProcess.close();
2578                 myProcess.waitForFinished();
2579                 m_abortProxy.removeAll(info.dest);
2580                 m_processingProxy.removeAll(info.dest);
2581                 QFile::remove(info.dest);
2582                 if (!m_abortAllProxies) {
2583                     for (int i = 0; i < processingItems.count(); i++)
2584                         setProxyStatus(processingItems.at(i), NOPROXY);
2585                 }
2586                 else continue;
2587                 result = -2;
2588             }
2589             else {
2590                 QString log = QString(myProcess.readAll());
2591                 processLogInfo(processingItems, &duration, log);
2592             }
2593             myProcess.waitForFinished(500);
2594         }
2595         myProcess.waitForFinished();
2596         m_abortProxy.removeAll(info.dest);
2597         m_processingProxy.removeAll(info.dest);
2598         if (result == -1) {
2599             result = myProcess.exitStatus();
2600         }
2601         
2602         // FFmpeg process terminated normally, but make sure proxy clip exists
2603         if (result != -2 && QFileInfo(info.dest).size() == 0) {
2604             result = QProcess::CrashExit;
2605         }
2606
2607         if (result == QProcess::NormalExit) {
2608             // proxy successfully created
2609             for (int i = 0; i < processingItems.count(); i++)
2610                 setProxyStatus(processingItems.at(i), PROXYDONE);
2611             slotGotProxy(info.dest);
2612         }
2613         else if (result == QProcess::CrashExit) {
2614             // Proxy process crashed
2615             QFile::remove(info.dest);
2616             for (int i = 0; i < processingItems.count(); i++)
2617                 setProxyStatus(processingItems.at(i), PROXYCRASHED);
2618         }
2619     }
2620 }
2621
2622
2623 void ProjectList::processLogInfo(QList <ProjectItem *>items, int *duration, const QString &log)
2624 {
2625     int progress;
2626     if (*duration == 0) {
2627         if (log.contains("Duration:")) {
2628             QString data = log.section("Duration:", 1, 1).section(',', 0, 0).simplified();
2629             QStringList numbers = data.split(':');
2630             *duration = (int) (numbers.at(0).toInt() * 3600 + numbers.at(1).toInt() * 60 + numbers.at(2).toDouble());
2631         }
2632     }
2633     else if (log.contains("time=")) {
2634         QString time = log.section("time=", 1, 1).simplified().section(' ', 0, 0);
2635         if (time.contains(':')) {
2636             QStringList numbers = time.split(':');
2637             progress = numbers.at(0).toInt() * 3600 + numbers.at(1).toInt() * 60 + numbers.at(2).toDouble();
2638         }
2639         else progress = (int) time.toDouble();
2640         for (int i = 0; i < items.count(); i++)
2641             setProxyStatus(items.at(i), CREATINGPROXY, (int) (100.0 * progress / (*duration)));
2642     }
2643 }
2644
2645 void ProjectList::updateProxyConfig()
2646 {
2647     ProjectItem *item;
2648     QTreeWidgetItemIterator it(m_listView);
2649     QUndoCommand *command = new QUndoCommand();
2650     command->setText(i18n("Update proxy settings"));
2651     QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/";
2652     while (*it) {
2653         if ((*it)->type() != PROJECTCLIPTYPE) {
2654             ++it;
2655             continue;
2656         }
2657         item = static_cast<ProjectItem *>(*it);
2658         if (item == NULL) {
2659             ++it;
2660             continue;
2661         }
2662         CLIPTYPE t = item->clipType();
2663         if ((t == VIDEO || t == AV || t == UNKNOWN) && item->referencedClip() != NULL) {
2664             if  (generateProxy() && useProxy() && !item->isProxyRunning()) {
2665                 DocClipBase *clip = item->referencedClip();
2666                 if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > m_doc->getDocumentProperty("proxyminsize").toInt()) {
2667                     if (clip->getProperty("proxy").isEmpty()) {
2668                         // We need to insert empty proxy in old properties so that undo will work
2669                         QMap <QString, QString> oldProps;// = clip->properties();
2670                         oldProps.insert("proxy", QString());
2671                         QMap <QString, QString> newProps;
2672                         newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + "." + m_doc->getDocumentProperty("proxyextension"));
2673                         new EditClipCommand(this, clip->getId(), oldProps, newProps, true, command);
2674                     }
2675                 }
2676             }
2677             else if (item->hasProxy()) {
2678                 // remove proxy
2679                 QMap <QString, QString> newProps;
2680                 newProps.insert("proxy", QString());
2681                 newProps.insert("replace", "1");
2682                 // insert required duration for proxy
2683                 newProps.insert("proxy_out", item->referencedClip()->producerProperty("out"));
2684                 new EditClipCommand(this, item->clipId(), item->referencedClip()->currentProperties(newProps), newProps, true, command);
2685             }
2686         }
2687         else if (t == IMAGE && item->referencedClip() != NULL) {
2688             if  (generateImageProxy() && useProxy()) {
2689                 DocClipBase *clip = item->referencedClip();
2690                 int maxImageSize = m_doc->getDocumentProperty("proxyimageminsize").toInt();
2691                 if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > maxImageSize || clip->getProperty("frame_size").section('x', 1, 1).toInt() > maxImageSize) {
2692                     if (clip->getProperty("proxy").isEmpty()) {
2693                         // We need to insert empty proxy in old properties so that undo will work
2694                         QMap <QString, QString> oldProps = clip->properties();
2695                         oldProps.insert("proxy", QString());
2696                         QMap <QString, QString> newProps;
2697                         newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + ".png");
2698                         new EditClipCommand(this, clip->getId(), oldProps, newProps, true, command);
2699                     }
2700                 }
2701             }
2702             else if (item->hasProxy()) {
2703                 // remove proxy
2704                 QMap <QString, QString> newProps;
2705                 newProps.insert("proxy", QString());
2706                 newProps.insert("replace", "1");
2707                 new EditClipCommand(this, item->clipId(), item->referencedClip()->properties(), newProps, true, command);
2708             }
2709         }
2710         ++it;
2711     }
2712     if (command->childCount() > 0) m_doc->commandStack()->push(command);
2713     else delete command;
2714 }
2715
2716 void ProjectList::slotProxyCurrentItem(bool doProxy, ProjectItem *itemToProxy)
2717 {
2718     QList<QTreeWidgetItem *> list;
2719     if (itemToProxy == NULL) list = m_listView->selectedItems();
2720     else list << itemToProxy;
2721
2722     // expand list (folders, subclips) to get real clips
2723     QTreeWidgetItem *listItem;
2724     QList<ProjectItem *> clipList;
2725     for (int i = 0; i < list.count(); i++) {
2726         listItem = list.at(i);
2727         if (listItem->type() == PROJECTFOLDERTYPE) {
2728             for (int j = 0; j < listItem->childCount(); j++) {
2729                 QTreeWidgetItem *sub = listItem->child(j);
2730                 if (sub->type() == PROJECTCLIPTYPE) {
2731                     ProjectItem *item = static_cast <ProjectItem*>(sub);
2732                     if (!clipList.contains(item)) clipList.append(item);
2733                 }
2734             }
2735         }
2736         else if (listItem->type() == PROJECTSUBCLIPTYPE) {
2737             QTreeWidgetItem *sub = listItem->parent();
2738             ProjectItem *item = static_cast <ProjectItem*>(sub);
2739             if (!clipList.contains(item)) clipList.append(item);
2740         }
2741         else if (listItem->type() == PROJECTCLIPTYPE) {
2742             ProjectItem *item = static_cast <ProjectItem*>(listItem);
2743             if (!clipList.contains(item)) clipList.append(item);
2744         }
2745     }
2746     
2747     QUndoCommand *command = new QUndoCommand();
2748     if (doProxy) command->setText(i18np("Add proxy clip", "Add proxy clips", clipList.count()));
2749     else command->setText(i18np("Remove proxy clip", "Remove proxy clips", clipList.count()));
2750     
2751     // Make sure the proxy folder exists
2752     QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/";
2753     KStandardDirs::makeDir(proxydir);
2754                 
2755     QMap <QString, QString> newProps;
2756     QMap <QString, QString> oldProps;
2757     if (!doProxy) newProps.insert("proxy", "-");
2758     for (int i = 0; i < clipList.count(); i++) {
2759         ProjectItem *item = clipList.at(i);
2760         CLIPTYPE t = item->clipType();
2761         if ((t == VIDEO || t == AV || t == UNKNOWN || t == IMAGE || t == PLAYLIST) && item->referencedClip()) {
2762             if ((doProxy && item->hasProxy()) || (!doProxy && !item->hasProxy() && item->referencedClip()->getProducer() != NULL)) continue;
2763             DocClipBase *clip = item->referencedClip();
2764             if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
2765                 kDebug()<<"//// TRYING TO PROXY: "<<item->clipId()<<", but it is busy";
2766                 continue;
2767             }
2768                 
2769             oldProps = clip->properties();
2770             if (doProxy) {
2771                 newProps.clear();
2772                 QString path = proxydir + clip->getClipHash() + "." + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension"));
2773                 // insert required duration for proxy
2774                 newProps.insert("proxy_out", clip->producerProperty("out"));
2775                 newProps.insert("proxy", path);
2776                 // We need to insert empty proxy so that undo will work
2777                 oldProps.insert("proxy", QString());
2778             }
2779             else if (item->referencedClip()->getProducer() == NULL) {
2780                 // Force clip reload
2781                 kDebug()<<"// CLIP HAD NULL PROD------------";
2782                 newProps.insert("resource", item->referencedClip()->getProperty("resource"));
2783             }
2784             new EditClipCommand(this, item->clipId(), oldProps, newProps, true, command);
2785         }
2786     }
2787     if (command->childCount() > 0) {
2788         m_doc->commandStack()->push(command);
2789     }
2790     else delete command;
2791 }
2792
2793
2794 void ProjectList::slotDeleteProxy(const QString proxyPath)
2795 {
2796     if (proxyPath.isEmpty()) return;
2797     QUndoCommand *proxyCommand = new QUndoCommand();
2798     proxyCommand->setText(i18n("Remove Proxy"));
2799     QTreeWidgetItemIterator it(m_listView);
2800     ProjectItem *item;
2801     while (*it) {
2802         if ((*it)->type() == PROJECTCLIPTYPE) {
2803             item = static_cast <ProjectItem *>(*it);
2804             if (item->referencedClip()->getProperty("proxy") == proxyPath) {
2805                 QMap <QString, QString> props;
2806                 props.insert("proxy", QString());
2807                 new EditClipCommand(this, item->clipId(), item->referencedClip()->currentProperties(props), props, true, proxyCommand);
2808             
2809             }
2810         }
2811         ++it;
2812     }
2813     if (proxyCommand->childCount() == 0)
2814         delete proxyCommand;
2815     else
2816         m_commandStack->push(proxyCommand);
2817     QFile::remove(proxyPath);
2818 }
2819
2820 void ProjectList::setProxyStatus(ProjectItem *item, PROXYSTATUS status, int progress)
2821 {
2822     if (item == NULL || m_abortAllProxies) return;
2823     monitorItemEditing(false);
2824     item->setProxyStatus(status, progress);
2825     if (status == PROXYCRASHED) {
2826         DocClipBase *clip = item->referencedClip();
2827         if (!clip) {
2828             kDebug()<<"// PROXY CRASHED";
2829         }
2830         else if (clip->getProducer() == NULL && !clip->isPlaceHolder()) {
2831             // disable proxy and fetch real clip
2832             clip->setProperty("proxy", "-");
2833             QDomElement xml = clip->toXML();
2834             m_render->getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), true);
2835         }
2836         else {
2837             // Disable proxy for this clip
2838             clip->setProperty("proxy", "-");
2839         }
2840     }
2841     monitorItemEditing(true);
2842 }
2843
2844 void ProjectList::monitorItemEditing(bool enable)
2845 {
2846     if (enable) connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));     
2847     else disconnect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));     
2848 }
2849
2850 QStringList ProjectList::expandedFolders() const
2851 {
2852     QStringList result;
2853     FolderProjectItem *item;
2854     QTreeWidgetItemIterator it(m_listView);
2855     while (*it) {
2856         if ((*it)->type() != PROJECTFOLDERTYPE) {
2857             ++it;
2858             continue;
2859         }
2860         if ((*it)->isExpanded()) {
2861             item = static_cast<FolderProjectItem *>(*it);
2862             result.append(item->clipId());
2863         }
2864         ++it;
2865     }
2866     return result;
2867 }
2868
2869 #include "projectlist.moc"