bool MainWindow::eventRequest(QVariant param, PluginRequest req)
{
if (req == qtrapids::PluginHostInterface::OPEN_FILE) {
- QString sourceFile = param.toString();
-
+ QString sourceFile = param.toString();
+
// Get the source files name from the full path:
QFileInfo fInfo(sourceFile);
QString targetFile = fInfo.fileName();
- targetFile = settings_.value("download/directory").toString() + targetFile;
+ targetFile = settings_.value("download/directory").toString() + "/" + targetFile;
// Copy temoporary file to Downloads directory...
if (!QFile::copy(sourceFile, targetFile)) {
// If copying was successful, remove the original temporary file.
QFile::remove(sourceFile);
}
-
+
+ /// @todo Torrent bencoding validity should be checked before starting(?)
// ...and start the torrent:
on_torrentFileSelected(targetFile);
+
+ } else if (req == qtrapids::PluginHostInterface::READ_BUFFER) {
+ // Create torrent information from char* buffer and start.
+ StartTorrentFromBufferData(param.toByteArray().constData(), param.toByteArray().size());
}
return true;
}
}
+
+
+// Opens torrent information from buffer data and adds torrent to session
+void MainWindow::StartTorrentFromBufferData(char const* data, int size)
+{
+ // For params, see: http://www.rasterbar.com/products/libtorrent/manual.html#add-torrent
+ /// @todo Should typedef libtorrent::torrent_info to something
+ AddTorrentParams addParams;
+ boost::intrusive_ptr<libtorrent::torrent_info> tiTmp =
+ new libtorrent::torrent_info(data, size);
+ addParams.ti = tiTmp;
+ // 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;
+ qtrapids::QTorrentHandle handle = btSession_.addTorrent(addParams);
+ dlView_->newItem(handle);
+// torrentHandles_.push_back(handlePtr);
+#ifdef QTRAPIDS_DEBUG
+ qDebug() << "Is valid: " << handle.isValid();
+#endif
+}
+
// =========================== SLOTS =================================
void MainWindow::on_openAction_clicked()
{
// Otherwise add torrent
// For params, see: http://www.rasterbar.com/products/libtorrent/manual.html#add-torrent
+ /// @todo Should typedef libtorrent::torrent_info to something
AddTorrentParams addParams;
boost::intrusive_ptr<libtorrent::torrent_info> tiTmp =
new libtorrent::torrent_info(boost::filesystem::path(file.toStdString()));
#endif
}
-
void MainWindow::on_alert(std::auto_ptr<Alert> al)
{
if (al.get() != NULL) {