- modified ftFileProvider so as to keep multiple client peers per instance

- updated TransfersDialog to display this info correctly


git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3316 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2010-07-27 16:05:21 +00:00
parent 8b3af9143f
commit 81203b3cfd
9 changed files with 220 additions and 245 deletions

View File

@ -684,10 +684,8 @@ bool ftDataMultiplex::locked_handleServerRequest(ftFileProvider *provider,
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
if (provider->getFileData(offset, chunksize, data)) if (provider->getFileData(peerId,offset, chunksize, data))
{ {
// setup info
provider->setPeerId(peerId) ;
/* send data out */ /* send data out */
sendData(peerId, hash, size, offset, chunksize, data); sendData(peerId, hash, size, offset, chunksize, data);
return true; return true;
@ -740,7 +738,7 @@ void ftDataMultiplex::deleteUnusedServers()
time_t now = time(NULL); time_t now = time(NULL);
for(std::map<std::string, ftFileProvider *>::iterator sit(mServers.begin());sit != mServers.end();) for(std::map<std::string, ftFileProvider *>::iterator sit(mServers.begin());sit != mServers.end();)
if ((now - sit->second->lastTS) > 10) if(sit->second->purgeOldPeers(now,10))
{ {
#ifdef SERVER_DEBUG #ifdef SERVER_DEBUG
std::cout << "info.lastTS = " << info.lastTS << ", now=" << now << std::endl ; std::cout << "info.lastTS = " << info.lastTS << ", now=" << now << std::endl ;

View File

@ -38,7 +38,7 @@ ftFileCreator::ftFileCreator(std::string path, uint64_t size, std::string hash)
_last_recv_time_t = time(NULL) ; _last_recv_time_t = time(NULL) ;
} }
bool ftFileCreator::getFileData(uint64_t offset, uint32_t &chunk_size, void *data) bool ftFileCreator::getFileData(const std::string& peer_id,uint64_t offset, uint32_t &chunk_size, void *data)
{ {
// Only send the data if we actually have it. // Only send the data if we actually have it.
// //
@ -50,7 +50,7 @@ bool ftFileCreator::getFileData(uint64_t offset, uint32_t &chunk_size, void *dat
} }
if(have_it) if(have_it)
return ftFileProvider::getFileData(offset, chunk_size, data); return ftFileProvider::getFileData(peer_id,offset, chunk_size, data);
else else
return false ; return false ;
} }

View File

@ -45,7 +45,7 @@ class ftFileCreator: public ftFileProvider
~ftFileCreator(); ~ftFileCreator();
/* overloaded from FileProvider */ /* overloaded from FileProvider */
virtual bool getFileData(uint64_t offset, uint32_t &chunk_size, void *data); virtual bool getFileData(const std::string& peer_id,uint64_t offset, uint32_t &chunk_size, void *data);
bool finished() ; bool finished() ;
uint64_t getRecvd(); uint64_t getRecvd();

View File

@ -10,18 +10,16 @@
#endif // WINDOWS_SYS #endif // WINDOWS_SYS
static const time_t UPLOAD_CHUNK_MAPS_TIME = 30 ; // time to ask for a new chunkmap from uploaders in seconds. static const time_t UPLOAD_CHUNK_MAPS_TIME = 20 ; // time to ask for a new chunkmap from uploaders in seconds.
ftFileProvider::ftFileProvider(std::string path, uint64_t size, std::string ftFileProvider::ftFileProvider(std::string path, uint64_t size, std::string hash)
hash) : mSize(size), hash(hash), file_name(path), fd(NULL),req_loc(0),transfer_rate(0),total_size(0) : mSize(size), hash(hash), file_name(path), fd(NULL)
{ {
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/ RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
clients_chunk_maps.clear();
#ifdef DEBUG_FT_FILE_PROVIDER #ifdef DEBUG_FT_FILE_PROVIDER
std::cout << "Creating file provider for " << hash << std::endl ; std::cout << "Creating file provider for " << hash << std::endl ;
#endif #endif
lastTS = time(NULL) ;
lastTS_t = lastTS ;
} }
ftFileProvider::~ftFileProvider(){ ftFileProvider::~ftFileProvider(){
@ -34,12 +32,6 @@ ftFileProvider::~ftFileProvider(){
} }
} }
void ftFileProvider::setPeerId(const std::string& id)
{
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
lastRequestor = id ;
}
bool ftFileProvider::fileOk() bool ftFileProvider::fileOk()
{ {
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/ RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
@ -65,25 +57,54 @@ bool ftFileProvider::FileDetails(FileInfo &info)
info.size = mSize; info.size = mSize;
info.path = file_name; info.path = file_name;
info.fname = RsDirUtil::getTopDir(file_name); info.fname = RsDirUtil::getTopDir(file_name);
info.transfered = req_loc ;
info.lastTS = lastTS; info.transfered = 0 ; // unused
info.lastTS = 0;
info.status = FT_STATE_DOWNLOADING ; info.status = FT_STATE_DOWNLOADING ;
info.peers.clear() ; info.peers.clear() ;
float total_transfer_rate = 0.0f ;
for(std::map<std::string,PeerUploadInfo>::const_iterator it(uploading_peers.begin());it!=uploading_peers.end();++it)
{
TransferInfo inf ; TransferInfo inf ;
inf.peerId = lastRequestor ; inf.peerId = it->first ;
inf.status = FT_STATE_DOWNLOADING ; inf.status = FT_STATE_DOWNLOADING ;
inf.name = info.fname ;
inf.transfered = it->second.req_loc ;
inf.tfRate = it->second.transfer_rate/1024.0 ;
total_transfer_rate += it->second.transfer_rate ;
info.lastTS = std::max(info.lastTS,it->second.lastTS);
inf.tfRate = transfer_rate/1024.0 ;
info.tfRate = transfer_rate/1024.0 ;
info.peers.push_back(inf) ; info.peers.push_back(inf) ;
}
info.tfRate = total_transfer_rate/1024.0 ;
/* Use req_loc / req_size to estimate data rate */ /* Use req_loc / req_size to estimate data rate */
return true; return true;
} }
bool ftFileProvider::purgeOldPeers(time_t now,uint32_t max_duration)
{
bool ret = true ;
for(std::map<std::string,PeerUploadInfo>::iterator it(uploading_peers.begin());it!=uploading_peers.end();)
if( (*it).second.lastTS+max_duration < (uint32_t)now)
{
std::map<std::string,PeerUploadInfo>::iterator tmp = it ;
++tmp ;
uploading_peers.erase(it) ;
it=tmp ;
}
else
{
ret = false ;
++it ;
}
return ret ;
}
void ftFileProvider::getAvailabilityMap(CompressedChunkMap& cmap) void ftFileProvider::getAvailabilityMap(CompressedChunkMap& cmap)
{ {
// We are here because the file we deal with is complete. So we return a plain map. // We are here because the file we deal with is complete. So we return a plain map.
@ -92,7 +113,7 @@ void ftFileProvider::getAvailabilityMap(CompressedChunkMap& cmap)
} }
bool ftFileProvider::getFileData(uint64_t offset, uint32_t &chunk_size, void *data) bool ftFileProvider::getFileData(const std::string& peer_id,uint64_t offset, uint32_t &chunk_size, void *data)
{ {
/* dodgey checking outside of mutex... /* dodgey checking outside of mutex...
* much check again inside FileAttrs(). * much check again inside FileAttrs().
@ -158,9 +179,23 @@ bool ftFileProvider::getFileData(uint64_t offset, uint32_t &chunk_size, void *da
* (d) timestamp * (d) timestamp
*/ */
time_t now_t = time(NULL) ; // This creates the peer info, and updates it.
//
time_t now = time(NULL) ;
uploading_peers[peer_id].updateStatus(offset,data_size,now) ;
}
else
{
std::cerr << "No data to read" << std::endl;
return 0;
}
return 1;
}
long int diff = (long int)now_t - (long int)lastTS_t ; // in bytes/s. Average over multiple samples void ftFileProvider::PeerUploadInfo::updateStatus(uint64_t offset,uint32_t data_size,time_t now)
{
lastTS = now ;
long int diff = (long int)now - (long int)lastTS_t ; // in bytes/s. Average over multiple samples
#ifdef DEBUG_FT_FILE_PROVIDER #ifdef DEBUG_FT_FILE_PROVIDER
std::cout << "diff = " << diff << std::endl ; std::cout << "diff = " << diff << std::endl ;
@ -172,53 +207,41 @@ bool ftFileProvider::getFileData(uint64_t offset, uint32_t &chunk_size, void *da
#ifdef DEBUG_FT_FILE_PROVIDER #ifdef DEBUG_FT_FILE_PROVIDER
std::cout << "updated TR = " << transfer_rate << ", total_size=" << total_size << std::endl ; std::cout << "updated TR = " << transfer_rate << ", total_size=" << total_size << std::endl ;
#endif #endif
lastTS_t = now_t ; lastTS_t = now ;
total_size = 0 ; total_size = 0 ;
} }
req_loc = offset; req_loc = offset;
lastTS = time(NULL) ;
req_size = data_size; req_size = data_size;
total_size += req_size ; total_size += req_size ;
} }
else {
std::cerr << "No data to read" << std::endl;
return 0;
}
return 1;
}
void ftFileProvider::setClientMap(const std::string& peer_id,const CompressedChunkMap& cmap) void ftFileProvider::setClientMap(const std::string& peer_id,const CompressedChunkMap& cmap)
{ {
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/ RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
std::pair<CompressedChunkMap,time_t>& map_info(clients_chunk_maps[peer_id]) ; // Create by default.
uploading_peers[peer_id].client_chunk_map = cmap ;
map_info.first = cmap ; uploading_peers[peer_id].client_chunk_map_stamp = time(NULL) ;
map_info.second = time(NULL) ;
} }
void ftFileProvider::getClientMap(const std::string& peer_id,CompressedChunkMap& cmap,bool& map_is_too_old) void ftFileProvider::getClientMap(const std::string& peer_id,CompressedChunkMap& cmap,bool& map_is_too_old)
{ {
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/ RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
std::map<std::string,std::pair<CompressedChunkMap,time_t> >::iterator it(clients_chunk_maps.find(peer_id)) ; PeerUploadInfo& pui(uploading_peers[peer_id]) ;
if(it == clients_chunk_maps.end()) time_t now = time(NULL) ;
{
clients_chunk_maps[peer_id] = std::pair<CompressedChunkMap,time_t>(CompressedChunkMap(),0) ;
it = clients_chunk_maps.find(peer_id) ;
}
if(time(NULL) - it->second.second > UPLOAD_CHUNK_MAPS_TIME) if(now - pui.client_chunk_map_stamp > UPLOAD_CHUNK_MAPS_TIME)
{ {
map_is_too_old = true ; map_is_too_old = true ;
it->second.second = time(NULL) ; // to avoid re-asking before the TTL pui.client_chunk_map_stamp = now ; // to avoid re-asking before the TTL
} }
else else
map_is_too_old = false ; map_is_too_old = false ;
cmap = it->second.first ; cmap = pui.client_chunk_map;
} }
int ftFileProvider::initializeFileAttrs() int ftFileProvider::initializeFileAttrs()
@ -273,23 +296,6 @@ int ftFileProvider::initializeFileAttrs()
} }
} }
/*
* if it opened, find it's length
* move to the end
*/
// if (0 != fseeko64(fd, 0L, SEEK_END))
// {
// std::cerr << "ftFileProvider::initializeFileAttrs() Seek Failed" << std::endl;
// return 0;
// }
//
// uint64_t recvdsize = ftello64(fd);
//
//#ifdef DEBUG_FT_FILE_PROVIDER
// std::cerr << "ftFileProvider::initializeFileAttrs() File Expected Size: " << mSize << " RecvdSize: " << recvdsize << std::endl;
//#endif
return 1; return 1;
} }

