]> git.sesse.net Git - kdenlive/blobdiff - src/projectlist.cpp
Fix some avformat producer concurrency crashes
[kdenlive] / src / projectlist.cpp
index 2d7993338b386e8f90748585785cb2f2590d359a..2b0999539d55621a67033f08dce024fc68b5d169 100644 (file)
@@ -31,6 +31,8 @@
 #include "renderer.h"
 #include "kthumb.h"
 #include "projectlistview.h"
+#include "timecodedisplay.h"
+#include "profilesdialog.h"
 #include "editclipcommand.h"
 #include "editclipcutcommand.h"
 #include "editfoldercommand.h"
@@ -46,6 +48,9 @@
 #include <KMessageBox>
 #include <KIO/NetAccess>
 #include <KFileItem>
+#include <KApplication>
+#include <KStandardDirs>
+
 #ifdef NEPOMUK
 #include <nepomuk/global.h>
 #include <nepomuk/resourcemanager.h>
 #include <QMenu>
 #include <QProcess>
 #include <QHeaderView>
+#include <QInputDialog>
+#include <QtConcurrentRun>
+#include <QVBoxLayout>
+
+InvalidDialog::InvalidDialog(const QString &caption, const QString &message, bool infoOnly, QWidget *parent) : KDialog(parent)
+{
+    setCaption(caption);
+    if (infoOnly) setButtons(KDialog::Ok);
+    else setButtons(KDialog::Yes | KDialog::No);
+    QWidget *w = new QWidget(this);
+    QVBoxLayout *l = new QVBoxLayout;
+    l->addWidget(new QLabel(message));
+    m_clipList = new QListWidget;
+    l->addWidget(m_clipList);
+    w->setLayout(l);
+    setMainWidget(w);
+}
+
+InvalidDialog::~InvalidDialog()
+{
+    delete m_clipList;
+}
+
+
+void InvalidDialog::addClip(const QString &id, const QString &path)
+{
+    QListWidgetItem *item = new QListWidgetItem(path);
+    item->setData(Qt::UserRole, id);
+    m_clipList->addItem(item);
+}
+
+QStringList InvalidDialog::getIds() const
+{
+    QStringList ids;
+    for (int i = 0; i < m_clipList->count(); i++) {
+        ids << m_clipList->item(i)->data(Qt::UserRole).toString();
+    }
+    return ids;
+}
+
 
 ProjectList::ProjectList(QWidget *parent) :
-        QWidget(parent),
-        m_render(NULL),
-        m_fps(-1),
-        m_commandStack(NULL),
-        m_editAction(NULL),
-        m_deleteAction(NULL),
-        m_openAction(NULL),
-        m_reloadAction(NULL),
-        m_transcodeAction(NULL),
-        m_doc(NULL),
-        m_refreshed(false),
-        m_infoQueue(),
-        m_thumbnailQueue()
-{
-
-    m_listView = new ProjectListView(this);;
+    QWidget(parent),
+    m_render(NULL),
+    m_fps(-1),
+    m_commandStack(NULL),
+    m_openAction(NULL),
+    m_reloadAction(NULL),
+    m_transcodeAction(NULL),
+    m_doc(NULL),
+    m_refreshed(false),
+    m_thumbnailQueue(),
+    m_abortAllProxies(false),
+    m_invalidClipDialog(NULL)
+{
     QVBoxLayout *layout = new QVBoxLayout;
     layout->setContentsMargins(0, 0, 0, 0);
     layout->setSpacing(0);
-
+    qRegisterMetaType<QDomElement>("QDomElement");
     // setup toolbar
-    KTreeWidgetSearchLine *searchView = new KTreeWidgetSearchLine(this);
-    m_toolbar = new QToolBar("projectToolBar", this);
-    m_toolbar->addWidget(searchView);
-    int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
-    m_toolbar->setIconSize(QSize(s, s));
-    searchView->setTreeWidget(m_listView);
+    QFrame *frame = new QFrame;
+    frame->setFrameStyle(QFrame::NoFrame);
+    QHBoxLayout *box = new QHBoxLayout;
+    KTreeWidgetSearchLine *searchView = new KTreeWidgetSearchLine;
 
-    m_addButton = new QToolButton(m_toolbar);
+    m_refreshMonitorTimer.setSingleShot(true);
+    m_refreshMonitorTimer.setInterval(100);
+    connect(&m_refreshMonitorTimer, SIGNAL(timeout()), this, SLOT(slotRefreshMonitor()));
+
+    box->addWidget(searchView);
+    //int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
+    //m_toolbar->setIconSize(QSize(s, s));
+
+    m_addButton = new QToolButton;
     m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
-    m_toolbar->addWidget(m_addButton);
+    m_addButton->setAutoRaise(true);
+    box->addWidget(m_addButton);
 
-    layout->addWidget(m_toolbar);
-    layout->addWidget(m_listView);
-    setLayout(layout);
+    m_editButton = new QToolButton;
+    m_editButton->setAutoRaise(true);
+    box->addWidget(m_editButton);
 
-    m_queueTimer.setInterval(100);
-    connect(&m_queueTimer, SIGNAL(timeout()), this, SLOT(slotProcessNextClipInQueue()));
-    m_queueTimer.setSingleShot(true);
+    m_deleteButton = new QToolButton;
+    m_deleteButton->setAutoRaise(true);
+    box->addWidget(m_deleteButton);
+    frame->setLayout(box);
+    layout->addWidget(frame);
 
+    m_listView = new ProjectListView;
+    layout->addWidget(m_listView);
+    setLayout(layout);
+    searchView->setTreeWidget(m_listView);
 
+    connect(this, SIGNAL(processNextThumbnail()), this, SLOT(slotProcessNextThumbnail()));
     connect(m_listView, SIGNAL(projectModified()), this, SIGNAL(projectModified()));
     connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
     connect(m_listView, SIGNAL(focusMonitor()), this, SLOT(slotClipSelected()));
@@ -128,8 +184,9 @@ ProjectList::ProjectList(QWidget *parent) :
 
 ProjectList::~ProjectList()
 {
+    m_abortAllProxies = true;
+    m_thumbnailQueue.clear();
     delete m_menu;
-    delete m_toolbar;
     m_listView->blockSignals(true);
     m_listView->clear();
     delete m_listViewDelegate;
@@ -145,13 +202,11 @@ void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
     QList <QAction *> actions = addMenu->actions();
     for (int i = 0; i < actions.count(); i++) {
         if (actions.at(i)->data().toString() == "clip_properties") {
-            m_editAction = actions.at(i);
-            m_toolbar->addAction(m_editAction);
+            m_editButton->setDefaultAction(actions.at(i));
             actions.removeAt(i);
             i--;
         } else if (actions.at(i)->data().toString() == "delete_clip") {
-            m_deleteAction = actions.at(i);
-            m_toolbar->addAction(m_deleteAction);
+            m_deleteButton->setDefaultAction(actions.at(i));
             actions.removeAt(i);
             i--;
         } else if (actions.at(i)->data().toString() == "edit_clip") {
@@ -162,6 +217,10 @@ void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
             m_reloadAction = actions.at(i);
             actions.removeAt(i);
             i--;
+        } else if (actions.at(i)->data().toString() == "proxy_clip") {
+            m_proxyAction = actions.at(i);
+            actions.removeAt(i);
+            i--;
         }
     }
 
@@ -175,23 +234,27 @@ void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
 
 void ProjectList::setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu, QMenu *inTimelineMenu)
 {
-    if (!addMenu) return;
+    if (!addMenu)
+        return;
     QMenu *menu = m_addButton->menu();
     menu->addMenu(addMenu);
     m_addButton->setMenu(menu);
 
     m_menu->addMenu(addMenu);
-    if (addMenu->isEmpty()) addMenu->setEnabled(false);
+    if (addMenu->isEmpty())
+        addMenu->setEnabled(false);
     m_menu->addMenu(transcodeMenu);
-    if (transcodeMenu->isEmpty()) transcodeMenu->setEnabled(false);
+    if (transcodeMenu->isEmpty())
+        transcodeMenu->setEnabled(false);
     m_transcodeAction = transcodeMenu;
     m_menu->addAction(m_reloadAction);
+    m_menu->addAction(m_proxyAction);
     m_menu->addMenu(inTimelineMenu);
     inTimelineMenu->setEnabled(false);
-    m_menu->addAction(m_editAction);
+    m_menu->addAction(m_editButton->defaultAction());
     m_menu->addAction(m_openAction);
-    m_menu->addAction(m_deleteAction);
-    m_menu->insertSeparator(m_deleteAction);
+    m_menu->addAction(m_deleteButton->defaultAction());
+    m_menu->insertSeparator(m_deleteButton->defaultAction());
 }
 
 
@@ -213,17 +276,19 @@ void ProjectList::updateProjectFormat(Timecode t)
 void ProjectList::slotEditClip()
 {
     QList<QTreeWidgetItem *> list = m_listView->selectedItems();
-    if (list.count() > 1) {
+    if (list.isEmpty()) return;
+    if (list.count() > 1 || list.at(0)->type() == PROJECTFOLDERTYPE) {
         editClipSelection(list);
         return;
     }
     ProjectItem *item;
-    if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return;
-    if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
+    if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
+        return;
+    if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE)
         item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
-    } else item = static_cast <ProjectItem*>(m_listView->currentItem());
-    if (!(item->flags() & Qt::ItemIsDragEnabled)) return;
-    if (item) {
+    else
+        item = static_cast <ProjectItem*>(m_listView->currentItem());
+    if (item && (item->flags() & Qt::ItemIsDragEnabled)) {
         emit clipSelected(item->referencedClip());
         emit showClipProperties(item->referencedClip());
     }
@@ -234,36 +299,72 @@ void ProjectList::editClipSelection(QList<QTreeWidgetItem *> list)
     // Gather all common properties
     QMap <QString, QString> commonproperties;
     QList <DocClipBase *> clipList;
-    commonproperties.insert("force_aspect_ratio", "-");
+    commonproperties.insert("force_aspect_num", "-");
+    commonproperties.insert("force_aspect_den", "-");
     commonproperties.insert("force_fps", "-");
     commonproperties.insert("force_progressive", "-");
+    commonproperties.insert("force_tff", "-");
     commonproperties.insert("threads", "-");
     commonproperties.insert("video_index", "-");
     commonproperties.insert("audio_index", "-");
+    commonproperties.insert("force_colorspace", "-");
+    commonproperties.insert("full_luma", "-");
+    QString transparency = "-";
 
     bool allowDurationChange = true;
     int commonDuration = -1;
+    bool hasImages = false;;
     ProjectItem *item;
     for (int i = 0; i < list.count(); i++) {
         item = NULL;
-        if (list.at(i)->type() == PROJECTFOLDERTYPE) continue;
-        if (list.at(i)->type() == PROJECTSUBCLIPTYPE) {
+        if (list.at(i)->type() == PROJECTFOLDERTYPE) {
+            // Add folder items to the list
+            int ct = list.at(i)->childCount();
+            for (int j = 0; j < ct; j++) {
+                list.append(list.at(i)->child(j));
+            }
+            continue;
+        }
+        else if (list.at(i)->type() == PROJECTSUBCLIPTYPE)
             item = static_cast <ProjectItem*>(list.at(i)->parent());
-        } else item = static_cast <ProjectItem*>(list.at(i));
-        if (!(item->flags() & Qt::ItemIsDragEnabled)) continue;
+        else
+            item = static_cast <ProjectItem*>(list.at(i));
+        if (!(item->flags() & Qt::ItemIsDragEnabled))
+            continue;
         if (item) {
             // check properties
             DocClipBase *clip = item->referencedClip();
             if (clipList.contains(clip)) continue;
-            if (clip->clipType() != COLOR && clip->clipType() != IMAGE && clip->clipType() != TEXT) {
-                allowDurationChange = false;
+            if (clip->clipType() == IMAGE) {
+                hasImages = true;
+                if (clip->getProperty("transparency").isEmpty() || clip->getProperty("transparency").toInt() == 0) {
+                    if (transparency == "-") {
+                        // first non transparent image
+                        transparency = "0";
+                    }
+                    else if (transparency == "1") {
+                        // we have transparent and non transparent clips
+                        transparency = "-1";
+                    }
+                }
+                else {
+                    if (transparency == "-") {
+                        // first transparent image
+                        transparency = "1";
+                    }
+                    else if (transparency == "0") {
+                        // we have transparent and non transparent clips
+                        transparency = "-1";
+                    }
+                }
             }
+            if (clip->clipType() != COLOR && clip->clipType() != IMAGE && clip->clipType() != TEXT)
+                allowDurationChange = false;
             if (allowDurationChange && commonDuration != 0) {
-                if (commonDuration == -1) {
+                if (commonDuration == -1)
                     commonDuration = clip->duration().frames(m_fps);
-                } else if (commonDuration != clip->duration().frames(m_fps)) {
+                else if (commonDuration != clip->duration().frames(m_fps))
                     commonDuration = 0;
-                }
             }
             clipList.append(clip);
             QMap <QString, QString> clipprops = clip->properties();
@@ -272,36 +373,49 @@ void ProjectList::editClipSelection(QList<QTreeWidgetItem *> list)
                 p.next();
                 if (p.value().isEmpty()) continue;
                 if (clipprops.contains(p.key())) {
-                    if (p.value() == "-") commonproperties.insert(p.key(), clipprops.value(p.key()));
-                    else if (p.value() != clipprops.value(p.key())) commonproperties.insert(p.key(), QString());
-                } else commonproperties.insert(p.key(), QString());
+                    if (p.value() == "-")
+                        commonproperties.insert(p.key(), clipprops.value(p.key()));
+                    else if (p.value() != clipprops.value(p.key()))
+                        commonproperties.insert(p.key(), QString());
+                } else {
+                    commonproperties.insert(p.key(), QString());
+                }
             }
         }
     }
-    if (allowDurationChange) commonproperties.insert("out", QString::number(commonDuration));
-    QMapIterator<QString, QString> p(commonproperties);
+    if (allowDurationChange)
+        commonproperties.insert("out", QString::number(commonDuration));
+    if (hasImages)
+        commonproperties.insert("transparency", transparency);
+    /*QMapIterator<QString, QString> p(commonproperties);
     while (p.hasNext()) {
         p.next();
         kDebug() << "Result: " << p.key() << " = " << p.value();
-    }
+    }*/
     emit showClipProperties(clipList, commonproperties);
 }
 
 void ProjectList::slotOpenClip()
 {
     ProjectItem *item;
-    if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return;
-    if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1) {
+    if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
+        return;
+    if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1)
         item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
-    } else item = static_cast <ProjectItem*>(m_listView->currentItem());
+    else
+        item = static_cast <ProjectItem*>(m_listView->currentItem());
     if (item) {
         if (item->clipType() == IMAGE) {
-            if (KdenliveSettings::defaultimageapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open images in the Settings dialog"));
-            else QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
+            if (KdenliveSettings::defaultimageapp().isEmpty())
+                KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open images in the Settings dialog"));
+            else
+                QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
         }
         if (item->clipType() == AUDIO) {
-            if (KdenliveSettings::defaultaudioapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open audio files in the Settings dialog"));
-            else QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
+            if (KdenliveSettings::defaultaudioapp().isEmpty())
+                KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open audio files in the Settings dialog"));
+            else
+                QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
         }
     }
 }
@@ -317,7 +431,8 @@ void ProjectList::cleanup()
             continue;
         }
         item = static_cast <ProjectItem *>(*it);
