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) {
60 QWidget *vbox = new QWidget;
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(KUrl, const QString &)), this, SLOT(slotAddClip(KUrl, 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() {
107 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction) {
108 QList <QAction *> actions = addMenu->actions();
109 for (int i = 0; i < actions.count(); i++) {
110 if (actions.at(i)->data().toString() == "clip_properties") {
111 m_editAction = actions.at(i);
112 m_toolbar->addAction(m_editAction);
115 } else if (actions.at(i)->data().toString() == "delete_clip") {
116 m_deleteAction = actions.at(i);
117 m_toolbar->addAction(m_deleteAction);
120 } else if (actions.at(i)->data().toString() == "edit_clip") {
121 m_openAction = actions.at(i);
124 } else if (actions.at(i)->data().toString() == "reload_clip") {
125 m_reloadAction = actions.at(i);
131 QMenu *m = new QMenu();
132 m->addActions(actions);
133 m_addButton->setMenu(m);
134 m_addButton->setDefaultAction(defaultAction);
135 m_menu = new QMenu();
136 m_menu->addActions(addMenu->actions());
139 void ProjectList::setupGeneratorMenu(QMenu *addMenu) {
140 if (!addMenu) return;
141 QMenu *menu = m_addButton->menu();
142 menu->addMenu(addMenu);
143 m_addButton->setMenu(menu);
145 m_menu->addMenu(addMenu);
146 if (addMenu->isEmpty()) addMenu->setEnabled(false);
147 m_menu->addAction(m_reloadAction);
148 m_menu->addAction(m_editAction);
149 m_menu->addAction(m_openAction);
150 m_menu->addAction(m_deleteAction);
151 m_menu->insertSeparator(m_deleteAction);
155 QByteArray ProjectList::headerInfo() {
156 return listView->header()->saveState();
159 void ProjectList::setHeaderInfo(const QByteArray &state) {
160 listView->header()->restoreState(state);
163 void ProjectList::slotEditClip() {
164 ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
165 if (item && !item->isGroup()) {
166 emit clipSelected(item->referencedClip());
167 emit showClipProperties(item->referencedClip());
171 void ProjectList::slotOpenClip() {
172 ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
173 if (item && !item->isGroup()) {
174 if (item->clipType() == IMAGE) {
175 if (KdenliveSettings::defaultimageapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open images in the Settings dialog"));
176 else QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
178 if (item->clipType() == AUDIO) {
179 if (KdenliveSettings::defaultaudioapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open audio files in the Settings dialog"));
180 else QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
185 void ProjectList::slotReloadClip() {
186 ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
187 if (item && !item->isGroup()) {
188 if (item->clipType() == IMAGE) {
189 item->referencedClip()->producer()->set("force_reload", 1);
191 emit getFileProperties(item->toXml(), item->clipId(), false);
195 void ProjectList::setRenderer(Render *projectRender) {
196 m_render = projectRender;
197 listView->setIconSize(QSize(40 * m_render->dar(), 40));
200 void ProjectList::slotClipSelected() {
201 if (listView->currentItem()) {
202 ProjectItem *clip = static_cast <ProjectItem*>(listView->currentItem());
203 if (!clip->isGroup()) {
204 m_selectedItem = clip;
205 emit clipSelected(clip->referencedClip());
207 m_editAction->setEnabled(true);
208 m_deleteAction->setEnabled(true);
209 m_reloadAction->setEnabled(true);
210 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
211 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
212 m_openAction->setEnabled(true);
213 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
214 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
215 m_openAction->setEnabled(true);
216 } else m_openAction->setEnabled(false);
218 emit clipSelected(NULL);
219 m_editAction->setEnabled(false);
220 m_deleteAction->setEnabled(false);
221 m_openAction->setEnabled(false);
222 m_reloadAction->setEnabled(false);
226 void ProjectList::slotPauseMonitor() {
227 if (m_render) m_render->pause();
230 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties) {
231 ProjectItem *item = getItemById(id);
233 slotUpdateClipProperties(item, properties);
234 if (properties.contains("colour") || properties.contains("resource") || properties.contains("xmldata")) slotRefreshClipThumbnail(item);
235 if (properties.contains("out")) item->changeDuration(properties.value("out").toInt());
239 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties) {
241 if (!clip->isGroup()) clip->setProperties(properties);
242 if (properties.contains("name")) {
243 listView->blockSignals(true);
244 clip->setText(1, properties.value("name"));
245 listView->blockSignals(false);
246 emit clipNameChanged(clip->clipId(), properties.value("name"));
248 if (properties.contains("description")) {
249 CLIPTYPE type = clip->clipType();
250 listView->blockSignals(true);
251 clip->setText(2, properties.value("description"));
252 listView->blockSignals(false);
253 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
254 // Use Nepomuk system to store clip description
255 Nepomuk::Resource f(clip->clipUrl().path());
256 f.setDescription(properties.value("description"));
258 emit projectModified();
262 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column) {
263 ProjectItem *clip = static_cast <ProjectItem*>(item);
265 if (clip->referencedClip()) {
266 QMap <QString, QString> oldprops;
267 QMap <QString, QString> newprops;
268 oldprops["description"] = clip->referencedClip()->getProperty("description");
269 newprops["description"] = item->text(2);
270 slotUpdateClipProperties(clip, newprops);
271 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
272 m_commandStack->push(command);
274 } else if (column == 1) {
275 if (clip->isGroup()) {
276 editFolder(item->text(1), clip->groupName(), clip->clipId());
277 clip->setGroupName(item->text(1));
278 m_doc->clipManager()->addFolder(clip->clipId(), item->text(1));
279 const int children = item->childCount();
280 for (int i = 0; i < children; i++) {
281 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
282 child->setProperty("groupname", item->text(1));
285 if (clip->referencedClip()) {
286 QMap <QString, QString> oldprops;
287 QMap <QString, QString> newprops;
288 oldprops["name"] = clip->referencedClip()->getProperty("name");
289 newprops["name"] = item->text(1);
290 slotUpdateClipProperties(clip, newprops);
291 emit projectModified();
292 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
293 m_commandStack->push(command);
299 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item) {
304 m_editAction->setEnabled(enable);
305 m_deleteAction->setEnabled(enable);
306 m_reloadAction->setEnabled(enable);
308 ProjectItem *clip = static_cast <ProjectItem*>(item);
309 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
310 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
311 m_openAction->setEnabled(true);
312 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
313 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
314 m_openAction->setEnabled(true);
315 } else m_openAction->setEnabled(false);
316 } else m_openAction->setEnabled(false);
320 void ProjectList::slotRemoveClip() {
321 if (!listView->currentItem()) return;
323 QMap <QString, QString> folderids;
324 QList<QTreeWidgetItem *> selected = listView->selectedItems();
326 for (int i = 0; i < selected.count(); i++) {
327 item = static_cast <ProjectItem *>(selected.at(i));
328 if (item->isGroup()) folderids[item->groupName()] = item->clipId();
329 else ids << item->clipId();
330 if (item->numReferences() > 0) {
331 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;
332 } else if (item->isGroup() && item->childCount() > 0) {
333 int children = item->childCount();
334 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;
335 for (int i = 0; i < children; ++i) {
336 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
337 ids << child->clipId();
341 if (!ids.isEmpty()) m_doc->deleteProjectClip(ids);
342 if (!folderids.isEmpty()) deleteProjectFolder(folderids);
343 if (listView->topLevelItemCount() == 0) {
344 m_editAction->setEnabled(false);
345 m_deleteAction->setEnabled(false);
346 m_openAction->setEnabled(false);
347 m_reloadAction->setEnabled(false);
351 void ProjectList::selectItemById(const QString &clipId) {
352 ProjectItem *item = getItemById(clipId);
353 if (item) listView->setCurrentItem(item);
357 void ProjectList::slotDeleteClip(const QString &clipId) {
358 ProjectItem *item = getItemById(clipId);
360 kDebug()<<"/// Cannot find clip to delete";
367 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId) {
368 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
369 m_commandStack->push(command);
370 m_doc->setModified(true);
373 void ProjectList::slotAddFolder() {
374 AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
375 m_commandStack->push(command);
378 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit) {
380 ProjectItem *item = getFolderItemById(clipId);
382 m_doc->clipManager()->deleteFolder(clipId);
387 ProjectItem *item = getFolderItemById(clipId);
388 QTreeWidgetItemIterator it(listView);
390 listView->blockSignals(true);
391 item->setGroupName(foldername);
392 listView->blockSignals(false);
393 m_doc->clipManager()->addFolder(clipId, foldername);
394 const int children = item->childCount();
395 for (int i = 0; i < children; i++) {
396 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
397 child->setProperty("groupname", foldername);
402 text << QString() << foldername;
403 listView->blockSignals(true);
404 (void) new ProjectItem(listView, text, clipId);
405 m_doc->clipManager()->addFolder(clipId, foldername);
406 listView->blockSignals(false);
413 void ProjectList::deleteProjectFolder(QMap <QString, QString> map) {
414 QMapIterator<QString, QString> i(map);
415 QUndoCommand *delCommand = new QUndoCommand();
416 delCommand->setText(i18n("Delete Folder"));
417 while (i.hasNext()) {
419 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
421 m_commandStack->push(delCommand);
422 m_doc->setModified(true);
425 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties) {
426 if (getProperties) listView->setEnabled(false);
427 listView->blockSignals(true);
428 const QString parent = clip->getProperty("groupid");
429 kDebug() << "Adding clip with groupid: " << parent;
430 ProjectItem *item = NULL;
431 if (!parent.isEmpty()) {
432 ProjectItem *parentitem = getFolderItemById(parent);
435 QString groupName = clip->getProperty("groupname");
436 //kDebug() << "Adding clip to new group: " << groupName;
437 if (groupName.isEmpty()) groupName = i18n("Folder");
438 text << QString() << groupName;
439 parentitem = new ProjectItem(listView, text, parent);
441 //kDebug() << "Adding clip to existing group: " << parentitem->groupName();
443 if (parentitem) item = new ProjectItem(parentitem, clip);
445 if (item == NULL) item = new ProjectItem(listView, clip);
447 KUrl url = clip->fileURL();
448 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
449 // if file has Nepomuk comment, use it
450 Nepomuk::Resource f(url.path());
451 QString annotation = f.description();
452 if (!annotation.isEmpty()) item->setText(2, annotation);
453 item->setText(3, QString::number(f.rating()));
455 listView->blockSignals(false);
458 void ProjectList::slotResetProjectList() {
460 emit clipSelected(NULL);
461 m_thumbnailQueue.clear();
466 void ProjectList::requestClipInfo(const QDomElement xml, const QString id) {
467 kDebug() << " PRG LISTĀ REQUEST CLP INFO: " << id;
468 m_infoQueue.insert(id, xml);
469 listView->setEnabled(false);
470 if (m_infoQueue.count() == 1) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
473 void ProjectList::slotProcessNextClipInQueue() {
474 if (m_infoQueue.isEmpty()) {
475 listView->setEnabled(true);
478 QMap<QString, QDomElement>::const_iterator i = m_infoQueue.constBegin();
479 if (i != m_infoQueue.constEnd()) {
480 const QDomElement dom = i.value();
481 const QString id = i.key();
482 m_infoQueue.remove(i.key());
483 emit getFileProperties(dom, id, true);
485 if (m_infoQueue.isEmpty()) listView->setEnabled(true);
488 void ProjectList::slotUpdateClip(const QString &id) {
489 ProjectItem *item = getItemById(id);
490 listView->blockSignals(true);
491 if (item) item->setData(1, UsageRole, QString::number(item->numReferences()));
492 listView->blockSignals(false);
495 void ProjectList::updateAllClips() {
496 QTreeWidgetItemIterator it(listView);
498 ProjectItem *item = static_cast <ProjectItem *>(*it);
499 if (!item->isGroup()) {
500 if (item->referencedClip()->producer() == NULL) {
501 DocClipBase *clip = item->referencedClip();
502 if (clip->clipType() == TEXT && !QFile::exists(clip->fileURL().path())) {
503 // regenerate text clip image if required
504 TitleWidget *dia_ui = new TitleWidget(KUrl(), QString(), m_render, this);
506 doc.setContent(clip->getProperty("xmldata"));
508 QImage pix = dia_ui->renderedPixmap();
509 pix.save(clip->fileURL().path());
512 requestClipInfo(clip->toXML(), clip->getId());
514 QString cachedPixmap = m_doc->projectFolder().path() + "/thumbs/" + item->getClipHash() + ".png";
515 if (QFile::exists(cachedPixmap)) {
516 //kDebug()<<"// USING CACHED PIX: "<<cachedPixmap;
517 listView->blockSignals(true);
518 item->setIcon(0, QPixmap(cachedPixmap));
519 listView->blockSignals(false);
520 } else requestClipThumbnail(item->clipId());
521 listView->blockSignals(true);
522 item->changeDuration(item->referencedClip()->producer()->get_playtime());
523 listView->blockSignals(false);
525 listView->blockSignals(true);
526 item->setData(1, UsageRole, QString::number(item->numReferences()));
527 listView->blockSignals(false);
528 qApp->processEvents();
532 QTimer::singleShot(500, this, SLOT(slotCheckForEmptyQueue()));
535 void ProjectList::slotAddClip(KUrl givenUrl, QString group) {
536 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
538 if (givenUrl.isEmpty()) {
539 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", this);
540 } else list.append(givenUrl);
541 if (list.isEmpty()) return;
544 if (group.isEmpty()) {
545 ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
546 if (item && !item->isGroup()) {
547 while (item->parent()) {
548 item = static_cast <ProjectItem*>(item->parent());
549 if (item->isGroup()) break;
552 if (item && item->isGroup()) {
553 group = item->groupName();
554 groupId = item->clipId();
557 m_doc->slotAddClipList(list, group, groupId);
560 void ProjectList::slotRemoveInvalidClip(const QString &id) {
561 ProjectItem *item = getItemById(id);
563 const QString path = item->referencedClip()->fileURL().path();
564 if (!path.isEmpty()) KMessageBox::sorry(this, i18n("Clip <b>%1</b><br>is invalid, will be removed from project.", path));
567 m_doc->deleteProjectClip(ids);
569 if (!m_infoQueue.isEmpty()) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
570 else listView->setEnabled(true);
573 void ProjectList::slotAddColorClip() {
574 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
575 QDialog *dia = new QDialog(this);
576 Ui::ColorClip_UI *dia_ui = new Ui::ColorClip_UI();
577 dia_ui->setupUi(dia);
578 dia_ui->clip_name->setText(i18n("Color Clip"));
579 dia_ui->clip_duration->setText(KdenliveSettings::color_duration());
580 if (dia->exec() == QDialog::Accepted) {
581 QString color = dia_ui->clip_color->color().name();
582 color = color.replace(0, 1, "0x") + "ff";
586 ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
587 if (item && !item->isGroup()) {
588 while (item->parent()) {
589 item = static_cast <ProjectItem*>(item->parent());
590 if (item->isGroup()) break;
593 if (item && item->isGroup()) {
594 group = item->groupName();
595 groupId = item->clipId();
598 m_doc->clipManager()->slotAddColorClipFile(dia_ui->clip_name->text(), color, dia_ui->clip_duration->text(), group, groupId);
599 m_doc->setModified(true);
606 void ProjectList::slotAddSlideshowClip() {
607 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
608 SlideshowClip *dia = new SlideshowClip(this);
610 if (dia->exec() == QDialog::Accepted) {
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->clipManager()->slotAddSlideshowClipFile(dia->clipName(), dia->selectedPath(), dia->imageCount(), dia->clipDuration(), dia->loop(), dia->fade(), dia->lumaDuration(), dia->lumaFile(), dia->softness(), group, groupId);
627 m_doc->setModified(true);
632 void ProjectList::slotAddTitleClip() {
635 ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
636 if (item && !item->isGroup()) {
637 while (item->parent()) {
638 item = static_cast <ProjectItem*>(item->parent());
639 if (item->isGroup()) break;
642 if (item && item->isGroup()) {
643 group = item->groupName();
644 groupId = item->clipId();
647 m_doc->slotCreateTextClip(group, groupId);
650 void ProjectList::setDocument(KdenliveDoc *doc) {
651 listView->blockSignals(true);
653 emit clipSelected(NULL);
654 m_thumbnailQueue.clear();
657 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
658 QMapIterator<QString, QString> f(flist);
659 while (f.hasNext()) {
661 (void) new ProjectItem(listView, QStringList() << QString() << f.value(), f.key());
664 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
665 for (int i = 0; i < list.count(); i++) {
666 slotAddClip(list.at(i), false);
670 m_timecode = doc->timecode();
671 m_commandStack = doc->commandStack();
673 QTreeWidgetItem *first = listView->topLevelItem(0);
674 if (first) listView->setCurrentItem(first);
675 listView->blockSignals(false);
676 m_toolbar->setEnabled(true);
679 QDomElement ProjectList::producersList() {
681 QDomElement prods = doc.createElement("producerlist");
682 doc.appendChild(prods);
683 kDebug() << "//////////// PRO LISTĀ BUILD PRDSLIST ";
684 QTreeWidgetItemIterator it(listView);
686 if (!((ProjectItem *)(*it))->isGroup())
687 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
693 void ProjectList::slotCheckForEmptyQueue() {
694 if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
696 emit loadingIsOver();
697 } else QTimer::singleShot(500, this, SLOT(slotCheckForEmptyQueue()));
700 void ProjectList::requestClipThumbnail(const QString &id) {
701 m_thumbnailQueue.append(id);
702 if (m_thumbnailQueue.count() == 1) QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
705 void ProjectList::slotProcessNextThumbnail() {
706 if (m_thumbnailQueue.isEmpty()) {
709 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
712 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update) {
713 ProjectItem *item = getItemById(clipId);
714 if (item) slotRefreshClipThumbnail(item, update);
715 else slotProcessNextThumbnail();
718 void ProjectList::slotRefreshClipThumbnail(ProjectItem *item, bool update) {
720 if (!item->referencedClip()) return;
722 int width = (int)(height * m_render->dar());
723 DocClipBase *clip = item->referencedClip();
724 if (!clip) slotProcessNextThumbnail();
726 if (clip->clipType() == AUDIO) pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
727 else pix = item->referencedClip()->thumbProducer()->extractImage(item->referencedClip()->getClipThumbFrame(), width, height);
728 listView->blockSignals(true);
729 item->setIcon(0, pix);
730 listView->blockSignals(false);
731 m_doc->cachePixmap(item->getClipHash(), pix);
732 if (update) emit projectModified();
733 if (!m_thumbnailQueue.isEmpty()) QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
737 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace) {
738 ProjectItem *item = getItemById(clipId);
739 if (item && producer) {
740 listView->blockSignals(true);
741 item->setProperties(properties, metadata);
742 Q_ASSERT_X(item->referencedClip(), "void ProjectList::slotReplyGetFileProperties", QString("Item with groupName %1 does not have a clip associated").arg(item->groupName()).toLatin1());
743 if (replace) item->referencedClip()->setProducer(producer);
744 emit receivedClipDuration(clipId, item->clipMaxDuration());
745 listView->blockSignals(false);
746 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
747 if (!m_infoQueue.isEmpty()) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
748 else listView->setEnabled(true);
751 void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix) {
752 ProjectItem *item = getItemById(clipId);
754 listView->blockSignals(true);
755 item->setIcon(0, pix);
756 m_doc->cachePixmap(item->getClipHash(), pix);
757 listView->blockSignals(false);
761 ProjectItem *ProjectList::getItemById(const QString &id) {
763 QTreeWidgetItemIterator it(listView);
765 item = static_cast<ProjectItem *>(*it);
766 if (item->clipId() == id && item->clipType() != FOLDER)
773 ProjectItem *ProjectList::getFolderItemById(const QString &id) {
775 QTreeWidgetItemIterator it(listView);
777 item = static_cast<ProjectItem *>(*it);
778 if (item->clipId() == id && item->clipType() == FOLDER)
785 void ProjectList::slotSelectClip(const QString &ix) {
786 ProjectItem *clip = getItemById(ix);
788 listView->setCurrentItem(clip);
789 listView->scrollToItem(clip);
790 m_editAction->setEnabled(true);
791 m_deleteAction->setEnabled(true);
792 m_reloadAction->setEnabled(true);
793 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
794 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
795 m_openAction->setEnabled(true);
796 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
797 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
798 m_openAction->setEnabled(true);
799 } else m_openAction->setEnabled(false);
803 #include "projectlist.moc"