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