Source code maintenance

Memory leaks:
- TransfersDialog::insertTransfers -> takeRow

Improvement:
- updating display of DetailsDialog in TransferDialog
  todo: maybe show summary of all selected files, calculating in TransfersDialog::updateDetailsDialog


git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2846 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2010-05-03 22:44:53 +00:00
parent 8feeb2adb3
commit 4e1395a14a
4 changed files with 149 additions and 110 deletions

View File

@ -36,8 +36,8 @@
#include <QStandardItemModel>
#include "util/misc.h"
#include <rsiface/rsfiles.h>
#include <rsiface/rstypes.h>
#include "TransfersDialog.h"
/** Default constructor */
DetailsDialog::DetailsDialog(QWidget *parent, Qt::WFlags flags)
@ -47,6 +47,8 @@ DetailsDialog::DetailsDialog(QWidget *parent, Qt::WFlags flags)
ui.setupUi(this);
setAttribute ( Qt::WA_DeleteOnClose, true );
CommentsModel = new QStandardItemModel(0, 3);
CommentsModel->setHeaderData(0, Qt::Horizontal, tr("Rating"));
CommentsModel->setHeaderData(1, Qt::Horizontal, tr("Comments"));
@ -63,15 +65,12 @@ DetailsDialog::DetailsDialog(QWidget *parent, Qt::WFlags flags)
_coheader->resizeSection ( 1, 240 );
_coheader->resizeSection ( 2, 100 );
updateDisplay();
}
/** Destructor. */
DetailsDialog::~DetailsDialog()
{
TransfersDialog::detailsdlg = NULL;
}
void DetailsDialog::on_ok_dButton_clicked()
@ -91,18 +90,17 @@ DetailsDialog::show()
{
ui.tabWidget->setCurrentIndex(0);
if (!this->isVisible()) {
QDialog::show();
} else {
QDialog::activateWindow();
setWindowState(windowState() & ~Qt::WindowMinimized | Qt::WindowActive);
QDialog::raise();
}
QDialog::show();
} else {
QDialog::activateWindow();
setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
QDialog::raise();
}
}
void DetailsDialog::closeEvent (QCloseEvent * event)
{
QWidget::closeEvent(event);
}
void DetailsDialog::setFileName(const QString & filename)
@ -113,7 +111,6 @@ void DetailsDialog::setFileName(const QString & filename)
c = CommentsModel->rowCount();
CommentsModel->removeRows(0,c);
{
c = CommentsModel->rowCount();
CommentsModel->insertRow(c);
@ -125,7 +122,6 @@ void DetailsDialog::setFileName(const QString & filename)
index = CommentsModel->index(c, 2);
CommentsModel->setData(index, filename);
}
ui.name_label_2->setText(filename);
@ -171,19 +167,19 @@ void DetailsDialog::setDatarate(const double & datarate)
ui.datarate_line->setText(temp);
}
void DetailsDialog::setCompleted(const qulonglong & completed)
void DetailsDialog::setCompleted(const QString & completed)
{
ui.completed_line->setText(misc::friendlyUnit(completed));
ui.completed_line->setText(completed);
}
void DetailsDialog::setRemaining(const qulonglong & remaining)
void DetailsDialog::setRemaining(const QString & remaining)
{
ui.remaining_line->setText(misc::friendlyUnit(remaining));
ui.remaining_line->setText(remaining);
}
void DetailsDialog::setDownloadtime(const qulonglong & downloadtime)
void DetailsDialog::setDownloadtime(const QString & downloadtime)
{
ui.downloadtime_line->setText(misc::userFriendlyDuration(downloadtime));
ui.downloadtime_line->setText(downloadtime);
}
void DetailsDialog::setLink(const QString & link)
@ -191,33 +187,12 @@ void DetailsDialog::setLink(const QString & link)
ui.Linktext->setText(link);
}
void DetailsDialog::showEvent(QShowEvent *event)
void DetailsDialog::setChunkSize(uint32_t chunksize)
{
updateDisplay();
ui.chunksizelabel->setText(misc::friendlyUnit(chunksize));
}
void DetailsDialog::updateDisplay()
void DetailsDialog::setNumberOfChunks(size_t numberofchunks)
{
bool ok=true ;
FileInfo nfo ;
if(!rsFiles->FileDetails(_file_hash, RS_FILE_HINTS_DOWNLOAD, nfo))
ok = false ;
FileChunksInfo info ;
if(!rsFiles->FileDownloadChunksDetails(_file_hash, info))
ok = false ;
if(ok)
{
uint32_t blockSize = info.chunk_size ;
ui.chunksizelabel->setText(misc::friendlyUnit(blockSize));
ui.numberofchunkslabel->setText(QString::number(info.chunks.size()));
}
}
ui.numberofchunkslabel->setText(QString::number(numberofchunks));
}

