projectlist.cpp 92.2 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/***************************************************************************
 *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
 ***************************************************************************/

Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
20
21
#include "projectlist.h"
#include "projectitem.h"
22
#include "addfoldercommand.h"
23
#include "kdenlivesettings.h"
24
#include "slideshowclip.h"
25
#include "ui_colorclip_ui.h"
26
#include "titlewidget.h"
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
27
#include "definitions.h"
28
#include "clipmanager.h"
29
30
31
#include "docclipbase.h"
#include "kdenlivedoc.h"
#include "renderer.h"
32
#include "kthumb.h"
33
#include "projectlistview.h"
Till Theato's avatar
Till Theato committed
34
#include "timecodedisplay.h"
35
#include "profilesdialog.h"
36
#include "editclipcommand.h"
37
#include "editclipcutcommand.h"
38
#include "editfoldercommand.h"
39
40
#include "addclipcutcommand.h"

41
#include "ui_templateclip_ui.h"
42
43
44
45
46
47
48

#include <KDebug>
#include <KAction>
#include <KLocale>
#include <KFileDialog>
#include <KInputDialog>
#include <KMessageBox>
49
50
#include <KIO/NetAccess>
#include <KFileItem>
51
#include <KApplication>
52
53
#include <KStandardDirs>

Marco Gittler's avatar
Marco Gittler committed
54
#ifdef NEPOMUK
55
56
57
#include <nepomuk/global.h>
#include <nepomuk/resourcemanager.h>
//#include <nepomuk/tag.h>
Marco Gittler's avatar
Marco Gittler committed
58
#endif
59
60
61
62
63
64
65

#include <QMouseEvent>
#include <QStylePainter>
#include <QPixmap>
#include <QIcon>
#include <QMenu>
#include <QProcess>
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
66
#include <QHeaderView>
67
#include <QInputDialog>
68
#include <QtConcurrentRun>
69

70
ProjectList::ProjectList(QWidget *parent) :
71
72
73
74
75
76
77
78
79
80
81
    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_infoQueue(),
    m_thumbnailQueue()
