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 "subprojectitem.h"
23 #include "addfoldercommand.h"
24 #include "kdenlivesettings.h"
25 #include "slideshowclip.h"
26 #include "ui_colorclip_ui.h"
27 #include "titlewidget.h"
28 #include "definitions.h"
29 #include "clipmanager.h"
30 #include "docclipbase.h"
31 #include "kdenlivedoc.h"
34 #include "projectlistview.h"
35 #include "editclipcommand.h"
36 #include "editfoldercommand.h"
37 #include "addclipcutcommand.h"
39 #include "ui_templateclip_ui.h"
44 #include <KFileDialog>
45 #include <KInputDialog>
46 #include <KMessageBox>
47 #include <KIO/NetAccess>
50 #include <nepomuk/global.h>
51 #include <nepomuk/resourcemanager.h>
52 //#include <nepomuk/tag.h>
54 #include <QMouseEvent>
55 #include <QStylePainter>
60 #include <QHeaderView>
62 ProjectList::ProjectList(QWidget *parent) :
71 m_transcodeAction(NULL),
78 m_listView = new ProjectListView(this);;
79 QVBoxLayout *layout = new QVBoxLayout;
80 layout->setContentsMargins(0, 0, 0, 0);
83 KTreeWidgetSearchLine *searchView = new KTreeWidgetSearchLine(this);
84 m_toolbar = new QToolBar("projectToolBar", this);
85 m_toolbar->addWidget(searchView);
86 int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
87 m_toolbar->setIconSize(QSize(s, s));
88 searchView->setTreeWidget(m_listView);
90 m_addButton = new QToolButton(m_toolbar);
91 m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
92 m_toolbar->addWidget(m_addButton);
94 layout->addWidget(m_toolbar);
95 layout->addWidget(m_listView);
98 m_queueTimer.setInterval(100);
99 connect(&m_queueTimer, SIGNAL(timeout()), this, SLOT(slotProcessNextClipInQueue()));
100 m_queueTimer.setSingleShot(true);
104 connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
105 connect(m_listView, SIGNAL(focusMonitor()), this, SLOT(slotClipSelected()));
106 connect(m_listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
107 connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
108 connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
109 connect(m_listView, SIGNAL(addClip(const QList <QUrl>, const QString &, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &, const QString &)));
110 connect(m_listView, SIGNAL(addClipCut(const QString &, int, int)), this, SLOT(slotAddClipCut(const QString &, int, int)));
111 connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
112 connect(m_listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
114 m_listViewDelegate = new ItemDelegate(m_listView);
115 m_listView->setItemDelegate(m_listViewDelegate);
117 if (KdenliveSettings::activate_nepomuk()) {
118 Nepomuk::ResourceManager::instance()->init();
119 if (!Nepomuk::ResourceManager::instance()->initialized()) {
120 kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
121 KdenliveSettings::setActivate_nepomuk(false);
126 ProjectList::~ProjectList()
130 m_listView->blockSignals(true);
132 delete m_listViewDelegate;
135 void ProjectList::focusTree() const
137 m_listView->setFocus();
140 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
142 QList <QAction *> actions = addMenu->actions();
143 for (int i = 0; i < actions.count(); i++) {
144 if (actions.at(i)->data().toString() == "clip_properties") {
145 m_editAction = actions.at(i);
146 m_toolbar->addAction(m_editAction);
149 } else if (actions.at(i)->data().toString() == "delete_clip") {
150 m_deleteAction = actions.at(i);
151 m_toolbar->addAction(m_deleteAction);
154 } else if (actions.at(i)->data().toString() == "edit_clip") {
155 m_openAction = actions.at(i);
158 } else if (actions.at(i)->data().toString() == "reload_clip") {
159 m_reloadAction = actions.at(i);
165 QMenu *m = new QMenu();
166 m->addActions(actions);
167 m_addButton->setMenu(m);
168 m_addButton->setDefaultAction(defaultAction);
169 m_menu = new QMenu();
170 m_menu->addActions(addMenu->actions());
173 void ProjectList::setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu)
175 if (!addMenu) return;
176 QMenu *menu = m_addButton->menu();
177 menu->addMenu(addMenu);
178 m_addButton->setMenu(menu);
180 m_menu->addMenu(addMenu);
181 if (addMenu->isEmpty()) addMenu->setEnabled(false);
182 m_menu->addMenu(transcodeMenu);
183 if (transcodeMenu->isEmpty()) transcodeMenu->setEnabled(false);
184 m_transcodeAction = transcodeMenu;
185 m_menu->addAction(m_reloadAction);
186 m_menu->addAction(m_editAction);
187 m_menu->addAction(m_openAction);
188 m_menu->addAction(m_deleteAction);
189 m_menu->insertSeparator(m_deleteAction);
193 QByteArray ProjectList::headerInfo() const
195 return m_listView->header()->saveState();
198 void ProjectList::setHeaderInfo(const QByteArray &state)
200 m_listView->header()->restoreState(state);
203 void ProjectList::slotEditClip()
206 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return;
207 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
208 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
209 } else item = static_cast <ProjectItem*>(m_listView->currentItem());
210 if (!(item->flags() & Qt::ItemIsDragEnabled)) return;
212 emit clipSelected(item->referencedClip());
213 emit showClipProperties(item->referencedClip());
217 void ProjectList::slotOpenClip()
220 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return;
221 if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1) {
222 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
223 } else item = static_cast <ProjectItem*>(m_listView->currentItem());
225 if (item->clipType() == IMAGE) {
226 if (KdenliveSettings::defaultimageapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open images in the Settings dialog"));
227 else QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
229 if (item->clipType() == AUDIO) {
230 if (KdenliveSettings::defaultaudioapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open audio files in the Settings dialog"));
231 else QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
236 void ProjectList::cleanup()
238 m_listView->clearSelection();
239 QTreeWidgetItemIterator it(m_listView);
242 if ((*it)->type() != PROJECTCLIPTYPE) {
246 item = static_cast <ProjectItem *>(*it);
247 if (item->numReferences() == 0) item->setSelected(true);
253 void ProjectList::trashUnusedClips()
255 QTreeWidgetItemIterator it(m_listView);
260 if ((*it)->type() != PROJECTCLIPTYPE) {
264 item = static_cast <ProjectItem *>(*it);
265 if (item->numReferences() == 0) {
266 ids << item->clipId();
267 KUrl url = item->clipUrl();
268 if (!url.isEmpty() && !urls.contains(url.path())) urls << url.path();
273 // Check that we don't use the URL in another clip
274 QTreeWidgetItemIterator it2(m_listView);
276 if ((*it2)->type() != PROJECTCLIPTYPE) {
280 item = static_cast <ProjectItem *>(*it2);
281 if (item->numReferences() > 0) {
282 KUrl url = item->clipUrl();
283 if (!url.isEmpty() && urls.contains(url.path())) urls.removeAll(url.path());
288 m_doc->deleteProjectClip(ids);
289 for (int i = 0; i < urls.count(); i++) {
290 KIO::NetAccess::del(KUrl(urls.at(i)), this);
294 void ProjectList::slotReloadClip(const QString &id)
296 QList<QTreeWidgetItem *> selected;
297 if (id.isEmpty()) selected = m_listView->selectedItems();
298 else selected.append(getItemById(id));
300 for (int i = 0; i < selected.count(); i++) {
301 if (selected.at(i)->type() != PROJECTCLIPTYPE) continue;
302 item = static_cast <ProjectItem *>(selected.at(i));
304 if (item->clipType() == IMAGE) {
305 item->referencedClip()->producer()->set("force_reload", 1);
306 } else if (item->clipType() == TEXT) {
307 if (!item->referencedClip()->getProperty("xmltemplate").isEmpty()) regenerateTemplate(item);
309 //requestClipInfo(item->toXml(), item->clipId(), true);
310 // Clear the file_hash value, which will cause a complete reload of the clip
311 emit getFileProperties(item->toXml(), item->clipId(), true);
316 void ProjectList::setRenderer(Render *projectRender)
318 m_render = projectRender;
319 m_listView->setIconSize(QSize(43 * m_render->dar(), 43));
322 void ProjectList::slotClipSelected()
324 if (m_listView->currentItem()) {
325 if (m_listView->currentItem()->type() == PROJECTFOLDERTYPE) {
326 emit clipSelected(NULL);
327 m_editAction->setEnabled(false);
328 m_deleteAction->setEnabled(true);
329 m_openAction->setEnabled(false);
330 m_reloadAction->setEnabled(false);
331 m_transcodeAction->setEnabled(false);
335 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
336 // this is a sub item, use base clip
337 clip = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
338 if (clip == NULL) kDebug() << "-----------ERROR";
339 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
340 emit clipSelected(clip->referencedClip(), sub->zone());
343 clip = static_cast <ProjectItem*>(m_listView->currentItem());
344 emit clipSelected(clip->referencedClip());
345 m_editAction->setEnabled(true);
346 m_deleteAction->setEnabled(true);
347 m_reloadAction->setEnabled(true);
348 m_transcodeAction->setEnabled(true);
349 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
350 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
351 m_openAction->setEnabled(true);
352 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
353 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
354 m_openAction->setEnabled(true);
355 } else m_openAction->setEnabled(false);
358 emit clipSelected(NULL);
359 m_editAction->setEnabled(false);
360 m_deleteAction->setEnabled(false);
361 m_openAction->setEnabled(false);
362 m_reloadAction->setEnabled(false);
363 m_transcodeAction->setEnabled(false);
367 void ProjectList::slotPauseMonitor()
369 if (m_render) m_render->pause();
372 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
374 ProjectItem *item = getItemById(id);
376 slotUpdateClipProperties(item, properties);
377 if (properties.contains("out")) {
379 } else if (properties.contains("colour") || properties.contains("resource") || properties.contains("xmldata") || properties.contains("force_aspect_ratio") || properties.contains("templatetext")) {
380 slotRefreshClipThumbnail(item);
386 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
389 clip->setProperties(properties);
390 if (properties.contains("name")) {
391 m_listView->blockSignals(true);
392 clip->setText(0, properties.value("name"));
393 m_listView->blockSignals(false);
394 emit clipNameChanged(clip->clipId(), properties.value("name"));
396 if (properties.contains("description")) {
397 CLIPTYPE type = clip->clipType();
398 m_listView->blockSignals(true);
399 clip->setText(1, properties.value("description"));
400 m_listView->blockSignals(false);
401 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
402 // Use Nepomuk system to store clip description
403 Nepomuk::Resource f(clip->clipUrl().path());
404 f.setDescription(properties.value("description"));
406 emit projectModified();
410 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
412 if (item->type() == PROJECTSUBCLIPTYPE) {
413 // this is a sub-item
416 if (item->type() == PROJECTFOLDERTYPE) {
417 if (column != 0) return;
418 FolderProjectItem *folder = static_cast <FolderProjectItem*>(item);
419 editFolder(item->text(0), folder->groupName(), folder->clipId());
420 folder->setGroupName(item->text(0));
421 m_doc->clipManager()->addFolder(folder->clipId(), item->text(0));
422 const int children = item->childCount();
423 for (int i = 0; i < children; i++) {
424 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
425 child->setProperty("groupname", item->text(0));
430 ProjectItem *clip = static_cast <ProjectItem*>(item);
432 if (clip->referencedClip()) {
433 QMap <QString, QString> oldprops;
434 QMap <QString, QString> newprops;
435 oldprops["description"] = clip->referencedClip()->getProperty("description");
436 newprops["description"] = item->text(1);
438 if (clip->clipType() == TEXT) {
439 // This is a text template clip, update the image
440 /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
441 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/
442 oldprops.insert("templatetext", clip->referencedClip()->getProperty("templatetext"));
443 newprops.insert("templatetext", item->text(1));
445 slotUpdateClipProperties(clip->clipId(), newprops);
446 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
447 m_commandStack->push(command);
449 } else if (column == 0) {
450 if (clip->referencedClip()) {
451 QMap <QString, QString> oldprops;
452 QMap <QString, QString> newprops;
453 oldprops["name"] = clip->referencedClip()->getProperty("name");
454 newprops["name"] = item->text(0);
455 slotUpdateClipProperties(clip, newprops);
456 emit projectModified();
457 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
458 m_commandStack->push(command);
463 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
469 m_editAction->setEnabled(enable);
470 m_deleteAction->setEnabled(enable);
471 m_reloadAction->setEnabled(enable);
472 m_transcodeAction->setEnabled(enable);
474 ProjectItem *clip = NULL;
475 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
476 clip = static_cast <ProjectItem*>(item->parent());
477 } else if (m_listView->currentItem()->type() == PROJECTCLIPTYPE) clip = static_cast <ProjectItem*>(item);
478 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
479 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
480 m_openAction->setEnabled(true);
481 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
482 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
483 m_openAction->setEnabled(true);
484 } else m_openAction->setEnabled(false);
485 } else m_openAction->setEnabled(false);
489 void ProjectList::slotRemoveClip()
491 if (!m_listView->currentItem()) return;
493 QMap <QString, QString> folderids;
494 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
496 QUndoCommand *delCommand = new QUndoCommand();
497 delCommand->setText(i18n("Delete Clip Zone"));
499 for (int i = 0; i < selected.count(); i++) {
500 if (selected.at(i)->type() == PROJECTSUBCLIPTYPE) {
502 SubProjectItem *sub = static_cast <SubProjectItem *>(selected.at(i));
503 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
504 new AddClipCutCommand(this, item->clipId(), sub->zone().x(), sub->zone().y(), true, delCommand);
508 if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
510 FolderProjectItem *folder = static_cast <FolderProjectItem *>(selected.at(i));
511 folderids[folder->groupName()] = folder->clipId();
512 int children = folder->childCount();
514 if (children > 0 && KMessageBox::questionYesNo(this, i18np("Delete folder <b>%2</b>?<br>This will also remove the clip in that folder", "Delete folder <b>%2</b>?<br>This will also remove the %1 clips in that folder", children, folder->text(1)), i18n("Delete Folder")) != KMessageBox::Yes) return;
515 for (int i = 0; i < children; ++i) {
516 ProjectItem *child = static_cast <ProjectItem *>(folder->child(i));
517 ids << child->clipId();
522 ProjectItem *item = static_cast <ProjectItem *>(selected.at(i));
523 ids << item->clipId();
524 if (item->numReferences() > 0) {
525 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;
528 if (delCommand->childCount() == 0) delete delCommand;
529 else m_commandStack->push(delCommand);
530 if (!ids.isEmpty()) m_doc->deleteProjectClip(ids);
531 if (!folderids.isEmpty()) deleteProjectFolder(folderids);
532 if (m_listView->topLevelItemCount() == 0) {
533 m_editAction->setEnabled(false);
534 m_deleteAction->setEnabled(false);
535 m_openAction->setEnabled(false);
536 m_reloadAction->setEnabled(false);
537 m_transcodeAction->setEnabled(false);
541 void ProjectList::selectItemById(const QString &clipId)
543 ProjectItem *item = getItemById(clipId);
544 if (item) m_listView->setCurrentItem(item);
548 void ProjectList::slotDeleteClip(const QString &clipId)
550 ProjectItem *item = getItemById(clipId);
552 kDebug() << "/// Cannot find clip to delete";
555 m_listView->blockSignals(true);
557 m_doc->clipManager()->deleteClip(clipId);
558 m_listView->blockSignals(false);
563 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
565 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
566 m_commandStack->push(command);
567 m_doc->setModified(true);
570 void ProjectList::slotAddFolder()
572 AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
573 m_commandStack->push(command);
576 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
579 FolderProjectItem *item = getFolderItemById(clipId);
581 m_doc->clipManager()->deleteFolder(clipId);
586 FolderProjectItem *item = getFolderItemById(clipId);
588 m_listView->blockSignals(true);
589 item->setGroupName(foldername);
590 m_listView->blockSignals(false);
591 m_doc->clipManager()->addFolder(clipId, foldername);
592 const int children = item->childCount();
593 for (int i = 0; i < children; i++) {
594 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
595 child->setProperty("groupname", foldername);
601 m_listView->blockSignals(true);
602 m_listView->setCurrentItem(new FolderProjectItem(m_listView, text, clipId));
603 m_doc->clipManager()->addFolder(clipId, foldername);
604 m_listView->blockSignals(false);
607 m_doc->setModified(true);
612 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
614 QMapIterator<QString, QString> i(map);
615 QUndoCommand *delCommand = new QUndoCommand();
616 delCommand->setText(i18n("Delete Folder"));
617 while (i.hasNext()) {
619 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
621 m_commandStack->push(delCommand);
624 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
626 m_listView->setEnabled(false);
628 m_listView->blockSignals(true);
630 // remove file_hash so that we load all properties for the clip
631 QDomElement e = clip->toXML().cloneNode().toElement();
632 e.removeAttribute("file_hash");
633 m_infoQueue.insert(clip->getId(), e);
634 //m_render->getFileProperties(clip->toXML(), clip->getId(), true);
636 const QString parent = clip->getProperty("groupid");
637 ProjectItem *item = NULL;
638 if (!parent.isEmpty()) {
639 FolderProjectItem *parentitem = getFolderItemById(parent);
642 QString groupName = clip->getProperty("groupname");
643 //kDebug() << "Adding clip to new group: " << groupName;
644 if (groupName.isEmpty()) groupName = i18n("Folder");
646 parentitem = new FolderProjectItem(m_listView, text, parent);
648 //kDebug() << "Adding clip to existing group: " << parentitem->groupName();
650 if (parentitem) item = new ProjectItem(parentitem, clip);
652 if (item == NULL) item = new ProjectItem(m_listView, clip);
653 KUrl url = clip->fileURL();
655 if (getProperties == false && !clip->getClipHash().isEmpty()) {
656 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
657 if (QFile::exists(cachedPixmap)) {
658 item->setIcon(0, QPixmap(cachedPixmap));
662 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
663 // if file has Nepomuk comment, use it
664 Nepomuk::Resource f(url.path());
665 QString annotation = f.description();
666 if (!annotation.isEmpty()) item->setText(1, annotation);
667 item->setText(2, QString::number(f.rating()));
671 QList <QPoint> cuts = clip->cutZones();
672 if (!cuts.isEmpty()) {
673 for (int i = 0; i < cuts.count(); i++) {
674 SubProjectItem *sub = new SubProjectItem(item, cuts.at(i).x(), cuts.at(i).y());
675 if (!clip->getClipHash().isEmpty()) {
676 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(cuts.at(i).x()) + ".png";
677 if (QFile::exists(cachedPixmap)) {
678 sub->setIcon(0, QPixmap(cachedPixmap));
684 if (getProperties && m_listView->isEnabled()) m_listView->blockSignals(false);
685 if (getProperties && !m_queueTimer.isActive()) m_queueTimer.start();
688 void ProjectList::slotResetProjectList()
691 emit clipSelected(NULL);
692 m_thumbnailQueue.clear();
697 void ProjectList::requestClipInfo(const QDomElement xml, const QString id)
700 m_infoQueue.insert(id, xml);
701 //if (m_infoQueue.count() == 1 || ) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
704 void ProjectList::slotProcessNextClipInQueue()
706 if (m_infoQueue.isEmpty()) {
707 slotProcessNextThumbnail();
711 QMap<QString, QDomElement>::const_iterator j = m_infoQueue.constBegin();
712 if (j != m_infoQueue.constEnd()) {
713 const QDomElement dom = j.value();
714 const QString id = j.key();
715 m_infoQueue.remove(j.key());
716 emit getFileProperties(dom, id, false);
720 void ProjectList::slotUpdateClip(const QString &id)
722 ProjectItem *item = getItemById(id);
723 m_listView->blockSignals(true);
724 if (item) item->setData(1, UsageRole, QString::number(item->numReferences()));
725 m_listView->blockSignals(false);
728 void ProjectList::updateAllClips()
730 m_listView->setSortingEnabled(false);
732 QTreeWidgetItemIterator it(m_listView);
735 m_listView->blockSignals(true);
737 if ((*it)->type() == PROJECTSUBCLIPTYPE) {
739 SubProjectItem *sub = static_cast <SubProjectItem *>(*it);
740 if (sub->icon(0).isNull()) {
741 item = static_cast <ProjectItem *>((*it)->parent());
742 requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x()));
746 } else if ((*it)->type() == PROJECTFOLDERTYPE) {
751 item = static_cast <ProjectItem *>(*it);
752 clip = item->referencedClip();
753 if (item->referencedClip()->producer() == NULL) {
754 if (clip->isPlaceHolder() == false) {
755 requestClipInfo(clip->toXML(), clip->getId());
756 } else item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
758 if (item->icon(0).isNull()) {
759 requestClipThumbnail(clip->getId());
761 if (item->data(0, DurationRole).toString().isEmpty()) {
762 item->changeDuration(item->referencedClip()->producer()->get_playtime());
765 item->setData(1, UsageRole, QString::number(item->numReferences()));
766 //qApp->processEvents();
769 qApp->processEvents();
770 if (!m_queueTimer.isActive()) m_queueTimer.start();
772 if (m_listView->isEnabled()) m_listView->blockSignals(false);
773 m_listView->setSortingEnabled(true);
774 if (m_infoQueue.isEmpty()) slotProcessNextThumbnail();
777 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
779 if (!m_commandStack) {
780 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
783 if (givenList.isEmpty()) {
784 // Build list of mime types
785 QStringList mimeTypes = QStringList() << "application/x-kdenlive" << "application/x-kdenlivetitle" << "video/x-flv" << "application/vnd.rn-realmedia" << "video/x-dv" << "video/dv" << "video/x-msvideo" << "video/x-matroska" << "video/mlt-playlist" << "video/mpeg" << "video/ogg" << "video/x-ms-wmv" << "audio/x-flac" << "audio/x-matroska" << "audio/mp4" << "audio/mpeg" << "audio/x-mp3" << "audio/ogg" << "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";
787 QString allExtensions;
788 foreach(const QString& mimeType, mimeTypes) {
789 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
791 allExtensions.append(mime->patterns().join(" "));
792 allExtensions.append(' ');
795 const QString dialogFilter = allExtensions.simplified() + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
796 list = KFileDialog::getOpenUrls(KUrl("kfiledialog:///clipfolder"), dialogFilter, this);
799 for (int i = 0; i < givenList.count(); i++)
800 list << givenList.at(i);
802 if (list.isEmpty()) return;
804 if (givenList.isEmpty()) {
805 QStringList groupInfo = getGroup();
806 m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1));
807 } else m_doc->slotAddClipList(list, groupName, groupId);
810 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
812 ProjectItem *item = getItemById(id);
813 QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
815 const QString path = item->referencedClip()->fileURL().path();
816 if (!path.isEmpty()) {
817 if (replace) KMessageBox::sorry(this, i18n("Clip <b>%1</b><br>is invalid, will be removed from project.", path));
819 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;
824 if (replace) m_doc->deleteProjectClip(ids);
828 void ProjectList::slotAddColorClip()
830 if (!m_commandStack) {
831 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
833 QDialog *dia = new QDialog(this);
834 Ui::ColorClip_UI dia_ui;
836 dia_ui.clip_name->setText(i18n("Color Clip"));
837 dia_ui.clip_duration->setText(KdenliveSettings::color_duration());
838 if (dia->exec() == QDialog::Accepted) {
839 QString color = dia_ui.clip_color->color().name();
840 color = color.replace(0, 1, "0x") + "ff";
841 QStringList groupInfo = getGroup();
842 m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, dia_ui.clip_duration->text(), groupInfo.at(0), groupInfo.at(1));
848 void ProjectList::slotAddSlideshowClip()
850 if (!m_commandStack) {
851 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
853 SlideshowClip *dia = new SlideshowClip(m_timecode, this);
855 if (dia->exec() == QDialog::Accepted) {
856 QStringList groupInfo = getGroup();
857 m_doc->slotCreateSlideshowClipFile(dia->clipName(), dia->selectedPath(), dia->imageCount(), dia->clipDuration(), dia->loop(), dia->fade(), dia->lumaDuration(), dia->lumaFile(), dia->softness(), groupInfo.at(0), groupInfo.at(1));
862 void ProjectList::slotAddTitleClip()
864 QStringList groupInfo = getGroup();
865 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
868 void ProjectList::slotAddTitleTemplateClip()
870 QStringList groupInfo = getGroup();
871 if (!m_commandStack) {
872 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
875 // Get the list of existing templates
877 filter << "*.kdenlivetitle";
878 const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
879 QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
881 QDialog *dia = new QDialog(this);
882 Ui::TemplateClip_UI dia_ui;
884 for (int i = 0; i < templateFiles.size(); ++i) {
885 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
887 dia_ui.template_list->fileDialog()->setFilter("*.kdenlivetitle");
888 //warning: setting base directory doesn't work??
890 dia_ui.template_list->fileDialog()->setUrl(startDir);
891 dia_ui.text_box->setHidden(true);
892 if (dia->exec() == QDialog::Accepted) {
893 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
894 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
895 // Create a cloned template clip
896 m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
901 QStringList ProjectList::getGroup() const
904 QTreeWidgetItem *item = m_listView->currentItem();
905 while (item && item->type() != PROJECTFOLDERTYPE) {
906 item = item->parent();
910 FolderProjectItem *folder = static_cast <FolderProjectItem *>(item);
911 result << folder->groupName();
912 result << folder->clipId();
913 } else result << QString() << QString();
917 void ProjectList::setDocument(KdenliveDoc *doc)
919 m_listView->blockSignals(true);
921 m_listView->setSortingEnabled(false);
922 emit clipSelected(NULL);
923 m_thumbnailQueue.clear();
927 m_timecode = doc->timecode();
928 m_commandStack = doc->commandStack();
931 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
932 QMapIterator<QString, QString> f(flist);
933 while (f.hasNext()) {
935 (void) new FolderProjectItem(m_listView, QStringList() << f.value(), f.key());
938 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
939 for (int i = 0; i < list.count(); i++) {
940 slotAddClip(list.at(i), false);
943 m_listView->blockSignals(false);
944 m_toolbar->setEnabled(true);
945 connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
946 connect(m_doc->clipManager(), SIGNAL(checkAllClips()), this, SLOT(updateAllClips()));
949 QList <DocClipBase*> ProjectList::documentClipList() const
951 if (m_doc == NULL) return QList <DocClipBase*> ();
952 return m_doc->clipManager()->documentClipList();
955 QDomElement ProjectList::producersList()
958 QDomElement prods = doc.createElement("producerlist");
959 doc.appendChild(prods);
960 kDebug() << "//////////// PRO LISTÂ BUILD PRDSLIST ";
961 QTreeWidgetItemIterator it(m_listView);
963 if ((*it)->type() != PROJECTCLIPTYPE) {
968 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
974 void ProjectList::slotCheckForEmptyQueue()
976 if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
978 emit loadingIsOver();
979 emit displayMessage(QString(), -1);
980 m_listView->blockSignals(false);
981 m_listView->setEnabled(true);
982 } else if (!m_refreshed) QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
985 void ProjectList::reloadClipThumbnails()
987 kDebug() << "////////////// RELOAD CLIPS THUMBNAILS!!!";
988 m_thumbnailQueue.clear();
989 QTreeWidgetItemIterator it(m_listView);
991 if ((*it)->type() != PROJECTCLIPTYPE) {
996 m_thumbnailQueue << ((ProjectItem *)(*it))->clipId();
999 QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
1002 void ProjectList::requestClipThumbnail(const QString id)
1004 if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id);
1007 void ProjectList::slotProcessNextThumbnail()
1009 if (m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
1010 slotCheckForEmptyQueue();
1013 if (!m_infoQueue.isEmpty()) {
1014 //QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
1017 if (m_thumbnailQueue.count() > 1) {
1018 int max = m_doc->clipManager()->clipsCount();
1019 emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - m_thumbnailQueue.count()) / max));
1021 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
1024 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
1026 QTreeWidgetItem *item = getAnyItemById(clipId);
1027 if (item) slotRefreshClipThumbnail(item, update);
1028 else slotProcessNextThumbnail();
1031 void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
1033 if (it == NULL) return;
1034 ProjectItem *item = NULL;
1035 bool isSubItem = false;
1037 if (it->type() == PROJECTFOLDERTYPE) return;
1038 if (it->type() == PROJECTSUBCLIPTYPE) {
1039 item = static_cast <ProjectItem *>(it->parent());
1040 frame = static_cast <SubProjectItem *>(it)->zone().x();
1043 item = static_cast <ProjectItem *>(it);
1044 frame = item->referencedClip()->getClipThumbFrame();
1048 DocClipBase *clip = item->referencedClip();
1050 slotProcessNextThumbnail();
1054 int height = it->sizeHint(0).height();
1055 int width = (int)(height * m_render->dar());
1056 if (clip->clipType() == AUDIO) pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
1057 else if (clip->clipType() == IMAGE) pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->producer(), 0, width, height));
1058 else pix = item->referencedClip()->thumbProducer()->extractImage(frame, width, height);
1060 if (!pix.isNull()) {
1061 m_listView->blockSignals(true);
1062 it->setIcon(0, pix);
1063 if (m_listView->isEnabled()) m_listView->blockSignals(false);
1064 if (!isSubItem) m_doc->cachePixmap(item->getClipHash(), pix);
1065 else m_doc->cachePixmap(item->getClipHash() + '#' + QString::number(frame), pix);
1067 if (update) emit projectModified();
1068 QTimer::singleShot(30, this, SLOT(slotProcessNextThumbnail()));
1072 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace)
1074 ProjectItem *item = getItemById(clipId);
1075 if (item && producer) {
1076 m_listView->blockSignals(true);
1077 item->setProperties(properties, metadata);
1078 //Q_ASSERT_X(item->referencedClip(), "void ProjectList::slotReplyGetFileProperties", QString("Item with groupName %1 does not have a clip associated").arg(item->groupName()).toLatin1());
1079 item->referencedClip()->setProducer(producer, replace);
1080 //emit receivedClipDuration(clipId);
1081 if (m_listView->isEnabled() && replace) {
1082 // update clip in clip monitor
1083 emit clipSelected(NULL);
1084 emit clipSelected(item->referencedClip());
1087 // Check if duration changed.
1088 emit receivedClipDuration(clipId);
1091 if (m_listView->isEnabled()) m_listView->blockSignals(false);
1092 if (item->icon(0).isNull()) {
1093 requestClipThumbnail(clipId);
1095 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
1096 int max = m_doc->clipManager()->clipsCount();
1097 emit displayMessage(i18n("Loading clips"), (int)(100 *(max - m_infoQueue.count()) / max));
1098 // small delay so that the app can display the progress info
1099 if (item && m_infoQueue.isEmpty() && m_thumbnailQueue.isEmpty()) {
1100 m_listView->setCurrentItem(item);
1101 emit clipSelected(item->referencedClip());
1103 QTimer::singleShot(30, this, SLOT(slotProcessNextClipInQueue()));
1106 void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
1108 ProjectItem *item = getItemById(clipId);
1109 if (item && !pix.isNull()) {
1110 m_listView->blockSignals(true);
1111 item->setIcon(0, pix);
1112 m_doc->cachePixmap(item->getClipHash(), pix);
1113 if (m_listView->isEnabled()) m_listView->blockSignals(false);
1117 QTreeWidgetItem *ProjectList::getAnyItemById(const QString &id)
1119 QTreeWidgetItemIterator it(m_listView);
1120 QString lookId = id;
1121 if (id.contains('#')) {
1122 lookId = id.section('#', 0, 0);
1125 ProjectItem *result = NULL;
1127 if ((*it)->type() != PROJECTCLIPTYPE) {
1132 ProjectItem *item = static_cast<ProjectItem *>(*it);
1133 if (item->clipId() == lookId) {
1139 if (result == NULL || !id.contains('#')) return result;
1140 else for (int i = 0; i < result->childCount(); i++) {
1141 SubProjectItem *sub = static_cast <SubProjectItem *>(result->child(i));
1142 if (sub && sub->zone().x() == id.section('#', 1, 1).toInt()) {
1151 ProjectItem *ProjectList::getItemById(const QString &id)
1154 QTreeWidgetItemIterator it(m_listView);
1156 if ((*it)->type() != PROJECTCLIPTYPE) {
1161 item = static_cast<ProjectItem *>(*it);
1162 if (item->clipId() == id)
1169 FolderProjectItem *ProjectList::getFolderItemById(const QString &id)
1171 FolderProjectItem *item;
1172 QTreeWidgetItemIterator it(m_listView);
1174 if ((*it)->type() == PROJECTFOLDERTYPE) {
1175 item = static_cast<FolderProjectItem *>(*it);
1183 void ProjectList::slotSelectClip(const QString &ix)
1185 ProjectItem *clip = getItemById(ix);
1187 m_listView->setCurrentItem(clip);
1188 m_listView->scrollToItem(clip);
1189 m_editAction->setEnabled(true);
1190 m_deleteAction->setEnabled(true);
1191 m_reloadAction->setEnabled(true);
1192 m_transcodeAction->setEnabled(true);
1193 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
1194 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
1195 m_openAction->setEnabled(true);
1196 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
1197 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
1198 m_openAction->setEnabled(true);
1199 } else m_openAction->setEnabled(false);
1203 QString ProjectList::currentClipUrl() const
1206 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return QString();
1207 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
1209 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
1210 } else item = static_cast <ProjectItem*>(m_listView->currentItem());
1211 if (item == NULL) return QString();
1212 return item->clipUrl().path();
1215 void ProjectList::regenerateTemplate(const QString &id)
1217 ProjectItem *clip = getItemById(id);
1218 if (clip) regenerateTemplate(clip);
1221 void ProjectList::regenerateTemplate(ProjectItem *clip)
1223 //TODO: remove this unused method, only force_reload is necessary
1224 clip->referencedClip()->producer()->set("force_reload", 1);
1227 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
1231 if (!file.open(QIODevice::ReadOnly)) {
1232 kWarning() << "ERROR, CANNOT READ: " << path;
1235 if (!doc.setContent(&file)) {
1236 kWarning() << "ERROR, CANNOT READ: " << path;
1241 QDomNodeList texts = doc.elementsByTagName("content");
1242 for (int i = 0; i < texts.count(); i++) {
1243 QString data = texts.item(i).firstChild().nodeValue();
1244 data.replace("%s", replaceString);
1245 texts.item(i).firstChild().setNodeValue(data);
1251 void ProjectList::slotAddClipCut(const QString &id, int in, int out)
1253 ProjectItem *clip = getItemById(id);
1254 if (clip == NULL) return;
1255 if (clip->referencedClip()->hasCutZone(QPoint(in, out))) return;
1256 AddClipCutCommand *command = new AddClipCutCommand(this, id, in, out, false);
1257 m_commandStack->push(command);
1260 void ProjectList::addClipCut(const QString &id, int in, int out)
1262 ProjectItem *clip = getItemById(id);
1264 DocClipBase *base = clip->referencedClip();
1265 base->addCutZone(in, out);
1266 m_listView->blockSignals(true);
1267 SubProjectItem *sub = new SubProjectItem(clip, in, out);
1269 QPixmap p = clip->referencedClip()->thumbProducer()->extractImage(in, (int)(sub->sizeHint(0).height() * m_render->dar()), sub->sizeHint(0).height() - 2);
1271 m_doc->cachePixmap(clip->getClipHash() + '#' + QString::number(in), p);
1272 m_listView->blockSignals(false);
1276 void ProjectList::removeClipCut(const QString &id, int in, int out)
1278 ProjectItem *clip = getItemById(id);
1280 DocClipBase *base = clip->referencedClip();
1281 base->removeCutZone(in, out);
1282 for (int i = 0; i < clip->childCount(); i++) {
1283 QTreeWidgetItem *it = clip->child(i);
1284 if (it->type() != PROJECTSUBCLIPTYPE) continue;
1285 SubProjectItem *sub = static_cast <SubProjectItem*>(it);
1286 if (sub->zone() == QPoint(in, out)) {
1287 m_listView->blockSignals(true);
1289 m_listView->blockSignals(false);
1296 #include "projectlist.moc"