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 searchView->setTreeWidget(m_listView);
88 m_addButton = new QToolButton(m_toolbar);
89 m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
90 m_toolbar->addWidget(m_addButton);
92 layout->addWidget(m_toolbar);
93 layout->addWidget(m_listView);
96 m_queueTimer.setInterval(100);
97 connect(&m_queueTimer, SIGNAL(timeout()), this, SLOT(slotProcessNextClipInQueue()));
98 m_queueTimer.setSingleShot(true);
102 connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
103 connect(m_listView, SIGNAL(focusMonitor()), this, SLOT(slotClipSelected()));
104 connect(m_listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
105 connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
106 connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
107 connect(m_listView, SIGNAL(addClip(const QList <QUrl>, const QString &, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &, const QString &)));
108 connect(m_listView, SIGNAL(addClipCut(const QString &, int, int)), this, SLOT(slotAddClipCut(const QString &, int, int)));
109 connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
110 connect(m_listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
112 m_listViewDelegate = new ItemDelegate(m_listView);
113 m_listView->setItemDelegate(m_listViewDelegate);
115 if (KdenliveSettings::activate_nepomuk()) {
116 Nepomuk::ResourceManager::instance()->init();
117 if (!Nepomuk::ResourceManager::instance()->initialized()) {
118 kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
119 KdenliveSettings::setActivate_nepomuk(false);
124 ProjectList::~ProjectList()
128 m_listView->blockSignals(true);
130 delete m_listViewDelegate;
133 void ProjectList::focusTree() const
135 m_listView->setFocus();
138 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
140 QList <QAction *> actions = addMenu->actions();
141 for (int i = 0; i < actions.count(); i++) {
142 if (actions.at(i)->data().toString() == "clip_properties") {
143 m_editAction = actions.at(i);
144 m_toolbar->addAction(m_editAction);
147 } else if (actions.at(i)->data().toString() == "delete_clip") {
148 m_deleteAction = actions.at(i);
149 m_toolbar->addAction(m_deleteAction);
152 } else if (actions.at(i)->data().toString() == "edit_clip") {
153 m_openAction = actions.at(i);
156 } else if (actions.at(i)->data().toString() == "reload_clip") {
157 m_reloadAction = actions.at(i);
163 QMenu *m = new QMenu();
164 m->addActions(actions);
165 m_addButton->setMenu(m);
166 m_addButton->setDefaultAction(defaultAction);
167 m_menu = new QMenu();
168 m_menu->addActions(addMenu->actions());
171 void ProjectList::setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu)
173 if (!addMenu) return;
174 QMenu *menu = m_addButton->menu();
175 menu->addMenu(addMenu);
176 m_addButton->setMenu(menu);
178 m_menu->addMenu(addMenu);
179 if (addMenu->isEmpty()) addMenu->setEnabled(false);
180 m_menu->addMenu(transcodeMenu);
181 if (transcodeMenu->isEmpty()) transcodeMenu->setEnabled(false);
182 m_transcodeAction = transcodeMenu;
183 m_menu->addAction(m_reloadAction);
184 m_menu->addAction(m_editAction);
185 m_menu->addAction(m_openAction);
186 m_menu->addAction(m_deleteAction);
187 m_menu->insertSeparator(m_deleteAction);
191 QByteArray ProjectList::headerInfo() const
193 return m_listView->header()->saveState();
196 void ProjectList::setHeaderInfo(const QByteArray &state)
198 m_listView->header()->restoreState(state);
201 void ProjectList::slotEditClip()
204 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return;
205 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
206 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
207 } else item = static_cast <ProjectItem*>(m_listView->currentItem());
208 if (!(item->flags() & Qt::ItemIsDragEnabled)) return;
210 emit clipSelected(item->referencedClip());
211 emit showClipProperties(item->referencedClip());
215 void ProjectList::slotOpenClip()
218 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return;
219 if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1) {
220 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
221 } else item = static_cast <ProjectItem*>(m_listView->currentItem());
223 if (item->clipType() == IMAGE) {
224 if (KdenliveSettings::defaultimageapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open images in the Settings dialog"));
225 else QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
227 if (item->clipType() == AUDIO) {
228 if (KdenliveSettings::defaultaudioapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open audio files in the Settings dialog"));
229 else QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
234 void ProjectList::cleanup()
236 m_listView->clearSelection();
237 QTreeWidgetItemIterator it(m_listView);
240 if ((*it)->type() != PROJECTCLIPTYPE) {
244 item = static_cast <ProjectItem *>(*it);
245 if (item->numReferences() == 0) item->setSelected(true);
251 void ProjectList::trashUnusedClips()
253 QTreeWidgetItemIterator it(m_listView);
258 if ((*it)->type() != PROJECTCLIPTYPE) {
262 item = static_cast <ProjectItem *>(*it);
263 if (item->numReferences() == 0) {
264 ids << item->clipId();
265 KUrl url = item->clipUrl();
266 if (!url.isEmpty() && !urls.contains(url.path())) urls << url.path();
271 // Check that we don't use the URL in another clip
272 QTreeWidgetItemIterator it2(m_listView);
274 if ((*it2)->type() != PROJECTCLIPTYPE) {
278 item = static_cast <ProjectItem *>(*it2);
279 if (item->numReferences() > 0) {
280 KUrl url = item->clipUrl();
281 if (!url.isEmpty() && urls.contains(url.path())) urls.removeAll(url.path());
286 m_doc->deleteProjectClip(ids);
287 for (int i = 0; i < urls.count(); i++) {
288 KIO::NetAccess::del(KUrl(urls.at(i)), this);
292 void ProjectList::slotReloadClip(const QString &id)
294 QList<QTreeWidgetItem *> selected;
295 if (id.isEmpty()) selected = m_listView->selectedItems();
296 else selected.append(getItemById(id));
298 for (int i = 0; i < selected.count(); i++) {
299 if (selected.at(i)->type() != PROJECTCLIPTYPE) continue;
300 item = static_cast <ProjectItem *>(selected.at(i));
302 if (item->clipType() == IMAGE) {
303 item->referencedClip()->producer()->set("force_reload", 1);
304 } else if (item->clipType() == TEXT) {
305 if (!item->referencedClip()->getProperty("xmltemplate").isEmpty()) regenerateTemplate(item);
307 //requestClipInfo(item->toXml(), item->clipId(), true);
308 // Clear the file_hash value, which will cause a complete reload of the clip
309 emit getFileProperties(item->toXml(), item->clipId(), true);
314 void ProjectList::setRenderer(Render *projectRender)
316 m_render = projectRender;
317 m_listView->setIconSize(QSize(43 * m_render->dar(), 43));
320 void ProjectList::slotClipSelected()
322 if (m_listView->currentItem()) {
323 if (m_listView->currentItem()->type() == PROJECTFOLDERTYPE) {
324 emit clipSelected(NULL);
325 m_editAction->setEnabled(false);
326 m_deleteAction->setEnabled(true);
327 m_openAction->setEnabled(false);
328 m_reloadAction->setEnabled(false);
329 m_transcodeAction->setEnabled(false);
333 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
334 // this is a sub item, use base clip
335 clip = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
336 if (clip == NULL) kDebug() << "-----------ERROR";
337 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
338 emit clipSelected(clip->referencedClip(), sub->zone());
341 clip = static_cast <ProjectItem*>(m_listView->currentItem());
342 emit clipSelected(clip->referencedClip());
343 m_editAction->setEnabled(true);
344 m_deleteAction->setEnabled(true);
345 m_reloadAction->setEnabled(true);
346 m_transcodeAction->setEnabled(true);
347 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
348 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
349 m_openAction->setEnabled(true);
350 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
351 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
352 m_openAction->setEnabled(true);
353 } else m_openAction->setEnabled(false);
356 emit clipSelected(NULL);
357 m_editAction->setEnabled(false);
358 m_deleteAction->setEnabled(false);
359 m_openAction->setEnabled(false);
360 m_reloadAction->setEnabled(false);
361 m_transcodeAction->setEnabled(false);
365 void ProjectList::slotPauseMonitor()
367 if (m_render) m_render->pause();
370 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
372 ProjectItem *item = getItemById(id);
374 slotUpdateClipProperties(item, properties);
375 if (properties.contains("out")) {
377 } else if (properties.contains("colour") || properties.contains("resource") || properties.contains("xmldata") || properties.contains("force_aspect_ratio") || properties.contains("templatetext")) {
378 slotRefreshClipThumbnail(item);
384 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
387 clip->setProperties(properties);
388 if (properties.contains("name")) {
389 m_listView->blockSignals(true);
390 clip->setText(0, properties.value("name"));
391 m_listView->blockSignals(false);
392 emit clipNameChanged(clip->clipId(), properties.value("name"));
394 if (properties.contains("description")) {
395 CLIPTYPE type = clip->clipType();
396 m_listView->blockSignals(true);
397 clip->setText(1, properties.value("description"));
398 m_listView->blockSignals(false);
399 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
400 // Use Nepomuk system to store clip description
401 Nepomuk::Resource f(clip->clipUrl().path());
402 f.setDescription(properties.value("description"));
404 emit projectModified();
408 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
410 if (item->type() == PROJECTSUBCLIPTYPE) {
411 // this is a sub-item
414 if (item->type() == PROJECTFOLDERTYPE) {
415 if (column != 0) return;
416 FolderProjectItem *folder = static_cast <FolderProjectItem*>(item);
417 editFolder(item->text(0), folder->groupName(), folder->clipId());
418 folder->setGroupName(item->text(0));
419 m_doc->clipManager()->addFolder(folder->clipId(), item->text(0));
420 const int children = item->childCount();
421 for (int i = 0; i < children; i++) {
422 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
423 child->setProperty("groupname", item->text(0));
428 ProjectItem *clip = static_cast <ProjectItem*>(item);
430 if (clip->referencedClip()) {
431 QMap <QString, QString> oldprops;
432 QMap <QString, QString> newprops;
433 oldprops["description"] = clip->referencedClip()->getProperty("description");
434 newprops["description"] = item->text(1);
436 if (clip->clipType() == TEXT) {
437 // This is a text template clip, update the image
438 /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
439 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/
440 oldprops.insert("templatetext", clip->referencedClip()->getProperty("templatetext"));
441 newprops.insert("templatetext", item->text(1));
443 slotUpdateClipProperties(clip->clipId(), newprops);
444 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
445 m_commandStack->push(command);
447 } else if (column == 0) {
448 if (clip->referencedClip()) {
449 QMap <QString, QString> oldprops;
450 QMap <QString, QString> newprops;
451 oldprops["name"] = clip->referencedClip()->getProperty("name");
452 newprops["name"] = item->text(0);
453 slotUpdateClipProperties(clip, newprops);
454 emit projectModified();
455 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
456 m_commandStack->push(command);
461 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
467 m_editAction->setEnabled(enable);
468 m_deleteAction->setEnabled(enable);
469 m_reloadAction->setEnabled(enable);
470 m_transcodeAction->setEnabled(enable);
472 ProjectItem *clip = NULL;
473 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
474 clip = static_cast <ProjectItem*>(item->parent());
475 } else if (m_listView->currentItem()->type() == PROJECTCLIPTYPE) clip = static_cast <ProjectItem*>(item);
476 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
477 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
478 m_openAction->setEnabled(true);
479 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
480 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
481 m_openAction->setEnabled(true);
482 } else m_openAction->setEnabled(false);
483 } else m_openAction->setEnabled(false);
487 void ProjectList::slotRemoveClip()
489 if (!m_listView->currentItem()) return;
491 QMap <QString, QString> folderids;
492 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
494 QUndoCommand *delCommand = new QUndoCommand();
495 delCommand->setText(i18n("Delete Clip Zone"));
497 for (int i = 0; i < selected.count(); i++) {
498 if (selected.at(i)->type() == PROJECTSUBCLIPTYPE) {
500 SubProjectItem *sub = static_cast <SubProjectItem *>(selected.at(i));
501 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
502 new AddClipCutCommand(this, item->clipId(), sub->zone().x(), sub->zone().y(), true, delCommand);
506 if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
508 FolderProjectItem *folder = static_cast <FolderProjectItem *>(selected.at(i));
509 folderids[folder->groupName()] = folder->clipId();
510 int children = folder->childCount();
512 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;
513 for (int i = 0; i < children; ++i) {
514 ProjectItem *child = static_cast <ProjectItem *>(folder->child(i));
515 ids << child->clipId();
520 ProjectItem *item = static_cast <ProjectItem *>(selected.at(i));
521 ids << item->clipId();
522 if (item->numReferences() > 0) {
523 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;
526 if (delCommand->childCount() == 0) delete delCommand;
527 else m_commandStack->push(delCommand);
528 if (!ids.isEmpty()) m_doc->deleteProjectClip(ids);
529 if (!folderids.isEmpty()) deleteProjectFolder(folderids);
530 if (m_listView->topLevelItemCount() == 0) {
531 m_editAction->setEnabled(false);
532 m_deleteAction->setEnabled(false);
533 m_openAction->setEnabled(false);
534 m_reloadAction->setEnabled(false);
535 m_transcodeAction->setEnabled(false);
539 void ProjectList::selectItemById(const QString &clipId)
541 ProjectItem *item = getItemById(clipId);
542 if (item) m_listView->setCurrentItem(item);
546 void ProjectList::slotDeleteClip(const QString &clipId)
548 ProjectItem *item = getItemById(clipId);
550 kDebug() << "/// Cannot find clip to delete";
553 m_listView->blockSignals(true);
555 m_doc->clipManager()->deleteClip(clipId);
556 m_listView->blockSignals(false);
561 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
563 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
564 m_commandStack->push(command);
565 m_doc->setModified(true);
568 void ProjectList::slotAddFolder()
570 AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
571 m_commandStack->push(command);
574 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
577 FolderProjectItem *item = getFolderItemById(clipId);
579 m_doc->clipManager()->deleteFolder(clipId);
584 FolderProjectItem *item = getFolderItemById(clipId);
586 m_listView->blockSignals(true);
587 item->setGroupName(foldername);
588 m_listView->blockSignals(false);
589 m_doc->clipManager()->addFolder(clipId, foldername);
590 const int children = item->childCount();
591 for (int i = 0; i < children; i++) {
592 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
593 child->setProperty("groupname", foldername);
599 m_listView->blockSignals(true);
600 m_listView->setCurrentItem(new FolderProjectItem(m_listView, text, clipId));
601 m_doc->clipManager()->addFolder(clipId, foldername);
602 m_listView->blockSignals(false);
605 m_doc->setModified(true);
610 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
612 QMapIterator<QString, QString> i(map);
613 QUndoCommand *delCommand = new QUndoCommand();
614 delCommand->setText(i18n("Delete Folder"));
615 while (i.hasNext()) {
617 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
619 m_commandStack->push(delCommand);
622 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
624 m_listView->setEnabled(false);
626 m_listView->blockSignals(true);
628 // remove file_hash so that we load all properties for the clip
629 QDomElement e = clip->toXML().cloneNode().toElement();
630 e.removeAttribute("file_hash");
631 m_infoQueue.insert(clip->getId(), e);
632 //m_render->getFileProperties(clip->toXML(), clip->getId(), true);
634 const QString parent = clip->getProperty("groupid");
635 ProjectItem *item = NULL;
636 if (!parent.isEmpty()) {
637 FolderProjectItem *parentitem = getFolderItemById(parent);
640 QString groupName = clip->getProperty("groupname");
641 //kDebug() << "Adding clip to new group: " << groupName;
642 if (groupName.isEmpty()) groupName = i18n("Folder");
644 parentitem = new FolderProjectItem(m_listView, text, parent);
646 //kDebug() << "Adding clip to existing group: " << parentitem->groupName();
648 if (parentitem) item = new ProjectItem(parentitem, clip);
650 if (item == NULL) item = new ProjectItem(m_listView, clip);
651 KUrl url = clip->fileURL();
653 if (getProperties == false && !clip->getClipHash().isEmpty()) {
654 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
655 if (QFile::exists(cachedPixmap)) {
656 item->setIcon(0, QPixmap(cachedPixmap));
660 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
661 // if file has Nepomuk comment, use it
662 Nepomuk::Resource f(url.path());
663 QString annotation = f.description();
664 if (!annotation.isEmpty()) item->setText(1, annotation);
665 item->setText(2, QString::number(f.rating()));
669 QList <QPoint> cuts = clip->cutZones();
670 if (!cuts.isEmpty()) {
671 for (int i = 0; i < cuts.count(); i++) {
672 SubProjectItem *sub = new SubProjectItem(item, cuts.at(i).x(), cuts.at(i).y());
673 if (!clip->getClipHash().isEmpty()) {
674 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(cuts.at(i).x()) + ".png";
675 if (QFile::exists(cachedPixmap)) {
676 sub->setIcon(0, QPixmap(cachedPixmap));
682 if (getProperties && m_listView->isEnabled()) m_listView->blockSignals(false);
683 if (getProperties && !m_queueTimer.isActive()) m_queueTimer.start();
686 void ProjectList::slotResetProjectList()
689 emit clipSelected(NULL);
690 m_thumbnailQueue.clear();
695 void ProjectList::requestClipInfo(const QDomElement xml, const QString id)
698 m_infoQueue.insert(id, xml);
699 //if (m_infoQueue.count() == 1 || ) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
702 void ProjectList::slotProcessNextClipInQueue()
704 if (m_infoQueue.isEmpty()) {
705 slotProcessNextThumbnail();
709 QMap<QString, QDomElement>::const_iterator j = m_infoQueue.constBegin();
710 if (j != m_infoQueue.constEnd()) {
711 const QDomElement dom = j.value();
712 const QString id = j.key();
713 m_infoQueue.remove(j.key());
714 emit getFileProperties(dom, id, false);
718 void ProjectList::slotUpdateClip(const QString &id)
720 ProjectItem *item = getItemById(id);
721 m_listView->blockSignals(true);
722 if (item) item->setData(1, UsageRole, QString::number(item->numReferences()));
723 m_listView->blockSignals(false);
726 void ProjectList::updateAllClips()
728 m_listView->setSortingEnabled(false);
730 QTreeWidgetItemIterator it(m_listView);
733 m_listView->blockSignals(true);
735 if ((*it)->type() == PROJECTSUBCLIPTYPE) {
737 SubProjectItem *sub = static_cast <SubProjectItem *>(*it);
738 if (sub->icon(0).isNull()) {
739 item = static_cast <ProjectItem *>((*it)->parent());
740 requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x()));
744 } else if ((*it)->type() == PROJECTFOLDERTYPE) {
749 item = static_cast <ProjectItem *>(*it);
750 clip = item->referencedClip();
751 if (item->referencedClip()->producer() == NULL) {
752 if (clip->isPlaceHolder() == false) {
753 requestClipInfo(clip->toXML(), clip->getId());
754 } else item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
756 if (item->icon(0).isNull()) {
757 requestClipThumbnail(clip->getId());
759 if (item->data(0, DurationRole).toString().isEmpty()) {
760 item->changeDuration(item->referencedClip()->producer()->get_playtime());
763 item->setData(1, UsageRole, QString::number(item->numReferences()));
764 //qApp->processEvents();
767 qApp->processEvents();
768 if (!m_queueTimer.isActive()) m_queueTimer.start();
770 if (m_listView->isEnabled()) m_listView->blockSignals(false);
771 m_listView->setSortingEnabled(true);
772 if (m_infoQueue.isEmpty()) slotProcessNextThumbnail();
775 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
777 if (!m_commandStack) {
778 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
781 if (givenList.isEmpty()) {
782 // Build list of mime types
783 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";
785 QString allExtensions;
786 foreach(const QString& mimeType, mimeTypes) {
787 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
789 allExtensions.append(mime->patterns().join(" "));
790 allExtensions.append(' ');
793 const QString dialogFilter = allExtensions.simplified() + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
794 list = KFileDialog::getOpenUrls(KUrl("kfiledialog:///clipfolder"), dialogFilter, this);
797 for (int i = 0; i < givenList.count(); i++)
798 list << givenList.at(i);
800 if (list.isEmpty()) return;
802 if (givenList.isEmpty()) {
803 QStringList groupInfo = getGroup();
804 m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1));
805 } else m_doc->slotAddClipList(list, groupName, groupId);
808 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
810 ProjectItem *item = getItemById(id);
811 QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
813 const QString path = item->referencedClip()->fileURL().path();
814 if (!path.isEmpty()) {
815 if (replace) KMessageBox::sorry(this, i18n("Clip <b>%1</b><br>is invalid, will be removed from project.", path));
817 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;
822 if (replace) m_doc->deleteProjectClip(ids);
826 void ProjectList::slotAddColorClip()
828 if (!m_commandStack) {
829 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
831 QDialog *dia = new QDialog(this);
832 Ui::ColorClip_UI dia_ui;
834 dia_ui.clip_name->setText(i18n("Color Clip"));
835 dia_ui.clip_duration->setText(KdenliveSettings::color_duration());
836 if (dia->exec() == QDialog::Accepted) {
837 QString color = dia_ui.clip_color->color().name();
838 color = color.replace(0, 1, "0x") + "ff";
839 QStringList groupInfo = getGroup();
840 m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, dia_ui.clip_duration->text(), groupInfo.at(0), groupInfo.at(1));
846 void ProjectList::slotAddSlideshowClip()
848 if (!m_commandStack) {
849 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
851 SlideshowClip *dia = new SlideshowClip(m_timecode, this);
853 if (dia->exec() == QDialog::Accepted) {
854 QStringList groupInfo = getGroup();
855 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));
860 void ProjectList::slotAddTitleClip()
862 QStringList groupInfo = getGroup();
863 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
866 void ProjectList::slotAddTitleTemplateClip()
868 QStringList groupInfo = getGroup();
869 if (!m_commandStack) {
870 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
873 // Get the list of existing templates
875 filter << "*.kdenlivetitle";
876 const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
877 QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
879 QDialog *dia = new QDialog(this);
880 Ui::TemplateClip_UI dia_ui;
882 for (int i = 0; i < templateFiles.size(); ++i) {
883 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
885 dia_ui.template_list->fileDialog()->setFilter("*.kdenlivetitle");
886 //warning: setting base directory doesn't work??
888 dia_ui.template_list->fileDialog()->setUrl(startDir);
889 dia_ui.text_box->setHidden(true);
890 if (dia->exec() == QDialog::Accepted) {
891 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
892 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
893 // Create a cloned template clip
894 m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
899 QStringList ProjectList::getGroup() const
902 QTreeWidgetItem *item = m_listView->currentItem();
903 while (item && item->type() != PROJECTFOLDERTYPE) {
904 item = item->parent();
908 FolderProjectItem *folder = static_cast <FolderProjectItem *>(item);
909 result << folder->groupName();
910 result << folder->clipId();
911 } else result << QString() << QString();
915 void ProjectList::setDocument(KdenliveDoc *doc)
917 m_listView->blockSignals(true);
919 m_listView->setSortingEnabled(false);
920 emit clipSelected(NULL);
921 m_thumbnailQueue.clear();
925 m_timecode = doc->timecode();
926 m_commandStack = doc->commandStack();
929 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
930 QMapIterator<QString, QString> f(flist);
931 while (f.hasNext()) {
933 (void) new FolderProjectItem(m_listView, QStringList() << f.value(), f.key());
936 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
937 for (int i = 0; i < list.count(); i++) {
938 slotAddClip(list.at(i), false);
941 m_listView->blockSignals(false);
942 m_toolbar->setEnabled(true);
943 connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
944 connect(m_doc->clipManager(), SIGNAL(checkAllClips()), this, SLOT(updateAllClips()));
947 QList <DocClipBase*> ProjectList::documentClipList() const
949 if (m_doc == NULL) return QList <DocClipBase*> ();
950 return m_doc->clipManager()->documentClipList();
953 QDomElement ProjectList::producersList()
956 QDomElement prods = doc.createElement("producerlist");
957 doc.appendChild(prods);
958 kDebug() << "//////////// PRO LISTÂ BUILD PRDSLIST ";
959 QTreeWidgetItemIterator it(m_listView);
961 if ((*it)->type() != PROJECTCLIPTYPE) {
966 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
972 void ProjectList::slotCheckForEmptyQueue()
974 if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
976 emit loadingIsOver();
977 emit displayMessage(QString(), -1);
978 m_listView->blockSignals(false);
979 m_listView->setEnabled(true);
980 } else if (!m_refreshed) QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
983 void ProjectList::reloadClipThumbnails()
985 kDebug() << "////////////// RELOAD CLIPS THUMBNAILS!!!";
986 m_thumbnailQueue.clear();
987 QTreeWidgetItemIterator it(m_listView);
989 if ((*it)->type() != PROJECTCLIPTYPE) {
994 m_thumbnailQueue << ((ProjectItem *)(*it))->clipId();
997 QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
1000 void ProjectList::requestClipThumbnail(const QString id)
1002 if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id);
1005 void ProjectList::slotProcessNextThumbnail()
1007 if (m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
1008 slotCheckForEmptyQueue();
1011 if (!m_infoQueue.isEmpty()) {
1012 //QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
1015 if (m_thumbnailQueue.count() > 1) {
1016 int max = m_doc->clipManager()->clipsCount();
1017 emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - m_thumbnailQueue.count()) / max));
1019 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
1022 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
1024 QTreeWidgetItem *item = getAnyItemById(clipId);
1025 if (item) slotRefreshClipThumbnail(item, update);
1026 else slotProcessNextThumbnail();
1029 void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
1031 if (it == NULL) return;
1032 ProjectItem *item = NULL;
1033 bool isSubItem = false;
1035 if (it->type() == PROJECTFOLDERTYPE) return;
1036 if (it->type() == PROJECTSUBCLIPTYPE) {
1037 item = static_cast <ProjectItem *>(it->parent());
1038 frame = static_cast <SubProjectItem *>(it)->zone().x();
1041 item = static_cast <ProjectItem *>(it);
1042 frame = item->referencedClip()->getClipThumbFrame();
1046 DocClipBase *clip = item->referencedClip();
1048 slotProcessNextThumbnail();
1052 int height = it->sizeHint(0).height();
1053 int width = (int)(height * m_render->dar());
1054 if (clip->clipType() == AUDIO) pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
1055 else if (clip->clipType() == IMAGE) pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->producer(), 0, width, height));
1056 else pix = item->referencedClip()->thumbProducer()->extractImage(frame, width, height);
1058 if (!pix.isNull()) {
1059 m_listView->blockSignals(true);
1060 it->setIcon(0, pix);
1061 if (m_listView->isEnabled()) m_listView->blockSignals(false);
1062 if (!isSubItem) m_doc->cachePixmap(item->getClipHash(), pix);
1063 else m_doc->cachePixmap(item->getClipHash() + '#' + QString::number(frame), pix);
1065 if (update) emit projectModified();
1066 QTimer::singleShot(30, this, SLOT(slotProcessNextThumbnail()));
1070 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace)
1072 ProjectItem *item = getItemById(clipId);
1073 if (item && producer) {
1074 m_listView->blockSignals(true);
1075 item->setProperties(properties, metadata);
1076 //Q_ASSERT_X(item->referencedClip(), "void ProjectList::slotReplyGetFileProperties", QString("Item with groupName %1 does not have a clip associated").arg(item->groupName()).toLatin1());
1077 item->referencedClip()->setProducer(producer, replace);
1078 //emit receivedClipDuration(clipId);
1079 if (m_listView->isEnabled() && replace) {
1080 // update clip in clip monitor
1081 emit clipSelected(NULL);
1082 emit clipSelected(item->referencedClip());
1085 // Check if duration changed.
1086 emit receivedClipDuration(clipId);
1089 if (m_listView->isEnabled()) m_listView->blockSignals(false);
1090 if (item->icon(0).isNull()) {
1091 requestClipThumbnail(clipId);
1093 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
1094 int max = m_doc->clipManager()->clipsCount();
1095 emit displayMessage(i18n("Loading clips"), (int)(100 *(max - m_infoQueue.count()) / max));
1096 // small delay so that the app can display the progress info
1097 if (item && m_infoQueue.isEmpty() && m_thumbnailQueue.isEmpty()) {
1098 m_listView->setCurrentItem(item);
1099 emit clipSelected(item->referencedClip());
1101 QTimer::singleShot(30, this, SLOT(slotProcessNextClipInQueue()));
1104 void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
1106 ProjectItem *item = getItemById(clipId);
1107 if (item && !pix.isNull()) {
1108 m_listView->blockSignals(true);
1109 item->setIcon(0, pix);
1110 m_doc->cachePixmap(item->getClipHash(), pix);
1111 if (m_listView->isEnabled()) m_listView->blockSignals(false);
1115 QTreeWidgetItem *ProjectList::getAnyItemById(const QString &id)
1117 QTreeWidgetItemIterator it(m_listView);
1118 QString lookId = id;
1119 if (id.contains('#')) {
1120 lookId = id.section('#', 0, 0);
1123 ProjectItem *result = NULL;
1125 if ((*it)->type() != PROJECTCLIPTYPE) {
1130 ProjectItem *item = static_cast<ProjectItem *>(*it);
1131 if (item->clipId() == lookId) {
1137 if (result == NULL || !id.contains('#')) return result;
1138 else for (int i = 0; i < result->childCount(); i++) {
1139 SubProjectItem *sub = static_cast <SubProjectItem *>(result->child(i));
1140 if (sub && sub->zone().x() == id.section('#', 1, 1).toInt()) {
1149 ProjectItem *ProjectList::getItemById(const QString &id)
1152 QTreeWidgetItemIterator it(m_listView);
1154 if ((*it)->type() != PROJECTCLIPTYPE) {
1159 item = static_cast<ProjectItem *>(*it);
1160 if (item->clipId() == id)
1167 FolderProjectItem *ProjectList::getFolderItemById(const QString &id)
1169 FolderProjectItem *item;
1170 QTreeWidgetItemIterator it(m_listView);
1172 if ((*it)->type() == PROJECTFOLDERTYPE) {
1173 item = static_cast<FolderProjectItem *>(*it);
1181 void ProjectList::slotSelectClip(const QString &ix)
1183 ProjectItem *clip = getItemById(ix);
1185 m_listView->setCurrentItem(clip);
1186 m_listView->scrollToItem(clip);
1187 m_editAction->setEnabled(true);
1188 m_deleteAction->setEnabled(true);
1189 m_reloadAction->setEnabled(true);
1190 m_transcodeAction->setEnabled(true);
1191 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
1192 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
1193 m_openAction->setEnabled(true);
1194 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
1195 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
1196 m_openAction->setEnabled(true);
1197 } else m_openAction->setEnabled(false);
1201 QString ProjectList::currentClipUrl() const
1204 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return QString();
1205 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
1207 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
1208 } else item = static_cast <ProjectItem*>(m_listView->currentItem());
1209 if (item == NULL) return QString();
1210 return item->clipUrl().path();
1213 void ProjectList::regenerateTemplate(const QString &id)
1215 ProjectItem *clip = getItemById(id);
1216 if (clip) regenerateTemplate(clip);
1219 void ProjectList::regenerateTemplate(ProjectItem *clip)
1221 //TODO: remove this unused method, only force_reload is necessary
1222 clip->referencedClip()->producer()->set("force_reload", 1);
1225 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
1229 if (!file.open(QIODevice::ReadOnly)) {
1230 kWarning() << "ERROR, CANNOT READ: " << path;
1233 if (!doc.setContent(&file)) {
1234 kWarning() << "ERROR, CANNOT READ: " << path;
1239 QDomNodeList texts = doc.elementsByTagName("content");
1240 for (int i = 0; i < texts.count(); i++) {
1241 QString data = texts.item(i).firstChild().nodeValue();
1242 data.replace("%s", replaceString);
1243 texts.item(i).firstChild().setNodeValue(data);
1249 void ProjectList::slotAddClipCut(const QString &id, int in, int out)
1251 ProjectItem *clip = getItemById(id);
1252 if (clip == NULL) return;
1253 if (clip->referencedClip()->hasCutZone(QPoint(in, out))) return;
1254 AddClipCutCommand *command = new AddClipCutCommand(this, id, in, out, false);
1255 m_commandStack->push(command);
1258 void ProjectList::addClipCut(const QString &id, int in, int out)
1260 ProjectItem *clip = getItemById(id);
1262 DocClipBase *base = clip->referencedClip();
1263 base->addCutZone(in, out);
1264 m_listView->blockSignals(true);
1265 SubProjectItem *sub = new SubProjectItem(clip, in, out);
1267 QPixmap p = clip->referencedClip()->thumbProducer()->extractImage(in, (int)(sub->sizeHint(0).height() * m_render->dar()), sub->sizeHint(0).height() - 2);
1269 m_doc->cachePixmap(clip->getClipHash() + '#' + QString::number(in), p);
1270 m_listView->blockSignals(false);
1274 void ProjectList::removeClipCut(const QString &id, int in, int out)
1276 ProjectItem *clip = getItemById(id);
1278 DocClipBase *base = clip->referencedClip();
1279 base->removeCutZone(in, out);
1280 for (int i = 0; i < clip->childCount(); i++) {
1281 QTreeWidgetItem *it = clip->child(i);
1282 if (it->type() != PROJECTSUBCLIPTYPE) continue;
1283 SubProjectItem *sub = static_cast <SubProjectItem*>(it);
1284 if (sub->zone() == QPoint(in, out)) {
1285 m_listView->blockSignals(true);
1287 m_listView->blockSignals(false);
1294 #include "projectlist.moc"