82
{
83
    QVBoxLayout *layout = new QVBoxLayout;
84
    layout->setContentsMargins(0, 0, 0, 0);
85
    layout->setSpacing(0);
86
    qRegisterMetaType<QDomElement>("QDomElement");
87
    // setup toolbar
88
89
90
91
92
93
    QFrame *frame = new QFrame;
    frame->setFrameStyle(QFrame::NoFrame);
    QHBoxLayout *box = new QHBoxLayout;
    KTreeWidgetSearchLine *searchView = new KTreeWidgetSearchLine;

    box->addWidget(searchView);
94
    //int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
95
    //m_toolbar->setIconSize(QSize(s, s));
96

97
    m_addButton = new QToolButton;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
98
    m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
99
100
    m_addButton->setAutoRaise(true);
    box->addWidget(m_addButton);
101

102
103
104
105
106
107
108
109
110
111
112
    m_editButton = new QToolButton;
    m_editButton->setAutoRaise(true);
    box->addWidget(m_editButton);

    m_deleteButton = new QToolButton;
    m_deleteButton->setAutoRaise(true);
    box->addWidget(m_deleteButton);
    frame->setLayout(box);
    layout->addWidget(frame);

    m_listView = new ProjectListView;
113
    layout->addWidget(m_listView);
114
    setLayout(layout);
115
    searchView->setTreeWidget(m_listView);
116

117
118
119
120
    m_proxyAction = new QAction(i18n("Proxy clip"), this);
    m_proxyAction->setCheckable(true);
    m_proxyAction->setChecked(false);
    connect(m_proxyAction, SIGNAL(toggled(bool)), this, SLOT(slotProxyCurrentItem(bool)));
121
    connect(this, SIGNAL(processNextThumbnail()), this, SLOT(slotProcessNextThumbnail()));
122
    connect(m_listView, SIGNAL(projectModified()), this, SIGNAL(projectModified()));
123
124
125
126
127
    connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
    connect(m_listView, SIGNAL(focusMonitor()), this, SLOT(slotClipSelected()));
    connect(m_listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
    connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
    connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
128
    connect(m_listView, SIGNAL(addClip(const QList <QUrl>, const QString &, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &, const QString &)));
129
    connect(m_listView, SIGNAL(addClipCut(const QString &, int, int)), this, SLOT(slotAddClipCut(const QString &, int, int)));
130
131
    connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
    connect(m_listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
132

133
134
    m_listViewDelegate = new ItemDelegate(m_listView);
    m_listView->setItemDelegate(m_listViewDelegate);
Marco Gittler's avatar
Marco Gittler committed
135
#ifdef NEPOMUK
136
    if (KdenliveSettings::activate_nepomuk()) {
137
        Nepomuk::ResourceManager::instance()->init();
138
        if (!Nepomuk::ResourceManager::instance()->initialized()) {
139
140
141
142
            kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
            KdenliveSettings::setActivate_nepomuk(false);
        }
    }
Marco Gittler's avatar
Marco Gittler committed
143
#endif
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
144
145
}

146
147
ProjectList::~ProjectList()
{
148
    delete m_menu;
149
150
151
    m_listView->blockSignals(true);
    m_listView->clear();
    delete m_listViewDelegate;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
152
153
}

154
155
156
157
158
void ProjectList::focusTree() const
{
    m_listView->setFocus();
}

159
160
void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
{
161
    QList <QAction *> actions = addMenu->actions();
162
163
    for (int i = 0; i < actions.count(); i++) {
        if (actions.at(i)->data().toString() == "clip_properties") {
164
            m_editButton->setDefaultAction(actions.at(i));
165
166
            actions.removeAt(i);
            i--;
167
        } else if (actions.at(i)->data().toString() == "delete_clip") {
168
            m_deleteButton->setDefaultAction(actions.at(i));
169
170
            actions.removeAt(i);
            i--;
171
        } else if (actions.at(i)->data().toString() == "edit_clip") {
172
173
174
            m_openAction = actions.at(i);
            actions.removeAt(i);
            i--;
175
        } else if (actions.at(i)->data().toString() == "reload_clip") {
176
177
178
            m_reloadAction = actions.at(i);
            actions.removeAt(i);
            i--;
179
180
181
182
183
184
        }
    }

    QMenu *m = new QMenu();
    m->addActions(actions);
    m_addButton->setMenu(m);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
185
186
187
188
189
    m_addButton->setDefaultAction(defaultAction);
    m_menu = new QMenu();
    m_menu->addActions(addMenu->actions());
}

190
void ProjectList::setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu, QMenu *inTimelineMenu)
191
{
192
    if (!addMenu)
193
        return;
194
195
196
    QMenu *menu = m_addButton->menu();
    menu->addMenu(addMenu);
    m_addButton->setMenu(menu);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
197

198
    m_menu->addMenu(addMenu);
199
    if (addMenu->isEmpty())
200
        addMenu->setEnabled(false);
201
    m_menu->addMenu(transcodeMenu);
202
    if (transcodeMenu->isEmpty())
203
        transcodeMenu->setEnabled(false);
204
    m_transcodeAction = transcodeMenu;
205
    m_menu->addAction(m_reloadAction);
206
    m_menu->addAction(m_proxyAction);
207
208
    m_menu->addMenu(inTimelineMenu);
    inTimelineMenu->setEnabled(false);
209
    m_menu->addAction(m_editButton->defaultAction());
210
    m_menu->addAction(m_openAction);
211
212
    m_menu->addAction(m_deleteButton->defaultAction());
    m_menu->insertSeparator(m_deleteButton->defaultAction());
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
213
214
215
}


216
QByteArray ProjectList::headerInfo() const
217
{
218
    return m_listView->header()->saveState();
219
220
}

221
222
void ProjectList::setHeaderInfo(const QByteArray &state)
{
223
    m_listView->header()->restoreState(state);
224
225
}

226
227
228
229
230
void ProjectList::updateProjectFormat(Timecode t)
{
    m_timecode = t;
}

231
232
void ProjectList::slotEditClip()
{
233
    QList<QTreeWidgetItem *> list = m_listView->selectedItems();
234
235
    if (list.isEmpty()) return;
    if (list.count() > 1 || list.at(0)->type() == PROJECTFOLDERTYPE) {
236
237
238
        editClipSelection(list);
        return;
    }
239
    ProjectItem *item;
240
    if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
241
        return;
242
    if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE)
243
        item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
244
245
    else
        item = static_cast <ProjectItem*>(m_listView->currentItem());
246
    if (item && (item->flags() & Qt::ItemIsDragEnabled)) {
247
248
249
        emit clipSelected(item->referencedClip());
        emit showClipProperties(item->referencedClip());
    }
250
251
}

