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>
51 #include <KApplication>
53 #include <nepomuk/global.h>
54 #include <nepomuk/resourcemanager.h>
55 //#include <nepomuk/tag.h>
58 #include <QMouseEvent>
59 #include <QStylePainter>
64 #include <QHeaderView>
65 #include <QInputDialog>
67 ProjectList::ProjectList(QWidget *parent) :
74 m_transcodeAction(NULL),
80 QVBoxLayout *layout = new QVBoxLayout;
81 layout->setContentsMargins(0, 0, 0, 0);
82 layout->setSpacing(0);
85 QFrame *frame = new QFrame;
86 frame->setFrameStyle(QFrame::NoFrame);
87 QHBoxLayout *box = new QHBoxLayout;
88 KTreeWidgetSearchLine *searchView = new KTreeWidgetSearchLine;
90 box->addWidget(searchView);
91 //int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
92 //m_toolbar->setIconSize(QSize(s, s));
94 m_addButton = new QToolButton;
95 m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
96 m_addButton->setAutoRaise(true);
97 box->addWidget(m_addButton);
99 m_editButton = new QToolButton;
100 m_editButton->setAutoRaise(true);
101 box->addWidget(m_editButton);
103 m_deleteButton = new QToolButton;
104 m_deleteButton->setAutoRaise(true);
105 box->addWidget(m_deleteButton);
106 frame->setLayout(box);
107 layout->addWidget(frame);
109 m_listView = new ProjectListView;
110 layout->addWidget(m_listView);
112 searchView->setTreeWidget(m_listView);
114 m_queueTimer.setInterval(100);
115 connect(&m_queueTimer, SIGNAL(timeout()), this, SLOT(slotProcessNextClipInQueue()));
116 m_queueTimer.setSingleShot(true);
119 connect(m_listView, SIGNAL(projectModified()), this, SIGNAL(projectModified()));
120 connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
121 connect(m_listView, SIGNAL(focusMonitor()), this, SLOT(slotClipSelected()));
122 connect(m_listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
123 connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
124 connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
125 connect(m_listView, SIGNAL(addClip(const QList <QUrl>, const QString &, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &, const QString &)));
126 connect(m_listView, SIGNAL(addClipCut(const QString &, int, int)), this, SLOT(slotAddClipCut(const QString &, int, int)));
127 connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
128 connect(m_listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
130 m_listViewDelegate = new ItemDelegate(m_listView);
131 m_listView->setItemDelegate(m_listViewDelegate);
133 if (KdenliveSettings::activate_nepomuk()) {
134 Nepomuk::ResourceManager::instance()->init();
135 if (!Nepomuk::ResourceManager::instance()->initialized()) {
136 kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
137 KdenliveSettings::setActivate_nepomuk(false);
143 ProjectList::~ProjectList()
146 m_listView->blockSignals(true);
148 delete m_listViewDelegate;
151 void ProjectList::focusTree() const
153 m_listView->setFocus();
156 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
158 QList <QAction *> actions = addMenu->actions();
159 for (int i = 0; i < actions.count(); i++) {
160 if (actions.at(i)->data().toString() == "clip_properties") {
161 m_editButton->setDefaultAction(actions.at(i));
164 } else if (actions.at(i)->data().toString() == "delete_clip") {
165 m_deleteButton->setDefaultAction(actions.at(i));
168 } else if (actions.at(i)->data().toString() == "edit_clip") {
169 m_openAction = actions.at(i);
172 } else if (actions.at(i)->data().toString() == "reload_clip") {
173 m_reloadAction = actions.at(i);
179 QMenu *m = new QMenu();
180 m->addActions(actions);
181 m_addButton->setMenu(m);
182 m_addButton->setDefaultAction(defaultAction);
183 m_menu = new QMenu();
184 m_menu->addActions(addMenu->actions());
187 void ProjectList::setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu, QMenu *inTimelineMenu)
191 QMenu *menu = m_addButton->menu();
192 menu->addMenu(addMenu);
193 m_addButton->setMenu(menu);
195 m_menu->addMenu(addMenu);
196 if (addMenu->isEmpty())
197 addMenu->setEnabled(false);
198 m_menu->addMenu(transcodeMenu);
199 if (transcodeMenu->isEmpty())
200 transcodeMenu->setEnabled(false);
201 m_transcodeAction = transcodeMenu;
202 m_menu->addAction(m_reloadAction);
203 m_menu->addMenu(inTimelineMenu);
204 inTimelineMenu->setEnabled(false);
205 m_menu->addAction(m_editButton->defaultAction());
206 m_menu->addAction(m_openAction);
207 m_menu->addAction(m_deleteButton->defaultAction());
208 m_menu->insertSeparator(m_deleteButton->defaultAction());
212 QByteArray ProjectList::headerInfo() const
214 return m_listView->header()->saveState();
217 void ProjectList::setHeaderInfo(const QByteArray &state)
219 m_listView->header()->restoreState(state);
222 void ProjectList::updateProjectFormat(Timecode t)
227 void ProjectList::slotEditClip()
229 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
230 if (list.count() > 1) {
231 editClipSelection(list);
235 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
237 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE)
238 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
240 item = static_cast <ProjectItem*>(m_listView->currentItem());
241 if (item && (item->flags() & Qt::ItemIsDragEnabled)) {
242 emit clipSelected(item->referencedClip());
243 emit showClipProperties(item->referencedClip());
247 void ProjectList::editClipSelection(QList<QTreeWidgetItem *> list)
249 // Gather all common properties
250 QMap <QString, QString> commonproperties;
251 QList <DocClipBase *> clipList;
252 commonproperties.insert("force_aspect_num", "-");
253 commonproperties.insert("force_aspect_den", "-");
254 commonproperties.insert("force_fps", "-");
255 commonproperties.insert("force_progressive", "-");
256 commonproperties.insert("force_tff", "-");
257 commonproperties.insert("threads", "-");
258 commonproperties.insert("video_index", "-");
259 commonproperties.insert("audio_index", "-");
260 commonproperties.insert("force_colorspace", "-");
261 commonproperties.insert("full_luma", "-");
263 bool allowDurationChange = true;
264 int commonDuration = -1;
266 for (int i = 0; i < list.count(); i++) {
268 if (list.at(i)->type() == PROJECTFOLDERTYPE)
270 if (list.at(i)->type() == PROJECTSUBCLIPTYPE)
271 item = static_cast <ProjectItem*>(list.at(i)->parent());
273 item = static_cast <ProjectItem*>(list.at(i));
274 if (!(item->flags() & Qt::ItemIsDragEnabled))
278 DocClipBase *clip = item->referencedClip();
279 if (clipList.contains(clip)) continue;
280 if (clip->clipType() != COLOR && clip->clipType() != IMAGE && clip->clipType() != TEXT)
281 allowDurationChange = false;
282 if (allowDurationChange && commonDuration != 0) {
283 if (commonDuration == -1)
284 commonDuration = clip->duration().frames(m_fps);
285 else if (commonDuration != clip->duration().frames(m_fps))
288 clipList.append(clip);
289 QMap <QString, QString> clipprops = clip->properties();
290 QMapIterator<QString, QString> p(commonproperties);
291 while (p.hasNext()) {
293 if (p.value().isEmpty()) continue;
294 if (clipprops.contains(p.key())) {
295 if (p.value() == "-")
296 commonproperties.insert(p.key(), clipprops.value(p.key()));
297 else if (p.value() != clipprops.value(p.key()))
298 commonproperties.insert(p.key(), QString());
300 commonproperties.insert(p.key(), QString());
305 if (allowDurationChange)
306 commonproperties.insert("out", QString::number(commonDuration));
307 QMapIterator<QString, QString> p(commonproperties);
308 while (p.hasNext()) {
310 kDebug() << "Result: " << p.key() << " = " << p.value();
312 emit showClipProperties(clipList, commonproperties);
315 void ProjectList::slotOpenClip()
318 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
320 if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1)
321 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
323 item = static_cast <ProjectItem*>(m_listView->currentItem());
325 if (item->clipType() == IMAGE) {
326 if (KdenliveSettings::defaultimageapp().isEmpty())
327 KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open images in the Settings dialog"));
329 QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
331 if (item->clipType() == AUDIO) {
332 if (KdenliveSettings::defaultaudioapp().isEmpty())
333 KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open audio files in the Settings dialog"));
335 QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
340 void ProjectList::cleanup()
342 m_listView->clearSelection();
343 QTreeWidgetItemIterator it(m_listView);
346 if ((*it)->type() != PROJECTCLIPTYPE) {
350 item = static_cast <ProjectItem *>(*it);
351 if (item->numReferences() == 0)
352 item->setSelected(true);
358 void ProjectList::trashUnusedClips()
360 QTreeWidgetItemIterator it(m_listView);
365 if ((*it)->type() != PROJECTCLIPTYPE) {
369 item = static_cast <ProjectItem *>(*it);
370 if (item->numReferences() == 0) {
371 ids << item->clipId();
372 KUrl url = item->clipUrl();
373 if (!url.isEmpty() && !urls.contains(url.path()))
379 // Check that we don't use the URL in another clip
380 QTreeWidgetItemIterator it2(m_listView);
382 if ((*it2)->type() != PROJECTCLIPTYPE) {
386 item = static_cast <ProjectItem *>(*it2);
387 if (item->numReferences() > 0) {
388 KUrl url = item->clipUrl();
389 if (!url.isEmpty() && urls.contains(url.path())) urls.removeAll(url.path());
394 emit deleteProjectClips(ids, QMap <QString, QString>());
395 for (int i = 0; i < urls.count(); i++)
396 KIO::NetAccess::del(KUrl(urls.at(i)), this);
399 void ProjectList::slotReloadClip(const QString &id)
401 QList<QTreeWidgetItem *> selected;
403 selected = m_listView->selectedItems();
405 selected.append(getItemById(id));
407 for (int i = 0; i < selected.count(); i++) {
408 if (selected.at(i)->type() != PROJECTCLIPTYPE) {
409 if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
410 for (int j = 0; j < selected.at(i)->childCount(); j++)
411 selected.append(selected.at(i)->child(j));
415 item = static_cast <ProjectItem *>(selected.at(i));
417 if (item->clipType() == TEXT) {
418 if (!item->referencedClip()->getProperty("xmltemplate").isEmpty())
419 regenerateTemplate(item);
420 } else if (item->clipType() != COLOR && item->clipType() != SLIDESHOW && item->referencedClip() && item->referencedClip()->checkHash() == false) {
421 item->referencedClip()->setPlaceHolder(true);
422 item->setProperty("file_hash", QString());
423 } else if (item->clipType() == IMAGE) {
424 item->referencedClip()->producer()->set("force_reload", 1);
426 //requestClipInfo(item->toXml(), item->clipId(), true);
427 // Clear the file_hash value, which will cause a complete reload of the clip
428 emit getFileProperties(item->toXml(), item->clipId(), m_listView->iconSize().height(), true);
433 void ProjectList::slotModifiedClip(const QString &id)
435 ProjectItem *item = getItemById(id);
437 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
438 if (!pixmap.isNull()) {
440 p.fillRect(0, 0, pixmap.width(), pixmap.height(), QColor(255, 255, 255, 200));
441 p.drawPixmap(0, 0, KIcon("view-refresh").pixmap(m_listView->iconSize()));
444 pixmap = KIcon("view-refresh").pixmap(m_listView->iconSize());
446 item->setData(0, Qt::DecorationRole, pixmap);
450 void ProjectList::slotMissingClip(const QString &id)
452 ProjectItem *item = getItemById(id);
454 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
455 if (item->referencedClip()) {
456 item->referencedClip()->setPlaceHolder(true);
457 if (m_render == NULL) kDebug() << "********* ERROR, NULL RENDR";
458 item->referencedClip()->setProducer(m_render->invalidProducer(id), true);
459 item->slotSetToolTip();
460 emit clipNeedsReload(id, true);
464 emit displayMessage(i18n("Check missing clips"), -2);
465 emit updateRenderStatus();
468 void ProjectList::slotAvailableClip(const QString &id)
470 ProjectItem *item = getItemById(id);
473 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
474 if (item->referencedClip()) { // && item->referencedClip()->checkHash() == false) {
475 item->setProperty("file_hash", QString());
479 item->referencedClip()->setValid();
480 item->slotSetToolTip();
483 emit updateRenderStatus();
486 bool ProjectList::hasMissingClips()
488 bool missing = false;
489 QTreeWidgetItemIterator it(m_listView);
491 if ((*it)->type() == PROJECTCLIPTYPE && !((*it)->flags() & Qt::ItemIsDragEnabled)) {
500 void ProjectList::setRenderer(Render *projectRender)
502 m_render = projectRender;
503 m_listView->setIconSize(QSize((ProjectItem::itemDefaultHeight() - 2) * m_render->dar(), ProjectItem::itemDefaultHeight() - 2));
506 void ProjectList::slotClipSelected()
508 if (!m_listView->isEnabled()) return;
509 if (m_listView->currentItem()) {
510 if (m_listView->currentItem()->type() == PROJECTFOLDERTYPE) {
511 emit clipSelected(NULL);
512 m_editButton->defaultAction()->setEnabled(false);
513 m_deleteButton->defaultAction()->setEnabled(true);
514 m_openAction->setEnabled(false);
515 m_reloadAction->setEnabled(false);
516 m_transcodeAction->setEnabled(false);
519 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
520 // this is a sub item, use base clip
521 m_deleteButton->defaultAction()->setEnabled(true);
522 clip = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
523 if (clip == NULL) kDebug() << "-----------ERROR";
524 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
525 emit clipSelected(clip->referencedClip(), sub->zone());
526 m_transcodeAction->setEnabled(false);
529 clip = static_cast <ProjectItem*>(m_listView->currentItem());
531 emit clipSelected(clip->referencedClip());
532 m_editButton->defaultAction()->setEnabled(true);
533 m_deleteButton->defaultAction()->setEnabled(true);
534 m_reloadAction->setEnabled(true);
535 m_transcodeAction->setEnabled(true);
536 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
537 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
538 m_openAction->setEnabled(true);
539 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
540 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
541 m_openAction->setEnabled(true);
543 m_openAction->setEnabled(false);
545 // Display relevant transcoding actions only
546 adjustTranscodeActions(clip);
547 // Display uses in timeline
548 emit findInTimeline(clip->clipId());
551 emit clipSelected(NULL);
552 m_editButton->defaultAction()->setEnabled(false);
553 m_deleteButton->defaultAction()->setEnabled(false);
554 m_openAction->setEnabled(false);
555 m_reloadAction->setEnabled(false);
556 m_transcodeAction->setEnabled(false);
560 void ProjectList::adjustTranscodeActions(ProjectItem *clip) const
562 if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW) {
563 m_transcodeAction->setEnabled(false);
566 m_transcodeAction->setEnabled(true);
567 QList<QAction *> transcodeActions = m_transcodeAction->actions();
570 for (int i = 0; i < transcodeActions.count(); i++) {
571 data = transcodeActions.at(i)->data().toStringList();
572 if (data.count() > 2) {
573 condition = data.at(2);
574 if (condition.startsWith("vcodec"))
575 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
576 else if (condition.startsWith("acodec"))
577 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
583 void ProjectList::slotPauseMonitor()
589 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
591 ProjectItem *item = getItemById(id);
593 slotUpdateClipProperties(item, properties);
594 if (properties.contains("out") || properties.contains("force_fps") || properties.contains("resource")) {
596 } else if (properties.contains("colour") ||
597 properties.contains("xmldata") ||
598 properties.contains("force_aspect_num") ||
599 properties.contains("force_aspect_den") ||
600 properties.contains("templatetext")) {
601 slotRefreshClipThumbnail(item);
603 } else if (properties.contains("full_luma") || properties.contains("force_colorspace")) {
609 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
613 clip->setProperties(properties);
614 if (properties.contains("name")) {
615 m_listView->blockSignals(true);
616 clip->setText(0, properties.value("name"));
617 m_listView->blockSignals(false);
618 emit clipNameChanged(clip->clipId(), properties.value("name"));
620 if (properties.contains("description")) {
621 CLIPTYPE type = clip->clipType();
622 m_listView->blockSignals(true);
623 clip->setText(1, properties.value("description"));
624 m_listView->blockSignals(false);
626 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
627 // Use Nepomuk system to store clip description
628 Nepomuk::Resource f(clip->clipUrl().path());
629 f.setDescription(properties.value("description"));
632 emit projectModified();
636 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
638 if (item->type() == PROJECTSUBCLIPTYPE) {
639 // this is a sub-item
641 // user edited description
642 SubProjectItem *sub = static_cast <SubProjectItem*>(item);
643 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
644 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), sub->zone(), sub->description(), sub->text(1), true);
645 m_commandStack->push(command);
646 //slotUpdateCutClipProperties(sub->clipId(), sub->zone(), sub->text(1), sub->text(1));
650 if (item->type() == PROJECTFOLDERTYPE) {
652 FolderProjectItem *folder = static_cast <FolderProjectItem*>(item);
653 editFolder(item->text(0), folder->groupName(), folder->clipId());
654 folder->setGroupName(item->text(0));
655 m_doc->clipManager()->addFolder(folder->clipId(), item->text(0));
656 const int children = item->childCount();
657 for (int i = 0; i < children; i++) {
658 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
659 child->setProperty("groupname", item->text(0));
665 ProjectItem *clip = static_cast <ProjectItem*>(item);
667 if (clip->referencedClip()) {
668 QMap <QString, QString> oldprops;
669 QMap <QString, QString> newprops;
670 oldprops["description"] = clip->referencedClip()->getProperty("description");
671 newprops["description"] = item->text(1);
673 if (clip->clipType() == TEXT) {
674 // This is a text template clip, update the image
675 /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
676 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/
677 oldprops.insert("templatetext", clip->referencedClip()->getProperty("templatetext"));
678 newprops.insert("templatetext", item->text(1));
680 slotUpdateClipProperties(clip->clipId(), newprops);
681 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
682 m_commandStack->push(command);
684 } else if (column == 0) {
685 if (clip->referencedClip()) {
686 QMap <QString, QString> oldprops;
687 QMap <QString, QString> newprops;
688 oldprops["name"] = clip->referencedClip()->getProperty("name");
689 newprops["name"] = item->text(0);
690 slotUpdateClipProperties(clip, newprops);
691 emit projectModified();
692 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
693 m_commandStack->push(command);
698 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
700 bool enable = item ? true : false;
701 m_editButton->defaultAction()->setEnabled(enable);
702 m_deleteButton->defaultAction()->setEnabled(enable);
703 m_reloadAction->setEnabled(enable);
704 m_transcodeAction->setEnabled(enable);
706 ProjectItem *clip = NULL;
707 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
708 clip = static_cast <ProjectItem*>(item->parent());
709 m_transcodeAction->setEnabled(false);
710 } else if (m_listView->currentItem()->type() == PROJECTCLIPTYPE) {
711 clip = static_cast <ProjectItem*>(item);
712 // Display relevant transcoding actions only
713 adjustTranscodeActions(clip);
714 // Display uses in timeline
715 emit findInTimeline(clip->clipId());
717 m_transcodeAction->setEnabled(false);
719 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
720 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
721 m_openAction->setEnabled(true);
722 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
723 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
724 m_openAction->setEnabled(true);
726 m_openAction->setEnabled(false);
730 m_openAction->setEnabled(false);
735 void ProjectList::slotRemoveClip()
737 if (!m_listView->currentItem())
740 QMap <QString, QString> folderids;
741 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
743 QUndoCommand *delCommand = new QUndoCommand();
744 delCommand->setText(i18n("Delete Clip Zone"));
745 for (int i = 0; i < selected.count(); i++) {
746 if (selected.at(i)->type() == PROJECTSUBCLIPTYPE) {
748 SubProjectItem *sub = static_cast <SubProjectItem *>(selected.at(i));
749 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
750 new AddClipCutCommand(this, item->clipId(), sub->zone().x(), sub->zone().y(), sub->description(), false, true, delCommand);
751 } else if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
753 FolderProjectItem *folder = static_cast <FolderProjectItem *>(selected.at(i));
754 folderids[folder->groupName()] = folder->clipId();
755 int children = folder->childCount();
757 if (children > 0 && KMessageBox::questionYesNo(kapp->activeWindow(), 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)
759 for (int i = 0; i < children; ++i) {
760 ProjectItem *child = static_cast <ProjectItem *>(folder->child(i));
761 ids << child->clipId();
764 ProjectItem *item = static_cast <ProjectItem *>(selected.at(i));
765 ids << item->clipId();
766 if (item->numReferences() > 0 && KMessageBox::questionYesNo(kapp->activeWindow(), 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"), KStandardGuiItem::yes(), KStandardGuiItem::no(), "DeleteAll") == KMessageBox::No) {
767 KMessageBox::enableMessage("DeleteAll");
772 KMessageBox::enableMessage("DeleteAll");
773 if (delCommand->childCount() == 0)
776 m_commandStack->push(delCommand);
777 emit deleteProjectClips(ids, folderids);
780 void ProjectList::updateButtons() const
782 if (m_listView->topLevelItemCount() == 0) {
783 m_deleteButton->defaultAction()->setEnabled(false);
785 m_deleteButton->defaultAction()->setEnabled(true);
786 if (!m_listView->currentItem())
787 m_listView->setCurrentItem(m_listView->topLevelItem(0));
788 QTreeWidgetItem *item = m_listView->currentItem();
789 if (item && item->type() == PROJECTCLIPTYPE) {
790 m_editButton->defaultAction()->setEnabled(true);
791 m_openAction->setEnabled(true);
792 m_reloadAction->setEnabled(true);
793 m_transcodeAction->setEnabled(true);
798 m_editButton->defaultAction()->setEnabled(false);
799 m_openAction->setEnabled(false);
800 m_reloadAction->setEnabled(false);
801 m_transcodeAction->setEnabled(false);
804 void ProjectList::selectItemById(const QString &clipId)
806 ProjectItem *item = getItemById(clipId);
808 m_listView->setCurrentItem(item);
812 void ProjectList::slotDeleteClip(const QString &clipId)
814 ProjectItem *item = getItemById(clipId);
816 kDebug() << "/// Cannot find clip to delete";
819 m_listView->blockSignals(true);
820 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
821 if (!newSelectedItem)
822 newSelectedItem = m_listView->itemBelow(item);
824 m_doc->clipManager()->deleteClip(clipId);
825 m_listView->blockSignals(false);
826 if (newSelectedItem) {
827 m_listView->setCurrentItem(newSelectedItem);
830 emit clipSelected(NULL);
835 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
837 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
838 m_commandStack->push(command);
839 m_doc->setModified(true);
842 void ProjectList::slotAddFolder()
844 AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
845 m_commandStack->push(command);
848 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
851 FolderProjectItem *item = getFolderItemById(clipId);
853 m_doc->clipManager()->deleteFolder(clipId);
854 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
855 if (!newSelectedItem)
856 newSelectedItem = m_listView->itemBelow(item);
859 m_listView->setCurrentItem(newSelectedItem);
865 FolderProjectItem *item = getFolderItemById(clipId);
867 m_listView->blockSignals(true);
868 item->setGroupName(foldername);
869 m_listView->blockSignals(false);
870 m_doc->clipManager()->addFolder(clipId, foldername);
871 const int children = item->childCount();
872 for (int i = 0; i < children; i++) {
873 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
874 child->setProperty("groupname", foldername);
878 m_listView->blockSignals(true);
879 m_listView->setCurrentItem(new FolderProjectItem(m_listView, QStringList() << foldername, clipId));
880 m_doc->clipManager()->addFolder(clipId, foldername);
881 m_listView->blockSignals(false);
882 m_listView->editItem(m_listView->currentItem(), 0);
886 m_doc->setModified(true);
891 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
893 QMapIterator<QString, QString> i(map);
894 QUndoCommand *delCommand = new QUndoCommand();
895 delCommand->setText(i18n("Delete Folder"));
896 while (i.hasNext()) {
898 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
900 m_commandStack->push(delCommand);
903 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
905 m_listView->setEnabled(false);
907 m_listView->blockSignals(true);
909 // remove file_hash so that we load all properties for the clip
910 QDomElement e = clip->toXML().cloneNode().toElement();
911 e.removeAttribute("file_hash");
912 m_infoQueue.insert(clip->getId(), e);
913 //m_render->getFileProperties(clip->toXML(), clip->getId(), true);
915 clip->askForAudioThumbs();
916 const QString parent = clip->getProperty("groupid");
917 ProjectItem *item = NULL;
918 if (!parent.isEmpty()) {
919 FolderProjectItem *parentitem = getFolderItemById(parent);
922 QString groupName = clip->getProperty("groupname");
923 //kDebug() << "Adding clip to new group: " << groupName;
924 if (groupName.isEmpty()) groupName = i18n("Folder");
926 parentitem = new FolderProjectItem(m_listView, text, parent);
930 item = new ProjectItem(parentitem, clip);
933 item = new ProjectItem(m_listView, clip);
934 KUrl url = clip->fileURL();
936 if (getProperties == false && !clip->getClipHash().isEmpty()) {
937 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
938 if (QFile::exists(cachedPixmap)) {
939 QPixmap pix(cachedPixmap);
941 KIO::NetAccess::del(KUrl(cachedPixmap), this);
942 item->setData(0, Qt::DecorationRole, pix);
946 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
947 // if file has Nepomuk comment, use it
948 Nepomuk::Resource f(url.path());
949 QString annotation = f.description();
950 if (!annotation.isEmpty()) item->setText(1, annotation);
951 item->setText(2, QString::number(f.rating()));
955 QList <CutZoneInfo> cuts = clip->cutZones();
956 if (!cuts.isEmpty()) {
957 for (int i = 0; i < cuts.count(); i++) {
958 SubProjectItem *sub = new SubProjectItem(item, cuts.at(i).zone.x(), cuts.at(i).zone.y(), cuts.at(i).description);
959 if (!clip->getClipHash().isEmpty()) {
960 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(cuts.at(i).zone.x()) + ".png";
961 if (QFile::exists(cachedPixmap)) {
962 QPixmap pix(cachedPixmap);
964 KIO::NetAccess::del(KUrl(cachedPixmap), this);
965 sub->setData(0, Qt::DecorationRole, pix);
970 if (m_listView->isEnabled()) {
973 m_listView->blockSignals(false);
975 if (getProperties && !m_queueTimer.isActive())
976 slotProcessNextClipInQueue();
979 void ProjectList::slotResetProjectList()
982 emit clipSelected(NULL);
983 m_thumbnailQueue.clear();
988 void ProjectList::requestClipInfo(const QDomElement xml, const QString id)
991 m_infoQueue.insert(id, xml);
992 //if (m_infoQueue.count() == 1 || ) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
995 void ProjectList::slotProcessNextClipInQueue()
997 if (m_infoQueue.isEmpty()) {
998 slotProcessNextThumbnail();
1002 QMap<QString, QDomElement>::const_iterator j = m_infoQueue.constBegin();
1003 if (j != m_infoQueue.constEnd()) {
1004 const QDomElement dom = j.value();
1005 const QString id = j.key();
1006 m_infoQueue.remove(j.key());
1007 emit getFileProperties(dom, id, m_listView->iconSize().height(), false);
1009 if (!m_infoQueue.isEmpty()) m_queueTimer.start();
1012 void ProjectList::slotUpdateClip(const QString &id)
1014 ProjectItem *item = getItemById(id);
1015 m_listView->blockSignals(true);
1016 if (item) item->setData(0, UsageRole, QString::number(item->numReferences()));
1017 m_listView->blockSignals(false);
1020 void ProjectList::updateAllClips()
1022 m_listView->setSortingEnabled(false);
1023 kDebug() << "// UPDATE ALL CLPY";
1025 QTreeWidgetItemIterator it(m_listView);
1028 m_listView->blockSignals(true);
1030 if ((*it)->type() == PROJECTSUBCLIPTYPE) {
1032 SubProjectItem *sub = static_cast <SubProjectItem *>(*it);
1033 if (sub->data(0, Qt::DecorationRole).isNull()) {
1034 item = static_cast <ProjectItem *>((*it)->parent());
1035 requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x()));
1039 } else if ((*it)->type() == PROJECTFOLDERTYPE) {
1044 item = static_cast <ProjectItem *>(*it);
1045 clip = item->referencedClip();
1046 if (item->referencedClip()->producer() == NULL) {
1047 if (clip->isPlaceHolder() == false)
1048 requestClipInfo(clip->toXML(), clip->getId());
1049 else if (!clip->isPlaceHolder())
1050 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
1052 if (item->data(0, Qt::DecorationRole).isNull())
1053 requestClipThumbnail(clip->getId());
1054 if (item->data(0, DurationRole).toString().isEmpty())
1055 item->changeDuration(item->referencedClip()->producer()->get_playtime());
1057 item->setData(0, UsageRole, QString::number(item->numReferences()));
1059 //qApp->processEvents();
1062 if (!m_queueTimer.isActive())
1063 m_queueTimer.start();
1064 if (m_listView->isEnabled())
1065 m_listView->blockSignals(false);
1066 m_listView->setSortingEnabled(true);
1067 if (m_infoQueue.isEmpty())
1068 slotProcessNextThumbnail();
1072 QString ProjectList::getExtensions()
1074 // Build list of mime types
1075 QStringList mimeTypes = QStringList() << "application/x-kdenlive" << "application/x-kdenlivetitle" << "video/mlt-playlist" << "text/plain"
1076 << "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"
1077 << "audio/x-flac" << "audio/x-matroska" << "audio/mp4" << "audio/mpeg" << "audio/x-mp3" << "audio/ogg" << "audio/x-wav" << "application/ogg" << "application/mxf" << "application/x-shockwave-flash"
1078 << "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";
1080 QString allExtensions;
1081 foreach(const QString & mimeType, mimeTypes) {
1082 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
1084 allExtensions.append(mime->patterns().join(" "));
1085 allExtensions.append(' ');
1088 return allExtensions.simplified();
1091 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
1093 if (!m_commandStack)
1094 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1097 if (givenList.isEmpty()) {
1098 QString allExtensions = getExtensions();
1099 const QString dialogFilter = allExtensions + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
1100 QCheckBox *b = new QCheckBox(i18n("Import image sequence"));
1101 b->setChecked(KdenliveSettings::autoimagesequence());
1102 KFileDialog *d = new KFileDialog(KUrl("kfiledialog:///clipfolder"), dialogFilter, kapp->activeWindow(), b);
1103 d->setOperationMode(KFileDialog::Opening);
1104 d->setMode(KFile::Files);
1106 list = d->selectedUrls();
1107 if (b->isChecked() && list.count() == 1) {
1108 // Check for image sequence
1109 KUrl url = list.at(0);
1110 QString fileName = url.fileName().section('.', 0, -2);
1111 if (fileName.at(fileName.size() - 1).isDigit()) {
1112 KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
1113 if (item.mimetype().startsWith("image")) {
1114 // import as sequence if we found more than one image in the sequence
1116 QString pattern = SlideshowClip::selectedPath(url.path(), false, QString(), &list);
1117 int count = list.count();
1120 QStringList groupInfo = getGroup();
1122 // get image sequence base name
1123 while (fileName.at(fileName.size() - 1).isDigit()) {
1127 m_doc->slotCreateSlideshowClipFile(fileName, pattern, count, m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()),
1128 false, false, false,
1129 m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))), QString(), 0,
1130 QString(), groupInfo.at(0), groupInfo.at(1));
1138 for (int i = 0; i < givenList.count(); i++)
1139 list << givenList.at(i);
1142 foreach(const KUrl & file, list) {
1143 // Check there is no folder here
1144 KMimeType::Ptr type = KMimeType::findByUrl(file);
1145 if (type->is("inode/directory")) {
1146 // user dropped a folder
1147 list.removeAll(file);
1154 if (givenList.isEmpty()) {
1155 QStringList groupInfo = getGroup();
1156 m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1));
1158 m_doc->slotAddClipList(list, groupName, groupId);
1162 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
1164 ProjectItem *item = getItemById(id);
1165 QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
1167 const QString path = item->referencedClip()->fileURL().path();
1168 if (item->referencedClip()->isPlaceHolder()) replace = false;
1169 if (!path.isEmpty()) {
1171 KMessageBox::sorry(kapp->activeWindow(), i18n("Clip <b>%1</b><br />is invalid, will be removed from project.", path));
1172 else if (KMessageBox::questionYesNo(kapp->activeWindow(), i18n("Clip <b>%1</b><br />is missing or invalid. Remove it from project?", path), i18n("Invalid clip")) == KMessageBox::Yes)
1176 emit deleteProjectClips(QStringList() << id, QMap <QString, QString>());
1180 void ProjectList::slotAddColorClip()
1182 if (!m_commandStack)
1183 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1185 QDialog *dia = new QDialog(this);
1186 Ui::ColorClip_UI dia_ui;
1187 dia_ui.setupUi(dia);
1188 dia->setWindowTitle(i18n("Color Clip"));
1189 dia_ui.clip_name->setText(i18n("Color Clip"));
1191 TimecodeDisplay *t = new TimecodeDisplay(m_timecode);
1192 t->setValue(KdenliveSettings::color_duration());
1193 t->setTimeCodeFormat(false);
1194 dia_ui.clip_durationBox->addWidget(t);
1195 dia_ui.clip_color->setColor(KdenliveSettings::colorclipcolor());
1197 if (dia->exec() == QDialog::Accepted) {
1198 QString color = dia_ui.clip_color->color().name();
1199 KdenliveSettings::setColorclipcolor(color);
1200 color = color.replace(0, 1, "0x") + "ff";
1201 QStringList groupInfo = getGroup();
1202 m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, m_timecode.getTimecode(t->gentime()), groupInfo.at(0), groupInfo.at(1));
1209 void ProjectList::slotAddSlideshowClip()
1211 if (!m_commandStack)
1212 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1214 SlideshowClip *dia = new SlideshowClip(m_timecode, this);
1216 if (dia->exec() == QDialog::Accepted) {
1217 QStringList groupInfo = getGroup();
1218 m_doc->slotCreateSlideshowClipFile(dia->clipName(), dia->selectedPath(), dia->imageCount(), dia->clipDuration(),
1219 dia->loop(), dia->crop(), dia->fade(),
1220 dia->lumaDuration(), dia->lumaFile(), dia->softness(),
1221 dia->animation(), groupInfo.at(0), groupInfo.at(1));
1226 void ProjectList::slotAddTitleClip()
1228 QStringList groupInfo = getGroup();
1229 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
1232 void ProjectList::slotAddTitleTemplateClip()
1234 if (!m_commandStack)
1235 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1237 QStringList groupInfo = getGroup();
1239 // Get the list of existing templates
1241 filter << "*.kdenlivetitle";
1242 const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
1243 QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
1245 QDialog *dia = new QDialog(this);
1246 Ui::TemplateClip_UI dia_ui;
1247 dia_ui.setupUi(dia);
1248 for (int i = 0; i < templateFiles.size(); ++i)
1249 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
1251 if (!templateFiles.isEmpty())
1252 dia_ui.buttonBox->button(QDialogButtonBox::Ok)->setFocus();
1253 dia_ui.template_list->fileDialog()->setFilter("application/x-kdenlivetitle");
1254 //warning: setting base directory doesn't work??
1255 KUrl startDir(path);
1256 dia_ui.template_list->fileDialog()->setUrl(startDir);
1257 dia_ui.text_box->setHidden(true);
1258 if (dia->exec() == QDialog::Accepted) {
1259 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
1260 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
1261 // Create a cloned template clip
1262 m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
1267 QStringList ProjectList::getGroup() const
1270 QTreeWidgetItem *item = m_listView->currentItem();
1271 while (item && item->type() != PROJECTFOLDERTYPE)
1272 item = item->parent();
1275 FolderProjectItem *folder = static_cast <FolderProjectItem *>(item);
1276 result << folder->groupName() << folder->clipId();
1278 result << QString() << QString();
1283 void ProjectList::setDocument(KdenliveDoc *doc)
1285 m_listView->blockSignals(true);
1286 m_listView->clear();
1287 m_listView->setSortingEnabled(false);
1288 emit clipSelected(NULL);
1289 m_thumbnailQueue.clear();
1290 m_infoQueue.clear();
1291 m_refreshed = false;
1293 m_timecode = doc->timecode();
1294 m_commandStack = doc->commandStack();
1297 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
1298 QMapIterator<QString, QString> f(flist);
1299 while (f.hasNext()) {
1301 (void) new FolderProjectItem(m_listView, QStringList() << f.value(), f.key());
1304 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
1305 for (int i = 0; i < list.count(); i++)
1306 slotAddClip(list.at(i), false);
1308 m_listView->blockSignals(false);
1309 connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
1310 connect(m_doc->clipManager(), SIGNAL(modifiedClip(const QString &)), this, SLOT(slotModifiedClip(const QString &)));
1311 connect(m_doc->clipManager(), SIGNAL(missingClip(const QString &)), this, SLOT(slotMissingClip(const QString &)));
1312 connect(m_doc->clipManager(), SIGNAL(availableClip(const QString &)), this, SLOT(slotAvailableClip(const QString &)));
1313 connect(m_doc->clipManager(), SIGNAL(checkAllClips()), this, SLOT(updateAllClips()));
1316 QList <DocClipBase*> ProjectList::documentClipList() const
1319 return QList <DocClipBase*> ();
1321 return m_doc->clipManager()->documentClipList();
1324 QDomElement ProjectList::producersList()
1327 QDomElement prods = doc.createElement("producerlist");
1328 doc.appendChild(prods);
1329 kDebug() << "//////////// PRO LIST BUILD PRDSLIST ";
1330 QTreeWidgetItemIterator it(m_listView);
1332 if ((*it)->type() != PROJECTCLIPTYPE) {
1337 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
1343 void ProjectList::slotCheckForEmptyQueue()
1345 if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
1347 emit loadingIsOver();
1348 emit displayMessage(QString(), -1);
1349 m_listView->blockSignals(false);
1350 m_listView->setEnabled(true);
1352 } else if (!m_refreshed) {
1353 QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
1357 void ProjectList::reloadClipThumbnails()
1359 kDebug() << "////////////// RELOAD CLIPS THUMBNAILS!!!";
1360 m_thumbnailQueue.clear();
1361 QTreeWidgetItemIterator it(m_listView);
1363 if ((*it)->type() != PROJECTCLIPTYPE) {
1368 m_thumbnailQueue << ((ProjectItem *)(*it))->clipId();
1371 QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
1374 void ProjectList::requestClipThumbnail(const QString id)
1376 if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id);
1379 void ProjectList::slotProcessNextThumbnail()
1381 if (m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
1382 slotCheckForEmptyQueue();
1385 if (!m_infoQueue.isEmpty()) {
1386 //QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
1389 if (m_thumbnailQueue.count() > 1) {
1390 int max = m_doc->clipManager()->clipsCount();
1391 emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - m_thumbnailQueue.count()) / max));
1393 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
1396 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
1398 QTreeWidgetItem *item = getAnyItemById(clipId);
1400 slotRefreshClipThumbnail(item, update);
1402 slotProcessNextThumbnail();
1405 void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
1407 if (it == NULL) return;
1408 ProjectItem *item = NULL;
1409 bool isSubItem = false;
1411 if (it->type() == PROJECTFOLDERTYPE) return;
1412 if (it->type() == PROJECTSUBCLIPTYPE) {
1413 item = static_cast <ProjectItem *>(it->parent());
1414 frame = static_cast <SubProjectItem *>(it)->zone().x();
1417 item = static_cast <ProjectItem *>(it);
1418 frame = item->referencedClip()->getClipThumbFrame();
1422 DocClipBase *clip = item->referencedClip();
1424 slotProcessNextThumbnail();
1428 int height = m_listView->iconSize().height();
1429 int width = (int)(height * m_render->dar());
1430 if (clip->clipType() == AUDIO)
1431 pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
1432 else if (clip->clipType() == IMAGE)
1433 pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->producer(), 0, width, height));
1435 pix = item->referencedClip()->thumbProducer()->extractImage(frame, width, height);
1437 if (!pix.isNull()) {
1438 m_listView->blockSignals(true);
1439 it->setData(0, Qt::DecorationRole, pix);
1440 if (m_listView->isEnabled())
1441 m_listView->blockSignals(false);
1443 m_doc->cachePixmap(item->getClipHash(), pix);
1445 m_doc->cachePixmap(item->getClipHash() + '#' + QString::number(frame), pix);
1448 emit projectModified();
1450 slotProcessNextThumbnail();
1454 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace)
1457 ProjectItem *item = getItemById(clipId);
1458 if (item && producer) {
1459 m_listView->blockSignals(true);
1460 item->setProperties(properties, metadata);
1461 if (item->referencedClip()->isPlaceHolder() && producer->is_valid()) {
1462 item->referencedClip()->setValid();
1463 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1466 item->referencedClip()->setProducer(producer, replace);
1467 item->referencedClip()->askForAudioThumbs();
1468 if (!replace && item->data(0, Qt::DecorationRole).isNull())
1469 requestClipThumbnail(clipId);
1470 if (!toReload.isEmpty())
1471 item->slotSetToolTip();
1473 if (m_listView->isEnabled() && replace) {
1474 // update clip in clip monitor
1475 emit clipSelected(NULL);
1476 emit clipSelected(item->referencedClip());
1477 //TODO: Make sure the line below has no side effect
1481 // Check if duration changed.
1482 emit receivedClipDuration(clipId);
1485 if (m_listView->isEnabled())
1486 m_listView->blockSignals(false);
1487 /*if (item->icon(0).isNull()) {
1488 requestClipThumbnail(clipId);
1490 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
1491 if (item && m_infoQueue.isEmpty() && m_thumbnailQueue.isEmpty()) {
1492 m_listView->setCurrentItem(item);
1493 bool updatedProfile = false;
1494 if (item->parent()) {
1495 if (item->parent()->type() == PROJECTFOLDERTYPE)
1496 static_cast <FolderProjectItem *>(item->parent())->switchIcon();
1497 } else if (KdenliveSettings::checkfirstprojectclip() && m_listView->topLevelItemCount() == 1) {
1498 // this is the first clip loaded in project, check if we want to adjust project settings to the clip
1499 updatedProfile = adjustProjectProfileToItem(item);
1501 if (updatedProfile == false) emit clipSelected(item->referencedClip());
1503 int max = m_doc->clipManager()->clipsCount();
1504 emit displayMessage(i18n("Loading clips"), (int)(100 *(max - m_infoQueue.count()) / max));
1506 if (!toReload.isEmpty())
1507 emit clipNeedsReload(toReload, true);
1509 qApp->processEvents();
1510 slotProcessNextClipInQueue();
1513 bool ProjectList::adjustProjectProfileToItem(ProjectItem *item)
1516 if (m_listView->currentItem() && m_listView->currentItem()->type() != PROJECTFOLDERTYPE)
1517 item = static_cast <ProjectItem*>(m_listView->currentItem());
1519 if (item == NULL || item->referencedClip() == NULL) {
1520 KMessageBox::information(kapp->activeWindow(), i18n("Cannot find profile from current clip"));
1523 bool profileUpdated = false;
1524 QString size = item->referencedClip()->getProperty("frame_size");
1525 int width = size.section('x', 0, 0).toInt();
1526 int height = size.section('x', -1).toInt();
1527 double fps = item->referencedClip()->getProperty("fps").toDouble();
1528 double par = item->referencedClip()->getProperty("aspect_ratio").toDouble();
1529 if (item->clipType() == IMAGE || item->clipType() == AV || item->clipType() == VIDEO) {
1530 if (ProfilesDialog::matchProfile(width, height, fps, par, item->clipType() == IMAGE, m_doc->mltProfile()) == false) {
1531 // get a list of compatible profiles
1532 QMap <QString, QString> suggestedProfiles = ProfilesDialog::getProfilesFromProperties(width, height, fps, par, item->clipType() == IMAGE);
1533 if (!suggestedProfiles.isEmpty()) {
1534 KDialog *dialog = new KDialog(this);
1535 dialog->setCaption(i18n("Change project profile"));
1536 dialog->setButtons(KDialog::Ok | KDialog::Cancel);
1539 QVBoxLayout *l = new QVBoxLayout;
1540 QLabel *label = new QLabel(i18n("Your clip does not match current project's profile.\nDo you want to change the project profile?\n\nThe following profiles match the clip (size: %1, fps: %2)", size, fps));
1541 l->addWidget(label);
1542 QListWidget *list = new QListWidget;
1543 list->setAlternatingRowColors(true);
1544 QMapIterator<QString, QString> i(suggestedProfiles);
1545 while (i.hasNext()) {
1547 QListWidgetItem *item = new QListWidgetItem(i.value(), list);
1548 item->setData(Qt::UserRole, i.key());
1549 item->setToolTip(i.key());
1551 list->setCurrentRow(0);
1553 container.setLayout(l);
1554 dialog->setButtonText(KDialog::Ok, i18n("Update profile"));
1555 dialog->setMainWidget(&container);
1556 if (dialog->exec() == QDialog::Accepted) {
1557 //Change project profile
1558 profileUpdated = true;
1559 if (list->currentItem())
1560 emit updateProfile(list->currentItem()->data(Qt::UserRole).toString());
1564 } else if (fps > 0) {
1565 KMessageBox::information(kapp->activeWindow(), 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", size, fps));
1569 return profileUpdated;
1572 void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
1574 ProjectItem *item = getItemById(clipId);
1575 if (item && !pix.isNull()) {
1576 m_listView->blockSignals(true);
1577 item->setData(0, Qt::DecorationRole, pix);
1578 m_doc->cachePixmap(item->getClipHash(), pix);
1579 if (m_listView->isEnabled())
1580 m_listView->blockSignals(false);
1584 QTreeWidgetItem *ProjectList::getAnyItemById(const QString &id)
1586 QTreeWidgetItemIterator it(m_listView);
1587 QString lookId = id;
1588 if (id.contains('#'))
1589 lookId = id.section('#', 0, 0);
1591 ProjectItem *result = NULL;
1593 if ((*it)->type() != PROJECTCLIPTYPE) {
1598 ProjectItem *item = static_cast<ProjectItem *>(*it);
1599 if (item->clipId() == lookId) {
1605 if (result == NULL || !id.contains('#')) {
1608 for (int i = 0; i < result->childCount(); i++) {
1609 SubProjectItem *sub = static_cast <SubProjectItem *>(result->child(i));
1610 if (sub && sub->zone().x() == id.section('#', 1, 1).toInt())
1619 ProjectItem *ProjectList::getItemById(const QString &id)
1622 QTreeWidgetItemIterator it(m_listView);
1624 if ((*it)->type() != PROJECTCLIPTYPE) {
1629 item = static_cast<ProjectItem *>(*it);
1630 if (item->clipId() == id)
1637 FolderProjectItem *ProjectList::getFolderItemById(const QString &id)
1639 FolderProjectItem *item;
1640 QTreeWidgetItemIterator it(m_listView);
1642 if ((*it)->type() == PROJECTFOLDERTYPE) {
1643 item = static_cast<FolderProjectItem *>(*it);
1644 if (item->clipId() == id)
1652 void ProjectList::slotSelectClip(const QString &ix)
1654 ProjectItem *clip = getItemById(ix);
1656 m_listView->setCurrentItem(clip);
1657 m_listView->scrollToItem(clip);
1658 m_editButton->defaultAction()->setEnabled(true);
1659 m_deleteButton->defaultAction()->setEnabled(true);
1660 m_reloadAction->setEnabled(true);
1661 m_transcodeAction->setEnabled(true);
1662 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
1663 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
1664 m_openAction->setEnabled(true);
1665 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
1666 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
1667 m_openAction->setEnabled(true);
1669 m_openAction->setEnabled(false);
1674 QString ProjectList::currentClipUrl() const
1677 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return QString();
1678 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
1680 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
1682 item = static_cast <ProjectItem*>(m_listView->currentItem());
1686 return item->clipUrl().path();
1689 KUrl::List ProjectList::getConditionalUrls(const QString &condition) const
1693 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
1694 for (int i = 0; i < list.count(); i++) {
1695 if (list.at(i)->type() == PROJECTFOLDERTYPE)
1697 if (list.at(i)->type() == PROJECTSUBCLIPTYPE) {
1699 item = static_cast <ProjectItem*>(list.at(i)->parent());
1701 item = static_cast <ProjectItem*>(list.at(i));
1703 if (item == NULL || item->type() == COLOR || item->type() == SLIDESHOW || item->type() == TEXT)
1705 DocClipBase *clip = item->referencedClip();
1706 if (!condition.isEmpty()) {
1707 if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section('=', 1, 1)))
1709 else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section('=', 1, 1)))
1712 result.append(item->clipUrl());
1717 void ProjectList::regenerateTemplate(const QString &id)
1719 ProjectItem *clip = getItemById(id);
1721 regenerateTemplate(clip);
1724 void ProjectList::regenerateTemplate(ProjectItem *clip)
1726 //TODO: remove this unused method, only force_reload is necessary
1727 clip->referencedClip()->producer()->set("force_reload", 1);
1730 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
1734 if (!file.open(QIODevice::ReadOnly)) {
1735 kWarning() << "ERROR, CANNOT READ: " << path;
1738 if (!doc.setContent(&file)) {
1739 kWarning() << "ERROR, CANNOT READ: " << path;
1744 QDomNodeList texts = doc.elementsByTagName("content");
1745 for (int i = 0; i < texts.count(); i++) {
1746 QString data = texts.item(i).firstChild().nodeValue();
1747 data.replace("%s", replaceString);
1748 texts.item(i).firstChild().setNodeValue(data);
1754 void ProjectList::slotAddClipCut(const QString &id, int in, int out)
1756 ProjectItem *clip = getItemById(id);
1757 if (clip == NULL || clip->referencedClip()->hasCutZone(QPoint(in, out)))
1759 AddClipCutCommand *command = new AddClipCutCommand(this, id, in, out, QString(), true, false);
1760 m_commandStack->push(command);
1763 void ProjectList::addClipCut(const QString &id, int in, int out, const QString desc, bool newItem)
1765 ProjectItem *clip = getItemById(id);
1767 DocClipBase *base = clip->referencedClip();
1768 base->addCutZone(in, out);
1769 m_listView->blockSignals(true);
1770 SubProjectItem *sub = new SubProjectItem(clip, in, out, desc);
1771 if (newItem && desc.isEmpty() && !m_listView->isColumnHidden(1)) {
1772 if (!clip->isExpanded())
1773 clip->setExpanded(true);
1774 m_listView->scrollToItem(sub);
1775 m_listView->editItem(sub, 1);
1777 QPixmap p = clip->referencedClip()->thumbProducer()->extractImage(in, (int)(sub->sizeHint(0).height() * m_render->dar()), sub->sizeHint(0).height() - 2);
1778 sub->setData(0, Qt::DecorationRole, p);
1779 m_doc->cachePixmap(clip->getClipHash() + '#' + QString::number(in), p);
1780 m_listView->blockSignals(false);
1782 emit projectModified();
1785 void ProjectList::removeClipCut(const QString &id, int in, int out)
1787 ProjectItem *clip = getItemById(id);
1789 DocClipBase *base = clip->referencedClip();
1790 base->removeCutZone(in, out);
1791 SubProjectItem *sub = getSubItem(clip, QPoint(in, out));
1793 m_listView->blockSignals(true);
1795 m_listView->blockSignals(false);
1798 emit projectModified();
1801 SubProjectItem *ProjectList::getSubItem(ProjectItem *clip, QPoint zone)
1803 SubProjectItem *sub = NULL;
1805 for (int i = 0; i < clip->childCount(); i++) {
1806 QTreeWidgetItem *it = clip->child(i);
1807 if (it->type() == PROJECTSUBCLIPTYPE) {
1808 sub = static_cast <SubProjectItem*>(it);
1809 if (sub->zone() == zone)
1819 void ProjectList::slotUpdateClipCut(QPoint p)
1821 if (!m_listView->currentItem() || m_listView->currentItem()->type() != PROJECTSUBCLIPTYPE)
1823 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
1824 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
1825 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), p, sub->text(1), sub->text(1), true);
1826 m_commandStack->push(command);
1829 void ProjectList::doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment)
1831 ProjectItem *clip = getItemById(id);
1832 SubProjectItem *sub = getSubItem(clip, oldzone);
1833 if (sub == NULL || clip == NULL)
1835 DocClipBase *base = clip->referencedClip();
1836 base->updateCutZone(oldzone.x(), oldzone.y(), zone.x(), zone.y(), comment);
1837 m_listView->blockSignals(true);
1839 sub->setDescription(comment);
1840 m_listView->blockSignals(false);
1841 emit projectModified();
1844 void ProjectList::slotForceProcessing(const QString &id)
1846 while (m_infoQueue.contains(id)) {
1847 slotProcessNextClipInQueue();
1851 void ProjectList::slotAddOrUpdateSequence(const QString frameName)
1853 QString fileName = KUrl(frameName).fileName().section('_', 0, -2);
1855 QString pattern = SlideshowClip::selectedPath(frameName, false, QString(), &list);
1856 int count = list.count();
1858 const QList <DocClipBase *> existing = m_doc->clipManager()->getClipByResource(pattern);
1859 if (!existing.isEmpty()) {
1860 // Sequence already exists, update
1861 QString id = existing.at(0)->getId();
1862 //ProjectItem *item = getItemById(id);
1863 QMap <QString, QString> oldprops;
1864 QMap <QString, QString> newprops;
1865 int ttl = existing.at(0)->getProperty("ttl").toInt();
1866 oldprops["out"] = existing.at(0)->getProperty("out");
1867 newprops["out"] = QString::number(ttl * count - 1);
1868 slotUpdateClipProperties(id, newprops);
1869 EditClipCommand *command = new EditClipCommand(this, id, oldprops, newprops, false);
1870 m_commandStack->push(command);
1873 QStringList groupInfo = getGroup();
1874 m_doc->slotCreateSlideshowClipFile(fileName, pattern, count, m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()),
1875 false, false, false,
1876 m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))), QString(), 0,
1877 QString(), groupInfo.at(0), groupInfo.at(1));
1879 } else emit displayMessage(i18n("Sequence not found"), -2);
1882 #include "projectlist.moc"