-        if (item->numReferences() == 0) item->setSelected(true);
+        if (item->numReferences() == 0)
+            item->setSelected(true);
         it++;
     }
     slotRemoveClip();
@@ -338,7 +453,8 @@ void ProjectList::trashUnusedClips()
         if (item->numReferences() == 0) {
             ids << item->clipId();
             KUrl url = item->clipUrl();
-            if (!url.isEmpty() && !urls.contains(url.path())) urls << url.path();
+            if (!url.isEmpty() && !urls.contains(url.path()))
+                urls << url.path();
         }
         it++;
     }
@@ -359,51 +475,109 @@ void ProjectList::trashUnusedClips()
     }
 
     emit deleteProjectClips(ids, QMap <QString, QString>());
-    for (int i = 0; i < urls.count(); i++) {
+    for (int i = 0; i < urls.count(); i++)
         KIO::NetAccess::del(KUrl(urls.at(i)), this);
-    }
 }
 
 void ProjectList::slotReloadClip(const QString &id)
 {
     QList<QTreeWidgetItem *> selected;
-    if (id.isEmpty()) selected = m_listView->selectedItems();
-    else selected.append(getItemById(id));
+    if (id.isEmpty())
+        selected = m_listView->selectedItems();
+    else {
+        ProjectItem *itemToReLoad = getItemById(id);
+        if (itemToReLoad) selected.append(itemToReLoad);
+    }
     ProjectItem *item;
     for (int i = 0; i < selected.count(); i++) {
         if (selected.at(i)->type() != PROJECTCLIPTYPE) {
             if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
-                    for (int j = 0; j < selected.at(i)->childCount(); j++)
-                        selected.append(selected.at(i)->child(j));
+                for (int j = 0; j < selected.at(i)->childCount(); j++)
+                    selected.append(selected.at(i)->child(j));
             }
             continue;
         }
         item = static_cast <ProjectItem *>(selected.at(i));
-        if (item) {
-            if (item->clipType() == TEXT) {
-                if (!item->referencedClip()->getProperty("xmltemplate").isEmpty()) regenerateTemplate(item);
-            } else if (item->clipType() != COLOR && item->clipType() != SLIDESHOW && item->referencedClip() &&  item->referencedClip()->checkHash() == false) {
+        if (item && !item->isProxyRunning()) {
+            DocClipBase *clip = item->referencedClip();
+            if (!clip->isClean()) {
+                // The clip is currently under processing (replacement in timeline), we cannot reload it now.
+                continue;
+            }
+            CLIPTYPE t = item->clipType();
+            if (t == TEXT) {
+                if (clip && !clip->getProperty("xmltemplate").isEmpty())
+                    regenerateTemplate(item);
+            } else if (t != COLOR && t != SLIDESHOW && clip && clip->checkHash() == false) {
                 item->referencedClip()->setPlaceHolder(true);
                 item->setProperty("file_hash", QString());
-            } else if (item->clipType() == IMAGE) {
-                item->referencedClip()->producer()->set("force_reload", 1);
+            } else if (t == IMAGE) {
+                clip->getProducer()->set("force_reload", 1);
             }
-            //requestClipInfo(item->toXml(), item->clipId(), true);
-            // Clear the file_hash value, which will cause a complete reload of the clip
-            emit getFileProperties(item->toXml(), item->clipId(), m_listView->iconSize().height(), true);
+
+            QDomElement e = item->toXml();
+            // Make sure we get the correct producer length if it was adjusted in timeline
+            if (t == COLOR || t == IMAGE || t == SLIDESHOW || t == TEXT) {
+                int length = QString(clip->producerProperty("length")).toInt();
+                if (length > 0 && !e.hasAttribute("length")) {
+                    e.setAttribute("length", length);
+                }
+            }
+            if (clip) {
+                clip->clearThumbProducer();
+            }
+            m_render->getFileProperties(e, item->clipId(), m_listView->iconSize().height(), true);
         }
     }
 }
 
+void ProjectList::slotModifiedClip(const QString &id)
+{
+    ProjectItem *item = getItemById(id);
+    if (item) {
+        QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
+        if (!pixmap.isNull()) {
+            QPainter p(&pixmap);
+            p.fillRect(0, 0, pixmap.width(), pixmap.height(), QColor(255, 255, 255, 200));
+            p.drawPixmap(0, 0, KIcon("view-refresh").pixmap(m_listView->iconSize()));
+            p.end();
+        } else {
+            pixmap = KIcon("view-refresh").pixmap(m_listView->iconSize());
+        }
+        item->setData(0, Qt::DecorationRole, pixmap);
+    }
+}
+
 void ProjectList::slotMissingClip(const QString &id)
 {
     ProjectItem *item = getItemById(id);
     if (item) {
-        item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
+        item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
+        int height = m_listView->iconSize().height();
+        int width = (int)(height  * m_render->dar());
+        QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
+        if (pixmap.isNull()) {
+            pixmap = QPixmap(width, height);
+            pixmap.fill(Qt::transparent);
+        }
+        KIcon icon("dialog-close");
+        QPainter p(&pixmap);
+        p.drawPixmap(3, 3, icon.pixmap(width - 6, height - 6));
+        p.end();
+        item->setData(0, Qt::DecorationRole, pixmap);
         if (item->referencedClip()) {
             item->referencedClip()->setPlaceHolder(true);
-            if (m_render == NULL) kDebug() << "*********  ERROR, NULL RENDR";
-            item->referencedClip()->setProducer(m_render->invalidProducer(id), true);
+            if (m_render == NULL) {
+                kDebug() << "*********  ERROR, NULL RENDR";
+                return;
+            }
+            Mlt::Producer *newProd = m_render->invalidProducer(id);
+            if (item->referencedClip()->getProducer()) {
+                Mlt::Properties props(newProd->get_properties());
+                Mlt::Properties src_props(item->referencedClip()->getProducer()->get_properties());
+                props.inherit(src_props);
+            }
+            item->referencedClip()->setProducer(newProd, true);
             item->slotSetToolTip();
             emit clipNeedsReload(id, true);
         }
@@ -416,8 +590,9 @@ void ProjectList::slotMissingClip(const QString &id)
 void ProjectList::slotAvailableClip(const QString &id)
 {
     ProjectItem *item = getItemById(id);
-    if (item == NULL) return;
-    item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
+    if (item == NULL)
+        return;
+    item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
     if (item->referencedClip()) { // && item->referencedClip()->checkHash() == false) {
         item->setProperty("file_hash", QString());
         slotReloadClip(id);
@@ -452,31 +627,35 @@ void ProjectList::setRenderer(Render *projectRender)
 
 void ProjectList::slotClipSelected()
 {
-    if (!m_listView->isEnabled()) return;
-    if (m_listView->currentItem()) {
-        if (m_listView->currentItem()->type() == PROJECTFOLDERTYPE) {
+    m_refreshMonitorTimer.stop();
+    QTreeWidgetItem *item = m_listView->currentItem();
+    ProjectItem *clip = NULL;
+    if (item) {
+        if (item->type() == PROJECTFOLDERTYPE) {
             emit clipSelected(NULL);
-            m_editAction->setEnabled(false);
-            m_deleteAction->setEnabled(true);
+            m_editButton->defaultAction()->setEnabled(item->childCount() > 0);
+            m_deleteButton->defaultAction()->setEnabled(true);
             m_openAction->setEnabled(false);
             m_reloadAction->setEnabled(false);
             m_transcodeAction->setEnabled(false);
         } else {
-            ProjectItem *clip;
-            if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
+            if (item->type() == PROJECTSUBCLIPTYPE) {
                 // this is a sub item, use base clip
-                m_deleteAction->setEnabled(true);
-                clip = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
+                m_deleteButton->defaultAction()->setEnabled(true);
+                clip = static_cast <ProjectItem*>(item->parent());
                 if (clip == NULL) kDebug() << "-----------ERROR";
-                SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
+                SubProjectItem *sub = static_cast <SubProjectItem*>(item);
                 emit clipSelected(clip->referencedClip(), sub->zone());
                 m_transcodeAction->setEnabled(false);
+                m_reloadAction->setEnabled(false);
+                adjustProxyActions(clip);
                 return;
             }
-            clip = static_cast <ProjectItem*>(m_listView->currentItem());
-            if (clip) emit clipSelected(clip->referencedClip());
-            m_editAction->setEnabled(true);
-            m_deleteAction->setEnabled(true);
+            clip = static_cast <ProjectItem*>(item);
+            if (clip && clip->referencedClip())
+                emit clipSelected(clip->referencedClip());
+            m_editButton->defaultAction()->setEnabled(true);
+            m_deleteButton->defaultAction()->setEnabled(true);
             m_reloadAction->setEnabled(true);
             m_transcodeAction->setEnabled(true);
             if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
@@ -485,7 +664,9 @@ void ProjectList::slotClipSelected()
             } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
                 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
                 m_openAction->setEnabled(true);
-            } else m_openAction->setEnabled(false);
+            } else {
+                m_openAction->setEnabled(false);
+            }
             // Display relevant transcoding actions only
             adjustTranscodeActions(clip);
             // Display uses in timeline
@@ -493,17 +674,30 @@ void ProjectList::slotClipSelected()
         }
     } else {
         emit clipSelected(NULL);
-        m_editAction->setEnabled(false);
-        m_deleteAction->setEnabled(false);
+        m_editButton->defaultAction()->setEnabled(false);
+        m_deleteButton->defaultAction()->setEnabled(false);
         m_openAction->setEnabled(false);
         m_reloadAction->setEnabled(false);
         m_transcodeAction->setEnabled(false);
     }
+    adjustProxyActions(clip);
+}
+
+void ProjectList::adjustProxyActions(ProjectItem *clip) const
+{
+    if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == SLIDESHOW || clip->clipType() == AUDIO) {
+        m_proxyAction->setEnabled(false);
+        return;
+    }
+    m_proxyAction->setEnabled(useProxy());
+    m_proxyAction->blockSignals(true);
+    m_proxyAction->setChecked(clip->hasProxy());
+    m_proxyAction->blockSignals(false);
 }
 
 void ProjectList::adjustTranscodeActions(ProjectItem *clip) const
 {
-    if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST) {
+    if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW) {
         m_transcodeAction->setEnabled(false);
         return;
     }
@@ -515,8 +709,10 @@ void ProjectList::adjustTranscodeActions(ProjectItem *clip) const
         data = transcodeActions.at(i)->data().toStringList();
         if (data.count() > 2) {
             condition = data.at(2);
-            if (condition.startsWith("vcodec")) transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section("=", 1, 1)));
-            else if (condition.startsWith("acodec")) transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section("=", 1, 1)));
+            if (condition.startsWith("vcodec"))
+                transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
+            else if (condition.startsWith("acodec"))
+                transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
         }
     }
 
@@ -524,7 +720,8 @@ void ProjectList::adjustTranscodeActions(ProjectItem *clip) const
 
 void ProjectList::slotPauseMonitor()
 {
-    if (m_render) m_render->pause();
+    if (m_render)
+        m_render->pause();
 }
 
 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