View File

@ -41,8 +41,6 @@ public:
/** Default destructor */
~DetailsDialog();
void updateDisplay() ;
void setFileHash(const std::string& hash) { _file_hash = hash ; }
public slots:
@ -57,17 +55,17 @@ public slots:
void setPriority(const QString & priority);
void setSources(const QString & sources);
void setDatarate(const double & datarate);
void setCompleted(const qulonglong & completed);
void setRemaining(const qulonglong & remaining) ;
void setDownloadtime(const qulonglong & downloadtime);
void setCompleted(const QString & completed);
void setRemaining(const QString & remaining) ;
void setDownloadtime(const QString & downloadtime);
void setType(const QString & type);
void setChunkSize(const uint32_t chunksize);
void setNumberOfChunks(const size_t numberofchunks);
protected:
void closeEvent (QCloseEvent * event);
virtual void showEvent(QShowEvent * event);
private slots:
void on_ok_dButton_clicked();
void on_cancel_dButton_clicked();

View File

@ -74,6 +74,8 @@
Q_DECLARE_METATYPE(FileProgressInfo)
DetailsDialog *TransfersDialog::detailsdlg = NULL;
/** Constructor */
TransfersDialog::TransfersDialog(QWidget *parent)
: RsAutoUpdatePage(1000,parent)
@ -185,7 +187,7 @@ TransfersDialog::TransfersDialog(QWidget *parent)
ui.fileTransferInfoWidget->setFrameStyle(QFrame::NoFrame);
ui.fileTransferInfoWidget->setFocusPolicy(Qt::NoFocus);
QObject::connect(ui.downloadList,SIGNAL(clicked(const QModelIndex&)),this,SLOT(showFileDetails())) ;
QObject::connect(ui.downloadList->selectionModel(),SIGNAL(selectionChanged (const QItemSelection&, const QItemSelection&)),this,SLOT(showFileDetails())) ;
TurtleRouterDialog *trdl = new TurtleRouterDialog();
ui.tunnelInfoWidget->setWidget(trdl);
@ -622,7 +624,14 @@ void TransfersDialog::delUploadItem(int row)
void TransfersDialog::updateDisplay()
{
insertTransfers();
updateDetailsDialog ();
}
static void QListDelete (const QList <QStandardItem*> &List)
{
qDeleteAll (List.begin (), List.end ());
}
void TransfersDialog::insertTransfers()
{
/* get the download lists */
@ -746,7 +755,7 @@ void TransfersDialog::insertTransfers()
//
for(int r=dlItem->rowCount()-1;r>=0;--r)
if(used_rows.find(r) == used_rows.end())
dlItem->takeRow(r) ;
QListDelete (dlItem->takeRow(r)) ;
}
// remove hashes that where not shown
//first clean the model in case some files are not download anymore
@ -757,7 +766,7 @@ void TransfersDialog::insertTransfers()
std::string hash = DLListModel->item(removeIndex, ID)->data(Qt::EditRole).toString().toStdString();
if(used_hashes.find(hash) == used_hashes.end())
DLListModel->takeRow(removeIndex);
QListDelete (DLListModel->takeRow(removeIndex));
else
removeIndex++;
}
@ -845,7 +854,7 @@ void TransfersDialog::insertTransfers()
std::string hash = ULListModel->item(removeIndex, UHASH)->data(Qt::EditRole).toString().toStdString();
if(used_hashes.find(hash) == used_hashes.end())
ULListModel->takeRow(removeIndex);
QListDelete (ULListModel->takeRow(removeIndex));
else
removeIndex++;
}
@ -927,70 +936,121 @@ void TransfersDialog::copyLink ()
void TransfersDialog::showDetailsDialog()
{
static DetailsDialog *detailsdlg = new DetailsDialog();
if (detailsdlg == NULL) {
// create window
detailsdlg = new DetailsDialog ();
}
updateDetailsDialog ();
detailsdlg->show();
}
void TransfersDialog::updateDetailsDialog()
{
if (detailsdlg == NULL) {
return;
}
QModelIndexList lst = ui.downloadList->selectionModel ()->selectedIndexes ();
std::string file_hash ;
QString fhash;
QString fsize;
QString fname;
QString fstatus;
QString fpriority;
QString fsources;
qulonglong filesize = 0;
double fdatarate = 0;
qulonglong fcompleted = 0;
qulonglong fremaining = 0;
qulonglong fdownloadtime = 0;
for (int i = 0; i < lst.count (); i++)
{
if (lst[i].column () == 0)
{
QModelIndex& ind = lst[i];
QString fhash = ind.model ()->data (ind.model ()->index (ind.row (), ID )).toString() ;
QString fsize = ind.model ()->data (ind.model ()->index (ind.row (), SIZE)).toString() ;
QString fname = ind.model ()->data (ind.model ()->index (ind.row (), NAME)).toString() ;
QString fstatus = ind.model ()->data (ind.model ()->index (ind.row (), STATUS)).toString() ;
QString fpriority = ind.model ()->data (ind.model ()->index (ind.row (), PRIORITY)).toString() ;
QString fsources= ind.model ()->data (ind.model ()->index (ind.row (), SOURCES)).toString() ;
qulonglong filesize = ind.model ()->data (ind.model ()->index (ind.row (), SIZE)).toULongLong() ;
double fdatarate = ind.model ()->data (ind.model ()->index (ind.row (), DLSPEED)).toDouble() ;
qulonglong fcompleted = ind.model ()->data (ind.model ()->index (ind.row (), COMPLETED)).toULongLong() ;
qulonglong fremaining = ind.model ()->data (ind.model ()->index (ind.row (), REMAINING)).toULongLong() ;
qulonglong fdownloadtime = ind.model ()->data (ind.model ()->index (ind.row (), DOWNLOADTIME)).toULongLong() ;
int nb_select = 0 ;
for(int i = 0; i <= DLListModel->rowCount(); i++)
if(selection->isRowSelected(i, QModelIndex()))
{
file_hash = getID(i, DLListModel).toStdString();
++nb_select ;
}
detailsdlg->setFileHash(file_hash);
// Set Details.. Window Title
detailsdlg->setWindowTitle(tr("Details:") + fname);
fhash = ind.model ()->data (ind.model ()->index (ind.row (), ID )).toString() ;
fsize = ind.model ()->data (ind.model ()->index (ind.row (), SIZE)).toString() ;
fname = ind.model ()->data (ind.model ()->index (ind.row (), NAME)).toString() ;
fstatus = ind.model ()->data (ind.model ()->index (ind.row (), STATUS)).toString() ;
fpriority = ind.model ()->data (ind.model ()->index (ind.row (), PRIORITY)).toString() ;
fsources= ind.model ()->data (ind.model ()->index (ind.row (), SOURCES)).toString() ;
filesize = ind.model ()->data (ind.model ()->index (ind.row (), SIZE)).toULongLong() ;
fdatarate = ind.model ()->data (ind.model ()->index (ind.row (), DLSPEED)).toDouble() ;
fcompleted = ind.model ()->data (ind.model ()->index (ind.row (), COMPLETED)).toULongLong() ;
fremaining = ind.model ()->data (ind.model ()->index (ind.row (), REMAINING)).toULongLong() ;
fdownloadtime = ind.model ()->data (ind.model ()->index (ind.row (), DOWNLOADTIME)).toULongLong() ;
// maybe show all links in retroshare link(s) Tab
// int nb_select = 0 ;
//
// for(int i = 0; i <= DLListModel->rowCount(); i++)
// if(selection->isRowSelected(i, QModelIndex()))
// {
// file_hash = getID(i, DLListModel).toStdString();
// ++nb_select ;
// }
file_hash = getID(ind.row(), DLListModel).toStdString();
// General GroupBox
detailsdlg->setHash(fhash);
detailsdlg->setFileName(fname);
detailsdlg->setSize(filesize);
detailsdlg->setStatus(fstatus);
detailsdlg->setPriority(fpriority);
detailsdlg->setType(QFileInfo(fname).suffix());
// Transfer GroupBox
detailsdlg->setSources(fsources);
detailsdlg->setDatarate(fdatarate);
detailsdlg->setCompleted(fcompleted);
detailsdlg->setRemaining(fremaining);
//Date GroupBox
detailsdlg->setDownloadtime(fdownloadtime);
// retroshare link(s) Tab
RetroShareLink link(fname, filesize, fhash);
detailsdlg->setLink(link.toString());
detailsdlg->show();
break;
}
}
detailsdlg->setFileHash(file_hash);
// Set Details.. Window Title
detailsdlg->setWindowTitle(tr("Details:") + fname);
// General GroupBox
detailsdlg->setHash(fhash);
detailsdlg->setFileName(fname);
detailsdlg->setSize(filesize);
detailsdlg->setStatus(fstatus);
detailsdlg->setPriority(fpriority);
detailsdlg->setType(QFileInfo(fname).suffix());
// Transfer GroupBox
detailsdlg->setSources(fsources);
detailsdlg->setDatarate(fdatarate);
if (fname.isEmpty()) {
detailsdlg->setCompleted(misc::friendlyUnit(-1));
detailsdlg->setRemaining(misc::friendlyUnit(-1));
} else {
detailsdlg->setCompleted(misc::friendlyUnit(fcompleted));
detailsdlg->setRemaining(misc::friendlyUnit(fremaining));
}
//Date GroupBox
if (fname.isEmpty()) {
detailsdlg->setDownloadtime(misc::userFriendlyDuration(-1));
} else {
detailsdlg->setDownloadtime(misc::userFriendlyDuration(fdownloadtime));
}
// retroshare link(s) Tab
if (fname.isEmpty()) {
detailsdlg->setLink("");
} else {
RetroShareLink link(fname, filesize, fhash);
detailsdlg->setLink(link.toString());
}
FileChunksInfo info ;
if (fhash.isEmpty() == false && rsFiles->FileDownloadChunksDetails(fhash.toStdString(), info)) {
detailsdlg->setChunkSize(info.chunk_size);
detailsdlg->setNumberOfChunks(info.chunks.size());
} else {
detailsdlg->setChunkSize(0);
detailsdlg->setNumberOfChunks(0);
}
}
void TransfersDialog::pasteLink()
@ -1312,6 +1372,8 @@ void TransfersDialog::showFileDetails()
std::cout << "calling update " << std::endl ;
dynamic_cast<FileTransferInfoWidget*>(ui.fileTransferInfoWidget->widget())->updateDisplay() ;
std::cout << "done" << std::endl ;
updateDetailsDialog ();
}
double TransfersDialog::getProgress(int , QStandardItemModel *)

View File

@ -43,6 +43,7 @@
class DLListDelegate;
class ULListDelegate;
class QStandardItemModel;
class DetailsDialog;
class TransfersDialog : public RsAutoUpdatePage
{
@ -57,7 +58,9 @@ public:
virtual void keyPressEvent(QKeyEvent *) ;
virtual void updateDisplay() ; // derived from RsAutoUpdateWidget
public slots:
static DetailsDialog *detailsdlg;
public slots:
void insertTransfers();
// void handleDownloadRequest(const QString& url);
@ -107,6 +110,7 @@ private slots:
// void saveSortIndicatorUpl(int logicalIndex, Qt::SortOrder order);
void showDetailsDialog();
void updateDetailsDialog();
signals:
void playFiles(QStringList files);