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 "timecodedisplay.h"
35 #include "profilesdialog.h"
36 #include "editclipcommand.h"
37 #include "editclipcutcommand.h"
38 #include "editfoldercommand.h"
39 #include "addclipcutcommand.h"
41 #include "ui_templateclip_ui.h"
46 #include <KFileDialog>
47 #include <KInputDialog>
48 #include <KMessageBox>
49 #include <KIO/NetAccess>
52 #include <nepomuk/global.h>
53 #include <nepomuk/resourcemanager.h>
54 //#include <nepomuk/tag.h>
57 #include <QMouseEvent>
58 #include <QStylePainter>
63 #include <QHeaderView>
64 #include <QInputDialog>
66 ProjectList::ProjectList(QWidget *parent) :
75 m_transcodeAction(NULL),
82 m_listView = new ProjectListView(this);;
83 QVBoxLayout *layout = new QVBoxLayout;
84 layout->setContentsMargins(0, 0, 0, 0);
85 layout->setSpacing(0);
88 KTreeWidgetSearchLine *searchView = new KTreeWidgetSearchLine(this);
89 m_toolbar = new QToolBar("projectToolBar", this);
90 m_toolbar->addWidget(searchView);
91 int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
92 m_toolbar->setIconSize(QSize(s, s));
93 searchView->setTreeWidget(m_listView);
95 m_addButton = new QToolButton(m_toolbar);
96 m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
97 m_toolbar->addWidget(m_addButton);
99 layout->addWidget(m_toolbar);
100 layout->addWidget(m_listView);
103 m_queueTimer.setInterval(100);
104 connect(&m_queueTimer, SIGNAL(timeout()), this, SLOT(slotProcessNextClipInQueue()));
105 m_queueTimer.setSingleShot(true);
108 connect(m_listView, SIGNAL(projectModified()), this, SIGNAL(projectModified()));
109 connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
110 connect(m_listView, SIGNAL(focusMonitor()), this, SLOT(slotClipSelected()));
111 connect(m_listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
112 connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
113 connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
114 connect(m_listView, SIGNAL(addClip(const QList <QUrl>, const QString &, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &, const QString &)));
115 connect(m_listView, SIGNAL(addClipCut(const QString &, int, int)), this, SLOT(slotAddClipCut(const QString &, int, int)));
116 connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
117 connect(m_listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
119 m_listViewDelegate = new ItemDelegate(m_listView);
120 m_listView->setItemDelegate(m_listViewDelegate);
122 if (KdenliveSettings::activate_nepomuk()) {
123 Nepomuk::ResourceManager::instance()->init();
124 if (!Nepomuk::ResourceManager::instance()->initialized()) {
125 kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
126 KdenliveSettings::setActivate_nepomuk(false);
132 ProjectList::~ProjectList()
136 m_listView->blockSignals(true);
138 delete m_listViewDelegate;
141 void ProjectList::focusTree() const
143 m_listView->setFocus();
146 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
148 QList <QAction *> actions = addMenu->actions();
149 for (int i = 0; i < actions.count(); i++) {
150 if (actions.at(i)->data().toString() == "clip_properties") {
151 m_editAction = actions.at(i);
152 m_toolbar->addAction(m_editAction);
155 } else if (actions.at(i)->data().toString() == "delete_clip") {
156 m_deleteAction = actions.at(i);
157 m_toolbar->addAction(m_deleteAction);
160 } else if (actions.at(i)->data().toString() == "edit_clip") {
161 m_openAction = actions.at(i);
164 } else if (actions.at(i)->data().toString() == "reload_clip") {
165 m_reloadAction = actions.at(i);
171 QMenu *m = new QMenu();
172 m->addActions(actions);
173 m_addButton->setMenu(m);
174 m_addButton->setDefaultAction(defaultAction);
175 m_menu = new QMenu();
176 m_menu->addActions(addMenu->actions());
179 void ProjectList::setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu, QMenu *inTimelineMenu)
183 QMenu *menu = m_addButton->menu();
184 menu->addMenu(addMenu);
185 m_addButton->setMenu(menu);
187 m_menu->addMenu(addMenu);
188 if (addMenu->isEmpty())
189 addMenu->setEnabled(false);
190 m_menu->addMenu(transcodeMenu);
191 if (transcodeMenu->isEmpty())
192 transcodeMenu->setEnabled(false);
193 m_transcodeAction = transcodeMenu;
194 m_menu->addAction(m_reloadAction);
195 m_menu->addMenu(inTimelineMenu);
196 inTimelineMenu->setEnabled(false);
197 m_menu->addAction(m_editAction);
198 m_menu->addAction(m_openAction);
199 m_menu->addAction(m_deleteAction);
200 m_menu->insertSeparator(m_deleteAction);
204 QByteArray ProjectList::headerInfo() const
206 return m_listView->header()->saveState();
209 void ProjectList::setHeaderInfo(const QByteArray &state)
211 m_listView->header()->restoreState(state);
214 void ProjectList::updateProjectFormat(Timecode t)
219 void ProjectList::slotEditClip()
221 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
222 if (list.count() > 1) {
223 editClipSelection(list);
227 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
229 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE)
230 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
232 item = static_cast <ProjectItem*>(m_listView->currentItem());
233 if (item && (item->flags() & Qt::ItemIsDragEnabled)) {
234 emit clipSelected(item->referencedClip());
235 emit showClipProperties(item->referencedClip());
239 void ProjectList::editClipSelection(QList<QTreeWidgetItem *> list)
241 // Gather all common properties
242 QMap <QString, QString> commonproperties;
243 QList <DocClipBase *> clipList;
244 commonproperties.insert("force_aspect_ratio", "-");
245 commonproperties.insert("force_fps", "-");
246 commonproperties.insert("force_progressive", "-");
247 commonproperties.insert("threads", "-");
248 commonproperties.insert("video_index", "-");
249 commonproperties.insert("audio_index", "-");
251 bool allowDurationChange = true;
252 int commonDuration = -1;
254 for (int i = 0; i < list.count(); i++) {
256 if (list.at(i)->type() == PROJECTFOLDERTYPE)
258 if (list.at(i)->type() == PROJECTSUBCLIPTYPE)
259 item = static_cast <ProjectItem*>(list.at(i)->parent());
261 item = static_cast <ProjectItem*>(list.at(i));
262 if (!(item->flags() & Qt::ItemIsDragEnabled))
266 DocClipBase *clip = item->referencedClip();
267 if (clipList.contains(clip)) continue;
268 if (clip->clipType() != COLOR && clip->clipType() != IMAGE && clip->clipType() != TEXT)
269 allowDurationChange = false;
270 if (allowDurationChange && commonDuration != 0) {
271 if (commonDuration == -1)
272 commonDuration = clip->duration().frames(m_fps);
273 else if (commonDuration != clip->duration().frames(m_fps))
276 clipList.append(clip);
277 QMap <QString, QString> clipprops = clip->properties();
278 QMapIterator<QString, QString> p(commonproperties);
279 while (p.hasNext()) {
281 if (p.value().isEmpty()) continue;
282 if (clipprops.contains(p.key())) {
283 if (p.value() == "-")
284 commonproperties.insert(p.key(), clipprops.value(p.key()));
285 else if (p.value() != clipprops.value(p.key()))
286 commonproperties.insert(p.key(), QString());
288 commonproperties.insert(p.key(), QString());
293 if (allowDurationChange)
294 commonproperties.insert("out", QString::number(commonDuration));
295 QMapIterator<QString, QString> p(commonproperties);
296 while (p.hasNext()) {
298 kDebug() << "Result: " << p.key() << " = " << p.value();
300 emit showClipProperties(clipList, commonproperties);
303 void ProjectList::slotOpenClip()
306 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
308 if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1)
309 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
311 item = static_cast <ProjectItem*>(m_listView->currentItem());
313 if (item->clipType() == IMAGE) {
314 if (KdenliveSettings::defaultimageapp().isEmpty())
315 KMessageBox::sorry(this, i18n("Please set a default application to open images in the Settings dialog"));
317 QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
319 if (item->clipType() == AUDIO) {
320 if (KdenliveSettings::defaultaudioapp().isEmpty())
321 KMessageBox::sorry(this, i18n("Please set a default application to open audio files in the Settings dialog"));
323 QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
328 void ProjectList::cleanup()
330 m_listView->clearSelection();
331 QTreeWidgetItemIterator it(m_listView);
334 if ((*it)->type() != PROJECTCLIPTYPE) {
338 item = static_cast <ProjectItem *>(*it);
339 if (item->numReferences() == 0)
340 item->setSelected(true);
346 void ProjectList::trashUnusedClips()
348 QTreeWidgetItemIterator it(m_listView);
353 if ((*it)->type() != PROJECTCLIPTYPE) {
357 item = static_cast <ProjectItem *>(*it);
358 if (item->numReferences() == 0) {
359 ids << item->clipId();
360 KUrl url = item->clipUrl();
361 if (!url.isEmpty() && !urls.contains(url.path()))
367 // Check that we don't use the URL in another clip
368 QTreeWidgetItemIterator it2(m_listView);
370 if ((*it2)->type() != PROJECTCLIPTYPE) {
374 item = static_cast <ProjectItem *>(*it2);
375 if (item->numReferences() > 0) {
376 KUrl url = item->clipUrl();
377 if (!url.isEmpty() && urls.contains(url.path())) urls.removeAll(url.path());
382 emit deleteProjectClips(ids, QMap <QString, QString>());
383 for (int i = 0; i < urls.count(); i++)
384 KIO::NetAccess::del(KUrl(urls.at(i)), this);
387 void ProjectList::slotReloadClip(const QString &id)
389 QList<QTreeWidgetItem *> selected;
391 selected = m_listView->selectedItems();
393 selected.append(getItemById(id));
395 for (int i = 0; i < selected.count(); i++) {
396 if (selected.at(i)->type() != PROJECTCLIPTYPE) {
397 if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
398 for (int j = 0; j < selected.at(i)->childCount(); j++)
399 selected.append(selected.at(i)->child(j));
403 item = static_cast <ProjectItem *>(selected.at(i));
405 if (item->clipType() == TEXT) {
406 if (!item->referencedClip()->getProperty("xmltemplate").isEmpty())
407 regenerateTemplate(item);
408 } else if (item->clipType() != COLOR && item->clipType() != SLIDESHOW && item->referencedClip() && item->referencedClip()->checkHash() == false) {
409 item->referencedClip()->setPlaceHolder(true);
410 item->setProperty("file_hash", QString());
411 } else if (item->clipType() == IMAGE) {
412 item->referencedClip()->producer()->set("force_reload", 1);
414 //requestClipInfo(item->toXml(), item->clipId(), true);
415 // Clear the file_hash value, which will cause a complete reload of the clip
416 emit getFileProperties(item->toXml(), item->clipId(), m_listView->iconSize().height(), true);
421 void ProjectList::slotModifiedClip(const QString &id)
423 ProjectItem *item = getItemById(id);
425 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
426 if (!pixmap.isNull()) {
428 p.fillRect(0, 0, pixmap.width(), pixmap.height(), QColor(255, 255, 255, 200));
429 p.drawPixmap(0, 0, KIcon("view-refresh").pixmap(m_listView->iconSize()));
432 pixmap = KIcon("view-refresh").pixmap(m_listView->iconSize());
434 item->setData(0, Qt::DecorationRole, pixmap);
438 void ProjectList::slotMissingClip(const QString &id)
440 ProjectItem *item = getItemById(id);
442 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
443 if (item->referencedClip()) {
444 item->referencedClip()->setPlaceHolder(true);
445 if (m_render == NULL) kDebug() << "********* ERROR, NULL RENDR";
446 item->referencedClip()->setProducer(m_render->invalidProducer(id), true);
447 item->slotSetToolTip();
448 emit clipNeedsReload(id, true);
452 emit displayMessage(i18n("Check missing clips"), -2);
453 emit updateRenderStatus();
456 void ProjectList::slotAvailableClip(const QString &id)
458 ProjectItem *item = getItemById(id);
461 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
462 if (item->referencedClip()) { // && item->referencedClip()->checkHash() == false) {
463 item->setProperty("file_hash", QString());
467 item->referencedClip()->setValid();
468 item->slotSetToolTip();
471 emit updateRenderStatus();
474 bool ProjectList::hasMissingClips()
476 bool missing = false;
477 QTreeWidgetItemIterator it(m_listView);
479 if ((*it)->type() == PROJECTCLIPTYPE && !((*it)->flags() & Qt::ItemIsDragEnabled)) {
488 void ProjectList::setRenderer(Render *projectRender)
490 m_render = projectRender;
491 m_listView->setIconSize(QSize((ProjectItem::itemDefaultHeight() - 2) * m_render->dar(), ProjectItem::itemDefaultHeight() - 2));
494 void ProjectList::slotClipSelected()
496 if (!m_listView->isEnabled()) return;
497 if (m_listView->currentItem()) {
498 if (m_listView->currentItem()->type() == PROJECTFOLDERTYPE) {
499 emit clipSelected(NULL);
500 m_editAction->setEnabled(false);
501 m_deleteAction->setEnabled(true);
502 m_openAction->setEnabled(false);
503 m_reloadAction->setEnabled(false);
504 m_transcodeAction->setEnabled(false);
507 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
508 // this is a sub item, use base clip
509 m_deleteAction->setEnabled(true);
510 clip = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
511 if (clip == NULL) kDebug() << "-----------ERROR";
512 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
513 emit clipSelected(clip->referencedClip(), sub->zone());
514 m_transcodeAction->setEnabled(false);
517 clip = static_cast <ProjectItem*>(m_listView->currentItem());
519 emit clipSelected(clip->referencedClip());
520 m_editAction->setEnabled(true);
521 m_deleteAction->setEnabled(true);
522 m_reloadAction->setEnabled(true);
523 m_transcodeAction->setEnabled(true);
524 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
525 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
526 m_openAction->setEnabled(true);
527 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
528 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
529 m_openAction->setEnabled(true);
531 m_openAction->setEnabled(false);
533 // Display relevant transcoding actions only
534 adjustTranscodeActions(clip);
535 // Display uses in timeline
536 emit findInTimeline(clip->clipId());
539 emit clipSelected(NULL);
540 m_editAction->setEnabled(false);
541 m_deleteAction->setEnabled(false);
542 m_openAction->setEnabled(false);
543 m_reloadAction->setEnabled(false);
544 m_transcodeAction->setEnabled(false);
548 void ProjectList::adjustTranscodeActions(ProjectItem *clip) const
550 if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW) {
551 m_transcodeAction->setEnabled(false);
554 m_transcodeAction->setEnabled(true);
555 QList<QAction *> transcodeActions = m_transcodeAction->actions();
558 for (int i = 0; i < transcodeActions.count(); i++) {
559 data = transcodeActions.at(i)->data().toStringList();
560 if (data.count() > 2) {
561 condition = data.at(2);
562 if (condition.startsWith("vcodec"))
563 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
564 else if (condition.startsWith("acodec"))
565 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
571 void ProjectList::slotPauseMonitor()
577 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
579 ProjectItem *item = getItemById(id);
581 slotUpdateClipProperties(item, properties);
582 if (properties.contains("out") || properties.contains("force_fps")) {
584 } else if (properties.contains("colour") || properties.contains("resource") || properties.contains("xmldata") || properties.contains("force_aspect_ratio") || properties.contains("templatetext")) {
585 slotRefreshClipThumbnail(item);
591 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
595 clip->setProperties(properties);
596 if (properties.contains("name")) {
597 m_listView->blockSignals(true);
598 clip->setText(0, properties.value("name"));
599 m_listView->blockSignals(false);
600 emit clipNameChanged(clip->clipId(), properties.value("name"));
602 if (properties.contains("description")) {
603 CLIPTYPE type = clip->clipType();
604 m_listView->blockSignals(true);
605 clip->setText(1, properties.value("description"));
606 m_listView->blockSignals(false);
608 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
609 // Use Nepomuk system to store clip description
610 Nepomuk::Resource f(clip->clipUrl().path());
611 f.setDescription(properties.value("description"));
614 emit projectModified();
618 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
620 if (item->type() == PROJECTSUBCLIPTYPE) {
621 // this is a sub-item
623 // user edited description
624 SubProjectItem *sub = static_cast <SubProjectItem*>(item);
625 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
626 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), sub->zone(), sub->description(), sub->text(1), true);
627 m_commandStack->push(command);
628 //slotUpdateCutClipProperties(sub->clipId(), sub->zone(), sub->text(1), sub->text(1));
632 if (item->type() == PROJECTFOLDERTYPE) {
634 FolderProjectItem *folder = static_cast <FolderProjectItem*>(item);
635 editFolder(item->text(0), folder->groupName(), folder->clipId());
636 folder->setGroupName(item->text(0));
637 m_doc->clipManager()->addFolder(folder->clipId(), item->text(0));
638 const int children = item->childCount();
639 for (int i = 0; i < children; i++) {
640 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
641 child->setProperty("groupname", item->text(0));
647 ProjectItem *clip = static_cast <ProjectItem*>(item);
649 if (clip->referencedClip()) {
650 QMap <QString, QString> oldprops;
651 QMap <QString, QString> newprops;
652 oldprops["description"] = clip->referencedClip()->getProperty("description");
653 newprops["description"] = item->text(1);
655 if (clip->clipType() == TEXT) {
656 // This is a text template clip, update the image
657 /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
658 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/
659 oldprops.insert("templatetext", clip->referencedClip()->getProperty("templatetext"));
660 newprops.insert("templatetext", item->text(1));
662 slotUpdateClipProperties(clip->clipId(), newprops);
663 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
664 m_commandStack->push(command);
666 } else if (column == 0) {
667 if (clip->referencedClip()) {
668 QMap <QString, QString> oldprops;
669 QMap <QString, QString> newprops;
670 oldprops["name"] = clip->referencedClip()->getProperty("name");
671 newprops["name"] = item->text(0);
672 slotUpdateClipProperties(clip, newprops);
673 emit projectModified();
674 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
675 m_commandStack->push(command);
680 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
682 bool enable = item ? true : false;
683 m_editAction->setEnabled(enable);
684 m_deleteAction->setEnabled(enable);
685 m_reloadAction->setEnabled(enable);
686 m_transcodeAction->setEnabled(enable);
688 ProjectItem *clip = NULL;
689 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
690 clip = static_cast <ProjectItem*>(item->parent());
691 m_transcodeAction->setEnabled(false);
692 } else if (m_listView->currentItem()->type() == PROJECTCLIPTYPE) {
693 clip = static_cast <ProjectItem*>(item);
694 // Display relevant transcoding actions only
695 adjustTranscodeActions(clip);
696 // Display uses in timeline
697 emit findInTimeline(clip->clipId());
699 m_transcodeAction->setEnabled(false);
701 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
702 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
703 m_openAction->setEnabled(true);
704 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
705 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
706 m_openAction->setEnabled(true);
708 m_openAction->setEnabled(false);
712 m_openAction->setEnabled(false);
717 void ProjectList::slotRemoveClip()
719 if (!m_listView->currentItem())
722 QMap <QString, QString> folderids;
723 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
725 QUndoCommand *delCommand = new QUndoCommand();
726 delCommand->setText(i18n("Delete Clip Zone"));
728 for (int i = 0; i < selected.count(); i++) {
729 if (selected.at(i)->type() == PROJECTSUBCLIPTYPE) {
731 SubProjectItem *sub = static_cast <SubProjectItem *>(selected.at(i));
732 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
733 new AddClipCutCommand(this, item->clipId(), sub->zone().x(), sub->zone().y(), sub->description(), false, true, delCommand);
734 } else if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
736 FolderProjectItem *folder = static_cast <FolderProjectItem *>(selected.at(i));
737 folderids[folder->groupName()] = folder->clipId();
738 int children = folder->childCount();
740 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)
742 for (int i = 0; i < children; ++i) {
743 ProjectItem *child = static_cast <ProjectItem *>(folder->child(i));
744 ids << child->clipId();
747 ProjectItem *item = static_cast <ProjectItem *>(selected.at(i));
748 ids << item->clipId();
749 if (item->numReferences() > 0 && 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)
754 if (delCommand->childCount() == 0)
757 m_commandStack->push(delCommand);
758 emit deleteProjectClips(ids, folderids);
761 void ProjectList::updateButtons() const
763 if (m_listView->topLevelItemCount() == 0) {
764 m_deleteAction->setEnabled(false);
766 m_deleteAction->setEnabled(true);
767 if (!m_listView->currentItem())
768 m_listView->setCurrentItem(m_listView->topLevelItem(0));
769 QTreeWidgetItem *item = m_listView->currentItem();
770 if (item && item->type() == PROJECTCLIPTYPE) {
771 m_editAction->setEnabled(true);
772 m_openAction->setEnabled(true);
773 m_reloadAction->setEnabled(true);
774 m_transcodeAction->setEnabled(true);
779 m_editAction->setEnabled(false);
780 m_openAction->setEnabled(false);
781 m_reloadAction->setEnabled(false);
782 m_transcodeAction->setEnabled(false);
785 void ProjectList::selectItemById(const QString &clipId)
787 ProjectItem *item = getItemById(clipId);
789 m_listView->setCurrentItem(item);
793 void ProjectList::slotDeleteClip(const QString &clipId)
795 ProjectItem *item = getItemById(clipId);
797 kDebug() << "/// Cannot find clip to delete";
800 m_listView->blockSignals(true);
801 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
802 if (!newSelectedItem)
803 newSelectedItem = m_listView->itemBelow(item);
805 m_doc->clipManager()->deleteClip(clipId);
806 m_listView->blockSignals(false);
807 if (newSelectedItem) {
808 m_listView->setCurrentItem(newSelectedItem);
811 emit clipSelected(NULL);
816 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
818 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
819 m_commandStack->push(command);
820 m_doc->setModified(true);
823 void ProjectList::slotAddFolder()
825 AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
826 m_commandStack->push(command);
829 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
832 FolderProjectItem *item = getFolderItemById(clipId);
834 m_doc->clipManager()->deleteFolder(clipId);
835 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
836 if (!newSelectedItem)
837 newSelectedItem = m_listView->itemBelow(item);
840 m_listView->setCurrentItem(newSelectedItem);
846 FolderProjectItem *item = getFolderItemById(clipId);
848 m_listView->blockSignals(true);
849 item->setGroupName(foldername);
850 m_listView->blockSignals(false);
851 m_doc->clipManager()->addFolder(clipId, foldername);
852 const int children = item->childCount();
853 for (int i = 0; i < children; i++) {
854 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
855 child->setProperty("groupname", foldername);
859 m_listView->blockSignals(true);
860 m_listView->setCurrentItem(new FolderProjectItem(m_listView, QStringList() << foldername, clipId));
861 m_doc->clipManager()->addFolder(clipId, foldername);
862 m_listView->blockSignals(false);
863 m_listView->editItem(m_listView->currentItem(), 0);
867 m_doc->setModified(true);
872 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
874 QMapIterator<QString, QString> i(map);
875 QUndoCommand *delCommand = new QUndoCommand();
876 delCommand->setText(i18n("Delete Folder"));
877 while (i.hasNext()) {
879 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
881 m_commandStack->push(delCommand);
884 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
886 m_listView->setEnabled(false);
888 m_listView->blockSignals(true);
890 // remove file_hash so that we load all properties for the clip
891 QDomElement e = clip->toXML().cloneNode().toElement();
892 e.removeAttribute("file_hash");
893 m_infoQueue.insert(clip->getId(), e);
894 //m_render->getFileProperties(clip->toXML(), clip->getId(), true);
896 clip->askForAudioThumbs();
897 const QString parent = clip->getProperty("groupid");
898 ProjectItem *item = NULL;
899 if (!parent.isEmpty()) {
900 FolderProjectItem *parentitem = getFolderItemById(parent);
903 QString groupName = clip->getProperty("groupname");
904 //kDebug() << "Adding clip to new group: " << groupName;
905 if (groupName.isEmpty()) groupName = i18n("Folder");
907 parentitem = new FolderProjectItem(m_listView, text, parent);
911 item = new ProjectItem(parentitem, clip);
914 item = new ProjectItem(m_listView, clip);
915 KUrl url = clip->fileURL();
917 if (getProperties == false && !clip->getClipHash().isEmpty()) {
918 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
919 if (QFile::exists(cachedPixmap)) {
920 QPixmap pix(cachedPixmap);
922 KIO::NetAccess::del(KUrl(cachedPixmap), this);
923 item->setData(0, Qt::DecorationRole, pix);
927 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
928 // if file has Nepomuk comment, use it
929 Nepomuk::Resource f(url.path());
930 QString annotation = f.description();
931 if (!annotation.isEmpty()) item->setText(1, annotation);
932 item->setText(2, QString::number(f.rating()));
936 QList <CutZoneInfo> cuts = clip->cutZones();
937 if (!cuts.isEmpty()) {
938 for (int i = 0; i < cuts.count(); i++) {
939 SubProjectItem *sub = new SubProjectItem(item, cuts.at(i).zone.x(), cuts.at(i).zone.y(), cuts.at(i).description);
940 if (!clip->getClipHash().isEmpty()) {
941 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(cuts.at(i).zone.x()) + ".png";
942 if (QFile::exists(cachedPixmap)) {
943 QPixmap pix(cachedPixmap);
945 KIO::NetAccess::del(KUrl(cachedPixmap), this);
946 sub->setData(0, Qt::DecorationRole, pix);
951 if (m_listView->isEnabled()) {
954 m_listView->blockSignals(false);
956 if (getProperties && !m_queueTimer.isActive())
957 slotProcessNextClipInQueue();
960 void ProjectList::slotResetProjectList()
963 emit clipSelected(NULL);
964 m_thumbnailQueue.clear();
969 void ProjectList::requestClipInfo(const QDomElement xml, const QString id)
972 m_infoQueue.insert(id, xml);
973 //if (m_infoQueue.count() == 1 || ) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
976 void ProjectList::slotProcessNextClipInQueue()
978 if (m_infoQueue.isEmpty()) {
979 slotProcessNextThumbnail();
983 QMap<QString, QDomElement>::const_iterator j = m_infoQueue.constBegin();
984 if (j != m_infoQueue.constEnd()) {
985 const QDomElement dom = j.value();
986 const QString id = j.key();
987 m_infoQueue.remove(j.key());
988 emit getFileProperties(dom, id, m_listView->iconSize().height(), false);
990 if (!m_infoQueue.isEmpty()) m_queueTimer.start();
993 void ProjectList::slotUpdateClip(const QString &id)
995 ProjectItem *item = getItemById(id);
996 m_listView->blockSignals(true);
997 if (item) item->setData(0, UsageRole, QString::number(item->numReferences()));
998 m_listView->blockSignals(false);
1001 void ProjectList::updateAllClips()
1003 m_listView->setSortingEnabled(false);
1004 kDebug() << "// UPDATE ALL CLPY";
1006 QTreeWidgetItemIterator it(m_listView);
1009 m_listView->blockSignals(true);
1011 if ((*it)->type() == PROJECTSUBCLIPTYPE) {
1013 SubProjectItem *sub = static_cast <SubProjectItem *>(*it);
1014 if (sub->data(0, Qt::DecorationRole).isNull()) {
1015 item = static_cast <ProjectItem *>((*it)->parent());
1016 requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x()));
1020 } else if ((*it)->type() == PROJECTFOLDERTYPE) {
1025 item = static_cast <ProjectItem *>(*it);
1026 clip = item->referencedClip();
1027 if (item->referencedClip()->producer() == NULL) {
1028 if (clip->isPlaceHolder() == false)
1029 requestClipInfo(clip->toXML(), clip->getId());
1030 else if (!clip->isPlaceHolder())
1031 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
1033 if (item->data(0, Qt::DecorationRole).isNull())
1034 requestClipThumbnail(clip->getId());
1035 if (item->data(0, DurationRole).toString().isEmpty())
1036 item->changeDuration(item->referencedClip()->producer()->get_playtime());
1038 item->setData(0, UsageRole, QString::number(item->numReferences()));
1040 //qApp->processEvents();
1043 if (!m_queueTimer.isActive())
1044 m_queueTimer.start();
1045 if (m_listView->isEnabled())
1046 m_listView->blockSignals(false);
1047 m_listView->setSortingEnabled(true);
1048 if (m_infoQueue.isEmpty())
1049 slotProcessNextThumbnail();
1053 QString ProjectList::getExtensions()
1055 // Build list of mime types
1056 QStringList mimeTypes = QStringList() << "application/x-kdenlive" << "application/x-kdenlivetitle" << "video/mlt-playlist" << "text/plain"
1057 << "video/x-flv" << "application/vnd.rn-realmedia" << "video/x-dv" << "video/dv" << "video/x-msvideo" << "video/x-matroska" << "video/mpeg" << "video/ogg" << "video/x-ms-wmv" << "video/mp4" << "video/quicktime"
1058 << "audio/x-flac" << "audio/x-matroska" << "audio/mp4" << "audio/mpeg" << "audio/x-mp3" << "audio/ogg" << "audio/x-wav" << "application/ogg" << "application/mxf"
1059 << "image/gif" << "image/jpeg" << "image/png" << "image/x-tga" << "image/x-bmp" << "image/svg+xml" << "image/tiff" << "image/x-xcf" << "image/x-xcf-gimp" << "image/x-vnd.adobe.photoshop" << "image/x-pcx" << "image/x-exr";
1061 QString allExtensions;
1062 foreach(const QString & mimeType, mimeTypes) {
1063 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
1065 allExtensions.append(mime->patterns().join(" "));
1066 allExtensions.append(' ');
1069 return allExtensions.simplified();
1072 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
1074 if (!m_commandStack)
1075 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1078 if (givenList.isEmpty()) {
1079 QString allExtensions = getExtensions();
1080 const QString dialogFilter = allExtensions + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
1081 QCheckBox *b = new QCheckBox(i18n("Import image sequence"));
1082 b->setChecked(KdenliveSettings::autoimagesequence());
1083 KFileDialog *d = new KFileDialog(KUrl("kfiledialog:///clipfolder"), dialogFilter, this, b);
1084 d->setOperationMode(KFileDialog::Opening);
1085 d->setMode(KFile::Files);
1087 list = d->selectedUrls();
1088 if (b->isChecked() && list.count() == 1) {
1089 // Check for image sequence
1090 KUrl url = list.at(0);
1091 QString fileName = url.fileName().section('.', 0, -2);
1092 if (fileName.at(fileName.size() - 1).isDigit()) {
1093 KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
1094 if (item.mimetype().startsWith("image")) {
1096 // import as sequence if we found more than one image in the sequence
1097 QString pattern = SlideshowClip::selectedPath(url.path(), false, QString(), &count);
1100 QStringList groupInfo = getGroup();
1102 // get image sequence base name
1103 while (fileName.at(fileName.size() - 1).isDigit()) {
1107 m_doc->slotCreateSlideshowClipFile(fileName, pattern, count, m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()),
1108 false, false, false,
1109 m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))), QString(), 0,
1110 QString(), groupInfo.at(0), groupInfo.at(1));
1118 for (int i = 0; i < givenList.count(); i++)
1119 list << givenList.at(i);
1122 foreach(const KUrl & file, list) {
1123 // Check there is no folder here
1124 KMimeType::Ptr type = KMimeType::findByUrl(file);
1125 if (type->is("inode/directory")) {
1126 // user dropped a folder
1127 list.removeAll(file);
1134 if (givenList.isEmpty()) {
1135 QStringList groupInfo = getGroup();
1136 m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1));
1138 m_doc->slotAddClipList(list, groupName, groupId);
1142 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
1144 ProjectItem *item = getItemById(id);
1145 QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
1147 const QString path = item->referencedClip()->fileURL().path();
1148 if (item->referencedClip()->isPlaceHolder()) replace = false;
1149 if (!path.isEmpty()) {
1151 KMessageBox::sorry(this, i18n("Clip <b>%1</b><br />is invalid, will be removed from project.", path));
1152 else if (KMessageBox::questionYesNo(this, i18n("Clip <b>%1</b><br />is missing or invalid. Remove it from project?", path), i18n("Invalid clip")) == KMessageBox::Yes)
1156 emit deleteProjectClips(QStringList() << id, QMap <QString, QString>());
1160 void ProjectList::slotAddColorClip()
1162 if (!m_commandStack)
1163 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1165 QDialog *dia = new QDialog(this);
1166 Ui::ColorClip_UI dia_ui;
1167 dia_ui.setupUi(dia);
1168 dia->setWindowTitle(i18n("Color Clip"));
1169 dia_ui.clip_name->setText(i18n("Color Clip"));
1171 TimecodeDisplay *t = new TimecodeDisplay(m_timecode);
1172 t->setValue(KdenliveSettings::color_duration());
1173 t->setTimeCodeFormat(false);
1174 dia_ui.clip_durationBox->addWidget(t);
1175 dia_ui.clip_color->setColor(KdenliveSettings::colorclipcolor());
1177 if (dia->exec() == QDialog::Accepted) {
1178 QString color = dia_ui.clip_color->color().name();
1179 KdenliveSettings::setColorclipcolor(color);
1180 color = color.replace(0, 1, "0x") + "ff";
1181 QStringList groupInfo = getGroup();
1182 m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, m_timecode.getTimecode(t->gentime()), groupInfo.at(0), groupInfo.at(1));
1189 void ProjectList::slotAddSlideshowClip()
1191 if (!m_commandStack)
1192 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1194 SlideshowClip *dia = new SlideshowClip(m_timecode, this);
1196 if (dia->exec() == QDialog::Accepted) {
1197 QStringList groupInfo = getGroup();
1198 m_doc->slotCreateSlideshowClipFile(dia->clipName(), dia->selectedPath(), dia->imageCount(), dia->clipDuration(),
1199 dia->loop(), dia->crop(), dia->fade(),
1200 dia->lumaDuration(), dia->lumaFile(), dia->softness(),
1201 dia->animation(), groupInfo.at(0), groupInfo.at(1));
1206 void ProjectList::slotAddTitleClip()
1208 QStringList groupInfo = getGroup();
1209 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
1212 void ProjectList::slotAddTitleTemplateClip()
1214 if (!m_commandStack)
1215 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1217 QStringList groupInfo = getGroup();
1219 // Get the list of existing templates
1221 filter << "*.kdenlivetitle";
1222 const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
1223 QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
1225 QDialog *dia = new QDialog(this);
1226 Ui::TemplateClip_UI dia_ui;
1227 dia_ui.setupUi(dia);
1228 for (int i = 0; i < templateFiles.size(); ++i)
1229 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
1231 if (!templateFiles.isEmpty())
1232 dia_ui.buttonBox->button(QDialogButtonBox::Ok)->setFocus();
1233 dia_ui.template_list->fileDialog()->setFilter("*.kdenlivetitle");
1234 //warning: setting base directory doesn't work??
1235 KUrl startDir(path);
1236 dia_ui.template_list->fileDialog()->setUrl(startDir);
1237 dia_ui.text_box->setHidden(true);
1238 if (dia->exec() == QDialog::Accepted) {
1239 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
1240 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
1241 // Create a cloned template clip
1242 m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
1247 QStringList ProjectList::getGroup() const
1250 QTreeWidgetItem *item = m_listView->currentItem();
1251 while (item && item->type() != PROJECTFOLDERTYPE)
1252 item = item->parent();
1255 FolderProjectItem *folder = static_cast <FolderProjectItem *>(item);
1256 result << folder->groupName() << folder->clipId();
1258 result << QString() << QString();
1263 void ProjectList::setDocument(KdenliveDoc *doc)
1265 m_listView->blockSignals(true);
1266 m_listView->clear();
1267 m_listView->setSortingEnabled(false);
1268 emit clipSelected(NULL);
1269 m_thumbnailQueue.clear();
1270 m_infoQueue.clear();
1271 m_refreshed = false;
1273 m_timecode = doc->timecode();
1274 m_commandStack = doc->commandStack();
1277 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
1278 QMapIterator<QString, QString> f(flist);
1279 while (f.hasNext()) {
1281 (void) new FolderProjectItem(m_listView, QStringList() << f.value(), f.key());
1284 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
1285 for (int i = 0; i < list.count(); i++)
1286 slotAddClip(list.at(i), false);
1288 m_listView->blockSignals(false);
1289 m_toolbar->setEnabled(true);
1290 connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
1291 connect(m_doc->clipManager(), SIGNAL(modifiedClip(const QString &)), this, SLOT(slotModifiedClip(const QString &)));
1292 connect(m_doc->clipManager(), SIGNAL(missingClip(const QString &)), this, SLOT(slotMissingClip(const QString &)));
1293 connect(m_doc->clipManager(), SIGNAL(availableClip(const QString &)), this, SLOT(slotAvailableClip(const QString &)));
1294 connect(m_doc->clipManager(), SIGNAL(checkAllClips()), this, SLOT(updateAllClips()));
1297 QList <DocClipBase*> ProjectList::documentClipList() const
1300 return QList <DocClipBase*> ();
1302 return m_doc->clipManager()->documentClipList();
1305 QDomElement ProjectList::producersList()
1308 QDomElement prods = doc.createElement("producerlist");
1309 doc.appendChild(prods);
1310 kDebug() << "//////////// PRO LIST BUILD PRDSLIST ";
1311 QTreeWidgetItemIterator it(m_listView);
1313 if ((*it)->type() != PROJECTCLIPTYPE) {
1318 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
1324 void ProjectList::slotCheckForEmptyQueue()
1326 if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
1328 emit loadingIsOver();
1329 emit displayMessage(QString(), -1);
1330 m_listView->blockSignals(false);
1331 m_listView->setEnabled(true);
1333 } else if (!m_refreshed) {
1334 QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
1338 void ProjectList::reloadClipThumbnails()
1340 kDebug() << "////////////// RELOAD CLIPS THUMBNAILS!!!";
1341 m_thumbnailQueue.clear();
1342 QTreeWidgetItemIterator it(m_listView);
1344 if ((*it)->type() != PROJECTCLIPTYPE) {
1349 m_thumbnailQueue << ((ProjectItem *)(*it))->clipId();
1352 QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
1355 void ProjectList::requestClipThumbnail(const QString id)
1357 if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id);
1360 void ProjectList::slotProcessNextThumbnail()
1362 if (m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
1363 slotCheckForEmptyQueue();
1366 if (!m_infoQueue.isEmpty()) {
1367 //QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
1370 if (m_thumbnailQueue.count() > 1) {
1371 int max = m_doc->clipManager()->clipsCount();
1372 emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - m_thumbnailQueue.count()) / max));
1374 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
1377 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
1379 QTreeWidgetItem *item = getAnyItemById(clipId);
1381 slotRefreshClipThumbnail(item, update);
1383 slotProcessNextThumbnail();
1386 void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
1388 if (it == NULL) return;
1389 ProjectItem *item = NULL;
1390 bool isSubItem = false;
1392 if (it->type() == PROJECTFOLDERTYPE) return;
1393 if (it->type() == PROJECTSUBCLIPTYPE) {
1394 item = static_cast <ProjectItem *>(it->parent());
1395 frame = static_cast <SubProjectItem *>(it)->zone().x();
1398 item = static_cast <ProjectItem *>(it);
1399 frame = item->referencedClip()->getClipThumbFrame();
1403 DocClipBase *clip = item->referencedClip();
1405 slotProcessNextThumbnail();
1409 int height = m_listView->iconSize().height();
1410 int width = (int)(height * m_render->dar());
1411 if (clip->clipType() == AUDIO)
1412 pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
1413 else if (clip->clipType() == IMAGE)
1414 pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->producer(), 0, width, height));
1416 pix = item->referencedClip()->thumbProducer()->extractImage(frame, width, height);
1418 if (!pix.isNull()) {
1419 m_listView->blockSignals(true);
1420 it->setData(0, Qt::DecorationRole, pix);
1421 if (m_listView->isEnabled())
1422 m_listView->blockSignals(false);
1424 m_doc->cachePixmap(item->getClipHash(), pix);
1426 m_doc->cachePixmap(item->getClipHash() + '#' + QString::number(frame), pix);
1429 emit projectModified();
1430 QTimer::singleShot(30, this, SLOT(slotProcessNextThumbnail()));
1434 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace)
1437 ProjectItem *item = getItemById(clipId);
1438 if (item && producer) {
1439 m_listView->blockSignals(true);
1440 item->setProperties(properties, metadata);
1441 if (item->referencedClip()->isPlaceHolder() && producer->is_valid()) {
1442 item->referencedClip()->setValid();
1443 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1446 //Q_ASSERT_X(item->referencedClip(), "void ProjectList::slotReplyGetFileProperties", QString("Item with groupName %1 does not have a clip associated").arg(item->groupName()).toLatin1());
1447 item->referencedClip()->setProducer(producer, replace);
1448 item->referencedClip()->askForAudioThumbs();
1449 if (!replace && item->data(0, Qt::DecorationRole).isNull())
1450 requestClipThumbnail(clipId);
1451 if (!toReload.isEmpty())
1452 item->slotSetToolTip();
1454 //emit receivedClipDuration(clipId);
1455 if (m_listView->isEnabled() && replace) {
1456 // update clip in clip monitor
1457 emit clipSelected(NULL);
1458 emit clipSelected(item->referencedClip());
1459 //TODO: Make sure the line below has no side effect
1463 // Check if duration changed.
1464 emit receivedClipDuration(clipId);
1467 if (m_listView->isEnabled())
1468 m_listView->blockSignals(false);
1469 /*if (item->icon(0).isNull()) {
1470 requestClipThumbnail(clipId);
1472 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
1473 int max = m_doc->clipManager()->clipsCount();
1474 if (item && m_infoQueue.isEmpty() && m_thumbnailQueue.isEmpty()) {
1475 m_listView->setCurrentItem(item);
1476 if (item->parent()) {
1477 if (item->parent()->type() == PROJECTFOLDERTYPE)
1478 static_cast <FolderProjectItem *>(item->parent())->switchIcon();
1479 } else if (KdenliveSettings::checkfirstprojectclip() && m_listView->topLevelItemCount() == 1) {
1480 // this is the first clip loaded in project, check if we want to adjust project settings to the clip
1481 int width = properties.value("frame_size").section('x', 0, 0).toInt();
1482 int height = properties.value("frame_size").section('x', -1).toInt();
1483 double fps = properties.value("fps").toDouble();
1484 int renderWidth = -1;
1485 int renderHeight = -1;
1486 double renderFps = -1;
1487 if (item->clipType() == IMAGE) {
1488 renderWidth = m_doc->renderer()->renderWidth();
1489 renderHeight = m_doc->height();
1490 } else if (item->clipType() == AV || item->clipType() == VIDEO) {
1491 renderWidth = m_doc->width();
1492 renderHeight = m_doc->height();
1493 renderFps = m_doc->fps();
1495 if ((renderWidth > 0 && width != renderWidth) || (renderHeight > 0 && height != renderHeight) || (renderFps > 0 && qAbs(fps - renderFps) > 0.5)) {
1496 QString suggestedProfile = ProfilesDialog::getPathFromProperties(width, height, fps, item->clipType() == IMAGE);
1497 if (!suggestedProfile.isEmpty()) {
1498 QString description = ProfilesDialog::getSettingsFromFile(suggestedProfile).value("description");
1499 if (KMessageBox::questionYesNo(this, i18n("Your clip does not match current project's profile.\nDo you want to adjust the profile (clip size: %1, fps: %2)?\nSuggested profile is %3", properties.value("frame_size"), fps, description)) == KMessageBox::Yes) {
1500 //Change project profile
1501 emit updateProfile(suggestedProfile);
1503 } else KMessageBox::information(this, i18n("Your clip does not match current project's profile.\nNo existing profile found to match the clip's properties.\nClip size: %1\nFps: %2\n", properties.value("frame_size"), fps));
1506 emit clipSelected(item->referencedClip());
1508 emit displayMessage(i18n("Loading clips"), (int)(100 *(max - m_infoQueue.count()) / max));
1510 if (!toReload.isEmpty())
1511 emit clipNeedsReload(toReload, true);
1512 // small delay so that the app can display the progress info
1513 QTimer::singleShot(30, this, SLOT(slotProcessNextClipInQueue()));
1516 void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
1518 ProjectItem *item = getItemById(clipId);
1519 if (item && !pix.isNull()) {
1520 m_listView->blockSignals(true);
1521 item->setData(0, Qt::DecorationRole, pix);
1522 m_doc->cachePixmap(item->getClipHash(), pix);
1523 if (m_listView->isEnabled())
1524 m_listView->blockSignals(false);
1528 QTreeWidgetItem *ProjectList::getAnyItemById(const QString &id)
1530 QTreeWidgetItemIterator it(m_listView);
1531 QString lookId = id;
1532 if (id.contains('#'))
1533 lookId = id.section('#', 0, 0);
1535 ProjectItem *result = NULL;
1537 if ((*it)->type() != PROJECTCLIPTYPE) {
1542 ProjectItem *item = static_cast<ProjectItem *>(*it);
1543 if (item->clipId() == lookId) {
1549 if (result == NULL || !id.contains('#')) {
1552 for (int i = 0; i < result->childCount(); i++) {
1553 SubProjectItem *sub = static_cast <SubProjectItem *>(result->child(i));
1554 if (sub && sub->zone().x() == id.section('#', 1, 1).toInt())
1563 ProjectItem *ProjectList::getItemById(const QString &id)
1566 QTreeWidgetItemIterator it(m_listView);
1568 if ((*it)->type() != PROJECTCLIPTYPE) {
1573 item = static_cast<ProjectItem *>(*it);
1574 if (item->clipId() == id)
1581 FolderProjectItem *ProjectList::getFolderItemById(const QString &id)
1583 FolderProjectItem *item;
1584 QTreeWidgetItemIterator it(m_listView);
1586 if ((*it)->type() == PROJECTFOLDERTYPE) {
1587 item = static_cast<FolderProjectItem *>(*it);
1588 if (item->clipId() == id)
1596 void ProjectList::slotSelectClip(const QString &ix)
1598 ProjectItem *clip = getItemById(ix);
1600 m_listView->setCurrentItem(clip);
1601 m_listView->scrollToItem(clip);
1602 m_editAction->setEnabled(true);
1603 m_deleteAction->setEnabled(true);
1604 m_reloadAction->setEnabled(true);
1605 m_transcodeAction->setEnabled(true);
1606 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
1607 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
1608 m_openAction->setEnabled(true);
1609 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
1610 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
1611 m_openAction->setEnabled(true);
1613 m_openAction->setEnabled(false);
1618 QString ProjectList::currentClipUrl() const
1621 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return QString();
1622 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
1624 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
1626 item = static_cast <ProjectItem*>(m_listView->currentItem());
1630 return item->clipUrl().path();
1633 KUrl::List ProjectList::getConditionalUrls(const QString &condition) const
1637 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
1638 for (int i = 0; i < list.count(); i++) {
1639 if (list.at(i)->type() == PROJECTFOLDERTYPE)
1641 if (list.at(i)->type() == PROJECTSUBCLIPTYPE) {
1643 item = static_cast <ProjectItem*>(list.at(i)->parent());
1645 item = static_cast <ProjectItem*>(list.at(i));
1647 if (item == NULL || item->type() == COLOR || item->type() == SLIDESHOW || item->type() == TEXT)
1649 DocClipBase *clip = item->referencedClip();
1650 if (!condition.isEmpty()) {
1651 if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section('=', 1, 1)))
1653 else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section('=', 1, 1)))
1656 result.append(item->clipUrl());
1661 void ProjectList::regenerateTemplate(const QString &id)
1663 ProjectItem *clip = getItemById(id);
1665 regenerateTemplate(clip);
1668 void ProjectList::regenerateTemplate(ProjectItem *clip)
1670 //TODO: remove this unused method, only force_reload is necessary
1671 clip->referencedClip()->producer()->set("force_reload", 1);
1674 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
1678 if (!file.open(QIODevice::ReadOnly)) {
1679 kWarning() << "ERROR, CANNOT READ: " << path;
1682 if (!doc.setContent(&file)) {
1683 kWarning() << "ERROR, CANNOT READ: " << path;
1688 QDomNodeList texts = doc.elementsByTagName("content");
1689 for (int i = 0; i < texts.count(); i++) {
1690 QString data = texts.item(i).firstChild().nodeValue();
1691 data.replace("%s", replaceString);
1692 texts.item(i).firstChild().setNodeValue(data);
1698 void ProjectList::slotAddClipCut(const QString &id, int in, int out)
1700 ProjectItem *clip = getItemById(id);
1701 if (clip == NULL || clip->referencedClip()->hasCutZone(QPoint(in, out)))
1703 AddClipCutCommand *command = new AddClipCutCommand(this, id, in, out, QString(), true, false);
1704 m_commandStack->push(command);
1707 void ProjectList::addClipCut(const QString &id, int in, int out, const QString desc, bool newItem)
1709 ProjectItem *clip = getItemById(id);
1711 DocClipBase *base = clip->referencedClip();
1712 base->addCutZone(in, out);
1713 m_listView->blockSignals(true);
1714 SubProjectItem *sub = new SubProjectItem(clip, in, out, desc);
1715 if (newItem && desc.isEmpty() && !m_listView->isColumnHidden(1)) {
1716 if (!clip->isExpanded())
1717 clip->setExpanded(true);
1718 m_listView->scrollToItem(sub);
1719 m_listView->editItem(sub, 1);
1721 QPixmap p = clip->referencedClip()->thumbProducer()->extractImage(in, (int)(sub->sizeHint(0).height() * m_render->dar()), sub->sizeHint(0).height() - 2);
1722 sub->setData(0, Qt::DecorationRole, p);
1723 m_doc->cachePixmap(clip->getClipHash() + '#' + QString::number(in), p);
1724 m_listView->blockSignals(false);
1726 emit projectModified();
1729 void ProjectList::removeClipCut(const QString &id, int in, int out)
1731 ProjectItem *clip = getItemById(id);
1733 DocClipBase *base = clip->referencedClip();
1734 base->removeCutZone(in, out);
1735 SubProjectItem *sub = getSubItem(clip, QPoint(in, out));
1737 m_listView->blockSignals(true);
1739 m_listView->blockSignals(false);
1742 emit projectModified();
1745 SubProjectItem *ProjectList::getSubItem(ProjectItem *clip, QPoint zone)
1747 SubProjectItem *sub = NULL;
1749 for (int i = 0; i < clip->childCount(); i++) {
1750 QTreeWidgetItem *it = clip->child(i);
1751 if (it->type() == PROJECTSUBCLIPTYPE) {
1752 sub = static_cast <SubProjectItem*>(it);
1753 if (sub->zone() == zone)
1763 void ProjectList::slotUpdateClipCut(QPoint p)
1765 if (!m_listView->currentItem() || m_listView->currentItem()->type() != PROJECTSUBCLIPTYPE)
1767 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
1768 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
1769 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), p, sub->text(1), sub->text(1), true);
1770 m_commandStack->push(command);
1773 void ProjectList::doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment)
1775 ProjectItem *clip = getItemById(id);
1776 SubProjectItem *sub = getSubItem(clip, oldzone);
1777 if (sub == NULL || clip == NULL)
1779 DocClipBase *base = clip->referencedClip();
1780 base->updateCutZone(oldzone.x(), oldzone.y(), zone.x(), zone.y(), comment);
1781 m_listView->blockSignals(true);
1783 sub->setDescription(comment);
1784 m_listView->blockSignals(false);
1785 emit projectModified();
1788 void ProjectList::slotForceProcessing(const QString &id)
1790 while (m_infoQueue.contains(id)) {
1791 slotProcessNextClipInQueue();
1795 #include "projectlist.moc"