- Some modifications to DownloadView formatting. Progress updated only if progressed 1%.
- Tried to correct build problem.
git-svn-id: file:///svnroot/qtrapids/trunk@19
42ac0dd5-4c8c-4c71-bb3e-
ecdfe252ffda
12 files changed:
--- /dev/null
+CONFIG -= debug
+
+debug {
+ DEFINES += QTRAPIDS_DEBUG
+} else {
+}
INCLUDEPATH = /usr/local/include/libtorrent \
/usr/local/include/boost-1_38
INCLUDEPATH = /usr/local/include/libtorrent \
/usr/local/include/boost-1_38
CONFIG += warn_on \
qt \
thread
CONFIG += warn_on \
qt \
thread
+CONFIG -= debug
+CONFIG += release
+
Alert const *alertTemp = NULL;
while (true)
{
Alert const *alertTemp = NULL;
while (true)
{
qDebug() << "AlertWaiter running";
qDebug() << "AlertWaiter running";
// wait_for_alert() call blocks. Returns libtorrent alert.
// Returns NULL, if no alerts in timeout period.
alertTemp = btSession_->wait_for_alert(ALERT_WAIT_TIMEOUT);
// wait_for_alert() call blocks. Returns libtorrent alert.
// Returns NULL, if no alerts in timeout period.
alertTemp = btSession_->wait_for_alert(ALERT_WAIT_TIMEOUT);
virtual void run(); // Overridden from QThread
signals:
virtual void run(); // Overridden from QThread
signals:
+ /// @TODO alert() uses direct connection, so th connected slot is executed by AlertWaiterThread
+ /// Hence, QMutex is needed in receiver slot/thread for thread-safety.
+ /// @NOTE Alternatively, we could use an event loop in the thread and use queued signal (is it heavier?)
void alert(Alert const *alert);
private:
void alert(Alert const *alert);
private:
QBittorrentSession::addTorrent(AddTorrentParams const& params)
{
// Delegate to Libtorrent and return QTorrentHandle.
QBittorrentSession::addTorrent(AddTorrentParams const& params)
{
// Delegate to Libtorrent and return QTorrentHandle.
// ========================== SLOTS ==============================
// ========================== SLOTS ==============================
+/// @TODO This function is called when AlertWaiterThread emits alert()
+/// If connection is direct, as it is now, we need to use QMutex here (if necessary?)
void QBittorrentSession::on_alert(Alert const *al)
//NOTE: al parameter not necessarily needed here, as we pop_alert() now!
{
void QBittorrentSession::on_alert(Alert const *al)
//NOTE: al parameter not necessarily needed here, as we pop_alert() now!
{
- //qDebug() << "QBittorrentSession:on_alert(" << al << ")";
-// if (al)
-// qDebug() << "on_alert():" << QString::fromStdString(al->message());
-
+#ifdef QTRAPIDS_DEBUG
+ if (al)
+ qDebug() << "on_alert():" << QString::fromStdString(al->message());
+#endif
+
std::auto_ptr<Alert> alertPtr = btSession_.pop_alert();
emit alert(alertPtr);
}
std::auto_ptr<Alert> alertPtr = btSession_.pop_alert();
emit alert(alertPtr);
}
include (../../includes.pri)
include (../../includes.pri)
+include (../../buildconf.pri)
TARGET = qtbittorrent
DESTDIR = ../../bin
TARGET = qtbittorrent
DESTDIR = ../../bin
-lboost_date_time-mt \
-lboost_thread-mt
-lboost_date_time-mt \
-lboost_thread-mt
+# Check build mode and print result in console
+debug {
+ message( "DEBUG" )
+} else {
+ message( "RELEASE" )
+}
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <QDebug>
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <QDebug>
#include <QVariant>
#include <QColor>
#include "DownloadView.h"
DownloadView::DownloadView(QWidget* parent) :
#include <QVariant>
#include <QColor>
#include "DownloadView.h"
DownloadView::DownloadView(QWidget* parent) :
- QTreeWidget(parent),
- items_()
+ QTreeWidget(parent),
+ items_(),
+ timer_(NULL)
- setRootIsDecorated(false); // Hide branch lines, making one-level treeview (similar to list)
- setHeaderItem(DownloadViewItem::getHeaderItem());
+ setRootIsDecorated(false); // Hide branch lines, making one-level treeview (similar to list)
+ setHeaderItem(DownloadViewItem::getHeaderItem());
- connect(this, SIGNAL(itemPressed(QTreeWidgetItem*, int)),
- this, SLOT(on_itemClicked(QTreeWidgetItem*, int)));
+ connect(this, SIGNAL(itemPressed(QTreeWidgetItem*, int)),
+ this, SLOT(on_itemClicked(QTreeWidgetItem*, int)));
+
+ timer_ = new QTimer(this);
+ connect(timer_, SIGNAL(timeout()), this, SLOT(on_timeout()));
+ timer_->start(5000);
void DownloadView::newItem(QTorrentHandle handle)
{
void DownloadView::newItem(QTorrentHandle handle)
{
qDebug() << "DownloadView::newItem() " << items_.count(handle);
qDebug() << "DownloadView::newItem() " << items_.count(handle);
DownloadViewItem *item = new DownloadViewItem(QStringList()
<< handle.name()
<< QString::number(handle.getTotalSize())
<< GetStatusString(handle.state())
DownloadViewItem *item = new DownloadViewItem(QStringList()
<< handle.name()
<< QString::number(handle.getTotalSize())
<< GetStatusString(handle.state())
- << QString::number(handle.progress())
- << QString::number(handle.downloadRate())
- << QString::number(handle.uploadRate())
+ << QString::number(100*handle.progress() + '%')
+ << QString::number(handle.downloadRate(), 'f', 2)
+ << QString::number(handle.uploadRate(), 'f', 2)
<< QString::number(handle.numSeeds()) + "/"
+ QString::number(handle.numLeeches())
<< QString::number(handle.ratio())
<< "ETA" );
<< QString::number(handle.numSeeds()) + "/"
+ QString::number(handle.numLeeches())
<< QString::number(handle.ratio())
<< "ETA" );
+ // Set text color for status:
QBrush brushTmp(GetStatusColor(handle.state()));
item->setForeground(2, brushTmp);
QBrush brushTmp(GetStatusColor(handle.state()));
item->setForeground(2, brushTmp);
void DownloadView::updateItem(QTorrentHandle handle)
{
void DownloadView::updateItem(QTorrentHandle handle)
{
- qDebug() << "DownloadView::updateItem() " << items_.count(handle);
+ //qDebug() << "DownloadView::updateItem() " << items_.count(handle);
+
+ static float lastProg = 0;
+ // If there are items currently downloading, update:
if (items_.count(handle) > 0) {
if (items_.count(handle) > 0) {
DownloadViewItem *item = items_[handle];
DownloadViewItem *item = items_[handle];
+
+ // Only the changing fields are being updated:
item->setData(2, Qt::DisplayRole,
QVariant(GetStatusString(handle.state())));
item->setData(2, Qt::DisplayRole,
QVariant(GetStatusString(handle.state())));
- item->setData(3, Qt::DisplayRole,
- QVariant(QString::number(handle.progress())));
item->setData(4, Qt::DisplayRole,
item->setData(4, Qt::DisplayRole,
- QVariant(QString::number(handle.downloadRate())));
+ QVariant(QString::number(handle.downloadRate(), 'f', 2)));
item->setData(5, Qt::DisplayRole,
item->setData(5, Qt::DisplayRole,
- QVariant(QString::number(handle.uploadRate())));
+ QVariant(QString::number(handle.uploadRate(), 'f', 2)));
item->setData(6, Qt::DisplayRole,
QString::number(handle.numSeeds()) + "/"
+ QString::number(handle.numLeeches()));
item->setData(6, Qt::DisplayRole,
QString::number(handle.numSeeds()) + "/"
+ QString::number(handle.numLeeches()));
+ // Set progress if increment is 1 percent.
+ float prog = handle.progress();
+ if ((prog-lastProg) >= 0.01 || prog >= 1.0) {
+ item->setData(3, Qt::DisplayRole,
+ QVariant(QString::number(100*prog) + '%'));
+ lastProg = prog;
+ }
+
+ /// @TODO: ETA-counter adjusting,if ETA is to be implemented
+
+ // Adjust color
QBrush brushTmp(GetStatusColor(handle.state()));
item->setForeground(2, brushTmp);
}
QBrush brushTmp(GetStatusColor(handle.state()));
item->setForeground(2, brushTmp);
}
QTorrentHandle DownloadView::removeSelected()
{
QTorrentHandle DownloadView::removeSelected()
{
qDebug() << "DownloadView::removeSelected() " << topLevelItemCount() ;
qDebug() << "DownloadView::removeSelected() " << topLevelItemCount() ;
DownloadViewItem *item = dynamic_cast<DownloadViewItem*> (currentItem());
DownloadViewItem *item = dynamic_cast<DownloadViewItem*> (currentItem());
if (index >= 0) {
takeTopLevelItem(index);
}
if (index >= 0) {
takeTopLevelItem(index);
}
qDebug() << "DownloadView::removeSelected() " << topLevelItemCount() ;
qDebug() << "DownloadView::removeSelected() " << topLevelItemCount() ;
+void DownloadView::setRefreshInterval(int msec)
+{
+ timer_->setInterval(msec);
+}
+
+
void DownloadView::on_itemClicked(QTreeWidgetItem * item, int column)
{
/*
void DownloadView::on_itemClicked(QTreeWidgetItem * item, int column)
{
/*
+void DownloadView::on_timeout() {
+#ifdef QTRAPIDS_DEBUG
+ qDebug() << "DownloadView::on_timeout()";
+#endif
+ UpdateView();
+}
+
+
QString DownloadView::GetStatusString(QTorrentHandle::State const& status) const
{
QString DownloadView::GetStatusString(QTorrentHandle::State const& status) const
{
default:
return QColor();
}
default:
return QColor();
}
-}
\ No newline at end of file
+}
+
+void DownloadView::UpdateView()
+{
+ DownloadViewItem *item = dynamic_cast<DownloadViewItem*> (currentItem());
+
+ std::map<QTorrentHandle, DownloadViewItem*>::iterator listIter
+ = items_.begin();
+ std::map<QTorrentHandle, DownloadViewItem*>::iterator listEnd
+ = items_.end();
+
+ while (listIter != listEnd) {
+ updateItem(listIter->first);
+ ++listIter;
+ }
+}
#include "QBittorrentSession.h"
class DownloadViewItem;
#include "QBittorrentSession.h"
class DownloadViewItem;
void updateItem(QTorrentHandle handle);
QTorrentHandle removeSelected();
void removeItem(QTorrentHandle handle);
void updateItem(QTorrentHandle handle);
QTorrentHandle removeSelected();
void removeItem(QTorrentHandle handle);
+ void setRefreshInterval(int msec);
private slots:
void on_itemClicked(QTreeWidgetItem * item, int column);
private slots:
void on_itemClicked(QTreeWidgetItem * item, int column);
private:
// Maps torrent to downloadview item.
// Key: SHA1 info hash of torrent. Data: View item corresponding to torrent.
std::map<QTorrentHandle, DownloadViewItem*> items_;
private:
// Maps torrent to downloadview item.
// Key: SHA1 info hash of torrent. Data: View item corresponding to torrent.
std::map<QTorrentHandle, DownloadViewItem*> items_;
// Private functions.
QString GetStatusString(QTorrentHandle::State const& status) const;
QColor GetStatusColor(QTorrentHandle::State const& status) const;
// Private functions.
QString GetStatusString(QTorrentHandle::State const& status) const;
QColor GetStatusColor(QTorrentHandle::State const& status) const;
- @class DownloadViewItem
+ @class DownloadViewItem
@brief Represents one item row of DownloadView
*/
class DownloadViewItem : public QTreeWidgetItem {
@brief Represents one item row of DownloadView
*/
class DownloadViewItem : public QTreeWidgetItem {
= QString(QObject::trUtf8("QtRapids, a simple BitTorrent client based on"
"\nQt and Libtorrent."
"\n\nURL: http://qtrapids.garage.maemo.org/"
= QString(QObject::trUtf8("QtRapids, a simple BitTorrent client based on"
"\nQt and Libtorrent."
"\n\nURL: http://qtrapids.garage.maemo.org/"
- "\n\nAuthor(s):\nLassi Väätämöinen, lassi.vaatamoinen@ixonos.com"
+ "\n\nAuthors:\nLassi Väätämöinen, lassi.vaatamoinen@ixonos.com"
+ "\nDenis Zalievsky, denis.zalewsky@ixonos.com"
"\n\nIxonos Plc, Finland\n"));
"\n\nIxonos Plc, Finland\n"));
void MainWindow::on_downloadItemSelectionChanged()
{
void MainWindow::on_downloadItemSelectionChanged()
{
qDebug() << "MainWindow::on_seedItemSelectionChanged():" << dlView_->currentItem();
qDebug() << "MainWindow::on_seedItemSelectionChanged():" << dlView_->currentItem();
if (dlView_->currentItem() != NULL) {
emit(itemSelected(true));
} else {
if (dlView_->currentItem() != NULL) {
emit(itemSelected(true));
} else {
void MainWindow::on_seedItemSelectionChanged()
{
void MainWindow::on_seedItemSelectionChanged()
{
qDebug() << "MainWindow::on_seedItemSelectionChanged():" << seedView_->currentItem();
qDebug() << "MainWindow::on_seedItemSelectionChanged():" << seedView_->currentItem();
if (seedView_->currentItem() != NULL) {
emit(itemSelected(true));
} else {
if (seedView_->currentItem() != NULL) {
emit(itemSelected(true));
} else {
void MainWindow::on_torrentFileSelected(const QString& file)
{
void MainWindow::on_torrentFileSelected(const QString& file)
{
qDebug() << " MainWindow::on_torrentFileSelected(): " << file;
qDebug() << " MainWindow::on_torrentFileSelected(): " << file;
// Torrent filename empty, do nothing.
if (file == "") {
return;
// Torrent filename empty, do nothing.
if (file == "") {
return;
QTorrentHandle handle = btSession_.addTorrent(addParams);
dlView_->newItem(handle);
// torrentHandles_.push_back(handlePtr);
QTorrentHandle handle = btSession_.addTorrent(addParams);
dlView_->newItem(handle);
// torrentHandles_.push_back(handlePtr);
qDebug() << "Is valid: " << handle.isValid();
qDebug() << "Is valid: " << handle.isValid();
}
void MainWindow::on_alert(std::auto_ptr<Alert> al)
{
}
void MainWindow::on_alert(std::auto_ptr<Alert> al)
{
- qDebug()
- << "MainWindow::on_torrentAlert(): "
- << QString::fromStdString(al->message());
-
+// qDebug()
+// << "MainWindow::on_torrentAlert(): "
+// << QString::fromStdString(al->message());
+
TorrentAlert *torrentAlert
= dynamic_cast<TorrentAlert*> (al.get());
TorrentAlert *torrentAlert
= dynamic_cast<TorrentAlert*> (al.get());
+ QTorrentHandle torrentHandle = QTorrentHandle(torrentAlert->handle);
dlView_->updateItem(QTorrentHandle(torrentAlert->handle));
}
dlView_->updateItem(QTorrentHandle(torrentAlert->handle));
}
include (../../includes.pri)
include (../../includes.pri)
+include (../../buildconf.pri)
SOURCES += DownloadView.cpp \
MainWindow.cpp \
SOURCES += DownloadView.cpp \
MainWindow.cpp \
-CONFIG -= release
-
-CONFIG += debug \
- qtestlib
-
-
QMAKE_LFLAGS_DEBUG += -L.
TARGETDEPS += ../../bin/libqtbittorrent.so
QMAKE_LFLAGS_DEBUG += -L.
TARGETDEPS += ../../bin/libqtbittorrent.so
+# Check build mode and print to console
+debug {
+ message( "DEBUG" )
+} else {
+ message( "RELEASE" )
+}
+
-SUBDIRS += gui \
- engine
+SUBDIRS += engine \
+ gui
-CONFIG += warn_on \
- thread \
- qt
+
+CONFIG += ordered \
+ warn_on \
+ thread \
+ qt
+CONFIG -= debug
TARGET = qtrapids
DESTDIR = ../bin
TARGET = qtrapids
DESTDIR = ../bin