|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "nmuiheaders.h" |
|
20 |
|
21 /*! |
|
22 \class NmViewerViewNetReply |
|
23 \brief Mail viewer network reply class |
|
24 */ |
|
25 |
|
26 /*! |
|
27 Constructor |
|
28 */ |
|
29 NmViewerViewNetReply::NmViewerViewNetReply(QVariant data) |
|
30 : QNetworkReply(), |
|
31 mDataArray(data.toByteArray()), |
|
32 mReadIndex(0) |
|
33 { |
|
34 open(ReadWrite); |
|
35 setReadBufferSize(mDataArray.length()); |
|
36 // QNetworkAccessManager starts listening the signals only |
|
37 // after the construction, so we cannot signal reply to be |
|
38 // ready instantly. We need to emit the signals after the |
|
39 // construction. |
|
40 QTimer::singleShot(100, this, SLOT(signalReady())); |
|
41 } |
|
42 |
|
43 /*! |
|
44 Destructor |
|
45 */ |
|
46 NmViewerViewNetReply::~NmViewerViewNetReply() |
|
47 { |
|
48 } |
|
49 |
|
50 /*! |
|
51 signalReady |
|
52 */ |
|
53 void NmViewerViewNetReply::signalReady() |
|
54 { |
|
55 emit readyRead(); |
|
56 emit finished(); |
|
57 } |
|
58 |
|
59 /*! |
|
60 setOriginalRequest. This function is created to provide access to call |
|
61 base class' protected function setRequest |
|
62 */ |
|
63 void NmViewerViewNetReply::setOriginalRequest(const QNetworkRequest &request) |
|
64 { |
|
65 setRequest(request); |
|
66 } |
|
67 |
|
68 /*! |
|
69 readData |
|
70 */ |
|
71 qint64 NmViewerViewNetReply::readData(char *data, qint64 maxlen) |
|
72 { |
|
73 qint64 i = 0; |
|
74 const qint64 dataLength(mDataArray.length()); |
|
75 |
|
76 if (0 >= dataLength || !data) { |
|
77 return -1; |
|
78 } |
|
79 |
|
80 for (i = 0; i < maxlen && mReadIndex < dataLength; i++, mReadIndex++) { |
|
81 data[i] = mDataArray.at(mReadIndex); |
|
82 } |
|
83 return i; |
|
84 } |
|
85 |
|
86 /*! |
|
87 readBufferSize. Returns the size of the read buffer, in bytes. |
|
88 */ |
|
89 qint64 NmViewerViewNetReply::readBufferSize() const |
|
90 { |
|
91 return mDataArray.length(); |
|
92 } |
|
93 |
|
94 /*! |
|
95 bytesAvailable. Returns the number of bytes that are available for reading. |
|
96 This function is commonly used with sequential devices to determine the number of bytes to |
|
97 allocate in a buffer before reading. Base implementation is called in order to |
|
98 include the size of QIODevices' buffer. |
|
99 */ |
|
100 qint64 NmViewerViewNetReply::bytesAvailable() const |
|
101 { |
|
102 return mDataArray.length() + QIODevice::bytesAvailable(); |
|
103 } |
|
104 |
|
105 /*! |
|
106 isSequential. Returns true if this device is sequential. |
|
107 */ |
|
108 bool NmViewerViewNetReply::isSequential () const |
|
109 { |
|
110 return false; |
|
111 } |
|
112 |
|
113 /*! |
|
114 abort. Aborts the operation immediately and close down any |
|
115 network connections still open |
|
116 */ |
|
117 void NmViewerViewNetReply::abort() |
|
118 { |
|
119 } |
|
120 |