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
/* ============================================================
 *
 * This file is a part of digiKam project
 * https://www.digikam.org
 *
 * Date        : 2018-06-29
 * Description : a tool to export images to Twitter social network
 *
 * SPDX-FileCopyrightText: 2018 by Tarek Talaat <tarektalaat93 at gmail dot com>
 * SPDX-FileCopyrightText: 2019 by Thanh Trung Dinh <dinhthanhtrung1996 at gmail dot com>
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 *
 * ============================================================ */

#pragma once

// Qt includes

#include <QByteArray>
#include <QString>
#include <QList>

// Local includes

#include "wstoolutils.h"

using namespace Digikam;

namespace DigikamGenericTwitterPlugin
{

static const int MAX_MEDIA_SIZE = 1048576;

class TwMPForm
{

public:

    TwMPForm();
    ~TwMPForm() = default;

    void reset();
    QByteArray fileHeader(const QString& imgPath);
    bool addFile(const QString& imgPath, bool fragmented = false);
    QByteArray createPair(const QByteArray& name, const QByteArray& value);
    bool addPair(const QByteArray& pair);
    void finish();
    QByteArray border();

    int numberOfChunks()           const;
    QString contentType()          const;
    QByteArray formData()          const;<--- Function 'formData()' should return member 'm_buffer' by const reference.
    QByteArray getChunk(int index) const;

private:

    void formChunks(const QByteArray& data);

private:

    QByteArray        m_buffer;
    QByteArray        m_boundary = QByteArray("00TwDK")                          +
                                   WSToolUtils::randomString(42 + 13).toLatin1() +
                                   QByteArray("KDwT99");
    QList<QByteArray> m_chunks;
};

} // namespace DigikamGenericTwitterPlugin