]> git.sesse.net Git - kdenlive/blob - src/projectlist.cpp
Fix small bug in audio thumbs creation
[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             emit clipSelected(item->referencedClip(), item->referencedClip()->zone(), true);
774         } else if (properties.contains("full_luma") || properties.contains("force_colorspace") || properties.contains("loop")) {
775             emit refreshClip(id, false);
776         }
777     }
778 }
779
780 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
781 {
782     if (!clip)
783         return;
784     clip->setProperties(properties);
785     if (properties.contains("name")) {
786         monitorItemEditing(false);
787         clip->setText(0, properties.value("name"));
788         monitorItemEditing(true);
789         emit clipNameChanged(clip->clipId(), properties.value("name"));
790     }
791     if (properties.contains("description")) {
792         CLIPTYPE type = clip->clipType();
793         monitorItemEditing(false);
794         clip->setText(1, properties.value("description"));
795         monitorItemEditing(true);
796 #ifdef NEPOMUK
797         if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
798             // Use Nepomuk system to store clip description
799             Nepomuk::Resource f(clip->clipUrl().path());
800             f.setDescription(properties.value("description"));
801         }
802 #endif
803         emit projectModified();
804     }
805 }
806
807 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
808 {
809     if (item->type() == PROJECTSUBCLIPTYPE) {
810         // this is a sub-item
811         if (column == 1) {
812             // user edited description
813             SubProjectItem *sub = static_cast <SubProjectItem*>(item);
814             ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
815             EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), sub->zone(), sub->description(), sub->text(1), true);
816             m_commandStack->push(command);
817             //slotUpdateCutClipProperties(sub->clipId(), sub->zone(), sub->text(1), sub->text(1));
818         }
819         return;
820     }
821     if (item->type() == PROJECTFOLDERTYPE) {
822         if (column == 0) {
823             FolderProjectItem *folder = static_cast <FolderProjectItem*>(item);
824             editFolder(item->text(0), folder->groupName(), folder->clipId());
825             folder->setGroupName(item->text(0));
826             m_doc->clipManager()->addFolder(folder->clipId(), item->text(0));
827             const int children = item->childCount();
828             for (int i = 0; i < children; i++) {
829                 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
830                 child->setProperty("groupname", item->text(0));
831             }
832         }
833         return;
834     }
835
836     ProjectItem *clip = static_cast <ProjectItem*>(item);
837     if (column == 1) {
838         if (clip->referencedClip()) {
839             QMap <QString, QString> oldprops;
840             QMap <QString, QString> newprops;
841             oldprops["description"] = clip->referencedClip()->getProperty("description");
842             newprops["description"] = item->text(1);
843
844             if (clip->clipType() == TEXT) {
845                 // This is a text template clip, update the image
846                 /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
847                 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/
848                 oldprops.insert("templatetext", clip->referencedClip()->getProperty("templatetext"));
849                 newprops.insert("templatetext", item->text(1));
850             }
851             slotUpdateClipProperties(clip->clipId(), newprops);
852             EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
853             m_commandStack->push(command);
854         }
855     } else if (column == 0) {
856         if (clip->referencedClip()) {
857             QMap <QString, QString> oldprops;
858             QMap <QString, QString> newprops;
859             oldprops["name"] = clip->referencedClip()->getProperty("name");
860             if (oldprops.value("name") != item->text(0)) {
861                 newprops["name"] = item->text(0);
862                 slotUpdateClipProperties(clip, newprops);
863                 emit projectModified();
864                 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
865                 m_commandStack->push(command);
866             }
867         }
868     }
869 }
870
871 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
872 {
873     bool enable = item ? true : false;
874     m_editButton->defaultAction()->setEnabled(enable);
875     m_deleteButton->defaultAction()->setEnabled(enable);
876     m_reloadAction->setEnabled(enable);
877     m_transcodeAction->setEnabled(enable);
878     m_stabilizeAction->setEnabled(enable);
879     if (enable) {
880         ProjectItem *clip = NULL;
881         if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
882             clip = static_cast <ProjectItem*>(item->parent());
883             m_transcodeAction->setEnabled(false);
884             m_stabilizeAction->setEnabled(false);
885             adjustProxyActions(clip);
886         } else if (m_listView->currentItem()->type() == PROJECTCLIPTYPE) {
887             clip = static_cast <ProjectItem*>(item);
888             // Display relevant transcoding actions only
889             adjustTranscodeActions(clip);
890             adjustStabilizeActions(clip);
891             adjustProxyActions(clip);
892             // Display uses in timeline
893             emit findInTimeline(clip->clipId());
894         } else {
895             m_transcodeAction->setEnabled(false);
896             m_stabilizeAction->setEnabled(false);
897         }
898         if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
899             m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
900             m_openAction->setEnabled(true);
901         } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
902             m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
903             m_openAction->setEnabled(true);
904         } else {
905             m_openAction->setEnabled(false);
906         }
907
908     } else {
909         m_openAction->setEnabled(false);
910     }
911     m_menu->popup(pos);
912 }
913
914 void ProjectList::slotRemoveClip()
915 {
916     if (!m_listView->currentItem())
917         return;
918     QStringList ids;
919     QMap <QString, QString> folderids;
920     QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
921
922     QUndoCommand *delCommand = new QUndoCommand();
923     delCommand->setText(i18n("Delete Clip Zone"));
924     for (int i = 0; i < selected.count(); i++) {
925         if (selected.at(i)->type() == PROJECTSUBCLIPTYPE) {
926             // subitem
927             SubProjectItem *sub = static_cast <SubProjectItem *>(selected.at(i));
928             ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
929             new AddClipCutCommand(this, item->clipId(), sub->zone().x(), sub->zone().y(), sub->description(), false, true, delCommand);
930         } else if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
931             // folder
932             FolderProjectItem *folder = static_cast <FolderProjectItem *>(selected.at(i));
933             folderids[folder->groupName()] = folder->clipId();
934             int children = folder->childCount();
935
936             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)
937                 return;
938             for (int i = 0; i < children; ++i) {
939                 ProjectItem *child = static_cast <ProjectItem *>(folder->child(i));
940                 ids << child->clipId();
941             }
942         } else {
943             ProjectItem *item = static_cast <ProjectItem *>(selected.at(i));
944             ids << item->clipId();
945             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) {
946                 KMessageBox::enableMessage("DeleteAll");
947                 return;
948             }
949         }
950     }
951     KMessageBox::enableMessage("DeleteAll");
952     if (delCommand->childCount() == 0)
953         delete delCommand;
954     else
955         m_commandStack->push(delCommand);
956     emit deleteProjectClips(ids, folderids);
957 }
958
959 void ProjectList::updateButtons() const
960 {
961     if (m_listView->topLevelItemCount() == 0) {
962         m_deleteButton->defaultAction()->setEnabled(false);
963         m_editButton->defaultAction()->setEnabled(false);
964     } else {
965         m_deleteButton->defaultAction()->setEnabled(true);
966         if (!m_listView->currentItem())
967             m_listView->setCurrentItem(m_listView->topLevelItem(0));
968         QTreeWidgetItem *item = m_listView->currentItem();
969         if (item && item->type() == PROJECTCLIPTYPE) {
970             m_editButton->defaultAction()->setEnabled(true);
971             m_openAction->setEnabled(true);
972             m_reloadAction->setEnabled(true);
973             m_transcodeAction->setEnabled(true);
974             m_stabilizeAction->setEnabled(true);
975             return;
976         }
977         else if (item && item->type() == PROJECTFOLDERTYPE && item->childCount() > 0) {
978             m_editButton->defaultAction()->setEnabled(true);
979         }
980         else m_editButton->defaultAction()->setEnabled(false);
981     }
982     m_openAction->setEnabled(false);
983     m_reloadAction->setEnabled(false);
984     m_transcodeAction->setEnabled(false);
985     m_stabilizeAction->setEnabled(false);
986     m_proxyAction->setEnabled(false);
987 }
988
989 void ProjectList::selectItemById(const QString &clipId)
990 {
991     ProjectItem *item = getItemById(clipId);
992     if (item)
993         m_listView->setCurrentItem(item);
994 }
995
996
997 void ProjectList::slotDeleteClip(const QString &clipId)
998 {
999     ProjectItem *item = getItemById(clipId);
1000     if (!item) {
1001         kDebug() << "/// Cannot find clip to delete";
1002         return;
1003     }
1004     if (item->isProxyRunning()) m_abortProxy.append(item->referencedClip()->getProperty("proxy"));
1005     m_listView->blockSignals(true);
1006     QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
1007     if (!newSelectedItem)
1008         newSelectedItem = m_listView->itemBelow(item);
1009     delete item;
1010     // Pause playing to prevent crash while deleting clip
1011     slotPauseMonitor();
1012     m_doc->clipManager()->deleteClip(clipId);
1013     m_listView->blockSignals(false);
1014     if (newSelectedItem) {
1015         m_listView->setCurrentItem(newSelectedItem);
1016     } else {
1017         updateButtons();
1018         emit clipSelected(NULL);
1019     }
1020 }
1021
1022
1023 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
1024 {
1025     EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
1026     m_commandStack->push(command);
1027     m_doc->setModified(true);
1028 }
1029
1030 void ProjectList::slotAddFolder()
1031 {
1032     AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
1033     m_commandStack->push(command);
1034 }
1035
1036 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
1037 {
1038     if (remove) {
1039         FolderProjectItem *item = getFolderItemById(clipId);
1040         if (item) {
1041             m_doc->clipManager()->deleteFolder(clipId);
1042             QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
1043             if (!newSelectedItem)
1044                 newSelectedItem = m_listView->itemBelow(item);
1045             delete item;
1046             if (newSelectedItem)
1047                 m_listView->setCurrentItem(newSelectedItem);
1048             else
1049                 updateButtons();
1050         }
1051     } else {
1052         if (edit) {
1053             FolderProjectItem *item = getFolderItemById(clipId);
1054             if (item) {
1055                 m_listView->blockSignals(true);
1056                 item->setGroupName(foldername);
1057                 m_listView->blockSignals(false);
1058                 m_doc->clipManager()->addFolder(clipId, foldername);
1059                 const int children = item->childCount();
1060                 for (int i = 0; i < children; i++) {
1061                     ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
1062                     child->setProperty("groupname", foldername);
1063                 }
1064             }
1065         } else {
1066             m_listView->blockSignals(true);
1067             m_listView->setCurrentItem(new FolderProjectItem(m_listView, QStringList() << foldername, clipId));
1068             m_doc->clipManager()->addFolder(clipId, foldername);
1069             m_listView->blockSignals(false);
1070             m_listView->editItem(m_listView->currentItem(), 0);
1071         }
1072         updateButtons();
1073     }
1074     m_doc->setModified(true);
1075 }
1076
1077
1078
1079 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
1080 {
1081     QMapIterator<QString, QString> i(map);
1082     QUndoCommand *delCommand = new QUndoCommand();
1083     delCommand->setText(i18n("Delete Folder"));
1084     while (i.hasNext()) {
1085         i.next();
1086         new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
1087     }
1088     if (delCommand->childCount() > 0) m_commandStack->push(delCommand);
1089     else delete delCommand;
1090 }
1091
1092 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
1093 {
1094     //m_listView->setEnabled(false);
1095     const QString parent = clip->getProperty("groupid");
1096     ProjectItem *item = NULL;
1097     monitorItemEditing(false);
1098     if (!parent.isEmpty()) {
1099         FolderProjectItem *parentitem = getFolderItemById(parent);
1100         if (!parentitem) {
1101             QStringList text;
1102             QString groupName = clip->getProperty("groupname");
1103             //kDebug() << "Adding clip to new group: " << groupName;
1104             if (groupName.isEmpty()) groupName = i18n("Folder");
1105             text << groupName;
1106             parentitem = new FolderProjectItem(m_listView, text, parent);
1107         }
1108
1109         if (parentitem)
1110             item = new ProjectItem(parentitem, clip);
1111     }
1112     if (item == NULL) {
1113         item = new ProjectItem(m_listView, clip);
1114     }
1115     if (item->data(0, DurationRole).isNull()) item->setData(0, DurationRole, i18n("Loading"));
1116     QString proxy = clip->getProperty("proxy");
1117     if (!proxy.isEmpty() && proxy != "-") slotCreateProxy(clip->getId());
1118     connect(clip, SIGNAL(createProxy(const QString &)), this, SLOT(slotCreateProxy(const QString &)));
1119     connect(clip, SIGNAL(abortProxy(const QString &, const QString &)), this, SLOT(slotAbortProxy(const QString, const QString)));
1120     if (getProperties) {
1121         int height = m_listView->iconSize().height();
1122         int width = (int)(height  * m_render->dar());
1123         QPixmap pix =  KIcon("video-x-generic").pixmap(QSize(width, height));
1124         item->setData(0, Qt::DecorationRole, pix);
1125         //item->setFlags(Qt::ItemIsSelectable);
1126         m_listView->processLayout();
1127         QDomElement e = clip->toXML().cloneNode().toElement();
1128         e.removeAttribute("file_hash");
1129         resetThumbsProducer(clip);
1130         m_render->getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true);
1131     }
1132     else if (item->hasProxy() && !item->isProxyRunning()) {
1133         slotCreateProxy(clip->getId());
1134     }
1135     
1136     KUrl url = clip->fileURL();
1137 #ifdef NEPOMUK
1138     if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
1139         // if file has Nepomuk comment, use it
1140         Nepomuk::Resource f(url.path());
1141         QString annotation = f.description();
1142         if (!annotation.isEmpty()) item->setText(1, annotation);
1143         item->setText(2, QString::number(f.rating()));
1144     }
1145 #endif
1146
1147     // Add info to date column
1148     QFileInfo fileInfo(url.path());
1149     if (fileInfo.exists()) {
1150         item->setText(3, fileInfo.lastModified().toString(QString("yyyy/MM/dd hh:mm:ss")));
1151     }
1152
1153     // Add cut zones
1154     QList <CutZoneInfo> cuts = clip->cutZones();
1155     if (!cuts.isEmpty()) {
1156         for (int i = 0; i < cuts.count(); i++) {
1157             SubProjectItem *sub = new SubProjectItem(item, cuts.at(i).zone.x(), cuts.at(i).zone.y(), cuts.at(i).description);
1158             if (!clip->getClipHash().isEmpty()) {
1159                 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(cuts.at(i).zone.x()) + ".png";
1160                 if (QFile::exists(cachedPixmap)) {
1161                     QPixmap pix(cachedPixmap);
1162                     if (pix.isNull())
1163                         KIO::NetAccess::del(KUrl(cachedPixmap), this);
1164                     sub->setData(0, Qt::DecorationRole, pix);
1165                 }
1166             }
1167         }
1168     }
1169     monitorItemEditing(true);
1170     updateButtons();
1171 }
1172
1173 void ProjectList::slotGotProxy(const QString &proxyPath)
1174 {
1175     if (proxyPath.isEmpty() || m_abortAllProxies) return;
1176     QTreeWidgetItemIterator it(m_listView);
1177     ProjectItem *item;
1178
1179     while (*it && !m_abortAllProxies) {
1180         if ((*it)->type() == PROJECTCLIPTYPE) {
1181             item = static_cast <ProjectItem *>(*it);
1182             if (item->referencedClip()->getProperty("proxy") == proxyPath)
1183                 slotGotProxy(item);
1184         }
1185         ++it;
1186     }
1187 }
1188
1189 void ProjectList::slotGotProxy(ProjectItem *item)
1190 {
1191     if (item == NULL) return;
1192     DocClipBase *clip = item->referencedClip();
1193     if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
1194         // Clip is being reprocessed, abort
1195         kDebug()<<"//// TRYING TO PROXY: "<<item->clipId()<<", but it is busy";
1196         return;
1197     }
1198     
1199     // Proxy clip successfully created
1200     QDomElement e = clip->toXML().cloneNode().toElement();
1201
1202     // Make sure we get the correct producer length if it was adjusted in timeline
1203     CLIPTYPE t = item->clipType();
1204     if (t == COLOR || t == IMAGE || t == SLIDESHOW || t == TEXT) {
1205         int length = QString(clip->producerProperty("length")).toInt();
1206         if (length > 0 && !e.hasAttribute("length")) {
1207             e.setAttribute("length", length);
1208         }
1209     }
1210     resetThumbsProducer(clip);
1211     m_render->getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true);
1212 }
1213
1214 void ProjectList::slotResetProjectList()
1215 {
1216     m_listView->blockSignals(true);
1217     m_abortAllProxies = true;
1218     m_proxyThreads.waitForFinished();
1219     m_proxyThreads.clearFutures();
1220     m_thumbnailQueue.clear();
1221     m_listView->clear();
1222     m_listView->setEnabled(true);
1223     emit clipSelected(NULL);
1224     m_refreshed = false;
1225     m_allClipsProcessed = false;
1226     m_abortAllProxies = false;
1227     m_listView->blockSignals(false);
1228 }
1229
1230 void ProjectList::slotUpdateClip(const QString &id)
1231 {
1232     ProjectItem *item = getItemById(id);
1233     monitorItemEditing(false);
1234     if (item) item->setData(0, UsageRole, QString::number(item->numReferences()));
1235     monitorItemEditing(true);
1236 }
1237
1238 void ProjectList::getCachedThumbnail(ProjectItem *item)
1239 {
1240     if (!item) return;
1241     DocClipBase *clip = item->referencedClip();
1242     if (!clip) return;
1243     QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
1244     if (QFile::exists(cachedPixmap)) {
1245         QPixmap pix(cachedPixmap);
1246         if (pix.isNull()) {
1247             KIO::NetAccess::del(KUrl(cachedPixmap), this);
1248             requestClipThumbnail(item->clipId());
1249         }
1250         else item->setData(0, Qt::DecorationRole, pix);
1251     }
1252     else {
1253         requestClipThumbnail(item->clipId());
1254     }
1255 }
1256
1257 void ProjectList::getCachedThumbnail(SubProjectItem *item)
1258 {
1259     if (!item) return;
1260     ProjectItem *parentItem = static_cast <ProjectItem *>(item->parent());
1261     if (!parentItem) return;
1262     DocClipBase *clip = parentItem->referencedClip();
1263     if (!clip) return;
1264     int pos = item->zone().x();
1265     QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + "#" + QString::number(pos) + ".png";
1266     if (QFile::exists(cachedPixmap)) {
1267         QPixmap pix(cachedPixmap);
1268         if (pix.isNull()) {
1269             KIO::NetAccess::del(KUrl(cachedPixmap), this);
1270             requestClipThumbnail(parentItem->clipId() + '#' + QString::number(pos));
1271         }
1272         else item->setData(0, Qt::DecorationRole, pix);
1273     }
1274     else requestClipThumbnail(parentItem->clipId() + '#' + QString::number(pos));
1275 }
1276
1277 void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged, QStringList brokenClips)
1278 {
1279     if (!m_allClipsProcessed) m_listView->setEnabled(false);
1280     m_listView->setSortingEnabled(false);
1281     QTreeWidgetItemIterator it(m_listView);
1282     DocClipBase *clip;
1283     ProjectItem *item;
1284     monitorItemEditing(false);
1285     int height = m_listView->iconSize().height();
1286     int width = (int)(height  * m_render->dar());
1287     QPixmap missingPixmap = QPixmap(width, height);
1288     missingPixmap.fill(Qt::transparent);
1289     KIcon icon("dialog-close");
1290     QPainter p(&missingPixmap);
1291     p.drawPixmap(3, 3, icon.pixmap(width - 6, height - 6));
1292     p.end();
1293     
1294     int max = m_doc->clipManager()->clipsCount();
1295     max = qMax(1, max);
1296     int ct = 0;
1297
1298     while (*it) {
1299         emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - ct++) / max));
1300         if ((*it)->type() == PROJECTSUBCLIPTYPE) {
1301             // subitem
1302             SubProjectItem *sub = static_cast <SubProjectItem *>(*it);
1303             if (displayRatioChanged) {
1304                 item = static_cast <ProjectItem *>((*it)->parent());
1305                 requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x()));
1306             }
1307             else if (sub->data(0, Qt::DecorationRole).isNull()) {
1308                 getCachedThumbnail(sub);
1309             }
1310             ++it;
1311             continue;
1312         } else if ((*it)->type() == PROJECTFOLDERTYPE) {
1313             // folder
1314             ++it;
1315             continue;
1316         } else {
1317             item = static_cast <ProjectItem *>(*it);
1318             clip = item->referencedClip();
1319             if (item->referencedClip()->getProducer() == NULL) {
1320                 bool replace = false;
1321                 if (brokenClips.contains(item->clipId())) {
1322                     // if this is a proxy clip, disable proxy
1323                     item->setProxyStatus(NOPROXY);
1324                     clip->setProperty("proxy", "-");
1325                     replace = true;
1326                 }
1327                 if (clip->isPlaceHolder() == false && !item->isProxyRunning()) {
1328                     QDomElement xml = clip->toXML();
1329                     if (fpsChanged) {
1330                         xml.removeAttribute("out");
1331                         xml.removeAttribute("file_hash");
1332                         xml.removeAttribute("proxy_out");
1333                     }
1334                     if (!replace) replace = xml.attribute("replace") == "1";
1335                     if (replace) resetThumbsProducer(clip);
1336                     m_render->getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), replace);
1337                 }
1338                 else if (clip->isPlaceHolder()) {
1339                     item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
1340                     if (item->data(0, Qt::DecorationRole).isNull()) {
1341                         item->setData(0, Qt::DecorationRole, missingPixmap);
1342                     }
1343                     else {
1344                         QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
1345                         QPainter p(&pixmap);
1346                         p.drawPixmap(3, 3, KIcon("dialog-close").pixmap(pixmap.width() - 6, pixmap.height() - 6));
1347                         p.end();
1348                         item->setData(0, Qt::DecorationRole, pixmap);
1349                     }
1350                 }
1351             } else {              
1352                 if (displayRatioChanged)
1353                     requestClipThumbnail(clip->getId());
1354                 else if (item->data(0, Qt::DecorationRole).isNull()) {
1355                     getCachedThumbnail(item);
1356                 }
1357                 if (item->data(0, DurationRole).toString().isEmpty()) {
1358                     item->changeDuration(item->referencedClip()->getProducer()->get_playtime());
1359                 }
1360                 if (clip->isPlaceHolder()) {
1361                     QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
1362                     if (pixmap.isNull()) {
1363                         pixmap = QPixmap(width, height);
1364                         pixmap.fill(Qt::transparent);
1365                     }
1366                     QPainter p(&pixmap);
1367                     p.drawPixmap(3, 3, KIcon("dialog-close").pixmap(pixmap.width() - 6, pixmap.height() - 6));
1368                     p.end();
1369                     item->setData(0, Qt::DecorationRole, pixmap);
1370                 }
1371             }
1372             item->setData(0, UsageRole, QString::number(item->numReferences()));
1373         }
1374         ++it;
1375     }
1376
1377     m_listView->setSortingEnabled(true);
1378     m_allClipsProcessed = true;
1379     if (m_render->processingItems() == 0) {
1380        monitorItemEditing(true);
1381        slotProcessNextThumbnail();
1382     }
1383 }
1384
1385 // static
1386 QString ProjectList::getExtensions()
1387 {
1388     // Build list of mime types
1389     QStringList mimeTypes = QStringList() << "application/x-kdenlive" << "application/x-kdenlivetitle" << "video/mlt-playlist" << "text/plain"
1390                             << "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"
1391                             << "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"
1392                             << "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";
1393
1394     QString allExtensions;
1395     foreach(const QString & mimeType, mimeTypes) {
1396         KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
1397         if (mime) {
1398             allExtensions.append(mime->patterns().join(" "));
1399             allExtensions.append(' ');
1400         }
1401     }
1402     return allExtensions.simplified();
1403 }
1404
1405 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
1406 {
1407     if (!m_commandStack)
1408         kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1409
1410     KUrl::List list;
1411     if (givenList.isEmpty()) {
1412         QString allExtensions = getExtensions();
1413         const QString dialogFilter = allExtensions + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
1414         QCheckBox *b = new QCheckBox(i18n("Import image sequence"));
1415         b->setChecked(KdenliveSettings::autoimagesequence());
1416         QCheckBox *c = new QCheckBox(i18n("Transparent background for images"));
1417         c->setChecked(KdenliveSettings::autoimagetransparency());
1418         QFrame *f = new QFrame;
1419         f->setFrameShape(QFrame::NoFrame);
1420         QHBoxLayout *l = new QHBoxLayout;
1421         l->addWidget(b);
1422         l->addWidget(c);
1423         l->addStretch(5);
1424         f->setLayout(l);
1425         KFileDialog *d = new KFileDialog(KUrl("kfiledialog:///clipfolder"), dialogFilter, kapp->activeWindow(), f);
1426         d->setOperationMode(KFileDialog::Opening);
1427         d->setMode(KFile::Files);
1428         if (d->exec() == QDialog::Accepted) {
1429             KdenliveSettings::setAutoimagetransparency(c->isChecked());
1430         }
1431         list = d->selectedUrls();
1432         if (b->isChecked() && list.count() == 1) {
1433             // Check for image sequence
1434             KUrl url = list.at(0);
1435             QString fileName = url.fileName().section('.', 0, -2);
1436             if (fileName.at(fileName.size() - 1).isDigit()) {
1437                 KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
1438                 if (item.mimetype().startsWith("image")) {
1439                     // import as sequence if we found more than one image in the sequence
1440                     QStringList list;
1441                     QString pattern = SlideshowClip::selectedPath(url.path(), false, QString(), &list);
1442                     int count = list.count();
1443                     if (count > 1) {
1444                         delete d;
1445                         QStringList groupInfo = getGroup();
1446
1447                         // get image sequence base name
1448                         while (fileName.at(fileName.size() - 1).isDigit()) {
1449                             fileName.chop(1);
1450                         }
1451
1452                         m_doc->slotCreateSlideshowClipFile(fileName, pattern, count, m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()),
1453                                                            false, false, false,
1454                                                            m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))), QString(), 0,
1455                                                            QString(), groupInfo.at(0), groupInfo.at(1));
1456                         return;
1457                     }
1458                 }
1459             }
1460         }
1461         delete d;
1462     } else {
1463         for (int i = 0; i < givenList.count(); i++)
1464             list << givenList.at(i);
1465     }
1466
1467     foreach(const KUrl & file, list) {
1468         // Check there is no folder here
1469         KMimeType::Ptr type = KMimeType::findByUrl(file);
1470         if (type->is("inode/directory")) {
1471             // user dropped a folder
1472             list.removeAll(file);
1473         }
1474     }
1475
1476     if (list.isEmpty())
1477         return;
1478
1479     if (givenList.isEmpty()) {
1480         QStringList groupInfo = getGroup();
1481         m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1));
1482     } else {
1483         m_doc->slotAddClipList(list, groupName, groupId);
1484     }
1485 }
1486
1487 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
1488 {
1489     ProjectItem *item = getItemById(id);
1490     m_processingClips.removeAll(id);
1491     m_thumbnailQueue.removeAll(id);
1492     if (item) {
1493         item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1494         const QString path = item->referencedClip()->fileURL().path();
1495         if (item->referencedClip()->isPlaceHolder()) replace = false;
1496         if (!path.isEmpty()) {
1497             if (m_invalidClipDialog) {
1498                 m_invalidClipDialog->addClip(id, path);
1499                 return;
1500             }
1501             else {
1502                 if (replace)
1503                     m_invalidClipDialog = new InvalidDialog(i18n("Invalid clip"),  i18n("Clip <b>%1</b><br />is invalid, will be removed from project.", QString()), replace, kapp->activeWindow());
1504                 else {
1505                     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());
1506                 }
1507                 m_invalidClipDialog->addClip(id, path);
1508                 int result = m_invalidClipDialog->exec();
1509                 if (result == KDialog::Yes) replace = true;
1510             }
1511         }
1512         if (m_invalidClipDialog) {
1513             if (replace)
1514                 emit deleteProjectClips(m_invalidClipDialog->getIds(), QMap <QString, QString>());
1515             delete m_invalidClipDialog;
1516             m_invalidClipDialog = NULL;
1517         }
1518         
1519     }
1520 }
1521
1522 void ProjectList::slotRemoveInvalidProxy(const QString &id, bool durationError)
1523 {
1524     ProjectItem *item = getItemById(id);
1525     if (item) {
1526         kDebug()<<"// Proxy for clip "<<id<<" is invalid, delete";
1527         item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1528         if (durationError) {
1529             kDebug() << "Proxy duration is wrong, try changing transcoding parameters.";
1530             emit displayMessage(i18n("Proxy clip unusable (duration is different from original)."), -2);
1531         }
1532         item->setProxyStatus(PROXYCRASHED);
1533         QString path = item->referencedClip()->getProperty("proxy");
1534         KUrl proxyFolder(m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/");
1535
1536         //Security check: make sure the invalid proxy file is in the proxy folder
1537         if (proxyFolder.isParentOf(KUrl(path))) {
1538             QFile::remove(path);
1539         }
1540         if (item->referencedClip()->getProducer() == NULL) {
1541             // Clip has no valid producer, request it
1542             slotProxyCurrentItem(false, item);
1543         }
1544         else {
1545             // refresh thumbs producer
1546             item->referencedClip()->reloadThumbProducer();
1547         }
1548     }
1549     m_processingClips.removeAll(id);
1550     m_thumbnailQueue.removeAll(id);
1551 }
1552
1553 void ProjectList::slotAddColorClip()
1554 {
1555     if (!m_commandStack)
1556         kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1557
1558     QDialog *dia = new QDialog(this);
1559     Ui::ColorClip_UI dia_ui;
1560     dia_ui.setupUi(dia);
1561     dia->setWindowTitle(i18n("Color Clip"));
1562     dia_ui.clip_name->setText(i18n("Color Clip"));
1563
1564     TimecodeDisplay *t = new TimecodeDisplay(m_timecode);
1565     t->setValue(KdenliveSettings::color_duration());
1566     dia_ui.clip_durationBox->addWidget(t);
1567     dia_ui.clip_color->setColor(KdenliveSettings::colorclipcolor());
1568
1569     if (dia->exec() == QDialog::Accepted) {
1570         QString color = dia_ui.clip_color->color().name();
1571         KdenliveSettings::setColorclipcolor(color);
1572         color = color.replace(0, 1, "0x") + "ff";
1573         QStringList groupInfo = getGroup();
1574         m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, m_timecode.getTimecode(t->gentime()), groupInfo.at(0), groupInfo.at(1));
1575     }
1576     delete t;
1577     delete dia;
1578 }
1579
1580
1581 void ProjectList::slotAddSlideshowClip()
1582 {
1583     if (!m_commandStack)
1584         kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1585
1586     SlideshowClip *dia = new SlideshowClip(m_timecode, this);
1587
1588     if (dia->exec() == QDialog::Accepted) {
1589         QStringList groupInfo = getGroup();
1590         m_doc->slotCreateSlideshowClipFile(dia->clipName(), dia->selectedPath(), dia->imageCount(), dia->clipDuration(),
1591                                            dia->loop(), dia->crop(), dia->fade(),
1592                                            dia->lumaDuration(), dia->lumaFile(), dia->softness(),
1593                                            dia->animation(), groupInfo.at(0), groupInfo.at(1));
1594     }
1595     delete dia;
1596 }
1597
1598 void ProjectList::slotAddTitleClip()
1599 {
1600     QStringList groupInfo = getGroup();
1601     m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
1602 }
1603
1604 void ProjectList::slotAddTitleTemplateClip()
1605 {
1606     if (!m_commandStack)
1607         kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1608
1609     QStringList groupInfo = getGroup();
1610
1611     // Get the list of existing templates
1612     QStringList filter;
1613     filter << "*.kdenlivetitle";
1614     const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
1615     QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
1616
1617     QDialog *dia = new QDialog(this);
1618     Ui::TemplateClip_UI dia_ui;
1619     dia_ui.setupUi(dia);
1620     for (int i = 0; i < templateFiles.size(); ++i)
1621         dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
1622
1623     if (!templateFiles.isEmpty())
1624         dia_ui.buttonBox->button(QDialogButtonBox::Ok)->setFocus();
1625     dia_ui.template_list->fileDialog()->setFilter("application/x-kdenlivetitle");
1626     //warning: setting base directory doesn't work??
1627     KUrl startDir(path);
1628     dia_ui.template_list->fileDialog()->setUrl(startDir);
1629     dia_ui.text_box->setHidden(true);
1630     if (dia->exec() == QDialog::Accepted) {
1631         QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
1632         if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
1633         // Create a cloned template clip
1634         m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
1635     }
1636     delete dia;
1637 }
1638
1639 QStringList ProjectList::getGroup() const
1640 {
1641     QStringList result;
1642     QTreeWidgetItem *item = m_listView->currentItem();
1643     while (item && item->type() != PROJECTFOLDERTYPE)
1644         item = item->parent();
1645
1646     if (item) {
1647         FolderProjectItem *folder = static_cast <FolderProjectItem *>(item);
1648         result << folder->groupName() << folder->clipId();
1649     } else {
1650         result << QString() << QString();
1651     }
1652     return result;
1653 }
1654
1655 void ProjectList::setDocument(KdenliveDoc *doc)
1656 {
1657     m_listView->blockSignals(true);
1658     m_abortAllProxies = true;
1659     m_proxyThreads.waitForFinished();
1660     m_proxyThreads.clearFutures();
1661     m_thumbnailQueue.clear();
1662     m_listView->clear();
1663     m_processingClips.clear();
1664     
1665     m_listView->setSortingEnabled(false);
1666     emit clipSelected(NULL);
1667     m_refreshed = false;
1668     m_allClipsProcessed = false;
1669     m_fps = doc->fps();
1670     m_timecode = doc->timecode();
1671     m_commandStack = doc->commandStack();
1672     m_doc = doc;
1673     m_abortAllProxies = false;
1674
1675     QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
1676     QStringList openedFolders = doc->getExpandedFolders();
1677     QMapIterator<QString, QString> f(flist);
1678     while (f.hasNext()) {
1679         f.next();
1680         FolderProjectItem *folder = new FolderProjectItem(m_listView, QStringList() << f.value(), f.key());
1681         folder->setExpanded(openedFolders.contains(f.key()));
1682     }
1683
1684     QList <DocClipBase*> list = doc->clipManager()->documentClipList();
1685     if (list.isEmpty()) {
1686         // blank document
1687         m_refreshed = true;
1688         m_allClipsProcessed = true;
1689     }
1690     for (int i = 0; i < list.count(); i++)
1691         slotAddClip(list.at(i), false);
1692
1693     m_listView->blockSignals(false);
1694     connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
1695     connect(m_doc->clipManager(), SIGNAL(modifiedClip(const QString &)), this, SLOT(slotModifiedClip(const QString &)));
1696     connect(m_doc->clipManager(), SIGNAL(missingClip(const QString &)), this, SLOT(slotMissingClip(const QString &)));
1697     connect(m_doc->clipManager(), SIGNAL(availableClip(const QString &)), this, SLOT(slotAvailableClip(const QString &)));
1698     connect(m_doc->clipManager(), SIGNAL(checkAllClips(bool, bool, QStringList)), this, SLOT(updateAllClips(bool, bool, QStringList)));
1699 }
1700
1701 QList <DocClipBase*> ProjectList::documentClipList() const
1702 {
1703     if (m_doc == NULL)
1704         return QList <DocClipBase*> ();
1705
1706     return m_doc->clipManager()->documentClipList();
1707 }
1708
1709 QDomElement ProjectList::producersList()
1710 {
1711     QDomDocument doc;
1712     QDomElement prods = doc.createElement("producerlist");
1713     doc.appendChild(prods);
1714     QTreeWidgetItemIterator it(m_listView);
1715     while (*it) {
1716         if ((*it)->type() != PROJECTCLIPTYPE) {
1717             // subitem
1718             ++it;
1719             continue;
1720         }
1721         prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
1722         ++it;
1723     }
1724     return prods;
1725 }
1726
1727 void ProjectList::slotCheckForEmptyQueue()
1728 {
1729     if (m_render->processingItems() == 0 && m_thumbnailQueue.isEmpty()) {
1730         if (!m_refreshed && m_allClipsProcessed) {
1731             m_refreshed = true;
1732             m_listView->setEnabled(true);
1733             slotClipSelected();
1734             QTimer::singleShot(500, this, SIGNAL(loadingIsOver()));
1735             emit displayMessage(QString(), -1);
1736         }
1737         updateButtons();
1738     } else if (!m_refreshed) {
1739         QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
1740     }
1741 }
1742
1743
1744 void ProjectList::requestClipThumbnail(const QString id)
1745 {
1746     if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id);
1747     slotProcessNextThumbnail();
1748 }
1749
1750 void ProjectList::resetThumbsProducer(DocClipBase *clip)
1751 {
1752     if (!clip) return;
1753     clip->clearThumbProducer();
1754     QString id = clip->getId();
1755     m_thumbnailQueue.removeAll(id);
1756 }
1757
1758 void ProjectList::slotProcessNextThumbnail()
1759 {
1760     if (m_render->processingItems() > 0) {
1761         return;
1762     }
1763     if (m_thumbnailQueue.isEmpty()) {
1764         slotCheckForEmptyQueue();
1765         return;
1766     }
1767     int max = m_doc->clipManager()->clipsCount();
1768     emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - m_thumbnailQueue.count()) / max));
1769     slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
1770 }
1771
1772 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
1773 {
1774     QTreeWidgetItem *item = getAnyItemById(clipId);
1775     if (item)
1776         slotRefreshClipThumbnail(item, update);
1777     else {
1778         slotProcessNextThumbnail();
1779     }
1780 }
1781
1782 void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
1783 {
1784     if (it == NULL) return;
1785     ProjectItem *item = NULL;
1786     bool isSubItem = false;
1787     int frame;
1788     if (it->type() == PROJECTFOLDERTYPE) return;
1789     if (it->type() == PROJECTSUBCLIPTYPE) {
1790         item = static_cast <ProjectItem *>(it->parent());
1791         frame = static_cast <SubProjectItem *>(it)->zone().x();
1792         isSubItem = true;
1793     } else {
1794         item = static_cast <ProjectItem *>(it);
1795         frame = item->referencedClip()->getClipThumbFrame();
1796     }
1797
1798     if (item) {
1799         DocClipBase *clip = item->referencedClip();
1800         if (!clip) {
1801             slotProcessNextThumbnail();
1802             return;
1803         }
1804         QPixmap pix;
1805         QImage img;
1806         int height = m_listView->iconSize().height();
1807         int swidth = (int)(height  * m_render->frameRenderWidth() / m_render->renderHeight()+ 0.5);
1808         int dwidth = (int)(height  * m_render->dar() + 0.5);
1809         if (clip->clipType() == AUDIO)
1810             pix = KIcon("audio-x-generic").pixmap(QSize(dwidth, height));
1811         else if (clip->clipType() == IMAGE)
1812             img = KThumb::getFrame(item->referencedClip()->getProducer(), 0, swidth, dwidth, height);
1813         else {
1814             img = item->referencedClip()->extractImage(frame, dwidth, height);
1815         }
1816
1817         if (!pix.isNull() || !img.isNull()) {
1818             monitorItemEditing(false);
1819             if (!img.isNull()) pix = QPixmap::fromImage(img);
1820             it->setData(0, Qt::DecorationRole, pix);
1821             monitorItemEditing(true);
1822             
1823             QString hash = item->getClipHash();
1824             if (!hash.isEmpty() && !img.isNull()) {
1825                 if (!isSubItem)
1826                     m_doc->cacheImage(hash, img);
1827                 else
1828                     m_doc->cacheImage(hash + '#' + QString::number(frame), img);
1829             }
1830         }
1831         if (update)
1832             emit projectModified();
1833         slotProcessNextThumbnail();
1834     }
1835 }
1836
1837
1838 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const stringMap &properties, const stringMap &metadata, bool replace)
1839 {
1840     QString toReload;
1841     ProjectItem *item = getItemById(clipId);
1842
1843     int queue = m_render->processingItems();
1844     if (item && producer) {
1845         monitorItemEditing(false);
1846         DocClipBase *clip = item->referencedClip();
1847         if (producer->is_valid()) {
1848             if (clip->isPlaceHolder()) {
1849                 clip->setValid();
1850                 toReload = clipId;
1851             }
1852             item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1853         }
1854         item->setProperties(properties, metadata);
1855         clip->setProducer(producer, replace);
1856
1857         // Proxy stuff
1858         QString size = properties.value("frame_size");
1859         if (!useProxy() && clip->getProperty("proxy").isEmpty()) setProxyStatus(item, NOPROXY);
1860         if (useProxy() && generateProxy() && clip->getProperty("proxy") == "-") setProxyStatus(item, NOPROXY);
1861         else if (useProxy() && !item->hasProxy() && !item->isProxyRunning()) {
1862             // proxy video and image clips
1863             int maxSize;
1864             CLIPTYPE t = item->clipType();
1865             if (t == IMAGE) maxSize = m_doc->getDocumentProperty("proxyimageminsize").toInt();
1866             else maxSize = m_doc->getDocumentProperty("proxyminsize").toInt();
1867             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)) {
1868                 if (clip->getProperty("proxy").isEmpty()) {
1869                     KUrl proxyPath = m_doc->projectFolder();
1870                     proxyPath.addPath("proxy/");
1871                     proxyPath.addPath(clip->getClipHash() + "." + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension")));
1872                     QMap <QString, QString> newProps;
1873                     // insert required duration for proxy
1874                     if (t != IMAGE) newProps.insert("proxy_out", clip->producerProperty("out"));
1875                     newProps.insert("proxy", proxyPath.path());
1876                     QMap <QString, QString> oldProps = clip->properties();
1877                     oldProps.insert("proxy", QString());
1878                     EditClipCommand *command = new EditClipCommand(this, clipId, oldProps, newProps, true);
1879                     m_doc->commandStack()->push(command);
1880                 }
1881             }
1882         }
1883
1884         if (!replace && m_allClipsProcessed && item->data(0, Qt::DecorationRole).isNull()) {
1885             getCachedThumbnail(item);
1886         }
1887         if (!toReload.isEmpty())
1888             item->slotSetToolTip();
1889     } else kDebug() << "////////  COULD NOT FIND CLIP TO UPDATE PRPS...";
1890     if (queue == 0) {
1891         monitorItemEditing(true);
1892         if (item && m_thumbnailQueue.isEmpty()) {
1893             if (!item->hasProxy() || m_render->activeClipId() == item->clipId())
1894                 m_listView->setCurrentItem(item);
1895             bool updatedProfile = false;
1896             if (item->parent()) {
1897                 if (item->parent()->type() == PROJECTFOLDERTYPE)
1898                     static_cast <FolderProjectItem *>(item->parent())->switchIcon();
1899             } else if (KdenliveSettings::checkfirstprojectclip() &&  m_listView->topLevelItemCount() == 1 && m_refreshed && m_allClipsProcessed) {
1900                 // this is the first clip loaded in project, check if we want to adjust project settings to the clip
1901                 updatedProfile = adjustProjectProfileToItem(item);
1902             }
1903             if (updatedProfile == false) {
1904                 //emit clipSelected(item->referencedClip());
1905             }
1906         } else {
1907             int max = m_doc->clipManager()->clipsCount();
1908             if (max > 0) emit displayMessage(i18n("Loading clips"), (int)(100 *(max - queue) / max));
1909         }
1910         if (m_allClipsProcessed) emit processNextThumbnail();
1911     }
1912     if (!item) {
1913         // no item for producer, delete it
1914         delete producer;
1915         return;
1916     }
1917     if (replace) toReload = clipId;
1918     if (!toReload.isEmpty())
1919         emit clipNeedsReload(toReload);
1920 }
1921
1922 bool ProjectList::adjustProjectProfileToItem(ProjectItem *item)
1923 {
1924     if (item == NULL) {
1925         if (m_listView->currentItem() && m_listView->currentItem()->type() != PROJECTFOLDERTYPE)
1926             item = static_cast <ProjectItem*>(m_listView->currentItem());
1927     }
1928     if (item == NULL || item->referencedClip() == NULL) {
1929         KMessageBox::information(kapp->activeWindow(), i18n("Cannot find profile from current clip"));
1930         return false;
1931     }
1932     bool profileUpdated = false;
1933     QString size = item->referencedClip()->getProperty("frame_size");
1934     int width = size.section('x', 0, 0).toInt();
1935     int height = size.section('x', -1).toInt();
1936     double fps = item->referencedClip()->getProperty("fps").toDouble();
1937     double par = item->referencedClip()->getProperty("aspect_ratio").toDouble();
1938     if (item->clipType() == IMAGE || item->clipType() == AV || item->clipType() == VIDEO) {
1939         if (ProfilesDialog::matchProfile(width, height, fps, par, item->clipType() == IMAGE, m_doc->mltProfile()) == false) {
1940             // get a list of compatible profiles
1941             QMap <QString, QString> suggestedProfiles = ProfilesDialog::getProfilesFromProperties(width, height, fps, par, item->clipType() == IMAGE);
1942             if (!suggestedProfiles.isEmpty()) {
1943                 KDialog *dialog = new KDialog(this);
1944                 dialog->setCaption(i18n("Change project profile"));
1945                 dialog->setButtons(KDialog::Ok | KDialog::Cancel);
1946
1947                 QWidget container;
1948                 QVBoxLayout *l = new QVBoxLayout;
1949                 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));
1950                 l->addWidget(label);
1951                 QListWidget *list = new QListWidget;
1952                 list->setAlternatingRowColors(true);
1953                 QMapIterator<QString, QString> i(suggestedProfiles);
1954                 while (i.hasNext()) {
1955                     i.next();
1956                     QListWidgetItem *item = new QListWidgetItem(i.value(), list);
1957                     item->setData(Qt::UserRole, i.key());
1958                     item->setToolTip(i.key());
1959                 }
1960                 list->setCurrentRow(0);
1961                 l->addWidget(list);
1962                 container.setLayout(l);
1963                 dialog->setButtonText(KDialog::Ok, i18n("Update profile"));
1964                 dialog->setMainWidget(&container);
1965                 if (dialog->exec() == QDialog::Accepted) {
1966                     //Change project profile
1967                     profileUpdated = true;
1968                     if (list->currentItem())
1969                         emit updateProfile(list->currentItem()->data(Qt::UserRole).toString());
1970                 }
1971                 delete list;
1972                 delete label;
1973             } else if (fps > 0) {
1974                 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));
1975             }
1976         }
1977     }
1978     return profileUpdated;
1979 }
1980
1981 QString ProjectList::getDocumentProperty(const QString &key) const
1982 {
1983     return m_doc->getDocumentProperty(key);
1984 }
1985
1986 bool ProjectList::useProxy() const
1987 {
1988     return m_doc->getDocumentProperty("enableproxy").toInt();
1989 }
1990
1991 bool ProjectList::generateProxy() const
1992 {
1993     return m_doc->getDocumentProperty("generateproxy").toInt();
1994 }
1995
1996 bool ProjectList::generateImageProxy() const
1997 {
1998     return m_doc->getDocumentProperty("generateimageproxy").toInt();
1999 }
2000
2001 void ProjectList::slotReplyGetImage(const QString &clipId, const QImage &img)
2002 {
2003     ProjectItem *item = getItemById(clipId);
2004     if (item && !img.isNull()) {
2005         QPixmap pix = QPixmap::fromImage(img);
2006         monitorItemEditing(false);
2007         item->setData(0, Qt::DecorationRole, pix);
2008         monitorItemEditing(true);
2009         QString hash = item->getClipHash();
2010         if (!hash.isEmpty()) m_doc->cacheImage(hash, img);
2011     }
2012 }
2013
2014 void ProjectList::slotReplyGetImage(const QString &clipId, const QString &name, int width, int height)
2015 {
2016     // For clips that have a generic icon (like audio clips...)
2017     ProjectItem *item = getItemById(clipId);
2018     QPixmap pix =  KIcon(name).pixmap(QSize(width, height));
2019     if (item && !pix.isNull()) {
2020         monitorItemEditing(false);
2021         item->setData(0, Qt::DecorationRole, pix);
2022         monitorItemEditing(true);
2023     }
2024 }
2025
2026 QTreeWidgetItem *ProjectList::getAnyItemById(const QString &id)
2027 {
2028     QTreeWidgetItemIterator it(m_listView);
2029     QString lookId = id;
2030     if (id.contains('#'))
2031         lookId = id.section('#', 0, 0);
2032
2033     ProjectItem *result = NULL;
2034     while (*it) {
2035         if ((*it)->type() != PROJECTCLIPTYPE) {
2036             // subitem
2037             ++it;
2038             continue;
2039         }
2040         ProjectItem *item = static_cast<ProjectItem *>(*it);
2041         if (item->clipId() == lookId) {
2042             result = item;
2043             break;
2044         }
2045         ++it;
2046     }
2047     if (result == NULL || !id.contains('#')) {
2048         return result;
2049     } else {
2050         for (int i = 0; i < result->childCount(); i++) {
2051             SubProjectItem *sub = static_cast <SubProjectItem *>(result->child(i));
2052             if (sub && sub->zone().x() == id.section('#', 1, 1).toInt())
2053                 return sub;
2054         }
2055     }
2056
2057     return NULL;
2058 }
2059
2060
2061 ProjectItem *ProjectList::getItemById(const QString &id)
2062 {
2063     ProjectItem *item;
2064     QTreeWidgetItemIterator it(m_listView);
2065     while (*it) {
2066         if ((*it)->type() != PROJECTCLIPTYPE) {
2067             // subitem or folder
2068             ++it;
2069             continue;
2070         }
2071         item = static_cast<ProjectItem *>(*it);
2072         if (item->clipId() == id)
2073             return item;
2074         ++it;
2075     }
2076     return NULL;
2077 }
2078
2079 FolderProjectItem *ProjectList::getFolderItemById(const QString &id)
2080 {
2081     FolderProjectItem *item;
2082     QTreeWidgetItemIterator it(m_listView);
2083     while (*it) {
2084         if ((*it)->type() == PROJECTFOLDERTYPE) {
2085             item = static_cast<FolderProjectItem *>(*it);
2086             if (item->clipId() == id)
2087                 return item;
2088         }
2089         ++it;
2090     }
2091     return NULL;
2092 }
2093
2094 void ProjectList::slotSelectClip(const QString &ix)
2095 {
2096     ProjectItem *clip = getItemById(ix);
2097     if (clip) {
2098         m_listView->setCurrentItem(clip);
2099         m_listView->scrollToItem(clip);
2100         m_editButton->defaultAction()->setEnabled(true);
2101         m_deleteButton->defaultAction()->setEnabled(true);
2102         m_reloadAction->setEnabled(true);
2103         m_transcodeAction->setEnabled(true);
2104         m_stabilizeAction->setEnabled(true);
2105         if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
2106             m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
2107             m_openAction->setEnabled(true);
2108         } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
2109             m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
2110             m_openAction->setEnabled(true);
2111         } else {
2112             m_openAction->setEnabled(false);
2113         }
2114     }
2115 }
2116
2117 QString ProjectList::currentClipUrl() const
2118 {
2119     ProjectItem *item;
2120     if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return QString();
2121     if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
2122         // subitem
2123         item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
2124     } else {
2125         item = static_cast <ProjectItem*>(m_listView->currentItem());
2126     }
2127     if (item == NULL)
2128         return QString();
2129     return item->clipUrl().path();
2130 }
2131
2132 KUrl::List ProjectList::getConditionalUrls(const QString &condition) const
2133 {
2134     KUrl::List result;
2135     ProjectItem *item;
2136     QList<QTreeWidgetItem *> list = m_listView->selectedItems();
2137     for (int i = 0; i < list.count(); i++) {
2138         if (list.at(i)->type() == PROJECTFOLDERTYPE)
2139             continue;
2140         if (list.at(i)->type() == PROJECTSUBCLIPTYPE) {
2141             // subitem
2142             item = static_cast <ProjectItem*>(list.at(i)->parent());
2143         } else {
2144             item = static_cast <ProjectItem*>(list.at(i));
2145         }
2146         if (item == NULL || item->type() == COLOR || item->type() == SLIDESHOW || item->type() == TEXT)
2147             continue;
2148         DocClipBase *clip = item->referencedClip();
2149         if (!condition.isEmpty()) {
2150             if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section('=', 1, 1)))
2151                 continue;
2152             else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section('=', 1, 1)))
2153                 continue;
2154         }
2155         result.append(item->clipUrl());
2156     }
2157     return result;
2158 }
2159
2160 void ProjectList::regenerateTemplate(const QString &id)
2161 {
2162     ProjectItem *clip = getItemById(id);
2163     if (clip)
2164         regenerateTemplate(clip);
2165 }
2166
2167 void ProjectList::regenerateTemplate(ProjectItem *clip)
2168 {
2169     //TODO: remove this unused method, only force_reload is necessary
2170     clip->referencedClip()->getProducer()->set("force_reload", 1);
2171 }
2172
2173 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
2174 {
2175     QDomDocument doc;
2176     QFile file(path);
2177     if (!file.open(QIODevice::ReadOnly)) {
2178         kWarning() << "ERROR, CANNOT READ: " << path;
2179         return doc;
2180     }
2181     if (!doc.setContent(&file)) {
2182         kWarning() << "ERROR, CANNOT READ: " << path;
2183         file.close();
2184         return doc;
2185     }
2186     file.close();
2187     QDomNodeList texts = doc.elementsByTagName("content");
2188     for (int i = 0; i < texts.count(); i++) {
2189         QString data = texts.item(i).firstChild().nodeValue();
2190         data.replace("%s", replaceString);
2191         texts.item(i).firstChild().setNodeValue(data);
2192     }
2193     return doc;
2194 }
2195
2196
2197 void ProjectList::slotAddClipCut(const QString &id, int in, int out)
2198 {
2199     ProjectItem *clip = getItemById(id);
2200     if (clip == NULL || clip->referencedClip()->hasCutZone(QPoint(in, out)))
2201         return;
2202     AddClipCutCommand *command = new AddClipCutCommand(this, id, in, out, QString(), true, false);
2203     m_commandStack->push(command);
2204 }
2205
2206 void ProjectList::addClipCut(const QString &id, int in, int out, const QString desc, bool newItem)
2207 {
2208     ProjectItem *clip = getItemById(id);
2209     if (clip) {
2210         DocClipBase *base = clip->referencedClip();
2211         base->addCutZone(in, out);
2212         monitorItemEditing(false);
2213         SubProjectItem *sub = new SubProjectItem(clip, in, out, desc);
2214         if (newItem && desc.isEmpty() && !m_listView->isColumnHidden(1)) {
2215             if (!clip->isExpanded())
2216                 clip->setExpanded(true);
2217             m_listView->scrollToItem(sub);
2218             m_listView->editItem(sub, 1);
2219         }
2220         QImage img = clip->referencedClip()->extractImage(in, (int)(sub->sizeHint(0).height()  * m_render->dar()), sub->sizeHint(0).height() - 2);
2221         sub->setData(0, Qt::DecorationRole, QPixmap::fromImage(img));
2222         QString hash = clip->getClipHash();
2223         if (!hash.isEmpty()) m_doc->cacheImage(hash + '#' + QString::number(in), img);
2224         monitorItemEditing(true);
2225     }
2226     emit projectModified();
2227 }
2228
2229 void ProjectList::removeClipCut(const QString &id, int in, int out)
2230 {
2231     ProjectItem *clip = getItemById(id);
2232     if (clip) {
2233         DocClipBase *base = clip->referencedClip();
2234         base->removeCutZone(in, out);
2235         SubProjectItem *sub = getSubItem(clip, QPoint(in, out));
2236         if (sub) {
2237             monitorItemEditing(false);
2238             delete sub;
2239             monitorItemEditing(true);
2240         }
2241     }
2242     emit projectModified();
2243 }
2244
2245 SubProjectItem *ProjectList::getSubItem(ProjectItem *clip, QPoint zone)
2246 {
2247     SubProjectItem *sub = NULL;
2248     if (clip) {
2249         for (int i = 0; i < clip->childCount(); i++) {
2250             QTreeWidgetItem *it = clip->child(i);
2251             if (it->type() == PROJECTSUBCLIPTYPE) {
2252                 sub = static_cast <SubProjectItem*>(it);
2253                 if (sub->zone() == zone)
2254                     break;
2255                 else
2256                     sub = NULL;
2257             }
2258         }
2259     }
2260     return sub;
2261 }
2262
2263 void ProjectList::slotUpdateClipCut(QPoint p)
2264 {
2265     if (!m_listView->currentItem() || m_listView->currentItem()->type() != PROJECTSUBCLIPTYPE)
2266         return;
2267     SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
2268     ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
2269     EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), p, sub->text(1), sub->text(1), true);
2270     m_commandStack->push(command);
2271 }
2272
2273 void ProjectList::doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment)
2274 {
2275     ProjectItem *clip = getItemById(id);
2276     SubProjectItem *sub = getSubItem(clip, oldzone);
2277     if (sub == NULL || clip == NULL)
2278         return;
2279     DocClipBase *base = clip->referencedClip();
2280     base->updateCutZone(oldzone.x(), oldzone.y(), zone.x(), zone.y(), comment);
2281     monitorItemEditing(false);
2282     sub->setZone(zone);
2283     sub->setDescription(comment);
2284     monitorItemEditing(true);
2285     emit projectModified();
2286 }
2287
2288 void ProjectList::slotForceProcessing(const QString &id)
2289 {
2290     m_render->forceProcessing(id);
2291 }
2292
2293 void ProjectList::slotAddOrUpdateSequence(const QString frameName)
2294 {
2295     QString fileName = KUrl(frameName).fileName().section('_', 0, -2);
2296     QStringList list;
2297     QString pattern = SlideshowClip::selectedPath(frameName, false, QString(), &list);
2298     int count = list.count();
2299     if (count > 1) {
2300         const QList <DocClipBase *> existing = m_doc->clipManager()->getClipByResource(pattern);
2301         if (!existing.isEmpty()) {
2302             // Sequence already exists, update
2303             QString id = existing.at(0)->getId();
2304             //ProjectItem *item = getItemById(id);
2305             QMap <QString, QString> oldprops;
2306             QMap <QString, QString> newprops;
2307             int ttl = existing.at(0)->getProperty("ttl").toInt();
2308             oldprops["out"] = existing.at(0)->getProperty("out");
2309             newprops["out"] = QString::number(ttl * count - 1);
2310             slotUpdateClipProperties(id, newprops);
2311             EditClipCommand *command = new EditClipCommand(this, id, oldprops, newprops, false);
2312             m_commandStack->push(command);
2313         } else {
2314             // Create sequence
2315             QStringList groupInfo = getGroup();
2316             m_doc->slotCreateSlideshowClipFile(fileName, pattern, count, m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()),
2317                                                false, false, false,
2318                                                m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))), QString(), 0,
2319                                                QString(), groupInfo.at(0), groupInfo.at(1));
2320         }
2321     } else emit displayMessage(i18n("Sequence not found"), -2);
2322 }
2323
2324 QMap <QString, QString> ProjectList::getProxies()
2325 {
2326     QMap <QString, QString> list;
2327     ProjectItem *item;
2328     QTreeWidgetItemIterator it(m_listView);
2329     while (*it) {
2330         if ((*it)->type() != PROJECTCLIPTYPE) {
2331             ++it;
2332             continue;
2333         }
2334         item = static_cast<ProjectItem *>(*it);
2335         if (item && item->referencedClip() != NULL) {
2336             if (item->hasProxy()) {
2337                 QString proxy = item->referencedClip()->getProperty("proxy");
2338                 list.insert(proxy, item->clipUrl().path());
2339             }
2340         }
2341         ++it;
2342     }
2343     return list;
2344 }
2345
2346 void ProjectList::slotCreateProxy(const QString id)
2347 {
2348     ProjectItem *item = getItemById(id);
2349     if (!item || item->isProxyRunning() || item->referencedClip()->isPlaceHolder()) return;
2350     QString path = item->referencedClip()->getProperty("proxy");
2351     if (path.isEmpty()) {
2352         setProxyStatus(item, PROXYCRASHED);
2353         return;
2354     }
2355     setProxyStatus(item, PROXYWAITING);
2356     if (m_abortProxy.contains(path)) m_abortProxy.removeAll(path);
2357     if (m_processingProxy.contains(path)) {
2358         // Proxy is already being generated
2359         return;
2360     }
2361     if (QFileInfo(path).size() > 0) {
2362         // Proxy already created
2363         setProxyStatus(item, PROXYDONE);
2364         slotGotProxy(path);
2365         return;
2366     }
2367     m_processingProxy.append(path);
2368
2369     PROXYINFO info;
2370     info.dest = path;
2371     info.src = item->clipUrl().path();
2372     info.type = item->clipType();
2373     info.exif = QString(item->referencedClip()->producerProperty("_exif_orientation")).toInt();
2374     m_proxyList.append(info);
2375     if (!m_proxyThreads.futures().isEmpty()) {
2376         // Remove inactive threads
2377         QList <QFuture<void> > futures = m_proxyThreads.futures();
2378         m_proxyThreads.clearFutures();
2379         for (int i = 0; i < futures.count(); i++)
2380             if (!futures.at(i).isFinished()) {
2381                 m_proxyThreads.addFuture(futures.at(i));
2382             }
2383     }
2384     if (m_proxyThreads.futures().isEmpty() || m_proxyThreads.futures().count() < KdenliveSettings::proxythreads()) m_proxyThreads.addFuture(QtConcurrent::run(this, &ProjectList::slotGenerateProxy));
2385 }
2386
2387 void ProjectList::slotAbortProxy(const QString id, const QString path)
2388 {
2389     QTreeWidgetItemIterator it(m_listView);
2390     ProjectItem *item = getItemById(id);
2391     if (!path.isEmpty() && m_processingProxy.contains(path)) {
2392         m_abortProxy << path;
2393         setProxyStatus(item, NOPROXY);
2394     }
2395     else {
2396         setProxyStatus(item, NOPROXY);
2397         slotGotProxy(item);
2398     }
2399 }
2400
2401 void ProjectList::slotGenerateProxy()
2402 {
2403     while (!m_proxyList.isEmpty() && !m_abortAllProxies) {
2404         emit projectModified();
2405         PROXYINFO info = m_proxyList.takeFirst();
2406         if (m_abortProxy.contains(info.dest)) {
2407             m_abortProxy.removeAll(info.dest);
2408             continue;
2409         }
2410         // Get the list of clips that will need to get progress info
2411         QTreeWidgetItemIterator it(m_listView);
2412         QList <ProjectItem *> processingItems;
2413         while (*it && !m_abortAllProxies) {
2414             if ((*it)->type() == PROJECTCLIPTYPE) {
2415                 ProjectItem *item = static_cast <ProjectItem *>(*it);
2416                 if (item->referencedClip()->getProperty("proxy") == info.dest) {
2417                     processingItems.append(item);
2418                 }
2419             }
2420             ++it;
2421         }
2422
2423         // Make sure proxy path is writable
2424         QFile file(info.dest);
2425         if (!file.open(QIODevice::WriteOnly)) {
2426             for (int i = 0; i < processingItems.count(); i++)
2427                 setProxyStatus(processingItems.at(i), PROXYCRASHED);
2428             m_processingProxy.removeAll(info.dest);
2429             continue;
2430         }
2431         file.close();
2432         QFile::remove(info.dest);
2433     
2434         for (int i = 0; i < processingItems.count(); i++)
2435             setProxyStatus(processingItems.at(i), CREATINGPROXY);
2436
2437         // Special case: playlist clips (.mlt or .kdenlive project files)
2438         if (info.type == PLAYLIST) {
2439             // change FFmpeg params to MLT format
2440             QStringList parameters;
2441             parameters << info.src;
2442             parameters << "-consumer" << "avformat:" + info.dest;
2443             QStringList params = m_doc->getDocumentProperty("proxyparams").simplified().split('-', QString::SkipEmptyParts);
2444         
2445             foreach(QString s, params) {
2446                 s = s.simplified();
2447                 if (s.count(' ') == 0) {
2448                     s.append("=1");
2449                 }
2450                 else s.replace(' ', '=');
2451                 parameters << s;
2452             }
2453         
2454             parameters.append(QString("real_time=-%1").arg(KdenliveSettings::mltthreads()));
2455
2456             //TODO: currently, when rendering an xml file through melt, the display ration is lost, so we enforce it manualy
2457             double display_ratio = KdenliveDoc::getDisplayRatio(info.src);
2458             parameters << "aspect=" + QString::number(display_ratio);
2459
2460             //kDebug()<<"TRANSCOD: "<<parameters;
2461             QProcess myProcess;
2462             myProcess.setProcessChannelMode(QProcess::MergedChannels);
2463             myProcess.start(KdenliveSettings::rendererpath(), parameters);
2464             myProcess.waitForStarted();
2465             int result = -1;
2466             int duration = 0;
2467             while (myProcess.state() != QProcess::NotRunning) {
2468                 // building proxy file
2469                 if (m_abortProxy.contains(info.dest) || m_abortAllProxies) {
2470                     myProcess.close();
2471                     myProcess.waitForFinished();
2472                     QFile::remove(info.dest);
2473                     m_abortProxy.removeAll(info.dest);
2474                     m_processingProxy.removeAll(info.dest);
2475                     for (int i = 0; i < processingItems.count(); i++)
2476                         setProxyStatus(processingItems.at(i), NOPROXY);
2477                     result = -2;
2478                 }
2479                 else {
2480                     QString log = QString(myProcess.readAll());
2481                     processLogInfo(processingItems, &duration, log);
2482                 }
2483                 myProcess.waitForFinished(500);
2484             }
2485             myProcess.waitForFinished();
2486             m_processingProxy.removeAll(info.dest);
2487             if (result == -1) result = myProcess.exitStatus();
2488             if (result == 0) {
2489                 // proxy successfully created
2490                 for (int i = 0; i < processingItems.count(); i++)
2491                     setProxyStatus(processingItems.at(i), PROXYDONE);
2492                 slotGotProxy(info.dest);
2493             }
2494             else if (result == 1) {
2495                 // Proxy process crashed
2496                 QFile::remove(info.dest);
2497                 for (int i = 0; i < processingItems.count(); i++)
2498                     setProxyStatus(processingItems.at(i), PROXYCRASHED);
2499             }
2500             continue;
2501         }
2502     
2503         if (info.type == IMAGE) {
2504             // Image proxy
2505             QImage i(info.src);
2506             if (i.isNull()) {
2507                 // Cannot load image
2508                 for (int i = 0; i < processingItems.count(); i++)
2509                     setProxyStatus(processingItems.at(i), PROXYCRASHED);
2510                 continue;
2511             }
2512             QImage proxy;
2513             // Images are scaled to profile size. 
2514             //TODO: Make it be configurable?
2515             if (i.width() > i.height()) proxy = i.scaledToWidth(m_render->frameRenderWidth());
2516             else proxy = i.scaledToHeight(m_render->renderHeight());
2517             if (info.exif > 1) {
2518                 // Rotate image according to exif data
2519                 QImage processed;
2520                 QMatrix matrix;
2521
2522                 switch ( info.exif ) {
2523                     case 2:
2524                         matrix.scale( -1, 1 );
2525                         break;
2526                     case 3:
2527                         matrix.rotate( 180 );
2528                         break;
2529                     case 4:
2530                         matrix.scale( 1, -1 );
2531                         break;
2532                     case 5:
2533                         matrix.rotate( 270 );
2534                         matrix.scale( -1, 1 );
2535                         break;
2536                     case 6:
2537                         matrix.rotate( 90 );
2538                         break;
2539                     case 7:
2540                         matrix.rotate( 90 );
2541                         matrix.scale( -1, 1 );
2542                         break;
2543                     case 8:
2544                         matrix.rotate( 270 );
2545                         break;
2546                 }
2547                 processed = proxy.transformed( matrix );
2548                 processed.save(info.dest);
2549             }
2550             else proxy.save(info.dest);
2551             for (int i = 0; i < processingItems.count(); i++)
2552                 setProxyStatus(processingItems.at(i), PROXYDONE);
2553             slotGotProxy(info.dest);
2554             m_abortProxy.removeAll(info.dest);
2555             m_processingProxy.removeAll(info.dest);
2556             continue;
2557         }
2558
2559         QStringList parameters;
2560         parameters << "-i" << info.src;
2561         QString params = m_doc->getDocumentProperty("proxyparams").simplified();
2562         foreach(QString s, params.split(' '))
2563         parameters << s;
2564
2565         // Make sure we don't block when proxy file already exists
2566         parameters << "-y";
2567         parameters << info.dest;
2568         QProcess myProcess;
2569         myProcess.setProcessChannelMode(QProcess::MergedChannels);
2570         myProcess.start("ffmpeg", parameters);
2571         myProcess.waitForStarted();
2572         int result = -1;
2573         int duration = 0;
2574    
2575         while (myProcess.state() != QProcess::NotRunning) {
2576             // building proxy file
2577             if (m_abortProxy.contains(info.dest) || m_abortAllProxies) {
2578                 myProcess.close();
2579                 myProcess.waitForFinished();
2580                 m_abortProxy.removeAll(info.dest);
2581                 m_processingProxy.removeAll(info.dest);
2582                 QFile::remove(info.dest);
2583                 if (!m_abortAllProxies) {
2584                     for (int i = 0; i < processingItems.count(); i++)
2585                         setProxyStatus(processingItems.at(i), NOPROXY);
2586                 }
2587                 else continue;
2588                 result = -2;
2589             }
2590             else {
2591                 QString log = QString(myProcess.readAll());
2592                 processLogInfo(processingItems, &duration, log);
2593             }
2594             myProcess.waitForFinished(500);
2595         }
2596         myProcess.waitForFinished();
2597         m_abortProxy.removeAll(info.dest);
2598         m_processingProxy.removeAll(info.dest);
2599         if (result == -1) {
2600             result = myProcess.exitStatus();
2601         }
2602         
2603         // FFmpeg process terminated normally, but make sure proxy clip exists
2604         if (result != -2 && QFileInfo(info.dest).size() == 0) {
2605             result = QProcess::CrashExit;
2606         }
2607
2608         if (result == QProcess::NormalExit) {
2609             // proxy successfully created
2610             for (int i = 0; i < processingItems.count(); i++)
2611                 setProxyStatus(processingItems.at(i), PROXYDONE);
2612             slotGotProxy(info.dest);
2613         }
2614         else if (result == QProcess::CrashExit) {
2615             // Proxy process crashed
2616             QFile::remove(info.dest);
2617             for (int i = 0; i < processingItems.count(); i++)
2618                 setProxyStatus(processingItems.at(i), PROXYCRASHED);
2619         }
2620     }
2621 }
2622
2623
2624 void ProjectList::processLogInfo(QList <ProjectItem *>items, int *duration, const QString &log)
2625 {
2626     int progress;
2627     if (*duration == 0) {
2628         if (log.contains("Duration:")) {
2629             QString data = log.section("Duration:", 1, 1).section(',', 0, 0).simplified();
2630             QStringList numbers = data.split(':');
2631             *duration = (int) (numbers.at(0).toInt() * 3600 + numbers.at(1).toInt() * 60 + numbers.at(2).toDouble());
2632         }
2633     }
2634     else if (log.contains("time=")) {
2635         QString time = log.section("time=", 1, 1).simplified().section(' ', 0, 0);
2636         if (time.contains(':')) {
2637             QStringList numbers = time.split(':');
2638             progress = numbers.at(0).toInt() * 3600 + numbers.at(1).toInt() * 60 + numbers.at(2).toDouble();
2639         }
2640         else progress = (int) time.toDouble();
2641         for (int i = 0; i < items.count(); i++)
2642             setProxyStatus(items.at(i), CREATINGPROXY, (int) (100.0 * progress / (*duration)));
2643     }
2644 }
2645
2646 void ProjectList::updateProxyConfig()
2647 {
2648     ProjectItem *item;
2649     QTreeWidgetItemIterator it(m_listView);
2650     QUndoCommand *command = new QUndoCommand();
2651     command->setText(i18n("Update proxy settings"));
2652     QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/";
2653     while (*it) {
2654         if ((*it)->type() != PROJECTCLIPTYPE) {
2655             ++it;
2656             continue;
2657         }
2658         item = static_cast<ProjectItem *>(*it);
2659         if (item == NULL) {
2660             ++it;
2661             continue;
2662         }
2663         CLIPTYPE t = item->clipType();
2664         if ((t == VIDEO || t == AV || t == UNKNOWN) && item->referencedClip() != NULL) {
2665             if  (generateProxy() && useProxy() && !item->isProxyRunning()) {
2666                 DocClipBase *clip = item->referencedClip();
2667                 if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > m_doc->getDocumentProperty("proxyminsize").toInt()) {
2668                     if (clip->getProperty("proxy").isEmpty()) {
2669                         // We need to insert empty proxy in old properties so that undo will work
2670                         QMap <QString, QString> oldProps;// = clip->properties();
2671                         oldProps.insert("proxy", QString());
2672                         QMap <QString, QString> newProps;
2673                         newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + "." + m_doc->getDocumentProperty("proxyextension"));
2674                         new EditClipCommand(this, clip->getId(), oldProps, newProps, true, command);
2675                     }
2676                 }
2677             }
2678             else if (item->hasProxy()) {
2679                 // remove proxy
2680                 QMap <QString, QString> newProps;
2681                 newProps.insert("proxy", QString());
2682                 newProps.insert("replace", "1");
2683                 // insert required duration for proxy
2684                 newProps.insert("proxy_out", item->referencedClip()->producerProperty("out"));
2685                 new EditClipCommand(this, item->clipId(), item->referencedClip()->properties(), newProps, true, command);
2686             }
2687         }
2688         else if (t == IMAGE && item->referencedClip() != NULL) {
2689             if  (generateImageProxy() && useProxy()) {
2690                 DocClipBase *clip = item->referencedClip();
2691                 int maxImageSize = m_doc->getDocumentProperty("proxyimageminsize").toInt();
2692                 if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > maxImageSize || clip->getProperty("frame_size").section('x', 1, 1).toInt() > maxImageSize) {
2693                     if (clip->getProperty("proxy").isEmpty()) {
2694                         // We need to insert empty proxy in old properties so that undo will work
2695                         QMap <QString, QString> oldProps = clip->properties();
2696                         oldProps.insert("proxy", QString());
2697                         QMap <QString, QString> newProps;
2698                         newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + ".png");
2699                         new EditClipCommand(this, clip->getId(), oldProps, newProps, true, command);
2700                     }
2701                 }
2702             }
2703             else if (item->hasProxy()) {
2704                 // remove proxy
2705                 QMap <QString, QString> newProps;
2706                 newProps.insert("proxy", QString());
2707                 newProps.insert("replace", "1");
2708                 new EditClipCommand(this, item->clipId(), item->referencedClip()->properties(), newProps, true, command);
2709             }
2710         }
2711         ++it;
2712     }
2713     if (command->childCount() > 0) m_doc->commandStack()->push(command);
2714     else delete command;
2715 }
2716
2717 void ProjectList::slotProxyCurrentItem(bool doProxy, ProjectItem *itemToProxy)
2718 {
2719     QList<QTreeWidgetItem *> list;
2720     if (itemToProxy == NULL) list = m_listView->selectedItems();
2721     else list << itemToProxy;
2722
2723     // expand list (folders, subclips) to get real clips
2724     QTreeWidgetItem *listItem;
2725     QList<ProjectItem *> clipList;
2726     for (int i = 0; i < list.count(); i++) {
2727         listItem = list.at(i);
2728         if (listItem->type() == PROJECTFOLDERTYPE) {
2729             for (int j = 0; j < listItem->childCount(); j++) {
2730                 QTreeWidgetItem *sub = listItem->child(j);
2731                 if (sub->type() == PROJECTCLIPTYPE) {
2732                     ProjectItem *item = static_cast <ProjectItem*>(sub);
2733                     if (!clipList.contains(item)) clipList.append(item);
2734                 }
2735             }
2736         }
2737         else if (listItem->type() == PROJECTSUBCLIPTYPE) {
2738             QTreeWidgetItem *sub = listItem->parent();
2739             ProjectItem *item = static_cast <ProjectItem*>(sub);
2740             if (!clipList.contains(item)) clipList.append(item);
2741         }
2742         else if (listItem->type() == PROJECTCLIPTYPE) {
2743             ProjectItem *item = static_cast <ProjectItem*>(listItem);
2744             if (!clipList.contains(item)) clipList.append(item);
2745         }
2746     }
2747     
2748     QUndoCommand *command = new QUndoCommand();
2749     if (doProxy) command->setText(i18np("Add proxy clip", "Add proxy clips", clipList.count()));
2750     else command->setText(i18np("Remove proxy clip", "Remove proxy clips", clipList.count()));
2751     
2752     // Make sure the proxy folder exists
2753     QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/";
2754     KStandardDirs::makeDir(proxydir);
2755                 
2756     QMap <QString, QString> newProps;
2757     QMap <QString, QString> oldProps;
2758     if (!doProxy) newProps.insert("proxy", "-");
2759     for (int i = 0; i < clipList.count(); i++) {
2760         ProjectItem *item = clipList.at(i);
2761         CLIPTYPE t = item->clipType();
2762         if ((t == VIDEO || t == AV || t == UNKNOWN || t == IMAGE || t == PLAYLIST) && item->referencedClip()) {
2763             if ((doProxy && item->hasProxy()) || (!doProxy && !item->hasProxy() && item->referencedClip()->getProducer() != NULL)) continue;
2764             DocClipBase *clip = item->referencedClip();
2765             if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
2766                 kDebug()<<"//// TRYING TO PROXY: "<<item->clipId()<<", but it is busy";
2767                 continue;
2768             }
2769                 
2770             oldProps = clip->properties();
2771             if (doProxy) {
2772                 newProps.clear();
2773                 QString path = proxydir + clip->getClipHash() + "." + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension"));
2774                 // insert required duration for proxy
2775                 newProps.insert("proxy_out", clip->producerProperty("out"));
2776                 newProps.insert("proxy", path);
2777                 // We need to insert empty proxy so that undo will work
2778                 oldProps.insert("proxy", QString());
2779             }
2780             else if (item->referencedClip()->getProducer() == NULL) {
2781                 // Force clip reload
2782                 kDebug()<<"// CLIP HAD NULL PROD------------";
2783                 newProps.insert("resource", item->referencedClip()->getProperty("resource"));
2784             }
2785             new EditClipCommand(this, item->clipId(), oldProps, newProps, true, command);
2786         }
2787     }
2788     if (command->childCount() > 0) {
2789         m_doc->commandStack()->push(command);
2790     }
2791     else delete command;
2792 }
2793
2794
2795 void ProjectList::slotDeleteProxy(const QString proxyPath)
2796 {
2797     if (proxyPath.isEmpty()) return;
2798     QUndoCommand *proxyCommand = new QUndoCommand();
2799     proxyCommand->setText(i18n("Remove Proxy"));
2800     QTreeWidgetItemIterator it(m_listView);
2801     ProjectItem *item;
2802     while (*it) {
2803         if ((*it)->type() == PROJECTCLIPTYPE) {
2804             item = static_cast <ProjectItem *>(*it);
2805             if (item->referencedClip()->getProperty("proxy") == proxyPath) {
2806                 QMap <QString, QString> props;
2807                 props.insert("proxy", QString());
2808                 new EditClipCommand(this, item->clipId(), item->referencedClip()->properties(), props, true, proxyCommand);
2809             
2810             }
2811         }
2812         ++it;
2813     }
2814     if (proxyCommand->childCount() == 0)
2815         delete proxyCommand;
2816     else
2817         m_commandStack->push(proxyCommand);
2818     QFile::remove(proxyPath);
2819 }
2820
2821 void ProjectList::setProxyStatus(ProjectItem *item, PROXYSTATUS status, int progress)
2822 {
2823     if (item == NULL || m_abortAllProxies) return;
2824     monitorItemEditing(false);
2825     item->setProxyStatus(status, progress);
2826     if (status == PROXYCRASHED) {
2827         DocClipBase *clip = item->referencedClip();
2828         if (!clip) {
2829             kDebug()<<"// PROXY CRASHED";
2830         }
2831         else if (clip->getProducer() == NULL && !clip->isPlaceHolder()) {
2832             // disable proxy and fetch real clip
2833             clip->setProperty("proxy", "-");
2834             QDomElement xml = clip->toXML();
2835             m_render->getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), true);
2836         }
2837         else {
2838             // Disable proxy for this clip
2839             clip->setProperty("proxy", "-");
2840         }
2841     }
2842     monitorItemEditing(true);
2843 }
2844
2845 void ProjectList::monitorItemEditing(bool enable)
2846 {
2847     if (enable) connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));     
2848     else disconnect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));     
2849 }
2850
2851 QStringList ProjectList::expandedFolders() const
2852 {
2853     QStringList result;
2854     FolderProjectItem *item;
2855     QTreeWidgetItemIterator it(m_listView);
2856     while (*it) {
2857         if ((*it)->type() != PROJECTFOLDERTYPE) {
2858             ++it;
2859             continue;
2860         }
2861         if ((*it)->isExpanded()) {
2862             item = static_cast<FolderProjectItem *>(*it);
2863             result.append(item->clipId());
2864         }
2865         ++it;
2866     }
2867     return result;
2868 }
2869
2870 #include "projectlist.moc"