@@ -532,30 +729,37 @@ void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QSt
     ProjectItem *item = getItemById(id);
     if (item) {
         slotUpdateClipProperties(item, properties);
-        if (properties.contains("out") || properties.contains("force_fps")) {
+        if (properties.contains("out") || properties.contains("force_fps") || properties.contains("resource")) {
             slotReloadClip(id);
-        } else if (properties.contains("colour") || properties.contains("resource") || properties.contains("xmldata") || properties.contains("force_aspect_ratio") || properties.contains("templatetext")) {
+        } else if (properties.contains("colour") ||
+                   properties.contains("xmldata") ||
+                   properties.contains("force_aspect_num") ||
+                   properties.contains("force_aspect_den") ||
+                   properties.contains("templatetext")) {
             slotRefreshClipThumbnail(item);
-            emit refreshClip();
+            emit refreshClip(id, true);
+        } else if (properties.contains("full_luma") || properties.contains("force_colorspace") || properties.contains("loop")) {
+            emit refreshClip(id, false);
         }
     }
 }
 
 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
 {
-    if (!clip) return;
+    if (!clip)
+        return;
     clip->setProperties(properties);
     if (properties.contains("name")) {
-        m_listView->blockSignals(true);
+        monitorItemEditing(false);
         clip->setText(0, properties.value("name"));
-        m_listView->blockSignals(false);
+        monitorItemEditing(true);
         emit clipNameChanged(clip->clipId(), properties.value("name"));
     }
     if (properties.contains("description")) {
         CLIPTYPE type = clip->clipType();
-        m_listView->blockSignals(true);
+        monitorItemEditing(false);
         clip->setText(1, properties.value("description"));
-        m_listView->blockSignals(false);
+        monitorItemEditing(true);
 #ifdef NEPOMUK
         if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
             // Use Nepomuk system to store clip description
@@ -582,15 +786,16 @@ void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
         return;
     }
     if (item->type() == PROJECTFOLDERTYPE) {
-        if (column != 0) return;
-        FolderProjectItem *folder = static_cast <FolderProjectItem*>(item);
-        editFolder(item->text(0), folder->groupName(), folder->clipId());
-        folder->setGroupName(item->text(0));
-        m_doc->clipManager()->addFolder(folder->clipId(), item->text(0));
-        const int children = item->childCount();
-        for (int i = 0; i < children; i++) {
-            ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
-            child->setProperty("groupname", item->text(0));
+        if (column == 0) {
+            FolderProjectItem *folder = static_cast <FolderProjectItem*>(item);
+            editFolder(item->text(0), folder->groupName(), folder->clipId());
+            folder->setGroupName(item->text(0));
+            m_doc->clipManager()->addFolder(folder->clipId(), item->text(0));
+            const int children = item->childCount();
+            for (int i = 0; i < children; i++) {
+                ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
+                child->setProperty("groupname", item->text(0));
+            }
         }
         return;
     }
@@ -619,23 +824,22 @@ void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
             QMap <QString, QString> oldprops;
             QMap <QString, QString> newprops;
             oldprops["name"] = clip->referencedClip()->getProperty("name");
-            newprops["name"] = item->text(0);
-            slotUpdateClipProperties(clip, newprops);
-            emit projectModified();
-            EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
-            m_commandStack->push(command);
+            if (oldprops.value("name") != item->text(0)) {
+                newprops["name"] = item->text(0);
+                slotUpdateClipProperties(clip, newprops);
+                emit projectModified();
+                EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
+                m_commandStack->push(command);
+            }
         }
     }
 }
 
 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
 {
-    bool enable = false;
-    if (item) {
-        enable = true;
-    }
-    m_editAction->setEnabled(enable);
-    m_deleteAction->setEnabled(enable);
+    bool enable = item ? true : false;
+    m_editButton->defaultAction()->setEnabled(enable);
+    m_deleteButton->defaultAction()->setEnabled(enable);
     m_reloadAction->setEnabled(enable);
     m_transcodeAction->setEnabled(enable);
     if (enable) {
@@ -643,35 +847,43 @@ void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
         if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
             clip = static_cast <ProjectItem*>(item->parent());
             m_transcodeAction->setEnabled(false);
+            adjustProxyActions(clip);
         } else if (m_listView->currentItem()->type() == PROJECTCLIPTYPE) {
             clip = static_cast <ProjectItem*>(item);
             // Display relevant transcoding actions only
             adjustTranscodeActions(clip);
+            adjustProxyActions(clip);
             // Display uses in timeline
             emit findInTimeline(clip->clipId());
-        } else m_transcodeAction->setEnabled(false);
+        } else {
+            m_transcodeAction->setEnabled(false);
+        }
         if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
             m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
             m_openAction->setEnabled(true);
         } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
             m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
             m_openAction->setEnabled(true);
-        } else m_openAction->setEnabled(false);
+        } else {
+            m_openAction->setEnabled(false);
+        }
 
-    } else m_openAction->setEnabled(false);
+    } else {
+        m_openAction->setEnabled(false);
+    }
     m_menu->popup(pos);
 }
 
 void ProjectList::slotRemoveClip()
 {
-    if (!m_listView->currentItem()) return;
+    if (!m_listView->currentItem())
+        return;
     QStringList ids;
     QMap <QString, QString> folderids;
     QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
 
     QUndoCommand *delCommand = new QUndoCommand();
     delCommand->setText(i18n("Delete Clip Zone"));
-
     for (int i = 0; i < selected.count(); i++) {
         if (selected.at(i)->type() == PROJECTSUBCLIPTYPE) {
             // subitem
@@ -684,7 +896,8 @@ void ProjectList::slotRemoveClip()
             folderids[folder->groupName()] = folder->clipId();
             int children = folder->childCount();
 
-            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) return;
+            if (children > 0 && KMessageBox::questionYesNo(kapp->activeWindow(), 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)
+                return;
             for (int i = 0; i < children; ++i) {
                 ProjectItem *child = static_cast <ProjectItem *>(folder->child(i));
                 ids << child->clipId();
@@ -692,44 +905,53 @@ void ProjectList::slotRemoveClip()
         } else {
             ProjectItem *item = static_cast <ProjectItem *>(selected.at(i));
             ids << item->clipId();
-            if (item->numReferences() > 0) {
-                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;
+            if (item->numReferences() > 0 && KMessageBox::questionYesNo(kapp->activeWindow(), 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"), KStandardGuiItem::yes(), KStandardGuiItem::no(), "DeleteAll") == KMessageBox::No) {
+                KMessageBox::enableMessage("DeleteAll");
+                return;
             }
         }
     }
-
-    if (delCommand->childCount() == 0) delete delCommand;
-    else m_commandStack->push(delCommand);
+    KMessageBox::enableMessage("DeleteAll");
+    if (delCommand->childCount() == 0)
+        delete delCommand;
+    else
+        m_commandStack->push(delCommand);
     emit deleteProjectClips(ids, folderids);
 }
 
 void ProjectList::updateButtons() const
 {
     if (m_listView->topLevelItemCount() == 0) {
-        m_deleteAction->setEnabled(false);
+        m_deleteButton->defaultAction()->setEnabled(false);
+        m_editButton->defaultAction()->setEnabled(false);
     } else {
-        m_deleteAction->setEnabled(true);
-        if (!m_listView->currentItem()) m_listView->setCurrentItem(m_listView->topLevelItem(0));
+        m_deleteButton->defaultAction()->setEnabled(true);
+        if (!m_listView->currentItem())
+            m_listView->setCurrentItem(m_listView->topLevelItem(0));
         QTreeWidgetItem *item = m_listView->currentItem();
         if (item && item->type() == PROJECTCLIPTYPE) {
-            m_editAction->setEnabled(true);
+            m_editButton->defaultAction()->setEnabled(true);
             m_openAction->setEnabled(true);
             m_reloadAction->setEnabled(true);
             m_transcodeAction->setEnabled(true);
             return;
         }
+        else if (item && item->type() == PROJECTFOLDERTYPE && item->childCount() > 0) {
+            m_editButton->defaultAction()->setEnabled(true);
+        }
+        else m_editButton->defaultAction()->setEnabled(false);
     }
-
-    m_editAction->setEnabled(false);
     m_openAction->setEnabled(false);
     m_reloadAction->setEnabled(false);
     m_transcodeAction->setEnabled(false);
+    m_proxyAction->setEnabled(false);
 }
 
 void ProjectList::selectItemById(const QString &clipId)
 {
     ProjectItem *item = getItemById(clipId);
-    if (item) m_listView->setCurrentItem(item);
+    if (item)
+        m_listView->setCurrentItem(item);
 }
 
 
@@ -740,10 +962,14 @@ void ProjectList::slotDeleteClip(const QString &clipId)
         kDebug() << "/// Cannot find clip to delete";
         return;
     }
+    if (item->isProxyRunning()) m_abortProxy.append(item->referencedClip()->getProperty("proxy"));
     m_listView->blockSignals(true);
     QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
-    if (!newSelectedItem) newSelectedItem = m_listView->itemBelow(item);
+    if (!newSelectedItem)
+        newSelectedItem = m_listView->itemBelow(item);
     delete item;
+    // Pause playing to prevent crash while deleting clip
+    slotPauseMonitor();
     m_doc->clipManager()->deleteClip(clipId);
     m_listView->blockSignals(false);
     if (newSelectedItem) {
@@ -775,10 +1001,13 @@ void ProjectList::slotAddFolder(const QString foldername, const QString &clipId,
         if (item) {
             m_doc->clipManager()->deleteFolder(clipId);
             QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
-            if (!newSelectedItem) newSelectedItem = m_listView->itemBelow(item);
+            if (!newSelectedItem)
+                newSelectedItem = m_listView->itemBelow(item);
             delete item;
-            if (newSelectedItem) m_listView->setCurrentItem(newSelectedItem);
-            else updateButtons();
+            if (newSelectedItem)
+                m_listView->setCurrentItem(newSelectedItem);
+            else
+                updateButtons();
         }
     } else {
         if (edit) {
@@ -795,12 +1024,11 @@ void ProjectList::slotAddFolder(const QString foldername, const QString &clipId,
                 }
             }
         } else {
-            QStringList text;
-            text << foldername;
             m_listView->blockSignals(true);
-            m_listView->setCurrentItem(new FolderProjectItem(m_listView, text, clipId));
+            m_listView->setCurrentItem(new FolderProjectItem(m_listView, QStringList() << foldername, clipId));
             m_doc->clipManager()->addFolder(clipId, foldername);
             m_listView->blockSignals(false);
+            m_listView->editItem(m_listView->currentItem(), 0);
         }
         updateButtons();
     }
@@ -818,24 +1046,16 @@ void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
         i.next();
         new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
     }
-    m_commandStack->push(delCommand);
+    if (delCommand->childCount() > 0) m_commandStack->push(delCommand);
+    else delete delCommand;
 }
 
 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
 {
-    m_listView->setEnabled(false);
-    if (getProperties) {
-        m_listView->blockSignals(true);
-        m_refreshed = false;
-        // remove file_hash so that we load all properties for the clip
-        QDomElement e = clip->toXML().cloneNode().toElement();
-        e.removeAttribute("file_hash");
-        m_infoQueue.insert(clip->getId(), e);
-        clip->askForAudioThumbs();
-        //m_render->getFileProperties(clip->toXML(), clip->getId(), true);
-    }
+    //m_listView->setEnabled(false);
     const QString parent = clip->getProperty("groupid");
     ProjectItem *item = NULL;
+    monitorItemEditing(false);
     if (!parent.isEmpty()) {
         FolderProjectItem *parentitem = getFolderItemById(parent);
         if (!parentitem) {
@@ -845,22 +1065,37 @@ void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
             if (groupName.isEmpty()) groupName = i18n("Folder");
             text << groupName;
             parentitem = new FolderProjectItem(m_listView, text, parent);
-        } else {
-            //kDebug() << "Adding clip to existing group: " << parentitem->groupName();
         }
-        if (parentitem) item = new ProjectItem(parentitem, clip);
-    }
-    if (item == NULL) item = new ProjectItem(m_listView, clip);
-    KUrl url = clip->fileURL();
 
-    if (getProperties == false && !clip->getClipHash().isEmpty()) {
-        QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
-        if (QFile::exists(cachedPixmap)) {
-            QPixmap pix(cachedPixmap);
-            if (pix.isNull()) KIO::NetAccess::del(KUrl(cachedPixmap), this);
-            item->setData(0, Qt::DecorationRole, pix);
-        }
+        if (parentitem)
+            item = new ProjectItem(parentitem, clip);
+    }
+    if (item == NULL) {
+        item = new ProjectItem(m_listView, clip);
     }
+    if (item->data(0, DurationRole).isNull()) item->setData(0, DurationRole, i18n("Loading"));
+    QString proxy = clip->getProperty("proxy");
+    if (!proxy.isEmpty() && proxy != "-") slotCreateProxy(clip->getId());
+    connect(clip, SIGNAL(createProxy(const QString &)), this, SLOT(slotCreateProxy(const QString &)));
+    connect(clip, SIGNAL(abortProxy(const QString &, const QString &)), this, SLOT(slotAbortProxy(const QString, const QString)));
+    if (getProperties) {
+        int height = m_listView->iconSize().height();
+        int width = (int)(height  * m_render->dar());
+        QPixmap pix =  KIcon("video-x-generic").pixmap(QSize(width, height));
+        item->setData(0, Qt::DecorationRole, pix);
+        //item->setFlags(Qt::ItemIsSelectable);
+        m_listView->processLayout();
+        QDomElement e = clip->toXML().cloneNode().toElement();
+        e.removeAttribute("file_hash");
+        clip->clearThumbProducer();
+        m_render->getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true);
+    }
+    else if (item->hasProxy() && !item->isProxyRunning()) {
+        slotCreateProxy(clip->getId());
+    }
+    clip->askForAudioThumbs();
+    
+    KUrl url = clip->fileURL();
 #ifdef NEPOMUK
     if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
         // if file has Nepomuk comment, use it
