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 "commands/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 "commands/editclipcommand.h"
37 #include "commands/editclipcutcommand.h"
38 #include "commands/editfoldercommand.h"
39 #include "commands/addclipcutcommand.h"
41 #include "ui_templateclip_ui.h"
46 #include <KFileDialog>
47 #include <KInputDialog>
48 #include <KMessageBox>
49 #include <KIO/NetAccess>
51 #include <KApplication>
52 #include <KStandardDirs>
55 #include <nepomuk/global.h>
56 #include <nepomuk/resourcemanager.h>
57 //#include <nepomuk/tag.h>
60 #include <QMouseEvent>
61 #include <QStylePainter>
66 #include <QHeaderView>
67 #include <QInputDialog>
68 #include <QtConcurrentRun>
69 #include <QVBoxLayout>
71 InvalidDialog::InvalidDialog(const QString &caption, const QString &message, bool infoOnly, QWidget *parent) : KDialog(parent)
74 if (infoOnly) setButtons(KDialog::Ok);
75 else setButtons(KDialog::Yes | KDialog::No);
76 QWidget *w = new QWidget(this);
77 QVBoxLayout *l = new QVBoxLayout;
78 l->addWidget(new QLabel(message));
79 m_clipList = new QListWidget;
80 l->addWidget(m_clipList);
85 InvalidDialog::~InvalidDialog()
91 void InvalidDialog::addClip(const QString &id, const QString &path)
93 QListWidgetItem *item = new QListWidgetItem(path);
94 item->setData(Qt::UserRole, id);
95 m_clipList->addItem(item);
98 QStringList InvalidDialog::getIds() const
101 for (int i = 0; i < m_clipList->count(); i++) {
102 ids << m_clipList->item(i)->data(Qt::UserRole).toString();
108 ProjectList::ProjectList(QWidget *parent) :
112 m_commandStack(NULL),
114 m_reloadAction(NULL),
115 m_transcodeAction(NULL),
118 m_allClipsProcessed(false),
120 m_abortAllProxies(false),
121 m_invalidClipDialog(NULL)
123 QVBoxLayout *layout = new QVBoxLayout;
124 layout->setContentsMargins(0, 0, 0, 0);
125 layout->setSpacing(0);
126 qRegisterMetaType<QDomElement>("QDomElement");
128 QFrame *frame = new QFrame;
129 frame->setFrameStyle(QFrame::NoFrame);
130 QHBoxLayout *box = new QHBoxLayout;
131 KTreeWidgetSearchLine *searchView = new KTreeWidgetSearchLine;
133 box->addWidget(searchView);
134 //int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
135 //m_toolbar->setIconSize(QSize(s, s));
137 m_addButton = new QToolButton;
138 m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
139 m_addButton->setAutoRaise(true);
140 box->addWidget(m_addButton);
142 m_editButton = new QToolButton;
143 m_editButton->setAutoRaise(true);
144 box->addWidget(m_editButton);
146 m_deleteButton = new QToolButton;
147 m_deleteButton->setAutoRaise(true);
148 box->addWidget(m_deleteButton);
149 frame->setLayout(box);
150 layout->addWidget(frame);
152 m_listView = new ProjectListView;
153 layout->addWidget(m_listView);
155 searchView->setTreeWidget(m_listView);
157 connect(this, SIGNAL(processNextThumbnail()), this, SLOT(slotProcessNextThumbnail()));
158 connect(m_listView, SIGNAL(projectModified()), this, SIGNAL(projectModified()));
159 connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
160 connect(m_listView, SIGNAL(focusMonitor()), this, SIGNAL(raiseClipMonitor()));
161 connect(m_listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
162 connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
163 connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
164 connect(m_listView, SIGNAL(addClip(const QList <QUrl>, const QString &, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &, const QString &)));
165 connect(m_listView, SIGNAL(addClipCut(const QString &, int, int)), this, SLOT(slotAddClipCut(const QString &, int, int)));
166 connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
167 connect(m_listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
169 m_listViewDelegate = new ItemDelegate(m_listView);
170 m_listView->setItemDelegate(m_listViewDelegate);
172 if (KdenliveSettings::activate_nepomuk()) {
173 Nepomuk::ResourceManager::instance()->init();
174 if (!Nepomuk::ResourceManager::instance()->initialized()) {
175 kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
176 KdenliveSettings::setActivate_nepomuk(false);
182 ProjectList::~ProjectList()
184 m_abortAllProxies = true;
185 m_thumbnailQueue.clear();
187 m_listView->blockSignals(true);
189 delete m_listViewDelegate;
192 void ProjectList::focusTree() const
194 m_listView->setFocus();
197 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
199 QList <QAction *> actions = addMenu->actions();
200 for (int i = 0; i < actions.count(); i++) {
201 if (actions.at(i)->data().toString() == "clip_properties") {
202 m_editButton->setDefaultAction(actions.at(i));
205 } else if (actions.at(i)->data().toString() == "delete_clip") {
206 m_deleteButton->setDefaultAction(actions.at(i));
209 } else if (actions.at(i)->data().toString() == "edit_clip") {
210 m_openAction = actions.at(i);
213 } else if (actions.at(i)->data().toString() == "reload_clip") {
214 m_reloadAction = actions.at(i);
217 } else if (actions.at(i)->data().toString() == "proxy_clip") {
218 m_proxyAction = actions.at(i);
224 QMenu *m = new QMenu();
225 m->addActions(actions);
226 m_addButton->setMenu(m);
227 m_addButton->setDefaultAction(defaultAction);
228 m_menu = new QMenu();
229 m_menu->addActions(addMenu->actions());
232 void ProjectList::setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu, QMenu *inTimelineMenu)
236 QMenu *menu = m_addButton->menu();
237 menu->addMenu(addMenu);
238 m_addButton->setMenu(menu);
240 m_menu->addMenu(addMenu);
241 if (addMenu->isEmpty())
242 addMenu->setEnabled(false);
243 m_menu->addMenu(transcodeMenu);
244 if (transcodeMenu->isEmpty())
245 transcodeMenu->setEnabled(false);
246 m_transcodeAction = transcodeMenu;
247 m_menu->addAction(m_reloadAction);
248 m_menu->addAction(m_proxyAction);
249 m_menu->addMenu(inTimelineMenu);
250 inTimelineMenu->setEnabled(false);
251 m_menu->addAction(m_editButton->defaultAction());
252 m_menu->addAction(m_openAction);
253 m_menu->addAction(m_deleteButton->defaultAction());
254 m_menu->insertSeparator(m_deleteButton->defaultAction());
257 void ProjectList::clearSelection()
259 m_listView->clearSelection();
262 QByteArray ProjectList::headerInfo() const
264 return m_listView->header()->saveState();
267 void ProjectList::setHeaderInfo(const QByteArray &state)
269 m_listView->header()->restoreState(state);
272 void ProjectList::updateProjectFormat(Timecode t)
277 void ProjectList::slotEditClip()
279 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
280 if (list.isEmpty()) return;
281 if (list.count() > 1 || list.at(0)->type() == PROJECTFOLDERTYPE) {
282 editClipSelection(list);
286 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
288 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE)
289 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
291 item = static_cast <ProjectItem*>(m_listView->currentItem());
292 if (item && (item->flags() & Qt::ItemIsDragEnabled)) {
293 emit clipSelected(item->referencedClip());
294 emit showClipProperties(item->referencedClip());
298 void ProjectList::editClipSelection(QList<QTreeWidgetItem *> list)
300 // Gather all common properties
301 QMap <QString, QString> commonproperties;
302 QList <DocClipBase *> clipList;
303 commonproperties.insert("force_aspect_num", "-");
304 commonproperties.insert("force_aspect_den", "-");
305 commonproperties.insert("force_fps", "-");
306 commonproperties.insert("force_progressive", "-");
307 commonproperties.insert("force_tff", "-");
308 commonproperties.insert("threads", "-");
309 commonproperties.insert("video_index", "-");
310 commonproperties.insert("audio_index", "-");
311 commonproperties.insert("force_colorspace", "-");
312 commonproperties.insert("full_luma", "-");
313 QString transparency = "-";
315 bool allowDurationChange = true;
316 int commonDuration = -1;
317 bool hasImages = false;;
319 for (int i = 0; i < list.count(); i++) {
321 if (list.at(i)->type() == PROJECTFOLDERTYPE) {
322 // Add folder items to the list
323 int ct = list.at(i)->childCount();
324 for (int j = 0; j < ct; j++) {
325 list.append(list.at(i)->child(j));
329 else if (list.at(i)->type() == PROJECTSUBCLIPTYPE)
330 item = static_cast <ProjectItem*>(list.at(i)->parent());
332 item = static_cast <ProjectItem*>(list.at(i));
333 if (!(item->flags() & Qt::ItemIsDragEnabled))
337 DocClipBase *clip = item->referencedClip();
338 if (clipList.contains(clip)) continue;
339 if (clip->clipType() == IMAGE) {
341 if (clip->getProperty("transparency").isEmpty() || clip->getProperty("transparency").toInt() == 0) {
342 if (transparency == "-") {
343 // first non transparent image
346 else if (transparency == "1") {
347 // we have transparent and non transparent clips
352 if (transparency == "-") {
353 // first transparent image
356 else if (transparency == "0") {
357 // we have transparent and non transparent clips
362 if (clip->clipType() != COLOR && clip->clipType() != IMAGE && clip->clipType() != TEXT)
363 allowDurationChange = false;
364 if (allowDurationChange && commonDuration != 0) {
365 if (commonDuration == -1)
366 commonDuration = clip->duration().frames(m_fps);
367 else if (commonDuration != clip->duration().frames(m_fps))
370 clipList.append(clip);
371 QMap <QString, QString> clipprops = clip->properties();
372 QMapIterator<QString, QString> p(commonproperties);
373 while (p.hasNext()) {
375 if (p.value().isEmpty()) continue;
376 if (clipprops.contains(p.key())) {
377 if (p.value() == "-")
378 commonproperties.insert(p.key(), clipprops.value(p.key()));
379 else if (p.value() != clipprops.value(p.key()))
380 commonproperties.insert(p.key(), QString());
382 commonproperties.insert(p.key(), QString());
387 if (allowDurationChange)
388 commonproperties.insert("out", QString::number(commonDuration));
390 commonproperties.insert("transparency", transparency);
391 /*QMapIterator<QString, QString> p(commonproperties);
392 while (p.hasNext()) {
394 kDebug() << "Result: " << p.key() << " = " << p.value();
396 emit showClipProperties(clipList, commonproperties);
399 void ProjectList::slotOpenClip()
402 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
404 if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1)
405 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
407 item = static_cast <ProjectItem*>(m_listView->currentItem());
409 if (item->clipType() == IMAGE) {
410 if (KdenliveSettings::defaultimageapp().isEmpty())
411 KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open images in the Settings dialog"));
413 QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
415 if (item->clipType() == AUDIO) {
416 if (KdenliveSettings::defaultaudioapp().isEmpty())
417 KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open audio files in the Settings dialog"));
419 QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
424 void ProjectList::cleanup()
426 m_listView->clearSelection();
427 QTreeWidgetItemIterator it(m_listView);
430 if ((*it)->type() != PROJECTCLIPTYPE) {
434 item = static_cast <ProjectItem *>(*it);
435 if (item->numReferences() == 0)
436 item->setSelected(true);
442 void ProjectList::trashUnusedClips()
444 QTreeWidgetItemIterator it(m_listView);
449 if ((*it)->type() != PROJECTCLIPTYPE) {
453 item = static_cast <ProjectItem *>(*it);
454 if (item->numReferences() == 0) {
455 ids << item->clipId();
456 KUrl url = item->clipUrl();
457 if (!url.isEmpty() && !urls.contains(url.path()))
463 // Check that we don't use the URL in another clip
464 QTreeWidgetItemIterator it2(m_listView);
466 if ((*it2)->type() != PROJECTCLIPTYPE) {
470 item = static_cast <ProjectItem *>(*it2);
471 if (item->numReferences() > 0) {
472 KUrl url = item->clipUrl();
473 if (!url.isEmpty() && urls.contains(url.path())) urls.removeAll(url.path());
478 emit deleteProjectClips(ids, QMap <QString, QString>());
479 for (int i = 0; i < urls.count(); i++)
480 KIO::NetAccess::del(KUrl(urls.at(i)), this);
483 void ProjectList::slotReloadClip(const QString &id)
485 QList<QTreeWidgetItem *> selected;
487 selected = m_listView->selectedItems();
489 ProjectItem *itemToReLoad = getItemById(id);
490 if (itemToReLoad) selected.append(itemToReLoad);
493 for (int i = 0; i < selected.count(); i++) {
494 if (selected.at(i)->type() != PROJECTCLIPTYPE) {
495 if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
496 for (int j = 0; j < selected.at(i)->childCount(); j++)
497 selected.append(selected.at(i)->child(j));
501 item = static_cast <ProjectItem *>(selected.at(i));
502 if (item && !item->isProxyRunning()) {
503 DocClipBase *clip = item->referencedClip();
504 if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
505 kDebug()<<"//// TRYING TO RELOAD: "<<item->clipId()<<", but it is busy";
508 CLIPTYPE t = item->clipType();
510 if (clip && !clip->getProperty("xmltemplate").isEmpty())
511 regenerateTemplate(item);
512 } else if (t != COLOR && t != SLIDESHOW && clip && clip->checkHash() == false) {
513 item->referencedClip()->setPlaceHolder(true);
514 item->setProperty("file_hash", QString());
515 } else if (t == IMAGE) {
516 clip->getProducer()->set("force_reload", 1);
519 QDomElement e = item->toXml();
520 // Make sure we get the correct producer length if it was adjusted in timeline
521 if (t == COLOR || t == IMAGE || t == SLIDESHOW || t == TEXT) {
522 int length = QString(clip->producerProperty("length")).toInt();
523 if (length > 0 && !e.hasAttribute("length")) {
524 e.setAttribute("length", length);
527 resetThumbsProducer(clip);
528 m_render->getFileProperties(e, item->clipId(), m_listView->iconSize().height(), true);
533 void ProjectList::slotModifiedClip(const QString &id)
535 ProjectItem *item = getItemById(id);
537 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
538 if (!pixmap.isNull()) {
540 p.fillRect(0, 0, pixmap.width(), pixmap.height(), QColor(255, 255, 255, 200));
541 p.drawPixmap(0, 0, KIcon("view-refresh").pixmap(m_listView->iconSize()));
544 pixmap = KIcon("view-refresh").pixmap(m_listView->iconSize());
546 item->setData(0, Qt::DecorationRole, pixmap);
550 void ProjectList::slotMissingClip(const QString &id)
552 ProjectItem *item = getItemById(id);
554 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
555 int height = m_listView->iconSize().height();
556 int width = (int)(height * m_render->dar());
557 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
558 if (pixmap.isNull()) {
559 pixmap = QPixmap(width, height);
560 pixmap.fill(Qt::transparent);
562 KIcon icon("dialog-close");
564 p.drawPixmap(3, 3, icon.pixmap(width - 6, height - 6));
566 item->setData(0, Qt::DecorationRole, pixmap);
567 if (item->referencedClip()) {
568 item->referencedClip()->setPlaceHolder(true);
569 if (m_render == NULL) {
570 kDebug() << "********* ERROR, NULL RENDR";
573 Mlt::Producer *newProd = m_render->invalidProducer(id);
574 if (item->referencedClip()->getProducer()) {
575 Mlt::Properties props(newProd->get_properties());
576 Mlt::Properties src_props(item->referencedClip()->getProducer()->get_properties());
577 props.inherit(src_props);
579 item->referencedClip()->setProducer(newProd, true);
580 item->slotSetToolTip();
581 emit clipNeedsReload(id);
585 emit displayMessage(i18n("Check missing clips"), -2);
586 emit updateRenderStatus();
589 void ProjectList::slotAvailableClip(const QString &id)
591 ProjectItem *item = getItemById(id);
594 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
595 if (item->referencedClip()) { // && item->referencedClip()->checkHash() == false) {
596 item->setProperty("file_hash", QString());
600 item->referencedClip()->setValid();
601 item->slotSetToolTip();
604 emit updateRenderStatus();
607 bool ProjectList::hasMissingClips()
609 bool missing = false;
610 QTreeWidgetItemIterator it(m_listView);
612 if ((*it)->type() == PROJECTCLIPTYPE && !((*it)->flags() & Qt::ItemIsDragEnabled)) {
621 void ProjectList::setRenderer(Render *projectRender)
623 m_render = projectRender;
624 m_listView->setIconSize(QSize((ProjectItem::itemDefaultHeight() - 2) * m_render->dar(), ProjectItem::itemDefaultHeight() - 2));
627 void ProjectList::slotClipSelected()
629 QTreeWidgetItem *item = m_listView->currentItem();
630 ProjectItem *clip = NULL;
632 if (item->type() == PROJECTFOLDERTYPE) {
633 emit clipSelected(NULL);
634 m_editButton->defaultAction()->setEnabled(item->childCount() > 0);
635 m_deleteButton->defaultAction()->setEnabled(true);
636 m_openAction->setEnabled(false);
637 m_reloadAction->setEnabled(false);
638 m_transcodeAction->setEnabled(false);
640 if (item->type() == PROJECTSUBCLIPTYPE) {
641 // this is a sub item, use base clip
642 m_deleteButton->defaultAction()->setEnabled(true);
643 clip = static_cast <ProjectItem*>(item->parent());
644 if (clip == NULL) kDebug() << "-----------ERROR";
645 SubProjectItem *sub = static_cast <SubProjectItem*>(item);
646 emit clipSelected(clip->referencedClip(), sub->zone());
647 m_transcodeAction->setEnabled(false);
648 m_reloadAction->setEnabled(false);
649 adjustProxyActions(clip);
652 clip = static_cast <ProjectItem*>(item);
653 if (clip && clip->referencedClip())
654 emit clipSelected(clip->referencedClip());
655 m_editButton->defaultAction()->setEnabled(true);
656 m_deleteButton->defaultAction()->setEnabled(true);
657 m_reloadAction->setEnabled(true);
658 m_transcodeAction->setEnabled(true);
659 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
660 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
661 m_openAction->setEnabled(true);
662 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
663 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
664 m_openAction->setEnabled(true);
666 m_openAction->setEnabled(false);
668 // Display relevant transcoding actions only
669 adjustTranscodeActions(clip);
670 // Display uses in timeline
671 emit findInTimeline(clip->clipId());
674 emit clipSelected(NULL);
675 m_editButton->defaultAction()->setEnabled(false);
676 m_deleteButton->defaultAction()->setEnabled(false);
677 m_openAction->setEnabled(false);
678 m_reloadAction->setEnabled(false);
679 m_transcodeAction->setEnabled(false);
681 adjustProxyActions(clip);
684 void ProjectList::adjustProxyActions(ProjectItem *clip) const
686 if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == SLIDESHOW || clip->clipType() == AUDIO) {
687 m_proxyAction->setEnabled(false);
690 m_proxyAction->setEnabled(useProxy());
691 m_proxyAction->blockSignals(true);
692 m_proxyAction->setChecked(clip->hasProxy());
693 m_proxyAction->blockSignals(false);
696 void ProjectList::adjustTranscodeActions(ProjectItem *clip) const
698 if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW) {
699 m_transcodeAction->setEnabled(false);
702 m_transcodeAction->setEnabled(true);
703 QList<QAction *> transcodeActions = m_transcodeAction->actions();
706 for (int i = 0; i < transcodeActions.count(); i++) {
707 data = transcodeActions.at(i)->data().toStringList();
708 if (data.count() > 2) {
709 condition = data.at(2);
710 if (condition.startsWith("vcodec"))
711 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
712 else if (condition.startsWith("acodec"))
713 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
719 void ProjectList::slotPauseMonitor()
725 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
727 ProjectItem *item = getItemById(id);
729 slotUpdateClipProperties(item, properties);
730 if (properties.contains("out") || properties.contains("force_fps") || properties.contains("resource")) {
732 } else if (properties.contains("colour") ||
733 properties.contains("xmldata") ||
734 properties.contains("force_aspect_num") ||
735 properties.contains("force_aspect_den") ||
736 properties.contains("templatetext")) {
737 slotRefreshClipThumbnail(item);
738 emit refreshClip(id, true);
739 } else if (properties.contains("full_luma") || properties.contains("force_colorspace") || properties.contains("loop")) {
740 emit refreshClip(id, false);
745 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
749 clip->setProperties(properties);
750 if (properties.contains("name")) {
751 monitorItemEditing(false);
752 clip->setText(0, properties.value("name"));
753 monitorItemEditing(true);
754 emit clipNameChanged(clip->clipId(), properties.value("name"));
756 if (properties.contains("description")) {
757 CLIPTYPE type = clip->clipType();
758 monitorItemEditing(false);
759 clip->setText(1, properties.value("description"));
760 monitorItemEditing(true);
762 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
763 // Use Nepomuk system to store clip description
764 Nepomuk::Resource f(clip->clipUrl().path());
765 f.setDescription(properties.value("description"));
768 emit projectModified();
772 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
774 if (item->type() == PROJECTSUBCLIPTYPE) {
775 // this is a sub-item
777 // user edited description
778 SubProjectItem *sub = static_cast <SubProjectItem*>(item);
779 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
780 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), sub->zone(), sub->description(), sub->text(1), true);
781 m_commandStack->push(command);
782 //slotUpdateCutClipProperties(sub->clipId(), sub->zone(), sub->text(1), sub->text(1));
786 if (item->type() == PROJECTFOLDERTYPE) {
788 FolderProjectItem *folder = static_cast <FolderProjectItem*>(item);
789 editFolder(item->text(0), folder->groupName(), folder->clipId());
790 folder->setGroupName(item->text(0));
791 m_doc->clipManager()->addFolder(folder->clipId(), item->text(0));
792 const int children = item->childCount();
793 for (int i = 0; i < children; i++) {
794 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
795 child->setProperty("groupname", item->text(0));
801 ProjectItem *clip = static_cast <ProjectItem*>(item);
803 if (clip->referencedClip()) {
804 QMap <QString, QString> oldprops;
805 QMap <QString, QString> newprops;
806 oldprops["description"] = clip->referencedClip()->getProperty("description");
807 newprops["description"] = item->text(1);
809 if (clip->clipType() == TEXT) {
810 // This is a text template clip, update the image
811 /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
812 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/
813 oldprops.insert("templatetext", clip->referencedClip()->getProperty("templatetext"));
814 newprops.insert("templatetext", item->text(1));
816 slotUpdateClipProperties(clip->clipId(), newprops);
817 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
818 m_commandStack->push(command);
820 } else if (column == 0) {
821 if (clip->referencedClip()) {
822 QMap <QString, QString> oldprops;
823 QMap <QString, QString> newprops;
824 oldprops["name"] = clip->referencedClip()->getProperty("name");
825 if (oldprops.value("name") != item->text(0)) {
826 newprops["name"] = item->text(0);
827 slotUpdateClipProperties(clip, newprops);
828 emit projectModified();
829 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
830 m_commandStack->push(command);
836 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
838 bool enable = item ? true : false;
839 m_editButton->defaultAction()->setEnabled(enable);
840 m_deleteButton->defaultAction()->setEnabled(enable);
841 m_reloadAction->setEnabled(enable);
842 m_transcodeAction->setEnabled(enable);
844 ProjectItem *clip = NULL;
845 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
846 clip = static_cast <ProjectItem*>(item->parent());
847 m_transcodeAction->setEnabled(false);
848 adjustProxyActions(clip);
849 } else if (m_listView->currentItem()->type() == PROJECTCLIPTYPE) {
850 clip = static_cast <ProjectItem*>(item);
851 // Display relevant transcoding actions only
852 adjustTranscodeActions(clip);
853 adjustProxyActions(clip);
854 // Display uses in timeline
855 emit findInTimeline(clip->clipId());
857 m_transcodeAction->setEnabled(false);
859 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
860 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
861 m_openAction->setEnabled(true);
862 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
863 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
864 m_openAction->setEnabled(true);
866 m_openAction->setEnabled(false);
870 m_openAction->setEnabled(false);
875 void ProjectList::slotRemoveClip()
877 if (!m_listView->currentItem())
880 QMap <QString, QString> folderids;
881 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
883 QUndoCommand *delCommand = new QUndoCommand();
884 delCommand->setText(i18n("Delete Clip Zone"));
885 for (int i = 0; i < selected.count(); i++) {
886 if (selected.at(i)->type() == PROJECTSUBCLIPTYPE) {
888 SubProjectItem *sub = static_cast <SubProjectItem *>(selected.at(i));
889 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
890 new AddClipCutCommand(this, item->clipId(), sub->zone().x(), sub->zone().y(), sub->description(), false, true, delCommand);
891 } else if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
893 FolderProjectItem *folder = static_cast <FolderProjectItem *>(selected.at(i));
894 folderids[folder->groupName()] = folder->clipId();
895 int children = folder->childCount();
897 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)
899 for (int i = 0; i < children; ++i) {
900 ProjectItem *child = static_cast <ProjectItem *>(folder->child(i));
901 ids << child->clipId();
904 ProjectItem *item = static_cast <ProjectItem *>(selected.at(i));
905 ids << item->clipId();
906 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) {
907 KMessageBox::enableMessage("DeleteAll");
912 KMessageBox::enableMessage("DeleteAll");
913 if (delCommand->childCount() == 0)
916 m_commandStack->push(delCommand);
917 emit deleteProjectClips(ids, folderids);
920 void ProjectList::updateButtons() const
922 if (m_listView->topLevelItemCount() == 0) {
923 m_deleteButton->defaultAction()->setEnabled(false);
924 m_editButton->defaultAction()->setEnabled(false);
926 m_deleteButton->defaultAction()->setEnabled(true);
927 if (!m_listView->currentItem())
928 m_listView->setCurrentItem(m_listView->topLevelItem(0));
929 QTreeWidgetItem *item = m_listView->currentItem();
930 if (item && item->type() == PROJECTCLIPTYPE) {
931 m_editButton->defaultAction()->setEnabled(true);
932 m_openAction->setEnabled(true);
933 m_reloadAction->setEnabled(true);
934 m_transcodeAction->setEnabled(true);
937 else if (item && item->type() == PROJECTFOLDERTYPE && item->childCount() > 0) {
938 m_editButton->defaultAction()->setEnabled(true);
940 else m_editButton->defaultAction()->setEnabled(false);
942 m_openAction->setEnabled(false);
943 m_reloadAction->setEnabled(false);
944 m_transcodeAction->setEnabled(false);
945 m_proxyAction->setEnabled(false);
948 void ProjectList::selectItemById(const QString &clipId)
950 ProjectItem *item = getItemById(clipId);
952 m_listView->setCurrentItem(item);
956 void ProjectList::slotDeleteClip(const QString &clipId)
958 ProjectItem *item = getItemById(clipId);
960 kDebug() << "/// Cannot find clip to delete";
963 if (item->isProxyRunning()) m_abortProxy.append(item->referencedClip()->getProperty("proxy"));
964 m_listView->blockSignals(true);
965 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
966 if (!newSelectedItem)
967 newSelectedItem = m_listView->itemBelow(item);
969 // Pause playing to prevent crash while deleting clip
971 m_doc->clipManager()->deleteClip(clipId);
972 m_listView->blockSignals(false);
973 if (newSelectedItem) {
974 m_listView->setCurrentItem(newSelectedItem);
977 emit clipSelected(NULL);
982 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
984 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
985 m_commandStack->push(command);
986 m_doc->setModified(true);
989 void ProjectList::slotAddFolder()
991 AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
992 m_commandStack->push(command);
995 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
998 FolderProjectItem *item = getFolderItemById(clipId);
1000 m_doc->clipManager()->deleteFolder(clipId);
1001 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
1002 if (!newSelectedItem)
1003 newSelectedItem = m_listView->itemBelow(item);
1005 if (newSelectedItem)
1006 m_listView->setCurrentItem(newSelectedItem);
1012 FolderProjectItem *item = getFolderItemById(clipId);
1014 m_listView->blockSignals(true);
1015 item->setGroupName(foldername);
1016 m_listView->blockSignals(false);
1017 m_doc->clipManager()->addFolder(clipId, foldername);
1018 const int children = item->childCount();
1019 for (int i = 0; i < children; i++) {
1020 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
1021 child->setProperty("groupname", foldername);
1025 m_listView->blockSignals(true);
1026 m_listView->setCurrentItem(new FolderProjectItem(m_listView, QStringList() << foldername, clipId));
1027 m_doc->clipManager()->addFolder(clipId, foldername);
1028 m_listView->blockSignals(false);
1029 m_listView->editItem(m_listView->currentItem(), 0);
1033 m_doc->setModified(true);
1038 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
1040 QMapIterator<QString, QString> i(map);
1041 QUndoCommand *delCommand = new QUndoCommand();
1042 delCommand->setText(i18n("Delete Folder"));
1043 while (i.hasNext()) {
1045 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
1047 if (delCommand->childCount() > 0) m_commandStack->push(delCommand);
1048 else delete delCommand;
1051 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
1053 //m_listView->setEnabled(false);
1054 const QString parent = clip->getProperty("groupid");
1055 ProjectItem *item = NULL;
1056 monitorItemEditing(false);
1057 if (!parent.isEmpty()) {
1058 FolderProjectItem *parentitem = getFolderItemById(parent);
1061 QString groupName = clip->getProperty("groupname");
1062 //kDebug() << "Adding clip to new group: " << groupName;
1063 if (groupName.isEmpty()) groupName = i18n("Folder");
1065 parentitem = new FolderProjectItem(m_listView, text, parent);
1069 item = new ProjectItem(parentitem, clip);
1072 item = new ProjectItem(m_listView, clip);
1074 if (item->data(0, DurationRole).isNull()) item->setData(0, DurationRole, i18n("Loading"));
1075 QString proxy = clip->getProperty("proxy");
1076 if (!proxy.isEmpty() && proxy != "-") slotCreateProxy(clip->getId());
1077 connect(clip, SIGNAL(createProxy(const QString &)), this, SLOT(slotCreateProxy(const QString &)));
1078 connect(clip, SIGNAL(abortProxy(const QString &, const QString &)), this, SLOT(slotAbortProxy(const QString, const QString)));
1079 if (getProperties) {
1080 int height = m_listView->iconSize().height();
1081 int width = (int)(height * m_render->dar());
1082 QPixmap pix = KIcon("video-x-generic").pixmap(QSize(width, height));
1083 item->setData(0, Qt::DecorationRole, pix);
1084 //item->setFlags(Qt::ItemIsSelectable);
1085 m_listView->processLayout();
1086 QDomElement e = clip->toXML().cloneNode().toElement();
1087 e.removeAttribute("file_hash");
1088 resetThumbsProducer(clip);
1089 m_render->getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true);
1091 else if (item->hasProxy() && !item->isProxyRunning()) {
1092 slotCreateProxy(clip->getId());
1094 clip->askForAudioThumbs();
1096 KUrl url = clip->fileURL();
1098 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
1099 // if file has Nepomuk comment, use it
1100 Nepomuk::Resource f(url.path());
1101 QString annotation = f.description();
1102 if (!annotation.isEmpty()) item->setText(1, annotation);
1103 item->setText(2, QString::number(f.rating()));
1107 QList <CutZoneInfo> cuts = clip->cutZones();
1108 if (!cuts.isEmpty()) {
1109 for (int i = 0; i < cuts.count(); i++) {
1110 SubProjectItem *sub = new SubProjectItem(item, cuts.at(i).zone.x(), cuts.at(i).zone.y(), cuts.at(i).description);
1111 if (!clip->getClipHash().isEmpty()) {
1112 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(cuts.at(i).zone.x()) + ".png";
1113 if (QFile::exists(cachedPixmap)) {
1114 QPixmap pix(cachedPixmap);
1116 KIO::NetAccess::del(KUrl(cachedPixmap), this);
1117 sub->setData(0, Qt::DecorationRole, pix);
1122 monitorItemEditing(true);
1126 void ProjectList::slotGotProxy(const QString &proxyPath)
1128 if (proxyPath.isEmpty() || m_abortAllProxies) return;
1129 QTreeWidgetItemIterator it(m_listView);
1132 while (*it && !m_abortAllProxies) {
1133 if ((*it)->type() == PROJECTCLIPTYPE) {
1134 item = static_cast <ProjectItem *>(*it);
1135 if (item->referencedClip()->getProperty("proxy") == proxyPath)
1142 void ProjectList::slotGotProxy(ProjectItem *item)
1144 if (item == NULL || !m_refreshed) return;
1145 DocClipBase *clip = item->referencedClip();
1146 if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
1147 // Clip is being reprocessed, abort
1148 kDebug()<<"//// TRYING TO PROXY: "<<item->clipId()<<", but it is busy";
1152 // Proxy clip successfully created
1153 QDomElement e = clip->toXML().cloneNode().toElement();
1155 // Make sure we get the correct producer length if it was adjusted in timeline
1156 CLIPTYPE t = item->clipType();
1157 if (t == COLOR || t == IMAGE || t == SLIDESHOW || t == TEXT) {
1158 int length = QString(clip->producerProperty("length")).toInt();
1159 if (length > 0 && !e.hasAttribute("length")) {
1160 e.setAttribute("length", length);
1163 resetThumbsProducer(clip);
1164 m_render->getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true);
1167 void ProjectList::slotResetProjectList()
1169 m_listView->blockSignals(true);
1170 m_abortAllProxies = true;
1171 m_proxyThreads.waitForFinished();
1172 m_proxyThreads.clearFutures();
1173 m_thumbnailQueue.clear();
1174 m_listView->clear();
1175 m_listView->setEnabled(true);
1176 emit clipSelected(NULL);
1177 m_refreshed = false;
1178 m_allClipsProcessed = false;
1179 m_abortAllProxies = false;
1180 m_listView->blockSignals(false);
1183 void ProjectList::slotUpdateClip(const QString &id)
1185 ProjectItem *item = getItemById(id);
1186 monitorItemEditing(false);
1187 if (item) item->setData(0, UsageRole, QString::number(item->numReferences()));
1188 monitorItemEditing(true);
1191 void ProjectList::getCachedThumbnail(ProjectItem *item)
1194 DocClipBase *clip = item->referencedClip();
1196 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
1197 if (QFile::exists(cachedPixmap)) {
1198 QPixmap pix(cachedPixmap);
1200 KIO::NetAccess::del(KUrl(cachedPixmap), this);
1201 requestClipThumbnail(item->clipId());
1203 else item->setData(0, Qt::DecorationRole, pix);
1206 requestClipThumbnail(item->clipId());
1210 void ProjectList::getCachedThumbnail(SubProjectItem *item)
1213 ProjectItem *parentItem = static_cast <ProjectItem *>(item->parent());
1214 if (!parentItem) return;
1215 DocClipBase *clip = parentItem->referencedClip();
1217 int pos = item->zone().x();
1218 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + "#" + QString::number(pos) + ".png";
1219 if (QFile::exists(cachedPixmap)) {
1220 QPixmap pix(cachedPixmap);
1222 KIO::NetAccess::del(KUrl(cachedPixmap), this);
1223 requestClipThumbnail(parentItem->clipId() + '#' + QString::number(pos));
1225 else item->setData(0, Qt::DecorationRole, pix);
1227 else requestClipThumbnail(parentItem->clipId() + '#' + QString::number(pos));
1230 void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged, QStringList brokenClips)
1232 if (!m_allClipsProcessed) m_listView->setEnabled(false);
1233 m_listView->setSortingEnabled(false);
1234 QTreeWidgetItemIterator it(m_listView);
1237 monitorItemEditing(false);
1238 int height = m_listView->iconSize().height();
1239 int width = (int)(height * m_render->dar());
1240 QPixmap missingPixmap = QPixmap(width, height);
1241 missingPixmap.fill(Qt::transparent);
1242 KIcon icon("dialog-close");
1243 QPainter p(&missingPixmap);
1244 p.drawPixmap(3, 3, icon.pixmap(width - 6, height - 6));
1247 int max = m_doc->clipManager()->clipsCount();
1252 emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - ct++) / max));
1253 if ((*it)->type() == PROJECTSUBCLIPTYPE) {
1255 SubProjectItem *sub = static_cast <SubProjectItem *>(*it);
1256 if (displayRatioChanged) {
1257 item = static_cast <ProjectItem *>((*it)->parent());
1258 requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x()));
1260 else if (sub->data(0, Qt::DecorationRole).isNull()) {
1261 getCachedThumbnail(sub);
1265 } else if ((*it)->type() == PROJECTFOLDERTYPE) {
1270 item = static_cast <ProjectItem *>(*it);
1271 clip = item->referencedClip();
1272 if (item->referencedClip()->getProducer() == NULL) {
1273 bool replace = false;
1274 if (brokenClips.contains(item->clipId())) {
1275 // if this is a proxy clip, disable proxy
1276 item->setProxyStatus(NOPROXY);
1277 clip->setProperty("proxy", "-");
1280 if (clip->isPlaceHolder() == false && !item->isProxyRunning()) {
1281 QDomElement xml = clip->toXML();
1283 xml.removeAttribute("out");
1284 xml.removeAttribute("file_hash");
1285 xml.removeAttribute("proxy_out");
1287 if (!replace) replace = xml.attribute("replace") == "1";
1288 if (replace) resetThumbsProducer(clip);
1289 m_render->getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), replace);
1291 else if (clip->isPlaceHolder()) {
1292 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
1293 if (item->data(0, Qt::DecorationRole).isNull()) {
1294 item->setData(0, Qt::DecorationRole, missingPixmap);
1297 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
1298 QPainter p(&pixmap);
1299 p.drawPixmap(3, 3, KIcon("dialog-close").pixmap(pixmap.width() - 6, pixmap.height() - 6));
1301 item->setData(0, Qt::DecorationRole, pixmap);
1305 if (displayRatioChanged)
1306 requestClipThumbnail(clip->getId());
1307 else if (item->data(0, Qt::DecorationRole).isNull()) {
1308 getCachedThumbnail(item);
1310 if (item->data(0, DurationRole).toString().isEmpty()) {
1311 item->changeDuration(item->referencedClip()->getProducer()->get_playtime());
1313 if (clip->isPlaceHolder()) {
1314 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
1315 if (pixmap.isNull()) {
1316 pixmap = QPixmap(width, height);
1317 pixmap.fill(Qt::transparent);
1319 QPainter p(&pixmap);
1320 p.drawPixmap(3, 3, KIcon("dialog-close").pixmap(pixmap.width() - 6, pixmap.height() - 6));
1322 item->setData(0, Qt::DecorationRole, pixmap);
1325 item->setData(0, UsageRole, QString::number(item->numReferences()));
1330 m_listView->setSortingEnabled(true);
1331 m_allClipsProcessed = true;
1332 if (m_render->processingItems() == 0) {
1333 monitorItemEditing(true);
1334 slotProcessNextThumbnail();
1339 QString ProjectList::getExtensions()
1341 // Build list of mime types
1342 QStringList mimeTypes = QStringList() << "application/x-kdenlive" << "application/x-kdenlivetitle" << "video/mlt-playlist" << "text/plain"
1343 << "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"
1344 << "audio/x-flac" << "audio/x-matroska" << "audio/mp4" << "audio/mpeg" << "audio/x-mp3" << "audio/ogg" << "audio/x-wav" << "audio/x-aiff" << "audio/aiff" << "application/ogg" << "application/mxf" << "application/x-shockwave-flash"
1345 << "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";
1347 QString allExtensions;
1348 foreach(const QString & mimeType, mimeTypes) {
1349 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
1351 allExtensions.append(mime->patterns().join(" "));
1352 allExtensions.append(' ');
1355 return allExtensions.simplified();
1358 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
1360 if (!m_commandStack)
1361 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1364 if (givenList.isEmpty()) {
1365 QString allExtensions = getExtensions();
1366 const QString dialogFilter = allExtensions + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
1367 QCheckBox *b = new QCheckBox(i18n("Import image sequence"));
1368 b->setChecked(KdenliveSettings::autoimagesequence());
1369 QCheckBox *c = new QCheckBox(i18n("Transparent background for images"));
1370 c->setChecked(KdenliveSettings::autoimagetransparency());
1371 QFrame *f = new QFrame;
1372 f->setFrameShape(QFrame::NoFrame);
1373 QHBoxLayout *l = new QHBoxLayout;
1378 KFileDialog *d = new KFileDialog(KUrl("kfiledialog:///clipfolder"), dialogFilter, kapp->activeWindow(), f);
1379 d->setOperationMode(KFileDialog::Opening);
1380 d->setMode(KFile::Files);
1381 if (d->exec() == QDialog::Accepted) {
1382 KdenliveSettings::setAutoimagetransparency(c->isChecked());
1384 list = d->selectedUrls();
1385 if (b->isChecked() && list.count() == 1) {
1386 // Check for image sequence
1387 KUrl url = list.at(0);
1388 QString fileName = url.fileName().section('.', 0, -2);
1389 if (fileName.at(fileName.size() - 1).isDigit()) {
1390 KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
1391 if (item.mimetype().startsWith("image")) {
1392 // import as sequence if we found more than one image in the sequence
1394 QString pattern = SlideshowClip::selectedPath(url.path(), false, QString(), &list);
1395 int count = list.count();
1398 QStringList groupInfo = getGroup();
1400 // get image sequence base name
1401 while (fileName.at(fileName.size() - 1).isDigit()) {
1405 m_doc->slotCreateSlideshowClipFile(fileName, pattern, count, m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()),
1406 false, false, false,
1407 m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))), QString(), 0,
1408 QString(), groupInfo.at(0), groupInfo.at(1));
1416 for (int i = 0; i < givenList.count(); i++)
1417 list << givenList.at(i);
1420 foreach(const KUrl & file, list) {
1421 // Check there is no folder here
1422 KMimeType::Ptr type = KMimeType::findByUrl(file);
1423 if (type->is("inode/directory")) {
1424 // user dropped a folder
1425 list.removeAll(file);
1432 if (givenList.isEmpty()) {
1433 QStringList groupInfo = getGroup();
1434 m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1));
1436 m_doc->slotAddClipList(list, groupName, groupId);
1440 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
1442 ProjectItem *item = getItemById(id);
1443 m_processingClips.removeAll(id);
1444 m_thumbnailQueue.removeAll(id);
1446 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1447 const QString path = item->referencedClip()->fileURL().path();
1448 if (item->referencedClip()->isPlaceHolder()) replace = false;
1449 if (!path.isEmpty()) {
1450 if (m_invalidClipDialog) {
1451 m_invalidClipDialog->addClip(id, path);
1456 m_invalidClipDialog = new InvalidDialog(i18n("Invalid clip"), i18n("Clip <b>%1</b><br />is invalid, will be removed from project.", QString()), replace, kapp->activeWindow());
1458 m_invalidClipDialog = new InvalidDialog(i18n("Invalid clip"), i18n("Clip <b>%1</b><br />is missing or invalid. Remove it from project?", QString()), replace, kapp->activeWindow());
1460 m_invalidClipDialog->addClip(id, path);
1461 int result = m_invalidClipDialog->exec();
1462 if (result == KDialog::Yes) replace = true;
1465 if (m_invalidClipDialog) {
1467 emit deleteProjectClips(m_invalidClipDialog->getIds(), QMap <QString, QString>());
1468 delete m_invalidClipDialog;
1469 m_invalidClipDialog = NULL;
1475 void ProjectList::slotRemoveInvalidProxy(const QString &id, bool durationError)
1477 ProjectItem *item = getItemById(id);
1479 kDebug()<<"// Proxy for clip "<<id<<" is invalid, delete";
1480 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1481 if (durationError) {
1482 kDebug() << "Proxy duration is wrong, try changing transcoding parameters.";
1483 emit displayMessage(i18n("Proxy clip unusable (duration is different from original)."), -2);
1485 item->setProxyStatus(PROXYCRASHED);
1486 QString path = item->referencedClip()->getProperty("proxy");
1487 KUrl proxyFolder(m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/");
1489 //Security check: make sure the invalid proxy file is in the proxy folder
1490 if (proxyFolder.isParentOf(KUrl(path))) {
1491 QFile::remove(path);
1493 if (item->referencedClip()->getProducer() == NULL) {
1494 // Clip has no valid producer, request it
1495 slotProxyCurrentItem(false, item);
1498 // refresh thumbs producer
1499 item->referencedClip()->reloadThumbProducer();
1502 m_processingClips.removeAll(id);
1503 m_thumbnailQueue.removeAll(id);
1506 void ProjectList::slotAddColorClip()
1508 if (!m_commandStack)
1509 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1511 QDialog *dia = new QDialog(this);
1512 Ui::ColorClip_UI dia_ui;
1513 dia_ui.setupUi(dia);
1514 dia->setWindowTitle(i18n("Color Clip"));
1515 dia_ui.clip_name->setText(i18n("Color Clip"));
1517 TimecodeDisplay *t = new TimecodeDisplay(m_timecode);
1518 t->setValue(KdenliveSettings::color_duration());
1519 t->setTimeCodeFormat(false);
1520 dia_ui.clip_durationBox->addWidget(t);
1521 dia_ui.clip_color->setColor(KdenliveSettings::colorclipcolor());
1523 if (dia->exec() == QDialog::Accepted) {
1524 QString color = dia_ui.clip_color->color().name();
1525 KdenliveSettings::setColorclipcolor(color);
1526 color = color.replace(0, 1, "0x") + "ff";
1527 QStringList groupInfo = getGroup();
1528 m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, m_timecode.getTimecode(t->gentime()), groupInfo.at(0), groupInfo.at(1));
1535 void ProjectList::slotAddSlideshowClip()
1537 if (!m_commandStack)
1538 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1540 SlideshowClip *dia = new SlideshowClip(m_timecode, this);
1542 if (dia->exec() == QDialog::Accepted) {
1543 QStringList groupInfo = getGroup();
1544 m_doc->slotCreateSlideshowClipFile(dia->clipName(), dia->selectedPath(), dia->imageCount(), dia->clipDuration(),
1545 dia->loop(), dia->crop(), dia->fade(),
1546 dia->lumaDuration(), dia->lumaFile(), dia->softness(),
1547 dia->animation(), groupInfo.at(0), groupInfo.at(1));
1552 void ProjectList::slotAddTitleClip()
1554 QStringList groupInfo = getGroup();
1555 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
1558 void ProjectList::slotAddTitleTemplateClip()
1560 if (!m_commandStack)
1561 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1563 QStringList groupInfo = getGroup();
1565 // Get the list of existing templates
1567 filter << "*.kdenlivetitle";
1568 const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
1569 QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
1571 QDialog *dia = new QDialog(this);
1572 Ui::TemplateClip_UI dia_ui;
1573 dia_ui.setupUi(dia);
1574 for (int i = 0; i < templateFiles.size(); ++i)
1575 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
1577 if (!templateFiles.isEmpty())
1578 dia_ui.buttonBox->button(QDialogButtonBox::Ok)->setFocus();
1579 dia_ui.template_list->fileDialog()->setFilter("application/x-kdenlivetitle");
1580 //warning: setting base directory doesn't work??
1581 KUrl startDir(path);
1582 dia_ui.template_list->fileDialog()->setUrl(startDir);
1583 dia_ui.text_box->setHidden(true);
1584 if (dia->exec() == QDialog::Accepted) {
1585 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
1586 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
1587 // Create a cloned template clip
1588 m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
1593 QStringList ProjectList::getGroup() const
1596 QTreeWidgetItem *item = m_listView->currentItem();
1597 while (item && item->type() != PROJECTFOLDERTYPE)
1598 item = item->parent();
1601 FolderProjectItem *folder = static_cast <FolderProjectItem *>(item);
1602 result << folder->groupName() << folder->clipId();
1604 result << QString() << QString();
1609 void ProjectList::setDocument(KdenliveDoc *doc)
1611 m_listView->blockSignals(true);
1612 m_abortAllProxies = true;
1613 m_proxyThreads.waitForFinished();
1614 m_proxyThreads.clearFutures();
1615 m_thumbnailQueue.clear();
1616 m_listView->clear();
1617 m_processingClips.clear();
1619 m_listView->setSortingEnabled(false);
1620 emit clipSelected(NULL);
1621 m_refreshed = false;
1622 m_allClipsProcessed = false;
1624 m_timecode = doc->timecode();
1625 m_commandStack = doc->commandStack();
1627 m_abortAllProxies = false;
1629 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
1630 QStringList openedFolders = doc->getExpandedFolders();
1631 QMapIterator<QString, QString> f(flist);
1632 while (f.hasNext()) {
1634 FolderProjectItem *folder = new FolderProjectItem(m_listView, QStringList() << f.value(), f.key());
1635 folder->setExpanded(openedFolders.contains(f.key()));
1638 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
1639 if (list.isEmpty()) {
1642 m_allClipsProcessed = true;
1644 for (int i = 0; i < list.count(); i++)
1645 slotAddClip(list.at(i), false);
1647 m_listView->blockSignals(false);
1648 connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
1649 connect(m_doc->clipManager(), SIGNAL(modifiedClip(const QString &)), this, SLOT(slotModifiedClip(const QString &)));
1650 connect(m_doc->clipManager(), SIGNAL(missingClip(const QString &)), this, SLOT(slotMissingClip(const QString &)));
1651 connect(m_doc->clipManager(), SIGNAL(availableClip(const QString &)), this, SLOT(slotAvailableClip(const QString &)));
1652 connect(m_doc->clipManager(), SIGNAL(checkAllClips(bool, bool, QStringList)), this, SLOT(updateAllClips(bool, bool, QStringList)));
1655 QList <DocClipBase*> ProjectList::documentClipList() const
1658 return QList <DocClipBase*> ();
1660 return m_doc->clipManager()->documentClipList();
1663 QDomElement ProjectList::producersList()
1666 QDomElement prods = doc.createElement("producerlist");
1667 doc.appendChild(prods);
1668 QTreeWidgetItemIterator it(m_listView);
1670 if ((*it)->type() != PROJECTCLIPTYPE) {
1675 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
1681 void ProjectList::slotCheckForEmptyQueue()
1683 if (m_render->processingItems() == 0 && m_thumbnailQueue.isEmpty()) {
1684 if (!m_refreshed && m_allClipsProcessed) {
1686 m_listView->setEnabled(true);
1688 QTimer::singleShot(500, this, SIGNAL(loadingIsOver()));
1689 emit displayMessage(QString(), -1);
1692 } else if (!m_refreshed) {
1693 QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
1698 void ProjectList::requestClipThumbnail(const QString id)
1700 if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id);
1701 slotProcessNextThumbnail();
1704 void ProjectList::resetThumbsProducer(DocClipBase *clip)
1707 clip->clearThumbProducer();
1708 QString id = clip->getId();
1709 m_thumbnailQueue.removeAll(id);
1712 void ProjectList::slotProcessNextThumbnail()
1714 if (m_render->processingItems() > 0) {
1717 if (m_thumbnailQueue.isEmpty()) {
1718 slotCheckForEmptyQueue();
1721 int max = m_doc->clipManager()->clipsCount();
1722 emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - m_thumbnailQueue.count()) / max));
1723 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
1726 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
1728 QTreeWidgetItem *item = getAnyItemById(clipId);
1730 slotRefreshClipThumbnail(item, update);
1732 slotProcessNextThumbnail();
1736 void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
1738 if (it == NULL) return;
1739 ProjectItem *item = NULL;
1740 bool isSubItem = false;
1742 if (it->type() == PROJECTFOLDERTYPE) return;
1743 if (it->type() == PROJECTSUBCLIPTYPE) {
1744 item = static_cast <ProjectItem *>(it->parent());
1745 frame = static_cast <SubProjectItem *>(it)->zone().x();
1748 item = static_cast <ProjectItem *>(it);
1749 frame = item->referencedClip()->getClipThumbFrame();
1753 DocClipBase *clip = item->referencedClip();
1755 slotProcessNextThumbnail();
1759 int height = m_listView->iconSize().height();
1760 int swidth = (int)(height * m_render->frameRenderWidth() / m_render->renderHeight()+ 0.5);
1761 int dwidth = (int)(height * m_render->dar() + 0.5);
1762 if (clip->clipType() == AUDIO)
1763 pix = KIcon("audio-x-generic").pixmap(QSize(dwidth, height));
1764 else if (clip->clipType() == IMAGE)
1765 pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->getProducer(), 0, swidth, dwidth, height));
1767 pix = item->referencedClip()->extractImage(frame, dwidth, height);
1770 if (!pix.isNull()) {
1771 monitorItemEditing(false);
1772 it->setData(0, Qt::DecorationRole, pix);
1773 monitorItemEditing(true);
1775 QString clipId = item->getClipHash();
1776 if (!clipId.isEmpty()) {
1778 m_doc->cachePixmap(clipId, pix);
1780 m_doc->cachePixmap(clipId + '#' + QString::number(frame), pix);
1784 emit projectModified();
1785 slotProcessNextThumbnail();
1790 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const stringMap &properties, const stringMap &metadata, bool replace)
1793 ProjectItem *item = getItemById(clipId);
1795 int queue = m_render->processingItems();
1796 if (item && producer) {
1797 monitorItemEditing(false);
1798 DocClipBase *clip = item->referencedClip();
1799 if (producer->is_valid()) {
1800 if (clip->isPlaceHolder()) {
1804 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1806 item->setProperties(properties, metadata);
1807 clip->setProducer(producer, replace);
1808 clip->askForAudioThumbs();
1811 QString size = properties.value("frame_size");
1812 if (!useProxy() && clip->getProperty("proxy").isEmpty()) setProxyStatus(item, NOPROXY);
1813 if (useProxy() && generateProxy() && clip->getProperty("proxy") == "-") setProxyStatus(item, NOPROXY);
1814 else if (useProxy() && !item->hasProxy() && !item->isProxyRunning()) {
1815 // proxy video and image clips
1817 CLIPTYPE t = item->clipType();
1818 if (t == IMAGE) maxSize = m_doc->getDocumentProperty("proxyimageminsize").toInt();
1819 else maxSize = m_doc->getDocumentProperty("proxyminsize").toInt();
1820 if ((((t == AV || t == VIDEO || t == PLAYLIST) && generateProxy()) || (t == IMAGE && generateImageProxy())) && (size.section('x', 0, 0).toInt() > maxSize || size.section('x', 1, 1).toInt() > maxSize)) {
1821 if (clip->getProperty("proxy").isEmpty()) {
1822 KUrl proxyPath = m_doc->projectFolder();
1823 proxyPath.addPath("proxy/");
1824 proxyPath.addPath(clip->getClipHash() + "." + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension")));
1825 QMap <QString, QString> newProps;
1826 // insert required duration for proxy
1827 if (t != IMAGE) newProps.insert("proxy_out", clip->producerProperty("out"));
1828 newProps.insert("proxy", proxyPath.path());
1829 QMap <QString, QString> oldProps = clip->properties();
1830 oldProps.insert("proxy", QString());
1831 EditClipCommand *command = new EditClipCommand(this, clipId, oldProps, newProps, true);
1832 m_doc->commandStack()->push(command);
1837 if (!replace && m_allClipsProcessed && item->data(0, Qt::DecorationRole).isNull()) {
1838 getCachedThumbnail(item);
1840 if (!toReload.isEmpty())
1841 item->slotSetToolTip();
1842 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
1844 monitorItemEditing(true);
1845 if (item && m_thumbnailQueue.isEmpty()) {
1846 m_listView->setCurrentItem(item);
1847 bool updatedProfile = false;
1848 if (item->parent()) {
1849 if (item->parent()->type() == PROJECTFOLDERTYPE)
1850 static_cast <FolderProjectItem *>(item->parent())->switchIcon();
1851 } else if (KdenliveSettings::checkfirstprojectclip() && m_listView->topLevelItemCount() == 1 && m_refreshed && m_allClipsProcessed) {
1852 // this is the first clip loaded in project, check if we want to adjust project settings to the clip
1853 updatedProfile = adjustProjectProfileToItem(item);
1855 if (updatedProfile == false) {
1856 //emit clipSelected(item->referencedClip());
1859 int max = m_doc->clipManager()->clipsCount();
1860 if (max > 0) emit displayMessage(i18n("Loading clips"), (int)(100 *(max - queue) / max));
1862 if (m_allClipsProcessed) emit processNextThumbnail();
1865 // no item for producer, delete it
1869 if (replace) toReload = clipId;
1870 if (!toReload.isEmpty())
1871 emit clipNeedsReload(toReload);
1874 bool ProjectList::adjustProjectProfileToItem(ProjectItem *item)
1877 if (m_listView->currentItem() && m_listView->currentItem()->type() != PROJECTFOLDERTYPE)
1878 item = static_cast <ProjectItem*>(m_listView->currentItem());
1880 if (item == NULL || item->referencedClip() == NULL) {
1881 KMessageBox::information(kapp->activeWindow(), i18n("Cannot find profile from current clip"));
1884 bool profileUpdated = false;
1885 QString size = item->referencedClip()->getProperty("frame_size");
1886 int width = size.section('x', 0, 0).toInt();
1887 int height = size.section('x', -1).toInt();
1888 double fps = item->referencedClip()->getProperty("fps").toDouble();
1889 double par = item->referencedClip()->getProperty("aspect_ratio").toDouble();
1890 if (item->clipType() == IMAGE || item->clipType() == AV || item->clipType() == VIDEO) {
1891 if (ProfilesDialog::matchProfile(width, height, fps, par, item->clipType() == IMAGE, m_doc->mltProfile()) == false) {
1892 // get a list of compatible profiles
1893 QMap <QString, QString> suggestedProfiles = ProfilesDialog::getProfilesFromProperties(width, height, fps, par, item->clipType() == IMAGE);
1894 if (!suggestedProfiles.isEmpty()) {
1895 KDialog *dialog = new KDialog(this);
1896 dialog->setCaption(i18n("Change project profile"));
1897 dialog->setButtons(KDialog::Ok | KDialog::Cancel);
1900 QVBoxLayout *l = new QVBoxLayout;
1901 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));
1902 l->addWidget(label);
1903 QListWidget *list = new QListWidget;
1904 list->setAlternatingRowColors(true);
1905 QMapIterator<QString, QString> i(suggestedProfiles);
1906 while (i.hasNext()) {
1908 QListWidgetItem *item = new QListWidgetItem(i.value(), list);
1909 item->setData(Qt::UserRole, i.key());
1910 item->setToolTip(i.key());
1912 list->setCurrentRow(0);
1914 container.setLayout(l);
1915 dialog->setButtonText(KDialog::Ok, i18n("Update profile"));
1916 dialog->setMainWidget(&container);
1917 if (dialog->exec() == QDialog::Accepted) {
1918 //Change project profile
1919 profileUpdated = true;
1920 if (list->currentItem())
1921 emit updateProfile(list->currentItem()->data(Qt::UserRole).toString());
1925 } else if (fps > 0) {
1926 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));
1930 return profileUpdated;
1933 QString ProjectList::getDocumentProperty(const QString &key) const
1935 return m_doc->getDocumentProperty(key);
1938 bool ProjectList::useProxy() const
1940 return m_doc->getDocumentProperty("enableproxy").toInt();
1943 bool ProjectList::generateProxy() const
1945 return m_doc->getDocumentProperty("generateproxy").toInt();
1948 bool ProjectList::generateImageProxy() const
1950 return m_doc->getDocumentProperty("generateimageproxy").toInt();
1953 void ProjectList::slotReplyGetImage(const QString &clipId, const QImage &img)
1955 QPixmap pix = QPixmap::fromImage(img);
1956 setThumbnail(clipId, pix);
1959 void ProjectList::slotReplyGetImage(const QString &clipId, const QString &name, int width, int height)
1961 QPixmap pix = KIcon(name).pixmap(QSize(width, height));
1962 setThumbnail(clipId, pix);
1965 void ProjectList::setThumbnail(const QString &clipId, const QPixmap &pix)
1967 ProjectItem *item = getItemById(clipId);
1968 if (item && !pix.isNull()) {
1969 monitorItemEditing(false);
1970 item->setData(0, Qt::DecorationRole, pix);
1971 monitorItemEditing(true);
1973 QString clipId = item->getClipHash();
1974 if (!clipId.isEmpty()) m_doc->cachePixmap(clipId, pix);
1978 QTreeWidgetItem *ProjectList::getAnyItemById(const QString &id)
1980 QTreeWidgetItemIterator it(m_listView);
1981 QString lookId = id;
1982 if (id.contains('#'))
1983 lookId = id.section('#', 0, 0);
1985 ProjectItem *result = NULL;
1987 if ((*it)->type() != PROJECTCLIPTYPE) {
1992 ProjectItem *item = static_cast<ProjectItem *>(*it);
1993 if (item->clipId() == lookId) {
1999 if (result == NULL || !id.contains('#')) {
2002 for (int i = 0; i < result->childCount(); i++) {
2003 SubProjectItem *sub = static_cast <SubProjectItem *>(result->child(i));
2004 if (sub && sub->zone().x() == id.section('#', 1, 1).toInt())
2013 ProjectItem *ProjectList::getItemById(const QString &id)
2016 QTreeWidgetItemIterator it(m_listView);
2018 if ((*it)->type() != PROJECTCLIPTYPE) {
2019 // subitem or folder
2023 item = static_cast<ProjectItem *>(*it);
2024 if (item->clipId() == id)
2031 FolderProjectItem *ProjectList::getFolderItemById(const QString &id)
2033 FolderProjectItem *item;
2034 QTreeWidgetItemIterator it(m_listView);
2036 if ((*it)->type() == PROJECTFOLDERTYPE) {
2037 item = static_cast<FolderProjectItem *>(*it);
2038 if (item->clipId() == id)
2046 void ProjectList::slotSelectClip(const QString &ix)
2048 ProjectItem *clip = getItemById(ix);
2050 m_listView->setCurrentItem(clip);
2051 m_listView->scrollToItem(clip);
2052 m_editButton->defaultAction()->setEnabled(true);
2053 m_deleteButton->defaultAction()->setEnabled(true);
2054 m_reloadAction->setEnabled(true);
2055 m_transcodeAction->setEnabled(true);
2056 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
2057 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
2058 m_openAction->setEnabled(true);
2059 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
2060 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
2061 m_openAction->setEnabled(true);
2063 m_openAction->setEnabled(false);
2068 QString ProjectList::currentClipUrl() const
2071 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return QString();
2072 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
2074 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
2076 item = static_cast <ProjectItem*>(m_listView->currentItem());
2080 return item->clipUrl().path();
2083 KUrl::List ProjectList::getConditionalUrls(const QString &condition) const
2087 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
2088 for (int i = 0; i < list.count(); i++) {
2089 if (list.at(i)->type() == PROJECTFOLDERTYPE)
2091 if (list.at(i)->type() == PROJECTSUBCLIPTYPE) {
2093 item = static_cast <ProjectItem*>(list.at(i)->parent());
2095 item = static_cast <ProjectItem*>(list.at(i));
2097 if (item == NULL || item->type() == COLOR || item->type() == SLIDESHOW || item->type() == TEXT)
2099 DocClipBase *clip = item->referencedClip();
2100 if (!condition.isEmpty()) {
2101 if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section('=', 1, 1)))
2103 else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section('=', 1, 1)))
2106 result.append(item->clipUrl());
2111 void ProjectList::regenerateTemplate(const QString &id)
2113 ProjectItem *clip = getItemById(id);
2115 regenerateTemplate(clip);
2118 void ProjectList::regenerateTemplate(ProjectItem *clip)
2120 //TODO: remove this unused method, only force_reload is necessary
2121 clip->referencedClip()->getProducer()->set("force_reload", 1);
2124 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
2128 if (!file.open(QIODevice::ReadOnly)) {
2129 kWarning() << "ERROR, CANNOT READ: " << path;
2132 if (!doc.setContent(&file)) {
2133 kWarning() << "ERROR, CANNOT READ: " << path;
2138 QDomNodeList texts = doc.elementsByTagName("content");
2139 for (int i = 0; i < texts.count(); i++) {
2140 QString data = texts.item(i).firstChild().nodeValue();
2141 data.replace("%s", replaceString);
2142 texts.item(i).firstChild().setNodeValue(data);
2148 void ProjectList::slotAddClipCut(const QString &id, int in, int out)
2150 ProjectItem *clip = getItemById(id);
2151 if (clip == NULL || clip->referencedClip()->hasCutZone(QPoint(in, out)))
2153 AddClipCutCommand *command = new AddClipCutCommand(this, id, in, out, QString(), true, false);
2154 m_commandStack->push(command);
2157 void ProjectList::addClipCut(const QString &id, int in, int out, const QString desc, bool newItem)
2159 ProjectItem *clip = getItemById(id);
2161 DocClipBase *base = clip->referencedClip();
2162 base->addCutZone(in, out);
2163 monitorItemEditing(false);
2164 SubProjectItem *sub = new SubProjectItem(clip, in, out, desc);
2165 if (newItem && desc.isEmpty() && !m_listView->isColumnHidden(1)) {
2166 if (!clip->isExpanded())
2167 clip->setExpanded(true);
2168 m_listView->scrollToItem(sub);
2169 m_listView->editItem(sub, 1);
2171 QPixmap p = clip->referencedClip()->extractImage(in, (int)(sub->sizeHint(0).height() * m_render->dar()), sub->sizeHint(0).height() - 2);
2172 sub->setData(0, Qt::DecorationRole, p);
2173 QString clipId = clip->getClipHash();
2174 if (!clipId.isEmpty()) m_doc->cachePixmap(clipId + '#' + QString::number(in), p);
2175 monitorItemEditing(true);
2177 emit projectModified();
2180 void ProjectList::removeClipCut(const QString &id, int in, int out)
2182 ProjectItem *clip = getItemById(id);
2184 DocClipBase *base = clip->referencedClip();
2185 base->removeCutZone(in, out);
2186 SubProjectItem *sub = getSubItem(clip, QPoint(in, out));
2188 monitorItemEditing(false);
2190 monitorItemEditing(true);
2193 emit projectModified();
2196 SubProjectItem *ProjectList::getSubItem(ProjectItem *clip, QPoint zone)
2198 SubProjectItem *sub = NULL;
2200 for (int i = 0; i < clip->childCount(); i++) {
2201 QTreeWidgetItem *it = clip->child(i);
2202 if (it->type() == PROJECTSUBCLIPTYPE) {
2203 sub = static_cast <SubProjectItem*>(it);
2204 if (sub->zone() == zone)
2214 void ProjectList::slotUpdateClipCut(QPoint p)
2216 if (!m_listView->currentItem() || m_listView->currentItem()->type() != PROJECTSUBCLIPTYPE)
2218 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
2219 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
2220 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), p, sub->text(1), sub->text(1), true);
2221 m_commandStack->push(command);
2224 void ProjectList::doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment)
2226 ProjectItem *clip = getItemById(id);
2227 SubProjectItem *sub = getSubItem(clip, oldzone);
2228 if (sub == NULL || clip == NULL)
2230 DocClipBase *base = clip->referencedClip();
2231 base->updateCutZone(oldzone.x(), oldzone.y(), zone.x(), zone.y(), comment);
2232 monitorItemEditing(false);
2234 sub->setDescription(comment);
2235 monitorItemEditing(true);
2236 emit projectModified();
2239 void ProjectList::slotForceProcessing(const QString &id)
2241 m_render->forceProcessing(id);
2244 void ProjectList::slotAddOrUpdateSequence(const QString frameName)
2246 QString fileName = KUrl(frameName).fileName().section('_', 0, -2);
2248 QString pattern = SlideshowClip::selectedPath(frameName, false, QString(), &list);
2249 int count = list.count();
2251 const QList <DocClipBase *> existing = m_doc->clipManager()->getClipByResource(pattern);
2252 if (!existing.isEmpty()) {
2253 // Sequence already exists, update
2254 QString id = existing.at(0)->getId();
2255 //ProjectItem *item = getItemById(id);
2256 QMap <QString, QString> oldprops;
2257 QMap <QString, QString> newprops;
2258 int ttl = existing.at(0)->getProperty("ttl").toInt();
2259 oldprops["out"] = existing.at(0)->getProperty("out");
2260 newprops["out"] = QString::number(ttl * count - 1);
2261 slotUpdateClipProperties(id, newprops);
2262 EditClipCommand *command = new EditClipCommand(this, id, oldprops, newprops, false);
2263 m_commandStack->push(command);
2266 QStringList groupInfo = getGroup();
2267 m_doc->slotCreateSlideshowClipFile(fileName, pattern, count, m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()),
2268 false, false, false,
2269 m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))), QString(), 0,
2270 QString(), groupInfo.at(0), groupInfo.at(1));
2272 } else emit displayMessage(i18n("Sequence not found"), -2);
2275 QMap <QString, QString> ProjectList::getProxies()
2277 QMap <QString, QString> list;
2279 QTreeWidgetItemIterator it(m_listView);
2281 if ((*it)->type() != PROJECTCLIPTYPE) {
2285 item = static_cast<ProjectItem *>(*it);
2286 if (item && item->referencedClip() != NULL) {
2287 if (item->hasProxy()) {
2288 QString proxy = item->referencedClip()->getProperty("proxy");
2289 list.insert(proxy, item->clipUrl().path());
2297 void ProjectList::slotCreateProxy(const QString id)
2299 ProjectItem *item = getItemById(id);
2300 if (!item || item->isProxyRunning() || item->referencedClip()->isPlaceHolder()) return;
2301 QString path = item->referencedClip()->getProperty("proxy");
2302 if (path.isEmpty()) {
2303 setProxyStatus(path, PROXYCRASHED);
2306 setProxyStatus(path, PROXYWAITING);
2307 if (m_abortProxy.contains(path)) m_abortProxy.removeAll(path);
2308 if (m_processingProxy.contains(path)) {
2309 // Proxy is already being generated
2312 if (QFile::exists(path)) {
2313 // Proxy already created
2314 setProxyStatus(path, PROXYDONE);
2318 m_processingProxy.append(path);
2322 info.src = item->clipUrl().path();
2323 info.type = item->clipType();
2324 info.exif = QString(item->referencedClip()->producerProperty("_exif_orientation")).toInt();
2325 m_proxyList.append(info);
2326 if (m_proxyThreads.futures().isEmpty() || m_proxyThreads.futures().count() < KdenliveSettings::proxythreads()) m_proxyThreads.addFuture(QtConcurrent::run(this, &ProjectList::slotGenerateProxy));
2329 void ProjectList::slotAbortProxy(const QString id, const QString path)
2331 QTreeWidgetItemIterator it(m_listView);
2332 ProjectItem *item = getItemById(id);
2333 setProxyStatus(item, NOPROXY);
2335 if (!path.isEmpty() && m_processingProxy.contains(path)) {
2336 m_abortProxy << path;
2337 setProxyStatus(path, NOPROXY);
2341 void ProjectList::slotGenerateProxy()
2343 while (!m_proxyList.isEmpty() && !m_abortAllProxies) {
2344 emit projectModified();
2345 PROXYINFO info = m_proxyList.takeFirst();
2346 if (m_abortProxy.contains(info.dest)) {
2347 m_abortProxy.removeAll(info.dest);
2351 // Make sure proxy path is writable
2352 QFile file(info.dest);
2353 if (!file.open(QIODevice::WriteOnly)) {
2354 setProxyStatus(info.dest, PROXYCRASHED);
2355 m_processingProxy.removeAll(info.dest);
2359 QFile::remove(info.dest);
2361 setProxyStatus(info.dest, CREATINGPROXY);
2363 // Get the list of clips that will need to get progress info
2364 QTreeWidgetItemIterator it(m_listView);
2365 QList <ProjectItem *> processingItems;
2366 while (*it && !m_abortAllProxies) {
2367 if ((*it)->type() == PROJECTCLIPTYPE) {
2368 ProjectItem *item = static_cast <ProjectItem *>(*it);
2369 if (item->referencedClip()->getProperty("proxy") == info.dest) {
2370 processingItems.append(item);
2376 // Special case: playlist clips (.mlt or .kdenlive project files)
2377 if (info.type == PLAYLIST) {
2378 // change FFmpeg params to MLT format
2379 QStringList parameters;
2380 parameters << info.src;
2381 parameters << "-consumer" << "avformat:" + info.dest;
2382 QStringList params = m_doc->getDocumentProperty("proxyparams").simplified().split('-', QString::SkipEmptyParts);
2384 foreach(QString s, params) {
2386 if (s.count(' ') == 0) {
2389 else s.replace(' ', '=');
2393 parameters.append(QString("real_time=-%1").arg(KdenliveSettings::mltthreads()));
2395 //TODO: currently, when rendering an xml file through melt, the display ration is lost, so we enforce it manualy
2396 double display_ratio = KdenliveDoc::getDisplayRatio(info.src);
2397 parameters << "aspect=" + QString::number(display_ratio);
2399 //kDebug()<<"TRANSCOD: "<<parameters;
2401 myProcess.setProcessChannelMode(QProcess::MergedChannels);
2402 myProcess.start(KdenliveSettings::rendererpath(), parameters);
2403 myProcess.waitForStarted();
2406 while (myProcess.state() != QProcess::NotRunning) {
2407 // building proxy file
2408 if (m_abortProxy.contains(info.dest) || m_abortAllProxies) {
2410 myProcess.waitForFinished();
2411 QFile::remove(info.dest);
2412 m_abortProxy.removeAll(info.dest);
2413 m_processingProxy.removeAll(info.dest);
2414 setProxyStatus(info.dest, NOPROXY);
2418 QString log = QString(myProcess.readAll());
2419 processLogInfo(processingItems, &duration, log);
2421 myProcess.waitForFinished(500);
2423 myProcess.waitForFinished();
2424 m_processingProxy.removeAll(info.dest);
2425 if (result == -1) result = myProcess.exitStatus();
2427 // proxy successfully created
2428 setProxyStatus(info.dest, PROXYDONE);
2429 slotGotProxy(info.dest);
2431 else if (result == 1) {
2432 // Proxy process crashed
2433 QFile::remove(info.dest);
2434 setProxyStatus(info.dest, PROXYCRASHED);
2439 if (info.type == IMAGE) {
2443 // Cannot load image
2444 setProxyStatus(info.dest, PROXYCRASHED);
2448 // Images are scaled to profile size.
2449 //TODO: Make it be configurable?
2450 if (i.width() > i.height()) proxy = i.scaledToWidth(m_render->frameRenderWidth());
2451 else proxy = i.scaledToHeight(m_render->renderHeight());
2452 if (info.exif > 1) {
2453 // Rotate image according to exif data
2457 switch ( info.exif ) {
2459 matrix.scale( -1, 1 );
2462 matrix.rotate( 180 );
2465 matrix.scale( 1, -1 );
2468 matrix.rotate( 270 );
2469 matrix.scale( -1, 1 );
2472 matrix.rotate( 90 );
2475 matrix.rotate( 90 );
2476 matrix.scale( -1, 1 );
2479 matrix.rotate( 270 );
2482 processed = proxy.transformed( matrix );
2483 processed.save(info.dest);
2485 else proxy.save(info.dest);
2486 setProxyStatus(info.dest, PROXYDONE);
2487 slotGotProxy(info.dest);
2488 m_abortProxy.removeAll(info.dest);
2489 m_processingProxy.removeAll(info.dest);
2493 QStringList parameters;
2494 parameters << "-i" << info.src;
2495 QString params = m_doc->getDocumentProperty("proxyparams").simplified();
2496 foreach(QString s, params.split(' '))
2499 // Make sure we don't block when proxy file already exists
2501 parameters << info.dest;
2503 myProcess.setProcessChannelMode(QProcess::MergedChannels);
2504 myProcess.start("ffmpeg", parameters);
2505 myProcess.waitForStarted();
2509 while (myProcess.state() != QProcess::NotRunning) {
2510 // building proxy file
2511 if (m_abortProxy.contains(info.dest) || m_abortAllProxies) {
2513 myProcess.waitForFinished();
2514 m_abortProxy.removeAll(info.dest);
2515 m_processingProxy.removeAll(info.dest);
2516 QFile::remove(info.dest);
2517 if (!m_abortAllProxies) setProxyStatus(info.dest, NOPROXY);
2522 QString log = QString(myProcess.readAll());
2523 processLogInfo(processingItems, &duration, log);
2525 myProcess.waitForFinished(500);
2527 myProcess.waitForFinished();
2528 m_abortProxy.removeAll(info.dest);
2529 m_processingProxy.removeAll(info.dest);
2530 if (result == -1) result = myProcess.exitStatus();
2532 // proxy successfully created
2533 setProxyStatus(info.dest, PROXYDONE);
2534 slotGotProxy(info.dest);
2536 else if (result == 1) {
2537 // Proxy process crashed
2538 QFile::remove(info.dest);
2539 setProxyStatus(info.dest, PROXYCRASHED);
2545 void ProjectList::processLogInfo(QList <ProjectItem *>items, int *duration, const QString &log)
2548 if (*duration == 0) {
2549 if (log.contains("Duration:")) {
2550 QString data = log.section("Duration:", 1, 1).section(',', 0, 0).simplified();
2551 QStringList numbers = data.split(':');
2552 *duration = (int) (numbers.at(0).toInt() * 3600 + numbers.at(1).toInt() * 60 + numbers.at(2).toDouble());
2555 else if (log.contains("time=")) {
2556 QString time = log.section("time=", 1, 1).simplified().section(' ', 0, 0);
2557 if (time.contains(':')) {
2558 QStringList numbers = time.split(':');
2559 progress = numbers.at(0).toInt() * 3600 + numbers.at(1).toInt() * 60 + numbers.at(2).toDouble();
2561 else progress = (int) time.toDouble();
2562 for (int i = 0; i < items.count(); i++)
2563 setProxyStatus(items.at(i), CREATINGPROXY, (int) (100.0 * progress / (*duration)));
2567 void ProjectList::updateProxyConfig()
2570 QTreeWidgetItemIterator it(m_listView);
2571 QUndoCommand *command = new QUndoCommand();
2572 command->setText(i18n("Update proxy settings"));
2573 QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/";
2575 if ((*it)->type() != PROJECTCLIPTYPE) {
2579 item = static_cast<ProjectItem *>(*it);
2584 CLIPTYPE t = item->clipType();
2585 if ((t == VIDEO || t == AV || t == UNKNOWN) && item->referencedClip() != NULL) {
2586 if (generateProxy() && useProxy() && !item->isProxyRunning()) {
2587 DocClipBase *clip = item->referencedClip();
2588 if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > m_doc->getDocumentProperty("proxyminsize").toInt()) {
2589 if (clip->getProperty("proxy").isEmpty()) {
2590 // We need to insert empty proxy in old properties so that undo will work
2591 QMap <QString, QString> oldProps;// = clip->properties();
2592 oldProps.insert("proxy", QString());
2593 QMap <QString, QString> newProps;
2594 newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + "." + m_doc->getDocumentProperty("proxyextension"));
2595 new EditClipCommand(this, clip->getId(), oldProps, newProps, true, command);
2599 else if (item->hasProxy()) {
2601 QMap <QString, QString> newProps;
2602 newProps.insert("proxy", QString());
2603 newProps.insert("replace", "1");
2604 // insert required duration for proxy
2605 newProps.insert("proxy_out", item->referencedClip()->producerProperty("out"));
2606 new EditClipCommand(this, item->clipId(), item->referencedClip()->properties(), newProps, true, command);
2609 else if (t == IMAGE && item->referencedClip() != NULL) {
2610 if (generateImageProxy() && useProxy()) {
2611 DocClipBase *clip = item->referencedClip();
2612 int maxImageSize = m_doc->getDocumentProperty("proxyimageminsize").toInt();
2613 if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > maxImageSize || clip->getProperty("frame_size").section('x', 1, 1).toInt() > maxImageSize) {
2614 if (clip->getProperty("proxy").isEmpty()) {
2615 // We need to insert empty proxy in old properties so that undo will work
2616 QMap <QString, QString> oldProps = clip->properties();
2617 oldProps.insert("proxy", QString());
2618 QMap <QString, QString> newProps;
2619 newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + ".png");
2620 new EditClipCommand(this, clip->getId(), oldProps, newProps, true, command);
2624 else if (item->hasProxy()) {
2626 QMap <QString, QString> newProps;
2627 newProps.insert("proxy", QString());
2628 newProps.insert("replace", "1");
2629 new EditClipCommand(this, item->clipId(), item->referencedClip()->properties(), newProps, true, command);
2634 if (command->childCount() > 0) m_doc->commandStack()->push(command);
2635 else delete command;
2638 void ProjectList::slotProxyCurrentItem(bool doProxy, ProjectItem *itemToProxy)
2640 QList<QTreeWidgetItem *> list;
2641 if (itemToProxy == NULL) list = m_listView->selectedItems();
2642 else list << itemToProxy;
2643 QTreeWidgetItem *listItem;
2644 QUndoCommand *command = new QUndoCommand();
2645 if (doProxy) command->setText(i18np("Add proxy clip", "Add proxy clips", list.count()));
2646 else command->setText(i18np("Remove proxy clip", "Remove proxy clips", list.count()));
2648 // Make sure the proxy folder exists
2649 QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/";
2650 KStandardDirs::makeDir(proxydir);
2652 QMap <QString, QString> newProps;
2653 QMap <QString, QString> oldProps;
2654 if (!doProxy) newProps.insert("proxy", "-");
2655 for (int i = 0; i < list.count(); i++) {
2656 listItem = list.at(i);
2657 if (listItem->type() == PROJECTFOLDERTYPE) {
2658 for (int j = 0; j < listItem->childCount(); j++) {
2659 QTreeWidgetItem *sub = listItem->child(j);
2660 if (!list.contains(sub)) list.append(sub);
2663 else if (listItem->type() == PROJECTSUBCLIPTYPE) {
2664 QTreeWidgetItem *sub = listItem->parent();
2665 if (!list.contains(sub)) list.append(sub);
2667 else if (listItem->type() == PROJECTCLIPTYPE) {
2668 ProjectItem *item = static_cast <ProjectItem*>(listItem);
2669 CLIPTYPE t = item->clipType();
2670 if ((t == VIDEO || t == AV || t == UNKNOWN || t == IMAGE || t == PLAYLIST) && item->referencedClip()) {
2671 if ((doProxy && item->hasProxy()) || (!doProxy && !item->hasProxy() && item->referencedClip()->getProducer() != NULL)) continue;
2672 DocClipBase *clip = item->referencedClip();
2673 if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
2674 kDebug()<<"//// TRYING TO PROXY: "<<item->clipId()<<", but it is busy";
2678 resetThumbsProducer(clip);
2679 oldProps = clip->properties();
2682 QString path = proxydir + clip->getClipHash() + "." + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension"));
2683 // insert required duration for proxy
2684 newProps.insert("proxy_out", clip->producerProperty("out"));
2685 newProps.insert("proxy", path);
2686 // We need to insert empty proxy so that undo will work
2687 oldProps.insert("proxy", QString());
2689 else if (item->referencedClip()->getProducer() == NULL) {
2690 // Force clip reload
2691 newProps.insert("resource", item->referencedClip()->getProperty("resource"));
2693 new EditClipCommand(this, item->clipId(), oldProps, newProps, true, command);
2697 if (command->childCount() > 0) {
2698 m_doc->commandStack()->push(command);
2700 else delete command;
2704 void ProjectList::slotDeleteProxy(const QString proxyPath)
2706 if (proxyPath.isEmpty()) return;
2707 QUndoCommand *proxyCommand = new QUndoCommand();
2708 proxyCommand->setText(i18n("Remove Proxy"));
2709 QTreeWidgetItemIterator it(m_listView);
2712 if ((*it)->type() == PROJECTCLIPTYPE) {
2713 item = static_cast <ProjectItem *>(*it);
2714 if (item->referencedClip()->getProperty("proxy") == proxyPath) {
2715 QMap <QString, QString> props;
2716 props.insert("proxy", QString());
2717 new EditClipCommand(this, item->clipId(), item->referencedClip()->properties(), props, true, proxyCommand);
2723 if (proxyCommand->childCount() == 0)
2724 delete proxyCommand;
2726 m_commandStack->push(proxyCommand);
2727 QFile::remove(proxyPath);
2730 void ProjectList::setProxyStatus(const QString proxyPath, PROXYSTATUS status, int progress)
2732 if (proxyPath.isEmpty() || m_abortAllProxies) return;
2733 QTreeWidgetItemIterator it(m_listView);
2735 while (*it && !m_abortAllProxies) {
2736 if ((*it)->type() == PROJECTCLIPTYPE) {
2737 item = static_cast <ProjectItem *>(*it);
2738 if (item->referencedClip()->getProperty("proxy") == proxyPath) {
2739 setProxyStatus(item, status, progress);
2746 void ProjectList::setProxyStatus(ProjectItem *item, PROXYSTATUS status, int progress)
2748 if (item == NULL) return;
2749 monitorItemEditing(false);
2750 item->setProxyStatus(status, progress);
2751 monitorItemEditing(true);
2754 void ProjectList::monitorItemEditing(bool enable)
2756 if (enable) connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
2757 else disconnect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
2760 QStringList ProjectList::expandedFolders() const
2763 FolderProjectItem *item;
2764 QTreeWidgetItemIterator it(m_listView);
2766 if ((*it)->type() != PROJECTFOLDERTYPE) {
2770 if ((*it)->isExpanded()) {
2771 item = static_cast<FolderProjectItem *>(*it);
2772 result.append(item->clipId());
2779 #include "projectlist.moc"