projectclip.cpp 46 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
/*
Copyright (C) 2012  Till Theato <root@ttill.de>
Copyright (C) 2014  Jean-Baptiste Mardelle <jb@kdenlive.org>
This file is part of Kdenlive. See www.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) version 3 or any later version
accepted by the membership of KDE e.V. (or its successor approved
11
by the membership of KDE e.V.), which shall act as a proxy
12 13 14 15 16 17 18 19 20 21 22 23 24
defined in Section 14 of version 3 of the license.

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, see <http://www.gnu.org/licenses/>.
*/

#include "projectclip.h"
#include "projectfolder.h"
25
#include "projectsubclip.h"
26
#include "projectitemmodel.h"
27
#include "bin.h"
28
#include "timecode.h"
29 30
#include "doc/kthumb.h"
#include "kdenlivesettings.h"
31
#include "timeline/clip.h"
32
#include "project/projectcommands.h"
33
#include "mltcontroller/clipcontroller.h"
34
#include "mltcontroller/bincontroller.h"
35
#include "lib/audio/audioStreamInfo.h"
36
#include "utils/KoIconUtils.h"
37
#include "mltcontroller/clippropertiescontroller.h"
38 39
#include "core.h"
#include "profiles/profilemodel.hpp"
40 41 42

#include <QDomElement>
#include <QFile>
43
#include <QDir>
Laurent Montel's avatar
Laurent Montel committed
44
#include "kdenlive_debug.h"
45
#include <QCryptographicHash>
46
#include <QtConcurrent>
47
#include <KLocalizedString>
48
#include <KMessageBox>
49

50 51 52
ProjectClip::ProjectClip(const QString &id, const QIcon &thumb, ProjectItemModel* model, std::shared_ptr<Mlt::Producer> producer, ProjectFolder *parent) :
    AbstractProjectItem(AbstractProjectItem::ClipItem, id, model, parent)
    , ClipController(pCore->binController(), producer)
53
    , m_abortAudioThumb(false)
Laurent Montel's avatar
Laurent Montel committed
54
    , m_thumbsProducer(nullptr)
55
{
56
    m_clipStatus = StatusReady;
57 58 59 60 61
    m_name = clipName();
    m_duration = getStringDuration();
    m_date = date;
    m_description = ClipController::description();
    m_type = clipType();
62
    if (m_type == Audio) {
63
        m_thumbnail = KoIconUtils::themedIcon(QStringLiteral("audio-x-generic"));
64 65 66
    } else {
        m_thumbnail = thumb;
    }
67 68
    // Make sure we have a hash for this clip
    hash();
69
    setParent(parent);
70
    connect(this, &ProjectClip::updateJobStatus, this, &ProjectClip::setJobStatus);
71 72
    static_cast<ProjectItemModel*>(m_model)->bin()->loadSubClips(id, getPropertiesFromPrefix(QStringLiteral("kdenlive:clipzone.")));
    connect(this, &ProjectClip::updateThumbProgress, static_cast<ProjectItemModel*>(m_model)->bin(), &Bin::doUpdateThumbsProgress);
73
    createAudioThumbs();
74 75
}

76 77 78
ProjectClip::ProjectClip(const QDomElement &description, const QIcon &thumb, ProjectItemModel* model, ProjectFolder *parent) :
    AbstractProjectItem(AbstractProjectItem::ClipItem, description, model, parent)
    , ClipController(pCore->binController(), ClipController::mediaUnavailable)
79
    , m_abortAudioThumb(false)
80
    , m_type(Unknown)
Laurent Montel's avatar
Laurent Montel committed
81
    , m_thumbsProducer(nullptr)
