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);
92 connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
93 connect(m_listView, SIGNAL(focusMonitor()), this, SLOT(slotClipSelected()));
94 connect(m_listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
95 connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
96 connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
97 connect(m_listView, SIGNAL(addClip(const QList <QUrl>, const QString &, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &, const QString &)));
98 connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
99 connect(m_listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
101 ItemDelegate *listViewDelegate = new ItemDelegate(m_listView);
102 m_listView->setItemDelegate(listViewDelegate);
104 if (KdenliveSettings::activate_nepomuk()) {
105 Nepomuk::ResourceManager::instance()->init();
106 if (!Nepomuk::ResourceManager::instance()->initialized()) {
107 kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
108 KdenliveSettings::setActivate_nepomuk(false);
113 ProjectList::~ProjectList()
119 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
121 QList <QAction *> actions = addMenu->actions();
122 for (int i = 0; i < actions.count(); i++) {
123 if (actions.at(i)->data().toString() == "clip_properties") {
124 m_editAction = actions.at(i);
125 m_toolbar->addAction(m_editAction);
128 } else if (actions.at(i)->data().toString() == "delete_clip") {
129 m_deleteAction = actions.at(i);
130 m_toolbar->addAction(m_deleteAction);
133 } else if (actions.at(i)->data().toString() == "edit_clip") {
134 m_openAction = actions.at(i);
137 } else if (actions.at(i)->data().toString() == "reload_clip") {
138 m_reloadAction = actions.at(i);
144 QMenu *m = new QMenu();
145 m->addActions(actions);
146 m_addButton->setMenu(m);
147 m_addButton->setDefaultAction(defaultAction);
148 m_menu = new QMenu();
149 m_menu->addActions(addMenu->actions());
152 void ProjectList::setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu)
154 if (!addMenu) return;
155 QMenu *menu = m_addButton->menu();
156 menu->addMenu(addMenu);
157 m_addButton->setMenu(menu);
159 m_menu->addMenu(addMenu);
160 if (addMenu->isEmpty()) addMenu->setEnabled(false);
161 m_menu->addMenu(transcodeMenu);
162 if (transcodeMenu->isEmpty()) transcodeMenu->setEnabled(false);
163 m_menu->addAction(m_reloadAction);
164 m_menu->addAction(m_editAction);
165 m_menu->addAction(m_openAction);
166 m_menu->addAction(m_deleteAction);
167 m_menu->insertSeparator(m_deleteAction);
171 QByteArray ProjectList::headerInfo() const
173 return m_listView->header()->saveState();
176 void ProjectList::setHeaderInfo(const QByteArray &state)
178 m_listView->header()->restoreState(state);
181 void ProjectList::slotEditClip()
183 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
184 if (!(item->flags() & Qt::ItemIsDragEnabled)) return;
185 if (item && !item->isGroup()) {
186 emit clipSelected(item->referencedClip());
187 emit showClipProperties(item->referencedClip());
191 void ProjectList::slotOpenClip()
193 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
194 if (item && !item->isGroup()) {
195 if (item->clipType() == IMAGE) {
196 if (KdenliveSettings::defaultimageapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open images in the Settings dialog"));
197 else QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
199 if (item->clipType() == AUDIO) {
200 if (KdenliveSettings::defaultaudioapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open audio files in the Settings dialog"));
201 else QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
206 void ProjectList::slotReloadClip()
208 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
210 for (int i = 0; i < selected.count(); i++) {
211 item = static_cast <ProjectItem *>(selected.at(i));
212 if (item && !item->isGroup()) {
213 if (item->clipType() == IMAGE) {
214 item->referencedClip()->producer()->set("force_reload", 1);
215 } else if (item->clipType() == TEXT) {
216 if (!item->referencedClip()->getProperty("xmltemplate").isEmpty()) regenerateTemplate(item);
218 //requestClipInfo(item->toXml(), item->clipId(), true);
219 emit getFileProperties(item->toXml(), item->clipId(), true);
224 void ProjectList::setRenderer(Render *projectRender)
226 m_render = projectRender;
227 m_listView->setIconSize(QSize(40 * m_render->dar(), 40));
230 void ProjectList::slotClipSelected()
232 if (m_listView->currentItem()) {
233 ProjectItem *clip = static_cast <ProjectItem*>(m_listView->currentItem());
234 if (!clip->isGroup()) {
235 m_selectedItem = clip;
236 emit clipSelected(clip->referencedClip());
238 m_editAction->setEnabled(true);
239 m_deleteAction->setEnabled(true);
240 m_reloadAction->setEnabled(true);
241 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
242 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
243 m_openAction->setEnabled(true);
244 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
245 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
246 m_openAction->setEnabled(true);
247 } else m_openAction->setEnabled(false);
249 emit clipSelected(NULL);
250 m_editAction->setEnabled(false);
251 m_deleteAction->setEnabled(false);
252 m_openAction->setEnabled(false);
253 m_reloadAction->setEnabled(false);
257 void ProjectList::slotPauseMonitor()
259 if (m_render) m_render->pause();
262 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
264 ProjectItem *item = getItemById(id);
266 slotUpdateClipProperties(item, properties);
267 if (properties.contains("colour") || properties.contains("resource") || properties.contains("xmldata") || properties.contains("force_aspect_ratio")) {
268 slotRefreshClipThumbnail(item);
271 if (properties.contains("out")) item->changeDuration(properties.value("out").toInt());
275 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
278 if (!clip->isGroup()) clip->setProperties(properties);
279 if (properties.contains("xmldata")) regenerateTemplateImage(clip);
280 if (properties.contains("name")) {
281 m_listView->blockSignals(true);
282 clip->setText(1, properties.value("name"));
283 m_listView->blockSignals(false);
284 emit clipNameChanged(clip->clipId(), properties.value("name"));
286 if (properties.contains("description")) {
287 CLIPTYPE type = clip->clipType();
288 m_listView->blockSignals(true);
289 clip->setText(2, properties.value("description"));
290 m_listView->blockSignals(false);
291 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
292 // Use Nepomuk system to store clip description
293 Nepomuk::Resource f(clip->clipUrl().path());
294 f.setDescription(properties.value("description"));
296 emit projectModified();
300 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
302 ProjectItem *clip = static_cast <ProjectItem*>(item);
304 if (clip->referencedClip()) {
305 QMap <QString, QString> oldprops;
306 QMap <QString, QString> newprops;
307 oldprops["description"] = clip->referencedClip()->getProperty("description");
308 newprops["description"] = item->text(2);
310 if (clip->clipType() == TEXT && !clip->referencedClip()->getProperty("xmltemplate").isEmpty()) {
311 // This is a text template clip, update the image
312 oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
313 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());
316 slotUpdateClipProperties(clip->clipId(), newprops);
317 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
318 m_commandStack->push(command);
320 } else if (column == 1) {
321 if (clip->isGroup()) {
322 editFolder(item->text(1), clip->groupName(), clip->clipId());
323 clip->setGroupName(item->text(1));
324 m_doc->clipManager()->addFolder(clip->clipId(), item->text(1));
325 const int children = item->childCount();
326 for (int i = 0; i < children; i++) {
327 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
328 child->setProperty("groupname", item->text(1));
331 if (clip->referencedClip()) {
332 QMap <QString, QString> oldprops;
333 QMap <QString, QString> newprops;
334 oldprops["name"] = clip->referencedClip()->getProperty("name");
335 newprops["name"] = item->text(1);
336 slotUpdateClipProperties(clip, newprops);
337 emit projectModified();
338 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
339 m_commandStack->push(command);
345 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
351 m_editAction->setEnabled(enable);
352 m_deleteAction->setEnabled(enable);
353 m_reloadAction->setEnabled(enable);
355 ProjectItem *clip = static_cast <ProjectItem*>(item);
356 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
357 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
358 m_openAction->setEnabled(true);
359 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
360 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
361 m_openAction->setEnabled(true);
362 } else m_openAction->setEnabled(false);
363 } else m_openAction->setEnabled(false);
367 void ProjectList::slotRemoveClip()
369 if (!m_listView->currentItem()) return;
371 QMap <QString, QString> folderids;
372 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
374 for (int i = 0; i < selected.count(); i++) {
375 item = static_cast <ProjectItem *>(selected.at(i));
376 if (item->isGroup()) folderids[item->groupName()] = item->clipId();
377 else ids << item->clipId();
378 if (item->numReferences() > 0) {
379 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;
380 } else if (item->isGroup() && item->childCount() > 0) {
381 int children = item->childCount();
382 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;
383 for (int i = 0; i < children; ++i) {
384 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
385 ids << child->clipId();
389 if (!ids.isEmpty()) m_doc->deleteProjectClip(ids);
390 if (!folderids.isEmpty()) deleteProjectFolder(folderids);
391 if (m_listView->topLevelItemCount() == 0) {
392 m_editAction->setEnabled(false);
393 m_deleteAction->setEnabled(false);
394 m_openAction->setEnabled(false);
395 m_reloadAction->setEnabled(false);
399 void ProjectList::selectItemById(const QString &clipId)
401 ProjectItem *item = getItemById(clipId);
402 if (item) m_listView->setCurrentItem(item);
406 void ProjectList::slotDeleteClip(const QString &clipId)
408 ProjectItem *item = getItemById(clipId);
410 kDebug() << "/// Cannot find clip to delete";
417 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
419 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
420 m_commandStack->push(command);
421 m_doc->setModified(true);
424 void ProjectList::slotAddFolder()
426 AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
427 m_commandStack->push(command);
430 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
433 ProjectItem *item = getFolderItemById(clipId);
435 m_doc->clipManager()->deleteFolder(clipId);
440 ProjectItem *item = getFolderItemById(clipId);
441 QTreeWidgetItemIterator it(m_listView);
443 m_listView->blockSignals(true);
444 item->setGroupName(foldername);
445 m_listView->blockSignals(false);
446 m_doc->clipManager()->addFolder(clipId, foldername);
447 const int children = item->childCount();
448 for (int i = 0; i < children; i++) {
449 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
450 child->setProperty("groupname", foldername);
455 text << QString() << foldername;
456 m_listView->blockSignals(true);
457 m_listView->setCurrentItem(new ProjectItem(m_listView, text, clipId));
458 m_doc->clipManager()->addFolder(clipId, foldername);
459 m_listView->blockSignals(false);
466 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
468 QMapIterator<QString, QString> i(map);
469 QUndoCommand *delCommand = new QUndoCommand();
470 delCommand->setText(i18n("Delete Folder"));
471 while (i.hasNext()) {
473 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
475 m_commandStack->push(delCommand);
476 m_doc->setModified(true);
479 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
481 if (getProperties) m_listView->setEnabled(false);
482 m_listView->blockSignals(true);
483 const QString parent = clip->getProperty("groupid");
484 kDebug() << "Adding clip with groupid: " << parent;
485 ProjectItem *item = NULL;
486 if (!parent.isEmpty()) {
487 ProjectItem *parentitem = getFolderItemById(parent);
490 QString groupName = clip->getProperty("groupname");
491 //kDebug() << "Adding clip to new group: " << groupName;
492 if (groupName.isEmpty()) groupName = i18n("Folder");
493 text << QString() << groupName;
494 parentitem = new ProjectItem(m_listView, text, parent);
496 //kDebug() << "Adding clip to existing group: " << parentitem->groupName();
498 if (parentitem) item = new ProjectItem(parentitem, clip);
500 if (item == NULL) item = new ProjectItem(m_listView, clip);
501 KUrl url = clip->fileURL();
502 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
503 // if file has Nepomuk comment, use it
504 Nepomuk::Resource f(url.path());
505 QString annotation = f.description();
506 if (!annotation.isEmpty()) item->setText(2, annotation);
507 item->setText(3, QString::number(f.rating()));
509 m_listView->blockSignals(false);
512 void ProjectList::slotResetProjectList()
515 emit clipSelected(NULL);
516 m_thumbnailQueue.clear();
521 void ProjectList::requestClipInfo(const QDomElement xml, const QString id)
523 kDebug() << " PRG LISTĀ REQUEST CLP INFO: " << id;
524 m_infoQueue.insert(id, xml);
525 m_listView->setEnabled(false);
526 if (m_infoQueue.count() == 1) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
529 void ProjectList::slotProcessNextClipInQueue()
531 if (m_infoQueue.isEmpty()) {
532 m_listView->setEnabled(true);
535 QMap<QString, QDomElement>::const_iterator i = m_infoQueue.constBegin();
536 if (i != m_infoQueue.constEnd()) {
537 const QDomElement dom = i.value();
538 const QString id = i.key();
539 m_infoQueue.remove(i.key());
540 emit getFileProperties(dom, id, false);
542 if (m_infoQueue.isEmpty()) m_listView->setEnabled(true);
545 void ProjectList::slotUpdateClip(const QString &id)
547 ProjectItem *item = getItemById(id);
548 m_listView->blockSignals(true);
549 if (item) item->setData(1, UsageRole, QString::number(item->numReferences()));
550 m_listView->blockSignals(false);
553 void ProjectList::updateAllClips()
555 QTreeWidgetItemIterator it(m_listView);
557 ProjectItem *item = static_cast <ProjectItem *>(*it);
558 if (!item->isGroup()) {
559 if (item->referencedClip()->producer() == NULL) {
560 DocClipBase *clip = item->referencedClip();
561 if (clip->clipType() == TEXT && !QFile::exists(clip->fileURL().path())) {
562 // regenerate text clip image if required
563 TitleWidget *dia_ui = new TitleWidget(KUrl(), QString(), m_render, this);
565 doc.setContent(clip->getProperty("xmldata"));
567 QImage pix = dia_ui->renderedPixmap();
568 pix.save(clip->fileURL().path());
571 if (clip->isPlaceHolder() == false) requestClipInfo(clip->toXML(), clip->getId());
572 else item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
574 QString cachedPixmap = m_doc->projectFolder().path() + "/thumbs/" + item->getClipHash() + ".png";
575 if (QFile::exists(cachedPixmap)) {
576 //kDebug()<<"// USING CACHED PIX: "<<cachedPixmap;
577 m_listView->blockSignals(true);
578 item->setIcon(0, QPixmap(cachedPixmap));
579 m_listView->blockSignals(false);
580 } else requestClipThumbnail(item->clipId());
582 if (item->data(1, DurationRole).toString().isEmpty()) {
583 m_listView->blockSignals(true);
584 item->changeDuration(item->referencedClip()->producer()->get_playtime());
585 m_listView->blockSignals(false);
588 m_listView->blockSignals(true);
589 item->setData(1, UsageRole, QString::number(item->numReferences()));
590 m_listView->blockSignals(false);
591 qApp->processEvents();
595 QTimer::singleShot(500, this, SLOT(slotCheckForEmptyQueue()));
598 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
600 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
602 if (givenList.isEmpty()) {
603 // Build list of mime types
604 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";
606 QString allExtensions;
607 foreach(const QString& mimeType, mimeTypes) {
608 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
610 allExtensions.append(mime->patterns().join(" "));
611 allExtensions.append(' ');
614 QString dialogFilter = allExtensions + ' ' + QLatin1Char('|') + i18n("All Supported Files");
615 dialogFilter.append("\n*" + QLatin1Char('|') + i18n("All Files"));
616 list = KFileDialog::getOpenUrls(KUrl("kfiledialog:///clipfolder"), dialogFilter, this);
619 for (int i = 0; i < givenList.count(); i++)
620 list << givenList.at(i);
622 if (list.isEmpty()) return;
624 if (givenList.isEmpty()) {
625 QStringList groupInfo = getGroup();
626 m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1));
627 } else m_doc->slotAddClipList(list, groupName, groupId);
630 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
632 ProjectItem *item = getItemById(id);
634 const QString path = item->referencedClip()->fileURL().path();
635 if (!path.isEmpty()) {
636 if (replace) KMessageBox::sorry(this, i18n("Clip <b>%1</b><br>is invalid, will be removed from project.", path));
638 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;
643 if (replace) m_doc->deleteProjectClip(ids);
645 if (!m_infoQueue.isEmpty()) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
646 else m_listView->setEnabled(true);
649 void ProjectList::slotAddColorClip()
651 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
652 QDialog *dia = new QDialog(this);
653 Ui::ColorClip_UI dia_ui;
655 dia_ui.clip_name->setText(i18n("Color Clip"));
656 dia_ui.clip_duration->setText(KdenliveSettings::color_duration());
657 if (dia->exec() == QDialog::Accepted) {
658 QString color = dia_ui.clip_color->color().name();
659 color = color.replace(0, 1, "0x") + "ff";
660 QStringList groupInfo = getGroup();
661 m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, dia_ui.clip_duration->text(), groupInfo.at(0), groupInfo.at(1));
667 void ProjectList::slotAddSlideshowClip()
669 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
670 SlideshowClip *dia = new SlideshowClip(m_timecode, this);
672 if (dia->exec() == QDialog::Accepted) {
673 QStringList groupInfo = getGroup();
674 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));
679 void ProjectList::slotAddTitleClip()
681 QStringList groupInfo = getGroup();
682 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
685 void ProjectList::slotAddTitleTemplateClip()
687 QStringList groupInfo = getGroup();
688 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
690 // Get the list of existing templates
692 filter << "*.kdenlivetitle";
693 const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
694 QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
696 QDialog *dia = new QDialog(this);
697 Ui::TemplateClip_UI dia_ui;
699 for (int i = 0; i < templateFiles.size(); ++i) {
700 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
702 dia_ui.template_list->fileDialog()->setFilter("*.kdenlivetitle");
703 //warning: setting base directory doesn't work??
705 dia_ui.template_list->fileDialog()->setUrl(startDir);
706 dia_ui.description->setHidden(true);
707 if (dia->exec() == QDialog::Accepted) {
708 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
709 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
710 if (dia_ui.normal_clip->isChecked()) {
711 // Create a normal title clip
712 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1), textTemplate);
714 // Create a cloned template clip
715 m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
721 QStringList ProjectList::getGroup() const
724 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
725 if (item && !item->isGroup()) {
726 while (item->parent()) {
727 item = static_cast <ProjectItem*>(item->parent());
728 if (item->isGroup()) break;
731 if (item && item->isGroup()) {
732 result << item->groupName();
733 result << item->clipId();
734 } else result << QString() << QString();
738 void ProjectList::setDocument(KdenliveDoc *doc)
740 m_listView->blockSignals(true);
742 emit clipSelected(NULL);
743 m_thumbnailQueue.clear();
746 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
747 QMapIterator<QString, QString> f(flist);
748 while (f.hasNext()) {
750 (void) new ProjectItem(m_listView, QStringList() << QString() << f.value(), f.key());
753 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
754 for (int i = 0; i < list.count(); i++) {
755 slotAddClip(list.at(i), false);
759 m_timecode = doc->timecode();
760 m_commandStack = doc->commandStack();
762 QTreeWidgetItem *first = m_listView->topLevelItem(0);
763 if (first) m_listView->setCurrentItem(first);
764 m_listView->blockSignals(false);
765 m_toolbar->setEnabled(true);
768 QDomElement ProjectList::producersList()
771 QDomElement prods = doc.createElement("producerlist");
772 doc.appendChild(prods);
773 kDebug() << "//////////// PRO LISTĀ BUILD PRDSLIST ";
774 QTreeWidgetItemIterator it(m_listView);
776 if (!((ProjectItem *)(*it))->isGroup())
777 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
783 void ProjectList::slotCheckForEmptyQueue()
785 if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
787 emit loadingIsOver();
788 } else QTimer::singleShot(500, this, SLOT(slotCheckForEmptyQueue()));
791 void ProjectList::reloadClipThumbnails()
793 m_thumbnailQueue.clear();
794 QTreeWidgetItemIterator it(m_listView);
796 if (!((ProjectItem *)(*it))->isGroup())
797 m_thumbnailQueue << ((ProjectItem *)(*it))->clipId();
800 QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
803 void ProjectList::requestClipThumbnail(const QString &id)
805 m_thumbnailQueue.append(id);
806 if (m_thumbnailQueue.count() == 1) QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
809 void ProjectList::slotProcessNextThumbnail()
811 if (m_thumbnailQueue.isEmpty()) {
814 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
817 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
819 ProjectItem *item = getItemById(clipId);
820 if (item) slotRefreshClipThumbnail(item, update);
821 else slotProcessNextThumbnail();
824 void ProjectList::slotRefreshClipThumbnail(ProjectItem *item, bool update)
827 if (!item->referencedClip()) return;
829 int width = (int)(height * m_render->dar());
830 DocClipBase *clip = item->referencedClip();
831 if (!clip) slotProcessNextThumbnail();
833 if (clip->clipType() == AUDIO) pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
834 else pix = item->referencedClip()->thumbProducer()->extractImage(item->referencedClip()->getClipThumbFrame(), width, height);
835 m_listView->blockSignals(true);
836 item->setIcon(0, pix);
837 m_listView->blockSignals(false);
838 m_doc->cachePixmap(item->getClipHash(), pix);
839 if (update) emit projectModified();
840 if (!m_thumbnailQueue.isEmpty()) QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
844 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace)
846 ProjectItem *item = getItemById(clipId);
847 if (item && producer) {
848 m_listView->blockSignals(true);
849 item->setProperties(properties, metadata);
850 Q_ASSERT_X(item->referencedClip(), "void ProjectList::slotReplyGetFileProperties", QString("Item with groupName %1 does not have a clip associated").arg(item->groupName()).toLatin1());
851 item->referencedClip()->setProducer(producer, replace);
852 emit receivedClipDuration(clipId);
854 // update clip in clip monitor
855 emit clipSelected(NULL);
856 emit clipSelected(item->referencedClip());
859 // Check if duration changed.
860 emit receivedClipDuration(clipId);
863 m_listView->blockSignals(false);
864 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
865 if (!m_infoQueue.isEmpty()) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
866 else m_listView->setEnabled(true);
869 void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
871 ProjectItem *item = getItemById(clipId);
873 m_listView->blockSignals(true);
874 item->setIcon(0, pix);
875 m_doc->cachePixmap(item->getClipHash(), pix);
876 m_listView->blockSignals(false);
880 ProjectItem *ProjectList::getItemById(const QString &id)
883 QTreeWidgetItemIterator it(m_listView);
885 item = static_cast<ProjectItem *>(*it);
886 if (item->clipId() == id && item->clipType() != FOLDER)
893 ProjectItem *ProjectList::getFolderItemById(const QString &id)
896 QTreeWidgetItemIterator it(m_listView);
898 item = static_cast<ProjectItem *>(*it);
899 if (item->clipId() == id && item->clipType() == FOLDER)
906 void ProjectList::slotSelectClip(const QString &ix)
908 ProjectItem *clip = getItemById(ix);
910 m_listView->setCurrentItem(clip);
911 m_listView->scrollToItem(clip);
912 m_editAction->setEnabled(true);
913 m_deleteAction->setEnabled(true);
914 m_reloadAction->setEnabled(true);
915 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
916 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
917 m_openAction->setEnabled(true);
918 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
919 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
920 m_openAction->setEnabled(true);
921 } else m_openAction->setEnabled(false);
925 QString ProjectList::currentClipUrl() const
927 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
928 if (item == NULL) return QString();
929 return item->clipUrl().path();
932 void ProjectList::regenerateTemplate(const QString &id)
934 ProjectItem *clip = getItemById(id);
935 if (clip) regenerateTemplate(clip);
938 void ProjectList::regenerateTemplate(ProjectItem *clip)
940 // Generate image for template clip
941 const QString comment = clip->referencedClip()->getProperty("description");
942 const QString path = clip->referencedClip()->getProperty("xmltemplate");
943 QDomDocument doc = generateTemplateXml(path, comment);
944 TitleWidget *dia_ui = new TitleWidget(KUrl(), QString(), m_render, this);
946 QImage pix = dia_ui->renderedPixmap();
947 pix.save(clip->clipUrl().path());
949 clip->referencedClip()->producer()->set("force_reload", 1);
952 void ProjectList::regenerateTemplateImage(ProjectItem *clip)
954 // Generate image for template clip
955 TitleWidget *dia_ui = new TitleWidget(KUrl(), QString(), m_render, this);
957 doc.setContent(clip->referencedClip()->getProperty("xmldata"));
959 QImage pix = dia_ui->renderedPixmap();
960 pix.save(clip->clipUrl().path());
964 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
968 if (!file.open(QIODevice::ReadOnly)) {
969 kWarning() << "ERROR, CANNOT READ: " << path;
972 if (!doc.setContent(&file)) {
973 kWarning() << "ERROR, CANNOT READ: " << path;
978 QDomNodeList texts = doc.elementsByTagName("content");
979 for (int i = 0; i < texts.count(); i++) {
980 QString data = texts.item(i).firstChild().nodeValue();
981 data.replace("%s", replaceString);
982 texts.item(i).firstChild().setNodeValue(data);
987 #include "projectlist.moc"