From ff0dd88ee1adbc8f1b932b17820bdaf9b62b792d Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Wed, 4 Apr 2007 18:55:38 +0000 Subject: [PATCH] - Improved a lot the torrent creation module --- Changelog | 1 + TODO | 5 +- src/createtorrent.ui | 829 +++++++++++++++++++++++++++----------- src/createtorrent_imp.cpp | 131 ++++-- src/createtorrent_imp.h | 9 +- 5 files changed, 701 insertions(+), 274 deletions(-) diff --git a/Changelog b/Changelog index d6e9aaec4..e18b24211 100644 --- a/Changelog +++ b/Changelog @@ -6,6 +6,7 @@ - FEATURE: Allow user to change qBT's style (Plastique, Cleanlooks, Motif, CDE, MacOSX, WinXP) - FEATURE: Allow the user to disable system tray integration - FEATURE: Search engine is now using one thread per website for faster results + - FEATURE: Improved a lot the torrent creation module - FEATURE: Ask for exit confirmation only if download list is not empty - BUGFIX: Window can now stay maximized on exit - COSMETIC: Redesigned torrent properties a little diff --git a/TODO b/TODO index 583d5eb72..0e95a1fc3 100644 --- a/TODO +++ b/TODO @@ -32,10 +32,7 @@ // in v0.10 (partial) - WIP - Download from RSS feeds (WIP by gtsoul, clean & finish rss.h, add a tab in mainWindow, debug) - Move finished torrent to another tab and keep on seeding them even after restart (debug) -- Improve torrent creation dialog (look & features) : - - Add Private combobox (allow to share on DHT or not) - - Use a QListWidget to allow multiple input paths - - Possibility to add url seeds +- Check storage st creation + hasher in torrent creation - Add IPv6 support (at least start working on it, libtorrent seems to support it, we should limit our code to IPv4 anymore) - Display Url seeds in torrent properties and allow to edit them - Use tooltips to explain options? diff --git a/src/createtorrent.ui b/src/createtorrent.ui index 52c8e5a92..e571c3a36 100644 --- a/src/createtorrent.ui +++ b/src/createtorrent.ui @@ -1,258 +1,607 @@ - - - createTorrentDialog 0 0 - 560 - 307 + 605 + 588 Torrent Creation Tool - - - 9 + + + + 9 + 9 + 587 + 27 + - - 6 + + + 0 + 27 + - - - - - 0 - 27 - - - - - 16777215 - 27 - - - - - Sans Serif - 14 - 75 - false - true - false - false - - - - Create Torrent file - - - Qt::AlignCenter - - - - - - - 0 - - - 6 - - - - - 0 - - - 6 - - - - - - 16777215 - 26 - - - - <center>Destination torrent file:</center> - - - txt_destination - - - - - - - - 16777215 - 26 - - - - <center>Input file or directory:</center> - - - txt_input - - - - - - - - 16777215 - 70 - - - - <center>Announce url:<br>(One per line)</center> - - - - - - - - - - <center>Comment:</center> - - - txt_comment - - - - - - - - - 0 - - - 6 - - - - - 0 - - - 6 - - - - - - - - ... - - - - - - - - - 0 - - - 6 - - - - - - - - Directory - - - - - - - ... - - - - - - - - - - - - false - - - - - - - - - - - 0 - - - 6 - - - - - Qt::Horizontal - - - - 131 - 31 - - - - - - - - Create - - - - - - - Cancel - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - + + + 16777215 + 27 + + + + + Sans Serif + 14 + 75 + false + true + false + false + + + + Torrent file creation + + + Qt::AlignCenter + + + + + + 9 + 42 + 587 + 438 + + + + + 0 + + + 6 + + + + + 0 + + + 6 + + + + + + 0 + 101 + + + + + 16777215 + 26 + + + + Input files or directories: + + + + + + + + 0 + 102 + + + + + 16777215 + 70 + + + + Announce urls (trackers): + + + + + + + + + + + 0 + 101 + + + + URL seeds (optional): + + + + + + + + 0 + 102 + + + + + 16777215 + 102 + + + + Comment (optional): + + + txt_comment + + + + + + + + + 0 + + + 6 + + + + + 0 + + + 6 + + + + + QAbstractItemView::MultiSelection + + + + + + + 0 + + + 6 + + + + + Qt::Vertical + + + + 20 + 16 + + + + + + + + + 22 + 22 + + + + + 22 + 22 + + + + + + + + + + + + 22 + 22 + + + + + 22 + 22 + + + + + + + + + + + + 22 + 22 + + + + + 22 + 22 + + + + + + + + + + + Qt::Vertical + + + + 20 + 16 + + + + + + + + + + + + 0 + + + 6 + + + + + QAbstractItemView::MultiSelection + + + + + + + 0 + + + 6 + + + + + Qt::Vertical + + + + 20 + 16 + + + + + + + + + 22 + 22 + + + + + 22 + 22 + + + + + + + + + + + + 22 + 22 + + + + + 22 + 22 + + + + + + + + + + + Qt::Vertical + + + + 20 + 16 + + + + + + + + + + + + 0 + + + 6 + + + + + QAbstractItemView::MultiSelection + + + + + + + 0 + + + 6 + + + + + Qt::Vertical + + + + 20 + 16 + + + + + + + + + 22 + 22 + + + + + 22 + 22 + + + + + + + + + + + + 22 + 22 + + + + + 22 + 22 + + + + + + + + + + + Qt::Vertical + + + + 20 + 16 + + + + + + + + + + + + + 421 + 102 + + + + + 421 + 102 + + + + false + + + + + + + + + + + 9 + 482 + 587 + 22 + + + + Private (won't be distributed on trackerless network / DHT if enabled) + + + + + + 9 + 510 + 587 + 30 + + + + + 0 + + + 6 + + + + + + 16777215 + 26 + + + + Destination torrent file: + + + txt_destination + + + + + + + 0 + + + 6 + + + + + + + + ... + + + + + + + + + + + 9 + 546 + 587 + 33 + + + + + 0 + + + 6 + + + + + Qt::Horizontal + + + + 131 + 31 + + + + + + + + Create + + + + + + + Cancel + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + - diff --git a/src/createtorrent_imp.cpp b/src/createtorrent_imp.cpp index d1c892be2..87f0dd53a 100644 --- a/src/createtorrent_imp.cpp +++ b/src/createtorrent_imp.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -41,6 +42,14 @@ using namespace boost::filesystem; createtorrent::createtorrent(QWidget *parent): QDialog(parent){ setupUi(this); + addTracker_button->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/add.png"))); + removeTracker_button->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/remove.png"))); + addURLSeed_button->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/add.png"))); + removeURLSeed_button->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/remove.png"))); + removeFolder_button->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/remove.png"))); + //TODO: Change those two + addFolder_button->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/add.png"))); + addFile_button->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/add.png"))); setAttribute(Qt::WA_DeleteOnClose); show(); } @@ -48,23 +57,71 @@ createtorrent::createtorrent(QWidget *parent): QDialog(parent){ void createtorrent::on_browse_destination_clicked(){ QString destination = QFileDialog::getSaveFileName(this, tr("Select destination torrent file"), QDir::homePath(), tr("Torrent Files")+" (*.torrent)"); if(!destination.isEmpty()){ + if(!destination.endsWith(".torrent")) + destination += ".torrent"; txt_destination->setText(destination); } } -void createtorrent::on_browse_input_clicked(){ - // Can't use QFileDialog static functions for this because - // user can select a file or a directory - QFileDialog *fd = new QFileDialog(this, tr("Select input directory or file"), QDir::homePath()); - if(checkDirectory->isChecked()){ - fd->setFileMode(QFileDialog::DirectoryOnly); - }else{ - fd->setFileMode(QFileDialog::ExistingFile); +void createtorrent::on_addFolder_button_clicked(){ + QString dir = QFileDialog::getExistingDirectory(this, tr("Select a folder to add to the torrent"), QDir::homePath(), QFileDialog::ShowDirsOnly); + if(!dir.isEmpty() && input_list->findItems(dir, Qt::MatchCaseSensitive).size() == 0) + input_list->addItem(dir); +} + +void createtorrent::on_addFile_button_clicked(){ + QStringList files = QFileDialog::getOpenFileNames(this, tr("Select files to add to the torrent"), QDir::homePath(), QString(), 0, QFileDialog::ShowDirsOnly); + QString file; + foreach(file, files){ + if(input_list->findItems(file, Qt::MatchCaseSensitive).size() == 0){ + input_list->addItem(file); + } } - QStringList fileNames; - if (fd->exec()){ - fileNames = fd->selectedFiles(); - txt_input->setText(fileNames.first()); +} + +void createtorrent::on_removeFolder_button_clicked(){ + QModelIndexList selectedIndexes = input_list->selectionModel()->selectedIndexes(); + for(int i=selectedIndexes.size()-1; i>=0; --i){ + QListWidgetItem *item = input_list->takeItem(selectedIndexes.at(i).row()); + delete item; + } +} + +void createtorrent::on_removeTracker_button_clicked(){ + QModelIndexList selectedIndexes = trackers_list->selectionModel()->selectedIndexes(); + for(int i=selectedIndexes.size()-1; i>=0; --i){ + QListWidgetItem *item = trackers_list->takeItem(selectedIndexes.at(i).row()); + delete item; + } +} + +void createtorrent::on_addTracker_button_clicked(){ + bool ok; + QString URL = QInputDialog::getText(this, tr("Please type an announce URL"), + tr("Announce URL:"), QLineEdit::Normal, + "http://", &ok); + if(ok){ + if(trackers_list->findItems(URL, Qt::MatchFixedString).size() == 0) + trackers_list->addItem(URL); + } +} + +void createtorrent::on_removeURLSeed_button_clicked(){ + QModelIndexList selectedIndexes = URLSeeds_list->selectionModel()->selectedIndexes(); + for(int i=selectedIndexes.size()-1; i>=0; --i){ + QListWidgetItem *item = URLSeeds_list->takeItem(selectedIndexes.at(i).row()); + delete item; + } +} + +void createtorrent::on_addURLSeed_button_clicked(){ + bool ok; + QString URL = QInputDialog::getText(this, tr("Please type an URL Seed"), + tr("URL Seed:"), QLineEdit::Normal, + "http://", &ok); + if(ok){ + if(URLSeeds_list->findItems(URL, Qt::MatchFixedString).size() == 0) + URLSeeds_list->addItem(URL); } } @@ -80,6 +137,15 @@ void add_files(torrent_info& t, path const& p, path const& l){ } } +QStringList createtorrent::allItems(QListWidget *list){ + QStringList res; + unsigned int nbItems = list->count(); + for(unsigned int i=0; i< nbItems; ++i){ + res << list->item(i)->text(); + } + return res; +} + // Main function that create a .torrent file void createtorrent::on_createButton_clicked(){ QString destination = txt_destination->text(); @@ -87,37 +153,40 @@ void createtorrent::on_createButton_clicked(){ QMessageBox::critical(0, tr("No destination path set"), tr("Please type a destination path first")); return; } - QString input = txt_input->text(); - if(input.isEmpty()){ + QStringList input = allItems(input_list); + if(input.size() == 0){ QMessageBox::critical(0, tr("No input path set"), tr("Please type an input path first")); return; } - if(!QFile::exists(input)){ - QMessageBox::critical(0, tr("Input path does not exist"), tr("Please type a valid input path first")); - return; - } - char const* creator_str = "qBittorrent"; - int piece_size = 256 * 1024; + char const* creator_str = "qBittorrent "VERSION; try { torrent_info t; - path full_path = complete(path((const char*)input.toUtf8())); + QString input_path; + path full_path; ofstream out(complete(path((const char*)destination.toUtf8())), std::ios_base::binary); - - add_files(t, full_path.branch_path(), full_path.leaf()); + foreach(input_path, input){ + full_path = complete(path((const char*)input_path.toUtf8())); + add_files(t, full_path.branch_path(), full_path.leaf()); + } + int piece_size = 256 * 1024; t.set_piece_size(piece_size); - - file_pool fp; - storage st(t, full_path.branch_path(), fp); - QStringList trackers = txt_announce->toPlainText().split('\n'); + // Add url seeds + QStringList urlSeeds = allItems(URLSeeds_list); + QString seed; + foreach(seed, urlSeeds){ + t.add_url_seed((const char*)seed.toUtf8()); + } + QStringList trackers = allItems(trackers_list); for(int i=0; i buf(piece_size); - for (int i = 0; i < num; ++i) - { + for (int i = 0; i < num; ++i) { st.read(&buf[0], i, 0, t.piece_size(i)); hasher h(&buf[0], t.piece_size(i)); t.set_hash(i, h.final()); @@ -126,6 +195,10 @@ void createtorrent::on_createButton_clicked(){ // torrent_info structure t.set_creator(creator_str); t.set_comment((const char*)txt_comment->toPlainText().toUtf8()); + // Is private ? + if(check_private->isChecked()){ + t.set_priv(true); + } // create the torrent and print it to out entry e = t.create_torrent(); libtorrent::bencode(std::ostream_iterator(out), e); diff --git a/src/createtorrent_imp.h b/src/createtorrent_imp.h index 81b44700b..7b3e10c53 100644 --- a/src/createtorrent_imp.h +++ b/src/createtorrent_imp.h @@ -30,11 +30,18 @@ class createtorrent : public QDialog, private Ui::createTorrentDialog{ public: createtorrent(QWidget *parent = 0); + QStringList allItems(QListWidget *list); protected slots: void on_browse_destination_clicked(); - void on_browse_input_clicked(); void on_createButton_clicked(); + void on_addFile_button_clicked(); + void on_addFolder_button_clicked(); + void on_removeFolder_button_clicked(); + void on_addTracker_button_clicked(); + void on_removeTracker_button_clicked(); + void on_addURLSeed_button_clicked(); + void on_removeURLSeed_button_clicked(); }; #endif