@@ -879,73 +1114,116 @@ void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
                 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(cuts.at(i).zone.x()) + ".png";
                 if (QFile::exists(cachedPixmap)) {
                     QPixmap pix(cachedPixmap);
-                    if (pix.isNull()) KIO::NetAccess::del(KUrl(cachedPixmap), this);
+                    if (pix.isNull())
+                        KIO::NetAccess::del(KUrl(cachedPixmap), this);
                     sub->setData(0, Qt::DecorationRole, pix);
                 }
             }
         }
     }
-    if (m_listView->isEnabled()) {
-        updateButtons();
-        if (getProperties) m_listView->blockSignals(false);
-    }
-    if (getProperties && !m_queueTimer.isActive()) m_queueTimer.start();
+    monitorItemEditing(true);
+    updateButtons();
 }
 
-void ProjectList::slotResetProjectList()
+void ProjectList::slotGotProxy(const QString &proxyPath)
 {
-    m_listView->clear();
-    emit clipSelected(NULL);
-    m_thumbnailQueue.clear();
-    m_infoQueue.clear();
-    m_refreshed = false;
-}
+    if (proxyPath.isEmpty() || !m_refreshed || m_abortAllProxies) return;
+    QTreeWidgetItemIterator it(m_listView);
+    ProjectItem *item;
 
-void ProjectList::requestClipInfo(const QDomElement xml, const QString id)
-{
-    m_refreshed = false;
-    m_infoQueue.insert(id, xml);
-    //if (m_infoQueue.count() == 1 || ) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
+    while (*it) {
+        if ((*it)->type() == PROJECTCLIPTYPE) {
+            item = static_cast <ProjectItem *>(*it);
+            if (item->referencedClip()->getProperty("proxy") == proxyPath)
+                slotGotProxy(item);
+        }
+        ++it;
+    }
 }
 
-void ProjectList::slotProcessNextClipInQueue()
+void ProjectList::slotGotProxy(ProjectItem *item)
 {
-    if (m_infoQueue.isEmpty()) {
-        slotProcessNextThumbnail();
+    if (item == NULL || !m_refreshed) return;
+    DocClipBase *clip = item->referencedClip();
+    if (!clip->isClean()) {
+        //WARNING: might result in clip said marked as proxy but not using proxy?
+        // The clip is currently under processing (replacement in timeline), we cannot reload it now.
         return;
     }
+    // Proxy clip successfully created
+    QDomElement e = clip->toXML().cloneNode().toElement();
 
-    QMap<QString, QDomElement>::const_iterator j = m_infoQueue.constBegin();
-    if (j != m_infoQueue.constEnd()) {
-        const QDomElement dom = j.value();
-        const QString id = j.key();
-        m_infoQueue.remove(j.key());
-        emit getFileProperties(dom, id, m_listView->iconSize().height(), false);
+    // Make sure we get the correct producer length if it was adjusted in timeline
+    CLIPTYPE t = item->clipType();
+    if (t == COLOR || t == IMAGE || t == SLIDESHOW || t == TEXT) {
+        int length = QString(clip->producerProperty("length")).toInt();
+        if (length > 0 && !e.hasAttribute("length")) {
+            e.setAttribute("length", length);
+        }
     }
+    clip->clearThumbProducer();
+    m_render->getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true);
+}
+
+void ProjectList::slotResetProjectList()
+{
+    m_abortAllProxies = true;
+    m_proxyThreads.waitForFinished();
+    m_proxyThreads.clearFutures();
+    m_thumbnailQueue.clear();
+    m_listView->clear();
+    emit clipSelected(NULL);
+    m_refreshed = false;
+    m_abortAllProxies = false;
 }
 
 void ProjectList::slotUpdateClip(const QString &id)
 {
     ProjectItem *item = getItemById(id);
-    m_listView->blockSignals(true);
+    monitorItemEditing(false);
     if (item) item->setData(0, UsageRole, QString::number(item->numReferences()));
-    m_listView->blockSignals(false);
+    monitorItemEditing(true);
 }
 
-void ProjectList::updateAllClips()
+void ProjectList::getCachedThumbnail(ProjectItem *item)
+{
+    if (!item) return;
+    DocClipBase *clip = item->referencedClip();
+    if (!clip) return;
+    QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
+    if (QFile::exists(cachedPixmap)) {
+        QPixmap pix(cachedPixmap);
+        if (pix.isNull()) {
+            KIO::NetAccess::del(KUrl(cachedPixmap), this);
+            requestClipThumbnail(item->clipId());
+        }
+        else item->setData(0, Qt::DecorationRole, pix);
+    }
+    else requestClipThumbnail(item->clipId());
+}
+
+void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged)
 {
     m_listView->setSortingEnabled(false);
-    kDebug() << "// UPDATE ALL CLPY";
 
     QTreeWidgetItemIterator it(m_listView);
     DocClipBase *clip;
     ProjectItem *item;
-    m_listView->blockSignals(true);
+    monitorItemEditing(false);
+    int height = m_listView->iconSize().height();
+    int width = (int)(height  * m_render->dar());
+    QPixmap missingPixmap = QPixmap(width, height);
+    missingPixmap.fill(Qt::transparent);
+    KIcon icon("dialog-close");
+    QPainter p(&missingPixmap);
+    p.drawPixmap(3, 3, icon.pixmap(width - 6, height - 6));
+    p.end();
+    kDebug()<<"//////////////7  UPDATE ALL CLPS";
     while (*it) {
         if ((*it)->type() == PROJECTSUBCLIPTYPE) {
             // subitem
             SubProjectItem *sub = static_cast <SubProjectItem *>(*it);
-            if (sub->data(0, Qt::DecorationRole).isNull()) {
+            if (displayRatioChanged || sub->data(0, Qt::DecorationRole).isNull()) {
                 item = static_cast <ProjectItem *>((*it)->parent());
                 requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x()));
             }
@@ -958,56 +1236,147 @@ void ProjectList::updateAllClips()
         } else {
             item = static_cast <ProjectItem *>(*it);
             clip = item->referencedClip();
-            if (item->referencedClip()->producer() == NULL) {
+            if (item->referencedClip()->getProducer() == NULL) {
                 if (clip->isPlaceHolder() == false) {
-                    requestClipInfo(clip->toXML(), clip->getId());
-                } else if (!clip->isPlaceHolder()) item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
-            } else {
-                if (item->data(0, Qt::DecorationRole).isNull()) {
+                    QDomElement xml = clip->toXML();
+                    if (fpsChanged) {
+                        xml.removeAttribute("out");
+                        xml.removeAttribute("file_hash");
+                        xml.removeAttribute("proxy_out");
+                    }
+                    bool replace = xml.attribute("replace") == "1";
+                    if (replace) clip->clearThumbProducer();
+                    m_render->getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), replace);
+                }
+                else {
+                    item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
+                    if (item->data(0, Qt::DecorationRole).isNull()) {
+                        item->setData(0, Qt::DecorationRole, missingPixmap);
+                    }
+                    else {
+                        QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
+                        QPainter p(&pixmap);
+                        p.drawPixmap(3, 3, KIcon("dialog-close").pixmap(pixmap.width() - 6, pixmap.height() - 6));
+                        p.end();
+                        item->setData(0, Qt::DecorationRole, pixmap);
+                    }
+                }
+            } else {              
+                if (displayRatioChanged)
                     requestClipThumbnail(clip->getId());
+                else if (item->data(0, Qt::DecorationRole).isNull()) {
+                    getCachedThumbnail(item);
                 }
                 if (item->data(0, DurationRole).toString().isEmpty()) {
-                    item->changeDuration(item->referencedClip()->producer()->get_playtime());
+                    item->changeDuration(item->referencedClip()->getProducer()->get_playtime());
+                }
+                if (clip->isPlaceHolder()) {
+                    QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
+                    if (pixmap.isNull()) {
+                        pixmap = QPixmap(width, height);
+                        pixmap.fill(Qt::transparent);
+                    }
+                    QPainter p(&pixmap);
+                    p.drawPixmap(3, 3, KIcon("dialog-close").pixmap(pixmap.width() - 6, pixmap.height() - 6));
+                    p.end();
+                    item->setData(0, Qt::DecorationRole, pixmap);
                 }
             }
             item->setData(0, UsageRole, QString::number(item->numReferences()));
         }
-        //qApp->processEvents();
         ++it;
     }
-    if (!m_queueTimer.isActive()) m_queueTimer.start();
-    if (m_listView->isEnabled()) m_listView->blockSignals(false);
+
     m_listView->setSortingEnabled(true);
-    if (m_infoQueue.isEmpty()) slotProcessNextThumbnail();
+    if (m_render->processingItems() == 0) {
+       monitorItemEditing(true);
+       slotProcessNextThumbnail();
+    }
+}
+
+// static
+QString ProjectList::getExtensions()
+{
+    // Build list of mime types
+    QStringList mimeTypes = QStringList() << "application/x-kdenlive" << "application/x-kdenlivetitle" << "video/mlt-playlist" << "text/plain"
+                            << "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" << "video/webm"
+                            << "audio/x-flac" << "audio/x-matroska" << "audio/mp4" << "audio/mpeg" << "audio/x-mp3" << "audio/ogg" << "audio/x-wav" << "audio/x-aiff" << "audio/aiff" << "application/ogg" << "application/mxf" << "application/x-shockwave-flash"
+                            << "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";
+
+    QString allExtensions;
+    foreach(const QString & mimeType, mimeTypes) {
+        KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
+        if (mime) {
+            allExtensions.append(mime->patterns().join(" "));
+            allExtensions.append(' ');
+        }
+    }
+    return allExtensions.simplified();
 }
 
 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
 {
-    if (!m_commandStack) {
+    if (!m_commandStack)
         kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
-    }
+
     KUrl::List list;
     if (givenList.isEmpty()) {
-        // Build list of mime types
-        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" << "image/x-xcf-gimp" << "image/x-vnd.adobe.photoshop" << "image/x-pcx" << "image/x-exr";
-
-        QString allExtensions;
-        foreach(const QString& mimeType, mimeTypes) {
-            KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
-            if (mime) {
-                allExtensions.append(mime->patterns().join(" "));
-                allExtensions.append(' ');
+        QString allExtensions = getExtensions();
+        const QString dialogFilter = allExtensions + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
+        QCheckBox *b = new QCheckBox(i18n("Import image sequence"));
+        b->setChecked(KdenliveSettings::autoimagesequence());
+        QCheckBox *c = new QCheckBox(i18n("Transparent background for images"));
+        c->setChecked(KdenliveSettings::autoimagetransparency());
+        QFrame *f = new QFrame;
+        f->setFrameShape(QFrame::NoFrame);
+        QHBoxLayout *l = new QHBoxLayout;
+        l->addWidget(b);
+        l->addWidget(c);
+        l->addStretch(5);
+        f->setLayout(l);
+        KFileDialog *d = new KFileDialog(KUrl("kfiledialog:///clipfolder"), dialogFilter, kapp->activeWindow(), f);
+        d->setOperationMode(KFileDialog::Opening);
+        d->setMode(KFile::Files);
+        if (d->exec() == QDialog::Accepted) {
+            KdenliveSettings::setAutoimagetransparency(c->isChecked());
+        }
+        list = d->selectedUrls();
+        if (b->isChecked() && list.count() == 1) {
+            // Check for image sequence
+            KUrl url = list.at(0);
+            QString fileName = url.fileName().section('.', 0, -2);
+            if (fileName.at(fileName.size() - 1).isDigit()) {
+                KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
+                if (item.mimetype().startsWith("image")) {
+                    // import as sequence if we found more than one image in the sequence
+                    QStringList list;
+                    QString pattern = SlideshowClip::selectedPath(url.path(), false, QString(), &list);
+                    int count = list.count();
+                    if (count > 1) {
+                        delete d;
+                        QStringList groupInfo = getGroup();
+
+                        // get image sequence base name
+                        while (fileName.at(fileName.size() - 1).isDigit()) {
+                            fileName.chop(1);
+                        }
+
+                        m_doc->slotCreateSlideshowClipFile(fileName, pattern, count, m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()),
+                                                           false, false, false,
+                                                           m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))), QString(), 0,
+                                                           QString(), groupInfo.at(0), groupInfo.at(1));
+                        return;
+                    }
+                }
             }
         }
-        const QString dialogFilter = allExtensions.simplified() + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
-        list = KFileDialog::getOpenUrls(KUrl("kfiledialog:///clipfolder"), dialogFilter, this);
-
+        delete d;
     } else {
         for (int i = 0; i < givenList.count(); i++)
             list << givenList.at(i);
     }
 
-    foreach(const KUrl &file, list) {
+    foreach(const KUrl & file, list) {
         // Check there is no folder here
         KMimeType::Ptr type = KMimeType::findByUrl(file);
         if (type->is("inode/directory")) {
@@ -1016,65 +1385,116 @@ void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &group
         }
     }
 
-    if (list.isEmpty()) return;
+    if (list.isEmpty())
+        return;
 
     if (givenList.isEmpty()) {
         QStringList groupInfo = getGroup();
         m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1));