82
{
Laurent Montel's avatar
Laurent Montel committed
83
    Q_ASSERT(description.hasAttribute(QStringLiteral("id")));
84
    m_clipStatus = StatusWaiting;
85
    m_thumbnail = thumb;
86 87
    if (description.hasAttribute(QStringLiteral("type"))) {
        m_type = (ClipType) description.attribute(QStringLiteral("type")).toInt();
88
        if (m_type == Audio) {
89
            m_thumbnail = KoIconUtils::themedIcon(QStringLiteral("audio-x-generic"));
90
        }
91
    }
92
    m_temporaryUrl = getXmlProperty(description, QStringLiteral("resource"));
93
    QString clipName = getXmlProperty(description, QStringLiteral("kdenlive:clipname"));
94 95
    if (!clipName.isEmpty()) {
        m_name = clipName;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
96
    } else if (!m_temporaryUrl.isEmpty()) {
97
        m_name = QFileInfo(m_temporaryUrl).fileName();
98 99
    } else {
        m_name = i18n("Untitled");
100
    }
101
    connect(this, &ProjectClip::updateJobStatus, this, &ProjectClip::setJobStatus);
102
    setParent(parent);
103
    connect(this, &ProjectClip::updateThumbProgress, static_cast<ProjectItemModel*>(m_model)->bin(), &Bin::doUpdateThumbsProgress);
104 105 106 107
}

ProjectClip::~ProjectClip()
{
108
    // controller is deleted in bincontroller
109
    abortAudioThumbs();
110
    static_cast<ProjectItemModel*>(m_model)->bin()->slotAbortAudioThumb(m_id, duration().ms());
111 112
    QMutexLocker audioLock(&m_audioMutex);
    m_thumbMutex.lock();
113
    m_requestedThumbs.clear();
114
    m_thumbMutex.unlock();
115
    m_thumbThread.waitForFinished();
116
    delete m_thumbsProducer;
117
    audioFrameCache.clear();
118 119
}

120 121 122
void ProjectClip::abortAudioThumbs()
{
    m_abortAudioThumb = true;
123
    emit doAbortAudioThumbs();
124 125
}

126 127
QString ProjectClip::getToolTip() const
{
128
    return url();
129 130
}

131
QString ProjectClip::getXmlProperty(const QDomElement &producer, const QString &propertyName, const QString &defaultValue)
132
{
133
    QString value = defaultValue;
134
    QDomNodeList props = producer.elementsByTagName(QStringLiteral("property"));
135
    for (int i = 0; i < props.count(); ++i) {
136
        if (props.at(i).toElement().attribute(QStringLiteral("name")) == propertyName) {
137 138 139 140 141 142 143
            value = props.at(i).firstChild().nodeValue();
            break;
        }
    }
    return value;
}

Laurent Montel's avatar
Laurent Montel committed
144
void ProjectClip::updateAudioThumbnail(const QVariantList &audioLevels)
145
{
146
    audioFrameCache = audioLevels;
147 148
    m_audioThumbCreated = true;
    static_cast<ProjectItemModel*>(m_model)->bin()->emitRefreshAudioThumbs(m_id);
149 150 151
    emit gotAudioData();
}

152 153
QStringList ProjectClip::markersText(GenTime in, GenTime out) const
{
154
    return markerComments(in, out);
155 156
}

157 158
bool ProjectClip::audioThumbCreated() const
{
159
    return (m_audioThumbCreated);
160 161
}

162 163
ClipType ProjectClip::clipType() const
{
164
    return m_type;
165 166
}

167 168 169 170
bool ProjectClip::hasParent(const QString &id) const
{
    AbstractProjectItem *par = parent();
    while (par) {
171 172 173 174
        if (par->clipId() == id) {
            return true;
        }
        par = par->parent();
175 176 177 178
    }
    return false;
}

179
ProjectClip *ProjectClip::clip(const QString &id)
180 181 182 183
{
    if (id == m_id) {
        return this;
    }
Laurent Montel's avatar
Laurent Montel committed
184
    return nullptr;
185 186
}

187
ProjectFolder *ProjectClip::folder(const QString &id)
188
{
189
    Q_UNUSED(id)
Laurent Montel's avatar
Laurent Montel committed
190
    return nullptr;
191 192
}

193

194
ProjectSubClip *ProjectClip::getSubClip(int in, int out)
195
{
196 197
    for (int i = 0; i < childCount(); ++i) {
        ProjectSubClip *clip = static_cast<ProjectSubClip *>(child(i))->subClip(in, out);
198 199 200 201
        if (clip) {
            return clip;
        }
    }
Laurent Montel's avatar
Laurent Montel committed
202
    return nullptr;
203 204
}

