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>
63 #include <nepomuk/global.h>
64 #include <nepomuk/resourcemanager.h>
65 #include <Nepomuk/Resource>
66 //#include <nepomuk/tag.h>
69 #include <QMouseEvent>
70 #include <QStylePainter>
75 #include <QHeaderView>
76 #include <QInputDialog>
77 #include <QtConcurrentRun>
78 #include <QVBoxLayout>
80 SmallInfoLabel::SmallInfoLabel(QWidget *parent) : QPushButton(parent)
85 /*QString style = "QToolButton {background-color: %1;border-style: outset;border-width: 2px;
86 border-radius: 5px;border-color: beige;}";*/
87 KColorScheme scheme(palette().currentColorGroup(), KColorScheme::Window, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
88 QColor bg = scheme.background(KColorScheme::LinkBackground).color();
89 QColor fg = scheme.foreground(KColorScheme::LinkText).color();
90 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());
92 bg = scheme.background(KColorScheme::ActiveBackground).color();
93 fg = scheme.foreground(KColorScheme::ActiveText).color();
94 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()));
97 m_timeLine = new QTimeLine(500, this);
98 QObject::connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(slotTimeLineChanged(qreal)));
99 QObject::connect(m_timeLine, SIGNAL(finished()), this, SLOT(slotTimeLineFinished()));
103 void SmallInfoLabel::slotTimeLineChanged(qreal value)
105 setFixedWidth(qMin(value * 2, qreal(1.0)) * sizeHint().width());
109 void SmallInfoLabel::slotTimeLineFinished()
111 if (m_timeLine->direction() == QTimeLine::Forward) {
121 void SmallInfoLabel::slotSetJobCount(int jobCount)
125 setText(i18np("%1 job", "%1 jobs", jobCount));
126 setToolTip(i18np("%1 pending job", "%1 pending jobs", jobCount));
128 if (!(KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects)) {
129 setFixedWidth(sizeHint().width());
135 setFixedWidth(sizeHint().width());
142 int wantedWidth = sizeHint().width();
143 setGeometry(-wantedWidth, 0, wantedWidth, height());
144 m_timeLine->setDirection(QTimeLine::Forward);
145 if (m_timeLine->state() == QTimeLine::NotRunning) {
150 if (!(KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects)) {
156 m_timeLine->setDirection(QTimeLine::Backward);
157 if (m_timeLine->state() == QTimeLine::NotRunning) {
165 InvalidDialog::InvalidDialog(const QString &caption, const QString &message, bool infoOnly, QWidget *parent) : KDialog(parent)
168 if (infoOnly) setButtons(KDialog::Ok);
169 else setButtons(KDialog::Yes | KDialog::No);
170 QWidget *w = new QWidget(this);
171 QVBoxLayout *l = new QVBoxLayout;
172 l->addWidget(new QLabel(message));
173 m_clipList = new QListWidget;
174 l->addWidget(m_clipList);
179 InvalidDialog::~InvalidDialog()
185 void InvalidDialog::addClip(const QString &id, const QString &path)
187 QListWidgetItem *item = new QListWidgetItem(path);
188 item->setData(Qt::UserRole, id);
189 m_clipList->addItem(item);
192 QStringList InvalidDialog::getIds() const
195 for (int i = 0; i < m_clipList->count(); i++) {
196 ids << m_clipList->item(i)->data(Qt::UserRole).toString();
202 ProjectList::ProjectList(QWidget *parent) :
206 m_commandStack(NULL),
208 m_reloadAction(NULL),
209 m_extractAudioAction(NULL),
210 m_transcodeAction(NULL),
211 m_stabilizeAction(NULL),
214 m_allClipsProcessed(false),
216 m_abortAllJobs(false),
218 m_invalidClipDialog(NULL)
220 qRegisterMetaType<stringMap> ("stringMap");
221 QVBoxLayout *layout = new QVBoxLayout;
222 layout->setContentsMargins(0, 0, 0, 0);
223 layout->setSpacing(0);
224 qRegisterMetaType<QDomElement>("QDomElement");
226 QFrame *frame = new QFrame;
227 frame->setFrameStyle(QFrame::NoFrame);
228 QHBoxLayout *box = new QHBoxLayout;
229 box->setContentsMargins(0, 0, 0, 0);
231 KTreeWidgetSearchLine *searchView = new KTreeWidgetSearchLine;
232 box->addWidget(searchView);
234 // small info button for pending jobs
235 m_infoLabel = new SmallInfoLabel(this);
236 connect(this, SIGNAL(jobCount(int)), m_infoLabel, SLOT(slotSetJobCount(int)));
237 m_jobsMenu = new QMenu(this);
238 connect(m_jobsMenu, SIGNAL(aboutToShow()), this, SLOT(slotPrepareJobsMenu()));
239 QAction *cancelJobs = new QAction(i18n("Cancel All Jobs"), this);
240 cancelJobs->setCheckable(false);
241 connect(cancelJobs, SIGNAL(triggered()), this, SLOT(slotCancelJobs()));
242 connect(this, SIGNAL(checkJobProcess()), this, SLOT(slotCheckJobProcess()));
243 m_discardCurrentClipJobs = new QAction(i18n("Cancel Current Clip Jobs"), this);
244 m_discardCurrentClipJobs->setCheckable(false);
245 connect(m_discardCurrentClipJobs, SIGNAL(triggered()), this, SLOT(slotDiscardClipJobs()));
246 m_jobsMenu->addAction(cancelJobs);
247 m_jobsMenu->addAction(m_discardCurrentClipJobs);
248 m_infoLabel->setMenu(m_jobsMenu);
249 box->addWidget(m_infoLabel);
251 int size = style()->pixelMetric(QStyle::PM_SmallIconSize);
252 QSize iconSize(size, size);
254 m_addButton = new QToolButton;
255 m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
256 m_addButton->setAutoRaise(true);
257 m_addButton->setIconSize(iconSize);
258 box->addWidget(m_addButton);
260 m_editButton = new QToolButton;
261 m_editButton->setAutoRaise(true);
262 m_editButton->setIconSize(iconSize);
263 box->addWidget(m_editButton);
265 m_deleteButton = new QToolButton;
266 m_deleteButton->setAutoRaise(true);
267 m_deleteButton->setIconSize(iconSize);
268 box->addWidget(m_deleteButton);
269 frame->setLayout(box);
270 layout->addWidget(frame);
272 m_listView = new ProjectListView;
273 layout->addWidget(m_listView);
275 #if KDE_IS_VERSION(4,7,0)
276 m_infoMessage = new KMessageWidget;
277 layout->addWidget(m_infoMessage);
278 m_infoMessage->setCloseButtonVisible(true);
279 //m_infoMessage->setWordWrap(true);
280 m_infoMessage->hide();
281 m_logAction = new QAction(i18n("Show Log"), this);
282 m_logAction->setCheckable(false);
283 connect(m_logAction, SIGNAL(triggered()), this, SLOT(slotShowJobLog()));
287 searchView->setTreeWidget(m_listView);
289 connect(this, SIGNAL(processNextThumbnail()), this, SLOT(slotProcessNextThumbnail()));
290 connect(m_listView, SIGNAL(projectModified()), this, SIGNAL(projectModified()));
291 connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
292 connect(m_listView, SIGNAL(focusMonitor()), this, SIGNAL(raiseClipMonitor()));
293 connect(m_listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
294 connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
295 connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
296 connect(m_listView, SIGNAL(addClip(const QList <QUrl>, const QString &, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &, const QString &)));
297 connect(this, SIGNAL(addClip(const QString, const QString &, const QString &)), this, SLOT(slotAddClip(const QString, const QString &, const QString &)));
298 connect(m_listView, SIGNAL(addClipCut(const QString &, int, int)), this, SLOT(slotAddClipCut(const QString &, int, int)));
299 connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
300 connect(m_listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
302 connect(this, SIGNAL(cancelRunningJob(const QString, stringMap )), this, SLOT(slotCancelRunningJob(const QString, stringMap)));
303 connect(this, SIGNAL(processLog(const QString, int , int, const QString)), this, SLOT(slotProcessLog(const QString, int , int, const QString)));
305 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)));
307 connect(this, SIGNAL(gotProxy(const QString)), this, SLOT(slotGotProxyForId(const QString)));
309 m_listViewDelegate = new ItemDelegate(m_listView);
310 m_listView->setItemDelegate(m_listViewDelegate);
312 if (KdenliveSettings::activate_nepomuk()) {
313 Nepomuk::ResourceManager::instance()->init();
314 if (!Nepomuk::ResourceManager::instance()->initialized()) {
315 kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
316 KdenliveSettings::setActivate_nepomuk(false);
322 ProjectList::~ProjectList()
324 m_abortAllJobs = true;
325 for (int i = 0; i < m_jobList.count(); i++) {
326 m_jobList.at(i)->setStatus(JOBABORTED);
329 m_thumbnailQueue.clear();
330 m_jobThreads.waitForFinished();
331 m_jobThreads.clearFutures();
332 if (!m_jobList.isEmpty()) qDeleteAll(m_jobList);
335 m_listView->blockSignals(true);
337 delete m_listViewDelegate;
338 #if KDE_IS_VERSION(4,7,0)
339 delete m_infoMessage;
343 void ProjectList::focusTree() const
345 m_listView->setFocus();
348 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
350 QList <QAction *> actions = addMenu->actions();
351 for (int i = 0; i < actions.count(); i++) {
352 if (actions.at(i)->data().toString() == "clip_properties") {
353 m_editButton->setDefaultAction(actions.at(i));
356 } else if (actions.at(i)->data().toString() == "delete_clip") {
357 m_deleteButton->setDefaultAction(actions.at(i));
360 } else if (actions.at(i)->data().toString() == "edit_clip") {
361 m_openAction = actions.at(i);
364 } else if (actions.at(i)->data().toString() == "reload_clip") {
365 m_reloadAction = actions.at(i);
368 } else if (actions.at(i)->data().toString() == "proxy_clip") {
369 m_proxyAction = actions.at(i);
375 QMenu *m = new QMenu();
376 m->addActions(actions);
377 m_addButton->setMenu(m);
378 m_addButton->setDefaultAction(defaultAction);
379 m_menu = new QMenu();
380 m_menu->addActions(addMenu->actions());
383 void ProjectList::setupGeneratorMenu(const QHash<QString,QMenu*>& menus)
385 if (!menus.contains("addMenu") && ! menus.value("addMenu") )
387 QMenu *menu = m_addButton->menu();
388 if (menus.contains("addMenu") && menus.value("addMenu")){
389 QMenu* addMenu=menus.value("addMenu");
390 menu->addMenu(addMenu);
391 m_addButton->setMenu(menu);
392 if (addMenu->isEmpty())
393 addMenu->setEnabled(false);
395 if (menus.contains("extractAudioMenu") && menus.value("extractAudioMenu") ){
396 QMenu* extractAudioMenu = menus.value("extractAudioMenu");
397 m_menu->addMenu(extractAudioMenu);
398 m_extractAudioAction = extractAudioMenu;
400 if (menus.contains("transcodeMenu") && menus.value("transcodeMenu") ){
401 QMenu* transcodeMenu = menus.value("transcodeMenu");
402 m_menu->addMenu(transcodeMenu);
403 if (transcodeMenu->isEmpty())
404 transcodeMenu->setEnabled(false);
405 m_transcodeAction = transcodeMenu;
407 if (menus.contains("stabilizeMenu") && menus.value("stabilizeMenu") ){
408 QMenu* stabilizeMenu=menus.value("stabilizeMenu");
409 m_menu->addMenu(stabilizeMenu);
410 if (stabilizeMenu->isEmpty())
411 stabilizeMenu->setEnabled(false);
412 m_stabilizeAction=stabilizeMenu;
415 m_menu->addAction(m_reloadAction);
416 m_menu->addAction(m_proxyAction);
417 if (menus.contains("inTimelineMenu") && menus.value("inTimelineMenu")){
418 QMenu* inTimelineMenu=menus.value("inTimelineMenu");
419 m_menu->addMenu(inTimelineMenu);
420 inTimelineMenu->setEnabled(false);
422 m_menu->addAction(m_editButton->defaultAction());
423 m_menu->addAction(m_openAction);
424 m_menu->addAction(m_deleteButton->defaultAction());
425 m_menu->insertSeparator(m_deleteButton->defaultAction());
428 void ProjectList::clearSelection()
430 m_listView->clearSelection();
433 QByteArray ProjectList::headerInfo() const
435 return m_listView->header()->saveState();
438 void ProjectList::setHeaderInfo(const QByteArray &state)
440 m_listView->header()->restoreState(state);
443 void ProjectList::updateProjectFormat(Timecode t)
448 void ProjectList::slotEditClip()
450 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
451 if (list.isEmpty()) return;
452 if (list.count() > 1 || list.at(0)->type() == PROJECTFOLDERTYPE) {
453 editClipSelection(list);
457 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
459 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE)
460 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
462 item = static_cast <ProjectItem*>(m_listView->currentItem());
463 if (item && (item->flags() & Qt::ItemIsDragEnabled)) {
464 emit clipSelected(item->referencedClip());
465 emit showClipProperties(item->referencedClip());
469 void ProjectList::editClipSelection(QList<QTreeWidgetItem *> list)
471 // Gather all common properties
472 QMap <QString, QString> commonproperties;
473 QList <DocClipBase *> clipList;
474 commonproperties.insert("force_aspect_num", "-");
475 commonproperties.insert("force_aspect_den", "-");
476 commonproperties.insert("force_fps", "-");
477 commonproperties.insert("force_progressive", "-");
478 commonproperties.insert("force_tff", "-");
479 commonproperties.insert("threads", "-");
480 commonproperties.insert("video_index", "-");
481 commonproperties.insert("audio_index", "-");
482 commonproperties.insert("force_colorspace", "-");
483 commonproperties.insert("full_luma", "-");
484 QString transparency = "-";
486 bool allowDurationChange = true;
487 int commonDuration = -1;
488 bool hasImages = false;;
490 for (int i = 0; i < list.count(); i++) {
492 if (list.at(i)->type() == PROJECTFOLDERTYPE) {
493 // Add folder items to the list
494 int ct = list.at(i)->childCount();
495 for (int j = 0; j < ct; j++) {
496 list.append(list.at(i)->child(j));
500 else if (list.at(i)->type() == PROJECTSUBCLIPTYPE)
501 item = static_cast <ProjectItem*>(list.at(i)->parent());
503 item = static_cast <ProjectItem*>(list.at(i));
504 if (!(item->flags() & Qt::ItemIsDragEnabled))
508 DocClipBase *clip = item->referencedClip();
509 if (clipList.contains(clip)) continue;
510 if (clip->clipType() == IMAGE) {
512 if (clip->getProperty("transparency").isEmpty() || clip->getProperty("transparency").toInt() == 0) {
513 if (transparency == "-") {
514 // first non transparent image
517 else if (transparency == "1") {
518 // we have transparent and non transparent clips
523 if (transparency == "-") {
524 // first transparent image
527 else if (transparency == "0") {
528 // we have transparent and non transparent clips
533 if (clip->clipType() != COLOR && clip->clipType() != IMAGE && clip->clipType() != TEXT)
534 allowDurationChange = false;
535 if (allowDurationChange && commonDuration != 0) {
536 if (commonDuration == -1)
537 commonDuration = clip->duration().frames(m_fps);
538 else if (commonDuration != clip->duration().frames(m_fps))
541 clipList.append(clip);
542 QMap <QString, QString> clipprops = clip->properties();
543 QMapIterator<QString, QString> p(commonproperties);
544 while (p.hasNext()) {
546 if (p.value().isEmpty()) continue;
547 if (clipprops.contains(p.key())) {
548 if (p.value() == "-")
549 commonproperties.insert(p.key(), clipprops.value(p.key()));
550 else if (p.value() != clipprops.value(p.key()))
551 commonproperties.insert(p.key(), QString());
553 commonproperties.insert(p.key(), QString());
558 if (allowDurationChange)
559 commonproperties.insert("out", QString::number(commonDuration));
561 commonproperties.insert("transparency", transparency);
562 /*QMapIterator<QString, QString> p(commonproperties);
563 while (p.hasNext()) {
565 kDebug() << "Result: " << p.key() << " = " << p.value();
567 if (clipList.isEmpty()) {
568 emit displayMessage(i18n("No available clip selected"), -2);
570 else emit showClipProperties(clipList, commonproperties);
573 void ProjectList::slotOpenClip()
576 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
578 if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1)
579 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
581 item = static_cast <ProjectItem*>(m_listView->currentItem());
583 if (item->clipType() == IMAGE) {
584 if (KdenliveSettings::defaultimageapp().isEmpty())
585 KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open images in the Settings dialog"));
587 QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
589 if (item->clipType() == AUDIO) {
590 if (KdenliveSettings::defaultaudioapp().isEmpty())
591 KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open audio files in the Settings dialog"));
593 QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
598 void ProjectList::cleanup()
600 m_listView->clearSelection();
601 QTreeWidgetItemIterator it(m_listView);
604 if ((*it)->type() != PROJECTCLIPTYPE) {
608 item = static_cast <ProjectItem *>(*it);
609 if (item->numReferences() == 0)
610 item->setSelected(true);
616 void ProjectList::trashUnusedClips()
618 QTreeWidgetItemIterator it(m_listView);
623 if ((*it)->type() != PROJECTCLIPTYPE) {
627 item = static_cast <ProjectItem *>(*it);
628 if (item->numReferences() == 0) {
629 ids << item->clipId();
630 KUrl url = item->clipUrl();
631 if (!url.isEmpty() && !urls.contains(url.path()))
637 // Check that we don't use the URL in another clip
638 QTreeWidgetItemIterator it2(m_listView);
640 if ((*it2)->type() != PROJECTCLIPTYPE) {
644 item = static_cast <ProjectItem *>(*it2);
645 if (item->numReferences() > 0) {
646 KUrl url = item->clipUrl();
647 if (!url.isEmpty() && urls.contains(url.path())) urls.removeAll(url.path());
652 emit deleteProjectClips(ids, QMap <QString, QString>());
653 for (int i = 0; i < urls.count(); i++)
654 KIO::NetAccess::del(KUrl(urls.at(i)), this);
657 void ProjectList::slotReloadClip(const QString &id)
659 QList<QTreeWidgetItem *> selected;
661 selected = m_listView->selectedItems();
663 ProjectItem *itemToReLoad = getItemById(id);
664 if (itemToReLoad) selected.append(itemToReLoad);
667 for (int i = 0; i < selected.count(); i++) {
668 if (selected.at(i)->type() != PROJECTCLIPTYPE) {
669 if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
670 for (int j = 0; j < selected.at(i)->childCount(); j++)
671 selected.append(selected.at(i)->child(j));
675 item = static_cast <ProjectItem *>(selected.at(i));
676 if (item && !hasPendingJob(item, PROXYJOB)) {
677 DocClipBase *clip = item->referencedClip();
678 if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
679 kDebug()<<"//// TRYING TO RELOAD: "<<item->clipId()<<", but it is busy";
682 CLIPTYPE t = item->clipType();
684 if (clip && !clip->getProperty("xmltemplate").isEmpty())
685 regenerateTemplate(item);
686 } else if (t != COLOR && t != SLIDESHOW && clip && clip->checkHash() == false) {
687 item->referencedClip()->setPlaceHolder(true);
688 item->setProperty("file_hash", QString());
689 } else if (t == IMAGE) {
690 clip->getProducer()->set("force_reload", 1);
693 QDomElement e = item->toXml();
694 // Make sure we get the correct producer length if it was adjusted in timeline
695 if (t == COLOR || t == IMAGE || t == SLIDESHOW || t == TEXT) {
696 int length = QString(clip->producerProperty("length")).toInt();
697 if (length > 0 && !e.hasAttribute("length")) {
698 e.setAttribute("length", length);
701 resetThumbsProducer(clip);
702 m_render->getFileProperties(e, item->clipId(), m_listView->iconSize().height(), true);
707 void ProjectList::slotModifiedClip(const QString &id)
709 ProjectItem *item = getItemById(id);
711 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
712 if (!pixmap.isNull()) {
714 p.fillRect(0, 0, pixmap.width(), pixmap.height(), QColor(255, 255, 255, 200));
715 p.drawPixmap(0, 0, KIcon("view-refresh").pixmap(m_listView->iconSize()));
718 pixmap = KIcon("view-refresh").pixmap(m_listView->iconSize());
720 item->setData(0, Qt::DecorationRole, pixmap);
724 void ProjectList::slotMissingClip(const QString &id)
726 ProjectItem *item = getItemById(id);
728 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
729 int height = m_listView->iconSize().height();
730 int width = (int)(height * m_render->dar());
731 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
732 if (pixmap.isNull()) {
733 pixmap = QPixmap(width, height);
734 pixmap.fill(Qt::transparent);
736 KIcon icon("dialog-close");
738 p.drawPixmap(3, 3, icon.pixmap(width - 6, height - 6));
740 item->setData(0, Qt::DecorationRole, pixmap);
741 if (item->referencedClip()) {
742 item->referencedClip()->setPlaceHolder(true);
743 if (m_render == NULL) {
744 kDebug() << "********* ERROR, NULL RENDR";
747 Mlt::Producer *newProd = m_render->invalidProducer(id);
748 if (item->referencedClip()->getProducer()) {
749 Mlt::Properties props(newProd->get_properties());
750 Mlt::Properties src_props(item->referencedClip()->getProducer()->get_properties());
751 props.inherit(src_props);
753 item->referencedClip()->setProducer(newProd, true);
754 item->slotSetToolTip();
755 emit clipNeedsReload(id);
759 emit displayMessage(i18n("Check missing clips"), -2);
760 emit updateRenderStatus();
763 void ProjectList::slotAvailableClip(const QString &id)
765 ProjectItem *item = getItemById(id);
768 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
769 if (item->referencedClip()) { // && item->referencedClip()->checkHash() == false) {
770 item->setProperty("file_hash", QString());
774 item->referencedClip()->setValid();
775 item->slotSetToolTip();
778 emit updateRenderStatus();
781 bool ProjectList::hasMissingClips()
783 bool missing = false;
784 QTreeWidgetItemIterator it(m_listView);
786 if ((*it)->type() == PROJECTCLIPTYPE && !((*it)->flags() & Qt::ItemIsDragEnabled)) {
795 void ProjectList::setRenderer(Render *projectRender)
797 m_render = projectRender;
798 m_listView->setIconSize(QSize((ProjectItem::itemDefaultHeight() - 2) * m_render->dar(), ProjectItem::itemDefaultHeight() - 2));
799 connect(m_render, SIGNAL(requestProxy(QString)), this, SLOT(slotCreateProxy(QString)));
802 void ProjectList::slotClipSelected()
804 QTreeWidgetItem *item = m_listView->currentItem();
805 ProjectItem *clip = NULL;
807 if (item->type() == PROJECTFOLDERTYPE) {
808 emit clipSelected(NULL);
809 m_editButton->defaultAction()->setEnabled(item->childCount() > 0);
810 m_deleteButton->defaultAction()->setEnabled(true);
811 m_openAction->setEnabled(false);
812 m_reloadAction->setEnabled(false);
813 m_extractAudioAction->setEnabled(false);
814 m_transcodeAction->setEnabled(false);
815 m_stabilizeAction->setEnabled(false);
817 if (item->type() == PROJECTSUBCLIPTYPE) {
818 // this is a sub item, use base clip
819 m_deleteButton->defaultAction()->setEnabled(true);
820 clip = static_cast <ProjectItem*>(item->parent());
821 if (clip == NULL) kDebug() << "-----------ERROR";
822 SubProjectItem *sub = static_cast <SubProjectItem*>(item);
823 emit clipSelected(clip->referencedClip(), sub->zone());
824 m_extractAudioAction->setEnabled(false);
825 m_transcodeAction->setEnabled(false);
826 m_stabilizeAction->setEnabled(false);
827 m_reloadAction->setEnabled(false);
828 adjustProxyActions(clip);
831 clip = static_cast <ProjectItem*>(item);
832 if (clip && clip->referencedClip())
833 emit clipSelected(clip->referencedClip());
834 m_editButton->defaultAction()->setEnabled(true);
835 m_deleteButton->defaultAction()->setEnabled(true);
836 m_reloadAction->setEnabled(true);
837 m_extractAudioAction->setEnabled(true);
838 m_transcodeAction->setEnabled(true);
839 m_stabilizeAction->setEnabled(true);
840 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
841 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
842 m_openAction->setEnabled(true);
843 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
844 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
845 m_openAction->setEnabled(true);
847 m_openAction->setEnabled(false);
849 // Display relevant transcoding actions only
850 adjustTranscodeActions(clip);
851 adjustStabilizeActions(clip);
852 // Display uses in timeline
853 emit findInTimeline(clip->clipId());
856 emit clipSelected(NULL);
857 m_editButton->defaultAction()->setEnabled(false);
858 m_deleteButton->defaultAction()->setEnabled(false);
859 m_openAction->setEnabled(false);
860 m_reloadAction->setEnabled(false);
861 m_extractAudioAction->setEnabled(true);
862 m_transcodeAction->setEnabled(false);
863 m_stabilizeAction->setEnabled(false);
865 adjustProxyActions(clip);
868 void ProjectList::adjustProxyActions(ProjectItem *clip) const
870 if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == SLIDESHOW || clip->clipType() == AUDIO) {
871 m_proxyAction->setEnabled(false);
874 bool enabled = useProxy();
875 if (clip->referencedClip() && !clip->referencedClip()->getProperty("_missingsource").isEmpty()) enabled = false;
876 m_proxyAction->setEnabled(enabled);
877 m_proxyAction->blockSignals(true);
878 m_proxyAction->setChecked(clip->hasProxy());
879 m_proxyAction->blockSignals(false);
882 void ProjectList::adjustStabilizeActions(ProjectItem *clip) const
885 if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW) {
886 m_stabilizeAction->setEnabled(false);
889 m_stabilizeAction->setEnabled(true);
893 void ProjectList::adjustTranscodeActions(ProjectItem *clip) const
895 if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW) {
896 m_transcodeAction->setEnabled(false);
897 m_extractAudioAction->setEnabled(false);
900 m_transcodeAction->setEnabled(true);
901 m_extractAudioAction->setEnabled(true);
902 QList<QAction *> transcodeActions = m_transcodeAction->actions();
905 for (int i = 0; i < transcodeActions.count(); i++) {
906 data = transcodeActions.at(i)->data().toStringList();
907 if (data.count() > 2) {
908 condition = data.at(2);
909 if (condition.startsWith("vcodec"))
910 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
911 else if (condition.startsWith("acodec"))
912 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
918 void ProjectList::slotPauseMonitor()
924 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
926 ProjectItem *item = getItemById(id);
928 slotUpdateClipProperties(item, properties);
929 if (properties.contains("out") || properties.contains("force_fps") || properties.contains("resource")) {
931 } else if (properties.contains("colour") ||
932 properties.contains("xmldata") ||
933 properties.contains("force_aspect_num") ||
934 properties.contains("force_aspect_den") ||
935 properties.contains("templatetext")) {
936 slotRefreshClipThumbnail(item);
937 emit refreshClip(id, true);
938 } else if (properties.contains("full_luma") || properties.contains("force_colorspace") || properties.contains("loop")) {
939 emit refreshClip(id, false);
944 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
948 clip->setProperties(properties);
949 if (properties.contains("proxy")) {
950 if (properties.value("proxy") == "-" || properties.value("proxy").isEmpty())
951 // this should only apply to proxy jobs
952 clip->setConditionalJobStatus(NOJOB, PROXYJOB);
954 if (properties.contains("name")) {
955 monitorItemEditing(false);
956 clip->setText(0, properties.value("name"));
957 monitorItemEditing(true);
958 emit clipNameChanged(clip->clipId(), properties.value("name"));
960 if (properties.contains("description")) {
961 CLIPTYPE type = clip->clipType();
962 monitorItemEditing(false);
963 clip->setText(1, properties.value("description"));
964 monitorItemEditing(true);
966 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
967 // Use Nepomuk system to store clip description
968 Nepomuk::Resource f(clip->clipUrl().path());
969 f.setDescription(properties.value("description"));
972 emit projectModified();
976 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
978 if (item->type() == PROJECTSUBCLIPTYPE) {
979 // this is a sub-item
981 // user edited description
982 SubProjectItem *sub = static_cast <SubProjectItem*>(item);
983 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
984 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), sub->zone(), sub->description(), sub->text(1), true);
985 m_commandStack->push(command);
986 //slotUpdateCutClipProperties(sub->clipId(), sub->zone(), sub->text(1), sub->text(1));
990 if (item->type() == PROJECTFOLDERTYPE) {
992 FolderProjectItem *folder = static_cast <FolderProjectItem*>(item);
993 editFolder(item->text(0), folder->groupName(), folder->clipId());
994 folder->setGroupName(item->text(0));
995 m_doc->clipManager()->addFolder(folder->clipId(), item->text(0));
996 const int children = item->childCount();
997 for (int i = 0; i < children; i++) {
998 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
999 child->setProperty("groupname", item->text(0));
1005 ProjectItem *clip = static_cast <ProjectItem*>(item);
1007 if (clip->referencedClip()) {
1008 QMap <QString, QString> oldprops;
1009 QMap <QString, QString> newprops;
1010 oldprops["description"] = clip->referencedClip()->getProperty("description");
1011 newprops["description"] = item->text(1);
1013 if (clip->clipType() == TEXT) {
1014 // This is a text template clip, update the image
1015 /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
1016 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/
1017 oldprops.insert("templatetext", clip->referencedClip()->getProperty("templatetext"));
1018 newprops.insert("templatetext", item->text(1));
1020 slotUpdateClipProperties(clip->clipId(), newprops);
1021 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
1022 m_commandStack->push(command);
1024 } else if (column == 0) {
1025 if (clip->referencedClip()) {
1026 QMap <QString, QString> oldprops;
1027 QMap <QString, QString> newprops;
1028 oldprops["name"] = clip->referencedClip()->getProperty("name");
1029 if (oldprops.value("name") != item->text(0)) {
1030 newprops["name"] = item->text(0);
1031 slotUpdateClipProperties(clip, newprops);
1032 emit projectModified();
1033 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
1034 m_commandStack->push(command);
1040 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
1042 bool enable = item ? true : false;
1043 m_editButton->defaultAction()->setEnabled(enable);
1044 m_deleteButton->defaultAction()->setEnabled(enable);
1045 m_reloadAction->setEnabled(enable);
1046 m_extractAudioAction->setEnabled(enable);
1047 m_transcodeAction->setEnabled(enable);
1048 m_stabilizeAction->setEnabled(enable);
1050 ProjectItem *clip = NULL;
1051 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
1052 clip = static_cast <ProjectItem*>(item->parent());
1053 m_extractAudioAction->setEnabled(false);
1054 m_transcodeAction->setEnabled(false);
1055 m_stabilizeAction->setEnabled(false);
1056 adjustProxyActions(clip);
1057 } else if (m_listView->currentItem()->type() == PROJECTCLIPTYPE) {
1058 clip = static_cast <ProjectItem*>(item);
1059 // Display relevant transcoding actions only
1060 adjustTranscodeActions(clip);
1061 adjustStabilizeActions(clip);
1062 adjustProxyActions(clip);
1063 // Display uses in timeline
1064 emit findInTimeline(clip->clipId());
1066 m_extractAudioAction->setEnabled(false);
1067 m_transcodeAction->setEnabled(false);
1068 m_stabilizeAction->setEnabled(false);
1070 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
1071 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
1072 m_openAction->setEnabled(true);
1073 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
1074 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
1075 m_openAction->setEnabled(true);
1077 m_openAction->setEnabled(false);
1081 m_openAction->setEnabled(false);
1086 void ProjectList::slotRemoveClip()
1088 if (!m_listView->currentItem())
1091 QMap <QString, QString> folderids;
1092 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
1094 QUndoCommand *delCommand = new QUndoCommand();
1095 delCommand->setText(i18n("Delete Clip Zone"));
1096 for (int i = 0; i < selected.count(); i++) {
1097 if (selected.at(i)->type() == PROJECTSUBCLIPTYPE) {
1099 SubProjectItem *sub = static_cast <SubProjectItem *>(selected.at(i));
1100 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
1101 new AddClipCutCommand(this, item->clipId(), sub->zone().x(), sub->zone().y(), sub->description(), false, true, delCommand);
1102 } else if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
1104 FolderProjectItem *folder = static_cast <FolderProjectItem *>(selected.at(i));
1105 folderids[folder->groupName()] = folder->clipId();
1106 int children = folder->childCount();
1108 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)
1110 for (int i = 0; i < children; ++i) {
1111 ProjectItem *child = static_cast <ProjectItem *>(folder->child(i));
1112 ids << child->clipId();
1115 ProjectItem *item = static_cast <ProjectItem *>(selected.at(i));
1116 ids << item->clipId();
1117 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) {
1118 KMessageBox::enableMessage("DeleteAll");
1123 KMessageBox::enableMessage("DeleteAll");
1124 if (delCommand->childCount() == 0)
1127 m_commandStack->push(delCommand);
1128 emit deleteProjectClips(ids, folderids);
1131 void ProjectList::updateButtons() const
1133 if (m_listView->topLevelItemCount() == 0) {
1134 m_deleteButton->defaultAction()->setEnabled(false);
1135 m_editButton->defaultAction()->setEnabled(false);
1137 m_deleteButton->defaultAction()->setEnabled(true);
1138 if (!m_listView->currentItem())
1139 m_listView->setCurrentItem(m_listView->topLevelItem(0));
1140 QTreeWidgetItem *item = m_listView->currentItem();
1141 if (item && item->type() == PROJECTCLIPTYPE) {
1142 m_editButton->defaultAction()->setEnabled(true);
1143 m_openAction->setEnabled(true);
1144 m_reloadAction->setEnabled(true);
1145 m_transcodeAction->setEnabled(true);
1146 m_stabilizeAction->setEnabled(true);
1149 else if (item && item->type() == PROJECTFOLDERTYPE && item->childCount() > 0) {
1150 m_editButton->defaultAction()->setEnabled(true);
1152 else m_editButton->defaultAction()->setEnabled(false);
1154 m_openAction->setEnabled(false);
1155 m_reloadAction->setEnabled(false);
1156 m_transcodeAction->setEnabled(false);
1157 m_stabilizeAction->setEnabled(false);
1158 m_proxyAction->setEnabled(false);
1161 void ProjectList::selectItemById(const QString &clipId)
1163 ProjectItem *item = getItemById(clipId);
1165 m_listView->setCurrentItem(item);
1169 void ProjectList::slotDeleteClip(const QString &clipId)
1171 ProjectItem *item = getItemById(clipId);
1173 kDebug() << "/// Cannot find clip to delete";
1176 deleteJobsForClip(clipId);
1177 m_listView->blockSignals(true);
1178 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
1179 if (!newSelectedItem)
1180 newSelectedItem = m_listView->itemBelow(item);
1182 // Pause playing to prevent crash while deleting clip
1184 m_doc->clipManager()->deleteClip(clipId);
1185 m_listView->blockSignals(false);
1186 if (newSelectedItem) {
1187 m_listView->setCurrentItem(newSelectedItem);
1190 emit clipSelected(NULL);
1195 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
1197 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
1198 m_commandStack->push(command);
1199 m_doc->setModified(true);
1202 void ProjectList::slotAddFolder(const QString &name)
1204 AddFolderCommand *command = new AddFolderCommand(this, name.isEmpty() ? i18n("Folder") : name, QString::number(m_doc->clipManager()->getFreeFolderId()), true);
1205 m_commandStack->push(command);
1208 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
1211 FolderProjectItem *item = getFolderItemById(clipId);
1213 m_doc->clipManager()->deleteFolder(clipId);
1214 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
1215 if (!newSelectedItem)
1216 newSelectedItem = m_listView->itemBelow(item);
1218 if (newSelectedItem)
1219 m_listView->setCurrentItem(newSelectedItem);
1225 FolderProjectItem *item = getFolderItemById(clipId);
1227 m_listView->blockSignals(true);
1228 item->setGroupName(foldername);
1229 m_listView->blockSignals(false);
1230 m_doc->clipManager()->addFolder(clipId, foldername);
1231 const int children = item->childCount();
1232 for (int i = 0; i < children; i++) {
1233 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
1234 child->setProperty("groupname", foldername);
1238 m_listView->blockSignals(true);
1239 m_listView->setCurrentItem(new FolderProjectItem(m_listView, QStringList() << foldername, clipId));
1240 m_doc->clipManager()->addFolder(clipId, foldername);
1241 m_listView->blockSignals(false);
1242 m_listView->editItem(m_listView->currentItem(), 0);
1246 m_doc->setModified(true);
1251 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
1253 QMapIterator<QString, QString> i(map);
1254 QUndoCommand *delCommand = new QUndoCommand();
1255 delCommand->setText(i18n("Delete Folder"));
1256 while (i.hasNext()) {
1258 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
1260 if (delCommand->childCount() > 0) m_commandStack->push(delCommand);
1261 else delete delCommand;
1264 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
1266 //m_listView->setEnabled(false);
1267 const QString parent = clip->getProperty("groupid");
1268 ProjectItem *item = NULL;
1269 monitorItemEditing(false);
1270 if (!parent.isEmpty()) {
1271 FolderProjectItem *parentitem = getFolderItemById(parent);
1274 QString groupName = clip->getProperty("groupname");
1275 //kDebug() << "Adding clip to new group: " << groupName;
1276 if (groupName.isEmpty()) groupName = i18n("Folder");
1278 parentitem = new FolderProjectItem(m_listView, text, parent);
1282 item = new ProjectItem(parentitem, clip);
1285 item = new ProjectItem(m_listView, clip);
1287 if (item->data(0, DurationRole).isNull()) item->setData(0, DurationRole, i18n("Loading"));
1288 connect(clip, SIGNAL(createProxy(const QString &)), this, SLOT(slotCreateProxy(const QString &)));
1289 connect(clip, SIGNAL(abortProxy(const QString &, const QString &)), this, SLOT(slotAbortProxy(const QString, const QString)));
1290 if (getProperties) {
1291 int height = m_listView->iconSize().height();
1292 int width = (int)(height * m_render->dar());
1293 QPixmap pix = KIcon("video-x-generic").pixmap(QSize(width, height));
1294 item->setData(0, Qt::DecorationRole, pix);
1295 //item->setFlags(Qt::ItemIsSelectable);
1296 m_listView->processLayout();
1297 QDomElement e = clip->toXML().cloneNode().toElement();
1298 e.removeAttribute("file_hash");
1299 resetThumbsProducer(clip);
1300 m_render->getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true);
1302 // WARNING: code below triggers unnecessary reload of all proxy clips on document loading... is it useful in some cases?
1303 /*else if (item->hasProxy() && !item->isJobRunning()) {
1304 slotCreateProxy(clip->getId());
1307 KUrl url = clip->fileURL();
1309 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk() && clip->getProperty("description").isEmpty()) {
1310 // if file has Nepomuk comment, use it
1311 Nepomuk::Resource f(url.path());
1312 QString annotation = f.description();
1313 if (!annotation.isEmpty()) {
1314 item->setText(1, annotation);
1315 clip->setProperty("description", annotation);
1317 item->setText(2, QString::number(f.rating()));
1321 // Add info to date column
1322 QFileInfo fileInfo(url.path());
1323 if (fileInfo.exists()) {
1324 item->setText(3, fileInfo.lastModified().toString(QString("yyyy/MM/dd hh:mm:ss")));
1328 QList <CutZoneInfo> cuts = clip->cutZones();
1329 if (!cuts.isEmpty()) {
1330 for (int i = 0; i < cuts.count(); i++) {
1331 SubProjectItem *sub = new SubProjectItem(item, cuts.at(i).zone.x(), cuts.at(i).zone.y(), cuts.at(i).description);
1332 if (!clip->getClipHash().isEmpty()) {
1333 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(cuts.at(i).zone.x()) + ".png";
1334 if (QFile::exists(cachedPixmap)) {
1335 QPixmap pix(cachedPixmap);
1337 KIO::NetAccess::del(KUrl(cachedPixmap), this);
1338 sub->setData(0, Qt::DecorationRole, pix);
1343 monitorItemEditing(true);
1347 void ProjectList::slotGotProxy(const QString &proxyPath)
1349 if (proxyPath.isEmpty() || m_abortAllJobs) return;
1350 QTreeWidgetItemIterator it(m_listView);
1353 while (*it && !m_closing) {
1354 if ((*it)->type() == PROJECTCLIPTYPE) {
1355 item = static_cast <ProjectItem *>(*it);
1356 if (item->referencedClip()->getProperty("proxy") == proxyPath)
1363 void ProjectList::slotGotProxyForId(const QString id)
1365 if (m_closing) return;
1366 ProjectItem *item = getItemById(id);
1370 void ProjectList::slotGotProxy(ProjectItem *item)
1372 if (item == NULL) return;
1373 DocClipBase *clip = item->referencedClip();
1374 if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
1375 // Clip is being reprocessed, abort
1376 kDebug()<<"//// TRYING TO PROXY: "<<item->clipId()<<", but it is busy";
1380 // Proxy clip successfully created
1381 QDomElement e = clip->toXML().cloneNode().toElement();
1383 // Make sure we get the correct producer length if it was adjusted in timeline
1384 CLIPTYPE t = item->clipType();
1385 if (t == COLOR || t == IMAGE || t == SLIDESHOW || t == TEXT) {
1386 int length = QString(clip->producerProperty("length")).toInt();
1387 if (length > 0 && !e.hasAttribute("length")) {
1388 e.setAttribute("length", length);
1391 resetThumbsProducer(clip);
1392 m_render->getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true);
1395 void ProjectList::slotResetProjectList()
1397 m_listView->blockSignals(true);
1398 m_abortAllJobs = true;
1399 for (int i = 0; i < m_jobList.count(); i++) {
1400 m_jobList.at(i)->setStatus(JOBABORTED);
1403 m_jobThreads.waitForFinished();
1404 m_jobThreads.clearFutures();
1405 m_thumbnailQueue.clear();
1406 if (!m_jobList.isEmpty()) qDeleteAll(m_jobList);
1408 m_listView->clear();
1409 m_listView->setEnabled(true);
1410 emit clipSelected(NULL);
1411 m_refreshed = false;
1412 m_allClipsProcessed = false;
1413 m_abortAllJobs = false;
1415 m_listView->blockSignals(false);
1418 void ProjectList::slotUpdateClip(const QString &id)
1420 ProjectItem *item = getItemById(id);
1421 monitorItemEditing(false);
1422 if (item) item->setData(0, UsageRole, QString::number(item->numReferences()));
1423 monitorItemEditing(true);
1426 void ProjectList::getCachedThumbnail(ProjectItem *item)
1429 DocClipBase *clip = item->referencedClip();
1431 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
1432 if (QFile::exists(cachedPixmap)) {
1433 QPixmap pix(cachedPixmap);
1435 KIO::NetAccess::del(KUrl(cachedPixmap), this);
1436 requestClipThumbnail(item->clipId());
1439 processThumbOverlays(item, pix);
1440 item->setData(0, Qt::DecorationRole, pix);
1444 requestClipThumbnail(item->clipId());
1448 void ProjectList::getCachedThumbnail(SubProjectItem *item)
1451 ProjectItem *parentItem = static_cast <ProjectItem *>(item->parent());
1452 if (!parentItem) return;
1453 DocClipBase *clip = parentItem->referencedClip();
1455 int pos = item->zone().x();
1456 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + "#" + QString::number(pos) + ".png";
1457 if (QFile::exists(cachedPixmap)) {
1458 QPixmap pix(cachedPixmap);
1460 KIO::NetAccess::del(KUrl(cachedPixmap), this);
1461 requestClipThumbnail(parentItem->clipId() + '#' + QString::number(pos));
1463 else item->setData(0, Qt::DecorationRole, pix);
1465 else requestClipThumbnail(parentItem->clipId() + '#' + QString::number(pos));
1468 void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged, QStringList brokenClips)
1470 if (!m_allClipsProcessed) m_listView->setEnabled(false);
1471 m_listView->setSortingEnabled(false);
1472 QTreeWidgetItemIterator it(m_listView);
1475 monitorItemEditing(false);
1476 int height = m_listView->iconSize().height();
1477 int width = (int)(height * m_render->dar());
1478 QPixmap missingPixmap = QPixmap(width, height);
1479 missingPixmap.fill(Qt::transparent);
1480 KIcon icon("dialog-close");
1481 QPainter p(&missingPixmap);
1482 p.drawPixmap(3, 3, icon.pixmap(width - 6, height - 6));
1485 int max = m_doc->clipManager()->clipsCount();
1490 emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - ct++) / max));
1491 if ((*it)->type() == PROJECTSUBCLIPTYPE) {
1493 SubProjectItem *sub = static_cast <SubProjectItem *>(*it);
1494 if (displayRatioChanged) {
1495 item = static_cast <ProjectItem *>((*it)->parent());
1496 requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x()));
1498 else if (sub->data(0, Qt::DecorationRole).isNull()) {
1499 getCachedThumbnail(sub);
1503 } else if ((*it)->type() == PROJECTFOLDERTYPE) {
1508 item = static_cast <ProjectItem *>(*it);
1509 clip = item->referencedClip();
1510 if (clip->getProducer() == NULL) {
1511 bool replace = false;
1512 if (brokenClips.contains(item->clipId())) {
1513 // if this is a proxy clip, disable proxy
1514 item->setConditionalJobStatus(NOJOB, PROXYJOB);
1515 discardJobs(item->clipId(), PROXYJOB);
1516 clip->setProperty("proxy", "-");
1519 if (clip->isPlaceHolder() == false && !hasPendingJob(item, PROXYJOB)) {
1520 QDomElement xml = clip->toXML();
1522 xml.removeAttribute("out");
1523 xml.removeAttribute("file_hash");
1524 xml.removeAttribute("proxy_out");
1526 if (!replace) replace = xml.attribute("_replaceproxy") == "1";
1527 xml.removeAttribute("_replaceproxy");
1529 resetThumbsProducer(clip);
1531 m_render->getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), replace);
1533 else if (clip->isPlaceHolder()) {
1534 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
1535 if (item->data(0, Qt::DecorationRole).isNull()) {
1536 item->setData(0, Qt::DecorationRole, missingPixmap);
1539 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
1540 QPainter p(&pixmap);
1541 p.drawPixmap(3, 3, KIcon("dialog-close").pixmap(pixmap.width() - 6, pixmap.height() - 6));
1543 item->setData(0, Qt::DecorationRole, pixmap);
1547 if (displayRatioChanged) {
1548 requestClipThumbnail(clip->getId());
1550 else if (item->data(0, Qt::DecorationRole).isNull()) {
1551 getCachedThumbnail(item);
1553 if (item->data(0, DurationRole).toString().isEmpty()) {
1554 item->changeDuration(clip->getProducer()->get_playtime());
1556 if (clip->isPlaceHolder()) {
1557 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
1558 if (pixmap.isNull()) {
1559 pixmap = QPixmap(width, height);
1560 pixmap.fill(Qt::transparent);
1562 QPainter p(&pixmap);
1563 p.drawPixmap(3, 3, KIcon("dialog-close").pixmap(pixmap.width() - 6, pixmap.height() - 6));
1565 item->setData(0, Qt::DecorationRole, pixmap);
1567 else if (clip->getProperty("_replaceproxy") == "1") {
1568 clip->setProperty("_replaceproxy", QString());
1569 slotCreateProxy(clip->getId());
1572 item->setData(0, UsageRole, QString::number(item->numReferences()));
1577 m_listView->setSortingEnabled(true);
1578 m_allClipsProcessed = true;
1579 if (m_render->processingItems() == 0) {
1580 monitorItemEditing(true);
1581 slotProcessNextThumbnail();
1586 QString ProjectList::getExtensions()
1588 // Build list of mime types
1589 QStringList mimeTypes = QStringList() << "application/x-kdenlive" << "application/x-kdenlivetitle" << "video/mlt-playlist" << "text/plain"
1590 << "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"
1591 << "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"
1592 << "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";
1594 QString allExtensions;
1595 foreach(const QString & mimeType, mimeTypes) {
1596 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
1598 allExtensions.append(mime->patterns().join(" "));
1599 allExtensions.append(' ');
1602 return allExtensions.simplified();
1605 void ProjectList::slotAddClip(const QString url, const QString &groupName, const QString &groupId)
1607 kDebug()<<"// Adding clip: "<<url;
1610 slotAddClip(list, groupName, groupId);
1613 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
1615 if (!m_commandStack)
1616 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1619 if (givenList.isEmpty()) {
1620 QString allExtensions = getExtensions();
1621 const QString dialogFilter = allExtensions + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
1622 QCheckBox *b = new QCheckBox(i18n("Import image sequence"));
1623 b->setChecked(KdenliveSettings::autoimagesequence());
1624 QCheckBox *c = new QCheckBox(i18n("Transparent background for images"));
1625 c->setChecked(KdenliveSettings::autoimagetransparency());
1626 QFrame *f = new QFrame;
1627 f->setFrameShape(QFrame::NoFrame);
1628 QHBoxLayout *l = new QHBoxLayout;
1633 KFileDialog *d = new KFileDialog(KUrl("kfiledialog:///clipfolder"), dialogFilter, kapp->activeWindow(), f);
1634 d->setOperationMode(KFileDialog::Opening);
1635 d->setMode(KFile::Files);
1636 if (d->exec() == QDialog::Accepted) {
1637 KdenliveSettings::setAutoimagetransparency(c->isChecked());
1639 list = d->selectedUrls();
1640 if (b->isChecked() && list.count() == 1) {
1641 // Check for image sequence
1642 KUrl url = list.at(0);
1643 QString fileName = url.fileName().section('.', 0, -2);
1644 if (fileName.at(fileName.size() - 1).isDigit()) {
1645 KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
1646 if (item.mimetype().startsWith("image")) {
1647 // import as sequence if we found more than one image in the sequence
1649 QString pattern = SlideshowClip::selectedPath(url.path(), false, QString(), &list);
1650 int count = list.count();
1653 QStringList groupInfo = getGroup();
1655 // get image sequence base name
1656 while (fileName.at(fileName.size() - 1).isDigit()) {
1660 m_doc->slotCreateSlideshowClipFile(fileName, pattern, count, m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()),
1661 false, false, false,
1662 m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))), QString(), 0,
1663 QString(), groupInfo.at(0), groupInfo.at(1));
1671 for (int i = 0; i < givenList.count(); i++)
1672 list << givenList.at(i);
1674 QList <KUrl::List> foldersList;
1676 foreach(const KUrl & file, list) {
1677 // Check there is no folder here
1678 KMimeType::Ptr type = KMimeType::findByUrl(file);
1679 if (type->is("inode/directory")) {
1680 // user dropped a folder, import its files
1681 list.removeAll(file);
1682 QDir dir(file.path());
1683 QStringList result = dir.entryList(QDir::Files);
1684 KUrl::List folderFiles;
1685 folderFiles << file;
1686 foreach(const QString & path, result) {
1687 KUrl newFile = file;
1688 newFile.addPath(path);
1689 folderFiles.append(newFile);
1691 if (folderFiles.count() > 1) foldersList.append(folderFiles);
1695 if (givenList.isEmpty() && !list.isEmpty()) {
1696 QStringList groupInfo = getGroup();
1697 m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1));
1698 } else if (!list.isEmpty()) {
1699 m_doc->slotAddClipList(list, groupName, groupId);
1702 if (!foldersList.isEmpty()) {
1704 for (int i = 0; i < foldersList.count(); i++) {
1705 KUrl::List urls = foldersList.at(i);
1706 KUrl folderUrl = urls.takeFirst();
1707 QString folderName = folderUrl.fileName();
1708 FolderProjectItem *folder = NULL;
1709 if (!folderName.isEmpty()) {
1710 folder = getFolderItemByName(folderName);
1711 if (folder == NULL) {
1712 slotAddFolder(folderName);
1713 folder = getFolderItemByName(folderName);
1717 m_doc->slotAddClipList(urls, folder->groupName(), folder->clipId());
1718 else m_doc->slotAddClipList(urls);
1723 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
1725 ProjectItem *item = getItemById(id);
1726 m_thumbnailQueue.removeAll(id);
1728 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1729 const QString path = item->referencedClip()->fileURL().path();
1730 if (item->referencedClip()->isPlaceHolder()) replace = false;
1731 if (!path.isEmpty()) {
1732 if (m_invalidClipDialog) {
1733 m_invalidClipDialog->addClip(id, path);
1738 m_invalidClipDialog = new InvalidDialog(i18n("Invalid clip"), i18n("Clip <b>%1</b><br />is invalid, will be removed from project.", QString()), replace, kapp->activeWindow());
1740 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());
1742 m_invalidClipDialog->addClip(id, path);
1743 int result = m_invalidClipDialog->exec();
1744 if (result == KDialog::Yes) replace = true;
1747 if (m_invalidClipDialog) {
1749 emit deleteProjectClips(m_invalidClipDialog->getIds(), QMap <QString, QString>());
1750 delete m_invalidClipDialog;
1751 m_invalidClipDialog = NULL;
1757 void ProjectList::slotRemoveInvalidProxy(const QString &id, bool durationError)
1759 ProjectItem *item = getItemById(id);
1761 kDebug()<<"// Proxy for clip "<<id<<" is invalid, delete";
1762 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1763 if (durationError) {
1764 kDebug() << "Proxy duration is wrong, try changing transcoding parameters.";
1765 emit displayMessage(i18n("Proxy clip unusable (duration is different from original)."), -2);
1767 slotUpdateJobStatus(item, PROXYJOB, JOBCRASHED, i18n("Failed to create proxy for %1. check parameters", item->text(0)), "project_settings");
1768 QString path = item->referencedClip()->getProperty("proxy");
1769 KUrl proxyFolder(m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/");
1771 //Security check: make sure the invalid proxy file is in the proxy folder
1772 if (proxyFolder.isParentOf(KUrl(path))) {
1773 QFile::remove(path);
1775 if (item->referencedClip()->getProducer() == NULL) {
1776 // Clip has no valid producer, request it
1777 slotProxyCurrentItem(false, item);
1780 // refresh thumbs producer
1781 item->referencedClip()->reloadThumbProducer();
1784 m_thumbnailQueue.removeAll(id);
1787 void ProjectList::slotAddColorClip()
1789 if (!m_commandStack)
1790 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1792 QDialog *dia = new QDialog(this);
1793 Ui::ColorClip_UI dia_ui;
1794 dia_ui.setupUi(dia);
1795 dia->setWindowTitle(i18n("Color Clip"));
1796 dia_ui.clip_name->setText(i18n("Color Clip"));
1798 TimecodeDisplay *t = new TimecodeDisplay(m_timecode);
1799 t->setValue(KdenliveSettings::color_duration());
1800 dia_ui.clip_durationBox->addWidget(t);
1801 dia_ui.clip_color->setColor(KdenliveSettings::colorclipcolor());
1803 if (dia->exec() == QDialog::Accepted) {
1804 QString color = dia_ui.clip_color->color().name();
1805 KdenliveSettings::setColorclipcolor(color);
1806 color = color.replace(0, 1, "0x") + "ff";
1807 QStringList groupInfo = getGroup();
1808 m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, m_timecode.getTimecode(t->gentime()), groupInfo.at(0), groupInfo.at(1));
1815 void ProjectList::slotAddSlideshowClip()
1817 if (!m_commandStack)
1818 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1820 SlideshowClip *dia = new SlideshowClip(m_timecode, this);
1822 if (dia->exec() == QDialog::Accepted) {
1823 QStringList groupInfo = getGroup();
1824 m_doc->slotCreateSlideshowClipFile(dia->clipName(), dia->selectedPath(), dia->imageCount(), dia->clipDuration(),
1825 dia->loop(), dia->crop(), dia->fade(),
1826 dia->lumaDuration(), dia->lumaFile(), dia->softness(),
1827 dia->animation(), groupInfo.at(0), groupInfo.at(1));
1832 void ProjectList::slotAddTitleClip()
1834 QStringList groupInfo = getGroup();
1835 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
1838 void ProjectList::slotAddTitleTemplateClip()
1840 if (!m_commandStack)
1841 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1843 QStringList groupInfo = getGroup();
1845 // Get the list of existing templates
1847 filter << "*.kdenlivetitle";
1848 const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
1849 QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
1851 QDialog *dia = new QDialog(this);
1852 Ui::TemplateClip_UI dia_ui;
1853 dia_ui.setupUi(dia);
1854 for (int i = 0; i < templateFiles.size(); ++i)
1855 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
1857 if (!templateFiles.isEmpty())
1858 dia_ui.buttonBox->button(QDialogButtonBox::Ok)->setFocus();
1859 dia_ui.template_list->fileDialog()->setFilter("application/x-kdenlivetitle");
1860 //warning: setting base directory doesn't work??
1861 KUrl startDir(path);
1862 dia_ui.template_list->fileDialog()->setUrl(startDir);
1863 dia_ui.text_box->setHidden(true);
1864 if (dia->exec() == QDialog::Accepted) {
1865 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
1866 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
1867 // Create a cloned template clip
1868 m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
1873 QStringList ProjectList::getGroup() const
1876 QTreeWidgetItem *item = m_listView->currentItem();
1877 while (item && item->type() != PROJECTFOLDERTYPE)
1878 item = item->parent();
1881 FolderProjectItem *folder = static_cast <FolderProjectItem *>(item);
1882 result << folder->groupName() << folder->clipId();
1884 result << QString() << QString();
1889 void ProjectList::setDocument(KdenliveDoc *doc)
1891 m_listView->blockSignals(true);
1892 m_abortAllJobs = true;
1893 for (int i = 0; i < m_jobList.count(); i++) {
1894 m_jobList.at(i)->setStatus(JOBABORTED);
1897 m_jobThreads.waitForFinished();
1898 m_jobThreads.clearFutures();
1899 m_thumbnailQueue.clear();
1900 m_listView->clear();
1902 m_listView->setSortingEnabled(false);
1903 emit clipSelected(NULL);
1904 m_refreshed = false;
1905 m_allClipsProcessed = false;
1907 m_timecode = doc->timecode();
1908 m_commandStack = doc->commandStack();
1910 m_abortAllJobs = false;
1913 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
1914 QStringList openedFolders = doc->getExpandedFolders();
1915 QMapIterator<QString, QString> f(flist);
1916 while (f.hasNext()) {
1918 FolderProjectItem *folder = new FolderProjectItem(m_listView, QStringList() << f.value(), f.key());
1919 folder->setExpanded(openedFolders.contains(f.key()));
1922 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
1923 if (list.isEmpty()) {
1926 m_allClipsProcessed = true;
1928 for (int i = 0; i < list.count(); i++)
1929 slotAddClip(list.at(i), false);
1931 m_listView->blockSignals(false);
1932 connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
1933 connect(m_doc->clipManager(), SIGNAL(modifiedClip(const QString &)), this, SLOT(slotModifiedClip(const QString &)));
1934 connect(m_doc->clipManager(), SIGNAL(missingClip(const QString &)), this, SLOT(slotMissingClip(const QString &)));
1935 connect(m_doc->clipManager(), SIGNAL(availableClip(const QString &)), this, SLOT(slotAvailableClip(const QString &)));
1936 connect(m_doc->clipManager(), SIGNAL(checkAllClips(bool, bool, QStringList)), this, SLOT(updateAllClips(bool, bool, QStringList)));
1939 QList <DocClipBase*> ProjectList::documentClipList() const
1942 return QList <DocClipBase*> ();
1944 return m_doc->clipManager()->documentClipList();
1947 QDomElement ProjectList::producersList()
1950 QDomElement prods = doc.createElement("producerlist");
1951 doc.appendChild(prods);
1952 QTreeWidgetItemIterator it(m_listView);
1954 if ((*it)->type() != PROJECTCLIPTYPE) {
1959 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
1965 void ProjectList::slotCheckForEmptyQueue()
1967 if (m_render->processingItems() == 0 && m_thumbnailQueue.isEmpty()) {
1968 if (!m_refreshed && m_allClipsProcessed) {
1970 m_listView->setEnabled(true);
1972 QTimer::singleShot(500, this, SIGNAL(loadingIsOver()));
1973 emit displayMessage(QString(), -1);
1976 } else if (!m_refreshed) {
1977 QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
1982 void ProjectList::requestClipThumbnail(const QString id)
1984 if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id);
1985 slotProcessNextThumbnail();
1988 void ProjectList::resetThumbsProducer(DocClipBase *clip)
1991 clip->clearThumbProducer();
1992 QString id = clip->getId();
1993 m_thumbnailQueue.removeAll(id);
1996 void ProjectList::slotProcessNextThumbnail()
1998 if (m_render->processingItems() > 0) {
2001 if (m_thumbnailQueue.isEmpty()) {
2002 slotCheckForEmptyQueue();
2005 int max = m_doc->clipManager()->clipsCount();
2006 emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - m_thumbnailQueue.count()) / max));
2007 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
2010 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
2012 QTreeWidgetItem *item = getAnyItemById(clipId);
2014 slotRefreshClipThumbnail(item, update);
2016 slotProcessNextThumbnail();
2020 void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
2022 if (it == NULL) return;
2023 ProjectItem *item = NULL;
2024 bool isSubItem = false;
2026 if (it->type() == PROJECTFOLDERTYPE) return;
2027 if (it->type() == PROJECTSUBCLIPTYPE) {
2028 item = static_cast <ProjectItem *>(it->parent());
2029 frame = static_cast <SubProjectItem *>(it)->zone().x();
2032 item = static_cast <ProjectItem *>(it);
2033 frame = item->referencedClip()->getClipThumbFrame();
2037 DocClipBase *clip = item->referencedClip();
2039 slotProcessNextThumbnail();
2044 int height = m_listView->iconSize().height();
2045 int swidth = (int)(height * m_render->frameRenderWidth() / m_render->renderHeight()+ 0.5);
2046 int dwidth = (int)(height * m_render->dar() + 0.5);
2047 if (clip->clipType() == AUDIO)
2048 pix = KIcon("audio-x-generic").pixmap(QSize(dwidth, height));
2049 else if (clip->clipType() == IMAGE)
2050 img = KThumb::getFrame(item->referencedClip()->getProducer(), 0, swidth, dwidth, height);
2052 img = item->referencedClip()->extractImage(frame, dwidth, height);
2055 if (!pix.isNull() || !img.isNull()) {
2056 monitorItemEditing(false);
2057 if (!img.isNull()) {
2058 pix = QPixmap::fromImage(img);
2059 processThumbOverlays(item, pix);
2061 it->setData(0, Qt::DecorationRole, pix);
2062 monitorItemEditing(true);
2064 QString hash = item->getClipHash();
2065 if (!hash.isEmpty() && !img.isNull()) {
2067 m_doc->cacheImage(hash, img);
2069 m_doc->cacheImage(hash + '#' + QString::number(frame), img);
2073 emit projectModified();
2074 slotProcessNextThumbnail();
2079 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const stringMap &properties, const stringMap &metadata, bool replace)
2082 ProjectItem *item = getItemById(clipId);
2083 int queue = m_render->processingItems();
2084 if (item && producer) {
2085 monitorItemEditing(false);
2086 DocClipBase *clip = item->referencedClip();
2087 if (producer->is_valid()) {
2088 if (clip->isPlaceHolder()) {
2092 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
2094 item->setProperties(properties, metadata);
2095 clip->setProducer(producer, replace);
2098 QString size = properties.value("frame_size");
2099 if (!useProxy() && clip->getProperty("proxy").isEmpty()) {
2100 item->setConditionalJobStatus(NOJOB, PROXYJOB);
2101 discardJobs(clipId, PROXYJOB);
2103 if (useProxy() && generateProxy() && clip->getProperty("proxy") == "-") {
2104 item->setConditionalJobStatus(NOJOB, PROXYJOB);
2105 discardJobs(clipId, PROXYJOB);
2107 else if (useProxy() && !item->hasProxy() && !hasPendingJob(item, PROXYJOB)) {
2108 // proxy video and image clips
2110 CLIPTYPE t = item->clipType();
2111 if (t == IMAGE) maxSize = m_doc->getDocumentProperty("proxyimageminsize").toInt();
2112 else maxSize = m_doc->getDocumentProperty("proxyminsize").toInt();
2113 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)) {
2114 if (clip->getProperty("proxy").isEmpty()) {
2115 KUrl proxyPath = m_doc->projectFolder();
2116 proxyPath.addPath("proxy/");
2117 proxyPath.addPath(clip->getClipHash() + "." + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension")));
2118 QMap <QString, QString> newProps;
2119 // insert required duration for proxy
2120 if (t != IMAGE) newProps.insert("proxy_out", clip->producerProperty("out"));
2121 newProps.insert("proxy", proxyPath.path());
2122 QMap <QString, QString> oldProps = clip->properties();
2123 oldProps.insert("proxy", QString());
2124 EditClipCommand *command = new EditClipCommand(this, clipId, oldProps, newProps, true);
2125 m_doc->commandStack()->push(command);
2130 if (!replace && m_allClipsProcessed && item->data(0, Qt::DecorationRole).isNull()) {
2131 getCachedThumbnail(item);
2133 if (!toReload.isEmpty())
2134 item->slotSetToolTip();
2135 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
2137 monitorItemEditing(true);
2138 if (item && m_thumbnailQueue.isEmpty()) {
2139 if (!item->hasProxy() || m_render->activeClipId() == item->clipId())
2140 m_listView->setCurrentItem(item);
2141 bool updatedProfile = false;
2142 if (item->parent()) {
2143 if (item->parent()->type() == PROJECTFOLDERTYPE)
2144 static_cast <FolderProjectItem *>(item->parent())->switchIcon();
2145 } else if (KdenliveSettings::checkfirstprojectclip() && m_listView->topLevelItemCount() == 1 && m_refreshed && m_allClipsProcessed) {
2146 // this is the first clip loaded in project, check if we want to adjust project settings to the clip
2147 updatedProfile = adjustProjectProfileToItem(item);
2149 if (updatedProfile == false) {
2150 //emit clipSelected(item->referencedClip());
2153 int max = m_doc->clipManager()->clipsCount();
2154 if (max > 0) emit displayMessage(i18n("Loading clips"), (int)(100 *(max - queue) / max));
2156 if (m_allClipsProcessed) emit processNextThumbnail();
2159 // no item for producer, delete it
2163 if (replace) toReload = clipId;
2164 if (!toReload.isEmpty())
2165 emit clipNeedsReload(toReload);
2168 bool ProjectList::adjustProjectProfileToItem(ProjectItem *item)
2171 if (m_listView->currentItem() && m_listView->currentItem()->type() != PROJECTFOLDERTYPE)
2172 item = static_cast <ProjectItem*>(m_listView->currentItem());
2174 if (item == NULL || item->referencedClip() == NULL) {
2175 KMessageBox::information(kapp->activeWindow(), i18n("Cannot find profile from current clip"));
2178 bool profileUpdated = false;
2179 QString size = item->referencedClip()->getProperty("frame_size");
2180 int width = size.section('x', 0, 0).toInt();
2181 int height = size.section('x', -1).toInt();
2182 // Fix some avchd clips tht report a wrong size (1920x1088)
2183 if (height == 1088) height = 1080;
2184 double fps = item->referencedClip()->getProperty("fps").toDouble();
2185 double par = item->referencedClip()->getProperty("aspect_ratio").toDouble();
2186 if (item->clipType() == IMAGE || item->clipType() == AV || item->clipType() == VIDEO) {
2187 if (ProfilesDialog::matchProfile(width, height, fps, par, item->clipType() == IMAGE, m_doc->mltProfile()) == false) {
2188 // get a list of compatible profiles
2189 QMap <QString, QString> suggestedProfiles = ProfilesDialog::getProfilesFromProperties(width, height, fps, par, item->clipType() == IMAGE);
2190 if (!suggestedProfiles.isEmpty()) {
2191 KDialog *dialog = new KDialog(this);
2192 dialog->setCaption(i18n("Change project profile"));
2193 dialog->setButtons(KDialog::Ok | KDialog::Cancel);
2196 QVBoxLayout *l = new QVBoxLayout;
2197 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));
2198 l->addWidget(label);
2199 QListWidget *list = new QListWidget;
2200 list->setAlternatingRowColors(true);
2201 QMapIterator<QString, QString> i(suggestedProfiles);
2202 while (i.hasNext()) {
2204 QListWidgetItem *item = new QListWidgetItem(i.value(), list);
2205 item->setData(Qt::UserRole, i.key());
2206 item->setToolTip(i.key());
2208 list->setCurrentRow(0);
2210 container.setLayout(l);
2211 dialog->setButtonText(KDialog::Ok, i18n("Update profile"));
2212 dialog->setMainWidget(&container);
2213 if (dialog->exec() == QDialog::Accepted) {
2214 //Change project profile
2215 profileUpdated = true;
2216 if (list->currentItem())
2217 emit updateProfile(list->currentItem()->data(Qt::UserRole).toString());
2221 } else if (fps > 0) {
2222 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));
2226 return profileUpdated;
2229 QString ProjectList::getDocumentProperty(const QString &key) const
2231 return m_doc->getDocumentProperty(key);
2234 bool ProjectList::useProxy() const
2236 return m_doc->getDocumentProperty("enableproxy").toInt();
2239 bool ProjectList::generateProxy() const
2241 return m_doc->getDocumentProperty("generateproxy").toInt();
2244 bool ProjectList::generateImageProxy() const
2246 return m_doc->getDocumentProperty("generateimageproxy").toInt();
2249 void ProjectList::slotReplyGetImage(const QString &clipId, const QImage &img)
2251 ProjectItem *item = getItemById(clipId);
2252 if (item && !img.isNull()) {
2253 QPixmap pix = QPixmap::fromImage(img);
2254 processThumbOverlays(item, pix);
2255 monitorItemEditing(false);
2256 item->setData(0, Qt::DecorationRole, pix);
2257 monitorItemEditing(true);
2258 QString hash = item->getClipHash();
2259 if (!hash.isEmpty()) m_doc->cacheImage(hash, img);
2263 void ProjectList::slotReplyGetImage(const QString &clipId, const QString &name, int width, int height)
2265 // For clips that have a generic icon (like audio clips...)
2266 ProjectItem *item = getItemById(clipId);
2267 QPixmap pix = KIcon(name).pixmap(QSize(width, height));
2268 if (item && !pix.isNull()) {
2269 monitorItemEditing(false);
2270 item->setData(0, Qt::DecorationRole, pix);
2271 monitorItemEditing(true);
2275 QTreeWidgetItem *ProjectList::getAnyItemById(const QString &id)
2277 QTreeWidgetItemIterator it(m_listView);
2278 QString lookId = id;
2279 if (id.contains('#'))
2280 lookId = id.section('#', 0, 0);
2282 ProjectItem *result = NULL;
2284 if ((*it)->type() != PROJECTCLIPTYPE) {
2289 ProjectItem *item = static_cast<ProjectItem *>(*it);
2290 if (item->clipId() == lookId) {
2296 if (result == NULL || !id.contains('#')) {
2299 for (int i = 0; i < result->childCount(); i++) {
2300 SubProjectItem *sub = static_cast <SubProjectItem *>(result->child(i));
2301 if (sub && sub->zone().x() == id.section('#', 1, 1).toInt())
2310 ProjectItem *ProjectList::getItemById(const QString &id)
2313 QTreeWidgetItemIterator it(m_listView);
2315 if ((*it)->type() != PROJECTCLIPTYPE) {
2316 // subitem or folder
2320 item = static_cast<ProjectItem *>(*it);
2321 if (item->clipId() == id)
2328 FolderProjectItem *ProjectList::getFolderItemByName(const QString &name)
2330 FolderProjectItem *item = NULL;
2331 QList <QTreeWidgetItem *> hits = m_listView->findItems(name, Qt::MatchExactly, 0);
2332 for (int i = 0; i < hits.count(); i++) {
2333 if (hits.at(i)->type() == PROJECTFOLDERTYPE) {
2334 item = static_cast<FolderProjectItem *>(hits.at(i));
2341 FolderProjectItem *ProjectList::getFolderItemById(const QString &id)
2343 FolderProjectItem *item;
2344 QTreeWidgetItemIterator it(m_listView);
2346 if ((*it)->type() == PROJECTFOLDERTYPE) {
2347 item = static_cast<FolderProjectItem *>(*it);
2348 if (item->clipId() == id)
2356 void ProjectList::slotSelectClip(const QString &ix)
2358 ProjectItem *clip = getItemById(ix);
2360 m_listView->setCurrentItem(clip);
2361 m_listView->scrollToItem(clip);
2362 m_editButton->defaultAction()->setEnabled(true);
2363 m_deleteButton->defaultAction()->setEnabled(true);
2364 m_reloadAction->setEnabled(true);
2365 m_extractAudioAction->setEnabled(true);
2366 m_transcodeAction->setEnabled(true);
2367 m_stabilizeAction->setEnabled(true);
2368 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
2369 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
2370 m_openAction->setEnabled(true);
2371 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
2372 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
2373 m_openAction->setEnabled(true);
2375 m_openAction->setEnabled(false);
2380 QString ProjectList::currentClipUrl() const
2383 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return QString();
2384 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
2386 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
2388 item = static_cast <ProjectItem*>(m_listView->currentItem());
2392 return item->clipUrl().path();
2395 KUrl::List ProjectList::getConditionalUrls(const QString &condition) const
2399 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
2400 for (int i = 0; i < list.count(); i++) {
2401 if (list.at(i)->type() == PROJECTFOLDERTYPE)
2403 if (list.at(i)->type() == PROJECTSUBCLIPTYPE) {
2405 item = static_cast <ProjectItem*>(list.at(i)->parent());
2407 item = static_cast <ProjectItem*>(list.at(i));
2409 if (item == NULL || item->type() == COLOR || item->type() == SLIDESHOW || item->type() == TEXT)
2411 DocClipBase *clip = item->referencedClip();
2412 if (!condition.isEmpty()) {
2413 if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section('=', 1, 1)))
2415 else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section('=', 1, 1)))
2418 result.append(item->clipUrl());
2423 QStringList ProjectList::getConditionalIds(const QString &condition) const
2427 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
2428 for (int i = 0; i < list.count(); i++) {
2429 if (list.at(i)->type() == PROJECTFOLDERTYPE)
2431 if (list.at(i)->type() == PROJECTSUBCLIPTYPE) {
2433 item = static_cast <ProjectItem*>(list.at(i)->parent());
2435 item = static_cast <ProjectItem*>(list.at(i));
2437 if (item == NULL || item->type() == COLOR || item->type() == SLIDESHOW || item->type() == TEXT)
2439 DocClipBase *clip = item->referencedClip();
2440 if (!condition.isEmpty()) {
2441 if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section('=', 1, 1)))
2443 else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section('=', 1, 1)))
2446 result.append(item->clipId());
2451 void ProjectList::regenerateTemplate(const QString &id)
2453 ProjectItem *clip = getItemById(id);
2455 regenerateTemplate(clip);
2458 void ProjectList::regenerateTemplate(ProjectItem *clip)
2460 //TODO: remove this unused method, only force_reload is necessary
2461 clip->referencedClip()->getProducer()->set("force_reload", 1);
2464 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
2468 if (!file.open(QIODevice::ReadOnly)) {
2469 kWarning() << "ERROR, CANNOT READ: " << path;
2472 if (!doc.setContent(&file)) {
2473 kWarning() << "ERROR, CANNOT READ: " << path;
2478 QDomNodeList texts = doc.elementsByTagName("content");
2479 for (int i = 0; i < texts.count(); i++) {
2480 QString data = texts.item(i).firstChild().nodeValue();
2481 data.replace("%s", replaceString);
2482 texts.item(i).firstChild().setNodeValue(data);
2488 void ProjectList::slotAddClipCut(const QString &id, int in, int out)
2490 ProjectItem *clip = getItemById(id);
2491 if (clip == NULL || clip->referencedClip()->hasCutZone(QPoint(in, out)))
2493 AddClipCutCommand *command = new AddClipCutCommand(this, id, in, out, QString(), true, false);
2494 m_commandStack->push(command);
2497 void ProjectList::addClipCut(const QString &id, int in, int out, const QString desc, bool newItem)
2499 ProjectItem *clip = getItemById(id);
2501 DocClipBase *base = clip->referencedClip();
2502 base->addCutZone(in, out);
2503 monitorItemEditing(false);
2504 SubProjectItem *sub = new SubProjectItem(clip, in, out, desc);
2505 if (newItem && desc.isEmpty() && !m_listView->isColumnHidden(1)) {
2506 if (!clip->isExpanded())
2507 clip->setExpanded(true);
2508 m_listView->scrollToItem(sub);
2509 m_listView->editItem(sub, 1);
2511 QImage img = clip->referencedClip()->extractImage(in, (int)(sub->sizeHint(0).height() * m_render->dar()), sub->sizeHint(0).height() - 2);
2512 sub->setData(0, Qt::DecorationRole, QPixmap::fromImage(img));
2513 QString hash = clip->getClipHash();
2514 if (!hash.isEmpty()) m_doc->cacheImage(hash + '#' + QString::number(in), img);
2515 monitorItemEditing(true);
2517 emit projectModified();
2520 void ProjectList::removeClipCut(const QString &id, int in, int out)
2522 ProjectItem *clip = getItemById(id);
2524 DocClipBase *base = clip->referencedClip();
2525 base->removeCutZone(in, out);
2526 SubProjectItem *sub = getSubItem(clip, QPoint(in, out));
2528 monitorItemEditing(false);
2530 monitorItemEditing(true);
2533 emit projectModified();
2536 SubProjectItem *ProjectList::getSubItem(ProjectItem *clip, QPoint zone)
2538 SubProjectItem *sub = NULL;
2540 for (int i = 0; i < clip->childCount(); i++) {
2541 QTreeWidgetItem *it = clip->child(i);
2542 if (it->type() == PROJECTSUBCLIPTYPE) {
2543 sub = static_cast <SubProjectItem*>(it);
2544 if (sub->zone() == zone)
2554 void ProjectList::slotUpdateClipCut(QPoint p)
2556 if (!m_listView->currentItem() || m_listView->currentItem()->type() != PROJECTSUBCLIPTYPE)
2558 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
2559 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
2560 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), p, sub->text(1), sub->text(1), true);
2561 m_commandStack->push(command);
2564 void ProjectList::doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment)
2566 ProjectItem *clip = getItemById(id);
2567 SubProjectItem *sub = getSubItem(clip, oldzone);
2568 if (sub == NULL || clip == NULL)
2570 DocClipBase *base = clip->referencedClip();
2571 base->updateCutZone(oldzone.x(), oldzone.y(), zone.x(), zone.y(), comment);
2572 monitorItemEditing(false);
2574 sub->setDescription(comment);
2575 monitorItemEditing(true);
2576 emit projectModified();
2579 void ProjectList::slotForceProcessing(const QString &id)
2581 m_render->forceProcessing(id);
2584 void ProjectList::slotAddOrUpdateSequence(const QString frameName)
2586 QString fileName = KUrl(frameName).fileName().section('_', 0, -2);
2588 QString pattern = SlideshowClip::selectedPath(frameName, false, QString(), &list);
2589 int count = list.count();
2591 const QList <DocClipBase *> existing = m_doc->clipManager()->getClipByResource(pattern);
2592 if (!existing.isEmpty()) {
2593 // Sequence already exists, update
2594 QString id = existing.at(0)->getId();
2595 //ProjectItem *item = getItemById(id);
2596 QMap <QString, QString> oldprops;
2597 QMap <QString, QString> newprops;
2598 int ttl = existing.at(0)->getProperty("ttl").toInt();
2599 oldprops["out"] = existing.at(0)->getProperty("out");
2600 newprops["out"] = QString::number(ttl * count - 1);
2601 slotUpdateClipProperties(id, newprops);
2602 EditClipCommand *command = new EditClipCommand(this, id, oldprops, newprops, false);
2603 m_commandStack->push(command);
2606 QStringList groupInfo = getGroup();
2607 m_doc->slotCreateSlideshowClipFile(fileName, pattern, count, m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()),
2608 false, false, false,
2609 m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))), QString(), 0,
2610 QString(), groupInfo.at(0), groupInfo.at(1));
2612 } else emit displayMessage(i18n("Sequence not found"), -2);
2615 QMap <QString, QString> ProjectList::getProxies()
2617 QMap <QString, QString> list;
2619 QTreeWidgetItemIterator it(m_listView);
2621 if ((*it)->type() != PROJECTCLIPTYPE) {
2625 item = static_cast<ProjectItem *>(*it);
2626 if (item && item->referencedClip() != NULL) {
2627 if (item->hasProxy()) {
2628 QString proxy = item->referencedClip()->getProperty("proxy");
2629 list.insert(proxy, item->clipUrl().path());
2637 void ProjectList::slotCreateProxy(const QString id)
2639 ProjectItem *item = getItemById(id);
2640 if (!item || hasPendingJob(item, PROXYJOB) || item->referencedClip()->isPlaceHolder()) return;
2641 QString path = item->referencedClip()->getProperty("proxy");
2642 if (path.isEmpty()) {
2643 slotUpdateJobStatus(item, PROXYJOB, JOBCRASHED, i18n("Failed to create proxy, empty path."));
2647 if (QFileInfo(path).size() > 0) {
2648 // Proxy already created
2649 setJobStatus(item, PROXYJOB, JOBDONE);
2654 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()));
2655 if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
2660 m_jobList.append(job);
2661 setJobStatus(item, job->jobType, JOBWAITING, 0, job->statusMessage());
2662 slotCheckJobProcess();
2665 void ProjectList::slotCutClipJob(const QString &id, QPoint zone)
2667 ProjectItem *item = getItemById(id);
2668 if (!item|| item->referencedClip()->isPlaceHolder()) return;
2669 QString source = item->clipUrl().path();
2670 QString ext = source.section('.', -1);
2671 QString dest = source.section('.', 0, -2) + "_" + QString::number(zone.x()) + "." + ext;
2673 double clipFps = item->referencedClip()->getProperty("fps").toDouble();
2674 if (clipFps == 0) clipFps = m_fps;
2675 // if clip and project have different frame rate, adjust in and out
2678 in = GenTime(in, m_timecode.fps()).frames(clipFps);
2679 out = GenTime(out, m_timecode.fps()).frames(clipFps);
2680 int max = GenTime(item->clipMaxDuration(), m_timecode.fps()).frames(clipFps);
2681 int duration = out - in + 1;
2682 QString timeIn = Timecode::getStringTimecode(in, clipFps, true);
2683 QString timeOut = Timecode::getStringTimecode(duration, clipFps, true);
2685 QDialog *d = new QDialog(this);
2686 Ui::CutJobDialog_UI ui;
2688 ui.extra_params->setVisible(false);
2689 ui.add_clip->setChecked(KdenliveSettings::add_clip_cut());
2690 ui.file_url->fileDialog()->setOperationMode(KFileDialog::Saving);
2691 ui.extra_params->setMaximumHeight(QFontMetrics(font()).lineSpacing() * 5);
2692 ui.file_url->setUrl(KUrl(dest));
2693 ui.button_more->setIcon(KIcon("configure"));
2694 ui.extra_params->setPlainText("-acodec copy -vcodec copy");
2695 QString mess = i18n("Extracting %1 out of %2", timeOut, Timecode::getStringTimecode(max, clipFps, true));
2696 ui.info_label->setText(mess);
2697 if (d->exec() != QDialog::Accepted) {
2701 dest = ui.file_url->url().path();
2702 bool acceptPath = dest != source;
2703 if (acceptPath && QFileInfo(dest).size() > 0) {
2704 // destination file olready exists, overwrite?
2707 while (!acceptPath) {
2708 // Do not allow to save over original clip
2709 if (dest == source) ui.info_label->setText("<b>" + i18n("You cannot overwrite original clip.") + "</b><br>" + mess);
2710 else if (KMessageBox::questionYesNo(this, i18n("Overwrite file %1", dest)) == KMessageBox::Yes) break;
2711 if (d->exec() != QDialog::Accepted) {
2715 dest = ui.file_url->url().path();
2716 acceptPath = dest != source;
2717 if (acceptPath && QFileInfo(dest).size() > 0) {
2721 QString extraParams = ui.extra_params->toPlainText().simplified();
2722 KdenliveSettings::setAdd_clip_cut(ui.add_clip->isChecked());
2725 QStringList jobParams;
2726 jobParams << dest << item->clipUrl().path() << timeIn << timeOut << QString::number(duration) << QString::number(KdenliveSettings::add_clip_cut());
2727 if (!extraParams.isEmpty()) jobParams << extraParams;
2728 CutClipJob *job = new CutClipJob(item->clipType(), id, jobParams);
2729 if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
2733 m_jobList.append(job);
2734 setJobStatus(item, job->jobType, JOBWAITING, 0, job->statusMessage());
2736 slotCheckJobProcess();
2739 void ProjectList::slotTranscodeClipJob(const QString &condition, QString params, QString desc)
2741 QStringList existingFiles;
2742 QStringList ids = getConditionalIds(condition);
2743 QStringList destinations;
2744 foreach(const QString &id, ids) {
2745 ProjectItem *item = getItemById(id);
2746 if (!item) continue;
2747 QString newFile = params.section(' ', -1).replace("%1", item->clipUrl().path());
2748 destinations << newFile;
2749 if (QFile::exists(newFile)) existingFiles << newFile;
2751 if (!existingFiles.isEmpty()) {
2752 if (KMessageBox::warningContinueCancelList(this, i18n("The transcoding job will overwrite the following files:"), existingFiles) == KMessageBox::Cancel) return;
2755 QDialog *d = new QDialog(this);
2756 Ui::CutJobDialog_UI ui;
2758 d->setWindowTitle(i18n("Transcoding"));
2759 ui.extra_params->setMaximumHeight(QFontMetrics(font()).lineSpacing() * 5);
2760 if (ids.count() == 1) {
2761 ui.file_url->setUrl(KUrl(destinations.first()));
2764 ui.destination_label->setVisible(false);
2765 ui.file_url->setVisible(false);
2767 ui.extra_params->setVisible(false);
2769 ui.button_more->setIcon(KIcon("configure"));
2770 ui.add_clip->setChecked(KdenliveSettings::add_clip_cut());
2771 ui.extra_params->setPlainText(params.simplified().section(" ", 0, -2));
2772 QString mess = desc;
2773 mess.append(" " + i18np("(%1 clip)", "(%1 clips)", ids.count()));
2774 ui.info_label->setText(mess);
2775 if (d->exec() != QDialog::Accepted) {
2779 params = ui.extra_params->toPlainText().simplified();
2780 KdenliveSettings::setAdd_clip_cut(ui.add_clip->isChecked());
2782 foreach(const QString &id, ids) {
2783 ProjectItem *item = getItemById(id);
2784 if (!item || !item->referencedClip()) continue;
2785 QString src = item->clipUrl().path();
2787 if (ids.count() > 1) dest = params.section(' ', -1).replace("%1", src);
2788 else dest = ui.file_url->url().path();
2789 QStringList jobParams;
2790 jobParams << dest << src << QString() << QString();
2791 double clipFps = item->referencedClip()->getProperty("fps").toDouble();
2792 if (clipFps == 0) clipFps = m_fps;
2793 int max = item->clipMaxDuration();
2794 QString duration = QString::number(max);
2795 jobParams << duration;
2796 jobParams << QString::number(KdenliveSettings::add_clip_cut());
2797 jobParams << params;
2798 CutClipJob *job = new CutClipJob(item->clipType(), id, jobParams);
2799 if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
2803 m_jobList.append(job);
2804 setJobStatus(item, job->jobType, JOBWAITING, 0, job->statusMessage());
2807 slotCheckJobProcess();
2811 void ProjectList::slotCheckJobProcess()
2813 if (!m_jobThreads.futures().isEmpty()) {
2814 // Remove inactive threads
2815 QList <QFuture<void> > futures = m_jobThreads.futures();
2816 m_jobThreads.clearFutures();
2817 for (int i = 0; i < futures.count(); i++)
2818 if (!futures.at(i).isFinished()) {
2819 m_jobThreads.addFuture(futures.at(i));
2822 if (m_jobList.isEmpty()) return;
2825 for (int i = 0; i < m_jobList.count(); i++) {
2826 if (m_jobList.at(i)->jobStatus == JOBWORKING || m_jobList.at(i)->jobStatus == JOBWAITING)
2829 // remove finished jobs
2830 AbstractClipJob *job = m_jobList.takeAt(i);
2836 emit jobCount(count);
2837 m_jobMutex.unlock();
2839 if (m_jobThreads.futures().isEmpty() || m_jobThreads.futures().count() < KdenliveSettings::proxythreads()) m_jobThreads.addFuture(QtConcurrent::run(this, &ProjectList::slotProcessJobs));
2842 void ProjectList::slotAbortProxy(const QString id, const QString path)
2846 ProjectItem *item = getItemById(id);
2848 if (!item->isProxyRunning()) slotGotProxy(item);
2849 item->setConditionalJobStatus(NOJOB, PROXYJOB);
2850 discardJobs(id, PROXYJOB);
2853 void ProjectList::slotProcessJobs()
2855 while (!m_jobList.isEmpty() && !m_abortAllJobs) {
2856 emit projectModified();
2857 AbstractClipJob *job = NULL;
2860 for (int i = 0; i < m_jobList.count(); i++) {
2861 if (m_jobList.at(i)->jobStatus == JOBWAITING) {
2863 m_jobList.at(i)->jobStatus = JOBWORKING;
2864 job = m_jobList.at(i);
2868 else if (m_jobList.at(i)->jobStatus == JOBWORKING)
2872 emit jobCount(count);
2873 m_jobMutex.unlock();
2878 QString destination = job->destination();
2879 // Check if the clip is still here
2880 DocClipBase *currentClip = m_doc->clipManager()->getClipById(job->clipId());
2881 //ProjectItem *processingItem = getItemById(job->clipId());
2882 if (currentClip == NULL) {
2883 job->setStatus(JOBDONE);
2886 // Set clip status to started
2887 emit processLog(job->clipId(), 0, job->jobType, job->statusMessage());
2889 // Make sure destination path is writable
2890 if (!destination.isEmpty()) {
2891 QFile file(destination);
2892 if (!file.open(QIODevice::WriteOnly)) {
2893 emit updateJobStatus(job->clipId(), job->jobType, JOBCRASHED, i18n("Cannot write to path: %1", destination));
2894 job->setStatus(JOBCRASHED);
2898 QFile::remove(destination);
2900 connect(job, SIGNAL(jobProgress(QString, int, int)), this, SIGNAL(processLog(QString, int, int)));
2901 connect(job, SIGNAL(cancelRunningJob(const QString, stringMap)), this, SIGNAL(cancelRunningJob(const QString, stringMap)));
2902 connect(job, SIGNAL(gotFilterJobResults(QString,int, int, QString,stringMap)), this, SIGNAL(gotFilterJobResults(QString,int, int, QString,stringMap)));
2904 if (job->jobType == MLTJOB) {
2905 MeltJob *jb = static_cast<MeltJob *> (job);
2906 jb->setProducer(currentClip->getProducer());
2909 if (job->jobStatus == JOBDONE) {
2910 emit updateJobStatus(job->clipId(), job->jobType, JOBDONE);
2911 //TODO: replace with more generic clip replacement framework
2912 if (job->jobType == PROXYJOB) emit gotProxy(job->clipId());
2913 if (job->addClipToProject()) {
2914 emit addClip(destination, QString(), QString());
2916 } else if (job->jobStatus == JOBCRASHED || job->jobStatus == JOBABORTED) {
2917 emit updateJobStatus(job->clipId(), job->jobType, job->jobStatus, job->errorMessage(), QString(), job->logDetails());
2920 // Thread finished, cleanup & update count
2921 QTimer::singleShot(200, this, SIGNAL(checkJobProcess()));
2925 void ProjectList::updateProxyConfig()
2928 QTreeWidgetItemIterator it(m_listView);
2929 QUndoCommand *command = new QUndoCommand();
2930 command->setText(i18n("Update proxy settings"));
2931 QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/";
2933 if ((*it)->type() != PROJECTCLIPTYPE) {
2937 item = static_cast<ProjectItem *>(*it);
2942 CLIPTYPE t = item->clipType();
2943 if ((t == VIDEO || t == AV || t == UNKNOWN) && item->referencedClip() != NULL) {
2944 if (generateProxy() && useProxy() && !hasPendingJob(item, PROXYJOB)) {
2945 DocClipBase *clip = item->referencedClip();
2946 if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > m_doc->getDocumentProperty("proxyminsize").toInt()) {
2947 if (clip->getProperty("proxy").isEmpty()) {
2948 // We need to insert empty proxy in old properties so that undo will work
2949 QMap <QString, QString> oldProps;// = clip->properties();
2950 oldProps.insert("proxy", QString());
2951 QMap <QString, QString> newProps;
2952 newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + "." + m_doc->getDocumentProperty("proxyextension"));
2953 new EditClipCommand(this, clip->getId(), oldProps, newProps, true, command);
2957 else if (item->hasProxy()) {
2959 QMap <QString, QString> newProps;
2960 newProps.insert("proxy", QString());
2961 // insert required duration for proxy
2962 newProps.insert("proxy_out", item->referencedClip()->producerProperty("out"));
2963 new EditClipCommand(this, item->clipId(), item->referencedClip()->currentProperties(newProps), newProps, true, command);
2966 else if (t == IMAGE && item->referencedClip() != NULL) {
2967 if (generateImageProxy() && useProxy()) {
2968 DocClipBase *clip = item->referencedClip();
2969 int maxImageSize = m_doc->getDocumentProperty("proxyimageminsize").toInt();
2970 if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > maxImageSize || clip->getProperty("frame_size").section('x', 1, 1).toInt() > maxImageSize) {
2971 if (clip->getProperty("proxy").isEmpty()) {
2972 // We need to insert empty proxy in old properties so that undo will work
2973 QMap <QString, QString> oldProps = clip->properties();
2974 oldProps.insert("proxy", QString());
2975 QMap <QString, QString> newProps;
2976 newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + ".png");
2977 new EditClipCommand(this, clip->getId(), oldProps, newProps, true, command);
2981 else if (item->hasProxy()) {
2983 QMap <QString, QString> newProps;
2984 newProps.insert("proxy", QString());
2985 new EditClipCommand(this, item->clipId(), item->referencedClip()->properties(), newProps, true, command);
2990 if (command->childCount() > 0) m_doc->commandStack()->push(command);
2991 else delete command;
2994 void ProjectList::slotProcessLog(const QString id, int progress, int type, const QString message)
2996 ProjectItem *item = getItemById(id);
2997 setJobStatus(item, (JOBTYPE) type, JOBWORKING, progress, message);
3000 void ProjectList::slotProxyCurrentItem(bool doProxy, ProjectItem *itemToProxy)
3002 QList<QTreeWidgetItem *> list;
3003 if (itemToProxy == NULL) list = m_listView->selectedItems();
3004 else list << itemToProxy;
3006 // expand list (folders, subclips) to get real clips
3007 QTreeWidgetItem *listItem;
3008 QList<ProjectItem *> clipList;
3009 for (int i = 0; i < list.count(); i++) {
3010 listItem = list.at(i);
3011 if (listItem->type() == PROJECTFOLDERTYPE) {
3012 for (int j = 0; j < listItem->childCount(); j++) {
3013 QTreeWidgetItem *sub = listItem->child(j);
3014 if (sub->type() == PROJECTCLIPTYPE) {
3015 ProjectItem *item = static_cast <ProjectItem*>(sub);
3016 if (!clipList.contains(item)) clipList.append(item);
3020 else if (listItem->type() == PROJECTSUBCLIPTYPE) {
3021 QTreeWidgetItem *sub = listItem->parent();
3022 ProjectItem *item = static_cast <ProjectItem*>(sub);
3023 if (!clipList.contains(item)) clipList.append(item);
3025 else if (listItem->type() == PROJECTCLIPTYPE) {
3026 ProjectItem *item = static_cast <ProjectItem*>(listItem);
3027 if (!clipList.contains(item)) clipList.append(item);
3031 QUndoCommand *command = new QUndoCommand();
3032 if (doProxy) command->setText(i18np("Add proxy clip", "Add proxy clips", clipList.count()));
3033 else command->setText(i18np("Remove proxy clip", "Remove proxy clips", clipList.count()));
3035 // Make sure the proxy folder exists
3036 QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/";
3037 KStandardDirs::makeDir(proxydir);
3039 QMap <QString, QString> newProps;
3040 QMap <QString, QString> oldProps;
3041 if (!doProxy) newProps.insert("proxy", "-");
3042 for (int i = 0; i < clipList.count(); i++) {
3043 ProjectItem *item = clipList.at(i);
3044 CLIPTYPE t = item->clipType();
3045 if ((t == VIDEO || t == AV || t == UNKNOWN || t == IMAGE || t == PLAYLIST) && item->referencedClip()) {
3046 if ((doProxy && item->hasProxy()) || (!doProxy && !item->hasProxy() && item->referencedClip()->getProducer() != NULL)) continue;
3047 DocClipBase *clip = item->referencedClip();
3048 if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
3049 kDebug()<<"//// TRYING TO PROXY: "<<item->clipId()<<", but it is busy";
3053 //oldProps = clip->properties();
3056 QString path = proxydir + clip->getClipHash() + "." + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension"));
3057 // insert required duration for proxy
3058 newProps.insert("proxy_out", clip->producerProperty("out"));
3059 newProps.insert("proxy", path);
3060 // We need to insert empty proxy so that undo will work
3061 //oldProps.insert("proxy", QString());
3063 else if (item->referencedClip()->getProducer() == NULL) {
3064 // Force clip reload
3065 kDebug()<<"// CLIP HAD NULL PROD------------";
3066 newProps.insert("resource", item->referencedClip()->getProperty("resource"));
3068 // We need to insert empty proxy so that undo will work
3069 oldProps = clip->currentProperties(newProps);
3070 if (doProxy) oldProps.insert("proxy", "-");
3071 new EditClipCommand(this, item->clipId(), oldProps, newProps, true, command);
3074 if (command->childCount() > 0) {
3075 m_doc->commandStack()->push(command);
3077 else delete command;
3081 void ProjectList::slotDeleteProxy(const QString proxyPath)
3083 if (proxyPath.isEmpty()) return;
3084 QUndoCommand *proxyCommand = new QUndoCommand();
3085 proxyCommand->setText(i18n("Remove Proxy"));
3086 QTreeWidgetItemIterator it(m_listView);
3089 if ((*it)->type() == PROJECTCLIPTYPE) {
3090 item = static_cast <ProjectItem *>(*it);
3091 if (item->referencedClip()->getProperty("proxy") == proxyPath) {
3092 QMap <QString, QString> props;
3093 props.insert("proxy", QString());
3094 new EditClipCommand(this, item->clipId(), item->referencedClip()->currentProperties(props), props, true, proxyCommand);
3100 if (proxyCommand->childCount() == 0)
3101 delete proxyCommand;
3103 m_commandStack->push(proxyCommand);
3104 QFile::remove(proxyPath);
3107 void ProjectList::setJobStatus(ProjectItem *item, JOBTYPE jobType, CLIPJOBSTATUS status, int progress, const QString &statusMessage)
3109 if (item == NULL || (m_abortAllJobs && m_closing)) return;
3110 monitorItemEditing(false);
3111 item->setJobStatus(jobType, status, progress, statusMessage);
3112 if (status == JOBCRASHED) {
3113 DocClipBase *clip = item->referencedClip();
3115 kDebug()<<"// PROXY CRASHED";
3117 else if (clip->getProducer() == NULL && !clip->isPlaceHolder()) {
3118 // disable proxy and fetch real clip
3119 clip->setProperty("proxy", "-");
3120 QDomElement xml = clip->toXML();
3121 m_render->getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), true);
3124 // Disable proxy for this clip
3125 clip->setProperty("proxy", "-");
3128 monitorItemEditing(true);
3131 void ProjectList::monitorItemEditing(bool enable)
3133 if (enable) connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
3134 else disconnect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
3137 QStringList ProjectList::expandedFolders() const
3140 FolderProjectItem *item;
3141 QTreeWidgetItemIterator it(m_listView);
3143 if ((*it)->type() != PROJECTFOLDERTYPE) {
3147 if ((*it)->isExpanded()) {
3148 item = static_cast<FolderProjectItem *>(*it);
3149 result.append(item->clipId());
3156 void ProjectList::processThumbOverlays(ProjectItem *item, QPixmap &pix)
3158 if (item->hasProxy()) {
3160 QColor c(220, 220, 10, 200);
3161 QRect r(0, 0, 12, 12);
3163 QFont font = p.font();
3166 p.setPen(Qt::black);
3167 p.drawText(r, Qt::AlignCenter, i18nc("The first letter of Proxy, used as abbreviation", "P"));
3171 void ProjectList::slotCancelJobs()
3173 m_abortAllJobs = true;
3174 for (int i = 0; i < m_jobList.count(); i++) {
3175 m_jobList.at(i)->setStatus(JOBABORTED);
3177 m_jobThreads.waitForFinished();
3178 m_jobThreads.clearFutures();
3179 QUndoCommand *command = new QUndoCommand();
3180 command->setText(i18np("Cancel job", "Cancel jobs", m_jobList.count()));
3182 for (int i = 0; i < m_jobList.count(); i++) {
3183 DocClipBase *currentClip = m_doc->clipManager()->getClipById(m_jobList.at(i)->clipId());
3184 if (!currentClip) continue;
3185 QMap <QString, QString> newProps = m_jobList.at(i)->cancelProperties();
3186 if (newProps.isEmpty()) continue;
3187 QMap <QString, QString> oldProps = currentClip->currentProperties(newProps);
3188 new EditClipCommand(this, m_jobList.at(i)->clipId(), oldProps, newProps, true, command);
3190 m_jobMutex.unlock();
3191 if (command->childCount() > 0) {
3192 m_doc->commandStack()->push(command);
3194 else delete command;
3195 if (!m_jobList.isEmpty()) qDeleteAll(m_jobList);
3197 m_abortAllJobs = false;
3198 m_infoLabel->slotSetJobCount(0);
3201 void ProjectList::slotCancelRunningJob(const QString id, stringMap newProps)
3203 if (newProps.isEmpty() || m_closing) return;
3204 DocClipBase *currentClip = m_doc->clipManager()->getClipById(id);
3205 if (!currentClip) return;
3206 QMap <QString, QString> oldProps = currentClip->currentProperties(newProps);
3207 if (newProps == oldProps) return;
3208 QMapIterator<QString, QString> i(oldProps);
3209 EditClipCommand *command = new EditClipCommand(this, id, oldProps, newProps, true);
3210 m_commandStack->push(command);
3213 bool ProjectList::hasPendingJob(ProjectItem *item, JOBTYPE type)
3215 if (!item || !item->referencedClip() || m_abortAllJobs) return false;
3216 AbstractClipJob *job;
3217 QMutexLocker lock(&m_jobMutex);
3218 for (int i = 0; i < m_jobList.count(); i++) {
3219 if (m_abortAllJobs) break;
3220 job = m_jobList.at(i);
3221 if (job->clipId() == item->clipId() && job->jobType == type && (job->jobStatus == JOBWAITING || job->jobStatus == JOBWORKING)) return true;
3227 void ProjectList::deleteJobsForClip(const QString &clipId)
3229 QMutexLocker lock(&m_jobMutex);
3230 for (int i = 0; i < m_jobList.count(); i++) {
3231 if (m_jobList.at(i)->clipId() == clipId) {
3232 m_jobList.at(i)->setStatus(JOBABORTED);
3237 void ProjectList::slotUpdateJobStatus(const QString id, int type, int status, const QString label, const QString actionName, const QString details)
3239 ProjectItem *item = getItemById(id);
3241 slotUpdateJobStatus(item, type, status, label, actionName, details);
3245 void ProjectList::slotUpdateJobStatus(ProjectItem *item, int type, int status, const QString &label, const QString &actionName, const QString details)
3247 item->setJobStatus((JOBTYPE) type, (CLIPJOBSTATUS) status);
3248 if (status != JOBCRASHED) return;
3249 #if KDE_IS_VERSION(4,7,0)
3250 m_infoMessage->animatedHide();
3252 m_infoMessage->setText(label);
3253 m_infoMessage->setWordWrap(label.length() > 35);
3254 m_infoMessage->setMessageType(KMessageWidget::Warning);
3255 QList<QAction *> actions = m_infoMessage->actions();
3256 for (int i = 0; i < actions.count(); i++) {
3257 m_infoMessage->removeAction(actions.at(i));
3260 if (!actionName.isEmpty()) {
3261 QAction *action = NULL;
3262 QList< KActionCollection * > collections = KActionCollection::allCollections();
3263 for (int i = 0; i < collections.count(); i++) {
3264 KActionCollection *coll = collections.at(i);
3265 action = coll->action(actionName);
3268 if (action) m_infoMessage->addAction(action);
3270 if (!details.isEmpty()) {
3271 m_errorLog = details;
3272 m_infoMessage->addAction(m_logAction);
3274 m_infoMessage->animatedShow();
3278 void ProjectList::slotShowJobLog()
3280 #if KDE_IS_VERSION(4,7,0)
3282 d.setButtons(KDialog::Close);
3284 t.setPlainText(m_errorLog);
3285 t.setReadOnly(true);
3286 d.setMainWidget(&t);
3291 QStringList ProjectList::getPendingJobs(const QString &id)
3294 QMutexLocker lock(&m_jobMutex);
3295 for (int i = 0; i < m_jobList.count(); i++) {
3296 if (m_jobList.at(i)->clipId() == id && (m_jobList.at(i)->jobStatus == JOBWAITING || m_jobList.at(i)->jobStatus == JOBWORKING)) {
3298 result << m_jobList.at(i)->description;
3304 void ProjectList::discardJobs(const QString &id, JOBTYPE type) {
3305 QMutexLocker lock(&m_jobMutex);
3306 for (int i = 0; i < m_jobList.count(); i++) {
3307 if (m_jobList.at(i)->clipId() == id && (m_jobList.at(i)->jobType == type || type == NOJOBTYPE)) {
3309 m_jobList.at(i)->setStatus(JOBABORTED);
3314 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)
3316 ProjectItem *item = getItemById(id);
3318 QStringList jobParams;
3319 jobParams << QString::number(info.cropStart.frames(m_fps)) << QString::number((info.cropStart + info.cropDuration).frames(m_fps));
3320 jobParams << QString() << filterName << filterParams << consumer << consumerParams << properties << QString::number(info.startPos.frames(m_fps)) << QString::number(info.track) << finalFilterName;
3321 MeltJob *job = new MeltJob(item->clipType(), id, jobParams);
3322 if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
3326 job->description = i18n("Filter %1", finalFilterName);
3327 m_jobList.append(job);
3328 setJobStatus(item, job->jobType, JOBWAITING, 0, job->statusMessage());
3329 slotCheckJobProcess();
3332 void ProjectList::startClipFilterJob(const QString &filterName, const QString &condition)
3334 QStringList ids = getConditionalIds(condition);
3335 QString destination;
3336 ProjectItem *item = getItemById(ids.at(0));
3338 emit displayMessage(i18n("Cannot find clip to process filter %1", filterName), -2);
3341 if (ids.count() == 1) {
3342 destination = item->clipUrl().path();
3345 destination = item->clipUrl().directory();
3347 ClipStabilize *d = new ClipStabilize(destination, ids.count(), filterName);
3348 if (d->exec() == QDialog::Accepted) {
3349 processClipJob(ids, d->destination(), d->autoAddClip(), d->params(), d->desc());
3354 void ProjectList::processClipJob(QStringList ids, const QString&destination, bool autoAdd, QStringList jobParams, const QString &description)
3356 QStringList preParams;
3358 preParams << QString::number(0) << QString::number(-1);
3360 preParams << jobParams.takeFirst();
3362 preParams << jobParams.takeFirst();
3364 preParams << jobParams.takeFirst();
3366 QString consumer = jobParams.takeFirst();
3368 foreach(const QString&id, ids) {
3369 ProjectItem *item = getItemById(id);
3370 if (!item) continue;
3371 if (ids.count() == 1) {
3372 consumer += ":" + destination;
3375 consumer += ":" + destination + item->clipUrl().fileName() + ".mlt";
3377 preParams << consumer << jobParams;
3379 MeltJob *job = new MeltJob(item->clipType(), id, preParams);
3381 job->setAddClipToProject(true);
3382 kDebug()<<"// ADDING TRUE";
3384 else kDebug()<<"// ADDING FALSE!!!";
3385 if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
3389 job->description = description;
3390 m_jobList.append(job);
3391 setJobStatus(item, job->jobType, JOBWAITING, 0, job->statusMessage());
3393 slotCheckJobProcess();
3396 void ProjectList::slotPrepareJobsMenu()
3399 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
3401 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE)
3402 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
3404 item = static_cast <ProjectItem*>(m_listView->currentItem());
3405 if (item && (item->flags() & Qt::ItemIsDragEnabled)) {
3406 QString id = item->clipId();
3407 m_discardCurrentClipJobs->setData(id);
3408 QStringList jobs = getPendingJobs(id);
3409 m_discardCurrentClipJobs->setEnabled(!jobs.isEmpty());
3411 m_discardCurrentClipJobs->setData(QString());
3412 m_discardCurrentClipJobs->setEnabled(false);
3416 void ProjectList::slotDiscardClipJobs()
3418 QString id = m_discardCurrentClipJobs->data().toString();
3419 if (id.isEmpty()) return;
3423 #include "projectlist.moc"