252
253
254
255
256
void ProjectList::editClipSelection(QList<QTreeWidgetItem *> list)
{
    // Gather all common properties
    QMap <QString, QString> commonproperties;
    QList <DocClipBase *> clipList;
257
258
    commonproperties.insert("force_aspect_num", "-");
    commonproperties.insert("force_aspect_den", "-");
259
    commonproperties.insert("force_fps", "-");
260
    commonproperties.insert("force_progressive", "-");
261
    commonproperties.insert("force_tff", "-");
262
263
264
    commonproperties.insert("threads", "-");
    commonproperties.insert("video_index", "-");
    commonproperties.insert("audio_index", "-");
265
266
    commonproperties.insert("force_colorspace", "-");
    commonproperties.insert("full_luma", "-");
267
    QString transparency = "-";
268

269
270
    bool allowDurationChange = true;
    int commonDuration = -1;
271
    bool hasImages = false;;
272
    ProjectItem *item;
273
    for (int i = 0; i < list.count(); i++) {
274
        item = NULL;
275
276
277
278
279
280
        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));
            }
281
            continue;
282
283
        }
        else if (list.at(i)->type() == PROJECTSUBCLIPTYPE)
284
            item = static_cast <ProjectItem*>(list.at(i)->parent());
285
286
        else
            item = static_cast <ProjectItem*>(list.at(i));
287
        if (!(item->flags() & Qt::ItemIsDragEnabled))
288
            continue;
289
        if (item) {
290
291
            // check properties
            DocClipBase *clip = item->referencedClip();
292
            if (clipList.contains(clip)) continue;
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
            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";
                    }
                }
            }
316
            if (clip->clipType() != COLOR && clip->clipType() != IMAGE && clip->clipType() != TEXT)
317
                allowDurationChange = false;
318
319
            if (allowDurationChange && commonDuration != 0) {
                if (commonDuration == -1)
320
                    commonDuration = clip->duration().frames(m_fps);
321
                else if (commonDuration != clip->duration().frames(m_fps))
322
323
                    commonDuration = 0;
            }
324
325
326
            clipList.append(clip);
            QMap <QString, QString> clipprops = clip->properties();
            QMapIterator<QString, QString> p(commonproperties);
327
            while (p.hasNext()) {
328
                p.next();
329
330
331
                if (p.value().isEmpty()) continue;
                if (clipprops.contains(p.key())) {
                    if (p.value() == "-")
332
                        commonproperties.insert(p.key(), clipprops.value(p.key()));
333
                    else if (p.value() != clipprops.value(p.key()))
334
335
336
337
                        commonproperties.insert(p.key(), QString());
                } else {
                    commonproperties.insert(p.key(), QString());
                }
338
339
340
            }
        }
    }
341
    if (allowDurationChange)
342
        commonproperties.insert("out", QString::number(commonDuration));
343
344
    if (hasImages)
        commonproperties.insert("transparency", transparency);
345
    /*QMapIterator<QString, QString> p(commonproperties);
346
    while (p.hasNext()) {
347
348
        p.next();
        kDebug() << "Result: " << p.key() << " = " << p.value();
349
    }*/
350
351
352
    emit showClipProperties(clipList, commonproperties);
}

353
354
void ProjectList::slotOpenClip()
{
355
    ProjectItem *item;
356
    if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
357
        return;
358
    if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1)
359
        item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
360
361
    else
        item = static_cast <ProjectItem*>(m_listView->currentItem());
