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() && m_listView->currentItem()->type() != PROJECTFOLDERTYPE) {
324 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
325 // this is a sub item, use base clip
326 clip = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
327 if (clip == NULL) kDebug() << "-----------ERROR";
328 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
329 emit clipSelected(clip->referencedClip(), sub->zone());
332 clip = static_cast <ProjectItem*>(m_listView->currentItem());
333 emit clipSelected(clip->referencedClip());
334 m_editAction->setEnabled(true);
335 m_deleteAction->setEnabled(true);
336 m_reloadAction->setEnabled(true);
337 m_transcodeAction->setEnabled(true);
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);
346 emit clipSelected(NULL);
347 m_editAction->setEnabled(false);
348 m_deleteAction->setEnabled(false);
349 m_openAction->setEnabled(false);
350 m_reloadAction->setEnabled(false);
351 m_transcodeAction->setEnabled(false);
355 void ProjectList::slotPauseMonitor()
357 if (m_render) m_render->pause();
360 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
362 ProjectItem *item = getItemById(id);
364 slotUpdateClipProperties(item, properties);
365 if (properties.contains("out")) {
367 } else if (properties.contains("colour") || properties.contains("resource") || properties.contains("xmldata") || properties.contains("force_aspect_ratio") || properties.contains("templatetext")) {
368 slotRefreshClipThumbnail(item);
374 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
377 clip->setProperties(properties);
378 if (properties.contains("name")) {
379 m_listView->blockSignals(true);
380 clip->setText(0, properties.value("name"));
381 m_listView->blockSignals(false);
382 emit clipNameChanged(clip->clipId(), properties.value("name"));
384 if (properties.contains("description")) {
385 CLIPTYPE type = clip->clipType();
386 m_listView->blockSignals(true);
387 clip->setText(1, properties.value("description"));
388 m_listView->blockSignals(false);
389 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
390 // Use Nepomuk system to store clip description
391 Nepomuk::Resource f(clip->clipUrl().path());
392 f.setDescription(properties.value("description"));
394 emit projectModified();
398 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
400 if (item->type() == PROJECTSUBCLIPTYPE) {
401 // this is a sub-item
404 if (item->type() == PROJECTFOLDERTYPE) {
405 if (column != 0) return;
406 FolderProjectItem *folder = static_cast <FolderProjectItem*>(item);
407 editFolder(item->text(1), folder->groupName(), folder->clipId());
408 folder->setGroupName(item->text(0));
409 m_doc->clipManager()->addFolder(folder->clipId(), item->text(1));
410 const int children = item->childCount();
411 for (int i = 0; i < children; i++) {
412 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
413 child->setProperty("groupname", item->text(0));
418 ProjectItem *clip = static_cast <ProjectItem*>(item);
420 if (clip->referencedClip()) {
421 QMap <QString, QString> oldprops;
422 QMap <QString, QString> newprops;
423 oldprops["description"] = clip->referencedClip()->getProperty("description");
424 newprops["description"] = item->text(1);
426 if (clip->clipType() == TEXT) {
427 // This is a text template clip, update the image
428 /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
429 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/
430 oldprops.insert("templatetext", clip->referencedClip()->getProperty("templatetext"));
431 newprops.insert("templatetext", item->text(1));
433 slotUpdateClipProperties(clip->clipId(), newprops);
434 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
435 m_commandStack->push(command);
437 } else if (column == 0) {
438 if (clip->referencedClip()) {
439 QMap <QString, QString> oldprops;
440 QMap <QString, QString> newprops;
441 oldprops["name"] = clip->referencedClip()->getProperty("name");
442 newprops["name"] = item->text(0);
443 slotUpdateClipProperties(clip, newprops);
444 emit projectModified();
445 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
446 m_commandStack->push(command);
451 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
457 m_editAction->setEnabled(enable);
458 m_deleteAction->setEnabled(enable);
459 m_reloadAction->setEnabled(enable);
460 m_transcodeAction->setEnabled(enable);
462 ProjectItem *clip = NULL;
463 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
464 clip = static_cast <ProjectItem*>(item->parent());
465 } else if (m_listView->currentItem()->type() == PROJECTCLIPTYPE) clip = static_cast <ProjectItem*>(item);
466 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
467 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
468 m_openAction->setEnabled(true);
469 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
470 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
471 m_openAction->setEnabled(true);
472 } else m_openAction->setEnabled(false);
473 } else m_openAction->setEnabled(false);
477 void ProjectList::slotRemoveClip()
479 if (!m_listView->currentItem()) return;
481 QMap <QString, QString> folderids;
482 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
484 QUndoCommand *delCommand = new QUndoCommand();
485 delCommand->setText(i18n("Delete Clip Zone"));
487 for (int i = 0; i < selected.count(); i++) {
488 if (selected.at(i)->type() == PROJECTSUBCLIPTYPE) {
490 SubProjectItem *sub = static_cast <SubProjectItem *>(selected.at(i));
491 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
492 new AddClipCutCommand(this, item->clipId(), sub->zone().x(), sub->zone().y(), true, delCommand);
496 if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
498 FolderProjectItem *folder = static_cast <FolderProjectItem *>(selected.at(i));
499 folderids[folder->groupName()] = folder->clipId();
500 int children = folder->childCount();
502 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;
503 for (int i = 0; i < children; ++i) {
504 ProjectItem *child = static_cast <ProjectItem *>(folder->child(i));
505 ids << child->clipId();
510 ProjectItem *item = static_cast <ProjectItem *>(selected.at(i));
511 ids << item->clipId();
512 if (item->numReferences() > 0) {
513 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;
516 if (delCommand->childCount() == 0) delete delCommand;
517 else m_commandStack->push(delCommand);
518 if (!ids.isEmpty()) m_doc->deleteProjectClip(ids);
519 if (!folderids.isEmpty()) deleteProjectFolder(folderids);
520 if (m_listView->topLevelItemCount() == 0) {
521 m_editAction->setEnabled(false);
522 m_deleteAction->setEnabled(false);
523 m_openAction->setEnabled(false);
524 m_reloadAction->setEnabled(false);
525 m_transcodeAction->setEnabled(false);
529 void ProjectList::selectItemById(const QString &clipId)
531 ProjectItem *item = getItemById(clipId);
532 if (item) m_listView->setCurrentItem(item);
536 void ProjectList::slotDeleteClip(const QString &clipId)
538 ProjectItem *item = getItemById(clipId);
540 kDebug() << "/// Cannot find clip to delete";
543 m_listView->blockSignals(true);
545 m_doc->clipManager()->deleteClip(clipId);
546 m_listView->blockSignals(false);
551 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
553 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
554 m_commandStack->push(command);
555 m_doc->setModified(true);
558 void ProjectList::slotAddFolder()
560 AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
561 m_commandStack->push(command);
564 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
567 FolderProjectItem *item = getFolderItemById(clipId);
569 m_doc->clipManager()->deleteFolder(clipId);
574 FolderProjectItem *item = getFolderItemById(clipId);
576 m_listView->blockSignals(true);
577 item->setGroupName(foldername);
578 m_listView->blockSignals(false);
579 m_doc->clipManager()->addFolder(clipId, foldername);
580 const int children = item->childCount();
581 for (int i = 0; i < children; i++) {
582 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
583 child->setProperty("groupname", foldername);
589 m_listView->blockSignals(true);
590 m_listView->setCurrentItem(new FolderProjectItem(m_listView, text, clipId));
591 m_doc->clipManager()->addFolder(clipId, foldername);
592 m_listView->blockSignals(false);
599 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
601 QMapIterator<QString, QString> i(map);
602 QUndoCommand *delCommand = new QUndoCommand();
603 delCommand->setText(i18n("Delete Folder"));
604 while (i.hasNext()) {
606 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
608 m_commandStack->push(delCommand);
609 m_doc->setModified(true);
612 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
614 m_listView->setEnabled(false);
616 m_listView->blockSignals(true);
618 // remove file_hash so that we load all properties for the clip
619 QDomElement e = clip->toXML().cloneNode().toElement();
620 e.removeAttribute("file_hash");
621 m_infoQueue.insert(clip->getId(), e);
622 //m_render->getFileProperties(clip->toXML(), clip->getId(), true);
624 const QString parent = clip->getProperty("groupid");
625 ProjectItem *item = NULL;
626 if (!parent.isEmpty()) {
627 FolderProjectItem *parentitem = getFolderItemById(parent);
630 QString groupName = clip->getProperty("groupname");
631 //kDebug() << "Adding clip to new group: " << groupName;
632 if (groupName.isEmpty()) groupName = i18n("Folder");
634 parentitem = new FolderProjectItem(m_listView, text, parent);
636 //kDebug() << "Adding clip to existing group: " << parentitem->groupName();
638 if (parentitem) item = new ProjectItem(parentitem, clip);
640 if (item == NULL) item = new ProjectItem(m_listView, clip);
641 KUrl url = clip->fileURL();
643 if (getProperties == false && !clip->getClipHash().isEmpty()) {
644 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
645 if (QFile::exists(cachedPixmap)) {
646 item->setIcon(0, QPixmap(cachedPixmap));
650 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
651 // if file has Nepomuk comment, use it
652 Nepomuk::Resource f(url.path());
653 QString annotation = f.description();
654 if (!annotation.isEmpty()) item->setText(1, annotation);
655 item->setText(2, QString::number(f.rating()));
659 QList <QPoint> cuts = clip->cutZones();
660 if (!cuts.isEmpty()) {
661 for (int i = 0; i < cuts.count(); i++) {
662 SubProjectItem *sub = new SubProjectItem(item, cuts.at(i).x(), cuts.at(i).y());
663 if (!clip->getClipHash().isEmpty()) {
664 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(cuts.at(i).x()) + ".png";
665 if (QFile::exists(cachedPixmap)) {
666 sub->setIcon(0, QPixmap(cachedPixmap));
672 if (getProperties && m_listView->isEnabled()) m_listView->blockSignals(false);
673 if (getProperties && !m_queueTimer.isActive()) m_queueTimer.start();
676 void ProjectList::slotResetProjectList()
679 emit clipSelected(NULL);
680 m_thumbnailQueue.clear();
685 void ProjectList::requestClipInfo(const QDomElement xml, const QString id)
688 m_infoQueue.insert(id, xml);
689 //if (m_infoQueue.count() == 1 || ) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
692 void ProjectList::slotProcessNextClipInQueue()
694 if (m_infoQueue.isEmpty()) {
695 slotProcessNextThumbnail();
699 QMap<QString, QDomElement>::const_iterator j = m_infoQueue.constBegin();
700 if (j != m_infoQueue.constEnd()) {
701 const QDomElement dom = j.value();
702 const QString id = j.key();
703 m_infoQueue.remove(j.key());
704 emit getFileProperties(dom, id, false);
708 void ProjectList::slotUpdateClip(const QString &id)
710 ProjectItem *item = getItemById(id);
711 m_listView->blockSignals(true);
712 if (item) item->setData(1, UsageRole, QString::number(item->numReferences()));
713 m_listView->blockSignals(false);
716 void ProjectList::updateAllClips()
718 m_listView->setSortingEnabled(false);
720 QTreeWidgetItemIterator it(m_listView);
723 m_listView->blockSignals(true);
725 if ((*it)->type() == PROJECTSUBCLIPTYPE) {
727 SubProjectItem *sub = static_cast <SubProjectItem *>(*it);
728 if (sub->icon(0).isNull()) {
729 item = static_cast <ProjectItem *>((*it)->parent());
730 requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x()));
734 } else if ((*it)->type() == PROJECTFOLDERTYPE) {
739 item = static_cast <ProjectItem *>(*it);
740 clip = item->referencedClip();
741 if (item->referencedClip()->producer() == NULL) {
742 if (clip->isPlaceHolder() == false) {
743 requestClipInfo(clip->toXML(), clip->getId());
744 } else item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
746 if (item->icon(0).isNull()) {
747 requestClipThumbnail(clip->getId());
749 if (item->data(0, DurationRole).toString().isEmpty()) {
750 item->changeDuration(item->referencedClip()->producer()->get_playtime());
753 item->setData(1, UsageRole, QString::number(item->numReferences()));
754 //qApp->processEvents();
757 qApp->processEvents();
758 if (!m_queueTimer.isActive()) m_queueTimer.start();
760 if (m_listView->isEnabled()) m_listView->blockSignals(false);
761 m_listView->setSortingEnabled(true);
762 if (m_infoQueue.isEmpty()) slotProcessNextThumbnail();
765 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
767 if (!m_commandStack) {
768 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
771 if (givenList.isEmpty()) {
772 // Build list of mime types
773 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";
775 QString allExtensions;
776 foreach(const QString& mimeType, mimeTypes) {
777 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
779 allExtensions.append(mime->patterns().join(" "));
780 allExtensions.append(' ');
783 const QString dialogFilter = allExtensions.simplified() + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
784 list = KFileDialog::getOpenUrls(KUrl("kfiledialog:///clipfolder"), dialogFilter, this);
787 for (int i = 0; i < givenList.count(); i++)
788 list << givenList.at(i);
790 if (list.isEmpty()) return;
792 if (givenList.isEmpty()) {
793 QStringList groupInfo = getGroup();
794 m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1));
795 } else m_doc->slotAddClipList(list, groupName, groupId);
798 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
800 ProjectItem *item = getItemById(id);
801 QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
803 const QString path = item->referencedClip()->fileURL().path();
804 if (!path.isEmpty()) {
805 if (replace) KMessageBox::sorry(this, i18n("Clip <b>%1</b><br>is invalid, will be removed from project.", path));
807 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;
812 if (replace) m_doc->deleteProjectClip(ids);
816 void ProjectList::slotAddColorClip()
818 if (!m_commandStack) {
819 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
821 QDialog *dia = new QDialog(this);
822 Ui::ColorClip_UI dia_ui;
824 dia_ui.clip_name->setText(i18n("Color Clip"));
825 dia_ui.clip_duration->setText(KdenliveSettings::color_duration());
826 if (dia->exec() == QDialog::Accepted) {
827 QString color = dia_ui.clip_color->color().name();
828 color = color.replace(0, 1, "0x") + "ff";
829 QStringList groupInfo = getGroup();
830 m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, dia_ui.clip_duration->text(), groupInfo.at(0), groupInfo.at(1));
836 void ProjectList::slotAddSlideshowClip()
838 if (!m_commandStack) {
839 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
841 SlideshowClip *dia = new SlideshowClip(m_timecode, this);
843 if (dia->exec() == QDialog::Accepted) {
844 QStringList groupInfo = getGroup();
845 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));
850 void ProjectList::slotAddTitleClip()
852 QStringList groupInfo = getGroup();
853 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
856 void ProjectList::slotAddTitleTemplateClip()
858 QStringList groupInfo = getGroup();
859 if (!m_commandStack) {
860 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
863 // Get the list of existing templates
865 filter << "*.kdenlivetitle";
866 const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
867 QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
869 QDialog *dia = new QDialog(this);
870 Ui::TemplateClip_UI dia_ui;
872 for (int i = 0; i < templateFiles.size(); ++i) {
873 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
875 dia_ui.template_list->fileDialog()->setFilter("*.kdenlivetitle");
876 //warning: setting base directory doesn't work??
878 dia_ui.template_list->fileDialog()->setUrl(startDir);
879 dia_ui.text_box->setHidden(true);
880 if (dia->exec() == QDialog::Accepted) {
881 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
882 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
883 // Create a cloned template clip
884 m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
889 QStringList ProjectList::getGroup() const
892 QTreeWidgetItem *item = m_listView->currentItem();
893 while (item && item->type() != PROJECTFOLDERTYPE) {
894 item = item->parent();
898 FolderProjectItem *folder = static_cast <FolderProjectItem *>(item);
899 result << folder->groupName();
900 result << folder->clipId();
901 } else result << QString() << QString();
905 void ProjectList::setDocument(KdenliveDoc *doc)
907 m_listView->blockSignals(true);
909 m_listView->setSortingEnabled(false);
910 emit clipSelected(NULL);
911 m_thumbnailQueue.clear();
915 m_timecode = doc->timecode();
916 m_commandStack = doc->commandStack();
919 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
920 QMapIterator<QString, QString> f(flist);
921 while (f.hasNext()) {
923 (void) new FolderProjectItem(m_listView, QStringList() << f.value(), f.key());
926 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
927 for (int i = 0; i < list.count(); i++) {
928 slotAddClip(list.at(i), false);
931 m_listView->blockSignals(false);
932 m_toolbar->setEnabled(true);
933 connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
934 connect(m_doc->clipManager(), SIGNAL(checkAllClips()), this, SLOT(updateAllClips()));
937 QList <DocClipBase*> ProjectList::documentClipList() const
939 if (m_doc == NULL) return QList <DocClipBase*> ();
940 return m_doc->clipManager()->documentClipList();
943 QDomElement ProjectList::producersList()
946 QDomElement prods = doc.createElement("producerlist");
947 doc.appendChild(prods);
948 kDebug() << "//////////// PRO LISTÂ BUILD PRDSLIST ";
949 QTreeWidgetItemIterator it(m_listView);
951 if ((*it)->type() != PROJECTCLIPTYPE) {
956 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
962 void ProjectList::slotCheckForEmptyQueue()
964 if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
966 emit loadingIsOver();
967 emit displayMessage(QString(), -1);
968 m_listView->blockSignals(false);
969 m_listView->setEnabled(true);
970 } else if (!m_refreshed) QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
973 void ProjectList::reloadClipThumbnails()
975 kDebug() << "////////////// RELOAD CLIPS THUMBNAILS!!!";
976 m_thumbnailQueue.clear();
977 QTreeWidgetItemIterator it(m_listView);
979 if ((*it)->type() != PROJECTCLIPTYPE) {
984 m_thumbnailQueue << ((ProjectItem *)(*it))->clipId();
987 QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
990 void ProjectList::requestClipThumbnail(const QString id)
992 if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id);
995 void ProjectList::slotProcessNextThumbnail()
997 if (m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
998 slotCheckForEmptyQueue();
1001 if (!m_infoQueue.isEmpty()) {
1002 //QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
1005 if (m_thumbnailQueue.count() > 1) {
1006 int max = m_doc->clipManager()->clipsCount();
1007 emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - m_thumbnailQueue.count()) / max));
1009 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
1012 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
1014 QTreeWidgetItem *item = getAnyItemById(clipId);
1015 if (item) slotRefreshClipThumbnail(item, update);
1016 else slotProcessNextThumbnail();
1019 void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
1021 if (it == NULL) return;
1022 ProjectItem *item = NULL;
1023 bool isSubItem = false;
1025 if (it->type() == PROJECTFOLDERTYPE) return;
1026 if (it->type() == PROJECTSUBCLIPTYPE) {
1027 item = static_cast <ProjectItem *>(it->parent());
1028 frame = static_cast <SubProjectItem *>(it)->zone().x();
1031 item = static_cast <ProjectItem *>(it);
1032 frame = item->referencedClip()->getClipThumbFrame();
1036 DocClipBase *clip = item->referencedClip();
1038 slotProcessNextThumbnail();
1042 int height = it->sizeHint(0).height();
1043 int width = (int)(height * m_render->dar());
1044 if (clip->clipType() == AUDIO) pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
1045 else if (clip->clipType() == IMAGE) pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->producer(), 0, width, height));
1046 else pix = item->referencedClip()->thumbProducer()->extractImage(frame, width, height);
1048 if (!pix.isNull()) {
1049 m_listView->blockSignals(true);
1050 it->setIcon(0, pix);
1051 if (m_listView->isEnabled()) m_listView->blockSignals(false);
1052 if (!isSubItem) m_doc->cachePixmap(item->getClipHash(), pix);
1053 else m_doc->cachePixmap(item->getClipHash() + '#' + QString::number(frame), pix);
1055 if (update) emit projectModified();
1056 QTimer::singleShot(30, this, SLOT(slotProcessNextThumbnail()));
1060 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace)
1062 ProjectItem *item = getItemById(clipId);
1063 if (item && producer) {
1064 m_listView->blockSignals(true);
1065 item->setProperties(properties, metadata);
1066 //Q_ASSERT_X(item->referencedClip(), "void ProjectList::slotReplyGetFileProperties", QString("Item with groupName %1 does not have a clip associated").arg(item->groupName()).toLatin1());
1067 item->referencedClip()->setProducer(producer, replace);
1068 //emit receivedClipDuration(clipId);
1069 if (m_listView->isEnabled() && replace) {
1070 // update clip in clip monitor
1071 emit clipSelected(NULL);
1072 emit clipSelected(item->referencedClip());
1075 // Check if duration changed.
1076 emit receivedClipDuration(clipId);
1079 if (m_listView->isEnabled()) m_listView->blockSignals(false);
1080 if (item->icon(0).isNull()) {
1081 requestClipThumbnail(clipId);
1083 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
1084 int max = m_doc->clipManager()->clipsCount();
1085 emit displayMessage(i18n("Loading clips"), (int)(100 *(max - m_infoQueue.count()) / max));
1086 // small delay so that the app can display the progress info
1087 if (item && m_infoQueue.isEmpty() && m_thumbnailQueue.isEmpty()) {
1088 m_listView->setCurrentItem(item);
1089 emit clipSelected(item->referencedClip());
1091 QTimer::singleShot(30, this, SLOT(slotProcessNextClipInQueue()));
1094 void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
1096 ProjectItem *item = getItemById(clipId);
1097 if (item && !pix.isNull()) {
1098 m_listView->blockSignals(true);
1099 item->setIcon(0, pix);
1100 m_doc->cachePixmap(item->getClipHash(), pix);
1101 if (m_listView->isEnabled()) m_listView->blockSignals(false);
1105 QTreeWidgetItem *ProjectList::getAnyItemById(const QString &id)
1107 QTreeWidgetItemIterator it(m_listView);
1108 QString lookId = id;
1109 if (id.contains('#')) {
1110 lookId = id.section('#', 0, 0);
1113 ProjectItem *result = NULL;
1115 if ((*it)->type() != PROJECTCLIPTYPE) {
1120 ProjectItem *item = static_cast<ProjectItem *>(*it);
1121 if (item->clipId() == lookId) {
1127 if (result == NULL || !id.contains('#')) return result;
1128 else for (int i = 0; i < result->childCount(); i++) {
1129 SubProjectItem *sub = static_cast <SubProjectItem *>(result->child(i));
1130 if (sub && sub->zone().x() == id.section('#', 1, 1).toInt()) {
1139 ProjectItem *ProjectList::getItemById(const QString &id)
1142 QTreeWidgetItemIterator it(m_listView);
1144 if ((*it)->type() != PROJECTCLIPTYPE) {
1149 item = static_cast<ProjectItem *>(*it);
1150 if (item->clipId() == id)
1157 FolderProjectItem *ProjectList::getFolderItemById(const QString &id)
1159 FolderProjectItem *item;
1160 QTreeWidgetItemIterator it(m_listView);
1162 if ((*it)->type() == PROJECTFOLDERTYPE) {
1163 item = static_cast<FolderProjectItem *>(*it);
1171 void ProjectList::slotSelectClip(const QString &ix)
1173 ProjectItem *clip = getItemById(ix);
1175 m_listView->setCurrentItem(clip);
1176 m_listView->scrollToItem(clip);
1177 m_editAction->setEnabled(true);
1178 m_deleteAction->setEnabled(true);
1179 m_reloadAction->setEnabled(true);
1180 m_transcodeAction->setEnabled(true);
1181 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
1182 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
1183 m_openAction->setEnabled(true);
1184 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
1185 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
1186 m_openAction->setEnabled(true);
1187 } else m_openAction->setEnabled(false);
1191 QString ProjectList::currentClipUrl() const
1194 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return QString();
1195 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
1197 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
1198 } else item = static_cast <ProjectItem*>(m_listView->currentItem());
1199 if (item == NULL) return QString();
1200 return item->clipUrl().path();
1203 void ProjectList::regenerateTemplate(const QString &id)
1205 ProjectItem *clip = getItemById(id);
1206 if (clip) regenerateTemplate(clip);
1209 void ProjectList::regenerateTemplate(ProjectItem *clip)
1211 //TODO: remove this unused method, only force_reload is necessary
1212 clip->referencedClip()->producer()->set("force_reload", 1);
1215 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
1219 if (!file.open(QIODevice::ReadOnly)) {
1220 kWarning() << "ERROR, CANNOT READ: " << path;
1223 if (!doc.setContent(&file)) {
1224 kWarning() << "ERROR, CANNOT READ: " << path;
1229 QDomNodeList texts = doc.elementsByTagName("content");
1230 for (int i = 0; i < texts.count(); i++) {
1231 QString data = texts.item(i).firstChild().nodeValue();
1232 data.replace("%s", replaceString);
1233 texts.item(i).firstChild().setNodeValue(data);
1239 void ProjectList::slotAddClipCut(const QString &id, int in, int out)
1241 ProjectItem *clip = getItemById(id);
1242 if (clip == NULL) return;
1243 if (clip->referencedClip()->hasCutZone(QPoint(in, out))) return;
1244 AddClipCutCommand *command = new AddClipCutCommand(this, id, in, out, false);
1245 m_commandStack->push(command);
1248 void ProjectList::addClipCut(const QString &id, int in, int out)
1250 ProjectItem *clip = getItemById(id);
1252 DocClipBase *base = clip->referencedClip();
1253 base->addCutZone(in, out);
1254 m_listView->blockSignals(true);
1255 SubProjectItem *sub = new SubProjectItem(clip, in, out);
1257 QPixmap p = clip->referencedClip()->thumbProducer()->extractImage(in, (int)(sub->sizeHint(0).height() * m_render->dar()), sub->sizeHint(0).height() - 2);
1259 m_doc->cachePixmap(clip->getClipHash() + '#' + QString::number(in), p);
1260 m_listView->blockSignals(false);
1264 void ProjectList::removeClipCut(const QString &id, int in, int out)
1266 ProjectItem *clip = getItemById(id);
1268 DocClipBase *base = clip->referencedClip();
1269 base->removeCutZone(in, out);
1270 for (int i = 0; i < clip->childCount(); i++) {
1271 QTreeWidgetItem *it = clip->child(i);
1272 if (it->type() != PROJECTSUBCLIPTYPE) continue;
1273 SubProjectItem *sub = static_cast <SubProjectItem*>(it);
1274 if (sub->zone() == QPoint(in, out)) {
1275 m_listView->blockSignals(true);
1277 m_listView->blockSignals(false);
1284 #include "projectlist.moc"