]> git.sesse.net Git - kdenlive/blob - src/projectlist.cpp
8264afeec9aec3f7f37a8071e7d830c30aaf7f1a
[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 "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"
31 #include "renderer.h"
32 #include "kthumb.h"
33 #include "projectlistview.h"
34 #include "timecodedisplay.h"
35 #include "profilesdialog.h"
36 #include "editclipcommand.h"
37 #include "editclipcutcommand.h"
38 #include "editfoldercommand.h"
39 #include "addclipcutcommand.h"
40
41 #include "ui_templateclip_ui.h"
42
43 #include <KDebug>
44 #include <KAction>
45 #include <KLocale>
46 #include <KFileDialog>
47 #include <KInputDialog>
48 #include <KMessageBox>
49 #include <KIO/NetAccess>
50 #include <KFileItem>
51 #ifdef NEPOMUK
52 #include <nepomuk/global.h>
53 #include <nepomuk/resourcemanager.h>
54 //#include <nepomuk/tag.h>
55 #endif
56
57 #include <QMouseEvent>
58 #include <QStylePainter>
59 #include <QPixmap>
60 #include <QIcon>
61 #include <QMenu>
62 #include <QProcess>
63 #include <QHeaderView>
64 #include <QInputDialog>
65
66 ProjectList::ProjectList(QWidget *parent) :
67     QWidget(parent),
68     m_render(NULL),
69     m_fps(-1),
70     m_commandStack(NULL),
71     m_editAction(NULL),
72     m_deleteAction(NULL),
73     m_openAction(NULL),
74     m_reloadAction(NULL),
75     m_transcodeAction(NULL),
76     m_doc(NULL),
77     m_refreshed(false),
78     m_infoQueue(),
79     m_thumbnailQueue()
80 {
81
82     m_listView = new ProjectListView(this);;
83     QVBoxLayout *layout = new QVBoxLayout;
84     layout->setContentsMargins(0, 0, 0, 0);
85     layout->setSpacing(0);
86
87     // setup toolbar
88     KTreeWidgetSearchLine *searchView = new KTreeWidgetSearchLine(this);
89     m_toolbar = new QToolBar("projectToolBar", this);
90     m_toolbar->addWidget(searchView);
91     int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
92     m_toolbar->setIconSize(QSize(s, s));
93     searchView->setTreeWidget(m_listView);
94
95     m_addButton = new QToolButton(m_toolbar);
96     m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
97     m_toolbar->addWidget(m_addButton);
98
99     layout->addWidget(m_toolbar);
100     layout->addWidget(m_listView);
101     setLayout(layout);
102
103     m_queueTimer.setInterval(100);
104     connect(&m_queueTimer, SIGNAL(timeout()), this, SLOT(slotProcessNextClipInQueue()));
105     m_queueTimer.setSingleShot(true);
106
107
108     connect(m_listView, SIGNAL(projectModified()), this, SIGNAL(projectModified()));
109     connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
110     connect(m_listView, SIGNAL(focusMonitor()), this, SLOT(slotClipSelected()));
111     connect(m_listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
112     connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
113     connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
114     connect(m_listView, SIGNAL(addClip(const QList <QUrl>, const QString &, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &, const QString &)));
115     connect(m_listView, SIGNAL(addClipCut(const QString &, int, int)), this, SLOT(slotAddClipCut(const QString &, int, int)));
116     connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
117     connect(m_listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
118
119     m_listViewDelegate = new ItemDelegate(m_listView);
120     m_listView->setItemDelegate(m_listViewDelegate);
121 #ifdef NEPOMUK
122     if (KdenliveSettings::activate_nepomuk()) {
123         Nepomuk::ResourceManager::instance()->init();
124         if (!Nepomuk::ResourceManager::instance()->initialized()) {
125             kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
126             KdenliveSettings::setActivate_nepomuk(false);
127         }
128     }
129 #endif
130 }
131
132 ProjectList::~ProjectList()
133 {
134     delete m_menu;
135     delete m_toolbar;
136     m_listView->blockSignals(true);
137     m_listView->clear();
138     delete m_listViewDelegate;
139 }
140
141 void ProjectList::focusTree() const
142 {
143     m_listView->setFocus();
144 }
145
146 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
147 {
148     QList <QAction *> actions = addMenu->actions();
149     for (int i = 0; i < actions.count(); i++) {
150         if (actions.at(i)->data().toString() == "clip_properties") {
151             m_editAction = actions.at(i);
152             m_toolbar->addAction(m_editAction);
153             actions.removeAt(i);
154             i--;
155         } else if (actions.at(i)->data().toString() == "delete_clip") {
156             m_deleteAction = actions.at(i);
157             m_toolbar->addAction(m_deleteAction);
158             actions.removeAt(i);
159             i--;
160         } else if (actions.at(i)->data().toString() == "edit_clip") {
161             m_openAction = actions.at(i);
162             actions.removeAt(i);
163             i--;
164         } else if (actions.at(i)->data().toString() == "reload_clip") {
165             m_reloadAction = actions.at(i);
166             actions.removeAt(i);
167             i--;
168         }
169     }
170
171     QMenu *m = new QMenu();
172     m->addActions(actions);
173     m_addButton->setMenu(m);
174     m_addButton->setDefaultAction(defaultAction);
175     m_menu = new QMenu();
176     m_menu->addActions(addMenu->actions());
177 }
178
179 void ProjectList::setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu, QMenu *inTimelineMenu)
180 {
181     if (!addMenu)
182         return;
183     QMenu *menu = m_addButton->menu();
184     menu->addMenu(addMenu);
185     m_addButton->setMenu(menu);
186
187     m_menu->addMenu(addMenu);
188     if (addMenu->isEmpty())
189         addMenu->setEnabled(false);
190     m_menu->addMenu(transcodeMenu);
191     if (transcodeMenu->isEmpty())
192         transcodeMenu->setEnabled(false);
193     m_transcodeAction = transcodeMenu;
194     m_menu->addAction(m_reloadAction);
195     m_menu->addMenu(inTimelineMenu);
196     inTimelineMenu->setEnabled(false);
197     m_menu->addAction(m_editAction);
198     m_menu->addAction(m_openAction);
199     m_menu->addAction(m_deleteAction);
200     m_menu->insertSeparator(m_deleteAction);
201 }
202
203
204 QByteArray ProjectList::headerInfo() const
205 {
206     return m_listView->header()->saveState();
207 }
208
209 void ProjectList::setHeaderInfo(const QByteArray &state)
210 {
211     m_listView->header()->restoreState(state);
212 }
213
214 void ProjectList::updateProjectFormat(Timecode t)
215 {
216     m_timecode = t;
217 }
218
219 void ProjectList::slotEditClip()
220 {
221     QList<QTreeWidgetItem *> list = m_listView->selectedItems();
222     if (list.count() > 1) {
223         editClipSelection(list);
224         return;
225     }
226     ProjectItem *item;
227     if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
228         return;
229     if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE)
230         item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
231     else
232         item = static_cast <ProjectItem*>(m_listView->currentItem());
233     if (item && (item->flags() & Qt::ItemIsDragEnabled)) {
234         emit clipSelected(item->referencedClip());
235         emit showClipProperties(item->referencedClip());
236     }
237 }
238
239 void ProjectList::editClipSelection(QList<QTreeWidgetItem *> list)
240 {
241     // Gather all common properties
242     QMap <QString, QString> commonproperties;
243     QList <DocClipBase *> clipList;
244     commonproperties.insert("force_aspect_ratio", "-");
245     commonproperties.insert("force_fps", "-");
246     commonproperties.insert("force_progressive", "-");
247     commonproperties.insert("threads", "-");
248     commonproperties.insert("video_index", "-");
249     commonproperties.insert("audio_index", "-");
250
251     bool allowDurationChange = true;
252     int commonDuration = -1;
253     ProjectItem *item;
254     for (int i = 0; i < list.count(); i++) {
255         item = NULL;
256         if (list.at(i)->type() == PROJECTFOLDERTYPE)
257             continue;
258         if (list.at(i)->type() == PROJECTSUBCLIPTYPE)
259             item = static_cast <ProjectItem*>(list.at(i)->parent());
260         else
261             item = static_cast <ProjectItem*>(list.at(i));
262         if (!(item->flags() & Qt::ItemIsDragEnabled))
263             continue;
264         if (item) {
265             // check properties
266             DocClipBase *clip = item->referencedClip();
267             if (clipList.contains(clip)) continue;
268             if (clip->clipType() != COLOR && clip->clipType() != IMAGE && clip->clipType() != TEXT)
269                 allowDurationChange = false;
270             if (allowDurationChange && commonDuration != 0) {
271                 if (commonDuration == -1)
272                     commonDuration = clip->duration().frames(m_fps);
273                 else if (commonDuration != clip->duration().frames(m_fps))
274                     commonDuration = 0;
275             }
276             clipList.append(clip);
277             QMap <QString, QString> clipprops = clip->properties();
278             QMapIterator<QString, QString> p(commonproperties);
279             while (p.hasNext()) {
280                 p.next();
281                 if (p.value().isEmpty()) continue;
282                 if (clipprops.contains(p.key())) {
283                     if (p.value() == "-")
284                         commonproperties.insert(p.key(), clipprops.value(p.key()));
285                     else if (p.value() != clipprops.value(p.key()))
286                         commonproperties.insert(p.key(), QString());
287                 } else {
288                     commonproperties.insert(p.key(), QString());
289                 }
290             }
291         }
292     }
293     if (allowDurationChange)
294         commonproperties.insert("out", QString::number(commonDuration));
295     QMapIterator<QString, QString> p(commonproperties);
296     while (p.hasNext()) {
297         p.next();
298         kDebug() << "Result: " << p.key() << " = " << p.value();
299     }
300     emit showClipProperties(clipList, commonproperties);
301 }
302
303 void ProjectList::slotOpenClip()
304 {
305     ProjectItem *item;
306     if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
307         return;
308     if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1)
309         item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
310     else
311         item = static_cast <ProjectItem*>(m_listView->currentItem());
312     if (item) {
313         if (item->clipType() == IMAGE) {
314             if (KdenliveSettings::defaultimageapp().isEmpty())
315                 KMessageBox::sorry(this, i18n("Please set a default application to open images in the Settings dialog"));
316             else
317                 QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
318         }
319         if (item->clipType() == AUDIO) {
320             if (KdenliveSettings::defaultaudioapp().isEmpty())
321                 KMessageBox::sorry(this, i18n("Please set a default application to open audio files in the Settings dialog"));
322             else
323                 QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
324         }
325     }
326 }
327
328 void ProjectList::cleanup()
329 {
330     m_listView->clearSelection();
331     QTreeWidgetItemIterator it(m_listView);
332     ProjectItem *item;
333     while (*it) {
334         if ((*it)->type() != PROJECTCLIPTYPE) {
335             it++;
336             continue;
337         }
338         item = static_cast <ProjectItem *>(*it);
339         if (item->numReferences() == 0)
340             item->setSelected(true);
341         it++;
342     }
343     slotRemoveClip();
344 }
345
346 void ProjectList::trashUnusedClips()
347 {
348     QTreeWidgetItemIterator it(m_listView);
349     ProjectItem *item;
350     QStringList ids;
351     QStringList urls;
352     while (*it) {
353         if ((*it)->type() != PROJECTCLIPTYPE) {
354             it++;
355             continue;
356         }
357         item = static_cast <ProjectItem *>(*it);
358         if (item->numReferences() == 0) {
359             ids << item->clipId();
360             KUrl url = item->clipUrl();
361             if (!url.isEmpty() && !urls.contains(url.path()))
362                 urls << url.path();
363         }
364         it++;
365     }
366
367     // Check that we don't use the URL in another clip
368     QTreeWidgetItemIterator it2(m_listView);
369     while (*it2) {
370         if ((*it2)->type() != PROJECTCLIPTYPE) {
371             it2++;
372             continue;
373         }
374         item = static_cast <ProjectItem *>(*it2);
375         if (item->numReferences() > 0) {
376             KUrl url = item->clipUrl();
377             if (!url.isEmpty() && urls.contains(url.path())) urls.removeAll(url.path());
378         }
379         it2++;
380     }
381
382     emit deleteProjectClips(ids, QMap <QString, QString>());
383     for (int i = 0; i < urls.count(); i++)
384         KIO::NetAccess::del(KUrl(urls.at(i)), this);
385 }
386
387 void ProjectList::slotReloadClip(const QString &id)
388 {
389     QList<QTreeWidgetItem *> selected;
390     if (id.isEmpty())
391         selected = m_listView->selectedItems();
392     else
393         selected.append(getItemById(id));
394     ProjectItem *item;
395     for (int i = 0; i < selected.count(); i++) {
396         if (selected.at(i)->type() != PROJECTCLIPTYPE) {
397             if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
398                 for (int j = 0; j < selected.at(i)->childCount(); j++)
399                     selected.append(selected.at(i)->child(j));
400             }
401             continue;
402         }
403         item = static_cast <ProjectItem *>(selected.at(i));
404         if (item) {
405             if (item->clipType() == TEXT) {
406                 if (!item->referencedClip()->getProperty("xmltemplate").isEmpty())
407                     regenerateTemplate(item);
408             } else if (item->clipType() != COLOR && item->clipType() != SLIDESHOW && item->referencedClip() &&  item->referencedClip()->checkHash() == false) {
409                 item->referencedClip()->setPlaceHolder(true);
410                 item->setProperty("file_hash", QString());
411             } else if (item->clipType() == IMAGE) {
412                 item->referencedClip()->producer()->set("force_reload", 1);
413             }
414             //requestClipInfo(item->toXml(), item->clipId(), true);
415             // Clear the file_hash value, which will cause a complete reload of the clip
416             emit getFileProperties(item->toXml(), item->clipId(), m_listView->iconSize().height(), true);
417         }
418     }
419 }
420
421 void ProjectList::slotModifiedClip(const QString &id)
422 {
423     ProjectItem *item = getItemById(id);
424     if (item) {
425         QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
426         if (!pixmap.isNull()) {
427             QPainter p(&pixmap);
428             p.fillRect(0, 0, pixmap.width(), pixmap.height(), QColor(255, 255, 255, 200));
429             p.drawPixmap(0, 0, KIcon("view-refresh").pixmap(m_listView->iconSize()));
430             p.end();
431         } else {
432             pixmap = KIcon("view-refresh").pixmap(m_listView->iconSize());
433         }
434         item->setData(0, Qt::DecorationRole, pixmap);
435     }
436 }
437
438 void ProjectList::slotMissingClip(const QString &id)
439 {
440     ProjectItem *item = getItemById(id);
441     if (item) {
442         item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
443         if (item->referencedClip()) {
444             item->referencedClip()->setPlaceHolder(true);
445             if (m_render == NULL) kDebug() << "*********  ERROR, NULL RENDR";
446             item->referencedClip()->setProducer(m_render->invalidProducer(id), true);
447             item->slotSetToolTip();
448             emit clipNeedsReload(id, true);
449         }
450     }
451     update();
452     emit displayMessage(i18n("Check missing clips"), -2);
453     emit updateRenderStatus();
454 }
455
456 void ProjectList::slotAvailableClip(const QString &id)
457 {
458     ProjectItem *item = getItemById(id);
459     if (item == NULL)
460         return;
461     item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
462     if (item->referencedClip()) { // && item->referencedClip()->checkHash() == false) {
463         item->setProperty("file_hash", QString());
464         slotReloadClip(id);
465     }
466     /*else {
467     item->referencedClip()->setValid();
468     item->slotSetToolTip();
469     }
470     update();*/
471     emit updateRenderStatus();
472 }
473
474 bool ProjectList::hasMissingClips()
475 {
476     bool missing = false;
477     QTreeWidgetItemIterator it(m_listView);
478     while (*it) {
479         if ((*it)->type() == PROJECTCLIPTYPE && !((*it)->flags() & Qt::ItemIsDragEnabled)) {
480             missing = true;
481             break;
482         }
483         it++;
484     }
485     return missing;
486 }
487
488 void ProjectList::setRenderer(Render *projectRender)
489 {
490     m_render = projectRender;
491     m_listView->setIconSize(QSize((ProjectItem::itemDefaultHeight() - 2) * m_render->dar(), ProjectItem::itemDefaultHeight() - 2));
492 }
493
494 void ProjectList::slotClipSelected()
495 {
496     if (!m_listView->isEnabled()) return;
497     if (m_listView->currentItem()) {
498         if (m_listView->currentItem()->type() == PROJECTFOLDERTYPE) {
499             emit clipSelected(NULL);
500             m_editAction->setEnabled(false);
501             m_deleteAction->setEnabled(true);
502             m_openAction->setEnabled(false);
503             m_reloadAction->setEnabled(false);
504             m_transcodeAction->setEnabled(false);
505         } else {
506             ProjectItem *clip;
507             if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
508                 // this is a sub item, use base clip
509                 m_deleteAction->setEnabled(true);
510                 clip = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
511                 if (clip == NULL) kDebug() << "-----------ERROR";
512                 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
513                 emit clipSelected(clip->referencedClip(), sub->zone());
514                 m_transcodeAction->setEnabled(false);
515                 return;
516             }
517             clip = static_cast <ProjectItem*>(m_listView->currentItem());
518             if (clip)
519                 emit clipSelected(clip->referencedClip());
520             m_editAction->setEnabled(true);
521             m_deleteAction->setEnabled(true);
522             m_reloadAction->setEnabled(true);
523             m_transcodeAction->setEnabled(true);
524             if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
525                 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
526                 m_openAction->setEnabled(true);
527             } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
528                 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
529                 m_openAction->setEnabled(true);
530             } else {
531                 m_openAction->setEnabled(false);
532             }
533             // Display relevant transcoding actions only
534             adjustTranscodeActions(clip);
535             // Display uses in timeline
536             emit findInTimeline(clip->clipId());
537         }
538     } else {
539         emit clipSelected(NULL);
540         m_editAction->setEnabled(false);
541         m_deleteAction->setEnabled(false);
542         m_openAction->setEnabled(false);
543         m_reloadAction->setEnabled(false);
544         m_transcodeAction->setEnabled(false);
545     }
546 }
547
548 void ProjectList::adjustTranscodeActions(ProjectItem *clip) const
549 {
550     if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW) {
551         m_transcodeAction->setEnabled(false);
552         return;
553     }
554     m_transcodeAction->setEnabled(true);
555     QList<QAction *> transcodeActions = m_transcodeAction->actions();
556     QStringList data;
557     QString condition;
558     for (int i = 0; i < transcodeActions.count(); i++) {
559         data = transcodeActions.at(i)->data().toStringList();
560         if (data.count() > 2) {
561             condition = data.at(2);
562             if (condition.startsWith("vcodec"))
563                 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
564             else if (condition.startsWith("acodec"))
565                 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
566         }
567     }
568
569 }
570
571 void ProjectList::slotPauseMonitor()
572 {
573     if (m_render)
574         m_render->pause();
575 }
576
577 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
578 {
579     ProjectItem *item = getItemById(id);
580     if (item) {
581         slotUpdateClipProperties(item, properties);
582         if (properties.contains("out") || properties.contains("force_fps")) {
583             slotReloadClip(id);
584         } else if (properties.contains("colour") || properties.contains("resource") || properties.contains("xmldata") || properties.contains("force_aspect_ratio") || properties.contains("templatetext")) {
585             slotRefreshClipThumbnail(item);
586             emit refreshClip();
587         }
588     }
589 }
590
591 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
592 {
593     if (!clip)
594         return;
595     clip->setProperties(properties);
596     if (properties.contains("name")) {
597         m_listView->blockSignals(true);
598         clip->setText(0, properties.value("name"));
599         m_listView->blockSignals(false);
600         emit clipNameChanged(clip->clipId(), properties.value("name"));
601     }
602     if (properties.contains("description")) {
603         CLIPTYPE type = clip->clipType();
604         m_listView->blockSignals(true);
605         clip->setText(1, properties.value("description"));
606         m_listView->blockSignals(false);
607 #ifdef NEPOMUK
608         if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
609             // Use Nepomuk system to store clip description
610             Nepomuk::Resource f(clip->clipUrl().path());
611             f.setDescription(properties.value("description"));
612         }
613 #endif
614         emit projectModified();
615     }
616 }
617
618 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
619 {
620     if (item->type() == PROJECTSUBCLIPTYPE) {
621         // this is a sub-item
622         if (column == 1) {
623             // user edited description
624             SubProjectItem *sub = static_cast <SubProjectItem*>(item);
625             ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
626             EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), sub->zone(), sub->description(), sub->text(1), true);
627             m_commandStack->push(command);
628             //slotUpdateCutClipProperties(sub->clipId(), sub->zone(), sub->text(1), sub->text(1));
629         }
630         return;
631     }
632     if (item->type() == PROJECTFOLDERTYPE) {
633         if (column == 0) {
634             FolderProjectItem *folder = static_cast <FolderProjectItem*>(item);
635             editFolder(item->text(0), folder->groupName(), folder->clipId());
636             folder->setGroupName(item->text(0));
637             m_doc->clipManager()->addFolder(folder->clipId(), item->text(0));
638             const int children = item->childCount();
639             for (int i = 0; i < children; i++) {
640                 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
641                 child->setProperty("groupname", item->text(0));
642             }
643         }
644         return;
645     }
646
647     ProjectItem *clip = static_cast <ProjectItem*>(item);
648     if (column == 1) {
649         if (clip->referencedClip()) {
650             QMap <QString, QString> oldprops;
651             QMap <QString, QString> newprops;
652             oldprops["description"] = clip->referencedClip()->getProperty("description");
653             newprops["description"] = item->text(1);
654
655             if (clip->clipType() == TEXT) {
656                 // This is a text template clip, update the image
657                 /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
658                 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/
659                 oldprops.insert("templatetext", clip->referencedClip()->getProperty("templatetext"));
660                 newprops.insert("templatetext", item->text(1));
661             }
662             slotUpdateClipProperties(clip->clipId(), newprops);
663             EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
664             m_commandStack->push(command);
665         }
666     } else if (column == 0) {
667         if (clip->referencedClip()) {
668             QMap <QString, QString> oldprops;
669             QMap <QString, QString> newprops;
670             oldprops["name"] = clip->referencedClip()->getProperty("name");
671             newprops["name"] = item->text(0);
672             slotUpdateClipProperties(clip, newprops);
673             emit projectModified();
674             EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
675             m_commandStack->push(command);
676         }
677     }
678 }
679
680 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
681 {
682     bool enable = item ? true : false;
683     m_editAction->setEnabled(enable);
684     m_deleteAction->setEnabled(enable);
685     m_reloadAction->setEnabled(enable);
686     m_transcodeAction->setEnabled(enable);
687     if (enable) {
688         ProjectItem *clip = NULL;
689         if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
690             clip = static_cast <ProjectItem*>(item->parent());
691             m_transcodeAction->setEnabled(false);
692         } else if (m_listView->currentItem()->type() == PROJECTCLIPTYPE) {
693             clip = static_cast <ProjectItem*>(item);
694             // Display relevant transcoding actions only
695             adjustTranscodeActions(clip);
696             // Display uses in timeline
697             emit findInTimeline(clip->clipId());
698         } else {
699             m_transcodeAction->setEnabled(false);
700         }
701         if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
702             m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
703             m_openAction->setEnabled(true);
704         } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
705             m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
706             m_openAction->setEnabled(true);
707         } else {
708             m_openAction->setEnabled(false);
709         }
710
711     } else {
712         m_openAction->setEnabled(false);
713     }
714     m_menu->popup(pos);
715 }
716
717 void ProjectList::slotRemoveClip()
718 {
719     if (!m_listView->currentItem())
720         return;
721     QStringList ids;
722     QMap <QString, QString> folderids;
723     QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
724
725     QUndoCommand *delCommand = new QUndoCommand();
726     delCommand->setText(i18n("Delete Clip Zone"));
727
728     for (int i = 0; i < selected.count(); i++) {
729         if (selected.at(i)->type() == PROJECTSUBCLIPTYPE) {
730             // subitem
731             SubProjectItem *sub = static_cast <SubProjectItem *>(selected.at(i));
732             ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
733             new AddClipCutCommand(this, item->clipId(), sub->zone().x(), sub->zone().y(), sub->description(), false, true, delCommand);
734         } else if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
735             // folder
736             FolderProjectItem *folder = static_cast <FolderProjectItem *>(selected.at(i));
737             folderids[folder->groupName()] = folder->clipId();
738             int children = folder->childCount();
739
740             if (children > 0 && 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, folder->text(1)), i18n("Delete Folder")) != KMessageBox::Yes)
741                 return;
742             for (int i = 0; i < children; ++i) {
743                 ProjectItem *child = static_cast <ProjectItem *>(folder->child(i));
744                 ids << child->clipId();
745             }
746         } else {
747             ProjectItem *item = static_cast <ProjectItem *>(selected.at(i));
748             ids << item->clipId();
749             if (item->numReferences() > 0 && 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)
750                 return;
751         }
752     }
753
754     if (delCommand->childCount() == 0)
755         delete delCommand;
756     else
757         m_commandStack->push(delCommand);
758     emit deleteProjectClips(ids, folderids);
759 }
760
761 void ProjectList::updateButtons() const
762 {
763     if (m_listView->topLevelItemCount() == 0) {
764         m_deleteAction->setEnabled(false);
765     } else {
766         m_deleteAction->setEnabled(true);
767         if (!m_listView->currentItem())
768             m_listView->setCurrentItem(m_listView->topLevelItem(0));
769         QTreeWidgetItem *item = m_listView->currentItem();
770         if (item && item->type() == PROJECTCLIPTYPE) {
771             m_editAction->setEnabled(true);
772             m_openAction->setEnabled(true);
773             m_reloadAction->setEnabled(true);
774             m_transcodeAction->setEnabled(true);
775             return;
776         }
777     }
778
779     m_editAction->setEnabled(false);
780     m_openAction->setEnabled(false);
781     m_reloadAction->setEnabled(false);
782     m_transcodeAction->setEnabled(false);
783 }
784
785 void ProjectList::selectItemById(const QString &clipId)
786 {
787     ProjectItem *item = getItemById(clipId);
788     if (item)
789         m_listView->setCurrentItem(item);
790 }
791
792
793 void ProjectList::slotDeleteClip(const QString &clipId)
794 {
795     ProjectItem *item = getItemById(clipId);
796     if (!item) {
797         kDebug() << "/// Cannot find clip to delete";
798         return;
799     }
800     m_listView->blockSignals(true);
801     QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
802     if (!newSelectedItem)
803         newSelectedItem = m_listView->itemBelow(item);
804     delete item;
805     m_doc->clipManager()->deleteClip(clipId);
806     m_listView->blockSignals(false);
807     if (newSelectedItem) {
808         m_listView->setCurrentItem(newSelectedItem);
809     } else {
810         updateButtons();
811         emit clipSelected(NULL);
812     }
813 }
814
815
816 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
817 {
818     EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
819     m_commandStack->push(command);
820     m_doc->setModified(true);
821 }
822
823 void ProjectList::slotAddFolder()
824 {
825     AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
826     m_commandStack->push(command);
827 }
828
829 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
830 {
831     if (remove) {
832         FolderProjectItem *item = getFolderItemById(clipId);
833         if (item) {
834             m_doc->clipManager()->deleteFolder(clipId);
835             QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
836             if (!newSelectedItem)
837                 newSelectedItem = m_listView->itemBelow(item);
838             delete item;
839             if (newSelectedItem)
840                 m_listView->setCurrentItem(newSelectedItem);
841             else
842                 updateButtons();
843         }
844     } else {
845         if (edit) {
846             FolderProjectItem *item = getFolderItemById(clipId);
847             if (item) {
848                 m_listView->blockSignals(true);
849                 item->setGroupName(foldername);
850                 m_listView->blockSignals(false);
851                 m_doc->clipManager()->addFolder(clipId, foldername);
852                 const int children = item->childCount();
853                 for (int i = 0; i < children; i++) {
854                     ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
855                     child->setProperty("groupname", foldername);
856                 }
857             }
858         } else {
859             m_listView->blockSignals(true);
860             m_listView->setCurrentItem(new FolderProjectItem(m_listView, QStringList() << foldername, clipId));
861             m_doc->clipManager()->addFolder(clipId, foldername);
862             m_listView->blockSignals(false);
863             m_listView->editItem(m_listView->currentItem(), 0);
864         }
865         updateButtons();
866     }
867     m_doc->setModified(true);
868 }
869
870
871
872 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
873 {
874     QMapIterator<QString, QString> i(map);
875     QUndoCommand *delCommand = new QUndoCommand();
876     delCommand->setText(i18n("Delete Folder"));
877     while (i.hasNext()) {
878         i.next();
879         new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
880     }
881     m_commandStack->push(delCommand);
882 }
883
884 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
885 {
886     m_listView->setEnabled(false);
887     if (getProperties) {
888         m_listView->blockSignals(true);
889         m_refreshed = false;
890         // remove file_hash so that we load all properties for the clip
891         QDomElement e = clip->toXML().cloneNode().toElement();
892         e.removeAttribute("file_hash");
893         m_infoQueue.insert(clip->getId(), e);
894         //m_render->getFileProperties(clip->toXML(), clip->getId(), true);
895     }
896     clip->askForAudioThumbs();
897     const QString parent = clip->getProperty("groupid");
898     ProjectItem *item = NULL;
899     if (!parent.isEmpty()) {
900         FolderProjectItem *parentitem = getFolderItemById(parent);
901         if (!parentitem) {
902             QStringList text;
903             QString groupName = clip->getProperty("groupname");
904             //kDebug() << "Adding clip to new group: " << groupName;
905             if (groupName.isEmpty()) groupName = i18n("Folder");
906             text << groupName;
907             parentitem = new FolderProjectItem(m_listView, text, parent);
908         }
909
910         if (parentitem)
911             item = new ProjectItem(parentitem, clip);
912     }
913     if (item == NULL)
914         item = new ProjectItem(m_listView, clip);
915     KUrl url = clip->fileURL();
916
917     if (getProperties == false && !clip->getClipHash().isEmpty()) {
918         QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
919         if (QFile::exists(cachedPixmap)) {
920             QPixmap pix(cachedPixmap);
921             if (pix.isNull())
922                 KIO::NetAccess::del(KUrl(cachedPixmap), this);
923             item->setData(0, Qt::DecorationRole, pix);
924         }
925     }
926 #ifdef NEPOMUK
927     if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
928         // if file has Nepomuk comment, use it
929         Nepomuk::Resource f(url.path());
930         QString annotation = f.description();
931         if (!annotation.isEmpty()) item->setText(1, annotation);
932         item->setText(2, QString::number(f.rating()));
933     }
934 #endif
935     // Add cut zones
936     QList <CutZoneInfo> cuts = clip->cutZones();
937     if (!cuts.isEmpty()) {
938         for (int i = 0; i < cuts.count(); i++) {
939             SubProjectItem *sub = new SubProjectItem(item, cuts.at(i).zone.x(), cuts.at(i).zone.y(), cuts.at(i).description);
940             if (!clip->getClipHash().isEmpty()) {
941                 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(cuts.at(i).zone.x()) + ".png";
942                 if (QFile::exists(cachedPixmap)) {
943                     QPixmap pix(cachedPixmap);
944                     if (pix.isNull())
945                         KIO::NetAccess::del(KUrl(cachedPixmap), this);
946                     sub->setData(0, Qt::DecorationRole, pix);
947                 }
948             }
949         }
950     }
951     if (m_listView->isEnabled()) {
952         updateButtons();
953         if (getProperties)
954             m_listView->blockSignals(false);
955     }
956     if (getProperties && !m_queueTimer.isActive())
957         slotProcessNextClipInQueue();
958 }
959
960 void ProjectList::slotResetProjectList()
961 {
962     m_listView->clear();
963     emit clipSelected(NULL);
964     m_thumbnailQueue.clear();
965     m_infoQueue.clear();
966     m_refreshed = false;
967 }
968
969 void ProjectList::requestClipInfo(const QDomElement xml, const QString id)
970 {
971     m_refreshed = false;
972     m_infoQueue.insert(id, xml);
973     //if (m_infoQueue.count() == 1 || ) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
974 }
975
976 void ProjectList::slotProcessNextClipInQueue()
977 {
978     if (m_infoQueue.isEmpty()) {
979         slotProcessNextThumbnail();
980         return;
981     }
982
983     QMap<QString, QDomElement>::const_iterator j = m_infoQueue.constBegin();
984     if (j != m_infoQueue.constEnd()) {
985         const QDomElement dom = j.value();
986         const QString id = j.key();
987         m_infoQueue.remove(j.key());
988         emit getFileProperties(dom, id, m_listView->iconSize().height(), false);
989     }
990     if (!m_infoQueue.isEmpty()) m_queueTimer.start();
991 }
992
993 void ProjectList::slotUpdateClip(const QString &id)
994 {
995     ProjectItem *item = getItemById(id);
996     m_listView->blockSignals(true);
997     if (item) item->setData(0, UsageRole, QString::number(item->numReferences()));
998     m_listView->blockSignals(false);
999 }
1000
1001 void ProjectList::updateAllClips()
1002 {
1003     m_listView->setSortingEnabled(false);
1004     kDebug() << "// UPDATE ALL CLPY";
1005
1006     QTreeWidgetItemIterator it(m_listView);
1007     DocClipBase *clip;
1008     ProjectItem *item;
1009     m_listView->blockSignals(true);
1010     while (*it) {
1011         if ((*it)->type() == PROJECTSUBCLIPTYPE) {
1012             // subitem
1013             SubProjectItem *sub = static_cast <SubProjectItem *>(*it);
1014             if (sub->data(0, Qt::DecorationRole).isNull()) {
1015                 item = static_cast <ProjectItem *>((*it)->parent());
1016                 requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x()));
1017             }
1018             ++it;
1019             continue;
1020         } else if ((*it)->type() == PROJECTFOLDERTYPE) {
1021             // folder
1022             ++it;
1023             continue;
1024         } else {
1025             item = static_cast <ProjectItem *>(*it);
1026             clip = item->referencedClip();
1027             if (item->referencedClip()->producer() == NULL) {
1028                 if (clip->isPlaceHolder() == false)
1029                     requestClipInfo(clip->toXML(), clip->getId());
1030                 else if (!clip->isPlaceHolder())
1031                     item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
1032             } else {
1033                 if (item->data(0, Qt::DecorationRole).isNull())
1034                     requestClipThumbnail(clip->getId());
1035                 if (item->data(0, DurationRole).toString().isEmpty())
1036                     item->changeDuration(item->referencedClip()->producer()->get_playtime());
1037             }
1038             item->setData(0, UsageRole, QString::number(item->numReferences()));
1039         }
1040         //qApp->processEvents();
1041         ++it;
1042     }
1043     if (!m_queueTimer.isActive())
1044         m_queueTimer.start();
1045     if (m_listView->isEnabled())
1046         m_listView->blockSignals(false);
1047     m_listView->setSortingEnabled(true);
1048     if (m_infoQueue.isEmpty())
1049         slotProcessNextThumbnail();
1050 }
1051
1052 // static
1053 QString ProjectList::getExtensions()
1054 {
1055     // Build list of mime types
1056     QStringList mimeTypes = QStringList() << "application/x-kdenlive" << "application/x-kdenlivetitle" << "video/mlt-playlist" << "text/plain"
1057                             << "video/x-flv" << "application/vnd.rn-realmedia" << "video/x-dv" << "video/dv" << "video/x-msvideo" << "video/x-matroska" << "video/mpeg" << "video/ogg" << "video/x-ms-wmv" << "video/mp4" << "video/quicktime"
1058                             << "audio/x-flac" << "audio/x-matroska" << "audio/mp4" << "audio/mpeg" << "audio/x-mp3" << "audio/ogg" << "audio/x-wav" << "application/ogg" << "application/mxf"
1059                             << "image/gif" << "image/jpeg" << "image/png" << "image/x-tga" << "image/x-bmp" << "image/svg+xml" << "image/tiff" << "image/x-xcf" << "image/x-xcf-gimp" << "image/x-vnd.adobe.photoshop" << "image/x-pcx" << "image/x-exr";
1060
1061     QString allExtensions;
1062     foreach(const QString & mimeType, mimeTypes) {
1063         KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
1064         if (mime) {
1065             allExtensions.append(mime->patterns().join(" "));
1066             allExtensions.append(' ');
1067         }
1068     }
1069     return allExtensions.simplified();
1070 }
1071
1072 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
1073 {
1074     if (!m_commandStack)
1075         kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1076
1077     KUrl::List list;
1078     if (givenList.isEmpty()) {
1079         QString allExtensions = getExtensions();
1080         const QString dialogFilter = allExtensions + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
1081         QCheckBox *b = new QCheckBox(i18n("Import image sequence"));
1082         b->setChecked(KdenliveSettings::autoimagesequence());
1083         KFileDialog *d = new KFileDialog(KUrl("kfiledialog:///clipfolder"), dialogFilter, this, b);
1084         d->setOperationMode(KFileDialog::Opening);
1085         d->setMode(KFile::Files);
1086         d->exec();
1087         list = d->selectedUrls();
1088         if (b->isChecked() && list.count() == 1) {
1089             // Check for image sequence
1090             KUrl url = list.at(0);
1091             QString fileName = url.fileName().section('.', 0, -2);
1092             if (fileName.at(fileName.size() - 1).isDigit()) {
1093                 KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
1094                 if (item.mimetype().startsWith("image")) {
1095                     int count = 0;
1096                     // import as sequence if we found more than one image in the sequence
1097                     QString pattern = SlideshowClip::selectedPath(url.path(), false, QString(), &count);
1098                     if (count > 1) {
1099                         delete d;
1100                         QStringList groupInfo = getGroup();
1101
1102                         // get image sequence base name
1103                         while (fileName.at(fileName.size() - 1).isDigit()) {
1104                             fileName.chop(1);
1105                         }
1106
1107                         m_doc->slotCreateSlideshowClipFile(fileName, pattern, count, m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()),
1108                                                            false, false, false,
1109                                                            m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))), QString(), 0,
1110                                                            QString(), groupInfo.at(0), groupInfo.at(1));
1111                         return;
1112                     }
1113                 }
1114             }
1115         }
1116         delete d;
1117     } else {
1118         for (int i = 0; i < givenList.count(); i++)
1119             list << givenList.at(i);
1120     }
1121
1122     foreach(const KUrl & file, list) {
1123         // Check there is no folder here
1124         KMimeType::Ptr type = KMimeType::findByUrl(file);
1125         if (type->is("inode/directory")) {
1126             // user dropped a folder
1127             list.removeAll(file);
1128         }
1129     }
1130
1131     if (list.isEmpty())
1132         return;
1133
1134     if (givenList.isEmpty()) {
1135         QStringList groupInfo = getGroup();
1136         m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1));
1137     } else {
1138         m_doc->slotAddClipList(list, groupName, groupId);
1139     }
1140 }
1141
1142 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
1143 {
1144     ProjectItem *item = getItemById(id);
1145     QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
1146     if (item) {
1147         const QString path = item->referencedClip()->fileURL().path();
1148         if (item->referencedClip()->isPlaceHolder()) replace = false;
1149         if (!path.isEmpty()) {
1150             if (replace)
1151                 KMessageBox::sorry(this, i18n("Clip <b>%1</b><br />is invalid, will be removed from project.", path));
1152             else if (KMessageBox::questionYesNo(this, i18n("Clip <b>%1</b><br />is missing or invalid. Remove it from project?", path), i18n("Invalid clip")) == KMessageBox::Yes)
1153                 replace = true;
1154         }
1155         if (replace)
1156             emit deleteProjectClips(QStringList() << id, QMap <QString, QString>());
1157     }
1158 }
1159
1160 void ProjectList::slotAddColorClip()
1161 {
1162     if (!m_commandStack)
1163         kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1164
1165     QDialog *dia = new QDialog(this);
1166     Ui::ColorClip_UI dia_ui;
1167     dia_ui.setupUi(dia);
1168     dia->setWindowTitle(i18n("Color Clip"));
1169     dia_ui.clip_name->setText(i18n("Color Clip"));
1170
1171     TimecodeDisplay *t = new TimecodeDisplay(m_timecode);
1172     t->setValue(KdenliveSettings::color_duration());
1173     t->setTimeCodeFormat(false);
1174     dia_ui.clip_durationBox->addWidget(t);
1175     dia_ui.clip_color->setColor(KdenliveSettings::colorclipcolor());
1176
1177     if (dia->exec() == QDialog::Accepted) {
1178         QString color = dia_ui.clip_color->color().name();
1179         KdenliveSettings::setColorclipcolor(color);
1180         color = color.replace(0, 1, "0x") + "ff";
1181         QStringList groupInfo = getGroup();
1182         m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, m_timecode.getTimecode(t->gentime()), groupInfo.at(0), groupInfo.at(1));
1183     }
1184     delete t;
1185     delete dia;
1186 }
1187
1188
1189 void ProjectList::slotAddSlideshowClip()
1190 {
1191     if (!m_commandStack)
1192         kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1193
1194     SlideshowClip *dia = new SlideshowClip(m_timecode, this);
1195
1196     if (dia->exec() == QDialog::Accepted) {
1197         QStringList groupInfo = getGroup();
1198         m_doc->slotCreateSlideshowClipFile(dia->clipName(), dia->selectedPath(), dia->imageCount(), dia->clipDuration(),
1199                                            dia->loop(), dia->crop(), dia->fade(),
1200                                            dia->lumaDuration(), dia->lumaFile(), dia->softness(),
1201                                            dia->animation(), groupInfo.at(0), groupInfo.at(1));
1202     }
1203     delete dia;
1204 }
1205
1206 void ProjectList::slotAddTitleClip()
1207 {
1208     QStringList groupInfo = getGroup();
1209     m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
1210 }
1211
1212 void ProjectList::slotAddTitleTemplateClip()
1213 {
1214     if (!m_commandStack)
1215         kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1216
1217     QStringList groupInfo = getGroup();
1218
1219     // Get the list of existing templates
1220     QStringList filter;
1221     filter << "*.kdenlivetitle";
1222     const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
1223     QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
1224
1225     QDialog *dia = new QDialog(this);
1226     Ui::TemplateClip_UI dia_ui;
1227     dia_ui.setupUi(dia);
1228     for (int i = 0; i < templateFiles.size(); ++i)
1229         dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
1230
1231     if (!templateFiles.isEmpty())
1232         dia_ui.buttonBox->button(QDialogButtonBox::Ok)->setFocus();
1233     dia_ui.template_list->fileDialog()->setFilter("*.kdenlivetitle");
1234     //warning: setting base directory doesn't work??
1235     KUrl startDir(path);
1236     dia_ui.template_list->fileDialog()->setUrl(startDir);
1237     dia_ui.text_box->setHidden(true);
1238     if (dia->exec() == QDialog::Accepted) {
1239         QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
1240         if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
1241         // Create a cloned template clip
1242         m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
1243     }
1244     delete dia;
1245 }
1246
1247 QStringList ProjectList::getGroup() const
1248 {
1249     QStringList result;
1250     QTreeWidgetItem *item = m_listView->currentItem();
1251     while (item && item->type() != PROJECTFOLDERTYPE)
1252         item = item->parent();
1253
1254     if (item) {
1255         FolderProjectItem *folder = static_cast <FolderProjectItem *>(item);
1256         result << folder->groupName() << folder->clipId();
1257     } else {
1258         result << QString() << QString();
1259     }
1260     return result;
1261 }
1262
1263 void ProjectList::setDocument(KdenliveDoc *doc)
1264 {
1265     m_listView->blockSignals(true);
1266     m_listView->clear();
1267     m_listView->setSortingEnabled(false);
1268     emit clipSelected(NULL);
1269     m_thumbnailQueue.clear();
1270     m_infoQueue.clear();
1271     m_refreshed = false;
1272     m_fps = doc->fps();
1273     m_timecode = doc->timecode();
1274     m_commandStack = doc->commandStack();
1275     m_doc = doc;
1276
1277     QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
1278     QMapIterator<QString, QString> f(flist);
1279     while (f.hasNext()) {
1280         f.next();
1281         (void) new FolderProjectItem(m_listView, QStringList() << f.value(), f.key());
1282     }
1283
1284     QList <DocClipBase*> list = doc->clipManager()->documentClipList();
1285     for (int i = 0; i < list.count(); i++)
1286         slotAddClip(list.at(i), false);
1287
1288     m_listView->blockSignals(false);
1289     m_toolbar->setEnabled(true);
1290     connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
1291     connect(m_doc->clipManager(), SIGNAL(modifiedClip(const QString &)), this, SLOT(slotModifiedClip(const QString &)));
1292     connect(m_doc->clipManager(), SIGNAL(missingClip(const QString &)), this, SLOT(slotMissingClip(const QString &)));
1293     connect(m_doc->clipManager(), SIGNAL(availableClip(const QString &)), this, SLOT(slotAvailableClip(const QString &)));
1294     connect(m_doc->clipManager(), SIGNAL(checkAllClips()), this, SLOT(updateAllClips()));
1295 }
1296
1297 QList <DocClipBase*> ProjectList::documentClipList() const
1298 {
1299     if (m_doc == NULL)
1300         return QList <DocClipBase*> ();
1301
1302     return m_doc->clipManager()->documentClipList();
1303 }
1304
1305 QDomElement ProjectList::producersList()
1306 {
1307     QDomDocument doc;
1308     QDomElement prods = doc.createElement("producerlist");
1309     doc.appendChild(prods);
1310     kDebug() << "////////////  PRO LIST BUILD PRDSLIST ";
1311     QTreeWidgetItemIterator it(m_listView);
1312     while (*it) {
1313         if ((*it)->type() != PROJECTCLIPTYPE) {
1314             // subitem
1315             ++it;
1316             continue;
1317         }
1318         prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
1319         ++it;
1320     }
1321     return prods;
1322 }
1323
1324 void ProjectList::slotCheckForEmptyQueue()
1325 {
1326     if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
1327         m_refreshed = true;
1328         emit loadingIsOver();
1329         emit displayMessage(QString(), -1);
1330         m_listView->blockSignals(false);
1331         m_listView->setEnabled(true);
1332         updateButtons();
1333     } else if (!m_refreshed) {
1334         QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
1335     }
1336 }
1337
1338 void ProjectList::reloadClipThumbnails()
1339 {
1340     kDebug() << "//////////////  RELOAD CLIPS THUMBNAILS!!!";
1341     m_thumbnailQueue.clear();
1342     QTreeWidgetItemIterator it(m_listView);
1343     while (*it) {
1344         if ((*it)->type() != PROJECTCLIPTYPE) {
1345             // subitem
1346             ++it;
1347             continue;
1348         }
1349         m_thumbnailQueue << ((ProjectItem *)(*it))->clipId();
1350         ++it;
1351     }
1352     QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
1353 }
1354
1355 void ProjectList::requestClipThumbnail(const QString id)
1356 {
1357     if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id);
1358 }
1359
1360 void ProjectList::slotProcessNextThumbnail()
1361 {
1362     if (m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
1363         slotCheckForEmptyQueue();
1364         return;
1365     }
1366     if (!m_infoQueue.isEmpty()) {
1367         //QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
1368         return;
1369     }
1370     if (m_thumbnailQueue.count() > 1) {
1371         int max = m_doc->clipManager()->clipsCount();
1372         emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - m_thumbnailQueue.count()) / max));
1373     }
1374     slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
1375 }
1376
1377 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
1378 {
1379     QTreeWidgetItem *item = getAnyItemById(clipId);
1380     if (item)
1381         slotRefreshClipThumbnail(item, update);
1382     else
1383         slotProcessNextThumbnail();
1384 }
1385
1386 void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
1387 {
1388     if (it == NULL) return;
1389     ProjectItem *item = NULL;
1390     bool isSubItem = false;
1391     int frame;
1392     if (it->type() == PROJECTFOLDERTYPE) return;
1393     if (it->type() == PROJECTSUBCLIPTYPE) {
1394         item = static_cast <ProjectItem *>(it->parent());
1395         frame = static_cast <SubProjectItem *>(it)->zone().x();
1396         isSubItem = true;
1397     } else {
1398         item = static_cast <ProjectItem *>(it);
1399         frame = item->referencedClip()->getClipThumbFrame();
1400     }
1401
1402     if (item) {
1403         DocClipBase *clip = item->referencedClip();
1404         if (!clip) {
1405             slotProcessNextThumbnail();
1406             return;
1407         }
1408         QPixmap pix;
1409         int height = m_listView->iconSize().height();
1410         int width = (int)(height  * m_render->dar());
1411         if (clip->clipType() == AUDIO)
1412             pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
1413         else if (clip->clipType() == IMAGE)
1414             pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->producer(), 0, width, height));
1415         else
1416             pix = item->referencedClip()->thumbProducer()->extractImage(frame, width, height);
1417
1418         if (!pix.isNull()) {
1419             m_listView->blockSignals(true);
1420             it->setData(0, Qt::DecorationRole, pix);
1421             if (m_listView->isEnabled())
1422                 m_listView->blockSignals(false);
1423             if (!isSubItem)
1424                 m_doc->cachePixmap(item->getClipHash(), pix);
1425             else
1426                 m_doc->cachePixmap(item->getClipHash() + '#' + QString::number(frame), pix);
1427         }
1428         if (update)
1429             emit projectModified();
1430         QTimer::singleShot(30, this, SLOT(slotProcessNextThumbnail()));
1431     }
1432 }
1433
1434 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace)
1435 {
1436     QString toReload;
1437     ProjectItem *item = getItemById(clipId);
1438     if (item && producer) {
1439         m_listView->blockSignals(true);
1440         item->setProperties(properties, metadata);
1441         if (item->referencedClip()->isPlaceHolder() && producer->is_valid()) {
1442             item->referencedClip()->setValid();
1443             item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1444             toReload = clipId;
1445         }
1446         //Q_ASSERT_X(item->referencedClip(), "void ProjectList::slotReplyGetFileProperties", QString("Item with groupName %1 does not have a clip associated").arg(item->groupName()).toLatin1());
1447         item->referencedClip()->setProducer(producer, replace);
1448         item->referencedClip()->askForAudioThumbs();
1449         if (!replace && item->data(0, Qt::DecorationRole).isNull())
1450             requestClipThumbnail(clipId);
1451         if (!toReload.isEmpty())
1452             item->slotSetToolTip();
1453
1454         //emit receivedClipDuration(clipId);
1455         if (m_listView->isEnabled() && replace) {
1456             // update clip in clip monitor
1457             emit clipSelected(NULL);
1458             emit clipSelected(item->referencedClip());
1459             //TODO: Make sure the line below has no side effect
1460             toReload = clipId;
1461         }
1462         /*else {
1463             // Check if duration changed.
1464             emit receivedClipDuration(clipId);
1465             delete producer;
1466         }*/
1467         if (m_listView->isEnabled())
1468             m_listView->blockSignals(false);
1469         /*if (item->icon(0).isNull()) {
1470             requestClipThumbnail(clipId);
1471         }*/
1472     } else kDebug() << "////////  COULD NOT FIND CLIP TO UPDATE PRPS...";
1473     int max = m_doc->clipManager()->clipsCount();
1474     if (item && m_infoQueue.isEmpty() && m_thumbnailQueue.isEmpty()) {
1475         m_listView->setCurrentItem(item);
1476         if (item->parent()) {
1477             if (item->parent()->type() == PROJECTFOLDERTYPE)
1478                 static_cast <FolderProjectItem *>(item->parent())->switchIcon();
1479         } else if (KdenliveSettings::checkfirstprojectclip() &&  m_listView->topLevelItemCount() == 1) {
1480             // this is the first clip loaded in project, check if we want to adjust project settings to the clip
1481             int width = properties.value("frame_size").section('x', 0, 0).toInt();
1482             int height = properties.value("frame_size").section('x', -1).toInt();
1483             double fps = properties.value("fps").toDouble();
1484             int renderWidth = -1;
1485             int renderHeight = -1;
1486             double renderFps = -1;
1487             if (item->clipType() == IMAGE) {
1488                 renderWidth = m_doc->renderer()->renderWidth();
1489                 renderHeight = m_doc->height();
1490             } else if (item->clipType() == AV || item->clipType() == VIDEO) {
1491                 renderWidth = m_doc->width();
1492                 renderHeight = m_doc->height();
1493                 renderFps = m_doc->fps();
1494             }
1495             if ((renderWidth > 0 && width != renderWidth) || (renderHeight > 0 && height != renderHeight) || (renderFps > 0 && qAbs(fps - renderFps) > 0.5)) {
1496                 QString suggestedProfile = ProfilesDialog::getPathFromProperties(width, height, fps, item->clipType() == IMAGE);
1497                 if (!suggestedProfile.isEmpty()) {
1498                     QString description = ProfilesDialog::getSettingsFromFile(suggestedProfile).value("description");
1499                     if (KMessageBox::questionYesNo(this, i18n("Your clip does not match current project's profile.\nDo you want to adjust the profile (clip size: %1, fps: %2)?\nSuggested profile is %3", properties.value("frame_size"), fps, description)) == KMessageBox::Yes) {
1500                         //Change project profile
1501                         emit updateProfile(suggestedProfile);
1502                     }
1503                 } else KMessageBox::information(this, i18n("Your clip does not match current project's profile.\nNo existing profile found to match the clip's properties.\nClip size: %1\nFps: %2\n", properties.value("frame_size"), fps));
1504             }
1505         }
1506         emit clipSelected(item->referencedClip());
1507     } else {
1508         emit displayMessage(i18n("Loading clips"), (int)(100 *(max - m_infoQueue.count()) / max));
1509     }
1510     if (!toReload.isEmpty())
1511         emit clipNeedsReload(toReload, true);
1512     // small delay so that the app can display the progress info
1513     QTimer::singleShot(30, this, SLOT(slotProcessNextClipInQueue()));
1514 }
1515
1516 void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
1517 {
1518     ProjectItem *item = getItemById(clipId);
1519     if (item && !pix.isNull()) {
1520         m_listView->blockSignals(true);
1521         item->setData(0, Qt::DecorationRole, pix);
1522         m_doc->cachePixmap(item->getClipHash(), pix);
1523         if (m_listView->isEnabled())
1524             m_listView->blockSignals(false);
1525     }
1526 }
1527
1528 QTreeWidgetItem *ProjectList::getAnyItemById(const QString &id)
1529 {
1530     QTreeWidgetItemIterator it(m_listView);
1531     QString lookId = id;
1532     if (id.contains('#'))
1533         lookId = id.section('#', 0, 0);
1534
1535     ProjectItem *result = NULL;
1536     while (*it) {
1537         if ((*it)->type() != PROJECTCLIPTYPE) {
1538             // subitem
1539             ++it;
1540             continue;
1541         }
1542         ProjectItem *item = static_cast<ProjectItem *>(*it);
1543         if (item->clipId() == lookId) {
1544             result = item;
1545             break;
1546         }
1547         ++it;
1548     }
1549     if (result == NULL || !id.contains('#')) {
1550         return result;
1551     } else {
1552         for (int i = 0; i < result->childCount(); i++) {
1553             SubProjectItem *sub = static_cast <SubProjectItem *>(result->child(i));
1554             if (sub && sub->zone().x() == id.section('#', 1, 1).toInt())
1555                 return sub;
1556         }
1557     }
1558
1559     return NULL;
1560 }
1561
1562
1563 ProjectItem *ProjectList::getItemById(const QString &id)
1564 {
1565     ProjectItem *item;
1566     QTreeWidgetItemIterator it(m_listView);
1567     while (*it) {
1568         if ((*it)->type() != PROJECTCLIPTYPE) {
1569             // subitem
1570             ++it;
1571             continue;
1572         }
1573         item = static_cast<ProjectItem *>(*it);
1574         if (item->clipId() == id)
1575             return item;
1576         ++it;
1577     }
1578     return NULL;
1579 }
1580
1581 FolderProjectItem *ProjectList::getFolderItemById(const QString &id)
1582 {
1583     FolderProjectItem *item;
1584     QTreeWidgetItemIterator it(m_listView);
1585     while (*it) {
1586         if ((*it)->type() == PROJECTFOLDERTYPE) {
1587             item = static_cast<FolderProjectItem *>(*it);
1588             if (item->clipId() == id)
1589                 return item;
1590         }
1591         ++it;
1592     }
1593     return NULL;
1594 }
1595
1596 void ProjectList::slotSelectClip(const QString &ix)
1597 {
1598     ProjectItem *clip = getItemById(ix);
1599     if (clip) {
1600         m_listView->setCurrentItem(clip);
1601         m_listView->scrollToItem(clip);
1602         m_editAction->setEnabled(true);
1603         m_deleteAction->setEnabled(true);
1604         m_reloadAction->setEnabled(true);
1605         m_transcodeAction->setEnabled(true);
1606         if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
1607             m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
1608             m_openAction->setEnabled(true);
1609         } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
1610             m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
1611             m_openAction->setEnabled(true);
1612         } else {
1613             m_openAction->setEnabled(false);
1614         }
1615     }
1616 }
1617
1618 QString ProjectList::currentClipUrl() const
1619 {
1620     ProjectItem *item;
1621     if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return QString();
1622     if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
1623         // subitem
1624         item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
1625     } else {
1626         item = static_cast <ProjectItem*>(m_listView->currentItem());
1627     }
1628     if (item == NULL)
1629         return QString();
1630     return item->clipUrl().path();
1631 }
1632
1633 KUrl::List ProjectList::getConditionalUrls(const QString &condition) const
1634 {
1635     KUrl::List result;
1636     ProjectItem *item;
1637     QList<QTreeWidgetItem *> list = m_listView->selectedItems();
1638     for (int i = 0; i < list.count(); i++) {
1639         if (list.at(i)->type() == PROJECTFOLDERTYPE)
1640             continue;
1641         if (list.at(i)->type() == PROJECTSUBCLIPTYPE) {
1642             // subitem
1643             item = static_cast <ProjectItem*>(list.at(i)->parent());
1644         } else {
1645             item = static_cast <ProjectItem*>(list.at(i));
1646         }
1647         if (item == NULL || item->type() == COLOR || item->type() == SLIDESHOW || item->type() == TEXT)
1648             continue;
1649         DocClipBase *clip = item->referencedClip();
1650         if (!condition.isEmpty()) {
1651             if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section('=', 1, 1)))
1652                 continue;
1653             else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section('=', 1, 1)))
1654                 continue;
1655         }
1656         result.append(item->clipUrl());
1657     }
1658     return result;
1659 }
1660
1661 void ProjectList::regenerateTemplate(const QString &id)
1662 {
1663     ProjectItem *clip = getItemById(id);
1664     if (clip)
1665         regenerateTemplate(clip);
1666 }
1667
1668 void ProjectList::regenerateTemplate(ProjectItem *clip)
1669 {
1670     //TODO: remove this unused method, only force_reload is necessary
1671     clip->referencedClip()->producer()->set("force_reload", 1);
1672 }
1673
1674 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
1675 {
1676     QDomDocument doc;
1677     QFile file(path);
1678     if (!file.open(QIODevice::ReadOnly)) {
1679         kWarning() << "ERROR, CANNOT READ: " << path;
1680         return doc;
1681     }
1682     if (!doc.setContent(&file)) {
1683         kWarning() << "ERROR, CANNOT READ: " << path;
1684         file.close();
1685         return doc;
1686     }
1687     file.close();
1688     QDomNodeList texts = doc.elementsByTagName("content");
1689     for (int i = 0; i < texts.count(); i++) {
1690         QString data = texts.item(i).firstChild().nodeValue();
1691         data.replace("%s", replaceString);
1692         texts.item(i).firstChild().setNodeValue(data);
1693     }
1694     return doc;
1695 }
1696
1697
1698 void ProjectList::slotAddClipCut(const QString &id, int in, int out)
1699 {
1700     ProjectItem *clip = getItemById(id);
1701     if (clip == NULL || clip->referencedClip()->hasCutZone(QPoint(in, out)))
1702         return;
1703     AddClipCutCommand *command = new AddClipCutCommand(this, id, in, out, QString(), true, false);
1704     m_commandStack->push(command);
1705 }
1706
1707 void ProjectList::addClipCut(const QString &id, int in, int out, const QString desc, bool newItem)
1708 {
1709     ProjectItem *clip = getItemById(id);
1710     if (clip) {
1711         DocClipBase *base = clip->referencedClip();
1712         base->addCutZone(in, out);
1713         m_listView->blockSignals(true);
1714         SubProjectItem *sub = new SubProjectItem(clip, in, out, desc);
1715         if (newItem && desc.isEmpty() && !m_listView->isColumnHidden(1)) {
1716             if (!clip->isExpanded())
1717                 clip->setExpanded(true);
1718             m_listView->scrollToItem(sub);
1719             m_listView->editItem(sub, 1);
1720         }
1721         QPixmap p = clip->referencedClip()->thumbProducer()->extractImage(in, (int)(sub->sizeHint(0).height()  * m_render->dar()), sub->sizeHint(0).height() - 2);
1722         sub->setData(0, Qt::DecorationRole, p);
1723         m_doc->cachePixmap(clip->getClipHash() + '#' + QString::number(in), p);
1724         m_listView->blockSignals(false);
1725     }
1726     emit projectModified();
1727 }
1728
1729 void ProjectList::removeClipCut(const QString &id, int in, int out)
1730 {
1731     ProjectItem *clip = getItemById(id);
1732     if (clip) {
1733         DocClipBase *base = clip->referencedClip();
1734         base->removeCutZone(in, out);
1735         SubProjectItem *sub = getSubItem(clip, QPoint(in, out));
1736         if (sub) {
1737             m_listView->blockSignals(true);
1738             delete sub;
1739             m_listView->blockSignals(false);
1740         }
1741     }
1742     emit projectModified();
1743 }
1744
1745 SubProjectItem *ProjectList::getSubItem(ProjectItem *clip, QPoint zone)
1746 {
1747     SubProjectItem *sub = NULL;
1748     if (clip) {
1749         for (int i = 0; i < clip->childCount(); i++) {
1750             QTreeWidgetItem *it = clip->child(i);
1751             if (it->type() == PROJECTSUBCLIPTYPE) {
1752                 sub = static_cast <SubProjectItem*>(it);
1753                 if (sub->zone() == zone)
1754                     break;
1755                 else
1756                     sub = NULL;
1757             }
1758         }
1759     }
1760     return sub;
1761 }
1762
1763 void ProjectList::slotUpdateClipCut(QPoint p)
1764 {
1765     if (!m_listView->currentItem() || m_listView->currentItem()->type() != PROJECTSUBCLIPTYPE)
1766         return;
1767     SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
1768     ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
1769     EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), p, sub->text(1), sub->text(1), true);
1770     m_commandStack->push(command);
1771 }
1772
1773 void ProjectList::doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment)
1774 {
1775     ProjectItem *clip = getItemById(id);
1776     SubProjectItem *sub = getSubItem(clip, oldzone);
1777     if (sub == NULL || clip == NULL)
1778         return;
1779     DocClipBase *base = clip->referencedClip();
1780     base->updateCutZone(oldzone.x(), oldzone.y(), zone.x(), zone.y(), comment);
1781     m_listView->blockSignals(true);
1782     sub->setZone(zone);
1783     sub->setDescription(comment);
1784     m_listView->blockSignals(false);
1785     emit projectModified();
1786 }
1787
1788 void ProjectList::slotForceProcessing(const QString &id)
1789 {
1790     while (m_infoQueue.contains(id)) {
1791         slotProcessNextClipInQueue();
1792     }
1793 }
1794
1795 #include "projectlist.moc"