362
363
364
    if (item) {
        if (item->clipType() == IMAGE) {
            if (KdenliveSettings::defaultimageapp().isEmpty())
365
                KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open images in the Settings dialog"));
366
367
            else
                QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
368
        }
369
370
        if (item->clipType() == AUDIO) {
            if (KdenliveSettings::defaultaudioapp().isEmpty())
371
                KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open audio files in the Settings dialog"));
372
373
            else
                QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
374
375
376
        }
    }
}
377

378
379
380
381
382
void ProjectList::cleanup()
{
    m_listView->clearSelection();
    QTreeWidgetItemIterator it(m_listView);
    ProjectItem *item;
383
384
    while (*it) {
        if ((*it)->type() != PROJECTCLIPTYPE) {
385
386
387
            it++;
            continue;
        }
388
        item = static_cast <ProjectItem *>(*it);
389
        if (item->numReferences() == 0)
390
            item->setSelected(true);
391
392
393
394
395
        it++;
    }
    slotRemoveClip();
}

396
397
398
399
400
void ProjectList::trashUnusedClips()
{
    QTreeWidgetItemIterator it(m_listView);
    ProjectItem *item;
    QStringList ids;
401
    QStringList urls;
402
403
    while (*it) {
        if ((*it)->type() != PROJECTCLIPTYPE) {
404
405
406
            it++;
            continue;
        }
407
        item = static_cast <ProjectItem *>(*it);
408
        if (item->numReferences() == 0) {
409
410
            ids << item->clipId();
            KUrl url = item->clipUrl();
411
            if (!url.isEmpty() && !urls.contains(url.path()))
412
                urls << url.path();
413
414
415
        }
        it++;
    }
416

417
418
    // Check that we don't use the URL in another clip
    QTreeWidgetItemIterator it2(m_listView);
419
420
    while (*it2) {
        if ((*it2)->type() != PROJECTCLIPTYPE) {
421
422
423
            it2++;
            continue;
        }
424
        item = static_cast <ProjectItem *>(*it2);
425
        if (item->numReferences() > 0) {
426
            KUrl url = item->clipUrl();
427
            if (!url.isEmpty() && urls.contains(url.path())) urls.removeAll(url.path());
428
429
430
431
        }
        it2++;
    }

432
    emit deleteProjectClips(ids, QMap <QString, QString>());
433
    for (int i = 0; i < urls.count(); i++)
434
        KIO::NetAccess::del(KUrl(urls.at(i)), this);
435
436
}

437
void ProjectList::slotReloadClip(const QString &id)
438
{
439
    QList<QTreeWidgetItem *> selected;
440
    if (id.isEmpty())
441
        selected = m_listView->selectedItems();
442
443
444
445
    else {
        ProjectItem *itemToReLoad = getItemById(id);
        if (itemToReLoad) selected.append(itemToReLoad);
    }
446
    ProjectItem *item;
447
448
449
450
    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++)
451
                    selected.append(selected.at(i)->child(j));
452
453
454
            }
            continue;
        }
455
        item = static_cast <ProjectItem *>(selected.at(i));
456
        if (item) {
457
458
            CLIPTYPE t = item->clipType();
            if (t == TEXT) {
459
                if (!item->referencedClip()->getProperty("xmltemplate").isEmpty())
460
                    regenerateTemplate(item);
461
            } else if (t != COLOR && t != SLIDESHOW && item->referencedClip() &&  item->referencedClip()->checkHash() == false) {
462
463
                item->referencedClip()->setPlaceHolder(true);
                item->setProperty("file_hash", QString());
464
            } else if (t == IMAGE) {
465
                item->referencedClip()->producer()->set("force_reload", 1);
466
            }
467
468
469
470
471
472
473
474

            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(item->referencedClip()->producerProperty("length")).toInt();
                if (length > 0 && !e.hasAttribute("length")) {
                    e.setAttribute("length", length);
                }
475
            }            
476
            emit getFileProperties(e, item->clipId(), m_listView->iconSize().height(), true, false);
477
478
479
480
        }
    }
}