-    } else m_doc->slotAddClipList(list, groupName, groupId);
+    } else {
+        m_doc->slotAddClipList(list, groupName, groupId);
+    }
 }
 
 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
 {
     ProjectItem *item = getItemById(id);
-    QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
+    m_processingClips.removeAll(id);
+    m_thumbnailQueue.removeAll(id);
     if (item) {
+        item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
         const QString path = item->referencedClip()->fileURL().path();
         if (item->referencedClip()->isPlaceHolder()) replace = false;
         if (!path.isEmpty()) {
-            if (replace) KMessageBox::sorry(this, i18n("Clip <b>%1</b><br />is invalid, will be removed from project.", path));
+            if (m_invalidClipDialog) {
+                m_invalidClipDialog->addClip(id, path);
+                return;
+            }
             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) replace = true;
+                if (replace)
+                    m_invalidClipDialog = new InvalidDialog(i18n("Invalid clip"),  i18n("Clip <b>%1</b><br />is invalid, will be removed from project.", QString()), replace, kapp->activeWindow());
+                else {
+                    m_invalidClipDialog = new InvalidDialog(i18n("Invalid clip"),  i18n("Clip <b>%1</b><br />is missing or invalid. Remove it from project?", QString()), replace, kapp->activeWindow());
+                }
+                m_invalidClipDialog->addClip(id, path);
+                int result = m_invalidClipDialog->exec();
+                if (result == KDialog::Yes) replace = true;
             }
         }
-        QStringList ids;
-        ids << id;
-        if (replace) emit deleteProjectClips(ids, QMap <QString, QString>());
+        if (m_invalidClipDialog) {
+            if (replace)
+                emit deleteProjectClips(m_invalidClipDialog->getIds(), QMap <QString, QString>());
+            delete m_invalidClipDialog;
+            m_invalidClipDialog = NULL;
+        }
+        
+    }
+}
+
+void ProjectList::slotRemoveInvalidProxy(const QString &id, bool durationError)
+{
+    ProjectItem *item = getItemById(id);
+    if (item) {
+        item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
+        if (durationError) {
+            kDebug() << "Proxy duration is wrong, try changing transcoding parameters.";
+            emit displayMessage(i18n("Proxy clip unusable (duration is different from original)."), -2);
+        }
+        item->setProxyStatus(PROXYCRASHED);
+        QString path = item->referencedClip()->getProperty("proxy");
+        KUrl proxyFolder(m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/");
+
+        //Security check: make sure the invalid proxy file is in the proxy folder
+        if (proxyFolder.isParentOf(KUrl(path))) {
+            QFile::remove(path);
+        }
     }
+    m_processingClips.removeAll(id);
+    m_thumbnailQueue.removeAll(id);
 }
 
 void ProjectList::slotAddColorClip()
 {
-    if (!m_commandStack) {
+    if (!m_commandStack)
         kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
-    }
+
     QDialog *dia = new QDialog(this);
     Ui::ColorClip_UI dia_ui;
     dia_ui.setupUi(dia);
     dia->setWindowTitle(i18n("Color Clip"));
     dia_ui.clip_name->setText(i18n("Color Clip"));
-    dia_ui.clip_duration->setInputMask(m_timecode.inputMask());
-    dia_ui.clip_duration->setText(m_timecode.reformatSeparators(KdenliveSettings::color_duration()));
+
+    TimecodeDisplay *t = new TimecodeDisplay(m_timecode);
+    t->setValue(KdenliveSettings::color_duration());
+    t->setTimeCodeFormat(false);
+    dia_ui.clip_durationBox->addWidget(t);
+    dia_ui.clip_color->setColor(KdenliveSettings::colorclipcolor());
+
     if (dia->exec() == QDialog::Accepted) {
         QString color = dia_ui.clip_color->color().name();
+        KdenliveSettings::setColorclipcolor(color);
         color = color.replace(0, 1, "0x") + "ff";
         QStringList groupInfo = getGroup();
-        m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, dia_ui.clip_duration->text(), groupInfo.at(0), groupInfo.at(1));
+        m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, m_timecode.getTimecode(t->gentime()), groupInfo.at(0), groupInfo.at(1));
     }
+    delete t;
     delete dia;
 }
 
 
 void ProjectList::slotAddSlideshowClip()
 {
-    if (!m_commandStack) {
+    if (!m_commandStack)
         kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
-    }
+
     SlideshowClip *dia = new SlideshowClip(m_timecode, this);
 
     if (dia->exec() == QDialog::Accepted) {
         QStringList groupInfo = getGroup();
-        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));
+        m_doc->slotCreateSlideshowClipFile(dia->clipName(), dia->selectedPath(), dia->imageCount(), dia->clipDuration(),
+                                           dia->loop(), dia->crop(), dia->fade(),
+                                           dia->lumaDuration(), dia->lumaFile(), dia->softness(),
+                                           dia->animation(), groupInfo.at(0), groupInfo.at(1));
     }
     delete dia;
 }
@@ -1087,10 +1507,10 @@ void ProjectList::slotAddTitleClip()
 
 void ProjectList::slotAddTitleTemplateClip()
 {
-    QStringList groupInfo = getGroup();
-    if (!m_commandStack) {
+    if (!m_commandStack)
         kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
-    }
+
+    QStringList groupInfo = getGroup();
 
     // Get the list of existing templates
     QStringList filter;
@@ -1101,12 +1521,12 @@ void ProjectList::slotAddTitleTemplateClip()
     QDialog *dia = new QDialog(this);
     Ui::TemplateClip_UI dia_ui;
     dia_ui.setupUi(dia);
-    for (int i = 0; i < templateFiles.size(); ++i) {
+    for (int i = 0; i < templateFiles.size(); ++i)
         dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
-    }
+
     if (!templateFiles.isEmpty())
         dia_ui.buttonBox->button(QDialogButtonBox::Ok)->setFocus();
-    dia_ui.template_list->fileDialog()->setFilter("*.kdenlivetitle");
+    dia_ui.template_list->fileDialog()->setFilter("application/x-kdenlivetitle");
     //warning: setting base directory doesn't work??
     KUrl startDir(path);
     dia_ui.template_list->fileDialog()->setUrl(startDir);
@@ -1124,55 +1544,64 @@ QStringList ProjectList::getGroup() const
 {
     QStringList result;
     QTreeWidgetItem *item = m_listView->currentItem();
-    while (item && item->type() != PROJECTFOLDERTYPE) {
+    while (item && item->type() != PROJECTFOLDERTYPE)
         item = item->parent();
-    }
 
     if (item) {
         FolderProjectItem *folder = static_cast <FolderProjectItem *>(item);
-        result << folder->groupName();
-        result << folder->clipId();
-    } else result << QString() << QString();
+        result << folder->groupName() << folder->clipId();
+    } else {
+        result << QString() << QString();
+    }
     return result;
 }
 
 void ProjectList::setDocument(KdenliveDoc *doc)
 {
     m_listView->blockSignals(true);
+    m_abortAllProxies = true;
+    m_proxyThreads.waitForFinished();
+    m_proxyThreads.clearFutures();
+    m_thumbnailQueue.clear();
     m_listView->clear();
+    m_processingClips.clear();
+    
     m_listView->setSortingEnabled(false);
     emit clipSelected(NULL);
-    m_thumbnailQueue.clear();
-    m_infoQueue.clear();
     m_refreshed = false;
     m_fps = doc->fps();
     m_timecode = doc->timecode();
     m_commandStack = doc->commandStack();
     m_doc = doc;
+    m_abortAllProxies = false;
 
     QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
+    QStringList openedFolders = doc->getExpandedFolders();
     QMapIterator<QString, QString> f(flist);
     while (f.hasNext()) {
         f.next();
-        (void) new FolderProjectItem(m_listView, QStringList() << f.value(), f.key());
+        FolderProjectItem *folder = new FolderProjectItem(m_listView, QStringList() << f.value(), f.key());
+        folder->setExpanded(openedFolders.contains(f.key()));
     }
 
     QList <DocClipBase*> list = doc->clipManager()->documentClipList();
-    for (int i = 0; i < list.count(); i++) {
+    if (list.isEmpty()) m_refreshed = true;
+    for (int i = 0; i < list.count(); i++)
         slotAddClip(list.at(i), false);
-    }
 
     m_listView->blockSignals(false);
-    m_toolbar->setEnabled(true);
     connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
+    connect(m_doc->clipManager(), SIGNAL(modifiedClip(const QString &)), this, SLOT(slotModifiedClip(const QString &)));
     connect(m_doc->clipManager(), SIGNAL(missingClip(const QString &)), this, SLOT(slotMissingClip(const QString &)));
     connect(m_doc->clipManager(), SIGNAL(availableClip(const QString &)), this, SLOT(slotAvailableClip(const QString &)));
-    connect(m_doc->clipManager(), SIGNAL(checkAllClips()), this, SLOT(updateAllClips()));
+    connect(m_doc->clipManager(), SIGNAL(checkAllClips(bool, bool)), this, SLOT(updateAllClips(bool, bool)));
 }
 
 QList <DocClipBase*> ProjectList::documentClipList() const
 {
-    if (m_doc == NULL) return QList <DocClipBase*> ();
+    if (m_doc == NULL)
+        return QList <DocClipBase*> ();
+
     return m_doc->clipManager()->documentClipList();
 }
 
@@ -1181,7 +1610,7 @@ QDomElement ProjectList::producersList()
     QDomDocument doc;
     QDomElement prods = doc.createElement("producerlist");
     doc.appendChild(prods);
-    kDebug() << "////////////  PRO LIST BUILD PRDSLIST ";
+    kDebug() << "////////////  PRO LIST BUILD PRDSLIST ";
     QTreeWidgetItemIterator it(m_listView);
     while (*it) {
         if ((*it)->type() != PROJECTCLIPTYPE) {
@@ -1197,60 +1626,47 @@ QDomElement ProjectList::producersList()
 
 void ProjectList::slotCheckForEmptyQueue()
 {
-    if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
-        m_refreshed = true;
-        emit loadingIsOver();
-        emit displayMessage(QString(), -1);
-        m_listView->blockSignals(false);
-        m_listView->setEnabled(true);
-        updateButtons();
-    } else if (!m_refreshed) QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
-}
-
-void ProjectList::reloadClipThumbnails()
-{
-    kDebug() << "//////////////  RELOAD CLIPS THUMBNAILS!!!";
-    m_thumbnailQueue.clear();
-    QTreeWidgetItemIterator it(m_listView);
-    while (*it) {
-        if ((*it)->type() != PROJECTCLIPTYPE) {
-            // subitem
-            ++it;
-            continue;
+    if (m_render->processingItems() == 0 && m_thumbnailQueue.isEmpty()) {
+        if (!m_refreshed) {
+            emit loadingIsOver();
+            emit displayMessage(QString(), -1);
+            m_refreshed = true;
         }
-        m_thumbnailQueue << ((ProjectItem *)(*it))->clipId();
-        ++it;
+        updateButtons();
+    } else if (!m_refreshed) {
+        QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
     }
-    QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
 }
 
+
 void ProjectList::requestClipThumbnail(const QString id)
 {
     if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id);
+    slotProcessNextThumbnail();
 }
 
 void ProjectList::slotProcessNextThumbnail()
 {
-    if (m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
-        slotCheckForEmptyQueue();
+    if (m_render->processingItems() > 0) {
         return;
     }
-    if (!m_infoQueue.isEmpty()) {
-        //QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
+    if (m_thumbnailQueue.isEmpty()) {
+        slotCheckForEmptyQueue();
         return;
     }
-    if (m_thumbnailQueue.count() > 1) {
-        int max = m_doc->clipManager()->clipsCount();
-        emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - m_thumbnailQueue.count()) / max));
-    }
+    int max = m_doc->clipManager()->clipsCount();
+    emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - m_thumbnailQueue.count()) / max));
     slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
 }
 
 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
 {
     QTreeWidgetItem *item = getAnyItemById(clipId);
-    if (item) slotRefreshClipThumbnail(item, update);
-    else slotProcessNextThumbnail();
+    if (item)
+        slotRefreshClipThumbnail(item, update);
+    else {
+        slotProcessNextThumbnail();
+    }
 }
 
 void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
@@ -1277,81 +1693,235 @@ void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
         }
         QPixmap pix;
         int height = m_listView->iconSize().height();
-        int width = (int)(height  * m_render->dar());
-        if (clip->clipType() == AUDIO) pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
-        else if (clip->clipType() == IMAGE) pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->producer(), 0, width, height));
-        else pix = item->referencedClip()->thumbProducer()->extractImage(frame, width, height);
+        int swidth = (int)(height  * m_render->frameRenderWidth() / m_render->renderHeight()+ 0.5);
+        int dwidth = (int)(height  * m_render->dar() + 0.5);
+        if (clip->clipType() == AUDIO)
+            pix = KIcon("audio-x-generic").pixmap(QSize(dwidth, height));
+        else if (clip->clipType() == IMAGE)
+            pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->getProducer(), 0, swidth, dwidth, height));
+        else {
+            pix = item->referencedClip()->extractImage(frame, dwidth, height);
+        }
 
         if (!pix.isNull()) {
-            m_listView->blockSignals(true);
+            monitorItemEditing(false);
             it->setData(0, Qt::DecorationRole, pix);
-            if (m_listView->isEnabled()) m_listView->blockSignals(false);
-            if (!isSubItem) m_doc->cachePixmap(item->getClipHash(), pix);
-            else m_doc->cachePixmap(item->getClipHash() + '#' + QString::number(frame), pix);
+            monitorItemEditing(true);
+                
+            if (!isSubItem)
+                m_doc->cachePixmap(item->getClipHash(), pix);
+            else
+                m_doc->cachePixmap(item->getClipHash() + '#' + QString::number(frame), pix);
         }
