From: lvaatamoinen Date: Fri, 6 Nov 2009 11:28:04 +0000 (+0000) Subject: - Added buildconf.pri to hold the master-level build options. X-Git-Url: https://vcs.maemo.org/git/?p=qtrapids;a=commitdiff_plain;h=f576091800144d69317250a69d40c711505a4f34 - Added buildconf.pri to hold the master-level build options. - 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 --- diff --git a/buildconf.pri b/buildconf.pri new file mode 100644 index 0000000..bd07767 --- /dev/null +++ b/buildconf.pri @@ -0,0 +1,6 @@ +CONFIG -= debug + +debug { + DEFINES += QTRAPIDS_DEBUG +} else { +} diff --git a/includes.pri b/includes.pri index ef725fa..108a4fb 100644 --- a/includes.pri +++ b/includes.pri @@ -1,2 +1,4 @@ INCLUDEPATH = /usr/local/include/libtorrent \ /usr/local/include/boost-1_38 + +CONFIG -= debug diff --git a/qtrapids.pro b/qtrapids.pro index 3f6c313..9235b82 100644 --- a/qtrapids.pro +++ b/qtrapids.pro @@ -3,3 +3,6 @@ TEMPLATE = subdirs CONFIG += warn_on \ qt \ thread +CONFIG -= debug +CONFIG += release + diff --git a/src/engine/AlertWaiterThread.cpp b/src/engine/AlertWaiterThread.cpp index 971967c..4f18636 100644 --- a/src/engine/AlertWaiterThread.cpp +++ b/src/engine/AlertWaiterThread.cpp @@ -58,7 +58,9 @@ void AlertWaiterThread::run() Alert const *alertTemp = NULL; while (true) { +#ifdef QTRAPIDS_DEBUG qDebug() << "AlertWaiter running"; +#endif // wait_for_alert() call blocks. Returns libtorrent alert. // Returns NULL, if no alerts in timeout period. alertTemp = btSession_->wait_for_alert(ALERT_WAIT_TIMEOUT); diff --git a/src/engine/AlertWaiterThread.h b/src/engine/AlertWaiterThread.h index ec46d7f..7d14ef9 100644 --- a/src/engine/AlertWaiterThread.h +++ b/src/engine/AlertWaiterThread.h @@ -41,6 +41,9 @@ class AlertWaiterThread : public QThread 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: diff --git a/src/engine/QBittorrentSession.cpp b/src/engine/QBittorrentSession.cpp index 57054c3..7d88e26 100644 --- a/src/engine/QBittorrentSession.cpp +++ b/src/engine/QBittorrentSession.cpp @@ -41,7 +41,7 @@ QBittorrentSession::~QBittorrentSession() } -QTorrentHandle +QTorrentHandle QBittorrentSession::addTorrent(AddTorrentParams const& params) { // Delegate to Libtorrent and return QTorrentHandle. @@ -58,14 +58,17 @@ void QBittorrentSession::removeTorrent(QTorrentHandle const& handle) // ========================== 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! { - //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 alertPtr = btSession_.pop_alert(); emit alert(alertPtr); } diff --git a/src/engine/engine.pro b/src/engine/engine.pro index eae2f6c..0c1c471 100644 --- a/src/engine/engine.pro +++ b/src/engine/engine.pro @@ -1,9 +1,10 @@ include (../../includes.pri) +include (../../buildconf.pri) TEMPLATE = lib -CONFIG += dll \ - debug +CONFIG += dll + VERSION = 0.1 @@ -17,8 +18,6 @@ SOURCES += AlertWaiterThread.cpp \ QT -= gui -CONFIG -= release - TARGET = qtbittorrent DESTDIR = ../../bin @@ -28,3 +27,9 @@ LIBS += -ltorrent-rasterbar \ -lboost_date_time-mt \ -lboost_thread-mt +# Check build mode and print result in console +debug { + message( "DEBUG" ) +} else { + message( "RELEASE" ) +} diff --git a/src/gui/DownloadView.cpp b/src/gui/DownloadView.cpp index 5d616d8..ede3b66 100644 --- a/src/gui/DownloadView.cpp +++ b/src/gui/DownloadView.cpp @@ -18,20 +18,26 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include +#include #include #include #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); } @@ -43,20 +49,23 @@ DownloadView::~DownloadView() void DownloadView::newItem(QTorrentHandle handle) { +#ifdef QTRAPIDS_DEBUG qDebug() << "DownloadView::newItem() " << items_.count(handle); +#endif 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" ); + // Set text color for status: QBrush brushTmp(GetStatusColor(handle.state())); item->setForeground(2, brushTmp); @@ -67,22 +76,37 @@ void DownloadView::newItem(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) { + DownloadViewItem *item = items_[handle]; + + // Only the changing fields are being updated: item->setData(2, Qt::DisplayRole, QVariant(GetStatusString(handle.state()))); - item->setData(3, Qt::DisplayRole, - QVariant(QString::number(handle.progress()))); item->setData(4, Qt::DisplayRole, - QVariant(QString::number(handle.downloadRate()))); + QVariant(QString::number(handle.downloadRate(), 'f', 2))); 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())); + // 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); } @@ -92,7 +116,9 @@ void DownloadView::updateItem(QTorrentHandle handle) QTorrentHandle DownloadView::removeSelected() { +#ifdef QTRAPIDS_DEBUG qDebug() << "DownloadView::removeSelected() " << topLevelItemCount() ; +#endif DownloadViewItem *item = dynamic_cast (currentItem()); @@ -116,9 +142,11 @@ QTorrentHandle DownloadView::removeSelected() if (index >= 0) { takeTopLevelItem(index); } - + +#ifdef QTRAPIDS_DEBUG qDebug() << "DownloadView::removeSelected() " << topLevelItemCount() ; - +#endif + return handle; } @@ -128,6 +156,12 @@ void DownloadView::removeItem(QTorrentHandle handle) } +void DownloadView::setRefreshInterval(int msec) +{ + timer_->setInterval(msec); +} + + void DownloadView::on_itemClicked(QTreeWidgetItem * item, int column) { /* @@ -140,6 +174,14 @@ 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 { @@ -182,4 +224,19 @@ QColor DownloadView::GetStatusColor(QTorrentHandle::State const& status) const default: return QColor(); } -} \ No newline at end of file +} + +void DownloadView::UpdateView() +{ + DownloadViewItem *item = dynamic_cast (currentItem()); + + std::map::iterator listIter + = items_.begin(); + std::map::iterator listEnd + = items_.end(); + + while (listIter != listEnd) { + updateItem(listIter->first); + ++listIter; + } +} diff --git a/src/gui/DownloadView.h b/src/gui/DownloadView.h index 5ab1442..6fadb92 100644 --- a/src/gui/DownloadView.h +++ b/src/gui/DownloadView.h @@ -27,6 +27,7 @@ #include "QBittorrentSession.h" class DownloadViewItem; +class QTimer; /** @class DownloadView @@ -46,22 +47,29 @@ Q_OBJECT void updateItem(QTorrentHandle handle); QTorrentHandle removeSelected(); void removeItem(QTorrentHandle handle); + void setRefreshInterval(int msec); private slots: void on_itemClicked(QTreeWidgetItem * item, int column); + void on_timeout(); + private: // Maps torrent to downloadview item. // Key: SHA1 info hash of torrent. Data: View item corresponding to torrent. std::map items_; + QTimer *timer_; // Private functions. QString GetStatusString(QTorrentHandle::State const& status) const; QColor GetStatusColor(QTorrentHandle::State const& status) const; + void UpdateView(); + + }; /** - @class DownloadViewItem + @class DownloadViewItem @brief Represents one item row of DownloadView */ class DownloadViewItem : public QTreeWidgetItem { diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index d45cc96..a3262e1 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -37,7 +37,8 @@ const QString ABOUT_TEXT = 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")); @@ -161,7 +162,9 @@ void MainWindow::on_aboutQtAction_clicked() void MainWindow::on_downloadItemSelectionChanged() { +#ifdef QTRAPIDS_DEBUG qDebug() << "MainWindow::on_seedItemSelectionChanged():" << dlView_->currentItem(); +#endif if (dlView_->currentItem() != NULL) { emit(itemSelected(true)); } else { @@ -171,7 +174,9 @@ void MainWindow::on_downloadItemSelectionChanged() void MainWindow::on_seedItemSelectionChanged() { +#ifdef QTRAPIDS_DEBUG qDebug() << "MainWindow::on_seedItemSelectionChanged():" << seedView_->currentItem(); +#endif if (seedView_->currentItem() != NULL) { emit(itemSelected(true)); } else { @@ -190,7 +195,9 @@ void MainWindow::handleToolBarAction(QAction* action) void MainWindow::on_torrentFileSelected(const QString& file) { +#ifdef QTRAPIDS_DEBUG qDebug() << " MainWindow::on_torrentFileSelected(): " << file; +#endif // Torrent filename empty, do nothing. if (file == "") { return; @@ -208,20 +215,26 @@ void MainWindow::on_torrentFileSelected(const QString& file) QTorrentHandle handle = btSession_.addTorrent(addParams); dlView_->newItem(handle); // torrentHandles_.push_back(handlePtr); +#ifdef QTRAPIDS_DEBUG qDebug() << "Is valid: " << handle.isValid(); +#endif } void MainWindow::on_alert(std::auto_ptr al) { + + if (al.get() != NULL) { - qDebug() - << "MainWindow::on_torrentAlert(): " - << QString::fromStdString(al->message()); - +// qDebug() +// << "MainWindow::on_torrentAlert(): " +// << QString::fromStdString(al->message()); + TorrentAlert *torrentAlert = dynamic_cast (al.get()); + if (torrentAlert) { + QTorrentHandle torrentHandle = QTorrentHandle(torrentAlert->handle); dlView_->updateItem(QTorrentHandle(torrentAlert->handle)); } diff --git a/src/gui/gui.pro b/src/gui/gui.pro index ca6a120..63dc4d2 100644 --- a/src/gui/gui.pro +++ b/src/gui/gui.pro @@ -1,4 +1,5 @@ include (../../includes.pri) +include (../../buildconf.pri) SOURCES += DownloadView.cpp \ MainWindow.cpp \ @@ -13,12 +14,7 @@ TEMPLATE = app TARGET = qtrapids -CONFIG -= release - -CONFIG += debug \ - qtestlib - - +CONFIG += qtestlib DESTDIR = ../../bin @@ -32,3 +28,10 @@ LIBS += -L../../bin \ QMAKE_LFLAGS_DEBUG += -L. TARGETDEPS += ../../bin/libqtbittorrent.so +# Check build mode and print to console +debug { + message( "DEBUG" ) +} else { + message( "RELEASE" ) +} + diff --git a/src/src.pro b/src/src.pro index 8923296..27453b1 100644 --- a/src/src.pro +++ b/src/src.pro @@ -1,9 +1,12 @@ -SUBDIRS += gui \ - engine +SUBDIRS += engine \ + gui -CONFIG += warn_on \ - thread \ - qt + +CONFIG += ordered \ + warn_on \ + thread \ + qt +CONFIG -= debug TARGET = qtrapids DESTDIR = ../bin