205 206 207
QStringList ProjectClip::subClipIds() const
{
    QStringList subIds;
208 209
    for (int i = 0; i < childCount(); ++i) {
        AbstractProjectItem *clip = static_cast<AbstractProjectItem*>(child(i));
210 211 212 213 214 215 216
        if (clip) {
            subIds << clip->clipId();
        }
    }
    return subIds;
}

217
ProjectClip *ProjectClip::clipAt(int ix)
218 219 220 221
{
    if (ix == index()) {
        return this;
    }
Laurent Montel's avatar
Laurent Montel committed
222
    return nullptr;
223 224
}

225
/*bool ProjectClip::isValid() const
226
{
227 228
    return m_controller->isValid();
}*/
229

230 231
bool ProjectClip::hasUrl() const
{
232 233
    if ((m_type != Color) && (m_type != Unknown)) {
        return (!clipUrl().isEmpty());
234
    }
235 236 237
    return false;
}

238
const QString ProjectClip::url() const
239
{
240
    return clipUrl();
241 242 243
}


244
GenTime ProjectClip::duration() const
245
{
246
    return getPlaytime();
247 248
}

249 250 251
int ProjectClip::frameDuration() const
{
    GenTime d = duration();
252
    return d.frames(pCore->getCurrentFps());
253 254
}

255
void ProjectClip::reloadProducer(bool refreshOnly)
256 257 258
{
    QDomDocument doc;
    QDomElement xml = toXml(doc);
259
    if (refreshOnly) {
260
        // set a special flag to request thumbnail only
261
        xml.setAttribute(QStringLiteral("refreshOnly"), QStringLiteral("1"));
262
    }
263
    static_cast<ProjectItemModel*>(m_model)->bin()->reloadProducer(m_id, xml);
264 265 266 267
}

void ProjectClip::setCurrent(bool current, bool notify)
{
268 269 270 271
    Q_UNUSED(notify);
    if (current) {
        static_cast<ProjectItemModel*>(m_model)->bin()->openProducer(static_cast<ClipController*>(this));
        static_cast<ProjectItemModel*>(m_model)->bin()->requestShowEffectStack(getEffectStack());
272 273 274
    }
}

275
QDomElement ProjectClip::toXml(QDomDocument &document, bool includeMeta)
276
{
277 278 279 280
    getProducerXML(document, includeMeta);
    QDomElement prod = document.documentElement().firstChildElement(QStringLiteral("producer"));
    if (m_type != Unknown) {
        prod.setAttribute(QStringLiteral("type"), (int) m_type);
281
    }
282
    return prod;
283 284
}

Laurent Montel's avatar
Laurent Montel committed
285
void ProjectClip::setThumbnail(const QImage &img)
286
{
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
287 288
    QPixmap thumb = roundedPixmap(QPixmap::fromImage(img));
    if (hasProxy() && !thumb.isNull()) {
289
        // Overlay proxy icon
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
290
        QPainter p(&thumb);
291
        QColor c(220, 220, 10, 200);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
292
        QRect r(0, 0, thumb.height() / 2.5, thumb.height() / 2.5);
293 294 295 296 297 298 299 300
        p.fillRect(r, c);
        QFont font = p.font();
        font.setPixelSize(r.height());
        font.setBold(true);
        p.setFont(font);
        p.setPen(Qt::black);
        p.drawText(r, Qt::AlignCenter, i18nc("The first letter of Proxy, used as abbreviation", "P"));
    }
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
301
    m_thumbnail = QIcon(thumb);
302
    emit thumbUpdated(img);
303
    static_cast<ProjectItemModel*>(m_model)->bin()->emitItemUpdated(this);
304 305
}

306 307 308 309 310
QPixmap ProjectClip::thumbnail(int width, int height)
{
    return m_thumbnail.pixmap(width, height);
}

