diff --git a/Changelog b/Changelog index 63723b003..b0476d497 100644 --- a/Changelog +++ b/Changelog @@ -4,7 +4,10 @@ - FEATURE: Added a torrent import assistant to seed or keep downloading outside torrents - FEATURE: qBittorrent can update itself from Sourceforge (Windows/Mac OS X only) - FEATURE: Added a transfer list column to display the current tracker + - FEATURE: Remember the last trackers used in the torrent creation tool + - FEATURE: The optimal piece size is now automatically computed in the torrent creation tool - COSMETIC: Replaced message box by on-screen notification for download errors + - COSMETIC: Improved the torrent creation tool appearance * Tue Aug 24 2010 - Christophe Dumez - v2.4.0 - FEATURE: Added actions to "Move to top/bottom" of priority queue diff --git a/src/misc.cpp b/src/misc.cpp index df86d9d60..3d23a7bfa 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -80,9 +80,9 @@ QString misc::QDesktopServicesDataLocation() { #if defined Q_WS_WINCE if (SHGetSpecialFolderPath(0, path, CSIDL_APPDATA, FALSE)) #else - if (SHGetSpecialFolderPath(0, path, CSIDL_LOCAL_APPDATA, FALSE)) + if (SHGetSpecialFolderPath(0, path, CSIDL_LOCAL_APPDATA, FALSE)) #endif - result = QString::fromWCharArray(path); + result = QString::fromWCharArray(path); if (!QCoreApplication::applicationName().isEmpty()) result = result + QLatin1String("\\") + qApp->applicationName(); if(!result.endsWith("\\")) @@ -106,7 +106,7 @@ QString misc::QDesktopServicesDataLocation() { if (xdgDataHome.isEmpty()) xdgDataHome = QDir::homePath() + QLatin1String("/.local/share"); xdgDataHome += QLatin1String("/data/") - + qApp->applicationName(); + + qApp->applicationName(); return xdgDataHome; #endif #endif @@ -158,7 +158,7 @@ long long misc::freeDiskSpaceOnPath(QString path) { const int ret = statfs (qPrintable(statfs_path), &stats) ; if(ret == 0) { available = ((unsigned long long)stats.f_bavail) * - ((unsigned long long)stats.f_bsize) ; + ((unsigned long long)stats.f_bsize) ; return available; } else { return -1; @@ -170,10 +170,10 @@ long long misc::freeDiskSpaceOnPath(QString path) { PULARGE_INTEGER); GetDiskFreeSpaceEx_t pGetDiskFreeSpaceEx = (GetDiskFreeSpaceEx_t)::GetProcAddress - ( - ::GetModuleHandle(TEXT("kernel32.dll")), - "GetDiskFreeSpaceExW" - ); + ( + ::GetModuleHandle(TEXT("kernel32.dll")), + "GetDiskFreeSpaceExW" + ); if ( pGetDiskFreeSpaceEx ) { ULARGE_INTEGER bytesFree, bytesTotal; @@ -220,7 +220,7 @@ void misc::shutdownComputer() { AEDisposeDesc(&targetDesc); if (error != noErr) { - return; + return; } error = AESend(&appleEventToSend, &eventReply, kAENoReply, @@ -730,3 +730,21 @@ QList misc::boolListfromStringList(const QStringList &l) { } return ret; } + +quint64 misc::computePathSize(QString path) +{ + // Check if it is a file + QFileInfo fi(path); + if(!fi.exists()) return 0; + if(fi.isFile()) return fi.size(); + // Compute folder size + quint64 size = 0; + foreach(const QFileInfo &subfi, QDir(path).entryInfoList(QDir::Dirs|QDir::Files)) { + if(subfi.fileName().startsWith(".")) continue; + if(subfi.isDir()) + size += misc::computePathSize(subfi.absoluteFilePath()); + else + size += subfi.size(); + } + return size; +} diff --git a/src/misc.h b/src/misc.h index c309dc313..8f9df5f61 100644 --- a/src/misc.h +++ b/src/misc.h @@ -117,6 +117,8 @@ public: return MyFile.remove(); } + static quint64 computePathSize(QString path); + static QString truncateRootFolder(boost::intrusive_ptr t); static QString truncateRootFolder(torrent_handle h); diff --git a/src/src.pro b/src/src.pro index f31a078b9..37725ed1c 100644 --- a/src/src.pro +++ b/src/src.pro @@ -309,7 +309,6 @@ contains(DEFINES, DISABLE_GUI) { cookiesdlg.h \ hidabletabwidget.h \ sessionapplication.h \ - torrentcreatordlg.h \ torrentimportdlg.h win32 { @@ -349,13 +348,13 @@ include(tracker/tracker.pri) include(properties/properties.pri) include(searchengine/searchengine.pri) include(rss/rss.pri) + include(torrentcreator/torrentcreator.pri) } !contains(DEFINES, DISABLE_GUI) { FORMS += ui/mainwindow.ui \ ui/options.ui \ ui/about.ui \ - ui/createtorrent.ui \ ui/preview.ui \ ui/login.ui \ ui/downloadfromurldlg.ui \ @@ -384,7 +383,6 @@ SOURCES += main.cpp \ cookiesdlg.cpp \ torrentadditiondlg.cpp \ sessionapplication.cpp \ - torrentcreatordlg.cpp \ torrentimportdlg.cpp win32 { diff --git a/src/torrentcreator/createtorrent.ui b/src/torrentcreator/createtorrent.ui new file mode 100644 index 000000000..b6807e32a --- /dev/null +++ b/src/torrentcreator/createtorrent.ui @@ -0,0 +1,330 @@ + + + createTorrentDialog + + + + 0 + 0 + 592 + 658 + + + + Torrent Creation Tool + + + + + + + 0 + 27 + + + + + 16777215 + 27 + + + + + Sans Serif + 14 + 75 + false + true + false + false + + + + Torrent file creation + + + Qt::AlignCenter + + + + + + + File or folder to add to the torrent: + + + + + + + + + + + + Add file + + + + :/Icons/oxygen/document-new.png:/Icons/oxygen/document-new.png + + + + + + + Add folder + + + + :/Icons/oxygen/folder-new.png:/Icons/oxygen/folder-new.png + + + + + + + + + + + Tracker URLs: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + Web seeds urls: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Comment: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + txt_comment + + + + + + + + 0 + 0 + + + + false + + + + + + + + 0 + 0 + + + + false + + + + + + + false + + + + + + + + + + + Piece size: + + + + + + + false + + + false + + + 3 + + + + 32 KiB + + + + + 64 KiB + + + + + 128 KiB + + + + + 256 KiB + + + + + 512 KiB + + + + + 1 MiB + + + + + 2 MiB + + + + + 4 MiB + + + + + + + + Auto + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Private (won't be distributed on DHT network if enabled) + + + + + + + Start seeding after creation + + + + + + + Progress: + + + + + + + 0 + + + + + + + 6 + + + 0 + + + + + Qt::Horizontal + + + + 131 + 31 + + + + + + + + Create and save... + + + + + + + Cancel + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + diff --git a/src/torrentcreator/torrentcreator.pri b/src/torrentcreator/torrentcreator.pri new file mode 100644 index 000000000..9be087937 --- /dev/null +++ b/src/torrentcreator/torrentcreator.pri @@ -0,0 +1,10 @@ +INCLUDEPATH += $$PWD + +FORMS += $$PWD/createtorrent.ui + +HEADERS += $$PWD/torrentcreatordlg.h \ + $$PWD/torrentcreatorthread.h + +SOURCES += $$PWD/torrentcreatordlg.cpp \ + $$PWD/torrentcreatorthread.cpp + diff --git a/src/torrentcreatordlg.cpp b/src/torrentcreator/torrentcreatordlg.cpp similarity index 54% rename from src/torrentcreatordlg.cpp rename to src/torrentcreator/torrentcreatordlg.cpp index e0568db63..fb16326dc 100644 --- a/src/torrentcreatordlg.cpp +++ b/src/torrentcreator/torrentcreatordlg.cpp @@ -1,6 +1,6 @@ /* * Bittorrent Client using Qt4 and libtorrent. - * Copyright (C) 2006 Christophe Dumez + * Copyright (C) 2010 Christophe Dumez * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -32,52 +32,29 @@ #include #include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include "torrentpersistentdata.h" #include "torrentcreatordlg.h" #include "misc.h" #include "qinisettings.h" +#include "torrentcreatorthread.h" -using namespace libtorrent; -using namespace boost::filesystem; +const uint NB_PIECES_MIN = 1200; +const uint NB_PIECES_MAX = 2200; -// do not include files and folders whose -// name starts with a . -bool file_filter(boost::filesystem::path const& filename) -{ - if (filename.leaf()[0] == '.') return false; - std::cerr << filename << std::endl; - return true; -} - -TorrentCreatorDlg::TorrentCreatorDlg(QWidget *parent): QDialog(parent){ +TorrentCreatorDlg::TorrentCreatorDlg(QWidget *parent): QDialog(parent), creatorThread(0) { setupUi(this); setAttribute(Qt::WA_DeleteOnClose); setModal(true); - creatorThread = new torrentCreatorThread(this); - connect(creatorThread, SIGNAL(creationSuccess(QString, QString)), this, SLOT(handleCreationSuccess(QString, QString))); - connect(creatorThread, SIGNAL(creationFailure(QString)), this, SLOT(handleCreationFailure(QString))); - connect(creatorThread, SIGNAL(updateProgress(int)), this, SLOT(updateProgressBar(int))); - path::default_name_check(no_check); + showProgressBar(false); + loadTrackerList(); + // Piece sizes + m_piece_sizes << 32 << 64 << 128 << 256 << 512 << 1024 << 2048 << 4096; show(); } TorrentCreatorDlg::~TorrentCreatorDlg() { - delete creatorThread; + if(creatorThread) + delete creatorThread; } void TorrentCreatorDlg::on_addFolder_button_clicked(){ @@ -90,6 +67,9 @@ void TorrentCreatorDlg::on_addFolder_button_clicked(){ dir = dir.replace("/", "\\"); #endif textInputPath->setText(dir); + // Update piece size + if(checkAutoPieceSize->isChecked()) + updateOptimalPieceSize(); } } @@ -103,75 +83,14 @@ void TorrentCreatorDlg::on_addFile_button_clicked(){ file = file.replace("/", "\\"); #endif textInputPath->setText(file); - } -} - -void TorrentCreatorDlg::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; + // Update piece size + if(checkAutoPieceSize->isChecked()) + updateOptimalPieceSize(); } } int TorrentCreatorDlg::getPieceSize() const { - switch(comboPieceSize->currentIndex()) { - case 0: - return 32*1024; - case 1: - return 64*1024; - case 2: - return 128*1024; - case 3: - return 256*1024; - case 4: - return 512*1024; - case 5: - return 1024*1024; - case 6: - return 2048*1024; - default: - return 256*1024; - } -} - -void TorrentCreatorDlg::on_addTracker_button_clicked() { - bool ok; - QString URL = QInputDialog::getText(this, tr("Please type an announce URL"), - tr("Announce URL:", "Tracker URL"), QLineEdit::Normal, - "http://", &ok); - if(ok){ - if(trackers_list->findItems(URL, Qt::MatchFixedString).size() == 0) - trackers_list->addItem(URL); - } -} - -void TorrentCreatorDlg::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 TorrentCreatorDlg::on_addURLSeed_button_clicked(){ - bool ok; - QString URL = QInputDialog::getText(this, tr("Please type a web seed url"), - tr("Web seed URL:"), QLineEdit::Normal, - "http://", &ok); - if(ok){ - if(URLSeeds_list->findItems(URL, Qt::MatchFixedString).size() == 0) - URLSeeds_list->addItem(URL); - } -} - -QStringList TorrentCreatorDlg::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; + return m_piece_sizes.at(comboPieceSize->currentIndex())*1024; } // Main function that create a .torrent file @@ -183,7 +102,9 @@ void TorrentCreatorDlg::on_createButton_clicked(){ QMessageBox::critical(0, tr("No input path set"), tr("Please type an input path first")); return; } - QStringList trackers = allItems(trackers_list); + QStringList trackers = trackers_list->toPlainText().split("\n"); + if(!trackers_list->toPlainText().trimmed().isEmpty()) + saveTrackerList(); QIniSettings settings("qBittorrent", "qBittorrent"); QString last_path = settings.value("CreateTorrent/last_save_path", QDir::homePath()).toString(); @@ -197,26 +118,30 @@ void TorrentCreatorDlg::on_createButton_clicked(){ return; } // Disable dialog - setEnabled(false); + setInteractionEnabled(false); + showProgressBar(true); // Set busy cursor setCursor(QCursor(Qt::WaitCursor)); // Actually create the torrent - QStringList url_seeds = allItems(URLSeeds_list); + QStringList url_seeds = URLSeeds_list->toPlainText().split("\n"); QString comment = txt_comment->toPlainText(); + // Create the creator thread + creatorThread = new TorrentCreatorThread(this); + connect(creatorThread, SIGNAL(creationSuccess(QString, QString)), this, SLOT(handleCreationSuccess(QString, QString))); + connect(creatorThread, SIGNAL(creationFailure(QString)), this, SLOT(handleCreationFailure(QString))); + connect(creatorThread, SIGNAL(updateProgress(int)), this, SLOT(updateProgressBar(int))); creatorThread->create(input, destination, trackers, url_seeds, comment, check_private->isChecked(), getPieceSize()); } void TorrentCreatorDlg::handleCreationFailure(QString msg) { - // Enable dialog - setEnabled(true); // Remove busy cursor setCursor(QCursor(Qt::ArrowCursor)); QMessageBox::information(0, tr("Torrent creation"), tr("Torrent creation was unsuccessful, reason: %1").arg(msg)); + setInteractionEnabled(true); + showProgressBar(false); } void TorrentCreatorDlg::handleCreationSuccess(QString path, QString branch_path) { - // Enable Dialog - setEnabled(true); // Remove busy cursor setCursor(QCursor(Qt::ArrowCursor)); if(checkStartSeeding->isChecked()) { @@ -248,7 +173,7 @@ void TorrentCreatorDlg::handleCreationSuccess(QString path, QString branch_path) void TorrentCreatorDlg::on_cancelButton_clicked() { // End torrent creation thread - if(creatorThread->isRunning()) { + if(creatorThread && creatorThread->isRunning()) { creatorThread->abortCreation(); creatorThread->terminate(); // Wait for termination @@ -262,66 +187,69 @@ void TorrentCreatorDlg::updateProgressBar(int progress) { progressBar->setValue(progress); } -// -// Torrent Creator Thread -// - -void torrentCreatorThread::create(QString _input_path, QString _save_path, QStringList _trackers, QStringList _url_seeds, QString _comment, bool _is_private, int _piece_size) { - input_path = _input_path; - save_path = _save_path; - trackers = _trackers; - url_seeds = _url_seeds; - comment = _comment; - is_private = _is_private; - piece_size = _piece_size; - abort = false; - start(); +void TorrentCreatorDlg::setInteractionEnabled(bool enabled) +{ + textInputPath->setEnabled(enabled); + addFile_button->setEnabled(enabled); + addFolder_button->setEnabled(enabled); + trackers_list->setEnabled(enabled); + URLSeeds_list->setEnabled(enabled); + txt_comment->setEnabled(enabled); + comboPieceSize->setEnabled(enabled); + check_private->setEnabled(enabled); + checkStartSeeding->setEnabled(enabled); + createButton->setEnabled(enabled); + //cancelButton->setEnabled(!enabled); } -void sendProgressUpdateSignal(int i, int num, torrentCreatorThread *parent){ - parent->sendProgressSignal((int)(i*100./(float)num)); +void TorrentCreatorDlg::showProgressBar(bool show) +{ + progressLbl->setVisible(show); + progressBar->setVisible(show); } -void torrentCreatorThread::sendProgressSignal(int progress) { - emit updateProgress(progress); -} - -void torrentCreatorThread::run() { - emit updateProgress(0); - char const* creator_str = "qBittorrent "VERSION; - try { - file_storage fs; - path full_path = complete(path(input_path.toUtf8().constData())); - // Adding files to the torrent - add_files(fs, full_path, file_filter); - if(abort) return; - create_torrent t(fs, piece_size); - - // Add url seeds - QString seed; - foreach(seed, url_seeds){ - t.add_url_seed(seed.toLocal8Bit().data()); - } - for(int i=0; i(&sendProgressUpdateSignal, _1, t.num_pieces(), this)); - // Set qBittorrent as creator and add user comment to - // torrent_info structure - t.set_creator(creator_str); - t.set_comment((const char*)comment.toUtf8()); - // Is private ? - t.set_priv(is_private); - if(abort) return; - // create the torrent and print it to out - ofstream out(complete(path((const char*)save_path.toUtf8())), std::ios_base::binary); - bencode(std::ostream_iterator(out), t.generate()); - emit updateProgress(100); - emit creationSuccess(save_path, QString::fromUtf8(full_path.branch_path().string().c_str())); - } - catch (std::exception& e){ - emit creationFailure(QString::fromUtf8(e.what())); +void TorrentCreatorDlg::on_checkAutoPieceSize_clicked(bool checked) +{ + comboPieceSize->setEnabled(!checked); + if(checked) { + updateOptimalPieceSize(); } } + +void TorrentCreatorDlg::updateOptimalPieceSize() +{ + quint64 torrent_size = misc::computePathSize(textInputPath->text()); + qDebug("Torrent size is %lld", torrent_size); + if(torrent_size == 0) return; + int i = 0; + qulonglong nb_pieces = 0; + do { + nb_pieces = (double)torrent_size/(m_piece_sizes.at(i)*1024.); + qDebug("nb_pieces=%lld with piece_size=%s", nb_pieces, qPrintable(comboPieceSize->itemText(i))); + if(nb_pieces <= NB_PIECES_MIN) { + if(i > 1) + --i; + break; + } + if(nb_pieces < NB_PIECES_MAX) { + qDebug("Good, nb_pieces=%lld < %d", nb_pieces, NB_PIECES_MAX); + break; + } + ++i; + }while(i NB_PIECES_MIN); + comboPieceSize->setCurrentIndex(i); +} + +void TorrentCreatorDlg::saveTrackerList() +{ + QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); + settings.setValue("CreateTorrent/TrackerList", trackers_list->toPlainText()); +} + +void TorrentCreatorDlg::loadTrackerList() +{ + QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); + trackers_list->setPlainText(settings.value("CreateTorrent/TrackerList", "").toString()); +} diff --git a/src/torrentcreatordlg.h b/src/torrentcreator/torrentcreatordlg.h similarity index 64% rename from src/torrentcreatordlg.h rename to src/torrentcreator/torrentcreatordlg.h index be86f9c0a..0b3b12a20 100644 --- a/src/torrentcreatordlg.h +++ b/src/torrentcreator/torrentcreatordlg.h @@ -1,6 +1,6 @@ /* * Bittorrent Client using Qt4 and libtorrent. - * Copyright (C) 2006 Christophe Dumez + * Copyright (C) 2010 Christophe Dumez * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -31,56 +31,16 @@ #ifndef CREATE_TORRENT_IMP_H #define CREATE_TORRENT_IMP_H -#include - #include "ui_createtorrent.h" -class torrentCreatorThread : public QThread { - Q_OBJECT - - QString input_path; - QString save_path; - QStringList trackers; - QStringList url_seeds; - QString comment; - bool is_private; - int piece_size; - bool abort; - QDialog *parent; - - public: - torrentCreatorThread(QDialog *_parent) { - parent = _parent; - } - ~torrentCreatorThread() { - abort = true; - wait(); - } - void create(QString _input_path, QString _save_path, QStringList _trackers, QStringList _url_seeds, QString _comment, bool _is_private, int _piece_size); - void sendProgressSignal(int progress); - void abortCreation() { abort = true; } - - protected: - void run(); - - signals: - void creationFailure(QString msg); - void creationSuccess(QString path, QString branch_path); - - signals: - void updateProgress(int progress); -}; +class TorrentCreatorThread; class TorrentCreatorDlg : public QDialog, private Ui::createTorrentDialog{ Q_OBJECT - - private: - torrentCreatorThread *creatorThread; public: TorrentCreatorDlg(QWidget *parent = 0); ~TorrentCreatorDlg(); - QStringList allItems(QListWidget *list); int getPieceSize() const; signals: @@ -94,12 +54,18 @@ class TorrentCreatorDlg : public QDialog, private Ui::createTorrentDialog{ void on_createButton_clicked(); void on_addFile_button_clicked(); void on_addFolder_button_clicked(); - void on_addTracker_button_clicked(); - void on_removeTracker_button_clicked(); - void on_addURLSeed_button_clicked(); - void on_removeURLSeed_button_clicked(); void handleCreationFailure(QString msg); void handleCreationSuccess(QString path, QString branch_path); + void setInteractionEnabled(bool enabled); + void showProgressBar(bool show); + void on_checkAutoPieceSize_clicked(bool checked); + void updateOptimalPieceSize(); + void saveTrackerList(); + void loadTrackerList(); + +private: + TorrentCreatorThread *creatorThread; + QList m_piece_sizes; }; #endif diff --git a/src/torrentcreator/torrentcreatorthread.cpp b/src/torrentcreator/torrentcreatorthread.cpp new file mode 100644 index 000000000..0c2753f82 --- /dev/null +++ b/src/torrentcreator/torrentcreatorthread.cpp @@ -0,0 +1,123 @@ +/* + * Bittorrent Client using Qt4 and libtorrent. + * Copyright (C) 2010 Christophe Dumez + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give permission to + * link this program with the OpenSSL project's "OpenSSL" library (or with + * modified versions of it that use the same license as the "OpenSSL" library), + * and distribute the linked executables. You must obey the GNU General Public + * License in all respects for all of the code used other than "OpenSSL". If you + * modify file(s), you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete this + * exception statement from your version. + * + * Contact : chris@qbittorrent.org + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "torrentcreatorthread.h" +#include "misc.h" + +using namespace libtorrent; +using namespace boost::filesystem; + +// do not include files and folders whose +// name starts with a . +bool file_filter(boost::filesystem::path const& filename) +{ + if (filename.leaf()[0] == '.') return false; + std::cerr << filename << std::endl; + return true; +} + +void TorrentCreatorThread::create(QString _input_path, QString _save_path, QStringList _trackers, QStringList _url_seeds, QString _comment, bool _is_private, int _piece_size) +{ + input_path = _input_path; + save_path = _save_path; + if(QFile(save_path).exists()) + misc::safeRemove(save_path); + trackers = _trackers; + url_seeds = _url_seeds; + comment = _comment; + is_private = _is_private; + piece_size = _piece_size; + path::default_name_check(no_check); + abort = false; + start(); +} + +void sendProgressUpdateSignal(int i, int num, TorrentCreatorThread *parent){ + parent->sendProgressSignal((int)(i*100./(float)num)); +} + +void TorrentCreatorThread::sendProgressSignal(int progress) { + emit updateProgress(progress); +} + +void TorrentCreatorThread::run() { + emit updateProgress(0); + char const* creator_str = "qBittorrent "VERSION; + try { + file_storage fs; + path full_path = complete(path(input_path.toUtf8().constData())); + // Adding files to the torrent + add_files(fs, full_path, file_filter); + if(abort) return; + create_torrent t(fs, piece_size); + + // Add url seeds + foreach(const QString &seed, url_seeds){ + t.add_url_seed(seed.trimmed().toLocal8Bit().data()); + } + foreach(const QString &tracker, trackers) { + t.add_tracker(tracker.trimmed().toLocal8Bit().data()); + } + if(abort) return; + // calculate the hash for all pieces + set_piece_hashes(t, full_path.branch_path(), boost::bind(&sendProgressUpdateSignal, _1, t.num_pieces(), this)); + // Set qBittorrent as creator and add user comment to + // torrent_info structure + t.set_creator(creator_str); + t.set_comment((const char*)comment.toUtf8()); + // Is private ? + t.set_priv(is_private); + if(abort) return; + // create the torrent and print it to out + ofstream out(complete(path((const char*)save_path.toUtf8())), std::ios_base::binary); + bencode(std::ostream_iterator(out), t.generate()); + emit updateProgress(100); + emit creationSuccess(save_path, QString::fromUtf8(full_path.branch_path().string().c_str())); + } + catch (std::exception& e){ + emit creationFailure(QString::fromUtf8(e.what())); + } +} diff --git a/src/torrentcreator/torrentcreatorthread.h b/src/torrentcreator/torrentcreatorthread.h new file mode 100644 index 000000000..3e87008d6 --- /dev/null +++ b/src/torrentcreator/torrentcreatorthread.h @@ -0,0 +1,73 @@ +/* + * Bittorrent Client using Qt4 and libtorrent. + * Copyright (C) 2010 Christophe Dumez + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give permission to + * link this program with the OpenSSL project's "OpenSSL" library (or with + * modified versions of it that use the same license as the "OpenSSL" library), + * and distribute the linked executables. You must obey the GNU General Public + * License in all respects for all of the code used other than "OpenSSL". If you + * modify file(s), you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete this + * exception statement from your version. + * + * Contact : chris@qbittorrent.org + */ + +#ifndef TORRENTCREATORTHREAD_H +#define TORRENTCREATORTHREAD_H + +#include +#include +#include + +class TorrentCreatorThread : public QThread { + Q_OBJECT + +public: + TorrentCreatorThread(QDialog *_parent) { + parent = _parent; + } + ~TorrentCreatorThread() { + abort = true; + wait(); + } + void create(QString _input_path, QString _save_path, QStringList _trackers, QStringList _url_seeds, QString _comment, bool _is_private, int _piece_size); + void sendProgressSignal(int progress); + void abortCreation() { abort = true; } + +protected: + void run(); + +signals: + void creationFailure(QString msg); + void creationSuccess(QString path, QString branch_path); + void updateProgress(int progress); + +private: + QString input_path; + QString save_path; + QStringList trackers; + QStringList url_seeds; + QString comment; + bool is_private; + int piece_size; + bool abort; + QDialog *parent; +}; + +#endif // TORRENTCREATORTHREAD_H diff --git a/src/ui/createtorrent.ui b/src/ui/createtorrent.ui deleted file mode 100644 index 798c2f2d5..000000000 --- a/src/ui/createtorrent.ui +++ /dev/null @@ -1,545 +0,0 @@ - - - createTorrentDialog - - - - 0 - 0 - 592 - 658 - - - - Torrent Creation Tool - - - - - - - 0 - 27 - - - - - 16777215 - 27 - - - - - Sans Serif - 14 - 75 - false - true - false - false - - - - Torrent file creation - - - Qt::AlignCenter - - - - - - - File or folder to add to the torrent: - - - - - - - - - - - - Add file - - - - :/Icons/oxygen/document-new.png:/Icons/oxygen/document-new.png - - - - - - - Add folder - - - - :/Icons/oxygen/folder-new.png:/Icons/oxygen/folder-new.png - - - - - - - - - - - - - - 0 - 102 - - - - - 16777215 - 70 - - - - Announce urls (trackers): - - - - - - - - - - - 0 - 101 - - - - Web seeds urls (optional): - - - - - - - - 0 - 102 - - - - - 16777215 - 102 - - - - Comment (optional): - - - txt_comment - - - - - - - - - - - 6 - - - 0 - - - - - QAbstractItemView::MultiSelection - - - - - - - 6 - - - 0 - - - - - Qt::Vertical - - - - 20 - 16 - - - - - - - - - 22 - 22 - - - - - 22 - 22 - - - - - - - - :/Icons/oxygen/list-add.png:/Icons/oxygen/list-add.png - - - - 18 - 18 - - - - - - - - - 22 - 22 - - - - - 22 - 22 - - - - - - - - :/Icons/oxygen/list-remove.png:/Icons/oxygen/list-remove.png - - - - 18 - 18 - - - - - - - - Qt::Vertical - - - - 20 - 16 - - - - - - - - - - - - 6 - - - 0 - - - - - QAbstractItemView::MultiSelection - - - - - - - 6 - - - 0 - - - - - Qt::Vertical - - - - 20 - 16 - - - - - - - - - 22 - 22 - - - - - 22 - 22 - - - - - - - - :/Icons/oxygen/list-add.png:/Icons/oxygen/list-add.png - - - - 18 - 18 - - - - - - - - - 22 - 22 - - - - - 22 - 22 - - - - - - - - :/Icons/oxygen/list-remove.png:/Icons/oxygen/list-remove.png - - - - 18 - 18 - - - - - - - - Qt::Vertical - - - - 20 - 16 - - - - - - - - - - - - - 421 - 102 - - - - false - - - - - - - - - - - - - Piece size: - - - - - - - 3 - - - - 32 KiB - - - - - 64 KiB - - - - - 128 KiB - - - - - 256 KiB - - - - - 512 KiB - - - - - 1 MiB - - - - - 2 MiB - - - - - 4 MiB - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Private (won't be distributed on DHT network if enabled) - - - - - - - Start seeding after creation - - - - - - - Progress: - - - - - - - 0 - - - - - - - 6 - - - 0 - - - - - Qt::Horizontal - - - - 131 - 31 - - - - - - - - Create and save... - - - - - - - Cancel - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - -