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 ***************************************************************************/
20 #include "projectlist.h"
21 #include "projectitem.h"
22 #include "addfoldercommand.h"
23 #include "kdenlivesettings.h"
24 #include "slideshowclip.h"
25 #include "ui_colorclip_ui.h"
26 #include "titlewidget.h"
27 #include "definitions.h"
28 #include "clipmanager.h"
29 #include "docclipbase.h"
30 #include "kdenlivedoc.h"
33 #include "projectlistview.h"
34 #include "editclipcommand.h"
35 #include "editfoldercommand.h"
41 #include <KFileDialog>
42 #include <KInputDialog>
43 #include <KMessageBox>
45 #include <nepomuk/global.h>
46 #include <nepomuk/resourcemanager.h>
47 //#include <nepomuk/tag.h>
49 #include <QMouseEvent>
50 #include <QStylePainter>
55 #include <QHeaderView>
57 ProjectList::ProjectList(QWidget *parent)
58 : 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)
61 listView = new ProjectListView(this);;
62 QVBoxLayout *layout = new QVBoxLayout;
63 layout->setContentsMargins(0, 0, 0, 0);
66 searchView = new KTreeWidgetSearchLine(this);
67 m_toolbar = new QToolBar("projectToolBar", this);
68 m_toolbar->addWidget(searchView);
70 m_addButton = new QToolButton(m_toolbar);
71 m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
72 m_toolbar->addWidget(m_addButton);
74 layout->addWidget(m_toolbar);
75 layout->addWidget(listView);
77 //m_toolbar->setEnabled(false);
79 searchView->setTreeWidget(listView);
81 connect(listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
82 connect(listView, SIGNAL(focusMonitor()), this, SLOT(slotClipSelected()));
83 connect(listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
84 connect(listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
85 connect(listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
86 connect(listView, SIGNAL(addClip(const QList <QUrl>, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &)));
87 connect(listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
88 connect(listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
90 ItemDelegate *listViewDelegate = new ItemDelegate(listView);
91 listView->setItemDelegate(listViewDelegate);
93 if (KdenliveSettings::activate_nepomuk()) {
94 Nepomuk::ResourceManager::instance()->init();
95 if (!Nepomuk::ResourceManager::instance()->initialized()) {
96 kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
97 KdenliveSettings::setActivate_nepomuk(false);
102 ProjectList::~ProjectList()
108 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
110 QList <QAction *> actions = addMenu->actions();
111 for (int i = 0; i < actions.count(); i++) {
112 if (actions.at(i)->data().toString() == "clip_properties") {
113 m_editAction = actions.at(i);
114 m_toolbar->addAction(m_editAction);
117 } else if (actions.at(i)->data().toString() == "delete_clip") {
118 m_deleteAction = actions.at(i);
119 m_toolbar->addAction(m_deleteAction);
122 } else if (actions.at(i)->data().toString() == "edit_clip") {
123 m_openAction = actions.at(i);
126 } else if (actions.at(i)->data().toString() == "reload_clip") {
127 m_reloadAction = actions.at(i);
133 QMenu *m = new QMenu();
134 m->addActions(actions);
135 m_addButton->setMenu(m);
136 m_addButton->setDefaultAction(defaultAction);
137 m_menu = new QMenu();
138 m_menu->addActions(addMenu->actions());
141 void ProjectList::setupGeneratorMenu(QMenu *addMenu)
143 if (!addMenu) return;
144 QMenu *menu = m_addButton->menu();
145 menu->addMenu(addMenu);
146 m_addButton->setMenu(menu);
148 m_menu->addMenu(addMenu);
149 if (addMenu->isEmpty()) addMenu->setEnabled(false);
150 m_menu->addAction(m_reloadAction);
151 m_menu->addAction(m_editAction);
152 m_menu->addAction(m_openAction);
153 m_menu->addAction(m_deleteAction);
154 m_menu->insertSeparator(m_deleteAction);
158 QByteArray ProjectList::headerInfo()
160 return listView->header()->saveState();
163 void ProjectList::setHeaderInfo(const QByteArray &state)
165 listView->header()->restoreState(state);
168 void ProjectList::slotEditClip()
170 ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
171 if (item && !item->isGroup()) {
172 emit clipSelected(item->referencedClip());
173 emit showClipProperties(item->referencedClip());
177 void ProjectList::slotOpenClip()
179 ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
180 if (item && !item->isGroup()) {
181 if (item->clipType() == IMAGE) {
182 if (KdenliveSettings::defaultimageapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open images in the Settings dialog"));
183 else QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
185 if (item->clipType() == AUDIO) {
186 if (KdenliveSettings::defaultaudioapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open audio files in the Settings dialog"));
187 else QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
192 void ProjectList::slotReloadClip()
194 ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
195 if (item && !item->isGroup()) {
196 if (item->clipType() == IMAGE) {
197 item->referencedClip()->producer()->set("force_reload", 1);
199 emit getFileProperties(item->toXml(), item->clipId(), false);
203 void ProjectList::setRenderer(Render *projectRender)
205 m_render = projectRender;
206 listView->setIconSize(QSize(40 * m_render->dar(), 40));
209 void ProjectList::slotClipSelected()
211 if (listView->currentItem()) {
212 ProjectItem *clip = static_cast <ProjectItem*>(listView->currentItem());
213 if (!clip->isGroup()) {
214 m_selectedItem = clip;
215 emit clipSelected(clip->referencedClip());
217 m_editAction->setEnabled(true);
218 m_deleteAction->setEnabled(true);
219 m_reloadAction->setEnabled(true);
220 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
221 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
222 m_openAction->setEnabled(true);
223 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
224 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
225 m_openAction->setEnabled(true);
226 } else m_openAction->setEnabled(false);
228 emit clipSelected(NULL);
229 m_editAction->setEnabled(false);
230 m_deleteAction->setEnabled(false);
231 m_openAction->setEnabled(false);
232 m_reloadAction->setEnabled(false);
236 void ProjectList::slotPauseMonitor()
238 if (m_render) m_render->pause();
241 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
243 ProjectItem *item = getItemById(id);
245 slotUpdateClipProperties(item, properties);
246 if (properties.contains("colour") || properties.contains("resource") || properties.contains("xmldata")) slotRefreshClipThumbnail(item);
247 if (properties.contains("out")) item->changeDuration(properties.value("out").toInt());
251 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
254 if (!clip->isGroup()) clip->setProperties(properties);
255 if (properties.contains("name")) {
256 listView->blockSignals(true);
257 clip->setText(1, properties.value("name"));
258 listView->blockSignals(false);
259 emit clipNameChanged(clip->clipId(), properties.value("name"));
261 if (properties.contains("description")) {
262 CLIPTYPE type = clip->clipType();
263 listView->blockSignals(true);
264 clip->setText(2, properties.value("description"));
265 listView->blockSignals(false);
266 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
267 // Use Nepomuk system to store clip description
268 Nepomuk::Resource f(clip->clipUrl().path());
269 f.setDescription(properties.value("description"));
271 emit projectModified();
275 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
277 ProjectItem *clip = static_cast <ProjectItem*>(item);
279 if (clip->referencedClip()) {
280 QMap <QString, QString> oldprops;
281 QMap <QString, QString> newprops;
282 oldprops["description"] = clip->referencedClip()->getProperty("description");
283 newprops["description"] = item->text(2);
284 slotUpdateClipProperties(clip, newprops);
285 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
286 m_commandStack->push(command);
288 } else if (column == 1) {
289 if (clip->isGroup()) {
290 editFolder(item->text(1), clip->groupName(), clip->clipId());
291 clip->setGroupName(item->text(1));
292 m_doc->clipManager()->addFolder(clip->clipId(), item->text(1));
293 const int children = item->childCount();
294 for (int i = 0; i < children; i++) {
295 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
296 child->setProperty("groupname", item->text(1));
299 if (clip->referencedClip()) {
300 QMap <QString, QString> oldprops;
301 QMap <QString, QString> newprops;
302 oldprops["name"] = clip->referencedClip()->getProperty("name");
303 newprops["name"] = item->text(1);
304 slotUpdateClipProperties(clip, newprops);
305 emit projectModified();
306 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
307 m_commandStack->push(command);
313 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
319 m_editAction->setEnabled(enable);
320 m_deleteAction->setEnabled(enable);
321 m_reloadAction->setEnabled(enable);
323 ProjectItem *clip = static_cast <ProjectItem*>(item);
324 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
325 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
326 m_openAction->setEnabled(true);
327 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
328 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
329 m_openAction->setEnabled(true);
330 } else m_openAction->setEnabled(false);
331 } else m_openAction->setEnabled(false);
335 void ProjectList::slotRemoveClip()
337 if (!listView->currentItem()) return;
339 QMap <QString, QString> folderids;
340 QList<QTreeWidgetItem *> selected = listView->selectedItems();
342 for (int i = 0; i < selected.count(); i++) {
343 item = static_cast <ProjectItem *>(selected.at(i));
344 if (item->isGroup()) folderids[item->groupName()] = item->clipId();
345 else ids << item->clipId();
346 if (item->numReferences() > 0) {
347 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;
348 } else if (item->isGroup() && item->childCount() > 0) {
349 int children = item->childCount();
350 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;
351 for (int i = 0; i < children; ++i) {
352 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
353 ids << child->clipId();
357 if (!ids.isEmpty()) m_doc->deleteProjectClip(ids);
358 if (!folderids.isEmpty()) deleteProjectFolder(folderids);
359 if (listView->topLevelItemCount() == 0) {
360 m_editAction->setEnabled(false);
361 m_deleteAction->setEnabled(false);
362 m_openAction->setEnabled(false);
363 m_reloadAction->setEnabled(false);
367 void ProjectList::selectItemById(const QString &clipId)
369 ProjectItem *item = getItemById(clipId);
370 if (item) listView->setCurrentItem(item);
374 void ProjectList::slotDeleteClip(const QString &clipId)
376 ProjectItem *item = getItemById(clipId);
378 kDebug() << "/// Cannot find clip to delete";
385 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
387 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
388 m_commandStack->push(command);
389 m_doc->setModified(true);
392 void ProjectList::slotAddFolder()
394 AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
395 m_commandStack->push(command);
398 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
401 ProjectItem *item = getFolderItemById(clipId);
403 m_doc->clipManager()->deleteFolder(clipId);
408 ProjectItem *item = getFolderItemById(clipId);
409 QTreeWidgetItemIterator it(listView);
411 listView->blockSignals(true);
412 item->setGroupName(foldername);
413 listView->blockSignals(false);
414 m_doc->clipManager()->addFolder(clipId, foldername);
415 const int children = item->childCount();
416 for (int i = 0; i < children; i++) {
417 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
418 child->setProperty("groupname", foldername);
423 text << QString() << foldername;
424 listView->blockSignals(true);
425 (void) new ProjectItem(listView, text, clipId);
426 m_doc->clipManager()->addFolder(clipId, foldername);
427 listView->blockSignals(false);
434 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
436 QMapIterator<QString, QString> i(map);
437 QUndoCommand *delCommand = new QUndoCommand();
438 delCommand->setText(i18n("Delete Folder"));
439 while (i.hasNext()) {
441 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
443 m_commandStack->push(delCommand);
444 m_doc->setModified(true);
447 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
449 if (getProperties) listView->setEnabled(false);
450 listView->blockSignals(true);
451 const QString parent = clip->getProperty("groupid");
452 kDebug() << "Adding clip with groupid: " << parent;
453 ProjectItem *item = NULL;
454 if (!parent.isEmpty()) {
455 ProjectItem *parentitem = getFolderItemById(parent);
458 QString groupName = clip->getProperty("groupname");
459 //kDebug() << "Adding clip to new group: " << groupName;
460 if (groupName.isEmpty()) groupName = i18n("Folder");
461 text << QString() << groupName;
462 parentitem = new ProjectItem(listView, text, parent);
464 //kDebug() << "Adding clip to existing group: " << parentitem->groupName();
466 if (parentitem) item = new ProjectItem(parentitem, clip);
468 if (item == NULL) item = new ProjectItem(listView, clip);
470 KUrl url = clip->fileURL();
471 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
472 // if file has Nepomuk comment, use it
473 Nepomuk::Resource f(url.path());
474 QString annotation = f.description();
475 if (!annotation.isEmpty()) item->setText(2, annotation);
476 item->setText(3, QString::number(f.rating()));
478 listView->blockSignals(false);
481 void ProjectList::slotResetProjectList()
484 emit clipSelected(NULL);
485 m_thumbnailQueue.clear();
490 void ProjectList::requestClipInfo(const QDomElement xml, const QString id)
492 kDebug() << " PRG LISTĀ REQUEST CLP INFO: " << id;
493 m_infoQueue.insert(id, xml);
494 listView->setEnabled(false);
495 if (m_infoQueue.count() == 1) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
498 void ProjectList::slotProcessNextClipInQueue()
500 if (m_infoQueue.isEmpty()) {
501 listView->setEnabled(true);
504 QMap<QString, QDomElement>::const_iterator i = m_infoQueue.constBegin();
505 if (i != m_infoQueue.constEnd()) {
506 const QDomElement dom = i.value();
507 const QString id = i.key();
508 m_infoQueue.remove(i.key());
509 emit getFileProperties(dom, id, true);
511 if (m_infoQueue.isEmpty()) listView->setEnabled(true);
514 void ProjectList::slotUpdateClip(const QString &id)
516 ProjectItem *item = getItemById(id);
517 listView->blockSignals(true);
518 if (item) item->setData(1, UsageRole, QString::number(item->numReferences()));
519 listView->blockSignals(false);
522 void ProjectList::updateAllClips()
524 QTreeWidgetItemIterator it(listView);
526 ProjectItem *item = static_cast <ProjectItem *>(*it);
527 if (!item->isGroup()) {
528 if (item->referencedClip()->producer() == NULL) {
529 DocClipBase *clip = item->referencedClip();
530 if (clip->clipType() == TEXT && !QFile::exists(clip->fileURL().path())) {
531 // regenerate text clip image if required
532 TitleWidget *dia_ui = new TitleWidget(KUrl(), QString(), m_render, this);
534 doc.setContent(clip->getProperty("xmldata"));
536 QImage pix = dia_ui->renderedPixmap();
537 pix.save(clip->fileURL().path());
540 requestClipInfo(clip->toXML(), clip->getId());
542 QString cachedPixmap = m_doc->projectFolder().path() + "/thumbs/" + item->getClipHash() + ".png";
543 if (QFile::exists(cachedPixmap)) {
544 //kDebug()<<"// USING CACHED PIX: "<<cachedPixmap;
545 listView->blockSignals(true);
546 item->setIcon(0, QPixmap(cachedPixmap));
547 listView->blockSignals(false);
548 } else requestClipThumbnail(item->clipId());
550 if (item->data(1, DurationRole).toString().isEmpty()) {
551 listView->blockSignals(true);
552 item->changeDuration(item->referencedClip()->producer()->get_playtime());
553 listView->blockSignals(false);
556 listView->blockSignals(true);
557 item->setData(1, UsageRole, QString::number(item->numReferences()));
558 listView->blockSignals(false);
559 qApp->processEvents();
563 QTimer::singleShot(500, this, SLOT(slotCheckForEmptyQueue()));
566 void ProjectList::slotAddClip(const QList <QUrl> givenList, QString group)
568 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
570 if (givenList.isEmpty()) {
571 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-tga 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 video/x-matroska audio/x-matroska", this);
573 for (int i = 0; i < givenList.count(); i++)
574 list << givenList.at(i);
576 if (list.isEmpty()) return;
579 if (group.isEmpty()) {
580 ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
581 if (item && !item->isGroup()) {
582 while (item->parent()) {
583 item = static_cast <ProjectItem*>(item->parent());
584 if (item->isGroup()) break;
587 if (item && item->isGroup()) {
588 group = item->groupName();
589 groupId = item->clipId();
592 m_doc->slotAddClipList(list, group, groupId);
595 void ProjectList::slotRemoveInvalidClip(const QString &id)
597 ProjectItem *item = getItemById(id);
599 const QString path = item->referencedClip()->fileURL().path();
600 if (!path.isEmpty()) KMessageBox::sorry(this, i18n("Clip <b>%1</b><br>is invalid, will be removed from project.", path));
603 m_doc->deleteProjectClip(ids);
605 if (!m_infoQueue.isEmpty()) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
606 else listView->setEnabled(true);
609 void ProjectList::slotAddColorClip()
611 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
612 QDialog *dia = new QDialog(this);
613 Ui::ColorClip_UI *dia_ui = new Ui::ColorClip_UI();
614 dia_ui->setupUi(dia);
615 dia_ui->clip_name->setText(i18n("Color Clip"));
616 dia_ui->clip_duration->setText(KdenliveSettings::color_duration());
617 if (dia->exec() == QDialog::Accepted) {
618 QString color = dia_ui->clip_color->color().name();
619 color = color.replace(0, 1, "0x") + "ff";
623 ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
624 if (item && !item->isGroup()) {
625 while (item->parent()) {
626 item = static_cast <ProjectItem*>(item->parent());
627 if (item->isGroup()) break;
630 if (item && item->isGroup()) {
631 group = item->groupName();
632 groupId = item->clipId();
635 m_doc->clipManager()->slotAddColorClipFile(dia_ui->clip_name->text(), color, dia_ui->clip_duration->text(), group, groupId);
636 m_doc->setModified(true);
643 void ProjectList::slotAddSlideshowClip()
645 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
646 SlideshowClip *dia = new SlideshowClip(this);
648 if (dia->exec() == QDialog::Accepted) {
652 ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
653 if (item && !item->isGroup()) {
654 while (item->parent()) {
655 item = static_cast <ProjectItem*>(item->parent());
656 if (item->isGroup()) break;
659 if (item && item->isGroup()) {
660 group = item->groupName();
661 groupId = item->clipId();
664 m_doc->clipManager()->slotAddSlideshowClipFile(dia->clipName(), dia->selectedPath(), dia->imageCount(), dia->clipDuration(), dia->loop(), dia->fade(), dia->lumaDuration(), dia->lumaFile(), dia->softness(), group, groupId);
665 m_doc->setModified(true);
670 void ProjectList::slotAddTitleClip()
674 ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
675 if (item && !item->isGroup()) {
676 while (item->parent()) {
677 item = static_cast <ProjectItem*>(item->parent());
678 if (item->isGroup()) break;
681 if (item && item->isGroup()) {
682 group = item->groupName();
683 groupId = item->clipId();
686 m_doc->slotCreateTextClip(group, groupId);
689 void ProjectList::setDocument(KdenliveDoc *doc)
691 listView->blockSignals(true);
693 emit clipSelected(NULL);
694 m_thumbnailQueue.clear();
697 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
698 QMapIterator<QString, QString> f(flist);
699 while (f.hasNext()) {
701 (void) new ProjectItem(listView, QStringList() << QString() << f.value(), f.key());
704 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
705 for (int i = 0; i < list.count(); i++) {
706 slotAddClip(list.at(i), false);
710 m_timecode = doc->timecode();
711 m_commandStack = doc->commandStack();
713 QTreeWidgetItem *first = listView->topLevelItem(0);
714 if (first) listView->setCurrentItem(first);
715 listView->blockSignals(false);
716 m_toolbar->setEnabled(true);
719 QDomElement ProjectList::producersList()
722 QDomElement prods = doc.createElement("producerlist");
723 doc.appendChild(prods);
724 kDebug() << "//////////// PRO LISTĀ BUILD PRDSLIST ";
725 QTreeWidgetItemIterator it(listView);
727 if (!((ProjectItem *)(*it))->isGroup())
728 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
734 void ProjectList::slotCheckForEmptyQueue()
736 if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
738 emit loadingIsOver();
739 } else QTimer::singleShot(500, this, SLOT(slotCheckForEmptyQueue()));
742 void ProjectList::requestClipThumbnail(const QString &id)
744 m_thumbnailQueue.append(id);
745 if (m_thumbnailQueue.count() == 1) QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
748 void ProjectList::slotProcessNextThumbnail()
750 if (m_thumbnailQueue.isEmpty()) {
753 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
756 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
758 ProjectItem *item = getItemById(clipId);
759 if (item) slotRefreshClipThumbnail(item, update);
760 else slotProcessNextThumbnail();
763 void ProjectList::slotRefreshClipThumbnail(ProjectItem *item, bool update)
766 if (!item->referencedClip()) return;
768 int width = (int)(height * m_render->dar());
769 DocClipBase *clip = item->referencedClip();
770 if (!clip) slotProcessNextThumbnail();
772 if (clip->clipType() == AUDIO) pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
773 else pix = item->referencedClip()->thumbProducer()->extractImage(item->referencedClip()->getClipThumbFrame(), width, height);
774 listView->blockSignals(true);
775 item->setIcon(0, pix);
776 listView->blockSignals(false);
777 m_doc->cachePixmap(item->getClipHash(), pix);
778 if (update) emit projectModified();
779 if (!m_thumbnailQueue.isEmpty()) QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
783 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace)
785 ProjectItem *item = getItemById(clipId);
786 if (item && producer) {
787 listView->blockSignals(true);
788 item->setProperties(properties, metadata);
789 Q_ASSERT_X(item->referencedClip(), "void ProjectList::slotReplyGetFileProperties", QString("Item with groupName %1 does not have a clip associated").arg(item->groupName()).toLatin1());
790 if (replace) item->referencedClip()->setProducer(producer);
791 emit receivedClipDuration(clipId, item->clipMaxDuration());
792 listView->blockSignals(false);
793 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
794 if (!m_infoQueue.isEmpty()) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
795 else listView->setEnabled(true);
798 void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
800 ProjectItem *item = getItemById(clipId);
802 listView->blockSignals(true);
803 item->setIcon(0, pix);
804 m_doc->cachePixmap(item->getClipHash(), pix);
805 listView->blockSignals(false);
809 ProjectItem *ProjectList::getItemById(const QString &id)
812 QTreeWidgetItemIterator it(listView);
814 item = static_cast<ProjectItem *>(*it);
815 if (item->clipId() == id && item->clipType() != FOLDER)
822 ProjectItem *ProjectList::getFolderItemById(const QString &id)
825 QTreeWidgetItemIterator it(listView);
827 item = static_cast<ProjectItem *>(*it);
828 if (item->clipId() == id && item->clipType() == FOLDER)
835 void ProjectList::slotSelectClip(const QString &ix)
837 ProjectItem *clip = getItemById(ix);
839 listView->setCurrentItem(clip);
840 listView->scrollToItem(clip);
841 m_editAction->setEnabled(true);
842 m_deleteAction->setEnabled(true);
843 m_reloadAction->setEnabled(true);
844 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
845 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
846 m_openAction->setEnabled(true);
847 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
848 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
849 m_openAction->setEnabled(true);
850 } else m_openAction->setEnabled(false);
854 #include "projectlist.moc"