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>
45 #include <nepomuk/global.h>
46 #include <nepomuk/resourcemanager.h>
47 //#include <nepomuk/tag.h>
49 #include <QMouseEvent>
50 #include <QStylePainter>
55 #include <QHeaderView>
57 ProjectList::ProjectList(QWidget *parent) :
72 m_listView = new ProjectListView(this);;
73 QVBoxLayout *layout = new QVBoxLayout;
74 layout->setContentsMargins(0, 0, 0, 0);
77 KTreeWidgetSearchLine *searchView = new KTreeWidgetSearchLine(this);
78 m_toolbar = new QToolBar("projectToolBar", this);
79 m_toolbar->addWidget(searchView);
80 searchView->setTreeWidget(m_listView);
82 m_addButton = new QToolButton(m_toolbar);
83 m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
84 m_toolbar->addWidget(m_addButton);
86 layout->addWidget(m_toolbar);
87 layout->addWidget(m_listView);
90 m_queueTimer.setInterval(100);
91 connect(&m_queueTimer, SIGNAL(timeout()), this, SLOT(slotProcessNextClipInQueue()));
92 m_queueTimer.setSingleShot(true);
96 connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
97 connect(m_listView, SIGNAL(focusMonitor()), this, SLOT(slotClipSelected()));
98 connect(m_listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
99 connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
100 connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
101 connect(m_listView, SIGNAL(addClip(const QList <QUrl>, const QString &, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &, const QString &)));
102 connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
103 connect(m_listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
105 ItemDelegate *listViewDelegate = new ItemDelegate(m_listView);
106 m_listView->setItemDelegate(listViewDelegate);
108 if (KdenliveSettings::activate_nepomuk()) {
109 Nepomuk::ResourceManager::instance()->init();
110 if (!Nepomuk::ResourceManager::instance()->initialized()) {
111 kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
112 KdenliveSettings::setActivate_nepomuk(false);
117 ProjectList::~ProjectList()
123 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
125 QList <QAction *> actions = addMenu->actions();
126 for (int i = 0; i < actions.count(); i++) {
127 if (actions.at(i)->data().toString() == "clip_properties") {
128 m_editAction = actions.at(i);
129 m_toolbar->addAction(m_editAction);
132 } else if (actions.at(i)->data().toString() == "delete_clip") {
133 m_deleteAction = actions.at(i);
134 m_toolbar->addAction(m_deleteAction);
137 } else if (actions.at(i)->data().toString() == "edit_clip") {
138 m_openAction = actions.at(i);
141 } else if (actions.at(i)->data().toString() == "reload_clip") {
142 m_reloadAction = actions.at(i);
148 QMenu *m = new QMenu();
149 m->addActions(actions);
150 m_addButton->setMenu(m);
151 m_addButton->setDefaultAction(defaultAction);
152 m_menu = new QMenu();
153 m_menu->addActions(addMenu->actions());
156 void ProjectList::setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu)
158 if (!addMenu) return;
159 QMenu *menu = m_addButton->menu();
160 menu->addMenu(addMenu);
161 m_addButton->setMenu(menu);
163 m_menu->addMenu(addMenu);
164 if (addMenu->isEmpty()) addMenu->setEnabled(false);
165 m_menu->addMenu(transcodeMenu);
166 if (transcodeMenu->isEmpty()) transcodeMenu->setEnabled(false);
167 m_menu->addAction(m_reloadAction);
168 m_menu->addAction(m_editAction);
169 m_menu->addAction(m_openAction);
170 m_menu->addAction(m_deleteAction);
171 m_menu->insertSeparator(m_deleteAction);
175 QByteArray ProjectList::headerInfo() const
177 return m_listView->header()->saveState();
180 void ProjectList::setHeaderInfo(const QByteArray &state)
182 m_listView->header()->restoreState(state);
185 void ProjectList::slotEditClip()
187 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
188 if (!(item->flags() & Qt::ItemIsDragEnabled)) return;
189 if (item && !item->isGroup()) {
190 emit clipSelected(item->referencedClip());
191 emit showClipProperties(item->referencedClip());
195 void ProjectList::slotOpenClip()
197 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
198 if (item && !item->isGroup()) {
199 if (item->clipType() == IMAGE) {
200 if (KdenliveSettings::defaultimageapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open images in the Settings dialog"));
201 else QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
203 if (item->clipType() == AUDIO) {
204 if (KdenliveSettings::defaultaudioapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open audio files in the Settings dialog"));
205 else QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
210 void ProjectList::slotReloadClip()
212 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
214 for (int i = 0; i < selected.count(); i++) {
215 item = static_cast <ProjectItem *>(selected.at(i));
216 if (item && !item->isGroup()) {
217 if (item->clipType() == IMAGE) {
218 item->referencedClip()->producer()->set("force_reload", 1);
219 } else if (item->clipType() == TEXT) {
220 if (!item->referencedClip()->getProperty("xmltemplate").isEmpty()) regenerateTemplate(item);
222 //requestClipInfo(item->toXml(), item->clipId(), true);
223 // Clear the file_hash value, which will cause a complete reload of the clip
224 emit getFileProperties(item->toXml(), item->clipId(), true);
229 void ProjectList::setRenderer(Render *projectRender)
231 m_render = projectRender;
232 m_listView->setIconSize(QSize(40 * m_render->dar(), 40));
235 void ProjectList::slotClipSelected()
237 if (m_listView->currentItem()) {
238 ProjectItem *clip = static_cast <ProjectItem*>(m_listView->currentItem());
239 if (!clip->isGroup()) {
240 m_selectedItem = clip;
241 emit clipSelected(clip->referencedClip());
243 m_editAction->setEnabled(true);
244 m_deleteAction->setEnabled(true);
245 m_reloadAction->setEnabled(true);
246 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
247 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
248 m_openAction->setEnabled(true);
249 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
250 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
251 m_openAction->setEnabled(true);
252 } else m_openAction->setEnabled(false);
254 emit clipSelected(NULL);
255 m_editAction->setEnabled(false);
256 m_deleteAction->setEnabled(false);
257 m_openAction->setEnabled(false);
258 m_reloadAction->setEnabled(false);
262 void ProjectList::slotPauseMonitor()
264 if (m_render) m_render->pause();
267 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
269 ProjectItem *item = getItemById(id);
271 slotUpdateClipProperties(item, properties);
272 if (properties.contains("colour") || properties.contains("resource") || properties.contains("xmldata") || properties.contains("force_aspect_ratio")) {
273 slotRefreshClipThumbnail(item);
276 if (properties.contains("out")) item->changeDuration(properties.value("out").toInt());
280 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
283 if (!clip->isGroup()) clip->setProperties(properties);
284 if (properties.contains("xmldata")) regenerateTemplateImage(clip);
285 if (properties.contains("name")) {
286 m_listView->blockSignals(true);
287 clip->setText(1, properties.value("name"));
288 m_listView->blockSignals(false);
289 emit clipNameChanged(clip->clipId(), properties.value("name"));
291 if (properties.contains("description")) {
292 CLIPTYPE type = clip->clipType();
293 m_listView->blockSignals(true);
294 clip->setText(2, properties.value("description"));
295 m_listView->blockSignals(false);
296 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
297 // Use Nepomuk system to store clip description
298 Nepomuk::Resource f(clip->clipUrl().path());
299 f.setDescription(properties.value("description"));
301 emit projectModified();
305 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
307 ProjectItem *clip = static_cast <ProjectItem*>(item);
309 if (clip->referencedClip()) {
310 QMap <QString, QString> oldprops;
311 QMap <QString, QString> newprops;
312 oldprops["description"] = clip->referencedClip()->getProperty("description");
313 newprops["description"] = item->text(2);
315 if (clip->clipType() == TEXT && !clip->referencedClip()->getProperty("xmltemplate").isEmpty()) {
316 // This is a text template clip, update the image
317 oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
318 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());
321 slotUpdateClipProperties(clip->clipId(), newprops);
322 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
323 m_commandStack->push(command);
325 } else if (column == 1) {
326 if (clip->isGroup()) {
327 editFolder(item->text(1), clip->groupName(), clip->clipId());
328 clip->setGroupName(item->text(1));
329 m_doc->clipManager()->addFolder(clip->clipId(), item->text(1));
330 const int children = item->childCount();
331 for (int i = 0; i < children; i++) {
332 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
333 child->setProperty("groupname", item->text(1));
336 if (clip->referencedClip()) {
337 QMap <QString, QString> oldprops;
338 QMap <QString, QString> newprops;
339 oldprops["name"] = clip->referencedClip()->getProperty("name");
340 newprops["name"] = item->text(1);
341 slotUpdateClipProperties(clip, newprops);
342 emit projectModified();
343 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
344 m_commandStack->push(command);
350 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
356 m_editAction->setEnabled(enable);
357 m_deleteAction->setEnabled(enable);
358 m_reloadAction->setEnabled(enable);
360 ProjectItem *clip = static_cast <ProjectItem*>(item);
361 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
362 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
363 m_openAction->setEnabled(true);
364 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
365 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
366 m_openAction->setEnabled(true);
367 } else m_openAction->setEnabled(false);
368 } else m_openAction->setEnabled(false);
372 void ProjectList::slotRemoveClip()
374 if (!m_listView->currentItem()) return;
376 QMap <QString, QString> folderids;
377 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
379 for (int i = 0; i < selected.count(); i++) {
380 item = static_cast <ProjectItem *>(selected.at(i));
381 if (item->isGroup()) folderids[item->groupName()] = item->clipId();
382 else ids << item->clipId();
383 if (item->numReferences() > 0) {
384 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;
385 } else if (item->isGroup() && item->childCount() > 0) {
386 int children = item->childCount();
387 if (KMessageBox::questionYesNo(this, i18n("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;
388 for (int i = 0; i < children; ++i) {
389 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
390 ids << child->clipId();
394 if (!ids.isEmpty()) m_doc->deleteProjectClip(ids);
395 if (!folderids.isEmpty()) deleteProjectFolder(folderids);
396 if (m_listView->topLevelItemCount() == 0) {
397 m_editAction->setEnabled(false);
398 m_deleteAction->setEnabled(false);
399 m_openAction->setEnabled(false);
400 m_reloadAction->setEnabled(false);
404 void ProjectList::selectItemById(const QString &clipId)
406 ProjectItem *item = getItemById(clipId);
407 if (item) m_listView->setCurrentItem(item);
411 void ProjectList::slotDeleteClip(const QString &clipId)
413 ProjectItem *item = getItemById(clipId);
415 kDebug() << "/// Cannot find clip to delete";
422 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
424 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
425 m_commandStack->push(command);
426 m_doc->setModified(true);
429 void ProjectList::slotAddFolder()
431 AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
432 m_commandStack->push(command);
435 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
438 ProjectItem *item = getFolderItemById(clipId);
440 m_doc->clipManager()->deleteFolder(clipId);
445 ProjectItem *item = getFolderItemById(clipId);
446 QTreeWidgetItemIterator it(m_listView);
448 m_listView->blockSignals(true);
449 item->setGroupName(foldername);
450 m_listView->blockSignals(false);
451 m_doc->clipManager()->addFolder(clipId, foldername);
452 const int children = item->childCount();
453 for (int i = 0; i < children; i++) {
454 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
455 child->setProperty("groupname", foldername);
460 text << QString() << foldername;
461 m_listView->blockSignals(true);
462 m_listView->setCurrentItem(new ProjectItem(m_listView, text, clipId));
463 m_doc->clipManager()->addFolder(clipId, foldername);
464 m_listView->blockSignals(false);
471 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
473 QMapIterator<QString, QString> i(map);
474 QUndoCommand *delCommand = new QUndoCommand();
475 delCommand->setText(i18n("Delete Folder"));
476 while (i.hasNext()) {
478 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
480 m_commandStack->push(delCommand);
481 m_doc->setModified(true);
484 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
486 if (getProperties) m_listView->setEnabled(false);
487 m_listView->blockSignals(true);
488 const QString parent = clip->getProperty("groupid");
489 kDebug() << "Adding clip with groupid: " << parent;
490 ProjectItem *item = NULL;
491 if (!parent.isEmpty()) {
492 ProjectItem *parentitem = getFolderItemById(parent);
495 QString groupName = clip->getProperty("groupname");
496 //kDebug() << "Adding clip to new group: " << groupName;
497 if (groupName.isEmpty()) groupName = i18n("Folder");
498 text << QString() << groupName;
499 parentitem = new ProjectItem(m_listView, text, parent);
501 //kDebug() << "Adding clip to existing group: " << parentitem->groupName();
503 if (parentitem) item = new ProjectItem(parentitem, clip);
505 if (item == NULL) item = new ProjectItem(m_listView, clip);
506 KUrl url = clip->fileURL();
508 if (getProperties == false && !clip->getClipHash().isEmpty()) {
509 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
510 if (QFile::exists(cachedPixmap)) {
511 item->setIcon(0, QPixmap(cachedPixmap));
515 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
516 // if file has Nepomuk comment, use it
517 Nepomuk::Resource f(url.path());
518 QString annotation = f.description();
519 if (!annotation.isEmpty()) item->setText(2, annotation);
520 item->setText(3, QString::number(f.rating()));
522 m_listView->blockSignals(false);
525 void ProjectList::slotResetProjectList()
528 emit clipSelected(NULL);
529 m_thumbnailQueue.clear();
534 void ProjectList::requestClipInfo(const QDomElement xml, const QString id)
536 m_infoQueue.insert(id, xml);
537 m_listView->setEnabled(false);
538 if (!m_queueTimer.isActive()) m_queueTimer.start();
539 //if (m_infoQueue.count() == 1 || ) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
542 void ProjectList::slotProcessNextClipInQueue()
544 if (m_infoQueue.isEmpty()) {
548 QMap<QString, QDomElement>::const_iterator j = m_infoQueue.constBegin();
549 if (j != m_infoQueue.constEnd()) {
550 const QDomElement dom = j.value();
551 const QString id = j.key();
552 m_infoQueue.remove(j.key());
553 emit getFileProperties(dom, id, false);
555 if (!m_infoQueue.isEmpty()) m_queueTimer.start();
558 void ProjectList::slotUpdateClip(const QString &id)
560 ProjectItem *item = getItemById(id);
561 m_listView->blockSignals(true);
562 if (item) item->setData(1, UsageRole, QString::number(item->numReferences()));
563 m_listView->blockSignals(false);
566 void ProjectList::updateAllClips()
568 QTreeWidgetItemIterator it(m_listView);
570 ProjectItem *item = static_cast <ProjectItem *>(*it);
571 if (!item->isGroup()) {
572 DocClipBase *clip = item->referencedClip();
573 if (clip->clipType() == TEXT && !QFile::exists(clip->fileURL().path())) {
574 // regenerate text clip image if required
575 TitleWidget *dia_ui = new TitleWidget(KUrl(), QString(), m_render, this);
577 doc.setContent(clip->getProperty("xmldata"));
579 QImage pix = dia_ui->renderedPixmap();
580 pix.save(clip->fileURL().path());
584 if (item->referencedClip()->producer() == NULL) {
585 if (clip->isPlaceHolder() == false) requestClipInfo(clip->toXML(), clip->getId());
586 else item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
588 if (item->icon(0).isNull()) {
589 requestClipThumbnail(clip->getId());
591 if (item->data(1, DurationRole).toString().isEmpty()) {
592 m_listView->blockSignals(true);
593 item->changeDuration(item->referencedClip()->producer()->get_playtime());
594 m_listView->blockSignals(false);
597 m_listView->blockSignals(true);
598 item->setData(1, UsageRole, QString::number(item->numReferences()));
599 m_listView->blockSignals(false);
600 qApp->processEvents();
604 if (m_infoQueue.isEmpty()) slotProcessNextThumbnail();
607 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
609 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
611 if (givenList.isEmpty()) {
612 // Build list of mime types
613 QStringList mimeTypes = QStringList() << "application/x-kdenlive" << "video/x-flv" << "application/vnd.rn-realmedia" << "video/x-dv" << "video/dv" << "video/x-msvideo" << "video/mpeg" << "video/x-ms-wmv" << "audio/mpeg" << "audio/x-mp3" << "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" << "video/mlt-playlist" << "audio/x-flac" << "audio/mp4" << "video/x-matroska" << "audio/x-matroska" << "video/ogg" << "audio/ogg";
615 QString allExtensions;
616 foreach(const QString& mimeType, mimeTypes) {
617 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
619 allExtensions.append(mime->patterns().join(" "));
620 allExtensions.append(' ');
623 QString dialogFilter = allExtensions + ' ' + QLatin1Char('|') + i18n("All Supported Files");
624 dialogFilter.append("\n*" + QLatin1Char('|') + i18n("All Files"));
625 list = KFileDialog::getOpenUrls(KUrl("kfiledialog:///clipfolder"), dialogFilter, this);
628 for (int i = 0; i < givenList.count(); i++)
629 list << givenList.at(i);
631 if (list.isEmpty()) return;
633 if (givenList.isEmpty()) {
634 QStringList groupInfo = getGroup();
635 m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1));
636 } else m_doc->slotAddClipList(list, groupName, groupId);
639 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
641 ProjectItem *item = getItemById(id);
643 const QString path = item->referencedClip()->fileURL().path();
644 if (!path.isEmpty()) {
645 if (replace) KMessageBox::sorry(this, i18n("Clip <b>%1</b><br>is invalid, will be removed from project.", path));
647 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;
652 if (replace) m_doc->deleteProjectClip(ids);
654 QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
657 void ProjectList::slotAddColorClip()
659 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
660 QDialog *dia = new QDialog(this);
661 Ui::ColorClip_UI dia_ui;
663 dia_ui.clip_name->setText(i18n("Color Clip"));
664 dia_ui.clip_duration->setText(KdenliveSettings::color_duration());
665 if (dia->exec() == QDialog::Accepted) {
666 QString color = dia_ui.clip_color->color().name();
667 color = color.replace(0, 1, "0x") + "ff";
668 QStringList groupInfo = getGroup();
669 m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, dia_ui.clip_duration->text(), groupInfo.at(0), groupInfo.at(1));
675 void ProjectList::slotAddSlideshowClip()
677 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
678 SlideshowClip *dia = new SlideshowClip(m_timecode, this);
680 if (dia->exec() == QDialog::Accepted) {
681 QStringList groupInfo = getGroup();
682 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));
687 void ProjectList::slotAddTitleClip()
689 QStringList groupInfo = getGroup();
690 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
693 void ProjectList::slotAddTitleTemplateClip()
695 QStringList groupInfo = getGroup();
696 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
698 // Get the list of existing templates
700 filter << "*.kdenlivetitle";
701 const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
702 QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
704 QDialog *dia = new QDialog(this);
705 Ui::TemplateClip_UI dia_ui;
707 for (int i = 0; i < templateFiles.size(); ++i) {
708 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
710 dia_ui.template_list->fileDialog()->setFilter("*.kdenlivetitle");
711 //warning: setting base directory doesn't work??
713 dia_ui.template_list->fileDialog()->setUrl(startDir);
714 dia_ui.description->setHidden(true);
715 if (dia->exec() == QDialog::Accepted) {
716 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
717 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
718 if (dia_ui.normal_clip->isChecked()) {
719 // Create a normal title clip
720 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1), textTemplate);
722 // Create a cloned template clip
723 m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
729 QStringList ProjectList::getGroup() const
732 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
733 if (item && !item->isGroup()) {
734 while (item->parent()) {
735 item = static_cast <ProjectItem*>(item->parent());
736 if (item->isGroup()) break;
739 if (item && item->isGroup()) {
740 result << item->groupName();
741 result << item->clipId();
742 } else result << QString() << QString();
746 void ProjectList::setDocument(KdenliveDoc *doc)
748 m_listView->blockSignals(true);
750 emit clipSelected(NULL);
751 m_thumbnailQueue.clear();
755 m_timecode = doc->timecode();
756 m_commandStack = doc->commandStack();
759 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
760 QMapIterator<QString, QString> f(flist);
761 while (f.hasNext()) {
763 (void) new ProjectItem(m_listView, QStringList() << QString() << f.value(), f.key());
766 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
767 for (int i = 0; i < list.count(); i++) {
768 slotAddClip(list.at(i), false);
772 QTreeWidgetItem *first = m_listView->topLevelItem(0);
773 if (first) m_listView->setCurrentItem(first);
774 m_listView->blockSignals(false);
775 m_toolbar->setEnabled(true);
778 QDomElement ProjectList::producersList()
781 QDomElement prods = doc.createElement("producerlist");
782 doc.appendChild(prods);
783 kDebug() << "//////////// PRO LISTĀ BUILD PRDSLIST ";
784 QTreeWidgetItemIterator it(m_listView);
786 if (!((ProjectItem *)(*it))->isGroup())
787 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
793 void ProjectList::slotCheckForEmptyQueue()
795 if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
796 m_listView->setEnabled(true);
798 emit loadingIsOver();
799 } else QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
802 void ProjectList::reloadClipThumbnails()
804 m_thumbnailQueue.clear();
805 QTreeWidgetItemIterator it(m_listView);
807 if (!((ProjectItem *)(*it))->isGroup())
808 m_thumbnailQueue << ((ProjectItem *)(*it))->clipId();
811 QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
814 void ProjectList::requestClipThumbnail(const QString id)
816 m_thumbnailQueue.append(id);
819 void ProjectList::slotProcessNextThumbnail()
821 if (m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
822 slotCheckForEmptyQueue();
825 if (!m_infoQueue.isEmpty()) {
826 QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
829 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
832 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
834 ProjectItem *item = getItemById(clipId);
835 if (item) slotRefreshClipThumbnail(item, update);
836 else slotProcessNextThumbnail();
839 void ProjectList::slotRefreshClipThumbnail(ProjectItem *item, bool update)
843 int width = (int)(height * m_render->dar());
844 DocClipBase *clip = item->referencedClip();
845 if (!clip) slotProcessNextThumbnail();
847 if (clip->clipType() == AUDIO) pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
848 else if (clip->clipType() == TEXT || clip->clipType() == IMAGE) pix = KThumb::getFrame(item->referencedClip()->producer(), 0, width, height);
849 else pix = item->referencedClip()->thumbProducer()->extractImage(item->referencedClip()->getClipThumbFrame(), width, height);
851 m_listView->blockSignals(true);
852 item->setIcon(0, pix);
853 m_listView->blockSignals(false);
854 m_doc->cachePixmap(item->getClipHash(), pix);
856 if (update) emit projectModified();
857 QTimer::singleShot(100, this, SLOT(slotProcessNextThumbnail()));
861 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace)
863 ProjectItem *item = getItemById(clipId);
864 if (item && producer) {
865 m_listView->blockSignals(true);
866 item->setProperties(properties, metadata);
867 Q_ASSERT_X(item->referencedClip(), "void ProjectList::slotReplyGetFileProperties", QString("Item with groupName %1 does not have a clip associated").arg(item->groupName()).toLatin1());
868 item->referencedClip()->setProducer(producer, replace);
869 emit receivedClipDuration(clipId);
871 // update clip in clip monitor
872 emit clipSelected(NULL);
873 emit clipSelected(item->referencedClip());
876 // Check if duration changed.
877 emit receivedClipDuration(clipId);
880 m_listView->blockSignals(false);
881 if (item->icon(0).isNull()) {
882 requestClipThumbnail(clipId);
884 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
886 if (m_infoQueue.isEmpty()) {
887 slotProcessNextThumbnail();
891 void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
893 ProjectItem *item = getItemById(clipId);
894 if (item && !pix.isNull()) {
895 m_listView->blockSignals(true);
896 item->setIcon(0, pix);
897 m_doc->cachePixmap(item->getClipHash(), pix);
898 m_listView->blockSignals(false);
902 ProjectItem *ProjectList::getItemById(const QString &id)
905 QTreeWidgetItemIterator it(m_listView);
907 item = static_cast<ProjectItem *>(*it);
908 if (item->clipId() == id && item->clipType() != FOLDER)
915 ProjectItem *ProjectList::getFolderItemById(const QString &id)
918 QTreeWidgetItemIterator it(m_listView);
920 item = static_cast<ProjectItem *>(*it);
921 if (item->clipId() == id && item->clipType() == FOLDER)
928 void ProjectList::slotSelectClip(const QString &ix)
930 ProjectItem *clip = getItemById(ix);
932 m_listView->setCurrentItem(clip);
933 m_listView->scrollToItem(clip);
934 m_editAction->setEnabled(true);
935 m_deleteAction->setEnabled(true);
936 m_reloadAction->setEnabled(true);
937 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
938 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
939 m_openAction->setEnabled(true);
940 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
941 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
942 m_openAction->setEnabled(true);
943 } else m_openAction->setEnabled(false);
947 QString ProjectList::currentClipUrl() const
949 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
950 if (item == NULL) return QString();
951 return item->clipUrl().path();
954 void ProjectList::regenerateTemplate(const QString &id)
956 ProjectItem *clip = getItemById(id);
957 if (clip) regenerateTemplate(clip);
960 void ProjectList::regenerateTemplate(ProjectItem *clip)
962 // Generate image for template clip
963 const QString comment = clip->referencedClip()->getProperty("description");
964 const QString path = clip->referencedClip()->getProperty("xmltemplate");
965 QDomDocument doc = generateTemplateXml(path, comment);
966 TitleWidget *dia_ui = new TitleWidget(KUrl(), QString(), m_render, this);
968 QImage pix = dia_ui->renderedPixmap();
969 pix.save(clip->clipUrl().path());
971 clip->referencedClip()->producer()->set("force_reload", 1);
974 void ProjectList::regenerateTemplateImage(ProjectItem *clip)
976 // Generate image for template clip
977 TitleWidget *dia_ui = new TitleWidget(KUrl(), QString(), m_render, this);
979 doc.setContent(clip->referencedClip()->getProperty("xmldata"));
981 QImage pix = dia_ui->renderedPixmap();
982 pix.save(clip->clipUrl().path());
986 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
990 if (!file.open(QIODevice::ReadOnly)) {
991 kWarning() << "ERROR, CANNOT READ: " << path;
994 if (!doc.setContent(&file)) {
995 kWarning() << "ERROR, CANNOT READ: " << path;
1000 QDomNodeList texts = doc.elementsByTagName("content");
1001 for (int i = 0; i < texts.count(); i++) {
1002 QString data = texts.item(i).firstChild().nodeValue();
1003 data.replace("%s", replaceString);
1004 texts.item(i).firstChild().setNodeValue(data);
1009 #include "projectlist.moc"