481
482
483
void ProjectList::slotModifiedClip(const QString &id)
{
    ProjectItem *item = getItemById(id);
484
    if (item) {
485
        QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
486
        if (!pixmap.isNull()) {
487
488
489
490
            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();
491
492
493
        } else {
            pixmap = KIcon("view-refresh").pixmap(m_listView->iconSize());
        }
494
        item->setData(0, Qt::DecorationRole, pixmap);
495
496
497
    }
}

498
499
500
void ProjectList::slotMissingClip(const QString &id)
{
    ProjectItem *item = getItemById(id);
501
    if (item) {
502
        item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
503
        if (item->referencedClip()) {
504
            item->referencedClip()->setPlaceHolder(true);
505
            if (m_render == NULL) kDebug() << "*********  ERROR, NULL RENDR";
506
507
508
509
510
511
512
513
514
515
516
517
518
            item->referencedClip()->setProducer(m_render->invalidProducer(id), true);
            item->slotSetToolTip();
            emit clipNeedsReload(id, true);
        }
    }
    update();
    emit displayMessage(i18n("Check missing clips"), -2);
    emit updateRenderStatus();
}

void ProjectList::slotAvailableClip(const QString &id)
{
    ProjectItem *item = getItemById(id);
519
    if (item == NULL)
520
        return;
521
    item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
522
    if (item->referencedClip()) { // && item->referencedClip()->checkHash() == false) {
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
        item->setProperty("file_hash", QString());
        slotReloadClip(id);
    }
    /*else {
    item->referencedClip()->setValid();
    item->slotSetToolTip();
    }
    update();*/
    emit updateRenderStatus();
}

bool ProjectList::hasMissingClips()
{
    bool missing = false;
    QTreeWidgetItemIterator it(m_listView);
538
539
    while (*it) {
        if ((*it)->type() == PROJECTCLIPTYPE && !((*it)->flags() & Qt::ItemIsDragEnabled)) {
540
541
542
543
544
545
546
547
            missing = true;
            break;
        }
        it++;
    }
    return missing;
}

548
549
void ProjectList::setRenderer(Render *projectRender)
{
550
    m_render = projectRender;
551
    m_listView->setIconSize(QSize((ProjectItem::itemDefaultHeight() - 2) * m_render->dar(), ProjectItem::itemDefaultHeight() - 2));
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
552
553
}

554
555
void ProjectList::slotClipSelected()
{
556
557
558
    if (!m_listView->isEnabled()) return;
    if (m_listView->currentItem()) {
        if (m_listView->currentItem()->type() == PROJECTFOLDERTYPE) {
559
            emit clipSelected(NULL);
560
            m_editButton->defaultAction()->setEnabled(m_listView->currentItem()->childCount() > 0);
561
            m_deleteButton->defaultAction()->setEnabled(true);
562
563
564
            m_openAction->setEnabled(false);
            m_reloadAction->setEnabled(false);
            m_transcodeAction->setEnabled(false);
565
            m_proxyAction->setEnabled(false);
566
567
        } else {
            ProjectItem *clip;
568
            if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
569
                // this is a sub item, use base clip
570
                m_deleteButton->defaultAction()->setEnabled(true);
571
                clip = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
572
                if (clip == NULL) kDebug() << "-----------ERROR";
573
574
                SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
                emit clipSelected(clip->referencedClip(), sub->zone());
575
                m_transcodeAction->setEnabled(false);
576
577
578
                return;
            }
            clip = static_cast <ProjectItem*>(m_listView->currentItem());
579
            if (clip && clip->referencedClip())
580
                emit clipSelected(clip->referencedClip());
581
582
            m_editButton->defaultAction()->setEnabled(true);
            m_deleteButton->defaultAction()->setEnabled(true);
583
584
            m_reloadAction->setEnabled(true);
            m_transcodeAction->setEnabled(true);
585
            if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
586
587
                m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
                m_openAction->setEnabled(true);
588
            } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
589
590
                m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
                m_openAction->setEnabled(true);
591
592
593
            } else {
                m_openAction->setEnabled(false);
            }
594
595
            // Display relevant transcoding actions only
            adjustTranscodeActions(clip);
596
597
            // Display uses in timeline
            emit findInTimeline(clip->clipId());
598
        }
