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("threads", "-");
257 commonproperties.insert("video_index", "-");
258 commonproperties.insert("audio_index", "-");
259 commonproperties.insert("force_colorspace", "-");
260 commonproperties.insert("full_luma", "-");
262 bool allowDurationChange = true;
263 int commonDuration = -1;
265 for (int i = 0; i < list.count(); i++) {
267 if (list.at(i)->type() == PROJECTFOLDERTYPE)
269 if (list.at(i)->type() == PROJECTSUBCLIPTYPE)
270 item = static_cast <ProjectItem*>(list.at(i)->parent());
272 item = static_cast <ProjectItem*>(list.at(i));
273 if (!(item->flags() & Qt::ItemIsDragEnabled))
277 DocClipBase *clip = item->referencedClip();
278 if (clipList.contains(clip)) continue;
279 if (clip->clipType() != COLOR && clip->clipType() != IMAGE && clip->clipType() != TEXT)
280 allowDurationChange = false;
281 if (allowDurationChange && commonDuration != 0) {
282 if (commonDuration == -1)
283 commonDuration = clip->duration().frames(m_fps);
284 else if (commonDuration != clip->duration().frames(m_fps))
287 clipList.append(clip);
288 QMap <QString, QString> clipprops = clip->properties();
289 QMapIterator<QString, QString> p(commonproperties);
290 while (p.hasNext()) {
292 if (p.value().isEmpty()) continue;
293 if (clipprops.contains(p.key())) {
294 if (p.value() == "-")
295 commonproperties.insert(p.key(), clipprops.value(p.key()));
296 else if (p.value() != clipprops.value(p.key()))
297 commonproperties.insert(p.key(), QString());
299 commonproperties.insert(p.key(), QString());
304 if (allowDurationChange)
305 commonproperties.insert("out", QString::number(commonDuration));
306 QMapIterator<QString, QString> p(commonproperties);
307 while (p.hasNext()) {
309 kDebug() << "Result: " << p.key() << " = " << p.value();
311 emit showClipProperties(clipList, commonproperties);
314 void ProjectList::slotOpenClip()
317 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
319 if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1)
320 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
322 item = static_cast <ProjectItem*>(m_listView->currentItem());
324 if (item->clipType() == IMAGE) {
325 if (KdenliveSettings::defaultimageapp().isEmpty())
326 KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open images in the Settings dialog"));
328 QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
330 if (item->clipType() == AUDIO) {
331 if (KdenliveSettings::defaultaudioapp().isEmpty())
332 KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open audio files in the Settings dialog"));
334 QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
339 void ProjectList::cleanup()
341 m_listView->clearSelection();
342 QTreeWidgetItemIterator it(m_listView);
345 if ((*it)->type() != PROJECTCLIPTYPE) {
349 item = static_cast <ProjectItem *>(*it);
350 if (item->numReferences() == 0)
351 item->setSelected(true);
357 void ProjectList::trashUnusedClips()
359 QTreeWidgetItemIterator it(m_listView);
364 if ((*it)->type() != PROJECTCLIPTYPE) {
368 item = static_cast <ProjectItem *>(*it);
369 if (item->numReferences() == 0) {
370 ids << item->clipId();
371 KUrl url = item->clipUrl();
372 if (!url.isEmpty() && !urls.contains(url.path()))
378 // Check that we don't use the URL in another clip
379 QTreeWidgetItemIterator it2(m_listView);
381 if ((*it2)->type() != PROJECTCLIPTYPE) {
385 item = static_cast <ProjectItem *>(*it2);
386 if (item->numReferences() > 0) {
387 KUrl url = item->clipUrl();
388 if (!url.isEmpty() && urls.contains(url.path())) urls.removeAll(url.path());
393 emit deleteProjectClips(ids, QMap <QString, QString>());
394 for (int i = 0; i < urls.count(); i++)
395 KIO::NetAccess::del(KUrl(urls.at(i)), this);
398 void ProjectList::slotReloadClip(const QString &id)
400 QList<QTreeWidgetItem *> selected;
402 selected = m_listView->selectedItems();
404 selected.append(getItemById(id));
406 for (int i = 0; i < selected.count(); i++) {
407 if (selected.at(i)->type() != PROJECTCLIPTYPE) {
408 if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
409 for (int j = 0; j < selected.at(i)->childCount(); j++)
410 selected.append(selected.at(i)->child(j));
414 item = static_cast <ProjectItem *>(selected.at(i));
416 if (item->clipType() == TEXT) {
417 if (!item->referencedClip()->getProperty("xmltemplate").isEmpty())
418 regenerateTemplate(item);
419 } else if (item->clipType() != COLOR && item->clipType() != SLIDESHOW && item->referencedClip() && item->referencedClip()->checkHash() == false) {
420 item->referencedClip()->setPlaceHolder(true);
421 item->setProperty("file_hash", QString());
422 } else if (item->clipType() == IMAGE) {
423 item->referencedClip()->producer()->set("force_reload", 1);
425 //requestClipInfo(item->toXml(), item->clipId(), true);
426 // Clear the file_hash value, which will cause a complete reload of the clip
427 emit getFileProperties(item->toXml(), item->clipId(), m_listView->iconSize().height(), true);
432 void ProjectList::slotModifiedClip(const QString &id)
434 ProjectItem *item = getItemById(id);
436 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
437 if (!pixmap.isNull()) {
439 p.fillRect(0, 0, pixmap.width(), pixmap.height(), QColor(255, 255, 255, 200));
440 p.drawPixmap(0, 0, KIcon("view-refresh").pixmap(m_listView->iconSize()));
443 pixmap = KIcon("view-refresh").pixmap(m_listView->iconSize());
445 item->setData(0, Qt::DecorationRole, pixmap);
449 void ProjectList::slotMissingClip(const QString &id)
451 ProjectItem *item = getItemById(id);
453 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
454 if (item->referencedClip()) {
455 item->referencedClip()->setPlaceHolder(true);
456 if (m_render == NULL) kDebug() << "********* ERROR, NULL RENDR";
457 item->referencedClip()->setProducer(m_render->invalidProducer(id), true);
458 item->slotSetToolTip();
459 emit clipNeedsReload(id, true);
463 emit displayMessage(i18n("Check missing clips"), -2);
464 emit updateRenderStatus();
467 void ProjectList::slotAvailableClip(const QString &id)
469 ProjectItem *item = getItemById(id);
472 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
473 if (item->referencedClip()) { // && item->referencedClip()->checkHash() == false) {
474 item->setProperty("file_hash", QString());
478 item->referencedClip()->setValid();
479 item->slotSetToolTip();
482 emit updateRenderStatus();
485 bool ProjectList::hasMissingClips()
487 bool missing = false;
488 QTreeWidgetItemIterator it(m_listView);
490 if ((*it)->type() == PROJECTCLIPTYPE && !((*it)->flags() & Qt::ItemIsDragEnabled)) {
499 void ProjectList::setRenderer(Render *projectRender)
501 m_render = projectRender;
502 m_listView->setIconSize(QSize((ProjectItem::itemDefaultHeight() - 2) * m_render->dar(), ProjectItem::itemDefaultHeight() - 2));
505 void ProjectList::slotClipSelected()
507 if (!m_listView->isEnabled()) return;
508 if (m_listView->currentItem()) {
509 if (m_listView->currentItem()->type() == PROJECTFOLDERTYPE) {
510 emit clipSelected(NULL);
511 m_editButton->defaultAction()->setEnabled(false);
512 m_deleteButton->defaultAction()->setEnabled(true);
513 m_openAction->setEnabled(false);
514 m_reloadAction->setEnabled(false);
515 m_transcodeAction->setEnabled(false);
518 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
519 // this is a sub item, use base clip
520 m_deleteButton->defaultAction()->setEnabled(true);
521 clip = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
522 if (clip == NULL) kDebug() << "-----------ERROR";
523 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
524 emit clipSelected(clip->referencedClip(), sub->zone());
525 m_transcodeAction->setEnabled(false);
528 clip = static_cast <ProjectItem*>(m_listView->currentItem());
530 emit clipSelected(clip->referencedClip());
531 m_editButton->defaultAction()->setEnabled(true);
532 m_deleteButton->defaultAction()->setEnabled(true);
533 m_reloadAction->setEnabled(true);
534 m_transcodeAction->setEnabled(true);
535 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
536 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
537 m_openAction->setEnabled(true);
538 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
539 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
540 m_openAction->setEnabled(true);
542 m_openAction->setEnabled(false);
544 // Display relevant transcoding actions only
545 adjustTranscodeActions(clip);
546 // Display uses in timeline
547 emit findInTimeline(clip->clipId());
550 emit clipSelected(NULL);
551 m_editButton->defaultAction()->setEnabled(false);
552 m_deleteButton->defaultAction()->setEnabled(false);
553 m_openAction->setEnabled(false);
554 m_reloadAction->setEnabled(false);
555 m_transcodeAction->setEnabled(false);
559 void ProjectList::adjustTranscodeActions(ProjectItem *clip) const
561 if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW) {
562 m_transcodeAction->setEnabled(false);
565 m_transcodeAction->setEnabled(true);
566 QList<QAction *> transcodeActions = m_transcodeAction->actions();
569 for (int i = 0; i < transcodeActions.count(); i++) {
570 data = transcodeActions.at(i)->data().toStringList();
571 if (data.count() > 2) {
572 condition = data.at(2);
573 if (condition.startsWith("vcodec"))
574 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
575 else if (condition.startsWith("acodec"))
576 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
582 void ProjectList::slotPauseMonitor()
588 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
590 ProjectItem *item = getItemById(id);
592 slotUpdateClipProperties(item, properties);
593 if (properties.contains("out") || properties.contains("force_fps") || properties.contains("resource")) {
595 } else if (properties.contains("colour") ||
596 properties.contains("xmldata") ||
597 properties.contains("force_aspect_num") ||
598 properties.contains("force_aspect_den") ||
599 properties.contains("templatetext")) {
600 slotRefreshClipThumbnail(item);
602 } else if (properties.contains("full_luma") || properties.contains("force_colorspace")) {
608 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
612 clip->setProperties(properties);
613 if (properties.contains("name")) {
614 m_listView->blockSignals(true);
615 clip->setText(0, properties.value("name"));
616 m_listView->blockSignals(false);
617 emit clipNameChanged(clip->clipId(), properties.value("name"));
619 if (properties.contains("description")) {
620 CLIPTYPE type = clip->clipType();
621 m_listView->blockSignals(true);
622 clip->setText(1, properties.value("description"));
623 m_listView->blockSignals(false);
625 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
626 // Use Nepomuk system to store clip description
627 Nepomuk::Resource f(clip->clipUrl().path());
628 f.setDescription(properties.value("description"));
631 emit projectModified();
635 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
637 if (item->type() == PROJECTSUBCLIPTYPE) {
638 // this is a sub-item
640 // user edited description
641 SubProjectItem *sub = static_cast <SubProjectItem*>(item);
642 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
643 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), sub->zone(), sub->description(), sub->text(1), true);
644 m_commandStack->push(command);
645 //slotUpdateCutClipProperties(sub->clipId(), sub->zone(), sub->text(1), sub->text(1));
649 if (item->type() == PROJECTFOLDERTYPE) {
651 FolderProjectItem *folder = static_cast <FolderProjectItem*>(item);
652 editFolder(item->text(0), folder->groupName(), folder->clipId());
653 folder->setGroupName(item->text(0));
654 m_doc->clipManager()->addFolder(folder->clipId(), item->text(0));
655 const int children = item->childCount();
656 for (int i = 0; i < children; i++) {
657 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
658 child->setProperty("groupname", item->text(0));
664 ProjectItem *clip = static_cast <ProjectItem*>(item);
666 if (clip->referencedClip()) {
667 QMap <QString, QString> oldprops;
668 QMap <QString, QString> newprops;
669 oldprops["description"] = clip->referencedClip()->getProperty("description");
670 newprops["description"] = item->text(1);
672 if (clip->clipType() == TEXT) {
673 // This is a text template clip, update the image
674 /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
675 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/
676 oldprops.insert("templatetext", clip->referencedClip()->getProperty("templatetext"));
677 newprops.insert("templatetext", item->text(1));
679 slotUpdateClipProperties(clip->clipId(), newprops);
680 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
681 m_commandStack->push(command);
683 } else if (column == 0) {
684 if (clip->referencedClip()) {
685 QMap <QString, QString> oldprops;
686 QMap <QString, QString> newprops;
687 oldprops["name"] = clip->referencedClip()->getProperty("name");
688 newprops["name"] = item->text(0);
689 slotUpdateClipProperties(clip, newprops);
690 emit projectModified();
691 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
692 m_commandStack->push(command);
697 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
699 bool enable = item ? true : false;
700 m_editButton->defaultAction()->setEnabled(enable);
701 m_deleteButton->defaultAction()->setEnabled(enable);
702 m_reloadAction->setEnabled(enable);
703 m_transcodeAction->setEnabled(enable);
705 ProjectItem *clip = NULL;
706 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
707 clip = static_cast <ProjectItem*>(item->parent());
708 m_transcodeAction->setEnabled(false);
709 } else if (m_listView->currentItem()->type() == PROJECTCLIPTYPE) {
710 clip = static_cast <ProjectItem*>(item);
711 // Display relevant transcoding actions only
712 adjustTranscodeActions(clip);
713 // Display uses in timeline
714 emit findInTimeline(clip->clipId());
716 m_transcodeAction->setEnabled(false);
718 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
719 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
720 m_openAction->setEnabled(true);
721 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
722 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
723 m_openAction->setEnabled(true);
725 m_openAction->setEnabled(false);
729 m_openAction->setEnabled(false);
734 void ProjectList::slotRemoveClip()
736 if (!m_listView->currentItem())
739 QMap <QString, QString> folderids;
740 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
742 QUndoCommand *delCommand = new QUndoCommand();
743 delCommand->setText(i18n("Delete Clip Zone"));
744 for (int i = 0; i < selected.count(); i++) {
745 if (selected.at(i)->type() == PROJECTSUBCLIPTYPE) {
747 SubProjectItem *sub = static_cast <SubProjectItem *>(selected.at(i));
748 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
749 new AddClipCutCommand(this, item->clipId(), sub->zone().x(), sub->zone().y(), sub->description(), false, true, delCommand);
750 } else if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
752 FolderProjectItem *folder = static_cast <FolderProjectItem *>(selected.at(i));
753 folderids[folder->groupName()] = folder->clipId();
754 int children = folder->childCount();
756 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)
758 for (int i = 0; i < children; ++i) {
759 ProjectItem *child = static_cast <ProjectItem *>(folder->child(i));
760 ids << child->clipId();
763 ProjectItem *item = static_cast <ProjectItem *>(selected.at(i));
764 ids << item->clipId();
765 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) {
766 KMessageBox::enableMessage("DeleteAll");
771 KMessageBox::enableMessage("DeleteAll");
772 if (delCommand->childCount() == 0)
775 m_commandStack->push(delCommand);
776 emit deleteProjectClips(ids, folderids);
779 void ProjectList::updateButtons() const
781 if (m_listView->topLevelItemCount() == 0) {
782 m_deleteButton->defaultAction()->setEnabled(false);
784 m_deleteButton->defaultAction()->setEnabled(true);
785 if (!m_listView->currentItem())
786 m_listView->setCurrentItem(m_listView->topLevelItem(0));
787 QTreeWidgetItem *item = m_listView->currentItem();
788 if (item && item->type() == PROJECTCLIPTYPE) {
789 m_editButton->defaultAction()->setEnabled(true);
790 m_openAction->setEnabled(true);
791 m_reloadAction->setEnabled(true);
792 m_transcodeAction->setEnabled(true);
797 m_editButton->defaultAction()->setEnabled(false);
798 m_openAction->setEnabled(false);
799 m_reloadAction->setEnabled(false);
800 m_transcodeAction->setEnabled(false);
803 void ProjectList::selectItemById(const QString &clipId)
805 ProjectItem *item = getItemById(clipId);
807 m_listView->setCurrentItem(item);
811 void ProjectList::slotDeleteClip(const QString &clipId)
813 ProjectItem *item = getItemById(clipId);
815 kDebug() << "/// Cannot find clip to delete";
818 m_listView->blockSignals(true);
819 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
820 if (!newSelectedItem)
821 newSelectedItem = m_listView->itemBelow(item);
823 m_doc->clipManager()->deleteClip(clipId);
824 m_listView->blockSignals(false);
825 if (newSelectedItem) {
826 m_listView->setCurrentItem(newSelectedItem);
829 emit clipSelected(NULL);
834 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
836 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
837 m_commandStack->push(command);
838 m_doc->setModified(true);
841 void ProjectList::slotAddFolder()
843 AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
844 m_commandStack->push(command);
847 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
850 FolderProjectItem *item = getFolderItemById(clipId);
852 m_doc->clipManager()->deleteFolder(clipId);
853 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
854 if (!newSelectedItem)
855 newSelectedItem = m_listView->itemBelow(item);
858 m_listView->setCurrentItem(newSelectedItem);
864 FolderProjectItem *item = getFolderItemById(clipId);
866 m_listView->blockSignals(true);
867 item->setGroupName(foldername);
868 m_listView->blockSignals(false);
869 m_doc->clipManager()->addFolder(clipId, foldername);
870 const int children = item->childCount();
871 for (int i = 0; i < children; i++) {
872 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
873 child->setProperty("groupname", foldername);
877 m_listView->blockSignals(true);
878 m_listView->setCurrentItem(new FolderProjectItem(m_listView, QStringList() << foldername, clipId));
879 m_doc->clipManager()->addFolder(clipId, foldername);
880 m_listView->blockSignals(false);
881 m_listView->editItem(m_listView->currentItem(), 0);
885 m_doc->setModified(true);
890 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
892 QMapIterator<QString, QString> i(map);
893 QUndoCommand *delCommand = new QUndoCommand();
894 delCommand->setText(i18n("Delete Folder"));
895 while (i.hasNext()) {
897 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
899 m_commandStack->push(delCommand);
902 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
904 m_listView->setEnabled(false);
906 m_listView->blockSignals(true);
908 // remove file_hash so that we load all properties for the clip
909 QDomElement e = clip->toXML().cloneNode().toElement();
910 e.removeAttribute("file_hash");
911 m_infoQueue.insert(clip->getId(), e);
912 //m_render->getFileProperties(clip->toXML(), clip->getId(), true);
914 clip->askForAudioThumbs();
915 const QString parent = clip->getProperty("groupid");
916 ProjectItem *item = NULL;
917 if (!parent.isEmpty()) {
918 FolderProjectItem *parentitem = getFolderItemById(parent);
921 QString groupName = clip->getProperty("groupname");
922 //kDebug() << "Adding clip to new group: " << groupName;
923 if (groupName.isEmpty()) groupName = i18n("Folder");
925 parentitem = new FolderProjectItem(m_listView, text, parent);
929 item = new ProjectItem(parentitem, clip);
932 item = new ProjectItem(m_listView, clip);
933 KUrl url = clip->fileURL();
935 if (getProperties == false && !clip->getClipHash().isEmpty()) {
936 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
937 if (QFile::exists(cachedPixmap)) {
938 QPixmap pix(cachedPixmap);
940 KIO::NetAccess::del(KUrl(cachedPixmap), this);
941 item->setData(0, Qt::DecorationRole, pix);
945 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
946 // if file has Nepomuk comment, use it
947 Nepomuk::Resource f(url.path());
948 QString annotation = f.description();
949 if (!annotation.isEmpty()) item->setText(1, annotation);
950 item->setText(2, QString::number(f.rating()));
954 QList <CutZoneInfo> cuts = clip->cutZones();
955 if (!cuts.isEmpty()) {
956 for (int i = 0; i < cuts.count(); i++) {
957 SubProjectItem *sub = new SubProjectItem(item, cuts.at(i).zone.x(), cuts.at(i).zone.y(), cuts.at(i).description);
958 if (!clip->getClipHash().isEmpty()) {
959 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(cuts.at(i).zone.x()) + ".png";
960 if (QFile::exists(cachedPixmap)) {
961 QPixmap pix(cachedPixmap);
963 KIO::NetAccess::del(KUrl(cachedPixmap), this);
964 sub->setData(0, Qt::DecorationRole, pix);
969 if (m_listView->isEnabled()) {
972 m_listView->blockSignals(false);
974 if (getProperties && !m_queueTimer.isActive())
975 slotProcessNextClipInQueue();
978 void ProjectList::slotResetProjectList()
981 emit clipSelected(NULL);
982 m_thumbnailQueue.clear();
987 void ProjectList::requestClipInfo(const QDomElement xml, const QString id)
990 m_infoQueue.insert(id, xml);
991 //if (m_infoQueue.count() == 1 || ) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
994 void ProjectList::slotProcessNextClipInQueue()
996 if (m_infoQueue.isEmpty()) {
997 slotProcessNextThumbnail();
1001 QMap<QString, QDomElement>::const_iterator j = m_infoQueue.constBegin();
1002 if (j != m_infoQueue.constEnd()) {
1003 const QDomElement dom = j.value();
1004 const QString id = j.key();
1005 m_infoQueue.remove(j.key());
1006 emit getFileProperties(dom, id, m_listView->iconSize().height(), false);
1008 if (!m_infoQueue.isEmpty()) m_queueTimer.start();
1011 void ProjectList::slotUpdateClip(const QString &id)
1013 ProjectItem *item = getItemById(id);
1014 m_listView->blockSignals(true);
1015 if (item) item->setData(0, UsageRole, QString::number(item->numReferences()));
1016 m_listView->blockSignals(false);
1019 void ProjectList::updateAllClips()
1021 m_listView->setSortingEnabled(false);
1022 kDebug() << "// UPDATE ALL CLPY";
1024 QTreeWidgetItemIterator it(m_listView);
1027 m_listView->blockSignals(true);
1029 if ((*it)->type() == PROJECTSUBCLIPTYPE) {
1031 SubProjectItem *sub = static_cast <SubProjectItem *>(*it);
1032 if (sub->data(0, Qt::DecorationRole).isNull()) {
1033 item = static_cast <ProjectItem *>((*it)->parent());
1034 requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x()));
1038 } else if ((*it)->type() == PROJECTFOLDERTYPE) {
1043 item = static_cast <ProjectItem *>(*it);
1044 clip = item->referencedClip();
1045 if (item->referencedClip()->producer() == NULL) {
1046 if (clip->isPlaceHolder() == false)
1047 requestClipInfo(clip->toXML(), clip->getId());
1048 else if (!clip->isPlaceHolder())
1049 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
1051 if (item->data(0, Qt::DecorationRole).isNull())
1052 requestClipThumbnail(clip->getId());
1053 if (item->data(0, DurationRole).toString().isEmpty())
1054 item->changeDuration(item->referencedClip()->producer()->get_playtime());
1056 item->setData(0, UsageRole, QString::number(item->numReferences()));
1058 //qApp->processEvents();
1061 if (!m_queueTimer.isActive())
1062 m_queueTimer.start();
1063 if (m_listView->isEnabled())
1064 m_listView->blockSignals(false);
1065 m_listView->setSortingEnabled(true);
1066 if (m_infoQueue.isEmpty())
1067 slotProcessNextThumbnail();
1071 QString ProjectList::getExtensions()
1073 // Build list of mime types
1074 QStringList mimeTypes = QStringList() << "application/x-kdenlive" << "application/x-kdenlivetitle" << "video/mlt-playlist" << "text/plain"
1075 << "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"
1076 << "audio/x-flac" << "audio/x-matroska" << "audio/mp4" << "audio/mpeg" << "audio/x-mp3" << "audio/ogg" << "audio/x-wav" << "application/ogg" << "application/mxf"
1077 << "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";
1079 QString allExtensions;
1080 foreach(const QString & mimeType, mimeTypes) {
1081 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
1083 allExtensions.append(mime->patterns().join(" "));
1084 allExtensions.append(' ');
1087 return allExtensions.simplified();
1090 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
1092 if (!m_commandStack)
1093 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1096 if (givenList.isEmpty()) {
1097 QString allExtensions = getExtensions();
1098 const QString dialogFilter = allExtensions + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
1099 QCheckBox *b = new QCheckBox(i18n("Import image sequence"));
1100 b->setChecked(KdenliveSettings::autoimagesequence());
1101 KFileDialog *d = new KFileDialog(KUrl("kfiledialog:///clipfolder"), dialogFilter, kapp->activeWindow(), b);
1102 d->setOperationMode(KFileDialog::Opening);
1103 d->setMode(KFile::Files);
1105 list = d->selectedUrls();
1106 if (b->isChecked() && list.count() == 1) {
1107 // Check for image sequence
1108 KUrl url = list.at(0);
1109 QString fileName = url.fileName().section('.', 0, -2);
1110 if (fileName.at(fileName.size() - 1).isDigit()) {
1111 KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
1112 if (item.mimetype().startsWith("image")) {
1113 // import as sequence if we found more than one image in the sequence
1115 QString pattern = SlideshowClip::selectedPath(url.path(), false, QString(), &list);
1116 int count = list.count();
1119 QStringList groupInfo = getGroup();
1121 // get image sequence base name
1122 while (fileName.at(fileName.size() - 1).isDigit()) {
1126 m_doc->slotCreateSlideshowClipFile(fileName, pattern, count, m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()),
1127 false, false, false,
1128 m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))), QString(), 0,
1129 QString(), groupInfo.at(0), groupInfo.at(1));
1137 for (int i = 0; i < givenList.count(); i++)
1138 list << givenList.at(i);
1141 foreach(const KUrl & file, list) {
1142 // Check there is no folder here
1143 KMimeType::Ptr type = KMimeType::findByUrl(file);
1144 if (type->is("inode/directory")) {
1145 // user dropped a folder
1146 list.removeAll(file);
1153 if (givenList.isEmpty()) {
1154 QStringList groupInfo = getGroup();
1155 m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1));
1157 m_doc->slotAddClipList(list, groupName, groupId);
1161 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
1163 ProjectItem *item = getItemById(id);
1164 QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
1166 const QString path = item->referencedClip()->fileURL().path();
1167 if (item->referencedClip()->isPlaceHolder()) replace = false;
1168 if (!path.isEmpty()) {
1170 KMessageBox::sorry(kapp->activeWindow(), i18n("Clip <b>%1</b><br />is invalid, will be removed from project.", path));
1171 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)
1175 emit deleteProjectClips(QStringList() << id, QMap <QString, QString>());
1179 void ProjectList::slotAddColorClip()
1181 if (!m_commandStack)
1182 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1184 QDialog *dia = new QDialog(this);
1185 Ui::ColorClip_UI dia_ui;
1186 dia_ui.setupUi(dia);
1187 dia->setWindowTitle(i18n("Color Clip"));
1188 dia_ui.clip_name->setText(i18n("Color Clip"));
1190 TimecodeDisplay *t = new TimecodeDisplay(m_timecode);
1191 t->setValue(KdenliveSettings::color_duration());
1192 t->setTimeCodeFormat(false);
1193 dia_ui.clip_durationBox->addWidget(t);
1194 dia_ui.clip_color->setColor(KdenliveSettings::colorclipcolor());
1196 if (dia->exec() == QDialog::Accepted) {
1197 QString color = dia_ui.clip_color->color().name();
1198 KdenliveSettings::setColorclipcolor(color);
1199 color = color.replace(0, 1, "0x") + "ff";
1200 QStringList groupInfo = getGroup();
1201 m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, m_timecode.getTimecode(t->gentime()), groupInfo.at(0), groupInfo.at(1));
1208 void ProjectList::slotAddSlideshowClip()
1210 if (!m_commandStack)
1211 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1213 SlideshowClip *dia = new SlideshowClip(m_timecode, this);
1215 if (dia->exec() == QDialog::Accepted) {
1216 QStringList groupInfo = getGroup();
1217 m_doc->slotCreateSlideshowClipFile(dia->clipName(), dia->selectedPath(), dia->imageCount(), dia->clipDuration(),
1218 dia->loop(), dia->crop(), dia->fade(),
1219 dia->lumaDuration(), dia->lumaFile(), dia->softness(),
1220 dia->animation(), groupInfo.at(0), groupInfo.at(1));
1225 void ProjectList::slotAddTitleClip()
1227 QStringList groupInfo = getGroup();
1228 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
1231 void ProjectList::slotAddTitleTemplateClip()
1233 if (!m_commandStack)
1234 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1236 QStringList groupInfo = getGroup();
1238 // Get the list of existing templates
1240 filter << "*.kdenlivetitle";
1241 const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
1242 QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
1244 QDialog *dia = new QDialog(this);
1245 Ui::TemplateClip_UI dia_ui;
1246 dia_ui.setupUi(dia);
1247 for (int i = 0; i < templateFiles.size(); ++i)
1248 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
1250 if (!templateFiles.isEmpty())
1251 dia_ui.buttonBox->button(QDialogButtonBox::Ok)->setFocus();
1252 dia_ui.template_list->fileDialog()->setFilter("application/x-kdenlivetitle");
1253 //warning: setting base directory doesn't work??
1254 KUrl startDir(path);
1255 dia_ui.template_list->fileDialog()->setUrl(startDir);
1256 dia_ui.text_box->setHidden(true);
1257 if (dia->exec() == QDialog::Accepted) {
1258 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
1259 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
1260 // Create a cloned template clip
1261 m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
1266 QStringList ProjectList::getGroup() const
1269 QTreeWidgetItem *item = m_listView->currentItem();
1270 while (item && item->type() != PROJECTFOLDERTYPE)
1271 item = item->parent();
1274 FolderProjectItem *folder = static_cast <FolderProjectItem *>(item);
1275 result << folder->groupName() << folder->clipId();
1277 result << QString() << QString();
1282 void ProjectList::setDocument(KdenliveDoc *doc)
1284 m_listView->blockSignals(true);
1285 m_listView->clear();
1286 m_listView->setSortingEnabled(false);
1287 emit clipSelected(NULL);
1288 m_thumbnailQueue.clear();
1289 m_infoQueue.clear();
1290 m_refreshed = false;
1292 m_timecode = doc->timecode();
1293 m_commandStack = doc->commandStack();
1296 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
1297 QMapIterator<QString, QString> f(flist);
1298 while (f.hasNext()) {
1300 (void) new FolderProjectItem(m_listView, QStringList() << f.value(), f.key());
1303 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
1304 for (int i = 0; i < list.count(); i++)
1305 slotAddClip(list.at(i), false);
1307 m_listView->blockSignals(false);
1308 connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
1309 connect(m_doc->clipManager(), SIGNAL(modifiedClip(const QString &)), this, SLOT(slotModifiedClip(const QString &)));
1310 connect(m_doc->clipManager(), SIGNAL(missingClip(const QString &)), this, SLOT(slotMissingClip(const QString &)));
1311 connect(m_doc->clipManager(), SIGNAL(availableClip(const QString &)), this, SLOT(slotAvailableClip(const QString &)));
1312 connect(m_doc->clipManager(), SIGNAL(checkAllClips()), this, SLOT(updateAllClips()));
1315 QList <DocClipBase*> ProjectList::documentClipList() const
1318 return QList <DocClipBase*> ();
1320 return m_doc->clipManager()->documentClipList();
1323 QDomElement ProjectList::producersList()
1326 QDomElement prods = doc.createElement("producerlist");
1327 doc.appendChild(prods);
1328 kDebug() << "//////////// PRO LIST BUILD PRDSLIST ";
1329 QTreeWidgetItemIterator it(m_listView);
1331 if ((*it)->type() != PROJECTCLIPTYPE) {
1336 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
1342 void ProjectList::slotCheckForEmptyQueue()
1344 if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
1346 emit loadingIsOver();
1347 emit displayMessage(QString(), -1);
1348 m_listView->blockSignals(false);
1349 m_listView->setEnabled(true);
1351 } else if (!m_refreshed) {
1352 QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
1356 void ProjectList::reloadClipThumbnails()
1358 kDebug() << "////////////// RELOAD CLIPS THUMBNAILS!!!";
1359 m_thumbnailQueue.clear();
1360 QTreeWidgetItemIterator it(m_listView);
1362 if ((*it)->type() != PROJECTCLIPTYPE) {
1367 m_thumbnailQueue << ((ProjectItem *)(*it))->clipId();
1370 QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
1373 void ProjectList::requestClipThumbnail(const QString id)
1375 if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id);
1378 void ProjectList::slotProcessNextThumbnail()
1380 if (m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
1381 slotCheckForEmptyQueue();
1384 if (!m_infoQueue.isEmpty()) {
1385 //QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
1388 if (m_thumbnailQueue.count() > 1) {
1389 int max = m_doc->clipManager()->clipsCount();
1390 emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - m_thumbnailQueue.count()) / max));
1392 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
1395 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
1397 QTreeWidgetItem *item = getAnyItemById(clipId);
1399 slotRefreshClipThumbnail(item, update);
1401 slotProcessNextThumbnail();
1404 void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
1406 if (it == NULL) return;
1407 ProjectItem *item = NULL;
1408 bool isSubItem = false;
1410 if (it->type() == PROJECTFOLDERTYPE) return;
1411 if (it->type() == PROJECTSUBCLIPTYPE) {
1412 item = static_cast <ProjectItem *>(it->parent());
1413 frame = static_cast <SubProjectItem *>(it)->zone().x();
1416 item = static_cast <ProjectItem *>(it);
1417 frame = item->referencedClip()->getClipThumbFrame();
1421 DocClipBase *clip = item->referencedClip();
1423 slotProcessNextThumbnail();
1427 int height = m_listView->iconSize().height();
1428 int width = (int)(height * m_render->dar());
1429 if (clip->clipType() == AUDIO)
1430 pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
1431 else if (clip->clipType() == IMAGE)
1432 pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->producer(), 0, width, height));
1434 pix = item->referencedClip()->thumbProducer()->extractImage(frame, width, height);
1436 if (!pix.isNull()) {
1437 m_listView->blockSignals(true);
1438 it->setData(0, Qt::DecorationRole, pix);
1439 if (m_listView->isEnabled())
1440 m_listView->blockSignals(false);
1442 m_doc->cachePixmap(item->getClipHash(), pix);
1444 m_doc->cachePixmap(item->getClipHash() + '#' + QString::number(frame), pix);
1447 emit projectModified();
1448 QTimer::singleShot(30, this, SLOT(slotProcessNextThumbnail()));
1452 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace)
1455 ProjectItem *item = getItemById(clipId);
1456 if (item && producer) {
1457 m_listView->blockSignals(true);
1458 item->setProperties(properties, metadata);
1459 if (item->referencedClip()->isPlaceHolder() && producer->is_valid()) {
1460 item->referencedClip()->setValid();
1461 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1464 //Q_ASSERT_X(item->referencedClip(), "void ProjectList::slotReplyGetFileProperties", QString("Item with groupName %1 does not have a clip associated").arg(item->groupName()).toLatin1());
1465 item->referencedClip()->setProducer(producer, replace);
1466 item->referencedClip()->askForAudioThumbs();
1467 if (!replace && item->data(0, Qt::DecorationRole).isNull())
1468 requestClipThumbnail(clipId);
1469 if (!toReload.isEmpty())
1470 item->slotSetToolTip();
1472 //emit receivedClipDuration(clipId);
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 int max = m_doc->clipManager()->clipsCount();
1492 if (item && m_infoQueue.isEmpty() && m_thumbnailQueue.isEmpty()) {
1493 m_listView->setCurrentItem(item);
1494 bool updatedProfile = false;
1495 if (item->parent()) {
1496 if (item->parent()->type() == PROJECTFOLDERTYPE)
1497 static_cast <FolderProjectItem *>(item->parent())->switchIcon();
1498 } else if (KdenliveSettings::checkfirstprojectclip() && m_listView->topLevelItemCount() == 1) {
1499 // this is the first clip loaded in project, check if we want to adjust project settings to the clip
1500 updatedProfile = adjustProjectProfileToItem(item);
1502 if (updatedProfile == false) emit clipSelected(item->referencedClip());
1504 emit displayMessage(i18n("Loading clips"), (int)(100 *(max - m_infoQueue.count()) / max));
1506 if (!toReload.isEmpty())
1507 emit clipNeedsReload(toReload, true);
1508 // small delay so that the app can display the progress info
1509 QTimer::singleShot(30, this, SLOT(slotProcessNextClipInQueue()));
1512 bool ProjectList::adjustProjectProfileToItem(ProjectItem *item)
1515 if (m_listView->currentItem() && m_listView->currentItem()->type() != PROJECTFOLDERTYPE)
1516 item = static_cast <ProjectItem*>(m_listView->currentItem());
1518 if (item == NULL || item->referencedClip() == NULL) {
1519 KMessageBox::information(kapp->activeWindow(), i18n("Cannot find profile from current clip"));
1522 bool profileUpdated = false;
1523 QString size = item->referencedClip()->getProperty("frame_size");
1524 int width = size.section('x', 0, 0).toInt();
1525 int height = size.section('x', -1).toInt();
1526 double fps = item->referencedClip()->getProperty("fps").toDouble();
1527 double par = item->referencedClip()->getProperty("aspect_ratio").toDouble();
1528 if (item->clipType() == IMAGE || item->clipType() == AV || item->clipType() == VIDEO) {
1529 if (ProfilesDialog::matchProfile(width, height, fps, par, item->clipType() == IMAGE, m_doc->mltProfile()) == false) {
1530 // get a list of compatible profiles
1531 QMap <QString, QString> suggestedProfiles = ProfilesDialog::getProfilesFromProperties(width, height, fps, par, item->clipType() == IMAGE);
1532 if (!suggestedProfiles.isEmpty()) {
1533 KDialog *dialog = new KDialog(this);
1534 dialog->setCaption(i18n("Change project profile"));
1535 dialog->setButtons(KDialog::Ok | KDialog::Cancel);
1538 QVBoxLayout *l = new QVBoxLayout;
1539 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));
1540 l->addWidget(label);
1541 QListWidget *list = new QListWidget;
1542 list->setAlternatingRowColors(true);
1543 QMapIterator<QString, QString> i(suggestedProfiles);
1544 while (i.hasNext()) {
1546 QListWidgetItem *item = new QListWidgetItem(i.value(), list);
1547 item->setData(Qt::UserRole, i.key());
1548 item->setToolTip(i.key());
1550 list->setCurrentRow(0);
1552 container.setLayout(l);
1553 dialog->setButtonText(KDialog::Ok, i18n("Update profile"));
1554 dialog->setMainWidget(&container);
1555 if (dialog->exec() == QDialog::Accepted) {
1556 //Change project profile
1557 profileUpdated = true;
1558 if (list->currentItem())
1559 emit updateProfile(list->currentItem()->data(Qt::UserRole).toString());
1563 } else if (fps > 0) {
1564 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));
1568 return profileUpdated;
1571 void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
1573 ProjectItem *item = getItemById(clipId);
1574 if (item && !pix.isNull()) {
1575 m_listView->blockSignals(true);
1576 item->setData(0, Qt::DecorationRole, pix);
1577 m_doc->cachePixmap(item->getClipHash(), pix);
1578 if (m_listView->isEnabled())
1579 m_listView->blockSignals(false);
1583 QTreeWidgetItem *ProjectList::getAnyItemById(const QString &id)
1585 QTreeWidgetItemIterator it(m_listView);
1586 QString lookId = id;
1587 if (id.contains('#'))
1588 lookId = id.section('#', 0, 0);
1590 ProjectItem *result = NULL;
1592 if ((*it)->type() != PROJECTCLIPTYPE) {
1597 ProjectItem *item = static_cast<ProjectItem *>(*it);
1598 if (item->clipId() == lookId) {
1604 if (result == NULL || !id.contains('#')) {
1607 for (int i = 0; i < result->childCount(); i++) {
1608 SubProjectItem *sub = static_cast <SubProjectItem *>(result->child(i));
1609 if (sub && sub->zone().x() == id.section('#', 1, 1).toInt())
1618 ProjectItem *ProjectList::getItemById(const QString &id)
1621 QTreeWidgetItemIterator it(m_listView);
1623 if ((*it)->type() != PROJECTCLIPTYPE) {
1628 item = static_cast<ProjectItem *>(*it);
1629 if (item->clipId() == id)
1636 FolderProjectItem *ProjectList::getFolderItemById(const QString &id)
1638 FolderProjectItem *item;
1639 QTreeWidgetItemIterator it(m_listView);
1641 if ((*it)->type() == PROJECTFOLDERTYPE) {
1642 item = static_cast<FolderProjectItem *>(*it);
1643 if (item->clipId() == id)
1651 void ProjectList::slotSelectClip(const QString &ix)
1653 ProjectItem *clip = getItemById(ix);
1655 m_listView->setCurrentItem(clip);
1656 m_listView->scrollToItem(clip);
1657 m_editButton->defaultAction()->setEnabled(true);
1658 m_deleteButton->defaultAction()->setEnabled(true);
1659 m_reloadAction->setEnabled(true);
1660 m_transcodeAction->setEnabled(true);
1661 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
1662 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
1663 m_openAction->setEnabled(true);
1664 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
1665 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
1666 m_openAction->setEnabled(true);
1668 m_openAction->setEnabled(false);
1673 QString ProjectList::currentClipUrl() const
1676 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return QString();
1677 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
1679 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
1681 item = static_cast <ProjectItem*>(m_listView->currentItem());
1685 return item->clipUrl().path();
1688 KUrl::List ProjectList::getConditionalUrls(const QString &condition) const
1692 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
1693 for (int i = 0; i < list.count(); i++) {
1694 if (list.at(i)->type() == PROJECTFOLDERTYPE)
1696 if (list.at(i)->type() == PROJECTSUBCLIPTYPE) {
1698 item = static_cast <ProjectItem*>(list.at(i)->parent());
1700 item = static_cast <ProjectItem*>(list.at(i));
1702 if (item == NULL || item->type() == COLOR || item->type() == SLIDESHOW || item->type() == TEXT)
1704 DocClipBase *clip = item->referencedClip();
1705 if (!condition.isEmpty()) {
1706 if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section('=', 1, 1)))
1708 else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section('=', 1, 1)))
1711 result.append(item->clipUrl());
1716 void ProjectList::regenerateTemplate(const QString &id)
1718 ProjectItem *clip = getItemById(id);
1720 regenerateTemplate(clip);
1723 void ProjectList::regenerateTemplate(ProjectItem *clip)
1725 //TODO: remove this unused method, only force_reload is necessary
1726 clip->referencedClip()->producer()->set("force_reload", 1);
1729 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
1733 if (!file.open(QIODevice::ReadOnly)) {
1734 kWarning() << "ERROR, CANNOT READ: " << path;
1737 if (!doc.setContent(&file)) {
1738 kWarning() << "ERROR, CANNOT READ: " << path;
1743 QDomNodeList texts = doc.elementsByTagName("content");
1744 for (int i = 0; i < texts.count(); i++) {
1745 QString data = texts.item(i).firstChild().nodeValue();
1746 data.replace("%s", replaceString);
1747 texts.item(i).firstChild().setNodeValue(data);
1753 void ProjectList::slotAddClipCut(const QString &id, int in, int out)
1755 ProjectItem *clip = getItemById(id);
1756 if (clip == NULL || clip->referencedClip()->hasCutZone(QPoint(in, out)))
1758 AddClipCutCommand *command = new AddClipCutCommand(this, id, in, out, QString(), true, false);
1759 m_commandStack->push(command);
1762 void ProjectList::addClipCut(const QString &id, int in, int out, const QString desc, bool newItem)
1764 ProjectItem *clip = getItemById(id);
1766 DocClipBase *base = clip->referencedClip();
1767 base->addCutZone(in, out);
1768 m_listView->blockSignals(true);
1769 SubProjectItem *sub = new SubProjectItem(clip, in, out, desc);
1770 if (newItem && desc.isEmpty() && !m_listView->isColumnHidden(1)) {
1771 if (!clip->isExpanded())
1772 clip->setExpanded(true);
1773 m_listView->scrollToItem(sub);
1774 m_listView->editItem(sub, 1);
1776 QPixmap p = clip->referencedClip()->thumbProducer()->extractImage(in, (int)(sub->sizeHint(0).height() * m_render->dar()), sub->sizeHint(0).height() - 2);
1777 sub->setData(0, Qt::DecorationRole, p);
1778 m_doc->cachePixmap(clip->getClipHash() + '#' + QString::number(in), p);
1779 m_listView->blockSignals(false);
1781 emit projectModified();
1784 void ProjectList::removeClipCut(const QString &id, int in, int out)
1786 ProjectItem *clip = getItemById(id);
1788 DocClipBase *base = clip->referencedClip();
1789 base->removeCutZone(in, out);
1790 SubProjectItem *sub = getSubItem(clip, QPoint(in, out));
1792 m_listView->blockSignals(true);
1794 m_listView->blockSignals(false);
1797 emit projectModified();
1800 SubProjectItem *ProjectList::getSubItem(ProjectItem *clip, QPoint zone)
1802 SubProjectItem *sub = NULL;
1804 for (int i = 0; i < clip->childCount(); i++) {
1805 QTreeWidgetItem *it = clip->child(i);
1806 if (it->type() == PROJECTSUBCLIPTYPE) {
1807 sub = static_cast <SubProjectItem*>(it);
1808 if (sub->zone() == zone)
1818 void ProjectList::slotUpdateClipCut(QPoint p)
1820 if (!m_listView->currentItem() || m_listView->currentItem()->type() != PROJECTSUBCLIPTYPE)
1822 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
1823 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
1824 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), p, sub->text(1), sub->text(1), true);
1825 m_commandStack->push(command);
1828 void ProjectList::doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment)
1830 ProjectItem *clip = getItemById(id);
1831 SubProjectItem *sub = getSubItem(clip, oldzone);
1832 if (sub == NULL || clip == NULL)
1834 DocClipBase *base = clip->referencedClip();
1835 base->updateCutZone(oldzone.x(), oldzone.y(), zone.x(), zone.y(), comment);
1836 m_listView->blockSignals(true);
1838 sub->setDescription(comment);
1839 m_listView->blockSignals(false);
1840 emit projectModified();
1843 void ProjectList::slotForceProcessing(const QString &id)
1845 while (m_infoQueue.contains(id)) {
1846 slotProcessNextClipInQueue();
1850 void ProjectList::slotAddOrUpdateSequence(const QString frameName)
1852 QString fileName = KUrl(frameName).fileName().section('_', 0, -2);
1854 QString pattern = SlideshowClip::selectedPath(frameName, false, QString(), &list);
1855 int count = list.count();
1857 const QList <DocClipBase *> existing = m_doc->clipManager()->getClipByResource(pattern);
1858 if (!existing.isEmpty()) {
1859 // Sequence already exists, update
1860 QString id = existing.at(0)->getId();
1861 //ProjectItem *item = getItemById(id);
1862 QMap <QString, QString> oldprops;
1863 QMap <QString, QString> newprops;
1864 int ttl = existing.at(0)->getProperty("ttl").toInt();
1865 oldprops["out"] = existing.at(0)->getProperty("out");
1866 newprops["out"] = QString::number(ttl * count - 1);
1867 slotUpdateClipProperties(id, newprops);
1868 EditClipCommand *command = new EditClipCommand(this, id, oldprops, newprops, false);
1869 m_commandStack->push(command);
1872 QStringList groupInfo = getGroup();
1873 m_doc->slotCreateSlideshowClipFile(fileName, pattern, count, m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()),
1874 false, false, false,
1875 m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))), QString(), 0,
1876 QString(), groupInfo.at(0), groupInfo.at(1));
1878 } else emit displayMessage(i18n("Sequence not found"), -2);
1881 #include "projectlist.moc"