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 CLIPTYPE t = item->clipType();
419 if (!item->referencedClip()->getProperty("xmltemplate").isEmpty())
420 regenerateTemplate(item);
421 } else if (t != COLOR && t != SLIDESHOW && item->referencedClip() && item->referencedClip()->checkHash() == false) {
422 item->referencedClip()->setPlaceHolder(true);
423 item->setProperty("file_hash", QString());
424 } else if (t == IMAGE) {
425 item->referencedClip()->producer()->set("force_reload", 1);
428 QDomElement e = item->toXml();
429 // Make sure we get the correct producer length if it was adjusted in timeline
430 if (t == COLOR || t == IMAGE || t == SLIDESHOW || t == TEXT) {
431 int length = QString(item->referencedClip()->producerProperty("length")).toInt();
432 if (length > 0 && !e.hasAttribute("length")) {
433 e.setAttribute("length", length);
434 e.setAttribute("out", length - 1);
438 emit getFileProperties(e, item->clipId(), m_listView->iconSize().height(), true);
443 void ProjectList::slotModifiedClip(const QString &id)
445 ProjectItem *item = getItemById(id);
447 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
448 if (!pixmap.isNull()) {
450 p.fillRect(0, 0, pixmap.width(), pixmap.height(), QColor(255, 255, 255, 200));
451 p.drawPixmap(0, 0, KIcon("view-refresh").pixmap(m_listView->iconSize()));
454 pixmap = KIcon("view-refresh").pixmap(m_listView->iconSize());
456 item->setData(0, Qt::DecorationRole, pixmap);
460 void ProjectList::slotMissingClip(const QString &id)
462 ProjectItem *item = getItemById(id);
464 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
465 if (item->referencedClip()) {
466 item->referencedClip()->setPlaceHolder(true);
467 if (m_render == NULL) kDebug() << "********* ERROR, NULL RENDR";
468 item->referencedClip()->setProducer(m_render->invalidProducer(id), true);
469 item->slotSetToolTip();
470 emit clipNeedsReload(id, true);
474 emit displayMessage(i18n("Check missing clips"), -2);
475 emit updateRenderStatus();
478 void ProjectList::slotAvailableClip(const QString &id)
480 ProjectItem *item = getItemById(id);
483 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
484 if (item->referencedClip()) { // && item->referencedClip()->checkHash() == false) {
485 item->setProperty("file_hash", QString());
489 item->referencedClip()->setValid();
490 item->slotSetToolTip();
493 emit updateRenderStatus();
496 bool ProjectList::hasMissingClips()
498 bool missing = false;
499 QTreeWidgetItemIterator it(m_listView);
501 if ((*it)->type() == PROJECTCLIPTYPE && !((*it)->flags() & Qt::ItemIsDragEnabled)) {
510 void ProjectList::setRenderer(Render *projectRender)
512 m_render = projectRender;
513 m_listView->setIconSize(QSize((ProjectItem::itemDefaultHeight() - 2) * m_render->dar(), ProjectItem::itemDefaultHeight() - 2));
516 void ProjectList::slotClipSelected()
518 if (!m_listView->isEnabled()) return;
519 if (m_listView->currentItem()) {
520 if (m_listView->currentItem()->type() == PROJECTFOLDERTYPE) {
521 emit clipSelected(NULL);
522 m_editButton->defaultAction()->setEnabled(false);
523 m_deleteButton->defaultAction()->setEnabled(true);
524 m_openAction->setEnabled(false);
525 m_reloadAction->setEnabled(false);
526 m_transcodeAction->setEnabled(false);
529 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
530 // this is a sub item, use base clip
531 m_deleteButton->defaultAction()->setEnabled(true);
532 clip = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
533 if (clip == NULL) kDebug() << "-----------ERROR";
534 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
535 emit clipSelected(clip->referencedClip(), sub->zone());
536 m_transcodeAction->setEnabled(false);
539 clip = static_cast <ProjectItem*>(m_listView->currentItem());
541 emit clipSelected(clip->referencedClip());
542 m_editButton->defaultAction()->setEnabled(true);
543 m_deleteButton->defaultAction()->setEnabled(true);
544 m_reloadAction->setEnabled(true);
545 m_transcodeAction->setEnabled(true);
546 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
547 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
548 m_openAction->setEnabled(true);
549 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
550 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
551 m_openAction->setEnabled(true);
553 m_openAction->setEnabled(false);
555 // Display relevant transcoding actions only
556 adjustTranscodeActions(clip);
557 // Display uses in timeline
558 emit findInTimeline(clip->clipId());
561 emit clipSelected(NULL);
562 m_editButton->defaultAction()->setEnabled(false);
563 m_deleteButton->defaultAction()->setEnabled(false);
564 m_openAction->setEnabled(false);
565 m_reloadAction->setEnabled(false);
566 m_transcodeAction->setEnabled(false);
570 void ProjectList::adjustTranscodeActions(ProjectItem *clip) const
572 if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW) {
573 m_transcodeAction->setEnabled(false);
576 m_transcodeAction->setEnabled(true);
577 QList<QAction *> transcodeActions = m_transcodeAction->actions();
580 for (int i = 0; i < transcodeActions.count(); i++) {
581 data = transcodeActions.at(i)->data().toStringList();
582 if (data.count() > 2) {
583 condition = data.at(2);
584 if (condition.startsWith("vcodec"))
585 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
586 else if (condition.startsWith("acodec"))
587 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
593 void ProjectList::slotPauseMonitor()
599 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
601 ProjectItem *item = getItemById(id);
603 slotUpdateClipProperties(item, properties);
604 if (properties.contains("out") || properties.contains("force_fps") || properties.contains("resource")) {
606 } else if (properties.contains("colour") ||
607 properties.contains("xmldata") ||
608 properties.contains("force_aspect_num") ||
609 properties.contains("force_aspect_den") ||
610 properties.contains("templatetext")) {
611 slotRefreshClipThumbnail(item);
613 } else if (properties.contains("full_luma") || properties.contains("force_colorspace")) {
619 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
623 clip->setProperties(properties);
624 if (properties.contains("name")) {
625 m_listView->blockSignals(true);
626 clip->setText(0, properties.value("name"));
627 m_listView->blockSignals(false);
628 emit clipNameChanged(clip->clipId(), properties.value("name"));
630 if (properties.contains("description")) {
631 CLIPTYPE type = clip->clipType();
632 m_listView->blockSignals(true);
633 clip->setText(1, properties.value("description"));
634 m_listView->blockSignals(false);
636 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
637 // Use Nepomuk system to store clip description
638 Nepomuk::Resource f(clip->clipUrl().path());
639 f.setDescription(properties.value("description"));
642 emit projectModified();
646 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
648 if (item->type() == PROJECTSUBCLIPTYPE) {
649 // this is a sub-item
651 // user edited description
652 SubProjectItem *sub = static_cast <SubProjectItem*>(item);
653 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
654 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), sub->zone(), sub->description(), sub->text(1), true);
655 m_commandStack->push(command);
656 //slotUpdateCutClipProperties(sub->clipId(), sub->zone(), sub->text(1), sub->text(1));
660 if (item->type() == PROJECTFOLDERTYPE) {
662 FolderProjectItem *folder = static_cast <FolderProjectItem*>(item);
663 editFolder(item->text(0), folder->groupName(), folder->clipId());
664 folder->setGroupName(item->text(0));
665 m_doc->clipManager()->addFolder(folder->clipId(), item->text(0));
666 const int children = item->childCount();
667 for (int i = 0; i < children; i++) {
668 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
669 child->setProperty("groupname", item->text(0));
675 ProjectItem *clip = static_cast <ProjectItem*>(item);
677 if (clip->referencedClip()) {
678 QMap <QString, QString> oldprops;
679 QMap <QString, QString> newprops;
680 oldprops["description"] = clip->referencedClip()->getProperty("description");
681 newprops["description"] = item->text(1);
683 if (clip->clipType() == TEXT) {
684 // This is a text template clip, update the image
685 /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
686 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/
687 oldprops.insert("templatetext", clip->referencedClip()->getProperty("templatetext"));
688 newprops.insert("templatetext", item->text(1));
690 slotUpdateClipProperties(clip->clipId(), newprops);
691 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
692 m_commandStack->push(command);
694 } else if (column == 0) {
695 if (clip->referencedClip()) {
696 QMap <QString, QString> oldprops;
697 QMap <QString, QString> newprops;
698 oldprops["name"] = clip->referencedClip()->getProperty("name");
699 newprops["name"] = item->text(0);
700 slotUpdateClipProperties(clip, newprops);
701 emit projectModified();
702 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
703 m_commandStack->push(command);
708 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
710 bool enable = item ? true : false;
711 m_editButton->defaultAction()->setEnabled(enable);
712 m_deleteButton->defaultAction()->setEnabled(enable);
713 m_reloadAction->setEnabled(enable);
714 m_transcodeAction->setEnabled(enable);
716 ProjectItem *clip = NULL;
717 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
718 clip = static_cast <ProjectItem*>(item->parent());
719 m_transcodeAction->setEnabled(false);
720 } else if (m_listView->currentItem()->type() == PROJECTCLIPTYPE) {
721 clip = static_cast <ProjectItem*>(item);
722 // Display relevant transcoding actions only
723 adjustTranscodeActions(clip);
724 // Display uses in timeline
725 emit findInTimeline(clip->clipId());
727 m_transcodeAction->setEnabled(false);
729 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
730 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
731 m_openAction->setEnabled(true);
732 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
733 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
734 m_openAction->setEnabled(true);
736 m_openAction->setEnabled(false);
740 m_openAction->setEnabled(false);
745 void ProjectList::slotRemoveClip()
747 if (!m_listView->currentItem())
750 QMap <QString, QString> folderids;
751 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
753 QUndoCommand *delCommand = new QUndoCommand();
754 delCommand->setText(i18n("Delete Clip Zone"));
755 for (int i = 0; i < selected.count(); i++) {
756 if (selected.at(i)->type() == PROJECTSUBCLIPTYPE) {
758 SubProjectItem *sub = static_cast <SubProjectItem *>(selected.at(i));
759 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
760 new AddClipCutCommand(this, item->clipId(), sub->zone().x(), sub->zone().y(), sub->description(), false, true, delCommand);
761 } else if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
763 FolderProjectItem *folder = static_cast <FolderProjectItem *>(selected.at(i));
764 folderids[folder->groupName()] = folder->clipId();
765 int children = folder->childCount();
767 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)
769 for (int i = 0; i < children; ++i) {
770 ProjectItem *child = static_cast <ProjectItem *>(folder->child(i));
771 ids << child->clipId();
774 ProjectItem *item = static_cast <ProjectItem *>(selected.at(i));
775 ids << item->clipId();
776 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) {
777 KMessageBox::enableMessage("DeleteAll");
782 KMessageBox::enableMessage("DeleteAll");
783 if (delCommand->childCount() == 0)
786 m_commandStack->push(delCommand);
787 emit deleteProjectClips(ids, folderids);
790 void ProjectList::updateButtons() const
792 if (m_listView->topLevelItemCount() == 0) {
793 m_deleteButton->defaultAction()->setEnabled(false);
795 m_deleteButton->defaultAction()->setEnabled(true);
796 if (!m_listView->currentItem())
797 m_listView->setCurrentItem(m_listView->topLevelItem(0));
798 QTreeWidgetItem *item = m_listView->currentItem();
799 if (item && item->type() == PROJECTCLIPTYPE) {
800 m_editButton->defaultAction()->setEnabled(true);
801 m_openAction->setEnabled(true);
802 m_reloadAction->setEnabled(true);
803 m_transcodeAction->setEnabled(true);
808 m_editButton->defaultAction()->setEnabled(false);
809 m_openAction->setEnabled(false);
810 m_reloadAction->setEnabled(false);
811 m_transcodeAction->setEnabled(false);
814 void ProjectList::selectItemById(const QString &clipId)
816 ProjectItem *item = getItemById(clipId);
818 m_listView->setCurrentItem(item);
822 void ProjectList::slotDeleteClip(const QString &clipId)
824 ProjectItem *item = getItemById(clipId);
826 kDebug() << "/// Cannot find clip to delete";
829 m_listView->blockSignals(true);
830 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
831 if (!newSelectedItem)
832 newSelectedItem = m_listView->itemBelow(item);
834 m_doc->clipManager()->deleteClip(clipId);
835 m_listView->blockSignals(false);
836 if (newSelectedItem) {
837 m_listView->setCurrentItem(newSelectedItem);
840 emit clipSelected(NULL);
845 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
847 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
848 m_commandStack->push(command);
849 m_doc->setModified(true);
852 void ProjectList::slotAddFolder()
854 AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
855 m_commandStack->push(command);
858 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
861 FolderProjectItem *item = getFolderItemById(clipId);
863 m_doc->clipManager()->deleteFolder(clipId);
864 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
865 if (!newSelectedItem)
866 newSelectedItem = m_listView->itemBelow(item);
869 m_listView->setCurrentItem(newSelectedItem);
875 FolderProjectItem *item = getFolderItemById(clipId);
877 m_listView->blockSignals(true);
878 item->setGroupName(foldername);
879 m_listView->blockSignals(false);
880 m_doc->clipManager()->addFolder(clipId, foldername);
881 const int children = item->childCount();
882 for (int i = 0; i < children; i++) {
883 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
884 child->setProperty("groupname", foldername);
888 m_listView->blockSignals(true);
889 m_listView->setCurrentItem(new FolderProjectItem(m_listView, QStringList() << foldername, clipId));
890 m_doc->clipManager()->addFolder(clipId, foldername);
891 m_listView->blockSignals(false);
892 m_listView->editItem(m_listView->currentItem(), 0);
896 m_doc->setModified(true);
901 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
903 QMapIterator<QString, QString> i(map);
904 QUndoCommand *delCommand = new QUndoCommand();
905 delCommand->setText(i18n("Delete Folder"));
906 while (i.hasNext()) {
908 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
910 m_commandStack->push(delCommand);
913 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
915 m_listView->setEnabled(false);
916 if (getProperties) m_listView->blockSignals(true);
917 const QString parent = clip->getProperty("groupid");
918 ProjectItem *item = NULL;
919 if (!parent.isEmpty()) {
920 FolderProjectItem *parentitem = getFolderItemById(parent);
923 QString groupName = clip->getProperty("groupname");
924 //kDebug() << "Adding clip to new group: " << groupName;
925 if (groupName.isEmpty()) groupName = i18n("Folder");
927 parentitem = new FolderProjectItem(m_listView, text, parent);
931 item = new ProjectItem(parentitem, clip);
934 item = new ProjectItem(m_listView, clip);
935 if (item->data(0, DurationRole).isNull()) item->setData(0, DurationRole, i18n("Loading"));
937 m_listView->blockSignals(true);
941 CLIPTYPE t = clip->clipType();
942 if ((t == VIDEO || t == AV || t == UNKNOWN) && KdenliveSettings::enableproxy()) {
943 if (clip->getProperty("proxy").isEmpty()) {
944 connect(clip, SIGNAL(proxyReady(const QString, bool)), this, SLOT(slotGotProxy(const QString, bool)));
945 item->setProxyStatus(1);
946 clip->generateProxy(m_doc->projectFolder());
949 // Proxy clip already created
950 item->setProxyStatus(2);
951 QDomElement e = clip->toXML().cloneNode().toElement();
952 e.removeAttribute("file_hash");
953 m_infoQueue.insert(clip->getId(), e);
958 // We don't use proxies
959 // remove file_hash so that we load all properties for the clip
960 QDomElement e = clip->toXML().cloneNode().toElement();
961 e.removeAttribute("file_hash");
962 m_infoQueue.insert(clip->getId(), e);
964 //m_render->getFileProperties(clip->toXML(), clip->getId(), true);
966 clip->askForAudioThumbs();
968 KUrl url = clip->fileURL();
969 if (getProperties == false && !clip->getClipHash().isEmpty()) {
970 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
971 if (QFile::exists(cachedPixmap)) {
972 QPixmap pix(cachedPixmap);
974 KIO::NetAccess::del(KUrl(cachedPixmap), this);
975 item->setData(0, Qt::DecorationRole, pix);
979 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
980 // if file has Nepomuk comment, use it
981 Nepomuk::Resource f(url.path());
982 QString annotation = f.description();
983 if (!annotation.isEmpty()) item->setText(1, annotation);
984 item->setText(2, QString::number(f.rating()));
988 QList <CutZoneInfo> cuts = clip->cutZones();
989 if (!cuts.isEmpty()) {
990 for (int i = 0; i < cuts.count(); i++) {
991 SubProjectItem *sub = new SubProjectItem(item, cuts.at(i).zone.x(), cuts.at(i).zone.y(), cuts.at(i).description);
992 if (!clip->getClipHash().isEmpty()) {
993 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(cuts.at(i).zone.x()) + ".png";
994 if (QFile::exists(cachedPixmap)) {
995 QPixmap pix(cachedPixmap);
997 KIO::NetAccess::del(KUrl(cachedPixmap), this);
998 sub->setData(0, Qt::DecorationRole, pix);
1003 if (m_listView->isEnabled()) {
1006 m_listView->blockSignals(false);
1009 if (getProperties && !m_queueTimer.isActive())
1010 slotProcessNextClipInQueue();
1013 void ProjectList::slotGotProxy(const QString id, bool success)
1015 ProjectItem *item = getItemById(id);
1017 disconnect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
1019 // Proxy clip successfully created
1020 item->setProxyStatus(2);
1021 QDomElement e = item->referencedClip()->toXML().cloneNode().toElement();
1022 e.removeAttribute("file_hash");
1023 m_infoQueue.insert(id, e);
1024 if (!m_queueTimer.isActive()) slotProcessNextClipInQueue();
1026 else item->setProxyStatus(0);
1027 connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
1032 void ProjectList::slotResetProjectList()
1034 m_listView->clear();
1035 emit clipSelected(NULL);
1036 m_thumbnailQueue.clear();
1037 m_infoQueue.clear();
1038 m_refreshed = false;
1041 void ProjectList::requestClipInfo(const QDomElement xml, const QString id)
1043 m_refreshed = false;
1044 m_infoQueue.insert(id, xml);
1045 //if (m_infoQueue.count() == 1 || ) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
1048 void ProjectList::slotProcessNextClipInQueue()
1050 if (m_infoQueue.isEmpty()) {
1051 slotProcessNextThumbnail();
1055 QMap<QString, QDomElement>::const_iterator j = m_infoQueue.constBegin();
1056 if (j != m_infoQueue.constEnd()) {
1057 const QDomElement dom = j.value();
1058 const QString id = j.key();
1059 m_infoQueue.remove(j.key());
1060 emit getFileProperties(dom, id, m_listView->iconSize().height(), false);
1062 if (!m_infoQueue.isEmpty()) m_queueTimer.start();
1065 void ProjectList::slotUpdateClip(const QString &id)
1067 ProjectItem *item = getItemById(id);
1068 m_listView->blockSignals(true);
1069 if (item) item->setData(0, UsageRole, QString::number(item->numReferences()));
1070 m_listView->blockSignals(false);
1073 void ProjectList::updateAllClips()
1075 m_listView->setSortingEnabled(false);
1076 kDebug() << "// UPDATE ALL CLPY";
1078 QTreeWidgetItemIterator it(m_listView);
1081 m_listView->blockSignals(true);
1083 if ((*it)->type() == PROJECTSUBCLIPTYPE) {
1085 SubProjectItem *sub = static_cast <SubProjectItem *>(*it);
1086 if (sub->data(0, Qt::DecorationRole).isNull()) {
1087 item = static_cast <ProjectItem *>((*it)->parent());
1088 requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x()));
1092 } else if ((*it)->type() == PROJECTFOLDERTYPE) {
1097 item = static_cast <ProjectItem *>(*it);
1098 clip = item->referencedClip();
1099 if (item->referencedClip()->producer() == NULL) {
1100 if (clip->isPlaceHolder() == false)
1101 requestClipInfo(clip->toXML(), clip->getId());
1102 else if (!clip->isPlaceHolder())
1103 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
1105 if (item->data(0, Qt::DecorationRole).isNull())
1106 requestClipThumbnail(clip->getId());
1107 if (item->data(0, DurationRole).toString().isEmpty())
1108 item->changeDuration(item->referencedClip()->producer()->get_playtime());
1110 item->setData(0, UsageRole, QString::number(item->numReferences()));
1112 //qApp->processEvents();
1115 if (!m_queueTimer.isActive())
1116 m_queueTimer.start();
1117 if (m_listView->isEnabled())
1118 m_listView->blockSignals(false);
1119 m_listView->setSortingEnabled(true);
1120 if (m_infoQueue.isEmpty())
1121 slotProcessNextThumbnail();
1125 QString ProjectList::getExtensions()
1127 // Build list of mime types
1128 QStringList mimeTypes = QStringList() << "application/x-kdenlive" << "application/x-kdenlivetitle" << "video/mlt-playlist" << "text/plain"
1129 << "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" << "video/webm"
1130 << "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"
1131 << "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";
1133 QString allExtensions;
1134 foreach(const QString & mimeType, mimeTypes) {
1135 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
1137 allExtensions.append(mime->patterns().join(" "));
1138 allExtensions.append(' ');
1141 return allExtensions.simplified();
1144 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
1146 if (!m_commandStack)
1147 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1150 if (givenList.isEmpty()) {
1151 QString allExtensions = getExtensions();
1152 const QString dialogFilter = allExtensions + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
1153 QCheckBox *b = new QCheckBox(i18n("Import image sequence"));
1154 b->setChecked(KdenliveSettings::autoimagesequence());
1155 KFileDialog *d = new KFileDialog(KUrl("kfiledialog:///clipfolder"), dialogFilter, kapp->activeWindow(), b);
1156 d->setOperationMode(KFileDialog::Opening);
1157 d->setMode(KFile::Files);
1159 list = d->selectedUrls();
1160 if (b->isChecked() && list.count() == 1) {
1161 // Check for image sequence
1162 KUrl url = list.at(0);
1163 QString fileName = url.fileName().section('.', 0, -2);
1164 if (fileName.at(fileName.size() - 1).isDigit()) {
1165 KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
1166 if (item.mimetype().startsWith("image")) {
1167 // import as sequence if we found more than one image in the sequence
1169 QString pattern = SlideshowClip::selectedPath(url.path(), false, QString(), &list);
1170 int count = list.count();
1173 QStringList groupInfo = getGroup();
1175 // get image sequence base name
1176 while (fileName.at(fileName.size() - 1).isDigit()) {
1180 m_doc->slotCreateSlideshowClipFile(fileName, pattern, count, m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()),
1181 false, false, false,
1182 m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))), QString(), 0,
1183 QString(), groupInfo.at(0), groupInfo.at(1));
1191 for (int i = 0; i < givenList.count(); i++)
1192 list << givenList.at(i);
1195 foreach(const KUrl & file, list) {
1196 // Check there is no folder here
1197 KMimeType::Ptr type = KMimeType::findByUrl(file);
1198 if (type->is("inode/directory")) {
1199 // user dropped a folder
1200 list.removeAll(file);
1207 if (givenList.isEmpty()) {
1208 QStringList groupInfo = getGroup();
1209 m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1));
1211 m_doc->slotAddClipList(list, groupName, groupId);
1215 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
1217 ProjectItem *item = getItemById(id);
1218 QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
1220 const QString path = item->referencedClip()->fileURL().path();
1221 if (item->referencedClip()->isPlaceHolder()) replace = false;
1222 if (!path.isEmpty()) {
1224 KMessageBox::sorry(kapp->activeWindow(), i18n("Clip <b>%1</b><br />is invalid, will be removed from project.", path));
1225 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)
1229 emit deleteProjectClips(QStringList() << id, QMap <QString, QString>());
1233 void ProjectList::slotAddColorClip()
1235 if (!m_commandStack)
1236 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1238 QDialog *dia = new QDialog(this);
1239 Ui::ColorClip_UI dia_ui;
1240 dia_ui.setupUi(dia);
1241 dia->setWindowTitle(i18n("Color Clip"));
1242 dia_ui.clip_name->setText(i18n("Color Clip"));
1244 TimecodeDisplay *t = new TimecodeDisplay(m_timecode);
1245 t->setValue(KdenliveSettings::color_duration());
1246 t->setTimeCodeFormat(false);
1247 dia_ui.clip_durationBox->addWidget(t);
1248 dia_ui.clip_color->setColor(KdenliveSettings::colorclipcolor());
1250 if (dia->exec() == QDialog::Accepted) {
1251 QString color = dia_ui.clip_color->color().name();
1252 KdenliveSettings::setColorclipcolor(color);
1253 color = color.replace(0, 1, "0x") + "ff";
1254 QStringList groupInfo = getGroup();
1255 m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, m_timecode.getTimecode(t->gentime()), groupInfo.at(0), groupInfo.at(1));
1262 void ProjectList::slotAddSlideshowClip()
1264 if (!m_commandStack)
1265 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1267 SlideshowClip *dia = new SlideshowClip(m_timecode, this);
1269 if (dia->exec() == QDialog::Accepted) {
1270 QStringList groupInfo = getGroup();
1271 m_doc->slotCreateSlideshowClipFile(dia->clipName(), dia->selectedPath(), dia->imageCount(), dia->clipDuration(),
1272 dia->loop(), dia->crop(), dia->fade(),
1273 dia->lumaDuration(), dia->lumaFile(), dia->softness(),
1274 dia->animation(), groupInfo.at(0), groupInfo.at(1));
1279 void ProjectList::slotAddTitleClip()
1281 QStringList groupInfo = getGroup();
1282 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
1285 void ProjectList::slotAddTitleTemplateClip()
1287 if (!m_commandStack)
1288 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1290 QStringList groupInfo = getGroup();
1292 // Get the list of existing templates
1294 filter << "*.kdenlivetitle";
1295 const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
1296 QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
1298 QDialog *dia = new QDialog(this);
1299 Ui::TemplateClip_UI dia_ui;
1300 dia_ui.setupUi(dia);
1301 for (int i = 0; i < templateFiles.size(); ++i)
1302 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
1304 if (!templateFiles.isEmpty())
1305 dia_ui.buttonBox->button(QDialogButtonBox::Ok)->setFocus();
1306 dia_ui.template_list->fileDialog()->setFilter("application/x-kdenlivetitle");
1307 //warning: setting base directory doesn't work??
1308 KUrl startDir(path);
1309 dia_ui.template_list->fileDialog()->setUrl(startDir);
1310 dia_ui.text_box->setHidden(true);
1311 if (dia->exec() == QDialog::Accepted) {
1312 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
1313 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
1314 // Create a cloned template clip
1315 m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
1320 QStringList ProjectList::getGroup() const
1323 QTreeWidgetItem *item = m_listView->currentItem();
1324 while (item && item->type() != PROJECTFOLDERTYPE)
1325 item = item->parent();
1328 FolderProjectItem *folder = static_cast <FolderProjectItem *>(item);
1329 result << folder->groupName() << folder->clipId();
1331 result << QString() << QString();
1336 void ProjectList::setDocument(KdenliveDoc *doc)
1338 m_listView->blockSignals(true);
1339 m_listView->clear();
1340 m_listView->setSortingEnabled(false);
1341 emit clipSelected(NULL);
1342 m_thumbnailQueue.clear();
1343 m_infoQueue.clear();
1344 m_refreshed = false;
1346 m_timecode = doc->timecode();
1347 m_commandStack = doc->commandStack();
1350 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
1351 QMapIterator<QString, QString> f(flist);
1352 while (f.hasNext()) {
1354 (void) new FolderProjectItem(m_listView, QStringList() << f.value(), f.key());
1357 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
1358 for (int i = 0; i < list.count(); i++)
1359 slotAddClip(list.at(i), false);
1361 m_listView->blockSignals(false);
1362 connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
1363 connect(m_doc->clipManager(), SIGNAL(modifiedClip(const QString &)), this, SLOT(slotModifiedClip(const QString &)));
1364 connect(m_doc->clipManager(), SIGNAL(missingClip(const QString &)), this, SLOT(slotMissingClip(const QString &)));
1365 connect(m_doc->clipManager(), SIGNAL(availableClip(const QString &)), this, SLOT(slotAvailableClip(const QString &)));
1366 connect(m_doc->clipManager(), SIGNAL(checkAllClips()), this, SLOT(updateAllClips()));
1369 QList <DocClipBase*> ProjectList::documentClipList() const
1372 return QList <DocClipBase*> ();
1374 return m_doc->clipManager()->documentClipList();
1377 QDomElement ProjectList::producersList()
1380 QDomElement prods = doc.createElement("producerlist");
1381 doc.appendChild(prods);
1382 kDebug() << "//////////// PRO LIST BUILD PRDSLIST ";
1383 QTreeWidgetItemIterator it(m_listView);
1385 if ((*it)->type() != PROJECTCLIPTYPE) {
1390 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
1396 void ProjectList::slotCheckForEmptyQueue()
1398 if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
1400 emit loadingIsOver();
1401 emit displayMessage(QString(), -1);
1402 m_listView->blockSignals(false);
1403 m_listView->setEnabled(true);
1405 } else if (!m_refreshed) {
1406 QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
1410 void ProjectList::reloadClipThumbnails()
1412 m_thumbnailQueue.clear();
1413 QTreeWidgetItemIterator it(m_listView);
1415 if ((*it)->type() != PROJECTCLIPTYPE) {
1420 m_thumbnailQueue << ((ProjectItem *)(*it))->clipId();
1423 QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
1426 void ProjectList::requestClipThumbnail(const QString id)
1428 if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id);
1431 void ProjectList::slotProcessNextThumbnail()
1433 if (m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
1434 slotCheckForEmptyQueue();
1437 if (!m_infoQueue.isEmpty()) {
1438 //QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
1441 if (m_thumbnailQueue.count() > 1) {
1442 int max = m_doc->clipManager()->clipsCount();
1443 emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - m_thumbnailQueue.count()) / max));
1445 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
1448 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
1450 QTreeWidgetItem *item = getAnyItemById(clipId);
1452 slotRefreshClipThumbnail(item, update);
1454 slotProcessNextThumbnail();
1457 void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
1459 if (it == NULL) return;
1460 ProjectItem *item = NULL;
1461 bool isSubItem = false;
1463 if (it->type() == PROJECTFOLDERTYPE) return;
1464 if (it->type() == PROJECTSUBCLIPTYPE) {
1465 item = static_cast <ProjectItem *>(it->parent());
1466 frame = static_cast <SubProjectItem *>(it)->zone().x();
1469 item = static_cast <ProjectItem *>(it);
1470 frame = item->referencedClip()->getClipThumbFrame();
1474 DocClipBase *clip = item->referencedClip();
1476 slotProcessNextThumbnail();
1480 int height = m_listView->iconSize().height();
1481 int width = (int)(height * m_render->dar());
1482 if (clip->clipType() == AUDIO)
1483 pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
1484 else if (clip->clipType() == IMAGE)
1485 pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->producer(), 0, width, height));
1487 pix = item->referencedClip()->thumbProducer()->extractImage(frame, width, height);
1489 if (!pix.isNull()) {
1490 m_listView->blockSignals(true);
1491 it->setData(0, Qt::DecorationRole, pix);
1492 if (m_listView->isEnabled())
1493 m_listView->blockSignals(false);
1495 m_doc->cachePixmap(item->getClipHash(), pix);
1497 m_doc->cachePixmap(item->getClipHash() + '#' + QString::number(frame), pix);
1500 emit projectModified();
1502 slotProcessNextThumbnail();
1506 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace)
1509 ProjectItem *item = getItemById(clipId);
1510 if (item && producer) {
1511 m_listView->blockSignals(true);
1512 item->setProperties(properties, metadata);
1513 if (item->referencedClip()->isPlaceHolder() && producer->is_valid()) {
1514 item->referencedClip()->setValid();
1515 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1518 item->referencedClip()->setProducer(producer, replace);
1519 item->referencedClip()->askForAudioThumbs();
1520 if (!replace && item->data(0, Qt::DecorationRole).isNull())
1521 requestClipThumbnail(clipId);
1522 if (!toReload.isEmpty())
1523 item->slotSetToolTip();
1525 if (m_listView->isEnabled() && replace) {
1526 // update clip in clip monitor
1527 emit clipSelected(NULL);
1528 emit clipSelected(item->referencedClip());
1529 //TODO: Make sure the line below has no side effect
1533 // Check if duration changed.
1534 emit receivedClipDuration(clipId);
1537 if (m_listView->isEnabled())
1538 m_listView->blockSignals(false);
1539 /*if (item->icon(0).isNull()) {
1540 requestClipThumbnail(clipId);
1542 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
1543 if (item && m_infoQueue.isEmpty() && m_thumbnailQueue.isEmpty()) {
1544 m_listView->setCurrentItem(item);
1545 bool updatedProfile = false;
1546 if (item->parent()) {
1547 if (item->parent()->type() == PROJECTFOLDERTYPE)
1548 static_cast <FolderProjectItem *>(item->parent())->switchIcon();
1549 } else if (KdenliveSettings::checkfirstprojectclip() && m_listView->topLevelItemCount() == 1) {
1550 // this is the first clip loaded in project, check if we want to adjust project settings to the clip
1551 updatedProfile = adjustProjectProfileToItem(item);
1553 if (updatedProfile == false) emit clipSelected(item->referencedClip());
1555 int max = m_doc->clipManager()->clipsCount();
1556 emit displayMessage(i18n("Loading clips"), (int)(100 *(max - m_infoQueue.count()) / max));
1558 if (!toReload.isEmpty())
1559 emit clipNeedsReload(toReload, true);
1561 qApp->processEvents();
1562 slotProcessNextClipInQueue();
1565 bool ProjectList::adjustProjectProfileToItem(ProjectItem *item)
1568 if (m_listView->currentItem() && m_listView->currentItem()->type() != PROJECTFOLDERTYPE)
1569 item = static_cast <ProjectItem*>(m_listView->currentItem());
1571 if (item == NULL || item->referencedClip() == NULL) {
1572 KMessageBox::information(kapp->activeWindow(), i18n("Cannot find profile from current clip"));
1575 bool profileUpdated = false;
1576 QString size = item->referencedClip()->getProperty("frame_size");
1577 int width = size.section('x', 0, 0).toInt();
1578 int height = size.section('x', -1).toInt();
1579 double fps = item->referencedClip()->getProperty("fps").toDouble();
1580 double par = item->referencedClip()->getProperty("aspect_ratio").toDouble();
1581 if (item->clipType() == IMAGE || item->clipType() == AV || item->clipType() == VIDEO) {
1582 if (ProfilesDialog::matchProfile(width, height, fps, par, item->clipType() == IMAGE, m_doc->mltProfile()) == false) {
1583 // get a list of compatible profiles
1584 QMap <QString, QString> suggestedProfiles = ProfilesDialog::getProfilesFromProperties(width, height, fps, par, item->clipType() == IMAGE);
1585 if (!suggestedProfiles.isEmpty()) {
1586 KDialog *dialog = new KDialog(this);
1587 dialog->setCaption(i18n("Change project profile"));
1588 dialog->setButtons(KDialog::Ok | KDialog::Cancel);
1591 QVBoxLayout *l = new QVBoxLayout;
1592 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));
1593 l->addWidget(label);
1594 QListWidget *list = new QListWidget;
1595 list->setAlternatingRowColors(true);
1596 QMapIterator<QString, QString> i(suggestedProfiles);
1597 while (i.hasNext()) {
1599 QListWidgetItem *item = new QListWidgetItem(i.value(), list);
1600 item->setData(Qt::UserRole, i.key());
1601 item->setToolTip(i.key());
1603 list->setCurrentRow(0);
1605 container.setLayout(l);
1606 dialog->setButtonText(KDialog::Ok, i18n("Update profile"));
1607 dialog->setMainWidget(&container);
1608 if (dialog->exec() == QDialog::Accepted) {
1609 //Change project profile
1610 profileUpdated = true;
1611 if (list->currentItem())
1612 emit updateProfile(list->currentItem()->data(Qt::UserRole).toString());
1616 } else if (fps > 0) {
1617 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));
1621 return profileUpdated;
1624 void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
1626 ProjectItem *item = getItemById(clipId);
1627 if (item && !pix.isNull()) {
1628 m_listView->blockSignals(true);
1629 item->setData(0, Qt::DecorationRole, pix);
1630 m_doc->cachePixmap(item->getClipHash(), pix);
1631 if (m_listView->isEnabled())
1632 m_listView->blockSignals(false);
1636 QTreeWidgetItem *ProjectList::getAnyItemById(const QString &id)
1638 QTreeWidgetItemIterator it(m_listView);
1639 QString lookId = id;
1640 if (id.contains('#'))
1641 lookId = id.section('#', 0, 0);
1643 ProjectItem *result = NULL;
1645 if ((*it)->type() != PROJECTCLIPTYPE) {
1650 ProjectItem *item = static_cast<ProjectItem *>(*it);
1651 if (item->clipId() == lookId) {
1657 if (result == NULL || !id.contains('#')) {
1660 for (int i = 0; i < result->childCount(); i++) {
1661 SubProjectItem *sub = static_cast <SubProjectItem *>(result->child(i));
1662 if (sub && sub->zone().x() == id.section('#', 1, 1).toInt())
1671 ProjectItem *ProjectList::getItemById(const QString &id)
1674 QTreeWidgetItemIterator it(m_listView);
1676 if ((*it)->type() != PROJECTCLIPTYPE) {
1681 item = static_cast<ProjectItem *>(*it);
1682 if (item->clipId() == id)
1689 FolderProjectItem *ProjectList::getFolderItemById(const QString &id)
1691 FolderProjectItem *item;
1692 QTreeWidgetItemIterator it(m_listView);
1694 if ((*it)->type() == PROJECTFOLDERTYPE) {
1695 item = static_cast<FolderProjectItem *>(*it);
1696 if (item->clipId() == id)
1704 void ProjectList::slotSelectClip(const QString &ix)
1706 ProjectItem *clip = getItemById(ix);
1708 m_listView->setCurrentItem(clip);
1709 m_listView->scrollToItem(clip);
1710 m_editButton->defaultAction()->setEnabled(true);
1711 m_deleteButton->defaultAction()->setEnabled(true);
1712 m_reloadAction->setEnabled(true);
1713 m_transcodeAction->setEnabled(true);
1714 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
1715 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
1716 m_openAction->setEnabled(true);
1717 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
1718 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
1719 m_openAction->setEnabled(true);
1721 m_openAction->setEnabled(false);
1726 QString ProjectList::currentClipUrl() const
1729 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return QString();
1730 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
1732 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
1734 item = static_cast <ProjectItem*>(m_listView->currentItem());
1738 return item->clipUrl().path();
1741 KUrl::List ProjectList::getConditionalUrls(const QString &condition) const
1745 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
1746 for (int i = 0; i < list.count(); i++) {
1747 if (list.at(i)->type() == PROJECTFOLDERTYPE)
1749 if (list.at(i)->type() == PROJECTSUBCLIPTYPE) {
1751 item = static_cast <ProjectItem*>(list.at(i)->parent());
1753 item = static_cast <ProjectItem*>(list.at(i));
1755 if (item == NULL || item->type() == COLOR || item->type() == SLIDESHOW || item->type() == TEXT)
1757 DocClipBase *clip = item->referencedClip();
1758 if (!condition.isEmpty()) {
1759 if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section('=', 1, 1)))
1761 else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section('=', 1, 1)))
1764 result.append(item->clipUrl());
1769 void ProjectList::regenerateTemplate(const QString &id)
1771 ProjectItem *clip = getItemById(id);
1773 regenerateTemplate(clip);
1776 void ProjectList::regenerateTemplate(ProjectItem *clip)
1778 //TODO: remove this unused method, only force_reload is necessary
1779 clip->referencedClip()->producer()->set("force_reload", 1);
1782 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
1786 if (!file.open(QIODevice::ReadOnly)) {
1787 kWarning() << "ERROR, CANNOT READ: " << path;
1790 if (!doc.setContent(&file)) {
1791 kWarning() << "ERROR, CANNOT READ: " << path;
1796 QDomNodeList texts = doc.elementsByTagName("content");
1797 for (int i = 0; i < texts.count(); i++) {
1798 QString data = texts.item(i).firstChild().nodeValue();
1799 data.replace("%s", replaceString);
1800 texts.item(i).firstChild().setNodeValue(data);
1806 void ProjectList::slotAddClipCut(const QString &id, int in, int out)
1808 ProjectItem *clip = getItemById(id);
1809 if (clip == NULL || clip->referencedClip()->hasCutZone(QPoint(in, out)))
1811 AddClipCutCommand *command = new AddClipCutCommand(this, id, in, out, QString(), true, false);
1812 m_commandStack->push(command);
1815 void ProjectList::addClipCut(const QString &id, int in, int out, const QString desc, bool newItem)
1817 ProjectItem *clip = getItemById(id);
1819 DocClipBase *base = clip->referencedClip();
1820 base->addCutZone(in, out);
1821 m_listView->blockSignals(true);
1822 SubProjectItem *sub = new SubProjectItem(clip, in, out, desc);
1823 if (newItem && desc.isEmpty() && !m_listView->isColumnHidden(1)) {
1824 if (!clip->isExpanded())
1825 clip->setExpanded(true);
1826 m_listView->scrollToItem(sub);
1827 m_listView->editItem(sub, 1);
1829 QPixmap p = clip->referencedClip()->thumbProducer()->extractImage(in, (int)(sub->sizeHint(0).height() * m_render->dar()), sub->sizeHint(0).height() - 2);
1830 sub->setData(0, Qt::DecorationRole, p);
1831 m_doc->cachePixmap(clip->getClipHash() + '#' + QString::number(in), p);
1832 m_listView->blockSignals(false);
1834 emit projectModified();
1837 void ProjectList::removeClipCut(const QString &id, int in, int out)
1839 ProjectItem *clip = getItemById(id);
1841 DocClipBase *base = clip->referencedClip();
1842 base->removeCutZone(in, out);
1843 SubProjectItem *sub = getSubItem(clip, QPoint(in, out));
1845 m_listView->blockSignals(true);
1847 m_listView->blockSignals(false);
1850 emit projectModified();
1853 SubProjectItem *ProjectList::getSubItem(ProjectItem *clip, QPoint zone)
1855 SubProjectItem *sub = NULL;
1857 for (int i = 0; i < clip->childCount(); i++) {
1858 QTreeWidgetItem *it = clip->child(i);
1859 if (it->type() == PROJECTSUBCLIPTYPE) {
1860 sub = static_cast <SubProjectItem*>(it);
1861 if (sub->zone() == zone)
1871 void ProjectList::slotUpdateClipCut(QPoint p)
1873 if (!m_listView->currentItem() || m_listView->currentItem()->type() != PROJECTSUBCLIPTYPE)
1875 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
1876 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
1877 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), p, sub->text(1), sub->text(1), true);
1878 m_commandStack->push(command);
1881 void ProjectList::doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment)
1883 ProjectItem *clip = getItemById(id);
1884 SubProjectItem *sub = getSubItem(clip, oldzone);
1885 if (sub == NULL || clip == NULL)
1887 DocClipBase *base = clip->referencedClip();
1888 base->updateCutZone(oldzone.x(), oldzone.y(), zone.x(), zone.y(), comment);
1889 m_listView->blockSignals(true);
1891 sub->setDescription(comment);
1892 m_listView->blockSignals(false);
1893 emit projectModified();
1896 void ProjectList::slotForceProcessing(const QString &id)
1898 while (m_infoQueue.contains(id)) {
1899 slotProcessNextClipInQueue();
1903 void ProjectList::slotAddOrUpdateSequence(const QString frameName)
1905 QString fileName = KUrl(frameName).fileName().section('_', 0, -2);
1907 QString pattern = SlideshowClip::selectedPath(frameName, false, QString(), &list);
1908 int count = list.count();
1910 const QList <DocClipBase *> existing = m_doc->clipManager()->getClipByResource(pattern);
1911 if (!existing.isEmpty()) {
1912 // Sequence already exists, update
1913 QString id = existing.at(0)->getId();
1914 //ProjectItem *item = getItemById(id);
1915 QMap <QString, QString> oldprops;
1916 QMap <QString, QString> newprops;
1917 int ttl = existing.at(0)->getProperty("ttl").toInt();
1918 oldprops["out"] = existing.at(0)->getProperty("out");
1919 newprops["out"] = QString::number(ttl * count - 1);
1920 slotUpdateClipProperties(id, newprops);
1921 EditClipCommand *command = new EditClipCommand(this, id, oldprops, newprops, false);
1922 m_commandStack->push(command);
1925 QStringList groupInfo = getGroup();
1926 m_doc->slotCreateSlideshowClipFile(fileName, pattern, count, m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()),
1927 false, false, false,
1928 m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))), QString(), 0,
1929 QString(), groupInfo.at(0), groupInfo.at(1));
1931 } else emit displayMessage(i18n("Sequence not found"), -2);
1934 QMap <QString, QString> ProjectList::getProxies()
1936 QMap <QString, QString> list;
1938 QTreeWidgetItemIterator it(m_listView);
1940 if ((*it)->type() != PROJECTCLIPTYPE) {
1945 item = static_cast<ProjectItem *>(*it);
1946 if (item && item->referencedClip() != NULL) {
1947 QString proxy = item->referencedClip()->getProperty("proxy");
1948 if (!proxy.isEmpty()) list.insert(proxy, item->clipUrl().path());
1955 #include "projectlist.moc"