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"
51 #include <KFileDialog>
52 #include <KInputDialog>
53 #include <KMessageBox>
54 #include <KIO/NetAccess>
56 #include <KApplication>
57 #include <KStandardDirs>
58 #include <KColorScheme>
59 #include <KActionCollection>
60 #include <KUrlRequester>
65 #include <nepomuk/global.h>
66 #include <nepomuk/resourcemanager.h>
67 #include <Nepomuk/Resource>
68 //#include <nepomuk/tag.h>
71 #include <QMouseEvent>
72 #include <QStylePainter>
78 #include <QHeaderView>
79 #include <QInputDialog>
80 #include <QtConcurrentRun>
81 #include <QVBoxLayout>
82 #include <KPassivePopup>
85 MyMessageWidget::MyMessageWidget(QWidget *parent) : KMessageWidget(parent) {}
86 MyMessageWidget::MyMessageWidget(const QString &text, QWidget *parent) : KMessageWidget(text, parent) {}
89 bool MyMessageWidget::event(QEvent* ev) {
90 if (ev->type() == QEvent::Hide || ev->type() == QEvent::Close) emit messageClosing();
91 return KMessageWidget::event(ev);
94 SmallInfoLabel::SmallInfoLabel(QWidget *parent) : QPushButton(parent)
99 /*QString style = "QToolButton {background-color: %1;border-style: outset;border-width: 2px;
100 border-radius: 5px;border-color: beige;}";*/
101 m_timeLine = new QTimeLine(500, this);
102 QObject::connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(slotTimeLineChanged(qreal)));
103 QObject::connect(m_timeLine, SIGNAL(finished()), this, SLOT(slotTimeLineFinished()));
107 const QString SmallInfoLabel::getStyleSheet(const QPalette &p)
109 KColorScheme scheme(p.currentColorGroup(), KColorScheme::Window, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
110 QColor bg = scheme.background(KColorScheme::LinkBackground).color();
111 QColor fg = scheme.foreground(KColorScheme::LinkText).color();
112 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());
114 bg = scheme.background(KColorScheme::ActiveBackground).color();
115 fg = scheme.foreground(KColorScheme::ActiveText).color();
116 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()));
121 void SmallInfoLabel::slotTimeLineChanged(qreal value)
123 setFixedWidth(qMin(value * 2, qreal(1.0)) * sizeHint().width());
127 void SmallInfoLabel::slotTimeLineFinished()
129 if (m_timeLine->direction() == QTimeLine::Forward) {
139 void SmallInfoLabel::slotSetJobCount(int jobCount)
143 setText(i18np("%1 job", "%1 jobs", jobCount));
144 setToolTip(i18np("%1 pending job", "%1 pending jobs", jobCount));
146 if (!(KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects)) {
147 setFixedWidth(sizeHint().width());
153 setFixedWidth(sizeHint().width());
160 int wantedWidth = sizeHint().width();
161 setGeometry(-wantedWidth, 0, wantedWidth, height());
162 m_timeLine->setDirection(QTimeLine::Forward);
163 if (m_timeLine->state() == QTimeLine::NotRunning) {
168 if (!(KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects)) {
174 m_timeLine->setDirection(QTimeLine::Backward);
175 if (m_timeLine->state() == QTimeLine::NotRunning) {
183 InvalidDialog::InvalidDialog(const QString &caption, const QString &message, bool infoOnly, QWidget *parent) : KDialog(parent)
186 if (infoOnly) setButtons(KDialog::Ok);
187 else setButtons(KDialog::Yes | KDialog::No);
188 QWidget *w = new QWidget(this);
189 QVBoxLayout *l = new QVBoxLayout;
190 l->addWidget(new QLabel(message));
191 m_clipList = new QListWidget;
192 l->addWidget(m_clipList);
197 InvalidDialog::~InvalidDialog()
203 void InvalidDialog::addClip(const QString &id, const QString &path)
205 QListWidgetItem *item = new QListWidgetItem(path);
206 item->setData(Qt::UserRole, id);
207 m_clipList->addItem(item);
210 QStringList InvalidDialog::getIds() const
213 for (int i = 0; i < m_clipList->count(); i++) {
214 ids << m_clipList->item(i)->data(Qt::UserRole).toString();
220 ProjectList::ProjectList(QWidget *parent) :
224 m_commandStack(NULL),
226 m_reloadAction(NULL),
227 m_extractAudioAction(NULL),
228 m_transcodeAction(NULL),
229 m_stabilizeAction(NULL),
232 m_allClipsProcessed(false),
234 m_abortAllJobs(false),
236 m_invalidClipDialog(NULL)
238 qRegisterMetaType<stringMap> ("stringMap");
239 QVBoxLayout *layout = new QVBoxLayout;
240 layout->setContentsMargins(0, 0, 0, 0);
241 layout->setSpacing(0);
242 qRegisterMetaType<QDomElement>("QDomElement");
244 QFrame *frame = new QFrame;
245 frame->setFrameStyle(QFrame::NoFrame);
246 QHBoxLayout *box = new QHBoxLayout;
247 box->setContentsMargins(0, 0, 0, 0);
249 KTreeWidgetSearchLine *searchView = new KTreeWidgetSearchLine;
250 box->addWidget(searchView);
252 // small info button for pending jobs
253 m_infoLabel = new SmallInfoLabel(this);
254 m_infoLabel->setStyleSheet(SmallInfoLabel::getStyleSheet(palette()));
255 connect(this, SIGNAL(jobCount(int)), m_infoLabel, SLOT(slotSetJobCount(int)));
256 m_jobsMenu = new QMenu(this);
257 connect(m_jobsMenu, SIGNAL(aboutToShow()), this, SLOT(slotPrepareJobsMenu()));
258 QAction *cancelJobs = new QAction(i18n("Cancel All Jobs"), this);
259 cancelJobs->setCheckable(false);
260 connect(cancelJobs, SIGNAL(triggered()), this, SLOT(slotCancelJobs()));
261 connect(this, SIGNAL(checkJobProcess()), this, SLOT(slotCheckJobProcess()));
262 m_discardCurrentClipJobs = new QAction(i18n("Cancel Current Clip Jobs"), this);
263 m_discardCurrentClipJobs->setCheckable(false);
264 connect(m_discardCurrentClipJobs, SIGNAL(triggered()), this, SLOT(slotDiscardClipJobs()));
265 m_jobsMenu->addAction(cancelJobs);
266 m_jobsMenu->addAction(m_discardCurrentClipJobs);
267 m_infoLabel->setMenu(m_jobsMenu);
268 box->addWidget(m_infoLabel);
270 int size = style()->pixelMetric(QStyle::PM_SmallIconSize);
271 QSize iconSize(size, size);
273 m_addButton = new QToolButton;
274 m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
275 m_addButton->setAutoRaise(true);
276 m_addButton->setIconSize(iconSize);
277 box->addWidget(m_addButton);
279 m_editButton = new QToolButton;
280 m_editButton->setAutoRaise(true);
281 m_editButton->setIconSize(iconSize);
282 box->addWidget(m_editButton);
284 m_deleteButton = new QToolButton;
285 m_deleteButton->setAutoRaise(true);
286 m_deleteButton->setIconSize(iconSize);
287 box->addWidget(m_deleteButton);
288 frame->setLayout(box);
289 layout->addWidget(frame);
291 m_listView = new ProjectListView(this);
292 layout->addWidget(m_listView);
294 #if KDE_IS_VERSION(4,7,0)
295 m_infoMessage = new MyMessageWidget;
296 layout->addWidget(m_infoMessage);
297 m_infoMessage->setCloseButtonVisible(true);
298 connect(m_infoMessage, SIGNAL(messageClosing()), this, SLOT(slotResetInfoMessage()));
299 //m_infoMessage->setWordWrap(true);
300 m_infoMessage->hide();
301 m_logAction = new QAction(i18n("Show Log"), this);
302 m_logAction->setCheckable(false);
303 connect(m_logAction, SIGNAL(triggered()), this, SLOT(slotShowJobLog()));
307 searchView->setTreeWidget(m_listView);
309 connect(this, SIGNAL(processNextThumbnail()), this, SLOT(slotProcessNextThumbnail()));
310 connect(m_listView, SIGNAL(projectModified()), this, SIGNAL(projectModified()));
311 connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
312 connect(m_listView, SIGNAL(focusMonitor()), this, SIGNAL(raiseClipMonitor()));
313 connect(m_listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
314 connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
315 connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
316 connect(m_listView, SIGNAL(addClip(const QList <QUrl>, const QString &, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &, const QString &)));
317 connect(this, SIGNAL(addClip(const QString, const QString &, const QString &)), this, SLOT(slotAddClip(const QString, const QString &, const QString &)));
318 connect(m_listView, SIGNAL(addClipCut(const QString &, int, int)), this, SLOT(slotAddClipCut(const QString &, int, int)));
319 connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
320 connect(m_listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
322 connect(this, SIGNAL(cancelRunningJob(const QString, stringMap )), this, SLOT(slotCancelRunningJob(const QString, stringMap)));
323 connect(this, SIGNAL(processLog(const QString, int , int, const QString)), this, SLOT(slotProcessLog(const QString, int , int, const QString)));
325 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)));
327 connect(this, SIGNAL(gotProxy(const QString)), this, SLOT(slotGotProxyForId(const QString)));
329 m_listViewDelegate = new ItemDelegate(m_listView);
330 m_listView->setItemDelegate(m_listViewDelegate);
332 if (KdenliveSettings::activate_nepomuk()) {
333 Nepomuk::ResourceManager::instance()->init();
334 if (!Nepomuk::ResourceManager::instance()->initialized()) {
335 kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
336 KdenliveSettings::setActivate_nepomuk(false);
342 ProjectList::~ProjectList()
344 m_abortAllJobs = true;
345 for (int i = 0; i < m_jobList.count(); i++) {
346 m_jobList.at(i)->setStatus(JOBABORTED);
349 m_thumbnailQueue.clear();
350 m_jobThreads.waitForFinished();
351 m_jobThreads.clearFutures();
352 if (!m_jobList.isEmpty()) qDeleteAll(m_jobList);
355 m_listView->blockSignals(true);
357 delete m_listViewDelegate;
358 #if KDE_IS_VERSION(4,7,0)
359 delete m_infoMessage;
363 void ProjectList::focusTree() const
365 m_listView->setFocus();
368 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
370 QList <QAction *> actions = addMenu->actions();
371 for (int i = 0; i < actions.count(); i++) {
372 if (actions.at(i)->data().toString() == "clip_properties") {
373 m_editButton->setDefaultAction(actions.at(i));
376 } else if (actions.at(i)->data().toString() == "delete_clip") {
377 m_deleteButton->setDefaultAction(actions.at(i));
380 } else if (actions.at(i)->data().toString() == "edit_clip") {
381 m_openAction = actions.at(i);
384 } else if (actions.at(i)->data().toString() == "reload_clip") {
385 m_reloadAction = actions.at(i);
388 } else if (actions.at(i)->data().toString() == "proxy_clip") {
389 m_proxyAction = actions.at(i);
395 QMenu *m = new QMenu();
396 m->addActions(actions);
397 m_addButton->setMenu(m);
398 m_addButton->setDefaultAction(defaultAction);
399 m_menu = new QMenu();
400 m_menu->addActions(addMenu->actions());
403 void ProjectList::setupGeneratorMenu(const QHash<QString,QMenu*>& menus)
405 if (!menus.contains("addMenu") && ! menus.value("addMenu") )
407 QMenu *menu = m_addButton->menu();
408 if (menus.contains("addMenu") && menus.value("addMenu")){
409 QMenu* addMenu=menus.value("addMenu");
410 menu->addMenu(addMenu);
411 m_addButton->setMenu(menu);
412 if (addMenu->isEmpty())
413 addMenu->setEnabled(false);
415 if (menus.contains("extractAudioMenu") && menus.value("extractAudioMenu") ){
416 QMenu* extractAudioMenu = menus.value("extractAudioMenu");
417 m_menu->addMenu(extractAudioMenu);
418 m_extractAudioAction = extractAudioMenu;
420 if (menus.contains("transcodeMenu") && menus.value("transcodeMenu") ){
421 QMenu* transcodeMenu = menus.value("transcodeMenu");
422 m_menu->addMenu(transcodeMenu);
423 if (transcodeMenu->isEmpty())
424 transcodeMenu->setEnabled(false);
425 m_transcodeAction = transcodeMenu;
427 if (menus.contains("stabilizeMenu") && menus.value("stabilizeMenu") ){
428 QMenu* stabilizeMenu=menus.value("stabilizeMenu");
429 m_menu->addMenu(stabilizeMenu);
430 if (stabilizeMenu->isEmpty())
431 stabilizeMenu->setEnabled(false);
432 m_stabilizeAction=stabilizeMenu;
435 m_menu->addAction(m_reloadAction);
436 m_menu->addAction(m_proxyAction);
437 if (menus.contains("inTimelineMenu") && menus.value("inTimelineMenu")){
438 QMenu* inTimelineMenu=menus.value("inTimelineMenu");
439 m_menu->addMenu(inTimelineMenu);
440 inTimelineMenu->setEnabled(false);
442 m_menu->addAction(m_editButton->defaultAction());
443 m_menu->addAction(m_openAction);
444 m_menu->addAction(m_deleteButton->defaultAction());
445 m_menu->insertSeparator(m_deleteButton->defaultAction());
448 void ProjectList::clearSelection()
450 m_listView->clearSelection();
453 QByteArray ProjectList::headerInfo() const
455 return m_listView->header()->saveState();
458 void ProjectList::setHeaderInfo(const QByteArray &state)
460 m_listView->header()->restoreState(state);
463 void ProjectList::updateProjectFormat(Timecode t)
468 void ProjectList::slotEditClip()
470 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
471 if (list.isEmpty()) return;
472 if (list.count() > 1 || list.at(0)->type() == PROJECTFOLDERTYPE) {
473 editClipSelection(list);
477 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
479 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE)
480 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
482 item = static_cast <ProjectItem*>(m_listView->currentItem());
483 if (item && (item->flags() & Qt::ItemIsDragEnabled)) {
484 emit clipSelected(item->referencedClip());
485 emit showClipProperties(item->referencedClip());
489 void ProjectList::editClipSelection(QList<QTreeWidgetItem *> list)
491 // Gather all common properties
492 QMap <QString, QString> commonproperties;
493 QList <DocClipBase *> clipList;
494 commonproperties.insert("force_aspect_num", "-");
495 commonproperties.insert("force_aspect_den", "-");
496 commonproperties.insert("force_fps", "-");
497 commonproperties.insert("force_progressive", "-");
498 commonproperties.insert("force_tff", "-");
499 commonproperties.insert("threads", "-");
500 commonproperties.insert("video_index", "-");
501 commonproperties.insert("audio_index", "-");
502 commonproperties.insert("force_colorspace", "-");
503 commonproperties.insert("full_luma", "-");
504 QString transparency = "-";
506 bool allowDurationChange = true;
507 int commonDuration = -1;
508 bool hasImages = false;;
510 for (int i = 0; i < list.count(); i++) {
512 if (list.at(i)->type() == PROJECTFOLDERTYPE) {
513 // Add folder items to the list
514 int ct = list.at(i)->childCount();
515 for (int j = 0; j < ct; j++) {
516 list.append(list.at(i)->child(j));
520 else if (list.at(i)->type() == PROJECTSUBCLIPTYPE)
521 item = static_cast <ProjectItem*>(list.at(i)->parent());
523 item = static_cast <ProjectItem*>(list.at(i));
524 if (!(item->flags() & Qt::ItemIsDragEnabled))
528 DocClipBase *clip = item->referencedClip();
529 if (clipList.contains(clip)) continue;
530 if (clip->clipType() == IMAGE) {
532 if (clip->getProperty("transparency").isEmpty() || clip->getProperty("transparency").toInt() == 0) {
533 if (transparency == "-") {
534 // first non transparent image
537 else if (transparency == "1") {
538 // we have transparent and non transparent clips
543 if (transparency == "-") {
544 // first transparent image
547 else if (transparency == "0") {
548 // we have transparent and non transparent clips
553 if (clip->clipType() != COLOR && clip->clipType() != IMAGE && clip->clipType() != TEXT)
554 allowDurationChange = false;
555 if (allowDurationChange && commonDuration != 0) {
556 if (commonDuration == -1)
557 commonDuration = clip->duration().frames(m_fps);
558 else if (commonDuration != clip->duration().frames(m_fps))
561 clipList.append(clip);
562 QMap <QString, QString> clipprops = clip->properties();
563 QMapIterator<QString, QString> p(commonproperties);
564 while (p.hasNext()) {
566 if (p.value().isEmpty()) continue;
567 if (clipprops.contains(p.key())) {
568 if (p.value() == "-")
569 commonproperties.insert(p.key(), clipprops.value(p.key()));
570 else if (p.value() != clipprops.value(p.key()))
571 commonproperties.insert(p.key(), QString());
573 commonproperties.insert(p.key(), QString());
578 if (allowDurationChange)
579 commonproperties.insert("out", QString::number(commonDuration));
581 commonproperties.insert("transparency", transparency);
582 /*QMapIterator<QString, QString> p(commonproperties);
583 while (p.hasNext()) {
585 kDebug() << "Result: " << p.key() << " = " << p.value();
587 if (clipList.isEmpty()) {
588 emit displayMessage(i18n("No available clip selected"), -2);
590 else emit showClipProperties(clipList, commonproperties);
593 void ProjectList::slotOpenClip()
596 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
598 if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1)
599 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
601 item = static_cast <ProjectItem*>(m_listView->currentItem());
603 if (item->clipType() == IMAGE) {
604 if (KdenliveSettings::defaultimageapp().isEmpty())
605 KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open images in the Settings dialog"));
607 QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
609 if (item->clipType() == AUDIO) {
610 if (KdenliveSettings::defaultaudioapp().isEmpty())
611 KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open audio files in the Settings dialog"));
613 QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
618 void ProjectList::cleanup()
620 m_listView->clearSelection();
621 QTreeWidgetItemIterator it(m_listView);
624 if ((*it)->type() != PROJECTCLIPTYPE) {
628 item = static_cast <ProjectItem *>(*it);
629 if (item->numReferences() == 0)
630 item->setSelected(true);
636 void ProjectList::trashUnusedClips()
638 QTreeWidgetItemIterator it(m_listView);
643 if ((*it)->type() != PROJECTCLIPTYPE) {
647 item = static_cast <ProjectItem *>(*it);
648 if (item->numReferences() == 0) {
649 ids << item->clipId();
650 KUrl url = item->clipUrl();
651 if (!url.isEmpty() && !urls.contains(url.path()))
657 // Check that we don't use the URL in another clip
658 QTreeWidgetItemIterator it2(m_listView);
660 if ((*it2)->type() != PROJECTCLIPTYPE) {
664 item = static_cast <ProjectItem *>(*it2);
665 if (item->numReferences() > 0) {
666 KUrl url = item->clipUrl();
667 if (!url.isEmpty() && urls.contains(url.path())) urls.removeAll(url.path());
672 emit deleteProjectClips(ids, QMap <QString, QString>());
673 for (int i = 0; i < urls.count(); i++)
674 KIO::NetAccess::del(KUrl(urls.at(i)), this);
677 void ProjectList::slotReloadClip(const QString &id)
679 QList<QTreeWidgetItem *> selected;
681 selected = m_listView->selectedItems();
683 ProjectItem *itemToReLoad = getItemById(id);
684 if (itemToReLoad) selected.append(itemToReLoad);
687 for (int i = 0; i < selected.count(); i++) {
688 if (selected.at(i)->type() != PROJECTCLIPTYPE) {
689 if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
690 for (int j = 0; j < selected.at(i)->childCount(); j++)
691 selected.append(selected.at(i)->child(j));
695 item = static_cast <ProjectItem *>(selected.at(i));
696 if (item && !hasPendingJob(item, PROXYJOB)) {
697 DocClipBase *clip = item->referencedClip();
698 if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
699 kDebug()<<"//// TRYING TO RELOAD: "<<item->clipId()<<", but it is busy";
702 CLIPTYPE t = item->clipType();
704 if (clip && !clip->getProperty("xmltemplate").isEmpty())
705 regenerateTemplate(item);
706 } else if (t != COLOR && t != SLIDESHOW && clip && clip->checkHash() == false) {
707 item->referencedClip()->setPlaceHolder(true);
708 item->setProperty("file_hash", QString());
709 } else if (t == IMAGE) {
710 //clip->getProducer() clip->getProducer()->set("force_reload", 1);
713 QDomElement e = item->toXml();
714 // Make sure we get the correct producer length if it was adjusted in timeline
715 if (t == COLOR || t == IMAGE || t == SLIDESHOW || t == TEXT) {
716 int length = QString(clip->producerProperty("length")).toInt();
717 if (length > 0 && !e.hasAttribute("length")) {
718 e.setAttribute("length", length);
721 resetThumbsProducer(clip);
722 m_render->getFileProperties(e, item->clipId(), m_listView->iconSize().height(), true);
727 void ProjectList::slotModifiedClip(const QString &id)
729 ProjectItem *item = getItemById(id);
731 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
732 if (!pixmap.isNull()) {
734 p.fillRect(0, 0, pixmap.width(), pixmap.height(), QColor(255, 255, 255, 200));
735 p.drawPixmap(0, 0, KIcon("view-refresh").pixmap(m_listView->iconSize()));
738 pixmap = KIcon("view-refresh").pixmap(m_listView->iconSize());
740 item->setData(0, Qt::DecorationRole, pixmap);
744 void ProjectList::slotMissingClip(const QString &id)
746 ProjectItem *item = getItemById(id);
748 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
749 int height = m_listView->iconSize().height();
750 if (m_render == NULL) {
751 kDebug() << "********* ERROR, NULL RENDR";
754 int width = (int)(height * m_render->dar());
755 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
756 if (pixmap.isNull()) {
757 pixmap = QPixmap(width, height);
758 pixmap.fill(Qt::transparent);
760 KIcon icon("dialog-close");
762 p.drawPixmap(3, 3, icon.pixmap(width - 6, height - 6));
764 item->setData(0, Qt::DecorationRole, pixmap);
765 if (item->referencedClip()) {
766 item->referencedClip()->setPlaceHolder(true);
767 Mlt::Producer *newProd = m_render->invalidProducer(id);
768 if (item->referencedClip()->getProducer()) {
769 Mlt::Properties props(newProd->get_properties());
770 Mlt::Properties src_props(item->referencedClip()->getProducer()->get_properties());
771 props.inherit(src_props);
773 item->referencedClip()->setProducer(newProd, true);
774 item->slotSetToolTip();
775 emit clipNeedsReload(id);
779 emit displayMessage(i18n("Check missing clips"), -2);
780 emit updateRenderStatus();
783 void ProjectList::slotAvailableClip(const QString &id)
785 ProjectItem *item = getItemById(id);
788 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
789 if (item->referencedClip()) { // && item->referencedClip()->checkHash() == false) {
790 item->setProperty("file_hash", QString());
794 item->referencedClip()->setValid();
795 item->slotSetToolTip();
798 emit updateRenderStatus();
801 bool ProjectList::hasMissingClips()
803 bool missing = false;
804 QTreeWidgetItemIterator it(m_listView);
806 if ((*it)->type() == PROJECTCLIPTYPE && !((*it)->flags() & Qt::ItemIsDragEnabled)) {
815 void ProjectList::setRenderer(Render *projectRender)
817 m_render = projectRender;
818 m_listView->setIconSize(QSize((ProjectItem::itemDefaultHeight() - 2) * m_render->dar(), ProjectItem::itemDefaultHeight() - 2));
819 connect(m_render, SIGNAL(requestProxy(QString)), this, SLOT(slotCreateProxy(QString)));
822 void ProjectList::slotClipSelected()
824 QTreeWidgetItem *item = m_listView->currentItem();
825 ProjectItem *clip = NULL;
827 if (item->type() == PROJECTFOLDERTYPE) {
828 emit clipSelected(NULL);
829 m_editButton->defaultAction()->setEnabled(item->childCount() > 0);
830 m_deleteButton->defaultAction()->setEnabled(true);
831 m_openAction->setEnabled(false);
832 m_reloadAction->setEnabled(false);
833 m_extractAudioAction->setEnabled(false);
834 m_transcodeAction->setEnabled(false);
835 m_stabilizeAction->setEnabled(false);
837 if (item->type() == PROJECTSUBCLIPTYPE) {
838 // this is a sub item, use base clip
839 m_deleteButton->defaultAction()->setEnabled(true);
840 clip = static_cast <ProjectItem*>(item->parent());
841 if (clip == NULL) kDebug() << "-----------ERROR";
842 SubProjectItem *sub = static_cast <SubProjectItem*>(item);
843 emit clipSelected(clip->referencedClip(), sub->zone());
844 m_extractAudioAction->setEnabled(false);
845 m_transcodeAction->setEnabled(false);
846 m_stabilizeAction->setEnabled(false);
847 m_reloadAction->setEnabled(false);
848 adjustProxyActions(clip);
851 clip = static_cast <ProjectItem*>(item);
852 if (clip && clip->referencedClip())
853 emit clipSelected(clip->referencedClip());
854 m_editButton->defaultAction()->setEnabled(true);
855 m_deleteButton->defaultAction()->setEnabled(true);
856 m_reloadAction->setEnabled(true);
857 m_extractAudioAction->setEnabled(true);
858 m_transcodeAction->setEnabled(true);
859 m_stabilizeAction->setEnabled(true);
860 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
861 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
862 m_openAction->setEnabled(true);
863 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
864 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
865 m_openAction->setEnabled(true);
867 m_openAction->setEnabled(false);
869 // Display relevant transcoding actions only
870 adjustTranscodeActions(clip);
871 adjustStabilizeActions(clip);
872 // Display uses in timeline
873 emit findInTimeline(clip->clipId());
876 emit clipSelected(NULL);
877 m_editButton->defaultAction()->setEnabled(false);
878 m_deleteButton->defaultAction()->setEnabled(false);
879 m_openAction->setEnabled(false);
880 m_reloadAction->setEnabled(false);
881 m_extractAudioAction->setEnabled(true);
882 m_transcodeAction->setEnabled(false);
883 m_stabilizeAction->setEnabled(false);
885 adjustProxyActions(clip);
888 void ProjectList::adjustProxyActions(ProjectItem *clip) const
890 if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == SLIDESHOW || clip->clipType() == AUDIO) {
891 m_proxyAction->setEnabled(false);
894 bool enabled = useProxy();
895 if (clip->referencedClip() && !clip->referencedClip()->getProperty("_missingsource").isEmpty()) enabled = false;
896 m_proxyAction->setEnabled(enabled);
897 m_proxyAction->blockSignals(true);
898 m_proxyAction->setChecked(clip->hasProxy());
899 m_proxyAction->blockSignals(false);
902 void ProjectList::adjustStabilizeActions(ProjectItem *clip) const
905 if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW) {
906 m_stabilizeAction->setEnabled(false);
909 m_stabilizeAction->setEnabled(true);
913 void ProjectList::adjustTranscodeActions(ProjectItem *clip) const
915 if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW) {
916 m_transcodeAction->setEnabled(false);
917 m_extractAudioAction->setEnabled(false);
920 m_transcodeAction->setEnabled(true);
921 m_extractAudioAction->setEnabled(true);
922 QList<QAction *> transcodeActions = m_transcodeAction->actions();
925 for (int i = 0; i < transcodeActions.count(); i++) {
926 data = transcodeActions.at(i)->data().toStringList();
927 if (data.count() > 2) {
928 condition = data.at(2);
929 if (condition.startsWith("vcodec"))
930 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
931 else if (condition.startsWith("acodec"))
932 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
938 void ProjectList::slotPauseMonitor()
944 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
946 ProjectItem *item = getItemById(id);
948 slotUpdateClipProperties(item, properties);
949 if (properties.contains("out") || properties.contains("force_fps") || properties.contains("resource") || properties.contains("video_index") || properties.contains("audio_index")) {
951 } else if (properties.contains("colour") ||
952 properties.contains("xmldata") ||
953 properties.contains("force_aspect_num") ||
954 properties.contains("force_aspect_den") ||
955 properties.contains("templatetext")) {
956 slotRefreshClipThumbnail(item);
957 emit refreshClip(id, true);
958 } else if (properties.contains("full_luma") || properties.contains("force_colorspace") || properties.contains("loop")) {
959 emit refreshClip(id, false);
964 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
968 clip->setProperties(properties);
969 if (properties.contains("proxy")) {
970 if (properties.value("proxy") == "-" || properties.value("proxy").isEmpty())
971 // this should only apply to proxy jobs
972 clip->setConditionalJobStatus(NOJOB, PROXYJOB);
974 if (properties.contains("name")) {
975 monitorItemEditing(false);
976 clip->setText(0, properties.value("name"));
977 monitorItemEditing(true);
978 emit clipNameChanged(clip->clipId(), properties.value("name"));
980 if (properties.contains("description")) {
981 CLIPTYPE type = clip->clipType();
982 monitorItemEditing(false);
983 clip->setText(1, properties.value("description"));
984 monitorItemEditing(true);
986 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
987 // Use Nepomuk system to store clip description
988 Nepomuk::Resource f(clip->clipUrl().path());
989 f.setDescription(properties.value("description"));
992 emit projectModified();
996 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
998 if (item->type() == PROJECTSUBCLIPTYPE) {
999 // this is a sub-item
1001 // user edited description
1002 SubProjectItem *sub = static_cast <SubProjectItem*>(item);
1003 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
1004 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), sub->zone(), sub->description(), sub->text(1), true);
1005 m_commandStack->push(command);
1006 //slotUpdateCutClipProperties(sub->clipId(), sub->zone(), sub->text(1), sub->text(1));
1010 if (item->type() == PROJECTFOLDERTYPE) {
1012 FolderProjectItem *folder = static_cast <FolderProjectItem*>(item);
1013 editFolder(item->text(0), folder->groupName(), folder->clipId());
1014 folder->setGroupName(item->text(0));
1015 m_doc->clipManager()->addFolder(folder->clipId(), item->text(0));
1016 const int children = item->childCount();
1017 for (int i = 0; i < children; i++) {
1018 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
1019 child->setProperty("groupname", item->text(0));
1025 ProjectItem *clip = static_cast <ProjectItem*>(item);
1027 if (clip->referencedClip()) {
1028 QMap <QString, QString> oldprops;
1029 QMap <QString, QString> newprops;
1030 oldprops["description"] = clip->referencedClip()->getProperty("description");
1031 newprops["description"] = item->text(1);
1033 if (clip->clipType() == TEXT) {
1034 // This is a text template clip, update the image
1035 /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
1036 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/
1037 oldprops.insert("templatetext", clip->referencedClip()->getProperty("templatetext"));
1038 newprops.insert("templatetext", item->text(1));
1040 slotUpdateClipProperties(clip->clipId(), newprops);
1041 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
1042 m_commandStack->push(command);
1044 } else if (column == 0) {
1045 if (clip->referencedClip()) {
1046 QMap <QString, QString> oldprops;
1047 QMap <QString, QString> newprops;
1048 oldprops["name"] = clip->referencedClip()->getProperty("name");
1049 if (oldprops.value("name") != item->text(0)) {
1050 newprops["name"] = item->text(0);
1051 slotUpdateClipProperties(clip, newprops);
1052 emit projectModified();
1053 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
1054 m_commandStack->push(command);
1055 QTimer::singleShot(100, this, SLOT(slotCheckScrolling()));
1061 void ProjectList::slotCheckScrolling()
1063 m_listView->scrollToItem(m_listView->currentItem());
1066 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
1068 bool enable = item ? true : false;
1069 m_editButton->defaultAction()->setEnabled(enable);
1070 m_deleteButton->defaultAction()->setEnabled(enable);
1071 m_reloadAction->setEnabled(enable);
1072 m_extractAudioAction->setEnabled(enable);
1073 m_transcodeAction->setEnabled(enable);
1074 m_stabilizeAction->setEnabled(enable);
1076 ProjectItem *clip = NULL;
1077 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
1078 clip = static_cast <ProjectItem*>(item->parent());
1079 m_extractAudioAction->setEnabled(false);
1080 m_transcodeAction->setEnabled(false);
1081 m_stabilizeAction->setEnabled(false);
1082 adjustProxyActions(clip);
1083 } else if (m_listView->currentItem()->type() == PROJECTCLIPTYPE) {
1084 clip = static_cast <ProjectItem*>(item);
1085 // Display relevant transcoding actions only
1086 adjustTranscodeActions(clip);
1087 adjustStabilizeActions(clip);
1088 adjustProxyActions(clip);
1089 // Display uses in timeline
1090 emit findInTimeline(clip->clipId());
1092 m_extractAudioAction->setEnabled(false);
1093 m_transcodeAction->setEnabled(false);
1094 m_stabilizeAction->setEnabled(false);
1096 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
1097 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
1098 m_openAction->setEnabled(true);
1099 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
1100 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
1101 m_openAction->setEnabled(true);
1103 m_openAction->setEnabled(false);
1107 m_openAction->setEnabled(false);
1112 void ProjectList::slotRemoveClip()
1114 if (!m_listView->currentItem())
1117 QMap <QString, QString> folderids;
1118 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
1120 QUndoCommand *delCommand = new QUndoCommand();
1121 delCommand->setText(i18n("Delete Clip Zone"));
1122 for (int i = 0; i < selected.count(); i++) {
1123 if (selected.at(i)->type() == PROJECTSUBCLIPTYPE) {
1125 SubProjectItem *sub = static_cast <SubProjectItem *>(selected.at(i));
1126 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
1127 new AddClipCutCommand(this, item->clipId(), sub->zone().x(), sub->zone().y(), sub->description(), false, true, delCommand);
1128 } else if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
1130 FolderProjectItem *folder = static_cast <FolderProjectItem *>(selected.at(i));
1131 folderids[folder->groupName()] = folder->clipId();
1132 int children = folder->childCount();
1134 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)
1136 for (int i = 0; i < children; ++i) {
1137 ProjectItem *child = static_cast <ProjectItem *>(folder->child(i));
1138 ids << child->clipId();
1141 ProjectItem *item = static_cast <ProjectItem *>(selected.at(i));
1142 ids << item->clipId();
1143 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) {
1144 KMessageBox::enableMessage("DeleteAll");
1149 KMessageBox::enableMessage("DeleteAll");
1150 if (delCommand->childCount() == 0)
1153 m_commandStack->push(delCommand);
1154 emit deleteProjectClips(ids, folderids);
1157 void ProjectList::updateButtons() const
1159 if (m_listView->topLevelItemCount() == 0) {
1160 m_deleteButton->defaultAction()->setEnabled(false);
1161 m_editButton->defaultAction()->setEnabled(false);
1163 m_deleteButton->defaultAction()->setEnabled(true);
1164 if (!m_listView->currentItem())
1165 m_listView->setCurrentItem(m_listView->topLevelItem(0));
1166 QTreeWidgetItem *item = m_listView->currentItem();
1167 if (item && item->type() == PROJECTCLIPTYPE) {
1168 m_editButton->defaultAction()->setEnabled(true);
1169 m_openAction->setEnabled(true);
1170 m_reloadAction->setEnabled(true);
1171 m_transcodeAction->setEnabled(true);
1172 m_stabilizeAction->setEnabled(true);
1175 else if (item && item->type() == PROJECTFOLDERTYPE && item->childCount() > 0) {
1176 m_editButton->defaultAction()->setEnabled(true);
1178 else m_editButton->defaultAction()->setEnabled(false);
1180 m_openAction->setEnabled(false);
1181 m_reloadAction->setEnabled(false);
1182 m_transcodeAction->setEnabled(false);
1183 m_stabilizeAction->setEnabled(false);
1184 m_proxyAction->setEnabled(false);
1187 void ProjectList::selectItemById(const QString &clipId)
1189 ProjectItem *item = getItemById(clipId);
1191 m_listView->setCurrentItem(item);
1195 void ProjectList::slotDeleteClip(const QString &clipId)
1197 ProjectItem *item = getItemById(clipId);
1199 kDebug() << "/// Cannot find clip to delete";
1202 deleteJobsForClip(clipId);
1203 m_listView->blockSignals(true);
1204 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
1205 if (!newSelectedItem)
1206 newSelectedItem = m_listView->itemBelow(item);
1208 // Pause playing to prevent crash while deleting clip
1210 m_doc->clipManager()->deleteClip(clipId);
1211 m_listView->blockSignals(false);
1212 if (newSelectedItem) {
1213 m_listView->setCurrentItem(newSelectedItem);
1216 emit clipSelected(NULL);
1221 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
1223 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
1224 m_commandStack->push(command);
1225 m_doc->setModified(true);
1228 void ProjectList::slotAddFolder(const QString &name)
1230 AddFolderCommand *command = new AddFolderCommand(this, name.isEmpty() ? i18n("Folder") : name, QString::number(m_doc->clipManager()->getFreeFolderId()), true);
1231 m_commandStack->push(command);
1234 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
1237 FolderProjectItem *item = getFolderItemById(clipId);
1239 m_doc->clipManager()->deleteFolder(clipId);
1240 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
1241 if (!newSelectedItem)
1242 newSelectedItem = m_listView->itemBelow(item);
1244 if (newSelectedItem)
1245 m_listView->setCurrentItem(newSelectedItem);
1251 FolderProjectItem *item = getFolderItemById(clipId);
1253 m_listView->blockSignals(true);
1254 item->setGroupName(foldername);
1255 m_listView->blockSignals(false);
1256 m_doc->clipManager()->addFolder(clipId, foldername);
1257 const int children = item->childCount();
1258 for (int i = 0; i < children; i++) {
1259 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
1260 child->setProperty("groupname", foldername);
1264 m_listView->blockSignals(true);
1265 m_listView->setCurrentItem(new FolderProjectItem(m_listView, QStringList() << foldername, clipId));
1266 m_doc->clipManager()->addFolder(clipId, foldername);
1267 m_listView->blockSignals(false);
1268 m_listView->editItem(m_listView->currentItem(), 0);
1272 m_doc->setModified(true);
1277 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
1279 QMapIterator<QString, QString> i(map);
1280 QUndoCommand *delCommand = new QUndoCommand();
1281 delCommand->setText(i18n("Delete Folder"));
1282 while (i.hasNext()) {
1284 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
1286 if (delCommand->childCount() > 0) m_commandStack->push(delCommand);
1287 else delete delCommand;
1290 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
1292 //m_listView->setEnabled(false);
1293 const QString parent = clip->getProperty("groupid");
1294 QString groupName = clip->getProperty("groupname");
1295 ProjectItem *item = NULL;
1296 monitorItemEditing(false);
1297 if (!parent.isEmpty()) {
1298 FolderProjectItem *parentitem = getFolderItemById(parent);
1301 //kDebug() << "Adding clip to new group: " << groupName;
1302 if (groupName.isEmpty()) groupName = i18n("Folder");
1304 parentitem = new FolderProjectItem(m_listView, text, parent);
1308 item = new ProjectItem(parentitem, clip);
1311 item = new ProjectItem(m_listView, clip);
1313 if (item->data(0, DurationRole).isNull()) item->setData(0, DurationRole, i18n("Loading"));
1314 connect(clip, SIGNAL(createProxy(const QString &)), this, SLOT(slotCreateProxy(const QString &)));
1315 connect(clip, SIGNAL(abortProxy(const QString &, const QString &)), this, SLOT(slotAbortProxy(const QString, const QString)));
1316 if (getProperties) {
1317 int height = m_listView->iconSize().height();
1318 int width = (int)(height * m_render->dar());
1319 QPixmap pix = KIcon("video-x-generic").pixmap(QSize(width, height));
1320 item->setData(0, Qt::DecorationRole, pix);
1321 //item->setFlags(Qt::ItemIsSelectable);
1322 m_listView->processLayout();
1323 QDomElement e = clip->toXML().cloneNode().toElement();
1324 if (!groupName.isEmpty()) {
1325 e.setAttribute("groupId", parent);
1326 e.setAttribute("group", groupName);
1328 e.removeAttribute("file_hash");
1329 resetThumbsProducer(clip);
1330 m_render->getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true);
1332 // WARNING: code below triggers unnecessary reload of all proxy clips on document loading... is it useful in some cases?
1333 /*else if (item->hasProxy() && !item->isJobRunning()) {
1334 slotCreateProxy(clip->getId());
1337 KUrl url = clip->fileURL();
1339 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk() && clip->getProperty("description").isEmpty()) {
1340 // if file has Nepomuk comment, use it
1341 Nepomuk::Resource f(url.path());
1342 QString annotation = f.description();
1343 if (!annotation.isEmpty()) {
1344 item->setText(1, annotation);
1345 clip->setProperty("description", annotation);
1347 item->setText(2, QString::number(f.rating()));
1351 // Add info to date column
1352 QFileInfo fileInfo(url.path());
1353 if (fileInfo.exists()) {
1354 item->setText(3, fileInfo.lastModified().toString(QString("yyyy/MM/dd hh:mm:ss")));
1358 QList <CutZoneInfo> cuts = clip->cutZones();
1359 if (!cuts.isEmpty()) {
1360 for (int i = 0; i < cuts.count(); i++) {
1361 SubProjectItem *sub = new SubProjectItem(item, cuts.at(i).zone.x(), cuts.at(i).zone.y(), cuts.at(i).description);
1362 if (!clip->getClipHash().isEmpty()) {
1363 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(cuts.at(i).zone.x()) + ".png";
1364 if (QFile::exists(cachedPixmap)) {
1365 QPixmap pix(cachedPixmap);
1367 KIO::NetAccess::del(KUrl(cachedPixmap), this);
1368 sub->setData(0, Qt::DecorationRole, pix);
1373 monitorItemEditing(true);
1377 void ProjectList::slotGotProxy(const QString &proxyPath)
1379 if (proxyPath.isEmpty() || m_abortAllJobs) return;
1380 QTreeWidgetItemIterator it(m_listView);
1383 while (*it && !m_closing) {
1384 if ((*it)->type() == PROJECTCLIPTYPE) {
1385 item = static_cast <ProjectItem *>(*it);
1386 if (item->referencedClip()->getProperty("proxy") == proxyPath)
1393 void ProjectList::slotGotProxyForId(const QString id)
1395 if (m_closing) return;
1396 ProjectItem *item = getItemById(id);
1400 void ProjectList::slotGotProxy(ProjectItem *item)
1402 if (item == NULL) return;
1403 DocClipBase *clip = item->referencedClip();
1404 if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
1405 // Clip is being reprocessed, abort
1406 kDebug()<<"//// TRYING TO PROXY: "<<item->clipId()<<", but it is busy";
1410 // Proxy clip successfully created
1411 QDomElement e = clip->toXML().cloneNode().toElement();
1413 // Make sure we get the correct producer length if it was adjusted in timeline
1414 CLIPTYPE t = item->clipType();
1415 if (t == COLOR || t == IMAGE || t == SLIDESHOW || t == TEXT) {
1416 int length = QString(clip->producerProperty("length")).toInt();
1417 if (length > 0 && !e.hasAttribute("length")) {
1418 e.setAttribute("length", length);
1421 resetThumbsProducer(clip);
1422 m_render->getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true);
1425 void ProjectList::slotResetProjectList()
1427 m_listView->blockSignals(true);
1428 m_abortAllJobs = true;
1429 for (int i = 0; i < m_jobList.count(); i++) {
1430 m_jobList.at(i)->setStatus(JOBABORTED);
1433 m_jobThreads.waitForFinished();
1434 m_jobThreads.clearFutures();
1435 m_thumbnailQueue.clear();
1436 if (!m_jobList.isEmpty()) qDeleteAll(m_jobList);
1438 m_listView->clear();
1439 m_listView->setEnabled(true);
1440 emit clipSelected(NULL);
1441 m_refreshed = false;
1442 m_allClipsProcessed = false;
1443 m_abortAllJobs = false;
1445 m_listView->blockSignals(false);
1448 void ProjectList::slotUpdateClip(const QString &id)
1450 ProjectItem *item = getItemById(id);
1451 monitorItemEditing(false);
1452 if (item) item->setData(0, UsageRole, QString::number(item->numReferences()));
1453 monitorItemEditing(true);
1456 void ProjectList::getCachedThumbnail(ProjectItem *item)
1459 DocClipBase *clip = item->referencedClip();
1461 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
1462 if (QFile::exists(cachedPixmap)) {
1463 QPixmap pix(cachedPixmap);
1465 KIO::NetAccess::del(KUrl(cachedPixmap), this);
1466 requestClipThumbnail(item->clipId());
1469 processThumbOverlays(item, pix);
1470 item->setData(0, Qt::DecorationRole, pix);
1474 requestClipThumbnail(item->clipId());
1478 void ProjectList::getCachedThumbnail(SubProjectItem *item)
1481 ProjectItem *parentItem = static_cast <ProjectItem *>(item->parent());
1482 if (!parentItem) return;
1483 DocClipBase *clip = parentItem->referencedClip();
1485 int pos = item->zone().x();
1486 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(pos) + ".png";
1487 if (QFile::exists(cachedPixmap)) {
1488 QPixmap pix(cachedPixmap);
1490 KIO::NetAccess::del(KUrl(cachedPixmap), this);
1491 requestClipThumbnail(parentItem->clipId() + '#' + QString::number(pos));
1493 else item->setData(0, Qt::DecorationRole, pix);
1495 else requestClipThumbnail(parentItem->clipId() + '#' + QString::number(pos));
1498 void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged, QStringList brokenClips)
1500 if (!m_allClipsProcessed) m_listView->setEnabled(false);
1501 m_listView->setSortingEnabled(false);
1502 QTreeWidgetItemIterator it(m_listView);
1505 monitorItemEditing(false);
1506 int height = m_listView->iconSize().height();
1507 int width = (int)(height * m_render->dar());
1508 QPixmap missingPixmap = QPixmap(width, height);
1509 missingPixmap.fill(Qt::transparent);
1510 KIcon icon("dialog-close");
1511 QPainter p(&missingPixmap);
1512 p.drawPixmap(3, 3, icon.pixmap(width - 6, height - 6));
1515 int max = m_doc->clipManager()->clipsCount();
1520 emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - ct++) / max));
1521 if ((*it)->type() == PROJECTSUBCLIPTYPE) {
1523 SubProjectItem *sub = static_cast <SubProjectItem *>(*it);
1524 if (displayRatioChanged) {
1525 item = static_cast <ProjectItem *>((*it)->parent());
1526 requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x()));
1528 else if (sub->data(0, Qt::DecorationRole).isNull()) {
1529 getCachedThumbnail(sub);
1533 } else if ((*it)->type() == PROJECTFOLDERTYPE) {
1538 item = static_cast <ProjectItem *>(*it);
1539 clip = item->referencedClip();
1540 if (clip->getProducer() == NULL) {
1541 bool replace = false;
1542 if (brokenClips.contains(item->clipId())) {
1543 // if this is a proxy clip, disable proxy
1544 item->setConditionalJobStatus(NOJOB, PROXYJOB);
1545 discardJobs(item->clipId(), PROXYJOB);
1546 clip->setProperty("proxy", "-");
1549 if (clip->isPlaceHolder() == false && !hasPendingJob(item, PROXYJOB)) {
1550 QDomElement xml = clip->toXML();
1552 xml.removeAttribute("out");
1553 xml.removeAttribute("file_hash");
1554 xml.removeAttribute("proxy_out");
1556 if (!replace) replace = xml.attribute("_replaceproxy") == "1";
1557 xml.removeAttribute("_replaceproxy");
1559 resetThumbsProducer(clip);
1561 m_render->getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), replace);
1563 else if (clip->isPlaceHolder()) {
1564 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
1565 if (item->data(0, Qt::DecorationRole).isNull()) {
1566 item->setData(0, Qt::DecorationRole, missingPixmap);
1569 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
1570 QPainter p(&pixmap);
1571 p.drawPixmap(3, 3, KIcon("dialog-close").pixmap(pixmap.width() - 6, pixmap.height() - 6));
1573 item->setData(0, Qt::DecorationRole, pixmap);
1577 if (displayRatioChanged) {
1578 requestClipThumbnail(clip->getId());
1580 else if (item->data(0, Qt::DecorationRole).isNull()) {
1581 getCachedThumbnail(item);
1583 if (item->data(0, DurationRole).toString().isEmpty()) {
1584 item->changeDuration(clip->getProducer()->get_playtime());
1586 if (clip->isPlaceHolder()) {
1587 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
1588 if (pixmap.isNull()) {
1589 pixmap = QPixmap(width, height);
1590 pixmap.fill(Qt::transparent);
1592 QPainter p(&pixmap);
1593 p.drawPixmap(3, 3, KIcon("dialog-close").pixmap(pixmap.width() - 6, pixmap.height() - 6));
1595 item->setData(0, Qt::DecorationRole, pixmap);
1597 else if (clip->getProperty("_replaceproxy") == "1") {
1598 clip->setProperty("_replaceproxy", QString());
1599 slotCreateProxy(clip->getId());
1602 item->setData(0, UsageRole, QString::number(item->numReferences()));
1607 m_listView->setSortingEnabled(true);
1608 m_allClipsProcessed = true;
1609 if (m_render->processingItems() == 0) {
1610 monitorItemEditing(true);
1611 slotProcessNextThumbnail();
1616 QString ProjectList::getExtensions()
1618 // Build list of mime types
1619 QStringList mimeTypes = QStringList() << "application/x-kdenlive" << "application/x-kdenlivetitle" << "video/mlt-playlist" << "text/plain";
1622 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";
1625 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";
1628 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";
1630 QString allExtensions;
1631 foreach(const QString & mimeType, mimeTypes) {
1632 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
1634 allExtensions.append(mime->patterns().join(" "));
1635 allExtensions.append(' ');
1638 return allExtensions.simplified();
1641 void ProjectList::slotAddClip(const QString url, const QString &groupName, const QString &groupId)
1643 kDebug()<<"// Adding clip: "<<url;
1646 slotAddClip(list, groupName, groupId);
1649 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
1651 if (!m_commandStack)
1652 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1655 if (givenList.isEmpty()) {
1656 QString allExtensions = getExtensions();
1657 const QString dialogFilter = allExtensions + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
1658 QCheckBox *b = new QCheckBox(i18n("Import image sequence"));
1659 b->setChecked(KdenliveSettings::autoimagesequence());
1660 QCheckBox *c = new QCheckBox(i18n("Transparent background for images"));
1661 c->setChecked(KdenliveSettings::autoimagetransparency());
1662 QFrame *f = new QFrame;
1663 f->setFrameShape(QFrame::NoFrame);
1664 QHBoxLayout *l = new QHBoxLayout;
1669 QPointer<KFileDialog> d = new KFileDialog(KUrl("kfiledialog:///clipfolder"), dialogFilter, kapp->activeWindow(), f);
1670 d->setOperationMode(KFileDialog::Opening);
1671 d->setMode(KFile::Files);
1672 if (d->exec() == QDialog::Accepted) {
1673 KdenliveSettings::setAutoimagetransparency(c->isChecked());
1675 list = d->selectedUrls();
1676 if (b->isChecked() && list.count() == 1) {
1677 // Check for image sequence
1678 KUrl url = list.at(0);
1679 QString fileName = url.fileName().section('.', 0, -2);
1680 if (fileName.at(fileName.size() - 1).isDigit()) {
1681 KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
1682 if (item.mimetype().startsWith("image")) {
1683 // import as sequence if we found more than one image in the sequence
1685 QString pattern = SlideshowClip::selectedPath(url.path(), false, QString(), &list);
1686 int count = list.count();
1689 QStringList groupInfo = getGroup();
1691 // get image sequence base name
1692 while (fileName.at(fileName.size() - 1).isDigit()) {
1695 QMap <QString, QString> properties;
1696 properties.insert("name", fileName);
1697 properties.insert("resource", pattern);
1698 properties.insert("in", "0");
1699 QString duration = m_timecode.reformatSeparators(KdenliveSettings::sequence_duration());
1700 properties.insert("out", QString::number(m_doc->getFramePos(duration) * count));
1701 properties.insert("ttl", QString::number(m_doc->getFramePos(duration)));
1702 properties.insert("loop", QString::number(false));
1703 properties.insert("crop", QString::number(false));
1704 properties.insert("fade", QString::number(false));
1705 properties.insert("luma_duration", QString::number(m_doc->getFramePos(m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))))));
1706 m_doc->slotCreateSlideshowClipFile(properties, groupInfo.at(0), groupInfo.at(1));
1714 for (int i = 0; i < givenList.count(); i++)
1715 list << givenList.at(i);
1717 QList <KUrl::List> foldersList;
1719 foreach(const KUrl & file, list) {
1720 // Check there is no folder here
1721 KMimeType::Ptr type = KMimeType::findByUrl(file);
1722 if (type->is("inode/directory")) {
1723 // user dropped a folder, import its files
1724 list.removeAll(file);
1725 QDir dir(file.path());
1726 QStringList result = dir.entryList(QDir::Files);
1727 KUrl::List folderFiles;
1728 folderFiles << file;
1729 foreach(const QString & path, result) {
1730 KUrl newFile = file;
1731 newFile.addPath(path);
1732 folderFiles.append(newFile);
1734 if (folderFiles.count() > 1) foldersList.append(folderFiles);
1738 if (givenList.isEmpty() && !list.isEmpty()) {
1739 QStringList groupInfo = getGroup();
1740 QMap <QString, QString> data;
1741 data.insert("group", groupInfo.at(0));
1742 data.insert("groupId", groupInfo.at(1));
1743 m_doc->slotAddClipList(list, data);
1744 } else if (!list.isEmpty()) {
1745 QMap <QString, QString> data;
1746 data.insert("group", groupName);
1747 data.insert("groupId", groupId);
1748 m_doc->slotAddClipList(list, data);
1751 if (!foldersList.isEmpty()) {
1753 for (int i = 0; i < foldersList.count(); i++) {
1754 KUrl::List urls = foldersList.at(i);
1755 KUrl folderUrl = urls.takeFirst();
1756 QString folderName = folderUrl.fileName();
1757 FolderProjectItem *folder = NULL;
1758 if (!folderName.isEmpty()) {
1759 folder = getFolderItemByName(folderName);
1760 if (folder == NULL) {
1761 slotAddFolder(folderName);
1762 folder = getFolderItemByName(folderName);
1766 QMap <QString, QString> data;
1767 data.insert("group", folder->groupName());
1768 data.insert("groupId", folder->clipId());
1769 m_doc->slotAddClipList(urls, data);
1771 else m_doc->slotAddClipList(urls);
1776 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
1778 ProjectItem *item = getItemById(id);
1779 m_thumbnailQueue.removeAll(id);
1781 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1782 const QString path = item->referencedClip()->fileURL().path();
1783 if (item->referencedClip()->isPlaceHolder()) replace = false;
1784 if (!path.isEmpty()) {
1785 if (m_invalidClipDialog) {
1786 m_invalidClipDialog->addClip(id, path);
1791 m_invalidClipDialog = new InvalidDialog(i18n("Invalid clip"), i18n("Clip <b>%1</b><br />is invalid, will be removed from project.", QString()), replace, kapp->activeWindow());
1793 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());
1795 m_invalidClipDialog->addClip(id, path);
1796 int result = m_invalidClipDialog->exec();
1797 if (result == KDialog::Yes) replace = true;
1800 if (m_invalidClipDialog) {
1802 emit deleteProjectClips(m_invalidClipDialog->getIds(), QMap <QString, QString>());
1803 delete m_invalidClipDialog;
1804 m_invalidClipDialog = NULL;
1810 void ProjectList::slotRemoveInvalidProxy(const QString &id, bool durationError)
1812 ProjectItem *item = getItemById(id);
1814 kDebug()<<"// Proxy for clip "<<id<<" is invalid, delete";
1815 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1816 if (durationError) {
1817 kDebug() << "Proxy duration is wrong, try changing transcoding parameters.";
1818 emit displayMessage(i18n("Proxy clip unusable (duration is different from original)."), -2);
1820 slotUpdateJobStatus(item, PROXYJOB, JOBCRASHED, i18n("Failed to create proxy for %1. check parameters", item->text(0)), "project_settings");
1821 QString path = item->referencedClip()->getProperty("proxy");
1822 KUrl proxyFolder(m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/");
1824 //Security check: make sure the invalid proxy file is in the proxy folder
1825 if (proxyFolder.isParentOf(KUrl(path))) {
1826 QFile::remove(path);
1828 if (item->referencedClip()->getProducer() == NULL) {
1829 // Clip has no valid producer, request it
1830 slotProxyCurrentItem(false, item);
1833 // refresh thumbs producer
1834 item->referencedClip()->reloadThumbProducer();
1837 m_thumbnailQueue.removeAll(id);
1840 void ProjectList::slotAddColorClip()
1842 if (!m_commandStack)
1843 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1845 QPointer<QDialog> dia = new QDialog(this);
1846 Ui::ColorClip_UI dia_ui;
1847 dia_ui.setupUi(dia);
1848 dia->setWindowTitle(i18n("Color Clip"));
1849 dia_ui.clip_name->setText(i18n("Color Clip"));
1851 TimecodeDisplay *t = new TimecodeDisplay(m_timecode);
1852 t->setValue(KdenliveSettings::color_duration());
1853 dia_ui.clip_durationBox->addWidget(t);
1854 dia_ui.clip_color->setColor(KdenliveSettings::colorclipcolor());
1856 if (dia->exec() == QDialog::Accepted) {
1857 QString color = dia_ui.clip_color->color().name();
1858 KdenliveSettings::setColorclipcolor(color);
1859 color = color.replace(0, 1, "0x") + "ff";
1860 QStringList groupInfo = getGroup();
1861 m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, m_timecode.getTimecode(t->gentime()), groupInfo.at(0), groupInfo.at(1));
1868 void ProjectList::slotAddSlideshowClip()
1870 if (!m_commandStack)
1871 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1873 SlideshowClip *dia = new SlideshowClip(m_timecode, this);
1875 if (dia->exec() == QDialog::Accepted) {
1876 QStringList groupInfo = getGroup();
1878 QMap <QString, QString> properties;
1879 properties.insert("name", dia->clipName());
1880 properties.insert("resource", dia->selectedPath());
1881 properties.insert("in", "0");
1882 properties.insert("out", QString::number(m_doc->getFramePos(dia->clipDuration()) * dia->imageCount()));
1883 properties.insert("ttl", QString::number(m_doc->getFramePos(dia->clipDuration())));
1884 properties.insert("loop", QString::number(dia->loop()));
1885 properties.insert("crop", QString::number(dia->crop()));
1886 properties.insert("fade", QString::number(dia->fade()));
1887 properties.insert("luma_duration", dia->lumaDuration());
1888 properties.insert("luma_file", dia->lumaFile());
1889 properties.insert("softness", QString::number(dia->softness()));
1890 properties.insert("animation", dia->animation());
1892 m_doc->slotCreateSlideshowClipFile(properties, groupInfo.at(0), groupInfo.at(1));
1897 void ProjectList::slotAddTitleClip()
1899 QStringList groupInfo = getGroup();
1900 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
1903 void ProjectList::slotAddTitleTemplateClip()
1905 if (!m_commandStack)
1906 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1908 QStringList groupInfo = getGroup();
1910 // Get the list of existing templates
1912 filter << "*.kdenlivetitle";
1913 const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
1914 QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
1916 QPointer<QDialog> dia = new QDialog(this);
1917 Ui::TemplateClip_UI dia_ui;
1918 dia_ui.setupUi(dia);
1919 for (int i = 0; i < templateFiles.size(); ++i)
1920 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
1922 if (!templateFiles.isEmpty())
1923 dia_ui.buttonBox->button(QDialogButtonBox::Ok)->setFocus();
1924 dia_ui.template_list->fileDialog()->setFilter("application/x-kdenlivetitle");
1925 //warning: setting base directory doesn't work??
1926 KUrl startDir(path);
1927 dia_ui.template_list->fileDialog()->setUrl(startDir);
1928 dia_ui.text_box->setHidden(true);
1929 if (dia->exec() == QDialog::Accepted) {
1930 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
1931 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
1932 // Create a cloned template clip
1933 m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
1938 QStringList ProjectList::getGroup() const
1941 QTreeWidgetItem *item = m_listView->currentItem();
1942 while (item && item->type() != PROJECTFOLDERTYPE)
1943 item = item->parent();
1946 FolderProjectItem *folder = static_cast <FolderProjectItem *>(item);
1947 result << folder->groupName() << folder->clipId();
1949 result << QString() << QString();
1954 void ProjectList::setDocument(KdenliveDoc *doc)
1956 m_listView->blockSignals(true);
1957 m_abortAllJobs = true;
1958 for (int i = 0; i < m_jobList.count(); i++) {
1959 m_jobList.at(i)->setStatus(JOBABORTED);
1962 m_jobThreads.waitForFinished();
1963 m_jobThreads.clearFutures();
1964 m_thumbnailQueue.clear();
1965 m_listView->clear();
1967 m_listView->setSortingEnabled(false);
1968 emit clipSelected(NULL);
1969 m_refreshed = false;
1970 m_allClipsProcessed = false;
1972 m_timecode = doc->timecode();
1973 m_commandStack = doc->commandStack();
1975 m_abortAllJobs = false;
1978 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
1979 QStringList openedFolders = doc->getExpandedFolders();
1980 QMapIterator<QString, QString> f(flist);
1981 while (f.hasNext()) {
1983 FolderProjectItem *folder = new FolderProjectItem(m_listView, QStringList() << f.value(), f.key());
1984 folder->setExpanded(openedFolders.contains(f.key()));
1987 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
1988 if (list.isEmpty()) {
1991 m_allClipsProcessed = true;
1993 for (int i = 0; i < list.count(); i++)
1994 slotAddClip(list.at(i), false);
1996 m_listView->blockSignals(false);
1997 connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
1998 connect(m_doc->clipManager(), SIGNAL(modifiedClip(const QString &)), this, SLOT(slotModifiedClip(const QString &)));
1999 connect(m_doc->clipManager(), SIGNAL(missingClip(const QString &)), this, SLOT(slotMissingClip(const QString &)));
2000 connect(m_doc->clipManager(), SIGNAL(availableClip(const QString &)), this, SLOT(slotAvailableClip(const QString &)));
2001 connect(m_doc->clipManager(), SIGNAL(checkAllClips(bool, bool, QStringList)), this, SLOT(updateAllClips(bool, bool, QStringList)));
2004 QList <DocClipBase*> ProjectList::documentClipList() const
2007 return QList <DocClipBase*> ();
2009 return m_doc->clipManager()->documentClipList();
2012 QDomElement ProjectList::producersList()
2015 QDomElement prods = doc.createElement("producerlist");
2016 doc.appendChild(prods);
2017 QTreeWidgetItemIterator it(m_listView);
2019 if ((*it)->type() != PROJECTCLIPTYPE) {
2024 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
2030 void ProjectList::slotCheckForEmptyQueue()
2032 if (m_render->processingItems() == 0 && m_thumbnailQueue.isEmpty()) {
2033 if (!m_refreshed && m_allClipsProcessed) {
2035 m_listView->setEnabled(true);
2037 QTimer::singleShot(500, this, SIGNAL(loadingIsOver()));
2038 emit displayMessage(QString(), -1);
2041 } else if (!m_refreshed) {
2042 QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
2047 void ProjectList::requestClipThumbnail(const QString id)
2049 if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id);
2050 slotProcessNextThumbnail();
2053 void ProjectList::resetThumbsProducer(DocClipBase *clip)
2056 clip->clearThumbProducer();
2057 QString id = clip->getId();
2058 m_thumbnailQueue.removeAll(id);
2061 void ProjectList::slotProcessNextThumbnail()
2063 if (m_render->processingItems() > 0) {
2066 if (m_thumbnailQueue.isEmpty()) {
2067 slotCheckForEmptyQueue();
2070 int max = m_doc->clipManager()->clipsCount();
2071 emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - m_thumbnailQueue.count()) / max));
2072 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
2075 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
2077 QTreeWidgetItem *item = getAnyItemById(clipId);
2079 slotRefreshClipThumbnail(item, update);
2081 slotProcessNextThumbnail();
2085 void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
2087 if (it == NULL) return;
2088 ProjectItem *item = NULL;
2089 bool isSubItem = false;
2091 if (it->type() == PROJECTFOLDERTYPE) return;
2092 if (it->type() == PROJECTSUBCLIPTYPE) {
2093 item = static_cast <ProjectItem *>(it->parent());
2094 frame = static_cast <SubProjectItem *>(it)->zone().x();
2097 item = static_cast <ProjectItem *>(it);
2098 frame = item->referencedClip()->getClipThumbFrame();
2102 DocClipBase *clip = item->referencedClip();
2104 slotProcessNextThumbnail();
2109 int height = m_listView->iconSize().height();
2110 int swidth = (int)(height * m_render->frameRenderWidth() / m_render->renderHeight()+ 0.5);
2111 int dwidth = (int)(height * m_render->dar() + 0.5);
2112 if (clip->clipType() == AUDIO)
2113 pix = KIcon("audio-x-generic").pixmap(QSize(dwidth, height));
2114 else if (clip->clipType() == IMAGE) {
2115 img = KThumb::getFrame(item->referencedClip()->getProducer(), 0, swidth, dwidth, height);
2118 img = item->referencedClip()->extractImage(frame, dwidth, height);
2120 if (!pix.isNull() || !img.isNull()) {
2121 monitorItemEditing(false);
2122 if (!img.isNull()) {
2123 pix = QPixmap::fromImage(img);
2124 processThumbOverlays(item, pix);
2126 it->setData(0, Qt::DecorationRole, pix);
2127 monitorItemEditing(true);
2129 QString hash = item->getClipHash();
2130 if (!hash.isEmpty() && !img.isNull()) {
2132 m_doc->cacheImage(hash, img);
2134 m_doc->cacheImage(hash + '#' + QString::number(frame), img);
2138 emit projectModified();
2139 slotProcessNextThumbnail();
2144 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const stringMap &properties, const stringMap &metadata, bool replace)
2147 ProjectItem *item = getItemById(clipId);
2148 int queue = m_render->processingItems();
2149 if (item && producer) {
2150 monitorItemEditing(false);
2151 DocClipBase *clip = item->referencedClip();
2152 if (producer->is_valid()) {
2153 if (clip->isPlaceHolder()) {
2157 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
2159 item->setProperties(properties, metadata);
2160 clip->setProducer(producer, replace);
2163 QString size = properties.value("frame_size");
2164 if (!useProxy() && clip->getProperty("proxy").isEmpty()) {
2165 item->setConditionalJobStatus(NOJOB, PROXYJOB);
2166 discardJobs(clipId, PROXYJOB);
2168 if (useProxy() && generateProxy() && clip->getProperty("proxy") == "-") {
2169 item->setConditionalJobStatus(NOJOB, PROXYJOB);
2170 discardJobs(clipId, PROXYJOB);
2172 else if (useProxy() && !item->hasProxy() && !hasPendingJob(item, PROXYJOB)) {
2173 // proxy video and image clips
2175 CLIPTYPE t = item->clipType();
2176 if (t == IMAGE) maxSize = m_doc->getDocumentProperty("proxyimageminsize").toInt();
2177 else maxSize = m_doc->getDocumentProperty("proxyminsize").toInt();
2178 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)) {
2179 if (clip->getProperty("proxy").isEmpty()) {
2180 KUrl proxyPath = m_doc->projectFolder();
2181 proxyPath.addPath("proxy/");
2182 proxyPath.addPath(clip->getClipHash() + '.' + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension")));
2183 QMap <QString, QString> newProps;
2184 // insert required duration for proxy
2185 if (t != IMAGE) newProps.insert("proxy_out", clip->producerProperty("out"));
2186 newProps.insert("proxy", proxyPath.path());
2187 QMap <QString, QString> oldProps = clip->properties();
2188 oldProps.insert("proxy", QString());
2189 EditClipCommand *command = new EditClipCommand(this, clipId, oldProps, newProps, true);
2190 m_doc->commandStack()->push(command);
2195 if (!replace && m_allClipsProcessed && item->data(0, Qt::DecorationRole).isNull()) {
2196 getCachedThumbnail(item);
2198 if (!toReload.isEmpty())
2199 item->slotSetToolTip();
2200 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
2202 monitorItemEditing(true);
2203 if (item && m_thumbnailQueue.isEmpty()) {
2204 if (!item->hasProxy() || m_render->activeClipId() == item->clipId())
2205 m_listView->setCurrentItem(item);
2206 bool updatedProfile = false;
2207 if (item->parent()) {
2208 if (item->parent()->type() == PROJECTFOLDERTYPE)
2209 static_cast <FolderProjectItem *>(item->parent())->switchIcon();
2210 } else if (KdenliveSettings::checkfirstprojectclip() && m_listView->topLevelItemCount() == 1 && m_refreshed && m_allClipsProcessed) {
2211 // this is the first clip loaded in project, check if we want to adjust project settings to the clip
2212 updatedProfile = adjustProjectProfileToItem(item);
2214 if (updatedProfile == false) {
2215 //emit clipSelected(item->referencedClip());
2218 int max = m_doc->clipManager()->clipsCount();
2219 if (max > 0) emit displayMessage(i18n("Loading clips"), (int)(100 *(max - queue) / max));
2221 if (m_allClipsProcessed) emit processNextThumbnail();
2224 // no item for producer, delete it
2228 if (replace) toReload = clipId;
2229 if (!toReload.isEmpty())
2230 emit clipNeedsReload(toReload);
2233 bool ProjectList::adjustProjectProfileToItem(ProjectItem *item)
2236 if (m_listView->currentItem() && m_listView->currentItem()->type() != PROJECTFOLDERTYPE)
2237 item = static_cast <ProjectItem*>(m_listView->currentItem());
2239 if (item == NULL || item->referencedClip() == NULL) {
2240 KMessageBox::information(kapp->activeWindow(), i18n("Cannot find profile from current clip"));
2243 bool profileUpdated = false;
2244 QString size = item->referencedClip()->getProperty("frame_size");
2245 int width = size.section('x', 0, 0).toInt();
2246 int height = size.section('x', -1).toInt();
2247 // Fix some avchd clips tht report a wrong size (1920x1088)
2248 if (height == 1088) height = 1080;
2249 double fps = item->referencedClip()->getProperty("fps").toDouble();
2250 double par = item->referencedClip()->getProperty("aspect_ratio").toDouble();
2251 if (item->clipType() == IMAGE || item->clipType() == AV || item->clipType() == VIDEO) {
2252 if (ProfilesDialog::matchProfile(width, height, fps, par, item->clipType() == IMAGE, m_doc->mltProfile()) == false) {
2253 // get a list of compatible profiles
2254 QMap <QString, QString> suggestedProfiles = ProfilesDialog::getProfilesFromProperties(width, height, fps, par, item->clipType() == IMAGE);
2255 if (!suggestedProfiles.isEmpty()) {
2256 KDialog *dialog = new KDialog(this);
2257 dialog->setCaption(i18n("Change project profile"));
2258 dialog->setButtons(KDialog::Ok | KDialog::Cancel);
2261 QVBoxLayout *l = new QVBoxLayout;
2262 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));
2263 l->addWidget(label);
2264 QListWidget *list = new QListWidget;
2265 list->setAlternatingRowColors(true);
2266 QMapIterator<QString, QString> i(suggestedProfiles);
2267 while (i.hasNext()) {
2269 QListWidgetItem *item = new QListWidgetItem(i.value(), list);
2270 item->setData(Qt::UserRole, i.key());
2271 item->setToolTip(i.key());
2273 list->setCurrentRow(0);
2275 container.setLayout(l);
2276 dialog->setButtonText(KDialog::Ok, i18n("Update profile"));
2277 dialog->setMainWidget(&container);
2278 if (dialog->exec() == QDialog::Accepted) {
2279 //Change project profile
2280 profileUpdated = true;
2281 if (list->currentItem())
2282 emit updateProfile(list->currentItem()->data(Qt::UserRole).toString());
2286 } else if (fps > 0) {
2287 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));
2291 return profileUpdated;
2294 QString ProjectList::getDocumentProperty(const QString &key) const
2296 return m_doc->getDocumentProperty(key);
2299 bool ProjectList::useProxy() const
2301 return m_doc->getDocumentProperty("enableproxy").toInt();
2304 bool ProjectList::generateProxy() const
2306 return m_doc->getDocumentProperty("generateproxy").toInt();
2309 bool ProjectList::generateImageProxy() const
2311 return m_doc->getDocumentProperty("generateimageproxy").toInt();
2314 void ProjectList::slotReplyGetImage(const QString &clipId, const QImage &img)
2316 ProjectItem *item = getItemById(clipId);
2317 if (item && !img.isNull()) {
2318 QPixmap pix = QPixmap::fromImage(img);
2319 processThumbOverlays(item, pix);
2320 monitorItemEditing(false);
2321 item->setData(0, Qt::DecorationRole, pix);
2322 monitorItemEditing(true);
2323 QString hash = item->getClipHash();
2324 if (!hash.isEmpty()) m_doc->cacheImage(hash, img);
2328 void ProjectList::slotReplyGetImage(const QString &clipId, const QString &name, int width, int height)
2330 // For clips that have a generic icon (like audio clips...)
2331 ProjectItem *item = getItemById(clipId);
2332 QPixmap pix = KIcon(name).pixmap(QSize(width, height));
2333 if (item && !pix.isNull()) {
2334 monitorItemEditing(false);
2335 item->setData(0, Qt::DecorationRole, pix);
2336 monitorItemEditing(true);
2340 QTreeWidgetItem *ProjectList::getAnyItemById(const QString &id)
2342 QTreeWidgetItemIterator it(m_listView);
2343 QString lookId = id;
2344 if (id.contains('#'))
2345 lookId = id.section('#', 0, 0);
2347 ProjectItem *result = NULL;
2349 if ((*it)->type() != PROJECTCLIPTYPE) {
2354 ProjectItem *item = static_cast<ProjectItem *>(*it);
2355 if (item->clipId() == lookId) {
2361 if (result == NULL || !id.contains('#')) {
2364 for (int i = 0; i < result->childCount(); i++) {
2365 SubProjectItem *sub = static_cast <SubProjectItem *>(result->child(i));
2366 if (sub && sub->zone().x() == id.section('#', 1, 1).toInt())
2375 ProjectItem *ProjectList::getItemById(const QString &id)
2378 QTreeWidgetItemIterator it(m_listView);
2380 if ((*it)->type() != PROJECTCLIPTYPE) {
2381 // subitem or folder
2385 item = static_cast<ProjectItem *>(*it);
2386 if (item->clipId() == id)
2393 FolderProjectItem *ProjectList::getFolderItemByName(const QString &name)
2395 FolderProjectItem *item = NULL;
2396 QList <QTreeWidgetItem *> hits = m_listView->findItems(name, Qt::MatchExactly, 0);
2397 for (int i = 0; i < hits.count(); i++) {
2398 if (hits.at(i)->type() == PROJECTFOLDERTYPE) {
2399 item = static_cast<FolderProjectItem *>(hits.at(i));
2406 FolderProjectItem *ProjectList::getFolderItemById(const QString &id)
2408 FolderProjectItem *item;
2409 QTreeWidgetItemIterator it(m_listView);
2411 if ((*it)->type() == PROJECTFOLDERTYPE) {
2412 item = static_cast<FolderProjectItem *>(*it);
2413 if (item->clipId() == id)
2421 void ProjectList::slotSelectClip(const QString &ix)
2423 ProjectItem *clip = getItemById(ix);
2425 m_listView->setCurrentItem(clip);
2426 m_listView->scrollToItem(clip);
2427 m_editButton->defaultAction()->setEnabled(true);
2428 m_deleteButton->defaultAction()->setEnabled(true);
2429 m_reloadAction->setEnabled(true);
2430 m_extractAudioAction->setEnabled(true);
2431 m_transcodeAction->setEnabled(true);
2432 m_stabilizeAction->setEnabled(true);
2433 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
2434 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
2435 m_openAction->setEnabled(true);
2436 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
2437 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
2438 m_openAction->setEnabled(true);
2440 m_openAction->setEnabled(false);
2445 QString ProjectList::currentClipUrl() const
2448 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return QString();
2449 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
2451 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
2453 item = static_cast <ProjectItem*>(m_listView->currentItem());
2457 return item->clipUrl().path();
2460 KUrl::List ProjectList::getConditionalUrls(const QString &condition) const
2464 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
2465 for (int i = 0; i < list.count(); i++) {
2466 if (list.at(i)->type() == PROJECTFOLDERTYPE)
2468 if (list.at(i)->type() == PROJECTSUBCLIPTYPE) {
2470 item = static_cast <ProjectItem*>(list.at(i)->parent());
2472 item = static_cast <ProjectItem*>(list.at(i));
2474 if (item == NULL || item->type() == COLOR || item->type() == SLIDESHOW || item->type() == TEXT)
2476 DocClipBase *clip = item->referencedClip();
2477 if (!condition.isEmpty()) {
2478 if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section('=', 1, 1)))
2480 else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section('=', 1, 1)))
2483 result.append(item->clipUrl());
2488 QStringList ProjectList::getConditionalIds(const QString &condition) const
2492 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
2493 for (int i = 0; i < list.count(); i++) {
2494 if (list.at(i)->type() == PROJECTFOLDERTYPE)
2496 if (list.at(i)->type() == PROJECTSUBCLIPTYPE) {
2498 item = static_cast <ProjectItem*>(list.at(i)->parent());
2500 item = static_cast <ProjectItem*>(list.at(i));
2502 if (item == NULL || item->type() == COLOR || item->type() == SLIDESHOW || item->type() == TEXT)
2504 DocClipBase *clip = item->referencedClip();
2505 if (!condition.isEmpty()) {
2506 if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section('=', 1, 1)))
2508 else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section('=', 1, 1)))
2511 result.append(item->clipId());
2516 void ProjectList::regenerateTemplate(const QString &id)
2518 ProjectItem *clip = getItemById(id);
2520 regenerateTemplate(clip);
2523 void ProjectList::regenerateTemplate(ProjectItem *clip)
2525 //TODO: remove this unused method, only force_reload is necessary
2526 clip->referencedClip()->getProducer()->set("force_reload", 1);
2529 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
2533 if (!file.open(QIODevice::ReadOnly)) {
2534 kWarning() << "ERROR, CANNOT READ: " << path;
2537 if (!doc.setContent(&file)) {
2538 kWarning() << "ERROR, CANNOT READ: " << path;
2543 QDomNodeList texts = doc.elementsByTagName("content");
2544 for (int i = 0; i < texts.count(); i++) {
2545 QString data = texts.item(i).firstChild().nodeValue();
2546 data.replace("%s", replaceString);
2547 texts.item(i).firstChild().setNodeValue(data);
2553 void ProjectList::slotAddClipCut(const QString &id, int in, int out)
2555 ProjectItem *clip = getItemById(id);
2556 if (clip == NULL || clip->referencedClip()->hasCutZone(QPoint(in, out)))
2558 AddClipCutCommand *command = new AddClipCutCommand(this, id, in, out, QString(), true, false);
2559 m_commandStack->push(command);
2562 void ProjectList::addClipCut(const QString &id, int in, int out, const QString desc, bool newItem)
2564 ProjectItem *clip = getItemById(id);
2566 DocClipBase *base = clip->referencedClip();
2567 base->addCutZone(in, out);
2568 monitorItemEditing(false);
2569 SubProjectItem *sub = new SubProjectItem(clip, in, out, desc);
2570 if (newItem && desc.isEmpty() && !m_listView->isColumnHidden(1)) {
2571 if (!clip->isExpanded())
2572 clip->setExpanded(true);
2573 m_listView->scrollToItem(sub);
2574 m_listView->editItem(sub, 1);
2576 QImage img = clip->referencedClip()->extractImage(in, (int)(sub->sizeHint(0).height() * m_render->dar()), sub->sizeHint(0).height() - 2);
2577 sub->setData(0, Qt::DecorationRole, QPixmap::fromImage(img));
2578 QString hash = clip->getClipHash();
2579 if (!hash.isEmpty()) m_doc->cacheImage(hash + '#' + QString::number(in), img);
2580 monitorItemEditing(true);
2582 emit projectModified();
2585 void ProjectList::removeClipCut(const QString &id, int in, int out)
2587 ProjectItem *clip = getItemById(id);
2589 DocClipBase *base = clip->referencedClip();
2590 base->removeCutZone(in, out);
2591 SubProjectItem *sub = getSubItem(clip, QPoint(in, out));
2593 monitorItemEditing(false);
2595 monitorItemEditing(true);
2598 emit projectModified();
2601 SubProjectItem *ProjectList::getSubItem(ProjectItem *clip, QPoint zone)
2603 SubProjectItem *sub = NULL;
2605 for (int i = 0; i < clip->childCount(); i++) {
2606 QTreeWidgetItem *it = clip->child(i);
2607 if (it->type() == PROJECTSUBCLIPTYPE) {
2608 sub = static_cast <SubProjectItem*>(it);
2609 if (sub->zone() == zone)
2619 void ProjectList::slotUpdateClipCut(QPoint p)
2621 if (!m_listView->currentItem() || m_listView->currentItem()->type() != PROJECTSUBCLIPTYPE)
2623 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
2624 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
2625 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), p, sub->text(1), sub->text(1), true);
2626 m_commandStack->push(command);
2629 void ProjectList::doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment)
2631 ProjectItem *clip = getItemById(id);
2632 SubProjectItem *sub = getSubItem(clip, oldzone);
2633 if (sub == NULL || clip == NULL)
2635 DocClipBase *base = clip->referencedClip();
2636 base->updateCutZone(oldzone.x(), oldzone.y(), zone.x(), zone.y(), comment);
2637 monitorItemEditing(false);
2639 sub->setDescription(comment);
2640 monitorItemEditing(true);
2641 emit projectModified();
2644 void ProjectList::slotForceProcessing(const QString &id)
2646 m_render->forceProcessing(id);
2649 void ProjectList::slotAddOrUpdateSequence(const QString frameName)
2651 QString fileName = KUrl(frameName).fileName().section('_', 0, -2);
2653 QString pattern = SlideshowClip::selectedPath(frameName, false, QString(), &list);
2654 int count = list.count();
2656 const QList <DocClipBase *> existing = m_doc->clipManager()->getClipByResource(pattern);
2657 if (!existing.isEmpty()) {
2658 // Sequence already exists, update
2659 QString id = existing.at(0)->getId();
2660 //ProjectItem *item = getItemById(id);
2661 QMap <QString, QString> oldprops;
2662 QMap <QString, QString> newprops;
2663 int ttl = existing.at(0)->getProperty("ttl").toInt();
2664 oldprops["out"] = existing.at(0)->getProperty("out");
2665 newprops["out"] = QString::number(ttl * count - 1);
2666 slotUpdateClipProperties(id, newprops);
2667 EditClipCommand *command = new EditClipCommand(this, id, oldprops, newprops, false);
2668 m_commandStack->push(command);
2671 QStringList groupInfo = getGroup();
2672 QMap <QString, QString> properties;
2673 properties.insert("name", fileName);
2674 properties.insert("resource", pattern);
2675 properties.insert("in", "0");
2676 QString duration = m_timecode.reformatSeparators(KdenliveSettings::sequence_duration());
2677 properties.insert("out", QString::number(m_doc->getFramePos(duration) * count));
2678 properties.insert("ttl", QString::number(m_doc->getFramePos(duration)));
2679 properties.insert("loop", QString::number(false));
2680 properties.insert("crop", QString::number(false));
2681 properties.insert("fade", QString::number(false));
2682 properties.insert("luma_duration", m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))));
2684 m_doc->slotCreateSlideshowClipFile(properties, groupInfo.at(0), groupInfo.at(1));
2686 } else emit displayMessage(i18n("Sequence not found"), -2);
2689 QMap <QString, QString> ProjectList::getProxies()
2691 QMap <QString, QString> list;
2693 QTreeWidgetItemIterator it(m_listView);
2695 if ((*it)->type() != PROJECTCLIPTYPE) {
2699 item = static_cast<ProjectItem *>(*it);
2700 if (item && item->referencedClip() != NULL) {
2701 if (item->hasProxy()) {
2702 QString proxy = item->referencedClip()->getProperty("proxy");
2703 list.insert(proxy, item->clipUrl().path());
2711 void ProjectList::slotCreateProxy(const QString id)
2713 ProjectItem *item = getItemById(id);
2714 if (!item || hasPendingJob(item, PROXYJOB) || item->referencedClip()->isPlaceHolder()) return;
2715 QString path = item->referencedClip()->getProperty("proxy");
2716 if (path.isEmpty()) {
2717 slotUpdateJobStatus(item, PROXYJOB, JOBCRASHED, i18n("Failed to create proxy, empty path."));
2721 if (QFileInfo(path).size() > 0) {
2722 // Proxy already created
2723 setJobStatus(item, PROXYJOB, JOBDONE);
2728 ProxyJob *job = new ProxyJob(item->clipType(), id, QStringList() << path << item->clipUrl().path() << item->referencedClip()->producerProperty("_exif_orientation") << m_doc->getDocumentProperty("proxyparams").simplified() << QString::number(m_render->frameRenderWidth()) << QString::number(m_render->renderHeight()));
2729 if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
2734 m_jobList.append(job);
2735 setJobStatus(item, job->jobType, JOBWAITING, 0, job->statusMessage());
2736 slotCheckJobProcess();
2739 void ProjectList::slotCutClipJob(const QString &id, QPoint zone)
2741 ProjectItem *item = getItemById(id);
2742 if (!item|| item->referencedClip()->isPlaceHolder()) return;
2743 QString source = item->clipUrl().path();
2744 QString ext = source.section('.', -1);
2745 QString dest = source.section('.', 0, -2) + '_' + QString::number(zone.x()) + '.' + ext;
2747 double clipFps = item->referencedClip()->getProperty("fps").toDouble();
2748 if (clipFps == 0) clipFps = m_fps;
2749 // if clip and project have different frame rate, adjust in and out
2752 in = GenTime(in, m_timecode.fps()).frames(clipFps);
2753 out = GenTime(out, m_timecode.fps()).frames(clipFps);
2754 int max = GenTime(item->clipMaxDuration(), m_timecode.fps()).frames(clipFps);
2755 int duration = out - in + 1;
2756 QString timeIn = Timecode::getStringTimecode(in, clipFps, true);
2757 QString timeOut = Timecode::getStringTimecode(duration, clipFps, true);
2759 QPointer<QDialog> d = new QDialog(this);
2760 Ui::CutJobDialog_UI ui;
2762 ui.extra_params->setVisible(false);
2763 ui.add_clip->setChecked(KdenliveSettings::add_clip_cut());
2764 ui.file_url->fileDialog()->setOperationMode(KFileDialog::Saving);
2765 ui.extra_params->setMaximumHeight(QFontMetrics(font()).lineSpacing() * 5);
2766 ui.file_url->setUrl(KUrl(dest));
2767 ui.button_more->setIcon(KIcon("configure"));
2768 ui.extra_params->setPlainText("-acodec copy -vcodec copy");
2769 QString mess = i18n("Extracting %1 out of %2", timeOut, Timecode::getStringTimecode(max, clipFps, true));
2770 ui.info_label->setText(mess);
2771 if (d->exec() != QDialog::Accepted) {
2775 dest = ui.file_url->url().path();
2776 bool acceptPath = dest != source;
2777 if (acceptPath && QFileInfo(dest).size() > 0) {
2778 // destination file olready exists, overwrite?
2781 while (!acceptPath) {
2782 // Do not allow to save over original clip
2783 if (dest == source) ui.info_label->setText("<b>" + i18n("You cannot overwrite original clip.") + "</b><br>" + mess);
2784 else if (KMessageBox::questionYesNo(this, i18n("Overwrite file %1", dest)) == KMessageBox::Yes) break;
2785 if (d->exec() != QDialog::Accepted) {
2789 dest = ui.file_url->url().path();
2790 acceptPath = dest != source;
2791 if (acceptPath && QFileInfo(dest).size() > 0) {
2795 QString extraParams = ui.extra_params->toPlainText().simplified();
2796 KdenliveSettings::setAdd_clip_cut(ui.add_clip->isChecked());
2799 QStringList jobParams;
2800 jobParams << dest << item->clipUrl().path() << timeIn << timeOut << QString::number(duration) << QString::number(KdenliveSettings::add_clip_cut());
2801 if (!extraParams.isEmpty()) jobParams << extraParams;
2802 CutClipJob *job = new CutClipJob(item->clipType(), id, jobParams);
2803 if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
2807 m_jobList.append(job);
2808 setJobStatus(item, job->jobType, JOBWAITING, 0, job->statusMessage());
2810 slotCheckJobProcess();
2813 void ProjectList::slotTranscodeClipJob(const QString &condition, QString params, QString desc)
2815 QStringList existingFiles;
2816 QStringList ids = getConditionalIds(condition);
2817 QStringList destinations;
2818 foreach(const QString &id, ids) {
2819 ProjectItem *item = getItemById(id);
2820 if (!item) continue;
2821 QString newFile = params.section(' ', -1).replace("%1", item->clipUrl().path());
2822 destinations << newFile;
2823 if (QFile::exists(newFile)) existingFiles << newFile;
2825 if (!existingFiles.isEmpty()) {
2826 if (KMessageBox::warningContinueCancelList(this, i18n("The transcoding job will overwrite the following files:"), existingFiles) == KMessageBox::Cancel) return;
2829 QDialog *d = new QDialog(this);
2830 Ui::CutJobDialog_UI ui;
2832 d->setWindowTitle(i18n("Transcoding"));
2833 ui.extra_params->setMaximumHeight(QFontMetrics(font()).lineSpacing() * 5);
2834 if (ids.count() == 1) {
2835 ui.file_url->setUrl(KUrl(destinations.first()));
2838 ui.destination_label->setVisible(false);
2839 ui.file_url->setVisible(false);
2841 ui.extra_params->setVisible(false);
2843 ui.button_more->setIcon(KIcon("configure"));
2844 ui.add_clip->setChecked(KdenliveSettings::add_clip_cut());
2845 ui.extra_params->setPlainText(params.simplified().section(' ', 0, -2));
2846 QString mess = desc;
2847 mess.append(' ' + i18np("(%1 clip)", "(%1 clips)", ids.count()));
2848 ui.info_label->setText(mess);
2849 if (d->exec() != QDialog::Accepted) {
2853 params = ui.extra_params->toPlainText().simplified();
2854 KdenliveSettings::setAdd_clip_cut(ui.add_clip->isChecked());
2856 foreach(const QString &id, ids) {
2857 ProjectItem *item = getItemById(id);
2858 if (!item || !item->referencedClip()) continue;
2859 QString src = item->clipUrl().path();
2861 if (ids.count() > 1) {
2862 dest = destinations.at(index);
2865 else dest = ui.file_url->url().path();
2866 QStringList jobParams;
2867 jobParams << dest << src << QString() << QString();
2868 double clipFps = item->referencedClip()->getProperty("fps").toDouble();
2869 if (clipFps == 0) clipFps = m_fps;
2870 int max = item->clipMaxDuration();
2871 QString duration = QString::number(max);
2872 jobParams << duration;
2873 jobParams << QString::number(KdenliveSettings::add_clip_cut());
2874 jobParams << params;
2875 CutClipJob *job = new CutClipJob(item->clipType(), id, jobParams);
2876 if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
2880 m_jobList.append(job);
2881 setJobStatus(item, job->jobType, JOBWAITING, 0, job->statusMessage());
2884 slotCheckJobProcess();
2888 void ProjectList::slotCheckJobProcess()
2890 if (!m_jobThreads.futures().isEmpty()) {
2891 // Remove inactive threads
2892 QList <QFuture<void> > futures = m_jobThreads.futures();
2893 m_jobThreads.clearFutures();
2894 for (int i = 0; i < futures.count(); i++)
2895 if (!futures.at(i).isFinished()) {
2896 m_jobThreads.addFuture(futures.at(i));
2899 if (m_jobList.isEmpty()) return;
2902 for (int i = 0; i < m_jobList.count(); i++) {
2903 if (m_jobList.at(i)->jobStatus == JOBWORKING || m_jobList.at(i)->jobStatus == JOBWAITING)
2906 // remove finished jobs
2907 AbstractClipJob *job = m_jobList.takeAt(i);
2913 emit jobCount(count);
2914 m_jobMutex.unlock();
2916 if (m_jobThreads.futures().isEmpty() || m_jobThreads.futures().count() < KdenliveSettings::proxythreads()) m_jobThreads.addFuture(QtConcurrent::run(this, &ProjectList::slotProcessJobs));
2919 void ProjectList::slotAbortProxy(const QString id, const QString path)
2923 ProjectItem *item = getItemById(id);
2925 if (!item->isProxyRunning()) slotGotProxy(item);
2926 item->setConditionalJobStatus(NOJOB, PROXYJOB);
2927 discardJobs(id, PROXYJOB);
2930 void ProjectList::slotProcessJobs()
2932 while (!m_jobList.isEmpty() && !m_abortAllJobs) {
2933 emit projectModified();
2934 AbstractClipJob *job = NULL;
2937 for (int i = 0; i < m_jobList.count(); i++) {
2938 if (m_jobList.at(i)->jobStatus == JOBWAITING) {
2940 m_jobList.at(i)->jobStatus = JOBWORKING;
2941 job = m_jobList.at(i);
2945 else if (m_jobList.at(i)->jobStatus == JOBWORKING)
2949 emit jobCount(count);
2950 m_jobMutex.unlock();
2955 QString destination = job->destination();
2956 // Check if the clip is still here
2957 DocClipBase *currentClip = m_doc->clipManager()->getClipById(job->clipId());
2958 //ProjectItem *processingItem = getItemById(job->clipId());
2959 if (currentClip == NULL) {
2960 job->setStatus(JOBDONE);
2963 // Set clip status to started
2964 emit processLog(job->clipId(), 0, job->jobType, job->statusMessage());
2966 // Make sure destination path is writable
2967 if (!destination.isEmpty()) {
2968 QFile file(destination);
2969 if (!file.open(QIODevice::WriteOnly)) {
2970 emit updateJobStatus(job->clipId(), job->jobType, JOBCRASHED, i18n("Cannot write to path: %1", destination));
2971 job->setStatus(JOBCRASHED);
2975 QFile::remove(destination);
2977 connect(job, SIGNAL(jobProgress(QString, int, int)), this, SIGNAL(processLog(QString, int, int)));
2978 connect(job, SIGNAL(cancelRunningJob(const QString, stringMap)), this, SIGNAL(cancelRunningJob(const QString, stringMap)));
2979 connect(job, SIGNAL(gotFilterJobResults(QString,int, int, QString,stringMap)), this, SIGNAL(gotFilterJobResults(QString,int, int, QString,stringMap)));
2981 if (job->jobType == MLTJOB) {
2982 MeltJob *jb = static_cast<MeltJob *> (job);
2983 jb->setProducer(currentClip->getProducer(), currentClip->fileURL());
2986 if (job->jobStatus == JOBDONE) {
2987 emit updateJobStatus(job->clipId(), job->jobType, JOBDONE);
2988 //TODO: replace with more generic clip replacement framework
2989 if (job->jobType == PROXYJOB) emit gotProxy(job->clipId());
2990 if (job->addClipToProject()) {
2991 emit addClip(destination, QString(), QString());
2993 } else if (job->jobStatus == JOBCRASHED || job->jobStatus == JOBABORTED) {
2994 emit updateJobStatus(job->clipId(), job->jobType, job->jobStatus, job->errorMessage(), QString(), job->logDetails());
2997 // Thread finished, cleanup & update count
2998 QTimer::singleShot(200, this, SIGNAL(checkJobProcess()));
3002 void ProjectList::updateProxyConfig()
3005 QTreeWidgetItemIterator it(m_listView);
3006 QUndoCommand *command = new QUndoCommand();
3007 command->setText(i18n("Update proxy settings"));
3008 QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/";
3010 if ((*it)->type() != PROJECTCLIPTYPE) {
3014 item = static_cast<ProjectItem *>(*it);
3019 CLIPTYPE t = item->clipType();
3020 if ((t == VIDEO || t == AV || t == UNKNOWN) && item->referencedClip() != NULL) {
3021 if (generateProxy() && useProxy() && !hasPendingJob(item, PROXYJOB)) {
3022 DocClipBase *clip = item->referencedClip();
3023 if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > m_doc->getDocumentProperty("proxyminsize").toInt()) {
3024 if (clip->getProperty("proxy").isEmpty()) {
3025 // We need to insert empty proxy in old properties so that undo will work
3026 QMap <QString, QString> oldProps;// = clip->properties();
3027 oldProps.insert("proxy", QString());
3028 QMap <QString, QString> newProps;
3029 newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + '.' + m_doc->getDocumentProperty("proxyextension"));
3030 new EditClipCommand(this, clip->getId(), oldProps, newProps, true, command);
3034 else if (item->hasProxy()) {
3036 QMap <QString, QString> newProps;
3037 newProps.insert("proxy", QString());
3038 // insert required duration for proxy
3039 newProps.insert("proxy_out", item->referencedClip()->producerProperty("out"));
3040 new EditClipCommand(this, item->clipId(), item->referencedClip()->currentProperties(newProps), newProps, true, command);
3043 else if (t == IMAGE && item->referencedClip() != NULL) {
3044 if (generateImageProxy() && useProxy()) {
3045 DocClipBase *clip = item->referencedClip();
3046 int maxImageSize = m_doc->getDocumentProperty("proxyimageminsize").toInt();
3047 if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > maxImageSize || clip->getProperty("frame_size").section('x', 1, 1).toInt() > maxImageSize) {
3048 if (clip->getProperty("proxy").isEmpty()) {
3049 // We need to insert empty proxy in old properties so that undo will work
3050 QMap <QString, QString> oldProps = clip->properties();
3051 oldProps.insert("proxy", QString());
3052 QMap <QString, QString> newProps;
3053 newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + ".png");
3054 new EditClipCommand(this, clip->getId(), oldProps, newProps, true, command);
3058 else if (item->hasProxy()) {
3060 QMap <QString, QString> newProps;
3061 newProps.insert("proxy", QString());
3062 new EditClipCommand(this, item->clipId(), item->referencedClip()->properties(), newProps, true, command);
3067 if (command->childCount() > 0) m_doc->commandStack()->push(command);
3068 else delete command;
3071 void ProjectList::slotProcessLog(const QString id, int progress, int type, const QString message)
3073 ProjectItem *item = getItemById(id);
3074 setJobStatus(item, (JOBTYPE) type, JOBWORKING, progress, message);
3077 void ProjectList::slotProxyCurrentItem(bool doProxy, ProjectItem *itemToProxy)
3079 QList<QTreeWidgetItem *> list;
3080 if (itemToProxy == NULL) list = m_listView->selectedItems();
3081 else list << itemToProxy;
3083 // expand list (folders, subclips) to get real clips
3084 QTreeWidgetItem *listItem;
3085 QList<ProjectItem *> clipList;
3086 for (int i = 0; i < list.count(); i++) {
3087 listItem = list.at(i);
3088 if (listItem->type() == PROJECTFOLDERTYPE) {
3089 for (int j = 0; j < listItem->childCount(); j++) {
3090 QTreeWidgetItem *sub = listItem->child(j);
3091 if (sub->type() == PROJECTCLIPTYPE) {
3092 ProjectItem *item = static_cast <ProjectItem*>(sub);
3093 if (!clipList.contains(item)) clipList.append(item);
3097 else if (listItem->type() == PROJECTSUBCLIPTYPE) {
3098 QTreeWidgetItem *sub = listItem->parent();
3099 ProjectItem *item = static_cast <ProjectItem*>(sub);
3100 if (!clipList.contains(item)) clipList.append(item);
3102 else if (listItem->type() == PROJECTCLIPTYPE) {
3103 ProjectItem *item = static_cast <ProjectItem*>(listItem);
3104 if (!clipList.contains(item)) clipList.append(item);
3108 QUndoCommand *command = new QUndoCommand();
3109 if (doProxy) command->setText(i18np("Add proxy clip", "Add proxy clips", clipList.count()));
3110 else command->setText(i18np("Remove proxy clip", "Remove proxy clips", clipList.count()));
3112 // Make sure the proxy folder exists
3113 QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/";
3114 KStandardDirs::makeDir(proxydir);
3116 QMap <QString, QString> newProps;
3117 QMap <QString, QString> oldProps;
3118 if (!doProxy) newProps.insert("proxy", "-");
3119 for (int i = 0; i < clipList.count(); i++) {
3120 ProjectItem *item = clipList.at(i);
3121 CLIPTYPE t = item->clipType();
3122 if ((t == VIDEO || t == AV || t == UNKNOWN || t == IMAGE || t == PLAYLIST) && item->referencedClip()) {
3123 if ((doProxy && item->hasProxy()) || (!doProxy && !item->hasProxy() && item->referencedClip()->getProducer() != NULL)) continue;
3124 DocClipBase *clip = item->referencedClip();
3125 if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
3126 kDebug()<<"//// TRYING TO PROXY: "<<item->clipId()<<", but it is busy";
3130 //oldProps = clip->properties();
3133 QString path = proxydir + clip->getClipHash() + '.' + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension"));
3134 // insert required duration for proxy
3135 newProps.insert("proxy_out", clip->producerProperty("out"));
3136 newProps.insert("proxy", path);
3137 // We need to insert empty proxy so that undo will work
3138 //oldProps.insert("proxy", QString());
3140 else if (item->referencedClip()->getProducer() == NULL) {
3141 // Force clip reload
3142 kDebug()<<"// CLIP HAD NULL PROD------------";
3143 newProps.insert("resource", item->referencedClip()->getProperty("resource"));
3145 // We need to insert empty proxy so that undo will work
3146 oldProps = clip->currentProperties(newProps);
3147 if (doProxy) oldProps.insert("proxy", "-");
3148 new EditClipCommand(this, item->clipId(), oldProps, newProps, true, command);
3151 if (command->childCount() > 0) {
3152 m_doc->commandStack()->push(command);
3154 else delete command;
3158 void ProjectList::slotDeleteProxy(const QString proxyPath)
3160 if (proxyPath.isEmpty()) return;
3161 QUndoCommand *proxyCommand = new QUndoCommand();
3162 proxyCommand->setText(i18n("Remove Proxy"));
3163 QTreeWidgetItemIterator it(m_listView);
3166 if ((*it)->type() == PROJECTCLIPTYPE) {
3167 item = static_cast <ProjectItem *>(*it);
3168 if (item->referencedClip()->getProperty("proxy") == proxyPath) {
3169 QMap <QString, QString> props;
3170 props.insert("proxy", QString());
3171 new EditClipCommand(this, item->clipId(), item->referencedClip()->currentProperties(props), props, true, proxyCommand);
3177 if (proxyCommand->childCount() == 0)
3178 delete proxyCommand;
3180 m_commandStack->push(proxyCommand);
3181 QFile::remove(proxyPath);
3184 void ProjectList::setJobStatus(ProjectItem *item, JOBTYPE jobType, CLIPJOBSTATUS status, int progress, const QString &statusMessage)
3186 if (item == NULL || (m_abortAllJobs && m_closing)) return;
3187 monitorItemEditing(false);
3188 item->setJobStatus(jobType, status, progress, statusMessage);
3189 if (status == JOBCRASHED) {
3190 DocClipBase *clip = item->referencedClip();
3192 kDebug()<<"// PROXY CRASHED";
3194 else if (clip->getProducer() == NULL && !clip->isPlaceHolder()) {
3195 // disable proxy and fetch real clip
3196 clip->setProperty("proxy", "-");
3197 QDomElement xml = clip->toXML();
3198 m_render->getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), true);
3201 // Disable proxy for this clip
3202 clip->setProperty("proxy", "-");
3205 monitorItemEditing(true);
3208 void ProjectList::monitorItemEditing(bool enable)
3210 if (enable) connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
3211 else disconnect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
3214 QStringList ProjectList::expandedFolders() const
3217 FolderProjectItem *item;
3218 QTreeWidgetItemIterator it(m_listView);
3220 if ((*it)->type() != PROJECTFOLDERTYPE) {
3224 if ((*it)->isExpanded()) {
3225 item = static_cast<FolderProjectItem *>(*it);
3226 result.append(item->clipId());
3233 void ProjectList::processThumbOverlays(ProjectItem *item, QPixmap &pix)
3235 if (item->hasProxy()) {
3237 QColor c(220, 220, 10, 200);
3238 QRect r(0, 0, 12, 12);
3240 QFont font = p.font();
3243 p.setPen(Qt::black);
3244 p.drawText(r, Qt::AlignCenter, i18nc("The first letter of Proxy, used as abbreviation", "P"));
3248 void ProjectList::slotCancelJobs()
3250 m_abortAllJobs = true;
3251 for (int i = 0; i < m_jobList.count(); i++) {
3252 m_jobList.at(i)->setStatus(JOBABORTED);
3254 m_jobThreads.waitForFinished();
3255 m_jobThreads.clearFutures();
3256 QUndoCommand *command = new QUndoCommand();
3257 command->setText(i18np("Cancel job", "Cancel jobs", m_jobList.count()));
3259 for (int i = 0; i < m_jobList.count(); i++) {
3260 DocClipBase *currentClip = m_doc->clipManager()->getClipById(m_jobList.at(i)->clipId());
3261 if (!currentClip) continue;
3262 QMap <QString, QString> newProps = m_jobList.at(i)->cancelProperties();
3263 if (newProps.isEmpty()) continue;
3264 QMap <QString, QString> oldProps = currentClip->currentProperties(newProps);
3265 new EditClipCommand(this, m_jobList.at(i)->clipId(), oldProps, newProps, true, command);
3267 m_jobMutex.unlock();
3268 if (command->childCount() > 0) {
3269 m_doc->commandStack()->push(command);
3271 else delete command;
3272 if (!m_jobList.isEmpty()) qDeleteAll(m_jobList);
3274 m_abortAllJobs = false;
3275 m_infoLabel->slotSetJobCount(0);
3278 void ProjectList::slotCancelRunningJob(const QString id, stringMap newProps)
3280 if (newProps.isEmpty() || m_closing) return;
3281 DocClipBase *currentClip = m_doc->clipManager()->getClipById(id);
3282 if (!currentClip) return;
3283 QMap <QString, QString> oldProps = currentClip->currentProperties(newProps);
3284 if (newProps == oldProps) return;
3285 QMapIterator<QString, QString> i(oldProps);
3286 EditClipCommand *command = new EditClipCommand(this, id, oldProps, newProps, true);
3287 m_commandStack->push(command);
3290 bool ProjectList::hasPendingJob(ProjectItem *item, JOBTYPE type)
3292 if (!item || !item->referencedClip() || m_abortAllJobs) return false;
3293 AbstractClipJob *job;
3294 QMutexLocker lock(&m_jobMutex);
3295 for (int i = 0; i < m_jobList.count(); i++) {
3296 if (m_abortAllJobs) break;
3297 job = m_jobList.at(i);
3298 if (job->clipId() == item->clipId() && job->jobType == type && (job->jobStatus == JOBWAITING || job->jobStatus == JOBWORKING)) return true;
3304 void ProjectList::deleteJobsForClip(const QString &clipId)
3306 QMutexLocker lock(&m_jobMutex);
3307 for (int i = 0; i < m_jobList.count(); i++) {
3308 if (m_jobList.at(i)->clipId() == clipId) {
3309 m_jobList.at(i)->setStatus(JOBABORTED);
3314 void ProjectList::slotUpdateJobStatus(const QString id, int type, int status, const QString label, const QString actionName, const QString details)
3316 ProjectItem *item = getItemById(id);
3318 slotUpdateJobStatus(item, type, status, label, actionName, details);
3322 void ProjectList::slotUpdateJobStatus(ProjectItem *item, int type, int status, const QString &label, const QString &actionName, const QString details)
3324 item->setJobStatus((JOBTYPE) type, (CLIPJOBSTATUS) status);
3325 if (status != JOBCRASHED) return;
3326 #if KDE_IS_VERSION(4,7,0)
3327 QList<QAction *> actions = m_infoMessage->actions();
3328 if (m_infoMessage->isHidden()) {
3329 m_infoMessage->setText(label);
3330 m_infoMessage->setWordWrap(m_infoMessage->text().length() > 35);
3331 m_infoMessage->setMessageType(KMessageWidget::Warning);
3334 if (!actionName.isEmpty()) {
3335 QAction *action = NULL;
3336 QList< KActionCollection * > collections = KActionCollection::allCollections();
3337 for (int i = 0; i < collections.count(); i++) {
3338 KActionCollection *coll = collections.at(i);
3339 action = coll->action(actionName);
3342 if (action && !actions.contains(action)) m_infoMessage->addAction(action);
3344 if (!details.isEmpty()) {
3345 m_errorLog.append(details);
3346 if (!actions.contains(m_logAction)) m_infoMessage->addAction(m_logAction);
3348 m_infoMessage->animatedShow();
3350 // warning for KDE < 4.7
3351 KPassivePopup *passivePop = new KPassivePopup( this );
3352 passivePop->setAutoDelete(true);
3353 connect(passivePop, SIGNAL(clicked()), this, SLOT(slotClosePopup()));
3354 m_errorLog.append(details);
3355 KVBox *vb = new KVBox( passivePop );
3356 KHBox *vh1 = new KHBox( vb );
3357 KIcon icon("dialog-warning");
3358 QLabel *iconLabel = new QLabel(vh1);
3359 iconLabel->setPixmap(icon.pixmap(m_listView->iconSize()));
3360 (void) new QLabel( label, vh1);
3361 KHBox *box = new KHBox( vb );
3362 QPushButton *but = new QPushButton( "Show log", box );
3363 connect(but, SIGNAL(clicked(bool)), this, SLOT(slotShowJobLog()));
3365 passivePop->setView( vb );
3371 void ProjectList::slotShowJobLog()
3374 d.setButtons(KDialog::Close);
3376 for (int i = 0; i < m_errorLog.count(); i++) {
3377 if (i > 0) t.insertHtml("<br><hr /><br>");
3378 t.insertPlainText(m_errorLog.at(i));
3380 t.setReadOnly(true);
3381 d.setMainWidget(&t);
3385 QStringList ProjectList::getPendingJobs(const QString &id)
3388 QMutexLocker lock(&m_jobMutex);
3389 for (int i = 0; i < m_jobList.count(); i++) {
3390 if (m_jobList.at(i)->clipId() == id && (m_jobList.at(i)->jobStatus == JOBWAITING || m_jobList.at(i)->jobStatus == JOBWORKING)) {
3392 result << m_jobList.at(i)->description;
3398 void ProjectList::discardJobs(const QString &id, JOBTYPE type) {
3399 QMutexLocker lock(&m_jobMutex);
3400 for (int i = 0; i < m_jobList.count(); i++) {
3401 if (m_jobList.at(i)->clipId() == id && (m_jobList.at(i)->jobType == type || type == NOJOBTYPE)) {
3403 m_jobList.at(i)->setStatus(JOBABORTED);
3408 void ProjectList::slotStartFilterJob(ItemInfo info, const QString&id, const QString&filterName, const QString&filterParams, const QString&finalFilterName, const QString&consumer, const QString&consumerParams, const QString&properties)
3410 ProjectItem *item = getItemById(id);
3412 QStringList jobParams;
3413 jobParams << QString::number(info.cropStart.frames(m_fps)) << QString::number((info.cropStart + info.cropDuration).frames(m_fps));
3414 jobParams << QString() << filterName << filterParams << consumer << consumerParams << properties << QString::number(info.startPos.frames(m_fps)) << QString::number(info.track) << finalFilterName;
3415 MeltJob *job = new MeltJob(item->clipType(), id, jobParams);
3416 if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
3420 job->description = i18n("Filter %1", finalFilterName);
3421 m_jobList.append(job);
3422 setJobStatus(item, job->jobType, JOBWAITING, 0, job->statusMessage());
3423 slotCheckJobProcess();
3426 void ProjectList::startClipFilterJob(const QString &filterName, const QString &condition)
3428 QStringList ids = getConditionalIds(condition);
3429 QString destination;
3430 ProjectItem *item = getItemById(ids.at(0));
3432 emit displayMessage(i18n("Cannot find clip to process filter %1", filterName), -2);
3435 if (ids.count() == 1) {
3436 destination = item->clipUrl().path();
3439 destination = item->clipUrl().directory();
3441 QPointer<ClipStabilize> d = new ClipStabilize(destination, ids.count(), filterName);
3442 if (d->exec() == QDialog::Accepted) {
3443 processClipJob(ids, d->destination(), d->autoAddClip(), d->params(), d->desc());
3448 void ProjectList::processClipJob(QStringList ids, const QString&destination, bool autoAdd, QStringList jobParams, const QString &description)
3450 QStringList preParams;
3452 preParams << QString::number(0) << QString::number(-1);
3454 preParams << jobParams.takeFirst();
3456 preParams << jobParams.takeFirst();
3458 preParams << jobParams.takeFirst();
3460 QString consumer = jobParams.takeFirst();
3462 foreach(const QString&id, ids) {
3463 ProjectItem *item = getItemById(id);
3464 if (!item) continue;
3465 if (ids.count() == 1) {
3466 consumer += ':' + destination;
3469 consumer += ':' + destination + item->clipUrl().fileName() + ".mlt";
3471 preParams << consumer << jobParams;
3473 MeltJob *job = new MeltJob(item->clipType(), id, preParams);
3475 job->setAddClipToProject(true);
3476 kDebug()<<"// ADDING TRUE";
3478 else kDebug()<<"// ADDING FALSE!!!";
3479 if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
3483 job->description = description;
3484 m_jobList.append(job);
3485 setJobStatus(item, job->jobType, JOBWAITING, 0, job->statusMessage());
3487 slotCheckJobProcess();
3490 void ProjectList::slotPrepareJobsMenu()
3493 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
3495 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE)
3496 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
3498 item = static_cast <ProjectItem*>(m_listView->currentItem());
3499 if (item && (item->flags() & Qt::ItemIsDragEnabled)) {
3500 QString id = item->clipId();
3501 m_discardCurrentClipJobs->setData(id);
3502 QStringList jobs = getPendingJobs(id);
3503 m_discardCurrentClipJobs->setEnabled(!jobs.isEmpty());
3505 m_discardCurrentClipJobs->setData(QString());
3506 m_discardCurrentClipJobs->setEnabled(false);
3510 void ProjectList::slotDiscardClipJobs()
3512 QString id = m_discardCurrentClipJobs->data().toString();
3513 if (id.isEmpty()) return;
3517 void ProjectList::updatePalette()
3519 m_infoLabel->setStyleSheet(SmallInfoLabel::getStyleSheet(QApplication::palette()));
3520 m_listView->updateStyleSheet();
3523 void ProjectList::slotResetInfoMessage()
3525 #if KDE_IS_VERSION(4,7,0)
3527 QList<QAction *> actions = m_infoMessage->actions();
3528 for (int i = 0; i < actions.count(); i++) {
3529 m_infoMessage->removeAction(actions.at(i));
3534 void ProjectList::slotClosePopup()
3539 #include "projectlist.moc"