View File

@ -41,14 +41,12 @@ class ftFileProvider
ftFileProvider(std::string path, uint64_t size, std::string hash); ftFileProvider(std::string path, uint64_t size, std::string hash);
virtual ~ftFileProvider(); virtual ~ftFileProvider();
virtual bool getFileData(uint64_t offset, uint32_t &chunk_size, void *data); virtual bool getFileData(const std::string& peer_id,uint64_t offset, uint32_t &chunk_size, void *data);
virtual bool FileDetails(FileInfo &info); virtual bool FileDetails(FileInfo &info);
std::string getHash(); std::string getHash();
uint64_t getFileSize(); uint64_t getFileSize();
bool fileOk(); bool fileOk();
void setPeerId(const std::string& id) ;
// Provides a client for the map of chunks actually present in the file. If the provider is also // Provides a client for the map of chunks actually present in the file. If the provider is also
// a file creator, because the file is actually being downloaded, then the map may be partially complete. // a file creator, because the file is actually being downloaded, then the map may be partially complete.
// Otherwize, a plain map is returned. // Otherwize, a plain map is returned.
@ -65,7 +63,9 @@ class ftFileProvider
void getClientMap(const std::string& peer_id,CompressedChunkMap& cmap,bool& map_is_too_old) ; void getClientMap(const std::string& peer_id,CompressedChunkMap& cmap,bool& map_is_too_old) ;
void setClientMap(const std::string& peer_id,const CompressedChunkMap& cmap) ; void setClientMap(const std::string& peer_id,const CompressedChunkMap& cmap) ;
time_t lastTS; // used for checking if it's alive // Removes inactive peers from the client list. Returns true if all peers have been removed.
//
bool purgeOldPeers(time_t now,uint32_t max_duration) ;
protected: protected:
virtual int initializeFileAttrs(); /* does for both */ virtual int initializeFileAttrs(); /* does for both */
@ -78,17 +78,31 @@ class ftFileProvider
* Structure to gather statistics FIXME: lastRequestor - figure out a * Structure to gather statistics FIXME: lastRequestor - figure out a
* way to get last requestor (peerID) * way to get last requestor (peerID)
*/ */
std::string lastRequestor; class PeerUploadInfo
{
public:
PeerUploadInfo()
: req_loc(0),req_size(1), lastTS_t(0), transfer_rate(0), total_size(0), client_chunk_map_stamp(0) {}
void updateStatus(uint64_t offset,uint32_t data_size,time_t now) ;
uint64_t req_loc; uint64_t req_loc;
uint32_t req_size; uint32_t req_size;
time_t lastTS_t; // used for estimating transfer rate. time_t lastTS_t; // used for estimating transfer rate.
time_t lastTS; // last update time (for purging)
// these two are used for speed estimation // these two are used for speed estimation
float transfer_rate ; float transfer_rate ;
uint32_t total_size ; uint32_t total_size ;
// Info about what the downloading peer already has // Info about what the downloading peer already has
std::map<std::string,std::pair<CompressedChunkMap,time_t> > clients_chunk_maps ; CompressedChunkMap client_chunk_map ;
time_t client_chunk_map_stamp ;
};
// Contains statistics (speed, peer name, etc.) of all uploading peers for that file.
//
std::map<std::string,PeerUploadInfo> uploading_peers ;
/* /*
* Mutex Required for stuff below * Mutex Required for stuff below

View File

@ -62,6 +62,7 @@ class TransferInfo
std::string name; /* if has alternative name? */ std::string name; /* if has alternative name? */
double tfRate; /* kbytes */ double tfRate; /* kbytes */
int status; /* FT_STATE_... */ int status; /* FT_STATE_... */
uint64_t transfered ; // used when no chunkmap data is available
}; };
enum QueueMove { QUEUE_TOP = 0x00, enum QueueMove { QUEUE_TOP = 0x00,

View File

@ -143,6 +143,8 @@ TransfersDialog::TransfersDialog(QWidget *parent)
ULListModel->setHeaderData(UTRANSFERRED, Qt::Horizontal, tr("Transferred", "")); ULListModel->setHeaderData(UTRANSFERRED, Qt::Horizontal, tr("Transferred", ""));
ULListModel->setHeaderData(UHASH, Qt::Horizontal, tr("Hash", "")); ULListModel->setHeaderData(UHASH, Qt::Horizontal, tr("Hash", ""));
ui.uploadsList->setModel(ULListModel); ui.uploadsList->setModel(ULListModel);
ULListModel->insertColumn(UUSERID);
ui.uploadsList->hideColumn(UUSERID);
ULDelegate = new ULListDelegate(); ULDelegate = new ULListDelegate();
ui.uploadsList->setItemDelegate(ULDelegate); ui.uploadsList->setItemDelegate(ULDelegate);
@ -416,12 +418,6 @@ void TransfersDialog::downloadListCostumPopupMenu( QPoint point )
contextMnu.exec(QCursor::pos()); contextMnu.exec(QCursor::pos());
} }
TransfersDialog::~TransfersDialog()
{
;
}
int TransfersDialog::addItem(const QString&, const QString& name, const QString& coreID, qlonglong fileSize, const FileProgressInfo& pinfo, double dlspeed, int TransfersDialog::addItem(const QString&, const QString& name, const QString& coreID, qlonglong fileSize, const FileProgressInfo& pinfo, double dlspeed,
const QString& sources, const QString& status, const QString& priority, qlonglong completed, qlonglong remaining, qlonglong downloadtime) const QString& sources, const QString& status, const QString& priority, qlonglong completed, qlonglong remaining, qlonglong downloadtime)
{ {
@ -447,39 +443,42 @@ int TransfersDialog::addItem(const QString&, const QString& name, const QString&
DLListModel->setData(DLListModel->index(row, ID), QVariant((QString)coreID)); DLListModel->setData(DLListModel->index(row, ID), QVariant((QString)coreID));
QString ext = QFileInfo(name).suffix(); QString ext = QFileInfo(name).suffix();
if (ext == "jpg" || ext == "jpeg" || ext == "tif" || ext == "tiff" || ext == "JPG"|| ext == "png" || ext == "gif" DLListModel->setData(DLListModel->index(row,NAME), getIconFromExtension(ext), Qt::DecorationRole);
|| ext == "bmp" || ext == "ico" || ext == "svg") {
DLListModel->setData(DLListModel->index(row,NAME), QIcon(QString::fromUtf8(":/images/FileTypePicture.png")), Qt::DecorationRole);
} else if (ext == "avi" ||ext == "AVI" || ext == "mpg" || ext == "mpeg" || ext == "wmv" || ext == "divx" || ext == "ts"
|| ext == "mkv" || ext == "mp4" || ext == "flv" || ext == "mov" || ext == "asf" || ext == "xvid"
|| ext == "vob" || ext == "qt" || ext == "rm" || ext == "3gp" || ext == "mpeg" || ext == "ogm") {
DLListModel->setData(DLListModel->index(row,NAME), QIcon(QString::fromUtf8(":/images/FileTypeVideo.png")), Qt::DecorationRole);
} else if (ext == "ogg" || ext == "mp3" || ext == "MP3" || ext == "mp1" || ext == "mp2" || ext == "wav" || ext == "wma") {
DLListModel->setData(DLListModel->index(row,NAME), QIcon(QString::fromUtf8(":/images/FileTypeAudio.png")), Qt::DecorationRole);
} else if (ext == "tar" || ext == "bz2" || ext == "zip" || ext == "gz" || ext == "7z" || ext == "msi"
|| ext == "rar" || ext == "rpm" || ext == "ace" || ext == "jar" || ext == "tgz" || ext == "lha"
|| ext == "cab" || ext == "cbz"|| ext == "cbr" || ext == "alz" || ext == "sit" || ext == "arj" || ext == "deb") {
DLListModel->setData(DLListModel->index(row,NAME), QIcon(QString::fromUtf8(":/images/FileTypeArchive.png")), Qt::DecorationRole);
}else if (ext == "app" || ext == "bat" || ext == "cgi" || ext == "com"
|| ext == "exe" || ext == "js" || ext == "pif"
|| ext == "py" || ext == "pl" || ext == "sh" || ext == "vb" || ext == "ws") {
DLListModel->setData(DLListModel->index(row,NAME), QIcon(QString::fromUtf8(":/images/FileTypeProgram.png")), Qt::DecorationRole);
} else if (ext == "iso" || ext == "nrg" || ext == "mdf" || ext == "img" || ext == "dmg" || ext == "bin" ) {
DLListModel->setData(DLListModel->index(row,NAME), QIcon(QString::fromUtf8(":/images/FileTypeCDImage.png")), Qt::DecorationRole);
} else if (ext == "txt" || ext == "cpp" || ext == "c" || ext == "h") {
DLListModel->setData(DLListModel->index(row,NAME), QIcon(QString::fromUtf8(":/images/FileTypeDocument.png")), Qt::DecorationRole);
} else if (ext == "doc" || ext == "rtf" || ext == "sxw" || ext == "xls" || ext == "pps" || ext == "xml"
|| ext == "sxc" || ext == "odt" || ext == "ods" || ext == "dot" || ext == "ppt" || ext == "css" ) {
DLListModel->setData(DLListModel->index(row,NAME), QIcon(QString::fromUtf8(":/images/FileTypeDocument.png")), Qt::DecorationRole);
} else if (ext == "html" || ext == "htm" || ext == "php") {
DLListModel->setData(DLListModel->index(row,NAME), QIcon(QString::fromUtf8(":/images/FileTypeDocument.png")), Qt::DecorationRole);
} else {
DLListModel->setData(DLListModel->index(row,NAME), QIcon(QString::fromUtf8(":/images/FileTypeAny.png")), Qt::DecorationRole);
}
return row ; return row ;
} }
QIcon TransfersDialog::getIconFromExtension(const QString& ext)
{
if (ext == "jpg" || ext == "jpeg" || ext == "tif" || ext == "tiff" || ext == "JPG"|| ext == "png" || ext == "gif" || ext == "bmp" || ext == "ico" || ext == "svg")
return QIcon(QString::fromUtf8(":/images/FileTypePicture.png")) ;
else if (ext == "avi" ||ext == "AVI" || ext == "mpg" || ext == "mpeg" || ext == "wmv" || ext == "divx" || ext == "ts"
|| ext == "mkv" || ext == "mp4" || ext == "flv" || ext == "mov" || ext == "asf" || ext == "xvid"
|| ext == "vob" || ext == "qt" || ext == "rm" || ext == "3gp" || ext == "mpeg" || ext == "ogm")
return QIcon(QString::fromUtf8(":/images/FileTypeVideo.png")) ;
else if (ext == "ogg" || ext == "mp3" || ext == "MP3" || ext == "mp1" || ext == "mp2" || ext == "wav" || ext == "wma")
return QIcon(QString::fromUtf8(":/images/FileTypeAudio.png")) ;
else if (ext == "tar" || ext == "bz2" || ext == "zip" || ext == "gz" || ext == "7z" || ext == "msi"
|| ext == "rar" || ext == "rpm" || ext == "ace" || ext == "jar" || ext == "tgz" || ext == "lha"
|| ext == "cab" || ext == "cbz"|| ext == "cbr" || ext == "alz" || ext == "sit" || ext == "arj" || ext == "deb")
return QIcon(QString::fromUtf8(":/images/FileTypeArchive.png")) ;
else if (ext == "app" || ext == "bat" || ext == "cgi" || ext == "com"
|| ext == "exe" || ext == "js" || ext == "pif"
|| ext == "py" || ext == "pl" || ext == "sh" || ext == "vb" || ext == "ws")
return QIcon(QString::fromUtf8(":/images/FileTypeProgram.png")) ;
else if (ext == "iso" || ext == "nrg" || ext == "mdf" || ext == "img" || ext == "dmg" || ext == "bin" )
return QIcon(QString::fromUtf8(":/images/FileTypeCDImage.png")) ;
else if (ext == "txt" || ext == "cpp" || ext == "c" || ext == "h")
return QIcon(QString::fromUtf8(":/images/FileTypeDocument.png")) ;
else if (ext == "doc" || ext == "rtf" || ext == "sxw" || ext == "xls" || ext == "pps" || ext == "xml"
|| ext == "sxc" || ext == "odt" || ext == "ods" || ext == "dot" || ext == "ppt" || ext == "css" )
return QIcon(QString::fromUtf8(":/images/FileTypeDocument.png")) ;
else if (ext == "html" || ext == "htm" || ext == "php")
return QIcon(QString::fromUtf8(":/images/FileTypeDocument.png")) ;
else
return QIcon(QString::fromUtf8(":/images/FileTypeAny.png")) ;
}
int TransfersDialog::addPeerToItem(int row, const QString& name, const QString& coreID, double dlspeed, uint32_t status, const FileProgressInfo& peerInfo) int TransfersDialog::addPeerToItem(int row, const QString& name, const QString& coreID, double dlspeed, uint32_t status, const FileProgressInfo& peerInfo)
{ {
QStandardItem *dlItem = DLListModel->item(row); QStandardItem *dlItem = DLListModel->item(row);
@ -591,13 +590,20 @@ int TransfersDialog::addPeerToItem(int row, const QString& name, const QString&
} }
int TransfersDialog::addUploadItem(const QString&, const QString& name, const QString& coreID, qlonglong fileSize, const FileProgressInfo& pinfo, double dlspeed, const QString& source, const QString& status, qlonglong completed, qlonglong) int TransfersDialog::addUploadItem( const QString&, const QString& name, const QString& coreID,
qlonglong fileSize, const FileProgressInfo& pinfo, double dlspeed,
const QString& source, const QString& peer_id, const QString& status, qlonglong completed, qlonglong)
{ {
// Find items does not work reliably, because it (apparently) needs Qt to flush pending events to work, so we can't call it
// on a table that was just filled in.
//
int row ; int row ;
QList<QStandardItem *> list = ULListModel->findItems(coreID, Qt::MatchExactly, UHASH); for(row=0;row<ULListModel->rowCount();++row)
if (list.size() > 0) { if(ULListModel->item(row,UUSERID)->data(Qt::EditRole).toString() == peer_id && ULListModel->item(row,UHASH)->data(Qt::EditRole).toString() == coreID)
row = list.front()->row(); break ;
} else {
if(row >= ULListModel->rowCount() )
{
row = ULListModel->rowCount(); row = ULListModel->rowCount();
ULListModel->insertRow(row); ULListModel->insertRow(row);
} }
@ -610,64 +616,10 @@ int TransfersDialog::addUploadItem(const QString&, const QString& name, const QS
ULListModel->setData(ULListModel->index(row, USTATUS), QVariant((QString)status)); ULListModel->setData(ULListModel->index(row, USTATUS), QVariant((QString)status));
ULListModel->setData(ULListModel->index(row, USERNAME), QVariant((QString)source)); ULListModel->setData(ULListModel->index(row, USERNAME), QVariant((QString)source));
ULListModel->setData(ULListModel->index(row, UHASH), QVariant((QString)coreID)); ULListModel->setData(ULListModel->index(row, UHASH), QVariant((QString)coreID));
ULListModel->setData(ULListModel->index(row, UUSERID), QVariant((QString)peer_id));
QString ext = QFileInfo(name).suffix(); QString ext = QFileInfo(name).suffix();
if (ext == "rsfc" || ext == "rsfb") ULListModel->setData(ULListModel->index(row,UNAME), getIconFromExtension(ext), Qt::DecorationRole);
{
ULListModel->setData(ULListModel->index(row,UNAME), QIcon(QString::fromUtf8(":/images/folder16.png")), Qt::DecorationRole);
}
else if (ext == "rsrl")
{
ULListModel->setData(ULListModel->index(row,UNAME), QIcon(QString::fromUtf8(":/images/irkick.png")), Qt::DecorationRole);
}
else if (ext == "jpg" || ext == "jpeg" || ext == "tif" || ext == "tiff" || ext == "JPG"|| ext == "png" || ext == "gif"
|| ext == "bmp" || ext == "ico" || ext == "svg")
{
ULListModel->setData(ULListModel->index(row,UNAME), QIcon(QString::fromUtf8(":/images/FileTypePicture.png")), Qt::DecorationRole);
}
else if (ext == "avi" ||ext == "AVI" || ext == "mpg" || ext == "mpeg" || ext == "wmv" || ext == "divx" || ext == "ts"
|| ext == "mkv" || ext == "mp4" || ext == "flv" || ext == "mov" || ext == "asf" || ext == "xvid"
|| ext == "vob" || ext == "qt" || ext == "rm" || ext == "3gp" || ext == "mpeg" || ext == "ogm")
{
ULListModel->setData(ULListModel->index(row,UNAME), QIcon(QString::fromUtf8(":/images/FileTypeVideo.png")), Qt::DecorationRole);
}
else if (ext == "ogg" || ext == "mp3" || ext == "MP3" || ext == "mp1" || ext == "mp2" || ext == "wav" || ext == "wma")
{
ULListModel->setData(ULListModel->index(row,UNAME), QIcon(QString::fromUtf8(":/images/FileTypeAudio.png")), Qt::DecorationRole);
}
else if (ext == "tar" || ext == "bz2" || ext == "zip" || ext == "gz" || ext == "7z" || ext == "msi"
|| ext == "rar" || ext == "rpm" || ext == "ace" || ext == "jar" || ext == "tgz" || ext == "lha"
|| ext == "cab" || ext == "cbz"|| ext == "cbr" || ext == "alz" || ext == "sit" || ext == "arj" || ext == "deb")
{
ULListModel->setData(ULListModel->index(row,UNAME), QIcon(QString::fromUtf8(":/images/FileTypeArchive.png")), Qt::DecorationRole);
}
else if (ext == "app" || ext == "bat" || ext == "cgi" || ext == "com" || ext == "exe" || ext == "js" || ext == "pif"
|| ext == "py" || ext == "pl" || ext == "sh" || ext == "vb" || ext == "ws")
{
ULListModel->setData(ULListModel->index(row,UNAME), QIcon(QString::fromUtf8(":/images/FileTypeProgram.png")), Qt::DecorationRole);
}
else if (ext == "iso" || ext == "nrg" || ext == "mdf" || ext == "img" || ext == "dmg" || ext == "bin" )
{
ULListModel->setData(ULListModel->index(row,UNAME), QIcon(QString::fromUtf8(":/images/FileTypeCDImage.png")), Qt::DecorationRole);
}
else if (ext == "txt" || ext == "cpp" || ext == "c" || ext == "h")
{
ULListModel->setData(ULListModel->index(row,UNAME), QIcon(QString::fromUtf8(":/images/FileTypeDocument.png")), Qt::DecorationRole);
}
else if (ext == "doc" || ext == "rtf" || ext == "sxw" || ext == "xls" || ext == "pps" || ext == "xml"
|| ext == "sxc" || ext == "odt" || ext == "ods" || ext == "dot" || ext == "ppt" || ext == "css" )
{
ULListModel->setData(ULListModel->index(row,UNAME), QIcon(QString::fromUtf8(":/images/FileTypeDocument.png")), Qt::DecorationRole);
}
else if (ext == "html" || ext == "htm" || ext == "php")
{
ULListModel->setData(ULListModel->index(row,UNAME), QIcon(QString::fromUtf8(":/images/FileTypeDocument.png")), Qt::DecorationRole);
}
else
{
ULListModel->setData(ULListModel->index(row,UNAME), QIcon(QString::fromUtf8(":/images/FileTypeAny.png")), Qt::DecorationRole);
}
return row; return row;
} }
@ -704,8 +656,6 @@ void TransfersDialog::insertTransfers()
// std::list<DwlDetails> dwlDetails; // std::list<DwlDetails> dwlDetails;
// rsFiles->getDwlDetails(dwlDetails); // rsFiles->getDwlDetails(dwlDetails);
std::set<std::string> used_hashes ; std::set<std::string> used_hashes ;
// clear all source peers. // clear all source peers.
@ -859,7 +809,7 @@ void TransfersDialog::insertTransfers()
QString fileHash = QString::fromStdString(info.hash); QString fileHash = QString::fromStdString(info.hash);
QString fileName = QString::fromUtf8(info.fname.c_str()); QString fileName = QString::fromUtf8(info.fname.c_str());
QString sources = getPeerName(pit->peerId); QString source = getPeerName(pit->peerId);
QString status; QString status;
switch(pit->status) switch(pit->status)
@ -880,9 +830,9 @@ void TransfersDialog::insertTransfers()
double dlspeed = pit->tfRate * 1024.0; double dlspeed = pit->tfRate * 1024.0;
qlonglong fileSize = info.size; qlonglong fileSize = info.size;
qlonglong completed = info.transfered; qlonglong completed = pit->transfered;
double progress = (info.size > 0)?(info.transfered * 100.0 / info.size):0.0; double progress = (info.size > 0)?(pit->transfered * 100.0 / info.size):0.0;
qlonglong remaining = (info.size - info.transfered) / (info.tfRate * 1024.0); qlonglong remaining = (info.size - pit->transfered) / (pit->tfRate * 1024.0);
// Estimate the completion. We need something more accurate, meaning that we need to // Estimate the completion. We need something more accurate, meaning that we need to
// transmit the completion info. // transmit the completion info.
@ -903,9 +853,9 @@ void TransfersDialog::insertTransfers()
else else
pinfo.progress = progress ; pinfo.progress = progress ;
addUploadItem("", fileName, fileHash, fileSize, pinfo, dlspeed, sources, status, completed, remaining); addUploadItem("", fileName, fileHash, fileSize, pinfo, dlspeed, source,QString::fromStdString(pit->peerId), status, completed, remaining);
used_hashes.insert(info.hash) ; used_hashes.insert(fileHash.toStdString() + pit->peerId) ;
} }
} }
@ -916,9 +866,15 @@ void TransfersDialog::insertTransfers()
while (removeIndex < ULListModel->rowCount()) while (removeIndex < ULListModel->rowCount())
{ {
std::string hash = ULListModel->item(removeIndex, UHASH)->data(Qt::EditRole).toString().toStdString(); std::string hash = ULListModel->item(removeIndex, UHASH)->data(Qt::EditRole).toString().toStdString();
std::string peer = ULListModel->item(removeIndex, UUSERID)->data(Qt::EditRole).toString().toStdString();
if(used_hashes.find(hash) == used_hashes.end()) std::cerr<< "searching " << hash+peer << std::endl ;
if(used_hashes.find(hash + peer) == used_hashes.end())
{
std::cerr << "found"<< std::endl ;
QListDelete (ULListModel->takeRow(removeIndex)); QListDelete (ULListModel->takeRow(removeIndex));
}
else else
removeIndex++; removeIndex++;
} }

