Browse Source

- Improved a lot the torrent creation module

adaptive-webui-19844
Christophe Dumez 18 years ago
parent
commit
ff0dd88ee1
  1. 1
      Changelog
  2. 5
      TODO
  3. 829
      src/createtorrent.ui
  4. 131
      src/createtorrent_imp.cpp
  5. 9
      src/createtorrent_imp.h

1
Changelog

@ -6,6 +6,7 @@
- FEATURE: Allow user to change qBT's style (Plastique, Cleanlooks, Motif, CDE, MacOSX, WinXP) - FEATURE: Allow user to change qBT's style (Plastique, Cleanlooks, Motif, CDE, MacOSX, WinXP)
- FEATURE: Allow the user to disable system tray integration - FEATURE: Allow the user to disable system tray integration
- FEATURE: Search engine is now using one thread per website for faster results - 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 - FEATURE: Ask for exit confirmation only if download list is not empty
- BUGFIX: Window can now stay maximized on exit - BUGFIX: Window can now stay maximized on exit
- COSMETIC: Redesigned torrent properties a little - COSMETIC: Redesigned torrent properties a little

5
TODO

@ -32,10 +32,7 @@
// in v0.10 (partial) - WIP // in v0.10 (partial) - WIP
- Download from RSS feeds (WIP by gtsoul, clean & finish rss.h, add a tab in mainWindow, debug) - 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) - Move finished torrent to another tab and keep on seeding them even after restart (debug)
- Improve torrent creation dialog (look & features) : - Check storage st creation + hasher in torrent creation
- Add Private combobox (allow to share on DHT or not)
- Use a QListWidget to allow multiple input paths
- Possibility to add url seeds
- Add IPv6 support (at least start working on it, libtorrent seems to support it, we should limit our code to IPv4 anymore) - 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 - Display Url seeds in torrent properties and allow to edit them
- Use tooltips to explain options? - Use tooltips to explain options?

829
src/createtorrent.ui