-        if (update) emit projectModified();
-        QTimer::singleShot(30, this, SLOT(slotProcessNextThumbnail()));
+        if (update)
+            emit projectModified();
+        slotProcessNextThumbnail();
     }
 }
 
-void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace)
+void ProjectList::slotRefreshMonitor()
+{
+    if (m_listView->selectedItems().count() == 1 && m_render && m_render->processingItems() == 0) {
+        if (m_listView->currentItem() && m_listView->currentItem()->type() != PROJECTFOLDERTYPE) {
+            ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
+            DocClipBase *clip = item->referencedClip();
+            if (clip && clip->isClean()) emit clipSelected(clip);
+        }
+    }
+}
+
+void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const stringMap &properties, const stringMap &metadata, bool replace, bool refreshThumbnail)
 {
     QString toReload;
     ProjectItem *item = getItemById(clipId);
+
+    int queue = m_render->processingItems();
+    if (queue == 0) {
+        m_listView->setEnabled(true);
+    }
     if (item && producer) {
-        m_listView->blockSignals(true);
+        monitorItemEditing(false);
+        DocClipBase *clip = item->referencedClip();
+        if (producer->is_valid()) {
+            if (clip->isPlaceHolder()) {
+                clip->setValid();
+                toReload = clipId;
+            }
+            item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
+        }
+        clip->setProducer(producer, replace);
         item->setProperties(properties, metadata);
-        if (item->referencedClip()->isPlaceHolder() && producer->is_valid()) {
-            item->referencedClip()->setValid();
-            item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
-            toReload = clipId;
-        }
-        //Q_ASSERT_X(item->referencedClip(), "void ProjectList::slotReplyGetFileProperties", QString("Item with groupName %1 does not have a clip associated").arg(item->groupName()).toLatin1());
-        item->referencedClip()->setProducer(producer, replace);
-        item->referencedClip()->askForAudioThumbs();
-        if (!replace && item->data(0, Qt::DecorationRole).isNull()) {
-            requestClipThumbnail(clipId);
+        clip->askForAudioThumbs();
+        if (refreshThumbnail) getCachedThumbnail(item);
+        // Proxy stuff
+        QString size = properties.value("frame_size");
+        if (!useProxy() && clip->getProperty("proxy").isEmpty()) setProxyStatus(item, NOPROXY);
+        if (useProxy() && generateProxy() && clip->getProperty("proxy") == "-") setProxyStatus(item, NOPROXY);
+        else if (useProxy() && !item->hasProxy() && !item->isProxyRunning()) {
+            // proxy video and image clips
+            int maxSize;
+            CLIPTYPE t = item->clipType();
+            if (t == IMAGE) maxSize = m_doc->getDocumentProperty("proxyimageminsize").toInt();
+            else maxSize = m_doc->getDocumentProperty("proxyminsize").toInt();
+            if ((((t == AV || t == VIDEO || t == PLAYLIST) && generateProxy()) || (t == IMAGE && generateImageProxy())) && (size.section('x', 0, 0).toInt() > maxSize || size.section('x', 1, 1).toInt() > maxSize)) {
+                if (clip->getProperty("proxy").isEmpty()) {
+                    KUrl proxyPath = m_doc->projectFolder();
+                    proxyPath.addPath("proxy/");
+                    proxyPath.addPath(clip->getClipHash() + "." + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension")));
+                    QMap <QString, QString> newProps;
+                    // insert required duration for proxy
+                    if (t != IMAGE) newProps.insert("proxy_out", clip->producerProperty("out"));
+                    newProps.insert("proxy", proxyPath.path());
+                    QMap <QString, QString> oldProps = clip->properties();
+                    oldProps.insert("proxy", QString());
+                    EditClipCommand *command = new EditClipCommand(this, clipId, oldProps, newProps, true);
+                    m_doc->commandStack()->push(command);
+                }
+            }
         }
-        if (!toReload.isEmpty()) {
-            item->slotSetToolTip();
 
-        }
-        //emit receivedClipDuration(clipId);
-        if (m_listView->isEnabled() && replace) {
-            // update clip in clip monitor
-            emit clipSelected(NULL);
-            emit clipSelected(item->referencedClip());
-            //TODO: Make sure the line below has no side effect
-            toReload = clipId;
-        }
-        /*else {
-            // Check if duration changed.
-            emit receivedClipDuration(clipId);
-            delete producer;
-        }*/
-        if (m_listView->isEnabled()) m_listView->blockSignals(false);
-        /*if (item->icon(0).isNull()) {
+        if (!replace && item->data(0, Qt::DecorationRole).isNull() && !refreshThumbnail) {
             requestClipThumbnail(clipId);
-        }*/
+        }
+        if (!toReload.isEmpty())
+            item->slotSetToolTip();
     } else kDebug() << "////////  COULD NOT FIND CLIP TO UPDATE PRPS...";
-    int max = m_doc->clipManager()->clipsCount();
-    if (item && m_infoQueue.isEmpty() && m_thumbnailQueue.isEmpty()) {
-        m_listView->setCurrentItem(item);
-        emit clipSelected(item->referencedClip());
-    } else emit displayMessage(i18n("Loading clips"), (int)(100 *(max - m_infoQueue.count()) / max));
-    if (!toReload.isEmpty()) emit clipNeedsReload(toReload, true);
-    // small delay so that the app can display the progress info
-    QTimer::singleShot(30, this, SLOT(slotProcessNextClipInQueue()));
+    if (queue == 0) {
+        monitorItemEditing(true);
+        if (item && m_thumbnailQueue.isEmpty()) {
+            m_listView->setCurrentItem(item);
+            bool updatedProfile = false;
+            if (item->parent()) {
+                if (item->parent()->type() == PROJECTFOLDERTYPE)
+                    static_cast <FolderProjectItem *>(item->parent())->switchIcon();
+            } else if (KdenliveSettings::checkfirstprojectclip() &&  m_listView->topLevelItemCount() == 1) {
+                // this is the first clip loaded in project, check if we want to adjust project settings to the clip
+                updatedProfile = adjustProjectProfileToItem(item);
+            }
+            if (updatedProfile == false) {
+                //emit clipSelected(item->referencedClip());
+            }
+        } else {
+            int max = m_doc->clipManager()->clipsCount();
+            emit displayMessage(i18n("Loading clips"), (int)(100 *(max - queue) / max));
+        }
+        processNextThumbnail();
+    }
+    if (replace && item) {
+        if (item->numReferences() > 0) toReload = clipId;
+        else item->referencedClip()->cleanupProducers();
+        // update clip in clip monitor
+        if (queue == 0 && item->isSelected() && m_listView->selectedItems().count() == 1)
+            m_refreshMonitorTimer.start();
+    }
+    if (!item) {
+        // no item for producer, delete it
+        delete producer;
+    }
+    if (!toReload.isEmpty())
+        emit clipNeedsReload(toReload, true);
+}
+
+bool ProjectList::adjustProjectProfileToItem(ProjectItem *item)
+{
+    if (item == NULL) {
+        if (m_listView->currentItem() && m_listView->currentItem()->type() != PROJECTFOLDERTYPE)
+            item = static_cast <ProjectItem*>(m_listView->currentItem());
+    }
+    if (item == NULL || item->referencedClip() == NULL) {
+        KMessageBox::information(kapp->activeWindow(), i18n("Cannot find profile from current clip"));
+        return false;
+    }
+    bool profileUpdated = false;
+    QString size = item->referencedClip()->getProperty("frame_size");
+    int width = size.section('x', 0, 0).toInt();
+    int height = size.section('x', -1).toInt();
+    double fps = item->referencedClip()->getProperty("fps").toDouble();
+    double par = item->referencedClip()->getProperty("aspect_ratio").toDouble();
+    if (item->clipType() == IMAGE || item->clipType() == AV || item->clipType() == VIDEO) {
+        if (ProfilesDialog::matchProfile(width, height, fps, par, item->clipType() == IMAGE, m_doc->mltProfile()) == false) {
+            // get a list of compatible profiles
+            QMap <QString, QString> suggestedProfiles = ProfilesDialog::getProfilesFromProperties(width, height, fps, par, item->clipType() == IMAGE);
+            if (!suggestedProfiles.isEmpty()) {
+                KDialog *dialog = new KDialog(this);
+                dialog->setCaption(i18n("Change project profile"));
+                dialog->setButtons(KDialog::Ok | KDialog::Cancel);
+
+                QWidget container;
+                QVBoxLayout *l = new QVBoxLayout;
+                QLabel *label = new QLabel(i18n("Your clip does not match current project's profile.\nDo you want to change the project profile?\n\nThe following profiles match the clip (size: %1, fps: %2)", size, fps));
+                l->addWidget(label);
+                QListWidget *list = new QListWidget;
+                list->setAlternatingRowColors(true);
+                QMapIterator<QString, QString> i(suggestedProfiles);
+                while (i.hasNext()) {
+                    i.next();
+                    QListWidgetItem *item = new QListWidgetItem(i.value(), list);
+                    item->setData(Qt::UserRole, i.key());
+                    item->setToolTip(i.key());
+                }
+                list->setCurrentRow(0);
+                l->addWidget(list);
+                container.setLayout(l);
+                dialog->setButtonText(KDialog::Ok, i18n("Update profile"));
+                dialog->setMainWidget(&container);
+                if (dialog->exec() == QDialog::Accepted) {
+                    //Change project profile
+                    profileUpdated = true;
+                    if (list->currentItem())
+                        emit updateProfile(list->currentItem()->data(Qt::UserRole).toString());
+                }
+                delete list;
+                delete label;
+            } else if (fps > 0) {
+                KMessageBox::information(kapp->activeWindow(), 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", size, fps));
+            }
+        }
+    }
+    return profileUpdated;
+}
+
+QString ProjectList::getDocumentProperty(const QString &key) const
+{
+    return m_doc->getDocumentProperty(key);
+}
+
+bool ProjectList::useProxy() const
+{
+    return m_doc->getDocumentProperty("enableproxy").toInt();
+}
+
+bool ProjectList::generateProxy() const
+{
+    return m_doc->getDocumentProperty("generateproxy").toInt();
 }
 
-void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
+bool ProjectList::generateImageProxy() const
+{
+    return m_doc->getDocumentProperty("generateimageproxy").toInt();
+}
+
+void ProjectList::slotReplyGetImage(const QString &clipId, const QImage &img)
+{
+    QPixmap pix = QPixmap::fromImage(img);
+    setThumbnail(clipId, pix);
+}
+
+void ProjectList::slotReplyGetImage(const QString &clipId, const QString &name, int width, int height)
+{
+    QPixmap pix =  KIcon(name).pixmap(QSize(width, height));
+    setThumbnail(clipId, pix);
+}
+
+void ProjectList::setThumbnail(const QString &clipId, const QPixmap &pix)
 {
     ProjectItem *item = getItemById(clipId);
     if (item && !pix.isNull()) {
-        m_listView->blockSignals(true);
+        monitorItemEditing(false);
         item->setData(0, Qt::DecorationRole, pix);
+        monitorItemEditing(true);
+        //update();
         m_doc->cachePixmap(item->getClipHash(), pix);
-        if (m_listView->isEnabled()) m_listView->blockSignals(false);
     }
 }
 
@@ -1359,9 +1929,8 @@ QTreeWidgetItem *ProjectList::getAnyItemById(const QString &id)
 {
     QTreeWidgetItemIterator it(m_listView);
     QString lookId = id;
-    if (id.contains('#')) {
+    if (id.contains('#'))
         lookId = id.section('#', 0, 0);
-    }
 
     ProjectItem *result = NULL;
     while (*it) {
@@ -1377,13 +1946,15 @@ QTreeWidgetItem *ProjectList::getAnyItemById(const QString &id)
         }
         ++it;
     }
-    if (result == NULL || !id.contains('#')) return result;
-    else for (int i = 0; i < result->childCount(); i++) {
+    if (result == NULL || !id.contains('#')) {
+        return result;
+    } else {
+        for (int i = 0; i < result->childCount(); i++) {
             SubProjectItem *sub = static_cast <SubProjectItem *>(result->child(i));
-            if (sub && sub->zone().x() == id.section('#', 1, 1).toInt()) {
+            if (sub && sub->zone().x() == id.section('#', 1, 1).toInt())
                 return sub;
-            }
         }
+    }
 
     return NULL;
 }
@@ -1395,7 +1966,7 @@ ProjectItem *ProjectList::getItemById(const QString &id)
     QTreeWidgetItemIterator it(m_listView);
     while (*it) {
         if ((*it)->type() != PROJECTCLIPTYPE) {
-            // subitem
+            // subitem or folder
             ++it;
             continue;
         }
@@ -1414,7 +1985,8 @@ FolderProjectItem *ProjectList::getFolderItemById(const QString &id)
     while (*it) {
         if ((*it)->type() == PROJECTFOLDERTYPE) {
             item = static_cast<FolderProjectItem *>(*it);
-            if (item->clipId() == id) return item;
+            if (item->clipId() == id)
+                return item;
         }
         ++it;
     }
@@ -1427,8 +1999,8 @@ void ProjectList::slotSelectClip(const QString &ix)
     if (clip) {
         m_listView->setCurrentItem(clip);
         m_listView->scrollToItem(clip);
-        m_editAction->setEnabled(true);
-        m_deleteAction->setEnabled(true);
+        m_editButton->defaultAction()->setEnabled(true);
+        m_deleteButton->defaultAction()->setEnabled(true);
         m_reloadAction->setEnabled(true);
         m_transcodeAction->setEnabled(true);
         if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
@@ -1437,7 +2009,9 @@ void ProjectList::slotSelectClip(const QString &ix)
         } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
             m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
             m_openAction->setEnabled(true);
-        } else m_openAction->setEnabled(false);
+        } else {
+            m_openAction->setEnabled(false);
+        }
     }
 }
 
