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 "projecttree/proxyclipjob.h"
24 #include "projecttree/cutclipjob.h"
25 #include "projecttree/meltjob.h"
26 #include "kdenlivesettings.h"
27 #include "slideshowclip.h"
28 #include "ui_colorclip_ui.h"
29 #include "widgets/titlewidget.h"
30 #include "definitions.h"
31 #include "clipmanager.h"
32 #include "docclipbase.h"
33 #include "kdenlivedoc.h"
36 #include "projectlistview.h"
37 #include "timecodedisplay.h"
38 #include "profilesdialog.h"
39 #include "clipstabilize.h"
40 #include "commands/editclipcommand.h"
41 #include "commands/editclipcutcommand.h"
42 #include "commands/editfoldercommand.h"
43 #include "commands/addclipcutcommand.h"
45 #include "ui_templateclip_ui.h"
46 #include "ui_cutjobdialog_ui.h"
47 #include "ui_scenecutdialog_ui.h"
51 #include <KLocalizedString>
52 #include <KFileDialog>
53 #include <KInputDialog>
54 #include <KMessageBox>
55 #include <KIO/NetAccess>
57 #include <KApplication>
58 #include <KStandardDirs>
59 #include <KColorScheme>
60 #include <KActionCollection>
61 #include <KUrlRequester>
66 #include <nepomuk/global.h>
67 #include <nepomuk/resourcemanager.h>
68 #include <Nepomuk/Resource>
69 //#include <nepomuk/tag.h>
72 #ifdef USE_NEPOMUKCORE
73 #include <nepomuk2/resourcemanager.h>
74 #include <Nepomuk2/Resource>
77 #include <QMouseEvent>
78 #include <QStylePainter>
84 #include <QHeaderView>
85 #include <QInputDialog>
86 #include <QtConcurrentRun>
87 #include <QVBoxLayout>
88 #include <KPassivePopup>
92 MyMessageWidget::MyMessageWidget(QWidget *parent) : KMessageWidget(parent) {}
93 MyMessageWidget::MyMessageWidget(const QString &text, QWidget *parent) : KMessageWidget(text, parent) {}
96 bool MyMessageWidget::event(QEvent* ev) {
97 if (ev->type() == QEvent::Hide || ev->type() == QEvent::Close) emit messageClosing();
98 return KMessageWidget::event(ev);
101 SmallInfoLabel::SmallInfoLabel(QWidget *parent) : QPushButton(parent)
106 /*QString style = "QToolButton {background-color: %1;border-style: outset;border-width: 2px;
107 border-radius: 5px;border-color: beige;}";*/
108 m_timeLine = new QTimeLine(500, this);
109 QObject::connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(slotTimeLineChanged(qreal)));
110 QObject::connect(m_timeLine, SIGNAL(finished()), this, SLOT(slotTimeLineFinished()));
114 const QString SmallInfoLabel::getStyleSheet(const QPalette &p)
116 KColorScheme scheme(p.currentColorGroup(), KColorScheme::Window, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
117 QColor bg = scheme.background(KColorScheme::LinkBackground).color();
118 QColor fg = scheme.foreground(KColorScheme::LinkText).color();
119 QString style = QString("QPushButton {padding:2px;background-color: rgb(%1, %2, %3);border-radius: 4px;border: none;color: rgb(%4, %5, %6)}").arg(bg.red()).arg(bg.green()).arg(bg.blue()).arg(fg.red()).arg(fg.green()).arg(fg.blue());
121 bg = scheme.background(KColorScheme::ActiveBackground).color();
122 fg = scheme.foreground(KColorScheme::ActiveText).color();
123 style.append(QString("\nQPushButton:hover {padding:2px;background-color: rgb(%1, %2, %3);border-radius: 4px;border: none;color: rgb(%4, %5, %6)}").arg(bg.red()).arg(bg.green()).arg(bg.blue()).arg(fg.red()).arg(fg.green()).arg(fg.blue()));
128 void SmallInfoLabel::slotTimeLineChanged(qreal value)
130 setFixedWidth(qMin(value * 2, qreal(1.0)) * sizeHint().width());
134 void SmallInfoLabel::slotTimeLineFinished()
136 if (m_timeLine->direction() == QTimeLine::Forward) {
146 void SmallInfoLabel::slotSetJobCount(int jobCount)
150 setText(i18np("%1 job", "%1 jobs", jobCount));
151 setToolTip(i18np("%1 pending job", "%1 pending jobs", jobCount));
153 if (!(KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects)) {
154 setFixedWidth(sizeHint().width());
160 setFixedWidth(sizeHint().width());
167 int wantedWidth = sizeHint().width();
168 setGeometry(-wantedWidth, 0, wantedWidth, height());
169 m_timeLine->setDirection(QTimeLine::Forward);
170 if (m_timeLine->state() == QTimeLine::NotRunning) {
175 if (!(KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects)) {
181 m_timeLine->setDirection(QTimeLine::Backward);
182 if (m_timeLine->state() == QTimeLine::NotRunning) {
189 ProjectList::ProjectList(QGLWidget *glContext, QWidget *parent) :
194 , m_commandStack(NULL)
196 , m_reloadAction(NULL)
197 , m_extractAudioAction(NULL)
198 , m_transcodeAction(NULL)
199 , m_clipsActionsMenu(NULL)
202 , m_allClipsProcessed(false)
204 , m_proxyAction(NULL)
205 , m_abortAllJobs(false)
207 , m_invalidClipDialog(NULL)
208 , m_mainGLContext(glContext)
210 qRegisterMetaType<stringMap> ("stringMap");
211 QVBoxLayout *layout = new QVBoxLayout;
212 layout->setContentsMargins(0, 0, 0, 0);
213 layout->setSpacing(0);
214 qRegisterMetaType<QDomElement>("QDomElement");
216 QFrame *frame = new QFrame;
217 frame->setFrameStyle(QFrame::NoFrame);
218 QHBoxLayout *box = new QHBoxLayout;
219 box->setContentsMargins(0, 0, 0, 0);
221 KTreeWidgetSearchLine *searchView = new KTreeWidgetSearchLine;
222 box->addWidget(searchView);
224 // small info button for pending jobs
225 m_infoLabel = new SmallInfoLabel(this);
226 m_infoLabel->setStyleSheet(SmallInfoLabel::getStyleSheet(palette()));
227 connect(this, SIGNAL(jobCount(int)), m_infoLabel, SLOT(slotSetJobCount(int)));
228 m_jobsMenu = new QMenu(this);
229 connect(m_jobsMenu, SIGNAL(aboutToShow()), this, SLOT(slotPrepareJobsMenu()));
230 QAction *cancelJobs = new QAction(i18n("Cancel All Jobs"), this);
231 cancelJobs->setCheckable(false);
232 connect(cancelJobs, SIGNAL(triggered()), this, SLOT(slotCancelJobs()));
233 connect(this, SIGNAL(checkJobProcess()), this, SLOT(slotCheckJobProcess()));
234 m_discardCurrentClipJobs = new QAction(i18n("Cancel Current Clip Jobs"), this);
235 m_discardCurrentClipJobs->setCheckable(false);
236 connect(m_discardCurrentClipJobs, SIGNAL(triggered()), this, SLOT(slotDiscardClipJobs()));
237 m_jobsMenu->addAction(cancelJobs);
238 m_jobsMenu->addAction(m_discardCurrentClipJobs);
239 m_infoLabel->setMenu(m_jobsMenu);
240 box->addWidget(m_infoLabel);
242 int size = style()->pixelMetric(QStyle::PM_SmallIconSize);
243 QSize iconSize(size, size);
245 m_addButton = new QToolButton;
246 m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
247 m_addButton->setAutoRaise(true);
248 m_addButton->setIconSize(iconSize);
249 box->addWidget(m_addButton);
251 m_editButton = new QToolButton;
252 m_editButton->setAutoRaise(true);
253 m_editButton->setIconSize(iconSize);
254 box->addWidget(m_editButton);
256 m_deleteButton = new QToolButton;
257 m_deleteButton->setAutoRaise(true);
258 m_deleteButton->setIconSize(iconSize);
259 box->addWidget(m_deleteButton);
260 frame->setLayout(box);
261 layout->addWidget(frame);
263 m_listView = new ProjectListView(this);
264 layout->addWidget(m_listView);
266 #if KDE_IS_VERSION(4,7,0)
267 m_infoMessage = new MyMessageWidget;
268 layout->addWidget(m_infoMessage);
269 m_infoMessage->setCloseButtonVisible(true);
270 connect(m_infoMessage, SIGNAL(messageClosing()), this, SLOT(slotResetInfoMessage()));
271 //m_infoMessage->setWordWrap(true);
272 m_infoMessage->hide();
273 m_logAction = new QAction(i18n("Show Log"), this);
274 m_logAction->setCheckable(false);
275 connect(m_logAction, SIGNAL(triggered()), this, SLOT(slotShowJobLog()));
279 searchView->setTreeWidget(m_listView);
281 connect(this, SIGNAL(processNextThumbnail()), this, SLOT(slotProcessNextThumbnail()));
282 connect(m_listView, SIGNAL(projectModified()), this, SIGNAL(projectModified()));
283 connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
284 connect(m_listView, SIGNAL(focusMonitor(bool)), this, SIGNAL(raiseClipMonitor(bool)));
285 connect(m_listView, SIGNAL(pauseMonitor()), this, SIGNAL(pauseMonitor()));
286 connect(m_listView, SIGNAL(requestMenu(QPoint,QTreeWidgetItem*)), this, SLOT(slotContextMenu(QPoint,QTreeWidgetItem*)));
287 connect(m_listView, SIGNAL(addClip()), this, SIGNAL(pauseMonitor()));
288 connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
289 connect(m_listView, SIGNAL(addClip(QList<QUrl>,QString,QString)), this, SLOT(slotAddClip(QList<QUrl>,QString,QString)));
290 connect(this, SIGNAL(addClip(QString,QString,QString)), this, SLOT(slotAddClip(QString,QString,QString)));
291 connect(m_listView, SIGNAL(addClipCut(QString,int,int)), this, SLOT(slotAddClipCut(QString,int,int)));
292 connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(slotItemEdited(QTreeWidgetItem*,int)));
293 connect(m_listView, SIGNAL(showProperties(DocClipBase*)), this, SIGNAL(showClipProperties(DocClipBase*)));
295 connect(this, SIGNAL(cancelRunningJob(QString,stringMap)), this, SLOT(slotCancelRunningJob(QString,stringMap)));
296 connect(this, SIGNAL(processLog(QString,int,int,QString)), this, SLOT(slotProcessLog(QString,int,int,QString)));
298 connect(this, SIGNAL(updateJobStatus(QString,int,int,QString,QString,QString)), this, SLOT(slotUpdateJobStatus(QString,int,int,QString,QString,QString)));
300 connect(this, SIGNAL(gotProxy(QString)), this, SLOT(slotGotProxyForId(QString)));
302 m_listViewDelegate = new ItemDelegate(m_listView);
303 m_listView->setItemDelegate(m_listViewDelegate);
305 if (KdenliveSettings::activate_nepomuk()) {
306 Nepomuk::ResourceManager::instance()->init();
307 if (!Nepomuk::ResourceManager::instance()->initialized()) {
308 kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
309 KdenliveSettings::setActivate_nepomuk(false);
313 #ifdef USE_NEPOMUKCORE
314 if (KdenliveSettings::activate_nepomuk()) {
315 Nepomuk2::ResourceManager::instance()->init();
316 if (!Nepomuk2::ResourceManager::instance()->initialized()) {
317 kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
318 KdenliveSettings::setActivate_nepomuk(false);
325 ProjectList::~ProjectList()
327 m_abortAllJobs = true;
328 for (int i = 0; i < m_jobList.count(); ++i) {
329 m_jobList.at(i)->setStatus(JobAborted);
332 m_thumbnailQueue.clear();
333 m_jobThreads.waitForFinished();
334 m_jobThreads.clearFutures();
335 if (!m_jobList.isEmpty()) qDeleteAll(m_jobList);
337 if (m_menu) delete m_menu;
338 m_listView->blockSignals(true);
340 delete m_listViewDelegate;
341 #if KDE_IS_VERSION(4,7,0)
342 delete m_infoMessage;
346 void ProjectList::focusTree() const
348 m_listView->setFocus();
351 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
353 QList <QAction *> actions = addMenu->actions();
354 for (int i = 0; i < actions.count(); ++i) {
355 if (actions.at(i)->data().toString() == "clip_properties") {
356 m_editButton->setDefaultAction(actions.at(i));
359 } else if (actions.at(i)->data().toString() == "delete_clip") {
360 m_deleteButton->setDefaultAction(actions.at(i));
363 } else if (actions.at(i)->data().toString() == "edit_clip") {
364 m_openAction = actions.at(i);
367 } else if (actions.at(i)->data().toString() == "reload_clip") {
368 m_reloadAction = actions.at(i);
371 } else if (actions.at(i)->data().toString() == "proxy_clip") {
372 m_proxyAction = actions.at(i);
378 QMenu *m = new QMenu();
379 m->addActions(actions);
380 m_addButton->setMenu(m);
381 m_addButton->setDefaultAction(defaultAction);
382 m_menu = new QMenu();
383 m_menu->addActions(addMenu->actions());
386 void ProjectList::setupGeneratorMenu(const QHash<QString,QMenu*>& menus)
389 kDebug()<<"Warning, menu was not created, something is wrong";
392 if (!menus.contains("addMenu") && ! menus.value("addMenu") )
394 QMenu *menu = m_addButton->menu();
395 if (menus.contains("addMenu") && menus.value("addMenu")){
396 QMenu* addMenu=menus.value("addMenu");
397 menu->addMenu(addMenu);
398 m_addButton->setMenu(menu);
399 if (addMenu->isEmpty())
400 addMenu->setEnabled(false);
402 if (menus.contains("extractAudioMenu") && menus.value("extractAudioMenu") ){
403 QMenu* extractAudioMenu = menus.value("extractAudioMenu");
404 m_menu->addMenu(extractAudioMenu);
405 m_extractAudioAction = extractAudioMenu;
407 if (menus.contains("transcodeMenu") && menus.value("transcodeMenu") ){
408 QMenu* transcodeMenu = menus.value("transcodeMenu");
409 m_menu->addMenu(transcodeMenu);
410 if (transcodeMenu->isEmpty())
411 transcodeMenu->setEnabled(false);
412 m_transcodeAction = transcodeMenu;
414 if (menus.contains("clipActionsMenu") && menus.value("clipActionsMenu") ){
415 QMenu* stabilizeMenu=menus.value("clipActionsMenu");
416 m_menu->addMenu(stabilizeMenu);
417 if (stabilizeMenu->isEmpty())
418 stabilizeMenu->setEnabled(false);
419 m_clipsActionsMenu = stabilizeMenu;
422 if (m_reloadAction) m_menu->addAction(m_reloadAction);
423 if (m_proxyAction) m_menu->addAction(m_proxyAction);
424 if (menus.contains("inTimelineMenu") && menus.value("inTimelineMenu")){
425 QMenu* inTimelineMenu=menus.value("inTimelineMenu");
426 m_menu->addMenu(inTimelineMenu);
427 inTimelineMenu->setEnabled(false);
429 m_menu->addAction(m_editButton->defaultAction());
430 m_menu->addAction(m_openAction);
431 m_menu->addAction(m_deleteButton->defaultAction());
432 m_menu->insertSeparator(m_deleteButton->defaultAction());
435 void ProjectList::clearSelection()
437 m_listView->clearSelection();
440 QByteArray ProjectList::headerInfo() const
442 return m_listView->header()->saveState();
445 void ProjectList::setHeaderInfo(const QByteArray &state)
447 m_listView->header()->restoreState(state);
450 void ProjectList::updateProjectFormat(Timecode t)
455 void ProjectList::slotEditClip()
457 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
458 if (list.isEmpty()) return;
459 if (list.count() > 1 || list.at(0)->type() == ProjectFoldeType) {
460 editClipSelection(list);
464 if (!m_listView->currentItem() || m_listView->currentItem()->type() == ProjectFoldeType)
466 if (m_listView->currentItem()->type() == ProjectSubclipType)
467 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
469 item = static_cast <ProjectItem*>(m_listView->currentItem());
470 if (item && (item->flags() & Qt::ItemIsDragEnabled)) {
471 emit clipSelected(item->referencedClip());
472 emit showClipProperties(item->referencedClip());
476 void ProjectList::editClipSelection(QList<QTreeWidgetItem *> list)
478 // Gather all common properties
479 QMap <QString, QString> commonproperties;
480 QList <DocClipBase *> clipList;
481 commonproperties.insert("force_aspect_num", "-");
482 commonproperties.insert("force_aspect_den", "-");
483 commonproperties.insert("force_fps", "-");
484 commonproperties.insert("force_progressive", "-");
485 commonproperties.insert("force_tff", "-");
486 commonproperties.insert("threads", "-");
487 commonproperties.insert("video_index", "-");
488 commonproperties.insert("audio_index", "-");
489 commonproperties.insert("force_colorspace", "-");
490 commonproperties.insert("full_luma", "-");
491 QString transparency = "-";
493 bool allowDurationChange = true;
494 int commonDuration = -1;
495 bool hasImages = false;;
497 for (int i = 0; i < list.count(); ++i) {
499 if (list.at(i)->type() == ProjectFoldeType) {
500 // Add folder items to the list
501 int ct = list.at(i)->childCount();
502 for (int j = 0; j < ct; j++) {
503 list.append(list.at(i)->child(j));
507 else if (list.at(i)->type() == ProjectSubclipType)
508 item = static_cast <ProjectItem*>(list.at(i)->parent());
510 item = static_cast <ProjectItem*>(list.at(i));
511 if (!(item->flags() & Qt::ItemIsDragEnabled))
515 DocClipBase *clip = item->referencedClip();
516 if (clipList.contains(clip)) continue;
517 if (clip->clipType() == Image) {
519 if (clip->getProperty("transparency").isEmpty() || clip->getProperty("transparency").toInt() == 0) {
520 if (transparency == "-") {
521 // first non transparent image
524 else if (transparency == "1") {
525 // we have transparent and non transparent clips
530 if (transparency == "-") {
531 // first transparent image
534 else if (transparency == "0") {
535 // we have transparent and non transparent clips
540 if (clip->clipType() != Color && clip->clipType() != Image && clip->clipType() != Text)
541 allowDurationChange = false;
542 if (allowDurationChange && commonDuration != 0) {
543 if (commonDuration == -1)
544 commonDuration = clip->duration().frames(m_fps);
545 else if (commonDuration != clip->duration().frames(m_fps))
548 clipList.append(clip);
549 QMap <QString, QString> clipprops = clip->properties();
550 QMapIterator<QString, QString> p(commonproperties);
551 while (p.hasNext()) {
553 if (p.value().isEmpty()) continue;
554 if (clipprops.contains(p.key())) {
555 if (p.value() == "-")
556 commonproperties.insert(p.key(), clipprops.value(p.key()));
557 else if (p.value() != clipprops.value(p.key()))
558 commonproperties.insert(p.key(), QString());
560 commonproperties.insert(p.key(), QString());
565 if (allowDurationChange)
566 commonproperties.insert("out", QString::number(commonDuration));
568 commonproperties.insert("transparency", transparency);
569 /*QMapIterator<QString, QString> p(commonproperties);
570 while (p.hasNext()) {
572 kDebug() << "Result: " << p.key() << " = " << p.value();
574 if (clipList.isEmpty()) {
575 emit displayMessage(i18n("No available clip selected"), -2, ErrorMessage);
577 else emit showClipProperties(clipList, commonproperties);
580 void ProjectList::slotOpenClip()
583 if (!m_listView->currentItem() || m_listView->currentItem()->type() == ProjectFoldeType)
585 if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1)
586 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
588 item = static_cast <ProjectItem*>(m_listView->currentItem());
590 if (item->clipType() == Image) {
591 if (KdenliveSettings::defaultimageapp().isEmpty())
592 KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open images in the Settings dialog"));
594 QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
596 if (item->clipType() == Audio) {
597 if (KdenliveSettings::defaultaudioapp().isEmpty())
598 KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open audio files in the Settings dialog"));
600 QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
605 void ProjectList::cleanup()
607 m_listView->clearSelection();
608 QTreeWidgetItemIterator it(m_listView);
611 if ((*it)->type() != ProjectClipType) {
615 item = static_cast <ProjectItem *>(*it);
616 if (item->numReferences() == 0)
617 item->setSelected(true);
623 void ProjectList::trashUnusedClips()
625 QTreeWidgetItemIterator it(m_listView);
630 if ((*it)->type() != ProjectClipType) {
634 item = static_cast <ProjectItem *>(*it);
635 if (item->numReferences() == 0) {
636 ids << item->clipId();
637 KUrl url = item->clipUrl();
638 if (!url.isEmpty() && !urls.contains(url.path()))
644 // Check that we don't use the URL in another clip
645 QTreeWidgetItemIterator it2(m_listView);
647 if ((*it2)->type() != ProjectClipType) {
651 item = static_cast <ProjectItem *>(*it2);
652 if (item->numReferences() > 0) {
653 KUrl url = item->clipUrl();
654 if (!url.isEmpty() && urls.contains(url.path())) urls.removeAll(url.path());
659 emit deleteProjectClips(ids, QMap <QString, QString>());
660 for (int i = 0; i < urls.count(); ++i)
661 KIO::NetAccess::del(KUrl(urls.at(i)), this);
664 void ProjectList::slotReloadClip(const QString &id)
666 QList<QTreeWidgetItem *> selected;
668 selected = m_listView->selectedItems();
670 ProjectItem *itemToReLoad = getItemById(id);
671 if (itemToReLoad) selected.append(itemToReLoad);
674 for (int i = 0; i < selected.count(); ++i) {
675 if (selected.at(i)->type() != ProjectClipType) {
676 if (selected.at(i)->type() == ProjectFoldeType) {
677 for (int j = 0; j < selected.at(i)->childCount(); j++)
678 selected.append(selected.at(i)->child(j));
682 item = static_cast <ProjectItem *>(selected.at(i));
683 if (item && !hasPendingJob(item, PROXYJOB)) {
684 DocClipBase *clip = item->referencedClip();
685 if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
686 kDebug()<<"//// TRYING TO RELOAD: "<<item->clipId()<<", but it is busy";
689 ClipType t = item->clipType();
691 if (clip && !clip->getProperty("xmltemplate").isEmpty())
692 regenerateTemplate(item);
693 } else if (t != Color && t != SlideShow && clip && clip->checkHash() == false) {
694 item->referencedClip()->setPlaceHolder(true);
695 item->setProperty("file_hash", QString());
696 } else if (t == Image) {
697 //clip->getProducer() clip->getProducer()->set("force_reload", 1);
700 QDomElement e = item->toXml();
701 // Make sure we get the correct producer length if it was adjusted in timeline
702 if (t == Color || t == Image || t == SlideShow || t == Text) {
703 int length = QString(clip->producerProperty("length")).toInt();
704 if (length > 0 && !e.hasAttribute("length")) {
705 e.setAttribute("length", length);
707 e.setAttribute("duration", clip->getProperty("duration"));
709 resetThumbsProducer(clip);
710 m_render->getFileProperties(e, item->clipId(), m_listView->iconSize().height(), true);
715 void ProjectList::slotModifiedClip(const QString &id)
717 ProjectItem *item = getItemById(id);
719 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
720 if (!pixmap.isNull()) {
722 p.fillRect(0, 0, pixmap.width(), pixmap.height(), QColor(255, 255, 255, 200));
723 p.drawPixmap(0, 0, KIcon("view-refresh").pixmap(m_listView->iconSize()));
726 pixmap = KIcon("view-refresh").pixmap(m_listView->iconSize());
728 item->setPixmap(pixmap);
732 void ProjectList::slotMissingClip(const QString &id)
734 ProjectItem *item = getItemById(id);
736 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
737 int height = m_listView->iconSize().height();
738 if (m_render == NULL) {
739 kDebug() << "********* ERROR, NULL RENDR";
742 int width = (int)(height * m_render->dar());
743 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
744 if (pixmap.isNull()) {
745 pixmap = QPixmap(width, height);
746 pixmap.fill(Qt::transparent);
748 KIcon icon("dialog-close");
750 p.drawPixmap(3, 3, icon.pixmap(width - 6, height - 6));
752 item->setPixmap(pixmap);
753 if (item->referencedClip()) {
754 item->referencedClip()->setPlaceHolder(true);
755 Mlt::Producer *newProd = m_render->invalidProducer(id);
756 if (item->referencedClip()->getProducer()) {
757 Mlt::Properties props(newProd->get_properties());
758 Mlt::Properties src_props(item->referencedClip()->getProducer()->get_properties());
759 props.inherit(src_props);
761 item->referencedClip()->setProducer(newProd, true);
762 item->slotSetToolTip();
763 emit clipNeedsReload(id);
767 emit displayMessage(i18n("Check missing clips"), -2, ErrorMessage);
768 emit updateRenderStatus();
771 void ProjectList::slotAvailableClip(const QString &id)
773 ProjectItem *item = getItemById(id);
776 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
777 if (item->referencedClip()) { // && item->referencedClip()->checkHash() == false) {
778 item->setProperty("file_hash", QString());
782 item->referencedClip()->setValid();
783 item->slotSetToolTip();
786 emit updateRenderStatus();
789 bool ProjectList::hasMissingClips()
791 bool missing = false;
792 QTreeWidgetItemIterator it(m_listView);
794 if ((*it)->type() == ProjectClipType && !((*it)->flags() & Qt::ItemIsDragEnabled)) {
803 void ProjectList::setRenderer(Render *projectRender)
805 m_render = projectRender;
806 m_listView->setIconSize(QSize((ProjectItem::itemDefaultHeight() - 2) * m_render->dar(), ProjectItem::itemDefaultHeight() - 2));
807 connect(m_render, SIGNAL(requestProxy(QString)), this, SLOT(slotCreateProxy(QString)));
810 void ProjectList::slotClipSelected()
812 QTreeWidgetItem *item = m_listView->currentItem();
813 ProjectItem *clip = NULL;
815 if (item->type() == ProjectFoldeType) {
816 emit clipSelected(NULL);
817 m_editButton->defaultAction()->setEnabled(item->childCount() > 0);
818 m_deleteButton->defaultAction()->setEnabled(true);
819 m_openAction->setEnabled(false);
820 m_reloadAction->setEnabled(false);
821 m_extractAudioAction->setEnabled(false);
822 m_transcodeAction->setEnabled(false);
823 m_clipsActionsMenu->setEnabled(false);
825 if (item->type() == ProjectSubclipType) {
826 // this is a sub item, use base clip
827 m_deleteButton->defaultAction()->setEnabled(true);
828 clip = static_cast <ProjectItem*>(item->parent());
830 kDebug() << "-----------ERROR";
833 SubProjectItem *sub = static_cast <SubProjectItem*>(item);
834 if (clip->referencedClip()->getProducer() == NULL) m_render->getFileProperties(clip->referencedClip()->toXML(), clip->clipId(), m_listView->iconSize().height(), true);
835 emit clipSelected(clip->referencedClip(), sub->zone());
836 m_extractAudioAction->setEnabled(false);
837 m_transcodeAction->setEnabled(false);
838 m_clipsActionsMenu->setEnabled(false);
839 m_reloadAction->setEnabled(false);
840 adjustProxyActions(clip);
843 clip = static_cast <ProjectItem*>(item);
844 if (clip && clip->referencedClip())
845 emit clipSelected(clip->referencedClip());
846 if (clip->referencedClip()->getProducer() == NULL) m_render->getFileProperties(clip->referencedClip()->toXML(), clip->clipId(), m_listView->iconSize().height(), true);
847 m_editButton->defaultAction()->setEnabled(true);
848 m_deleteButton->defaultAction()->setEnabled(true);
849 m_reloadAction->setEnabled(true);
850 m_extractAudioAction->setEnabled(true);
851 m_transcodeAction->setEnabled(true);
852 m_clipsActionsMenu->setEnabled(true);
853 if (clip && clip->clipType() == Image && !KdenliveSettings::defaultimageapp().isEmpty()) {
854 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
855 m_openAction->setEnabled(true);
856 } else if (clip && clip->clipType() == Audio && !KdenliveSettings::defaultaudioapp().isEmpty()) {
857 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
858 m_openAction->setEnabled(true);
860 m_openAction->setEnabled(false);
862 // Display relevant transcoding actions only
863 adjustTranscodeActions(clip);
864 adjustStabilizeActions(clip);
865 // Display uses in timeline
866 emit findInTimeline(clip->clipId());
869 emit clipSelected(NULL);
870 m_editButton->defaultAction()->setEnabled(false);
871 m_deleteButton->defaultAction()->setEnabled(false);
872 m_openAction->setEnabled(false);
873 m_reloadAction->setEnabled(false);
874 m_extractAudioAction->setEnabled(true);
875 m_transcodeAction->setEnabled(false);
876 m_clipsActionsMenu->setEnabled(false);
878 adjustProxyActions(clip);
881 void ProjectList::adjustProxyActions(ProjectItem *clip) const
883 if (!m_proxyAction) return;
884 if (clip == NULL || clip->type() != ProjectClipType || clip->clipType() == Color || clip->clipType() == Text || clip->clipType() == SlideShow || clip->clipType() == Audio) {
885 m_proxyAction->setEnabled(false);
888 bool enabled = useProxy();
889 if (clip->referencedClip() && !clip->referencedClip()->getProperty("_missingsource").isEmpty()) enabled = false;
890 m_proxyAction->setEnabled(enabled);
891 m_proxyAction->blockSignals(true);
892 m_proxyAction->setChecked(clip->hasProxy());
893 m_proxyAction->blockSignals(false);
896 void ProjectList::adjustStabilizeActions(ProjectItem *clip) const
899 if (clip == NULL || clip->type() != ProjectClipType || clip->clipType() == Color || clip->clipType() == Text || clip->clipType() == SlideShow) {
900 m_clipsActionsMenu->setEnabled(false);
903 m_clipsActionsMenu->setEnabled(true);
907 void ProjectList::adjustTranscodeActions(ProjectItem *clip) const
909 if (clip == NULL || clip->type() != ProjectClipType || clip->clipType() == Color || clip->clipType() == Text || clip->clipType() == Playlist || clip->clipType() == SlideShow) {
910 m_transcodeAction->setEnabled(false);
911 m_extractAudioAction->setEnabled(false);
914 m_transcodeAction->setEnabled(true);
915 m_extractAudioAction->setEnabled(true);
916 QList<QAction *> transcodeActions = m_transcodeAction->actions();
919 for (int i = 0; i < transcodeActions.count(); ++i) {
920 data = transcodeActions.at(i)->data().toStringList();
921 if (data.count() > 2) {
922 condition = data.at(2);
923 if (condition.startsWith("vcodec"))
924 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
925 else if (condition.startsWith("acodec"))
926 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
932 void ProjectList::slotPauseMonitor()
938 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
940 ProjectItem *item = getItemById(id);
942 slotUpdateClipProperties(item, properties);
943 if (properties.contains("out") || properties.contains("force_fps") || properties.contains("resource") || properties.contains("video_index") || properties.contains("audio_index") || properties.contains("full_luma") || properties.contains("force_progressive") || properties.contains("force_tff") || properties.contains("force_colorspace")) {
945 } else if (properties.contains("colour") ||
946 properties.contains("xmldata") ||
947 properties.contains("force_aspect_num") ||
948 properties.contains("force_aspect_den") ||
949 properties.contains("templatetext")) {
950 slotRefreshClipThumbnail(item);
951 emit refreshClip(id, true);
952 } else if (properties.contains("loop")) {
953 emit refreshClip(id, false);
958 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
962 clip->setProperties(properties);
963 if (properties.contains("proxy")) {
964 if (properties.value("proxy") == "-" || properties.value("proxy").isEmpty())
965 // this should only apply to proxy jobs
966 clip->setConditionalJobStatus(NoJob, PROXYJOB);
968 if (properties.contains("name")) {
969 monitorItemEditing(false);
970 clip->setText(0, properties.value("name"));
971 monitorItemEditing(true);
972 emit clipNameChanged(clip->clipId(), properties.value("name"));
974 if (properties.contains("description")) {
976 ClipType type = clip->clipType();
978 monitorItemEditing(false);
979 clip->setText(1, properties.value("description"));
980 monitorItemEditing(true);
983 bool hasType = (type == Audio || type == Video || type == AV ||
984 type == Image || type == Playlist);
986 if (KdenliveSettings::activate_nepomuk() && hasType) {
987 // Use Nepomuk system to store clip description
988 Nepomuk::Resource f(clip->clipUrl().path());
989 f.setDescription(properties.value("description"));
992 emit projectModified();
996 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
998 if (item->type() == ProjectSubclipType) {
999 // this is a sub-item
1001 // user edited description
1002 SubProjectItem *sub = static_cast <SubProjectItem*>(item);
1003 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
1004 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), sub->zone(), sub->description(), sub->text(1), true);
1005 m_commandStack->push(command);
1006 //slotUpdateCutClipProperties(sub->clipId(), sub->zone(), sub->text(1), sub->text(1));
1010 if (item->type() == ProjectFoldeType) {
1012 FolderProjectItem *folder = static_cast <FolderProjectItem*>(item);
1013 if (item->text(0) == folder->groupName()) return;
1014 editFolder(item->text(0), folder->groupName(), folder->clipId());
1015 folder->setGroupName(item->text(0));
1016 m_doc->clipManager()->addFolder(folder->clipId(), item->text(0));
1017 const int children = item->childCount();
1018 for (int i = 0; i < children; ++i) {
1019 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
1020 child->setProperty("groupname", item->text(0));
1026 ProjectItem *clip = static_cast <ProjectItem*>(item);
1028 if (clip->referencedClip()) {
1029 QMap <QString, QString> oldprops;
1030 QMap <QString, QString> newprops;
1031 oldprops["description"] = clip->referencedClip()->getProperty("description");
1032 newprops["description"] = item->text(1);
1034 if (clip->clipType() == Text) {
1035 // This is a text template clip, update the image
1036 /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
1037 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/
1038 oldprops.insert("templatetext", clip->referencedClip()->getProperty("templatetext"));
1039 newprops.insert("templatetext", item->text(1));
1041 slotUpdateClipProperties(clip->clipId(), newprops);
1042 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
1043 m_commandStack->push(command);
1045 } else if (column == 0) {
1046 if (clip->referencedClip()) {
1047 QMap <QString, QString> oldprops;
1048 QMap <QString, QString> newprops;
1049 oldprops["name"] = clip->referencedClip()->getProperty("name");
1050 if (oldprops.value("name") != item->text(0)) {
1051 newprops["name"] = item->text(0);
1052 slotUpdateClipProperties(clip, newprops);
1053 emit projectModified();
1054 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
1055 m_commandStack->push(command);
1056 QTimer::singleShot(100, this, SLOT(slotCheckScrolling()));
1062 void ProjectList::slotCheckScrolling()
1064 m_listView->scrollToItem(m_listView->currentItem());
1067 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
1070 kDebug()<<"Warning, menu was not created, something is wrong";
1073 bool enable = item ? true : false;
1074 m_editButton->defaultAction()->setEnabled(enable);
1075 m_deleteButton->defaultAction()->setEnabled(enable);
1076 m_reloadAction->setEnabled(enable);
1077 m_extractAudioAction->setEnabled(enable);
1078 m_transcodeAction->setEnabled(enable);
1079 m_clipsActionsMenu->setEnabled(enable);
1081 ProjectItem *clip = NULL;
1082 if (m_listView->currentItem()->type() == ProjectSubclipType) {
1083 clip = static_cast <ProjectItem*>(item->parent());
1084 m_extractAudioAction->setEnabled(false);
1085 m_transcodeAction->setEnabled(false);
1086 m_clipsActionsMenu->setEnabled(false);
1087 adjustProxyActions(clip);
1088 } else if (m_listView->currentItem()->type() == ProjectClipType) {
1089 clip = static_cast <ProjectItem*>(item);
1090 // Display relevant transcoding actions only
1091 adjustTranscodeActions(clip);
1092 adjustStabilizeActions(clip);
1093 adjustProxyActions(clip);
1094 // Display uses in timeline
1095 emit findInTimeline(clip->clipId());
1097 m_extractAudioAction->setEnabled(false);
1098 m_transcodeAction->setEnabled(false);
1099 m_clipsActionsMenu->setEnabled(false);
1101 if (clip && clip->clipType() == Image && !KdenliveSettings::defaultimageapp().isEmpty()) {
1102 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
1103 m_openAction->setEnabled(true);
1104 } else if (clip && clip->clipType() == Audio && !KdenliveSettings::defaultaudioapp().isEmpty()) {
1105 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
1106 m_openAction->setEnabled(true);
1108 m_openAction->setEnabled(false);
1112 m_openAction->setEnabled(false);
1117 void ProjectList::slotRemoveClip()
1119 if (!m_listView->currentItem())
1122 QMap <QString, QString> folderids;
1123 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
1125 QUndoCommand *delCommand = new QUndoCommand();
1126 delCommand->setText(i18n("Delete Clip Zone"));
1127 for (int i = 0; i < selected.count(); ++i) {
1128 if (selected.at(i)->type() == ProjectSubclipType) {
1130 SubProjectItem *sub = static_cast <SubProjectItem *>(selected.at(i));
1131 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
1132 new AddClipCutCommand(this, item->clipId(), sub->zone().x(), sub->zone().y(), sub->description(), false, true, delCommand);
1133 } else if (selected.at(i)->type() == ProjectFoldeType) {
1135 FolderProjectItem *folder = static_cast <FolderProjectItem *>(selected.at(i));
1136 folderids[folder->groupName()] = folder->clipId();
1137 int children = folder->childCount();
1139 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)
1141 for (int i = 0; i < children; ++i) {
1142 ProjectItem *child = static_cast <ProjectItem *>(folder->child(i));
1143 ids << child->clipId();
1146 ProjectItem *item = static_cast <ProjectItem *>(selected.at(i));
1147 ids << item->clipId();
1148 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->text(1)), i18n("Delete Clip"), KStandardGuiItem::yes(), KStandardGuiItem::no(), "DeleteAll") == KMessageBox::No) {
1149 KMessageBox::enableMessage("DeleteAll");
1154 KMessageBox::enableMessage("DeleteAll");
1155 if (delCommand->childCount() == 0)
1158 m_commandStack->push(delCommand);
1159 emit deleteProjectClips(ids, folderids);
1162 void ProjectList::updateButtons() const
1164 if (m_listView->topLevelItemCount() == 0) {
1165 m_deleteButton->defaultAction()->setEnabled(false);
1166 m_editButton->defaultAction()->setEnabled(false);
1168 m_deleteButton->defaultAction()->setEnabled(true);
1169 if (!m_listView->currentItem())
1170 m_listView->setCurrentItem(m_listView->topLevelItem(0));
1171 QTreeWidgetItem *item = m_listView->currentItem();
1172 if (item && item->type() == ProjectClipType) {
1173 m_editButton->defaultAction()->setEnabled(true);
1174 m_openAction->setEnabled(true);
1175 m_reloadAction->setEnabled(true);
1176 m_transcodeAction->setEnabled(true);
1177 m_clipsActionsMenu->setEnabled(true);
1180 else if (item && item->type() == ProjectFoldeType && item->childCount() > 0) {
1181 m_editButton->defaultAction()->setEnabled(true);
1183 else m_editButton->defaultAction()->setEnabled(false);
1185 m_openAction->setEnabled(false);
1186 if (m_reloadAction) m_reloadAction->setEnabled(false);
1187 m_transcodeAction->setEnabled(false);
1188 m_clipsActionsMenu->setEnabled(false);
1189 if (m_proxyAction) m_proxyAction->setEnabled(false);
1192 void ProjectList::selectItemById(const QString &clipId)
1194 ProjectItem *item = getItemById(clipId);
1196 m_listView->setCurrentItem(item);
1200 void ProjectList::slotDeleteClip(const QString &clipId)
1202 ProjectItem *item = getItemById(clipId);
1204 kDebug() << "/// Cannot find clip to delete";
1207 deleteJobsForClip(clipId);
1208 m_listView->blockSignals(true);
1209 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
1210 if (!newSelectedItem)
1211 newSelectedItem = m_listView->itemBelow(item);
1213 // Pause playing to prevent crash while deleting clip
1215 m_doc->clipManager()->deleteClip(clipId);
1216 m_listView->blockSignals(false);
1217 if (newSelectedItem) {
1218 m_listView->setCurrentItem(newSelectedItem);
1221 emit clipSelected(NULL);
1226 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
1228 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
1229 m_commandStack->push(command);
1230 m_doc->setModified(true);
1233 void ProjectList::slotAddFolder(const QString &name)
1235 AddFolderCommand *command = new AddFolderCommand(this, name.isEmpty() ? i18n("Folder") : name, QString::number(m_doc->clipManager()->getFreeFolderId()), true);
1236 m_commandStack->push(command);
1239 void ProjectList::slotAddFolder(const QString &foldername, const QString &clipId, bool remove, bool edit)
1242 FolderProjectItem *item = getFolderItemById(clipId);
1244 m_doc->clipManager()->deleteFolder(clipId);
1245 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
1246 if (!newSelectedItem)
1247 newSelectedItem = m_listView->itemBelow(item);
1249 if (newSelectedItem)
1250 m_listView->setCurrentItem(newSelectedItem);
1256 FolderProjectItem *item = getFolderItemById(clipId);
1258 m_listView->blockSignals(true);
1259 item->setGroupName(foldername);
1260 m_listView->blockSignals(false);
1261 m_doc->clipManager()->addFolder(clipId, foldername);
1262 const int children = item->childCount();
1263 for (int i = 0; i < children; ++i) {
1264 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
1265 child->setProperty("groupname", foldername);
1269 m_listView->blockSignals(true);
1270 m_listView->setCurrentItem(new FolderProjectItem(m_listView, QStringList() << foldername, clipId));
1271 m_doc->clipManager()->addFolder(clipId, foldername);
1272 m_listView->blockSignals(false);
1273 m_listView->editItem(m_listView->currentItem(), 0);
1277 m_doc->setModified(true);
1282 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
1284 QMapIterator<QString, QString> i(map);
1285 QUndoCommand *delCommand = new QUndoCommand();
1286 delCommand->setText(i18n("Delete Folder"));
1287 while (i.hasNext()) {
1289 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
1291 if (delCommand->childCount() > 0) m_commandStack->push(delCommand);
1292 else delete delCommand;
1295 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
1297 //m_listView->setEnabled(false);
1298 const QString parent = clip->getProperty("groupid");
1299 QString groupName = clip->getProperty("groupname");
1300 QSize pixelSize((int)(m_listView->iconSize().height() * m_render->dar()), m_listView->iconSize().height());
1301 ProjectItem *item = NULL;
1302 monitorItemEditing(false);
1303 if (!parent.isEmpty()) {
1304 FolderProjectItem *parentitem = getFolderItemById(parent);
1307 //kDebug() << "Adding clip to new group: " << groupName;
1308 if (groupName.isEmpty()) groupName = i18n("Folder");
1310 parentitem = new FolderProjectItem(m_listView, text, parent);
1314 item = new ProjectItem(parentitem, clip, pixelSize);
1317 item = new ProjectItem(m_listView, clip, pixelSize);
1319 if (item->data(0, ItemDelegate::DurationRole).isNull()) item->setData(0, ItemDelegate::DurationRole, i18n("Loading"));
1320 connect(clip, SIGNAL(createProxy(QString)), this, SLOT(slotCreateProxy(QString)));
1321 connect(clip, SIGNAL(abortProxy(QString,QString)), this, SLOT(slotAbortProxy(QString,QString)));
1323 if (getProperties) {
1324 //item->setFlags(Qt::ItemIsSelectable);
1325 m_listView->processLayout();
1326 QDomElement e = clip->toXML().cloneNode().toElement();
1327 if (!groupName.isEmpty()) {
1328 e.setAttribute("groupId", parent);
1329 e.setAttribute("group", groupName);
1331 e.removeAttribute("file_hash");
1332 resetThumbsProducer(clip);
1333 m_render->getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true);
1335 // WARNING: code below triggers unnecessary reload of all proxy clips on document loading... is it useful in some cases?
1336 /*else if (item->hasProxy() && !item->isJobRunning()) {
1337 slotCreateProxy(clip->getId());
1340 KUrl url = clip->fileURL();
1342 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk() && clip->getProperty("description").isEmpty()) {
1343 // if file has Nepomuk comment, use it
1344 Nepomuk::Resource f(url.path());
1345 QString annotation = f.description();
1346 if (!annotation.isEmpty()) {
1347 item->setText(1, annotation);
1348 clip->setProperty("description", annotation);
1350 item->setText(2, QString::number(f.rating()));
1354 // Add info to date column
1355 QFileInfo fileInfo(url.path());
1356 if (fileInfo.exists()) {
1357 item->setText(3, fileInfo.lastModified().toString(QString("yyyy/MM/dd hh:mm:ss")));
1361 QList <CutZoneInfo> cuts = clip->cutZones();
1362 if (!cuts.isEmpty()) {
1363 for (int i = 0; i < cuts.count(); ++i) {
1364 SubProjectItem *sub = new SubProjectItem(m_render->dar(), item, cuts.at(i).zone.x(), cuts.at(i).zone.y(), cuts.at(i).description);
1365 if (!clip->getClipHash().isEmpty()) {
1366 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(cuts.at(i).zone.x()) + ".png";
1367 if (QFile::exists(cachedPixmap)) {
1368 QPixmap pix(cachedPixmap);
1370 KIO::NetAccess::del(KUrl(cachedPixmap), this);
1371 sub->setData(0, Qt::DecorationRole, pix);
1376 monitorItemEditing(true);
1380 void ProjectList::slotGotProxy(const QString &proxyPath)
1382 if (proxyPath.isEmpty() || m_abortAllJobs) return;
1383 QTreeWidgetItemIterator it(m_listView);
1386 while (*it && !m_closing) {
1387 if ((*it)->type() == ProjectClipType) {
1388 item = static_cast <ProjectItem *>(*it);
1389 if (item->referencedClip()->getProperty("proxy") == proxyPath)
1396 void ProjectList::slotGotProxyForId(const QString id)
1398 if (m_closing) return;
1399 ProjectItem *item = getItemById(id);
1403 void ProjectList::slotGotProxy(ProjectItem *item)
1405 if (item == NULL) return;
1406 DocClipBase *clip = item->referencedClip();
1407 if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
1408 // Clip is being reprocessed, abort
1409 kDebug()<<"//// TRYING TO PROXY: "<<item->clipId()<<", but it is busy";
1413 // Proxy clip successfully created
1414 QDomElement e = clip->toXML().cloneNode().toElement();
1416 // Make sure we get the correct producer length if it was adjusted in timeline
1417 ClipType t = item->clipType();
1418 if (t == Color || t == Image || t == SlideShow || t == Text) {
1419 int length = QString(clip->producerProperty("length")).toInt();
1420 if (length > 0 && !e.hasAttribute("length")) {
1421 e.setAttribute("length", length);
1424 resetThumbsProducer(clip);
1425 m_render->getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true);
1428 void ProjectList::slotResetProjectList()
1430 m_listView->blockSignals(true);
1431 m_abortAllJobs = true;
1432 for (int i = 0; i < m_jobList.count(); ++i) {
1433 m_jobList.at(i)->setStatus(JobAborted);
1436 m_jobThreads.waitForFinished();
1437 m_jobThreads.clearFutures();
1438 m_thumbnailQueue.clear();
1439 if (!m_jobList.isEmpty()) qDeleteAll(m_jobList);
1441 m_listView->clear();
1442 m_listView->setEnabled(true);
1443 emit clipSelected(NULL);
1444 m_refreshed = false;
1445 m_allClipsProcessed = false;
1446 m_abortAllJobs = false;
1448 m_listView->blockSignals(false);
1451 void ProjectList::slotUpdateClip(const QString &id)
1453 ProjectItem *item = getItemById(id);
1454 monitorItemEditing(false);
1456 item->setData(0, ItemDelegate::UsageRole, QString::number(item->numReferences()));
1458 monitorItemEditing(true);
1461 void ProjectList::getCachedThumbnail(ProjectItem *item)
1464 DocClipBase *clip = item->referencedClip();
1468 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
1469 if (QFile::exists(cachedPixmap)) {
1470 QPixmap pix(cachedPixmap);
1472 KIO::NetAccess::del(KUrl(cachedPixmap), this);
1473 requestClipThumbnail(item->clipId());
1476 QPixmap result = roundedPixmap(pix);
1477 processThumbOverlays(item, result);
1478 item->setPixmap(result);
1482 requestClipThumbnail(item->clipId());
1486 QPixmap ProjectList::roundedPixmap(const QImage &img)
1488 QPixmap pix(img.width(), img.height());
1489 pix.fill(Qt::transparent);
1491 p.setRenderHint(QPainter::Antialiasing, true);
1493 path.addRoundedRect(0.5, 0.5, pix.width() - 1, pix.height() - 1, 2, 2);
1494 p.setClipPath(path);
1495 p.drawImage(0, 0, img);
1500 QPixmap ProjectList::roundedPixmap(const QPixmap &source)
1502 QPixmap pix(source.width(), source.height());
1503 pix.fill(Qt::transparent);
1505 p.setRenderHint(QPainter::Antialiasing, true);
1507 path.addRoundedRect(0.5, 0.5, pix.width() - 1, pix.height() - 1, 2, 2);
1508 p.setClipPath(path);
1509 p.drawPixmap(0, 0, source);
1514 void ProjectList::getCachedThumbnail(SubProjectItem *item)
1517 ProjectItem *parentItem = static_cast <ProjectItem *>(item->parent());
1518 if (!parentItem) return;
1519 DocClipBase *clip = parentItem->referencedClip();
1521 int pos = item->zone().x();
1522 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(pos) + ".png";
1523 if (QFile::exists(cachedPixmap)) {
1524 QPixmap pix(cachedPixmap);
1526 KIO::NetAccess::del(KUrl(cachedPixmap), this);
1527 requestClipThumbnail(parentItem->clipId() + '#' + QString::number(pos));
1529 else item->setData(0, Qt::DecorationRole, pix);
1531 else requestClipThumbnail(parentItem->clipId() + '#' + QString::number(pos));
1534 void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged, const QStringList &brokenClips)
1536 // We are in a new thread, so we need a new OpenGL context for the remainder of the function.
1537 QGLWidget ctx(0, m_mainGLContext);
1540 if (!m_allClipsProcessed) m_listView->setEnabled(false);
1541 m_listView->setSortingEnabled(false);
1542 QTreeWidgetItemIterator it(m_listView);
1545 monitorItemEditing(false);
1546 int height = m_listView->iconSize().height();
1547 int width = (int)(height * m_render->dar());
1548 QPixmap missingPixmap = QPixmap(width, height);
1549 missingPixmap.fill(Qt::transparent);
1550 KIcon icon("dialog-close");
1551 QPainter p(&missingPixmap);
1552 p.drawPixmap(3, 3, icon.pixmap(width - 6, height - 6));
1555 int max = m_doc->clipManager()->clipsCount();
1560 emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - ct++) / max));
1561 if ((*it)->type() == ProjectSubclipType) {
1563 SubProjectItem *sub = static_cast <SubProjectItem *>(*it);
1564 if (displayRatioChanged) {
1565 item = static_cast <ProjectItem *>((*it)->parent());
1566 requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x()));
1568 else if (sub->data(0, Qt::DecorationRole).isNull()) {
1569 getCachedThumbnail(sub);
1573 } else if ((*it)->type() == ProjectFoldeType) {
1578 item = static_cast <ProjectItem *>(*it);
1579 clip = item->referencedClip();
1580 if (clip->getProducer() == NULL) {
1581 bool replace = false;
1582 if (brokenClips.contains(item->clipId())) {
1583 // if this is a proxy clip, disable proxy
1584 item->setConditionalJobStatus(NoJob, PROXYJOB);
1585 discardJobs(item->clipId(), PROXYJOB);
1586 clip->setProperty("proxy", "-");
1589 if (clip->isPlaceHolder() == false && !hasPendingJob(item, PROXYJOB)) {
1590 QDomElement xml = clip->toXML();
1591 getCachedThumbnail(item);
1593 xml.removeAttribute("out");
1594 xml.removeAttribute("file_hash");
1595 xml.removeAttribute("proxy_out");
1597 if (!replace) replace = xml.attribute("_replaceproxy") == "1";
1598 xml.removeAttribute("_replaceproxy");
1600 resetThumbsProducer(clip);
1601 m_render->getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), replace);
1603 else if (item->numReferences() > 0) {
1604 // In some cases, like slowmotion clips, the producer is not loaded automatically be MLT
1605 m_render->getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), replace);
1608 else if (clip->isPlaceHolder()) {
1609 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
1610 if (!item->hasPixmap()) {
1611 item->setPixmap(missingPixmap);
1614 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
1615 QPainter p(&pixmap);
1616 p.drawPixmap(3, 3, KIcon("dialog-close").pixmap(pixmap.width() - 6, pixmap.height() - 6));
1618 item->setPixmap(pixmap);
1622 if (displayRatioChanged) {
1623 requestClipThumbnail(clip->getId());
1625 else if (!item->hasPixmap()) {
1626 getCachedThumbnail(item);
1628 if (item->data(0, ItemDelegate::DurationRole).toString().isEmpty()) {
1629 item->changeDuration(clip->getProducer()->get_playtime());
1631 if (clip->isPlaceHolder()) {
1632 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
1633 if (pixmap.isNull()) {
1634 pixmap = QPixmap(width, height);
1635 pixmap.fill(Qt::transparent);
1637 QPainter p(&pixmap);
1638 p.drawPixmap(3, 3, KIcon("dialog-close").pixmap(pixmap.width() - 6, pixmap.height() - 6));
1640 item->setPixmap(pixmap);
1642 else if (clip->getProperty("_replaceproxy") == "1") {
1643 clip->setProperty("_replaceproxy", QString());
1644 slotCreateProxy(clip->getId());
1647 item->setData(0, ItemDelegate::UsageRole, QString::number(item->numReferences()));
1652 m_listView->setSortingEnabled(true);
1653 m_allClipsProcessed = true;
1654 if (m_render->processingItems() == 0) {
1655 monitorItemEditing(true);
1656 slotProcessNextThumbnail();
1661 QString ProjectList::getExtensions()
1663 // Build list of mime types
1664 QStringList mimeTypes = QStringList() << "application/x-kdenlive" << "application/x-kdenlivetitle" << "video/mlt-playlist" << "text/plain";
1667 mimeTypes << "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" << "video/3gpp" << "video/mp2t";
1670 mimeTypes << "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" << "audio/ac3";
1673 mimeTypes << "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";
1675 QString allExtensions;
1676 foreach(const QString & mimeType, mimeTypes) {
1677 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
1679 allExtensions.append(mime->patterns().join(" "));
1680 allExtensions.append(' ');
1683 return allExtensions.simplified();
1686 void ProjectList::slotAddClip(const QString &url, const QString &groupName, const QString &groupId)
1688 kDebug()<<"// Adding clip: "<<url;
1691 slotAddClip(list, groupName, groupId);
1694 void ProjectList::slotAddClip(const QList <QUrl> &givenList, const QString &groupName, const QString &groupId)
1696 if (!m_commandStack)
1697 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1700 if (givenList.isEmpty()) {
1701 QString allExtensions = getExtensions();
1702 const QString dialogFilter = allExtensions + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
1703 QCheckBox *b = new QCheckBox(i18n("Import image sequence"));
1704 b->setChecked(KdenliveSettings::autoimagesequence());
1705 QCheckBox *c = new QCheckBox(i18n("Transparent background for images"));
1706 c->setChecked(KdenliveSettings::autoimagetransparency());
1707 QFrame *f = new QFrame;
1708 f->setFrameShape(QFrame::NoFrame);
1709 QHBoxLayout *l = new QHBoxLayout;
1715 QPointer<KFileDialog> d = new KFileDialog(KUrl("kfiledialog:///clipfolder"), dialogFilter, kapp->activeWindow(), f);
1716 d->setOperationMode(KFileDialog::Opening);
1717 d->setMode(KFile::Files);
1718 if (d->exec() == QDialog::Accepted) {
1719 KdenliveSettings::setAutoimagetransparency(c->isChecked());
1720 list = d->selectedUrls();
1721 if (b->isChecked() && list.count() == 1) {
1722 // Check for image sequence
1723 KUrl url = list.at(0);
1724 QString fileName = url.fileName().section('.', 0, -2);
1725 if (fileName.at(fileName.size() - 1).isDigit()) {
1726 KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
1727 if (item.mimetype().startsWith("image")) {
1728 // import as sequence if we found more than one image in the sequence
1730 QString pattern = SlideshowClip::selectedPath(url.path(), false, QString(), &list);
1731 int count = list.count();
1734 QStringList groupInfo = getGroup();
1736 // get image sequence base name
1737 while (fileName.at(fileName.size() - 1).isDigit()) {
1740 QMap <QString, QString> properties;
1741 properties.insert("name", fileName);
1742 properties.insert("resource", pattern);
1743 properties.insert("in", "0");
1744 QString duration = m_timecode.reformatSeparators(KdenliveSettings::sequence_duration());
1745 properties.insert("out", QString::number(m_doc->getFramePos(duration) * count));
1746 properties.insert("ttl", QString::number(m_doc->getFramePos(duration)));
1747 properties.insert("loop", QString::number(false));
1748 properties.insert("crop", QString::number(false));
1749 properties.insert("fade", QString::number(false));
1750 properties.insert("luma_duration", QString::number(m_doc->getFramePos(m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))))));
1751 m_doc->slotCreateSlideshowClipFile(properties, groupInfo.at(0), groupInfo.at(1));
1760 for (int i = 0; i < givenList.count(); ++i)
1761 list << givenList.at(i);
1763 QList <KUrl::List> foldersList;
1765 foreach(const KUrl & file, list) {
1766 // Check there is no folder here
1767 KMimeType::Ptr type = KMimeType::findByUrl(file);
1768 if (type->is("inode/directory")) {
1769 // user dropped a folder, import its files
1770 list.removeAll(file);
1771 QDir dir(file.path());
1772 QStringList result = dir.entryList(QDir::Files);
1773 KUrl::List folderFiles;
1774 folderFiles << file;
1775 foreach(const QString & path, result) {
1776 KUrl newFile = file;
1777 newFile.addPath(path);
1778 folderFiles.append(newFile);
1780 if (folderFiles.count() > 1) foldersList.append(folderFiles);
1784 if (givenList.isEmpty() && !list.isEmpty()) {
1785 QStringList groupInfo = getGroup();
1786 QMap <QString, QString> data;
1787 data.insert("group", groupInfo.at(0));
1788 data.insert("groupId", groupInfo.at(1));
1789 m_doc->slotAddClipList(list, data);
1790 } else if (!list.isEmpty()) {
1791 QMap <QString, QString> data;
1792 data.insert("group", groupName);
1793 data.insert("groupId", groupId);
1794 m_doc->slotAddClipList(list, data);
1797 if (!foldersList.isEmpty()) {
1799 for (int i = 0; i < foldersList.count(); ++i) {
1800 KUrl::List urls = foldersList.at(i);
1801 KUrl folderUrl = urls.takeFirst();
1802 QString folderName = folderUrl.fileName();
1803 FolderProjectItem *folder = NULL;
1804 if (!folderName.isEmpty()) {
1805 folder = getFolderItemByName(folderName);
1806 if (folder == NULL) {
1807 slotAddFolder(folderName);
1808 folder = getFolderItemByName(folderName);
1812 QMap <QString, QString> data;
1813 data.insert("group", folder->groupName());
1814 data.insert("groupId", folder->clipId());
1815 m_doc->slotAddClipList(urls, data);
1817 else m_doc->slotAddClipList(urls);
1822 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
1824 ProjectItem *item = getItemById(id);
1825 m_thumbnailQueue.removeAll(id);
1827 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1828 const QString path = item->referencedClip()->fileURL().path();
1829 if (item->referencedClip()->isPlaceHolder()) replace = false;
1830 if (!path.isEmpty()) {
1831 if (m_invalidClipDialog) {
1832 m_invalidClipDialog->addClip(id, path);
1837 m_invalidClipDialog = new InvalidDialog(i18n("Invalid clip"), i18n("Clip is invalid, will be removed from project."), replace, kapp->activeWindow());
1839 m_invalidClipDialog = new InvalidDialog(i18n("Invalid clip"), i18n("Clip is missing or invalid. Remove it from project?"), replace, kapp->activeWindow());
1841 m_invalidClipDialog->addClip(id, path);
1842 int result = m_invalidClipDialog->exec();
1843 if (result == KDialog::Yes) replace = true;
1846 if (m_invalidClipDialog) {
1848 emit deleteProjectClips(m_invalidClipDialog->getIds(), QMap <QString, QString>());
1849 delete m_invalidClipDialog;
1850 m_invalidClipDialog = NULL;
1856 void ProjectList::slotRemoveInvalidProxy(const QString &id, bool durationError)
1858 ProjectItem *item = getItemById(id);
1860 kDebug()<<"// Proxy for clip "<<id<<" is invalid, delete";
1861 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1862 if (durationError) {
1863 kDebug() << "Proxy duration is wrong, try changing transcoding parameters.";
1864 emit displayMessage(i18n("Proxy clip unusable (duration is different from original)."), -2, ErrorMessage);
1866 slotUpdateJobStatus(item, PROXYJOB, JobCrashed, i18n("Failed to create proxy for %1. check parameters", item->text(0)), "project_settings");
1867 QString path = item->referencedClip()->getProperty("proxy");
1868 KUrl proxyFolder(m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/");
1870 //Security check: make sure the invalid proxy file is in the proxy folder
1871 if (proxyFolder.isParentOf(KUrl(path))) {
1872 QFile::remove(path);
1874 if (item->referencedClip()->getProducer() == NULL) {
1875 // Clip has no valid producer, request it
1876 slotProxyCurrentItem(false, item);
1879 // refresh thumbs producer
1880 item->referencedClip()->reloadThumbProducer();
1883 m_thumbnailQueue.removeAll(id);
1886 void ProjectList::slotAddColorClip()
1888 if (!m_commandStack)
1889 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1891 QPointer<QDialog> dia = new QDialog(this);
1892 Ui::ColorClip_UI dia_ui;
1893 dia_ui.setupUi(dia);
1894 dia->setWindowTitle(i18n("Color Clip"));
1895 dia_ui.clip_name->setText(i18n("Color Clip"));
1897 TimecodeDisplay *t = new TimecodeDisplay(m_timecode);
1898 t->setValue(KdenliveSettings::color_duration());
1899 dia_ui.clip_durationBox->addWidget(t);
1900 dia_ui.clip_color->setColor(KdenliveSettings::colorclipcolor());
1902 if (dia->exec() == QDialog::Accepted) {
1903 QString color = dia_ui.clip_color->color().name();
1904 KdenliveSettings::setColorclipcolor(color);
1905 color = color.replace(0, 1, "0x") + "ff";
1906 QStringList groupInfo = getGroup();
1907 m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, m_timecode.getTimecode(t->gentime()), groupInfo.at(0), groupInfo.at(1));
1914 void ProjectList::slotAddSlideshowClip()
1916 if (!m_commandStack)
1917 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1919 SlideshowClip *dia = new SlideshowClip(m_timecode, this);
1921 if (dia->exec() == QDialog::Accepted) {
1922 QStringList groupInfo = getGroup();
1924 QMap <QString, QString> properties;
1925 properties.insert("name", dia->clipName());
1926 properties.insert("resource", dia->selectedPath());
1927 properties.insert("in", "0");
1928 properties.insert("out", QString::number(m_doc->getFramePos(dia->clipDuration()) * dia->imageCount()));
1929 properties.insert("ttl", QString::number(m_doc->getFramePos(dia->clipDuration())));
1930 properties.insert("loop", QString::number(dia->loop()));
1931 properties.insert("crop", QString::number(dia->crop()));
1932 properties.insert("fade", QString::number(dia->fade()));
1933 properties.insert("luma_duration", dia->lumaDuration());
1934 properties.insert("luma_file", dia->lumaFile());
1935 properties.insert("softness", QString::number(dia->softness()));
1936 properties.insert("animation", dia->animation());
1938 m_doc->slotCreateSlideshowClipFile(properties, groupInfo.at(0), groupInfo.at(1));
1943 void ProjectList::slotAddTitleClip()
1945 QStringList groupInfo = getGroup();
1946 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
1949 void ProjectList::slotAddTitleTemplateClip()
1951 if (!m_commandStack)
1952 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1954 QStringList groupInfo = getGroup();
1956 // Get the list of existing templates
1958 filter << "*.kdenlivetitle";
1959 const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
1960 QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
1962 QPointer<QDialog> dia = new QDialog(this);
1963 Ui::TemplateClip_UI dia_ui;
1964 dia_ui.setupUi(dia);
1965 for (int i = 0; i < templateFiles.size(); ++i)
1966 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
1968 if (!templateFiles.isEmpty())
1969 dia_ui.buttonBox->button(QDialogButtonBox::Ok)->setFocus();
1970 dia_ui.template_list->fileDialog()->setFilter("application/x-kdenlivetitle");
1971 //warning: setting base directory doesn't work??
1972 KUrl startDir(path);
1973 dia_ui.template_list->fileDialog()->setUrl(startDir);
1974 dia_ui.text_box->setHidden(true);
1975 if (dia->exec() == QDialog::Accepted) {
1976 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
1977 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
1978 // Create a cloned template clip
1979 m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
1984 QStringList ProjectList::getGroup() const
1987 QTreeWidgetItem *item = m_listView->currentItem();
1988 while (item && item->type() != ProjectFoldeType)
1989 item = item->parent();
1992 FolderProjectItem *folder = static_cast <FolderProjectItem *>(item);
1993 result << folder->groupName() << folder->clipId();
1995 result << QString() << QString();
2000 void ProjectList::setDocument(KdenliveDoc *doc)
2002 m_listView->blockSignals(true);
2003 m_abortAllJobs = true;
2004 for (int i = 0; i < m_jobList.count(); ++i) {
2005 m_jobList.at(i)->setStatus(JobAborted);
2008 m_jobThreads.waitForFinished();
2009 m_jobThreads.clearFutures();
2010 m_thumbnailQueue.clear();
2011 m_listView->clear();
2013 m_listView->setSortingEnabled(false);
2014 emit clipSelected(NULL);
2015 m_refreshed = false;
2016 m_allClipsProcessed = false;
2018 m_timecode = doc->timecode();
2019 m_commandStack = doc->commandStack();
2021 m_abortAllJobs = false;
2024 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
2025 QStringList openedFolders = doc->getExpandedFolders();
2026 QMapIterator<QString, QString> f(flist);
2027 while (f.hasNext()) {
2029 FolderProjectItem *folder = new FolderProjectItem(m_listView, QStringList() << f.value(), f.key());
2030 folder->setExpanded(openedFolders.contains(f.key()));
2033 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
2034 if (list.isEmpty()) {
2037 m_allClipsProcessed = true;
2039 for (int i = 0; i < list.count(); ++i)
2040 slotAddClip(list.at(i), false);
2042 m_listView->blockSignals(false);
2043 connect(m_doc->clipManager(), SIGNAL(reloadClip(QString)), this, SLOT(slotReloadClip(QString)));
2044 connect(m_doc->clipManager(), SIGNAL(modifiedClip(QString)), this, SLOT(slotModifiedClip(QString)));
2045 connect(m_doc->clipManager(), SIGNAL(missingClip(QString)), this, SLOT(slotMissingClip(QString)));
2046 connect(m_doc->clipManager(), SIGNAL(availableClip(QString)), this, SLOT(slotAvailableClip(QString)));
2047 connect(m_doc->clipManager(), SIGNAL(checkAllClips(bool,bool,QStringList)), this, SLOT(updateAllClips(bool,bool,QStringList)));
2048 connect(m_doc->clipManager(), SIGNAL(thumbReady(QString,int,QImage)), this, SLOT(slotSetThumbnail(QString,int,QImage)));
2051 void ProjectList::slotSetThumbnail(const QString &id, int framePos, QImage img)
2053 QString fullid = id + '#' + QString::number(framePos);
2054 ProjectItem *pItem = NULL;
2055 QTreeWidgetItem *item = getAnyItemById(fullid);
2056 if (item && item->parent()) pItem = static_cast <ProjectItem *>(item->parent());
2057 if (!item && framePos == 0) pItem = getItemById(id);
2058 if (!item && !pItem) return;
2060 if (item->type() == ProjectClipType) static_cast<ProjectItem*>(item)->setPixmap(QPixmap::fromImage(img));
2061 else item->setData(0, Qt::DecorationRole, QPixmap::fromImage(img));
2063 else if (pItem) pItem->setPixmap(QPixmap::fromImage(img));
2065 QString hash = pItem->getClipHash();
2066 if (!hash.isEmpty()) m_doc->cacheImage(hash + '#' + QString::number(framePos), img);
2070 QList <DocClipBase*> ProjectList::documentClipList() const
2073 return QList <DocClipBase*> ();
2075 return m_doc->clipManager()->documentClipList();
2078 QDomElement ProjectList::producersList()
2081 QDomElement prods = doc.createElement("producerlist");
2082 doc.appendChild(prods);
2083 QTreeWidgetItemIterator it(m_listView);
2085 if ((*it)->type() != ProjectClipType) {
2090 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
2096 void ProjectList::slotCheckForEmptyQueue()
2098 if (m_render->processingItems() == 0 && m_thumbnailQueue.isEmpty()) {
2099 if (!m_refreshed && m_allClipsProcessed) {
2101 m_listView->setEnabled(true);
2103 QTimer::singleShot(500, this, SIGNAL(loadingIsOver()));
2104 emit displayMessage(QString(), -1);
2107 } else if (!m_refreshed) {
2108 QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
2113 void ProjectList::requestClipThumbnail(const QString &id)
2115 if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id);
2116 slotProcessNextThumbnail();
2119 void ProjectList::resetThumbsProducer(DocClipBase *clip)
2122 clip->clearThumbProducer();
2123 QString id = clip->getId();
2124 m_thumbnailQueue.removeAll(id);
2127 void ProjectList::slotProcessNextThumbnail()
2129 if (m_render->processingItems() > 0) {
2132 if (m_thumbnailQueue.isEmpty()) {
2133 slotCheckForEmptyQueue();
2136 int max = m_doc->clipManager()->clipsCount();
2137 emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - m_thumbnailQueue.count()) / max));
2138 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
2141 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
2143 QTreeWidgetItem *item = getAnyItemById(clipId);
2145 slotRefreshClipThumbnail(item, update);
2147 slotProcessNextThumbnail();
2151 void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
2153 if (it == NULL) return;
2154 ProjectItem *item = NULL;
2155 bool isSubItem = false;
2157 if (it->type() == ProjectFoldeType) return;
2158 if (it->type() == ProjectSubclipType) {
2159 item = static_cast <ProjectItem *>(it->parent());
2160 frame = static_cast <SubProjectItem *>(it)->zone().x();
2163 item = static_cast <ProjectItem *>(it);
2164 frame = item->referencedClip()->getClipThumbFrame();
2168 DocClipBase *clip = item->referencedClip();
2170 slotProcessNextThumbnail();
2174 int height = m_listView->iconSize().height();
2175 int swidth = (int)(height * m_render->frameRenderWidth() / m_render->renderHeight()+ 0.5);
2176 int dwidth = (int)(height * m_render->dar() + 0.5);
2177 if (clip->clipType() == Image) {
2178 img = KThumb::getFrame(item->referencedClip()->getProducer(), 0, swidth, dwidth, height);
2180 else if (clip->clipType() != Audio) {
2181 img = item->referencedClip()->extractImage(frame, dwidth, height);
2183 if (!img.isNull()) {
2184 monitorItemEditing(false);
2185 QPixmap pix = roundedPixmap(img);
2186 processThumbOverlays(item, pix);
2187 if (isSubItem) it->setData(0, Qt::DecorationRole, pix);
2188 else item->setPixmap(pix);
2189 monitorItemEditing(true);
2191 QString hash = item->getClipHash();
2192 if (!hash.isEmpty() && !img.isNull()) {
2194 m_doc->cacheImage(hash, img);
2196 m_doc->cacheImage(hash + '#' + QString::number(frame), img);
2200 emit projectModified();
2201 slotProcessNextThumbnail();
2205 void ProjectList::extractMetadata(DocClipBase *clip)
2207 ClipType t = clip->clipType();
2208 if (t != AV && t != Video) {
2209 // Currently, we only use exiftool on video files
2212 QMap <QString, QString> props = clip->properties();
2213 if (KdenliveSettings::use_exiftool() && !props.contains("exiftool")) {
2214 QMap <QString, QString> meta;
2215 QString url = clip->fileURL().path();
2216 //Check for Canon THM file
2217 url = url.section('.', 0, -2) + ".THM";
2218 if (QFile::exists(url)) {
2219 // Read the exif metadata embeded in the THM file
2222 args << "-g" << "-args" << url;
2223 p.start("exiftool", args);
2224 p.waitForFinished();
2225 QString res = p.readAllStandardOutput();
2226 QStringList list = res.split("\n");
2227 foreach(QString tagline, list) {
2228 if (tagline.startsWith("-File") || tagline.startsWith("-ExifTool")) continue;
2229 QString tag = tagline.section(':', 1).simplified();
2230 if (tag.startsWith("ImageWidth") || tag.startsWith("ImageHeight")) continue;
2231 if (!tag.section('=', 0, 0).isEmpty() && !tag.section('=', 1).simplified().isEmpty())
2232 meta.insert(tag.section('=', 0, 0), tag.section('=', 1).simplified());
2235 QString codecid = props.value("videocodecid").simplified();
2236 if (codecid == "h264") {
2239 args << "-g" << "-args" << clip->fileURL().encodedPathAndQuery();
2240 p.start("exiftool", args);
2241 p.waitForFinished();
2242 QString res = p.readAllStandardOutput();
2243 QStringList list = res.split("\n");
2244 foreach(QString tagline, list) {
2245 if (!tagline.startsWith("-H264")) continue;
2246 QString tag = tagline.section(':', 1);
2247 if (tag.startsWith("ImageWidth") || tag.startsWith("ImageHeight")) continue;
2248 meta.insert(tag.section('=', 0, 0), tag.section('=', 1));
2252 clip->setProperty("exiftool", "1");
2253 if (!meta.isEmpty()) {
2254 clip->setMetadata(meta, "ExifTool");
2255 //checkCamcorderFilters(clip, meta);
2258 if (KdenliveSettings::use_magicLantern() && !props.contains("magiclantern")) {
2259 QMap <QString, QString> meta;
2260 QString url = clip->fileURL().path();
2261 url = url.section('.', 0, -2) + ".LOG";
2262 if (QFile::exists(url)) {
2264 if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
2265 while (!file.atEnd()) {
2266 QString line = file.readLine().simplified();
2267 if (line.startsWith('#') || line.isEmpty() || !line.contains(':')) continue;
2268 if (line.startsWith("CSV data")) break;
2269 meta.insert(line.section(':', 0, 0).simplified(), line.section(':', 1).simplified());
2274 if (!meta.isEmpty())
2275 clip->setMetadata(meta, "Magic Lantern");
2276 clip->setProperty("magiclantern", "1");
2281 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const stringMap &properties, const stringMap &metadata, bool replace)
2283 QMutexLocker lock(&m_processMutex);
2285 ProjectItem *item = getItemById(clipId);
2286 if (item && producer) {
2287 monitorItemEditing(false);
2288 DocClipBase *clip = item->referencedClip();
2289 if (producer->is_valid()) {
2290 if (clip->isPlaceHolder()) {
2294 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
2296 item->setProperties(properties, metadata);
2297 clip->setProducer(producer, replace);
2298 extractMetadata(clip);
2299 m_render->processingDone(clipId);
2302 QString size = properties.value("frame_size");
2303 if (!useProxy() && clip->getProperty("proxy").isEmpty()) {
2304 item->setConditionalJobStatus(NoJob, PROXYJOB);
2305 discardJobs(clipId, PROXYJOB);
2307 if (useProxy() && generateProxy() && clip->getProperty("proxy") == "-") {
2308 item->setConditionalJobStatus(NoJob, PROXYJOB);
2309 discardJobs(clipId, PROXYJOB);
2311 else if (useProxy() && !item->hasProxy() && !hasPendingJob(item, PROXYJOB)) {
2312 // proxy video and image clips
2314 ClipType t = item->clipType();
2315 if (t == Image) maxSize = m_doc->getDocumentProperty("proxyimageminsize").toInt();
2316 else maxSize = m_doc->getDocumentProperty("proxyminsize").toInt();
2317 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)) {
2318 if (clip->getProperty("proxy").isEmpty()) {
2319 KUrl proxyPath = m_doc->projectFolder();
2320 proxyPath.addPath("proxy/");
2321 proxyPath.addPath(clip->getClipHash() + '.' + (t == Image ? "png" : m_doc->getDocumentProperty("proxyextension")));
2322 QMap <QString, QString> newProps;
2323 // insert required duration for proxy
2324 if (t != Image) newProps.insert("proxy_out", clip->producerProperty("out"));
2325 newProps.insert("proxy", proxyPath.path());
2326 QMap <QString, QString> oldProps = clip->properties();
2327 oldProps.insert("proxy", QString());
2328 EditClipCommand *command = new EditClipCommand(this, clipId, oldProps, newProps, true);
2329 m_doc->commandStack()->push(command);
2334 if (!replace && m_allClipsProcessed && !item->hasPixmap()) {
2335 getCachedThumbnail(item);
2337 if (!toReload.isEmpty())
2338 item->slotSetToolTip();
2340 kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
2341 m_render->processingDone(clipId);
2343 int queue = m_render->processingItems();
2345 monitorItemEditing(true);
2346 if (item && m_thumbnailQueue.isEmpty()) {
2347 if (!item->hasProxy() || m_render->activeClipId() == item->clipId())
2348 m_listView->setCurrentItem(item);
2349 bool updatedProfile = false;
2350 if (item->parent()) {
2351 if (item->parent()->type() == ProjectFoldeType)
2352 static_cast <FolderProjectItem *>(item->parent())->switchIcon();
2353 } else if (KdenliveSettings::checkfirstprojectclip() && m_listView->topLevelItemCount() == 1 && m_refreshed && m_allClipsProcessed) {
2354 // this is the first clip loaded in project, check if we want to adjust project settings to the clip
2355 updatedProfile = adjustProjectProfileToItem(item);
2356 if (updatedProfile == false) {
2357 emit clipSelected(item->referencedClip());
2360 if (updatedProfile == false) {
2361 //emit clipSelected(item->referencedClip());
2364 int max = m_doc->clipManager()->clipsCount();
2365 if (max > 0) emit displayMessage(i18n("Loading clips"), (int)(100 *(max - queue) / max));
2367 if (m_allClipsProcessed) emit processNextThumbnail();
2370 // no item for producer, delete it
2374 if (replace) toReload = clipId;
2375 if (!toReload.isEmpty()) {
2376 emit clipNeedsReload(toReload);
2380 bool ProjectList::adjustProjectProfileToItem(ProjectItem *item)
2383 if (m_listView->currentItem() && m_listView->currentItem()->type() != ProjectFoldeType)
2384 item = static_cast <ProjectItem*>(m_listView->currentItem());
2386 if (item == NULL || item->referencedClip() == NULL) {
2387 KMessageBox::information(kapp->activeWindow(), i18n("Cannot find profile from current clip"));
2390 bool profileUpdated = false;
2391 QString size = item->referencedClip()->getProperty("frame_size");
2392 int width = size.section('x', 0, 0).toInt();
2393 int height = size.section('x', -1).toInt();
2394 // Fix some avchd clips tht report a wrong size (1920x1088)
2395 if (height == 1088) height = 1080;
2396 double fps = item->referencedClip()->getProperty("fps").toDouble();
2397 double par = item->referencedClip()->getProperty("aspect_ratio").toDouble();
2398 if (item->clipType() == Image || item->clipType() == AV || item->clipType() == Video) {
2399 if (ProfilesDialog::matchProfile(width, height, fps, par, item->clipType() == Image, m_doc->mltProfile()) == false) {
2400 // get a list of compatible profiles
2401 QMap <QString, QString> suggestedProfiles = ProfilesDialog::getProfilesFromProperties(width, height, fps, par, item->clipType() == Image);
2402 if (!suggestedProfiles.isEmpty()) {
2403 KDialog *dialog = new KDialog(this);
2404 dialog->setCaption(i18n("Change project profile"));
2405 dialog->setButtons(KDialog::Ok | KDialog::Cancel);
2408 QVBoxLayout *l = new QVBoxLayout;
2409 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));
2410 l->addWidget(label);
2411 QListWidget *list = new QListWidget;
2412 list->setAlternatingRowColors(true);
2413 QMapIterator<QString, QString> i(suggestedProfiles);
2414 while (i.hasNext()) {
2416 QListWidgetItem *item = new QListWidgetItem(i.value(), list);
2417 item->setData(Qt::UserRole, i.key());
2418 item->setToolTip(i.key());
2420 list->setCurrentRow(0);
2422 container.setLayout(l);
2423 dialog->setButtonText(KDialog::Ok, i18n("Update profile"));
2424 dialog->setMainWidget(&container);
2425 if (dialog->exec() == QDialog::Accepted) {
2426 //Change project profile
2427 profileUpdated = true;
2428 if (list->currentItem())
2429 emit updateProfile(list->currentItem()->data(Qt::UserRole).toString());
2433 } else if (fps > 0) {
2434 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));
2438 return profileUpdated;
2441 QString ProjectList::getDocumentProperty(const QString &key) const
2443 return m_doc->getDocumentProperty(key);
2446 bool ProjectList::useProxy() const
2448 return m_doc->getDocumentProperty("enableproxy").toInt();
2451 bool ProjectList::generateProxy() const
2453 return m_doc->getDocumentProperty("generateproxy").toInt();
2456 bool ProjectList::generateImageProxy() const
2458 return m_doc->getDocumentProperty("generateimageproxy").toInt();
2461 void ProjectList::slotReplyGetImage(const QString &clipId, const QImage &img)
2463 ProjectItem *item = getItemById(clipId);
2464 if (item && !img.isNull()) {
2465 QPixmap pix = roundedPixmap(img);
2466 processThumbOverlays(item, pix);
2467 monitorItemEditing(false);
2468 item->setPixmap(pix);
2469 monitorItemEditing(true);
2470 QString hash = item->getClipHash();
2471 if (!hash.isEmpty()) m_doc->cacheImage(hash, img);
2475 void ProjectList::slotReplyGetImage(const QString &clipId, const QString &name, int width, int height)
2477 // For clips that have a generic icon (like audio clips...)
2478 ProjectItem *item = getItemById(clipId);
2479 QPixmap pix = KIcon(name).pixmap(QSize(width, height));
2480 if (item && !pix.isNull()) {
2481 monitorItemEditing(false);
2482 item->setData(0, Qt::DecorationRole, pix);
2483 monitorItemEditing(true);
2487 QTreeWidgetItem *ProjectList::getAnyItemById(const QString &id)
2489 QTreeWidgetItemIterator it(m_listView);
2490 QString lookId = id;
2491 if (id.contains('#'))
2492 lookId = id.section('#', 0, 0);
2494 ProjectItem *result = NULL;
2496 if ((*it)->type() != ProjectClipType) {
2501 ProjectItem *item = static_cast<ProjectItem *>(*it);
2502 if (item->clipId() == lookId) {
2508 if (result == NULL || !id.contains('#')) {
2511 for (int i = 0; i < result->childCount(); ++i) {
2512 SubProjectItem *sub = static_cast <SubProjectItem *>(result->child(i));
2513 if (sub && sub->zone().x() == id.section('#', 1, 1).toInt())
2522 ProjectItem *ProjectList::getItemById(const QString &id)
2525 QTreeWidgetItemIterator it(m_listView);
2527 if ((*it)->type() != ProjectClipType) {
2528 // subitem or folder
2532 item = static_cast<ProjectItem *>(*it);
2533 if (item->clipId() == id)
2540 FolderProjectItem *ProjectList::getFolderItemByName(const QString &name)
2542 FolderProjectItem *item = NULL;
2543 QList <QTreeWidgetItem *> hits = m_listView->findItems(name, Qt::MatchExactly, 0);
2544 for (int i = 0; i < hits.count(); ++i) {
2545 if (hits.at(i)->type() == ProjectFoldeType) {
2546 item = static_cast<FolderProjectItem *>(hits.at(i));
2553 FolderProjectItem *ProjectList::getFolderItemById(const QString &id)
2555 FolderProjectItem *item;
2556 QTreeWidgetItemIterator it(m_listView);
2558 if ((*it)->type() == ProjectFoldeType) {
2559 item = static_cast<FolderProjectItem *>(*it);
2560 if (item->clipId() == id)
2568 void ProjectList::slotSelectClip(const QString &ix)
2570 ProjectItem *clip = getItemById(ix);
2572 m_listView->setCurrentItem(clip);
2573 m_listView->scrollToItem(clip);
2574 m_editButton->defaultAction()->setEnabled(true);
2575 m_deleteButton->defaultAction()->setEnabled(true);
2576 m_reloadAction->setEnabled(true);
2577 m_extractAudioAction->setEnabled(true);
2578 m_transcodeAction->setEnabled(true);
2579 m_clipsActionsMenu->setEnabled(true);
2580 if (clip->clipType() == Image && !KdenliveSettings::defaultimageapp().isEmpty()) {
2581 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
2582 m_openAction->setEnabled(true);
2583 } else if (clip->clipType() == Audio && !KdenliveSettings::defaultaudioapp().isEmpty()) {
2584 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
2585 m_openAction->setEnabled(true);
2587 m_openAction->setEnabled(false);
2592 QString ProjectList::currentClipUrl() const
2595 if (!m_listView->currentItem() || m_listView->currentItem()->type() == ProjectFoldeType) return QString();
2596 if (m_listView->currentItem()->type() == ProjectSubclipType) {
2598 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
2600 item = static_cast <ProjectItem*>(m_listView->currentItem());
2604 return item->clipUrl().path();
2607 KUrl::List ProjectList::getConditionalUrls(const QString &condition) const
2611 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
2612 for (int i = 0; i < list.count(); ++i) {
2613 if (list.at(i)->type() == ProjectFoldeType)
2615 if (list.at(i)->type() == ProjectSubclipType) {
2617 item = static_cast <ProjectItem*>(list.at(i)->parent());
2619 item = static_cast <ProjectItem*>(list.at(i));
2621 if (item == NULL || item->type() == Color || item->type() == SlideShow || item->type() == Text)
2623 DocClipBase *clip = item->referencedClip();
2624 if (!condition.isEmpty()) {
2625 if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section('=', 1, 1)))
2627 else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section('=', 1, 1)))
2630 result.append(item->clipUrl());
2635 QMap <QString, QString> ProjectList::getConditionalIds(const QString &condition) const
2637 QMap <QString, QString> result;
2639 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
2640 for (int i = 0; i < list.count(); ++i) {
2641 if (list.at(i)->type() == ProjectFoldeType)
2643 if (list.at(i)->type() == ProjectSubclipType) {
2645 item = static_cast <ProjectItem*>(list.at(i)->parent());
2647 item = static_cast <ProjectItem*>(list.at(i));
2649 if (item == NULL || item->type() == Color || item->type() == SlideShow || item->type() == Text)
2651 DocClipBase *clip = item->referencedClip();
2652 if (!condition.isEmpty()) {
2653 if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section('=', 1, 1)))
2655 else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section('=', 1, 1)))
2658 result.insert(item->clipId(), item->clipUrl().path());
2663 void ProjectList::regenerateTemplate(const QString &id)
2665 ProjectItem *clip = getItemById(id);
2667 regenerateTemplate(clip);
2670 void ProjectList::regenerateTemplate(ProjectItem *clip)
2672 //TODO: remove this unused method, only force_reload is necessary
2673 clip->referencedClip()->getProducer()->set("force_reload", 1);
2676 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
2680 if (!file.open(QIODevice::ReadOnly)) {
2681 kWarning() << "ERROR, CANNOT READ: " << path;
2684 if (!doc.setContent(&file)) {
2685 kWarning() << "ERROR, CANNOT READ: " << path;
2690 QDomNodeList texts = doc.elementsByTagName("content");
2691 for (int i = 0; i < texts.count(); ++i) {
2692 QString data = texts.item(i).firstChild().nodeValue();
2693 data.replace("%s", replaceString);
2694 texts.item(i).firstChild().setNodeValue(data);
2700 void ProjectList::slotAddClipCut(const QString &id, int in, int out)
2702 ProjectItem *clip = getItemById(id);
2703 if (clip == NULL || clip->referencedClip()->hasCutZone(QPoint(in, out)))
2705 AddClipCutCommand *command = new AddClipCutCommand(this, id, in, out, QString(), true, false);
2706 m_commandStack->push(command);
2709 void ProjectList::addClipCut(const QString &id, int in, int out, const QString desc, bool newItem)
2711 ProjectItem *clip = getItemById(id);
2713 DocClipBase *base = clip->referencedClip();
2714 base->addCutZone(in, out);
2715 monitorItemEditing(false);
2716 SubProjectItem *sub = new SubProjectItem(m_render->dar(), clip, in, out, desc);
2717 if (newItem && desc.isEmpty() && !m_listView->isColumnHidden(1)) {
2718 if (!clip->isExpanded())
2719 clip->setExpanded(true);
2720 m_listView->scrollToItem(sub);
2721 m_listView->editItem(sub, 1);
2723 m_doc->clipManager()->slotRequestThumbs(QString('#' + id), QList <int>() << in);
2724 monitorItemEditing(true);
2726 emit projectModified();
2729 void ProjectList::removeClipCut(const QString &id, int in, int out)
2731 ProjectItem *clip = getItemById(id);
2733 DocClipBase *base = clip->referencedClip();
2734 base->removeCutZone(in, out);
2735 SubProjectItem *sub = getSubItem(clip, QPoint(in, out));
2737 monitorItemEditing(false);
2739 monitorItemEditing(true);
2742 emit projectModified();
2745 SubProjectItem *ProjectList::getSubItem(ProjectItem *clip, const QPoint &zone)
2747 SubProjectItem *sub = NULL;
2749 for (int i = 0; i < clip->childCount(); ++i) {
2750 QTreeWidgetItem *it = clip->child(i);
2751 if (it->type() == ProjectSubclipType) {
2752 sub = static_cast <SubProjectItem*>(it);
2753 if (sub->zone() == zone)
2763 void ProjectList::slotUpdateClipCut(QPoint p)
2765 if (!m_listView->currentItem() || m_listView->currentItem()->type() != ProjectSubclipType)
2767 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
2768 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
2769 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), p, sub->text(1), sub->text(1), true);
2770 m_commandStack->push(command);
2773 void ProjectList::doUpdateClipCut(const QString &id, const QPoint &oldzone, const QPoint &zone, const QString &comment)
2775 ProjectItem *clip = getItemById(id);
2776 SubProjectItem *sub = getSubItem(clip, oldzone);
2777 if (sub == NULL || clip == NULL)
2779 DocClipBase *base = clip->referencedClip();
2780 base->updateCutZone(oldzone.x(), oldzone.y(), zone.x(), zone.y(), comment);
2781 monitorItemEditing(false);
2783 sub->setDescription(comment);
2784 monitorItemEditing(true);
2785 emit projectModified();
2788 void ProjectList::slotForceProcessing(const QString &id)
2790 m_render->forceProcessing(id);
2793 void ProjectList::slotAddOrUpdateSequence(const QString &frameName)
2795 QString fileName = KUrl(frameName).fileName().section('_', 0, -2);
2797 QString pattern = SlideshowClip::selectedPath(frameName, false, QString(), &list);
2798 int count = list.count();
2800 const QList <DocClipBase *> existing = m_doc->clipManager()->getClipByResource(pattern);
2801 if (!existing.isEmpty()) {
2802 // Sequence already exists, update
2803 QString id = existing.at(0)->getId();
2804 //ProjectItem *item = getItemById(id);
2805 QMap <QString, QString> oldprops;
2806 QMap <QString, QString> newprops;
2807 int ttl = existing.at(0)->getProperty("ttl").toInt();
2808 oldprops["out"] = existing.at(0)->getProperty("out");
2809 newprops["out"] = QString::number(ttl * count - 1);
2810 slotUpdateClipProperties(id, newprops);
2811 EditClipCommand *command = new EditClipCommand(this, id, oldprops, newprops, false);
2812 m_commandStack->push(command);
2815 QStringList groupInfo = getGroup();
2816 QMap <QString, QString> properties;
2817 properties.insert("name", fileName);
2818 properties.insert("resource", pattern);
2819 properties.insert("in", "0");
2820 QString duration = m_timecode.reformatSeparators(KdenliveSettings::sequence_duration());
2821 properties.insert("out", QString::number(m_doc->getFramePos(duration) * count));
2822 properties.insert("ttl", QString::number(m_doc->getFramePos(duration)));
2823 properties.insert("loop", QString::number(false));
2824 properties.insert("crop", QString::number(false));
2825 properties.insert("fade", QString::number(false));
2826 properties.insert("luma_duration", m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))));
2828 m_doc->slotCreateSlideshowClipFile(properties, groupInfo.at(0), groupInfo.at(1));
2830 } else emit displayMessage(i18n("Sequence not found"), -2, ErrorMessage);
2833 QMap <QString, QString> ProjectList::getProxies()
2835 QMap <QString, QString> list;
2837 QTreeWidgetItemIterator it(m_listView);
2839 if ((*it)->type() != ProjectClipType) {
2843 item = static_cast<ProjectItem *>(*it);
2844 if (item && item->referencedClip() != NULL) {
2845 if (item->hasProxy()) {
2846 QString proxy = item->referencedClip()->getProperty("proxy");
2847 list.insert(proxy, item->clipUrl().path());
2855 void ProjectList::slotCreateProxy(const QString &id)
2857 ProjectItem *item = getItemById(id);
2858 if (!item || hasPendingJob(item, PROXYJOB) || item->referencedClip()->isPlaceHolder()) return;
2859 QString path = item->referencedClip()->getProperty("proxy");
2860 if (path.isEmpty()) {
2861 slotUpdateJobStatus(item, PROXYJOB, JobCrashed, i18n("Failed to create proxy, empty path."));
2865 if (QFileInfo(path).size() > 0) {
2866 // Proxy already created
2867 setJobStatus(item, PROXYJOB, JobDone);
2871 QString sourcePath = item->clipUrl().path();
2872 if (item->clipType() == Playlist) {
2873 // Special case: playlists use the special 'consumer' producer to support resizing
2874 sourcePath.prepend("consumer:");
2876 ProxyJob *job = new ProxyJob(item->clipType(), id, QStringList() << path << sourcePath << item->referencedClip()->producerProperty("_exif_orientation") << m_doc->getDocumentProperty("proxyparams").simplified() << QString::number(m_render->frameRenderWidth()) << QString::number(m_render->renderHeight()));
2877 if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
2882 m_jobList.append(job);
2883 setJobStatus(item, job->jobType, JobWaiting, 0, job->statusMessage());
2884 slotCheckJobProcess();
2887 void ProjectList::slotCutClipJob(const QString &id, QPoint zone)
2889 ProjectItem *item = getItemById(id);
2890 if (!item|| item->referencedClip()->isPlaceHolder()) return;
2891 QString source = item->clipUrl().path();
2892 QString ext = source.section('.', -1);
2893 QString dest = source.section('.', 0, -2) + '_' + QString::number(zone.x()) + '.' + ext;
2895 double clipFps = item->referencedClip()->getProperty("fps").toDouble();
2896 if (clipFps == 0) clipFps = m_fps;
2897 // if clip and project have different frame rate, adjust in and out
2900 in = GenTime(in, m_timecode.fps()).frames(clipFps);
2901 out = GenTime(out, m_timecode.fps()).frames(clipFps);
2902 int max = GenTime(item->clipMaxDuration(), m_timecode.fps()).frames(clipFps);
2903 int duration = out - in + 1;
2904 QString timeIn = Timecode::getStringTimecode(in, clipFps, true);
2905 QString timeOut = Timecode::getStringTimecode(duration, clipFps, true);
2907 QPointer<QDialog> d = new QDialog(this);
2908 Ui::CutJobDialog_UI ui;
2910 ui.extra_params->setVisible(false);
2911 ui.add_clip->setChecked(KdenliveSettings::add_new_clip());
2912 ui.file_url->fileDialog()->setOperationMode(KFileDialog::Saving);
2913 ui.extra_params->setMaximumHeight(QFontMetrics(font()).lineSpacing() * 5);
2914 ui.file_url->setUrl(KUrl(dest));
2915 ui.button_more->setIcon(KIcon("configure"));
2916 ui.extra_params->setPlainText("-acodec copy -vcodec copy");
2917 QString mess = i18n("Extracting %1 out of %2", timeOut, Timecode::getStringTimecode(max, clipFps, true));
2918 ui.info_label->setText(mess);
2919 if (d->exec() != QDialog::Accepted) {
2923 dest = ui.file_url->url().path();
2924 bool acceptPath = dest != source;
2925 if (acceptPath && QFileInfo(dest).size() > 0) {
2926 // destination file olready exists, overwrite?
2929 while (!acceptPath) {
2930 // Do not allow to save over original clip
2931 if (dest == source) ui.info_label->setText("<b>" + i18n("You cannot overwrite original clip.") + "</b><br>" + mess);
2932 else if (KMessageBox::questionYesNo(this, i18n("Overwrite file %1", dest)) == KMessageBox::Yes) break;
2933 if (d->exec() != QDialog::Accepted) {
2937 dest = ui.file_url->url().path();
2938 acceptPath = dest != source;
2939 if (acceptPath && QFileInfo(dest).size() > 0) {
2943 QString extraParams = ui.extra_params->toPlainText().simplified();
2944 KdenliveSettings::setAdd_new_clip(ui.add_clip->isChecked());
2947 QStringList jobParams;
2948 jobParams << dest << item->clipUrl().path() << timeIn << timeOut << QString::number(duration) << QString::number(KdenliveSettings::add_new_clip());
2949 if (!extraParams.isEmpty()) jobParams << extraParams;
2950 CutClipJob *job = new CutClipJob(item->clipType(), id, jobParams);
2951 if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
2955 m_jobList.append(job);
2956 setJobStatus(item, job->jobType, JobWaiting, 0, job->statusMessage());
2958 slotCheckJobProcess();
2961 void ProjectList::slotTranscodeClipJob(const QString &condition, QString params, QString desc)
2963 QStringList existingFiles;
2964 QMap <QString, QString> ids = getConditionalIds(condition);
2965 QMap<QString, QString>::const_iterator i = ids.constBegin();
2966 QStringList destinations;
2967 while (i != ids.constEnd()) {
2968 QString newFile = params.section(' ', -1).replace("%1", i.value());
2969 destinations << newFile;
2970 if (QFile::exists(newFile)) existingFiles << newFile;
2973 if (!existingFiles.isEmpty()) {
2974 if (KMessageBox::warningContinueCancelList(this, i18n("The transcoding job will overwrite the following files:"), existingFiles) == KMessageBox::Cancel) return;
2977 QDialog *d = new QDialog(this);
2978 Ui::CutJobDialog_UI ui;
2980 d->setWindowTitle(i18n("Transcoding"));
2981 ui.extra_params->setMaximumHeight(QFontMetrics(font()).lineSpacing() * 5);
2982 if (ids.count() == 1) {
2983 ui.file_url->setUrl(KUrl(destinations.first()));
2986 ui.destination_label->setVisible(false);
2987 ui.file_url->setVisible(false);
2989 ui.extra_params->setVisible(false);
2991 ui.button_more->setIcon(KIcon("configure"));
2992 ui.add_clip->setChecked(KdenliveSettings::add_new_clip());
2993 ui.extra_params->setPlainText(params.simplified().section(' ', 0, -2));
2994 QString mess = desc;
2995 mess.append(' ' + i18np("(%1 clip)", "(%1 clips)", ids.count()));
2996 ui.info_label->setText(mess);
2997 if (d->exec() != QDialog::Accepted) {
3001 params = ui.extra_params->toPlainText().simplified();
3002 KdenliveSettings::setAdd_new_clip(ui.add_clip->isChecked());
3004 i = ids.constBegin();
3005 while (i != ids.constEnd()) {
3006 ProjectItem *item = getItemById(i.key());
3007 if (!item || !item->referencedClip()) continue;
3008 QString src = i.value();
3010 if (ids.count() > 1) {
3011 dest = destinations.at(index);
3014 else dest = ui.file_url->url().path();
3015 QStringList jobParams;
3016 jobParams << dest << src << QString() << QString();
3017 double clipFps = item->referencedClip()->getProperty("fps").toDouble();
3018 if (clipFps == 0) clipFps = m_fps;
3019 int max = item->clipMaxDuration();
3020 QString duration = QString::number(max);
3021 jobParams << duration;
3022 jobParams << QString::number(KdenliveSettings::add_new_clip());
3023 jobParams << params;
3024 CutClipJob *job = new CutClipJob(item->clipType(), i.key(), jobParams);
3025 if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
3029 m_jobList.append(job);
3030 setJobStatus(item, job->jobType, JobWaiting, 0, job->statusMessage());
3034 slotCheckJobProcess();
3038 void ProjectList::slotCheckJobProcess()
3040 if (!m_jobThreads.futures().isEmpty()) {
3041 // Remove inactive threads
3042 QList <QFuture<void> > futures = m_jobThreads.futures();
3043 m_jobThreads.clearFutures();
3044 for (int i = 0; i < futures.count(); ++i)
3045 if (!futures.at(i).isFinished()) {
3046 m_jobThreads.addFuture(futures.at(i));
3049 if (m_jobList.isEmpty()) return;
3053 for (int i = 0; i < m_jobList.count(); ++i) {
3054 if (m_jobList.at(i)->status() == JobWorking || m_jobList.at(i)->status() == JobWaiting)
3057 // remove finished jobs
3058 AbstractClipJob *job = m_jobList.takeAt(i);
3063 emit jobCount(count);
3064 m_jobMutex.unlock();
3065 if (m_jobThreads.futures().isEmpty() || m_jobThreads.futures().count() < KdenliveSettings::proxythreads()) m_jobThreads.addFuture(QtConcurrent::run(this, &ProjectList::slotProcessJobs));
3068 void ProjectList::slotAbortProxy(const QString &id, const QString &path)
3072 ProjectItem *item = getItemById(id);
3074 if (!item->isProxyRunning()) slotGotProxy(item);
3075 item->setConditionalJobStatus(NoJob, PROXYJOB);
3076 discardJobs(id, PROXYJOB);
3079 void ProjectList::slotProcessJobs()
3081 while (!m_jobList.isEmpty() && !m_abortAllJobs) {
3082 emit projectModified();
3083 AbstractClipJob *job = NULL;
3086 for (int i = 0; i < m_jobList.count(); ++i) {
3087 if (m_jobList.at(i)->status() == JobWaiting) {
3089 m_jobList.at(i)->setStatus(JobWorking);
3090 job = m_jobList.at(i);
3094 else if (m_jobList.at(i)->status() == JobWorking)
3098 emit jobCount(count);
3099 m_jobMutex.unlock();
3104 QString destination = job->destination();
3105 // Check if the clip is still here
3106 DocClipBase *currentClip = m_doc->clipManager()->getClipById(job->clipId());
3107 //ProjectItem *processingItem = getItemById(job->clipId());
3108 if (currentClip == NULL) {
3109 job->setStatus(JobDone);
3112 // Set clip status to started
3113 emit processLog(job->clipId(), 0, job->jobType, job->statusMessage());
3115 // Make sure destination path is writable
3116 if (!destination.isEmpty()) {
3117 QFile file(destination);
3118 if (!file.open(QIODevice::WriteOnly)) {
3119 emit updateJobStatus(job->clipId(), job->jobType, JobCrashed, i18n("Cannot write to path: %1", destination));
3120 job->setStatus(JobCrashed);
3124 QFile::remove(destination);
3126 connect(job, SIGNAL(jobProgress(QString,int,int)), this, SIGNAL(processLog(QString,int,int)));
3127 connect(job, SIGNAL(cancelRunningJob(QString,stringMap)), this, SIGNAL(cancelRunningJob(QString,stringMap)));
3129 if (job->jobType == MLTJOB) {
3130 MeltJob *jb = static_cast<MeltJob *> (job);
3131 jb->setProducer(currentClip->getProducer(), currentClip->fileURL());
3132 if (jb->isProjectFilter())
3133 connect(job, SIGNAL(gotFilterJobResults(QString,int,int,stringMap,stringMap)), this, SLOT(slotGotFilterJobResults(QString,int,int,stringMap,stringMap)));
3135 connect(job, SIGNAL(gotFilterJobResults(QString,int,int,stringMap,stringMap)), this, SIGNAL(gotFilterJobResults(QString,int,int,stringMap,stringMap)));
3138 if (job->status() == JobDone) {
3139 emit updateJobStatus(job->clipId(), job->jobType, JobDone);
3140 //TODO: replace with more generic clip replacement framework
3141 if (job->jobType == PROXYJOB) emit gotProxy(job->clipId());
3142 if (job->addClipToProject()) {
3143 emit addClip(destination, QString(), QString());
3145 } else if (job->status() == JobCrashed || job->status() == JobAborted) {
3146 emit updateJobStatus(job->clipId(), job->jobType, job->status(), job->errorMessage(), QString(), job->logDetails());
3149 // Thread finished, cleanup & update count
3150 QTimer::singleShot(200, this, SIGNAL(checkJobProcess()));
3154 void ProjectList::updateProxyConfig()
3157 QTreeWidgetItemIterator it(m_listView);
3158 QUndoCommand *command = new QUndoCommand();
3159 command->setText(i18n("Update proxy settings"));
3160 QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/";
3162 if ((*it)->type() != ProjectClipType) {
3166 item = static_cast<ProjectItem *>(*it);
3171 ClipType t = item->clipType();
3172 if ((t == Video || t == AV || t == Unknown) && item->referencedClip() != NULL) {
3173 if (generateProxy() && useProxy() && !hasPendingJob(item, PROXYJOB)) {
3174 DocClipBase *clip = item->referencedClip();
3175 if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > m_doc->getDocumentProperty("proxyminsize").toInt()) {
3176 if (clip->getProperty("proxy").isEmpty()) {
3177 // We need to insert empty proxy in old properties so that undo will work
3178 QMap <QString, QString> oldProps;// = clip->properties();
3179 oldProps.insert("proxy", QString());
3180 QMap <QString, QString> newProps;
3181 newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + '.' + m_doc->getDocumentProperty("proxyextension"));
3182 new EditClipCommand(this, clip->getId(), oldProps, newProps, true, command);
3186 else if (item->hasProxy()) {
3188 QMap <QString, QString> newProps;
3189 newProps.insert("proxy", QString());
3190 // insert required duration for proxy
3191 newProps.insert("proxy_out", item->referencedClip()->producerProperty("out"));
3192 new EditClipCommand(this, item->clipId(), item->referencedClip()->currentProperties(newProps), newProps, true, command);
3195 else if (t == Image && item->referencedClip() != NULL) {
3196 if (generateImageProxy() && useProxy()) {
3197 DocClipBase *clip = item->referencedClip();
3198 int maxImageSize = m_doc->getDocumentProperty("proxyimageminsize").toInt();
3199 if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > maxImageSize || clip->getProperty("frame_size").section('x', 1, 1).toInt() > maxImageSize) {
3200 if (clip->getProperty("proxy").isEmpty()) {
3201 // We need to insert empty proxy in old properties so that undo will work
3202 QMap <QString, QString> oldProps = clip->properties();
3203 oldProps.insert("proxy", QString());
3204 QMap <QString, QString> newProps;
3205 newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + ".png");
3206 new EditClipCommand(this, clip->getId(), oldProps, newProps, true, command);
3210 else if (item->hasProxy()) {
3212 QMap <QString, QString> newProps;
3213 newProps.insert("proxy", QString());
3214 new EditClipCommand(this, item->clipId(), item->referencedClip()->properties(), newProps, true, command);
3219 if (command->childCount() > 0) m_doc->commandStack()->push(command);
3220 else delete command;
3223 void ProjectList::slotProcessLog(const QString &id, int progress, int type, const QString &message)
3225 ProjectItem *item = getItemById(id);
3226 setJobStatus(item, (JOBTYPE) type, JobWorking, progress, message);
3229 void ProjectList::slotProxyCurrentItem(bool doProxy, ProjectItem *itemToProxy)
3231 QList<QTreeWidgetItem *> list;
3232 if (itemToProxy == NULL) list = m_listView->selectedItems();
3233 else list << itemToProxy;
3235 // expand list (folders, subclips) to get real clips
3236 QTreeWidgetItem *listItem;
3237 QList<ProjectItem *> clipList;
3238 for (int i = 0; i < list.count(); ++i) {
3239 listItem = list.at(i);
3240 if (listItem->type() == ProjectFoldeType) {
3241 for (int j = 0; j < listItem->childCount(); j++) {
3242 QTreeWidgetItem *sub = listItem->child(j);
3243 if (sub->type() == ProjectClipType) {
3244 ProjectItem *item = static_cast <ProjectItem*>(sub);
3245 if (!clipList.contains(item)) clipList.append(item);
3249 else if (listItem->type() == ProjectSubclipType) {
3250 QTreeWidgetItem *sub = listItem->parent();
3251 ProjectItem *item = static_cast <ProjectItem*>(sub);
3252 if (!clipList.contains(item)) clipList.append(item);
3254 else if (listItem->type() == ProjectClipType) {
3255 ProjectItem *item = static_cast <ProjectItem*>(listItem);
3256 if (!clipList.contains(item)) clipList.append(item);
3260 QUndoCommand *command = new QUndoCommand();
3261 if (doProxy) command->setText(i18np("Add proxy clip", "Add proxy clips", clipList.count()));
3262 else command->setText(i18np("Remove proxy clip", "Remove proxy clips", clipList.count()));
3264 // Make sure the proxy folder exists
3265 QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/";
3266 KStandardDirs::makeDir(proxydir);
3268 QMap <QString, QString> newProps;
3269 QMap <QString, QString> oldProps;
3270 if (!doProxy) newProps.insert("proxy", "-");
3271 for (int i = 0; i < clipList.count(); ++i) {
3272 ProjectItem *item = clipList.at(i);
3273 ClipType t = item->clipType();
3274 if ((t == Video || t == AV || t == Unknown || t == Image || t == Playlist) && item->referencedClip()) {
3275 if ((doProxy && item->hasProxy()) || (!doProxy && !item->hasProxy() && item->referencedClip()->getProducer() != NULL)) continue;
3276 DocClipBase *clip = item->referencedClip();
3277 if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
3278 kDebug()<<"//// TRYING TO PROXY: "<<item->clipId()<<", but it is busy";
3282 //oldProps = clip->properties();
3285 QString path = proxydir + clip->getClipHash() + '.' + (t == Image ? "png" : m_doc->getDocumentProperty("proxyextension"));
3286 // insert required duration for proxy
3287 newProps.insert("proxy_out", clip->producerProperty("out"));
3288 newProps.insert("proxy", path);
3289 // We need to insert empty proxy so that undo will work
3290 //oldProps.insert("proxy", QString());
3292 else if (item->referencedClip()->getProducer() == NULL) {
3293 // Force clip reload
3294 kDebug()<<"// CLIP HAD NULL PROD------------";
3295 newProps.insert("resource", item->referencedClip()->getProperty("resource"));
3297 // We need to insert empty proxy so that undo will work
3298 oldProps = clip->currentProperties(newProps);
3299 if (doProxy) oldProps.insert("proxy", "-");
3300 new EditClipCommand(this, item->clipId(), oldProps, newProps, true, command);
3303 if (command->childCount() > 0) {
3304 m_doc->commandStack()->push(command);
3306 else delete command;
3310 void ProjectList::slotDeleteProxy(const QString proxyPath)
3312 if (proxyPath.isEmpty()) return;
3313 QUndoCommand *proxyCommand = new QUndoCommand();
3314 proxyCommand->setText(i18n("Remove Proxy"));
3315 QTreeWidgetItemIterator it(m_listView);
3318 if ((*it)->type() == ProjectClipType) {
3319 item = static_cast <ProjectItem *>(*it);
3320 if (item->referencedClip()->getProperty("proxy") == proxyPath) {
3321 QMap <QString, QString> props;
3322 props.insert("proxy", QString());
3323 new EditClipCommand(this, item->clipId(), item->referencedClip()->currentProperties(props), props, true, proxyCommand);
3329 if (proxyCommand->childCount() == 0)
3330 delete proxyCommand;
3332 m_commandStack->push(proxyCommand);
3333 QFile::remove(proxyPath);
3336 void ProjectList::setJobStatus(ProjectItem *item, JOBTYPE jobType, ClipJobStatus status, int progress, const QString &statusMessage)
3338 if (item == NULL || (m_abortAllJobs && m_closing)) return;
3339 monitorItemEditing(false);
3340 item->setJobStatus(jobType, status, progress, statusMessage);
3341 if (status == JobCrashed) {
3342 DocClipBase *clip = item->referencedClip();
3344 kDebug()<<"// PROXY CRASHED";
3346 else if (clip->getProducer() == NULL && !clip->isPlaceHolder()) {
3347 // disable proxy and fetch real clip
3348 clip->setProperty("proxy", "-");
3349 QDomElement xml = clip->toXML();
3350 m_render->getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), true);
3353 // Disable proxy for this clip
3354 clip->setProperty("proxy", "-");
3357 monitorItemEditing(true);
3360 void ProjectList::monitorItemEditing(bool enable)
3362 if (enable) connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(slotItemEdited(QTreeWidgetItem*,int)));
3363 else disconnect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(slotItemEdited(QTreeWidgetItem*,int)));
3366 QStringList ProjectList::expandedFolders() const
3369 FolderProjectItem *item;
3370 QTreeWidgetItemIterator it(m_listView);
3372 if ((*it)->type() != ProjectFoldeType) {
3376 if ((*it)->isExpanded()) {
3377 item = static_cast<FolderProjectItem *>(*it);
3378 result.append(item->clipId());
3385 void ProjectList::processThumbOverlays(ProjectItem *item, QPixmap &pix)
3387 if (item->hasProxy()) {
3389 QColor c(220, 220, 10, 200);
3390 QRect r(0, 0, 12, 12);
3392 QFont font = p.font();
3395 p.setPen(Qt::black);
3396 p.drawText(r, Qt::AlignCenter, i18nc("The first letter of Proxy, used as abbreviation", "P"));
3400 void ProjectList::slotCancelJobs()
3402 m_abortAllJobs = true;
3403 for (int i = 0; i < m_jobList.count(); ++i) {
3404 m_jobList.at(i)->setStatus(JobAborted);
3406 m_jobThreads.waitForFinished();
3407 m_jobThreads.clearFutures();
3408 QUndoCommand *command = new QUndoCommand();
3409 command->setText(i18np("Cancel job", "Cancel jobs", m_jobList.count()));
3411 for (int i = 0; i < m_jobList.count(); ++i) {
3412 DocClipBase *currentClip = m_doc->clipManager()->getClipById(m_jobList.at(i)->clipId());
3413 if (!currentClip) continue;
3414 QMap <QString, QString> newProps = m_jobList.at(i)->cancelProperties();
3415 if (newProps.isEmpty()) continue;
3416 QMap <QString, QString> oldProps = currentClip->currentProperties(newProps);
3417 new EditClipCommand(this, m_jobList.at(i)->clipId(), oldProps, newProps, true, command);
3419 m_jobMutex.unlock();
3420 if (command->childCount() > 0) {
3421 m_doc->commandStack()->push(command);
3423 else delete command;
3424 if (!m_jobList.isEmpty()) qDeleteAll(m_jobList);
3426 m_abortAllJobs = false;
3427 m_infoLabel->slotSetJobCount(0);
3430 void ProjectList::slotCancelRunningJob(const QString id, stringMap newProps)
3432 if (newProps.isEmpty() || m_closing) return;
3433 DocClipBase *currentClip = m_doc->clipManager()->getClipById(id);
3434 if (!currentClip) return;
3435 QMap <QString, QString> oldProps = currentClip->currentProperties(newProps);
3436 if (newProps == oldProps) return;
3437 QMapIterator<QString, QString> i(oldProps);
3438 EditClipCommand *command = new EditClipCommand(this, id, oldProps, newProps, true);
3439 m_commandStack->push(command);
3442 bool ProjectList::hasPendingJob(ProjectItem *item, JOBTYPE type)
3444 if (!item || !item->referencedClip() || m_abortAllJobs) return false;
3445 AbstractClipJob *job;
3446 QMutexLocker lock(&m_jobMutex);
3447 for (int i = 0; i < m_jobList.count(); ++i) {
3448 if (m_abortAllJobs) break;
3449 job = m_jobList.at(i);
3450 if (job->clipId() == item->clipId() && job->jobType == type && (job->status() == JobWaiting || job->status() == JobWorking)) return true;
3456 void ProjectList::deleteJobsForClip(const QString &clipId)
3458 QMutexLocker lock(&m_jobMutex);
3459 for (int i = 0; i < m_jobList.count(); ++i) {
3460 if (m_jobList.at(i)->clipId() == clipId) {
3461 m_jobList.at(i)->setStatus(JobAborted);
3466 void ProjectList::slotUpdateJobStatus(const QString id, int type, int status, const QString label, const QString actionName, const QString details)
3468 ProjectItem *item = getItemById(id);
3470 slotUpdateJobStatus(item, type, status, label, actionName, details);
3474 void ProjectList::slotUpdateJobStatus(ProjectItem *item, int type, int status, const QString &label, const QString &actionName, const QString details)
3476 item->setJobStatus((JOBTYPE) type, (ClipJobStatus) status);
3477 if (status != JobCrashed) return;
3478 #if KDE_IS_VERSION(4,7,0)
3479 QList<QAction *> actions = m_infoMessage->actions();
3480 if (m_infoMessage->isHidden()) {
3481 m_infoMessage->setText(label);
3482 m_infoMessage->setWordWrap(m_infoMessage->text().length() > 35);
3483 m_infoMessage->setMessageType(KMessageWidget::Warning);
3486 if (!actionName.isEmpty()) {
3487 QAction *action = NULL;
3488 QList< KActionCollection * > collections = KActionCollection::allCollections();
3489 for (int i = 0; i < collections.count(); ++i) {
3490 KActionCollection *coll = collections.at(i);
3491 action = coll->action(actionName);
3494 if (action && !actions.contains(action)) m_infoMessage->addAction(action);
3496 if (!details.isEmpty()) {
3497 m_errorLog.append(details);
3498 if (!actions.contains(m_logAction)) m_infoMessage->addAction(m_logAction);
3500 m_infoMessage->animatedShow();
3502 // warning for KDE < 4.7
3503 KPassivePopup *passivePop = new KPassivePopup( this );
3504 passivePop->setAutoDelete(true);
3505 connect(passivePop, SIGNAL(clicked()), this, SLOT(slotClosePopup()));
3506 m_errorLog.append(details);
3507 KVBox *vb = new KVBox( passivePop );
3508 KHBox *vh1 = new KHBox( vb );
3509 KIcon icon("dialog-warning");
3510 QLabel *iconLabel = new QLabel(vh1);
3511 iconLabel->setPixmap(icon.pixmap(m_listView->iconSize()));
3512 (void) new QLabel( label, vh1);
3513 KHBox *box = new KHBox( vb );
3514 QPushButton *but = new QPushButton( "Show log", box );
3515 connect(but, SIGNAL(clicked(bool)), this, SLOT(slotShowJobLog()));
3517 passivePop->setView( vb );
3523 void ProjectList::slotShowJobLog()
3526 d.setButtons(KDialog::Close);
3528 for (int i = 0; i < m_errorLog.count(); ++i) {
3529 if (i > 0) t.insertHtml("<br><hr /><br>");
3530 t.insertPlainText(m_errorLog.at(i));
3532 t.setReadOnly(true);
3533 d.setMainWidget(&t);
3537 QStringList ProjectList::getPendingJobs(const QString &id)
3540 QMutexLocker lock(&m_jobMutex);
3541 for (int i = 0; i < m_jobList.count(); ++i) {
3542 if (m_jobList.at(i)->clipId() == id && (m_jobList.at(i)->status() == JobWaiting || m_jobList.at(i)->status() == JobWorking)) {
3544 result << m_jobList.at(i)->description;
3550 void ProjectList::discardJobs(const QString &id, JOBTYPE type) {
3551 QMutexLocker lock(&m_jobMutex);
3552 for (int i = 0; i < m_jobList.count(); ++i) {
3553 if (m_jobList.at(i)->clipId() == id && (m_jobList.at(i)->jobType == type || type == NOJOBTYPE)) {
3555 m_jobList.at(i)->setStatus(JobAborted);
3560 void ProjectList::slotStartFilterJob(ItemInfo info, const QString&id, const QString&filterName, const QString&filterParams, const QString&consumer, const QString&consumerParams, const QMap <QString, QString> &extraParams)
3562 ProjectItem *item = getItemById(id);
3564 QStringList jobParams;
3565 jobParams << QString::number((int) info.cropStart.frames(m_fps)) << QString::number((int) (info.cropStart + info.cropDuration).frames(m_fps));
3566 jobParams << QString() << filterName << filterParams << consumer << consumerParams << QString::number((int) info.startPos.frames(m_fps)) << QString::number(info.track);
3567 MeltJob *job = new MeltJob(item->clipType(), id, jobParams, extraParams);
3568 if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
3572 job->description = i18n("Filter %1", extraParams.value("finalfilter"));
3573 m_jobList.append(job);
3574 setJobStatus(item, job->jobType, JobWaiting, 0, job->statusMessage());
3575 slotCheckJobProcess();
3578 void ProjectList::startClipFilterJob(const QString &filterName, const QString &condition)
3580 QMap <QString, QString> ids = getConditionalIds(condition);
3581 QStringList destination;
3582 QMap<QString, QString>::const_iterator first = ids.constBegin();
3583 if (first == ids.constEnd()) {
3584 emit displayMessage(i18n("Cannot find clip to process filter %1", filterName), -2, ErrorMessage);
3587 ProjectItem *item = getItemById(first.key());
3589 emit displayMessage(i18n("Cannot find clip to process filter %1", filterName), -2, ErrorMessage);
3592 if (ids.count() == 1) {
3593 destination << item->clipUrl().path();
3596 destination = ids.values();
3598 if (filterName == "framebuffer") {
3599 Mlt::Profile profile;
3600 QStringList keys = ids.keys();
3602 foreach(const QString &url, destination) {
3603 QString prodstring = QString("framebuffer:" + url + "?-1");
3604 Mlt::Producer *reversed = new Mlt::Producer(profile, prodstring.toUtf8().constData());
3605 if (!reversed || !reversed->is_valid()) {
3606 emit displayMessage(i18n("Cannot reverse clip"), -2, ErrorMessage);
3609 QString dest = url + ".mlt";
3610 if (QFile::exists(dest)) {
3611 if (KMessageBox::questionYesNo(this, i18n("File %1 already exists.\nDo you want to overwrite it?", dest)) == KMessageBox::No) continue;
3613 Mlt::Consumer *cons = new Mlt::Consumer(profile, "xml", dest.toUtf8().constData());
3614 if (cons == NULL || !cons->is_valid()) {
3615 emit displayMessage(i18n("Cannot render reversed clip"), -2, ErrorMessage);
3619 list.insert_at(0, reversed, 0);
3621 cons->connect(list);
3626 DocClipBase *base = m_doc->clipManager()->getClipById(keys.at(ix));
3628 groupId = base->getProperty("groupid");
3629 groupName = base->getProperty("groupname");
3631 emit addClip(dest, groupId, groupName);
3637 if (filterName == "motion_est") {
3638 // Show config dialog
3639 QPointer<QDialog> d = new QDialog(this);
3640 Ui::SceneCutDialog_UI ui;
3642 // Set up categories
3643 for (int i = 0; i < 5; ++i) {
3644 ui.marker_type->insertItem(i, i18n("Category %1", i));
3645 ui.marker_type->setItemData(i, CommentedTime::markerColor(i), Qt::DecorationRole);
3647 ui.marker_type->setCurrentIndex(KdenliveSettings::default_marker_type());
3648 if (d->exec() != QDialog::Accepted) {
3653 QStringList jobParams;
3655 jobParams << QString();
3656 // Filter params, use a smaller region of the image to speed up operation
3657 // In fact, it's faster to rescale whole image than using part of it (bounding=\"25%x25%:15%x15\")
3658 jobParams << filterName << "shot_change_list=0 denoise=0";
3660 jobParams << "null" << "all=1 terminate_on_pause=1 real_time=-1 rescale=nearest deinterlace_method=onefield top_field_first=-1";
3661 QMap <QString, QString> extraParams;
3662 extraParams.insert("key", "shot_change_list");
3663 extraParams.insert("projecttreefilter", "1");
3664 QString keyword("%count");
3665 extraParams.insert("resultmessage", i18n("Found %1 scenes.", keyword));
3666 extraParams.insert("resize_profile", "160");
3667 if (ui.store_data->isChecked()) {
3668 // We want to save result as clip metadata
3669 extraParams.insert("storedata", "1");
3671 if (ui.zone_only->isChecked()) {
3672 // We want to analyze only clip zone
3673 extraParams.insert("zoneonly", "1");
3675 if (ui.add_markers->isChecked()) {
3676 // We want to create markers
3677 extraParams.insert("addmarkers", QString::number(ui.marker_type->currentIndex()));
3679 if (ui.cut_scenes->isChecked()) {
3680 // We want to cut scenes
3681 extraParams.insert("cutscenes", "1");
3684 processClipJob(ids.keys(), QString(), false, jobParams, i18n("Auto split"), extraParams);
3687 QPointer<ClipStabilize> d = new ClipStabilize(destination, filterName);
3688 if (d->exec() == QDialog::Accepted) {
3689 QMap <QString, QString> extraParams;
3690 extraParams.insert("producer_profile", "1");
3691 processClipJob(ids.keys(), d->destination(), d->autoAddClip(), d->params(), d->desc(), extraParams);
3697 void ProjectList::processClipJob(QStringList ids, const QString&destination, bool autoAdd, QStringList jobParams, const QString &description, QMap <QString, QString> extraParams)
3699 QStringList preParams;
3701 preParams << QString::number(0) << QString::number(-1);
3703 preParams << jobParams.takeFirst();
3705 preParams << jobParams.takeFirst();
3707 preParams << jobParams.takeFirst();
3709 QString consumer = jobParams.takeFirst();
3711 foreach(const QString&id, ids) {
3712 ProjectItem *item = getItemById(id);
3713 if (!item) continue;
3714 QStringList jobArgs;
3715 if (extraParams.contains("zoneonly")) {
3716 // Analyse clip zone only, remove in / out and replace with zone
3717 preParams.takeFirst();
3718 preParams.takeFirst();
3719 QPoint zone = item->referencedClip()->zone();
3720 jobArgs << QString::number(zone.x()) << QString::number(zone.y());
3722 jobArgs << preParams;
3723 if (ids.count() == 1) {
3724 jobArgs << consumer + ':' + destination;
3727 jobArgs << consumer + ':' + destination + item->clipUrl().fileName() + ".mlt";
3729 jobArgs << jobParams;
3731 MeltJob *job = new MeltJob(item->clipType(), id, jobArgs, extraParams);
3733 job->setAddClipToProject(true);
3734 kDebug()<<"// ADDING TRUE";
3736 else kDebug()<<"// ADDING FALSE!!!";
3738 if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
3742 job->description = description;
3743 m_jobList.append(job);
3744 setJobStatus(item, job->jobType, JobWaiting, 0, job->statusMessage());
3745 slotCheckJobProcess();
3750 void ProjectList::slotPrepareJobsMenu()
3753 if (!m_listView->currentItem() || m_listView->currentItem()->type() == ProjectFoldeType)
3755 if (m_listView->currentItem()->type() == ProjectSubclipType)
3756 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
3758 item = static_cast <ProjectItem*>(m_listView->currentItem());
3759 if (item && (item->flags() & Qt::ItemIsDragEnabled)) {
3760 QString id = item->clipId();
3761 m_discardCurrentClipJobs->setData(id);
3762 QStringList jobs = getPendingJobs(id);
3763 m_discardCurrentClipJobs->setEnabled(!jobs.isEmpty());
3765 m_discardCurrentClipJobs->setData(QString());
3766 m_discardCurrentClipJobs->setEnabled(false);
3770 void ProjectList::slotDiscardClipJobs()
3772 QString id = m_discardCurrentClipJobs->data().toString();
3773 if (id.isEmpty()) return;
3777 void ProjectList::updatePalette()
3779 m_infoLabel->setStyleSheet(SmallInfoLabel::getStyleSheet(QApplication::palette()));
3780 m_listView->updateStyleSheet();
3783 void ProjectList::slotResetInfoMessage()
3785 #if KDE_IS_VERSION(4,7,0)
3787 QList<QAction *> actions = m_infoMessage->actions();
3788 for (int i = 0; i < actions.count(); ++i) {
3789 m_infoMessage->removeAction(actions.at(i));
3794 void ProjectList::slotClosePopup()
3799 void ProjectList::slotGotFilterJobResults(QString id, int , int , stringMap results, stringMap filterInfo)
3801 // Currently, only the first value of results is used
3802 //kDebug()<<"// FILTER RES:\n"<<filterInfo<<"\n--------------\n"<<results;
3803 ProjectItem *clip = getItemById(id);
3806 // Check for return value
3807 int markersType = -1;
3808 if (filterInfo.contains("addmarkers")) markersType = filterInfo.value("addmarkers").toInt();
3809 if (results.isEmpty()) {
3810 emit displayMessage(i18n("No data returned from clip analysis"), 0, ErrorMessage);
3813 bool dataProcessed = false;
3814 QString key = filterInfo.value("key");
3815 int offset = filterInfo.value("offset").toInt();
3816 QStringList value = results.value(key).split(';', QString::SkipEmptyParts);
3817 kDebug()<<"// RESULT; "<<key<<" = "<<value;
3818 if (filterInfo.contains("resultmessage")) {
3819 QString mess = filterInfo.value("resultmessage");
3820 mess.replace("%count", QString::number(value.count()));
3821 emit displayMessage(mess, 0, InformationMessage);
3823 else emit displayMessage(i18n("Processing data analysis"), 0, InformationMessage);
3824 if (filterInfo.contains("cutscenes")) {
3825 // Check if we want to cut scenes from returned data
3826 dataProcessed = true;
3828 QUndoCommand *command = new QUndoCommand();
3829 command->setText(i18n("Auto Split Clip"));
3830 foreach (QString pos, value) {
3831 if (!pos.contains("=")) continue;
3832 int newPos = pos.section("=", 0, 0).toInt();
3833 // Don't use scenes shorter than 1 second
3834 if (newPos - cutPos < 24) continue;
3835 (void) new AddClipCutCommand(this, id, cutPos + offset, newPos + offset, QString(), true, false, command);
3838 if (command->childCount() == 0)
3840 else m_commandStack->push(command);
3842 if (markersType >= 0) {
3843 // Add markers from returned data
3844 dataProcessed = true;
3846 QUndoCommand *command = new QUndoCommand();
3847 command->setText(i18n("Add Markers"));
3848 QList <CommentedTime> markersList;
3850 foreach (QString pos, value) {
3851 if (!pos.contains("=")) continue;
3852 int newPos = pos.section("=", 0, 0).toInt();
3853 // Don't use scenes shorter than 1 second
3854 if (newPos - cutPos < 24) continue;
3855 CommentedTime m(GenTime(newPos + offset, m_fps), QString::number(index), markersType);
3860 emit addMarkers(id, markersList);
3862 if (!dataProcessed || filterInfo.contains("storedata")) {
3863 // Store returned data as clip extra data
3864 clip->referencedClip()->setAnalysisData(filterInfo.contains("displaydataname") ? filterInfo.value("displaydataname") : key, results.value(key), filterInfo.value("offset").toInt());
3865 emit updateAnalysisData(clip->referencedClip());
3871 // Work in progress: apply filter based on clip's camcorder
3872 void ProjectList::checkCamcorderFilters(DocClipBase *clip, QMap <QString, QString> meta)
3874 KConfig conf("camcorderfilters.rc", KConfig::CascadeConfig, "appdata");
3875 QStringList groups = conf.groupList();
3876 foreach(QString grp, groups) {
3877 if (!meta.contains(grp)) continue;
3878 KConfigGroup group(&conf, grp);
3879 QString value = group.readEntry(meta.value(grp));
3880 if (value.isEmpty()) continue;
3881 clip->setProperty(value.section(' ', 0, 0), value.section(' ', 1));
3886 #include "projectlist.moc"