]> git.sesse.net Git - kdenlive/blob - src/projectlist.cpp
3 point editing progress: "t" switches from project tree to timeline
[kdenlive] / src / projectlist.cpp
1 /***************************************************************************
2  *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
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.                                   *
8  *                                                                         *
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.                          *
13  *                                                                         *
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  ***************************************************************************/
19
20 #include "projectlist.h"
21 #include "projectitem.h"
22 #include "subprojectitem.h"
23 #include "addfoldercommand.h"
24 #include "kdenlivesettings.h"
25 #include "slideshowclip.h"
26 #include "ui_colorclip_ui.h"
27 #include "titlewidget.h"
28 #include "definitions.h"
29 #include "clipmanager.h"
30 #include "docclipbase.h"
31 #include "kdenlivedoc.h"
32 #include "renderer.h"
33 #include "kthumb.h"
34 #include "projectlistview.h"
35 #include "editclipcommand.h"
36 #include "editfoldercommand.h"
37 #include "addclipcutcommand.h"
38
39 #include "ui_templateclip_ui.h"
40
41 #include <KDebug>
42 #include <KAction>
43 #include <KLocale>
44 #include <KFileDialog>
45 #include <KInputDialog>
46 #include <KMessageBox>
47 #include <KIO/NetAccess>
48 #include <KFileItem>
49
50 #include <nepomuk/global.h>
51 #include <nepomuk/resourcemanager.h>
52 //#include <nepomuk/tag.h>
53
54 #include <QMouseEvent>
55 #include <QStylePainter>
56 #include <QPixmap>
57 #include <QIcon>
58 #include <QMenu>
59 #include <QProcess>
60 #include <QHeaderView>
61
62 ProjectList::ProjectList(QWidget *parent) :
63         QWidget(parent),
64         m_render(NULL),
65         m_fps(-1),
66         m_commandStack(NULL),
67         m_editAction(NULL),
68         m_deleteAction(NULL),
69         m_openAction(NULL),
70         m_reloadAction(NULL),
71         m_transcodeAction(NULL),
72         m_doc(NULL),
73         m_refreshed(false),
74         m_infoQueue(),
75         m_thumbnailQueue()
76 {
77
78     m_listView = new ProjectListView(this);;
79     QVBoxLayout *layout = new QVBoxLayout;
80     layout->setContentsMargins(0, 0, 0, 0);
81
82     // setup toolbar
83     KTreeWidgetSearchLine *searchView = new KTreeWidgetSearchLine(this);
84     m_toolbar = new QToolBar("projectToolBar", this);
85     m_toolbar->addWidget(searchView);
86     searchView->setTreeWidget(m_listView);
87
88     m_addButton = new QToolButton(m_toolbar);
89     m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
90     m_toolbar->addWidget(m_addButton);
91
92     layout->addWidget(m_toolbar);
93     layout->addWidget(m_listView);
94     setLayout(layout);
95
96     m_queueTimer.setInterval(100);
97     connect(&m_queueTimer, SIGNAL(timeout()), this, SLOT(slotProcessNextClipInQueue()));
98     m_queueTimer.setSingleShot(true);
99
100
101
102     connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
103     connect(m_listView, SIGNAL(focusMonitor()), this, SLOT(slotClipSelected()));
104     connect(m_listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
105     connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
106     connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
107     connect(m_listView, SIGNAL(addClip(const QList <QUrl>, const QString &, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &, const QString &)));
108     connect(m_listView, SIGNAL(addClipCut(const QString &, int, int)), this, SLOT(slotAddClipCut(const QString &, int, int)));
109     connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
110     connect(m_listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
111
112     m_listViewDelegate = new ItemDelegate(m_listView);
113     m_listView->setItemDelegate(m_listViewDelegate);
114
115     if (KdenliveSettings::activate_nepomuk()) {
116         Nepomuk::ResourceManager::instance()->init();
117         if (!Nepomuk::ResourceManager::instance()->initialized()) {
118             kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
119             KdenliveSettings::setActivate_nepomuk(false);
120         }
121     }
122 }
123
124 ProjectList::~ProjectList()
125 {
126     delete m_menu;
127     delete m_toolbar;
128     m_listView->blockSignals(true);
129     m_listView->clear();
130     delete m_listViewDelegate;
131 }
132
133 void ProjectList::focusTree() const
134 {
135     m_listView->setFocus();
136 }
137
138 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
139 {
140     QList <QAction *> actions = addMenu->actions();
141     for (int i = 0; i < actions.count(); i++) {
142         if (actions.at(i)->data().toString() == "clip_properties") {
143             m_editAction = actions.at(i);
144             m_toolbar->addAction(m_editAction);
145             actions.removeAt(i);
146             i--;
147         } else if (actions.at(i)->data().toString() == "delete_clip") {
148             m_deleteAction = actions.at(i);
149             m_toolbar->addAction(m_deleteAction);
150             actions.removeAt(i);
151             i--;
152         } else if (actions.at(i)->data().toString() == "edit_clip") {
153             m_openAction = actions.at(i);
154             actions.removeAt(i);
155             i--;
156         } else if (actions.at(i)->data().toString() == "reload_clip") {
157             m_reloadAction = actions.at(i);
158             actions.removeAt(i);
159             i--;
160         }
161     }
162
163     QMenu *m = new QMenu();
164     m->addActions(actions);
165     m_addButton->setMenu(m);
166     m_addButton->setDefaultAction(defaultAction);
167     m_menu = new QMenu();
168     m_menu->addActions(addMenu->actions());
169 }
170
171 void ProjectList::setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu)
172 {
173     if (!addMenu) return;
174     QMenu *menu = m_addButton->menu();
175     menu->addMenu(addMenu);
176     m_addButton->setMenu(menu);
177
178     m_menu->addMenu(addMenu);
179     if (addMenu->isEmpty()) addMenu->setEnabled(false);
180     m_menu->addMenu(transcodeMenu);
181     if (transcodeMenu->isEmpty()) transcodeMenu->setEnabled(false);
182     m_transcodeAction = transcodeMenu;
183     m_menu->addAction(m_reloadAction);
184     m_menu->addAction(m_editAction);
185     m_menu->addAction(m_openAction);
186     m_menu->addAction(m_deleteAction);
187     m_menu->insertSeparator(m_deleteAction);
188 }
189
190
191 QByteArray ProjectList::headerInfo() const
192 {
193     return m_listView->header()->saveState();
194 }
195
196 void ProjectList::setHeaderInfo(const QByteArray &state)
197 {
198     m_listView->header()->restoreState(state);
199 }
200
201 void ProjectList::slotEditClip()
202 {
203     ProjectItem *item;
204     if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1) {
205         item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
206     } else item = static_cast <ProjectItem*>(m_listView->currentItem());
207     if (!(item->flags() & Qt::ItemIsDragEnabled)) return;
208     if (item && !item->isGroup()) {
209         emit clipSelected(item->referencedClip());
210         emit showClipProperties(item->referencedClip());
211     }
212 }
213
214 void ProjectList::slotOpenClip()
215 {
216     ProjectItem *item;
217     if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1) {
218         item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
219     } else item = static_cast <ProjectItem*>(m_listView->currentItem());
220     if (item && !item->isGroup()) {
221         if (item->clipType() == IMAGE) {
222             if (KdenliveSettings::defaultimageapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open images in the Settings dialog"));
223             else QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
224         }
225         if (item->clipType() == AUDIO) {
226             if (KdenliveSettings::defaultaudioapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open audio files in the Settings dialog"));
227             else QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
228         }
229     }
230 }
231
232 void ProjectList::cleanup()
233 {
234     m_listView->clearSelection();
235     QTreeWidgetItemIterator it(m_listView);
236     ProjectItem *item;
237     while (*it) {
238         if ((*it)->type() == QTreeWidgetItem::UserType + 1) {
239             it++;
240             continue;
241         }
242         item = static_cast <ProjectItem *>(*it);
243         if (!item->isGroup() && item->numReferences() == 0) item->setSelected(true);
244         it++;
245     }
246     slotRemoveClip();
247 }
248
249 void ProjectList::trashUnusedClips()
250 {
251     QTreeWidgetItemIterator it(m_listView);
252     ProjectItem *item;
253     QStringList ids;
254     QStringList urls;
255     while (*it) {
256         if ((*it)->type() == QTreeWidgetItem::UserType + 1) {
257             it++;
258             continue;
259         }
260         item = static_cast <ProjectItem *>(*it);
261         if (!item->isGroup() && item->numReferences() == 0) {
262             ids << item->clipId();
263             KUrl url = item->clipUrl();
264             if (!url.isEmpty()) urls << url.path();
265         }
266         it++;
267     }
268     urls.removeDuplicates();
269     // Check that we don't use the URL in another clip
270     QTreeWidgetItemIterator it2(m_listView);
271     while (*it2) {
272         if ((*it2)->type() == QTreeWidgetItem::UserType + 1) {
273             it2++;
274             continue;
275         }
276         item = static_cast <ProjectItem *>(*it2);
277         if (item->numReferences() > 0) {
278             KUrl url = item->clipUrl();
279             if (!url.isEmpty() && urls.contains(url.path())) urls.removeAll(url.path());
280         }
281         it2++;
282     }
283
284     m_doc->deleteProjectClip(ids);
285     for (int i = 0; i < urls.count(); i++) {
286         KIO::NetAccess::del(KUrl(urls.at(i)), this);
287     }
288 }
289
290 void ProjectList::slotReloadClip(const QString &id)
291 {
292     QList<QTreeWidgetItem *> selected;
293     if (id.isEmpty()) selected = m_listView->selectedItems();
294     else selected.append(getItemById(id));
295     ProjectItem *item;
296     for (int i = 0; i < selected.count(); i++) {
297         if (selected.at(i)->type() == QTreeWidgetItem::UserType + 1) continue;
298         item = static_cast <ProjectItem *>(selected.at(i));
299         if (item && !item->isGroup()) {
300             if (item->clipType() == IMAGE) {
301                 item->referencedClip()->producer()->set("force_reload", 1);
302             } else if (item->clipType() == TEXT) {
303                 if (!item->referencedClip()->getProperty("xmltemplate").isEmpty()) regenerateTemplate(item);
304             }
305             //requestClipInfo(item->toXml(), item->clipId(), true);
306             // Clear the file_hash value, which will cause a complete reload of the clip
307             emit getFileProperties(item->toXml(), item->clipId(), true);
308         }
309     }
310 }
311
312 void ProjectList::setRenderer(Render *projectRender)
313 {
314     m_render = projectRender;
315     m_listView->setIconSize(QSize(40 * m_render->dar(), 40));
316 }
317
318 void ProjectList::slotClipSelected()
319 {
320     if (m_listView->currentItem()) {
321         ProjectItem *clip;
322         if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1) {
323             // this is a sub item, use base clip
324             clip = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
325             if (clip == NULL) kDebug() << "-----------ERROR";
326             SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
327             emit clipSelected(clip->referencedClip(), sub->zone());
328             return;
329         }
330         clip = static_cast <ProjectItem*>(m_listView->currentItem());
331         if (!clip->isGroup()) {
332             emit clipSelected(clip->referencedClip());
333         }
334         m_editAction->setEnabled(true);
335         m_deleteAction->setEnabled(true);
336         m_reloadAction->setEnabled(true);
337         m_transcodeAction->setEnabled(true);
338         if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
339             m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
340             m_openAction->setEnabled(true);
341         } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
342             m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
343             m_openAction->setEnabled(true);
344         } else m_openAction->setEnabled(false);
345     } else {
346         emit clipSelected(NULL);
347         m_editAction->setEnabled(false);
348         m_deleteAction->setEnabled(false);
349         m_openAction->setEnabled(false);
350         m_reloadAction->setEnabled(false);
351         m_transcodeAction->setEnabled(false);
352     }
353 }
354
355 void ProjectList::slotPauseMonitor()
356 {
357     if (m_render) m_render->pause();
358 }
359
360 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
361 {
362     ProjectItem *item = getItemById(id);
363     if (item) {
364         slotUpdateClipProperties(item, properties);
365         if (properties.contains("out")) {
366             slotReloadClip(id);
367         } else if (properties.contains("colour") || properties.contains("resource") || properties.contains("xmldata") || properties.contains("force_aspect_ratio") || properties.contains("templatetext")) {
368             slotRefreshClipThumbnail(item);
369             emit refreshClip();
370         }
371     }
372 }
373
374 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
375 {
376     if (!clip) return;
377     if (!clip->isGroup()) clip->setProperties(properties);
378     if (properties.contains("name")) {
379         m_listView->blockSignals(true);
380         clip->setText(1, properties.value("name"));
381         m_listView->blockSignals(false);
382         emit clipNameChanged(clip->clipId(), properties.value("name"));
383     }
384     if (properties.contains("description")) {
385         CLIPTYPE type = clip->clipType();
386         m_listView->blockSignals(true);
387         clip->setText(2, properties.value("description"));
388         m_listView->blockSignals(false);
389         if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
390             // Use Nepomuk system to store clip description
391             Nepomuk::Resource f(clip->clipUrl().path());
392             f.setDescription(properties.value("description"));
393         }
394         emit projectModified();
395     }
396 }
397
398 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
399 {
400     if (item->type() == QTreeWidgetItem::UserType + 1) {
401         // this is a sub-item
402         return;
403     }
404
405     ProjectItem *clip = static_cast <ProjectItem*>(item);
406     if (column == 2) {
407         if (clip->referencedClip()) {
408             QMap <QString, QString> oldprops;
409             QMap <QString, QString> newprops;
410             oldprops["description"] = clip->referencedClip()->getProperty("description");
411             newprops["description"] = item->text(2);
412
413             if (clip->clipType() == TEXT) {
414                 // This is a text template clip, update the image
415                 /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
416                 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/
417                 oldprops.insert("templatetext", clip->referencedClip()->getProperty("templatetext"));
418                 newprops.insert("templatetext", item->text(2));
419             }
420             slotUpdateClipProperties(clip->clipId(), newprops);
421             EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
422             m_commandStack->push(command);
423         }
424     } else if (column == 1) {
425         if (clip->isGroup()) {
426             editFolder(item->text(1), clip->groupName(), clip->clipId());
427             clip->setGroupName(item->text(1));
428             m_doc->clipManager()->addFolder(clip->clipId(), item->text(1));
429             const int children = item->childCount();
430             for (int i = 0; i < children; i++) {
431                 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
432                 child->setProperty("groupname", item->text(1));
433             }
434         } else {
435             if (clip->referencedClip()) {
436                 QMap <QString, QString> oldprops;
437                 QMap <QString, QString> newprops;
438                 oldprops["name"] = clip->referencedClip()->getProperty("name");
439                 newprops["name"] = item->text(1);
440                 slotUpdateClipProperties(clip, newprops);
441                 emit projectModified();
442                 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
443                 m_commandStack->push(command);
444             }
445         }
446     }
447 }
448
449 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
450 {
451     bool enable = false;
452     if (item) {
453         enable = true;
454     }
455     m_editAction->setEnabled(enable);
456     m_deleteAction->setEnabled(enable);
457     m_reloadAction->setEnabled(enable);
458     m_transcodeAction->setEnabled(enable);
459     if (enable) {
460         ProjectItem *clip;
461         if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1) {
462             clip = static_cast <ProjectItem*>(item->parent());
463         } else clip = static_cast <ProjectItem*>(item);
464         if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
465             m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
466             m_openAction->setEnabled(true);
467         } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
468             m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
469             m_openAction->setEnabled(true);
470         } else m_openAction->setEnabled(false);
471     } else m_openAction->setEnabled(false);
472     m_menu->popup(pos);
473 }
474
475 void ProjectList::slotRemoveClip()
476 {
477     if (!m_listView->currentItem()) return;
478     QStringList ids;
479     QMap <QString, QString> folderids;
480     QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
481
482     QUndoCommand *delCommand = new QUndoCommand();
483     delCommand->setText(i18n("Delete Clip Zone"));
484
485     for (int i = 0; i < selected.count(); i++) {
486         if (selected.at(i)->type() == QTreeWidgetItem::UserType + 1) {
487             // subitem
488             SubProjectItem *sub = static_cast <SubProjectItem *>(selected.at(i));
489             ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
490             new AddClipCutCommand(this, item->clipId(), sub->zone().x(), sub->zone().y(), true, delCommand);
491             continue;
492         }
493         ProjectItem *item = static_cast <ProjectItem *>(selected.at(i));
494         if (item->isGroup()) folderids[item->groupName()] = item->clipId();
495         else ids << item->clipId();
496         if (item->numReferences() > 0) {
497             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;
498         } else if (item->isGroup() && item->childCount() > 0) {
499             int children = item->childCount();
500             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;
501             for (int i = 0; i < children; ++i) {
502                 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
503                 ids << child->clipId();
504             }
505         }
506     }
507     if (delCommand->childCount() == 0) delete delCommand;
508     else m_commandStack->push(delCommand);
509     if (!ids.isEmpty()) m_doc->deleteProjectClip(ids);
510     if (!folderids.isEmpty()) deleteProjectFolder(folderids);
511     if (m_listView->topLevelItemCount() == 0) {
512         m_editAction->setEnabled(false);
513         m_deleteAction->setEnabled(false);
514         m_openAction->setEnabled(false);
515         m_reloadAction->setEnabled(false);
516         m_transcodeAction->setEnabled(false);
517     }
518 }
519
520 void ProjectList::selectItemById(const QString &clipId)
521 {
522     ProjectItem *item = getItemById(clipId);
523     if (item) m_listView->setCurrentItem(item);
524 }
525
526
527 void ProjectList::slotDeleteClip(const QString &clipId)
528 {
529     ProjectItem *item = getItemById(clipId);
530     if (!item) {
531         kDebug() << "/// Cannot find clip to delete";
532         return;
533     }
534     m_listView->blockSignals(true);
535     delete item;
536     m_doc->clipManager()->deleteClip(clipId);
537     m_listView->blockSignals(false);
538     slotClipSelected();
539 }
540
541
542 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
543 {
544     EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
545     m_commandStack->push(command);
546     m_doc->setModified(true);
547 }
548
549 void ProjectList::slotAddFolder()
550 {
551     AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
552     m_commandStack->push(command);
553 }
554
555 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
556 {
557     if (remove) {
558         ProjectItem *item = getFolderItemById(clipId);
559         if (item) {
560             m_doc->clipManager()->deleteFolder(clipId);
561             delete item;
562         }
563     } else {
564         if (edit) {
565             ProjectItem *item = getFolderItemById(clipId);
566             if (item) {
567                 m_listView->blockSignals(true);
568                 item->setGroupName(foldername);
569                 m_listView->blockSignals(false);
570                 m_doc->clipManager()->addFolder(clipId, foldername);
571                 const int children = item->childCount();
572                 for (int i = 0; i < children; i++) {
573                     ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
574                     child->setProperty("groupname", foldername);
575                 }
576             }
577         } else {
578             QStringList text;
579             text << QString() << foldername;
580             m_listView->blockSignals(true);
581             m_listView->setCurrentItem(new ProjectItem(m_listView, text, clipId));
582             m_doc->clipManager()->addFolder(clipId, foldername);
583             m_listView->blockSignals(false);
584         }
585     }
586 }
587
588
589
590 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
591 {
592     QMapIterator<QString, QString> i(map);
593     QUndoCommand *delCommand = new QUndoCommand();
594     delCommand->setText(i18n("Delete Folder"));
595     while (i.hasNext()) {
596         i.next();
597         new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
598     }
599     m_commandStack->push(delCommand);
600     m_doc->setModified(true);
601 }
602
603 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
604 {
605     m_listView->setEnabled(false);
606     if (getProperties) {
607         m_listView->blockSignals(true);
608         m_refreshed = false;
609         // remove file_hash so that we load all properties for the clip
610         QDomElement e = clip->toXML().cloneNode().toElement();
611         e.removeAttribute("file_hash");
612         m_infoQueue.insert(clip->getId(), e);
613         //m_render->getFileProperties(clip->toXML(), clip->getId(), true);
614     }
615     const QString parent = clip->getProperty("groupid");
616     ProjectItem *item = NULL;
617     if (!parent.isEmpty()) {
618         ProjectItem *parentitem = getFolderItemById(parent);
619         if (!parentitem) {
620             QStringList text;
621             QString groupName = clip->getProperty("groupname");
622             //kDebug() << "Adding clip to new group: " << groupName;
623             if (groupName.isEmpty()) groupName = i18n("Folder");
624             text << QString() << groupName;
625             parentitem = new ProjectItem(m_listView, text, parent);
626         } else {
627             //kDebug() << "Adding clip to existing group: " << parentitem->groupName();
628         }
629         if (parentitem) item = new ProjectItem(parentitem, clip);
630     }
631     if (item == NULL) item = new ProjectItem(m_listView, clip);
632     KUrl url = clip->fileURL();
633
634     if (getProperties == false && !clip->getClipHash().isEmpty()) {
635         QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
636         if (QFile::exists(cachedPixmap)) {
637             item->setIcon(0, QPixmap(cachedPixmap));
638         }
639     }
640
641     if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
642         // if file has Nepomuk comment, use it
643         Nepomuk::Resource f(url.path());
644         QString annotation = f.description();
645         if (!annotation.isEmpty()) item->setText(2, annotation);
646         item->setText(3, QString::number(f.rating()));
647     }
648
649     // Add cut zones
650     QList <QPoint> cuts = clip->cutZones();
651     if (!cuts.isEmpty()) {
652         for (int i = 0; i < cuts.count(); i++) {
653             SubProjectItem *sub = new SubProjectItem(item, cuts.at(i).x(), cuts.at(i).y());
654             if (!clip->getClipHash().isEmpty()) {
655                 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(cuts.at(i).x()) + ".png";
656                 if (QFile::exists(cachedPixmap)) {
657                     sub->setIcon(0, QPixmap(cachedPixmap));
658                 }
659             }
660         }
661     }
662
663     if (getProperties && m_listView->isEnabled()) m_listView->blockSignals(false);
664     if (getProperties && !m_queueTimer.isActive()) m_queueTimer.start();
665 }
666
667 void ProjectList::slotResetProjectList()
668 {
669     m_listView->clear();
670     emit clipSelected(NULL);
671     m_thumbnailQueue.clear();
672     m_infoQueue.clear();
673     m_refreshed = false;
674 }
675
676 void ProjectList::requestClipInfo(const QDomElement xml, const QString id)
677 {
678     m_refreshed = false;
679     m_infoQueue.insert(id, xml);
680     //if (m_infoQueue.count() == 1 || ) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
681 }
682
683 void ProjectList::slotProcessNextClipInQueue()
684 {
685     if (m_infoQueue.isEmpty()) {
686         slotProcessNextThumbnail();
687         return;
688     }
689
690     QMap<QString, QDomElement>::const_iterator j = m_infoQueue.constBegin();
691     if (j != m_infoQueue.constEnd()) {
692         const QDomElement dom = j.value();
693         const QString id = j.key();
694         m_infoQueue.remove(j.key());
695         emit getFileProperties(dom, id, false);
696     }
697 }
698
699 void ProjectList::slotUpdateClip(const QString &id)
700 {
701     ProjectItem *item = getItemById(id);
702     m_listView->blockSignals(true);
703     if (item) item->setData(1, UsageRole, QString::number(item->numReferences()));
704     m_listView->blockSignals(false);
705 }
706
707 void ProjectList::updateAllClips()
708 {
709     m_listView->setSortingEnabled(false);
710
711     QTreeWidgetItemIterator it(m_listView);
712     DocClipBase *clip;
713     ProjectItem *item;
714     m_listView->blockSignals(true);
715     while (*it) {
716         if ((*it)->type() == QTreeWidgetItem::UserType + 1) {
717             // subitem
718             SubProjectItem *sub = static_cast <SubProjectItem *>(*it);
719             if (sub->icon(0).isNull()) {
720                 item = static_cast <ProjectItem *>((*it)->parent());
721                 requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x()));
722             }
723             ++it;
724             continue;
725         }
726         item = static_cast <ProjectItem *>(*it);
727         if (!item->isGroup()) {
728             clip = item->referencedClip();
729             if (item->referencedClip()->producer() == NULL) {
730                 if (clip->isPlaceHolder() == false) {
731                     requestClipInfo(clip->toXML(), clip->getId());
732                 } else item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
733             } else {
734                 if (item->icon(0).isNull()) {
735                     requestClipThumbnail(clip->getId());
736                 }
737                 if (item->data(1, DurationRole).toString().isEmpty()) {
738                     item->changeDuration(item->referencedClip()->producer()->get_playtime());
739                 }
740             }
741             item->setData(1, UsageRole, QString::number(item->numReferences()));
742             //qApp->processEvents();
743         }
744         ++it;
745     }
746     qApp->processEvents();
747     if (!m_queueTimer.isActive()) m_queueTimer.start();
748
749     if (m_listView->isEnabled()) m_listView->blockSignals(false);
750     m_listView->setSortingEnabled(true);
751     if (m_infoQueue.isEmpty()) slotProcessNextThumbnail();
752 }
753
754 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
755 {
756     if (!m_commandStack) {
757         kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
758     }
759     KUrl::List list;
760     if (givenList.isEmpty()) {
761         // Build list of mime types
762         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";
763
764         QString allExtensions;
765         foreach(const QString& mimeType, mimeTypes) {
766             KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
767             if (mime) {
768                 allExtensions.append(mime->patterns().join(" "));
769                 allExtensions.append(' ');
770             }
771         }
772         const QString dialogFilter = allExtensions.simplified() + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
773         list = KFileDialog::getOpenUrls(KUrl("kfiledialog:///clipfolder"), dialogFilter, this);
774
775     } else {
776         for (int i = 0; i < givenList.count(); i++)
777             list << givenList.at(i);
778     }
779     if (list.isEmpty()) return;
780
781     if (givenList.isEmpty()) {
782         QStringList groupInfo = getGroup();
783         m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1));
784     } else m_doc->slotAddClipList(list, groupName, groupId);
785 }
786
787 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
788 {
789     ProjectItem *item = getItemById(id);
790     QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
791     if (item) {
792         const QString path = item->referencedClip()->fileURL().path();
793         if (!path.isEmpty()) {
794             if (replace) KMessageBox::sorry(this, i18n("Clip <b>%1</b><br>is invalid, will be removed from project.", path));
795             else {
796                 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;
797             }
798         }
799         QStringList ids;
800         ids << id;
801         if (replace) m_doc->deleteProjectClip(ids);
802     }
803 }
804
805 void ProjectList::slotAddColorClip()
806 {
807     if (!m_commandStack) {
808         kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
809     }
810     QDialog *dia = new QDialog(this);
811     Ui::ColorClip_UI dia_ui;
812     dia_ui.setupUi(dia);
813     dia_ui.clip_name->setText(i18n("Color Clip"));
814     dia_ui.clip_duration->setText(KdenliveSettings::color_duration());
815     if (dia->exec() == QDialog::Accepted) {
816         QString color = dia_ui.clip_color->color().name();
817         color = color.replace(0, 1, "0x") + "ff";
818         QStringList groupInfo = getGroup();
819         m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, dia_ui.clip_duration->text(), groupInfo.at(0), groupInfo.at(1));
820     }
821     delete dia;
822 }
823
824
825 void ProjectList::slotAddSlideshowClip()
826 {
827     if (!m_commandStack) {
828         kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
829     }
830     SlideshowClip *dia = new SlideshowClip(m_timecode, this);
831
832     if (dia->exec() == QDialog::Accepted) {
833         QStringList groupInfo = getGroup();
834         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));
835     }
836     delete dia;
837 }
838
839 void ProjectList::slotAddTitleClip()
840 {
841     QStringList groupInfo = getGroup();
842     m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
843 }
844
845 void ProjectList::slotAddTitleTemplateClip()
846 {
847     QStringList groupInfo = getGroup();
848     if (!m_commandStack) {
849         kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
850     }
851
852     // Get the list of existing templates
853     QStringList filter;
854     filter << "*.kdenlivetitle";
855     const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
856     QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
857
858     QDialog *dia = new QDialog(this);
859     Ui::TemplateClip_UI dia_ui;
860     dia_ui.setupUi(dia);
861     for (int i = 0; i < templateFiles.size(); ++i) {
862         dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
863     }
864     dia_ui.template_list->fileDialog()->setFilter("*.kdenlivetitle");
865     //warning: setting base directory doesn't work??
866     KUrl startDir(path);
867     dia_ui.template_list->fileDialog()->setUrl(startDir);
868     dia_ui.text_box->setHidden(true);
869     if (dia->exec() == QDialog::Accepted) {
870         QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
871         if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
872         // Create a cloned template clip
873         m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
874     }
875     delete dia;
876 }
877
878 QStringList ProjectList::getGroup() const
879 {
880     QStringList result;
881     ProjectItem *item = NULL;
882     if (m_listView->currentItem() && m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1) {
883         // sub item selected
884         item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
885     } else item = static_cast <ProjectItem*>(m_listView->currentItem());
886     if (item && !item->isGroup()) {
887         while (item->parent()) {
888             item = static_cast <ProjectItem*>(item->parent());
889             if (item->isGroup()) break;
890         }
891     }
892     if (item && item->isGroup()) {
893         result << item->groupName();
894         result << item->clipId();
895     } else result << QString() << QString();
896     return result;
897 }
898
899 void ProjectList::setDocument(KdenliveDoc *doc)
900 {
901     m_listView->blockSignals(true);
902     m_listView->clear();
903     m_listView->setSortingEnabled(false);
904     emit clipSelected(NULL);
905     m_thumbnailQueue.clear();
906     m_infoQueue.clear();
907     m_refreshed = false;
908     m_fps = doc->fps();
909     m_timecode = doc->timecode();
910     m_commandStack = doc->commandStack();
911     m_doc = doc;
912
913     QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
914     QMapIterator<QString, QString> f(flist);
915     while (f.hasNext()) {
916         f.next();
917         (void) new ProjectItem(m_listView, QStringList() << QString() << f.value(), f.key());
918     }
919
920     QList <DocClipBase*> list = doc->clipManager()->documentClipList();
921     for (int i = 0; i < list.count(); i++) {
922         slotAddClip(list.at(i), false);
923     }
924
925     m_listView->blockSignals(false);
926     m_toolbar->setEnabled(true);
927     connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
928     connect(m_doc->clipManager(), SIGNAL(checkAllClips()), this, SLOT(updateAllClips()));
929 }
930
931 QList <DocClipBase*> ProjectList::documentClipList() const
932 {
933     if (m_doc == NULL) return QList <DocClipBase*> ();
934     return m_doc->clipManager()->documentClipList();
935 }
936
937 QDomElement ProjectList::producersList()
938 {
939     QDomDocument doc;
940     QDomElement prods = doc.createElement("producerlist");
941     doc.appendChild(prods);
942     kDebug() << "////////////  PRO LIST BUILD PRDSLIST ";
943     QTreeWidgetItemIterator it(m_listView);
944     while (*it) {
945         if ((*it)->type() == QTreeWidgetItem::UserType + 1) {
946             // subitem
947             ++it;
948             continue;
949         }
950         if (!((ProjectItem *)(*it))->isGroup())
951             prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
952         ++it;
953     }
954     return prods;
955 }
956
957 void ProjectList::slotCheckForEmptyQueue()
958 {
959     if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
960         m_refreshed = true;
961         emit loadingIsOver();
962         emit displayMessage(QString(), -1);
963         m_listView->blockSignals(false);
964         m_listView->setEnabled(true);
965     } else if (!m_refreshed) QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
966 }
967
968 void ProjectList::reloadClipThumbnails()
969 {
970     kDebug() << "//////////////  RELOAD CLIPS THUMBNAILS!!!";
971     m_thumbnailQueue.clear();
972     QTreeWidgetItemIterator it(m_listView);
973     while (*it) {
974         if ((*it)->type() == QTreeWidgetItem::UserType + 1) {
975             // subitem
976             ++it;
977             continue;
978         }
979         if (!((ProjectItem *)(*it))->isGroup())
980             m_thumbnailQueue << ((ProjectItem *)(*it))->clipId();
981         ++it;
982     }
983     QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
984 }
985
986 void ProjectList::requestClipThumbnail(const QString id)
987 {
988     if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id);
989 }
990
991 void ProjectList::slotProcessNextThumbnail()
992 {
993     if (m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
994         slotCheckForEmptyQueue();
995         return;
996     }
997     if (!m_infoQueue.isEmpty()) {
998         //QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
999         return;
1000     }
1001     if (m_thumbnailQueue.count() > 1) {
1002         int max = m_doc->clipManager()->clipsCount();
1003         emit displayMessage(i18n("Loading thumbnails"), (int)(100 * (max - m_thumbnailQueue.count()) / max));
1004     }
1005     slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
1006 }
1007
1008 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
1009 {
1010     QTreeWidgetItem *item = getAnyItemById(clipId);
1011     if (item) slotRefreshClipThumbnail(item, update);
1012     else slotProcessNextThumbnail();
1013 }
1014
1015 void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
1016 {
1017     if (it == NULL) return;
1018     ProjectItem *item = NULL;
1019     bool isSubItem = false;
1020     int frame;
1021     if (it->type() == QTreeWidgetItem::UserType + 1) {
1022         item = static_cast <ProjectItem *>(it->parent());
1023         frame = static_cast <SubProjectItem *>(it)->zone().x();
1024         isSubItem = true;
1025     } else {
1026         item = static_cast <ProjectItem *>(it);
1027         frame = item->referencedClip()->getClipThumbFrame();
1028     }
1029
1030     if (item) {
1031         DocClipBase *clip = item->referencedClip();
1032         if (!clip) {
1033             slotProcessNextThumbnail();
1034             return;
1035         }
1036         QPixmap pix;
1037         int height = it->sizeHint(0).height();
1038         int width = (int)(height  * m_render->dar());
1039         if (clip->clipType() == AUDIO) pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
1040         else if (clip->clipType() == IMAGE) pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->producer(), 0, width, height));
1041         else pix = item->referencedClip()->thumbProducer()->extractImage(frame, width, height);
1042
1043         if (!pix.isNull()) {
1044             m_listView->blockSignals(true);
1045             it->setIcon(0, pix);
1046             if (m_listView->isEnabled()) m_listView->blockSignals(false);
1047             if (!isSubItem) m_doc->cachePixmap(item->getClipHash(), pix);
1048             else m_doc->cachePixmap(item->getClipHash() + '#' + QString::number(frame), pix);
1049         }
1050         if (update) emit projectModified();
1051         QTimer::singleShot(30, this, SLOT(slotProcessNextThumbnail()));
1052     }
1053 }
1054
1055 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace)
1056 {
1057     ProjectItem *item = getItemById(clipId);
1058     if (item && producer) {
1059         m_listView->blockSignals(true);
1060         item->setProperties(properties, metadata);
1061         Q_ASSERT_X(item->referencedClip(), "void ProjectList::slotReplyGetFileProperties", QString("Item with groupName %1 does not have a clip associated").arg(item->groupName()).toLatin1());
1062         item->referencedClip()->setProducer(producer, replace);
1063         //emit receivedClipDuration(clipId);
1064         if (m_listView->isEnabled() && replace) {
1065             // update clip in clip monitor
1066             emit clipSelected(NULL);
1067             emit clipSelected(item->referencedClip());
1068         }
1069         /*else {
1070             // Check if duration changed.
1071             emit receivedClipDuration(clipId);
1072             delete producer;
1073         }*/
1074         if (m_listView->isEnabled()) m_listView->blockSignals(false);
1075         if (item->icon(0).isNull()) {
1076             requestClipThumbnail(clipId);
1077         }
1078     } else kDebug() << "////////  COULD NOT FIND CLIP TO UPDATE PRPS...";
1079     int max = m_doc->clipManager()->clipsCount();
1080     emit displayMessage(i18n("Loading clips"), (int)(100 * (max - m_infoQueue.count()) / max));
1081     // small delay so that the app can display the progress info
1082     if (item && m_infoQueue.isEmpty() && m_thumbnailQueue.isEmpty()) {
1083         m_listView->setCurrentItem(item);
1084         emit clipSelected(item->referencedClip());
1085     }
1086     QTimer::singleShot(30, this, SLOT(slotProcessNextClipInQueue()));
1087 }
1088
1089 void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
1090 {
1091     ProjectItem *item = getItemById(clipId);
1092     if (item && !pix.isNull()) {
1093         m_listView->blockSignals(true);
1094         item->setIcon(0, pix);
1095         m_doc->cachePixmap(item->getClipHash(), pix);
1096         if (m_listView->isEnabled()) m_listView->blockSignals(false);
1097     }
1098 }
1099
1100 QTreeWidgetItem *ProjectList::getAnyItemById(const QString &id)
1101 {
1102     QTreeWidgetItemIterator it(m_listView);
1103     QString lookId = id;
1104     if (id.contains('#')) {
1105         lookId = id.section('#', 0, 0);
1106     }
1107
1108     ProjectItem *result = NULL;
1109     while (*it) {
1110         if ((*it)->type() == QTreeWidgetItem::UserType + 1) {
1111             // subitem
1112             ++it;
1113             continue;
1114         }
1115         ProjectItem *item = static_cast<ProjectItem *>(*it);
1116         if (item->clipId() == lookId && item->clipType() != FOLDER) {
1117             result = item;
1118             break;
1119         }
1120         ++it;
1121     }
1122     if (!id.contains('#')) return result;
1123     else for (int i = 0; i < result->childCount(); i++) {
1124             SubProjectItem *sub = static_cast <SubProjectItem *>(result->child(i));
1125             if (sub && sub->zone().x() == id.section('#', 1, 1).toInt()) {
1126                 return sub;
1127             }
1128         }
1129
1130     return NULL;
1131 }
1132
1133
1134 ProjectItem *ProjectList::getItemById(const QString &id)
1135 {
1136     ProjectItem *item;
1137     QTreeWidgetItemIterator it(m_listView);
1138     while (*it) {
1139         if ((*it)->type() == QTreeWidgetItem::UserType + 1) {
1140             // subitem
1141             ++it;
1142             continue;
1143         }
1144         item = static_cast<ProjectItem *>(*it);
1145         if (item->clipId() == id && item->clipType() != FOLDER)
1146             return item;
1147         ++it;
1148     }
1149     return NULL;
1150 }
1151
1152 ProjectItem *ProjectList::getFolderItemById(const QString &id)
1153 {
1154     ProjectItem *item;
1155     QTreeWidgetItemIterator it(m_listView);
1156     while (*it) {
1157         item = static_cast<ProjectItem *>(*it);
1158         if (item->clipId() == id && item->clipType() == FOLDER)
1159             return item;
1160         ++it;
1161     }
1162     return NULL;
1163 }
1164
1165 void ProjectList::slotSelectClip(const QString &ix)
1166 {
1167     ProjectItem *clip = getItemById(ix);
1168     if (clip) {
1169         m_listView->setCurrentItem(clip);
1170         m_listView->scrollToItem(clip);
1171         m_editAction->setEnabled(true);
1172         m_deleteAction->setEnabled(true);
1173         m_reloadAction->setEnabled(true);
1174         m_transcodeAction->setEnabled(true);
1175         if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
1176             m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
1177             m_openAction->setEnabled(true);
1178         } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
1179             m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
1180             m_openAction->setEnabled(true);
1181         } else m_openAction->setEnabled(false);
1182     }
1183 }
1184
1185 QString ProjectList::currentClipUrl() const
1186 {
1187     ProjectItem *item;
1188     if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1) {
1189         // subitem
1190         item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
1191     } else item = static_cast <ProjectItem*>(m_listView->currentItem());
1192     if (item == NULL) return QString();
1193     return item->clipUrl().path();
1194 }
1195
1196 void ProjectList::regenerateTemplate(const QString &id)
1197 {
1198     ProjectItem *clip = getItemById(id);
1199     if (clip) regenerateTemplate(clip);
1200 }
1201
1202 void ProjectList::regenerateTemplate(ProjectItem *clip)
1203 {
1204     //TODO: remove this unused method, only force_reload is necessary
1205     clip->referencedClip()->producer()->set("force_reload", 1);
1206 }
1207
1208 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
1209 {
1210     QDomDocument doc;
1211     QFile file(path);
1212     if (!file.open(QIODevice::ReadOnly)) {
1213         kWarning() << "ERROR, CANNOT READ: " << path;
1214         return doc;
1215     }
1216     if (!doc.setContent(&file)) {
1217         kWarning() << "ERROR, CANNOT READ: " << path;
1218         file.close();
1219         return doc;
1220     }
1221     file.close();
1222     QDomNodeList texts = doc.elementsByTagName("content");
1223     for (int i = 0; i < texts.count(); i++) {
1224         QString data = texts.item(i).firstChild().nodeValue();
1225         data.replace("%s", replaceString);
1226         texts.item(i).firstChild().setNodeValue(data);
1227     }
1228     return doc;
1229 }
1230
1231
1232 void ProjectList::slotAddClipCut(const QString &id, int in, int out)
1233 {
1234     ProjectItem *clip = getItemById(id);
1235     if (clip == NULL) return;
1236     if (clip->referencedClip()->hasCutZone(QPoint(in, out))) return;
1237     AddClipCutCommand *command = new AddClipCutCommand(this, id, in, out, false);
1238     m_commandStack->push(command);
1239 }
1240
1241 void ProjectList::addClipCut(const QString &id, int in, int out)
1242 {
1243     ProjectItem *clip = getItemById(id);
1244     if (clip) {
1245         DocClipBase *base = clip->referencedClip();
1246         base->addCutZone(in, out);
1247         m_listView->blockSignals(true);
1248         SubProjectItem *sub = new SubProjectItem(clip, in, out);
1249
1250         QPixmap p = clip->referencedClip()->thumbProducer()->extractImage(in, (int)(sub->sizeHint(0).height()  * m_render->dar()), sub->sizeHint(0).height());
1251         sub->setIcon(0, p);
1252         m_doc->cachePixmap(clip->getClipHash() + '#' + QString::number(in), p);
1253         m_listView->blockSignals(false);
1254     }
1255 }
1256
1257 void ProjectList::removeClipCut(const QString &id, int in, int out)
1258 {
1259     ProjectItem *clip = getItemById(id);
1260     if (clip) {
1261         DocClipBase *base = clip->referencedClip();
1262         base->removeCutZone(in, out);
1263         for (int i = 0; i < clip->childCount(); i++) {
1264             QTreeWidgetItem *it = clip->child(i);
1265             if (it->type() != QTreeWidgetItem::UserType + 1) continue;
1266             SubProjectItem *sub = static_cast <SubProjectItem*>(it);
1267             if (sub->zone() == QPoint(in, out)) {
1268                 m_listView->blockSignals(true);
1269                 delete it;
1270                 m_listView->blockSignals(false);
1271                 break;
1272             }
1273         }
1274     }
1275 }
1276
1277 #include "projectlist.moc"