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