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) :
72 m_listView = new ProjectListView(this);;
73 QVBoxLayout *layout = new QVBoxLayout;
74 layout->setContentsMargins(0, 0, 0, 0);
77 KTreeWidgetSearchLine *searchView = new KTreeWidgetSearchLine(this);
78 m_toolbar = new QToolBar("projectToolBar", this);
79 m_toolbar->addWidget(searchView);
80 searchView->setTreeWidget(m_listView);
82 m_addButton = new QToolButton(m_toolbar);
83 m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
84 m_toolbar->addWidget(m_addButton);
86 layout->addWidget(m_toolbar);
87 layout->addWidget(m_listView);
92 connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
93 connect(m_listView, SIGNAL(focusMonitor()), this, SLOT(slotClipSelected()));
94 connect(m_listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
95 connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
96 connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
97 connect(m_listView, SIGNAL(addClip(const QList <QUrl>, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &)));
98 connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
99 connect(m_listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
101 ItemDelegate *listViewDelegate = new ItemDelegate(m_listView);
102 m_listView->setItemDelegate(listViewDelegate);
104 if (KdenliveSettings::activate_nepomuk()) {
105 Nepomuk::ResourceManager::instance()->init();
106 if (!Nepomuk::ResourceManager::instance()->initialized()) {
107 kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
108 KdenliveSettings::setActivate_nepomuk(false);
113 ProjectList::~ProjectList()
119 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
121 QList <QAction *> actions = addMenu->actions();
122 for (int i = 0; i < actions.count(); i++) {
123 if (actions.at(i)->data().toString() == "clip_properties") {
124 m_editAction = actions.at(i);
125 m_toolbar->addAction(m_editAction);
128 } else if (actions.at(i)->data().toString() == "delete_clip") {
129 m_deleteAction = actions.at(i);
130 m_toolbar->addAction(m_deleteAction);
133 } else if (actions.at(i)->data().toString() == "edit_clip") {
134 m_openAction = actions.at(i);
137 } else if (actions.at(i)->data().toString() == "reload_clip") {
138 m_reloadAction = actions.at(i);
144 QMenu *m = new QMenu();
145 m->addActions(actions);
146 m_addButton->setMenu(m);
147 m_addButton->setDefaultAction(defaultAction);
148 m_menu = new QMenu();
149 m_menu->addActions(addMenu->actions());
152 void ProjectList::setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu)
154 if (!addMenu) return;
155 QMenu *menu = m_addButton->menu();
156 menu->addMenu(addMenu);
157 m_addButton->setMenu(menu);
159 m_menu->addMenu(addMenu);
160 if (addMenu->isEmpty()) addMenu->setEnabled(false);
161 m_menu->addMenu(transcodeMenu);
162 if (transcodeMenu->isEmpty()) transcodeMenu->setEnabled(false);
163 m_menu->addAction(m_reloadAction);
164 m_menu->addAction(m_editAction);
165 m_menu->addAction(m_openAction);
166 m_menu->addAction(m_deleteAction);
167 m_menu->insertSeparator(m_deleteAction);
171 QByteArray ProjectList::headerInfo() const
173 return m_listView->header()->saveState();
176 void ProjectList::setHeaderInfo(const QByteArray &state)
178 m_listView->header()->restoreState(state);
181 void ProjectList::slotEditClip()
183 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
184 if (!(item->flags() & Qt::ItemIsDragEnabled)) return;
185 if (item && !item->isGroup()) {
186 emit clipSelected(item->referencedClip());
187 emit showClipProperties(item->referencedClip());
191 void ProjectList::slotOpenClip()
193 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
194 if (item && !item->isGroup()) {
195 if (item->clipType() == IMAGE) {
196 if (KdenliveSettings::defaultimageapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open images in the Settings dialog"));
197 else QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
199 if (item->clipType() == AUDIO) {
200 if (KdenliveSettings::defaultaudioapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open audio files in the Settings dialog"));
201 else QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
206 void ProjectList::slotReloadClip()
208 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
209 if (item && !item->isGroup()) {
210 if (item->clipType() == IMAGE) {
211 item->referencedClip()->producer()->set("force_reload", 1);
213 emit getFileProperties(item->toXml(), item->clipId(), false);
217 void ProjectList::setRenderer(Render *projectRender)
219 m_render = projectRender;
220 m_listView->setIconSize(QSize(40 * m_render->dar(), 40));
223 void ProjectList::slotClipSelected()
225 if (m_listView->currentItem()) {
226 ProjectItem *clip = static_cast <ProjectItem*>(m_listView->currentItem());
227 if (!clip->isGroup()) {
228 m_selectedItem = clip;
229 emit clipSelected(clip->referencedClip());
231 m_editAction->setEnabled(true);
232 m_deleteAction->setEnabled(true);
233 m_reloadAction->setEnabled(true);
234 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
235 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
236 m_openAction->setEnabled(true);
237 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
238 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
239 m_openAction->setEnabled(true);
240 } else m_openAction->setEnabled(false);
242 emit clipSelected(NULL);
243 m_editAction->setEnabled(false);
244 m_deleteAction->setEnabled(false);
245 m_openAction->setEnabled(false);
246 m_reloadAction->setEnabled(false);
250 void ProjectList::slotPauseMonitor()
252 if (m_render) m_render->pause();
255 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
257 ProjectItem *item = getItemById(id);
259 slotUpdateClipProperties(item, properties);
260 if (properties.contains("colour") || properties.contains("resource") || properties.contains("xmldata") || properties.contains("force_aspect_ratio")) slotRefreshClipThumbnail(item);
261 if (properties.contains("out")) item->changeDuration(properties.value("out").toInt());
265 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
268 if (!clip->isGroup()) clip->setProperties(properties);
269 if (properties.contains("name")) {
270 m_listView->blockSignals(true);
271 clip->setText(1, properties.value("name"));
272 m_listView->blockSignals(false);
273 emit clipNameChanged(clip->clipId(), properties.value("name"));
275 if (properties.contains("description")) {
276 CLIPTYPE type = clip->clipType();
277 m_listView->blockSignals(true);
278 clip->setText(2, properties.value("description"));
279 m_listView->blockSignals(false);
280 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
281 // Use Nepomuk system to store clip description
282 Nepomuk::Resource f(clip->clipUrl().path());
283 f.setDescription(properties.value("description"));
285 emit projectModified();
289 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
291 ProjectItem *clip = static_cast <ProjectItem*>(item);
293 if (clip->referencedClip()) {
294 QMap <QString, QString> oldprops;
295 QMap <QString, QString> newprops;
296 oldprops["description"] = clip->referencedClip()->getProperty("description");
297 newprops["description"] = item->text(2);
298 slotUpdateClipProperties(clip, newprops);
299 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
300 m_commandStack->push(command);
302 } else if (column == 1) {
303 if (clip->isGroup()) {
304 editFolder(item->text(1), clip->groupName(), clip->clipId());
305 clip->setGroupName(item->text(1));
306 m_doc->clipManager()->addFolder(clip->clipId(), item->text(1));
307 const int children = item->childCount();
308 for (int i = 0; i < children; i++) {
309 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
310 child->setProperty("groupname", item->text(1));
313 if (clip->referencedClip()) {
314 QMap <QString, QString> oldprops;
315 QMap <QString, QString> newprops;
316 oldprops["name"] = clip->referencedClip()->getProperty("name");
317 newprops["name"] = item->text(1);
318 slotUpdateClipProperties(clip, newprops);
319 emit projectModified();
320 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
321 m_commandStack->push(command);
327 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
333 m_editAction->setEnabled(enable);
334 m_deleteAction->setEnabled(enable);
335 m_reloadAction->setEnabled(enable);
337 ProjectItem *clip = static_cast <ProjectItem*>(item);
338 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
339 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
340 m_openAction->setEnabled(true);
341 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
342 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
343 m_openAction->setEnabled(true);
344 } else m_openAction->setEnabled(false);
345 } else m_openAction->setEnabled(false);
349 void ProjectList::slotRemoveClip()
351 if (!m_listView->currentItem()) return;
353 QMap <QString, QString> folderids;
354 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
356 for (int i = 0; i < selected.count(); i++) {
357 item = static_cast <ProjectItem *>(selected.at(i));
358 if (item->isGroup()) folderids[item->groupName()] = item->clipId();
359 else ids << item->clipId();
360 if (item->numReferences() > 0) {
361 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;
362 } else if (item->isGroup() && item->childCount() > 0) {
363 int children = item->childCount();
364 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;
365 for (int i = 0; i < children; ++i) {
366 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
367 ids << child->clipId();
371 if (!ids.isEmpty()) m_doc->deleteProjectClip(ids);
372 if (!folderids.isEmpty()) deleteProjectFolder(folderids);
373 if (m_listView->topLevelItemCount() == 0) {
374 m_editAction->setEnabled(false);
375 m_deleteAction->setEnabled(false);
376 m_openAction->setEnabled(false);
377 m_reloadAction->setEnabled(false);
381 void ProjectList::selectItemById(const QString &clipId)
383 ProjectItem *item = getItemById(clipId);
384 if (item) m_listView->setCurrentItem(item);
388 void ProjectList::slotDeleteClip(const QString &clipId)
390 ProjectItem *item = getItemById(clipId);
392 kDebug() << "/// Cannot find clip to delete";
399 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
401 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
402 m_commandStack->push(command);
403 m_doc->setModified(true);
406 void ProjectList::slotAddFolder()
408 AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
409 m_commandStack->push(command);
412 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
415 ProjectItem *item = getFolderItemById(clipId);
417 m_doc->clipManager()->deleteFolder(clipId);
422 ProjectItem *item = getFolderItemById(clipId);
423 QTreeWidgetItemIterator it(m_listView);
425 m_listView->blockSignals(true);
426 item->setGroupName(foldername);
427 m_listView->blockSignals(false);
428 m_doc->clipManager()->addFolder(clipId, foldername);
429 const int children = item->childCount();
430 for (int i = 0; i < children; i++) {
431 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
432 child->setProperty("groupname", foldername);
437 text << QString() << foldername;
438 m_listView->blockSignals(true);
439 (void) new ProjectItem(m_listView, text, clipId);
440 m_doc->clipManager()->addFolder(clipId, foldername);
441 m_listView->blockSignals(false);
448 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
450 QMapIterator<QString, QString> i(map);
451 QUndoCommand *delCommand = new QUndoCommand();
452 delCommand->setText(i18n("Delete Folder"));
453 while (i.hasNext()) {
455 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
457 m_commandStack->push(delCommand);
458 m_doc->setModified(true);
461 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
463 if (getProperties) m_listView->setEnabled(false);
464 m_listView->blockSignals(true);
465 const QString parent = clip->getProperty("groupid");
466 kDebug() << "Adding clip with groupid: " << parent;
467 ProjectItem *item = NULL;
468 if (!parent.isEmpty()) {
469 ProjectItem *parentitem = getFolderItemById(parent);
472 QString groupName = clip->getProperty("groupname");
473 //kDebug() << "Adding clip to new group: " << groupName;
474 if (groupName.isEmpty()) groupName = i18n("Folder");
475 text << QString() << groupName;
476 parentitem = new ProjectItem(m_listView, text, parent);
478 //kDebug() << "Adding clip to existing group: " << parentitem->groupName();
480 if (parentitem) item = new ProjectItem(parentitem, clip);
482 if (item == NULL) item = new ProjectItem(m_listView, clip);
484 KUrl url = clip->fileURL();
485 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
486 // if file has Nepomuk comment, use it
487 Nepomuk::Resource f(url.path());
488 QString annotation = f.description();
489 if (!annotation.isEmpty()) item->setText(2, annotation);
490 item->setText(3, QString::number(f.rating()));
492 m_listView->blockSignals(false);
495 void ProjectList::slotResetProjectList()
498 emit clipSelected(NULL);
499 m_thumbnailQueue.clear();
504 void ProjectList::requestClipInfo(const QDomElement xml, const QString id)
506 kDebug() << " PRG LISTĀ REQUEST CLP INFO: " << id;
507 m_infoQueue.insert(id, xml);
508 m_listView->setEnabled(false);
509 if (m_infoQueue.count() == 1) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
512 void ProjectList::slotProcessNextClipInQueue()
514 if (m_infoQueue.isEmpty()) {
515 m_listView->setEnabled(true);
518 QMap<QString, QDomElement>::const_iterator i = m_infoQueue.constBegin();
519 if (i != m_infoQueue.constEnd()) {
520 const QDomElement dom = i.value();
521 const QString id = i.key();
522 m_infoQueue.remove(i.key());
523 emit getFileProperties(dom, id, true);
525 if (m_infoQueue.isEmpty()) m_listView->setEnabled(true);
528 void ProjectList::slotUpdateClip(const QString &id)
530 ProjectItem *item = getItemById(id);
531 m_listView->blockSignals(true);
532 if (item) item->setData(1, UsageRole, QString::number(item->numReferences()));
533 m_listView->blockSignals(false);
536 void ProjectList::updateAllClips()
538 QTreeWidgetItemIterator it(m_listView);
540 ProjectItem *item = static_cast <ProjectItem *>(*it);
541 if (!item->isGroup()) {
542 if (item->referencedClip()->producer() == NULL) {
543 DocClipBase *clip = item->referencedClip();
544 if (clip->clipType() == TEXT && !QFile::exists(clip->fileURL().path())) {
545 // regenerate text clip image if required
546 TitleWidget *dia_ui = new TitleWidget(KUrl(), QString(), m_render, this);
548 doc.setContent(clip->getProperty("xmldata"));
550 QImage pix = dia_ui->renderedPixmap();
551 pix.save(clip->fileURL().path());
554 if (clip->isPlaceHolder() == false) requestClipInfo(clip->toXML(), clip->getId());
555 else item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
557 QString cachedPixmap = m_doc->projectFolder().path() + "/thumbs/" + item->getClipHash() + ".png";
558 if (QFile::exists(cachedPixmap)) {
559 //kDebug()<<"// USING CACHED PIX: "<<cachedPixmap;
560 m_listView->blockSignals(true);
561 item->setIcon(0, QPixmap(cachedPixmap));
562 m_listView->blockSignals(false);
563 } else requestClipThumbnail(item->clipId());
565 if (item->data(1, DurationRole).toString().isEmpty()) {
566 m_listView->blockSignals(true);
567 item->changeDuration(item->referencedClip()->producer()->get_playtime());
568 m_listView->blockSignals(false);
571 m_listView->blockSignals(true);
572 item->setData(1, UsageRole, QString::number(item->numReferences()));
573 m_listView->blockSignals(false);
574 qApp->processEvents();
578 QTimer::singleShot(500, this, SLOT(slotCheckForEmptyQueue()));
581 void ProjectList::slotAddClip(const QList <QUrl> givenList, QString group)
583 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
585 if (givenList.isEmpty()) {
586 // Build list of mime types
587 QStringList mimeTypes = QStringList() << "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-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" << "video/ogg" << "audio/ogg";
589 QString allExtensions;
590 foreach(const QString& mimeType, mimeTypes) {
591 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
593 allExtensions.append(mime->patterns().join(" "));
594 allExtensions.append(' ');
597 QString dialogFilter = allExtensions + ' ' + QLatin1Char('|') + i18n("All Supported Files");
598 dialogFilter.append("\n*" + QLatin1Char('|') + i18n("All Files"));
599 list = KFileDialog::getOpenUrls(KUrl("kfiledialog:///clipfolder"), dialogFilter, this);
602 for (int i = 0; i < givenList.count(); i++)
603 list << givenList.at(i);
605 if (list.isEmpty()) return;
608 if (group.isEmpty()) {
609 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
610 if (item && !item->isGroup()) {
611 while (item->parent()) {
612 item = static_cast <ProjectItem*>(item->parent());
613 if (item->isGroup()) break;
616 if (item && item->isGroup()) {
617 group = item->groupName();
618 groupId = item->clipId();
621 m_doc->slotAddClipList(list, group, groupId);
624 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
626 ProjectItem *item = getItemById(id);
628 const QString path = item->referencedClip()->fileURL().path();
629 if (!path.isEmpty()) {
630 if (replace) KMessageBox::sorry(this, i18n("Clip <b>%1</b><br>is invalid, will be removed from project.", path));
632 if (KMessageBox::questionYesNo(this, i18n("Clip <b>%1</b><br>is missing or invalid. Remove it from project?", path), i18n("Invalid clip")) == KMessageBox::Yes) replace = true;
637 if (replace) m_doc->deleteProjectClip(ids);
639 if (!m_infoQueue.isEmpty()) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
640 else m_listView->setEnabled(true);
643 void ProjectList::slotAddColorClip()
645 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
646 QDialog *dia = new QDialog(this);
647 Ui::ColorClip_UI *dia_ui = new Ui::ColorClip_UI();
648 dia_ui->setupUi(dia);
649 dia_ui->clip_name->setText(i18n("Color Clip"));
650 dia_ui->clip_duration->setText(KdenliveSettings::color_duration());
651 if (dia->exec() == QDialog::Accepted) {
652 QString color = dia_ui->clip_color->color().name();
653 color = color.replace(0, 1, "0x") + "ff";
657 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
658 if (item && !item->isGroup()) {
659 while (item->parent()) {
660 item = static_cast <ProjectItem*>(item->parent());
661 if (item->isGroup()) break;
664 if (item && item->isGroup()) {
665 group = item->groupName();
666 groupId = item->clipId();
669 m_doc->clipManager()->slotAddColorClipFile(dia_ui->clip_name->text(), color, dia_ui->clip_duration->text(), group, groupId);
670 m_doc->setModified(true);
677 void ProjectList::slotAddSlideshowClip()
679 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
680 SlideshowClip *dia = new SlideshowClip(m_timecode, this);
682 if (dia->exec() == QDialog::Accepted) {
686 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
687 if (item && !item->isGroup()) {
688 while (item->parent()) {
689 item = static_cast <ProjectItem*>(item->parent());
690 if (item->isGroup()) break;
693 if (item && item->isGroup()) {
694 group = item->groupName();
695 groupId = item->clipId();
698 m_doc->clipManager()->slotAddSlideshowClipFile(dia->clipName(), dia->selectedPath(), dia->imageCount(), dia->clipDuration(), dia->loop(), dia->fade(), dia->lumaDuration(), dia->lumaFile(), dia->softness(), group, groupId);
699 m_doc->setModified(true);
704 void ProjectList::slotAddTitleClip()
708 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
709 if (item && !item->isGroup()) {
710 while (item->parent()) {
711 item = static_cast <ProjectItem*>(item->parent());
712 if (item->isGroup()) break;
715 if (item && item->isGroup()) {
716 group = item->groupName();
717 groupId = item->clipId();
720 m_doc->slotCreateTextClip(group, groupId);
723 void ProjectList::setDocument(KdenliveDoc *doc)
725 m_listView->blockSignals(true);
727 emit clipSelected(NULL);
728 m_thumbnailQueue.clear();
731 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
732 QMapIterator<QString, QString> f(flist);
733 while (f.hasNext()) {
735 (void) new ProjectItem(m_listView, QStringList() << QString() << f.value(), f.key());
738 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
739 for (int i = 0; i < list.count(); i++) {
740 slotAddClip(list.at(i), false);
744 m_timecode = doc->timecode();
745 m_commandStack = doc->commandStack();
747 QTreeWidgetItem *first = m_listView->topLevelItem(0);
748 if (first) m_listView->setCurrentItem(first);
749 m_listView->blockSignals(false);
750 m_toolbar->setEnabled(true);
753 QDomElement ProjectList::producersList()
756 QDomElement prods = doc.createElement("producerlist");
757 doc.appendChild(prods);
758 kDebug() << "//////////// PRO LISTĀ BUILD PRDSLIST ";
759 QTreeWidgetItemIterator it(m_listView);
761 if (!((ProjectItem *)(*it))->isGroup())
762 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
768 void ProjectList::slotCheckForEmptyQueue()
770 if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
772 emit loadingIsOver();
773 } else QTimer::singleShot(500, this, SLOT(slotCheckForEmptyQueue()));
776 void ProjectList::reloadClipThumbnails()
778 m_thumbnailQueue.clear();
779 QTreeWidgetItemIterator it(m_listView);
781 if (!((ProjectItem *)(*it))->isGroup())
782 m_thumbnailQueue << ((ProjectItem *)(*it))->clipId();
785 QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
788 void ProjectList::requestClipThumbnail(const QString &id)
790 m_thumbnailQueue.append(id);
791 if (m_thumbnailQueue.count() == 1) QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
794 void ProjectList::slotProcessNextThumbnail()
796 if (m_thumbnailQueue.isEmpty()) {
799 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
802 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
804 ProjectItem *item = getItemById(clipId);
805 if (item) slotRefreshClipThumbnail(item, update);
806 else slotProcessNextThumbnail();
809 void ProjectList::slotRefreshClipThumbnail(ProjectItem *item, bool update)
812 if (!item->referencedClip()) return;
814 int width = (int)(height * m_render->dar());
815 DocClipBase *clip = item->referencedClip();
816 if (!clip) slotProcessNextThumbnail();
818 if (clip->clipType() == AUDIO) pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
819 else pix = item->referencedClip()->thumbProducer()->extractImage(item->referencedClip()->getClipThumbFrame(), width, height);
820 m_listView->blockSignals(true);
821 item->setIcon(0, pix);
822 m_listView->blockSignals(false);
823 m_doc->cachePixmap(item->getClipHash(), pix);
824 if (update) emit projectModified();
825 if (!m_thumbnailQueue.isEmpty()) QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
829 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace)
831 ProjectItem *item = getItemById(clipId);
832 if (item && producer) {
833 m_listView->blockSignals(true);
834 item->setProperties(properties, metadata);
835 Q_ASSERT_X(item->referencedClip(), "void ProjectList::slotReplyGetFileProperties", QString("Item with groupName %1 does not have a clip associated").arg(item->groupName()).toLatin1());
836 if (replace) item->referencedClip()->setProducer(producer);
838 // Check if duration changed.
839 emit receivedClipDuration(clipId);
842 m_listView->blockSignals(false);
843 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
844 if (!m_infoQueue.isEmpty()) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
845 else m_listView->setEnabled(true);
848 void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
850 ProjectItem *item = getItemById(clipId);
852 m_listView->blockSignals(true);
853 item->setIcon(0, pix);
854 m_doc->cachePixmap(item->getClipHash(), pix);
855 m_listView->blockSignals(false);
859 ProjectItem *ProjectList::getItemById(const QString &id)
862 QTreeWidgetItemIterator it(m_listView);
864 item = static_cast<ProjectItem *>(*it);
865 if (item->clipId() == id && item->clipType() != FOLDER)
872 ProjectItem *ProjectList::getFolderItemById(const QString &id)
875 QTreeWidgetItemIterator it(m_listView);
877 item = static_cast<ProjectItem *>(*it);
878 if (item->clipId() == id && item->clipType() == FOLDER)
885 void ProjectList::slotSelectClip(const QString &ix)
887 ProjectItem *clip = getItemById(ix);
889 m_listView->setCurrentItem(clip);
890 m_listView->scrollToItem(clip);
891 m_editAction->setEnabled(true);
892 m_deleteAction->setEnabled(true);
893 m_reloadAction->setEnabled(true);
894 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
895 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
896 m_openAction->setEnabled(true);
897 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
898 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
899 m_openAction->setEnabled(true);
900 } else m_openAction->setEnabled(false);
904 QString ProjectList::currentClipUrl() const
906 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
907 if (item == NULL) return QString();
908 return item->clipUrl().path();
911 #include "projectlist.moc"