• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdenetwork API Reference
  • KDE Home
  • Contact Us
 

kget

  • sources
  • kde-4.12
  • kdenetwork
  • kget
  • transfer-plugins
  • bittorrent
btcache.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE project
2 
3  Copyright (C) 2008 Lukas Appelhans <l.appelhans@gmx.de>
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 */
10 #include "btcache.h"
11 
12 #include <diskio/chunk.h>
13 
14 #include <KDebug>
15 #include <QDataStream>
16 
17 using namespace bt;
18 //TODO: Support buffered mode?
19 BTCache::BTCache(Torrent & tor,const QString & tmpdir,const QString & datadir)
20  : Cache(tor, tmpdir, datadir),
21  QObject(0)
22 {
23 }
24 
25 BTCache::~BTCache()
26 {
27 }
28 
29 void BTCache::load(Chunk* c)
30 {
31  c->setData(0, Chunk::MMAPPED);
32 }
33 
34 void BTCache::save(Chunk* c)
35 {
36  /*if (c->getStatus() == Chunk::MMAPPED)
37  {
38  KIO::fileoffset_t off = c->getIndex() * tor.getChunkSize();
39  kDebug(5001) << "Fileoffset is: " + QString::number(off);
40  QByteArray data;
41  QDataStream s(&data, QIODevice::WriteOnly | QIODevice::Unbuffered);
42  s << c->getData();
43  emit dataArrived(off, data);
44  c->clear();
45  c->setStatus(Chunk::ON_DISK);
46  }
47  else if (c->getStatus() == Chunk::BUFFERED)
48  {*/
49  KIO::fileoffset_t off = c->getIndex() * tor.getChunkSize();
50  kDebug(5001) << "Fileoffset is: " + QString::number(off);
51  QByteArray data;
52  QDataStream s(&data, QIODevice::WriteOnly | QIODevice::Unbuffered);
53  s << c->getData();
54  emit dataArrived(off, data);
55  //fd->write(c->getData(),c->getSize(),off);//Send a signal here that the signal has arrived
56  c->clear();
57  c->setStatus(Chunk::ON_DISK);
58  //}
59 }
60 
61 bool BTCache::prep(Chunk* c)
62 {
63  c->setData(0, Chunk::MMAPPED);
64  return true;
65 }
66 
67 void BTCache::deleteDataFiles()
68 {
69 }
70 
71 Cache* BTCacheFactory::create(Torrent & tor,const QString & tmpdir,const QString & datadir)
72 {
73  BTCache *newcache = new BTCache(tor, tmpdir, datadir);
74  emit cacheAdded(newcache);
75  return newcache;
76 }
77 
78 #include "btcache.moc"
BTCache::save
virtual void save(Chunk *c)
Save a chunk to disk.
Definition: btcache.cpp:34
BTCache::prep
virtual bool prep(Chunk *c)
Prepare a chunk for downloading.
Definition: btcache.cpp:61
BTCache::dataArrived
void dataArrived(const KIO::fileoffset_t &offset, const QByteArray &data)
BTCache::load
virtual void load(Chunk *c)
Load a chunk into memory.
Definition: btcache.cpp:29
QObject
btcache.h
BTCacheFactory::cacheAdded
void cacheAdded(BTCache *cache)
BTCache::deleteDataFiles
virtual KJob * deleteDataFiles()
Delete all data files, in case of multi file torrents empty directories should also be deleted...
Definition: btcache.h:139
BTCache::BTCache
BTCache(bt::Torrent &tor, const QString &tmpdir, const QString &datadir)
Definition: btcache.cpp:19
BTCacheFactory::create
virtual Cache * create(Torrent &tor, const QString &tmpdir, const QString &datadir)
Definition: btcache.cpp:71
BTCache::~BTCache
~BTCache()
Definition: btcache.cpp:25
BTCache
Definition: btcache.h:33
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:53:17 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kget

Skip menu "kget"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal