1 /***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
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. *
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. *
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 ***************************************************************************/
21 #include <QMouseEvent>
22 #include <QStylePainter>
31 #include <KFileDialog>
32 #include <KInputDialog>
33 #include <KMessageBox>
35 #include <nepomuk/global.h>
36 #include <nepomuk/resourcemanager.h>
37 //#include <nepomuk/tag.h>
39 #include "projectlist.h"
40 #include "projectitem.h"
41 #include "addfoldercommand.h"
42 #include "kdenlivesettings.h"
43 #include "slideshowclip.h"
44 #include "ui_colorclip_ui.h"
45 #include "titlewidget.h"
46 #include "definitions.h"
47 #include "clipmanager.h"
48 #include "docclipbase.h"
49 #include "kdenlivedoc.h"
52 #include "projectlistview.h"
53 #include "editclipcommand.h"
54 #include "editfoldercommand.h"
56 ProjectList::ProjectList(QWidget *parent)
57 : 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), m_editAction(NULL), m_openAction(NULL), m_deleteAction(NULL), m_reloadAction(NULL) {
59 QWidget *vbox = new QWidget;
60 listView = new ProjectListView(this);;
61 QVBoxLayout *layout = new QVBoxLayout;
62 layout->setContentsMargins(0, 0, 0, 0);
63 // mbd: I think this has died at some point: m_clipIdCounter = 0;
65 searchView = new KTreeWidgetSearchLine(this);
66 m_toolbar = new QToolBar("projectToolBar", this);
67 m_toolbar->addWidget(searchView);
69 m_addButton = new QToolButton(m_toolbar);
70 m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
71 m_toolbar->addWidget(m_addButton);
73 layout->addWidget(m_toolbar);
74 layout->addWidget(listView);
76 //m_toolbar->setEnabled(false);
78 searchView->setTreeWidget(listView);
80 connect(listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
81 connect(listView, SIGNAL(focusMonitor()), this, SLOT(slotClipSelected()));
82 connect(listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
83 connect(listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
84 connect(listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
85 connect(listView, SIGNAL(addClip(KUrl, const QString &)), this, SLOT(slotAddClip(KUrl, const QString &)));
86 connect(listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
87 connect(listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
89 ItemDelegate *listViewDelegate = new ItemDelegate(listView);
90 listView->setItemDelegate(listViewDelegate);
92 if (KdenliveSettings::activate_nepomuk()) {
93 Nepomuk::ResourceManager::instance()->init();
94 if (!Nepomuk::ResourceManager::instance()->initialized()) {
95 kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
96 KdenliveSettings::setActivate_nepomuk(false);
101 ProjectList::~ProjectList() {
106 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction) {
107 QList <QAction *> actions = addMenu->actions();
108 for (int i = 0; i < actions.count(); i++) {
109 if (actions.at(i)->data().toString() == "clip_properties") {
110 m_editAction = actions.at(i);
111 m_toolbar->addAction(m_editAction);
114 } else if (actions.at(i)->data().toString() == "delete_clip") {
115 m_deleteAction = actions.at(i);
116 m_toolbar->addAction(m_deleteAction);
119 } else if (actions.at(i)->data().toString() == "edit_clip") {
120 m_openAction = actions.at(i);
123 } else if (actions.at(i)->data().toString() == "reload_clip") {
124 m_reloadAction = actions.at(i);
130 QMenu *m = new QMenu();
131 m->addActions(actions);
132 m_addButton->setMenu(m);
133 m_addButton->setDefaultAction(defaultAction);
134 m_menu = new QMenu();
135 m_menu->addActions(addMenu->actions());
138 void ProjectList::setupGeneratorMenu(QMenu *addMenu) {
139 if (!addMenu) return;
140 QMenu *menu = m_addButton->menu();
141 menu->addMenu(addMenu);
142 m_addButton->setMenu(menu);
144 m_menu->addMenu(addMenu);
145 if (addMenu->isEmpty()) addMenu->setEnabled(false);
146 m_menu->addAction(m_reloadAction);
147 m_menu->addAction(m_editAction);
148 m_menu->addAction(m_openAction);
149 m_menu->addAction(m_deleteAction);
150 m_menu->insertSeparator(m_deleteAction);
154 QByteArray ProjectList::headerInfo() {
155 return listView->header()->saveState();
158 void ProjectList::setHeaderInfo(const QByteArray &state) {
159 listView->header()->restoreState(state);
162 void ProjectList::slotEditClip() {
163 ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
164 if (item && !item->isGroup()) {
165 emit clipSelected(item->referencedClip());
166 emit showClipProperties(item->referencedClip());
170 void ProjectList::slotOpenClip() {
171 ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
172 if (item && !item->isGroup()) {
173 if (item->clipType() == IMAGE) {
174 if (KdenliveSettings::defaultimageapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open images in the Settings dialog"));
175 else QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
177 if (item->clipType() == AUDIO) {
178 if (KdenliveSettings::defaultaudioapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open audio files in the Settings dialog"));
179 else QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
184 void ProjectList::slotReloadClip() {
185 ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
186 if (item && !item->isGroup()) {
187 if (item->clipType() == IMAGE) {
188 item->referencedClip()->producer()->set("force_reload", 1);
190 emit getFileProperties(item->toXml(), item->clipId(), false);
194 void ProjectList::setRenderer(Render *projectRender) {
195 m_render = projectRender;
196 listView->setIconSize(QSize(40 * m_render->dar(), 40));
199 void ProjectList::slotClipSelected() {
200 if (listView->currentItem()) {
201 ProjectItem *clip = static_cast <ProjectItem*>(listView->currentItem());
202 if (!clip->isGroup()) {
203 m_selectedItem = clip;
204 emit clipSelected(clip->referencedClip());
206 m_editAction->setEnabled(true);
207 m_deleteAction->setEnabled(true);
208 m_reloadAction->setEnabled(true);
209 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
210 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
211 m_openAction->setEnabled(true);
212 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
213 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
214 m_openAction->setEnabled(true);
215 } else m_openAction->setEnabled(false);
217 emit clipSelected(NULL);
218 m_editAction->setEnabled(false);
219 m_deleteAction->setEnabled(false);
220 m_openAction->setEnabled(false);
221 m_reloadAction->setEnabled(false);
225 void ProjectList::slotPauseMonitor() {
226 if (m_render) m_render->pause();
229 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties) {
230 ProjectItem *item = getItemById(id);
232 slotUpdateClipProperties(item, properties);
233 if (properties.contains("colour") || properties.contains("resource") || properties.contains("xmldata")) slotRefreshClipThumbnail(item);
234 if (properties.contains("out")) item->changeDuration(properties.value("out").toInt());
238 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties) {
240 if (!clip->isGroup()) clip->setProperties(properties);
241 if (properties.contains("name")) {
242 listView->blockSignals(true);
243 clip->setText(1, properties.value("name"));
244 listView->blockSignals(false);
245 emit clipNameChanged(clip->clipId(), properties.value("name"));
247 if (properties.contains("description")) {
248 CLIPTYPE type = clip->clipType();
249 listView->blockSignals(true);
250 clip->setText(2, properties.value("description"));
251 listView->blockSignals(false);
252 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
253 // Use Nepomuk system to store clip description
254 Nepomuk::Resource f(clip->clipUrl().path());
255 f.setDescription(properties.value("description"));
257 emit projectModified();
261 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column) {
262 ProjectItem *clip = static_cast <ProjectItem*>(item);
264 if (clip->referencedClip()) {
265 QMap <QString, QString> oldprops;
266 QMap <QString, QString> newprops;
267 oldprops["description"] = clip->referencedClip()->getProperty("description");
268 newprops["description"] = item->text(2);
269 slotUpdateClipProperties(clip, newprops);
270 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
271 m_commandStack->push(command);
273 } else if (column == 1) {
274 if (clip->isGroup()) {
275 editFolder(item->text(1), clip->groupName(), clip->clipId());
276 clip->setGroupName(item->text(1));
277 m_doc->clipManager()->addFolder(clip->clipId(), item->text(1));
278 const int children = item->childCount();
279 for (int i = 0; i < children; i++) {
280 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
281 child->setProperty("groupname", item->text(1));
284 if (clip->referencedClip()) {
285 QMap <QString, QString> oldprops;
286 QMap <QString, QString> newprops;
287 oldprops["name"] = clip->referencedClip()->getProperty("name");
288 newprops["name"] = item->text(1);
289 slotUpdateClipProperties(clip, newprops);
290 emit projectModified();
291 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
292 m_commandStack->push(command);
298 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item) {
303 m_editAction->setEnabled(enable);
304 m_deleteAction->setEnabled(enable);
305 m_reloadAction->setEnabled(enable);
307 ProjectItem *clip = static_cast <ProjectItem*>(item);
308 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
309 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
310 m_openAction->setEnabled(true);
311 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
312 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
313 m_openAction->setEnabled(true);
314 } else m_openAction->setEnabled(false);
315 } else m_openAction->setEnabled(false);
319 void ProjectList::slotRemoveClip() {
320 if (!listView->currentItem()) return;
322 QMap <QString, QString> folderids;
323 QList<QTreeWidgetItem *> selected = listView->selectedItems();
325 for (int i = 0; i < selected.count(); i++) {
326 item = static_cast <ProjectItem *>(selected.at(i));
327 if (item->isGroup()) folderids[item->groupName()] = item->clipId();
328 else ids << item->clipId();
329 if (item->numReferences() > 0) {
330 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;
331 } else if (item->isGroup() && item->childCount() > 0) {
332 int children = item->childCount();
333 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;
334 for (int i = 0; i < children; ++i) {
335 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
336 ids << child->clipId();
340 if (!ids.isEmpty()) m_doc->deleteProjectClip(ids);
341 if (!folderids.isEmpty()) deleteProjectFolder(folderids);
342 if (listView->topLevelItemCount() == 0) {
343 m_editAction->setEnabled(false);
344 m_deleteAction->setEnabled(false);
345 m_openAction->setEnabled(false);
346 m_reloadAction->setEnabled(false);
350 void ProjectList::selectItemById(const QString &clipId) {
351 ProjectItem *item = getItemById(clipId);
352 if (item) listView->setCurrentItem(item);
356 void ProjectList::slotDeleteClip(const QString &clipId) {
357 ProjectItem *item = getItemById(clipId);
358 QTreeWidgetItem *p = item->parent();
360 kDebug() << "/////// DELETED CLIP HAS A PARENT... " << p->indexOfChild(item);
361 QTreeWidgetItem *clone = p->takeChild(p->indexOfChild(item));
368 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId) {
369 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
370 m_commandStack->push(command);
371 m_doc->setModified(true);
374 void ProjectList::slotAddFolder() {
375 AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
376 m_commandStack->push(command);
379 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit) {
381 ProjectItem *item = getFolderItemById(clipId);
383 m_doc->clipManager()->deleteFolder(clipId);
388 ProjectItem *item = getFolderItemById(clipId);
389 QTreeWidgetItemIterator it(listView);
391 listView->blockSignals(true);
392 item->setGroupName(foldername);
393 listView->blockSignals(false);
394 m_doc->clipManager()->addFolder(clipId, foldername);
395 const int children = item->childCount();
396 for (int i = 0; i < children; i++) {
397 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
398 child->setProperty("groupname", foldername);
403 text << QString() << foldername;
404 listView->blockSignals(true);
405 (void) new ProjectItem(listView, text, clipId);
406 m_doc->clipManager()->addFolder(clipId, foldername);
407 listView->blockSignals(false);
414 void ProjectList::deleteProjectFolder(QMap <QString, QString> map) {
415 QMapIterator<QString, QString> i(map);
416 QUndoCommand *delCommand = new QUndoCommand();
417 delCommand->setText(i18n("Delete Folder"));
418 while (i.hasNext()) {
420 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
422 m_commandStack->push(delCommand);
423 m_doc->setModified(true);
426 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties) {
427 if (getProperties) listView->setEnabled(false);
428 listView->blockSignals(true);
429 const QString parent = clip->getProperty("groupid");
430 kDebug() << "Adding clip with groupid: " << parent;
431 ProjectItem *item = NULL;
432 if (!parent.isEmpty()) {
433 ProjectItem *parentitem = getFolderItemById(parent);
436 QString groupName = clip->getProperty("groupname");
437 //kDebug() << "Adding clip to new group: " << groupName;
438 if (groupName.isEmpty()) groupName = i18n("Folder");
439 text << QString() << groupName;
440 parentitem = new ProjectItem(listView, text, parent);
442 //kDebug() << "Adding clip to existing group: " << parentitem->groupName();
444 if (parentitem) item = new ProjectItem(parentitem, clip);
446 if (item == NULL) item = new ProjectItem(listView, clip);
448 KUrl url = clip->fileURL();
449 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
450 // if file has Nepomuk comment, use it
451 Nepomuk::Resource f(url.path());
452 QString annotation = f.description();
453 if (!annotation.isEmpty()) item->setText(2, annotation);
454 item->setText(3, QString::number(f.rating()));
456 listView->blockSignals(false);
459 void ProjectList::slotResetProjectList() {
461 emit clipSelected(NULL);
462 m_thumbnailQueue.clear();
467 void ProjectList::requestClipInfo(const QDomElement xml, const QString id) {
468 kDebug() << " PRG LISTĀ REQUEST CLP INFO: " << id;
469 m_infoQueue.insert(id, xml);
470 listView->setEnabled(false);
471 if (m_infoQueue.count() == 1) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
474 void ProjectList::slotProcessNextClipInQueue() {
475 if (m_infoQueue.isEmpty()) {
476 listView->setEnabled(true);
479 QMap<QString, QDomElement>::const_iterator i = m_infoQueue.constBegin();
480 if (i != m_infoQueue.constEnd()) {
481 const QDomElement dom = i.value();
482 const QString id = i.key();
483 m_infoQueue.remove(i.key());
484 emit getFileProperties(dom, id, true);
486 if (m_infoQueue.isEmpty()) listView->setEnabled(true);
489 void ProjectList::slotUpdateClip(const QString &id) {
490 ProjectItem *item = getItemById(id);
491 listView->blockSignals(true);
492 if (item) item->setData(1, UsageRole, QString::number(item->numReferences()));
493 listView->blockSignals(false);
496 void ProjectList::updateAllClips() {
497 QTreeWidgetItemIterator it(listView);
499 ProjectItem *item = static_cast <ProjectItem *>(*it);
500 if (!item->isGroup()) {
501 if (item->referencedClip()->producer() == NULL) {
502 DocClipBase *clip = item->referencedClip();
503 if (clip->clipType() == TEXT && !QFile::exists(clip->fileURL().path())) {
504 // regenerate text clip image if required
505 TitleWidget *dia_ui = new TitleWidget(KUrl(), QString(), m_render, this);
507 doc.setContent(clip->getProperty("xmldata"));
509 QImage pix = dia_ui->renderedPixmap();
510 pix.save(clip->fileURL().path());
513 requestClipInfo(clip->toXML(), clip->getId());
515 QString cachedPixmap = m_doc->projectFolder().path() + "/thumbs/" + item->getClipHash() + ".png";
516 if (QFile::exists(cachedPixmap)) {
517 //kDebug()<<"// USING CACHED PIX: "<<cachedPixmap;
518 listView->blockSignals(true);
519 item->setIcon(0, QPixmap(cachedPixmap));
520 listView->blockSignals(false);
521 } else requestClipThumbnail(item->clipId());
522 listView->blockSignals(true);
523 item->changeDuration(item->referencedClip()->producer()->get_playtime());
524 listView->blockSignals(false);
526 listView->blockSignals(true);
527 item->setData(1, UsageRole, QString::number(item->numReferences()));
528 listView->blockSignals(false);
529 qApp->processEvents();
533 QTimer::singleShot(500, this, SLOT(slotCheckForEmptyQueue()));
536 void ProjectList::slotAddClip(KUrl givenUrl, QString group) {
537 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
539 if (givenUrl.isEmpty()) {
540 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/x-matroska 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);
541 } else list.append(givenUrl);
542 if (list.isEmpty()) return;
544 QString groupId = QString();
545 if (group.isEmpty()) {
546 ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
547 if (item && !item->isGroup()) {
548 while (item->parent()) {
549 item = static_cast <ProjectItem*>(item->parent());
550 if (item->isGroup()) break;
553 if (item && item->isGroup()) {
554 group = item->groupName();
555 groupId = item->clipId();
558 m_doc->slotAddClipList(list, group, groupId);
561 void ProjectList::slotRemoveInvalidClip(const QString &id) {
562 ProjectItem *item = getItemById(id);
564 const QString path = item->referencedClip()->fileURL().path();
565 if (!path.isEmpty()) KMessageBox::sorry(this, i18n("Clip <b>%1</b><br>is invalid, will be removed from project.", path));
568 m_doc->deleteProjectClip(ids);
570 if (!m_infoQueue.isEmpty()) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
571 else listView->setEnabled(true);
574 void ProjectList::slotAddColorClip() {
575 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
576 QDialog *dia = new QDialog(this);
577 Ui::ColorClip_UI *dia_ui = new Ui::ColorClip_UI();
578 dia_ui->setupUi(dia);
579 dia_ui->clip_name->setText(i18n("Color Clip"));
580 dia_ui->clip_duration->setText(KdenliveSettings::color_duration());
581 if (dia->exec() == QDialog::Accepted) {
582 QString color = dia_ui->clip_color->color().name();
583 color = color.replace(0, 1, "0x") + "ff";
585 QString group = QString();
586 QString groupId = QString();
587 ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
588 if (item && !item->isGroup()) {
589 while (item->parent()) {
590 item = static_cast <ProjectItem*>(item->parent());
591 if (item->isGroup()) break;
594 if (item && item->isGroup()) {
595 group = item->groupName();
596 groupId = item->clipId();
599 m_doc->slotAddColorClipFile(dia_ui->clip_name->text(), color, dia_ui->clip_duration->text(), group, groupId);
606 void ProjectList::slotAddSlideshowClip() {
607 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
608 SlideshowClip *dia = new SlideshowClip(this);
610 if (dia->exec() == QDialog::Accepted) {
612 QString group = QString();
613 QString groupId = QString();
614 ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
615 if (item && !item->isGroup()) {
616 while (item->parent()) {
617 item = static_cast <ProjectItem*>(item->parent());
618 if (item->isGroup()) break;
621 if (item && item->isGroup()) {
622 group = item->groupName();
623 groupId = item->clipId();
626 m_doc->slotAddSlideshowClipFile(dia->clipName(), dia->selectedPath(), dia->imageCount(), dia->clipDuration(), dia->loop(), dia->fade(), dia->lumaDuration(), dia->lumaFile(), dia->softness(), group, groupId);
631 void ProjectList::slotAddTitleClip() {
632 QString group = QString();
633 QString groupId = QString();
634 ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
635 if (item && !item->isGroup()) {
636 while (item->parent()) {
637 item = static_cast <ProjectItem*>(item->parent());
638 if (item->isGroup()) break;
641 if (item && item->isGroup()) {
642 group = item->groupName();
643 groupId = item->clipId();
646 m_doc->slotCreateTextClip(group, groupId);
649 void ProjectList::setDocument(KdenliveDoc *doc) {
650 listView->blockSignals(true);
652 emit clipSelected(NULL);
653 m_thumbnailQueue.clear();
656 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
657 QMapIterator<QString, QString> f(flist);
658 while (f.hasNext()) {
660 (void) new ProjectItem(listView, QStringList() << QString() << f.value(), f.key());
663 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
664 for (int i = 0; i < list.count(); i++) {
665 slotAddClip(list.at(i), false);
669 m_timecode = doc->timecode();
670 m_commandStack = doc->commandStack();
672 QTreeWidgetItem *first = listView->topLevelItem(0);
673 if (first) listView->setCurrentItem(first);
674 listView->blockSignals(false);
675 m_toolbar->setEnabled(true);
678 QDomElement ProjectList::producersList() {
680 QDomElement prods = doc.createElement("producerlist");
681 doc.appendChild(prods);
682 kDebug() << "//////////// PRO LISTĀ BUILD PRDSLIST ";
683 QTreeWidgetItemIterator it(listView);
685 if (!((ProjectItem *)(*it))->isGroup())
686 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
692 void ProjectList::slotCheckForEmptyQueue() {
693 if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
695 emit loadingIsOver();
696 } else QTimer::singleShot(500, this, SLOT(slotCheckForEmptyQueue()));
699 void ProjectList::requestClipThumbnail(const QString &id) {
700 m_thumbnailQueue.append(id);
701 if (m_thumbnailQueue.count() == 1) QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
704 void ProjectList::slotProcessNextThumbnail() {
705 if (m_thumbnailQueue.isEmpty()) {
708 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
711 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update) {
712 ProjectItem *item = getItemById(clipId);
713 if (item) slotRefreshClipThumbnail(item, update);
714 else slotProcessNextThumbnail();
717 void ProjectList::slotRefreshClipThumbnail(ProjectItem *item, bool update) {
719 if (!item->referencedClip()) return;
721 int width = (int)(height * m_render->dar());
722 DocClipBase *clip = item->referencedClip();
723 if (!clip) slotProcessNextThumbnail();
725 if (clip->clipType() == AUDIO) pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
726 else pix = item->referencedClip()->thumbProducer()->extractImage(item->referencedClip()->getClipThumbFrame(), width, height);
727 listView->blockSignals(true);
728 item->setIcon(0, pix);
729 listView->blockSignals(false);
730 m_doc->cachePixmap(item->getClipHash(), pix);
731 if (update) emit projectModified();
732 if (!m_thumbnailQueue.isEmpty()) QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
736 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace) {
737 ProjectItem *item = getItemById(clipId);
738 if (item && producer) {
739 listView->blockSignals(true);
740 item->setProperties(properties, metadata);
741 Q_ASSERT_X(item->referencedClip(), "void ProjectList::slotReplyGetFileProperties", QString("Item with groupName %1 does not have a clip associated").arg(item->groupName()).toLatin1());
742 if (replace) item->referencedClip()->setProducer(producer);
743 emit receivedClipDuration(clipId, item->clipMaxDuration());
744 listView->blockSignals(false);
745 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
746 if (!m_infoQueue.isEmpty()) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
747 else listView->setEnabled(true);
750 void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix) {
751 ProjectItem *item = getItemById(clipId);
753 listView->blockSignals(true);
754 item->setIcon(0, pix);
755 m_doc->cachePixmap(item->getClipHash(), pix);
756 listView->blockSignals(false);
760 ProjectItem *ProjectList::getItemById(const QString &id) {
762 QTreeWidgetItemIterator it(listView);
764 item = static_cast<ProjectItem *>(*it);
765 if (item->clipId() == id && item->clipType() != FOLDER)
772 ProjectItem *ProjectList::getFolderItemById(const QString &id) {
774 QTreeWidgetItemIterator it(listView);
776 item = static_cast<ProjectItem *>(*it);
777 if (item->clipId() == id && item->clipType() == FOLDER)
784 void ProjectList::slotSelectClip(const QString &ix) {
785 ProjectItem *clip = getItemById(ix);
787 listView->setCurrentItem(clip);
788 listView->scrollToItem(clip);
789 m_editAction->setEnabled(true);
790 m_deleteAction->setEnabled(true);
791 m_reloadAction->setEnabled(true);
792 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
793 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
794 m_openAction->setEnabled(true);
795 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
796 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
797 m_openAction->setEnabled(true);
798 } else m_openAction->setEnabled(false);
802 #include "projectlist.moc"