599
    } else {
600
        emit clipSelected(NULL);
601
602
        m_editButton->defaultAction()->setEnabled(false);
        m_deleteButton->defaultAction()->setEnabled(false);
603
        m_openAction->setEnabled(false);
604
        m_reloadAction->setEnabled(false);
605
        m_transcodeAction->setEnabled(false);
606
    }
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
607
608
}

609
610
611
612
613
614
void ProjectList::adjustProxyActions(ProjectItem *clip) const
{
    if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW || clip->clipType() == AUDIO) {
        m_proxyAction->setEnabled(false);
        return;
    }
615
    m_proxyAction->setEnabled(useProxy());
616
    m_proxyAction->blockSignals(true);
617
    m_proxyAction->setChecked(clip->hasProxy());
618
    m_proxyAction->blockSignals(false);
619
620
}

621
622
void ProjectList::adjustTranscodeActions(ProjectItem *clip) const
{
623
    if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW) {
624
625
626
627
628
629
630
        m_transcodeAction->setEnabled(false);
        return;
    }
    m_transcodeAction->setEnabled(true);
    QList<QAction *> transcodeActions = m_transcodeAction->actions();
    QStringList data;
    QString condition;
631
    for (int i = 0; i < transcodeActions.count(); i++) {
632
        data = transcodeActions.at(i)->data().toStringList();
633
        if (data.count() > 2) {
634
            condition = data.at(2);
635
            if (condition.startsWith("vcodec"))
636
                transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
637
            else if (condition.startsWith("acodec"))
638
                transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
639
640
641
642
643
        }
    }

}

644
645
void ProjectList::slotPauseMonitor()
{
646
    if (m_render)
647
        m_render->pause();
648
649
}

650
651
void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
{
652
    ProjectItem *item = getItemById(id);
653
    if (item) {
654
        slotUpdateClipProperties(item, properties);
655
        if (properties.contains("out") || properties.contains("force_fps") || properties.contains("resource")) {
656
            slotReloadClip(id);
657
658
659
660
661
        } else if (properties.contains("colour") ||
                   properties.contains("xmldata") ||
                   properties.contains("force_aspect_num") ||
                   properties.contains("force_aspect_den") ||
                   properties.contains("templatetext")) {
662
            slotRefreshClipThumbnail(item);
663
664
665
            emit refreshClip(id, true);
        } else if (properties.contains("full_luma") || properties.contains("force_colorspace") || properties.contains("loop")) {
            emit refreshClip(id, false);
666
        }
667
    }
668
669
}

670
671
void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
{
672
    if (!clip)
673
        return;
674
    clip->setProperties(properties);
675
    if (properties.contains("name")) {
676
        monitorItemEditing(false);
677
        clip->setText(0, properties.value("name"));
678
        monitorItemEditing(true);
679
680
        emit clipNameChanged(clip->clipId(), properties.value("name"));
    }
681
    if (properties.contains("description")) {
682
        CLIPTYPE type = clip->clipType();
683
        monitorItemEditing(false);
684
        clip->setText(1, properties.value("description"));
685
        monitorItemEditing(true);
Marco Gittler's avatar
Marco Gittler committed
686
#ifdef NEPOMUK
687
        if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
688
689
            // Use Nepomuk system to store clip description
            Nepomuk::Resource f(clip->clipUrl().path());
690
            f.setDescription(properties.value("description"));
691
        }
Marco Gittler's avatar
Marco Gittler committed
692
#endif
693
        emit projectModified();
694
695
696
    }
}

697
698
void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
{
699
    if (item->type() == PROJECTSUBCLIPTYPE) {
700
        // this is a sub-item
701
        if (column == 1) {
702
703
704
705
706
707
708
            // user edited description
            SubProjectItem *sub = static_cast <SubProjectItem*>(item);
            ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
            EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), sub->zone(), sub->description(), sub->text(1), true);
            m_commandStack->push(command);
            //slotUpdateCutClipProperties(sub->clipId(), sub->zone(), sub->text(1), sub->text(1));
        }
709
710
        return;
    }
