Cppcheck - HTML report - digiKam-master-rev-960d3ce42d

# Cppcheck report - digiKam-master-rev-960d3ce42d: ../../core/libs/iojobs/iojobdata.cpp

      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    /* ============================================================
     *
     * This file is a part of digiKam project
     * https://www.digikam.org
     *
     * Date        : 2018-02-24
     * Description : Container for IOJob data.
     *
     * SPDX-FileCopyrightText: 2018 by Maik Qualmann <metzpinguin at gmail dot com>
     *
     * SPDX-License-Identifier: GPL-2.0-or-later
     *
     * ============================================================ */

    #include "iojobdata.h"

    // Qt includes

    #include <QRecursiveMutex>
    #include <QMutexLocker>

    // Local includes

    #include "album.h"
    #include "iteminfo.h"
    #include "digikam_debug.h"

    namespace Digikam
    {

    class Q_DECL_HIDDEN IOJobData::Private
    {
    public:

        Private() = default;

        int                operation        = Unknown;
        int                fileConflict     = Continue;

        bool               errorOrCancel    = false;

        PAlbum*            srcAlbum         = nullptr;
        PAlbum*            destAlbum        = nullptr;

        DTrashItemInfoList trashItemList;
        QMap<QUrl, QUrl>   changeDestMap;
        QList<ItemInfo>    itemInfosList;
        QList<QUrl>        sourceUrlList;
        QList<int>         sourceAlbumIds;

        QUrl               destUrl;

        QString            progressId;
        QDateTime          jobTime          = QDateTime::currentDateTime();

        QRecursiveMutex    mutex;
    };

    IOJobData::IOJobData(int operation,
                         const QList<ItemInfo>& infos,
                         PAlbum* const dest)
        : d(new Private)
    {
        d->operation = operation;
        d->destAlbum = dest;

        setItemInfos(infos);

        if (d->destAlbum)
        {
            d->destUrl = d->destAlbum->fileUrl();
        }
    }

    IOJobData::IOJobData(int operation,
                         const QList<ItemInfo>& infos,
                         const QUrl& dest)
        : d(new Private)
    {
        d->operation = operation;
        d->destUrl   = dest;

        setItemInfos(infos);
    }

    IOJobData::IOJobData(int operation,
                         const QList<QUrl>& urls,
                         PAlbum* const dest)
        : d(new Private)
    {
        d->operation     = operation;
        d->sourceUrlList = urls;
        d->destAlbum     = dest;

        if (d->destAlbum)
        {
            d->destUrl = d->destAlbum->fileUrl();
        }
    }

    IOJobData::IOJobData(int operation,
                         PAlbum* const src,
                         PAlbum* const dest)
        : d(new Private)
    {
        d->operation = operation;
        d->srcAlbum  = src;
        d->destAlbum = dest;

        if (d->srcAlbum)
        {
            d->sourceUrlList << d->srcAlbum->fileUrl();
        }

        if (d->destAlbum)
        {
            d->destUrl = d->destAlbum->fileUrl();
        }
    }

    IOJobData::IOJobData(int operation,
                         const QList<QUrl>& urls,
                         const QUrl& dest)
        : d(new Private)
    {
        d->operation     = operation;
        d->sourceUrlList = urls;
        d->destUrl       = dest;
    }

    IOJobData::IOJobData(int operation,
                         const ItemInfo& info,
                         const QString& newName,
                         bool overwrite)
        : d(new Private)
    {
        d->operation = operation;

        if (overwrite)
        {
            d->fileConflict = Overwrite;
        }

        setItemInfos(QList<ItemInfo>() << info);

        d->destUrl = info.fileUrl().adjusted(QUrl::RemoveFilename);
        d->destUrl.setPath(d->destUrl.path() + newName);
    }

    IOJobData::IOJobData(int operation,
                         const DTrashItemInfoList& infos)
        : d(new Private)
    {
        d->operation     = operation;
        d->trashItemList = infos;

        // We need source URLs as dummy.

        for (const DTrashItemInfo& item : std::as_const(d->trashItemList))
        {
            d->sourceUrlList << QUrl::fromLocalFile(item.trashPath);
        }
    }

    IOJobData::~IOJobData()
    {
        delete d;
    }

    void IOJobData::setItemInfos(const QList<ItemInfo>& infos)
    {
        d->itemInfosList = infos;

        d->sourceUrlList.clear();
        d->sourceAlbumIds.clear();

        for (const ItemInfo& info : std::as_const(d->itemInfosList))
        {
            d->sourceUrlList << info.fileUrl();

            if (!d->sourceAlbumIds.contains(info.albumId()))
            {
                d->sourceAlbumIds << info.albumId();
            }
        }
    }

    void IOJobData::setSourceUrls(const QList<QUrl>& urls)
    {
        d->sourceUrlList = urls;
    }

    void IOJobData::setDestUrl(const QUrl& srcUrl,
                               const QUrl& destUrl)<--- Shadow argument
    {
        QMutexLocker locker(&d->mutex);

        d->changeDestMap.insert(srcUrl, destUrl);
    }

    void IOJobData::setProgressId(const QString& id)
    {
        d->progressId = id;
    }

    void IOJobData::setFileConflict(int fc)
    {
        d->fileConflict = fc;
    }

    void IOJobData::setErrorOrCancel(bool err)
    {
        d->errorOrCancel |= err;
    }

    int IOJobData::operation() const
    {
        return d->operation;
    }

    int IOJobData::fileConflict() const
    {
        return d->fileConflict;
    }

    bool IOJobData::errorOrCancel() const
    {
        return d->errorOrCancel;
    }

    PAlbum* IOJobData::srcAlbum() const
    {
        return d->srcAlbum;
    }

    PAlbum* IOJobData::destAlbum() const
    {
        return d->destAlbum;
    }

    QUrl IOJobData::destUrl(const QUrl& srcUrl) const
    {
        QMutexLocker locker(&d->mutex);

        if (srcUrl.isEmpty())
        {
            return d->destUrl;
        }

        return d->changeDestMap.value(srcUrl, d->destUrl);
    }

    QUrl IOJobData::getNextUrl() const
    {
        QMutexLocker locker(&d->mutex);

        QUrl url;

        if (!d->sourceUrlList.isEmpty())
        {
            url = d->sourceUrlList.takeFirst();
        }

        return url;
    }

    QString IOJobData::destName(const QUrl& srcUrl) const
    {
        QMutexLocker locker(&d->mutex);

        QUrl url = srcUrl.adjusted(QUrl::StripTrailingSlash);
        url      = d->changeDestMap.value(srcUrl, url);

        return url.fileName();
    }

    QString IOJobData::getProgressId() const
    {
        return d->progressId;
    }

    QDateTime IOJobData::jobTime() const
    {
        return d->jobTime;
    }

    ItemInfo IOJobData::findItemInfo(const QUrl& url) const
    {
        for (const ItemInfo& info : std::as_const(d->itemInfosList))
        {
            if (info.fileUrl() == url)
            {    // cppcheck-suppress useStlAlgorithm
                return info;
            }
        }

        return ItemInfo();
    }

    QList<int> IOJobData::srcAlbumIds() const
    {
        return d->sourceAlbumIds;
    }

    QList<QUrl> IOJobData::sourceUrls() const
    {
        return d->sourceUrlList;
    }

    QList<ItemInfo> IOJobData::itemInfos() const
    {
        return d->itemInfosList;
    }

    DTrashItemInfoList IOJobData::trashItems() const
    {
        return d->trashItemList;
    }

    } // namespace Digikam