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 "editclipcommand.h"
35 #include "editfoldercommand.h"
36 #include "ui_templateclip_ui.h"
41 #include <KFileDialog>
42 #include <KInputDialog>
43 #include <KMessageBox>
44 #include <KIO/NetAccess>
47 #include <nepomuk/global.h>
48 #include <nepomuk/resourcemanager.h>
49 //#include <nepomuk/tag.h>
51 #include <QMouseEvent>
52 #include <QStylePainter>
57 #include <QHeaderView>
59 ProjectList::ProjectList(QWidget *parent) :
68 m_transcodeAction(NULL),
75 m_listView = new ProjectListView(this);;
76 QVBoxLayout *layout = new QVBoxLayout;
77 layout->setContentsMargins(0, 0, 0, 0);
80 KTreeWidgetSearchLine *searchView = new KTreeWidgetSearchLine(this);
81 m_toolbar = new QToolBar("projectToolBar", this);
82 m_toolbar->addWidget(searchView);
83 searchView->setTreeWidget(m_listView);
85 m_addButton = new QToolButton(m_toolbar);
86 m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
87 m_toolbar->addWidget(m_addButton);
89 layout->addWidget(m_toolbar);
90 layout->addWidget(m_listView);
93 m_queueTimer.setInterval(100);
94 connect(&m_queueTimer, SIGNAL(timeout()), this, SLOT(slotProcessNextClipInQueue()));
95 m_queueTimer.setSingleShot(true);
99 connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
100 connect(m_listView, SIGNAL(focusMonitor()), this, SLOT(slotClipSelected()));
101 connect(m_listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
102 connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
103 connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
104 connect(m_listView, SIGNAL(addClip(const QList <QUrl>, const QString &, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &, const QString &)));
105 connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
106 connect(m_listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
108 m_listViewDelegate = new ItemDelegate(m_listView);
109 m_listView->setItemDelegate(m_listViewDelegate);
111 if (KdenliveSettings::activate_nepomuk()) {
112 Nepomuk::ResourceManager::instance()->init();
113 if (!Nepomuk::ResourceManager::instance()->initialized()) {
114 kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
115 KdenliveSettings::setActivate_nepomuk(false);
120 ProjectList::~ProjectList()
124 m_listView->blockSignals(true);
126 delete m_listViewDelegate;
129 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
131 QList <QAction *> actions = addMenu->actions();
132 for (int i = 0; i < actions.count(); i++) {
133 if (actions.at(i)->data().toString() == "clip_properties") {
134 m_editAction = actions.at(i);
135 m_toolbar->addAction(m_editAction);
138 } else if (actions.at(i)->data().toString() == "delete_clip") {
139 m_deleteAction = actions.at(i);
140 m_toolbar->addAction(m_deleteAction);
143 } else if (actions.at(i)->data().toString() == "edit_clip") {
144 m_openAction = actions.at(i);
147 } else if (actions.at(i)->data().toString() == "reload_clip") {
148 m_reloadAction = actions.at(i);
154 QMenu *m = new QMenu();
155 m->addActions(actions);
156 m_addButton->setMenu(m);
157 m_addButton->setDefaultAction(defaultAction);
158 m_menu = new QMenu();
159 m_menu->addActions(addMenu->actions());
162 void ProjectList::setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu)
164 if (!addMenu) return;
165 QMenu *menu = m_addButton->menu();
166 menu->addMenu(addMenu);
167 m_addButton->setMenu(menu);
169 m_menu->addMenu(addMenu);
170 if (addMenu->isEmpty()) addMenu->setEnabled(false);
171 m_menu->addMenu(transcodeMenu);
172 if (transcodeMenu->isEmpty()) transcodeMenu->setEnabled(false);
173 m_transcodeAction = transcodeMenu;
174 m_menu->addAction(m_reloadAction);
175 m_menu->addAction(m_editAction);
176 m_menu->addAction(m_openAction);
177 m_menu->addAction(m_deleteAction);
178 m_menu->insertSeparator(m_deleteAction);
182 QByteArray ProjectList::headerInfo() const
184 return m_listView->header()->saveState();
187 void ProjectList::setHeaderInfo(const QByteArray &state)
189 m_listView->header()->restoreState(state);
192 void ProjectList::slotEditClip()
194 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
195 if (!(item->flags() & Qt::ItemIsDragEnabled)) return;
196 if (item && !item->isGroup()) {
197 emit clipSelected(item->referencedClip());
198 emit showClipProperties(item->referencedClip());
202 void ProjectList::slotOpenClip()
204 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
205 if (item && !item->isGroup()) {
206 if (item->clipType() == IMAGE) {
207 if (KdenliveSettings::defaultimageapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open images in the Settings dialog"));
208 else QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
210 if (item->clipType() == AUDIO) {
211 if (KdenliveSettings::defaultaudioapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open audio files in the Settings dialog"));
212 else QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
217 void ProjectList::cleanup()
219 m_listView->clearSelection();
220 QTreeWidgetItemIterator it(m_listView);
223 item = static_cast <ProjectItem *>(*it);
224 if (item->numReferences() == 0) item->setSelected(true);
230 void ProjectList::trashUnusedClips()
232 QTreeWidgetItemIterator it(m_listView);
237 item = static_cast <ProjectItem *>(*it);
238 if (item->numReferences() == 0) {
239 ids << item->clipId();
240 KUrl url = item->clipUrl();
241 if (!url.isEmpty()) urls << url;
245 m_doc->deleteProjectClip(ids);
246 for (int i = 0; i < urls.count(); i++) {
247 KIO::NetAccess::del(urls.at(i), this);
251 void ProjectList::slotReloadClip(const QString &id)
253 QList<QTreeWidgetItem *> selected;
254 if (id.isEmpty()) selected = m_listView->selectedItems();
255 else selected.append(getItemById(id));
257 for (int i = 0; i < selected.count(); i++) {
258 item = static_cast <ProjectItem *>(selected.at(i));
259 if (item && !item->isGroup()) {
260 if (item->clipType() == IMAGE) {
261 item->referencedClip()->producer()->set("force_reload", 1);
262 } else if (item->clipType() == TEXT) {
263 if (!item->referencedClip()->getProperty("xmltemplate").isEmpty()) regenerateTemplate(item);
265 //requestClipInfo(item->toXml(), item->clipId(), true);
266 // Clear the file_hash value, which will cause a complete reload of the clip
267 emit getFileProperties(item->toXml(), item->clipId(), true);
272 void ProjectList::setRenderer(Render *projectRender)
274 m_render = projectRender;
275 m_listView->setIconSize(QSize(40 * m_render->dar(), 40));
278 void ProjectList::slotClipSelected()
280 if (m_listView->currentItem()) {
281 ProjectItem *clip = static_cast <ProjectItem*>(m_listView->currentItem());
282 if (!clip->isGroup()) {
283 m_selectedItem = clip;
284 emit clipSelected(clip->referencedClip());
286 m_editAction->setEnabled(true);
287 m_deleteAction->setEnabled(true);
288 m_reloadAction->setEnabled(true);
289 m_transcodeAction->setEnabled(true);
290 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
291 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
292 m_openAction->setEnabled(true);
293 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
294 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
295 m_openAction->setEnabled(true);
296 } else m_openAction->setEnabled(false);
298 emit clipSelected(NULL);
299 m_editAction->setEnabled(false);
300 m_deleteAction->setEnabled(false);
301 m_openAction->setEnabled(false);
302 m_reloadAction->setEnabled(false);
303 m_transcodeAction->setEnabled(false);
307 void ProjectList::slotPauseMonitor()
309 if (m_render) m_render->pause();
312 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
314 ProjectItem *item = getItemById(id);
316 slotUpdateClipProperties(item, properties);
317 if (properties.contains("colour") || properties.contains("resource") || properties.contains("xmldata") || properties.contains("force_aspect_ratio") || properties.contains("templatetext")) {
318 slotRefreshClipThumbnail(item);
321 if (properties.contains("out")) item->changeDuration(properties.value("out").toInt());
325 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
328 if (!clip->isGroup()) clip->setProperties(properties);
329 if (properties.contains("name")) {
330 m_listView->blockSignals(true);
331 clip->setText(1, properties.value("name"));
332 m_listView->blockSignals(false);
333 emit clipNameChanged(clip->clipId(), properties.value("name"));
335 if (properties.contains("description")) {
336 CLIPTYPE type = clip->clipType();
337 m_listView->blockSignals(true);
338 clip->setText(2, properties.value("description"));
339 m_listView->blockSignals(false);
340 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
341 // Use Nepomuk system to store clip description
342 Nepomuk::Resource f(clip->clipUrl().path());
343 f.setDescription(properties.value("description"));
345 emit projectModified();
349 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
351 ProjectItem *clip = static_cast <ProjectItem*>(item);
353 if (clip->referencedClip()) {
354 QMap <QString, QString> oldprops;
355 QMap <QString, QString> newprops;
356 oldprops["description"] = clip->referencedClip()->getProperty("description");
357 newprops["description"] = item->text(2);
359 if (clip->clipType() == TEXT) {
360 // This is a text template clip, update the image
361 /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
362 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/
363 oldprops.insert("templatetext", clip->referencedClip()->getProperty("templatetext"));
364 newprops.insert("templatetext", item->text(2));
366 slotUpdateClipProperties(clip->clipId(), newprops);
367 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
368 m_commandStack->push(command);
370 } else if (column == 1) {
371 if (clip->isGroup()) {
372 editFolder(item->text(1), clip->groupName(), clip->clipId());
373 clip->setGroupName(item->text(1));
374 m_doc->clipManager()->addFolder(clip->clipId(), item->text(1));
375 const int children = item->childCount();
376 for (int i = 0; i < children; i++) {
377 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
378 child->setProperty("groupname", item->text(1));
381 if (clip->referencedClip()) {
382 QMap <QString, QString> oldprops;
383 QMap <QString, QString> newprops;
384 oldprops["name"] = clip->referencedClip()->getProperty("name");
385 newprops["name"] = item->text(1);
386 slotUpdateClipProperties(clip, newprops);
387 emit projectModified();
388 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
389 m_commandStack->push(command);
395 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
401 m_editAction->setEnabled(enable);
402 m_deleteAction->setEnabled(enable);
403 m_reloadAction->setEnabled(enable);
404 m_transcodeAction->setEnabled(enable);
406 ProjectItem *clip = static_cast <ProjectItem*>(item);
407 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
408 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
409 m_openAction->setEnabled(true);
410 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
411 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
412 m_openAction->setEnabled(true);
413 } else m_openAction->setEnabled(false);
414 } else m_openAction->setEnabled(false);
418 void ProjectList::slotRemoveClip()
420 if (!m_listView->currentItem()) return;
422 QMap <QString, QString> folderids;
423 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
425 for (int i = 0; i < selected.count(); i++) {
426 item = static_cast <ProjectItem *>(selected.at(i));
427 if (item->isGroup()) folderids[item->groupName()] = item->clipId();
428 else ids << item->clipId();
429 if (item->numReferences() > 0) {
430 if (KMessageBox::questionYesNo(this, 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")) != KMessageBox::Yes) return;
431 } else if (item->isGroup() && item->childCount() > 0) {
432 int children = item->childCount();
433 if (KMessageBox::questionYesNo(this, 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, item->names().at(1)), i18n("Delete Folder")) != KMessageBox::Yes) return;
434 for (int i = 0; i < children; ++i) {
435 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
436 ids << child->clipId();
440 if (!ids.isEmpty()) m_doc->deleteProjectClip(ids);
441 if (!folderids.isEmpty()) deleteProjectFolder(folderids);
442 if (m_listView->topLevelItemCount() == 0) {
443 m_editAction->setEnabled(false);
444 m_deleteAction->setEnabled(false);
445 m_openAction->setEnabled(false);
446 m_reloadAction->setEnabled(false);
447 m_transcodeAction->setEnabled(false);
451 void ProjectList::selectItemById(const QString &clipId)
453 ProjectItem *item = getItemById(clipId);
454 if (item) m_listView->setCurrentItem(item);
458 void ProjectList::slotDeleteClip(const QString &clipId)
460 ProjectItem *item = getItemById(clipId);
462 kDebug() << "/// Cannot find clip to delete";
465 m_listView->blockSignals(true);
467 m_doc->clipManager()->deleteClip(clipId);
468 m_listView->blockSignals(false);
473 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
475 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
476 m_commandStack->push(command);
477 m_doc->setModified(true);
480 void ProjectList::slotAddFolder()
482 AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
483 m_commandStack->push(command);
486 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
489 ProjectItem *item = getFolderItemById(clipId);
491 m_doc->clipManager()->deleteFolder(clipId);
496 ProjectItem *item = getFolderItemById(clipId);
498 m_listView->blockSignals(true);
499 item->setGroupName(foldername);
500 m_listView->blockSignals(false);
501 m_doc->clipManager()->addFolder(clipId, foldername);
502 const int children = item->childCount();
503 for (int i = 0; i < children; i++) {
504 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
505 child->setProperty("groupname", foldername);
510 text << QString() << foldername;
511 m_listView->blockSignals(true);
512 m_listView->setCurrentItem(new ProjectItem(m_listView, text, clipId));
513 m_doc->clipManager()->addFolder(clipId, foldername);
514 m_listView->blockSignals(false);
521 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
523 QMapIterator<QString, QString> i(map);
524 QUndoCommand *delCommand = new QUndoCommand();
525 delCommand->setText(i18n("Delete Folder"));
526 while (i.hasNext()) {
528 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
530 m_commandStack->push(delCommand);
531 m_doc->setModified(true);
534 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
536 m_listView->setEnabled(false);
538 m_listView->blockSignals(true);
540 // remove file_hash so that we load all properties for the clip
541 QDomElement e = clip->toXML().cloneNode().toElement();
542 e.removeAttribute("file_hash");
543 m_infoQueue.insert(clip->getId(), e);
544 //m_render->getFileProperties(clip->toXML(), clip->getId(), true);
546 const QString parent = clip->getProperty("groupid");
547 kDebug() << "Adding clip with groupid: " << parent;
548 ProjectItem *item = NULL;
549 if (!parent.isEmpty()) {
550 ProjectItem *parentitem = getFolderItemById(parent);
553 QString groupName = clip->getProperty("groupname");
554 //kDebug() << "Adding clip to new group: " << groupName;
555 if (groupName.isEmpty()) groupName = i18n("Folder");
556 text << QString() << groupName;
557 parentitem = new ProjectItem(m_listView, text, parent);
559 //kDebug() << "Adding clip to existing group: " << parentitem->groupName();
561 if (parentitem) item = new ProjectItem(parentitem, clip);
563 if (item == NULL) item = new ProjectItem(m_listView, clip);
564 KUrl url = clip->fileURL();
566 if (getProperties == false && !clip->getClipHash().isEmpty()) {
567 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
568 if (QFile::exists(cachedPixmap)) {
569 item->setIcon(0, QPixmap(cachedPixmap));
573 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
574 // if file has Nepomuk comment, use it
575 Nepomuk::Resource f(url.path());
576 QString annotation = f.description();
577 if (!annotation.isEmpty()) item->setText(2, annotation);
578 item->setText(3, QString::number(f.rating()));
580 if (getProperties && m_listView->isEnabled()) m_listView->blockSignals(false);
581 if (getProperties && !m_queueTimer.isActive()) m_queueTimer.start();
584 void ProjectList::slotResetProjectList()
587 emit clipSelected(NULL);
588 m_thumbnailQueue.clear();
593 void ProjectList::requestClipInfo(const QDomElement xml, const QString id)
596 m_infoQueue.insert(id, xml);
597 //if (m_infoQueue.count() == 1 || ) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
600 void ProjectList::slotProcessNextClipInQueue()
602 if (m_infoQueue.isEmpty()) {
603 slotProcessNextThumbnail();
607 QMap<QString, QDomElement>::const_iterator j = m_infoQueue.constBegin();
608 if (j != m_infoQueue.constEnd()) {
609 const QDomElement dom = j.value();
610 const QString id = j.key();
611 m_infoQueue.remove(j.key());
612 emit getFileProperties(dom, id, false);
615 if (!m_infoQueue.isEmpty() && !m_queueTimer.isActive()) m_queueTimer.start();
618 void ProjectList::slotUpdateClip(const QString &id)
620 ProjectItem *item = getItemById(id);
621 m_listView->blockSignals(true);
622 if (item) item->setData(1, UsageRole, QString::number(item->numReferences()));
623 m_listView->blockSignals(false);
626 void ProjectList::updateAllClips()
628 m_listView->setSortingEnabled(false);
630 QTreeWidgetItemIterator it(m_listView);
633 m_listView->blockSignals(true);
635 item = static_cast <ProjectItem *>(*it);
636 if (!item->isGroup()) {
637 clip = item->referencedClip();
638 if (item->referencedClip()->producer() == NULL) {
639 if (clip->isPlaceHolder() == false) {
640 requestClipInfo(clip->toXML(), clip->getId());
641 } else item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
643 if (item->icon(0).isNull()) {
644 requestClipThumbnail(clip->getId());
646 if (item->data(1, DurationRole).toString().isEmpty()) {
647 item->changeDuration(item->referencedClip()->producer()->get_playtime());
650 item->setData(1, UsageRole, QString::number(item->numReferences()));
651 //qApp->processEvents();
655 qApp->processEvents();
656 if (!m_queueTimer.isActive()) m_queueTimer.start();
658 if (m_listView->isEnabled()) m_listView->blockSignals(false);
659 m_listView->setSortingEnabled(true);
660 if (m_infoQueue.isEmpty()) slotProcessNextThumbnail();
663 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
665 if (!m_commandStack) {
666 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
669 if (givenList.isEmpty()) {
670 // Build list of mime types
671 QStringList mimeTypes = QStringList() << "application/x-kdenlive" << "application/x-kdenlivetitle" << "video/x-flv" << "application/vnd.rn-realmedia" << "video/x-dv" << "video/dv" << "video/x-msvideo" << "video/x-matroska" << "video/mlt-playlist" << "video/mpeg" << "video/ogg" << "video/x-ms-wmv" << "audio/x-flac" << "audio/x-matroska" << "audio/mp4" << "audio/mpeg" << "audio/x-mp3" << "audio/ogg" << "audio/x-wav" << "application/ogg" << "video/mp4" << "video/quicktime" << "image/gif" << "image/jpeg" << "image/png" << "image/x-tga" << "image/x-bmp" << "image/svg+xml" << "image/tiff" << "image/x-xcf-gimp" << "image/x-vnd.adobe.photoshop" << "image/x-pcx" << "image/x-exr";
673 QString allExtensions;
674 foreach(const QString& mimeType, mimeTypes) {
675 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
677 allExtensions.append(mime->patterns().join(" "));
678 allExtensions.append(' ');
681 const QString dialogFilter = allExtensions.simplified() + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
682 list = KFileDialog::getOpenUrls(KUrl("kfiledialog:///clipfolder"), dialogFilter, this);
685 for (int i = 0; i < givenList.count(); i++)
686 list << givenList.at(i);
688 if (list.isEmpty()) return;
690 if (givenList.isEmpty()) {
691 QStringList groupInfo = getGroup();
692 m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1));
693 } else m_doc->slotAddClipList(list, groupName, groupId);
696 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
698 ProjectItem *item = getItemById(id);
699 QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
701 const QString path = item->referencedClip()->fileURL().path();
702 if (!path.isEmpty()) {
703 if (replace) KMessageBox::sorry(this, i18n("Clip <b>%1</b><br>is invalid, will be removed from project.", path));
705 if (KMessageBox::questionYesNo(this, i18n("Clip <b>%1</b><br>is missing or invalid. Remove it from project?", path), i18n("Invalid clip")) == KMessageBox::Yes) replace = true;
710 if (replace) m_doc->deleteProjectClip(ids);
714 void ProjectList::slotAddColorClip()
716 if (!m_commandStack) {
717 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
719 QDialog *dia = new QDialog(this);
720 Ui::ColorClip_UI dia_ui;
722 dia_ui.clip_name->setText(i18n("Color Clip"));
723 dia_ui.clip_duration->setText(KdenliveSettings::color_duration());
724 if (dia->exec() == QDialog::Accepted) {
725 QString color = dia_ui.clip_color->color().name();
726 color = color.replace(0, 1, "0x") + "ff";
727 QStringList groupInfo = getGroup();
728 m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, dia_ui.clip_duration->text(), groupInfo.at(0), groupInfo.at(1));
734 void ProjectList::slotAddSlideshowClip()
736 if (!m_commandStack) {
737 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
739 SlideshowClip *dia = new SlideshowClip(m_timecode, this);
741 if (dia->exec() == QDialog::Accepted) {
742 QStringList groupInfo = getGroup();
743 m_doc->slotCreateSlideshowClipFile(dia->clipName(), dia->selectedPath(), dia->imageCount(), dia->clipDuration(), dia->loop(), dia->fade(), dia->lumaDuration(), dia->lumaFile(), dia->softness(), groupInfo.at(0), groupInfo.at(1));
748 void ProjectList::slotAddTitleClip()
750 QStringList groupInfo = getGroup();
751 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
754 void ProjectList::slotAddTitleTemplateClip()
756 QStringList groupInfo = getGroup();
757 if (!m_commandStack) {
758 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
761 // Get the list of existing templates
763 filter << "*.kdenlivetitle";
764 const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
765 QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
767 QDialog *dia = new QDialog(this);
768 Ui::TemplateClip_UI dia_ui;
770 for (int i = 0; i < templateFiles.size(); ++i) {
771 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
773 dia_ui.template_list->fileDialog()->setFilter("*.kdenlivetitle");
774 //warning: setting base directory doesn't work??
776 dia_ui.template_list->fileDialog()->setUrl(startDir);
777 dia_ui.text_box->setHidden(true);
778 if (dia->exec() == QDialog::Accepted) {
779 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
780 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
781 // Create a cloned template clip
782 m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
787 QStringList ProjectList::getGroup() const
790 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
791 if (item && !item->isGroup()) {
792 while (item->parent()) {
793 item = static_cast <ProjectItem*>(item->parent());
794 if (item->isGroup()) break;
797 if (item && item->isGroup()) {
798 result << item->groupName();
799 result << item->clipId();
800 } else result << QString() << QString();
804 void ProjectList::setDocument(KdenliveDoc *doc)
806 m_listView->blockSignals(true);
808 m_listView->setSortingEnabled(false);
809 emit clipSelected(NULL);
810 m_thumbnailQueue.clear();
814 m_timecode = doc->timecode();
815 m_commandStack = doc->commandStack();
818 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
819 QMapIterator<QString, QString> f(flist);
820 while (f.hasNext()) {
822 (void) new ProjectItem(m_listView, QStringList() << QString() << f.value(), f.key());
825 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
826 for (int i = 0; i < list.count(); i++) {
827 slotAddClip(list.at(i), false);
830 m_listView->blockSignals(false);
831 m_toolbar->setEnabled(true);
832 connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
833 connect(m_doc->clipManager(), SIGNAL(checkAllClips()), this, SLOT(updateAllClips()));
836 QDomElement ProjectList::producersList()
839 QDomElement prods = doc.createElement("producerlist");
840 doc.appendChild(prods);
841 kDebug() << "//////////// PRO LISTĀ BUILD PRDSLIST ";
842 QTreeWidgetItemIterator it(m_listView);
844 if (!((ProjectItem *)(*it))->isGroup())
845 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
851 void ProjectList::slotCheckForEmptyQueue()
853 if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
855 emit loadingIsOver();
856 emit displayMessage(QString(), DefaultMessage);
857 m_listView->blockSignals(false);
858 m_listView->setEnabled(true);
859 } else if (!m_refreshed) QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
862 void ProjectList::reloadClipThumbnails()
864 m_thumbnailQueue.clear();
865 QTreeWidgetItemIterator it(m_listView);
867 if (!((ProjectItem *)(*it))->isGroup())
868 m_thumbnailQueue << ((ProjectItem *)(*it))->clipId();
871 QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
874 void ProjectList::requestClipThumbnail(const QString id)
876 m_thumbnailQueue.append(id);
879 void ProjectList::slotProcessNextThumbnail()
881 if (m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
882 slotCheckForEmptyQueue();
885 if (!m_infoQueue.isEmpty()) {
886 //QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
889 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
890 if (m_thumbnailQueue.count() > 1) {
891 emit displayMessage(i18n("Loading clips (%1)", m_thumbnailQueue.count()), InformationMessage);
892 qApp->processEvents();
896 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
898 ProjectItem *item = getItemById(clipId);
899 if (item) slotRefreshClipThumbnail(item, update);
900 else slotProcessNextThumbnail();
903 void ProjectList::slotRefreshClipThumbnail(ProjectItem *item, bool update)
906 DocClipBase *clip = item->referencedClip();
908 slotProcessNextThumbnail();
913 int width = (int)(height * m_render->dar());
914 if (clip->clipType() == AUDIO) pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
915 else if (clip->clipType() == IMAGE) pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->producer(), 0, width, height));
916 else pix = item->referencedClip()->thumbProducer()->extractImage(item->referencedClip()->getClipThumbFrame(), width, height);
918 m_listView->blockSignals(true);
919 item->setIcon(0, pix);
920 if (m_listView->isEnabled()) m_listView->blockSignals(false);
921 m_doc->cachePixmap(item->getClipHash(), pix);
923 if (update) emit projectModified();
924 QTimer::singleShot(100, this, SLOT(slotProcessNextThumbnail()));
928 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace)
930 ProjectItem *item = getItemById(clipId);
931 if (item && producer) {
932 m_listView->blockSignals(true);
933 item->setProperties(properties, metadata);
934 Q_ASSERT_X(item->referencedClip(), "void ProjectList::slotReplyGetFileProperties", QString("Item with groupName %1 does not have a clip associated").arg(item->groupName()).toLatin1());
935 item->referencedClip()->setProducer(producer, replace);
936 //emit receivedClipDuration(clipId);
937 if (m_listView->isEnabled() && replace) {
938 // update clip in clip monitor
939 emit clipSelected(NULL);
940 emit clipSelected(item->referencedClip());
943 // Check if duration changed.
944 emit receivedClipDuration(clipId);
947 if (m_listView->isEnabled()) m_listView->blockSignals(false);
948 if (item->icon(0).isNull()) {
949 requestClipThumbnail(clipId);
951 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
953 slotProcessNextClipInQueue();
956 void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
958 ProjectItem *item = getItemById(clipId);
959 if (item && !pix.isNull()) {
960 m_listView->blockSignals(true);
961 item->setIcon(0, pix);
962 m_doc->cachePixmap(item->getClipHash(), pix);
963 if (m_listView->isEnabled()) m_listView->blockSignals(false);
967 ProjectItem *ProjectList::getItemById(const QString &id)
970 QTreeWidgetItemIterator it(m_listView);
972 item = static_cast<ProjectItem *>(*it);
973 if (item->clipId() == id && item->clipType() != FOLDER)
980 ProjectItem *ProjectList::getFolderItemById(const QString &id)
983 QTreeWidgetItemIterator it(m_listView);
985 item = static_cast<ProjectItem *>(*it);
986 if (item->clipId() == id && item->clipType() == FOLDER)
993 void ProjectList::slotSelectClip(const QString &ix)
995 ProjectItem *clip = getItemById(ix);
997 m_listView->setCurrentItem(clip);
998 m_listView->scrollToItem(clip);
999 m_editAction->setEnabled(true);
1000 m_deleteAction->setEnabled(true);
1001 m_reloadAction->setEnabled(true);
1002 m_transcodeAction->setEnabled(true);
1003 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
1004 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
1005 m_openAction->setEnabled(true);
1006 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
1007 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
1008 m_openAction->setEnabled(true);
1009 } else m_openAction->setEnabled(false);
1013 QString ProjectList::currentClipUrl() const
1015 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
1016 if (item == NULL) return QString();
1017 return item->clipUrl().path();
1020 void ProjectList::regenerateTemplate(const QString &id)
1022 ProjectItem *clip = getItemById(id);
1023 if (clip) regenerateTemplate(clip);
1026 void ProjectList::regenerateTemplate(ProjectItem *clip)
1028 //TODO: remove this unused method, only force_reload is necessary
1029 clip->referencedClip()->producer()->set("force_reload", 1);
1032 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
1036 if (!file.open(QIODevice::ReadOnly)) {
1037 kWarning() << "ERROR, CANNOT READ: " << path;
1040 if (!doc.setContent(&file)) {
1041 kWarning() << "ERROR, CANNOT READ: " << path;
1046 QDomNodeList texts = doc.elementsByTagName("content");
1047 for (int i = 0; i < texts.count(); i++) {
1048 QString data = texts.item(i).firstChild().nodeValue();
1049 data.replace("%s", replaceString);
1050 texts.item(i).firstChild().setNodeValue(data);
1055 #include "projectlist.moc"