File indexing completed on 2024-04-21 04:57:12

0001 /* This file is part of the KDE project
0002 
0003    Copyright (C) 2008 Lukas Appelhans <l.appelhans@gmx.de>
0004 
0005    This program is free software; you can redistribute it and/or
0006    modify it under the terms of the GNU General Public
0007    License as published by the Free Software Foundation; either
0008    version 2 of the License, or (at your option) any later version.
0009 */
0010 
0011 #ifndef BTDATASOURCE_H
0012 #define BTDATASOURCE_H
0013 
0014 #include "core/transferdatasource.h"
0015 
0016 #include <KIO/Job>
0017 #include <QTimer>
0018 #include <QUrl>
0019 
0020 namespace bt
0021 {
0022 class TorrentControl;
0023 }
0024 
0025 class BTChunkSelectorFactory;
0026 class BTChunkSelector;
0027 class BTCacheFactory;
0028 class BTCache;
0029 
0030 class BTDataSource : public TransferDataSource
0031 {
0032     Q_OBJECT
0033 public:
0034     BTDataSource(const QUrl &srcUrl, QObject *parent);
0035     ~BTDataSource() override;
0036 
0037     void start() override;
0038     void stop() override;
0039     void addSegments(const QPair<KIO::fileoffset_t, KIO::fileoffset_t> &segmentSize, const QPair<int, int> &segmentRange) override;
0040     void getData(const KIO::fileoffset_t &off, const QByteArray &dataArray);
0041 
0042 private Q_SLOTS:
0043     void init(const QUrl &torrentSource, const QByteArray &data);
0044     void cacheAdded(BTCache *cache);
0045     void selectorAdded(BTChunkSelector *selector);
0046     void update();
0047 
0048 private:
0049     bt::TorrentControl *tc;
0050     BTChunkSelectorFactory *csf;
0051     BTChunkSelector *cs;
0052     BTCacheFactory *cf;
0053 
0054     KIO::fileoffset_t m_offset;
0055     KIO::fileoffset_t m_bytes;
0056     QUrl m_torrentSource;
0057     QTimer timer;
0058 };
0059 
0060 #endif