@@ -1448,8 +2022,11 @@ QString ProjectList::currentClipUrl() const
     if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
         // subitem
         item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
-    } else item = static_cast <ProjectItem*>(m_listView->currentItem());
-    if (item == NULL) return QString();
+    } else {
+        item = static_cast <ProjectItem*>(m_listView->currentItem());
+    }
+    if (item == NULL)
+        return QString();
     return item->clipUrl().path();
 }
 
@@ -1459,17 +2036,22 @@ KUrl::List ProjectList::getConditionalUrls(const QString &condition) const
     ProjectItem *item;
     QList<QTreeWidgetItem *> list = m_listView->selectedItems();
     for (int i = 0; i < list.count(); i++) {
-        if (list.at(i)->type() == PROJECTFOLDERTYPE) continue;
+        if (list.at(i)->type() == PROJECTFOLDERTYPE)
+            continue;
         if (list.at(i)->type() == PROJECTSUBCLIPTYPE) {
             // subitem
             item = static_cast <ProjectItem*>(list.at(i)->parent());
-        } else item = static_cast <ProjectItem*>(list.at(i));
-        if (item == NULL) continue;
-        if (item->type() == COLOR || item->type() == SLIDESHOW || item->type() == TEXT) continue;
+        } else {
+            item = static_cast <ProjectItem*>(list.at(i));
+        }
+        if (item == NULL || item->type() == COLOR || item->type() == SLIDESHOW || item->type() == TEXT)
+            continue;
         DocClipBase *clip = item->referencedClip();
         if (!condition.isEmpty()) {
-            if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section("=", 1, 1))) continue;
-            else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section("=", 1, 1))) continue;
+            if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section('=', 1, 1)))
+                continue;
+            else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section('=', 1, 1)))
+                continue;
         }
         result.append(item->clipUrl());
     }
@@ -1479,13 +2061,14 @@ KUrl::List ProjectList::getConditionalUrls(const QString &condition) const
 void ProjectList::regenerateTemplate(const QString &id)
 {
     ProjectItem *clip = getItemById(id);
-    if (clip) regenerateTemplate(clip);
+    if (clip)
+        regenerateTemplate(clip);
 }
 
 void ProjectList::regenerateTemplate(ProjectItem *clip)
 {
     //TODO: remove this unused method, only force_reload is necessary
-    clip->referencedClip()->producer()->set("force_reload", 1);
+    clip->referencedClip()->getProducer()->set("force_reload", 1);
 }
 
 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
@@ -1515,8 +2098,8 @@ QDomDocument ProjectList::generateTemplateXml(QString path, const QString &repla
 void ProjectList::slotAddClipCut(const QString &id, int in, int out)
 {
     ProjectItem *clip = getItemById(id);
-    if (clip == NULL) return;
-    if (clip->referencedClip()->hasCutZone(QPoint(in, out))) return;
+    if (clip == NULL || clip->referencedClip()->hasCutZone(QPoint(in, out)))
+        return;
     AddClipCutCommand *command = new AddClipCutCommand(this, id, in, out, QString(), true, false);
     m_commandStack->push(command);
 }
@@ -1527,17 +2110,18 @@ void ProjectList::addClipCut(const QString &id, int in, int out, const QString d
     if (clip) {
         DocClipBase *base = clip->referencedClip();
         base->addCutZone(in, out);
-        m_listView->blockSignals(true);
+        monitorItemEditing(false);
         SubProjectItem *sub = new SubProjectItem(clip, in, out, desc);
         if (newItem && desc.isEmpty() && !m_listView->isColumnHidden(1)) {
-            if (!clip->isExpanded()) clip->setExpanded(true);
-           m_listView->scrollToItem(sub);
+            if (!clip->isExpanded())
+                clip->setExpanded(true);
+            m_listView->scrollToItem(sub);
             m_listView->editItem(sub, 1);
         }
-        QPixmap p = clip->referencedClip()->thumbProducer()->extractImage(in, (int)(sub->sizeHint(0).height()  * m_render->dar()), sub->sizeHint(0).height() - 2);
+        QPixmap p = clip->referencedClip()->extractImage(in, (int)(sub->sizeHint(0).height()  * m_render->dar()), sub->sizeHint(0).height() - 2);
         sub->setData(0, Qt::DecorationRole, p);
         m_doc->cachePixmap(clip->getClipHash() + '#' + QString::number(in), p);
-        m_listView->blockSignals(false);
+        monitorItemEditing(true);
     }
     emit projectModified();
 }
@@ -1550,9 +2134,9 @@ void ProjectList::removeClipCut(const QString &id, int in, int out)
         base->removeCutZone(in, out);
         SubProjectItem *sub = getSubItem(clip, QPoint(in, out));
         if (sub) {
-            m_listView->blockSignals(true);
+            monitorItemEditing(false);
             delete sub;
-            m_listView->blockSignals(false);
+            monitorItemEditing(true);
         }
     }
     emit projectModified();
@@ -1566,8 +2150,10 @@ SubProjectItem *ProjectList::getSubItem(ProjectItem *clip, QPoint zone)
             QTreeWidgetItem *it = clip->child(i);
             if (it->type() == PROJECTSUBCLIPTYPE) {
                 sub = static_cast <SubProjectItem*>(it);
-                if (sub->zone() == zone) break;
-                else sub = NULL;
+                if (sub->zone() == zone)
+                    break;
+                else
+                    sub = NULL;
             }
         }
     }
@@ -1576,7 +2162,8 @@ SubProjectItem *ProjectList::getSubItem(ProjectItem *clip, QPoint zone)
 
 void ProjectList::slotUpdateClipCut(QPoint p)
 {
-    if (!m_listView->currentItem() || m_listView->currentItem()->type() != PROJECTSUBCLIPTYPE) return;
+    if (!m_listView->currentItem() || m_listView->currentItem()->type() != PROJECTSUBCLIPTYPE)
+        return;
     SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
     ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
     EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), p, sub->text(1), sub->text(1), true);
