1/* This file is part of the KDE libraries
2 Copyright (c) 2009 David Faure <faure@kde.org>
3 Copyright (c) 2010 Sebastian Trueg <trueg@kde.org>
4
5 This library is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2 of the License or ( at
8 your option ) version 3 or, at the discretion of KDE e.V. ( which shall
9 act as a proxy as in section 14 of the GPLv3 ), any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20*/
21#ifndef BROWSERRUN_P_H
22#define BROWSERRUN_P_H
23
24#include <kio/copyjob.h>
25#include <kdebug.h>
26
27#include "config-nepomuk.h"
28
29#include <QtCore/QDateTime>
30
31#ifdef HAVE_NEPOMUK
32#include "../nepomuk/utils/utils.h"
33#endif
34
35namespace KParts {
36
37/**
38 * This watcher is notified when the "download" job is done,
39 * so we can remember where a downloaded file comes from.
40 */
41class DownloadJobWatcher : public QObject
42{
43 Q_OBJECT
44public:
45 DownloadJobWatcher(KIO::FileCopyJob* job, const QMap<QString, QString> &metaData)
46 : QObject(job), m_metaData(metaData), m_downloadJobStartTime(QDateTime::currentDateTime())
47 {
48 kDebug() << "download started: srcUrl=" << job->srcUrl()
49 << "destUrl=" << job->destUrl()
50 << "referrer=" << m_metaData.value("referrer");
51 connect(job, SIGNAL(result(KJob*)), this, SLOT(slotDownloadFinished(KJob*)));
52 }
53
54private Q_SLOTS:
55 void slotDownloadFinished(KJob* job)
56 {
57 KIO::FileCopyJob* fileCopyJob = static_cast<KIO::FileCopyJob *>(job);
58 if (job->error()) {
59 kDebug() << "error during download: srcUrl=" << fileCopyJob->srcUrl()
60 << "destUrl=" << fileCopyJob->destUrl()
61 << "referrer=" << m_metaData.value("referrer");
62 // TODO: test whether destUrl+".part" exists
63 } else {
64 kDebug() << "download finished: srcUrl=" << fileCopyJob->srcUrl()
65 << "destUrl=" << fileCopyJob->destUrl()
66 << "referrer=" << m_metaData.value("referrer");
67#ifdef HAVE_NEPOMUK
68 Nepomuk::Utils::createCopyEvent( fileCopyJob->srcUrl(),
69 fileCopyJob->destUrl(),
70 m_downloadJobStartTime,
71 KUrl(m_metaData.value("referrer")) );
72#endif
73 }
74 }
75
76private:
77 QMap<QString, QString> m_metaData;
78 QDateTime m_downloadJobStartTime;
79};
80}
81
82#endif /* BROWSERRUN_P_H */
83
84