diff --git a/Changelog b/Changelog index 394e3d201..5057f2576 100644 --- a/Changelog +++ b/Changelog @@ -14,6 +14,8 @@ - FEATURE: Individual share ratio is now displayed in each torrent properties. - FEATURE: Tuned default settings to improve download speed - FEATURE: Downloading from an URL will retry 10 times if too many users. + - FEATURE: Now remembers filtered pieces in a torrent on restart + - FEATURE: Now updating pieces progress in real time in torrent properties - I18N: Added Norwegian translation - BUGFIX: Fixed a memory leak when pressing OK in torrent properties - BUGFIX: Improved code so that GUI never freeze during downloading from an url @@ -30,7 +32,8 @@ - BUGFIX: Fixed Isohunt search engine - BUGFIX: Fixed download from URL function (was buggy) - BUGFIX: Fixed download button in search engine - - BUGFIX: Switched to full allocation mode to fix selective download + - BUGFIX: Fixed selective download + - BUGFIX: Fixed memory leaks in torrent properties - COSMETIC: Now displaying the number of downloads in tab title - COSMETIC: Redesigned download from url dialog - COSMETIC: Added a message to warn user that we started download from an url diff --git a/TODO b/TODO index 35b93693d..32647a07e 100644 --- a/TODO +++ b/TODO @@ -34,9 +34,6 @@ // Before 0.7.0 - Test tracker authentication - Wait for libtorrent v0.11rc release -- Fix this when deletingSelection sometimes: - terminate called after throwing an instance of 'libtorrent::invalid_handle' - what(): invalid torrent handle used - Abandon +- Fix selective download diff --git a/src/GUI.cpp b/src/GUI.cpp index 53569da2c..41bf02aae 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -719,6 +719,56 @@ void GUI::saveWindowSize() const{ } } +bool GUI::loadFilteredPieces(torrent_handle &h){ + bool has_filtered_pieces = false; + torrent_info torrentInfo = h.get_torrent_info(); + QString fileName = QString(torrentInfo.name().c_str()); + QFile pieces_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileName+".pieces"); + // Read saved file + if(!pieces_file.open(QIODevice::ReadOnly | QIODevice::Text)){ + return has_filtered_pieces; + } + QByteArray pieces_selection = pieces_file.readAll(); + pieces_file.close(); + QList pieces_selection_list = pieces_selection.split('\n'); + if(pieces_selection_list.size() != torrentInfo.num_files()+1){ + std::cout << "Error: Corrupted pieces file\n"; + return has_filtered_pieces; + } + for(int i=0; i 1){ + isFiltered = 0; + } + h.filter_piece(i, pieces_selection_list.at(i).toInt()); + if(isFiltered){ + has_filtered_pieces = true; + } + } + return has_filtered_pieces; +} + +bool GUI::hasFilteredPieces(const QString& fileName){ + QFile pieces_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileName+".pieces"); + // Read saved file + if(!pieces_file.open(QIODevice::ReadOnly | QIODevice::Text)){ + return false; + } + QByteArray pieces_selection = pieces_file.readAll(); + pieces_file.close(); + QList pieces_selection_list = pieces_selection.split('\n'); + for(int i=0; i 1){ + isFiltered = 0; + } + if(isFiltered){ + return true; + } + } + return false; +} + void GUI::loadWindowSize(){ qDebug("Loading window size"); QFile lastWindowSize(misc::qBittorrentPath()+"lastWindowSize.txt"); @@ -1075,6 +1125,8 @@ void GUI::saveFastResumeData() const{ bencode(std::ostream_iterator(out), resumeData); } } + // Remove torrent + s->remove_torrent(h); } qDebug("Fast resume data saved"); } @@ -1111,7 +1163,7 @@ void GUI::deleteAll(){ torrents = torrentBackup.entryList(); QString torrent; foreach(torrent, torrents){ - if(torrent.endsWith(".fastresume") || torrent.endsWith(".torrent") || torrent.endsWith(".paused") || torrent.endsWith(".incremental")){ + if(torrent.endsWith(".fastresume") || torrent.endsWith(".torrent") || torrent.endsWith(".pieces") || torrent.endsWith(".paused") || torrent.endsWith(".incremental")){ torrentBackup.remove(torrent); } } @@ -1175,6 +1227,7 @@ void GUI::deleteSelection(){ torrentBackup.remove(fileName+".fastresume"); torrentBackup.remove(fileName+".paused"); torrentBackup.remove(fileName+".incremental"); + torrentBackup.remove(fileName+".pieces"); // Update info bar setInfoBar("'" + fileName +"' "+tr("removed.", " removed.")); --nbTorrents; @@ -1276,9 +1329,17 @@ void GUI::addTorrents(const QStringList& pathsList, bool fromScanDir, const QStr } int row = DLListModel->rowCount(); // Adding files to bittorrent session - h = s->add_torrent(t, fs::path(saveDir.path().toStdString()), resume_data, false); + if(hasFilteredPieces(QString(t.name().c_str()))){ + h = s->add_torrent(t, fs::path(saveDir.path().toStdString()), resume_data, false); + qDebug("Full allocation mode"); + }else{ + h = s->add_torrent(t, fs::path(saveDir.path().toStdString()), resume_data, true); + qDebug("Compact allocation mode"); + } h.set_max_connections(60); h.set_max_uploads(-1); + // Load filtered pieces + loadFilteredPieces(h); //qDebug("Added to session"); torrent_status torrentStatus = h.status(); DLListModel->setData(DLListModel->index(row, PROGRESS), QVariant((double)torrentStatus.progress)); @@ -1378,6 +1439,88 @@ void GUI::addTorrents(const QStringList& pathsList, bool fromScanDir, const QStr } } +void GUI::reloadTorrent(const torrent_handle &h, bool compact_mode){ + QDir saveDir(options->getSavePath()), torrentBackup(misc::qBittorrentPath() + "BT_backup"); + QString fileName = QString(h.get_torrent_info().name().c_str()); + qDebug("Reloading torrent: %s", fileName.toStdString().c_str()); + torrent_handle new_h; + entry resumeData; + torrent_info t = h.get_torrent_info(); + // Checking if torrentBackup Dir exists + // create it if it is not + if(! torrentBackup.exists()){ + torrentBackup.mkpath(torrentBackup.path()); + } + // Write fast resume data + // Pause download (needed before fast resume writing) + h.pause(); + // Extracting resume data + if (h.has_metadata()){ + // get fast resume data + resumeData = h.write_resume_data(); + } + int row = -1; + // Delete item from download list + for(int i=0; irowCount(); ++i){ + if(DLListModel->data(DLListModel->index(i, NAME)).toString()==fileName){ + row = i; + break; + } + } + Q_ASSERT(row != -1); + DLListModel->removeRow(row); + // Remove torrent + s->remove_torrent(h); + handles.remove(fileName); + // Add torrent again to session + unsigned short timeout = 0; + while(h.is_valid() && timeout < 6){ + SleeperThread::msleep(1000); + ++timeout; + } + if(h.is_valid()){ + std::cout << "Error: Couldn't reload the torrent\n"; + return; + } + new_h = s->add_torrent(t, fs::path(saveDir.path().toStdString()), resumeData, compact_mode); + if(compact_mode){ + qDebug("Using compact allocation mode"); + }else{ + qDebug("Using full allocation mode"); + } + handles.insert(QString(t.name().c_str()), new_h); + new_h.set_max_connections(60); + new_h.set_max_uploads(-1); + // Load filtered pieces + loadFilteredPieces(new_h); + // Adding torrent to download list + DLListModel->insertRow(row); + DLListModel->setData(DLListModel->index(row, NAME), QVariant(t.name().c_str())); + DLListModel->setData(DLListModel->index(row, SIZE), QVariant((qlonglong)t.total_size())); + DLListModel->setData(DLListModel->index(row, DLSPEED), QVariant((double)0.)); + DLListModel->setData(DLListModel->index(row, UPSPEED), QVariant((double)0.)); + DLListModel->setData(DLListModel->index(row, ETA), QVariant((qlonglong)-1)); + // Pause torrent if it was paused last time + if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+QString(t.name().c_str())+".paused")){ + DLListModel->setData(DLListModel->index(row, STATUS), QVariant(tr("Paused"))); + DLListModel->setData(DLListModel->index(row, NAME), QVariant(QIcon(":/Icons/skin/paused.png")), Qt::DecorationRole); + setRowColor(row, "red"); + }else{ + DLListModel->setData(DLListModel->index(row, STATUS), QVariant(tr("Connecting..."))); + DLListModel->setData(DLListModel->index(row, NAME), QVariant(QIcon(":/Icons/skin/connecting.png")), Qt::DecorationRole); + setRowColor(row, "grey"); + } + // Pause torrent if it was paused last time + if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileName+".paused")){ + new_h.pause(); + } + // Incremental download + if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileName+".incremental")){ + qDebug("Incremental download enabled for %s", fileName.toStdString().c_str()); + new_h.set_sequenced_download_threshold(15); + } +} + // As program parameters, we can get paths or urls. // This function parse the parameters and call // the right addTorrent function, considering @@ -1409,6 +1552,7 @@ void GUI::showProperties(const QModelIndex &index){ torrent_handle h = handles.value(fileName); QStringList errors = trackerErrors.value(fileName, QStringList(tr("None"))); properties *prop = new properties(this, h, errors); + connect(prop, SIGNAL(changedFilteredPieces(torrent_handle, bool)), this, SLOT(reloadTorrent(torrent_handle, bool))); prop->show(); } diff --git a/src/GUI.h b/src/GUI.h index 7388bee07..5b42e022b 100644 --- a/src/GUI.h +++ b/src/GUI.h @@ -153,6 +153,9 @@ class GUI : public QMainWindow, private Ui::MainWindow{ void addUnauthenticatedTracker(QPair tracker); void processDownloadedFile(QString url, QString file_path, int return_code, QString errorBuffer); void downloadFromURLList(const QStringList& url_list); + bool loadFilteredPieces(torrent_handle &h); + bool hasFilteredPieces(const QString& fileName); + void reloadTorrent(const torrent_handle &h, bool compact_mode = true); // Search slots void on_search_button_clicked(); void on_stop_search_button_clicked(); diff --git a/src/downloadThread.h b/src/downloadThread.h index 1faf8effd..f1c371ba2 100644 --- a/src/downloadThread.h +++ b/src/downloadThread.h @@ -119,7 +119,7 @@ class downloadThread : public QThread { QFile::remove(filePath.c_str()); return; } - int retries = 0; + unsigned short retries = 0; bool to_many_users = false; do{ // Perform Download diff --git a/src/lang/qbittorrent_de.qm b/src/lang/qbittorrent_de.qm index ba5ef0dd9..fa19d0144 100644 Binary files a/src/lang/qbittorrent_de.qm and b/src/lang/qbittorrent_de.qm differ diff --git a/src/lang/qbittorrent_de.ts b/src/lang/qbittorrent_de.ts index d6db49284..e41677d2e 100644 --- a/src/lang/qbittorrent_de.ts +++ b/src/lang/qbittorrent_de.ts @@ -99,19 +99,19 @@ Copyright (c) 2006 Christophe Dumez<br> Birthday: - + Geburtstag: Occupation: - + Beschäftigung: 03/05/1985 - 03/05/1985 + 03.05.1985 Student in computer science - + Informatikstudent @@ -361,23 +361,23 @@ Copyright (c) 2006 Christophe Dumez<br> DHT (Trackerless): - + DHT (Trackerlos): Disable DHT (Trackerless) support - + Deaktiviere DHT (Trackerlos) Unterstützung Automatically clear finished downloads - + Abgeschlossene Downloads automatisch beseitigen Preview program - + Vorschau Programm Audio/Video player: - + Audio/Video Player: @@ -759,35 +759,36 @@ Changelog: Preview process already running - + Preview Prozess läuft bereits There is already another preview process running. Please close the other one first. - + Ein anderer Preview Prozess läuft zu Zeit. +Bitte schliessen Sie diesen zuerst. Couldn't download Couldn't download <file> - + Konnte Datei nicht downloaden reason: Reason why the download failed - + Grund: Downloading Example: Downloading www.example.com/test.torrent - Lade + Lade Please wait... - + Bitte warten... Transfers - + Transfer @@ -982,15 +983,15 @@ Please close the other one first. Transfers - + Transfer Preview file - + Vorschau Datei Clear log - + Log löschen @@ -1043,62 +1044,62 @@ Please close the other one first. Preview impossible - + Vorschau unmöglich Sorry, we can't preview this file - + Bedauere, wir können keine Vorschau für diese Datei erstellen Name - Name + Name Size - Grösse + Grösse Progress - Fortschritt + Fortschritt No URL entered - + Keine URL eingegeben Please type at least one URL. - + Bitte geben Sie mindestens eine URL an. authentication Tracker authentication - + Tracker Authentifizierung Tracker: - + Tracker: Login - + Login Username: - + Benutzername: Password: - Kennwort: + Kennwort: Log in - + Einloggen Cancel - Abbrechen + Abbrechen @@ -1211,23 +1212,23 @@ Please close the other one first. downloadFromURL Download Torrents from URLs - + Torrents von URLs laden Only one URL per line - + Nur eine URL pro Zeile Download - + Lade Cancel - Abbrechen + Abbrechen Download from urls - + Von URLs laden @@ -1373,30 +1374,30 @@ Please close the other one first. Choose your favourite preview program - + Wählen Sie ihr bevorzugtes Vorschau Programm preview Preview selection - + Vorschau auswahl File preview - + Datei vorschauen The following files support previewing, <br>please select one of them: - + Die folgenden Dateien unterstützen Vorschau, <br>bitte wählen Sie eine: Preview - + Vorschau Cancel - Abbrechen + Abbrechen @@ -1615,15 +1616,15 @@ Please close the other one first. Options - Optionen + Optionen Download in correct order (slower but good for previewing) - + In richtiger Reihenfolge herunterladen (langsamer, aber besser zum Vorschauen) Share Ratio: - + Share Verhältnis: diff --git a/src/lang/qbittorrent_it.qm b/src/lang/qbittorrent_it.qm index 1044ff9af..9acf1c592 100644 Binary files a/src/lang/qbittorrent_it.qm and b/src/lang/qbittorrent_it.qm differ diff --git a/src/lang/qbittorrent_it.ts b/src/lang/qbittorrent_it.ts index 449b38b67..b3dfd1afb 100644 --- a/src/lang/qbittorrent_it.ts +++ b/src/lang/qbittorrent_it.ts @@ -66,26 +66,18 @@ <br> Copyright © 2006 by Christophe Dumez<br> <br> <u>Home Page:</u> <i>http://www.qbittorrent.org</i><br> - Un client bittorrent in Qt4 e libtorrent. Scritto in c++.<br><br>Copyright © 2006 di Christophe Dumez<br> -<br> <u>Home Page:</u> <i>http://www.qbittorrent.org</i><br> - - - A bittorrent client using Qt4 and libtorrent, programmed in C++.<br> -<br> -Copyright © 2006 by Christophe Dumez<br> -<br> <u>Home Page:</u> <i>http://www.qbittorrent.org</i><br> - Un client bittorrent in Qt4 e libtorrent. Scritto in C++.<br> + Un client bittorrent in Qt4 e libtorrent. Scritto in C++.<br> <br> Copyright © 2006 di Christophe Dumez<br> <br> <u>Home Page:</u> <i>http://www.qbittorrent.org</i><br> Birthday: - + Compleanno: Occupation: - + Occupazione: 03/05/1985 @@ -93,6 +85,13 @@ Copyright © 2006 di Christophe Dumez<br> Student in computer science + Studente di informatica + + + A bittorrent client using Qt4 and libtorrent, programmed in C++.<br> +<br> +Copyright © 2006 by Christophe Dumez<br> +<br> <u>Home Page:</u> <i>http://www.qbittorrent.org</i><br> @@ -141,10 +140,6 @@ Copyright © 2006 di Christophe Dumez<br> ... ... - - Kb/s - Kb/s - Disable Disabilitare @@ -217,14 +212,6 @@ Copyright © 2006 di Christophe Dumez<br> Share ratio: Percentuale di condivisione: - - 1 KB DL = - 1 KB DL = - - - KB UP max. - KB UP max. - Activate IP Filtering Attivare filtraggio IP @@ -289,10 +276,6 @@ Copyright © 2006 di Christophe Dumez<br> Ask for confirmation on exit Chiedi conferma ed esci - - Clear finished downloads on exit - Cancella i download finiti all'uscita - Go to systray when minimizing window Riduci alla systray quando si minimizza la finestra @@ -327,23 +310,23 @@ Copyright © 2006 di Christophe Dumez<br> DHT (Trackerless): - + DHT (senza tracker): Disable DHT (Trackerless) support - + Disabilita il supporto DHT Automatically clear finished downloads - + Cancella automaticamente i download terminati Preview program - + Programma di anteprima Audio/Video player: - + Player audio/video: @@ -352,10 +335,6 @@ Copyright © 2006 di Christophe Dumez<br> Open Torrent Files Apri file torrent - - Unknown - Sconosciuto - This file is either corrupted or this isn't a torrent. Questo file è corrotto o non è un torrent @@ -376,14 +355,6 @@ Copyright © 2006 di Christophe Dumez<br> Are you sure you want to delete the selected item(s) in download list? Sei sicuro di voler cancellare gli elementi selezionati dalla lista dei download? - - paused - In pausa - - - started - Iniziato - Finished Finito @@ -412,10 +383,6 @@ Copyright © 2006 di Christophe Dumez<br> All Downloads Resumed. Tutti i download ripresi. - - DL Speed: - Velocità Download: - started. Iniziato. @@ -472,10 +439,6 @@ Copyright © 2006 di Christophe Dumez<br> qBittorrent qBittorrent - - qBittorrent - qBittorrent - Are you sure? -- qBittorrent Sei sicuro? -- qBittorrent @@ -528,22 +491,6 @@ Copyright © 2006 di Christophe Dumez<br> Searching... Ricerca... - - Could not create search plugin. - Impossibile creare il plugin di ricerca - - - Stopped - Fermato - - - Torrent file URL - URL del file Torrent - - - Torrent file URL: - URL del file Torrent - Are you sure you want to quit? -- qBittorrent Sicuro di voler uscire? -- qBittorrent @@ -552,26 +499,10 @@ Copyright © 2006 di Christophe Dumez<br> Are you sure you want to quit qbittorrent? Sicuro di voler uscire da qBittorrent? - - Timed out - Time out - - - Error during search... - Errore nella ricerca... - KiB/s Kb/s - - KiB/s - Kb/s - - - Stalled - In stallo - Search is finished Ricerca completata @@ -588,10 +519,6 @@ Copyright © 2006 di Christophe Dumez<br> Search returned no results La ricerca non ha prodotto risultati - - Search is Finished - Ricerca finita - Search plugin update -- qBittorrent Aggiornamento del plugin di ricerca -- qBittorrent @@ -668,36 +595,42 @@ Changelog: Preview process already running - + Processo di anteprima già in esecuzione There is already another preview process running. Please close the other one first. - + C'è già un altro processo di anteprima avviato. Per favore chiuderlo. Couldn't download Couldn't download <file> - + Impossibile scaricare reason: Reason why the download failed - + motivo: + + + Downloading + +Example: Downloading www.example.com/test.torrent + Scaricando + + + Please wait... + Attendere prego... + + + Transfers + Trasferimenti Downloading Example: Downloading www.example.com/test.torrent Scaricando - - Please wait... - - - - Transfers - - MainWindow @@ -713,34 +646,6 @@ Please close the other one first. Total UP Speed: Velocità totale upload: - - Name - Nome - - - Size - Dimensione - - - % DL - % scaricato - - - DL Speed - Velocità download - - - UP Speed - velocità upload - - - Status - Status - - - ETA - ETA - &Options &Opzioni @@ -809,10 +714,6 @@ Please close the other one first. Connection Status Status connessione - - Downloads - Downloads - Search Ricerca @@ -841,18 +742,6 @@ Please close the other one first. Stop Stop - - Seeds - Seeds - - - Leechers - Leechers - - - Search Engine - Motore di ricerca - Download from URL Download da URL @@ -873,10 +762,6 @@ Please close the other one first. Create torrent Crea torrent - - Ratio: - Percentuale: - Update search plugin Aggiorna plugin di ricerca @@ -887,15 +772,15 @@ Please close the other one first. Transfers - + Trasferimenti Preview file - + Anteprima file Clear log - + Cancella log @@ -909,13 +794,6 @@ Please close the other one first. Vero - - QTextEdit - - Clear - Pulisci - - Ui @@ -930,21 +808,13 @@ Please close the other one first. I would like to thank the following people who volunteered to translate qBittorrent: Vorrei ringraziare le seguenti persone che si sono rese volontarie per tradurre qBittorrent: - - <ul><li>I would like to thank sourceforge.net for hosting qBittorrent project.</li> - <ul><li>Voglio inoltre ringraziare Sourceforge.Net per ospitare i files relativi al progetto.</li> - - - <li>I also like to thank Jeffery Fernandez (developer@jefferyfernandez.id.au), our RPM packager, for his great work.</li></ul> - <li>Voglio anche ringraziare Jeffery Fernandez (developer@jefferyfernandez.id.au), il nostro creatore di RPM, per il suo grande lavoro.</li></ul> - Preview impossible - + Anteprima impossibile Sorry, we can't preview this file - + Spiacenti, non è possibile fare un'anteprima di questo file Name @@ -960,30 +830,30 @@ Please close the other one first. No URL entered - + Nessuna URL inserita Please type at least one URL. - + Per favore inserire almeno un URL. authentication Tracker authentication - + Autenticazione del tracker Tracker: - + Tracker: Login - + Login Username: - + Nome utente: Password: @@ -991,11 +861,11 @@ Please close the other one first. Log in - + Log in Cancel - + Annulla @@ -1008,22 +878,6 @@ Please close the other one first. Create Torrent file Crea file torrent - - Destination torrent file: - Torrent file di destinazione: - - - Input file or directory: - File o directory di input: - - - Announce url (Tracker): - URL del tracker: - - - Comment: - Commento: - ... ... @@ -1108,11 +962,11 @@ Please close the other one first. downloadFromURL Download Torrents from URLs - + Scarica torrent da URL Only one URL per line - + Solo un URL per linea Download @@ -1120,11 +974,11 @@ Please close the other one first. Cancel - + Annulla Download from urls - + Download da URL @@ -1154,12 +1008,6 @@ Please close the other one first. tebibytes (1024 gibibytes) Tb - - m - -minutes - m - h hours @@ -1170,12 +1018,6 @@ minutes days gg - - h - -hours - h - Unknown Sconosciuto @@ -1277,30 +1119,30 @@ hours Choose your favourite preview program - + Scegliere il programma d'anteprima preferito preview Preview selection - + Anteprima della selezione File preview - + Anteprima del file The following files support previewing, <br>please select one of them: - + I seguenti files supportano l'anteprima, <br>per favore scegliere uno d'essi: Preview - + Anteprima Cancel - + Annulla @@ -1309,10 +1151,6 @@ hours Torrent Properties Proprietà del torrent - - Main Infos - Informazioni principali - File Name Nome del file @@ -1321,38 +1159,14 @@ hours Current Session Sessione corrente - - Total Uploaded: - Totale Upload: - - - Total Downloaded: - Totale Download: - Download state: Stato download: - - Current Tracker: - Tracker corrente: - - - Number of Peers: - Numero di peer: - - - Torrent Content - Contenuto del torrent - OK OK - - Total Failed: - Totale fallito: - Finished Finito @@ -1421,14 +1235,6 @@ hours You can select here precisely which files you want to download in current torrent. Qua puoi scegliere quali file del torrent scaricare. - - False - Falso - - - True - Vero - Tracker Tracker @@ -1483,11 +1289,11 @@ hours Download in correct order (slower but good for previewing) - + Scarica nel giusto ordine (più lento ma migliore per le anteprime) Share Ratio: - + Percentuale di condivisione: diff --git a/src/properties_imp.cpp b/src/properties_imp.cpp index 1a47b04e2..8d085ac82 100644 --- a/src/properties_imp.cpp +++ b/src/properties_imp.cpp @@ -24,14 +24,13 @@ #include "PropListDelegate.h" // Constructor -properties::properties(QWidget *parent, torrent_handle h, QStringList trackerErrors): QDialog(parent){ +properties::properties(QWidget *parent, torrent_handle h, QStringList trackerErrors): QDialog(parent), h(h){ setupUi(this); // set icons unselect->setIcon(QIcon(QString::fromUtf8(":/Icons/button_cancel.png"))); select->setIcon(QIcon(QString::fromUtf8(":/Icons/button_ok.png"))); setAttribute(Qt::WA_DeleteOnClose); - this->h = h; // Set Properties list model PropListModel = new QStandardItemModel(0,4); PropListModel->setHeaderData(NAME, Qt::Horizontal, tr("File Name")); @@ -145,6 +144,30 @@ properties::properties(QWidget *parent, torrent_handle h, QStringList trackerErr }else{ incrementalDownload->setChecked(false); } + updateProgressTimer = new QTimer(this); + connect(updateProgressTimer, SIGNAL(timeout()), this, SLOT(updateProgress())); + updateProgressTimer->start(2000); + std::vector filters = h.filtered_pieces(); +// std::cout << "filtered pieces: "; +// for(int i=0; i fp; + h.file_progress(fp); + torrent_info torrentInfo = h.get_torrent_info(); + for(int i=0; isetData(PropListModel->index(i, PROGRESS), QVariant((double)fp[i])); + } } // Set the color of a row in data model @@ -171,6 +194,8 @@ void properties::toggleSelectedState(const QModelIndex& index){ setRowColor(row, "red"); PropListModel->setData(PropListModel->index(row, SELECTED), QVariant(false)); } + // Save filtered pieces to a file to remember them + saveFilteredPieces(); } void properties::on_incrementalDownload_stateChanged(int){ @@ -204,6 +229,8 @@ void properties::on_select_clicked(){ } } } + // Save filtered pieces to a file to remember them + saveFilteredPieces(); } void properties::on_okButton_clicked(){ @@ -226,4 +253,30 @@ void properties::on_unselect_clicked(){ } } } + // Save filtered pieces to a file to remember them + saveFilteredPieces(); +} + +void properties::saveFilteredPieces(){ + torrent_info torrentInfo = h.get_torrent_info(); + bool hasFilteredPieces = false; + QString fileName = QString(torrentInfo.name().c_str()); + QFile pieces_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileName+".pieces"); + // First, remove old file + pieces_file.remove(); + // Write new files + if(!pieces_file.open(QIODevice::WriteOnly | QIODevice::Text)){ + std::cout << "Error: Could not save filtered pieces\n"; + return; + } + for(int i=0; i #include +#include class PropListDelegate; @@ -36,6 +37,7 @@ class properties : public QDialog, private Ui::properties{ torrent_handle h; PropListDelegate *PropDelegate; QStandardItemModel *PropListModel; + QTimer *updateProgressTimer; protected slots: void on_select_clicked(); @@ -44,10 +46,16 @@ class properties : public QDialog, private Ui::properties{ void on_incrementalDownload_stateChanged(int); void setRowColor(int row, QString color); void toggleSelectedState(const QModelIndex& index); + void saveFilteredPieces(); + void updateProgress(); + + signals: + void changedFilteredPieces(torrent_handle h, bool compact_mode); public: // Constructor - properties(QWidget *parent = 0, torrent_handle h = torrent_handle(), QStringList trackerErrors = QStringList()); + properties(QWidget *parent, torrent_handle h, QStringList trackerErrors = QStringList()); + ~properties(); }; #endif