16
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Trolltech hereby grants a license to use the Qt/Eclipse Integration
|
|
4 |
** plug-in (the software contained herein), in binary form, solely for the
|
|
5 |
** purpose of creating code to be used with Trolltech's Qt software.
|
|
6 |
**
|
|
7 |
** Qt Designer is licensed under the terms of the GNU General Public
|
|
8 |
** License versions 2.0 and 3.0 ("GPL License"). Trolltech offers users the
|
|
9 |
** right to use certain no GPL licensed software under the terms of its GPL
|
|
10 |
** Exception version 1.2 (http://trolltech.com/products/qt/gplexception).
|
|
11 |
**
|
|
12 |
** THIS SOFTWARE IS PROVIDED BY TROLLTECH AND ITS CONTRIBUTORS (IF ANY) "AS
|
|
13 |
** IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
14 |
** TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
|
15 |
** PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
|
16 |
** OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
17 |
** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
18 |
** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
19 |
** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
20 |
** LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
21 |
** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
22 |
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
|
23 |
**
|
|
24 |
** Since we now have the GPL exception I think that the "special exception
|
|
25 |
** is no longer needed. The license text proposed above (other than the
|
|
26 |
** special exception portion of it) is the BSD license and we have added
|
|
27 |
** the BSD license as a permissible license under the exception.
|
|
28 |
**
|
|
29 |
****************************************************************************/
|
|
30 |
|
|
31 |
#include <qdebug.h>
|
|
32 |
#include <QImage>
|
|
33 |
#include <QByteArray>
|
|
34 |
#include <qnetworkproxy.h>
|
|
35 |
#include <qfile.h>
|
|
36 |
#include "ImageDownload.h"
|
|
37 |
#include "HomeView.h"
|
|
38 |
|
|
39 |
bool downloading = false;
|
|
40 |
|
|
41 |
#define EMULATORTESTING
|
|
42 |
|
|
43 |
ImageDownload::ImageDownload(QObject *parent)
|
|
44 |
{
|
|
45 |
manager = new QNetworkAccessManager(this);
|
|
46 |
|
|
47 |
#ifdef EMULATORTESTING
|
|
48 |
qDebug()<<"Using PROXY SETTINGS!!!, change for device testing in image download";
|
|
49 |
|
|
50 |
// Reading the keys, CSM Stubbed - START
|
|
51 |
QFile winFile("c:\\data\\DoNotShare.txt");
|
|
52 |
if (!winFile.open(QIODevice::ReadOnly))
|
|
53 |
{
|
|
54 |
qDebug()<<"File to read the windows username and password could not be opened, returning!!!";
|
|
55 |
return;
|
|
56 |
}
|
|
57 |
|
|
58 |
QByteArray winArr = winFile.readAll();
|
|
59 |
QList<QByteArray> winList = winArr.split(' ');
|
|
60 |
winFile.close();
|
|
61 |
|
|
62 |
QString httpUser(winList[0]);
|
|
63 |
QString httpPass(winList[1]);
|
|
64 |
|
|
65 |
// For proxy settings on emulator only - REMOVE for device
|
|
66 |
QString httpProxy = "10.1.0.214";
|
|
67 |
QString httpPort = "3128";
|
|
68 |
|
|
69 |
//==Classes used from Network Module==
|
|
70 |
QNetworkProxy proxy;
|
|
71 |
|
|
72 |
proxy.setType(QNetworkProxy::HttpProxy);
|
|
73 |
proxy.setHostName(httpProxy);
|
|
74 |
proxy.setPort(httpPort.toInt());
|
|
75 |
proxy.setUser(httpUser);
|
|
76 |
proxy.setPassword(httpPass);
|
|
77 |
|
|
78 |
QNetworkProxy::setApplicationProxy(proxy);
|
|
79 |
#endif
|
|
80 |
}
|
|
81 |
|
|
82 |
ImageDownload::~ImageDownload()
|
|
83 |
{
|
|
84 |
if(manager)
|
|
85 |
delete manager;
|
|
86 |
}
|
|
87 |
|
|
88 |
void ImageDownload::downloadImage(HomeView *homeView, QString name, QUrl url, const SmfItemIdentifier &identifier)
|
|
89 |
{
|
|
90 |
m_homeView = homeView;
|
|
91 |
m_identifier = identifier;
|
|
92 |
qDebug()<<"Inside ImageDownload::downloadImage(name, url)";
|
|
93 |
QNetworkRequest request;
|
|
94 |
request.setUrl(url);
|
|
95 |
qDebug()<<"URL of image to be downloaded = "<<url;
|
|
96 |
connect(manager, SIGNAL(finished(QNetworkReply*)),
|
|
97 |
this, SLOT(networkReplyFinished(QNetworkReply*)));
|
|
98 |
|
|
99 |
QNetworkReply* reply = manager->get(request);
|
|
100 |
m_nameReplyHash.insert(name, reply);
|
|
101 |
}
|
|
102 |
|
|
103 |
|
|
104 |
|
|
105 |
void ImageDownload::networkReplyFinished ( QNetworkReply *aNetworkReply )
|
|
106 |
{
|
|
107 |
qDebug()<<"Error code if any = "<<aNetworkReply->error();
|
|
108 |
qDebug()<<"Response for reply = "<<aNetworkReply;
|
|
109 |
|
|
110 |
QByteArray response = aNetworkReply->readAll();
|
|
111 |
qDebug()<<"Response Size :"<<response.size();
|
|
112 |
if(response.size())
|
|
113 |
{
|
|
114 |
QImage image = QImage::fromData(response);
|
|
115 |
|
|
116 |
QString fileName("c:\\data\\");
|
|
117 |
fileName.append(m_nameReplyHash.key(aNetworkReply));
|
|
118 |
fileName.append(".jpg");
|
|
119 |
|
|
120 |
qDebug()<<"Image URL :"<<fileName;
|
|
121 |
|
|
122 |
bool saved = image.save(fileName, "JPG", -1);
|
|
123 |
qDebug()<<"Image saved ? "<<saved;
|
|
124 |
m_nameReplyHash.remove(m_nameReplyHash.key(aNetworkReply));
|
|
125 |
if(m_nameReplyHash.count() == 0)
|
|
126 |
{
|
|
127 |
downloading = false;
|
|
128 |
if(SmfFriendsFetch == m_identifier)
|
|
129 |
m_homeView->populateFriendsWidget();
|
|
130 |
else if(SmfPostsFetch == m_identifier)
|
|
131 |
m_homeView->populatePostsWidget();
|
|
132 |
else if(SmfPhotosFetch == m_identifier)
|
|
133 |
m_homeView->populatePhotosGridView();
|
|
134 |
// ToDo:- for albums, photos and activity
|
|
135 |
else
|
|
136 |
qDebug()<<"Unknown request for download, so do nothing";
|
|
137 |
}
|
|
138 |
}
|
|
139 |
else
|
|
140 |
{
|
|
141 |
qDebug()<<"Response data is NULL";
|
|
142 |
}
|
|
143 |
}
|