@@ -1587,14 +2174,527 @@ void ProjectList::doUpdateClipCut(const QString &id, const QPoint oldzone, const
 {
     ProjectItem *clip = getItemById(id);
     SubProjectItem *sub = getSubItem(clip, oldzone);
-    if (sub == NULL || clip == NULL) return;
+    if (sub == NULL || clip == NULL)
+        return;
     DocClipBase *base = clip->referencedClip();
     base->updateCutZone(oldzone.x(), oldzone.y(), zone.x(), zone.y(), comment);
-    m_listView->blockSignals(true);
+    monitorItemEditing(false);
     sub->setZone(zone);
     sub->setDescription(comment);
-    m_listView->blockSignals(false);
+    monitorItemEditing(true);
+    emit projectModified();
+}
+
+void ProjectList::slotForceProcessing(const QString &id)
+{
+    m_render->forceProcessing(id);
+}
+
+void ProjectList::slotAddOrUpdateSequence(const QString frameName)
+{
+    QString fileName = KUrl(frameName).fileName().section('_', 0, -2);
+    QStringList list;
+    QString pattern = SlideshowClip::selectedPath(frameName, false, QString(), &list);
+    int count = list.count();
+    if (count > 1) {
+        const QList <DocClipBase *> existing = m_doc->clipManager()->getClipByResource(pattern);
+        if (!existing.isEmpty()) {
+            // Sequence already exists, update
+            QString id = existing.at(0)->getId();
+            //ProjectItem *item = getItemById(id);
+            QMap <QString, QString> oldprops;
+            QMap <QString, QString> newprops;
+            int ttl = existing.at(0)->getProperty("ttl").toInt();
+            oldprops["out"] = existing.at(0)->getProperty("out");
+            newprops["out"] = QString::number(ttl * count - 1);
+            slotUpdateClipProperties(id, newprops);
+            EditClipCommand *command = new EditClipCommand(this, id, oldprops, newprops, false);
+            m_commandStack->push(command);
+        } else {
+            // Create sequence
+            QStringList groupInfo = getGroup();
+            m_doc->slotCreateSlideshowClipFile(fileName, pattern, count, m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()),
+                                               false, false, false,
+                                               m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))), QString(), 0,
+                                               QString(), groupInfo.at(0), groupInfo.at(1));
+        }
+    } else emit displayMessage(i18n("Sequence not found"), -2);
+}
+
+QMap <QString, QString> ProjectList::getProxies()
+{
+    QMap <QString, QString> list;
+    ProjectItem *item;
+    QTreeWidgetItemIterator it(m_listView);
+    while (*it) {
+        if ((*it)->type() != PROJECTCLIPTYPE) {
+            ++it;
+            continue;
+        }
+        item = static_cast<ProjectItem *>(*it);
+        if (item && item->referencedClip() != NULL) {
+            if (item->hasProxy()) {
+                QString proxy = item->referencedClip()->getProperty("proxy");
+                list.insert(proxy, item->clipUrl().path());
+            }
+        }
+        ++it;
+    }
+    return list;
+}
+
+void ProjectList::slotCreateProxy(const QString id)
+{
+    ProjectItem *item = getItemById(id);
+    if (!item || item->isProxyRunning() || item->referencedClip()->isPlaceHolder()) return;
+    QString path = item->referencedClip()->getProperty("proxy");
+    if (path.isEmpty()) {
+        setProxyStatus(path, PROXYCRASHED);
+        return;
+    }
+    setProxyStatus(path, PROXYWAITING);
+    if (m_abortProxy.contains(path)) m_abortProxy.removeAll(path);
+    if (m_processingProxy.contains(path)) {
+        // Proxy is already being generated
+        return;
+    }
+    if (QFile::exists(path)) {
+        // Proxy already created
+        setProxyStatus(path, PROXYDONE);
+        slotGotProxy(path);
+        return;
+    }
+    m_processingProxy.append(path);
+
+    PROXYINFO info;
+    info.dest = path;
+    info.src = item->clipUrl().path();
+    info.type = item->clipType();
+    info.exif = QString(item->referencedClip()->producerProperty("_exif_orientation")).toInt();
+    m_proxyList.append(info);
+    m_proxyThreads.addFuture(QtConcurrent::run(this, &ProjectList::slotGenerateProxy));
+}
+
+void ProjectList::slotAbortProxy(const QString id, const QString path)
+{
+    QTreeWidgetItemIterator it(m_listView);
+    ProjectItem *item = getItemById(id);
+    setProxyStatus(item, NOPROXY);
+    slotGotProxy(item);
+    if (!path.isEmpty() && m_processingProxy.contains(path)) {
+        m_abortProxy << path;
+        setProxyStatus(path, NOPROXY);
+    }
+}
+
+void ProjectList::slotGenerateProxy()
+{
+    if (m_proxyList.isEmpty() || m_abortAllProxies) return;
     emit projectModified();
+    PROXYINFO info = m_proxyList.takeFirst();
+    if (m_abortProxy.contains(info.dest)) {
+        m_abortProxy.removeAll(info.dest);
+        return;
+    }
+
+    // Make sure proxy path is writable
+    QFile file(info.dest);
+    if (!file.open(QIODevice::WriteOnly)) {
+        setProxyStatus(info.dest, PROXYCRASHED);
+        m_processingProxy.removeAll(info.dest);
+        return;
+    }
+    file.close();
+    QFile::remove(info.dest);
+    
+    setProxyStatus(info.dest, CREATINGPROXY);
+
+    // Special case: playlist clips (.mlt or .kdenlive project files)
+    if (info.type == PLAYLIST) {
+        // change FFmpeg params to MLT format
+        QStringList parameters;
+        parameters << info.src;
+        parameters << "-consumer" << "avformat:" + info.dest;
+        QStringList params = m_doc->getDocumentProperty("proxyparams").simplified().split('-', QString::SkipEmptyParts);
+        
+        foreach(QString s, params) {
+            s = s.simplified();
+            if (s.count(' ') == 0) {
+                s.append("=1");
+            }
+            else s.replace(' ', '=');
+            parameters << s;
+        }
+        
+        parameters.append(QString("real_time=-%1").arg(KdenliveSettings::mltthreads()));
+
+        //TODO: currently, when rendering an xml file through melt, the display ration is lost, so we enforce it manualy
+        double display_ratio = KdenliveDoc::getDisplayRatio(info.src);
+        parameters << "aspect=" + QString::number(display_ratio);
+
+        //kDebug()<<"TRANSCOD: "<<parameters;
+        QProcess myProcess;
+        myProcess.setProcessChannelMode(QProcess::MergedChannels);
+        myProcess.start(KdenliveSettings::rendererpath(), parameters);
+        myProcess.waitForStarted();
+        int result = -1;
+        int duration = 0;
+        while (myProcess.state() != QProcess::NotRunning) {
+            // building proxy file
+            if (m_abortProxy.contains(info.dest) || m_abortAllProxies) {
+                myProcess.close();
+                myProcess.waitForFinished();
+                QFile::remove(info.dest);
+                m_abortProxy.removeAll(info.dest);
+                m_processingProxy.removeAll(info.dest);
+                setProxyStatus(info.dest, NOPROXY);
+                result = -2;
+            }
+            else {
+                QString log = QString(myProcess.readAll());
+                processLogInfo(info.dest, &duration, log);
+            }
+            myProcess.waitForFinished(500);
+        }
+        myProcess.waitForFinished();
+        m_processingProxy.removeAll(info.dest);
+        if (result == -1) result = myProcess.exitStatus();
+        if (result == 0) {
+            // proxy successfully created
+            setProxyStatus(info.dest, PROXYDONE);
+            slotGotProxy(info.dest);
+        }
+        else if (result == 1) {
+            // Proxy process crashed
+            QFile::remove(info.dest);
+            setProxyStatus(info.dest, PROXYCRASHED);
+        }   
+
+    }
+    
+    if (info.type == IMAGE) {
+        // Image proxy
+        QImage i(info.src);
+        if (i.isNull()) {
+            // Cannot load image
+            setProxyStatus(info.dest, PROXYCRASHED);
+            return;
+        }
+        QImage proxy;
+        // Images are scaled to profile size. 
+        //TODO: Make it be configurable?
+        if (i.width() > i.height()) proxy = i.scaledToWidth(m_render->frameRenderWidth());
+        else proxy = i.scaledToHeight(m_render->renderHeight());
+        if (info.exif > 1) {
+            // Rotate image according to exif data
+            QImage processed;
+            QMatrix matrix;
+
+            switch ( info.exif ) {
+                case 2:
+                  matrix.scale( -1, 1 );
+                  break;
+                case 3:
+                  matrix.rotate( 180 );
+                  break;
+                case 4:
+                  matrix.scale( 1, -1 );
+                  break;
+                case 5:
+                  matrix.rotate( 270 );
+                  matrix.scale( -1, 1 );
+                  break;
+                case 6:
+                  matrix.rotate( 90 );
+                  break;
+                case 7:
+                  matrix.rotate( 90 );
+                  matrix.scale( -1, 1 );
+                  break;
+                case 8:
+                  matrix.rotate( 270 );
+                  break;
+              }
+              processed = proxy.transformed( matrix );
+              processed.save(info.dest);
+        }
+        else proxy.save(info.dest);
+        setProxyStatus(info.dest, PROXYDONE);
+        slotGotProxy(info.dest);
+        m_abortProxy.removeAll(info.dest);
+        m_processingProxy.removeAll(info.dest);
+        return;
+    }
+
+    QStringList parameters;
+    parameters << "-i" << info.src;
+    QString params = m_doc->getDocumentProperty("proxyparams").simplified();
+    foreach(QString s, params.split(' '))
+    parameters << s;
+
+    // Make sure we don't block when proxy file already exists
+    parameters << "-y";
+    parameters << info.dest;
+    kDebug()<<"// STARTING PROXY GEN: "<<parameters;
+    QProcess myProcess;
+    myProcess.setProcessChannelMode(QProcess::MergedChannels);
+    myProcess.start("ffmpeg", parameters);
+    myProcess.waitForStarted();
+    int result = -1;
+    int duration = 0;
+    while (myProcess.state() != QProcess::NotRunning) {
+        // building proxy file
+        if (m_abortProxy.contains(info.dest) || m_abortAllProxies) {
+            myProcess.close();
+            myProcess.waitForFinished();
+            m_abortProxy.removeAll(info.dest);
+            m_processingProxy.removeAll(info.dest);
+            QFile::remove(info.dest);
+            setProxyStatus(info.dest, NOPROXY);
+            result = -2;
+            
+        }
+        else {
+            QString log = QString(myProcess.readAll());
+            processLogInfo(info.dest, &duration, log);
+        }
+        myProcess.waitForFinished(500);
+    }
+    myProcess.waitForFinished();
+    if (result == -1) result = myProcess.exitStatus();
+    if (result == 0) {
+        // proxy successfully created
+        setProxyStatus(info.dest, PROXYDONE);
+        slotGotProxy(info.dest);
+    }
+    else if (result == 1) {
+        // Proxy process crashed
+        QFile::remove(info.dest);
+        setProxyStatus(info.dest, PROXYCRASHED);
+    }
+    m_abortProxy.removeAll(info.dest);
+    m_processingProxy.removeAll(info.dest);
+}
+
+
+void ProjectList::processLogInfo(const QString &path, int *duration, const QString &log)
+{
+    int progress;
+    if (*duration == 0) {
+        if (log.contains("Duration:")) {
+            QString data = log.section("Duration:", 1, 1).section(',', 0, 0).simplified();
+            QStringList numbers = data.split(':');
+            *duration = (int) (numbers.at(0).toInt() * 3600 + numbers.at(1).toInt() * 60 + numbers.at(2).toDouble());
+        }
+    }
+    else if (log.contains("time=")) {
+        QString time = log.section("time=", 1, 1).simplified().section(' ', 0, 0);
+        if (time.contains(':')) {
+            QStringList numbers = time.split(':');
+            progress = numbers.at(0).toInt() * 3600 + numbers.at(1).toInt() * 60 + numbers.at(2).toDouble();
+        }
+        else progress = (int) time.toDouble();
+        setProxyStatus(path, CREATINGPROXY, (int) (100.0 * progress / (*duration)));
+    }
+}
+
+void ProjectList::updateProxyConfig()
+{
+    ProjectItem *item;
+    QTreeWidgetItemIterator it(m_listView);
+    QUndoCommand *command = new QUndoCommand();
+    command->setText(i18n("Update proxy settings"));
+    QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/";
+    while (*it) {
+        if ((*it)->type() != PROJECTCLIPTYPE) {
+            ++it;
+            continue;
+        }
+        item = static_cast<ProjectItem *>(*it);
+        if (item == NULL) {
+            ++it;
+            continue;
+        }
+        CLIPTYPE t = item->clipType();
+        if ((t == VIDEO || t == AV || t == UNKNOWN) && item->referencedClip() != NULL) {
+            if  (generateProxy() && useProxy() && !item->isProxyRunning()) {
+                DocClipBase *clip = item->referencedClip();
+                if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > m_doc->getDocumentProperty("proxyminsize").toInt()) {
+                    if (clip->getProperty("proxy").isEmpty()) {
+                        // We need to insert empty proxy in old properties so that undo will work
+                        QMap <QString, QString> oldProps;// = clip->properties();
+                        oldProps.insert("proxy", QString());
+                        QMap <QString, QString> newProps;
+                        newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + "." + m_doc->getDocumentProperty("proxyextension"));
+                        new EditClipCommand(this, clip->getId(), oldProps, newProps, true, command);
+                    }
+                }
+            }
+            else if (item->hasProxy()) {
+                // remove proxy
+                QMap <QString, QString> newProps;
+                newProps.insert("proxy", QString());
+                newProps.insert("replace", "1");
+                // insert required duration for proxy
+                newProps.insert("proxy_out", item->referencedClip()->producerProperty("out"));
+                new EditClipCommand(this, item->clipId(), item->referencedClip()->properties(), newProps, true, command);
+            }
+        }
+        else if (t == IMAGE && item->referencedClip() != NULL) {
+            if  (generateImageProxy() && useProxy()) {
+                DocClipBase *clip = item->referencedClip();
+                int maxImageSize = m_doc->getDocumentProperty("proxyimageminsize").toInt();
+                if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > maxImageSize || clip->getProperty("frame_size").section('x', 1, 1).toInt() > maxImageSize) {
+                    if (clip->getProperty("proxy").isEmpty()) {
+                        // We need to insert empty proxy in old properties so that undo will work
+                        QMap <QString, QString> oldProps = clip->properties();
+                        oldProps.insert("proxy", QString());
+                        QMap <QString, QString> newProps;
+                        newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + ".png");
+                        new EditClipCommand(this, clip->getId(), oldProps, newProps, true, command);
+                    }
+                }
+            }
+            else if (item->hasProxy()) {
+                // remove proxy
+                QMap <QString, QString> newProps;
+                newProps.insert("proxy", QString());
+                newProps.insert("replace", "1");
+                new EditClipCommand(this, item->clipId(), item->referencedClip()->properties(), newProps, true, command);
+            }
+        }
+        ++it;
+    }
+    if (command->childCount() > 0) m_doc->commandStack()->push(command);
+    else delete command;
+}
+
+void ProjectList::slotProxyCurrentItem(bool doProxy)
+{
+    QList<QTreeWidgetItem *> list = m_listView->selectedItems();
+    QTreeWidgetItem *listItem;
+    QUndoCommand *command = new QUndoCommand();
+    if (doProxy) command->setText(i18np("Add proxy clip", "Add proxy clips", list.count()));
+    else command->setText(i18np("Remove proxy clip", "Remove proxy clips", list.count()));
+    
+    // Make sure the proxy folder exists
+    QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/";
+    KStandardDirs::makeDir(proxydir);
+                
+    QMap <QString, QString> newProps;
+    QMap <QString, QString> oldProps;
+    if (!doProxy) newProps.insert("proxy", "-");
+    for (int i = 0; i < list.count(); i++) {
+        listItem = list.at(i);
+        if (listItem->type() == PROJECTFOLDERTYPE) {
+            for (int j = 0; j < listItem->childCount(); j++) {
+                QTreeWidgetItem *sub = listItem->child(j);
+                if (!list.contains(sub)) list.append(sub);
+            }
+        }
+        else if (listItem->type() == PROJECTSUBCLIPTYPE) {
+            QTreeWidgetItem *sub = listItem->parent();
+            if (!list.contains(sub)) list.append(sub);
+        }
+        else if (listItem->type() == PROJECTCLIPTYPE) {
+            ProjectItem *item = static_cast <ProjectItem*>(listItem);
+            CLIPTYPE t = item->clipType();
+            if ((t == VIDEO || t == AV || t == UNKNOWN || t == IMAGE || t == PLAYLIST) && item->referencedClip()) {
+                if ((doProxy && item->hasProxy()) || (!doProxy && !item->hasProxy())) continue;
+                oldProps = item->referencedClip()->properties();
+                if (doProxy) {
+                    newProps.clear();
+                    QString path = proxydir + item->referencedClip()->getClipHash() + "." + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension"));
+                    // insert required duration for proxy
+                    newProps.insert("proxy_out", item->referencedClip()->producerProperty("out"));
+                    newProps.insert("proxy", path);
+                    // We need to insert empty proxy so that undo will work
+                    oldProps.insert("proxy", QString());
+                }
+                new EditClipCommand(this, item->clipId(), oldProps, newProps, true, command);
+            }
+        }
+    }
+    if (command->childCount() > 0) {
+        m_doc->commandStack()->push(command);
+    }
+    else delete command;
+}
+
+
+void ProjectList::slotDeleteProxy(const QString proxyPath)
+{
+    if (proxyPath.isEmpty()) return;
+    QUndoCommand *proxyCommand = new QUndoCommand();
+    proxyCommand->setText(i18n("Remove Proxy"));
+    QTreeWidgetItemIterator it(m_listView);
+    ProjectItem *item;
+    while (*it) {
+        if ((*it)->type() == PROJECTCLIPTYPE) {
+            item = static_cast <ProjectItem *>(*it);
+            if (item->referencedClip()->getProperty("proxy") == proxyPath) {
+                QMap <QString, QString> props;
+                props.insert("proxy", QString());
+                new EditClipCommand(this, item->clipId(), item->referencedClip()->properties(), props, true, proxyCommand);
+            
+            }
+        }
+        ++it;
+    }
+    if (proxyCommand->childCount() == 0)
+        delete proxyCommand;
+    else
+        m_commandStack->push(proxyCommand);
+    QFile::remove(proxyPath);
+}
+
+void ProjectList::setProxyStatus(const QString proxyPath, PROXYSTATUS status, int progress)
+{
+    if (proxyPath.isEmpty() || m_abortAllProxies) return;
+    QTreeWidgetItemIterator it(m_listView);
+    ProjectItem *item;
+    while (*it) {
+        if ((*it)->type() == PROJECTCLIPTYPE) {
+            item = static_cast <ProjectItem *>(*it);
+            if (item->referencedClip()->getProperty("proxy") == proxyPath) {
+                setProxyStatus(item, status, progress);
+            }
+        }
+        ++it;
+    }
+}
+
+void ProjectList::setProxyStatus(ProjectItem *item, PROXYSTATUS status, int progress)
+{
+    if (item == NULL) return;
+    monitorItemEditing(false);
+    item->setProxyStatus(status, progress);
+    monitorItemEditing(true);
+}
+
+void ProjectList::monitorItemEditing(bool enable)
+{
+    if (enable) connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));     
+    else disconnect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));     
+}
+
+QStringList ProjectList::expandedFolders() const
+{
+    QStringList result;
+    FolderProjectItem *item;
+    QTreeWidgetItemIterator it(m_listView);
+    while (*it) {
+        if ((*it)->type() != PROJECTFOLDERTYPE) {
+            ++it;
+            continue;
+        }
+        if ((*it)->isExpanded()) {
+            item = static_cast<FolderProjectItem *>(*it);
+            result.append(item->clipId());
+        }
+        ++it;
+    }
+    return result;
 }
 
 #include "projectlist.moc"