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 "addfoldercommand.h"
23 #include "kdenlivesettings.h"
24 #include "slideshowclip.h"
25 #include "ui_colorclip_ui.h"
26 #include "titlewidget.h"
27 #include "definitions.h"
28 #include "clipmanager.h"
29 #include "docclipbase.h"
30 #include "kdenlivedoc.h"
33 #include "projectlistview.h"
34 #include "timecodedisplay.h"
35 #include "profilesdialog.h"
36 #include "editclipcommand.h"
37 #include "editclipcutcommand.h"
38 #include "editfoldercommand.h"
39 #include "addclipcutcommand.h"
41 #include "ui_templateclip_ui.h"
46 #include <KFileDialog>
47 #include <KInputDialog>
48 #include <KMessageBox>
49 #include <KIO/NetAccess>
51 #include <KApplication>
53 #include <nepomuk/global.h>
54 #include <nepomuk/resourcemanager.h>
55 //#include <nepomuk/tag.h>
58 #include <QMouseEvent>
59 #include <QStylePainter>
64 #include <QHeaderView>
65 #include <QInputDialog>
66 #include <QtConcurrentRun>
68 ProjectList::ProjectList(QWidget *parent) :
75 m_transcodeAction(NULL),
81 QVBoxLayout *layout = new QVBoxLayout;
82 layout->setContentsMargins(0, 0, 0, 0);
83 layout->setSpacing(0);
84 qRegisterMetaType<QDomElement>("QDomElement");
86 QFrame *frame = new QFrame;
87 frame->setFrameStyle(QFrame::NoFrame);
88 QHBoxLayout *box = new QHBoxLayout;
89 KTreeWidgetSearchLine *searchView = new KTreeWidgetSearchLine;
91 box->addWidget(searchView);
92 //int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
93 //m_toolbar->setIconSize(QSize(s, s));
95 m_addButton = new QToolButton;
96 m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
97 m_addButton->setAutoRaise(true);
98 box->addWidget(m_addButton);
100 m_editButton = new QToolButton;
101 m_editButton->setAutoRaise(true);
102 box->addWidget(m_editButton);
104 m_deleteButton = new QToolButton;
105 m_deleteButton->setAutoRaise(true);
106 box->addWidget(m_deleteButton);
107 frame->setLayout(box);
108 layout->addWidget(frame);
110 m_listView = new ProjectListView;
111 layout->addWidget(m_listView);
113 searchView->setTreeWidget(m_listView);
115 m_proxyAction = new QAction(i18n("Proxy clip"), this);
116 m_proxyAction->setCheckable(true);
117 m_proxyAction->setChecked(false);
118 connect(m_proxyAction, SIGNAL(toggled(bool)), this, SLOT(slotProxyCurrentItem(bool)));
119 connect(this, SIGNAL(processNextThumbnail()), this, SLOT(slotProcessNextThumbnail()));
120 connect(m_listView, SIGNAL(projectModified()), this, SIGNAL(projectModified()));
121 connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
122 connect(m_listView, SIGNAL(focusMonitor()), this, SLOT(slotClipSelected()));
123 connect(m_listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
124 connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
125 connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
126 connect(m_listView, SIGNAL(addClip(const QList <QUrl>, const QString &, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &, const QString &)));
127 connect(m_listView, SIGNAL(addClipCut(const QString &, int, int)), this, SLOT(slotAddClipCut(const QString &, int, int)));
128 connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
129 connect(m_listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
131 m_listViewDelegate = new ItemDelegate(m_listView);
132 m_listView->setItemDelegate(m_listViewDelegate);
134 if (KdenliveSettings::activate_nepomuk()) {
135 Nepomuk::ResourceManager::instance()->init();
136 if (!Nepomuk::ResourceManager::instance()->initialized()) {
137 kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
138 KdenliveSettings::setActivate_nepomuk(false);
144 ProjectList::~ProjectList()
147 m_listView->blockSignals(true);
149 delete m_listViewDelegate;
152 void ProjectList::focusTree() const
154 m_listView->setFocus();
157 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
159 QList <QAction *> actions = addMenu->actions();
160 for (int i = 0; i < actions.count(); i++) {
161 if (actions.at(i)->data().toString() == "clip_properties") {
162 m_editButton->setDefaultAction(actions.at(i));
165 } else if (actions.at(i)->data().toString() == "delete_clip") {
166 m_deleteButton->setDefaultAction(actions.at(i));
169 } else if (actions.at(i)->data().toString() == "edit_clip") {
170 m_openAction = actions.at(i);
173 } else if (actions.at(i)->data().toString() == "reload_clip") {
174 m_reloadAction = actions.at(i);
180 QMenu *m = new QMenu();
181 m->addActions(actions);
182 m_addButton->setMenu(m);
183 m_addButton->setDefaultAction(defaultAction);
184 m_menu = new QMenu();
185 m_menu->addActions(addMenu->actions());
188 void ProjectList::setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu, QMenu *inTimelineMenu)
192 QMenu *menu = m_addButton->menu();
193 menu->addMenu(addMenu);
194 m_addButton->setMenu(menu);
196 m_menu->addMenu(addMenu);
197 if (addMenu->isEmpty())
198 addMenu->setEnabled(false);
199 m_menu->addMenu(transcodeMenu);
200 if (transcodeMenu->isEmpty())
201 transcodeMenu->setEnabled(false);
202 m_transcodeAction = transcodeMenu;
203 m_menu->addAction(m_reloadAction);
204 m_menu->addAction(m_proxyAction);
205 m_menu->addMenu(inTimelineMenu);
206 inTimelineMenu->setEnabled(false);
207 m_menu->addAction(m_editButton->defaultAction());
208 m_menu->addAction(m_openAction);
209 m_menu->addAction(m_deleteButton->defaultAction());
210 m_menu->insertSeparator(m_deleteButton->defaultAction());
214 QByteArray ProjectList::headerInfo() const
216 return m_listView->header()->saveState();
219 void ProjectList::setHeaderInfo(const QByteArray &state)
221 m_listView->header()->restoreState(state);
224 void ProjectList::updateProjectFormat(Timecode t)
229 void ProjectList::slotEditClip()
231 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
232 if (list.isEmpty()) return;
233 if (list.count() > 1 || list.at(0)->type() == PROJECTFOLDERTYPE) {
234 editClipSelection(list);
238 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
240 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE)
241 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
243 item = static_cast <ProjectItem*>(m_listView->currentItem());
244 if (item && (item->flags() & Qt::ItemIsDragEnabled)) {
245 emit clipSelected(item->referencedClip());
246 emit showClipProperties(item->referencedClip());
250 void ProjectList::editClipSelection(QList<QTreeWidgetItem *> list)
252 // Gather all common properties
253 QMap <QString, QString> commonproperties;
254 QList <DocClipBase *> clipList;
255 commonproperties.insert("force_aspect_num", "-");
256 commonproperties.insert("force_aspect_den", "-");
257 commonproperties.insert("force_fps", "-");
258 commonproperties.insert("force_progressive", "-");
259 commonproperties.insert("force_tff", "-");
260 commonproperties.insert("threads", "-");
261 commonproperties.insert("video_index", "-");
262 commonproperties.insert("audio_index", "-");
263 commonproperties.insert("force_colorspace", "-");
264 commonproperties.insert("full_luma", "-");
266 bool allowDurationChange = true;
267 int commonDuration = -1;
269 for (int i = 0; i < list.count(); i++) {
271 if (list.at(i)->type() == PROJECTFOLDERTYPE) {
272 // Add folder items to the list
273 int ct = list.at(i)->childCount();
274 for (int j = 0; j < ct; j++) {
275 list.append(list.at(i)->child(j));
279 else if (list.at(i)->type() == PROJECTSUBCLIPTYPE)
280 item = static_cast <ProjectItem*>(list.at(i)->parent());
282 item = static_cast <ProjectItem*>(list.at(i));
283 if (!(item->flags() & Qt::ItemIsDragEnabled))
287 DocClipBase *clip = item->referencedClip();
288 if (clipList.contains(clip)) continue;
289 if (clip->clipType() != COLOR && clip->clipType() != IMAGE && clip->clipType() != TEXT)
290 allowDurationChange = false;
291 if (allowDurationChange && commonDuration != 0) {
292 if (commonDuration == -1)
293 commonDuration = clip->duration().frames(m_fps);
294 else if (commonDuration != clip->duration().frames(m_fps))
297 clipList.append(clip);
298 QMap <QString, QString> clipprops = clip->properties();
299 QMapIterator<QString, QString> p(commonproperties);
300 while (p.hasNext()) {
302 if (p.value().isEmpty()) continue;
303 if (clipprops.contains(p.key())) {
304 if (p.value() == "-")
305 commonproperties.insert(p.key(), clipprops.value(p.key()));
306 else if (p.value() != clipprops.value(p.key()))
307 commonproperties.insert(p.key(), QString());
309 commonproperties.insert(p.key(), QString());
314 if (allowDurationChange)
315 commonproperties.insert("out", QString::number(commonDuration));
316 /*QMapIterator<QString, QString> p(commonproperties);
317 while (p.hasNext()) {
319 kDebug() << "Result: " << p.key() << " = " << p.value();
321 emit showClipProperties(clipList, commonproperties);
324 void ProjectList::slotOpenClip()
327 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
329 if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1)
330 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
332 item = static_cast <ProjectItem*>(m_listView->currentItem());
334 if (item->clipType() == IMAGE) {
335 if (KdenliveSettings::defaultimageapp().isEmpty())
336 KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open images in the Settings dialog"));
338 QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
340 if (item->clipType() == AUDIO) {
341 if (KdenliveSettings::defaultaudioapp().isEmpty())
342 KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open audio files in the Settings dialog"));
344 QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
349 void ProjectList::cleanup()
351 m_listView->clearSelection();
352 QTreeWidgetItemIterator it(m_listView);
355 if ((*it)->type() != PROJECTCLIPTYPE) {
359 item = static_cast <ProjectItem *>(*it);
360 if (item->numReferences() == 0)
361 item->setSelected(true);
367 void ProjectList::trashUnusedClips()
369 QTreeWidgetItemIterator it(m_listView);
374 if ((*it)->type() != PROJECTCLIPTYPE) {
378 item = static_cast <ProjectItem *>(*it);
379 if (item->numReferences() == 0) {
380 ids << item->clipId();
381 KUrl url = item->clipUrl();
382 if (!url.isEmpty() && !urls.contains(url.path()))
388 // Check that we don't use the URL in another clip
389 QTreeWidgetItemIterator it2(m_listView);
391 if ((*it2)->type() != PROJECTCLIPTYPE) {
395 item = static_cast <ProjectItem *>(*it2);
396 if (item->numReferences() > 0) {
397 KUrl url = item->clipUrl();
398 if (!url.isEmpty() && urls.contains(url.path())) urls.removeAll(url.path());
403 emit deleteProjectClips(ids, QMap <QString, QString>());
404 for (int i = 0; i < urls.count(); i++)
405 KIO::NetAccess::del(KUrl(urls.at(i)), this);
408 void ProjectList::slotReloadClip(const QString &id)
410 QList<QTreeWidgetItem *> selected;
412 selected = m_listView->selectedItems();
414 ProjectItem *itemToReLoad = getItemById(id);
415 if (itemToReLoad) selected.append(itemToReLoad);
418 for (int i = 0; i < selected.count(); i++) {
419 if (selected.at(i)->type() != PROJECTCLIPTYPE) {
420 if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
421 for (int j = 0; j < selected.at(i)->childCount(); j++)
422 selected.append(selected.at(i)->child(j));
426 item = static_cast <ProjectItem *>(selected.at(i));
428 CLIPTYPE t = item->clipType();
430 if (!item->referencedClip()->getProperty("xmltemplate").isEmpty())
431 regenerateTemplate(item);
432 } else if (t != COLOR && t != SLIDESHOW && item->referencedClip() && item->referencedClip()->checkHash() == false) {
433 item->referencedClip()->setPlaceHolder(true);
434 item->setProperty("file_hash", QString());
435 } else if (t == IMAGE) {
436 item->referencedClip()->producer()->set("force_reload", 1);
439 QDomElement e = item->toXml();
440 // Make sure we get the correct producer length if it was adjusted in timeline
441 if (t == COLOR || t == IMAGE || t == SLIDESHOW || t == TEXT) {
442 int length = QString(item->referencedClip()->producerProperty("length")).toInt();
443 if (length > 0 && !e.hasAttribute("length")) {
444 e.setAttribute("length", length);
445 e.setAttribute("out", length - 1);
449 emit getFileProperties(e, item->clipId(), m_listView->iconSize().height(), true, false);
454 void ProjectList::slotModifiedClip(const QString &id)
456 ProjectItem *item = getItemById(id);
458 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
459 if (!pixmap.isNull()) {
461 p.fillRect(0, 0, pixmap.width(), pixmap.height(), QColor(255, 255, 255, 200));
462 p.drawPixmap(0, 0, KIcon("view-refresh").pixmap(m_listView->iconSize()));
465 pixmap = KIcon("view-refresh").pixmap(m_listView->iconSize());
467 item->setData(0, Qt::DecorationRole, pixmap);
471 void ProjectList::slotMissingClip(const QString &id)
473 ProjectItem *item = getItemById(id);
475 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
476 if (item->referencedClip()) {
477 item->referencedClip()->setPlaceHolder(true);
478 if (m_render == NULL) kDebug() << "********* ERROR, NULL RENDR";
479 item->referencedClip()->setProducer(m_render->invalidProducer(id), true);
480 item->slotSetToolTip();
481 emit clipNeedsReload(id, true);
485 emit displayMessage(i18n("Check missing clips"), -2);
486 emit updateRenderStatus();
489 void ProjectList::slotAvailableClip(const QString &id)
491 ProjectItem *item = getItemById(id);
494 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
495 if (item->referencedClip()) { // && item->referencedClip()->checkHash() == false) {
496 item->setProperty("file_hash", QString());
500 item->referencedClip()->setValid();
501 item->slotSetToolTip();
504 emit updateRenderStatus();
507 bool ProjectList::hasMissingClips()
509 bool missing = false;
510 QTreeWidgetItemIterator it(m_listView);
512 if ((*it)->type() == PROJECTCLIPTYPE && !((*it)->flags() & Qt::ItemIsDragEnabled)) {
521 void ProjectList::setRenderer(Render *projectRender)
523 m_render = projectRender;
524 m_listView->setIconSize(QSize((ProjectItem::itemDefaultHeight() - 2) * m_render->dar(), ProjectItem::itemDefaultHeight() - 2));
527 void ProjectList::slotClipSelected()
529 if (!m_listView->isEnabled()) return;
530 if (m_listView->currentItem()) {
531 if (m_listView->currentItem()->type() == PROJECTFOLDERTYPE) {
532 emit clipSelected(NULL);
533 m_editButton->defaultAction()->setEnabled(m_listView->currentItem()->childCount() > 0);
534 m_deleteButton->defaultAction()->setEnabled(true);
535 m_openAction->setEnabled(false);
536 m_reloadAction->setEnabled(false);
537 m_transcodeAction->setEnabled(false);
538 m_proxyAction->setEnabled(false);
541 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
542 // this is a sub item, use base clip
543 m_deleteButton->defaultAction()->setEnabled(true);
544 clip = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
545 if (clip == NULL) kDebug() << "-----------ERROR";
546 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
547 emit clipSelected(clip->referencedClip(), sub->zone());
548 m_transcodeAction->setEnabled(false);
551 clip = static_cast <ProjectItem*>(m_listView->currentItem());
552 if (clip && clip->referencedClip())
553 emit clipSelected(clip->referencedClip());
554 m_editButton->defaultAction()->setEnabled(true);
555 m_deleteButton->defaultAction()->setEnabled(true);
556 m_reloadAction->setEnabled(true);
557 m_transcodeAction->setEnabled(true);
558 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
559 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
560 m_openAction->setEnabled(true);
561 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
562 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
563 m_openAction->setEnabled(true);
565 m_openAction->setEnabled(false);
567 // Display relevant transcoding actions only
568 adjustTranscodeActions(clip);
569 // Display uses in timeline
570 emit findInTimeline(clip->clipId());
573 emit clipSelected(NULL);
574 m_editButton->defaultAction()->setEnabled(false);
575 m_deleteButton->defaultAction()->setEnabled(false);
576 m_openAction->setEnabled(false);
577 m_reloadAction->setEnabled(false);
578 m_transcodeAction->setEnabled(false);
582 void ProjectList::adjustProxyActions(ProjectItem *clip) const
584 if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW || clip->clipType() == AUDIO) {
585 m_proxyAction->setEnabled(false);
588 m_proxyAction->setEnabled(true);
589 m_proxyAction->blockSignals(true);
590 m_proxyAction->setChecked(clip->hasProxy());
591 m_proxyAction->blockSignals(false);
594 void ProjectList::adjustTranscodeActions(ProjectItem *clip) const
596 if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW) {
597 m_transcodeAction->setEnabled(false);
600 m_transcodeAction->setEnabled(true);
601 QList<QAction *> transcodeActions = m_transcodeAction->actions();
604 for (int i = 0; i < transcodeActions.count(); i++) {
605 data = transcodeActions.at(i)->data().toStringList();
606 if (data.count() > 2) {
607 condition = data.at(2);
608 if (condition.startsWith("vcodec"))
609 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
610 else if (condition.startsWith("acodec"))
611 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
617 void ProjectList::slotPauseMonitor()
623 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
625 ProjectItem *item = getItemById(id);
627 slotUpdateClipProperties(item, properties);
628 if (properties.contains("out") || properties.contains("force_fps") || properties.contains("resource")) {
630 } else if (properties.contains("colour") ||
631 properties.contains("xmldata") ||
632 properties.contains("force_aspect_num") ||
633 properties.contains("force_aspect_den") ||
634 properties.contains("templatetext")) {
635 slotRefreshClipThumbnail(item);
636 emit refreshClip(id, true);
637 } else if (properties.contains("full_luma") || properties.contains("force_colorspace") || properties.contains("loop")) {
638 emit refreshClip(id, false);
643 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
647 clip->setProperties(properties);
648 if (properties.contains("name")) {
649 monitorItemEditing(false);
650 clip->setText(0, properties.value("name"));
651 monitorItemEditing(true);
652 emit clipNameChanged(clip->clipId(), properties.value("name"));
654 if (properties.contains("description")) {
655 CLIPTYPE type = clip->clipType();
656 monitorItemEditing(false);
657 clip->setText(1, properties.value("description"));
658 monitorItemEditing(true);
660 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
661 // Use Nepomuk system to store clip description
662 Nepomuk::Resource f(clip->clipUrl().path());
663 f.setDescription(properties.value("description"));
666 emit projectModified();
670 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
672 if (item->type() == PROJECTSUBCLIPTYPE) {
673 // this is a sub-item
675 // user edited description
676 SubProjectItem *sub = static_cast <SubProjectItem*>(item);
677 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
678 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), sub->zone(), sub->description(), sub->text(1), true);
679 m_commandStack->push(command);
680 //slotUpdateCutClipProperties(sub->clipId(), sub->zone(), sub->text(1), sub->text(1));
684 if (item->type() == PROJECTFOLDERTYPE) {
686 FolderProjectItem *folder = static_cast <FolderProjectItem*>(item);
687 editFolder(item->text(0), folder->groupName(), folder->clipId());
688 folder->setGroupName(item->text(0));
689 m_doc->clipManager()->addFolder(folder->clipId(), item->text(0));
690 const int children = item->childCount();
691 for (int i = 0; i < children; i++) {
692 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
693 child->setProperty("groupname", item->text(0));
699 ProjectItem *clip = static_cast <ProjectItem*>(item);
701 if (clip->referencedClip()) {
702 QMap <QString, QString> oldprops;
703 QMap <QString, QString> newprops;
704 oldprops["description"] = clip->referencedClip()->getProperty("description");
705 newprops["description"] = item->text(1);
707 if (clip->clipType() == TEXT) {
708 // This is a text template clip, update the image
709 /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
710 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/
711 oldprops.insert("templatetext", clip->referencedClip()->getProperty("templatetext"));
712 newprops.insert("templatetext", item->text(1));
714 slotUpdateClipProperties(clip->clipId(), newprops);
715 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
716 m_commandStack->push(command);
718 } else if (column == 0) {
719 if (clip->referencedClip()) {
720 QMap <QString, QString> oldprops;
721 QMap <QString, QString> newprops;
722 oldprops["name"] = clip->referencedClip()->getProperty("name");
723 newprops["name"] = item->text(0);
724 slotUpdateClipProperties(clip, newprops);
725 emit projectModified();
726 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
727 m_commandStack->push(command);
732 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
734 bool enable = item ? true : false;
735 m_editButton->defaultAction()->setEnabled(enable);
736 m_deleteButton->defaultAction()->setEnabled(enable);
737 m_reloadAction->setEnabled(enable);
738 m_transcodeAction->setEnabled(enable);
740 ProjectItem *clip = NULL;
741 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
742 clip = static_cast <ProjectItem*>(item->parent());
743 m_transcodeAction->setEnabled(false);
744 } else if (m_listView->currentItem()->type() == PROJECTCLIPTYPE) {
745 clip = static_cast <ProjectItem*>(item);
746 // Display relevant transcoding actions only
747 adjustTranscodeActions(clip);
748 adjustProxyActions(clip);
749 // Display uses in timeline
750 emit findInTimeline(clip->clipId());
752 m_transcodeAction->setEnabled(false);
754 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
755 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
756 m_openAction->setEnabled(true);
757 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
758 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
759 m_openAction->setEnabled(true);
761 m_openAction->setEnabled(false);
765 m_openAction->setEnabled(false);
770 void ProjectList::slotRemoveClip()
772 if (!m_listView->currentItem())
775 QMap <QString, QString> folderids;
776 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
778 QUndoCommand *delCommand = new QUndoCommand();
779 delCommand->setText(i18n("Delete Clip Zone"));
780 for (int i = 0; i < selected.count(); i++) {
781 if (selected.at(i)->type() == PROJECTSUBCLIPTYPE) {
783 SubProjectItem *sub = static_cast <SubProjectItem *>(selected.at(i));
784 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
785 new AddClipCutCommand(this, item->clipId(), sub->zone().x(), sub->zone().y(), sub->description(), false, true, delCommand);
786 } else if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
788 FolderProjectItem *folder = static_cast <FolderProjectItem *>(selected.at(i));
789 folderids[folder->groupName()] = folder->clipId();
790 int children = folder->childCount();
792 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)
794 for (int i = 0; i < children; ++i) {
795 ProjectItem *child = static_cast <ProjectItem *>(folder->child(i));
796 ids << child->clipId();
799 ProjectItem *item = static_cast <ProjectItem *>(selected.at(i));
800 ids << item->clipId();
801 if (item->numReferences() > 0 && KMessageBox::questionYesNo(kapp->activeWindow(), i18np("Delete clip <b>%2</b>?<br />This will also remove the clip in timeline", "Delete clip <b>%2</b>?<br />This will also remove its %1 clips in timeline", item->numReferences(), item->names().at(1)), i18n("Delete Clip"), KStandardGuiItem::yes(), KStandardGuiItem::no(), "DeleteAll") == KMessageBox::No) {
802 KMessageBox::enableMessage("DeleteAll");
807 KMessageBox::enableMessage("DeleteAll");
808 if (delCommand->childCount() == 0)
811 m_commandStack->push(delCommand);
812 emit deleteProjectClips(ids, folderids);
815 void ProjectList::updateButtons() const
817 if (m_listView->topLevelItemCount() == 0) {
818 m_deleteButton->defaultAction()->setEnabled(false);
819 m_editButton->defaultAction()->setEnabled(false);
821 m_deleteButton->defaultAction()->setEnabled(true);
822 if (!m_listView->currentItem())
823 m_listView->setCurrentItem(m_listView->topLevelItem(0));
824 QTreeWidgetItem *item = m_listView->currentItem();
825 if (item && item->type() == PROJECTCLIPTYPE) {
826 m_editButton->defaultAction()->setEnabled(true);
827 m_openAction->setEnabled(true);
828 m_reloadAction->setEnabled(true);
829 m_transcodeAction->setEnabled(true);
830 m_proxyAction->setEnabled(true);
833 else if (item && item->type() == PROJECTFOLDERTYPE && item->childCount() > 0) {
834 m_editButton->defaultAction()->setEnabled(true);
836 else m_editButton->defaultAction()->setEnabled(false);
838 m_openAction->setEnabled(false);
839 m_reloadAction->setEnabled(false);
840 m_transcodeAction->setEnabled(false);
841 m_proxyAction->setEnabled(false);
844 void ProjectList::selectItemById(const QString &clipId)
846 ProjectItem *item = getItemById(clipId);
848 m_listView->setCurrentItem(item);
852 void ProjectList::slotDeleteClip(const QString &clipId)
854 ProjectItem *item = getItemById(clipId);
856 kDebug() << "/// Cannot find clip to delete";
859 m_listView->blockSignals(true);
860 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
861 if (!newSelectedItem)
862 newSelectedItem = m_listView->itemBelow(item);
864 m_doc->clipManager()->deleteClip(clipId);
865 m_listView->blockSignals(false);
866 if (newSelectedItem) {
867 m_listView->setCurrentItem(newSelectedItem);
870 emit clipSelected(NULL);
875 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
877 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
878 m_commandStack->push(command);
879 m_doc->setModified(true);
882 void ProjectList::slotAddFolder()
884 AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
885 m_commandStack->push(command);
888 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
891 FolderProjectItem *item = getFolderItemById(clipId);
893 m_doc->clipManager()->deleteFolder(clipId);
894 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
895 if (!newSelectedItem)
896 newSelectedItem = m_listView->itemBelow(item);
899 m_listView->setCurrentItem(newSelectedItem);
905 FolderProjectItem *item = getFolderItemById(clipId);
907 m_listView->blockSignals(true);
908 item->setGroupName(foldername);
909 m_listView->blockSignals(false);
910 m_doc->clipManager()->addFolder(clipId, foldername);
911 const int children = item->childCount();
912 for (int i = 0; i < children; i++) {
913 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
914 child->setProperty("groupname", foldername);
918 m_listView->blockSignals(true);
919 m_listView->setCurrentItem(new FolderProjectItem(m_listView, QStringList() << foldername, clipId));
920 m_doc->clipManager()->addFolder(clipId, foldername);
921 m_listView->blockSignals(false);
922 m_listView->editItem(m_listView->currentItem(), 0);
926 m_doc->setModified(true);
931 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
933 QMapIterator<QString, QString> i(map);
934 QUndoCommand *delCommand = new QUndoCommand();
935 delCommand->setText(i18n("Delete Folder"));
936 while (i.hasNext()) {
938 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
940 m_commandStack->push(delCommand);
943 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
945 m_listView->setEnabled(false);
946 const QString parent = clip->getProperty("groupid");
947 ProjectItem *item = NULL;
948 monitorItemEditing(false);
949 if (!parent.isEmpty()) {
950 FolderProjectItem *parentitem = getFolderItemById(parent);
953 QString groupName = clip->getProperty("groupname");
954 //kDebug() << "Adding clip to new group: " << groupName;
955 if (groupName.isEmpty()) groupName = i18n("Folder");
957 parentitem = new FolderProjectItem(m_listView, text, parent);
961 item = new ProjectItem(parentitem, clip);
964 item = new ProjectItem(m_listView, clip);
966 if (item->data(0, DurationRole).isNull()) item->setData(0, DurationRole, i18n("Loading"));
968 m_listView->processLayout();
971 CLIPTYPE t = clip->clipType();
972 if ((t == VIDEO || t == AV || t == UNKNOWN) && useProxy()) {
973 if (clip->getProperty("proxy").isEmpty()) {
974 connect(clip, SIGNAL(proxyReady(const QString&, bool)), this, SLOT(slotGotProxy(const QString&, bool)));
975 setProxyStatus(item, 1);
976 clip->generateProxy(m_doc->projectFolder(), proxyParams());
979 // Proxy clip already created
980 setProxyStatus(item, 2);
981 QDomElement e = clip->toXML().cloneNode().toElement();
982 e.removeAttribute("file_hash");
983 m_infoQueue.insert(clip->getId(), e);
987 // We don't use proxies
988 // remove file_hash so that we load all properties for the clip
989 QDomElement e = clip->toXML().cloneNode().toElement();
990 e.removeAttribute("file_hash");
991 m_infoQueue.insert(clip->getId(), e);
993 //m_render->getFileProperties(clip->toXML(), clip->getId(), true);
995 else if (!clip->getProperty("proxy").isEmpty()) {
996 connect(clip, SIGNAL(proxyReady(const QString&, bool)), this, SLOT(slotGotProxy(const QString&, bool)));
997 setProxyStatus(item, 1);
998 clip->generateProxy(m_doc->projectFolder(), proxyParams());
1000 clip->askForAudioThumbs();
1002 KUrl url = clip->fileURL();
1003 if (getProperties == false && !clip->getClipHash().isEmpty()) {
1004 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
1005 if (QFile::exists(cachedPixmap)) {
1006 QPixmap pix(cachedPixmap);
1008 KIO::NetAccess::del(KUrl(cachedPixmap), this);
1009 item->setData(0, Qt::DecorationRole, pix);
1013 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
1014 // if file has Nepomuk comment, use it
1015 Nepomuk::Resource f(url.path());
1016 QString annotation = f.description();
1017 if (!annotation.isEmpty()) item->setText(1, annotation);
1018 item->setText(2, QString::number(f.rating()));
1022 QList <CutZoneInfo> cuts = clip->cutZones();
1023 if (!cuts.isEmpty()) {
1024 for (int i = 0; i < cuts.count(); i++) {
1025 SubProjectItem *sub = new SubProjectItem(item, cuts.at(i).zone.x(), cuts.at(i).zone.y(), cuts.at(i).description);
1026 if (!clip->getClipHash().isEmpty()) {
1027 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(cuts.at(i).zone.x()) + ".png";
1028 if (QFile::exists(cachedPixmap)) {
1029 QPixmap pix(cachedPixmap);
1031 KIO::NetAccess::del(KUrl(cachedPixmap), this);
1032 sub->setData(0, Qt::DecorationRole, pix);
1037 monitorItemEditing(true);
1038 if (m_listView->isEnabled()) {
1042 if (getProperties && m_processingClips.isEmpty())
1043 m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
1046 void ProjectList::slotGotProxy(const QString &id, bool success)
1048 ProjectItem *item = getItemById(id);
1051 // Proxy clip successfully created
1052 setProxyStatus(item, 2);
1053 QDomElement e = item->referencedClip()->toXML().cloneNode().toElement();
1054 e.removeAttribute("file_hash");
1055 e.setAttribute("replace", 1);
1056 m_infoQueue.insert(id, e);
1057 if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
1059 else setProxyStatus(item, 0);
1064 void ProjectList::slotResetProjectList()
1066 m_listView->clear();
1067 emit clipSelected(NULL);
1068 m_thumbnailQueue.clear();
1069 m_infoQueue.clear();
1070 m_refreshed = false;
1073 void ProjectList::requestClipInfo(const QDomElement xml, const QString id)
1075 m_refreshed = false;
1076 m_infoQueue.insert(id, xml);
1077 //if (m_infoQueue.count() == 1 || ) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
1080 void ProjectList::slotProcessNextClipInQueue()
1082 if (m_infoQueue.isEmpty()) {
1083 emit processNextThumbnail();
1087 QMap<QString, QDomElement>::const_iterator j = m_infoQueue.constBegin();
1088 if (j != m_infoQueue.constEnd()) {
1089 QDomElement dom = j.value();
1090 const QString id = j.key();
1091 m_infoQueue.remove(id);
1092 m_processingClips.append(id);
1094 if (dom.hasAttribute("replace")) {
1095 // Proxy action was enabled / disabled and we want to replace current producer
1096 dom.removeAttribute("replace");
1099 else replace = false;
1100 bool selectClip = !replace;
1101 if (m_infoQueue.count() > 1) selectClip = false;
1102 emit getFileProperties(dom, id, m_listView->iconSize().height(), replace, selectClip);
1106 void ProjectList::slotUpdateClip(const QString &id)
1108 ProjectItem *item = getItemById(id);
1109 monitorItemEditing(false);
1110 if (item) item->setData(0, UsageRole, QString::number(item->numReferences()));
1111 monitorItemEditing(true);
1114 void ProjectList::updateAllClips()
1116 m_listView->setSortingEnabled(false);
1117 kDebug() << "// UPDATE ALL CLPY";
1119 QTreeWidgetItemIterator it(m_listView);
1122 monitorItemEditing(false);
1124 if ((*it)->type() == PROJECTSUBCLIPTYPE) {
1126 SubProjectItem *sub = static_cast <SubProjectItem *>(*it);
1127 if (sub->data(0, Qt::DecorationRole).isNull()) {
1128 item = static_cast <ProjectItem *>((*it)->parent());
1129 requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x()));
1133 } else if ((*it)->type() == PROJECTFOLDERTYPE) {
1138 item = static_cast <ProjectItem *>(*it);
1139 clip = item->referencedClip();
1140 if (item->referencedClip()->producer() == NULL) {
1141 if (clip->isPlaceHolder() == false)
1142 requestClipInfo(clip->toXML(), clip->getId());
1143 else if (!clip->isPlaceHolder())
1144 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
1146 if (item->data(0, Qt::DecorationRole).isNull())
1147 requestClipThumbnail(clip->getId());
1148 if (item->data(0, DurationRole).toString().isEmpty())
1149 item->changeDuration(item->referencedClip()->producer()->get_playtime());
1151 item->setData(0, UsageRole, QString::number(item->numReferences()));
1153 //qApp->processEvents();
1156 /*if (!m_queueTimer.isActive())
1157 m_queueTimer.start();*/
1158 if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
1159 if (m_listView->isEnabled())
1160 monitorItemEditing(true);
1161 m_listView->setSortingEnabled(true);
1162 if (m_infoQueue.isEmpty())
1163 slotProcessNextThumbnail();
1167 QString ProjectList::getExtensions()
1169 // Build list of mime types
1170 QStringList mimeTypes = QStringList() << "application/x-kdenlive" << "application/x-kdenlivetitle" << "video/mlt-playlist" << "text/plain"
1171 << "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"
1172 << "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"
1173 << "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";
1175 QString allExtensions;
1176 foreach(const QString & mimeType, mimeTypes) {
1177 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
1179 allExtensions.append(mime->patterns().join(" "));
1180 allExtensions.append(' ');
1183 return allExtensions.simplified();
1186 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
1188 if (!m_commandStack)
1189 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1192 if (givenList.isEmpty()) {
1193 QString allExtensions = getExtensions();
1194 const QString dialogFilter = allExtensions + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
1195 QCheckBox *b = new QCheckBox(i18n("Import image sequence"));
1196 b->setChecked(KdenliveSettings::autoimagesequence());
1197 KFileDialog *d = new KFileDialog(KUrl("kfiledialog:///clipfolder"), dialogFilter, kapp->activeWindow(), b);
1198 d->setOperationMode(KFileDialog::Opening);
1199 d->setMode(KFile::Files);
1201 list = d->selectedUrls();
1202 if (b->isChecked() && list.count() == 1) {
1203 // Check for image sequence
1204 KUrl url = list.at(0);
1205 QString fileName = url.fileName().section('.', 0, -2);
1206 if (fileName.at(fileName.size() - 1).isDigit()) {
1207 KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
1208 if (item.mimetype().startsWith("image")) {
1209 // import as sequence if we found more than one image in the sequence
1211 QString pattern = SlideshowClip::selectedPath(url.path(), false, QString(), &list);
1212 int count = list.count();
1215 QStringList groupInfo = getGroup();
1217 // get image sequence base name
1218 while (fileName.at(fileName.size() - 1).isDigit()) {
1222 m_doc->slotCreateSlideshowClipFile(fileName, pattern, count, m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()),
1223 false, false, false,
1224 m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))), QString(), 0,
1225 QString(), groupInfo.at(0), groupInfo.at(1));
1233 for (int i = 0; i < givenList.count(); i++)
1234 list << givenList.at(i);
1237 foreach(const KUrl & file, list) {
1238 // Check there is no folder here
1239 KMimeType::Ptr type = KMimeType::findByUrl(file);
1240 if (type->is("inode/directory")) {
1241 // user dropped a folder
1242 list.removeAll(file);
1249 if (givenList.isEmpty()) {
1250 QStringList groupInfo = getGroup();
1251 m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1));
1253 m_doc->slotAddClipList(list, groupName, groupId);
1257 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
1259 ProjectItem *item = getItemById(id);
1260 m_processingClips.removeAll(id);
1261 if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
1263 const QString path = item->referencedClip()->fileURL().path();
1264 if (item->referencedClip()->isPlaceHolder()) replace = false;
1265 if (!path.isEmpty()) {
1267 KMessageBox::sorry(kapp->activeWindow(), i18n("Clip <b>%1</b><br />is invalid, will be removed from project.", path));
1268 else if (KMessageBox::questionYesNo(kapp->activeWindow(), i18n("Clip <b>%1</b><br />is missing or invalid. Remove it from project?", path), i18n("Invalid clip")) == KMessageBox::Yes)
1272 emit deleteProjectClips(QStringList() << id, QMap <QString, QString>());
1276 void ProjectList::slotAddColorClip()
1278 if (!m_commandStack)
1279 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1281 QDialog *dia = new QDialog(this);
1282 Ui::ColorClip_UI dia_ui;
1283 dia_ui.setupUi(dia);
1284 dia->setWindowTitle(i18n("Color Clip"));
1285 dia_ui.clip_name->setText(i18n("Color Clip"));
1287 TimecodeDisplay *t = new TimecodeDisplay(m_timecode);
1288 t->setValue(KdenliveSettings::color_duration());
1289 t->setTimeCodeFormat(false);
1290 dia_ui.clip_durationBox->addWidget(t);
1291 dia_ui.clip_color->setColor(KdenliveSettings::colorclipcolor());
1293 if (dia->exec() == QDialog::Accepted) {
1294 QString color = dia_ui.clip_color->color().name();
1295 KdenliveSettings::setColorclipcolor(color);
1296 color = color.replace(0, 1, "0x") + "ff";
1297 QStringList groupInfo = getGroup();
1298 m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, m_timecode.getTimecode(t->gentime()), groupInfo.at(0), groupInfo.at(1));
1305 void ProjectList::slotAddSlideshowClip()
1307 if (!m_commandStack)
1308 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1310 SlideshowClip *dia = new SlideshowClip(m_timecode, this);
1312 if (dia->exec() == QDialog::Accepted) {
1313 QStringList groupInfo = getGroup();
1314 m_doc->slotCreateSlideshowClipFile(dia->clipName(), dia->selectedPath(), dia->imageCount(), dia->clipDuration(),
1315 dia->loop(), dia->crop(), dia->fade(),
1316 dia->lumaDuration(), dia->lumaFile(), dia->softness(),
1317 dia->animation(), groupInfo.at(0), groupInfo.at(1));
1322 void ProjectList::slotAddTitleClip()
1324 QStringList groupInfo = getGroup();
1325 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
1328 void ProjectList::slotAddTitleTemplateClip()
1330 if (!m_commandStack)
1331 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1333 QStringList groupInfo = getGroup();
1335 // Get the list of existing templates
1337 filter << "*.kdenlivetitle";
1338 const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
1339 QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
1341 QDialog *dia = new QDialog(this);
1342 Ui::TemplateClip_UI dia_ui;
1343 dia_ui.setupUi(dia);
1344 for (int i = 0; i < templateFiles.size(); ++i)
1345 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
1347 if (!templateFiles.isEmpty())
1348 dia_ui.buttonBox->button(QDialogButtonBox::Ok)->setFocus();
1349 dia_ui.template_list->fileDialog()->setFilter("application/x-kdenlivetitle");
1350 //warning: setting base directory doesn't work??
1351 KUrl startDir(path);
1352 dia_ui.template_list->fileDialog()->setUrl(startDir);
1353 dia_ui.text_box->setHidden(true);
1354 if (dia->exec() == QDialog::Accepted) {
1355 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
1356 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
1357 // Create a cloned template clip
1358 m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
1363 QStringList ProjectList::getGroup() const
1366 QTreeWidgetItem *item = m_listView->currentItem();
1367 while (item && item->type() != PROJECTFOLDERTYPE)
1368 item = item->parent();
1371 FolderProjectItem *folder = static_cast <FolderProjectItem *>(item);
1372 result << folder->groupName() << folder->clipId();
1374 result << QString() << QString();
1379 void ProjectList::setDocument(KdenliveDoc *doc)
1381 m_listView->blockSignals(true);
1382 m_listView->clear();
1383 m_processingClips.clear();
1384 m_listView->setSortingEnabled(false);
1385 emit clipSelected(NULL);
1386 m_thumbnailQueue.clear();
1387 m_infoQueue.clear();
1388 m_refreshed = false;
1390 m_timecode = doc->timecode();
1391 m_commandStack = doc->commandStack();
1394 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
1395 QMapIterator<QString, QString> f(flist);
1396 while (f.hasNext()) {
1398 (void) new FolderProjectItem(m_listView, QStringList() << f.value(), f.key());
1401 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
1402 for (int i = 0; i < list.count(); i++)
1403 slotAddClip(list.at(i), false);
1405 m_listView->blockSignals(false);
1406 connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
1407 connect(m_doc->clipManager(), SIGNAL(modifiedClip(const QString &)), this, SLOT(slotModifiedClip(const QString &)));
1408 connect(m_doc->clipManager(), SIGNAL(missingClip(const QString &)), this, SLOT(slotMissingClip(const QString &)));
1409 connect(m_doc->clipManager(), SIGNAL(availableClip(const QString &)), this, SLOT(slotAvailableClip(const QString &)));
1410 connect(m_doc->clipManager(), SIGNAL(checkAllClips()), this, SLOT(updateAllClips()));
1413 QList <DocClipBase*> ProjectList::documentClipList() const
1416 return QList <DocClipBase*> ();
1418 return m_doc->clipManager()->documentClipList();
1421 QDomElement ProjectList::producersList()
1424 QDomElement prods = doc.createElement("producerlist");
1425 doc.appendChild(prods);
1426 kDebug() << "//////////// PRO LIST BUILD PRDSLIST ";
1427 QTreeWidgetItemIterator it(m_listView);
1429 if ((*it)->type() != PROJECTCLIPTYPE) {
1434 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
1440 void ProjectList::slotCheckForEmptyQueue()
1442 if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
1444 emit loadingIsOver();
1445 emit displayMessage(QString(), -1);
1446 m_listView->blockSignals(false);
1447 m_listView->setEnabled(true);
1449 } else if (!m_refreshed) {
1450 QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
1454 void ProjectList::reloadClipThumbnails()
1456 m_thumbnailQueue.clear();
1457 QTreeWidgetItemIterator it(m_listView);
1459 if ((*it)->type() != PROJECTCLIPTYPE) {
1464 m_thumbnailQueue << ((ProjectItem *)(*it))->clipId();
1467 QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
1470 void ProjectList::requestClipThumbnail(const QString id)
1472 if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id);
1475 void ProjectList::slotProcessNextThumbnail()
1477 if (m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
1478 slotCheckForEmptyQueue();
1481 if (!m_infoQueue.isEmpty()) {
1482 //QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
1485 if (m_thumbnailQueue.count() > 1) {
1486 int max = m_doc->clipManager()->clipsCount();
1487 emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - m_thumbnailQueue.count()) / max));
1489 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
1492 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
1494 QTreeWidgetItem *item = getAnyItemById(clipId);
1496 slotRefreshClipThumbnail(item, update);
1498 slotProcessNextThumbnail();
1501 void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
1503 if (it == NULL) return;
1504 ProjectItem *item = NULL;
1505 bool isSubItem = false;
1507 if (it->type() == PROJECTFOLDERTYPE) return;
1508 if (it->type() == PROJECTSUBCLIPTYPE) {
1509 item = static_cast <ProjectItem *>(it->parent());
1510 frame = static_cast <SubProjectItem *>(it)->zone().x();
1513 item = static_cast <ProjectItem *>(it);
1514 frame = item->referencedClip()->getClipThumbFrame();
1518 DocClipBase *clip = item->referencedClip();
1520 slotProcessNextThumbnail();
1524 int height = m_listView->iconSize().height();
1525 int width = (int)(height * m_render->dar());
1526 if (clip->clipType() == AUDIO)
1527 pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
1528 else if (clip->clipType() == IMAGE)
1529 pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->producer(), 0, width, height));
1531 pix = item->referencedClip()->thumbProducer()->extractImage(frame, width, height);
1533 if (!pix.isNull()) {
1534 monitorItemEditing(false);
1535 it->setData(0, Qt::DecorationRole, pix);
1536 monitorItemEditing(true);
1539 m_doc->cachePixmap(item->getClipHash(), pix);
1541 m_doc->cachePixmap(item->getClipHash() + '#' + QString::number(frame), pix);
1544 emit projectModified();
1546 slotProcessNextThumbnail();
1550 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace, bool selectClip)
1553 ProjectItem *item = getItemById(clipId);
1554 m_processingClips.removeAll(clipId);
1555 if (m_infoQueue.isEmpty() && m_processingClips.isEmpty()) m_listView->setEnabled(true);
1556 if (item && producer) {
1557 //m_listView->blockSignals(true);
1558 monitorItemEditing(false);
1559 item->setProperties(properties, metadata);
1560 if (item->referencedClip()->isPlaceHolder() && producer->is_valid()) {
1561 item->referencedClip()->setValid();
1562 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1565 if (item->referencedClip()->getProperty("proxy").isEmpty()) setProxyStatus(item, 0);
1566 item->referencedClip()->setProducer(producer, replace);
1567 item->referencedClip()->askForAudioThumbs();
1568 if (!replace && item->data(0, Qt::DecorationRole).isNull())
1569 requestClipThumbnail(clipId);
1570 if (!toReload.isEmpty())
1571 item->slotSetToolTip();
1573 if (m_listView->isEnabled() && replace) {
1574 // update clip in clip monitor
1575 emit clipSelected(NULL);
1576 emit clipSelected(item->referencedClip());
1577 //TODO: Make sure the line below has no side effect
1581 // Check if duration changed.
1582 emit receivedClipDuration(clipId);
1585 if (m_listView->isEnabled())
1586 monitorItemEditing(true);
1587 /*if (item->icon(0).isNull()) {
1588 requestClipThumbnail(clipId);
1590 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
1591 if (selectClip && m_infoQueue.isEmpty()) {
1592 if (item && m_infoQueue.isEmpty() && m_thumbnailQueue.isEmpty()) {
1593 m_listView->setCurrentItem(item);
1594 bool updatedProfile = false;
1595 if (item->parent()) {
1596 if (item->parent()->type() == PROJECTFOLDERTYPE)
1597 static_cast <FolderProjectItem *>(item->parent())->switchIcon();
1598 } else if (KdenliveSettings::checkfirstprojectclip() && m_listView->topLevelItemCount() == 1) {
1599 // this is the first clip loaded in project, check if we want to adjust project settings to the clip
1600 updatedProfile = adjustProjectProfileToItem(item);
1602 if (updatedProfile == false) emit clipSelected(item->referencedClip());
1604 int max = m_doc->clipManager()->clipsCount();
1605 emit displayMessage(i18n("Loading clips"), (int)(100 *(max - m_infoQueue.count()) / max));
1608 if (!toReload.isEmpty())
1609 emit clipNeedsReload(toReload, true);
1611 if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
1614 bool ProjectList::adjustProjectProfileToItem(ProjectItem *item)
1617 if (m_listView->currentItem() && m_listView->currentItem()->type() != PROJECTFOLDERTYPE)
1618 item = static_cast <ProjectItem*>(m_listView->currentItem());
1620 if (item == NULL || item->referencedClip() == NULL) {
1621 KMessageBox::information(kapp->activeWindow(), i18n("Cannot find profile from current clip"));
1624 bool profileUpdated = false;
1625 QString size = item->referencedClip()->getProperty("frame_size");
1626 int width = size.section('x', 0, 0).toInt();
1627 int height = size.section('x', -1).toInt();
1628 double fps = item->referencedClip()->getProperty("fps").toDouble();
1629 double par = item->referencedClip()->getProperty("aspect_ratio").toDouble();
1630 if (item->clipType() == IMAGE || item->clipType() == AV || item->clipType() == VIDEO) {
1631 if (ProfilesDialog::matchProfile(width, height, fps, par, item->clipType() == IMAGE, m_doc->mltProfile()) == false) {
1632 // get a list of compatible profiles
1633 QMap <QString, QString> suggestedProfiles = ProfilesDialog::getProfilesFromProperties(width, height, fps, par, item->clipType() == IMAGE);
1634 if (!suggestedProfiles.isEmpty()) {
1635 KDialog *dialog = new KDialog(this);
1636 dialog->setCaption(i18n("Change project profile"));
1637 dialog->setButtons(KDialog::Ok | KDialog::Cancel);
1640 QVBoxLayout *l = new QVBoxLayout;
1641 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));
1642 l->addWidget(label);
1643 QListWidget *list = new QListWidget;
1644 list->setAlternatingRowColors(true);
1645 QMapIterator<QString, QString> i(suggestedProfiles);
1646 while (i.hasNext()) {
1648 QListWidgetItem *item = new QListWidgetItem(i.value(), list);
1649 item->setData(Qt::UserRole, i.key());
1650 item->setToolTip(i.key());
1652 list->setCurrentRow(0);
1654 container.setLayout(l);
1655 dialog->setButtonText(KDialog::Ok, i18n("Update profile"));
1656 dialog->setMainWidget(&container);
1657 if (dialog->exec() == QDialog::Accepted) {
1658 //Change project profile
1659 profileUpdated = true;
1660 if (list->currentItem())
1661 emit updateProfile(list->currentItem()->data(Qt::UserRole).toString());
1665 } else if (fps > 0) {
1666 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));
1670 return profileUpdated;
1673 bool ProjectList::useProxy() const
1675 return m_doc->getDocumentProperty("enableproxy").toInt();
1678 QString ProjectList::proxyParams() const
1680 return m_doc->getDocumentProperty("proxyparams").simplified();
1683 void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
1685 ProjectItem *item = getItemById(clipId);
1686 if (item && !pix.isNull()) {
1687 monitorItemEditing(false);
1688 item->setData(0, Qt::DecorationRole, pix);
1689 monitorItemEditing(true);
1690 m_doc->cachePixmap(item->getClipHash(), pix);
1691 if (m_listView->isEnabled())
1692 m_listView->blockSignals(false);
1696 QTreeWidgetItem *ProjectList::getAnyItemById(const QString &id)
1698 QTreeWidgetItemIterator it(m_listView);
1699 QString lookId = id;
1700 if (id.contains('#'))
1701 lookId = id.section('#', 0, 0);
1703 ProjectItem *result = NULL;
1705 if ((*it)->type() != PROJECTCLIPTYPE) {
1710 ProjectItem *item = static_cast<ProjectItem *>(*it);
1711 if (item->clipId() == lookId) {
1717 if (result == NULL || !id.contains('#')) {
1720 for (int i = 0; i < result->childCount(); i++) {
1721 SubProjectItem *sub = static_cast <SubProjectItem *>(result->child(i));
1722 if (sub && sub->zone().x() == id.section('#', 1, 1).toInt())
1731 ProjectItem *ProjectList::getItemById(const QString &id)
1734 QTreeWidgetItemIterator it(m_listView);
1736 if ((*it)->type() != PROJECTCLIPTYPE) {
1737 // subitem or folder
1741 item = static_cast<ProjectItem *>(*it);
1742 if (item->clipId() == id)
1749 FolderProjectItem *ProjectList::getFolderItemById(const QString &id)
1751 FolderProjectItem *item;
1752 QTreeWidgetItemIterator it(m_listView);
1754 if ((*it)->type() == PROJECTFOLDERTYPE) {
1755 item = static_cast<FolderProjectItem *>(*it);
1756 if (item->clipId() == id)
1764 void ProjectList::slotSelectClip(const QString &ix)
1766 ProjectItem *clip = getItemById(ix);
1768 m_listView->setCurrentItem(clip);
1769 m_listView->scrollToItem(clip);
1770 m_editButton->defaultAction()->setEnabled(true);
1771 m_deleteButton->defaultAction()->setEnabled(true);
1772 m_reloadAction->setEnabled(true);
1773 m_transcodeAction->setEnabled(true);
1774 m_proxyAction->setEnabled(true);
1775 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
1776 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
1777 m_openAction->setEnabled(true);
1778 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
1779 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
1780 m_openAction->setEnabled(true);
1782 m_openAction->setEnabled(false);
1787 QString ProjectList::currentClipUrl() const
1790 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return QString();
1791 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
1793 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
1795 item = static_cast <ProjectItem*>(m_listView->currentItem());
1799 return item->clipUrl().path();
1802 KUrl::List ProjectList::getConditionalUrls(const QString &condition) const
1806 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
1807 for (int i = 0; i < list.count(); i++) {
1808 if (list.at(i)->type() == PROJECTFOLDERTYPE)
1810 if (list.at(i)->type() == PROJECTSUBCLIPTYPE) {
1812 item = static_cast <ProjectItem*>(list.at(i)->parent());
1814 item = static_cast <ProjectItem*>(list.at(i));
1816 if (item == NULL || item->type() == COLOR || item->type() == SLIDESHOW || item->type() == TEXT)
1818 DocClipBase *clip = item->referencedClip();
1819 if (!condition.isEmpty()) {
1820 if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section('=', 1, 1)))
1822 else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section('=', 1, 1)))
1825 result.append(item->clipUrl());
1830 void ProjectList::regenerateTemplate(const QString &id)
1832 ProjectItem *clip = getItemById(id);
1834 regenerateTemplate(clip);
1837 void ProjectList::regenerateTemplate(ProjectItem *clip)
1839 //TODO: remove this unused method, only force_reload is necessary
1840 clip->referencedClip()->producer()->set("force_reload", 1);
1843 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
1847 if (!file.open(QIODevice::ReadOnly)) {
1848 kWarning() << "ERROR, CANNOT READ: " << path;
1851 if (!doc.setContent(&file)) {
1852 kWarning() << "ERROR, CANNOT READ: " << path;
1857 QDomNodeList texts = doc.elementsByTagName("content");
1858 for (int i = 0; i < texts.count(); i++) {
1859 QString data = texts.item(i).firstChild().nodeValue();
1860 data.replace("%s", replaceString);
1861 texts.item(i).firstChild().setNodeValue(data);
1867 void ProjectList::slotAddClipCut(const QString &id, int in, int out)
1869 ProjectItem *clip = getItemById(id);
1870 if (clip == NULL || clip->referencedClip()->hasCutZone(QPoint(in, out)))
1872 AddClipCutCommand *command = new AddClipCutCommand(this, id, in, out, QString(), true, false);
1873 m_commandStack->push(command);
1876 void ProjectList::addClipCut(const QString &id, int in, int out, const QString desc, bool newItem)
1878 ProjectItem *clip = getItemById(id);
1880 DocClipBase *base = clip->referencedClip();
1881 base->addCutZone(in, out);
1882 monitorItemEditing(false);
1883 SubProjectItem *sub = new SubProjectItem(clip, in, out, desc);
1884 if (newItem && desc.isEmpty() && !m_listView->isColumnHidden(1)) {
1885 if (!clip->isExpanded())
1886 clip->setExpanded(true);
1887 m_listView->scrollToItem(sub);
1888 m_listView->editItem(sub, 1);
1890 QPixmap p = clip->referencedClip()->thumbProducer()->extractImage(in, (int)(sub->sizeHint(0).height() * m_render->dar()), sub->sizeHint(0).height() - 2);
1891 sub->setData(0, Qt::DecorationRole, p);
1892 m_doc->cachePixmap(clip->getClipHash() + '#' + QString::number(in), p);
1893 monitorItemEditing(true);
1895 emit projectModified();
1898 void ProjectList::removeClipCut(const QString &id, int in, int out)
1900 ProjectItem *clip = getItemById(id);
1902 DocClipBase *base = clip->referencedClip();
1903 base->removeCutZone(in, out);
1904 SubProjectItem *sub = getSubItem(clip, QPoint(in, out));
1906 monitorItemEditing(false);
1908 monitorItemEditing(true);
1911 emit projectModified();
1914 SubProjectItem *ProjectList::getSubItem(ProjectItem *clip, QPoint zone)
1916 SubProjectItem *sub = NULL;
1918 for (int i = 0; i < clip->childCount(); i++) {
1919 QTreeWidgetItem *it = clip->child(i);
1920 if (it->type() == PROJECTSUBCLIPTYPE) {
1921 sub = static_cast <SubProjectItem*>(it);
1922 if (sub->zone() == zone)
1932 void ProjectList::slotUpdateClipCut(QPoint p)
1934 if (!m_listView->currentItem() || m_listView->currentItem()->type() != PROJECTSUBCLIPTYPE)
1936 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
1937 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
1938 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), p, sub->text(1), sub->text(1), true);
1939 m_commandStack->push(command);
1942 void ProjectList::doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment)
1944 ProjectItem *clip = getItemById(id);
1945 SubProjectItem *sub = getSubItem(clip, oldzone);
1946 if (sub == NULL || clip == NULL)
1948 DocClipBase *base = clip->referencedClip();
1949 base->updateCutZone(oldzone.x(), oldzone.y(), zone.x(), zone.y(), comment);
1950 monitorItemEditing(false);
1952 sub->setDescription(comment);
1953 monitorItemEditing(true);
1954 emit projectModified();
1957 void ProjectList::slotForceProcessing(const QString &id)
1959 while (m_infoQueue.contains(id)) {
1960 slotProcessNextClipInQueue();
1964 void ProjectList::slotAddOrUpdateSequence(const QString frameName)
1966 QString fileName = KUrl(frameName).fileName().section('_', 0, -2);
1968 QString pattern = SlideshowClip::selectedPath(frameName, false, QString(), &list);
1969 int count = list.count();
1971 const QList <DocClipBase *> existing = m_doc->clipManager()->getClipByResource(pattern);
1972 if (!existing.isEmpty()) {
1973 // Sequence already exists, update
1974 QString id = existing.at(0)->getId();
1975 //ProjectItem *item = getItemById(id);
1976 QMap <QString, QString> oldprops;
1977 QMap <QString, QString> newprops;
1978 int ttl = existing.at(0)->getProperty("ttl").toInt();
1979 oldprops["out"] = existing.at(0)->getProperty("out");
1980 newprops["out"] = QString::number(ttl * count - 1);
1981 slotUpdateClipProperties(id, newprops);
1982 EditClipCommand *command = new EditClipCommand(this, id, oldprops, newprops, false);
1983 m_commandStack->push(command);
1986 QStringList groupInfo = getGroup();
1987 m_doc->slotCreateSlideshowClipFile(fileName, pattern, count, m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()),
1988 false, false, false,
1989 m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))), QString(), 0,
1990 QString(), groupInfo.at(0), groupInfo.at(1));
1992 } else emit displayMessage(i18n("Sequence not found"), -2);
1995 QMap <QString, QString> ProjectList::getProxies()
1997 QMap <QString, QString> list;
1999 QTreeWidgetItemIterator it(m_listView);
2001 if ((*it)->type() != PROJECTCLIPTYPE) {
2005 item = static_cast<ProjectItem *>(*it);
2006 if (item && item->referencedClip() != NULL) {
2007 QString proxy = item->referencedClip()->getProperty("proxy");
2008 if (!proxy.isEmpty()) list.insert(proxy, item->clipUrl().path());
2015 void ProjectList::updateProxyConfig()
2018 QTreeWidgetItemIterator it(m_listView);
2020 if ((*it)->type() != PROJECTCLIPTYPE) {
2024 item = static_cast<ProjectItem *>(*it);
2029 CLIPTYPE t = item->clipType();
2030 if ((t == VIDEO || t == AV || t == UNKNOWN) && item->referencedClip() != NULL) {
2032 DocClipBase *clip = item->referencedClip();
2033 connect(clip, SIGNAL(proxyReady(const QString &, bool)), this, SLOT(slotGotProxy(const QString &, bool)));
2034 setProxyStatus(item, 1);
2035 clip->generateProxy(m_doc->projectFolder(), proxyParams());
2037 else if (!item->referencedClip()->getProperty("proxy").isEmpty()) {
2039 item->referencedClip()->clearProperty("proxy");
2040 QDomElement e = item->toXml().cloneNode().toElement();
2041 e.removeAttribute("file_hash");
2042 e.setAttribute("replace", 1);
2043 m_infoQueue.insert(item->clipId(), e);
2048 if (!m_infoQueue.isEmpty() && !m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
2051 void ProjectList::slotProxyCurrentItem(bool doProxy)
2053 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
2054 QTreeWidgetItem *listItem;
2055 for (int i = 0; i < list.count(); i++) {
2056 listItem = list.at(i);
2057 if (listItem->type() == PROJECTFOLDERTYPE) {
2058 for (int j = 0; j < listItem->childCount(); j++) {
2059 QTreeWidgetItem *sub = listItem->child(j);
2060 if (!list.contains(sub)) list.append(sub);
2063 if (listItem->type() == PROJECTCLIPTYPE) {
2064 ProjectItem *item = static_cast <ProjectItem*>(listItem);
2065 CLIPTYPE t = item->clipType();
2066 if ((t == VIDEO || t == AV || t == UNKNOWN) && item->referencedClip()) {
2068 DocClipBase *clip = item->referencedClip();
2069 connect(clip, SIGNAL(proxyReady(const QString&, bool)), this, SLOT(slotGotProxy(const QString&, bool)));
2070 setProxyStatus(item, 1);
2071 clip->generateProxy(m_doc->projectFolder(), proxyParams());
2073 else if (!item->referencedClip()->getProperty("proxy").isEmpty()) {
2075 if (!item->isProxyRunning()) {
2076 setProxyStatus(item, 0);
2077 QDomElement e = item->toXml().cloneNode().toElement();
2078 e.removeAttribute("file_hash");
2079 e.setAttribute("replace", 1);
2080 m_infoQueue.insert(item->clipId(), e);
2082 else setProxyStatus(item, 0);
2087 if (!m_infoQueue.isEmpty() && !m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
2090 void ProjectList::setProxyStatus(ProjectItem *item, int status)
2092 monitorItemEditing(false);
2093 item->setProxyStatus(status);
2094 monitorItemEditing(true);
2097 void ProjectList::monitorItemEditing(bool enable)
2099 if (enable) connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
2100 else disconnect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
2103 #include "projectlist.moc"