311
bool ProjectClip::setProducer(std::shared_ptr<Mlt::Producer> producer, bool replaceProducer)
312
{
313 314 315 316 317 318 319
    Q_UNUSED(replaceProducer);

    updateProducer(producer);

    // Update info
    if (m_name.isEmpty()) {
        m_name = clipName();
320
    }
321 322 323 324 325 326 327
    m_date = date;
    m_description = ClipController::description();
    m_temporaryUrl.clear();
    if (m_type == Unknown) {
        m_type = clipType();
        if (m_type == Audio) {
            m_thumbnail = KoIconUtils::themedIcon(QStringLiteral("audio-x-generic"));
328
        }
329
    }
330
    m_duration = getStringDuration();
331
    m_clipStatus = StatusReady;
332
    if (!hasProxy()) {
333
        static_cast<ProjectItemModel*>(m_model)->bin()->emitRefreshPanel(m_id);
334
    }
335
    static_cast<ProjectItemModel*>(m_model)->bin()->emitItemUpdated(this);
336
    // Make sure we have a hash for this clip
337
    getFileHash();
338
    createAudioThumbs();
339
    return true;
340 341 342 343
}

void ProjectClip::createAudioThumbs()
{
344
    if (KdenliveSettings::audiothumbnails() && (m_type == AV || m_type == Audio || m_type == Playlist)) {
345
        static_cast<ProjectItemModel*>(m_model)->bin()->requestAudioThumbs(m_id, duration().ms());
346
        emit updateJobStatus(AbstractClipJob::THUMBJOB, JobWaiting, 0);
347
    }
348 349 350
}


351 352 353 354 355 356
Mlt::Producer *ProjectClip::thumbProducer()
{
    QMutexLocker locker(&m_producerMutex);
    if (m_thumbsProducer) {
        return m_thumbsProducer;
    }
357
    if (clipType() == Unknown) {
Laurent Montel's avatar
Laurent Montel committed
358
        return nullptr;
359
    }
360 361
    std::shared_ptr<Mlt::Producer> prod = originalProducer();
    if (!prod->is_valid()) {
Laurent Montel's avatar
Laurent Montel committed
362
        return nullptr;
363
    }
364
    Clip clip(*prod.get());
365
    if (KdenliveSettings::gpu_accel()) {
366
        m_thumbsProducer = clip.softClone(ClipController::getPassPropertiesList());
367 368
        Mlt::Filter scaler(*prod->profile(), "swscale");
        Mlt::Filter converter(*prod->profile(), "avcolor_space");
369 370
        m_thumbsProducer->attach(scaler);
        m_thumbsProducer->attach(converter);
371 372
    } else {
        m_thumbsProducer = clip.clone();
373 374 375 376
    }
    return m_thumbsProducer;
}

377
bool ProjectClip::isReady() const
378
{
379
    return m_clipStatus == StatusReady;
380 381
}

382
/*void ProjectClip::setZone(const QPoint &zone)
383 384
{
    m_zone = zone;
385
}*/
386 387 388

QPoint ProjectClip::zone() const
{
389 390
    int x = getProducerIntProperty(QStringLiteral("kdenlive:zone_in"));
    int y = getProducerIntProperty(QStringLiteral("kdenlive:zone_out"));
391
    return QPoint(x, y);
392 393
}

Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
394 395
void ProjectClip::resetProducerProperty(const QString &name)
{
396
    resetProperty(name);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
397 398 399
}

void ProjectClip::setProducerProperty(const QString &name, int data)
400
{
401
    ClipController::setProperty(name, data);
402 403
}

Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
404
void ProjectClip::setProducerProperty(const QString &name, double data)
405
{
406
    ClipController::setProperty(name, data);
407 408
}

Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
409
void ProjectClip::setProducerProperty(const QString &name, const QString &data)
410
{
411
    ClipController::setProperty(name, data);
412 413
}

Laurent Montel's avatar
Laurent Montel committed
414
QMap<QString, QString> ProjectClip::currentProperties(const QMap<QString, QString> &props)
415
{
Laurent Montel's avatar
Laurent Montel committed
416
    QMap<QString, QString> currentProps;
417 418
    QMap<QString, QString>::const_iterator i = props.constBegin();
    while (i != props.constEnd()) {
419
        currentProps.insert(i.key(), ClipController::property(i.key()));
420 421 422 423 424
        ++i;
    }
    return currentProps;
}

425 426
QColor ProjectClip::getProducerColorProperty(const QString &key) const
{
427
    return color_property(key);
428 429
}

430 431
int ProjectClip::getProducerIntProperty(const QString &key) const
{
432
    return int_property(key);
433
}
434

