[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: extragear/network/kmldonkey
From: Aleksey Markelov <markelovai () gmail ! com>
Date: 2009-07-06 16:20:36
Message-ID: 1246897236.954564.24715.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 992330 by amarkelov:
--qt3 (FileInfo download/downloaded containers)
M +1 -1 kmldonkey/availability.cpp
M +2 -2 kmldonkey/clientlist.cpp
M +5 -5 kmldonkey/downloadpage.cpp
M +45 -35 libkmldonkey/donkeyprotocol.cpp
M +6 -4 libkmldonkey/donkeyprotocol.h
M +10 -49 libkmldonkey/fileinfo.cpp
M +10 -12 libkmldonkey/fileinfo.h
--- trunk/extragear/network/kmldonkey/kmldonkey/availability.cpp #992329:992330
@@ -123,7 +123,7 @@
QChar dv;
if (isClientRenderer) {
- const QMap<int,QString>& cc = fi->fileSources();
+ const QHash<int,QByteArray>& cc = fi->fileSources();
if (cc.contains(clno)) {
const QString s = cc[clno];
dv = (chunk >= 0 && chunk < s.size()) ? s[chunk] : '0';
--- trunk/extragear/network/kmldonkey/kmldonkey/clientlist.cpp #992329:992330
@@ -222,8 +222,8 @@
int sortcol = sortColumn(), i = 0;
setUpdatesEnabled(false);
setSorting(-1);
- const QMap<int,QString>& src = fi->fileSources();
- QMap<int,QString>::ConstIterator it = src.begin();
+ const QHash<int,QByteArray>& src = fi->fileSources();
+ QHash<int,QByteArray>::ConstIterator it = src.begin();
for ( ; it != src.end(); ++it) {
++i;
while (sources.remove(it.key())) ;
--- trunk/extragear/network/kmldonkey/kmldonkey/downloadpage.cpp #992329:992330
@@ -155,11 +155,11 @@
void DownloadPage::updateDownloadView()
{
- Q3IntDictIterator<FileInfo> it (KMLDonkey::App->donkey->downloadFiles() );
-
- for ( ; it.current(); ++it )
- if ( it.current()->fileState() != FileInfo::Complete )
- fileUpdated( it.current()->fileNo() );
+ foreach (FileInfo *fi, KMLDonkey::App->donkey->downloadFiles()) {
+ if (fi->fileState() != FileInfo::Complete) {
+ fileUpdated(fi->fileNo());
+ }
+ }
}
void DownloadPage::slotSetFilterTimeout() //SLOT
--- trunk/extragear/network/kmldonkey/libkmldonkey/donkeyprotocol.cpp #992329:992330
@@ -45,6 +45,12 @@
#include <QHostAddress>
#include <kdebug.h>
+template<class T> void ptrContainerClear(T &cont)
+{
+ qDeleteAll(cont);
+ cont.clear();
+}
+
DonkeyProtocol::DonkeyProtocol(bool poll, QObject *parent)
: ProtocolInterface("mldonkey", parent)
, m_socket(new DonkeySocket(this))
@@ -55,8 +61,6 @@
connectedservers = 0;
proto = MIN_PROTOCOL_VERSION;
wantpoll = poll;
- download.setAutoDelete(true);
- downloaded.setAutoDelete(true);
servers.setAutoDelete(true);
networks.setAutoDelete(true);
clients.setAutoDelete(true);
@@ -71,6 +75,8 @@
DonkeyProtocol::~DonkeyProtocol()
{
+ qDeleteAll(download);
+ qDeleteAll(downloaded);
}
@@ -143,8 +149,8 @@
void DonkeyProtocol::flushState()
{
- download.clear();
- downloaded.clear();
+ ptrContainerClear(download);
+ ptrContainerClear(downloaded);
upload.clear();
servers.clear();
networks.clear();
@@ -190,11 +196,11 @@
void DonkeyProtocol::pruneClientRecord(int clientno)
{
- Q3IntDictIterator<FileInfo> it(download);
- for (; it.current(); ++it) {
- it.current()->removeSource(clientno);
- emit fileUpdated(it.current()->fileNo());
- emit fileSourceRemoved(it.current()->fileNo(), clientno);
+ foreach (FileInfo *fi, download) {
+ if (fi->removeSource(clientno)) {
+ emit fileUpdated(fi->fileNo());
+ emit fileSourceRemoved(fi->fileNo(), clientno);
+ }
}
if (friends.removeAll(clientno))
emit friendRemoved(clientno);
@@ -332,7 +338,7 @@
{
int fn = msg->readInt32();
int cl = msg->readInt32();
- QString av = msg->readString();
+ QByteArray av = msg->readByteArray();
FileInfo* file = findDownloadFileNo(fn);
if (file) {
file->updateAvailability(cl, av);
@@ -433,15 +439,17 @@
case DownloadFiles_v4:
case DownloadFiles:
{
- download.clear();
+ ptrContainerClear(download);
int i, j = msg->readInt16();
for (i=0; i<j; i++) {
- FileInfo* fi = new FileInfo(msg, proto);
- FileInfo* fo = findDownloadFileNo(fi->fileNo());
- if (fo)
- fo->updateFileInfo(fi);
- else
- download.replace(fi->fileNo(), fi);
+ int fn = msg->readInt32();
+ FileInfo *fi = findDownloadFileNo(fn);
+ if (fi) {
+ fi->updateFileInfo(msg, proto);
+ } else {
+ fi = new FileInfo(fn, msg, proto);
+ download.insert(fn, fi);
+ }
emit fileUpdated(fi->fileNo());
}
emit updatedDownloadFiles();
@@ -458,7 +466,7 @@
case FileInfo::Cancelled:
case FileInfo::Aborted:
emit fileRemoved(fn);
- download.remove(fi->fileNo());
+ delete download.take(fi->fileNo());
break;
default:
emit fileUpdated(fn);
@@ -472,15 +480,17 @@
case DownloadedFiles_v2:
case DownloadedFiles:
{
- downloaded.clear();
+ ptrContainerClear(downloaded);
int i, j = msg->readInt16();
for (i=0; i<j; i++) {
- FileInfo* fi = new FileInfo(msg, proto);
- FileInfo* fo = findDownloadedFileNo(fi->fileNo());
- if (fo)
- fo->updateFileInfo(fi);
- else
- downloaded.replace(fi->fileNo(), fi);
+ int fn = msg->readInt32();
+ FileInfo *fi = findDownloadedFileNo(fn);
+ if (fi) {
+ fi->updateFileInfo(msg, proto);
+ } else {
+ fi = new FileInfo(fn, msg, proto);
+ downloaded.insert(fn, fi);
+ }
}
emit updatedDownloadedFiles();
} break;
@@ -491,12 +501,12 @@
case File_info_v3:
case File_info:
{
- FileInfo* fi = findDownloadFileNo(msg->readInt32());
- msg->resetPosition();
+ int fn = msg->readInt32();
+ FileInfo* fi = findDownloadFileNo(fn);
bool isnew = ! fi;
if (isnew) {
- fi = new FileInfo(msg, proto);
- download.replace(fi->fileNo(), fi);
+ fi = new FileInfo(fn, msg, proto);
+ download.insert(fn, fi);
} else {
fi->updateFileInfo(msg, proto);
}
@@ -504,12 +514,12 @@
case FileInfo::Shared:
case FileInfo::Cancelled:
case FileInfo::Aborted:
- emit fileRemoved(fi->fileNo());
- download.remove(fi->fileNo());
+ emit fileRemoved(fn);
+ delete download.take(fn);
break;
default:
- emit fileUpdated(fi->fileNo());
- if (isnew) emit fileAdded(fi->fileNo(), downloadstarted);
+ emit fileUpdated(fn);
+ if (isnew) emit fileAdded(fn, downloadstarted);
break;
}
} break;
@@ -836,12 +846,12 @@
m_socket->sendMessage(DonkeyMessage(GetConnectedServers));
}
-const Q3IntDict<FileInfo>& DonkeyProtocol::downloadFiles()
+const FileInfoHash& DonkeyProtocol::downloadFiles()
{
return download;
}
-const Q3IntDict<FileInfo>& DonkeyProtocol::downloadedFiles()
+const FileInfoHash& DonkeyProtocol::downloadedFiles()
{
return downloaded;
}
--- trunk/extragear/network/kmldonkey/libkmldonkey/donkeyprotocol.h #992329:992330
@@ -68,6 +68,8 @@
class ResultInfo;
class SearchQuery;
+typedef QHash<int, FileInfo *> FileInfoHash;
+
//! A high level abstraction of the mldonkey GUI protocol.
/*!
* DonkeyProtocol wraps around a DonkeySocket object, and handles all
@@ -321,14 +323,14 @@
* \return A dictionary containing FileInfo objects representing the
* currently downloading files, indexed on their fileNo() values.
*/
- const Q3IntDict<FileInfo>& downloadFiles();
+ const FileInfoHash& downloadFiles();
//! Get the completed files.
/*!
* \return A dictionary containing FileInfo objects representing the
* completed files, indexed on their fileNo() values.
*/
- const Q3IntDict<FileInfo>& downloadedFiles();
+ const FileInfoHash& downloadedFiles();
//! Get the connected servers.
/*!
@@ -836,8 +838,8 @@
DonkeySocket *m_socket;
QString uname, passwd;
- Q3IntDict<FileInfo> download;
- Q3IntDict<FileInfo> downloaded;
+ FileInfoHash download;
+ FileInfoHash downloaded;
QMap<int,bool> upload;
Q3IntDict<ServerInfo> servers;
Q3IntDict<Network> networks;
--- trunk/extragear/network/kmldonkey/libkmldonkey/fileinfo.cpp #992329:992330
@@ -32,66 +32,27 @@
-FileInfo::FileInfo(DonkeyMessage* msg, int proto)
+FileInfo::FileInfo(int num, DonkeyMessage* msg, int proto)
{
- first = true;
+ this->num = num;
updateFileInfo(msg, proto);
-}
-FileInfo::FileInfo(const FileInfo& fi)
-{
- num = fi.fileNo();
- first = true;
- updateFileInfo(&fi);
+ firstdown = downloaded;
+ firsttime = time(0);
}
FileInfo::~FileInfo()
{
}
-void FileInfo::updateFileInfo(const FileInfo* fi)
-{
- network = fi->fileNetwork();
- names = fi->fileNames();
- size = fi->fileSize();
- downloaded = fi->fileDownloaded();
- if (first) {
- firstdown = downloaded;
- first = false;
- firsttime = time(0);
- }
- nlocations = fi->fileNLocations();
- nclients = fi->fileNClients();
- state = fi->fileState();
- abortedmsg = fi->fileAbortedMsg();
- chunks = fi->fileChunks();
- availability = fi->fileAvailability();
- speed = fi->fileSpeed();
- chunks_age = fi->fileChunksAge();
- age = fi->fileAge();
- format = fi->fileFormat();
- formatinfo = fi->fileFormatInfo();
- name = fi->fileName();
- lastseen = fi->fileLastSeen();
- priority = fi->filePriority();
- comment = fi->fileComment();
- uids = fi->fileUids();
-}
-
void FileInfo::updateFileInfo(DonkeyMessage* msg, int proto)
{
int i,j;
- num = msg->readInt32();
network = msg->readInt32();
names = msg->readStringList();
QByteArray md4 = msg->readMd4();
size = msg->readInt64();
downloaded = msg->readInt64();
- if (first) {
- firstdown = downloaded;
- first = false;
- firsttime = time(0);
- }
nlocations = msg->readInt32();
nclients = msg->readInt32();
state = (State)msg->readInt8();
@@ -317,7 +278,7 @@
return chunks;
}
-const QMap<int,QByteArray>& FileInfo::fileAvailability() const
+const QHash<int,QByteArray>& FileInfo::fileAvailability() const
{
return availability;
}
@@ -362,7 +323,7 @@
return priority;
}
-const QMap<int,QString>& FileInfo::fileSources() const
+const QHash<int,QByteArray>& FileInfo::fileSources() const
{
return sources;
}
@@ -381,15 +342,15 @@
void FileInfo::addSource(int source)
{
if (!sources.contains(source))
- sources.insert(source, QString::null);
+ sources.insert(source, QByteArray());
}
-void FileInfo::removeSource(int source)
+bool FileInfo::removeSource(int source)
{
- sources.remove(source);
+ return sources.remove(source) != 0;
}
-void FileInfo::updateAvailability(int source, const QString& avail)
+void FileInfo::updateAvailability(int source, const QByteArray &avail)
{
sources.insert(source, avail);
}
--- trunk/extragear/network/kmldonkey/libkmldonkey/fileinfo.h #992329:992330
@@ -25,7 +25,7 @@
#include <QString>
#include <QStringList>
-#include <QMap>
+#include <QHash>
#include <sys/types.h>
#include <time.h>
@@ -53,13 +53,10 @@
Queued
};
- FileInfo(DonkeyMessage* msg, int proto);
- FileInfo(const FileInfo&);
- FileInfo() { num = 0; }
+ FileInfo(int num, DonkeyMessage* msg, int proto);
~FileInfo();
void updateFileInfo(DonkeyMessage* msg, int proto);
- void updateFileInfo(const FileInfo* fi);
//! The numerical ID of the file.
const int& fileNo() const;
@@ -90,7 +87,7 @@
//! String describing file chunks downloaded, one char for each chunk.
const QByteArray& fileChunks() const;
//! A map of networks, with each value describing chunk availability, one char for each chunk.
- const QMap<int,QByteArray>& fileAvailability() const;
+ const QHash<int,QByteArray>& fileAvailability() const;
//! Current download speed.
const double& fileSpeed() const;
//! The age of individual chunks.
@@ -108,15 +105,15 @@
//! The file priority.
const int& filePriority() const;
//! File availability described by a map of client IDs to strings similar to fileChunks().
- const QMap<int,QString>& fileSources() const;
+ const QHash<int,QByteArray>& fileSources() const;
//! The file's comment, if any.
const QString& fileComment() const;
void setFileName(const QString& newname);
void addSource(int source);
- void removeSource(int source);
- void updateAvailability(int source, const QString& avail);
+ bool removeSource(int source);
+ void updateAvailability(int source, const QByteArray &avail);
void updateDownloadStatus(DonkeyMessage* msg, int proto);
//! Converts a QByteArray containing an MD4 hash to a readable string.
@@ -141,7 +138,7 @@
State state;
QString abortedmsg;
QByteArray chunks;
- QMap<int,QByteArray> availability;
+ QHash<int,QByteArray> availability;
double speed;
QList<time_t> chunks_age;
time_t age, firsttime;
@@ -149,9 +146,10 @@
QString formatinfo;
int lastseen, priority;
QString comment;
- bool first;
- QMap<int,QString> sources;
+ QHash<int,QByteArray> sources;
+
+ Q_DISABLE_COPY(FileInfo);
};
#endif
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic