Browse Source

- Fixed torrent creation (closes #402025)

adaptive-webui-19844
Christophe Dumez 16 years ago
parent
commit
c4aa23c86b
  1. 17
      src/createtorrent_imp.cpp
  2. 3
      src/createtorrent_imp.h

17
src/createtorrent_imp.cpp

@ -184,7 +184,6 @@ void createtorrent::on_createButton_clicked(){
void createtorrent::handleCreationFailure(QString msg) { void createtorrent::handleCreationFailure(QString msg) {
QMessageBox::information(0, tr("Torrent creation"), tr("Torrent creation was unsuccessful, reason: %1").arg(msg)); QMessageBox::information(0, tr("Torrent creation"), tr("Torrent creation was unsuccessful, reason: %1").arg(msg));
hide();
} }
void createtorrent::handleCreationSuccess(QString path, const char* branch_path) { void createtorrent::handleCreationSuccess(QString path, const char* branch_path) {
@ -205,7 +204,7 @@ void createtorrent::handleCreationSuccess(QString path, const char* branch_path)
emit torrent_to_seed(path); emit torrent_to_seed(path);
} }
QMessageBox::information(0, tr("Torrent creation"), tr("Torrent was created successfully:")+" "+path); QMessageBox::information(0, tr("Torrent creation"), tr("Torrent was created successfully:")+" "+path);
hide(); close();
} }
void createtorrent::updateProgressBar(int progress) { void createtorrent::updateProgressBar(int progress) {
@ -228,8 +227,12 @@ void torrentCreatorThread::create(QString _input_path, QString _save_path, QStri
start(); start();
} }
void sendProgressUpdateSignal(int i, int num, QDialog *parent){ void sendProgressUpdateSignal(int i, int num, torrentCreatorThread *parent){
((createtorrent*)parent)->updateProgressBar((int)(i*100./(float)num)); parent->sendProgressSignal((int)(i*100./(float)num));
}
void torrentCreatorThread::sendProgressSignal(int progress) {
emit updateProgress(progress);
} }
void torrentCreatorThread::run() { void torrentCreatorThread::run() {
@ -254,15 +257,13 @@ void torrentCreatorThread::run() {
} }
if(abort) return; if(abort) return;
// calculate the hash for all pieces // calculate the hash for all pieces
set_piece_hashes(t, full_path.branch_path(), boost::bind<void>(&sendProgressUpdateSignal, _1, t.num_pieces(), parent)); set_piece_hashes(t, full_path.branch_path(), boost::bind<void>(&sendProgressUpdateSignal, _1, t.num_pieces(), this));
// Set qBittorrent as creator and add user comment to // Set qBittorrent as creator and add user comment to
// torrent_info structure // torrent_info structure
t.set_creator(creator_str); t.set_creator(creator_str);
t.set_comment((const char*)comment.toLocal8Bit()); t.set_comment((const char*)comment.toLocal8Bit());
// Is private ? // Is private ?
if(is_private){ t.set_prive(is_private);
t.set_priv(true);
}
if(abort) return; if(abort) return;
// create the torrent and print it to out // create the torrent and print it to out
ofstream out(complete(path((const char*)save_path.toLocal8Bit())), std::ios_base::binary); ofstream out(complete(path((const char*)save_path.toLocal8Bit())), std::ios_base::binary);

3
src/createtorrent_imp.h

@ -57,6 +57,7 @@ class torrentCreatorThread : public QThread {
wait(); wait();
} }
void create(QString _input_path, QString _save_path, QStringList _trackers, QStringList _url_seeds, QString _comment, bool _is_private, int _piece_size); 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);
protected: protected:
void run(); void run();
@ -64,6 +65,8 @@ class torrentCreatorThread : public QThread {
signals: signals:
void creationFailure(QString msg); void creationFailure(QString msg);
void creationSuccess(QString path, const char* branch_path); void creationSuccess(QString path, const char* branch_path);
signals:
void updateProgress(int progress); void updateProgress(int progress);
}; };

Loading…
Cancel
Save