~ubuntu-branches/debian/jessie/attica-kf5/jessie

« back to all changes in this revision

Viewing changes to src/putjob.cpp

  • Committer: Package Import Robot
  • Author(s): Maximiliano Curia
  • Date: 2014-07-15 10:53:09 UTC
  • Revision ID: package-import@ubuntu.com-20140715105309-nnjxenwcs6h4qznf
Tags: upstream-5.0.0
ImportĀ upstreamĀ versionĀ 5.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    This file is part of KDE.
 
3
 
 
4
    Copyright (c) 2011 Laszlo Papp <djszapi@archlinux.us>
 
5
 
 
6
    This library is free software; you can redistribute it and/or
 
7
    modify it under the terms of the GNU Lesser General Public
 
8
    License as published by the Free Software Foundation; either
 
9
    version 2.1 of the License, or (at your option) version 3, or any
 
10
    later version accepted by the membership of KDE e.V. (or its
 
11
    successor approved by the membership of KDE e.V.), which shall
 
12
    act as a proxy defined in Section 6 of version 3 of the license.
 
13
 
 
14
    This library is distributed in the hope that it will be useful,
 
15
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
17
    Lesser General Public License for more details.
 
18
 
 
19
    You should have received a copy of the GNU Lesser General Public
 
20
    License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 
21
 
 
22
*/
 
23
 
 
24
#include "putjob.h"
 
25
 
 
26
#include <QXmlStreamReader>
 
27
#include <QDebug>
 
28
 
 
29
#include <QtNetwork/QNetworkAccessManager>
 
30
 
 
31
#include "platformdependent_v2.h"
 
32
 
 
33
using namespace Attica;
 
34
 
 
35
PutJob::PutJob(PlatformDependent *internals, const QNetworkRequest &request, QIODevice *iodevice)
 
36
    : BaseJob(internals), m_ioDevice(iodevice), m_request(request)
 
37
{
 
38
}
 
39
 
 
40
Attica::PutJob::PutJob(PlatformDependent *internals, const QNetworkRequest &request, const QByteArray &byteArray)
 
41
    : BaseJob(internals), m_ioDevice(0), m_byteArray(byteArray), m_request(request)
 
42
{
 
43
}
 
44
 
 
45
PutJob::PutJob(PlatformDependent *internals, const QNetworkRequest &request, const StringMap &parameters)
 
46
    : BaseJob(internals), m_ioDevice(0), m_request(request)
 
47
{
 
48
    // Create put data
 
49
    int j = 0;
 
50
    for (StringMap::const_iterator i = parameters.begin(); i != parameters.end(); ++i) {
 
51
        if (j++ > 0) {
 
52
            m_byteArray.append('&');
 
53
        }
 
54
        m_byteArray.append(QUrl::toPercentEncoding(i.key()));
 
55
        m_byteArray.append('=');
 
56
        m_byteArray.append(QUrl::toPercentEncoding(i.value()));
 
57
    }
 
58
}
 
59
 
 
60
QNetworkReply *PutJob::executeRequest()
 
61
{
 
62
    Attica::PlatformDependentV2 *platformDependentV2 = dynamic_cast<Attica::PlatformDependentV2 *>(internals());
 
63
    if (!platformDependentV2) {
 
64
        return 0;
 
65
    }
 
66
 
 
67
    if (m_ioDevice) {
 
68
        return platformDependentV2->put(m_request, m_ioDevice);
 
69
    } else {
 
70
        return platformDependentV2->put(m_request, m_byteArray);
 
71
    }
 
72
}
 
73
 
 
74
void PutJob::parse(const QString &xmlString)
 
75
{
 
76
    //qDebug() << "PutJob::parse" << xmlString;
 
77
    QXmlStreamReader xml(xmlString);
 
78
    Metadata data;
 
79
    while (!xml.atEnd()) {
 
80
        xml.readNext();
 
81
 
 
82
        if (xml.isStartElement()) {
 
83
            if (xml.name() == QLatin1String("meta")) {
 
84
                while (!xml.atEnd()) {
 
85
                    xml.readNext();
 
86
                    if (xml.isEndElement() && xml.name() == QLatin1String("meta")) {
 
87
                        break;
 
88
                    } else if (xml.isStartElement()) {
 
89
                        if (xml.name() == QLatin1String("status")) {
 
90
                            data.setStatusString(xml.readElementText());
 
91
                        } else if (xml.name() == QLatin1String("statuscode")) {
 
92
                            data.setStatusCode(xml.readElementText().toInt());
 
93
                        } else if (xml.name() == QLatin1String("message")) {
 
94
                            data.setMessage(xml.readElementText());
 
95
                        } else if (xml.name() == QLatin1String("totalitems")) {
 
96
                            data.setTotalItems(xml.readElementText().toInt());
 
97
                        } else if (xml.name() == QLatin1String("itemsperpage")) {
 
98
                            data.setItemsPerPage(xml.readElementText().toInt());
 
99
                        }
 
100
                    }
 
101
                }
 
102
            } else if (xml.name() == QLatin1String("data")) {
 
103
                while (!xml.atEnd()) {
 
104
                    xml.readNext();
 
105
                    if (xml.isEndElement() && xml.name() == QLatin1String("data")) {
 
106
                        break;
 
107
                    } else if (xml.isStartElement()) {
 
108
                        if (xml.name() == QLatin1String("projectid")) {
 
109
                            data.setResultingId(xml.readElementText());
 
110
                        } if (xml.name() == QLatin1String("buildjobid")) {
 
111
                            data.setResultingId(xml.readElementText());
 
112
                        }
 
113
 
 
114
                    }
 
115
                }
 
116
            }
 
117
        }
 
118
    }
 
119
    setMetadata(data);
 
120
}
 
121
 
 
122
#include "putjob.moc"