711
712
    if (item->type() == PROJECTFOLDERTYPE) {
        if (column == 0) {
713
714
715
716
717
            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();
718
            for (int i = 0; i < children; i++) {
719
720
721
                ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
                child->setProperty("groupname", item->text(0));
            }
722
723
724
        }
        return;
    }
725

726
    ProjectItem *clip = static_cast <ProjectItem*>(item);
727
728
    if (column == 1) {
        if (clip->referencedClip()) {
729
730
731
            QMap <QString, QString> oldprops;
            QMap <QString, QString> newprops;
            oldprops["description"] = clip->referencedClip()->getProperty("description");
732
            newprops["description"] = item->text(1);
733

734
            if (clip->clipType() == TEXT) {
735
                // This is a text template clip, update the image
736
737
738
                /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
                newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/
                oldprops.insert("templatetext", clip->referencedClip()->getProperty("templatetext"));
739
                newprops.insert("templatetext", item->text(1));
740
            }
741
742
743
            slotUpdateClipProperties(clip->clipId(), newprops);
            EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
            m_commandStack->push(command);
744
        }
745
746
    } else if (column == 0) {
        if (clip->referencedClip()) {
747
748
749
            QMap <QString, QString> oldprops;
            QMap <QString, QString> newprops;
            oldprops["name"] = clip->referencedClip()->getProperty("name");
750
751
752
753
754
755
756
            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);
            }
757
        }
758
    }
759
760
}

761
762
void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
{
763
    bool enable = item ? true : false;
764
765
    m_editButton->defaultAction()->setEnabled(enable);
    m_deleteButton->defaultAction()->setEnabled(enable);
766
    m_reloadAction->setEnabled(enable);
767
    m_transcodeAction->setEnabled(enable);
768
    if (enable) {
769
        ProjectItem *clip = NULL;
770
        if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
771
            clip = static_cast <ProjectItem*>(item->parent());
772
            m_transcodeAction->setEnabled(false);
773
        } else if (m_listView->currentItem()->type() == PROJECTCLIPTYPE) {
774
775
776
            clip = static_cast <ProjectItem*>(item);
            // Display relevant transcoding actions only
            adjustTranscodeActions(clip);
777
            adjustProxyActions(clip);
778
779
            // Display uses in timeline
            emit findInTimeline(clip->clipId());
780
781
782
        } else {
            m_transcodeAction->setEnabled(false);
        }
783
        if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
784
785
            m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
            m_openAction->setEnabled(true);
786
        } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
787
788
            m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
            m_openAction->setEnabled(true);
789
790
791
        } else {
            m_openAction->setEnabled(false);
        }
792

793
794
795
    } else {
        m_openAction->setEnabled(false);
    }
796
    m_menu->popup(pos);
797
798
}

799
800
void ProjectList::slotRemoveClip()
{
801
    if (!m_listView->currentItem())
802
        return;
803
    QStringList ids;
804
    QMap <QString, QString> folderids;
805
    QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
806
807
808

    QUndoCommand *delCommand = new QUndoCommand();
    delCommand->setText(i18n("Delete Clip Zone"));
809
810
    for (int i = 0; i < selected.count(); i++) {
        if (selected.at(i)->type() == PROJECTSUBCLIPTYPE) {
811
812
813
            // subitem
            SubProjectItem *sub = static_cast <SubProjectItem *>(selected.at(i));
            ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
814
            new AddClipCutCommand(this, item->clipId(), sub->zone().x(), sub->zone().y(), sub->description(), false, true, delCommand);
815
        } else if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
816
817
818
819
820
            // folder
            FolderProjectItem *folder = static_cast <FolderProjectItem *>(selected.at(i));
            folderids[folder->groupName()] = folder->clipId();
            int children = folder->childCount();

821
            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)
822
                return;
823
            for (int i = 0; i < children; ++i) {
824
                ProjectItem *child = static_cast <ProjectItem *>(folder->child(i));
825
826
                ids << child->clipId();
            }
827
828
829
        } else {
            ProjectItem *item = static_cast <ProjectItem *>(selected.at(i));
            ids << item->clipId();
830
831
            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");
832
                return;
833
            }
834
        }
835
    }
836
    KMess