From 81203b3cfdea0e30681940985baeb3a28aa067bb Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 27 Jul 2010 16:05:21 +0000 Subject: [PATCH] - 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 --- libretroshare/src/ft/ftdatamultiplex.cc | 32 ++-- libretroshare/src/ft/ftfilecreator.cc | 4 +- libretroshare/src/ft/ftfilecreator.h | 2 +- libretroshare/src/ft/ftfileprovider.cc | 160 +++++++++-------- libretroshare/src/ft/ftfileprovider.h | 40 +++-- libretroshare/src/rsiface/rstypes.h | 11 +- retroshare-gui/src/gui/TransfersDialog.cpp | 196 ++++++++------------- retroshare-gui/src/gui/TransfersDialog.h | 5 +- retroshare-gui/src/gui/ULListDelegate.h | 15 +- 9 files changed, 220 insertions(+), 245 deletions(-) diff --git a/libretroshare/src/ft/ftdatamultiplex.cc b/libretroshare/src/ft/ftdatamultiplex.cc index 35c30da2b..818cbb893 100644 --- a/libretroshare/src/ft/ftdatamultiplex.cc +++ b/libretroshare/src/ft/ftdatamultiplex.cc @@ -684,10 +684,8 @@ bool ftDataMultiplex::locked_handleServerRequest(ftFileProvider *provider, std::cerr << std::endl; #endif - if (provider->getFileData(offset, chunksize, data)) + if (provider->getFileData(peerId,offset, chunksize, data)) { - // setup info - provider->setPeerId(peerId) ; /* send data out */ sendData(peerId, hash, size, offset, chunksize, data); return true; @@ -738,26 +736,26 @@ void ftDataMultiplex::deleteUnusedServers() //scan the uploads list in ftdatamultiplex and delete the items which time out time_t now = time(NULL); - + for(std::map::iterator sit(mServers.begin());sit != mServers.end();) - if ((now - sit->second->lastTS) > 10) - { + if(sit->second->purgeOldPeers(now,10)) + { #ifdef SERVER_DEBUG - std::cout << "info.lastTS = " << info.lastTS << ", now=" << now << std::endl ; + std::cout << "info.lastTS = " << info.lastTS << ", now=" << now << std::endl ; #endif - // We don't delete servers that are clients at the same time ! - if(dynamic_cast(sit->second) == NULL) - delete sit->second; + // We don't delete servers that are clients at the same time ! + if(dynamic_cast(sit->second) == NULL) + delete sit->second; - std::map::iterator tmp(sit); - ++tmp ; + std::map::iterator tmp(sit); + ++tmp ; - mServers.erase(sit); + mServers.erase(sit); - sit = tmp ; - } - else - ++sit ; + sit = tmp ; + } + else + ++sit ; } bool ftDataMultiplex::handleSearchRequest(const std::string& peerId, const std::string& hash) diff --git a/libretroshare/src/ft/ftfilecreator.cc b/libretroshare/src/ft/ftfilecreator.cc index 0a3d9deb4..d407c27d7 100644 --- a/libretroshare/src/ft/ftfilecreator.cc +++ b/libretroshare/src/ft/ftfilecreator.cc @@ -38,7 +38,7 @@ ftFileCreator::ftFileCreator(std::string path, uint64_t size, std::string hash) _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. // @@ -50,7 +50,7 @@ bool ftFileCreator::getFileData(uint64_t offset, uint32_t &chunk_size, void *dat } if(have_it) - return ftFileProvider::getFileData(offset, chunk_size, data); + return ftFileProvider::getFileData(peer_id,offset, chunk_size, data); else return false ; } diff --git a/libretroshare/src/ft/ftfilecreator.h b/libretroshare/src/ft/ftfilecreator.h index 7beb34ff7..1048fa7c7 100644 --- a/libretroshare/src/ft/ftfilecreator.h +++ b/libretroshare/src/ft/ftfilecreator.h @@ -45,7 +45,7 @@ class ftFileCreator: public ftFileProvider ~ftFileCreator(); /* 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() ; uint64_t getRecvd(); diff --git a/libretroshare/src/ft/ftfileprovider.cc b/libretroshare/src/ft/ftfileprovider.cc index 9d82e07ee..485756c9f 100644 --- a/libretroshare/src/ft/ftfileprovider.cc +++ b/libretroshare/src/ft/ftfileprovider.cc @@ -10,18 +10,16 @@ #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 -hash) : mSize(size), hash(hash), file_name(path), fd(NULL),req_loc(0),transfer_rate(0),total_size(0) +ftFileProvider::ftFileProvider(std::string path, uint64_t size, std::string hash) + : mSize(size), hash(hash), file_name(path), fd(NULL) { RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/ - clients_chunk_maps.clear(); + #ifdef DEBUG_FT_FILE_PROVIDER std::cout << "Creating file provider for " << hash << std::endl ; #endif - lastTS = time(NULL) ; - lastTS_t = lastTS ; } ftFileProvider::~ftFileProvider(){ @@ -34,15 +32,9 @@ ftFileProvider::~ftFileProvider(){ } } -void ftFileProvider::setPeerId(const std::string& id) -{ - RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/ - lastRequestor = id ; -} - bool ftFileProvider::fileOk() { - RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/ + RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/ return (fd != NULL); } @@ -65,25 +57,54 @@ bool ftFileProvider::FileDetails(FileInfo &info) info.size = mSize; info.path = 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.peers.clear() ; + float total_transfer_rate = 0.0f ; - TransferInfo inf ; - inf.peerId = lastRequestor ; - inf.status = FT_STATE_DOWNLOADING ; + for(std::map::const_iterator it(uploading_peers.begin());it!=uploading_peers.end();++it) + { + TransferInfo inf ; + inf.peerId = it->first ; + inf.status = FT_STATE_DOWNLOADING ; + inf.name = info.fname ; + inf.transfered = it->second.req_loc ; - inf.tfRate = transfer_rate/1024.0 ; - info.tfRate = transfer_rate/1024.0 ; - info.peers.push_back(inf) ; + inf.tfRate = it->second.transfer_rate/1024.0 ; + total_transfer_rate += it->second.transfer_rate ; + info.lastTS = std::max(info.lastTS,it->second.lastTS); + + info.peers.push_back(inf) ; + } + info.tfRate = total_transfer_rate/1024.0 ; /* Use req_loc / req_size to estimate data rate */ return true; } +bool ftFileProvider::purgeOldPeers(time_t now,uint32_t max_duration) +{ + bool ret = true ; + for(std::map::iterator it(uploading_peers.begin());it!=uploading_peers.end();) + if( (*it).second.lastTS+max_duration < (uint32_t)now) + { + std::map::iterator tmp = it ; + ++tmp ; + uploading_peers.erase(it) ; + it=tmp ; + } + else + { + ret = false ; + ++it ; + } + return ret ; +} + void ftFileProvider::getAvailabilityMap(CompressedChunkMap& cmap) { // 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... * much check again inside FileAttrs(). @@ -158,67 +179,69 @@ bool ftFileProvider::getFileData(uint64_t offset, uint32_t &chunk_size, void *da * (d) timestamp */ - time_t now_t = time(NULL) ; - - long int diff = (long int)now_t - (long int)lastTS_t ; // in bytes/s. Average over multiple samples - -#ifdef DEBUG_FT_FILE_PROVIDER - std::cout << "diff = " << diff << std::endl ; -#endif - - if(diff > 3) - { - transfer_rate = total_size / (float)diff ; -#ifdef DEBUG_FT_FILE_PROVIDER - std::cout << "updated TR = " << transfer_rate << ", total_size=" << total_size << std::endl ; -#endif - lastTS_t = now_t ; - total_size = 0 ; - } - - req_loc = offset; - lastTS = time(NULL) ; - req_size = data_size; - total_size += req_size ; + // This creates the peer info, and updates it. + // + time_t now = time(NULL) ; + uploading_peers[peer_id].updateStatus(offset,data_size,now) ; } - else { + else + { std::cerr << "No data to read" << std::endl; return 0; } return 1; } +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 + std::cout << "diff = " << diff << std::endl ; +#endif + + if(diff > 3) + { + transfer_rate = total_size / (float)diff ; +#ifdef DEBUG_FT_FILE_PROVIDER + std::cout << "updated TR = " << transfer_rate << ", total_size=" << total_size << std::endl ; +#endif + lastTS_t = now ; + total_size = 0 ; + } + + req_loc = offset; + req_size = data_size; + total_size += req_size ; +} + void ftFileProvider::setClientMap(const std::string& peer_id,const CompressedChunkMap& cmap) { RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/ - std::pair& map_info(clients_chunk_maps[peer_id]) ; - - map_info.first = cmap ; - map_info.second = time(NULL) ; + // Create by default. + uploading_peers[peer_id].client_chunk_map = cmap ; + uploading_peers[peer_id].client_chunk_map_stamp = time(NULL) ; } void ftFileProvider::getClientMap(const std::string& peer_id,CompressedChunkMap& cmap,bool& map_is_too_old) { RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/ - std::map >::iterator it(clients_chunk_maps.find(peer_id)) ; - - if(it == clients_chunk_maps.end()) - { - clients_chunk_maps[peer_id] = std::pair(CompressedChunkMap(),0) ; - it = clients_chunk_maps.find(peer_id) ; - } - - if(time(NULL) - it->second.second > UPLOAD_CHUNK_MAPS_TIME) + PeerUploadInfo& pui(uploading_peers[peer_id]) ; + + time_t now = time(NULL) ; + + if(now - pui.client_chunk_map_stamp > UPLOAD_CHUNK_MAPS_TIME) { 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 map_is_too_old = false ; - cmap = it->second.first ; + cmap = pui.client_chunk_map; } 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; } diff --git a/libretroshare/src/ft/ftfileprovider.h b/libretroshare/src/ft/ftfileprovider.h index 1098a2372..85d304619 100644 --- a/libretroshare/src/ft/ftfileprovider.h +++ b/libretroshare/src/ft/ftfileprovider.h @@ -41,14 +41,12 @@ class ftFileProvider ftFileProvider(std::string path, uint64_t size, std::string hash); 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); std::string getHash(); uint64_t getFileSize(); 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 // a file creator, because the file is actually being downloaded, then the map may be partially complete. // 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 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: virtual int initializeFileAttrs(); /* does for both */ @@ -78,17 +78,31 @@ class ftFileProvider * Structure to gather statistics FIXME: lastRequestor - figure out a * way to get last requestor (peerID) */ - std::string lastRequestor; - uint64_t req_loc; - uint32_t req_size; - time_t lastTS_t; // used for estimating transfer rate. + class PeerUploadInfo + { + public: + PeerUploadInfo() + : req_loc(0),req_size(1), lastTS_t(0), transfer_rate(0), total_size(0), client_chunk_map_stamp(0) {} - // these two are used for speed estimation - float transfer_rate ; - uint32_t total_size ; + void updateStatus(uint64_t offset,uint32_t data_size,time_t now) ; - // Info about what the downloading peer already has - std::map > clients_chunk_maps ; + uint64_t req_loc; + uint32_t req_size; + time_t lastTS_t; // used for estimating transfer rate. + time_t lastTS; // last update time (for purging) + + // these two are used for speed estimation + float transfer_rate ; + uint32_t total_size ; + + // Info about what the downloading peer already has + 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 uploading_peers ; /* * Mutex Required for stuff below diff --git a/libretroshare/src/rsiface/rstypes.h b/libretroshare/src/rsiface/rstypes.h index edd81f063..aa0d67eb3 100644 --- a/libretroshare/src/rsiface/rstypes.h +++ b/libretroshare/src/rsiface/rstypes.h @@ -57,11 +57,12 @@ const uint32_t RS_CONFIG_DIRECTORY = 0x0002 ; class TransferInfo { public: - /**** Need Some of these Fields ****/ - std::string peerId; - std::string name; /* if has alternative name? */ - double tfRate; /* kbytes */ - int status; /* FT_STATE_... */ + /**** Need Some of these Fields ****/ + std::string peerId; + std::string name; /* if has alternative name? */ + double tfRate; /* kbytes */ + int status; /* FT_STATE_... */ + uint64_t transfered ; // used when no chunkmap data is available }; enum QueueMove { QUEUE_TOP = 0x00, diff --git a/retroshare-gui/src/gui/TransfersDialog.cpp b/retroshare-gui/src/gui/TransfersDialog.cpp index 5b9256908..d92b026d6 100644 --- a/retroshare-gui/src/gui/TransfersDialog.cpp +++ b/retroshare-gui/src/gui/TransfersDialog.cpp @@ -143,6 +143,8 @@ TransfersDialog::TransfersDialog(QWidget *parent) ULListModel->setHeaderData(UTRANSFERRED, Qt::Horizontal, tr("Transferred", "")); ULListModel->setHeaderData(UHASH, Qt::Horizontal, tr("Hash", "")); ui.uploadsList->setModel(ULListModel); + ULListModel->insertColumn(UUSERID); + ui.uploadsList->hideColumn(UUSERID); ULDelegate = new ULListDelegate(); ui.uploadsList->setItemDelegate(ULDelegate); @@ -416,12 +418,6 @@ void TransfersDialog::downloadListCostumPopupMenu( QPoint point ) contextMnu.exec(QCursor::pos()); } -TransfersDialog::~TransfersDialog() -{ - ; -} - - 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) { @@ -447,37 +443,40 @@ int TransfersDialog::addItem(const QString&, const QString& name, const QString& DLListModel->setData(DLListModel->index(row, ID), QVariant((QString)coreID)); QString ext = QFileInfo(name).suffix(); - if (ext == "jpg" || ext == "jpeg" || ext == "tif" || ext == "tiff" || ext == "JPG"|| ext == "png" || ext == "gif" - || 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); - } + DLListModel->setData(DLListModel->index(row,NAME), getIconFromExtension(ext), 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) @@ -591,85 +590,38 @@ 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) { - int row; - QList list = ULListModel->findItems(coreID, Qt::MatchExactly, UHASH); - if (list.size() > 0) { - row = list.front()->row(); - } else { - row = ULListModel->rowCount(); - ULListModel->insertRow(row); - } + // 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 ; + for(row=0;rowrowCount();++row) + if(ULListModel->item(row,UUSERID)->data(Qt::EditRole).toString() == peer_id && ULListModel->item(row,UHASH)->data(Qt::EditRole).toString() == coreID) + break ; - ULListModel->setData(ULListModel->index(row, UNAME), QVariant((QString)" "+name), Qt::DisplayRole); - ULListModel->setData(ULListModel->index(row, USIZE), QVariant((qlonglong)fileSize)); - ULListModel->setData(ULListModel->index(row, UTRANSFERRED), QVariant((qlonglong)completed)); - ULListModel->setData(ULListModel->index(row, ULSPEED), QVariant((double)dlspeed)); - ULListModel->setData(ULListModel->index(row, UPROGRESS), QVariant::fromValue(pinfo)); - ULListModel->setData(ULListModel->index(row, USTATUS), QVariant((QString)status)); - ULListModel->setData(ULListModel->index(row, USERNAME), QVariant((QString)source)); - ULListModel->setData(ULListModel->index(row, UHASH), QVariant((QString)coreID)); - - QString ext = QFileInfo(name).suffix(); - if (ext == "rsfc" || ext == "rsfb") - { - 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); - } + if(row >= ULListModel->rowCount() ) + { + row = ULListModel->rowCount(); + ULListModel->insertRow(row); + } + ULListModel->setData(ULListModel->index(row, UNAME), QVariant((QString)" "+name), Qt::DisplayRole); + ULListModel->setData(ULListModel->index(row, USIZE), QVariant((qlonglong)fileSize)); + ULListModel->setData(ULListModel->index(row, UTRANSFERRED), QVariant((qlonglong)completed)); + ULListModel->setData(ULListModel->index(row, ULSPEED), QVariant((double)dlspeed)); + ULListModel->setData(ULListModel->index(row, UPROGRESS), QVariant::fromValue(pinfo)); + ULListModel->setData(ULListModel->index(row, USTATUS), QVariant((QString)status)); + ULListModel->setData(ULListModel->index(row, USERNAME), QVariant((QString)source)); + ULListModel->setData(ULListModel->index(row, UHASH), QVariant((QString)coreID)); + ULListModel->setData(ULListModel->index(row, UUSERID), QVariant((QString)peer_id)); - return row; + QString ext = QFileInfo(name).suffix(); + ULListModel->setData(ULListModel->index(row,UNAME), getIconFromExtension(ext), Qt::DecorationRole); + + return row; } @@ -704,8 +656,6 @@ void TransfersDialog::insertTransfers() // std::list dwlDetails; // rsFiles->getDwlDetails(dwlDetails); - - std::set used_hashes ; // clear all source peers. @@ -859,7 +809,7 @@ void TransfersDialog::insertTransfers() QString fileHash = QString::fromStdString(info.hash); QString fileName = QString::fromUtf8(info.fname.c_str()); - QString sources = getPeerName(pit->peerId); + QString source = getPeerName(pit->peerId); QString status; switch(pit->status) @@ -880,9 +830,9 @@ void TransfersDialog::insertTransfers() double dlspeed = pit->tfRate * 1024.0; qlonglong fileSize = info.size; - qlonglong completed = info.transfered; - double progress = (info.size > 0)?(info.transfered * 100.0 / info.size):0.0; - qlonglong remaining = (info.size - info.transfered) / (info.tfRate * 1024.0); + qlonglong completed = pit->transfered; + double progress = (info.size > 0)?(pit->transfered * 100.0 / info.size):0.0; + qlonglong remaining = (info.size - pit->transfered) / (pit->tfRate * 1024.0); // Estimate the completion. We need something more accurate, meaning that we need to // transmit the completion info. @@ -903,9 +853,9 @@ void TransfersDialog::insertTransfers() else 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()) { 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)); + } else removeIndex++; } diff --git a/retroshare-gui/src/gui/TransfersDialog.h b/retroshare-gui/src/gui/TransfersDialog.h index d48f250d7..f2b4958e9 100644 --- a/retroshare-gui/src/gui/TransfersDialog.h +++ b/retroshare-gui/src/gui/TransfersDialog.h @@ -44,8 +44,6 @@ Q_OBJECT public: /** Default Constructor */ TransfersDialog(QWidget *parent = 0); - /** Default Destructor */ - ~TransfersDialog(); // replaced by shortcut // virtual void keyPressEvent(QKeyEvent *) ; @@ -111,6 +109,7 @@ signals: private: QString getPeerName(const std::string& peer_id) const ; + static QIcon getIconFromExtension(const QString&) ; QStandardItemModel *DLListModel; 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); 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 showFileDetails() ; diff --git a/retroshare-gui/src/gui/ULListDelegate.h b/retroshare-gui/src/gui/ULListDelegate.h index 0bffdeb82..a5960b9e2 100644 --- a/retroshare-gui/src/gui/ULListDelegate.h +++ b/retroshare-gui/src/gui/ULListDelegate.h @@ -25,14 +25,15 @@ #include // Defines for upload list list columns -#define UNAME 0 -#define USIZE 1 +#define UNAME 0 +#define USIZE 1 #define UTRANSFERRED 2 -#define ULSPEED 3 -#define UPROGRESS 4 -#define USTATUS 5 -#define USERNAME 6 -#define UHASH 7 +#define ULSPEED 3 +#define UPROGRESS 4 +#define USTATUS 5 +#define USERNAME 6 +#define UHASH 7 +#define UUSERID 8