~ubuntu-branches/ubuntu/trusty/kvirc/trusty-proposed

« back to all changes in this revision

Viewing changes to src/modules/http/httpfiletransfer.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kai Wasserbäch, Kai Wasserbäch, Raúl Sánchez Siles
  • Date: 2011-02-12 10:40:21 UTC
  • mfrom: (14.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110212104021-5mh4f75jlku20mnt
The combined "Twisted Experiment" and "Nocturnal Raid" release.

[ Kai Wasserbäch ]
* Synced to upstream's SVN revision 5467.
* debian/rules:
  - Added .PHONY line.
  - Resurrect -DMANUAL_REVISION, got lost somewhere and we build SVN
    revisions again.
  - Replace "-DWITH_NO_EMBEDDED_CODE=YES" with "-DWANT_CRYPTOPP=YES".
  - Change the remaining -DWITH/-DWITHOUT to the new -DWANT syntax.
* debian/control:
  - Removed DMUA, I'm a DD now.
  - Changed my e-mail address.
  - Removed unneeded relationships (no upgrades over two releases are
    supported).
  - Fix Suggests for kvirc-dbg.
  - kvirc-data: Make the "Suggests: kvirc" a Recommends, doesn't make much
    sense to install the -data package without the program.
* debian/source/local-options: Added with "unapply-patches".
* debian/kvirc.lintian-overrides: Updated to work for 4.1.1.
* debian/patches/21_make_shared-mime-info_B-D_superfluous.patch: Updated.
* debian/kvirc-data.install: Added .notifyrc.

[ Raúl Sánchez Siles ]
* Stating the right version where kvirc-data break and replace should happen.
* Fixing link to license file.
* Added French and Portuguese man pages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//=============================================================================
2
 
//
3
 
//   File : httpfiletransfer.h
4
 
//   Creation date : Tue Apr 22 2003 02:00:12 GMT by Szymon Stefanek
5
 
//
6
 
//   This config is part of the KVirc irc client distribution
7
 
//   Copyright (C) 2003-2008 Szymon Stefanek (pragma at kvirc dot net)
8
 
//
9
 
//   This program is FREE software. You can redistribute it and/or
10
 
//   modify it under the terms of the GNU General Public License
11
 
//   as published by the Free Software Foundation; either version 2
12
 
//   of the License, or (at your opinion) any later version.
13
 
//
14
 
//   This program 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.
17
 
//   See the GNU General Public License for more details.
18
 
//
19
 
//   You should have received a copy of the GNU General Public License
20
 
//   along with this program. If not, write to the Free Software Foundation,
21
 
//   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22
 
//
23
 
//=============================================================================
24
 
 
25
 
#include "httpfiletransfer.h"
26
 
 
27
 
#include "kvi_app.h"
28
 
#include "kvi_out.h"
29
 
#include "kvi_locale.h"
30
 
#include "kvi_window.h"
31
 
#include "kvi_iconmanager.h"
32
 
#include "kvi_netutils.h"
33
 
#include "kvi_kvs_eventtriggers.h"
34
 
#include "kvi_console.h"
35
 
#include "kvi_kvs_script.h"
36
 
#include "kvi_tal_popupmenu.h"
37
 
 
38
 
#include <QPainter>
39
 
 
40
 
static KviPointerList<KviHttpFileTransfer> * g_pHttpFileTransfers = 0;
41
 
static QPixmap * g_pHttpIcon = 0;
42
 
 
43
 
 
44
 
KviHttpFileTransfer::KviHttpFileTransfer()
45
 
: KviFileTransfer()
46
 
{
47
 
        init(); // ensure we're initialized
48
 
        g_pHttpFileTransfers->append(this);
49
 
 
50
 
        m_tStartTime = kvi_unixTime();
51
 
        m_tTransferStartTime = 0;
52
 
        m_tTransferEndTime = 0;
53
 
 
54
 
        m_bNotifyCompletion = true;
55
 
        m_bAutoClean = false;
56
 
        m_pAutoCleanTimer = 0;
57
 
        m_bNoOutput = false;
58
 
 
59
 
        m_pHttpRequest = new KviHttpRequest();
60
 
 
61
 
        connect(m_pHttpRequest,SIGNAL(status(const QString &)),this,SLOT(statusMessage(const QString &)));
62
 
        connect(m_pHttpRequest,SIGNAL(terminated(bool)),this,SLOT(transferTerminated(bool)));
63
 
        connect(m_pHttpRequest,SIGNAL(header(KviPointerHashTable<const char *,KviStr> *)),this,SLOT(headersReceived(KviPointerHashTable<const char *,KviStr> *)));
64
 
        connect(m_pHttpRequest,SIGNAL(resolvingHost(const QString &)),this,SLOT(resolvingHost(const QString &)));
65
 
        connect(m_pHttpRequest,SIGNAL(requestSent(const QStringList &)),this,SLOT(requestSent(const QStringList &)));
66
 
        connect(m_pHttpRequest,SIGNAL(contactingHost(const QString &)),this,SLOT(contactingHost(const QString &)));
67
 
        connect(m_pHttpRequest,SIGNAL(receivedResponse(const QString &)),this,SLOT(receivedResponse(const QString &)));
68
 
        connect(m_pHttpRequest,SIGNAL(connectionEstabilished()),this,SLOT(connectionEstabilished()));
69
 
 
70
 
        m_eGeneralStatus = Initializing;
71
 
        m_szStatusString = __tr2qs_ctx("Initializing","http");
72
 
}
73
 
 
74
 
KviHttpFileTransfer::~KviHttpFileTransfer()
75
 
{
76
 
        g_pHttpFileTransfers->removeRef(this);
77
 
        delete m_pHttpRequest;
78
 
        if(m_pAutoCleanTimer)
79
 
        {
80
 
                m_pAutoCleanTimer->stop();
81
 
                delete m_pAutoCleanTimer;
82
 
        }
83
 
}
84
 
 
85
 
void KviHttpFileTransfer::autoClean()
86
 
{
87
 
        killTimer(m_TimerId);
88
 
        die();
89
 
}
90
 
 
91
 
QString KviHttpFileTransfer::localFileName()
92
 
{
93
 
        return m_pHttpRequest->fileName();
94
 
}
95
 
 
96
 
void KviHttpFileTransfer::abort()
97
 
{
98
 
        m_pHttpRequest->abort();
99
 
}
100
 
 
101
 
void KviHttpFileTransfer::fillContextPopup(KviTalPopupMenu * m)
102
 
{
103
 
        int id = m->insertItem(__tr2qs_ctx("Abort","http"),this,SLOT(abort()));
104
 
        if(!active())m->setItemEnabled(id,false);
105
 
}
106
 
 
107
 
bool KviHttpFileTransfer::active()
108
 
{
109
 
        return ((m_eGeneralStatus == Connecting) || (m_eGeneralStatus == Downloading));
110
 
}
111
 
 
112
 
void KviHttpFileTransfer::displayPaint(QPainter * p,int column, QRect rect)
113
 
{
114
 
        int width = rect.width(), height = rect.height();
115
 
        QString txt;
116
 
        bool bIsTerminated = ((m_eGeneralStatus == Success) || (m_eGeneralStatus == Failure));
117
 
 
118
 
        switch(column)
119
 
        {
120
 
                case COLUMN_TRANSFERTYPE:
121
 
                {
122
 
                        int offset = 0;
123
 
                        switch(m_eGeneralStatus)
124
 
                        {
125
 
                                case Initializing:
126
 
                                case Connecting: offset = 0; break;
127
 
                                case Downloading: offset = 48; break;
128
 
                                case Success: offset = 96; break;
129
 
                                case Failure: offset = 144; break;
130
 
                        }
131
 
                        p->drawPixmap(rect.left() + 3, rect.top() + 3,*g_pHttpIcon,offset,0,48,64);
132
 
                }
133
 
                break;
134
 
                case COLUMN_FILEINFO:
135
 
                {
136
 
                        QFontMetrics fm(p->font());
137
 
 
138
 
                        QString szFrom = __tr2qs_ctx("From: ","http");
139
 
                        QString szTo   = __tr2qs_ctx("To: ","http");
140
 
 
141
 
                        int daW1 = fm.width(szFrom);
142
 
                        int daW2 = fm.width(szTo);
143
 
                        if(daW1 < daW2)daW1 = daW2;
144
 
                        int iLineSpacing = fm.lineSpacing();
145
 
 
146
 
                        p->setPen(Qt::black);
147
 
 
148
 
                        int iY = rect.top() + 4;
149
 
 
150
 
                        p->drawText(rect.left() + 4 + daW1,iY,width - (8 + daW1),height - 8,Qt::AlignTop | Qt::AlignLeft,m_pHttpRequest->url().url());
151
 
                        iY += iLineSpacing;
152
 
                        if(!(m_pHttpRequest->fileName().isEmpty()))
153
 
                        {
154
 
                                p->drawText(rect.left() + 4 + daW1,iY,width - (8 + daW1),height - 8,Qt::AlignTop | Qt::AlignLeft,m_pHttpRequest->fileName());
155
 
                        }
156
 
                        iY += iLineSpacing;
157
 
 
158
 
 
159
 
                        p->setPen(Qt::darkGray);
160
 
 
161
 
                        p->drawText(rect.left() + 4, rect.top() + 4,width - 8,height - 8,Qt::AlignTop | Qt::AlignLeft,szFrom);
162
 
                        p->drawText(rect.left() + 4, rect.top() + 4 + iLineSpacing,width - 8,height - 8,Qt::AlignTop | Qt::AlignLeft,szTo);
163
 
 
164
 
                        p->setPen(QColor(180,180,200));
165
 
 
166
 
                        iLineSpacing += 2;
167
 
 
168
 
                        p->drawRect(rect.left() + 4, rect.top() + height - (iLineSpacing + 4),width - 8,iLineSpacing);
169
 
                        p->fillRect(rect.left() + 5, rect.top() + height - (iLineSpacing + 3),width - 10,iLineSpacing - 2,bIsTerminated ? QColor(210,210,210) : QColor(190,190,240));
170
 
                        p->setPen(Qt::black);
171
 
                        p->drawText(rect.left() + 7, rect.top() + height - (iLineSpacing + 4),width - 14,iLineSpacing,Qt::AlignVCenter | Qt::AlignLeft,m_szStatusString);
172
 
                }
173
 
                break;
174
 
                case COLUMN_PROGRESS:
175
 
                {
176
 
                        QFontMetrics fm(p->font());
177
 
 
178
 
                        unsigned int uTotal = m_pHttpRequest->totalSize();
179
 
                        unsigned int uRecvd = m_pHttpRequest->receivedSize();
180
 
                        int iW = width - 8;
181
 
 
182
 
                        p->setPen(bIsTerminated ? Qt::lightGray : QColor(210,210,240));
183
 
                        p->drawRect(rect.left() + 4, rect.top() + 4,iW,12);
184
 
 
185
 
                        int iAvgSpeed = -1;
186
 
                        int iEta = -1;
187
 
 
188
 
                        if(m_tTransferStartTime > 0)
189
 
                        {
190
 
                                int tSpan = kvi_timeSpan(m_tTransferEndTime > 0 ? m_tTransferEndTime : kvi_unixTime(),m_tTransferStartTime);
191
 
                                if(tSpan > 0)
192
 
                                {
193
 
                                        //debug("SPAN: %d (%d - %d)",tSpan,m_tTransferEndTime > 0 ? m_tTransferEndTime : kvi_unixTime(),m_tTransferStartTime);
194
 
                                        iAvgSpeed = uRecvd / tSpan;
195
 
                                        if(!bIsTerminated && (uTotal >= uRecvd))
196
 
                                        {
197
 
                                                unsigned int uRemaining = uTotal - uRecvd;
198
 
                                                iEta = uRemaining / iAvgSpeed;
199
 
                                        }
200
 
                                }
201
 
                        }
202
 
 
203
 
                        if(uTotal > 0)
204
 
                        {
205
 
                                double dPerc = (double)(((double)uRecvd) * 100.0) / (double)uTotal;
206
 
                                iW -= 2;
207
 
                                int iL = (int) ((((double)iW) * dPerc) / 100.0);
208
 
                                //iR = iW - iL;
209
 
                                p->fillRect(rect.left() + 5, rect.top() + 5,iL,10,bIsTerminated ? QColor(140,110,110) : QColor(200,100,100));
210
 
 
211
 
                                txt = QString(__tr2qs_ctx("%1 of %2 (%3 %)","http")).arg(KviQString::makeSizeReadable(uRecvd),
212
 
                                        KviQString::makeSizeReadable(uTotal)).arg(dPerc,0,'f',2);
213
 
                        } else {
214
 
                                txt = KviQString::makeSizeReadable(m_pHttpRequest->receivedSize());
215
 
                        }
216
 
 
217
 
                        p->setPen(Qt::black);
218
 
 
219
 
                        p->drawText(rect.left() + 4, rect.top() + 19,width - 8,height - 8,Qt::AlignTop | Qt::AlignLeft,txt);
220
 
 
221
 
                        int iLeftHalf = (iW - 2) / 2;
222
 
                        int iRightHalf = iW - (iLeftHalf + 1);
223
 
                        int iLineSpacing = fm.lineSpacing() + 2;
224
 
                        /*
225
 
                        txt = __tr2qs_ctx("Spd:","dcc");
226
 
                        txt += " ";
227
 
                        if(iInstantSpeed >= 0)
228
 
                        {
229
 
                                QString tmpisp;
230
 
                                KviNetUtils::formatNetworkBandwidthString(tmpisp,iAvgSpeed);
231
 
                                txt += tmpisp;
232
 
                        } else {
233
 
                                txt += "? B/s";
234
 
                        }
235
 
                        */
236
 
                        txt = __tr2qs_ctx("Avg:","dcc");
237
 
                        txt += " ";
238
 
                        if(iAvgSpeed >= 0)
239
 
                        {
240
 
                                QString tmpspd;
241
 
                                KviNetUtils::formatNetworkBandwidthString(tmpspd,iAvgSpeed);
242
 
                                txt += tmpspd;
243
 
                        } else {
244
 
                                txt += "? B/s";
245
 
                        }
246
 
 
247
 
 
248
 
 
249
 
                        int iDaH = height - (iLineSpacing + 4);
250
 
 
251
 
                        p->setPen(QColor(180,180,200));
252
 
                        p->drawRect(rect.left() + 4, rect.top() + iDaH,iLeftHalf,iLineSpacing);
253
 
                        p->fillRect(rect.left() + 5, rect.top() + iDaH + 1,iLeftHalf - 2,iLineSpacing - 2,bIsTerminated ? QColor(210,210,210) : QColor(190,190,240));
254
 
                        p->setPen(bIsTerminated ? Qt::darkGray : Qt::black);
255
 
                        p->drawText(rect.left() + 6, rect.top() + iDaH,iLeftHalf - 4,iLineSpacing,Qt::AlignLeft | Qt::AlignVCenter,txt);
256
 
 
257
 
                        unsigned int uD,uH,uM,uS;
258
 
 
259
 
                        if(bIsTerminated)
260
 
                        {
261
 
                                KviTimeUtils::secondsToDaysHoursMinsSecs(kvi_timeSpan(m_tTransferEndTime,m_tTransferStartTime),&uD,&uH,&uM,&uS);
262
 
                                txt = "TOT: ";
263
 
                                if(uD > 0)txt += QString(__tr2qs_ctx("%1d %2h %3m %4s","http")).arg(uD).arg(uH).arg(uM).arg(uS);
264
 
                                else if(uH > 0)txt += QString(__tr2qs_ctx("%2h %3m %4s","http")).arg(uH).arg(uM).arg(uS);
265
 
                                else txt += QString(__tr2qs_ctx("%3m %4s","http")).arg(uM, uS);
266
 
                        } else {
267
 
                                if(iEta >= 0)
268
 
                                {
269
 
                                        KviTimeUtils::secondsToDaysHoursMinsSecs(iEta,&uD,&uH,&uM,&uS);
270
 
                                        txt = "ETA: ";
271
 
                                        if(uD > 0)txt += QString(__tr2qs_ctx("%1d %2h %3m %4s","http")).arg(uD).arg(uH).arg(uM).arg(uS);
272
 
                                        else if(uH > 0)txt += QString(__tr2qs_ctx("%2h %3m %4s","http")).arg(uH).arg(uM).arg(uS);
273
 
                                        else txt += QString(__tr2qs_ctx("%3m %4s","http")).arg(uM, uS);
274
 
                                } else {
275
 
                                        txt = "ETA: Unknown";
276
 
                                }
277
 
                        }
278
 
 
279
 
                        p->setPen(QColor(180,180,200));
280
 
                        p->drawRect(rect.left() + width - (4 + iRightHalf), rect.top() + iDaH,iRightHalf,iLineSpacing);
281
 
                        p->fillRect(rect.left() + width - (3 + iRightHalf), rect.top() + iDaH + 1,iRightHalf - 2,iLineSpacing - 2,bIsTerminated ? QColor(210,210,210) : QColor(190,190,240));
282
 
                        p->setPen(bIsTerminated ? Qt::darkGray : Qt::black);
283
 
                        p->drawText(rect.left() + width - (2 + iRightHalf), rect.top() + iDaH,iRightHalf - 4,iLineSpacing,Qt::AlignLeft | Qt::AlignVCenter,txt);
284
 
 
285
 
                }
286
 
                break;
287
 
        }
288
 
}
289
 
 
290
 
int KviHttpFileTransfer::displayHeight(int iLineSpacing)
291
 
{
292
 
        int iH = (iLineSpacing * 3) + 10;
293
 
        return iH >= 70 ? iH : 70;
294
 
}
295
 
 
296
 
QString KviHttpFileTransfer::tipText()
297
 
{
298
 
        QString s;
299
 
        s = QString("<table><tr><td bgcolor=\"#000000\"><font color=\"#FFFFFF\"><b>HTTP Transfer (ID %1)</b></font></td></tr>").arg(id());
300
 
 
301
 
        if(m_lRequest.count() > 0)
302
 
        {
303
 
                s += "<tr><td bgcolor=\"#404040\"><font color=\"#FFFFFF\">Request Headers</font></td></tr>";
304
 
                s += "<tr><td bgcolor=\"#C0C0C0\">";
305
 
                for(QStringList::ConstIterator it = m_lRequest.begin();it != m_lRequest.end();++it)
306
 
                {
307
 
                        s += "&nbsp; &nbsp;";
308
 
                        s += *it;
309
 
                        s += "<br>";
310
 
                }
311
 
                s += "</td></tr>";
312
 
        }
313
 
 
314
 
        if(m_lHeaders.count() > 0)
315
 
        {
316
 
                s += "<tr><td bgcolor=\"#404040\"><font color=\"#FFFFFF\">Response Headers</font></td></tr>";
317
 
                s += "<tr><td bgcolor=\"#C0C0C0\">";
318
 
                for(QStringList::ConstIterator it = m_lHeaders.begin();it != m_lHeaders.end();++it)
319
 
                {
320
 
                        s += "&nbsp; &nbsp;";
321
 
                        s += *it;
322
 
                        s += "<br>";
323
 
                }
324
 
                s += "</td></tr>";
325
 
        }
326
 
 
327
 
        s += "<table>";
328
 
 
329
 
        return s;
330
 
}
331
 
 
332
 
void KviHttpFileTransfer::init()
333
 
{
334
 
        if(g_pHttpFileTransfers)return;
335
 
        g_pHttpFileTransfers = new KviPointerList<KviHttpFileTransfer>;
336
 
        g_pHttpFileTransfers->setAutoDelete(false);
337
 
 
338
 
        QPixmap * pix = g_pIconManager->getImage("kvi_httpicons.png", false);
339
 
        if(pix)g_pHttpIcon = new QPixmap(*pix);
340
 
        else g_pHttpIcon = 0;
341
 
}
342
 
 
343
 
void KviHttpFileTransfer::done()
344
 
{
345
 
        if(!g_pHttpFileTransfers)return;
346
 
        while(KviHttpFileTransfer * t = g_pHttpFileTransfers->first())
347
 
                delete t;
348
 
        delete g_pHttpFileTransfers;
349
 
        g_pHttpFileTransfers = 0;
350
 
        delete g_pHttpIcon;
351
 
        g_pHttpIcon = 0;
352
 
}
353
 
 
354
 
unsigned int KviHttpFileTransfer::runningTransfers()
355
 
{
356
 
        if(!g_pHttpFileTransfers)return 0;
357
 
        return g_pHttpFileTransfers->count();
358
 
}
359
 
 
360
 
void KviHttpFileTransfer::requestSent(const QStringList &requestHeaders)
361
 
{
362
 
        m_szStatusString = __tr2qs_ctx("Request sent, waiting for reply...","http");
363
 
        displayUpdate();
364
 
 
365
 
        KviWindow * out = transferWindow();
366
 
        if(!out)return;
367
 
 
368
 
        if(!m_bNoOutput)
369
 
                out->output(KVI_OUT_GENERICSTATUS,__tr2qs_ctx("[HTTP %d]: Request data sent:","http"),id());
370
 
 
371
 
        for(QStringList::ConstIterator it = requestHeaders.begin();it != requestHeaders.end();++it)
372
 
        {
373
 
                if(!m_bNoOutput)
374
 
                        out->output(KVI_OUT_GENERICSTATUS,"[HTTP %d]:   %s",id(),(*it).toUtf8().data());
375
 
        }
376
 
 
377
 
        m_lRequest = requestHeaders;
378
 
}
379
 
 
380
 
void KviHttpFileTransfer::connectionEstabilished()
381
 
{
382
 
        m_szStatusString = __tr2qs_ctx("Connection established, sending request","http");
383
 
        displayUpdate();
384
 
}
385
 
 
386
 
void KviHttpFileTransfer::resolvingHost(const QString &hostname)
387
 
{
388
 
        m_szStatusString = __tr2qs_ctx("Resolving host %1","http").arg(hostname);
389
 
        displayUpdate();
390
 
}
391
 
 
392
 
void KviHttpFileTransfer::contactingHost(const QString &ipandport)
393
 
{
394
 
        m_szStatusString = __tr2qs_ctx("Contacting host %1","http").arg(ipandport);
395
 
        displayUpdate();
396
 
}
397
 
 
398
 
void KviHttpFileTransfer::receivedResponse(const QString &response)
399
 
{
400
 
        m_lHeaders.clear();
401
 
        m_lHeaders.append(response);
402
 
        m_szStatusString = __tr2qs_ctx("Transferring data (%1)","http").arg(response);
403
 
        m_tTransferStartTime = kvi_unixTime();
404
 
        m_eGeneralStatus = Downloading;
405
 
        displayUpdate();
406
 
}
407
 
 
408
 
void KviHttpFileTransfer::statusMessage(const QString &txt)
409
 
{
410
 
        KviWindow * out = transferWindow();
411
 
        if(out && (!m_bNoOutput))
412
 
                out->output(KVI_OUT_GENERICSTATUS,"[HTTP %d]: %Q",id(),&txt);
413
 
}
414
 
 
415
 
void KviHttpFileTransfer::transferTerminated(bool bSuccess)
416
 
{
417
 
        KviWindow * out = transferWindow();
418
 
 
419
 
        m_tTransferEndTime = kvi_unixTime();
420
 
 
421
 
        KviKvsVariantList vParams;
422
 
        vParams.append(new KviKvsVariant(bSuccess));
423
 
        vParams.append(new KviKvsVariant(m_pHttpRequest->url().url()));
424
 
        vParams.append(new KviKvsVariant(m_pHttpRequest->fileName()));
425
 
        vParams.append(new KviKvsVariant(m_vMagicIdentifier));
426
 
 
427
 
        if(m_szCompletionCallback.isNull())
428
 
        {
429
 
                KVS_TRIGGER_EVENT(KviEvent_OnHTTPGetTerminated,out ? out : (KviWindow *)(g_pApp->activeConsole()),&vParams)
430
 
        } else {
431
 
                KviKvsScript::run(m_szCompletionCallback,out ? out : (KviWindow *)(g_pApp->activeConsole()),&vParams);
432
 
        }
433
 
 
434
 
        if(bSuccess)
435
 
        {
436
 
                m_szStatusString = __tr2qs_ctx("Transfer completed","http");
437
 
                m_eGeneralStatus = Success;
438
 
                displayUpdate();
439
 
                if(out && (!m_bNoOutput))out->output(KVI_OUT_GENERICSUCCESS,__tr2qs_ctx("[HTTP %d]: Transfer completed","http"),id());
440
 
                g_pApp->fileDownloadTerminated(true,m_pHttpRequest->url().url(),m_pHttpRequest->fileName(),QString(),QString(),!m_bNotifyCompletion);
441
 
        } else {
442
 
                m_szStatusString = __tr2qs_ctx("Transfer failed","http");
443
 
                m_szStatusString += ": ";
444
 
                m_szStatusString += m_pHttpRequest->lastError();
445
 
                m_eGeneralStatus = Failure;
446
 
                displayUpdate();
447
 
                if(out && (!m_bNoOutput))out->output(KVI_OUT_GENERICERROR,__tr2qs_ctx("[HTTP %d]: Transfer failed: %Q","http"),id(),&(m_pHttpRequest->lastError()));
448
 
                g_pApp->fileDownloadTerminated(false,m_pHttpRequest->url().url(),m_pHttpRequest->fileName(),QString(),m_pHttpRequest->lastError(),!m_bNotifyCompletion);
449
 
        }
450
 
 
451
 
        if(m_bAutoClean)
452
 
        {
453
 
                if(m_pAutoCleanTimer)delete m_pAutoCleanTimer;
454
 
                m_pAutoCleanTimer = new QTimer();
455
 
                connect(m_pAutoCleanTimer,SIGNAL(timeout()),this,SLOT(autoClean()));
456
 
                m_pAutoCleanTimer->start(100);
457
 
                m_TimerId=m_pAutoCleanTimer->timerId();
458
 
        }
459
 
}
460
 
 
461
 
void KviHttpFileTransfer::headersReceived(KviPointerHashTable<const char *,KviStr> *h)
462
 
{
463
 
        if(!h)return;
464
 
        KviWindow * out = transferWindow();
465
 
 
466
 
        if(out && (!m_bNoOutput))out->output(KVI_OUT_GENERICSTATUS,__tr2qs_ctx("[HTTP %d]: Response headers:","http"),id());
467
 
        KviPointerHashTableIterator<const char *,KviStr> it(*h);
468
 
        while(KviStr * s = it.current())
469
 
        {
470
 
                QString szHeader = it.currentKey();
471
 
                szHeader += ": ";
472
 
                szHeader += s->ptr();
473
 
                m_lHeaders.append(szHeader);
474
 
                if(out && (!m_bNoOutput))out->output(KVI_OUT_GENERICSTATUS,"[HTTP %d]:   %s: %s",id(),it.currentKey(),s->ptr());
475
 
                ++it;
476
 
        }
477
 
}
478
 
 
479
 
bool KviHttpFileTransfer::startDownload()
480
 
{
481
 
        m_eGeneralStatus = Connecting;
482
 
        return m_pHttpRequest->start();
483
 
}
484
 
 
485
 
#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES
486
 
#include "m_httpfiletransfer.moc"
487
 
#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES