<projectname>qtrapids</projectname>
<projectdirectory>.</projectdirectory>
<absoluteprojectpath>false</absoluteprojectpath>
- <description/>
- <defaultencoding/>
+ <description></description>
+ <defaultencoding></defaultencoding>
</general>
<kdevfileview>
<groups>
<includePaths>.;</includePaths>
</codecompletion>
<creategettersetter>
- <prefixGet/>
+ <prefixGet></prefixGet>
<prefixSet>set</prefixSet>
<prefixVariable>m_,_</prefixVariable>
<parameterName>theValue</parameterName>
</kdevdoctreeview>
<kdevdebugger>
<general>
- <dbgshell/>
+ <dbgshell></dbgshell>
<breakpoints/>
<programargs/>
<gdbpath>/usr/bin/gdb</gdbpath>
<breakonloadinglibs>true</breakonloadinglibs>
<separatetty>false</separatetty>
<floatingtoolbar>false</floatingtoolbar>
- <configGdbScript/>
- <runShellScript/>
- <runGdbScript/>
+ <configGdbScript></configGdbScript>
+ <runShellScript></runShellScript>
+ <runGdbScript></runGdbScript>
<raiseGDBOnStart>false</raiseGDBOnStart>
</general>
<display>
<kdevtrollproject>
<run>
<mainprogram>/home/vaatala/Projects/qtrapids/trunk/bin/qtrapids</mainprogram>
- <programargs/>
+ <programargs></programargs>
<directoryradio>executable</directoryradio>
- <globaldebugarguments/>
+ <globaldebugarguments></globaldebugarguments>
<globalcwd>/home/vaatala/Projects/qtrapids/trunk/bin</globalcwd>
<useglobalprogram>true</useglobalprogram>
<terminal>false</terminal>
<envvar value="." name="LD_LIBRARY_PATH" />
</envvars>
<runarguments>
- <qtrapids/>
+ <qtrapids></qtrapids>
</runarguments>
<cwd>
<qtrapids>/home/vaatala/Projects/qtrapids/trunk</qtrapids>
</cwd>
<debugarguments>
- <qtrapids/>
+ <qtrapids></qtrapids>
</debugarguments>
</run>
<general>
- <activedir>src</activedir>
+ <activedir>src/gui</activedir>
</general>
<make>
<abortonerror>true</abortonerror>
<runmultiplejobs>false</runmultiplejobs>
<numberofjobs>1</numberofjobs>
<dontact>false</dontact>
- <makebin/>
+ <makebin></makebin>
<prio>0</prio>
<envvars/>
</make>
}
-QTorrentHandle QBittorrentSession::addTorrent(AddTorrentParams const& params)
+std::auto_ptr<QTorrentHandle>
+QBittorrentSession::addTorrent(AddTorrentParams const& params)
{
// Delegate to Libtorrent and return QTorrentHandle.
- QTorrentHandle handle(btSession_.add_torrent(params));
- qDebug() << "Is valid: " << handle.isValid();
- return handle;
+ std::auto_ptr<QTorrentHandle> handlePtr(new QTorrentHandle(btSession_.add_torrent(params)));
+ return handlePtr;
}
//NOTE: al parameter not necessarily needed here, as we pop_alert() now!
{
- qDebug() << "QBittorrentSession:on_alert(" << al << ")";
+ //qDebug() << "QBittorrentSession:on_alert(" << al << ")";
// if (al)
// qDebug() << "on_alert():" << QString::fromStdString(al->message());
-
std::auto_ptr<TorrentAlert> alertPtr = btSession_.pop_alert();
emit alert(alertPtr);
}
typedef libtorrent::session TorrentSession;
typedef libtorrent::add_torrent_params AddTorrentParams;
typedef libtorrent::alert TorrentAlert;
+typedef libtorrent::sha1_hash Sha1Hash;
/**
~QBittorrentSession();
/// @brief Add torrent to session.
- QTorrentHandle addTorrent(AddTorrentParams const& params);
+ std::auto_ptr<QTorrentHandle> addTorrent(AddTorrentParams const& params);
signals:
void alert(std::auto_ptr<TorrentAlert> al);
{
}
+
+TorrentStatus QTorrentHandle::status() const
+{
+ return torrentHandle_.status();
+}
+
+
+TorrentInfo const& QTorrentHandle::getTorrentInfo() const
+{
+ return torrentHandle_.get_torrent_info();
+}
+
+
bool QTorrentHandle::isValid() const
{
return torrentHandle_.is_valid();
}
+QString QTorrentHandle::name() const
+{
+ return QString::fromStdString(torrentHandle_.name());
+}
+
+
+
+
+bool QTorrentHandle::operator==(QTorrentHandle const& h)
+{
+ return torrentHandle_ == h.torrentHandle_;
+}
+
+
+bool QTorrentHandle::operator<(QTorrentHandle const& h)
+{
+ return torrentHandle_ < h.torrentHandle_;
+}
+
+size_t QTorrentHandle::getTotalSize() const
+{
+ TorrentInfo info = getTorrentInfo();
+ return static_cast<size_t> (info.total_size());
+}
+
+QString QTorrentHandle::state() const
+{
+ return GetStatusString(status());
+}
+
+float QTorrentHandle::progress() const
+{
+ TorrentStatus statusTmp = status();
+ return statusTmp.progress;
+}
+
+float QTorrentHandle::uploadRate() const
+{
+ TorrentStatus statusTmp = status();
+ return statusTmp.upload_rate;
+}
+
+
+float QTorrentHandle::downloadRate() const
+{
+ TorrentStatus statusTmp = status();
+ return statusTmp.download_rate;
+}
+
+qint32 QTorrentHandle::numSeeds() const
+{
+ TorrentStatus statusTmp = status();
+ return statusTmp.list_seeds;
+}
+
+qint32 QTorrentHandle::numLeeches() const
+{
+ TorrentStatus statusTmp = status();
+ return (statusTmp.list_peers - statusTmp.list_seeds);
+}
+
+qint32 QTorrentHandle::ratio() const
+{
+ TorrentStatus statusTmp = status();
+ size_t ratio;
+ if (statusTmp.total_payload_download == 0) {
+ ratio = 0;
+ } else {
+ ratio = static_cast<size_t> (statusTmp.total_payload_upload / statusTmp.total_payload_download);
+ }
+
+ return ratio;
+}
+
+
+QString QTorrentHandle::GetStatusString(TorrentStatus const& status) const
+{
+ switch (status.state) {
+ case TorrentStatus::queued_for_checking :
+ return "Queued";
+ case TorrentStatus::checking_files :
+ return "Checking";
+ case TorrentStatus::downloading_metadata :
+ return "DL meta";
+ case TorrentStatus::downloading :
+ return "DL";
+ case TorrentStatus::finished :
+ return "Finished";
+ case TorrentStatus::seeding :
+ return "Seeding";
+ case TorrentStatus::allocating :
+ return "Allocating";
+ default:
+ return "N/A";
+ }
+}
+
+
\ No newline at end of file
#ifndef QTORRENTHANDLE_H
#define QTORRENTHANDLE_H
+#include <QtGlobal>
+
#include <libtorrent/torrent_handle.hpp>
+typedef libtorrent::torrent_status TorrentStatus;
+typedef libtorrent::torrent_info TorrentInfo;
/**
@author Lassi Väätämöinen <lassi.vaatamoinen@ixonos.com>
QTorrentHandle(libtorrent::torrent_handle handle);
~QTorrentHandle();
+
+ TorrentStatus status() const;
+
+ TorrentInfo const& getTorrentInfo() const;
+
bool isValid() const;
+
+ QString name() const;
+ size_t getTotalSize() const;
+ QString state() const;
+ float progress() const;
+ float uploadRate() const;
+ float downloadRate() const;
+ qint32 numSeeds() const;
+ qint32 numLeeches() const;
+ qint32 ratio() const;
+
+
+ bool operator==(QTorrentHandle const& h);
+ bool operator<(QTorrentHandle const& h);
private:
QTorrentHandle(); // Prevent default construct.
libtorrent::torrent_handle torrentHandle_;
+ // Private functions.
+ QString GetStatusString(TorrentStatus const& status) const;
};
#endif
***************************************************************************/
#include "DownloadView.h"
-DownloadView::DownloadView(QWidget* parent): QTreeWidget(parent)
+DownloadView::DownloadView(QWidget* parent) :
+ QTreeWidget(parent),
+ items_()
{
setRootIsDecorated(false); // Hide branch lines, making one-level treeview (similar to list)
setHeaderItem(DownloadViewItem::getHeaderItem());
{
}
+void DownloadView::newItem(QTorrentHandle const* handle)
+{
+
+ DownloadViewItem *item = new DownloadViewItem(QStringList()
+ << handle->name()
+ << QString::number(handle->getTotalSize())
+ << handle->state()
+ << QString::number(handle->progress())
+ << QString::number(handle->downloadRate())
+ << QString::number(handle->uploadRate())
+ << QString::number(handle->numSeeds()) + "/" + QString::number(handle->numLeeches())
+ << QString::number(handle->ratio())
+ << "ETA" );
+
+ addTopLevelItem(item);
+
+}
+
+void DownloadView::updateItem(QTorrentHandle const* handle)
+{
+}
+
#ifndef DOWNLOADVIEW_H
#define DOWNLOADVIEW_H
+#include <map>
+
#include <QTreeWidget>
+#include "QBittorrentSession.h"
+
+class DownloadViewItem;
+
/**
+ @class DownloadView
+ @brief A view showing all downloaded torrents
@author Lassi Väätämöinen <lassi.vaatamoinen@ixonos.com>
*/
class DownloadView : public QTreeWidget
~DownloadView();
+ void newItem(QTorrentHandle const* handle);
+ void updateItem(QTorrentHandle const* handle);
+
private:
-
+ // Maps torrent to downloadview item.
+ // Key: SHA1 info hash of torrent. Data: View item corresponding to torrent.
+ std::map<Sha1Hash, DownloadViewItem*> items_;
+
};
#include "MainWindow.h"
-
const QString ABOUT_TEXT
= QString(QObject::trUtf8("QtRapids, a simple BitTorrent client based on"
"\nQt and Libtorrent."
// Tab widget as central widget.
setCentralWidget(tabWidget_);
-
// TOOLBAR
QToolBar *toolBar = new QToolBar();
toolBar->addAction(tr("Open"));
addToolBar(Qt::TopToolBarArea, toolBar);
connect(toolBar, SIGNAL(actionTriggered(QAction*)), this, SLOT(handleToolBarAction(QAction*)));
+
+ connect(&btSession_, SIGNAL(alert(std::auto_ptr<TorrentAlert>)),
+ this, SLOT(on_torrentAlert(std::auto_ptr<TorrentAlert>)));
}
boost::intrusive_ptr<libtorrent::torrent_info> tiTmp =
new libtorrent::torrent_info(boost::filesystem::path(file.toStdString()));
addParams.ti = tiTmp;
- addParams.save_path = boost::filesystem::path(settings_.value("download/directory").toString().toStdString()); // The only mandatory parameter, rest are optional.
+ // save_path is the only mandatory parameter, rest are optional.
+ addParams.save_path = boost::filesystem::path(settings_.value("download/directory").toString().toStdString());
//addParams.storage_mode = libtorrent::storage_mode_allocate;
- btSession_.addTorrent(addParams);
+ std::auto_ptr<QTorrentHandle> handlePtr = btSession_.addTorrent(addParams);
+ dlView_->newItem(handlePtr.get());
+ qDebug() << "Is valid: " << handlePtr->isValid();
}
+
+void MainWindow::on_torrentAlert(std::auto_ptr<TorrentAlert> al)
+{
+ if (al.get() != NULL)
+ qDebug() << "MainWindow::on_torrentAlert(): " << QString::fromStdString(al->message());
+}
\ No newline at end of file
void on_aboutQtAction_clicked();
void handleToolBarAction(QAction* action);
void on_torrentFileSelected(const QString& file);
+ void on_torrentAlert(std::auto_ptr<TorrentAlert> al);
private:
QTabWidget *tabWidget_;
#include "SeedView.h"
SeedView::SeedView(QWidget* parent):
- QTreeWidget(parent)
+ QTreeWidget(parent),
+ items_()
{
setRootIsDecorated(false); // Hide branch lines, making one-level treeview (similar to list)
setHeaderItem(SeedViewItem::getHeaderItem());
#include <QTreeWidget>
+#include "QBittorrentSession.h"
+
+class SeedViewItem;
+
/**
@author Lassi Väätämöinen <lassi.vaatamoinen@ixonos.com>
*/
SeedView(QWidget* parent);
~SeedView();
+
+ void newItem(QTorrentHandle const* handle);
+ void updateItem(QTorrentHandle const* handle);
private:
+ // Maps torrent to SeedView item.
+ // Key: SHA1 info hash of torrent. Data: View item corresponding to torrent.
+ std::map<Sha1Hash, SeedViewItem*> items_;
+
// Name
// Size
// Status