1 /***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include "projectlist.h"
21 #include "projectitem.h"
22 #include "addfoldercommand.h"
23 #include "kdenlivesettings.h"
24 #include "slideshowclip.h"
25 #include "ui_colorclip_ui.h"
26 #include "titlewidget.h"
27 #include "definitions.h"
28 #include "clipmanager.h"
29 #include "docclipbase.h"
30 #include "kdenlivedoc.h"
33 #include "projectlistview.h"
34 #include "editclipcommand.h"
35 #include "editclipcutcommand.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>
55 #include <QMouseEvent>
56 #include <QStylePainter>
61 #include <QHeaderView>
63 ProjectList::ProjectList(QWidget *parent) :
72 m_transcodeAction(NULL),
79 m_listView = new ProjectListView(this);;
80 QVBoxLayout *layout = new QVBoxLayout;
81 layout->setContentsMargins(0, 0, 0, 0);
84 KTreeWidgetSearchLine *searchView = new KTreeWidgetSearchLine(this);
85 m_toolbar = new QToolBar("projectToolBar", this);
86 m_toolbar->addWidget(searchView);
87 int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
88 m_toolbar->setIconSize(QSize(s, s));
89 searchView->setTreeWidget(m_listView);
91 m_addButton = new QToolButton(m_toolbar);
92 m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
93 m_toolbar->addWidget(m_addButton);
95 layout->addWidget(m_toolbar);
96 layout->addWidget(m_listView);
99 m_queueTimer.setInterval(100);
100 connect(&m_queueTimer, SIGNAL(timeout()), this, SLOT(slotProcessNextClipInQueue()));
101 m_queueTimer.setSingleShot(true);
104 connect(m_listView, SIGNAL(projectModified()), this, SIGNAL(projectModified()));
105 connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
106 connect(m_listView, SIGNAL(focusMonitor()), this, SLOT(slotClipSelected()));
107 connect(m_listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
108 connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
109 connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
110 connect(m_listView, SIGNAL(addClip(const QList <QUrl>, const QString &, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &, const QString &)));
111 connect(m_listView, SIGNAL(addClipCut(const QString &, int, int)), this, SLOT(slotAddClipCut(const QString &, int, int)));
112 connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
113 connect(m_listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
115 m_listViewDelegate = new ItemDelegate(m_listView);
116 m_listView->setItemDelegate(m_listViewDelegate);
118 if (KdenliveSettings::activate_nepomuk()) {
119 Nepomuk::ResourceManager::instance()->init();
120 if (!Nepomuk::ResourceManager::instance()->initialized()) {
121 kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
122 KdenliveSettings::setActivate_nepomuk(false);
128 ProjectList::~ProjectList()
132 m_listView->blockSignals(true);
134 delete m_listViewDelegate;
137 void ProjectList::focusTree() const
139 m_listView->setFocus();
142 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
144 QList <QAction *> actions = addMenu->actions();
145 for (int i = 0; i < actions.count(); i++) {
146 if (actions.at(i)->data().toString() == "clip_properties") {
147 m_editAction = actions.at(i);
148 m_toolbar->addAction(m_editAction);
151 } else if (actions.at(i)->data().toString() == "delete_clip") {
152 m_deleteAction = actions.at(i);
153 m_toolbar->addAction(m_deleteAction);
156 } else if (actions.at(i)->data().toString() == "edit_clip") {
157 m_openAction = actions.at(i);
160 } else if (actions.at(i)->data().toString() == "reload_clip") {
161 m_reloadAction = actions.at(i);
167 QMenu *m = new QMenu();
168 m->addActions(actions);
169 m_addButton->setMenu(m);
170 m_addButton->setDefaultAction(defaultAction);
171 m_menu = new QMenu();
172 m_menu->addActions(addMenu->actions());
175 void ProjectList::setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu)
177 if (!addMenu) return;
178 QMenu *menu = m_addButton->menu();
179 menu->addMenu(addMenu);
180 m_addButton->setMenu(menu);
182 m_menu->addMenu(addMenu);
183 if (addMenu->isEmpty()) addMenu->setEnabled(false);
184 m_menu->addMenu(transcodeMenu);
185 if (transcodeMenu->isEmpty()) transcodeMenu->setEnabled(false);
186 m_transcodeAction = transcodeMenu;
187 m_menu->addAction(m_reloadAction);
188 m_menu->addAction(m_editAction);
189 m_menu->addAction(m_openAction);
190 m_menu->addAction(m_deleteAction);
191 m_menu->insertSeparator(m_deleteAction);
195 QByteArray ProjectList::headerInfo() const
197 return m_listView->header()->saveState();
200 void ProjectList::setHeaderInfo(const QByteArray &state)
202 m_listView->header()->restoreState(state);
205 void ProjectList::slotEditClip()
207 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
208 if (list.count() > 1) {
209 editClipSelection(list);
213 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return;
214 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
215 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
216 } else item = static_cast <ProjectItem*>(m_listView->currentItem());
217 if (!(item->flags() & Qt::ItemIsDragEnabled)) return;
219 emit clipSelected(item->referencedClip());
220 emit showClipProperties(item->referencedClip());
224 void ProjectList::editClipSelection(QList<QTreeWidgetItem *> list)
226 // Gather all common properties
227 QMap <QString, QString> commonproperties;
228 QList <DocClipBase *> clipList;
229 commonproperties.insert("force_aspect_ratio", "-");
230 commonproperties.insert("force_fps", "-");
231 commonproperties.insert("force_progressive", "-");
232 commonproperties.insert("threads", "-");
233 commonproperties.insert("video_index", "-");
234 commonproperties.insert("audio_index", "-");
236 bool allowDurationChange = true;
237 int commonDuration = -1;
239 for (int i = 0; i < list.count(); i++) {
241 if (list.at(i)->type() == PROJECTFOLDERTYPE) continue;
242 if (list.at(i)->type() == PROJECTSUBCLIPTYPE) {
243 item = static_cast <ProjectItem*>(list.at(i)->parent());
244 } else item = static_cast <ProjectItem*>(list.at(i));
245 if (!(item->flags() & Qt::ItemIsDragEnabled)) continue;
248 DocClipBase *clip = item->referencedClip();
249 if (clipList.contains(clip)) continue;
250 if (clip->clipType() != COLOR && clip->clipType() != IMAGE && clip->clipType() != TEXT) {
251 allowDurationChange = false;
253 if (allowDurationChange && commonDuration != 0) {
254 if (commonDuration == -1) {
255 commonDuration = clip->duration().frames(m_fps);
256 } else if (commonDuration != clip->duration().frames(m_fps)) {
260 clipList.append(clip);
261 QMap <QString, QString> clipprops = clip->properties();
262 QMapIterator<QString, QString> p(commonproperties);
263 while (p.hasNext()) {
265 if (p.value().isEmpty()) continue;
266 if (clipprops.contains(p.key())) {
267 if (p.value() == "-") commonproperties.insert(p.key(), clipprops.value(p.key()));
268 else if (p.value() != clipprops.value(p.key())) commonproperties.insert(p.key(), QString());
269 } else commonproperties.insert(p.key(), QString());
273 if (allowDurationChange) commonproperties.insert("out", QString::number(commonDuration));
274 QMapIterator<QString, QString> p(commonproperties);
275 while (p.hasNext()) {
277 kDebug() << "Result: " << p.key() << " = " << p.value();
279 emit showClipProperties(clipList, commonproperties);
282 void ProjectList::slotOpenClip()
285 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return;
286 if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1) {
287 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
288 } else item = static_cast <ProjectItem*>(m_listView->currentItem());
290 if (item->clipType() == IMAGE) {
291 if (KdenliveSettings::defaultimageapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open images in the Settings dialog"));
292 else QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
294 if (item->clipType() == AUDIO) {
295 if (KdenliveSettings::defaultaudioapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open audio files in the Settings dialog"));
296 else QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
301 void ProjectList::cleanup()
303 m_listView->clearSelection();
304 QTreeWidgetItemIterator it(m_listView);
307 if ((*it)->type() != PROJECTCLIPTYPE) {
311 item = static_cast <ProjectItem *>(*it);
312 if (item->numReferences() == 0) item->setSelected(true);
318 void ProjectList::trashUnusedClips()
320 QTreeWidgetItemIterator it(m_listView);
325 if ((*it)->type() != PROJECTCLIPTYPE) {
329 item = static_cast <ProjectItem *>(*it);
330 if (item->numReferences() == 0) {
331 ids << item->clipId();
332 KUrl url = item->clipUrl();
333 if (!url.isEmpty() && !urls.contains(url.path())) urls << url.path();
338 // Check that we don't use the URL in another clip
339 QTreeWidgetItemIterator it2(m_listView);
341 if ((*it2)->type() != PROJECTCLIPTYPE) {
345 item = static_cast <ProjectItem *>(*it2);
346 if (item->numReferences() > 0) {
347 KUrl url = item->clipUrl();
348 if (!url.isEmpty() && urls.contains(url.path())) urls.removeAll(url.path());
353 m_doc->deleteProjectClip(ids);
354 for (int i = 0; i < urls.count(); i++) {
355 KIO::NetAccess::del(KUrl(urls.at(i)), this);
359 void ProjectList::slotReloadClip(const QString &id)
361 QList<QTreeWidgetItem *> selected;
362 if (id.isEmpty()) selected = m_listView->selectedItems();
363 else selected.append(getItemById(id));
365 for (int i = 0; i < selected.count(); i++) {
366 if (selected.at(i)->type() != PROJECTCLIPTYPE) continue;
367 item = static_cast <ProjectItem *>(selected.at(i));
369 if (item->clipType() == IMAGE) {
370 item->referencedClip()->producer()->set("force_reload", 1);
371 } else if (item->clipType() == TEXT) {
372 if (!item->referencedClip()->getProperty("xmltemplate").isEmpty()) regenerateTemplate(item);
374 //requestClipInfo(item->toXml(), item->clipId(), true);
375 // Clear the file_hash value, which will cause a complete reload of the clip
376 emit getFileProperties(item->toXml(), item->clipId(), m_listView->iconSize().height(), true);
381 void ProjectList::setRenderer(Render *projectRender)
383 m_render = projectRender;
384 m_listView->setIconSize(QSize((ProjectItem::itemDefaultHeight() - 2) * m_render->dar(), ProjectItem::itemDefaultHeight() - 2));
387 void ProjectList::slotClipSelected()
389 if (m_listView->currentItem()) {
390 if (m_listView->currentItem()->type() == PROJECTFOLDERTYPE) {
391 emit clipSelected(NULL);
392 m_editAction->setEnabled(false);
393 m_deleteAction->setEnabled(true);
394 m_openAction->setEnabled(false);
395 m_reloadAction->setEnabled(false);
396 m_transcodeAction->setEnabled(false);
399 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
400 // this is a sub item, use base clip
401 m_deleteAction->setEnabled(true);
402 clip = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
403 if (clip == NULL) kDebug() << "-----------ERROR";
404 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
405 emit clipSelected(clip->referencedClip(), sub->zone());
406 m_transcodeAction->setEnabled(false);
409 clip = static_cast <ProjectItem*>(m_listView->currentItem());
410 if (clip) emit clipSelected(clip->referencedClip());
411 m_editAction->setEnabled(true);
412 m_deleteAction->setEnabled(true);
413 m_reloadAction->setEnabled(true);
414 m_transcodeAction->setEnabled(true);
415 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
416 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
417 m_openAction->setEnabled(true);
418 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
419 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
420 m_openAction->setEnabled(true);
421 } else m_openAction->setEnabled(false);
422 // Display relevant transcoding actions only
423 adjustTranscodeActions(clip);
426 emit clipSelected(NULL);
427 m_editAction->setEnabled(false);
428 m_deleteAction->setEnabled(false);
429 m_openAction->setEnabled(false);
430 m_reloadAction->setEnabled(false);
431 m_transcodeAction->setEnabled(false);
435 void ProjectList::adjustTranscodeActions(ProjectItem *clip) const
437 if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST) {
438 m_transcodeAction->setEnabled(false);
441 m_transcodeAction->setEnabled(true);
442 QList<QAction *> transcodeActions = m_transcodeAction->actions();
445 for (int i = 0; i < transcodeActions.count(); i++) {
446 data = transcodeActions.at(i)->data().toStringList();
447 if (data.count() > 2) {
448 condition = data.at(2);
449 if (condition.startsWith("vcodec")) transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section("=", 1, 1)));
450 else if (condition.startsWith("acodec")) transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section("=", 1, 1)));
456 void ProjectList::slotPauseMonitor()
458 if (m_render) m_render->pause();
461 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
463 ProjectItem *item = getItemById(id);
465 slotUpdateClipProperties(item, properties);
466 if (properties.contains("out") || properties.contains("force_fps")) {
468 } else if (properties.contains("colour") || properties.contains("resource") || properties.contains("xmldata") || properties.contains("force_aspect_ratio") || properties.contains("templatetext")) {
469 slotRefreshClipThumbnail(item);
475 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
478 clip->setProperties(properties);
479 if (properties.contains("name")) {
480 m_listView->blockSignals(true);
481 clip->setText(0, properties.value("name"));
482 m_listView->blockSignals(false);
483 emit clipNameChanged(clip->clipId(), properties.value("name"));
485 if (properties.contains("description")) {
486 CLIPTYPE type = clip->clipType();
487 m_listView->blockSignals(true);
488 clip->setText(1, properties.value("description"));
489 m_listView->blockSignals(false);
491 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
492 // Use Nepomuk system to store clip description
493 Nepomuk::Resource f(clip->clipUrl().path());
494 f.setDescription(properties.value("description"));
497 emit projectModified();
501 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
503 if (item->type() == PROJECTSUBCLIPTYPE) {
504 // this is a sub-item
506 // user edited description
507 SubProjectItem *sub = static_cast <SubProjectItem*>(item);
508 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
509 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), sub->zone(), sub->description(), sub->text(1), true);
510 m_commandStack->push(command);
511 //slotUpdateCutClipProperties(sub->clipId(), sub->zone(), sub->text(1), sub->text(1));
515 if (item->type() == PROJECTFOLDERTYPE) {
516 if (column != 0) return;
517 FolderProjectItem *folder = static_cast <FolderProjectItem*>(item);
518 editFolder(item->text(0), folder->groupName(), folder->clipId());
519 folder->setGroupName(item->text(0));
520 m_doc->clipManager()->addFolder(folder->clipId(), item->text(0));
521 const int children = item->childCount();
522 for (int i = 0; i < children; i++) {
523 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
524 child->setProperty("groupname", item->text(0));
529 ProjectItem *clip = static_cast <ProjectItem*>(item);
531 if (clip->referencedClip()) {
532 QMap <QString, QString> oldprops;
533 QMap <QString, QString> newprops;
534 oldprops["description"] = clip->referencedClip()->getProperty("description");
535 newprops["description"] = item->text(1);
537 if (clip->clipType() == TEXT) {
538 // This is a text template clip, update the image
539 /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
540 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/
541 oldprops.insert("templatetext", clip->referencedClip()->getProperty("templatetext"));
542 newprops.insert("templatetext", item->text(1));
544 slotUpdateClipProperties(clip->clipId(), newprops);
545 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
546 m_commandStack->push(command);
548 } else if (column == 0) {
549 if (clip->referencedClip()) {
550 QMap <QString, QString> oldprops;
551 QMap <QString, QString> newprops;
552 oldprops["name"] = clip->referencedClip()->getProperty("name");
553 newprops["name"] = item->text(0);
554 slotUpdateClipProperties(clip, newprops);
555 emit projectModified();
556 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
557 m_commandStack->push(command);
562 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
568 m_editAction->setEnabled(enable);
569 m_deleteAction->setEnabled(enable);
570 m_reloadAction->setEnabled(enable);
571 m_transcodeAction->setEnabled(enable);
573 ProjectItem *clip = NULL;
574 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
575 clip = static_cast <ProjectItem*>(item->parent());
576 m_transcodeAction->setEnabled(false);
577 } else if (m_listView->currentItem()->type() == PROJECTCLIPTYPE) {
578 clip = static_cast <ProjectItem*>(item);
579 // Display relevant transcoding actions only
580 adjustTranscodeActions(clip);
581 } else m_transcodeAction->setEnabled(false);
582 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
583 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
584 m_openAction->setEnabled(true);
585 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
586 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
587 m_openAction->setEnabled(true);
588 } else m_openAction->setEnabled(false);
590 } else m_openAction->setEnabled(false);
594 void ProjectList::slotRemoveClip()
596 if (!m_listView->currentItem()) return;
598 QMap <QString, QString> folderids;
599 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
601 QUndoCommand *delCommand = new QUndoCommand();
602 delCommand->setText(i18n("Delete Clip Zone"));
604 for (int i = 0; i < selected.count(); i++) {
605 if (selected.at(i)->type() == PROJECTSUBCLIPTYPE) {
607 SubProjectItem *sub = static_cast <SubProjectItem *>(selected.at(i));
608 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
609 new AddClipCutCommand(this, item->clipId(), sub->zone().x(), sub->zone().y(), sub->description(), false, true, delCommand);
610 } else if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
612 FolderProjectItem *folder = static_cast <FolderProjectItem *>(selected.at(i));
613 folderids[folder->groupName()] = folder->clipId();
614 int children = folder->childCount();
616 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;
617 for (int i = 0; i < children; ++i) {
618 ProjectItem *child = static_cast <ProjectItem *>(folder->child(i));
619 ids << child->clipId();
622 ProjectItem *item = static_cast <ProjectItem *>(selected.at(i));
623 ids << item->clipId();
624 if (item->numReferences() > 0) {
625 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;
630 if (delCommand->childCount() == 0) delete delCommand;
631 else m_commandStack->push(delCommand);
632 if (!ids.isEmpty()) m_doc->deleteProjectClip(ids);
633 if (!folderids.isEmpty()) deleteProjectFolder(folderids);
634 if (m_listView->topLevelItemCount() == 0) {
635 m_editAction->setEnabled(false);
636 m_deleteAction->setEnabled(false);
637 m_openAction->setEnabled(false);
638 m_reloadAction->setEnabled(false);
639 m_transcodeAction->setEnabled(false);
643 void ProjectList::selectItemById(const QString &clipId)
645 ProjectItem *item = getItemById(clipId);
646 if (item) m_listView->setCurrentItem(item);
650 void ProjectList::slotDeleteClip(const QString &clipId)
652 ProjectItem *item = getItemById(clipId);
654 kDebug() << "/// Cannot find clip to delete";
657 m_listView->blockSignals(true);
659 m_doc->clipManager()->deleteClip(clipId);
660 m_listView->blockSignals(false);
665 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
667 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
668 m_commandStack->push(command);
669 m_doc->setModified(true);
672 void ProjectList::slotAddFolder()
674 AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
675 m_commandStack->push(command);
678 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
681 FolderProjectItem *item = getFolderItemById(clipId);
683 m_doc->clipManager()->deleteFolder(clipId);
688 FolderProjectItem *item = getFolderItemById(clipId);
690 m_listView->blockSignals(true);
691 item->setGroupName(foldername);
692 m_listView->blockSignals(false);
693 m_doc->clipManager()->addFolder(clipId, foldername);
694 const int children = item->childCount();
695 for (int i = 0; i < children; i++) {
696 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
697 child->setProperty("groupname", foldername);
703 m_listView->blockSignals(true);
704 m_listView->setCurrentItem(new FolderProjectItem(m_listView, text, clipId));
705 m_doc->clipManager()->addFolder(clipId, foldername);
706 m_listView->blockSignals(false);
709 m_doc->setModified(true);
714 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
716 QMapIterator<QString, QString> i(map);
717 QUndoCommand *delCommand = new QUndoCommand();
718 delCommand->setText(i18n("Delete Folder"));
719 while (i.hasNext()) {
721 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
723 m_commandStack->push(delCommand);
726 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
728 m_listView->setEnabled(false);
730 m_listView->blockSignals(true);
732 // remove file_hash so that we load all properties for the clip
733 QDomElement e = clip->toXML().cloneNode().toElement();
734 e.removeAttribute("file_hash");
735 m_infoQueue.insert(clip->getId(), e);
736 //m_render->getFileProperties(clip->toXML(), clip->getId(), true);
738 const QString parent = clip->getProperty("groupid");
739 ProjectItem *item = NULL;
740 if (!parent.isEmpty()) {
741 FolderProjectItem *parentitem = getFolderItemById(parent);
744 QString groupName = clip->getProperty("groupname");
745 //kDebug() << "Adding clip to new group: " << groupName;
746 if (groupName.isEmpty()) groupName = i18n("Folder");
748 parentitem = new FolderProjectItem(m_listView, text, parent);
750 //kDebug() << "Adding clip to existing group: " << parentitem->groupName();
752 if (parentitem) item = new ProjectItem(parentitem, clip);
754 if (item == NULL) item = new ProjectItem(m_listView, clip);
755 KUrl url = clip->fileURL();
757 if (getProperties == false && !clip->getClipHash().isEmpty()) {
758 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
759 if (QFile::exists(cachedPixmap)) {
760 QPixmap pix(cachedPixmap);
761 if (pix.isNull()) KIO::NetAccess::del(KUrl(cachedPixmap), this);
762 item->setData(0, Qt::DecorationRole, pix);
766 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
767 // if file has Nepomuk comment, use it
768 Nepomuk::Resource f(url.path());
769 QString annotation = f.description();
770 if (!annotation.isEmpty()) item->setText(1, annotation);
771 item->setText(2, QString::number(f.rating()));
775 QList <CutZoneInfo> cuts = clip->cutZones();
776 if (!cuts.isEmpty()) {
777 for (int i = 0; i < cuts.count(); i++) {
778 SubProjectItem *sub = new SubProjectItem(item, cuts.at(i).zone.x(), cuts.at(i).zone.y(), cuts.at(i).description);
779 if (!clip->getClipHash().isEmpty()) {
780 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(cuts.at(i).zone.x()) + ".png";
781 if (QFile::exists(cachedPixmap)) {
782 QPixmap pix(cachedPixmap);
783 if (pix.isNull()) KIO::NetAccess::del(KUrl(cachedPixmap), this);
784 sub->setData(0, Qt::DecorationRole, pix);
790 if (getProperties && m_listView->isEnabled()) m_listView->blockSignals(false);
791 if (getProperties && !m_queueTimer.isActive()) m_queueTimer.start();
794 void ProjectList::slotResetProjectList()
797 emit clipSelected(NULL);
798 m_thumbnailQueue.clear();
803 void ProjectList::requestClipInfo(const QDomElement xml, const QString id)
806 m_infoQueue.insert(id, xml);
807 //if (m_infoQueue.count() == 1 || ) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
810 void ProjectList::slotProcessNextClipInQueue()
812 if (m_infoQueue.isEmpty()) {
813 slotProcessNextThumbnail();
817 QMap<QString, QDomElement>::const_iterator j = m_infoQueue.constBegin();
818 if (j != m_infoQueue.constEnd()) {
819 const QDomElement dom = j.value();
820 const QString id = j.key();
821 m_infoQueue.remove(j.key());
822 emit getFileProperties(dom, id, m_listView->iconSize().height(), false);
826 void ProjectList::slotUpdateClip(const QString &id)
828 ProjectItem *item = getItemById(id);
829 m_listView->blockSignals(true);
830 if (item) item->setData(1, UsageRole, QString::number(item->numReferences()));
831 m_listView->blockSignals(false);
834 void ProjectList::updateAllClips()
836 m_listView->setSortingEnabled(false);
837 kDebug() << "// UPDATE ALL CLPY";
839 QTreeWidgetItemIterator it(m_listView);
842 m_listView->blockSignals(true);
844 if ((*it)->type() == PROJECTSUBCLIPTYPE) {
846 SubProjectItem *sub = static_cast <SubProjectItem *>(*it);
847 if (sub->data(0, Qt::DecorationRole).isNull()) {
848 item = static_cast <ProjectItem *>((*it)->parent());
849 requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x()));
853 } else if ((*it)->type() == PROJECTFOLDERTYPE) {
858 item = static_cast <ProjectItem *>(*it);
859 clip = item->referencedClip();
860 if (item->referencedClip()->producer() == NULL) {
861 if (clip->isPlaceHolder() == false) {
862 requestClipInfo(clip->toXML(), clip->getId());
863 } else if (!clip->isPlaceHolder()) item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
865 if (item->data(0, Qt::DecorationRole).isNull()) {
866 requestClipThumbnail(clip->getId());
868 if (item->data(0, DurationRole).toString().isEmpty()) {
869 item->changeDuration(item->referencedClip()->producer()->get_playtime());
872 item->setData(1, UsageRole, QString::number(item->numReferences()));
874 //qApp->processEvents();
877 if (!m_queueTimer.isActive()) m_queueTimer.start();
878 if (m_listView->isEnabled()) m_listView->blockSignals(false);
879 m_listView->setSortingEnabled(true);
880 if (m_infoQueue.isEmpty()) slotProcessNextThumbnail();
883 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
885 if (!m_commandStack) {
886 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
889 if (givenList.isEmpty()) {
890 // Build list of mime types
891 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";
893 QString allExtensions;
894 foreach(const QString& mimeType, mimeTypes) {
895 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
897 allExtensions.append(mime->patterns().join(" "));
898 allExtensions.append(' ');
901 const QString dialogFilter = allExtensions.simplified() + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
902 list = KFileDialog::getOpenUrls(KUrl("kfiledialog:///clipfolder"), dialogFilter, this);
905 for (int i = 0; i < givenList.count(); i++)
906 list << givenList.at(i);
909 foreach(const KUrl &file, list) {
910 // Check there is no folder here
911 KMimeType::Ptr type = KMimeType::findByUrl(file);
912 if (type->is("inode/directory")) {
913 // user dropped a folder
914 list.removeAll(file);
918 if (list.isEmpty()) return;
920 if (givenList.isEmpty()) {
921 QStringList groupInfo = getGroup();
922 m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1));
923 } else m_doc->slotAddClipList(list, groupName, groupId);
926 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
928 ProjectItem *item = getItemById(id);
929 QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
931 const QString path = item->referencedClip()->fileURL().path();
932 if (item->referencedClip()->isPlaceHolder()) replace = false;
933 if (!path.isEmpty()) {
934 if (replace) KMessageBox::sorry(this, i18n("Clip <b>%1</b><br>is invalid, will be removed from project.", path));
936 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;
941 if (replace) m_doc->deleteProjectClip(ids);
945 void ProjectList::slotAddColorClip()
947 if (!m_commandStack) {
948 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
950 QDialog *dia = new QDialog(this);
951 Ui::ColorClip_UI dia_ui;
953 dia->setWindowTitle(i18n("Color Clip"));
954 dia_ui.clip_name->setText(i18n("Color Clip"));
955 dia_ui.clip_duration->setText(KdenliveSettings::color_duration());
956 if (dia->exec() == QDialog::Accepted) {
957 QString color = dia_ui.clip_color->color().name();
958 color = color.replace(0, 1, "0x") + "ff";
959 QStringList groupInfo = getGroup();
960 m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, dia_ui.clip_duration->text(), groupInfo.at(0), groupInfo.at(1));
966 void ProjectList::slotAddSlideshowClip()
968 if (!m_commandStack) {
969 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
971 SlideshowClip *dia = new SlideshowClip(m_timecode, this);
973 if (dia->exec() == QDialog::Accepted) {
974 QStringList groupInfo = getGroup();
975 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));
980 void ProjectList::slotAddTitleClip()
982 QStringList groupInfo = getGroup();
983 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
986 void ProjectList::slotAddTitleTemplateClip()
988 QStringList groupInfo = getGroup();
989 if (!m_commandStack) {
990 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
993 // Get the list of existing templates
995 filter << "*.kdenlivetitle";
996 const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
997 QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
999 QDialog *dia = new QDialog(this);
1000 Ui::TemplateClip_UI dia_ui;
1001 dia_ui.setupUi(dia);
1002 for (int i = 0; i < templateFiles.size(); ++i) {
1003 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
1005 dia_ui.template_list->fileDialog()->setFilter("*.kdenlivetitle");
1006 //warning: setting base directory doesn't work??
1007 KUrl startDir(path);
1008 dia_ui.template_list->fileDialog()->setUrl(startDir);
1009 dia_ui.text_box->setHidden(true);
1010 if (dia->exec() == QDialog::Accepted) {
1011 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
1012 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
1013 // Create a cloned template clip
1014 m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
1019 QStringList ProjectList::getGroup() const
1022 QTreeWidgetItem *item = m_listView->currentItem();
1023 while (item && item->type() != PROJECTFOLDERTYPE) {
1024 item = item->parent();
1028 FolderProjectItem *folder = static_cast <FolderProjectItem *>(item);
1029 result << folder->groupName();
1030 result << folder->clipId();
1031 } else result << QString() << QString();
1035 void ProjectList::setDocument(KdenliveDoc *doc)
1037 m_listView->blockSignals(true);
1038 m_listView->clear();
1039 m_listView->setSortingEnabled(false);
1040 emit clipSelected(NULL);
1041 m_thumbnailQueue.clear();
1042 m_infoQueue.clear();
1043 m_refreshed = false;
1045 m_timecode = doc->timecode();
1046 m_commandStack = doc->commandStack();
1049 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
1050 QMapIterator<QString, QString> f(flist);
1051 while (f.hasNext()) {
1053 (void) new FolderProjectItem(m_listView, QStringList() << f.value(), f.key());
1056 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
1057 for (int i = 0; i < list.count(); i++) {
1058 slotAddClip(list.at(i), false);
1061 m_listView->blockSignals(false);
1062 m_toolbar->setEnabled(true);
1063 connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
1064 connect(m_doc->clipManager(), SIGNAL(checkAllClips()), this, SLOT(updateAllClips()));
1067 QList <DocClipBase*> ProjectList::documentClipList() const
1069 if (m_doc == NULL) return QList <DocClipBase*> ();
1070 return m_doc->clipManager()->documentClipList();
1073 QDomElement ProjectList::producersList()
1076 QDomElement prods = doc.createElement("producerlist");
1077 doc.appendChild(prods);
1078 kDebug() << "//////////// PRO LISTÂ BUILD PRDSLIST ";
1079 QTreeWidgetItemIterator it(m_listView);
1081 if ((*it)->type() != PROJECTCLIPTYPE) {
1086 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
1092 void ProjectList::slotCheckForEmptyQueue()
1094 if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
1096 emit loadingIsOver();
1097 emit displayMessage(QString(), -1);
1098 m_listView->blockSignals(false);
1099 m_listView->setEnabled(true);
1100 } else if (!m_refreshed) QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
1103 void ProjectList::reloadClipThumbnails()
1105 kDebug() << "////////////// RELOAD CLIPS THUMBNAILS!!!";
1106 m_thumbnailQueue.clear();
1107 QTreeWidgetItemIterator it(m_listView);
1109 if ((*it)->type() != PROJECTCLIPTYPE) {
1114 m_thumbnailQueue << ((ProjectItem *)(*it))->clipId();
1117 QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
1120 void ProjectList::requestClipThumbnail(const QString id)
1122 if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id);
1125 void ProjectList::slotProcessNextThumbnail()
1127 if (m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
1128 slotCheckForEmptyQueue();
1131 if (!m_infoQueue.isEmpty()) {
1132 //QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
1135 if (m_thumbnailQueue.count() > 1) {
1136 int max = m_doc->clipManager()->clipsCount();
1137 emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - m_thumbnailQueue.count()) / max));
1139 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
1142 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
1144 QTreeWidgetItem *item = getAnyItemById(clipId);
1145 if (item) slotRefreshClipThumbnail(item, update);
1146 else slotProcessNextThumbnail();
1149 void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
1151 if (it == NULL) return;
1152 ProjectItem *item = NULL;
1153 bool isSubItem = false;
1155 if (it->type() == PROJECTFOLDERTYPE) return;
1156 if (it->type() == PROJECTSUBCLIPTYPE) {
1157 item = static_cast <ProjectItem *>(it->parent());
1158 frame = static_cast <SubProjectItem *>(it)->zone().x();
1161 item = static_cast <ProjectItem *>(it);
1162 frame = item->referencedClip()->getClipThumbFrame();
1166 DocClipBase *clip = item->referencedClip();
1168 slotProcessNextThumbnail();
1172 int height = m_listView->iconSize().height();
1173 int width = (int)(height * m_render->dar());
1174 if (clip->clipType() == AUDIO) pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
1175 else if (clip->clipType() == IMAGE) pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->producer(), 0, width, height));
1176 else pix = item->referencedClip()->thumbProducer()->extractImage(frame, width, height);
1178 if (!pix.isNull()) {
1179 m_listView->blockSignals(true);
1180 it->setData(0, Qt::DecorationRole, pix);
1181 if (m_listView->isEnabled()) m_listView->blockSignals(false);
1182 if (!isSubItem) m_doc->cachePixmap(item->getClipHash(), pix);
1183 else m_doc->cachePixmap(item->getClipHash() + '#' + QString::number(frame), pix);
1185 if (update) emit projectModified();
1186 QTimer::singleShot(30, this, SLOT(slotProcessNextThumbnail()));
1190 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace)
1193 ProjectItem *item = getItemById(clipId);
1194 if (item && producer) {
1195 m_listView->blockSignals(true);
1196 item->setProperties(properties, metadata);
1197 if (item->referencedClip()->isPlaceHolder() && producer->is_valid()) {
1198 item->referencedClip()->setValid();
1199 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
1202 //Q_ASSERT_X(item->referencedClip(), "void ProjectList::slotReplyGetFileProperties", QString("Item with groupName %1 does not have a clip associated").arg(item->groupName()).toLatin1());
1203 item->referencedClip()->setProducer(producer, replace);
1204 if (!replace && item->data(0, Qt::DecorationRole).isNull()) {
1205 requestClipThumbnail(clipId);
1207 //emit receivedClipDuration(clipId);
1208 if (m_listView->isEnabled() && replace) {
1209 // update clip in clip monitor
1210 emit clipSelected(NULL);
1211 emit clipSelected(item->referencedClip());
1214 // Check if duration changed.
1215 emit receivedClipDuration(clipId);
1218 if (m_listView->isEnabled()) m_listView->blockSignals(false);
1219 /*if (item->icon(0).isNull()) {
1220 requestClipThumbnail(clipId);
1222 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
1223 int max = m_doc->clipManager()->clipsCount();
1224 emit displayMessage(i18n("Loading clips"), (int)(100 *(max - m_infoQueue.count()) / max));
1225 // small delay so that the app can display the progress info
1226 if (item && m_infoQueue.isEmpty() && m_thumbnailQueue.isEmpty()) {
1227 m_listView->setCurrentItem(item);
1228 emit clipSelected(item->referencedClip());
1230 if (!toReload.isEmpty()) emit clipNeedsReload(toReload, true);
1231 QTimer::singleShot(30, this, SLOT(slotProcessNextClipInQueue()));
1234 void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
1236 ProjectItem *item = getItemById(clipId);
1237 if (item && !pix.isNull()) {
1238 m_listView->blockSignals(true);
1239 item->setData(0, Qt::DecorationRole, pix);
1240 m_doc->cachePixmap(item->getClipHash(), pix);
1241 if (m_listView->isEnabled()) m_listView->blockSignals(false);
1245 QTreeWidgetItem *ProjectList::getAnyItemById(const QString &id)
1247 QTreeWidgetItemIterator it(m_listView);
1248 QString lookId = id;
1249 if (id.contains('#')) {
1250 lookId = id.section('#', 0, 0);
1253 ProjectItem *result = NULL;
1255 if ((*it)->type() != PROJECTCLIPTYPE) {
1260 ProjectItem *item = static_cast<ProjectItem *>(*it);
1261 if (item->clipId() == lookId) {
1267 if (result == NULL || !id.contains('#')) return result;
1268 else for (int i = 0; i < result->childCount(); i++) {
1269 SubProjectItem *sub = static_cast <SubProjectItem *>(result->child(i));
1270 if (sub && sub->zone().x() == id.section('#', 1, 1).toInt()) {
1279 ProjectItem *ProjectList::getItemById(const QString &id)
1282 QTreeWidgetItemIterator it(m_listView);
1284 if ((*it)->type() != PROJECTCLIPTYPE) {
1289 item = static_cast<ProjectItem *>(*it);
1290 if (item->clipId() == id)
1297 FolderProjectItem *ProjectList::getFolderItemById(const QString &id)
1299 FolderProjectItem *item;
1300 QTreeWidgetItemIterator it(m_listView);
1302 if ((*it)->type() == PROJECTFOLDERTYPE) {
1303 item = static_cast<FolderProjectItem *>(*it);
1304 if (item->clipId() == id) return item;
1311 void ProjectList::slotSelectClip(const QString &ix)
1313 ProjectItem *clip = getItemById(ix);
1315 m_listView->setCurrentItem(clip);
1316 m_listView->scrollToItem(clip);
1317 m_editAction->setEnabled(true);
1318 m_deleteAction->setEnabled(true);
1319 m_reloadAction->setEnabled(true);
1320 m_transcodeAction->setEnabled(true);
1321 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
1322 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
1323 m_openAction->setEnabled(true);
1324 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
1325 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
1326 m_openAction->setEnabled(true);
1327 } else m_openAction->setEnabled(false);
1331 QString ProjectList::currentClipUrl() const
1334 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return QString();
1335 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
1337 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
1338 } else item = static_cast <ProjectItem*>(m_listView->currentItem());
1339 if (item == NULL) return QString();
1340 return item->clipUrl().path();
1343 KUrl::List ProjectList::getConditionalUrls(const QString &condition) const
1347 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
1348 for (int i = 0; i < list.count(); i++) {
1349 if (list.at(i)->type() == PROJECTFOLDERTYPE) continue;
1350 if (list.at(i)->type() == PROJECTSUBCLIPTYPE) {
1352 item = static_cast <ProjectItem*>(list.at(i)->parent());
1353 } else item = static_cast <ProjectItem*>(list.at(i));
1354 if (item == NULL) continue;
1355 if (item->type() == COLOR || item->type() == SLIDESHOW || item->type() == TEXT) continue;
1356 DocClipBase *clip = item->referencedClip();
1357 if (!condition.isEmpty()) {
1358 if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section("=", 1, 1))) continue;
1359 else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section("=", 1, 1))) continue;
1361 result.append(item->clipUrl());
1366 void ProjectList::regenerateTemplate(const QString &id)
1368 ProjectItem *clip = getItemById(id);
1369 if (clip) regenerateTemplate(clip);
1372 void ProjectList::regenerateTemplate(ProjectItem *clip)
1374 //TODO: remove this unused method, only force_reload is necessary
1375 clip->referencedClip()->producer()->set("force_reload", 1);
1378 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
1382 if (!file.open(QIODevice::ReadOnly)) {
1383 kWarning() << "ERROR, CANNOT READ: " << path;
1386 if (!doc.setContent(&file)) {
1387 kWarning() << "ERROR, CANNOT READ: " << path;
1392 QDomNodeList texts = doc.elementsByTagName("content");
1393 for (int i = 0; i < texts.count(); i++) {
1394 QString data = texts.item(i).firstChild().nodeValue();
1395 data.replace("%s", replaceString);
1396 texts.item(i).firstChild().setNodeValue(data);
1402 void ProjectList::slotAddClipCut(const QString &id, int in, int out)
1404 ProjectItem *clip = getItemById(id);
1405 if (clip == NULL) return;
1406 if (clip->referencedClip()->hasCutZone(QPoint(in, out))) return;
1407 AddClipCutCommand *command = new AddClipCutCommand(this, id, in, out, QString(), true, false);
1408 m_commandStack->push(command);
1411 void ProjectList::addClipCut(const QString &id, int in, int out, const QString desc, bool newItem)
1413 ProjectItem *clip = getItemById(id);
1415 DocClipBase *base = clip->referencedClip();
1416 base->addCutZone(in, out);
1417 m_listView->blockSignals(true);
1418 SubProjectItem *sub = new SubProjectItem(clip, in, out, desc);
1419 if (newItem && desc.isEmpty() && !m_listView->isColumnHidden(1)) {
1420 if (!clip->isExpanded()) clip->setExpanded(true);
1421 m_listView->editItem(sub, 1);
1423 QPixmap p = clip->referencedClip()->thumbProducer()->extractImage(in, (int)(sub->sizeHint(0).height() * m_render->dar()), sub->sizeHint(0).height() - 2);
1424 sub->setData(0, Qt::DecorationRole, p);
1425 m_doc->cachePixmap(clip->getClipHash() + '#' + QString::number(in), p);
1426 m_listView->blockSignals(false);
1428 emit projectModified();
1431 void ProjectList::removeClipCut(const QString &id, int in, int out)
1433 ProjectItem *clip = getItemById(id);
1435 DocClipBase *base = clip->referencedClip();
1436 base->removeCutZone(in, out);
1437 SubProjectItem *sub = getSubItem(clip, QPoint(in, out));
1439 m_listView->blockSignals(true);
1441 m_listView->blockSignals(false);
1444 emit projectModified();
1447 SubProjectItem *ProjectList::getSubItem(ProjectItem *clip, QPoint zone)
1449 SubProjectItem *sub = NULL;
1451 for (int i = 0; i < clip->childCount(); i++) {
1452 QTreeWidgetItem *it = clip->child(i);
1453 if (it->type() == PROJECTSUBCLIPTYPE) {
1454 sub = static_cast <SubProjectItem*>(it);
1455 if (sub->zone() == zone) break;
1463 void ProjectList::slotUpdateClipCut(QPoint p)
1465 if (!m_listView->currentItem() || m_listView->currentItem()->type() != PROJECTSUBCLIPTYPE) return;
1466 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
1467 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
1468 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), p, sub->text(1), sub->text(1), true);
1469 m_commandStack->push(command);
1472 void ProjectList::doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment)
1474 ProjectItem *clip = getItemById(id);
1475 SubProjectItem *sub = getSubItem(clip, oldzone);
1476 if (sub == NULL || clip == NULL) return;
1477 DocClipBase *base = clip->referencedClip();
1478 base->updateCutZone(oldzone.x(), oldzone.y(), zone.x(), zone.y(), comment);
1479 m_listView->blockSignals(true);
1481 sub->setDescription(comment);
1482 m_listView->blockSignals(false);
1483 emit projectModified();
1486 #include "projectlist.moc"