@ -1,258 +1,607 @@
<ui version="4.0" > <ui version="4.0" >
<author></author>
<comment></comment>
<exportmacro></exportmacro>
<class>createTorrentDialog</class> <class>createTorrentDialog</class>
<widget class="QDialog" name="createTorrentDialog" > <widget class="QDialog" name="createTorrentDialog" >
<property name="geometry" > <property name="geometry" >
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>560</width> <width>605</width>
<height>307</height> <height>588</height>
</rect> </rect>
</property> </property>
<property name="windowTitle" > <property name="windowTitle" >
<string>Torrent Creation Tool</string> <string>Torrent Creation Tool</string>
</property> </property>
<layout class="QVBoxLayout" > <widget class="QLabel" name="createTorrent_title" >
<property name="margin" > <property name="geometry" >
<number>9</number> <rect>
<x>9</x>
<y>9</y>
<width>587</width>
<height>27</height>
</rect>
</property> </property>
<property name="spacing" > <property name="minimumSize" >
<number>6</number> <size>
<width>0</width>
<height>27</height>
</size>
</property> </property>
<item> <property name="maximumSize" >
<widget class="QLabel" name="createTorrent_title" > <size>
<property name="minimumSize" > <width>16777215</width>
<size> <height>27</height>
<width>0</width> </size>
<height>27</height> </property>
</size> <property name="font" >
</property> <font>
<property name="maximumSize" > <family>Sans Serif</family>
<size> <pointsize>14</pointsize>
<width>16777215</width> <weight>75</weight>
<height>27</height> <italic>false</italic>
</size> <bold>true</bold>
</property> <underline>false</underline>
<property name="font" > <strikeout>false</strikeout>
<font> </font>
<family>Sans Serif</family> </property>
<pointsize>14</pointsize> <property name="text" >
<weight>75</weight> <string>Torrent file creation</string>
<italic>false</italic> </property>
<bold>true</bold> <property name="alignment" >
<underline>false</underline> <set>Qt::AlignCenter</set>
<strikeout>false</strikeout> </property>
</font> </widget>
</property> <widget class="QWidget" name="" >
<property name="text" > <property name="geometry" >
<string>Create Torrent file</string> <rect>
</property> <x>9</x>
<property name="alignment" > <y>42</y>
<set>Qt::AlignCenter</set> <width>587</width>
</property> <height>438</height>
</widget> </rect>
</item> </property>
<item> <layout class="QHBoxLayout" >
<layout class="QHBoxLayout" > <property name="margin" >
<property name="margin" > <number>0</number>
<number>0</number> </property>
</property> <property name="spacing" >
<property name="spacing" > <number>6</number>
<number>6</number> </property>
</property> <item>
<item> <layout class="QVBoxLayout" >
<layout class="QVBoxLayout" > <property name="margin" >
<property name="margin" > <number>0</number>
<number>0</number> </property>
</property> <property name="spacing" >
<property name="spacing" > <number>6</number>
<number>6</number> </property>
</property> <item>
<item> <widget class="QLabel" name="lbl_input" >
<widget class="QLabel" name="lbl_destination" > <property name="minimumSize" >
<property name="maximumSize" > <size>
<size> <width>0</width>
<width>16777215</width> <height>101</height>
<height>26</height> </size>
</size> </property>
</property> <property name="maximumSize" >
<property name="text" > <size>
<string>&lt;center>Destination torrent file:&lt;/center></string> <width>16777215</width>
</property> <height>26</height>
<property name="buddy" > </size>
<cstring>txt_destination</cstring> </property>
</property> <property name="text" >
</widget> <string>Input files or directories:</string>
</item> </property>
<item> </widget>
<widget class="QLabel" name="lbl_input" > </item>
<property name="maximumSize" > <item>
<size> <widget class="QLabel" name="lbl_announce_url" >
<width>16777215</width> <property name="minimumSize" >
<height>26</height> <size>
</size> <width>0</width>
</property> <height>102</height>
<property name="text" > </size>
<string>&lt;center>Input file or directory:&lt;/center></string> </property>
</property> <property name="maximumSize" >
<property name="buddy" > <size>
<cstring>txt_input</cstring> <width>16777215</width>
</property> <height>70</height>
</widget> </size>
</item> </property>
<item> <property name="text" >
<widget class="QLabel" name="lbl_announce_url" > <string>Announce urls (trackers):</string>
<property name="maximumSize" > </property>
<size> <property name="buddy" >
<width>16777215</width> <cstring></cstring>
<height>70</height> </property>
</size> </widget>
</property> </item>
<property name="text" > <item>
<string>&lt;center>Announce url:&lt;br>(One per line)&lt;/center></string> <widget class="QLabel" name="urlSeeds_lbl" >
</property> <property name="minimumSize" >
<property name="buddy" > <size>
<cstring></cstring> <width>0</width>
</property> <height>101</height>
</widget> </size>
</item> </property>
<item> <property name="text" >
<widget class="QLabel" name="lbl_comment" > <string>URL seeds (optional):</string>
<property name="text" > </property>
<string>&lt;center>Comment:&lt;/center></string> </widget>
</property> </item>
<property name="buddy" > <item>
<cstring>txt_comment</cstring> <widget class="QLabel" name="lbl_comment" >
</property> <property name="minimumSize" >
</widget> <size>
</item> <width>0</width>
</layout> <height>102</height>
</item> </size>
<item> </property>
<layout class="QVBoxLayout" > <property name="maximumSize" >
<property name="margin" > <size>
<number>0</number> <width>16777215</width>
</property> <height>102</height>
<property name="spacing" > </size>
<number>6</number> </property>
</property> <property name="text" >
<item> <string>Comment (optional):</string>
<layout class="QHBoxLayout" > </property>
<property name="margin" > <property name="buddy" >
<number>0</number> <cstring>txt_comment</cstring>
</property> </property>
<property name="spacing" > </widget>
<number>6</number> </item>
</property> </layout>
<item> </item>
<widget class="QLineEdit" name="txt_destination" /> <item>
</item> <layout class="QVBoxLayout" >
<item> <property name="margin" >
<widget class="QToolButton" name="browse_destination" > <number>0</number>
<property name="text" > </property>
<string>...</string> <property name="spacing" >
</property> <number>6</number>
</widget> </property>
</item> <item>
</layout> <layout class="QHBoxLayout" >
</item> <property name="margin" >
<item> <number>0</number>
<layout class="QHBoxLayout" > </property>
<property name="margin" > <property name="spacing" >
<number>0</number> <number>6</number>
</property> </property>
<property name="spacing" > <item>
<number>6</number> <widget class="QListWidget" name="input_list" >
</property> <property name="selectionMode" >
<item> <enum>QAbstractItemView::MultiSelection</enum>
<widget class="QLineEdit" name="txt_input" /> </property>
</item> </widget>
<item> </item>
<widget class="QCheckBox" name="checkDirectory" > <item>
<property name="text" > <layout class="QVBoxLayout" >
<string>Directory</string> <property name="margin" >
</property> <number>0</number>
</widget> </property>
</item> <property name="spacing" >
<item> <number>6</number>
<widget class="QToolButton" name="browse_input" > </property>
<property name="text" > <item>
<string>...</string> <spacer>
</property> <property name="orientation" >
</widget> <enum>Qt::Vertical</enum>
</item> </property>
</layout> <property name="sizeHint" >
</item> <size>
<item> <width>20</width>
<widget class="QTextEdit" name="txt_announce" /> <height>16</height>
</item> </size>
<item> </property>
<widget class="QTextEdit" name="txt_comment" > </spacer>
<property name="acceptRichText" > </item>
<bool>false</bool> <item>
</property> <widget class="QPushButton" name="addFolder_button" >
</widget> <property name="minimumSize" >
</item> <size>
</layout> <width>22</width>
</item> <height>22</height>
</layout> </size>
</item> </property>
<item> <property name="maximumSize" >
<layout class="QHBoxLayout" > <size>
<property name="margin" > <width>22</width>
<number>0</number> <height>22</height>
</property> </size>
<property name="spacing" > </property>
<number>6</number> <property name="text" >
</property> <string/>
<item> </property>
<spacer> </widget>
<property name="orientation" > </item>
<enum>Qt::Horizontal</enum> <item>
</property> <widget class="QPushButton" name="removeFolder_button" >
<property name="sizeHint" > <property name="minimumSize" >
<size> <size>
<width>131</width> <width>22</width>
<height>31</height> <height>22</height>
</size> </size>
</property> </property>
</spacer> <property name="maximumSize" >
</item> <size>
<item> <width>22</width>
<widget class="QPushButton" name="createButton" > <height>22</height>
<property name="text" > </size>
<string>Create</string> </property>
</property> <property name="text" >
</widget> <string/>
</item> </property>
<item> </widget>
<widget class="QPushButton" name="cancelButton" > </item>
<property name="text" > <item>
<string>Cancel</string> <widget class="QPushButton" name="addFile_button" >
</property> <property name="minimumSize" >
</widget> <size>
</item> <width>22</width>
<item> <height>22</height>
<spacer> </size>
<property name="orientation" > </property>
<enum>Qt::Horizontal</enum> <property name="maximumSize" >
</property> <size>
<property name="sizeHint" > <width>22</width>
<size> <height>22</height>
<width>40</width> </size>
<height>20</height> </property>
</size> <property name="text" >
</property> <string/>
</spacer> </property>
</item> </widget>
</layout> </item>
</item> <item>
</layout> <spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>16</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QListWidget" name="trackers_list" >
<property name="selectionMode" >
<enum>QAbstractItemView::MultiSelection</enum>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>16</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="addTracker_button" >
<property name="minimumSize" >
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="text" >
<string/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="removeTracker_button" >
<property name="minimumSize" >
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="text" >
<string/>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>16</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QListWidget" name="URLSeeds_list" >
<property name="selectionMode" >
<enum>QAbstractItemView::MultiSelection</enum>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>16</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="addURLSeed_button" >
<property name="minimumSize" >
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="text" >
<string/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="removeURLSeed_button" >
<property name="minimumSize" >
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="text" >
<string/>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>16</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QTextEdit" name="txt_comment" >
<property name="minimumSize" >
<size>
<width>421</width>
<height>102</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>421</width>
<height>102</height>
</size>
</property>
<property name="acceptRichText" >
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QCheckBox" name="check_private" >
<property name="geometry" >
<rect>
<x>9</x>
<y>482</y>
<width>587</width>
<height>22</height>
</rect>
</property>
<property name="text" >
<string>Private (won't be distributed on trackerless network / DHT if enabled)</string>
</property>
</widget>
<widget class="QWidget" name="" >
<property name="geometry" >
<rect>
<x>9</x>
<y>510</y>
<width>587</width>
<height>30</height>
</rect>
</property>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QLabel" name="lbl_destination" >
<property name="maximumSize" >
<size>
<width>16777215</width>
<height>26</height>
</size>
</property>
<property name="text" >
<string>Destination torrent file:</string>
</property>
<property name="buddy" >
<cstring>txt_destination</cstring>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QLineEdit" name="txt_destination" />
</item>
<item>
<widget class="QToolButton" name="browse_destination" >
<property name="text" >
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="" >
<property name="geometry" >
<rect>
<x>9</x>
<y>546</y>
<width>587</width>
<height>33</height>
</rect>
</property>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>131</width>
<height>31</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="createButton" >
<property name="text" >
<string>Create</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cancelButton" >
<property name="text" >
<string>Cancel</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget> </widget>
<pixmapfunction></pixmapfunction>
<resources/> <resources/>
<connections> <connections>
<connection> <connection>

131
src/createtorrent_imp.cpp

@ -21,6 +21,7 @@
#include <QFileDialog> #include <QFileDialog>
#include <QMessageBox> #include <QMessageBox>
#include <QInputDialog>
#include <boost/filesystem/operations.hpp> #include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp> #include <boost/filesystem/path.hpp>
@ -41,6 +42,14 @@ using namespace boost::filesystem;
createtorrent::createtorrent(QWidget *parent): QDialog(parent){ createtorrent::createtorrent(QWidget *parent): QDialog(parent){
setupUi(this); 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); setAttribute(Qt::WA_DeleteOnClose);
show(); show();
} }
@ -48,23 +57,71 @@ createtorrent::createtorrent(QWidget *parent): QDialog(parent){
void createtorrent::on_browse_destination_clicked(){ void createtorrent::on_browse_destination_clicked(){
QString destination = QFileDialog::getSaveFileName(this, tr("Select destination torrent file"), QDir::homePath(), tr("Torrent Files")+" (*.torrent)"); QString destination = QFileDialog::getSaveFileName(this, tr("Select destination torrent file"), QDir::homePath(), tr("Torrent Files")+" (*.torrent)");
if(!destination.isEmpty()){ if(!destination.isEmpty()){
if(!destination.endsWith(".torrent"))
destination += ".torrent";
txt_destination->setText(destination); txt_destination->setText(destination);
} }
} }
void createtorrent::on_browse_input_clicked(){ void createtorrent::on_addFolder_button_clicked(){
// Can't use QFileDialog static functions for this because QString dir = QFileDialog::getExistingDirectory(this, tr("Select a folder to add to the torrent"), QDir::homePath(), QFileDialog::ShowDirsOnly);
// user can select a file or a directory if(!dir.isEmpty() && input_list->findItems(dir, Qt::MatchCaseSensitive).size() == 0)
QFileDialog *fd = new QFileDialog(this, tr("Select input directory or file"), QDir::homePath()); input_list->addItem(dir);
if(checkDirectory->isChecked()){ }
fd->setFileMode(QFileDialog::DirectoryOnly);
}else{ void createtorrent::on_addFile_button_clicked(){
fd->setFileMode(QFileDialog::ExistingFile); 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);
}
}
}
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;
} }
QStringList fileNames; }
if (fd->exec()){
fileNames = fd->selectedFiles(); void createtorrent::on_addURLSeed_button_clicked(){
txt_input->setText(fileNames.first()); 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 // Main function that create a .torrent file
void createtorrent::on_createButton_clicked(){ void createtorrent::on_createButton_clicked(){
QString destination = txt_destination->text(); 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")); QMessageBox::critical(0, tr("No destination path set"), tr("Please type a destination path first"));
return; return;
} }
QString input = txt_input->text(); QStringList input = allItems(input_list);
if(input.isEmpty()){ if(input.size() == 0){
QMessageBox::critical(0, tr("No input path set"), tr("Please type an input path first")); QMessageBox::critical(0, tr("No input path set"), tr("Please type an input path first"));
return; return;
} }
if(!QFile::exists(input)){ char const* creator_str = "qBittorrent "VERSION;
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;
try { try {
torrent_info t; 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); ofstream out(complete(path((const char*)destination.toUtf8())), std::ios_base::binary);
foreach(input_path, input){
add_files(t, full_path.branch_path(), full_path.leaf()); 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); t.set_piece_size(piece_size);
// Add url seeds
file_pool fp; QStringList urlSeeds = allItems(URLSeeds_list);
storage st(t, full_path.branch_path(), fp); QString seed;
QStringList trackers = txt_announce->toPlainText().split('\n'); foreach(seed, urlSeeds){
t.add_url_seed((const char*)seed.toUtf8());
}
QStringList trackers = allItems(trackers_list);
for(int i=0; i<trackers.size(); ++i){ for(int i=0; i<trackers.size(); ++i){
t.add_tracker((const char*)trackers.at(i).toUtf8()); t.add_tracker((const char*)trackers.at(i).toUtf8());
} }
// calculate the hash for all pieces // calculate the hash for all pieces
file_pool fp;
storage st(t, full_path.branch_path(), fp);
int num = t.num_pieces(); int num = t.num_pieces();
std::vector<char> buf(piece_size); std::vector<char> 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)); st.read(&buf[0], i, 0, t.piece_size(i));
hasher h(&buf[0], t.piece_size(i)); hasher h(&buf[0], t.piece_size(i));
t.set_hash(i, h.final()); t.set_hash(i, h.final());
@ -126,6 +195,10 @@ void createtorrent::on_createButton_clicked(){
// torrent_info structure // torrent_info structure
t.set_creator(creator_str); t.set_creator(creator_str);
t.set_comment((const char*)txt_comment->toPlainText().toUtf8()); 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 // create the torrent and print it to out
entry e = t.create_torrent(); entry e = t.create_torrent();
libtorrent::bencode(std::ostream_iterator<char>(out), e); libtorrent::bencode(std::ostream_iterator<char>(out), e);

9
src/createtorrent_imp.h

@ -30,11 +30,18 @@ class createtorrent : public QDialog, private Ui::createTorrentDialog{
public: public:
createtorrent(QWidget *parent = 0); createtorrent(QWidget *parent = 0);
QStringList allItems(QListWidget *list);
protected slots: protected slots:
void on_browse_destination_clicked(); void on_browse_destination_clicked();
void on_browse_input_clicked();
void on_createButton_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 #endif

Loading…
Cancel
Save