Menu

[5212b7]: / downloadagent.cpp  Maximize  Restore  History

Download this file

83 lines (65 with data), 1.7 kB

 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
#include "downloadagent.h"
#include "branchitem.h"
#include "mainwindow.h"
#include "vymmodel.h"
extern Main *mainWindow;
extern QDir vymBaseDir;
extern bool debug;
DownloadAgent::DownloadAgent (const QUrl &url, BranchItem *bi)
{
if (!bi)
{
qWarning ("Const DownloadAgent: bi==NULL");
delete (this);
return;
}
branchID=bi->getID();
VymModel *model=bi->getModel();
modelID=model->getModelID();
//qDebug()<<"Constr. DownloadAgent for "<<branchID;
connect(&networkManager, SIGNAL(finished(QNetworkReply*)),
SLOT(downloadFinished(QNetworkReply*)));
QNetworkRequest request(url);
QNetworkReply *reply = networkManager.get(request);
currentDownloads.append(reply);
}
DownloadAgent::~DownloadAgent ()
{
//qDebug()<<"Destr. DownloadAgent for "<<branchID;
}
void DownloadAgent::downloadFinished (QNetworkReply *reply)
{
qDebug()<<"DownloadAgent::downloadFinished";
QUrl url = reply->url();
if (reply->error())
{
fprintf(stderr, "VymModel: Download of %s failed: %s\n", url.toEncoded().constData(),
qPrintable(reply->errorString()));
} else
{
QByteArray a=reply->readAll();
VymModel *model=mainWindow->getModel (modelID);
if (model)
{
BranchItem *dst=(BranchItem*)(model->findID (branchID));
if (dst)
{
ImageItem *ii=model->createImage(dst);
if (ii)
{
QImage i;
if (!i.loadFromData (a))
fprintf(stderr, "VymModel: Adding of %s failed.\n", url.toEncoded().constData());
else
{
ii->load (i);
model->reposition();
}
}
}
}
}
currentDownloads.removeAll(reply);
reply->deleteLater();
deleteLater();
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.