]> git.sesse.net Git - kdenlive/blob - src/projectlist.cpp
Start caching of project tree thumbnails for faster project opening
[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
21 #include <QMouseEvent>
22 #include <QStylePainter>
23 #include <QPixmap>
24 #include <QIcon>
25 #include <QDialog>
26 #include <QtGui>
27
28 #include <KDebug>
29 #include <KAction>
30 #include <KLocale>
31 #include <KFileDialog>
32 #include <KInputDialog>
33 #include <KMessageBox>
34
35 #include <nepomuk/global.h>
36 #include <nepomuk/resource.h>
37 #include <nepomuk/tag.h>
38
39 #include "projectlist.h"
40 #include "projectitem.h"
41 #include "kdenlivesettings.h"
42 #include "slideshowclip.h"
43 #include "ui_colorclip_ui.h"
44 #include "titlewidget.h"
45
46
47 #include "definitions.h"
48 #include "clipmanager.h"
49 #include "docclipbase.h"
50 #include "kdenlivedoc.h"
51 #include "renderer.h"
52 #include "kthumb.h"
53 #include "projectlistview.h"
54
55 ProjectList::ProjectList(QWidget *parent)
56         : QWidget(parent), m_render(NULL), m_fps(-1), m_commandStack(NULL), m_selectedItem(NULL), m_infoQueue(QMap <QString, QDomElement> ()), m_thumbnailQueue(QList <QString> ()), m_refreshed(false) {
57
58     QWidget *vbox = new QWidget;
59     listView = new ProjectListView(this);;
60     QVBoxLayout *layout = new QVBoxLayout;
61     layout->setContentsMargins(0, 0, 0, 0);
62     m_clipIdCounter = 0;
63     // setup toolbar
64     searchView = new KTreeWidgetSearchLine(this);
65     m_toolbar = new QToolBar("projectToolBar", this);
66     m_toolbar->addWidget(searchView);
67
68     QToolButton *addButton = new QToolButton(m_toolbar);
69     QMenu *addMenu = new QMenu(this);
70     addButton->setMenu(addMenu);
71     addButton->setPopupMode(QToolButton::MenuButtonPopup);
72     m_toolbar->addWidget(addButton);
73
74     QAction *addClipButton = addMenu->addAction(KIcon("kdenlive-add-clip"), i18n("Add Clip"));
75     connect(addClipButton, SIGNAL(triggered()), this, SLOT(slotAddClip()));
76
77     QAction *addColorClip = addMenu->addAction(KIcon("kdenlive-add-color-clip"), i18n("Add Color Clip"));
78     connect(addColorClip, SIGNAL(triggered()), this, SLOT(slotAddColorClip()));
79
80     QAction *addSlideClip = addMenu->addAction(KIcon("kdenlive-add-slide-clip"), i18n("Add Slideshow Clip"));
81     connect(addSlideClip, SIGNAL(triggered()), this, SLOT(slotAddSlideshowClip()));
82
83     QAction *addTitleClip = addMenu->addAction(KIcon("kdenlive-add-text-clip"), i18n("Add Title Clip"));
84     connect(addTitleClip, SIGNAL(triggered()), this, SLOT(slotAddTitleClip()));
85
86     m_deleteAction = m_toolbar->addAction(KIcon("edit-delete"), i18n("Delete Clip"));
87     connect(m_deleteAction, SIGNAL(triggered()), this, SLOT(slotRemoveClip()));
88
89     m_editAction = m_toolbar->addAction(KIcon("document-properties"), i18n("Edit Clip"));
90     connect(m_editAction, SIGNAL(triggered()), this, SLOT(slotEditClip()));
91
92     QAction *addFolderButton = addMenu->addAction(KIcon("folder-new"), i18n("Create Folder"));
93     connect(addFolderButton, SIGNAL(triggered()), this, SLOT(slotAddFolder()));
94
95     addButton->setDefaultAction(addClipButton);
96
97     layout->addWidget(m_toolbar);
98     layout->addWidget(listView);
99     setLayout(layout);
100     //m_toolbar->setEnabled(false);
101
102     searchView->setTreeWidget(listView);
103
104     m_menu = new QMenu();
105     m_menu->addAction(addClipButton);
106     m_menu->addAction(addColorClip);
107     m_menu->addAction(addSlideClip);
108     m_menu->addAction(addTitleClip);
109     m_menu->addAction(m_editAction);
110     m_menu->addAction(m_deleteAction);
111     m_menu->addAction(addFolderButton);
112     m_menu->insertSeparator(m_deleteAction);
113
114     connect(listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
115     connect(listView, SIGNAL(focusMonitor()), this, SLOT(slotClipSelected()));
116     connect(listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
117     connect(listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
118     connect(listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
119     connect(listView, SIGNAL(addClip(QUrl, const QString &)), this, SLOT(slotAddClip(QUrl, const QString &)));
120     connect(listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
121     connect(listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
122
123     m_listViewDelegate = new ItemDelegate(listView);
124     listView->setItemDelegate(m_listViewDelegate);
125 }
126
127 ProjectList::~ProjectList() {
128     delete m_menu;
129     delete m_toolbar;
130 }
131
132 QByteArray ProjectList::headerInfo() {
133     return listView->header()->saveState();
134 }
135
136 void ProjectList::setHeaderInfo(const QByteArray &state) {
137     listView->header()->restoreState(state);
138 }
139
140 void ProjectList::slotEditClip() {
141     ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
142     if (item && !item->isGroup()) {
143         emit clipSelected(item->referencedClip());
144         emit showClipProperties(item->referencedClip());
145     }
146 }
147
148
149
150 void ProjectList::setRenderer(Render *projectRender) {
151     m_render = projectRender;
152 }
153
154 void ProjectList::slotClipSelected() {
155     if (listView->currentItem()) {
156         ProjectItem *clip = static_cast <ProjectItem*>(listView->currentItem());
157         if (!clip->isGroup()) {
158             m_selectedItem = clip;
159             emit clipSelected(clip->referencedClip());
160         }
161         m_editAction->setEnabled(true);
162         m_deleteAction->setEnabled(true);
163     } else {
164         m_editAction->setEnabled(false);
165         m_deleteAction->setEnabled(false);
166     }
167 }
168
169 void ProjectList::slotPauseMonitor() {
170     if (m_render) m_render->pause();
171 }
172
173 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties) {
174     ProjectItem *item = getItemById(id);
175     if (item) {
176         slotUpdateClipProperties(item, properties);
177         if (properties.contains("colour") || properties.contains("resource") || properties.contains("xmldata")) slotRefreshClipThumbnail(item);
178         if (properties.contains("out")) item->changeDuration(properties.value("out").toInt());
179     }
180 }
181
182 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties) {
183     if (!clip) return;
184     if (!clip->isGroup()) clip->setProperties(properties);
185     if (properties.contains("description")) {
186         CLIPTYPE type = clip->clipType();
187         clip->setText(2, properties.value("description"));
188         if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
189             // Use Nepomuk system to store clip description
190             Nepomuk::Resource f(clip->clipUrl().path());
191             if (f.isValid()) {
192                 f.setDescription(properties.value("description"));
193             } else {
194                 KMessageBox::sorry(this, i18n("Cannot access Desktop Search info for %1.\nDisabling Desktop Search integration.", clip->clipUrl().path()));
195                 KdenliveSettings::setActivate_nepomuk(false);
196             }
197         }
198         emit projectModified();
199     }
200 }
201
202 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column) {
203     ProjectItem *clip = static_cast <ProjectItem*>(item);
204     if (column == 2) {
205         QMap <QString, QString> props;
206         props["description"] = item->text(2);
207         slotUpdateClipProperties(clip, props);
208     } else if (column == 1 && clip->isGroup()) {
209         m_doc->slotEditFolder(item->text(1), clip->groupName(), clip->clipId());
210         clip->setGroupName(item->text(1));
211         const int children = item->childCount();
212         for (int i = 0; i < children; i++) {
213             ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
214             child->setProperty("groupname", item->text(1));
215         }
216     }
217 }
218
219 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item) {
220     bool enable = false;
221     if (item) {
222         enable = true;
223     }
224     m_editAction->setEnabled(enable);
225     m_deleteAction->setEnabled(enable);
226     m_menu->popup(pos);
227 }
228
229 void ProjectList::slotRemoveClip() {
230     if (!listView->currentItem()) return;
231     QList <QString> ids;
232     QMap <QString, QString> folderids;
233     QList<QTreeWidgetItem *> selected = listView->selectedItems();
234     ProjectItem *item;
235     for (int i = 0; i < selected.count(); i++) {
236         item = static_cast <ProjectItem *>(selected.at(i));
237         if (item->isGroup()) folderids[item->groupName()] = item->clipId();
238         else ids << item->clipId();
239         if (item->numReferences() > 0) {
240             if (KMessageBox::questionYesNo(this, i18np("Delete clip <b>%2</b> ?<br>This will also remove the clip in timeline", "Delete clip <b>%2</b> ?<br>This will also remove its %1 clips in timeline", item->numReferences(), item->names().at(1)), i18n("Delete Clip")) != KMessageBox::Yes) return;
241         } else if (item->isGroup() && item->childCount() > 0) {
242             int children = item->childCount();
243             if (KMessageBox::questionYesNo(this, i18n("Delete folder <b>%2</b> ?<br>This will also remove the %1 clips in that folder", children, item->names().at(1)), i18n("Delete Folder")) != KMessageBox::Yes) return;
244             for (int i = 0; i < children; ++i) {
245                 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
246                 ids << child->clipId();
247             }
248         }
249     }
250     if (!ids.isEmpty()) m_doc->deleteProjectClip(ids);
251     if (!folderids.isEmpty()) m_doc->deleteProjectFolder(folderids);
252     if (listView->topLevelItemCount() == 0) {
253         m_editAction->setEnabled(false);
254         m_deleteAction->setEnabled(false);
255     }
256 }
257
258 void ProjectList::selectItemById(const QString &clipId) {
259     ProjectItem *item = getItemById(clipId);
260     if (item) listView->setCurrentItem(item);
261 }
262
263
264 void ProjectList::slotDeleteClip(const QString &clipId) {
265     ProjectItem *item = getItemById(clipId);
266     QTreeWidgetItem *p = item->parent();
267     if (p) {
268         kDebug() << "///////  DELETED CLIP HAS A PARENT... " << p->indexOfChild(item);
269         QTreeWidgetItem *clone = p->takeChild(p->indexOfChild(item));
270     } else if (item) {
271         delete item;
272     }
273 }
274
275 void ProjectList::slotAddFolder() {
276
277     // QString folderName = KInputDialog::getText(i18n("New Folder"), i18n("Enter new folder name: "));
278     // if (folderName.isEmpty()) return;
279     m_doc->slotAddFolder(i18n("Folder")); //folderName);
280 }
281
282 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit) {
283     if (remove) {
284         ProjectItem *item;
285         QTreeWidgetItemIterator it(listView);
286         while (*it) {
287             item = static_cast <ProjectItem *>(*it);
288             if (item->isGroup() && item->clipId() == clipId) {
289                 delete item;
290                 break;
291             }
292             ++it;
293         }
294     } else {
295         if (edit) {
296             listView->blockSignals(true);
297             ProjectItem *item;
298             QTreeWidgetItemIterator it(listView);
299             while (*it) {
300                 item = static_cast <ProjectItem *>(*it);
301                 if (item->isGroup() && item->clipId() == clipId) {
302                     item->setGroupName(foldername);
303                     const int children = item->childCount();
304                     for (int i = 0; i < children; i++) {
305                         ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
306                         child->setProperty("groupname", foldername);
307                     }
308                     break;
309                 }
310                 ++it;
311             }
312             listView->blockSignals(false);
313         } else {
314             QStringList text;
315             text << QString() << foldername;
316             (void) new ProjectItem(listView, text, clipId);
317         }
318     }
319 }
320
321 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties) {
322     const QString parent = clip->getProperty("groupid");
323     //kDebug() << "Adding clip with groupid: " << parent;
324     ProjectItem *item = NULL;
325     if (!parent.isEmpty()) {
326         ProjectItem *parentitem = getItemById(parent);
327         if (!parentitem) {
328             QStringList text;
329             QString groupName = clip->getProperty("groupname");
330             //kDebug() << "Adding clip to new group: " << groupName;
331             if (groupName.isEmpty()) groupName = i18n("Folder");
332             text << QString() << groupName;
333             listView->blockSignals(true);
334             parentitem = new ProjectItem(listView, text, parent);
335             listView->blockSignals(false);
336         } else {
337             //kDebug() << "Adding clip to existing group: " << parentitem->groupName();
338         }
339         if (parentitem) item = new ProjectItem(parentitem, clip);
340     }
341     if (item == NULL) item = new ProjectItem(listView, clip);
342
343     KUrl url = clip->fileURL();
344     if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
345         // if file has Nepomuk comment, use it
346         Nepomuk::Resource f(url.path());
347         QString annotation;
348         if (f.isValid()) {
349             annotation = f.description();
350             /*
351             Nepomuk::Tag tag("test");
352             f.addTag(tag);*/
353         } else {
354             KMessageBox::sorry(this, i18n("Cannot access Desktop Search info for %1.\nDisabling Desktop Search integration.", url.path()));
355             KdenliveSettings::setActivate_nepomuk(false);
356         }
357         if (!annotation.isEmpty()) item->setText(2, annotation);
358     }
359     if (getProperties) requestClipInfo(clip->toXML(), clip->getId());
360 }
361
362 void ProjectList::requestClipInfo(const QDomElement xml, const QString id) {
363     kDebug() << " PRG LISTĀ REQUEST CLP INFO: " << id;
364     m_infoQueue.insert(id, xml);
365     listView->setEnabled(false);
366     if (m_infoQueue.count() == 1) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
367 }
368
369 void ProjectList::slotProcessNextClipInQueue() {
370     if (m_infoQueue.isEmpty()) {
371         listView->setEnabled(true);
372         return;
373     }
374     QMap<QString, QDomElement>::const_iterator i = m_infoQueue.constBegin();
375     if (i != m_infoQueue.constEnd()) {
376         const QDomElement dom = i.value();
377         const QString id = i.key();
378         m_infoQueue.remove(i.key());
379         emit getFileProperties(dom, id);
380     }
381     if (m_infoQueue.isEmpty()) listView->setEnabled(true);
382 }
383
384 void ProjectList::slotUpdateClip(const QString &id) {
385     ProjectItem *item = getItemById(id);
386     item->setData(1, UsageRole, QString::number(item->numReferences()));
387 }
388
389 void ProjectList::updateAllClips() {
390     QTreeWidgetItemIterator it(listView);
391     while (*it) {
392         ProjectItem *item = static_cast <ProjectItem *>(*it);
393         if (!item->isGroup()) {
394             if (item->referencedClip()->producer() == NULL) {
395                 DocClipBase *clip = item->referencedClip();
396                 if (clip->clipType() == TEXT && !QFile::exists(clip->fileURL().path())) {
397                     // regenerate text clip image if required
398                     TitleWidget *dia_ui = new TitleWidget(KUrl(), QString(), m_render, this);
399                     QDomDocument doc;
400                     doc.setContent(clip->getProperty("xmldata"));
401                     dia_ui->setXml(doc);
402                     QPixmap pix = dia_ui->renderedPixmap();
403                     pix.save(clip->fileURL().path());
404                     delete dia_ui;
405                 }
406                 requestClipInfo(clip->toXML(), clip->getId());
407             } else {
408                 QString cachedPixmap = m_doc->projectFolder().path() + "/thumbs/" + item->getClipHash() + ".png";
409                 if (QFile::exists(cachedPixmap)) {
410                     //kDebug()<<"// USING CACHED PIX: "<<cachedPixmap;
411                     item->setIcon(0, QPixmap(cachedPixmap));
412                 } else requestClipThumbnail(item->clipId());
413                 item->changeDuration(item->referencedClip()->producer()->get_playtime());
414             }
415             item->setData(1, UsageRole, QString::number(item->numReferences()));
416             qApp->processEvents();
417         }
418         ++it;
419     }
420     QTimer::singleShot(500, this, SLOT(slotCheckForEmptyQueue()));
421 }
422
423 void ProjectList::slotAddClip(QUrl givenUrl, QString group) {
424     if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
425     KUrl::List list;
426     if (givenUrl.isEmpty()) {
427         list = KFileDialog::getOpenUrls(KUrl("kfiledialog:///clipfolder"), "application/x-kdenlive video/x-flv application/vnd.rn-realmedia video/x-dv video/dv video/x-msvideo video/mpeg video/x-ms-wmv audio/mpeg audio/x-mp3 audio/x-wav application/ogg video/mp4 video/quicktime image/gif image/jpeg image/png image/x-bmp image/svg+xml image/tiff image/x-xcf-gimp image/x-vnd.adobe.photoshop image/x-pcx image/x-exr video/mlt-playlist audio/x-flac audio/mp4", this);
428     } else list.append(givenUrl);
429     if (list.isEmpty()) return;
430
431     QString groupId = QString();
432     if (group.isEmpty()) {
433         ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
434         if (item && !item->isGroup()) {
435             while (item->parent()) {
436                 item = static_cast <ProjectItem*>(item->parent());
437                 if (item->isGroup()) break;
438             }
439         }
440         if (item && item->isGroup()) {
441             group = item->groupName();
442             groupId = item->clipId();
443         }
444     }
445     m_doc->slotAddClipList(list, group, groupId);
446 }
447
448 void ProjectList::slotRemoveInvalidClip(const QString &id) {
449     ProjectItem *item = getItemById(id);
450     if (item) {
451         const QString path = item->referencedClip()->fileURL().path();
452         if (!path.isEmpty()) KMessageBox::sorry(this, i18n("<qt>Clip <b>%1</b><br>is invalid, will be removed from project.", path));
453         QList <QString> ids;
454         ids << id;
455         m_doc->deleteProjectClip(ids);
456     }
457     if (!m_infoQueue.isEmpty()) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
458 }
459
460 void ProjectList::slotAddColorClip() {
461     if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
462     QDialog *dia = new QDialog(this);
463     Ui::ColorClip_UI *dia_ui = new Ui::ColorClip_UI();
464     dia_ui->setupUi(dia);
465     dia_ui->clip_name->setText(i18n("Color Clip"));
466     dia_ui->clip_duration->setText(KdenliveSettings::color_duration());
467     if (dia->exec() == QDialog::Accepted) {
468         QString color = dia_ui->clip_color->color().name();
469         color = color.replace(0, 1, "0x") + "ff";
470
471         QString group = QString();
472         QString groupId = QString();
473         ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
474         if (item && !item->isGroup()) {
475             while (item->parent()) {
476                 item = static_cast <ProjectItem*>(item->parent());
477                 if (item->isGroup()) break;
478             }
479         }
480         if (item && item->isGroup()) {
481             group = item->groupName();
482             groupId = item->clipId();
483         }
484
485         m_doc->slotAddColorClipFile(dia_ui->clip_name->text(), color, dia_ui->clip_duration->text(), group, groupId);
486     }
487     delete dia_ui;
488     delete dia;
489 }
490
491
492 void ProjectList::slotAddSlideshowClip() {
493     if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
494     SlideshowClip *dia = new SlideshowClip(this);
495
496     if (dia->exec() == QDialog::Accepted) {
497
498         QString group = QString();
499         QString groupId = QString();
500         ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
501         if (item && !item->isGroup()) {
502             while (item->parent()) {
503                 item = static_cast <ProjectItem*>(item->parent());
504                 if (item->isGroup()) break;
505             }
506         }
507         if (item && item->isGroup()) {
508             group = item->groupName();
509             groupId = item->clipId();
510         }
511
512         m_doc->slotAddSlideshowClipFile(dia->clipName(), dia->selectedPath(), dia->imageCount(), dia->clipDuration(), dia->loop(), dia->fade(), dia->lumaDuration(), dia->lumaFile(), dia->softness(), group, groupId);
513     }
514     delete dia;
515 }
516
517 void ProjectList::slotAddTitleClip() {
518     QString group = QString();
519     QString groupId = QString();
520     ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
521     if (item && !item->isGroup()) {
522         while (item->parent()) {
523             item = static_cast <ProjectItem*>(item->parent());
524             if (item->isGroup()) break;
525         }
526     }
527     if (item && item->isGroup()) {
528         group = item->groupName();
529         groupId = item->clipId();
530     }
531
532     m_doc->slotCreateTextClip(group, groupId);
533 }
534
535 void ProjectList::setDocument(KdenliveDoc *doc) {
536     listView->blockSignals(true);
537     listView->clear();
538     m_thumbnailQueue.clear();
539     m_infoQueue.clear();
540     m_refreshed = false;
541     QList <DocClipBase*> list = doc->clipManager()->documentClipList();
542     for (int i = 0; i < list.count(); i++) {
543         slotAddClip(list.at(i), false);
544     }
545
546     m_fps = doc->fps();
547     m_timecode = doc->timecode();
548     m_commandStack = doc->commandStack();
549     m_doc = doc;
550     QTreeWidgetItem *first = listView->topLevelItem(0);
551     if (first) listView->setCurrentItem(first);
552     listView->blockSignals(false);
553     m_toolbar->setEnabled(true);
554 }
555
556 QDomElement ProjectList::producersList() {
557     QDomDocument doc;
558     QDomElement prods = doc.createElement("producerlist");
559     doc.appendChild(prods);
560     kDebug() << "////////////  PRO LISTĀ BUILD PRDSLIST ";
561     QTreeWidgetItemIterator it(listView);
562     while (*it) {
563         if (!((ProjectItem *)(*it))->isGroup())
564             prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
565         ++it;
566     }
567     return prods;
568 }
569
570 void ProjectList::slotCheckForEmptyQueue() {
571     if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
572         m_refreshed = true;
573         emit loadingIsOver();
574     } else QTimer::singleShot(500, this, SLOT(slotCheckForEmptyQueue()));
575 }
576
577 void ProjectList::requestClipThumbnail(const QString &id) {
578     m_thumbnailQueue.append(id);
579     if (m_thumbnailQueue.count() == 1) QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
580 }
581
582 void ProjectList::slotProcessNextThumbnail() {
583     if (m_thumbnailQueue.isEmpty()) {
584         return;
585     }
586     slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
587 }
588
589 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update) {
590     ProjectItem *item = getItemById(clipId);
591     if (item) slotRefreshClipThumbnail(item, update);
592     else slotProcessNextThumbnail();
593 }
594
595 void ProjectList::slotRefreshClipThumbnail(ProjectItem *item, bool update) {
596     if (item) {
597         if (!item->referencedClip()) return;
598         int height = 50;
599         int width = (int)(height  * m_render->dar());
600         DocClipBase *clip = item->referencedClip();
601         if (!clip) slotProcessNextThumbnail();
602         QPixmap pix;
603         if (clip->clipType() == AUDIO) pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
604         else pix = item->referencedClip()->thumbProducer()->extractImage(item->referencedClip()->getClipThumbFrame(), width, height);
605         item->setIcon(0, pix);
606         m_doc->cachePixmap(item->getClipHash(), pix);
607         if (update) emit projectModified();
608         if (!m_thumbnailQueue.isEmpty()) QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
609     }
610 }
611
612 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata) {
613     ProjectItem *item = getItemById(clipId);
614     if (item && producer) {
615         item->setProperties(properties, metadata);
616         item->referencedClip()->setProducer(producer);
617         emit receivedClipDuration(clipId, item->clipMaxDuration());
618     } else kDebug() << "////////  COULD NOT FIND CLIP TO UPDATE PRPS...";
619     if (!m_infoQueue.isEmpty()) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
620 }
621
622 void ProjectList::slotReplyGetImage(const QString &clipId, int pos, const QPixmap &pix, int w, int h) {
623     ProjectItem *item = getItemById(clipId);
624     if (item) {
625         item->setIcon(0, pix);
626         m_doc->cachePixmap(item->getClipHash(), pix);
627     }
628 }
629
630 ProjectItem *ProjectList::getItemById(const QString &id) {
631     QTreeWidgetItemIterator it(listView);
632     while (*it) {
633         if (((ProjectItem *)(*it))->clipId() == id)
634             return static_cast<ProjectItem *>(*it);
635         ++it;
636     }
637     return NULL;
638 #ifdef USED_TO_BE_THIS
639     while (*it) {
640         if (((ProjectItem *)(*it))->clipId() == id)
641             break;
642         ++it;
643     }
644     if (*it) return ((ProjectItem *)(*it));
645     return NULL;
646 #endif
647 }
648
649 void ProjectList::slotSelectClip(const QString &ix) {
650     ProjectItem *p = getItemById(ix);
651     if (p) {
652         listView->setCurrentItem(p);
653         listView->scrollToItem(p);
654         m_editAction->setEnabled(true);
655         m_deleteAction->setEnabled(true);
656     }
657 }
658
659 #include "projectlist.moc"