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 ProjectItem *item = NULL;
548 if (!parent.isEmpty()) {
549 ProjectItem *parentitem = getFolderItemById(parent);
552 QString groupName = clip->getProperty("groupname");
553 //kDebug() << "Adding clip to new group: " << groupName;
554 if (groupName.isEmpty()) groupName = i18n("Folder");
555 text << QString() << groupName;
556 parentitem = new ProjectItem(m_listView, text, parent);
558 //kDebug() << "Adding clip to existing group: " << parentitem->groupName();
560 if (parentitem) item = new ProjectItem(parentitem, clip);
562 if (item == NULL) item = new ProjectItem(m_listView, clip);
563 KUrl url = clip->fileURL();
565 if (getProperties == false && !clip->getClipHash().isEmpty()) {
566 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
567 if (QFile::exists(cachedPixmap)) {
568 item->setIcon(0, QPixmap(cachedPixmap));
572 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
573 // if file has Nepomuk comment, use it
574 Nepomuk::Resource f(url.path());
575 QString annotation = f.description();
576 if (!annotation.isEmpty()) item->setText(2, annotation);
577 item->setText(3, QString::number(f.rating()));
579 if (getProperties && m_listView->isEnabled()) m_listView->blockSignals(false);
580 if (getProperties && !m_queueTimer.isActive()) m_queueTimer.start();
583 void ProjectList::slotResetProjectList()
586 emit clipSelected(NULL);
587 m_thumbnailQueue.clear();
592 void ProjectList::requestClipInfo(const QDomElement xml, const QString id)
595 m_infoQueue.insert(id, xml);
596 //if (m_infoQueue.count() == 1 || ) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
599 void ProjectList::slotProcessNextClipInQueue()
601 if (m_infoQueue.isEmpty()) {
602 slotProcessNextThumbnail();
606 QMap<QString, QDomElement>::const_iterator j = m_infoQueue.constBegin();
607 if (j != m_infoQueue.constEnd()) {
608 const QDomElement dom = j.value();
609 const QString id = j.key();
610 m_infoQueue.remove(j.key());
611 emit getFileProperties(dom, id, false);
613 //if (!m_infoQueue.isEmpty() && !m_queueTimer.isActive()) m_queueTimer.start();
616 void ProjectList::slotUpdateClip(const QString &id)
618 ProjectItem *item = getItemById(id);
619 m_listView->blockSignals(true);
620 if (item) item->setData(1, UsageRole, QString::number(item->numReferences()));
621 m_listView->blockSignals(false);
624 void ProjectList::updateAllClips()
626 m_listView->setSortingEnabled(false);
628 QTreeWidgetItemIterator it(m_listView);
631 m_listView->blockSignals(true);
633 item = static_cast <ProjectItem *>(*it);
634 if (!item->isGroup()) {
635 clip = item->referencedClip();
636 if (item->referencedClip()->producer() == NULL) {
637 if (clip->isPlaceHolder() == false) {
638 requestClipInfo(clip->toXML(), clip->getId());
639 } else item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
641 if (item->icon(0).isNull()) {
642 requestClipThumbnail(clip->getId());
644 if (item->data(1, DurationRole).toString().isEmpty()) {
645 item->changeDuration(item->referencedClip()->producer()->get_playtime());
648 item->setData(1, UsageRole, QString::number(item->numReferences()));
649 //qApp->processEvents();
653 qApp->processEvents();
654 if (!m_queueTimer.isActive()) m_queueTimer.start();
656 if (m_listView->isEnabled()) m_listView->blockSignals(false);
657 m_listView->setSortingEnabled(true);
658 if (m_infoQueue.isEmpty()) slotProcessNextThumbnail();
661 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
663 if (!m_commandStack) {
664 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
667 if (givenList.isEmpty()) {
668 // Build list of mime types
669 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";
671 QString allExtensions;
672 foreach(const QString& mimeType, mimeTypes) {
673 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
675 allExtensions.append(mime->patterns().join(" "));
676 allExtensions.append(' ');
679 const QString dialogFilter = allExtensions.simplified() + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
680 list = KFileDialog::getOpenUrls(KUrl("kfiledialog:///clipfolder"), dialogFilter, this);
683 for (int i = 0; i < givenList.count(); i++)
684 list << givenList.at(i);
686 if (list.isEmpty()) return;
688 if (givenList.isEmpty()) {
689 QStringList groupInfo = getGroup();
690 m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1));
691 } else m_doc->slotAddClipList(list, groupName, groupId);
694 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
696 ProjectItem *item = getItemById(id);
697 QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
699 const QString path = item->referencedClip()->fileURL().path();
700 if (!path.isEmpty()) {
701 if (replace) KMessageBox::sorry(this, i18n("Clip <b>%1</b><br>is invalid, will be removed from project.", path));
703 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;
708 if (replace) m_doc->deleteProjectClip(ids);
712 void ProjectList::slotAddColorClip()
714 if (!m_commandStack) {
715 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
717 QDialog *dia = new QDialog(this);
718 Ui::ColorClip_UI dia_ui;
720 dia_ui.clip_name->setText(i18n("Color Clip"));
721 dia_ui.clip_duration->setText(KdenliveSettings::color_duration());
722 if (dia->exec() == QDialog::Accepted) {
723 QString color = dia_ui.clip_color->color().name();
724 color = color.replace(0, 1, "0x") + "ff";
725 QStringList groupInfo = getGroup();
726 m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, dia_ui.clip_duration->text(), groupInfo.at(0), groupInfo.at(1));
732 void ProjectList::slotAddSlideshowClip()
734 if (!m_commandStack) {
735 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
737 SlideshowClip *dia = new SlideshowClip(m_timecode, this);
739 if (dia->exec() == QDialog::Accepted) {
740 QStringList groupInfo = getGroup();
741 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));
746 void ProjectList::slotAddTitleClip()
748 QStringList groupInfo = getGroup();
749 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
752 void ProjectList::slotAddTitleTemplateClip()
754 QStringList groupInfo = getGroup();
755 if (!m_commandStack) {
756 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
759 // Get the list of existing templates
761 filter << "*.kdenlivetitle";
762 const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
763 QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
765 QDialog *dia = new QDialog(this);
766 Ui::TemplateClip_UI dia_ui;
768 for (int i = 0; i < templateFiles.size(); ++i) {
769 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
771 dia_ui.template_list->fileDialog()->setFilter("*.kdenlivetitle");
772 //warning: setting base directory doesn't work??
774 dia_ui.template_list->fileDialog()->setUrl(startDir);
775 dia_ui.text_box->setHidden(true);
776 if (dia->exec() == QDialog::Accepted) {
777 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
778 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
779 // Create a cloned template clip
780 m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
785 QStringList ProjectList::getGroup() const
788 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
789 if (item && !item->isGroup()) {
790 while (item->parent()) {
791 item = static_cast <ProjectItem*>(item->parent());
792 if (item->isGroup()) break;
795 if (item && item->isGroup()) {
796 result << item->groupName();
797 result << item->clipId();
798 } else result << QString() << QString();
802 void ProjectList::setDocument(KdenliveDoc *doc)
804 m_listView->blockSignals(true);
806 m_listView->setSortingEnabled(false);
807 emit clipSelected(NULL);
808 m_thumbnailQueue.clear();
812 m_timecode = doc->timecode();
813 m_commandStack = doc->commandStack();
816 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
817 QMapIterator<QString, QString> f(flist);
818 while (f.hasNext()) {
820 (void) new ProjectItem(m_listView, QStringList() << QString() << f.value(), f.key());
823 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
824 for (int i = 0; i < list.count(); i++) {
825 slotAddClip(list.at(i), false);
828 m_listView->blockSignals(false);
829 m_toolbar->setEnabled(true);
830 connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
831 connect(m_doc->clipManager(), SIGNAL(checkAllClips()), this, SLOT(updateAllClips()));
834 QDomElement ProjectList::producersList()
837 QDomElement prods = doc.createElement("producerlist");
838 doc.appendChild(prods);
839 kDebug() << "//////////// PRO LISTĀ BUILD PRDSLIST ";
840 QTreeWidgetItemIterator it(m_listView);
842 if (!((ProjectItem *)(*it))->isGroup())
843 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
849 void ProjectList::slotCheckForEmptyQueue()
851 if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
853 emit loadingIsOver();
854 emit displayMessage(QString(), -1);
855 m_listView->blockSignals(false);
856 m_listView->setEnabled(true);
857 } else if (!m_refreshed) QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
860 void ProjectList::reloadClipThumbnails()
862 kDebug() << "////////////// RELOAD CLIPS THUMBNAILS!!!";
863 m_thumbnailQueue.clear();
864 QTreeWidgetItemIterator it(m_listView);
866 if (!((ProjectItem *)(*it))->isGroup())
867 m_thumbnailQueue << ((ProjectItem *)(*it))->clipId();
870 QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
873 void ProjectList::requestClipThumbnail(const QString id)
875 if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id);
878 void ProjectList::slotProcessNextThumbnail()
880 if (m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
881 slotCheckForEmptyQueue();
884 if (!m_infoQueue.isEmpty()) {
885 //QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
888 if (m_thumbnailQueue.count() > 1) {
889 int max = m_doc->clipManager()->clipsCount();
890 emit displayMessage(i18n("Loading thumbnails"), (int)(100 * (max - m_thumbnailQueue.count()) / max));
892 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
895 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
897 ProjectItem *item = getItemById(clipId);
898 if (item) slotRefreshClipThumbnail(item, update);
899 else slotProcessNextThumbnail();
902 void ProjectList::slotRefreshClipThumbnail(ProjectItem *item, bool update)
905 DocClipBase *clip = item->referencedClip();
907 slotProcessNextThumbnail();
912 int width = (int)(height * m_render->dar());
913 if (clip->clipType() == AUDIO) pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
914 else if (clip->clipType() == IMAGE) pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->producer(), 0, width, height));
915 else pix = item->referencedClip()->thumbProducer()->extractImage(item->referencedClip()->getClipThumbFrame(), width, height);
917 m_listView->blockSignals(true);
918 item->setIcon(0, pix);
919 if (m_listView->isEnabled()) m_listView->blockSignals(false);
920 m_doc->cachePixmap(item->getClipHash(), pix);
922 if (update) emit projectModified();
923 QTimer::singleShot(30, this, SLOT(slotProcessNextThumbnail()));
927 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace)
929 ProjectItem *item = getItemById(clipId);
930 if (item && producer) {
931 m_listView->blockSignals(true);
932 item->setProperties(properties, metadata);
933 Q_ASSERT_X(item->referencedClip(), "void ProjectList::slotReplyGetFileProperties", QString("Item with groupName %1 does not have a clip associated").arg(item->groupName()).toLatin1());
934 item->referencedClip()->setProducer(producer, replace);
935 //emit receivedClipDuration(clipId);
936 if (m_listView->isEnabled() && replace) {
937 // update clip in clip monitor
938 emit clipSelected(NULL);
939 emit clipSelected(item->referencedClip());
942 // Check if duration changed.
943 emit receivedClipDuration(clipId);
946 if (m_listView->isEnabled()) m_listView->blockSignals(false);
947 if (item->icon(0).isNull()) {
948 requestClipThumbnail(clipId);
950 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
951 int max = m_doc->clipManager()->clipsCount();
952 emit displayMessage(i18n("Loading clips"), (int)(100 * (max - m_infoQueue.count()) / max));
953 // small delay so that the app can display the progress info
954 QTimer::singleShot(30, this, SLOT(slotProcessNextClipInQueue()));
957 void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
959 ProjectItem *item = getItemById(clipId);
960 if (item && !pix.isNull()) {
961 m_listView->blockSignals(true);
962 item->setIcon(0, pix);
963 m_doc->cachePixmap(item->getClipHash(), pix);
964 if (m_listView->isEnabled()) m_listView->blockSignals(false);
968 ProjectItem *ProjectList::getItemById(const QString &id)
971 QTreeWidgetItemIterator it(m_listView);
973 item = static_cast<ProjectItem *>(*it);
974 if (item->clipId() == id && item->clipType() != FOLDER)
981 ProjectItem *ProjectList::getFolderItemById(const QString &id)
984 QTreeWidgetItemIterator it(m_listView);
986 item = static_cast<ProjectItem *>(*it);
987 if (item->clipId() == id && item->clipType() == FOLDER)
994 void ProjectList::slotSelectClip(const QString &ix)
996 ProjectItem *clip = getItemById(ix);
998 m_listView->setCurrentItem(clip);
999 m_listView->scrollToItem(clip);
1000 m_editAction->setEnabled(true);
1001 m_deleteAction->setEnabled(true);
1002 m_reloadAction->setEnabled(true);
1003 m_transcodeAction->setEnabled(true);
1004 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
1005 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
1006 m_openAction->setEnabled(true);
1007 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
1008 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
1009 m_openAction->setEnabled(true);
1010 } else m_openAction->setEnabled(false);
1014 QString ProjectList::currentClipUrl() const
1016 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
1017 if (item == NULL) return QString();
1018 return item->clipUrl().path();
1021 void ProjectList::regenerateTemplate(const QString &id)
1023 ProjectItem *clip = getItemById(id);
1024 if (clip) regenerateTemplate(clip);
1027 void ProjectList::regenerateTemplate(ProjectItem *clip)
1029 //TODO: remove this unused method, only force_reload is necessary
1030 clip->referencedClip()->producer()->set("force_reload", 1);
1033 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
1037 if (!file.open(QIODevice::ReadOnly)) {
1038 kWarning() << "ERROR, CANNOT READ: " << path;
1041 if (!doc.setContent(&file)) {
1042 kWarning() << "ERROR, CANNOT READ: " << path;
1047 QDomNodeList texts = doc.elementsByTagName("content");
1048 for (int i = 0; i < texts.count(); i++) {
1049 QString data = texts.item(i).firstChild().nodeValue();
1050 data.replace("%s", replaceString);
1051 texts.item(i).firstChild().setNodeValue(data);
1056 #include "projectlist.moc"