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 "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"
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 #include <QMouseEvent>
73 #include <QStylePainter>
79 #include <QHeaderView>
80 #include <QInputDialog>
81 #include <QtConcurrentRun>
82 #include <QVBoxLayout>
83 #include <KPassivePopup>
86 MyMessageWidget::MyMessageWidget(QWidget *parent) : KMessageWidget(parent) {}
87 MyMessageWidget::MyMessageWidget(const QString &text, QWidget *parent) : KMessageWidget(text, parent) {}
90 bool MyMessageWidget::event(QEvent* ev) {
91 if (ev->type() == QEvent::Hide || ev->type() == QEvent::Close) emit messageClosing();
92 return KMessageWidget::event(ev);
95 SmallInfoLabel::SmallInfoLabel(QWidget *parent) : QPushButton(parent)
100 /*QString style = "QToolButton {background-color: %1;border-style: outset;border-width: 2px;
101 border-radius: 5px;border-color: beige;}";*/
102 m_timeLine = new QTimeLine(500, this);
103 QObject::connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(slotTimeLineChanged(qreal)));
104 QObject::connect(m_timeLine, SIGNAL(finished()), this, SLOT(slotTimeLineFinished()));
108 const QString SmallInfoLabel::getStyleSheet(const QPalette &p)
110 KColorScheme scheme(p.currentColorGroup(), KColorScheme::Window, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
111 QColor bg = scheme.background(KColorScheme::LinkBackground).color();
112 QColor fg = scheme.foreground(KColorScheme::LinkText).color();
113 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());
115 bg = scheme.background(KColorScheme::ActiveBackground).color();
116 fg = scheme.foreground(KColorScheme::ActiveText).color();
117 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()));
122 void SmallInfoLabel::slotTimeLineChanged(qreal value)
124 setFixedWidth(qMin(value * 2, qreal(1.0)) * sizeHint().width());
128 void SmallInfoLabel::slotTimeLineFinished()
130 if (m_timeLine->direction() == QTimeLine::Forward) {
140 void SmallInfoLabel::slotSetJobCount(int jobCount)
144 setText(i18np("%1 job", "%1 jobs", jobCount));
145 setToolTip(i18np("%1 pending job", "%1 pending jobs", jobCount));
147 if (!(KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects)) {
148 setFixedWidth(sizeHint().width());
154 setFixedWidth(sizeHint().width());
161 int wantedWidth = sizeHint().width();
162 setGeometry(-wantedWidth, 0, wantedWidth, height());
163 m_timeLine->setDirection(QTimeLine::Forward);
164 if (m_timeLine->state() == QTimeLine::NotRunning) {
169 if (!(KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects)) {
175 m_timeLine->setDirection(QTimeLine::Backward);
176 if (m_timeLine->state() == QTimeLine::NotRunning) {
184 InvalidDialog::InvalidDialog(const QString &caption, const QString &message, bool infoOnly, QWidget *parent) : KDialog(parent)
187 if (infoOnly) setButtons(KDialog::Ok);
188 else setButtons(KDialog::Yes | KDialog::No);
189 QWidget *w = new QWidget(this);
190 QVBoxLayout *l = new QVBoxLayout;
191 l->addWidget(new QLabel(message));
192 m_clipList = new QListWidget;
193 l->addWidget(m_clipList);
198 InvalidDialog::~InvalidDialog()
204 void InvalidDialog::addClip(const QString &id, const QString &path)
206 QListWidgetItem *item = new QListWidgetItem(path);
207 item->setData(Qt::UserRole, id);
208 m_clipList->addItem(item);
211 QStringList InvalidDialog::getIds() const
214 for (int i = 0; i < m_clipList->count(); i++) {
215 ids << m_clipList->item(i)->data(Qt::UserRole).toString();
221 ProjectList::ProjectList(QWidget *parent) :
225 m_commandStack(NULL),
227 m_reloadAction(NULL),
228 m_extractAudioAction(NULL),
229 m_transcodeAction(NULL),
230 m_stabilizeAction(NULL),
233 m_allClipsProcessed(false),
235 m_abortAllJobs(false),
237 m_invalidClipDialog(NULL)
239 qRegisterMetaType<stringMap> ("stringMap");
240 QVBoxLayout *layout = new QVBoxLayout;
241 layout->setContentsMargins(0, 0, 0, 0);
242 layout->setSpacing(0);
243 qRegisterMetaType<QDomElement>("QDomElement");
245 QFrame *frame = new QFrame;
246 frame->setFrameStyle(QFrame::NoFrame);
247 QHBoxLayout *box = new QHBoxLayout;
248 box->setContentsMargins(0, 0, 0, 0);
250 KTreeWidgetSearchLine *searchView = new KTreeWidgetSearchLine;
251 box->addWidget(searchView);
253 // small info button for pending jobs
254 m_infoLabel = new SmallInfoLabel(this);
255 m_infoLabel->setStyleSheet(SmallInfoLabel::getStyleSheet(palette()));
256 connect(this, SIGNAL(jobCount(int)), m_infoLabel, SLOT(slotSetJobCount(int)));
257 m_jobsMenu = new QMenu(this);
258 connect(m_jobsMenu, SIGNAL(aboutToShow()), this, SLOT(slotPrepareJobsMenu()));
259 QAction *cancelJobs = new QAction(i18n("Cancel All Jobs"), this);
260 cancelJobs->setCheckable(false);
261 connect(cancelJobs, SIGNAL(triggered()), this, SLOT(slotCancelJobs()));
262 connect(this, SIGNAL(checkJobProcess()), this, SLOT(slotCheckJobProcess()));
263 m_discardCurrentClipJobs = new QAction(i18n("Cancel Current Clip Jobs"), this);
264 m_discardCurrentClipJobs->setCheckable(false);
265 connect(m_discardCurrentClipJobs, SIGNAL(triggered()), this, SLOT(slotDiscardClipJobs()));
266 m_jobsMenu->addAction(cancelJobs);
267 m_jobsMenu->addAction(m_discardCurrentClipJobs);
268 m_infoLabel->setMenu(m_jobsMenu);
269 box->addWidget(m_infoLabel);
271 int size = style()->pixelMetric(QStyle::PM_SmallIconSize);
272 QSize iconSize(size, size);
274 m_addButton = new QToolButton;
275 m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
276 m_addButton->setAutoRaise(true);
277 m_addButton->setIconSize(iconSize);
278 box->addWidget(m_addButton);
280 m_editButton = new QToolButton;
281 m_editButton->setAutoRaise(true);
282 m_editButton->setIconSize(iconSize);
283 box->addWidget(m_editButton);
285 m_deleteButton = new QToolButton;
286 m_deleteButton->setAutoRaise(true);
287 m_deleteButton->setIconSize(iconSize);
288 box->addWidget(m_deleteButton);
289 frame->setLayout(box);
290 layout->addWidget(frame);
292 m_listView = new ProjectListView(this);
293 layout->addWidget(m_listView);
295 #if KDE_IS_VERSION(4,7,0)
296 m_infoMessage = new MyMessageWidget;
297 layout->addWidget(m_infoMessage);
298 m_infoMessage->setCloseButtonVisible(true);
299 connect(m_infoMessage, SIGNAL(messageClosing()), this, SLOT(slotResetInfoMessage()));
300 //m_infoMessage->setWordWrap(true);
301 m_infoMessage->hide();
302 m_logAction = new QAction(i18n("Show Log"), this);
303 m_logAction->setCheckable(false);
304 connect(m_logAction, SIGNAL(triggered()), this, SLOT(slotShowJobLog()));
308 searchView->setTreeWidget(m_listView);
310 connect(this, SIGNAL(processNextThumbnail()), this, SLOT(slotProcessNextThumbnail()));
311 connect(m_listView, SIGNAL(projectModified()), this, SIGNAL(projectModified()));
312 connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
313 connect(m_listView, SIGNAL(focusMonitor(bool)), this, SIGNAL(raiseClipMonitor(bool)));
314 connect(m_listView, SIGNAL(pauseMonitor()), this, SIGNAL(pauseMonitor()));
315 connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
316 connect(m_listView, SIGNAL(addClip()), this, SIGNAL(pauseMonitor()));
317 connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
318 connect(m_listView, SIGNAL(addClip(const QList <QUrl>, const QString &, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &, const QString &)));
319 connect(this, SIGNAL(addClip(const QString, const QString &, const QString &)), this, SLOT(slotAddClip(const QString, const QString &, const QString &)));
320 connect(m_listView, SIGNAL(addClipCut(const QString &, int, int)), this, SLOT(slotAddClipCut(const QString &, int, int)));
321 connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
322 connect(m_listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
324 connect(this, SIGNAL(cancelRunningJob(const QString, stringMap )), this, SLOT(slotCancelRunningJob(const QString, stringMap)));
325 connect(this, SIGNAL(processLog(const QString, int , int, const QString)), this, SLOT(slotProcessLog(const QString, int , int, const QString)));
327 connect(this, SIGNAL(updateJobStatus(const QString, int, int, const QString, const QString, const QString)), this, SLOT(slotUpdateJobStatus(const QString, int, int, const QString, const QString, const QString)));
329 connect(this, SIGNAL(gotProxy(const QString)), this, SLOT(slotGotProxyForId(const QString)));
331 m_listViewDelegate = new ItemDelegate(m_listView);
332 m_listView->setItemDelegate(m_listViewDelegate);
334 if (KdenliveSettings::activate_nepomuk()) {
335 Nepomuk::ResourceManager::instance()->init();
336 if (!Nepomuk::ResourceManager::instance()->initialized()) {
337 kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
338 KdenliveSettings::setActivate_nepomuk(false);
344 ProjectList::~ProjectList()
346 m_abortAllJobs = true;
347 for (int i = 0; i < m_jobList.count(); i++) {
348 m_jobList.at(i)->setStatus(JOBABORTED);
351 m_thumbnailQueue.clear();
352 m_jobThreads.waitForFinished();
353 m_jobThreads.clearFutures();
354 if (!m_jobList.isEmpty()) qDeleteAll(m_jobList);
357 m_listView->blockSignals(true);
359 delete m_listViewDelegate;
360 #if KDE_IS_VERSION(4,7,0)
361 delete m_infoMessage;
365 void ProjectList::focusTree() const
367 m_listView->setFocus();
370 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
372 QList <QAction *> actions = addMenu->actions();
373 for (int i = 0; i < actions.count(); i++) {
374 if (actions.at(i)->data().toString() == "clip_properties") {
375 m_editButton->setDefaultAction(actions.at(i));
378 } else if (actions.at(i)->data().toString() == "delete_clip") {
379 m_deleteButton->setDefaultAction(actions.at(i));
382 } else if (actions.at(i)->data().toString() == "edit_clip") {
383 m_openAction = actions.at(i);
386 } else if (actions.at(i)->data().toString() == "reload_clip") {
387 m_reloadAction = actions.at(i);
390 } else if (actions.at(i)->data().toString() == "proxy_clip") {
391 m_proxyAction = actions.at(i);
397 QMenu *m = new QMenu();
398 m->addActions(actions);
399 m_addButton->setMenu(m);
400 m_addButton->setDefaultAction(defaultAction);
401 m_menu = new QMenu();
402 m_menu->addActions(addMenu->actions());
405 void ProjectList::setupGeneratorMenu(const QHash<QString,QMenu*>& menus)
407 if (!menus.contains("addMenu") && ! menus.value("addMenu") )
409 QMenu *menu = m_addButton->menu();
410 if (menus.contains("addMenu") && menus.value("addMenu")){
411 QMenu* addMenu=menus.value("addMenu");
412 menu->addMenu(addMenu);
413 m_addButton->setMenu(menu);
414 if (addMenu->isEmpty())
415 addMenu->setEnabled(false);
417 if (menus.contains("extractAudioMenu") && menus.value("extractAudioMenu") ){
418 QMenu* extractAudioMenu = menus.value("extractAudioMenu");
419 m_menu->addMenu(extractAudioMenu);
420 m_extractAudioAction = extractAudioMenu;
422 if (menus.contains("transcodeMenu") && menus.value("transcodeMenu") ){
423 QMenu* transcodeMenu = menus.value("transcodeMenu");
424 m_menu->addMenu(transcodeMenu);
425 if (transcodeMenu->isEmpty())
426 transcodeMenu->setEnabled(false);
427 m_transcodeAction = transcodeMenu;
429 if (menus.contains("clipActionsMenu") && menus.value("clipActionsMenu") ){
430 QMenu* stabilizeMenu=menus.value("clipActionsMenu");
431 m_menu->addMenu(stabilizeMenu);
432 if (stabilizeMenu->isEmpty())
433 stabilizeMenu->setEnabled(false);
434 m_stabilizeAction=stabilizeMenu;
437 m_menu->addAction(m_reloadAction);
438 m_menu->addAction(m_proxyAction);
439 if (menus.contains("inTimelineMenu") && menus.value("inTimelineMenu")){
440 QMenu* inTimelineMenu=menus.value("inTimelineMenu");
441 m_menu->addMenu(inTimelineMenu);
442 inTimelineMenu->setEnabled(false);
444 m_menu->addAction(m_editButton->defaultAction());
445 m_menu->addAction(m_openAction);
446 m_menu->addAction(m_deleteButton->defaultAction());
447 m_menu->insertSeparator(m_deleteButton->defaultAction());
450 void ProjectList::clearSelection()
452 m_listView->clearSelection();
455 QByteArray ProjectList::headerInfo() const
457 return m_listView->header()->saveState();
460 void ProjectList::setHeaderInfo(const QByteArray &state)
462 m_listView->header()->restoreState(state);
465 void ProjectList::updateProjectFormat(Timecode t)
470 void ProjectList::slotEditClip()
472 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
473 if (list.isEmpty()) return;
474 if (list.count() > 1 || list.at(0)->type() == PROJECTFOLDERTYPE) {
475 editClipSelection(list);
479 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
481 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE)
482 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
484 item = static_cast <ProjectItem*>(m_listView->currentItem());
485 if (item && (item->flags() & Qt::ItemIsDragEnabled)) {
486 emit clipSelected(item->referencedClip());
487 emit showClipProperties(item->referencedClip());
491 void ProjectList::editClipSelection(QList<QTreeWidgetItem *> list)
493 // Gather all common properties
494 QMap <QString, QString> commonproperties;
495 QList <DocClipBase *> clipList;
496 commonproperties.insert("force_aspect_num", "-");
497 commonproperties.insert("force_aspect_den", "-");
498 commonproperties.insert("force_fps", "-");
499 commonproperties.insert("force_progressive", "-");
500 commonproperties.insert("force_tff", "-");
501 commonproperties.insert("threads", "-");
502 commonproperties.insert("video_index", "-");
503 commonproperties.insert("audio_index", "-");
504 commonproperties.insert("force_colorspace", "-");
505 commonproperties.insert("full_luma", "-");
506 QString transparency = "-";
508 bool allowDurationChange = true;
509 int commonDuration = -1;
510 bool hasImages = false;;
512 for (int i = 0; i < list.count(); i++) {
514 if (list.at(i)->type() == PROJECTFOLDERTYPE) {
515 // Add folder items to the list
516 int ct = list.at(i)->childCount();
517 for (int j = 0; j < ct; j++) {
518 list.append(list.at(i)->child(j));
522 else if (list.at(i)->type() == PROJECTSUBCLIPTYPE)
523 item = static_cast <ProjectItem*>(list.at(i)->parent());
525 item = static_cast <ProjectItem*>(list.at(i));
526 if (!(item->flags() & Qt::ItemIsDragEnabled))
530 DocClipBase *clip = item->referencedClip();
531 if (clipList.contains(clip)) continue;
532 if (clip->clipType() == IMAGE) {
534 if (clip->getProperty("transparency").isEmpty() || clip->getProperty("transparency").toInt() == 0) {
535 if (transparency == "-") {
536 // first non transparent image
539 else if (transparency == "1") {
540 // we have transparent and non transparent clips
545 if (transparency == "-") {
546 // first transparent image
549 else if (transparency == "0") {
550 // we have transparent and non transparent clips
555 if (clip->clipType() != COLOR && clip->clipType() != IMAGE && clip->clipType() != TEXT)
556 allowDurationChange = false;
557 if (allowDurationChange && commonDuration != 0) {
558 if (commonDuration == -1)
559 commonDuration = clip->duration().frames(m_fps);
560 else if (commonDuration != clip->duration().frames(m_fps))
563 clipList.append(clip);
564 QMap <QString, QString> clipprops = clip->properties();
565 QMapIterator<QString, QString> p(commonproperties);
566 while (p.hasNext()) {
568 if (p.value().isEmpty()) continue;
569 if (clipprops.contains(p.key())) {
570 if (p.value() == "-")
571 commonproperties.insert(p.key(), clipprops.value(p.key()));
572 else if (p.value() != clipprops.value(p.key()))
573 commonproperties.insert(p.key(), QString());
575 commonproperties.insert(p.key(), QString());
580 if (allowDurationChange)
581 commonproperties.insert("out", QString::number(commonDuration));
583 commonproperties.insert("transparency", transparency);
584 /*QMapIterator<QString, QString> p(commonproperties);
585 while (p.hasNext()) {
587 kDebug() << "Result: " << p.key() << " = " << p.value();
589 if (clipList.isEmpty()) {
590 emit displayMessage(i18n("No available clip selected"), -2, ErrorMessage);
592 else emit showClipProperties(clipList, commonproperties);
595 void ProjectList::slotOpenClip()
598 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
600 if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1)
601 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
603 item = static_cast <ProjectItem*>(m_listView->currentItem());
605 if (item->clipType() == IMAGE) {
606 if (KdenliveSettings::defaultimageapp().isEmpty())
607 KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open images in the Settings dialog"));
609 QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
611 if (item->clipType() == AUDIO) {
612 if (KdenliveSettings::defaultaudioapp().isEmpty())
613 KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open audio files in the Settings dialog"));
615 QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
620 void ProjectList::cleanup()
622 m_listView->clearSelection();
623 QTreeWidgetItemIterator it(m_listView);
626 if ((*it)->type() != PROJECTCLIPTYPE) {
630 item = static_cast <ProjectItem *>(*it);
631 if (item->numReferences() == 0)
632 item->setSelected(true);
638 void ProjectList::trashUnusedClips()
640 QTreeWidgetItemIterator it(m_listView);
645 if ((*it)->type() != PROJECTCLIPTYPE) {
649 item = static_cast <ProjectItem *>(*it);
650 if (item->numReferences() == 0) {
651 ids << item->clipId();
652 KUrl url = item->clipUrl();
653 if (!url.isEmpty() && !urls.contains(url.path()))
659 // Check that we don't use the URL in another clip
660 QTreeWidgetItemIterator it2(m_listView);
662 if ((*it2)->type() != PROJECTCLIPTYPE) {
666 item = static_cast <ProjectItem *>(*it2);
667 if (item->numReferences() > 0) {
668 KUrl url = item->clipUrl();
669 if (!url.isEmpty() && urls.contains(url.path())) urls.removeAll(url.path());
674 emit deleteProjectClips(ids, QMap <QString, QString>());
675 for (int i = 0; i < urls.count(); i++)
676 KIO::NetAccess::del(KUrl(urls.at(i)), this);
679 void ProjectList::slotReloadClip(const QString &id)
681 QList<QTreeWidgetItem *> selected;
683 selected = m_listView->selectedItems();
685 ProjectItem *itemToReLoad = getItemById(id);
686 if (itemToReLoad) selected.append(itemToReLoad);
689 for (int i = 0; i < selected.count(); i++) {
690 if (selected.at(i)->type() != PROJECTCLIPTYPE) {
691 if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
692 for (int j = 0; j < selected.at(i)->childCount(); j++)
693 selected.append(selected.at(i)->child(j));
697 item = static_cast <ProjectItem *>(selected.at(i));
698 if (item && !hasPendingJob(item, PROXYJOB)) {
699 DocClipBase *clip = item->referencedClip();
700 if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
701 kDebug()<<"//// TRYING TO RELOAD: "<<item->clipId()<<", but it is busy";
704 CLIPTYPE t = item->clipType();
706 if (clip && !clip->getProperty("xmltemplate").isEmpty())
707 regenerateTemplate(item);
708 } else if (t != COLOR && t != SLIDESHOW && clip && clip->checkHash() == false) {
709 item->referencedClip()->setPlaceHolder(true);
710 item->setProperty("file_hash", QString());
711 } else if (t == IMAGE) {
712 //clip->getProducer() clip->getProducer()->set("force_reload", 1);
715 QDomElement e = item->toXml();
716 // Make sure we get the correct producer length if it was adjusted in timeline
717 if (t == COLOR || t == IMAGE || t == SLIDESHOW || t == TEXT) {
718 int length = QString(clip->producerProperty("length")).toInt();
719 if (length > 0 && !e.hasAttribute("length")) {
720 e.setAttribute("length", length);
723 resetThumbsProducer(clip);
724 m_render->getFileProperties(e, item->clipId(), m_listView->iconSize().height(), true);
729 void ProjectList::slotModifiedClip(const QString &id)
731 ProjectItem *item = getItemById(id);
733 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
734 if (!pixmap.isNull()) {
736 p.fillRect(0, 0, pixmap.width(), pixmap.height(), QColor(255, 255, 255, 200));
737 p.drawPixmap(0, 0, KIcon("view-refresh").pixmap(m_listView->iconSize()));
740 pixmap = KIcon("view-refresh").pixmap(m_listView->iconSize());
742 item->setPixmap(pixmap);
746 void ProjectList::slotMissingClip(const QString &id)
748 ProjectItem *item = getItemById(id);
750 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
751 int height = m_listView->iconSize().height();
752 if (m_render == NULL) {
753 kDebug() << "********* ERROR, NULL RENDR";
756 int width = (int)(height * m_render->dar());
757 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
758 if (pixmap.isNull()) {
759 pixmap = QPixmap(width, height);
760 pixmap.fill(Qt::transparent);
762 KIcon icon("dialog-close");
764 p.drawPixmap(3, 3, icon.pixmap(width - 6, height - 6));
766 item->setPixmap(pixmap);
767 if (item->referencedClip()) {
768 item->referencedClip()->setPlaceHolder(true);
769 Mlt::Producer *newProd = m_render->invalidProducer(id);
770 if (item->referencedClip()->getProducer()) {
771 Mlt::Properties props(newProd->get_properties());
772 Mlt::Properties src_props(item->referencedClip()->getProducer()->get_properties());
773 props.inherit(src_props);
775 item->referencedClip()->setProducer(newProd, true);
776 item->slotSetToolTip();
777 emit clipNeedsReload(id);
781 emit displayMessage(i18n("Check missing clips"), -2, ErrorMessage);
782 emit updateRenderStatus();
785 void ProjectList::slotAvailableClip(const QString &id)
787 ProjectItem *item = getItemById(id);
790 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
791 if (item->referencedClip()) { // && item->referencedClip()->checkHash() == false) {
792 item->setProperty("file_hash", QString());
796 item->referencedClip()->setValid();
797 item->slotSetToolTip();
800 emit updateRenderStatus();
803 bool ProjectList::hasMissingClips()
805 bool missing = false;
806 QTreeWidgetItemIterator it(m_listView);
808 if ((*it)->type() == PROJECTCLIPTYPE && !((*it)->flags() & Qt::ItemIsDragEnabled)) {
817 void ProjectList::setRenderer(Render *projectRender)
819 m_render = projectRender;
820 m_listView->setIconSize(QSize((ProjectItem::itemDefaultHeight() - 2) * m_render->dar(), ProjectItem::itemDefaultHeight() - 2));
821 connect(m_render, SIGNAL(requestProxy(QString)), this, SLOT(slotCreateProxy(QString)));
824 void ProjectList::slotClipSelected()
826 QTreeWidgetItem *item = m_listView->currentItem();
827 ProjectItem *clip = NULL;
829 if (item->type() == PROJECTFOLDERTYPE) {
830 emit clipSelected(NULL);
831 m_editButton->defaultAction()->setEnabled(item->childCount() > 0);
832 m_deleteButton->defaultAction()->setEnabled(true);
833 m_openAction->setEnabled(false);
834 m_reloadAction->setEnabled(false);
835 m_extractAudioAction->setEnabled(false);
836 m_transcodeAction->setEnabled(false);
837 m_stabilizeAction->setEnabled(false);
839 if (item->type() == PROJECTSUBCLIPTYPE) {
840 // this is a sub item, use base clip
841 m_deleteButton->defaultAction()->setEnabled(true);
842 clip = static_cast <ProjectItem*>(item->parent());
843 if (clip == NULL) kDebug() << "-----------ERROR";
844 SubProjectItem *sub = static_cast <SubProjectItem*>(item);
845 emit clipSelected(clip->referencedClip(), sub->zone());
846 m_extractAudioAction->setEnabled(false);
847 m_transcodeAction->setEnabled(false);
848 m_stabilizeAction->setEnabled(false);
849 m_reloadAction->setEnabled(false);
850 adjustProxyActions(clip);
853 clip = static_cast <ProjectItem*>(item);
854 if (clip && clip->referencedClip())
855 emit clipSelected(clip->referencedClip());
856 m_editButton->defaultAction()->setEnabled(true);
857 m_deleteButton->defaultAction()->setEnabled(true);
858 m_reloadAction->setEnabled(true);
859 m_extractAudioAction->setEnabled(true);
860 m_transcodeAction->setEnabled(true);
861 m_stabilizeAction->setEnabled(true);
862 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
863 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
864 m_openAction->setEnabled(true);
865 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
866 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
867 m_openAction->setEnabled(true);
869 m_openAction->setEnabled(false);
871 // Display relevant transcoding actions only
872 adjustTranscodeActions(clip);
873 adjustStabilizeActions(clip);
874 // Display uses in timeline
875 emit findInTimeline(clip->clipId());
878 emit clipSelected(NULL);
879 m_editButton->defaultAction()->setEnabled(false);
880 m_deleteButton->defaultAction()->setEnabled(false);
881 m_openAction->setEnabled(false);
882 m_reloadAction->setEnabled(false);
883 m_extractAudioAction->setEnabled(true);
884 m_transcodeAction->setEnabled(false);
885 m_stabilizeAction->setEnabled(false);
887 adjustProxyActions(clip);
890 void ProjectList::adjustProxyActions(ProjectItem *clip) const
892 if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == SLIDESHOW || clip->clipType() == AUDIO) {
893 m_proxyAction->setEnabled(false);
896 bool enabled = useProxy();
897 if (clip->referencedClip() && !clip->referencedClip()->getProperty("_missingsource").isEmpty()) enabled = false;
898 m_proxyAction->setEnabled(enabled);
899 m_proxyAction->blockSignals(true);
900 m_proxyAction->setChecked(clip->hasProxy());
901 m_proxyAction->blockSignals(false);
904 void ProjectList::adjustStabilizeActions(ProjectItem *clip) const
907 if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == SLIDESHOW) {
908 m_stabilizeAction->setEnabled(false);
911 m_stabilizeAction->setEnabled(true);
915 void ProjectList::adjustTranscodeActions(ProjectItem *clip) const
917 if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW) {
918 m_transcodeAction->setEnabled(false);
919 m_extractAudioAction->setEnabled(false);
922 m_transcodeAction->setEnabled(true);
923 m_extractAudioAction->setEnabled(true);
924 QList<QAction *> transcodeActions = m_transcodeAction->actions();
927 for (int i = 0; i < transcodeActions.count(); i++) {
928 data = transcodeActions.at(i)->data().toStringList();
929 if (data.count() > 2) {
930 condition = data.at(2);
931 if (condition.startsWith("vcodec"))
932 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
933 else if (condition.startsWith("acodec"))
934 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
940 void ProjectList::slotPauseMonitor()
946 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
948 ProjectItem *item = getItemById(id);
950 slotUpdateClipProperties(item, properties);
951 if (properties.contains("out") || properties.contains("force_fps") || properties.contains("resource") || properties.contains("video_index") || properties.contains("audio_index")) {
953 } else if (properties.contains("colour") ||
954 properties.contains("xmldata") ||
955 properties.contains("force_aspect_num") ||
956 properties.contains("force_aspect_den") ||
957 properties.contains("full_luma") ||
958 properties.contains("templatetext")) {
959 slotRefreshClipThumbnail(item);
960 emit refreshClip(id, true);
961 } else if (properties.contains("force_colorspace") || properties.contains("loop")) {
962 emit refreshClip(id, false);
967 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
971 clip->setProperties(properties);
972 if (properties.contains("proxy")) {
973 if (properties.value("proxy") == "-" || properties.value("proxy").isEmpty())
974 // this should only apply to proxy jobs
975 clip->setConditionalJobStatus(NOJOB, PROXYJOB);
977 if (properties.contains("name")) {
978 monitorItemEditing(false);
979 clip->setText(0, properties.value("name"));
980 monitorItemEditing(true);
981 emit clipNameChanged(clip->clipId(), properties.value("name"));
983 if (properties.contains("description")) {
984 CLIPTYPE type = clip->clipType();
985 monitorItemEditing(false);
986 clip->setText(1, properties.value("description"));
987 monitorItemEditing(true);
989 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
990 // Use Nepomuk system to store clip description
991 Nepomuk::Resource f(clip->clipUrl().path());
992 f.setDescription(properties.value("description"));
995 emit projectModified();
999 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
1001 if (item->type() == PROJECTSUBCLIPTYPE) {
1002 // this is a sub-item
1004 // user edited description
1005 SubProjectItem *sub = static_cast <SubProjectItem*>(item);
1006 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
1007 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), sub->zone(), sub->description(), sub->text(1), true);
1008 m_commandStack->push(command);
1009 //slotUpdateCutClipProperties(sub->clipId(), sub->zone(), sub->text(1), sub->text(1));
1013 if (item->type() == PROJECTFOLDERTYPE) {
1015 FolderProjectItem *folder = static_cast <FolderProjectItem*>(item);
1016 editFolder(item->text(0), folder->groupName(), folder->clipId());
1017 folder->setGroupName(item->text(0));
1018 m_doc->clipManager()->addFolder(folder->clipId(), item->text(0));
1019 const int children = item->childCount();
1020 for (int i = 0; i < children; i++) {
1021 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
1022 child->setProperty("groupname", item->text(0));
1028 ProjectItem *clip = static_cast <ProjectItem*>(item);
1030 if (clip->referencedClip()) {
1031 QMap <QString, QString> oldprops;
1032 QMap <QString, QString> newprops;
1033 oldprops["description"] = clip->referencedClip()->getProperty("description");
1034 newprops["description"] = item->text(1);
1036 if (clip->clipType() == TEXT) {
1037 // This is a text template clip, update the image
1038 /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
1039 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/
1040 oldprops.insert("templatetext", clip->referencedClip()->getProperty("templatetext"));
1041 newprops.insert("templatetext", item->text(1));
1043 slotUpdateClipProperties(clip->clipId(), newprops);
1044 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
1045 m_commandStack->push(command);
1047 } else if (column == 0) {
1048 if (clip->referencedClip()) {
1049 QMap <QString, QString> oldprops;
1050 QMap <QString, QString> newprops;
1051 oldprops["name"] = clip->referencedClip()->getProperty("name");
1052 if (oldprops.value("name") != item->text(0)) {
1053 newprops["name"] = item->text(0);
1054 slotUpdateClipProperties(clip, newprops);
1055 emit projectModified();
1056 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
1057 m_commandStack->push(command);
1058 QTimer::singleShot(100, this, SLOT(slotCheckScrolling()));
1064 void ProjectList::slotCheckScrolling()
1066 m_listView->scrollToItem(m_listView->currentItem());
1069 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
1071 bool enable = item ? true : false;
1072 m_editButton->defaultAction()->setEnabled(enable);
1073 m_deleteButton->defaultAction()->setEnabled(enable);
1074 m_reloadAction->setEnabled(enable);
1075 m_extractAudioAction->setEnabled(enable);
1076 m_transcodeAction->setEnabled(enable);
1077 m_stabilizeAction->setEnabled(enable);
1079 ProjectItem *clip = NULL;
1080 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
1081 clip = static_cast <ProjectItem*>(item->parent());
1082 m_extractAudioAction->setEnabled(false);
1083 m_transcodeAction->setEnabled(false);
1084 m_stabilizeAction->setEnabled(false);
1085 adjustProxyActions(clip);
1086 } else if (m_listView->currentItem()->type() == PROJECTCLIPTYPE) {
1087 clip = static_cast <ProjectItem*>(item);
1088 // Display relevant transcoding actions only
1089 adjustTranscodeActions(clip);
1090 adjustStabilizeActions(clip);
1091 adjustProxyActions(clip);
1092 // Display uses in timeline
1093 emit findInTimeline(clip->clipId());
1095 m_extractAudioAction->setEnabled(false);
1096 m_transcodeAction->setEnabled(false);
1097 m_stabilizeAction->setEnabled(false);
1099 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
1100 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
1101 m_openAction->setEnabled(true);
1102 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
1103 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
1104 m_openAction->setEnabled(true);
1106 m_openAction->setEnabled(false);
1110 m_openAction->setEnabled(false);
1115 void ProjectList::slotRemoveClip()
1117 if (!m_listView->currentItem())
1120 QMap <QString, QString> folderids;
1121 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
1123 QUndoCommand *delCommand = new QUndoCommand();
1124 delCommand->setText(i18n("Delete Clip Zone"));
1125 for (int i = 0; i < selected.count(); i++) {
1126 if (selected.at(i)->type() == PROJECTSUBCLIPTYPE) {
1128 SubProjectItem *sub = static_cast <SubProjectItem *>(selected.at(i));
1129 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
1130 new AddClipCutCommand(this, item->clipId(), sub->zone().x(), sub->zone().y(), sub->description(), false, true, delCommand);
1131 } else if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
1133 FolderProjectItem *folder = static_cast <FolderProjectItem *>(selected.at(i));
1134 folderids[folder->groupName()] = folder->clipId();
1135 int children = folder->childCount();
1137 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)
1139 for (int i = 0; i < children; ++i) {
1140 ProjectItem *child = static_cast <ProjectItem *>(folder->child(i));
1141 ids << child->clipId();
1144 ProjectItem *item = static_cast <ProjectItem *>(selected.at(i));
1145 ids << item->clipId();
1146 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) {
1147 KMessageBox::enableMessage("DeleteAll");
1152 KMessageBox::enableMessage("DeleteAll");
1153 if (delCommand->childCount() == 0)
1156 m_commandStack->push(delCommand);
1157 emit deleteProjectClips(ids, folderids);
1160 void ProjectList::updateButtons() const
1162 if (m_listView->topLevelItemCount() == 0) {
1163 m_deleteButton->defaultAction()->setEnabled(false);
1164 m_editButton->defaultAction()->setEnabled(false);
1166 m_deleteButton->defaultAction()->setEnabled(true);
1167 if (!m_listView->currentItem())
1168 m_listView->setCurrentItem(m_listView->topLevelItem(0));
1169 QTreeWidgetItem *item = m_listView->currentItem();
1170 if (item && item->type() == PROJECTCLIPTYPE) {
1171 m_editButton->defaultAction()->setEnabled(true);
1172 m_openAction->setEnabled(true);
1173 m_reloadAction->setEnabled(true);
1174 m_transcodeAction->setEnabled(true);
1175 m_stabilizeAction->setEnabled(true);
1178 else if (item && item->type() == PROJECTFOLDERTYPE && item->childCount() > 0) {
1179 m_editButton->defaultAction()->setEnabled(true);
1181 else m_editButton->defaultAction()->setEnabled(false);
1183 m_openAction->setEnabled(false);
1184 m_reloadAction->setEnabled(false);
1185 m_transcodeAction->setEnabled(false);
1186 m_stabilizeAction->setEnabled(false);
1187 m_proxyAction->setEnabled(false);
1190 void ProjectList::selectItemById(const QString &clipId)
1192 ProjectItem *item = getItemById(clipId);
1194 m_listView->setCurrentItem(item);
1198 void ProjectList::slotDeleteClip(const QString &clipId)
1200 ProjectItem *item = getItemById(clipId);
1202 kDebug() << "/// Cannot find clip to delete";
1205 deleteJobsForClip(clipId);
1206 m_listView->blockSignals(true);
1207 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
1208 if (!newSelectedItem)
1209 newSelectedItem = m_listView->itemBelow(item);
1211 // Pause playing to prevent crash while deleting clip
1213 m_doc->clipManager()->deleteClip(clipId);
1214 m_listView->blockSignals(false);
1215 if (newSelectedItem) {
1216 m_listView->setCurrentItem(newSelectedItem);
1219 emit clipSelected(NULL);
1224 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
1226 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
1227 m_commandStack->push(command);
1228 m_doc->setModified(true);
1231 void ProjectList::slotAddFolder(const QString &name)
1233 AddFolderCommand *command = new AddFolderCommand(this, name.isEmpty() ? i18n("Folder") : name, QString::number(m_doc->clipManager()->getFreeFolderId()), true);
1234 m_commandStack->push(command);
1237 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
1240 FolderProjectItem *item = getFolderItemById(clipId);
1242 m_doc->clipManager()->deleteFolder(clipId);
1243 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
1244 if (!newSelectedItem)
1245 newSelectedItem = m_listView->itemBelow(item);
1247 if (newSelectedItem)
1248 m_listView->setCurrentItem(newSelectedItem);
1254 FolderProjectItem *item = getFolderItemById(clipId);
1256 m_listView->blockSignals(true);
1257 item->setGroupName(foldername);
1258 m_listView->blockSignals(false);
1259 m_doc->clipManager()->addFolder(clipId, foldername);
1260 const int children = item->childCount();
1261 for (int i = 0; i < children; i++) {
1262 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
1263 child->setProperty("groupname", foldername);
1267 m_listView->blockSignals(true);
1268 m_listView->setCurrentItem(new FolderProjectItem(m_listView, QStringList() << foldername, clipId));
1269 m_doc->clipManager()->addFolder(clipId, foldername);
1270 m_listView->blockSignals(false);
1271 m_listView->editItem(m_listView->currentItem(), 0);
1275 m_doc->setModified(true);
1280 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
1282 QMapIterator<QString, QString> i(map);
1283 QUndoCommand *delCommand = new QUndoCommand();
1284 delCommand->setText(i18n("Delete Folder"));
1285 while (i.hasNext()) {
1287 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
1289 if (delCommand->childCount() > 0) m_commandStack->push(delCommand);
1290 else delete delCommand;
1293 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
1295 //m_listView->setEnabled(false);
1296 const QString parent = clip->getProperty("groupid");
1297 QString groupName = clip->getProperty("groupname");
1298 QSize pixelSize((int)(m_listView->iconSize().height() * m_render->dar()), m_listView->iconSize().height());
1299 ProjectItem *item = NULL;
1300 monitorItemEditing(false);
1301 if (!parent.isEmpty()) {
1302 FolderProjectItem *parentitem = getFolderItemById(parent);
1305 //kDebug() << "Adding clip to new group: " << groupName;
1306 if (groupName.isEmpty()) groupName = i18n("Folder");
1308 parentitem = new FolderProjectItem(m_listView, text, parent);
1312 item = new ProjectItem(parentitem, clip, pixelSize);
1315 item = new ProjectItem(m_listView, clip, pixelSize);
1317 if (item->data(0, DurationRole).isNull()) item->setData(0, DurationRole, i18n("Loading"));
1318 connect(clip, SIGNAL(createProxy(const QString &)), this, SLOT(slotCreateProxy(const QString &)));
1319 connect(clip, SIGNAL(abortProxy(const QString &, const QString &)), this, SLOT(slotAbortProxy(const QString, const QString)));
1321 if (getProperties) {
1322 //item->setFlags(Qt::ItemIsSelectable);
1323 m_listView->processLayout();
1324 QDomElement e = clip->toXML().cloneNode().toElement();
1325 if (!groupName.isEmpty()) {
1326 e.setAttribute("groupId", parent);
1327 e.setAttribute("group", groupName);
1329 e.removeAttribute("file_hash");
1330 resetThumbsProducer(clip);
1331 m_render->getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true);
1333 // WARNING: code below triggers unnecessary reload of all proxy clips on document loading... is it useful in some cases?
1334 /*else if (item->hasProxy() && !item->isJobRunning()) {
1335 slotCreateProxy(clip->getId());
1338 KUrl url = clip->fileURL();
1340 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk() && clip->getProperty("description").isEmpty()) {
1341 // if file has Nepomuk comment, use it
1342 Nepomuk::Resource f(url.path());
1343 QString annotation = f.description();
1344 if (!annotation.isEmpty()) {
1345 item->setText(1, annotation);
1346 clip->setProperty("description", annotation);
1348 item->setText(2, QString::number(f.rating()));
1352 // Add info to date column
1353 QFileInfo fileInfo(url.path());
1354 if (fileInfo.exists()) {
1355 item->setText(3, fileInfo.lastModified().toString(QString("yyyy/MM/dd hh:mm:ss")));
1359 QList <CutZoneInfo> cuts = clip->cutZones();
1360 if (!cuts.isEmpty()) {
1361 for (int i = 0; i < cuts.count(); i++) {
1362 SubProjectItem *sub = new SubProjectItem(m_render->dar(), item, cuts.at(i).zone.x(), cuts.at(i).zone.y(), cuts.at(i).description);
1363 if (!clip->getClipHash().isEmpty()) {
1364 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(cuts.at(i).zone.x()) + ".png";
1365 if (QFile::exists(cachedPixmap)) {
1366 QPixmap pix(cachedPixmap);
1368 KIO::NetAccess::del(KUrl(cachedPixmap), this);
1369 sub->setData(0, Qt::DecorationRole, pix);
1374 monitorItemEditing(true);
1378 void ProjectList::slotGotProxy(const QString &proxyPath)
1380 if (proxyPath.isEmpty() || m_abortAllJobs) return;
1381 QTreeWidgetItemIterator it(m_listView);
1384 while (*it && !m_closing) {
1385 if ((*it)->type() == PROJECTCLIPTYPE) {
1386 item = static_cast <ProjectItem *>(*it);
1387 if (item->referencedClip()->getProperty("proxy") == proxyPath)
1394 void ProjectList::slotGotProxyForId(const QString id)
1396 if (m_closing) return;
1397 ProjectItem *item = getItemById(id);
1401 void ProjectList::slotGotProxy(ProjectItem *item)
1403 if (item == NULL) return;
1404 DocClipBase *clip = item->referencedClip();
1405 if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
1406 // Clip is being reprocessed, abort
1407 kDebug()<<"//// TRYING TO PROXY: "<<item->clipId()<<", but it is busy";
1411 // Proxy clip successfully created
1412 QDomElement e = clip->toXML().cloneNode().toElement();
1414 // Make sure we get the correct producer length if it was adjusted in timeline
1415 CLIPTYPE t = item->clipType();
1416 if (t == COLOR || t == IMAGE || t == SLIDESHOW || t == TEXT) {
1417 int length = QString(clip->producerProperty("length")).toInt();
1418 if (length > 0 && !e.hasAttribute("length")) {
1419 e.setAttribute("length", length);
1422 resetThumbsProducer(clip);
1423 m_render->getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true);
1426 void ProjectList::slotResetProjectList()
1428 m_listView->blockSignals(true);
1429 m_abortAllJobs = true;
1430 for (int i = 0; i < m_jobList.count(); i++) {
1431 m_jobList.at(i)->setStatus(JOBABORTED);
1434 m_jobThreads.waitForFinished();
1435 m_jobThreads.clearFutures();
1436 m_thumbnailQueue.clear();
1437 if (!m_jobList.isEmpty()) qDeleteAll(m_jobList);
1439 m_listView->clear();
1440 m_listView->setEnabled(true);
1441 emit clipSelected(NULL);
1442 m_refreshed = false;
1443 m_allClipsProcessed = false;
1444 m_abortAllJobs = false;
1446 m_listView->blockSignals(false);
1449 void ProjectList::slotUpdateClip(const QString &id)
1451 ProjectItem *item = getItemById(id);
1452 monitorItemEditing(false);
1453 if (item) item->setData(0, UsageRole, QString::number(item->numReferences()));
1454 monitorItemEditing(true);
1457 void ProjectList::getCachedThumbnail(ProjectItem *item)
1460 DocClipBase *clip = item->referencedClip();
1462 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
1463 if (QFile::exists(cachedPixmap)) {
1464 QPixmap pix(cachedPixmap);
1466 KIO::NetAccess::del(KUrl(cachedPixmap), this);
1467 requestClipThumbnail(item->clipId());
1470 QPixmap result = roundedPixmap(pix);
1471 processThumbOverlays(item, result);
1472 item->setPixmap(result);
1476 requestClipThumbnail(item->clipId());
1480 QPixmap ProjectList::roundedPixmap(QImage img)
1482 QPixmap pix(img.width(), img.height());
1483 pix.fill(Qt::transparent);
1485 p.setRenderHint(QPainter::Antialiasing, true);
1487 path.addRoundedRect(0.5, 0.5, pix.width() - 1, pix.height() - 1, 2, 2);
1488 p.setClipPath(path);
1489 p.drawImage(0, 0, img);
1494 QPixmap ProjectList::roundedPixmap(QPixmap source)
1496 QPixmap pix(source.width(), source.height());
1497 pix.fill(Qt::transparent);
1499 p.setRenderHint(QPainter::Antialiasing, true);
1501 path.addRoundedRect(0.5, 0.5, pix.width() - 1, pix.height() - 1, 2, 2);
1502 p.setClipPath(path);
1503 p.drawPixmap(0, 0, source);
1508 void ProjectList::getCachedThumbnail(SubProjectItem *item)
1511 ProjectItem *parentItem = static_cast <ProjectItem *>(item->parent());
1512 if (!parentItem) return;
1513 DocClipBase *clip = parentItem->referencedClip();
1515 int pos = item->zone().x();
1516 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(pos) + ".png";
1517 if (QFile::exists(cachedPixmap)) {
1518 QPixmap pix(cachedPixmap);
1520 KIO::NetAccess::del(KUrl(cachedPixmap), this);
1521 requestClipThumbnail(parentItem->clipId() + '#' + QString::number(pos));
1523 else item->setData(0, Qt::DecorationRole, pix);
1525 else requestClipThumbnail(parentItem->clipId() + '#' + QString::number(pos));
1528 void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged, QStringList brokenClips)
1530 if (!m_allClipsProcessed) m_listView->setEnabled(false);
1531 m_listView->setSortingEnabled(false);
1532 QTreeWidgetItemIterator it(m_listView);
1535 monitorItemEditing(false);
1536 int height = m_listView->iconSize().height();
1537 int width = (int)(height * m_render->dar());
1538 QPixmap missingPixmap = QPixmap(width, height);
1539 missingPixmap.fill(Qt::transparent);
1540 KIcon icon("dialog-close");
1541 QPainter p(&missingPixmap);
1542 p.drawPixmap(3, 3, icon.pixmap(width - 6, height - 6));
1545 int max = m_doc->clipManager()->clipsCount();
1550 emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - ct++) / max));
1551 if ((*it)->type() == PROJECTSUBCLIPTYPE) {
1553 SubProjectItem *sub = static_cast <SubProjectItem *>(*it);
1554 if (displayRatioChanged) {
1555 item = static_cast <ProjectItem *>((*it)->parent());
1556 requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x()));
1558 else if (sub->data(0, Qt::DecorationRole).isNull()) {
1559 getCachedThumbnail(sub);
1563 } else if ((*it)->type() == PROJECTFOLDERTYPE) {
1568 item = static_cast <ProjectItem *>(*it);
1569 clip = item->referencedClip();
1570 if (clip->getProducer() == NULL) {
1571 bool replace = false;
1572 if (brokenClips.contains(item->clipId())) {
1573 // if this is a proxy clip, disable proxy
1574 item->setConditionalJobStatus(NOJOB, PROXYJOB);
1575 discardJobs(item->clipId(), PROXYJOB);
1576 clip->setProperty("proxy", "-");
1579 if (clip->isPlaceHolder() == false && !hasPendingJob(item, PROXYJOB)) {
1580 QDomElement xml = clip->toXML();
1582 xml.removeAttribute("out");
1583 xml.removeAttribute("file_hash");
1584 xml.removeAttribute("proxy_out");
1586 if (!replace) replace = xml.attribute("_replaceproxy") == "1";
1587 xml.removeAttribute("_replaceproxy");
1589 resetThumbsProducer(clip);
1591 m_render->getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), replace);
1593 else if (clip->isPlaceHolder()) {
1594 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
1595 if (!item->hasPixmap()) {
1596 item->setPixmap(missingPixmap);
1599 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
1600 QPainter p(&pixmap);
1601 p.drawPixmap(3, 3, KIcon("dialog-close").pixmap(pixmap.width() - 6, pixmap.height() - 6));
1603 item->setPixmap(pixmap);
1607 if (displayRatioChanged) {
1608 requestClipThumbnail(clip->getId());
1610 else if (!item->hasPixmap()) {
1611 getCachedThumbnail(item);
1613 if (item->data(0, DurationRole).toString().isEmpty()) {
1614 item->changeDuration(clip->getProducer()->get_playtime());
1616 if (clip->isPlaceHolder()) {
1617 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
1618 if (pixmap.isNull()) {
1619 pixmap = QPixmap(width, height);
1620 pixmap.fill(Qt::transparent);
1622 QPainter p(&pixmap);
1623 p.drawPixmap(3, 3, KIcon("dialog-close").pixmap(pixmap.width() - 6, pixmap.height() - 6));
1625 item->setPixmap(pixmap);
1627 else if (clip->getProperty("_replaceproxy") == "1") {
1628 clip->setProperty("_replaceproxy", QString());
1629 slotCreateProxy(clip->getId());
1632 item->setData(0, UsageRole, QString::number(item->numReferences()));
1637 m_listView->setSortingEnabled(true);
1638 m_allClipsProcessed = true;
1639 if (m_render->processingItems() == 0) {
1640 monitorItemEditing(true);
1641 slotProcessNextThumbnail();
1646 QString ProjectList::getExtensions()
1648 // Build list of mime types
1649 QStringList mimeTypes = QStringList() << "application/x-kdenlive" << "application/x-kdenlivetitle" << "video/mlt-playlist" << "text/plain";
1652 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";
1655 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";
1658 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";
1660 QString allExtensions;
1661 foreach(const QString & mimeType, mimeTypes) {
1662 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
1664 allExtensions.append(mime->patterns().join(" "));
1665 allExtensions.append(' ');
1668 return allExtensions.simplified();
1671 void ProjectList::slotAddClip(const QString url, const QString &groupName, const QString &groupId)
1673 kDebug()<<"// Adding clip: "<<url;
1676 slotAddClip(list, groupName, groupId);
1679 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
1681 if (!m_commandStack)
1682 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1685 if (givenList.isEmpty()) {
1686 QString allExtensions = getExtensions();
1687 const QString dialogFilter = allExtensions + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
1688 QCheckBox *b = new QCheckBox(i18n("Import image sequence"));
1689 b->setChecked(KdenliveSettings::autoimagesequence());
1690 QCheckBox *c = new QCheckBox(i18n("Transparent background for images"));
1691 c->setChecked(KdenliveSettings::autoimagetransparency());
1692 QFrame *f = new QFrame;
1693 f->setFrameShape(QFrame::NoFrame);
1694 QHBoxLayout *l = new QHBoxLayout;
1699 QPointer<KFileDialog> d = new KFileDialog(KUrl("kfiledialog:///clipfolder"), dialogFilter, kapp->activeWindow(), f);
1700 d->setOperationMode(KFileDialog::Opening);
1701 d->setMode(KFile::Files);
1702 if (d->exec() == QDialog::Accepted) {
1703 KdenliveSettings::setAutoimagetransparency(c->isChecked());
1705 list = d->selectedUrls();
1706 if (b->isChecked() && list.count() == 1) {
1707 // Check for image sequence
1708 KUrl url = list.at(0);
1709 QString fileName = url.fileName().section('.', 0, -2);
1710 if (fileName.at(fileName.size() - 1).isDigit()) {
1711 KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
1712 if (item.mimetype().startsWith("image")) {
1713 // import as sequence if we found more than one image in the sequence
1715 QString pattern = SlideshowClip::selectedPath(url.path(), false, QString(), &list);
1716 int count = list.count();
1719 QStringList groupInfo = getGroup();
1721 // get image sequence base name
1722 while (fileName.at(fileName.size() - 1).isDigit()) {
1725 QMap <QString, QString> properties;
1726 properties.insert("name", fileName);
1727 properties.insert("resource", pattern);
1728 properties.insert("in", "0");
1729 QString duration = m_timecode.reformatSeparators(KdenliveSettings::sequence_duration());
1730 properties.insert("out", QString::number(m_doc->getFramePos(duration) * count));
1731 properties.insert("ttl", QString::number(m_doc->getFramePos(duration)));
1732 properties.insert("loop", QString::number(false));
1733 properties.insert("crop", QString::number(false));
1734 properties.insert("fade", QString::number(false));
1735 properties.insert("luma_duration", QString::number(m_doc->getFramePos(m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))))));
1736 m_doc->slotCreateSlideshowClipFile(properties, groupInfo.at(0), groupInfo.at(1));
1744 for (int i = 0; i < givenList.count(); i++)
1745 list << givenList.at(i);
1747 QList <KUrl::List> foldersList;
1749 foreach(const KUrl & file, list) {
1750 // Check there is no folder here
1751 KMimeType::Ptr type = KMimeType::findByUrl(file);
1752 if (type->is("inode/directory")) {
1753 // user dropped a folder, import its files
1754 list.removeAll(file);
1755 QDir dir(file.path());
1756 QStringList result = dir.entryList(QDir::Files);
1757 KUrl::List folderFiles;
1758 folderFiles << file;
1759 foreach(const QString & path, result) {
1760 KUrl newFile = file;
1761 newFile.addPath(path);
1762 folderFiles.append(newFile);
1764 if (folderFiles.count() > 1) foldersList.append(folderFiles);
1768 if (givenList.isEmpty() && !list.isEmpty()) {
1769 QStringList groupInfo = getGroup();
1770 QMap <QString, QString> data;
1771 data.insert("group", groupInfo.at(0));
1772 data.insert("groupId", groupInfo.at(1));
1773 m_doc->slotAddClipList(list, data);
1774 } else if (!list.isEmpty()) {
1775 QMap <QString, QString> data;
1776 data.insert("group", groupName);
1777 data.insert("groupId", groupId);
1778 m_doc->slotAddClipList(list, data);
1781 if (!foldersList.isEmpty()) {
1783 for (int i = 0; i < foldersList.count(); i++) {
1784 KUrl::List urls = foldersList.at(i);
1785 KUrl folderUrl = urls.takeFirst();
1786 QString folderName = folderUrl.fileName();
1787 FolderProjectItem *folder = NULL;
1788 if (!folderName.isEmpty()) {
1789 folder = getFolderItemByName(folderName);
1790 if (folder == NULL) {
1791 slotAddFolder(folderName);
1792 folder = getFolderItemByName(folderName);
1796 QMap <QString, QString> data;
1797 data.insert("group", folder->groupName());
1798 data.insert("groupId", folder->clipId());
1799 m_doc->slotAddClipList(urls, data);
1801 else m_doc->slotAddClipList(urls);
1806 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
1808 ProjectItem *item = getItemById(id);
1809 m_thumbnailQueue.removeAll(id);
1811 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1812 const QString path = item->referencedClip()->fileURL().path();
1813 if (item->referencedClip()->isPlaceHolder()) replace = false;
1814 if (!path.isEmpty()) {
1815 if (m_invalidClipDialog) {
1816 m_invalidClipDialog->addClip(id, path);
1821 m_invalidClipDialog = new InvalidDialog(i18n("Invalid clip"), i18n("Clip <b>%1</b><br />is invalid, will be removed from project.", QString()), replace, kapp->activeWindow());
1823 m_invalidClipDialog = new InvalidDialog(i18n("Invalid clip"), i18n("Clip <b>%1</b><br />is missing or invalid. Remove it from project?", QString()), replace, kapp->activeWindow());
1825 m_invalidClipDialog->addClip(id, path);
1826 int result = m_invalidClipDialog->exec();
1827 if (result == KDialog::Yes) replace = true;
1830 if (m_invalidClipDialog) {
1832 emit deleteProjectClips(m_invalidClipDialog->getIds(), QMap <QString, QString>());
1833 delete m_invalidClipDialog;
1834 m_invalidClipDialog = NULL;
1840 void ProjectList::slotRemoveInvalidProxy(const QString &id, bool durationError)
1842 ProjectItem *item = getItemById(id);
1844 kDebug()<<"// Proxy for clip "<<id<<" is invalid, delete";
1845 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1846 if (durationError) {
1847 kDebug() << "Proxy duration is wrong, try changing transcoding parameters.";
1848 emit displayMessage(i18n("Proxy clip unusable (duration is different from original)."), -2, ErrorMessage);
1850 slotUpdateJobStatus(item, PROXYJOB, JOBCRASHED, i18n("Failed to create proxy for %1. check parameters", item->text(0)), "project_settings");
1851 QString path = item->referencedClip()->getProperty("proxy");
1852 KUrl proxyFolder(m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/");
1854 //Security check: make sure the invalid proxy file is in the proxy folder
1855 if (proxyFolder.isParentOf(KUrl(path))) {
1856 QFile::remove(path);
1858 if (item->referencedClip()->getProducer() == NULL) {
1859 // Clip has no valid producer, request it
1860 slotProxyCurrentItem(false, item);
1863 // refresh thumbs producer
1864 item->referencedClip()->reloadThumbProducer();
1867 m_thumbnailQueue.removeAll(id);
1870 void ProjectList::slotAddColorClip()
1872 if (!m_commandStack)
1873 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1875 QPointer<QDialog> dia = new QDialog(this);
1876 Ui::ColorClip_UI dia_ui;
1877 dia_ui.setupUi(dia);
1878 dia->setWindowTitle(i18n("Color Clip"));
1879 dia_ui.clip_name->setText(i18n("Color Clip"));
1881 TimecodeDisplay *t = new TimecodeDisplay(m_timecode);
1882 t->setValue(KdenliveSettings::color_duration());
1883 dia_ui.clip_durationBox->addWidget(t);
1884 dia_ui.clip_color->setColor(KdenliveSettings::colorclipcolor());
1886 if (dia->exec() == QDialog::Accepted) {
1887 QString color = dia_ui.clip_color->color().name();
1888 KdenliveSettings::setColorclipcolor(color);
1889 color = color.replace(0, 1, "0x") + "ff";
1890 QStringList groupInfo = getGroup();
1891 m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, m_timecode.getTimecode(t->gentime()), groupInfo.at(0), groupInfo.at(1));
1898 void ProjectList::slotAddSlideshowClip()
1900 if (!m_commandStack)
1901 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1903 SlideshowClip *dia = new SlideshowClip(m_timecode, this);
1905 if (dia->exec() == QDialog::Accepted) {
1906 QStringList groupInfo = getGroup();
1908 QMap <QString, QString> properties;
1909 properties.insert("name", dia->clipName());
1910 properties.insert("resource", dia->selectedPath());
1911 properties.insert("in", "0");
1912 properties.insert("out", QString::number(m_doc->getFramePos(dia->clipDuration()) * dia->imageCount()));
1913 properties.insert("ttl", QString::number(m_doc->getFramePos(dia->clipDuration())));
1914 properties.insert("loop", QString::number(dia->loop()));
1915 properties.insert("crop", QString::number(dia->crop()));
1916 properties.insert("fade", QString::number(dia->fade()));
1917 properties.insert("luma_duration", dia->lumaDuration());
1918 properties.insert("luma_file", dia->lumaFile());
1919 properties.insert("softness", QString::number(dia->softness()));
1920 properties.insert("animation", dia->animation());
1922 m_doc->slotCreateSlideshowClipFile(properties, groupInfo.at(0), groupInfo.at(1));
1927 void ProjectList::slotAddTitleClip()
1929 QStringList groupInfo = getGroup();
1930 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
1933 void ProjectList::slotAddTitleTemplateClip()
1935 if (!m_commandStack)
1936 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1938 QStringList groupInfo = getGroup();
1940 // Get the list of existing templates
1942 filter << "*.kdenlivetitle";
1943 const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
1944 QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
1946 QPointer<QDialog> dia = new QDialog(this);
1947 Ui::TemplateClip_UI dia_ui;
1948 dia_ui.setupUi(dia);
1949 for (int i = 0; i < templateFiles.size(); ++i)
1950 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
1952 if (!templateFiles.isEmpty())
1953 dia_ui.buttonBox->button(QDialogButtonBox::Ok)->setFocus();
1954 dia_ui.template_list->fileDialog()->setFilter("application/x-kdenlivetitle");
1955 //warning: setting base directory doesn't work??
1956 KUrl startDir(path);
1957 dia_ui.template_list->fileDialog()->setUrl(startDir);
1958 dia_ui.text_box->setHidden(true);
1959 if (dia->exec() == QDialog::Accepted) {
1960 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
1961 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
1962 // Create a cloned template clip
1963 m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
1968 QStringList ProjectList::getGroup() const
1971 QTreeWidgetItem *item = m_listView->currentItem();
1972 while (item && item->type() != PROJECTFOLDERTYPE)
1973 item = item->parent();
1976 FolderProjectItem *folder = static_cast <FolderProjectItem *>(item);
1977 result << folder->groupName() << folder->clipId();
1979 result << QString() << QString();
1984 void ProjectList::setDocument(KdenliveDoc *doc)
1986 m_listView->blockSignals(true);
1987 m_abortAllJobs = true;
1988 for (int i = 0; i < m_jobList.count(); i++) {
1989 m_jobList.at(i)->setStatus(JOBABORTED);
1992 m_jobThreads.waitForFinished();
1993 m_jobThreads.clearFutures();
1994 m_thumbnailQueue.clear();
1995 m_listView->clear();
1997 m_listView->setSortingEnabled(false);
1998 emit clipSelected(NULL);
1999 m_refreshed = false;
2000 m_allClipsProcessed = false;
2002 m_timecode = doc->timecode();
2003 m_commandStack = doc->commandStack();
2005 m_abortAllJobs = false;
2008 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
2009 QStringList openedFolders = doc->getExpandedFolders();
2010 QMapIterator<QString, QString> f(flist);
2011 while (f.hasNext()) {
2013 FolderProjectItem *folder = new FolderProjectItem(m_listView, QStringList() << f.value(), f.key());
2014 folder->setExpanded(openedFolders.contains(f.key()));
2017 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
2018 if (list.isEmpty()) {
2021 m_allClipsProcessed = true;
2023 for (int i = 0; i < list.count(); i++)
2024 slotAddClip(list.at(i), false);
2026 m_listView->blockSignals(false);
2027 connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
2028 connect(m_doc->clipManager(), SIGNAL(modifiedClip(const QString &)), this, SLOT(slotModifiedClip(const QString &)));
2029 connect(m_doc->clipManager(), SIGNAL(missingClip(const QString &)), this, SLOT(slotMissingClip(const QString &)));
2030 connect(m_doc->clipManager(), SIGNAL(availableClip(const QString &)), this, SLOT(slotAvailableClip(const QString &)));
2031 connect(m_doc->clipManager(), SIGNAL(checkAllClips(bool, bool, QStringList)), this, SLOT(updateAllClips(bool, bool, QStringList)));
2032 connect(m_doc->clipManager(), SIGNAL(thumbReady(const QString &, int, QImage)), this, SLOT(slotSetThumbnail(const QString &, int, QImage)));
2035 void ProjectList::slotSetThumbnail(const QString &id, int framePos, QImage img)
2037 QString fullid = id + '#' + QString::number(framePos);
2038 ProjectItem *pItem = NULL;
2039 QTreeWidgetItem *item = getAnyItemById(fullid);
2040 if (item && item->parent()) pItem = static_cast <ProjectItem *>(item->parent());
2041 if (!item && framePos == 0) pItem = getItemById(id);
2042 if (!item && !pItem) return;
2044 if (item->type() == PROJECTCLIPTYPE) static_cast<ProjectItem*>(item)->setPixmap(QPixmap::fromImage(img));
2045 else item->setData(0, Qt::DecorationRole, QPixmap::fromImage(img));
2047 else if (pItem) pItem->setPixmap(QPixmap::fromImage(img));
2049 QString hash = pItem->getClipHash();
2050 if (!hash.isEmpty()) m_doc->cacheImage(hash + '#' + QString::number(framePos), img);
2054 QList <DocClipBase*> ProjectList::documentClipList() const
2057 return QList <DocClipBase*> ();
2059 return m_doc->clipManager()->documentClipList();
2062 QDomElement ProjectList::producersList()
2065 QDomElement prods = doc.createElement("producerlist");
2066 doc.appendChild(prods);
2067 QTreeWidgetItemIterator it(m_listView);
2069 if ((*it)->type() != PROJECTCLIPTYPE) {
2074 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
2080 void ProjectList::slotCheckForEmptyQueue()
2082 if (m_render->processingItems() == 0 && m_thumbnailQueue.isEmpty()) {
2083 if (!m_refreshed && m_allClipsProcessed) {
2085 m_listView->setEnabled(true);
2087 QTimer::singleShot(500, this, SIGNAL(loadingIsOver()));
2088 emit displayMessage(QString(), -1);
2091 } else if (!m_refreshed) {
2092 QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
2097 void ProjectList::requestClipThumbnail(const QString id)
2099 if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id);
2100 slotProcessNextThumbnail();
2103 void ProjectList::resetThumbsProducer(DocClipBase *clip)
2106 clip->clearThumbProducer();
2107 QString id = clip->getId();
2108 m_thumbnailQueue.removeAll(id);
2111 void ProjectList::slotProcessNextThumbnail()
2113 if (m_render->processingItems() > 0) {
2116 if (m_thumbnailQueue.isEmpty()) {
2117 slotCheckForEmptyQueue();
2120 int max = m_doc->clipManager()->clipsCount();
2121 emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - m_thumbnailQueue.count()) / max));
2122 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
2125 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
2127 QTreeWidgetItem *item = getAnyItemById(clipId);
2129 slotRefreshClipThumbnail(item, update);
2131 slotProcessNextThumbnail();
2135 void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
2137 if (it == NULL) return;
2138 ProjectItem *item = NULL;
2139 bool isSubItem = false;
2141 if (it->type() == PROJECTFOLDERTYPE) return;
2142 if (it->type() == PROJECTSUBCLIPTYPE) {
2143 item = static_cast <ProjectItem *>(it->parent());
2144 frame = static_cast <SubProjectItem *>(it)->zone().x();
2147 item = static_cast <ProjectItem *>(it);
2148 frame = item->referencedClip()->getClipThumbFrame();
2152 DocClipBase *clip = item->referencedClip();
2154 slotProcessNextThumbnail();
2158 int height = m_listView->iconSize().height();
2159 int swidth = (int)(height * m_render->frameRenderWidth() / m_render->renderHeight()+ 0.5);
2160 int dwidth = (int)(height * m_render->dar() + 0.5);
2161 if (clip->clipType() == IMAGE) {
2162 img = KThumb::getFrame(item->referencedClip()->getProducer(), 0, swidth, dwidth, height);
2164 else if (clip->clipType() != AUDIO) {
2165 img = item->referencedClip()->extractImage(frame, dwidth, height);
2167 if (!img.isNull()) {
2168 monitorItemEditing(false);
2169 QPixmap pix = roundedPixmap(img);
2170 processThumbOverlays(item, pix);
2171 if (isSubItem) it->setData(0, Qt::DecorationRole, pix);
2172 else item->setPixmap(pix);
2173 monitorItemEditing(true);
2175 QString hash = item->getClipHash();
2176 if (!hash.isEmpty() && !img.isNull()) {
2178 m_doc->cacheImage(hash, img);
2180 m_doc->cacheImage(hash + '#' + QString::number(frame), img);
2184 emit projectModified();
2185 slotProcessNextThumbnail();
2190 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const stringMap &properties, const stringMap &metadata, bool replace)
2193 ProjectItem *item = getItemById(clipId);
2194 int queue = m_render->processingItems();
2195 if (item && producer) {
2196 monitorItemEditing(false);
2197 DocClipBase *clip = item->referencedClip();
2198 if (producer->is_valid()) {
2199 if (clip->isPlaceHolder()) {
2203 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
2205 item->setProperties(properties, metadata);
2206 clip->setProducer(producer, replace);
2209 QString size = properties.value("frame_size");
2210 if (!useProxy() && clip->getProperty("proxy").isEmpty()) {
2211 item->setConditionalJobStatus(NOJOB, PROXYJOB);
2212 discardJobs(clipId, PROXYJOB);
2214 if (useProxy() && generateProxy() && clip->getProperty("proxy") == "-") {
2215 item->setConditionalJobStatus(NOJOB, PROXYJOB);
2216 discardJobs(clipId, PROXYJOB);
2218 else if (useProxy() && !item->hasProxy() && !hasPendingJob(item, PROXYJOB)) {
2219 // proxy video and image clips
2221 CLIPTYPE t = item->clipType();
2222 if (t == IMAGE) maxSize = m_doc->getDocumentProperty("proxyimageminsize").toInt();
2223 else maxSize = m_doc->getDocumentProperty("proxyminsize").toInt();
2224 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)) {
2225 if (clip->getProperty("proxy").isEmpty()) {
2226 KUrl proxyPath = m_doc->projectFolder();
2227 proxyPath.addPath("proxy/");
2228 proxyPath.addPath(clip->getClipHash() + '.' + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension")));
2229 QMap <QString, QString> newProps;
2230 // insert required duration for proxy
2231 if (t != IMAGE) newProps.insert("proxy_out", clip->producerProperty("out"));
2232 newProps.insert("proxy", proxyPath.path());
2233 QMap <QString, QString> oldProps = clip->properties();
2234 oldProps.insert("proxy", QString());
2235 EditClipCommand *command = new EditClipCommand(this, clipId, oldProps, newProps, true);
2236 m_doc->commandStack()->push(command);
2241 if (!replace && m_allClipsProcessed && !item->hasPixmap()) {
2242 getCachedThumbnail(item);
2244 if (!toReload.isEmpty())
2245 item->slotSetToolTip();
2246 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
2248 monitorItemEditing(true);
2249 if (item && m_thumbnailQueue.isEmpty()) {
2250 if (!item->hasProxy() || m_render->activeClipId() == item->clipId())
2251 m_listView->setCurrentItem(item);
2252 bool updatedProfile = false;
2253 if (item->parent()) {
2254 if (item->parent()->type() == PROJECTFOLDERTYPE)
2255 static_cast <FolderProjectItem *>(item->parent())->switchIcon();
2256 } else if (KdenliveSettings::checkfirstprojectclip() && m_listView->topLevelItemCount() == 1 && m_refreshed && m_allClipsProcessed) {
2257 // this is the first clip loaded in project, check if we want to adjust project settings to the clip
2258 updatedProfile = adjustProjectProfileToItem(item);
2260 if (updatedProfile == false) {
2261 //emit clipSelected(item->referencedClip());
2264 int max = m_doc->clipManager()->clipsCount();
2265 if (max > 0) emit displayMessage(i18n("Loading clips"), (int)(100 *(max - queue) / max));
2267 if (m_allClipsProcessed) emit processNextThumbnail();
2270 // no item for producer, delete it
2274 if (replace) toReload = clipId;
2275 if (!toReload.isEmpty())
2276 emit clipNeedsReload(toReload);
2279 bool ProjectList::adjustProjectProfileToItem(ProjectItem *item)
2282 if (m_listView->currentItem() && m_listView->currentItem()->type() != PROJECTFOLDERTYPE)
2283 item = static_cast <ProjectItem*>(m_listView->currentItem());
2285 if (item == NULL || item->referencedClip() == NULL) {
2286 KMessageBox::information(kapp->activeWindow(), i18n("Cannot find profile from current clip"));
2289 bool profileUpdated = false;
2290 QString size = item->referencedClip()->getProperty("frame_size");
2291 int width = size.section('x', 0, 0).toInt();
2292 int height = size.section('x', -1).toInt();
2293 // Fix some avchd clips tht report a wrong size (1920x1088)
2294 if (height == 1088) height = 1080;
2295 double fps = item->referencedClip()->getProperty("fps").toDouble();
2296 double par = item->referencedClip()->getProperty("aspect_ratio").toDouble();
2297 if (item->clipType() == IMAGE || item->clipType() == AV || item->clipType() == VIDEO) {
2298 if (ProfilesDialog::matchProfile(width, height, fps, par, item->clipType() == IMAGE, m_doc->mltProfile()) == false) {
2299 // get a list of compatible profiles
2300 QMap <QString, QString> suggestedProfiles = ProfilesDialog::getProfilesFromProperties(width, height, fps, par, item->clipType() == IMAGE);
2301 if (!suggestedProfiles.isEmpty()) {
2302 KDialog *dialog = new KDialog(this);
2303 dialog->setCaption(i18n("Change project profile"));
2304 dialog->setButtons(KDialog::Ok | KDialog::Cancel);
2307 QVBoxLayout *l = new QVBoxLayout;
2308 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));
2309 l->addWidget(label);
2310 QListWidget *list = new QListWidget;
2311 list->setAlternatingRowColors(true);
2312 QMapIterator<QString, QString> i(suggestedProfiles);
2313 while (i.hasNext()) {
2315 QListWidgetItem *item = new QListWidgetItem(i.value(), list);
2316 item->setData(Qt::UserRole, i.key());
2317 item->setToolTip(i.key());
2319 list->setCurrentRow(0);
2321 container.setLayout(l);
2322 dialog->setButtonText(KDialog::Ok, i18n("Update profile"));
2323 dialog->setMainWidget(&container);
2324 if (dialog->exec() == QDialog::Accepted) {
2325 //Change project profile
2326 profileUpdated = true;
2327 if (list->currentItem())
2328 emit updateProfile(list->currentItem()->data(Qt::UserRole).toString());
2332 } else if (fps > 0) {
2333 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));
2337 return profileUpdated;
2340 QString ProjectList::getDocumentProperty(const QString &key) const
2342 return m_doc->getDocumentProperty(key);
2345 bool ProjectList::useProxy() const
2347 return m_doc->getDocumentProperty("enableproxy").toInt();
2350 bool ProjectList::generateProxy() const
2352 return m_doc->getDocumentProperty("generateproxy").toInt();
2355 bool ProjectList::generateImageProxy() const
2357 return m_doc->getDocumentProperty("generateimageproxy").toInt();
2360 void ProjectList::slotReplyGetImage(const QString &clipId, const QImage &img)
2362 ProjectItem *item = getItemById(clipId);
2363 if (item && !img.isNull()) {
2364 QPixmap pix = roundedPixmap(img);
2365 processThumbOverlays(item, pix);
2366 monitorItemEditing(false);
2367 item->setPixmap(pix);
2368 monitorItemEditing(true);
2369 QString hash = item->getClipHash();
2370 if (!hash.isEmpty()) m_doc->cacheImage(hash, img);
2374 void ProjectList::slotReplyGetImage(const QString &clipId, const QString &name, int width, int height)
2376 // For clips that have a generic icon (like audio clips...)
2377 ProjectItem *item = getItemById(clipId);
2378 QPixmap pix = KIcon(name).pixmap(QSize(width, height));
2379 if (item && !pix.isNull()) {
2380 monitorItemEditing(false);
2381 item->setData(0, Qt::DecorationRole, pix);
2382 monitorItemEditing(true);
2386 QTreeWidgetItem *ProjectList::getAnyItemById(const QString &id)
2388 QTreeWidgetItemIterator it(m_listView);
2389 QString lookId = id;
2390 if (id.contains('#'))
2391 lookId = id.section('#', 0, 0);
2393 ProjectItem *result = NULL;
2395 if ((*it)->type() != PROJECTCLIPTYPE) {
2400 ProjectItem *item = static_cast<ProjectItem *>(*it);
2401 if (item->clipId() == lookId) {
2407 if (result == NULL || !id.contains('#')) {
2410 for (int i = 0; i < result->childCount(); i++) {
2411 SubProjectItem *sub = static_cast <SubProjectItem *>(result->child(i));
2412 if (sub && sub->zone().x() == id.section('#', 1, 1).toInt())
2421 ProjectItem *ProjectList::getItemById(const QString &id)
2424 QTreeWidgetItemIterator it(m_listView);
2426 if ((*it)->type() != PROJECTCLIPTYPE) {
2427 // subitem or folder
2431 item = static_cast<ProjectItem *>(*it);
2432 if (item->clipId() == id)
2439 FolderProjectItem *ProjectList::getFolderItemByName(const QString &name)
2441 FolderProjectItem *item = NULL;
2442 QList <QTreeWidgetItem *> hits = m_listView->findItems(name, Qt::MatchExactly, 0);
2443 for (int i = 0; i < hits.count(); i++) {
2444 if (hits.at(i)->type() == PROJECTFOLDERTYPE) {
2445 item = static_cast<FolderProjectItem *>(hits.at(i));
2452 FolderProjectItem *ProjectList::getFolderItemById(const QString &id)
2454 FolderProjectItem *item;
2455 QTreeWidgetItemIterator it(m_listView);
2457 if ((*it)->type() == PROJECTFOLDERTYPE) {
2458 item = static_cast<FolderProjectItem *>(*it);
2459 if (item->clipId() == id)
2467 void ProjectList::slotSelectClip(const QString &ix)
2469 ProjectItem *clip = getItemById(ix);
2471 m_listView->setCurrentItem(clip);
2472 m_listView->scrollToItem(clip);
2473 m_editButton->defaultAction()->setEnabled(true);
2474 m_deleteButton->defaultAction()->setEnabled(true);
2475 m_reloadAction->setEnabled(true);
2476 m_extractAudioAction->setEnabled(true);
2477 m_transcodeAction->setEnabled(true);
2478 m_stabilizeAction->setEnabled(true);
2479 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
2480 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
2481 m_openAction->setEnabled(true);
2482 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
2483 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
2484 m_openAction->setEnabled(true);
2486 m_openAction->setEnabled(false);
2491 QString ProjectList::currentClipUrl() const
2494 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return QString();
2495 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
2497 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
2499 item = static_cast <ProjectItem*>(m_listView->currentItem());
2503 return item->clipUrl().path();
2506 KUrl::List ProjectList::getConditionalUrls(const QString &condition) const
2510 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
2511 for (int i = 0; i < list.count(); i++) {
2512 if (list.at(i)->type() == PROJECTFOLDERTYPE)
2514 if (list.at(i)->type() == PROJECTSUBCLIPTYPE) {
2516 item = static_cast <ProjectItem*>(list.at(i)->parent());
2518 item = static_cast <ProjectItem*>(list.at(i));
2520 if (item == NULL || item->type() == COLOR || item->type() == SLIDESHOW || item->type() == TEXT)
2522 DocClipBase *clip = item->referencedClip();
2523 if (!condition.isEmpty()) {
2524 if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section('=', 1, 1)))
2526 else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section('=', 1, 1)))
2529 result.append(item->clipUrl());
2534 QStringList ProjectList::getConditionalIds(const QString &condition) const
2538 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
2539 for (int i = 0; i < list.count(); i++) {
2540 if (list.at(i)->type() == PROJECTFOLDERTYPE)
2542 if (list.at(i)->type() == PROJECTSUBCLIPTYPE) {
2544 item = static_cast <ProjectItem*>(list.at(i)->parent());
2546 item = static_cast <ProjectItem*>(list.at(i));
2548 if (item == NULL || item->type() == COLOR || item->type() == SLIDESHOW || item->type() == TEXT)
2550 DocClipBase *clip = item->referencedClip();
2551 if (!condition.isEmpty()) {
2552 if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section('=', 1, 1)))
2554 else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section('=', 1, 1)))
2557 result.append(item->clipId());
2562 void ProjectList::regenerateTemplate(const QString &id)
2564 ProjectItem *clip = getItemById(id);
2566 regenerateTemplate(clip);
2569 void ProjectList::regenerateTemplate(ProjectItem *clip)
2571 //TODO: remove this unused method, only force_reload is necessary
2572 clip->referencedClip()->getProducer()->set("force_reload", 1);
2575 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
2579 if (!file.open(QIODevice::ReadOnly)) {
2580 kWarning() << "ERROR, CANNOT READ: " << path;
2583 if (!doc.setContent(&file)) {
2584 kWarning() << "ERROR, CANNOT READ: " << path;
2589 QDomNodeList texts = doc.elementsByTagName("content");
2590 for (int i = 0; i < texts.count(); i++) {
2591 QString data = texts.item(i).firstChild().nodeValue();
2592 data.replace("%s", replaceString);
2593 texts.item(i).firstChild().setNodeValue(data);
2599 void ProjectList::slotAddClipCut(const QString &id, int in, int out)
2601 ProjectItem *clip = getItemById(id);
2602 if (clip == NULL || clip->referencedClip()->hasCutZone(QPoint(in, out)))
2604 AddClipCutCommand *command = new AddClipCutCommand(this, id, in, out, QString(), true, false);
2605 m_commandStack->push(command);
2608 void ProjectList::addClipCut(const QString &id, int in, int out, const QString desc, bool newItem)
2610 ProjectItem *clip = getItemById(id);
2612 DocClipBase *base = clip->referencedClip();
2613 base->addCutZone(in, out);
2614 monitorItemEditing(false);
2615 SubProjectItem *sub = new SubProjectItem(m_render->dar(), clip, in, out, desc);
2616 if (newItem && desc.isEmpty() && !m_listView->isColumnHidden(1)) {
2617 if (!clip->isExpanded())
2618 clip->setExpanded(true);
2619 m_listView->scrollToItem(sub);
2620 m_listView->editItem(sub, 1);
2622 m_doc->clipManager()->requestThumbs(QString('#' + id), QList <int>() << in);
2623 monitorItemEditing(true);
2625 emit projectModified();
2628 void ProjectList::removeClipCut(const QString &id, int in, int out)
2630 ProjectItem *clip = getItemById(id);
2632 DocClipBase *base = clip->referencedClip();
2633 base->removeCutZone(in, out);
2634 SubProjectItem *sub = getSubItem(clip, QPoint(in, out));
2636 monitorItemEditing(false);
2638 monitorItemEditing(true);
2641 emit projectModified();
2644 SubProjectItem *ProjectList::getSubItem(ProjectItem *clip, QPoint zone)
2646 SubProjectItem *sub = NULL;
2648 for (int i = 0; i < clip->childCount(); i++) {
2649 QTreeWidgetItem *it = clip->child(i);
2650 if (it->type() == PROJECTSUBCLIPTYPE) {
2651 sub = static_cast <SubProjectItem*>(it);
2652 if (sub->zone() == zone)
2662 void ProjectList::slotUpdateClipCut(QPoint p)
2664 if (!m_listView->currentItem() || m_listView->currentItem()->type() != PROJECTSUBCLIPTYPE)
2666 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
2667 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
2668 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), p, sub->text(1), sub->text(1), true);
2669 m_commandStack->push(command);
2672 void ProjectList::doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment)
2674 ProjectItem *clip = getItemById(id);
2675 SubProjectItem *sub = getSubItem(clip, oldzone);
2676 if (sub == NULL || clip == NULL)
2678 DocClipBase *base = clip->referencedClip();
2679 base->updateCutZone(oldzone.x(), oldzone.y(), zone.x(), zone.y(), comment);
2680 monitorItemEditing(false);
2682 sub->setDescription(comment);
2683 monitorItemEditing(true);
2684 emit projectModified();
2687 void ProjectList::slotForceProcessing(const QString &id)
2689 m_render->forceProcessing(id);
2692 void ProjectList::slotAddOrUpdateSequence(const QString frameName)
2694 QString fileName = KUrl(frameName).fileName().section('_', 0, -2);
2696 QString pattern = SlideshowClip::selectedPath(frameName, false, QString(), &list);
2697 int count = list.count();
2699 const QList <DocClipBase *> existing = m_doc->clipManager()->getClipByResource(pattern);
2700 if (!existing.isEmpty()) {
2701 // Sequence already exists, update
2702 QString id = existing.at(0)->getId();
2703 //ProjectItem *item = getItemById(id);
2704 QMap <QString, QString> oldprops;
2705 QMap <QString, QString> newprops;
2706 int ttl = existing.at(0)->getProperty("ttl").toInt();
2707 oldprops["out"] = existing.at(0)->getProperty("out");
2708 newprops["out"] = QString::number(ttl * count - 1);
2709 slotUpdateClipProperties(id, newprops);
2710 EditClipCommand *command = new EditClipCommand(this, id, oldprops, newprops, false);
2711 m_commandStack->push(command);
2714 QStringList groupInfo = getGroup();
2715 QMap <QString, QString> properties;
2716 properties.insert("name", fileName);
2717 properties.insert("resource", pattern);
2718 properties.insert("in", "0");
2719 QString duration = m_timecode.reformatSeparators(KdenliveSettings::sequence_duration());
2720 properties.insert("out", QString::number(m_doc->getFramePos(duration) * count));
2721 properties.insert("ttl", QString::number(m_doc->getFramePos(duration)));
2722 properties.insert("loop", QString::number(false));
2723 properties.insert("crop", QString::number(false));
2724 properties.insert("fade", QString::number(false));
2725 properties.insert("luma_duration", m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))));
2727 m_doc->slotCreateSlideshowClipFile(properties, groupInfo.at(0), groupInfo.at(1));
2729 } else emit displayMessage(i18n("Sequence not found"), -2, ErrorMessage);
2732 QMap <QString, QString> ProjectList::getProxies()
2734 QMap <QString, QString> list;
2736 QTreeWidgetItemIterator it(m_listView);
2738 if ((*it)->type() != PROJECTCLIPTYPE) {
2742 item = static_cast<ProjectItem *>(*it);
2743 if (item && item->referencedClip() != NULL) {
2744 if (item->hasProxy()) {
2745 QString proxy = item->referencedClip()->getProperty("proxy");
2746 list.insert(proxy, item->clipUrl().path());
2754 void ProjectList::slotCreateProxy(const QString id)
2756 ProjectItem *item = getItemById(id);
2757 if (!item || hasPendingJob(item, PROXYJOB) || item->referencedClip()->isPlaceHolder()) return;
2758 QString path = item->referencedClip()->getProperty("proxy");
2759 if (path.isEmpty()) {
2760 slotUpdateJobStatus(item, PROXYJOB, JOBCRASHED, i18n("Failed to create proxy, empty path."));
2764 if (QFileInfo(path).size() > 0) {
2765 // Proxy already created
2766 setJobStatus(item, PROXYJOB, JOBDONE);
2770 QString sourcePath = item->clipUrl().path();
2771 if (item->clipType() == PLAYLIST) {
2772 // Special case: playlists use the special 'consumer' producer to support resizing
2773 sourcePath.prepend("consumer:");
2775 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()));
2776 if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
2781 m_jobList.append(job);
2782 setJobStatus(item, job->jobType, JOBWAITING, 0, job->statusMessage());
2783 slotCheckJobProcess();
2786 void ProjectList::slotCutClipJob(const QString &id, QPoint zone)
2788 ProjectItem *item = getItemById(id);
2789 if (!item|| item->referencedClip()->isPlaceHolder()) return;
2790 QString source = item->clipUrl().path();
2791 QString ext = source.section('.', -1);
2792 QString dest = source.section('.', 0, -2) + '_' + QString::number(zone.x()) + '.' + ext;
2794 double clipFps = item->referencedClip()->getProperty("fps").toDouble();
2795 if (clipFps == 0) clipFps = m_fps;
2796 // if clip and project have different frame rate, adjust in and out
2799 in = GenTime(in, m_timecode.fps()).frames(clipFps);
2800 out = GenTime(out, m_timecode.fps()).frames(clipFps);
2801 int max = GenTime(item->clipMaxDuration(), m_timecode.fps()).frames(clipFps);
2802 int duration = out - in + 1;
2803 QString timeIn = Timecode::getStringTimecode(in, clipFps, true);
2804 QString timeOut = Timecode::getStringTimecode(duration, clipFps, true);
2806 QPointer<QDialog> d = new QDialog(this);
2807 Ui::CutJobDialog_UI ui;
2809 ui.extra_params->setVisible(false);
2810 ui.add_clip->setChecked(KdenliveSettings::add_new_clip());
2811 ui.file_url->fileDialog()->setOperationMode(KFileDialog::Saving);
2812 ui.extra_params->setMaximumHeight(QFontMetrics(font()).lineSpacing() * 5);
2813 ui.file_url->setUrl(KUrl(dest));
2814 ui.button_more->setIcon(KIcon("configure"));
2815 ui.extra_params->setPlainText("-acodec copy -vcodec copy");
2816 QString mess = i18n("Extracting %1 out of %2", timeOut, Timecode::getStringTimecode(max, clipFps, true));
2817 ui.info_label->setText(mess);
2818 if (d->exec() != QDialog::Accepted) {
2822 dest = ui.file_url->url().path();
2823 bool acceptPath = dest != source;
2824 if (acceptPath && QFileInfo(dest).size() > 0) {
2825 // destination file olready exists, overwrite?
2828 while (!acceptPath) {
2829 // Do not allow to save over original clip
2830 if (dest == source) ui.info_label->setText("<b>" + i18n("You cannot overwrite original clip.") + "</b><br>" + mess);
2831 else if (KMessageBox::questionYesNo(this, i18n("Overwrite file %1", dest)) == KMessageBox::Yes) break;
2832 if (d->exec() != QDialog::Accepted) {
2836 dest = ui.file_url->url().path();
2837 acceptPath = dest != source;
2838 if (acceptPath && QFileInfo(dest).size() > 0) {
2842 QString extraParams = ui.extra_params->toPlainText().simplified();
2843 KdenliveSettings::setAdd_new_clip(ui.add_clip->isChecked());
2846 QStringList jobParams;
2847 jobParams << dest << item->clipUrl().path() << timeIn << timeOut << QString::number(duration) << QString::number(KdenliveSettings::add_new_clip());
2848 if (!extraParams.isEmpty()) jobParams << extraParams;
2849 CutClipJob *job = new CutClipJob(item->clipType(), id, jobParams);
2850 if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
2854 m_jobList.append(job);
2855 setJobStatus(item, job->jobType, JOBWAITING, 0, job->statusMessage());
2857 slotCheckJobProcess();
2860 void ProjectList::slotTranscodeClipJob(const QString &condition, QString params, QString desc)
2862 QStringList existingFiles;
2863 QStringList ids = getConditionalIds(condition);
2864 QStringList destinations;
2865 foreach(const QString &id, ids) {
2866 ProjectItem *item = getItemById(id);
2867 if (!item) continue;
2868 QString newFile = params.section(' ', -1).replace("%1", item->clipUrl().path());
2869 destinations << newFile;
2870 if (QFile::exists(newFile)) existingFiles << newFile;
2872 if (!existingFiles.isEmpty()) {
2873 if (KMessageBox::warningContinueCancelList(this, i18n("The transcoding job will overwrite the following files:"), existingFiles) == KMessageBox::Cancel) return;
2876 QDialog *d = new QDialog(this);
2877 Ui::CutJobDialog_UI ui;
2879 d->setWindowTitle(i18n("Transcoding"));
2880 ui.extra_params->setMaximumHeight(QFontMetrics(font()).lineSpacing() * 5);
2881 if (ids.count() == 1) {
2882 ui.file_url->setUrl(KUrl(destinations.first()));
2885 ui.destination_label->setVisible(false);
2886 ui.file_url->setVisible(false);
2888 ui.extra_params->setVisible(false);
2890 ui.button_more->setIcon(KIcon("configure"));
2891 ui.add_clip->setChecked(KdenliveSettings::add_new_clip());
2892 ui.extra_params->setPlainText(params.simplified().section(' ', 0, -2));
2893 QString mess = desc;
2894 mess.append(' ' + i18np("(%1 clip)", "(%1 clips)", ids.count()));
2895 ui.info_label->setText(mess);
2896 if (d->exec() != QDialog::Accepted) {
2900 params = ui.extra_params->toPlainText().simplified();
2901 KdenliveSettings::setAdd_new_clip(ui.add_clip->isChecked());
2903 foreach(const QString &id, ids) {
2904 ProjectItem *item = getItemById(id);
2905 if (!item || !item->referencedClip()) continue;
2906 QString src = item->clipUrl().path();
2908 if (ids.count() > 1) {
2909 dest = destinations.at(index);
2912 else dest = ui.file_url->url().path();
2913 QStringList jobParams;
2914 jobParams << dest << src << QString() << QString();
2915 double clipFps = item->referencedClip()->getProperty("fps").toDouble();
2916 if (clipFps == 0) clipFps = m_fps;
2917 int max = item->clipMaxDuration();
2918 QString duration = QString::number(max);
2919 jobParams << duration;
2920 jobParams << QString::number(KdenliveSettings::add_new_clip());
2921 jobParams << params;
2922 CutClipJob *job = new CutClipJob(item->clipType(), id, jobParams);
2923 if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
2927 m_jobList.append(job);
2928 setJobStatus(item, job->jobType, JOBWAITING, 0, job->statusMessage());
2931 slotCheckJobProcess();
2935 void ProjectList::slotCheckJobProcess()
2937 if (!m_jobThreads.futures().isEmpty()) {
2938 // Remove inactive threads
2939 QList <QFuture<void> > futures = m_jobThreads.futures();
2940 m_jobThreads.clearFutures();
2941 for (int i = 0; i < futures.count(); i++)
2942 if (!futures.at(i).isFinished()) {
2943 m_jobThreads.addFuture(futures.at(i));
2946 if (m_jobList.isEmpty()) return;
2949 for (int i = 0; i < m_jobList.count(); i++) {
2950 if (m_jobList.at(i)->jobStatus == JOBWORKING || m_jobList.at(i)->jobStatus == JOBWAITING)
2953 // remove finished jobs
2954 AbstractClipJob *job = m_jobList.takeAt(i);
2960 emit jobCount(count);
2961 m_jobMutex.unlock();
2963 if (m_jobThreads.futures().isEmpty() || m_jobThreads.futures().count() < KdenliveSettings::proxythreads()) m_jobThreads.addFuture(QtConcurrent::run(this, &ProjectList::slotProcessJobs));
2966 void ProjectList::slotAbortProxy(const QString id, const QString path)
2970 ProjectItem *item = getItemById(id);
2972 if (!item->isProxyRunning()) slotGotProxy(item);
2973 item->setConditionalJobStatus(NOJOB, PROXYJOB);
2974 discardJobs(id, PROXYJOB);
2977 void ProjectList::slotProcessJobs()
2979 while (!m_jobList.isEmpty() && !m_abortAllJobs) {
2980 emit projectModified();
2981 AbstractClipJob *job = NULL;
2984 for (int i = 0; i < m_jobList.count(); i++) {
2985 if (m_jobList.at(i)->jobStatus == JOBWAITING) {
2987 m_jobList.at(i)->jobStatus = JOBWORKING;
2988 job = m_jobList.at(i);
2992 else if (m_jobList.at(i)->jobStatus == JOBWORKING)
2996 emit jobCount(count);
2997 m_jobMutex.unlock();
3002 QString destination = job->destination();
3003 // Check if the clip is still here
3004 DocClipBase *currentClip = m_doc->clipManager()->getClipById(job->clipId());
3005 //ProjectItem *processingItem = getItemById(job->clipId());
3006 if (currentClip == NULL) {
3007 job->setStatus(JOBDONE);
3010 // Set clip status to started
3011 emit processLog(job->clipId(), 0, job->jobType, job->statusMessage());
3013 // Make sure destination path is writable
3014 if (!destination.isEmpty()) {
3015 QFile file(destination);
3016 if (!file.open(QIODevice::WriteOnly)) {
3017 emit updateJobStatus(job->clipId(), job->jobType, JOBCRASHED, i18n("Cannot write to path: %1", destination));
3018 job->setStatus(JOBCRASHED);
3022 QFile::remove(destination);
3024 connect(job, SIGNAL(jobProgress(QString, int, int)), this, SIGNAL(processLog(QString, int, int)));
3025 connect(job, SIGNAL(cancelRunningJob(const QString, stringMap)), this, SIGNAL(cancelRunningJob(const QString, stringMap)));
3027 if (job->jobType == MLTJOB) {
3028 MeltJob *jb = static_cast<MeltJob *> (job);
3029 jb->setProducer(currentClip->getProducer(), currentClip->fileURL());
3030 if (jb->isProjectFilter())
3031 connect(job, SIGNAL(gotFilterJobResults(QString,int, int, stringMap,stringMap)), this, SLOT(slotGotFilterJobResults(QString,int, int,stringMap,stringMap)));
3033 connect(job, SIGNAL(gotFilterJobResults(QString,int, int, stringMap,stringMap)), this, SIGNAL(gotFilterJobResults(QString,int, int,stringMap,stringMap)));
3036 if (job->jobStatus == JOBDONE) {
3037 emit updateJobStatus(job->clipId(), job->jobType, JOBDONE);
3038 //TODO: replace with more generic clip replacement framework
3039 if (job->jobType == PROXYJOB) emit gotProxy(job->clipId());
3040 if (job->addClipToProject()) {
3041 emit addClip(destination, QString(), QString());
3043 } else if (job->jobStatus == JOBCRASHED || job->jobStatus == JOBABORTED) {
3044 emit updateJobStatus(job->clipId(), job->jobType, job->jobStatus, job->errorMessage(), QString(), job->logDetails());
3047 // Thread finished, cleanup & update count
3048 QTimer::singleShot(200, this, SIGNAL(checkJobProcess()));
3052 void ProjectList::updateProxyConfig()
3055 QTreeWidgetItemIterator it(m_listView);
3056 QUndoCommand *command = new QUndoCommand();
3057 command->setText(i18n("Update proxy settings"));
3058 QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/";
3060 if ((*it)->type() != PROJECTCLIPTYPE) {
3064 item = static_cast<ProjectItem *>(*it);
3069 CLIPTYPE t = item->clipType();
3070 if ((t == VIDEO || t == AV || t == UNKNOWN) && item->referencedClip() != NULL) {
3071 if (generateProxy() && useProxy() && !hasPendingJob(item, PROXYJOB)) {
3072 DocClipBase *clip = item->referencedClip();
3073 if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > m_doc->getDocumentProperty("proxyminsize").toInt()) {
3074 if (clip->getProperty("proxy").isEmpty()) {
3075 // We need to insert empty proxy in old properties so that undo will work
3076 QMap <QString, QString> oldProps;// = clip->properties();
3077 oldProps.insert("proxy", QString());
3078 QMap <QString, QString> newProps;
3079 newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + '.' + m_doc->getDocumentProperty("proxyextension"));
3080 new EditClipCommand(this, clip->getId(), oldProps, newProps, true, command);
3084 else if (item->hasProxy()) {
3086 QMap <QString, QString> newProps;
3087 newProps.insert("proxy", QString());
3088 // insert required duration for proxy
3089 newProps.insert("proxy_out", item->referencedClip()->producerProperty("out"));
3090 new EditClipCommand(this, item->clipId(), item->referencedClip()->currentProperties(newProps), newProps, true, command);
3093 else if (t == IMAGE && item->referencedClip() != NULL) {
3094 if (generateImageProxy() && useProxy()) {
3095 DocClipBase *clip = item->referencedClip();
3096 int maxImageSize = m_doc->getDocumentProperty("proxyimageminsize").toInt();
3097 if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > maxImageSize || clip->getProperty("frame_size").section('x', 1, 1).toInt() > maxImageSize) {
3098 if (clip->getProperty("proxy").isEmpty()) {
3099 // We need to insert empty proxy in old properties so that undo will work
3100 QMap <QString, QString> oldProps = clip->properties();
3101 oldProps.insert("proxy", QString());
3102 QMap <QString, QString> newProps;
3103 newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + ".png");
3104 new EditClipCommand(this, clip->getId(), oldProps, newProps, true, command);
3108 else if (item->hasProxy()) {
3110 QMap <QString, QString> newProps;
3111 newProps.insert("proxy", QString());
3112 new EditClipCommand(this, item->clipId(), item->referencedClip()->properties(), newProps, true, command);
3117 if (command->childCount() > 0) m_doc->commandStack()->push(command);
3118 else delete command;
3121 void ProjectList::slotProcessLog(const QString id, int progress, int type, const QString message)
3123 ProjectItem *item = getItemById(id);
3124 setJobStatus(item, (JOBTYPE) type, JOBWORKING, progress, message);
3127 void ProjectList::slotProxyCurrentItem(bool doProxy, ProjectItem *itemToProxy)
3129 QList<QTreeWidgetItem *> list;
3130 if (itemToProxy == NULL) list = m_listView->selectedItems();
3131 else list << itemToProxy;
3133 // expand list (folders, subclips) to get real clips
3134 QTreeWidgetItem *listItem;
3135 QList<ProjectItem *> clipList;
3136 for (int i = 0; i < list.count(); i++) {
3137 listItem = list.at(i);
3138 if (listItem->type() == PROJECTFOLDERTYPE) {
3139 for (int j = 0; j < listItem->childCount(); j++) {
3140 QTreeWidgetItem *sub = listItem->child(j);
3141 if (sub->type() == PROJECTCLIPTYPE) {
3142 ProjectItem *item = static_cast <ProjectItem*>(sub);
3143 if (!clipList.contains(item)) clipList.append(item);
3147 else if (listItem->type() == PROJECTSUBCLIPTYPE) {
3148 QTreeWidgetItem *sub = listItem->parent();
3149 ProjectItem *item = static_cast <ProjectItem*>(sub);
3150 if (!clipList.contains(item)) clipList.append(item);
3152 else if (listItem->type() == PROJECTCLIPTYPE) {
3153 ProjectItem *item = static_cast <ProjectItem*>(listItem);
3154 if (!clipList.contains(item)) clipList.append(item);
3158 QUndoCommand *command = new QUndoCommand();
3159 if (doProxy) command->setText(i18np("Add proxy clip", "Add proxy clips", clipList.count()));
3160 else command->setText(i18np("Remove proxy clip", "Remove proxy clips", clipList.count()));
3162 // Make sure the proxy folder exists
3163 QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/";
3164 KStandardDirs::makeDir(proxydir);
3166 QMap <QString, QString> newProps;
3167 QMap <QString, QString> oldProps;
3168 if (!doProxy) newProps.insert("proxy", "-");
3169 for (int i = 0; i < clipList.count(); i++) {
3170 ProjectItem *item = clipList.at(i);
3171 CLIPTYPE t = item->clipType();
3172 if ((t == VIDEO || t == AV || t == UNKNOWN || t == IMAGE || t == PLAYLIST) && item->referencedClip()) {
3173 if ((doProxy && item->hasProxy()) || (!doProxy && !item->hasProxy() && item->referencedClip()->getProducer() != NULL)) continue;
3174 DocClipBase *clip = item->referencedClip();
3175 if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
3176 kDebug()<<"//// TRYING TO PROXY: "<<item->clipId()<<", but it is busy";
3180 //oldProps = clip->properties();
3183 QString path = proxydir + clip->getClipHash() + '.' + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension"));
3184 // insert required duration for proxy
3185 newProps.insert("proxy_out", clip->producerProperty("out"));
3186 newProps.insert("proxy", path);
3187 // We need to insert empty proxy so that undo will work
3188 //oldProps.insert("proxy", QString());
3190 else if (item->referencedClip()->getProducer() == NULL) {
3191 // Force clip reload
3192 kDebug()<<"// CLIP HAD NULL PROD------------";
3193 newProps.insert("resource", item->referencedClip()->getProperty("resource"));
3195 // We need to insert empty proxy so that undo will work
3196 oldProps = clip->currentProperties(newProps);
3197 if (doProxy) oldProps.insert("proxy", "-");
3198 new EditClipCommand(this, item->clipId(), oldProps, newProps, true, command);
3201 if (command->childCount() > 0) {
3202 m_doc->commandStack()->push(command);
3204 else delete command;
3208 void ProjectList::slotDeleteProxy(const QString proxyPath)
3210 if (proxyPath.isEmpty()) return;
3211 QUndoCommand *proxyCommand = new QUndoCommand();
3212 proxyCommand->setText(i18n("Remove Proxy"));
3213 QTreeWidgetItemIterator it(m_listView);
3216 if ((*it)->type() == PROJECTCLIPTYPE) {
3217 item = static_cast <ProjectItem *>(*it);
3218 if (item->referencedClip()->getProperty("proxy") == proxyPath) {
3219 QMap <QString, QString> props;
3220 props.insert("proxy", QString());
3221 new EditClipCommand(this, item->clipId(), item->referencedClip()->currentProperties(props), props, true, proxyCommand);
3227 if (proxyCommand->childCount() == 0)
3228 delete proxyCommand;
3230 m_commandStack->push(proxyCommand);
3231 QFile::remove(proxyPath);
3234 void ProjectList::setJobStatus(ProjectItem *item, JOBTYPE jobType, CLIPJOBSTATUS status, int progress, const QString &statusMessage)
3236 if (item == NULL || (m_abortAllJobs && m_closing)) return;
3237 monitorItemEditing(false);
3238 item->setJobStatus(jobType, status, progress, statusMessage);
3239 if (status == JOBCRASHED) {
3240 DocClipBase *clip = item->referencedClip();
3242 kDebug()<<"// PROXY CRASHED";
3244 else if (clip->getProducer() == NULL && !clip->isPlaceHolder()) {
3245 // disable proxy and fetch real clip
3246 clip->setProperty("proxy", "-");
3247 QDomElement xml = clip->toXML();
3248 m_render->getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), true);
3251 // Disable proxy for this clip
3252 clip->setProperty("proxy", "-");
3255 monitorItemEditing(true);
3258 void ProjectList::monitorItemEditing(bool enable)
3260 if (enable) connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
3261 else disconnect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
3264 QStringList ProjectList::expandedFolders() const
3267 FolderProjectItem *item;
3268 QTreeWidgetItemIterator it(m_listView);
3270 if ((*it)->type() != PROJECTFOLDERTYPE) {
3274 if ((*it)->isExpanded()) {
3275 item = static_cast<FolderProjectItem *>(*it);
3276 result.append(item->clipId());
3283 void ProjectList::processThumbOverlays(ProjectItem *item, QPixmap &pix)
3285 if (item->hasProxy()) {
3287 QColor c(220, 220, 10, 200);
3288 QRect r(0, 0, 12, 12);
3290 QFont font = p.font();
3293 p.setPen(Qt::black);
3294 p.drawText(r, Qt::AlignCenter, i18nc("The first letter of Proxy, used as abbreviation", "P"));
3298 void ProjectList::slotCancelJobs()
3300 m_abortAllJobs = true;
3301 for (int i = 0; i < m_jobList.count(); i++) {
3302 m_jobList.at(i)->setStatus(JOBABORTED);
3304 m_jobThreads.waitForFinished();
3305 m_jobThreads.clearFutures();
3306 QUndoCommand *command = new QUndoCommand();
3307 command->setText(i18np("Cancel job", "Cancel jobs", m_jobList.count()));
3309 for (int i = 0; i < m_jobList.count(); i++) {
3310 DocClipBase *currentClip = m_doc->clipManager()->getClipById(m_jobList.at(i)->clipId());
3311 if (!currentClip) continue;
3312 QMap <QString, QString> newProps = m_jobList.at(i)->cancelProperties();
3313 if (newProps.isEmpty()) continue;
3314 QMap <QString, QString> oldProps = currentClip->currentProperties(newProps);
3315 new EditClipCommand(this, m_jobList.at(i)->clipId(), oldProps, newProps, true, command);
3317 m_jobMutex.unlock();
3318 if (command->childCount() > 0) {
3319 m_doc->commandStack()->push(command);
3321 else delete command;
3322 if (!m_jobList.isEmpty()) qDeleteAll(m_jobList);
3324 m_abortAllJobs = false;
3325 m_infoLabel->slotSetJobCount(0);
3328 void ProjectList::slotCancelRunningJob(const QString id, stringMap newProps)
3330 if (newProps.isEmpty() || m_closing) return;
3331 DocClipBase *currentClip = m_doc->clipManager()->getClipById(id);
3332 if (!currentClip) return;
3333 QMap <QString, QString> oldProps = currentClip->currentProperties(newProps);
3334 if (newProps == oldProps) return;
3335 QMapIterator<QString, QString> i(oldProps);
3336 EditClipCommand *command = new EditClipCommand(this, id, oldProps, newProps, true);
3337 m_commandStack->push(command);
3340 bool ProjectList::hasPendingJob(ProjectItem *item, JOBTYPE type)
3342 if (!item || !item->referencedClip() || m_abortAllJobs) return false;
3343 AbstractClipJob *job;
3344 QMutexLocker lock(&m_jobMutex);
3345 for (int i = 0; i < m_jobList.count(); i++) {
3346 if (m_abortAllJobs) break;
3347 job = m_jobList.at(i);
3348 if (job->clipId() == item->clipId() && job->jobType == type && (job->jobStatus == JOBWAITING || job->jobStatus == JOBWORKING)) return true;
3354 void ProjectList::deleteJobsForClip(const QString &clipId)
3356 QMutexLocker lock(&m_jobMutex);
3357 for (int i = 0; i < m_jobList.count(); i++) {
3358 if (m_jobList.at(i)->clipId() == clipId) {
3359 m_jobList.at(i)->setStatus(JOBABORTED);
3364 void ProjectList::slotUpdateJobStatus(const QString id, int type, int status, const QString label, const QString actionName, const QString details)
3366 ProjectItem *item = getItemById(id);
3368 slotUpdateJobStatus(item, type, status, label, actionName, details);
3372 void ProjectList::slotUpdateJobStatus(ProjectItem *item, int type, int status, const QString &label, const QString &actionName, const QString details)
3374 item->setJobStatus((JOBTYPE) type, (CLIPJOBSTATUS) status);
3375 if (status != JOBCRASHED) return;
3376 #if KDE_IS_VERSION(4,7,0)
3377 QList<QAction *> actions = m_infoMessage->actions();
3378 if (m_infoMessage->isHidden()) {
3379 m_infoMessage->setText(label);
3380 m_infoMessage->setWordWrap(m_infoMessage->text().length() > 35);
3381 m_infoMessage->setMessageType(KMessageWidget::Warning);
3384 if (!actionName.isEmpty()) {
3385 QAction *action = NULL;
3386 QList< KActionCollection * > collections = KActionCollection::allCollections();
3387 for (int i = 0; i < collections.count(); i++) {
3388 KActionCollection *coll = collections.at(i);
3389 action = coll->action(actionName);
3392 if (action && !actions.contains(action)) m_infoMessage->addAction(action);
3394 if (!details.isEmpty()) {
3395 m_errorLog.append(details);
3396 if (!actions.contains(m_logAction)) m_infoMessage->addAction(m_logAction);
3398 m_infoMessage->animatedShow();
3400 // warning for KDE < 4.7
3401 KPassivePopup *passivePop = new KPassivePopup( this );
3402 passivePop->setAutoDelete(true);
3403 connect(passivePop, SIGNAL(clicked()), this, SLOT(slotClosePopup()));
3404 m_errorLog.append(details);
3405 KVBox *vb = new KVBox( passivePop );
3406 KHBox *vh1 = new KHBox( vb );
3407 KIcon icon("dialog-warning");
3408 QLabel *iconLabel = new QLabel(vh1);
3409 iconLabel->setPixmap(icon.pixmap(m_listView->iconSize()));
3410 (void) new QLabel( label, vh1);
3411 KHBox *box = new KHBox( vb );
3412 QPushButton *but = new QPushButton( "Show log", box );
3413 connect(but, SIGNAL(clicked(bool)), this, SLOT(slotShowJobLog()));
3415 passivePop->setView( vb );
3421 void ProjectList::slotShowJobLog()
3424 d.setButtons(KDialog::Close);
3426 for (int i = 0; i < m_errorLog.count(); i++) {
3427 if (i > 0) t.insertHtml("<br><hr /><br>");
3428 t.insertPlainText(m_errorLog.at(i));
3430 t.setReadOnly(true);
3431 d.setMainWidget(&t);
3435 QStringList ProjectList::getPendingJobs(const QString &id)
3438 QMutexLocker lock(&m_jobMutex);
3439 for (int i = 0; i < m_jobList.count(); i++) {
3440 if (m_jobList.at(i)->clipId() == id && (m_jobList.at(i)->jobStatus == JOBWAITING || m_jobList.at(i)->jobStatus == JOBWORKING)) {
3442 result << m_jobList.at(i)->description;
3448 void ProjectList::discardJobs(const QString &id, JOBTYPE type) {
3449 QMutexLocker lock(&m_jobMutex);
3450 for (int i = 0; i < m_jobList.count(); i++) {
3451 if (m_jobList.at(i)->clipId() == id && (m_jobList.at(i)->jobType == type || type == NOJOBTYPE)) {
3453 m_jobList.at(i)->setStatus(JOBABORTED);
3458 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)
3460 ProjectItem *item = getItemById(id);
3462 QStringList jobParams;
3463 jobParams << QString::number(info.cropStart.frames(m_fps)) << QString::number((info.cropStart + info.cropDuration).frames(m_fps));
3464 jobParams << QString() << filterName << filterParams << consumer << consumerParams << QString::number(info.startPos.frames(m_fps)) << QString::number(info.track);
3465 MeltJob *job = new MeltJob(item->clipType(), id, jobParams, extraParams);
3466 if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
3470 job->description = i18n("Filter %1", extraParams.value("finalfilter"));
3471 m_jobList.append(job);
3472 setJobStatus(item, job->jobType, JOBWAITING, 0, job->statusMessage());
3473 slotCheckJobProcess();
3476 void ProjectList::startClipFilterJob(const QString &filterName, const QString &condition)
3478 QStringList ids = getConditionalIds(condition);
3479 QString destination;
3480 ProjectItem *item = getItemById(ids.at(0));
3482 emit displayMessage(i18n("Cannot find clip to process filter %1", filterName), -2, ErrorMessage);
3485 if (ids.count() == 1) {
3486 destination = item->clipUrl().path();
3489 destination = item->clipUrl().directory();
3491 if (filterName == "motion_est") {
3492 // Show config dialog
3493 QPointer<QDialog> d = new QDialog(this);
3494 Ui::SceneCutDialog_UI ui;
3496 // Set up categories
3497 for (int i = 0; i < 5; ++i) {
3498 ui.marker_type->insertItem(i, i18n("Category %1", i));
3499 ui.marker_type->setItemData(i, CommentedTime::markerColor(i), Qt::DecorationRole);
3501 ui.marker_type->setCurrentIndex(KdenliveSettings::default_marker_type());
3502 if (d->exec() != QDialog::Accepted) {
3507 QStringList jobParams;
3509 jobParams << QString();
3510 // Filter params, use a smaller region of the image to speed up operation
3511 // In fact, it's faster to rescale whole image than using part of it (bounding=\"25%x25%:15%x15\")
3512 jobParams << filterName << "shot_change_list=0 denoise=0";
3514 jobParams << "null" << "all=1 terminate_on_pause=1 real_time=-1 rescale=nearest deinterlace_method=onefield top_field_first=-1";
3515 QMap <QString, QString> extraParams;
3516 extraParams.insert("key", "shot_change_list");
3517 extraParams.insert("projecttreefilter", "1");
3518 QString keyword("%count");
3519 extraParams.insert("resultmessage", i18n("Found %1 scenes.", keyword));
3520 extraParams.insert("resize_profile", "160");
3521 if (ui.store_data->isChecked()) {
3522 // We want to save result as clip metadata
3523 extraParams.insert("storedata", "1");
3525 if (ui.zone_only->isChecked()) {
3526 // We want to analyze only clip zone
3527 extraParams.insert("zoneonly", "1");
3529 if (ui.add_markers->isChecked()) {
3530 // We want to create markers
3531 extraParams.insert("addmarkers", QString::number(ui.marker_type->currentIndex()));
3533 if (ui.cut_scenes->isChecked()) {
3534 // We want to cut scenes
3535 extraParams.insert("cutscenes", "1");
3538 processClipJob(ids, QString(), false, jobParams, i18n("Auto split"), extraParams);
3541 QPointer<ClipStabilize> d = new ClipStabilize(destination, ids.count(), filterName);
3542 if (d->exec() == QDialog::Accepted) {
3543 QMap <QString, QString> extraParams;
3544 extraParams.insert("producer_profile", "1");
3545 processClipJob(ids, d->destination(), d->autoAddClip(), d->params(), d->desc(), extraParams);
3551 void ProjectList::processClipJob(QStringList ids, const QString&destination, bool autoAdd, QStringList jobParams, const QString &description, QMap <QString, QString> extraParams)
3553 QStringList preParams;
3555 preParams << QString::number(0) << QString::number(-1);
3557 preParams << jobParams.takeFirst();
3559 preParams << jobParams.takeFirst();
3561 preParams << jobParams.takeFirst();
3563 QString consumer = jobParams.takeFirst();
3565 foreach(const QString&id, ids) {
3566 ProjectItem *item = getItemById(id);
3567 if (!item) continue;
3568 QStringList jobArgs;
3569 if (extraParams.contains("zoneonly")) {
3570 // Analyse clip zone only, remove in / out and replace with zone
3571 preParams.takeFirst();
3572 preParams.takeFirst();
3573 QPoint zone = item->referencedClip()->zone();
3574 jobArgs << QString::number(zone.x()) << QString::number(zone.y());
3576 jobArgs << preParams;
3577 if (ids.count() == 1) {
3578 jobArgs << consumer + ':' + destination;
3581 jobArgs << consumer + ':' + destination + item->clipUrl().fileName() + ".mlt";
3583 jobArgs << jobParams;
3585 MeltJob *job = new MeltJob(item->clipType(), id, jobArgs, extraParams);
3587 job->setAddClipToProject(true);
3588 kDebug()<<"// ADDING TRUE";
3590 else kDebug()<<"// ADDING FALSE!!!";
3592 if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
3596 job->description = description;
3597 m_jobList.append(job);
3598 setJobStatus(item, job->jobType, JOBWAITING, 0, job->statusMessage());
3600 slotCheckJobProcess();
3603 void ProjectList::slotPrepareJobsMenu()
3606 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
3608 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE)
3609 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
3611 item = static_cast <ProjectItem*>(m_listView->currentItem());
3612 if (item && (item->flags() & Qt::ItemIsDragEnabled)) {
3613 QString id = item->clipId();
3614 m_discardCurrentClipJobs->setData(id);
3615 QStringList jobs = getPendingJobs(id);
3616 m_discardCurrentClipJobs->setEnabled(!jobs.isEmpty());
3618 m_discardCurrentClipJobs->setData(QString());
3619 m_discardCurrentClipJobs->setEnabled(false);
3623 void ProjectList::slotDiscardClipJobs()
3625 QString id = m_discardCurrentClipJobs->data().toString();
3626 if (id.isEmpty()) return;
3630 void ProjectList::updatePalette()
3632 m_infoLabel->setStyleSheet(SmallInfoLabel::getStyleSheet(QApplication::palette()));
3633 m_listView->updateStyleSheet();
3636 void ProjectList::slotResetInfoMessage()
3638 #if KDE_IS_VERSION(4,7,0)
3640 QList<QAction *> actions = m_infoMessage->actions();
3641 for (int i = 0; i < actions.count(); i++) {
3642 m_infoMessage->removeAction(actions.at(i));
3647 void ProjectList::slotClosePopup()
3652 void ProjectList::slotGotFilterJobResults(QString id, int , int , stringMap results, stringMap filterInfo)
3654 // Currently, only the first value of results is used
3655 kDebug()<<"// FILTER RES:\n"<<filterInfo<<"\n--------------\n"<<results;
3656 ProjectItem *clip = getItemById(id);
3658 // Check for return value
3659 int markersType = -1;
3660 if (filterInfo.contains("addmarkers")) markersType = filterInfo.value("addmarkers").toInt();
3661 if (results.isEmpty()) {
3662 emit displayMessage(i18n("No data returned from clip analysis"), 0, ErrorMessage);
3665 bool dataProcessed = false;
3666 QString key = filterInfo.value("key");
3667 int offset = filterInfo.value("offset").toInt();
3668 QStringList value = results.value(key).split(';', QString::SkipEmptyParts);
3669 kDebug()<<"// RESULT; "<<key<<" = "<<value;
3670 if (filterInfo.contains("resultmessage")) {
3671 QString mess = filterInfo.value("resultmessage");
3672 mess.replace("%count", QString::number(value.count()));
3673 emit displayMessage(mess, 0, InformationMessage);
3675 else emit displayMessage(i18n("Processing data analysis"), 0, InformationMessage);
3676 if (filterInfo.contains("cutscenes")) {
3677 // Check if we want to cut scenes from returned data
3678 dataProcessed = true;
3680 QUndoCommand *command = new QUndoCommand();
3681 command->setText(i18n("Auto Split Clip"));
3682 foreach (QString pos, value) {
3683 if (!pos.contains("=")) continue;
3684 int newPos = pos.section("=", 0, 0).toInt();
3685 // Don't use scenes shorter than 1 second
3686 if (newPos - cutPos < 24) continue;
3687 (void) new AddClipCutCommand(this, id, cutPos + offset, newPos + offset, QString(), true, false, command);
3690 if (command->childCount() == 0)
3692 else m_commandStack->push(command);
3694 if (markersType >= 0) {
3695 // Add markers from returned data
3696 dataProcessed = true;
3698 QUndoCommand *command = new QUndoCommand();
3699 command->setText(i18n("Add Markers"));
3700 QList <CommentedTime> markersList;
3702 foreach (QString pos, value) {
3703 if (!pos.contains("=")) continue;
3704 int newPos = pos.section("=", 0, 0).toInt();
3705 // Don't use scenes shorter than 1 second
3706 if (newPos - cutPos < 24) continue;
3707 CommentedTime m(GenTime(newPos + offset, m_fps), QString::number(index), markersType);
3712 emit addMarkers(id, markersList);
3714 if (!dataProcessed || filterInfo.contains("storedata")) {
3715 // Store returned data as clip extra data
3716 clip->referencedClip()->setAnalysisData(filterInfo.contains("displaydataname") ? filterInfo.value("displaydataname") : key, results.value(key), filterInfo.value("offset").toInt());
3717 emit updateAnalysisData(clip->referencedClip());
3722 #include "projectlist.moc"