2008-06-20 08:43:23 -04:00
|
|
|
/****************************************************************
|
|
|
|
* RetroShare is distributed under the following license:
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 Robert Fernie
|
|
|
|
*
|
|
|
|
* 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., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
****************************************************************/
|
|
|
|
#include <QtGui>
|
|
|
|
|
|
|
|
#include "SubFileItem.h"
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#define DEBUG_ITEM 1
|
|
|
|
|
|
|
|
/** Constructor */
|
2008-06-24 00:36:45 -04:00
|
|
|
SubFileItem::SubFileItem(std::string hash, std::string name, uint64_t size)
|
|
|
|
:QWidget(NULL), mFileHash(hash), mFileName(name), mFileSize(size)
|
2008-06-20 08:43:23 -04:00
|
|
|
{
|
|
|
|
/* Invoke the Qt Designer generated object setup routine */
|
|
|
|
setupUi(this);
|
|
|
|
|
|
|
|
connect( expandButton, SIGNAL( clicked( void ) ), this, SLOT( toggle ( void ) ) );
|
|
|
|
connect( cancelButton, SIGNAL( clicked( void ) ), this, SLOT( cancel ( void ) ) );
|
|
|
|
connect( playButton, SIGNAL( clicked( void ) ), this, SLOT( play ( void ) ) );
|
|
|
|
|
2008-06-24 00:36:45 -04:00
|
|
|
amountDone = 1000;
|
2008-06-20 08:43:23 -04:00
|
|
|
|
|
|
|
small();
|
|
|
|
updateItemStatic();
|
|
|
|
updateItem();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SubFileItem::updateItemStatic()
|
|
|
|
{
|
|
|
|
/* fill in */
|
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "SubFileItem::updateItemStatic()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QString filename = "Biggest_File.txt";
|
|
|
|
fileLabel->setText(filename);
|
|
|
|
fileLabel->setToolTip(filename);
|
|
|
|
|
|
|
|
playButton->setEnabled(false);
|
2008-06-24 00:36:45 -04:00
|
|
|
|
|
|
|
if (mFileSize > 10000000) /* 10 Mb */
|
|
|
|
{
|
|
|
|
progressBar->setRange(0, mFileSize / 1000000);
|
|
|
|
progressBar->setFormat("%v MB");
|
|
|
|
}
|
|
|
|
else if (mFileSize > 10000) /* 10 Kb */
|
|
|
|
{
|
|
|
|
progressBar->setRange(0, mFileSize / 1000);
|
|
|
|
progressBar->setFormat("%v kB");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
progressBar->setRange(0, mFileSize);
|
|
|
|
progressBar->setFormat("%v B");
|
|
|
|
}
|
2008-06-20 08:43:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SubFileItem::done()
|
|
|
|
{
|
2008-06-24 00:36:45 -04:00
|
|
|
return (amountDone >= mFileSize);
|
2008-06-20 08:43:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SubFileItem::updateItem()
|
|
|
|
{
|
|
|
|
/* fill in */
|
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "SubFileItem::updateItem()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
int msec_rate = 1000;
|
|
|
|
|
2008-06-24 00:36:45 -04:00
|
|
|
uint64_t divisor = 1;
|
|
|
|
if (mFileSize > 10000000) /* 10 Mb */
|
|
|
|
{
|
|
|
|
divisor = 1000000;
|
|
|
|
}
|
|
|
|
else if (mFileSize > 10000) /* 10 Kb */
|
|
|
|
{
|
|
|
|
divisor = 1000;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (amountDone < mFileSize)
|
2008-06-20 08:43:23 -04:00
|
|
|
{
|
|
|
|
amountDone *= 1.1;
|
|
|
|
|
2008-06-24 00:36:45 -04:00
|
|
|
progressBar->setValue(amountDone / divisor);
|
2008-06-20 08:43:23 -04:00
|
|
|
QTimer::singleShot( msec_rate, this, SLOT(updateItem( void ) ));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* complete! */
|
2008-06-24 00:36:45 -04:00
|
|
|
amountDone = mFileSize + 1;
|
|
|
|
progressBar->setValue(mFileSize / divisor);
|
2008-06-20 08:43:23 -04:00
|
|
|
playButton->setEnabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SubFileItem::small()
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "SubFileItem::cancel()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
expandFrame->hide();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void SubFileItem::toggle()
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
if (expandFrame->isHidden())
|
|
|
|
{
|
|
|
|
expandFrame->show();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
expandFrame->hide();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void SubFileItem::cancel()
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "SubFileItem::cancel()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SubFileItem::play()
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "SubFileItem::play()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|