435 436
qint64 ProjectClip::getProducerInt64Property(const QString &key) const
{
437
    return int64_property(key);
438 439
}

440 441
double ProjectClip::getDoubleProducerProperty(const QString &key) const
{
442
    return double_property(key);
443 444
}

445
QString ProjectClip::getProducerProperty(const QString &key) const
446
{
447
    return ClipController::property(key);
448 449 450 451
}

const QString ProjectClip::hash()
{
452 453 454
    QString clipHash = ClipController::property(QStringLiteral("kdenlive:file_hash"));
    if (!clipHash.isEmpty()) {
        return clipHash;
455
    }
456
    return getFileHash();
457 458
}

459
const QString ProjectClip::getFileHash()
460
{
461 462 463
    QByteArray fileData;
    QByteArray fileHash;
    switch (m_type) {
464
    case SlideShow:
465
        fileData = clipUrl().toUtf8();
466 467 468
        fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
        break;
    case Text:
469
        fileData = ClipController::property(QStringLiteral("xmldata")).toUtf8();
470 471 472
        fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
        break;
    case QText:
473
        fileData = ClipController::property(QStringLiteral("text")).toUtf8();
474 475 476
        fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
        break;
    case Color:
477
        fileData = ClipController::property(QStringLiteral("resource")).toUtf8();
478 479 480
        fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
        break;
    default:
481
        QFile file(clipUrl());
482 483 484 485 486
        if (file.open(QIODevice::ReadOnly)) { // write size and hash only if resource points to a file
            /*
             * 1 MB = 1 second per 450 files (or faster)
             * 10 MB = 9 seconds per 450 files (or faster)
             */
487 488
            if (file.size() > 2000000) {
                fileData = file.read(1000000);
489
                if (file.seek(file.size() - 1000000)) {
490
                    fileData.append(file.readAll());
491 492
                }
            } else {
493
                fileData = file.readAll();
494
            }
495
            file.close();
496
            ClipController::setProperty(QStringLiteral("kdenlive:file_size"), QString::number(file.size()));
497
            fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
498 499 500 501 502
        }
        break;
    }
    if (fileHash.isEmpty()) {
        return QString();
503 504
    }
    QString result = fileHash.toHex();
505
    ClipController::setProperty(QStringLiteral("kdenlive:file_hash"), result);
506
    return result;
507
}
508 509 510

double ProjectClip::getOriginalFps() const
{
511
    return originalFps();
512
}
513 514 515

bool ProjectClip::hasProxy() const
{
516
    QString proxy = getProducerProperty(QStringLiteral("kdenlive:proxy"));
517 518 519
    if (proxy.isEmpty() || proxy == QLatin1String("-")) {
        return false;
    }
520 521 522
    return true;
}

