You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

117 lines
3.5 KiB

/***************************************************************************
* Copyright (C) 2008 by Oliver Groß *
* z.o.gross@gmx.de *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "qtransferlistmodel.h"
namespace qftrans {
QTransferListModel::QTransferListModel(QTransferDataList * data, QObject * parent) : QAbstractListModel(parent), m_Data(data) {
}
QTransferListModel::~QTransferListModel() {
}
int QTransferListModel::rowCount(const QModelIndex & /*parent*/) const {
if (m_Data)
return m_Data->size();
else
return 0;
}
QVariant QTransferListModel::data(const QModelIndex & index, int role) const {
if (role != Qt::DisplayRole)
return QVariant();
TransferData * data = static_cast<TransferData *>(index.internalPointer());
if (!data)
return QVariant();
QString status;
switch (data->status) {
case TS_SUSPENDED:
status = tr("suspended");
break;
case TS_PENDING:
status = tr("pending");
break;
case TS_ANNOUNCING:
status = tr("announcing to peer");
break;
case TS_WAITING:
status = tr("waiting");
break;
case TS_TRANSFERING:
status = data->localFile ? tr("Sending") : tr("Recieving");
break;
case TS_CLOSING:
status = tr("closing down");
break;
case TS_FINISHED:
status = (data->transfered == data->size) ? tr("finished") : tr("canceled");
break;
default:
status = tr("unknown status");
break;
}
QString size;
unsigned int fancySize = data->size;
unsigned int siCount = 0;
while (fancySize > 1000) {
fancySize /= 1000;
siCount++;
}
size = QString::number(fancySize);
switch (siCount) {
case 0:
break;
case 1:
size += 'K';
break;
case 2:
size += 'M';
break;
case 3:
size += 'G';
break;
default:
size += "*10^" + QString::number(siCount);
break;
}
size += 'B';
return (data->localFile ? "out #" : "in #") + QString::number(index.row()) + " [" + status + "] (" +
QString::number((unsigned int)((100.0 * data->transfered) / data->size)) + "%) " +
data->fileName + " (size: " + size + ")";
}
QModelIndex QTransferListModel::index (int row, int column, const QModelIndex & /*parent*/) const {
return createIndex(row, column, m_Data->at(row));
}
void QTransferListModel::updateEntry(TransferData * /*entry*/) {
// TODO proper tranfer entry update
emit layoutChanged();
}
}