View File

@ -44,8 +44,6 @@ Q_OBJECT
public: public:
/** Default Constructor */ /** Default Constructor */
TransfersDialog(QWidget *parent = 0); TransfersDialog(QWidget *parent = 0);
/** Default Destructor */
~TransfersDialog();
// replaced by shortcut // replaced by shortcut
// virtual void keyPressEvent(QKeyEvent *) ; // virtual void keyPressEvent(QKeyEvent *) ;
@ -111,6 +109,7 @@ signals:
private: private:
QString getPeerName(const std::string& peer_id) const ; QString getPeerName(const std::string& peer_id) const ;
static QIcon getIconFromExtension(const QString&) ;
QStandardItemModel *DLListModel; QStandardItemModel *DLListModel;
QStandardItemModel *ULListModel; QStandardItemModel *ULListModel;
@ -175,7 +174,7 @@ public slots:
int addPeerToItem(int row, const QString& name, const QString& coreID, double dlspeed, uint32_t status, const FileProgressInfo& peerInfo); int addPeerToItem(int row, const QString& name, const QString& coreID, double dlspeed, uint32_t status, const FileProgressInfo& peerInfo);
void delItem(int row); void delItem(int row);
int addUploadItem(const QString& symbol, const QString& name, const QString& coreID, qlonglong size, const FileProgressInfo& pinfo, double dlspeed, const QString& sources, const QString& status, qlonglong completed, qlonglong remaining); int addUploadItem(const QString& symbol, const QString& name, const QString& coreID, qlonglong size, const FileProgressInfo& pinfo, double dlspeed, const QString& sources,const QString& source_id, const QString& status, qlonglong completed, qlonglong remaining);
void delUploadItem(int row); void delUploadItem(int row);
void showFileDetails() ; void showFileDetails() ;

View File

@ -33,6 +33,7 @@
#define USTATUS 5 #define USTATUS 5
#define USERNAME 6 #define USERNAME 6
#define UHASH 7 #define UHASH 7
#define UUSERID 8