Laurent Montel's avatar
Laurent Montel committed
523
void ProjectClip::setProperties(const QMap<QString, QString> &properties, bool refreshPanel)
524 525
{
    QMapIterator<QString, QString> i(properties);
Laurent Montel's avatar
Laurent Montel committed
526
    QMap<QString, QString> passProperties;
527
    bool refreshAnalysis = false;
528
    bool reload = false;
529
    bool refreshOnly = true;
530 531
    // Some properties also need to be passed to track producers
    QStringList timelineProperties;
Laurent Montel's avatar
Laurent Montel committed
532 533
    if (properties.contains(QStringLiteral("templatetext"))) {
        m_description = properties.value(QStringLiteral("templatetext"));
534
        static_cast<ProjectItemModel*>(m_model)->bin()->emitItemUpdated(this);
535 536
        refreshPanel = true;
    }
537
    timelineProperties << QStringLiteral("force_aspect_ratio") << QStringLiteral("video_index") << QStringLiteral("audio_index") << QStringLiteral("set.force_full_luma") << QStringLiteral("full_luma") << QStringLiteral("threads") << QStringLiteral("force_colorspace") << QStringLiteral("force_tff") << QStringLiteral("force_progressive") << QStringLiteral("force_fps");
538
    QStringList keys;
539
    keys << QStringLiteral("luma_duration") << QStringLiteral("luma_file") << QStringLiteral("fade") << QStringLiteral("ttl") << QStringLiteral("softness") << QStringLiteral("crop") << QStringLiteral("animation");
540 541
    while (i.hasNext()) {
        i.next();
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
542
        setProducerProperty(i.key(), i.value());
543 544
        if (m_type == SlideShow && keys.contains(i.key())) {
            reload = true;
545
            refreshOnly = false;
546
        }
547 548 549
        if (i.key().startsWith(QLatin1String("kdenlive:clipanalysis"))) {
            refreshAnalysis = true;
        }
550 551 552
        if (timelineProperties.contains(i.key())) {
            passProperties.insert(i.key(), i.value());
        }
553
    }
554 555
    if (properties.contains(QStringLiteral("kdenlive:proxy"))) {
        QString value = properties.value(QStringLiteral("kdenlive:proxy"));
556
        // If value is "-", that means user manually disabled proxy on this clip
557
        if (value.isEmpty() || value == QLatin1String("-")) {
558
            // reset proxy
559 560
            if (static_cast<ProjectItemModel*>(m_model)->bin()->hasPendingJob(m_id, AbstractClipJob::PROXYJOB)) {
                static_cast<ProjectItemModel*>(m_model)->bin()->discardJobs(m_id, AbstractClipJob::PROXYJOB);
561
            } else {
562 563
                reloadProducer();
            }
564
        } else {
565
            // A proxy was requested, make sure to keep original url
566
            setProducerProperty(QStringLiteral("kdenlive:originalurl"), url());
567
            static_cast<ProjectItemModel*>(m_model)->bin()->startJob(m_id, AbstractClipJob::PROXYJOB);
568
        }
569
    } else if (properties.contains(QStringLiteral("resource")) || properties.contains(QStringLiteral("templatetext")) || properties.contains(QStringLiteral("autorotate"))) {
570
        // Clip resource changed, update thumbnail
571
        if (m_type != Color) {
572
            reloadProducer();
573 574
        } else {
            reload = true;
575
        }
576
    }
577
    if (properties.contains(QStringLiteral("xmldata")) || !passProperties.isEmpty()) {
578
        reload = true;
579
    }
580 581 582
    if (refreshAnalysis) {
        emit refreshAnalysisPanel();
    }
583
    if (properties.contains(QStringLiteral("length")) || properties.contains(QStringLiteral("kdenlive:duration"))) {
584 585
        m_duration = getStringDuration();
        static_cast<ProjectItemModel*>(m_model)->bin()->emitItemUpdated(this);
586 587
    }

588 589
    if (properties.contains(QStringLiteral("kdenlive:clipname"))) {
        m_name = properties.value(QStringLiteral("kdenlive:clipname"));
590
        refreshPanel = true;
591
        static_cast<ProjectItemModel*>(m_model)->bin()->emitItemUpdated(this);
592
    }
593 594 595 596
    if (refreshPanel) {
        // Some of the clip properties have changed through a command, update properties panel
        emit refreshPropertiesPanel();
    }
597
    if (reload) {
598
        // producer has changed, refresh monitor and thumbnail
599
        reloadProducer(refreshOnly);
600
        static_cast<ProjectItemModel*>(m_model)->bin()->refreshClip(m_id);
601
    }
602
    if (!passProperties.isEmpty()) {
603
        static_cast<ProjectItemModel*>(m_model)->bin()->updateTimelineProducers(m_id, passProperties);
604
    }
605 606
}

607
void ProjectClip::setJobStatus(int jobType, int status, int progress, const QString &statusMessage)
608
{
609
    m_jobType = (AbstractClipJob::JOBTYPE) jobType;
610
    if (progress > 0) {
611 612 613
        if (m_jobProgress == progress) {
            return;
        }
614
        m_jobProgress = progress;
615
    } else {
616
        m_jobProgress = status;
617 618 619
        if (m_jobType == AbstractClipJob::PROXYJOB && (status == JobAborted || status == JobCrashed)) {
            setProducerProperty(QStringLiteral("kdenlive:proxy"), QStringLiteral("-"));
        }
620 621
        if ((status == JobAborted || status == JobCrashed  || status == JobDone) && !statusMessage.isEmpty()) {
            m_jobMessage = statusMessage;
622
            static_cast<ProjectItemModel*>(m_model)->bin()->emitMessage(statusMessage, 100, OperationCompletedMessage);
623
        }
624
    }
625
    static_cast<ProjectItemModel*>(m_model)->bin()->emitItemUpdated(this);
626
}
627

628 629
ClipPropertiesController *ProjectClip::buildProperties(QWidget *parent)
{
630
    ClipPropertiesController *panel = new ClipPropertiesController(static_cast<ProjectItemModel*>(m_model)->bin()->projectTimecode(), static_cast<ClipController*>(this), parent);
Laurent Montel's avatar
Laurent Montel committed
631 632
    connect(this, &ProjectClip::refreshPropertiesPanel, panel, &ClipPropertiesController::slotReloadProperties);
    connect(this, &ProjectClip::refreshAnalysisPanel, panel, &ClipPropertiesController::slotFillAnalysisData);
633 634 635
    return panel;
}

636 637
void ProjectClip::updateParentInfo(const QString &folderid, const QString &foldername)
{
638 639
    Q_UNUSED(foldername);
    ClipController::setProperty(QStringLiteral("kdenlive:folderid"), folderid);
640 641
}

Laurent Montel's avatar
Laurent Montel committed
642
bool ProjectClip::matches(const QString &condition)
643 644
{
    //TODO
645
    Q_UNUSED(condition)
646 647 648
    return true;
}

649
const QString ProjectClip::codec(bool audioCodec) const
650
{
651
    return codec(audioCodec);
652
}
653

654
bool ProjectClip::rename(const QString &name, int column)
655
{
Laurent Montel's avatar
Laurent Montel committed
656 657
    QMap<QString, QString> newProperites;
    QMap<QString, QString> oldProperites;
658 659
    bool edited = false;
    switch (column) {
660 661 662 663
    case 0:
        if (m_name == name) {
            return false;
        }
664
        // Rename clip
665 666
        oldProperites.insert(QStringLiteral("kdenlive:clipname"), m_name);
        newProperites.insert(QStringLiteral("kdenlive:clipname"), name);
667 668 669
        m_name = name;
        edited = true;
        break;
670 671 672 673
    case 2:
        if (m_description == name) {
            return false;
        }
674
        // Rename clip
675 676 677 678 679 680 681
        if (m_type == TextTemplate) {
            oldProperites.insert(QStringLiteral("templatetext"), m_description);
            newProperites.insert(QStringLiteral("templatetext"), name);
        } else {
            oldProperites.insert(QStringLiteral("kdenlive:description"), m_description);
            newProperites.insert(QStringLiteral("kdenlive:description"), name);
        }
682 683 684 685 686
        m_description = name;
        edited = true;
        break;
    }
    if (edited) {
687
        static_cast<ProjectItemModel*>(m_model)->bin()->slotEditClipCommand(m_id, oldProperites, newProperites);
688 689
    }
    return edited;
690 691
}

Laurent Montel's avatar
Laurent Montel committed
692
void ProjectClip::addClipMarker(QList<CommentedTime> newMarkers, QUndoCommand *groupCommand)
693
{
Laurent Montel's avatar
Laurent Montel committed
694
    QList<CommentedTime> oldMarkers;
695
    for (int i = 0; i < newMarkers.count(); ++i) {
696
        CommentedTime oldMarker = markerAt(newMarkers.at(i).time());
697 698 699 700 701 702 703 704 705 706 707
        if (oldMarker == CommentedTime()) {
            oldMarker = newMarkers.at(i);
            oldMarker.setMarkerType(-1);
        }
        oldMarkers << oldMarker;
    }
    (void) new AddMarkerCommand(this, oldMarkers, newMarkers, groupCommand);
}

bool ProjectClip::deleteClipMarkers(QUndoCommand *command)
{
Laurent Montel's avatar
Laurent Montel committed
708
    QList<CommentedTime> markers = commentedSnapMarkers();
709 710 711
    if (markers.isEmpty()) {
        return false;
    }
Laurent Montel's avatar
Laurent Montel committed
712
    QList<CommentedTime> newMarkers;
713 714 715 716 717 718
    for (int i = 0; i < markers.size(); ++i) {
        CommentedTime marker = markers