Browse Source

Big code clean up

adaptive-webui-19844
Christophe Dumez 14 years ago
parent
commit
290932e128
  1. 2
      src/GUI.cpp
  2. 4
      src/GUI.h
  3. 4
      src/console_imp.h
  4. 4
      src/headlessloader.h
  5. 4
      src/misc.h
  6. 4
      src/propertieswidget.cpp
  7. 8
      src/propertieswidget.h
  8. 643
      src/qtlibtorrent/qbtsession.cpp
  9. 11
      src/qtlibtorrent/qbtsession.h
  10. 2
      src/rss/feeddownloader.cpp
  11. 4
      src/rss/feeddownloader.h
  12. 2
      src/rss/rss_imp.cpp
  13. 6
      src/rss/rss_imp.h
  14. 2
      src/rss/rssfeed.cpp
  15. 6
      src/rss/rssfeed.h
  16. 2
      src/rss/rssfolder.cpp
  17. 6
      src/rss/rssfolder.h
  18. 2
      src/rss/rssmanager.cpp
  19. 4
      src/rss/rssmanager.h
  20. 2
      src/searchengine.cpp
  21. 6
      src/searchengine.h
  22. 4
      src/statusbar.h
  23. 2
      src/torrentadditiondlg.cpp
  24. 4
      src/torrentadditiondlg.h
  25. 220
      src/torrentpersistentdata.h
  26. 2
      src/transferlistwidget.cpp
  27. 6
      src/transferlistwidget.h
  28. 2
      src/webui/eventmanager.cpp
  29. 6
      src/webui/eventmanager.h
  30. 2
      src/webui/httpconnection.cpp
  31. 6
      src/webui/httpconnection.h
  32. 2
      src/webui/httpserver.cpp
  33. 6
      src/webui/httpserver.h

2
src/GUI.cpp

@ -126,7 +126,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), for
// Fix Tool bar layout // Fix Tool bar layout
toolBar->layout()->setSpacing(7); toolBar->layout()->setSpacing(7);
// Creating Bittorrent session // Creating Bittorrent session
BTSession = new Bittorrent(); BTSession = new QBtSession();
connect(BTSession, SIGNAL(fullDiskError(QTorrentHandle&, QString)), this, SLOT(fullDiskError(QTorrentHandle&, QString))); connect(BTSession, SIGNAL(fullDiskError(QTorrentHandle&, QString)), this, SLOT(fullDiskError(QTorrentHandle&, QString)));
connect(BTSession, SIGNAL(finishedTorrent(QTorrentHandle&)), this, SLOT(finishedTorrent(QTorrentHandle&))); connect(BTSession, SIGNAL(finishedTorrent(QTorrentHandle&)), this, SLOT(finishedTorrent(QTorrentHandle&)));
connect(BTSession, SIGNAL(trackerAuthenticationRequired(QTorrentHandle&)), this, SLOT(trackerAuthenticationRequired(QTorrentHandle&))); connect(BTSession, SIGNAL(trackerAuthenticationRequired(QTorrentHandle&)), this, SLOT(trackerAuthenticationRequired(QTorrentHandle&)));

4
src/GUI.h

@ -37,7 +37,7 @@
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
#include "qtorrenthandle.h" #include "qtorrenthandle.h"
class Bittorrent; class QBtSession;
class QTimer; class QTimer;
class downloadFromURL; class downloadFromURL;
class SearchEngine; class SearchEngine;
@ -140,7 +140,7 @@ protected:
private: private:
QFileSystemWatcher *executable_watcher; QFileSystemWatcher *executable_watcher;
// Bittorrent // Bittorrent
Bittorrent *BTSession; QBtSession *BTSession;
QList<QPair<QTorrentHandle,QString> > unauthenticated_trackers; // Still needed? QList<QPair<QTorrentHandle,QString> > unauthenticated_trackers; // Still needed?
// GUI related // GUI related
QTimer *guiUpdater; QTimer *guiUpdater;

4
src/console_imp.h

@ -40,10 +40,10 @@ class consoleDlg : public QDialog, private Ui_ConsoleDlg{
Q_OBJECT Q_OBJECT
private: private:
Bittorrent *BTSession; QBtSession *BTSession;
public: public:
consoleDlg(QWidget *parent, Bittorrent* _BTSession) : QDialog(parent) { consoleDlg(QWidget *parent, QBtSession* _BTSession) : QDialog(parent) {
setupUi(this); setupUi(this);
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
setModal(true); setModal(true);

4
src/headlessloader.h

@ -44,7 +44,7 @@ public:
// Enable Web UI // Enable Web UI
Preferences::setWebUiEnabled(true); Preferences::setWebUiEnabled(true);
// Instanciate Bittorrent Object // Instanciate Bittorrent Object
BTSession = new Bittorrent(); BTSession = new QBtSession();
connect(BTSession, SIGNAL(newConsoleMessage(QString)), this, SLOT(displayConsoleMessage(QString))); connect(BTSession, SIGNAL(newConsoleMessage(QString)), this, SLOT(displayConsoleMessage(QString)));
// Resume unfinished torrents // Resume unfinished torrents
BTSession->startUpTorrents(); BTSession->startUpTorrents();
@ -103,7 +103,7 @@ public slots:
} }
private: private:
Bittorrent *BTSession; QBtSession *BTSession;
}; };

4
src/misc.h

@ -76,6 +76,10 @@ public:
return QString(o.str().c_str()); return QString(o.str().c_str());
} }
static inline sha1_hash toSha1Hash(QString hash) {
return sha1_hash(qPrintable(hash));
}
static void chmod644(const QDir& folder); static void chmod644(const QDir& folder);
static inline QString removeLastPathPart(QString path) { static inline QString removeLastPathPart(QString path) {

4
src/propertieswidget.cpp

@ -62,7 +62,7 @@
#define SELECTED_BUTTON_CSS "QPushButton {border: 1px solid rgb(85, 81, 91);border-radius: 3px;padding: 2px;background-color: rgb(255, 208, 105); margin-left: 3px; margin-right: 3px;}" #define SELECTED_BUTTON_CSS "QPushButton {border: 1px solid rgb(85, 81, 91);border-radius: 3px;padding: 2px;background-color: rgb(255, 208, 105); margin-left: 3px; margin-right: 3px;}"
#endif #endif
PropertiesWidget::PropertiesWidget(QWidget *parent, GUI* main_window, TransferListWidget *transferList, Bittorrent* BTSession): PropertiesWidget::PropertiesWidget(QWidget *parent, GUI* main_window, TransferListWidget *transferList, QBtSession* BTSession):
QWidget(parent), transferList(transferList), main_window(main_window), BTSession(BTSession) { QWidget(parent), transferList(transferList), main_window(main_window), BTSession(BTSession) {
setupUi(this); setupUi(this);
state = VISIBLE; state = VISIBLE;
@ -206,7 +206,7 @@ QTorrentHandle PropertiesWidget::getCurrentTorrent() const {
return h; return h;
} }
Bittorrent* PropertiesWidget::getBTSession() const { QBtSession* PropertiesWidget::getBTSession() const {
return BTSession; return BTSession;
} }

8
src/propertieswidget.h

@ -38,7 +38,7 @@
class TransferListWidget; class TransferListWidget;
class QTimer; class QTimer;
class Bittorrent; class QBtSession;
class TorrentFilesModel; class TorrentFilesModel;
class PropListDelegate; class PropListDelegate;
class QAction; class QAction;
@ -60,7 +60,7 @@ private:
GUI *main_window; GUI *main_window;
QTorrentHandle h; QTorrentHandle h;
QTimer *refreshTimer; QTimer *refreshTimer;
Bittorrent* BTSession; QBtSession* BTSession;
SlideState state; SlideState state;
TorrentFilesModel *PropListModel; TorrentFilesModel *PropListModel;
PropListDelegate *PropDelegate; PropListDelegate *PropDelegate;
@ -71,10 +71,10 @@ private:
PieceAvailabilityBar *pieces_availability; PieceAvailabilityBar *pieces_availability;
public: public:
PropertiesWidget(QWidget *parent, GUI* main_window, TransferListWidget *transferList, Bittorrent* BTSession); PropertiesWidget(QWidget *parent, GUI* main_window, TransferListWidget *transferList, QBtSession* BTSession);
~PropertiesWidget(); ~PropertiesWidget();
QTorrentHandle getCurrentTorrent() const; QTorrentHandle getCurrentTorrent() const;
Bittorrent* getBTSession() const; QBtSession* getBTSession() const;
TrackerList* getTrackerList() const { return trackerList; } TrackerList* getTrackerList() const { return trackerList; }
PeerListWidget* getPeerList() const { return peersList; } PeerListWidget* getPeerList() const { return peersList; }
QTreeView* getFilesList() const { return filesList; } QTreeView* getFilesList() const { return filesList; }

643
src/qtlibtorrent/qbtsession.cpp

File diff suppressed because it is too large Load Diff

11
src/qtlibtorrent/qbtsession.h

@ -62,13 +62,13 @@ class HttpServer;
class BandwidthScheduler; class BandwidthScheduler;
class ScanFoldersModel; class ScanFoldersModel;
class Bittorrent : public QObject { class QBtSession : public QObject {
Q_OBJECT Q_OBJECT
public: public:
// Constructor / Destructor // Constructor / Destructor
Bittorrent(); QBtSession();
~Bittorrent(); ~QBtSession();
QTorrentHandle getTorrentHandle(QString hash) const; QTorrentHandle getTorrentHandle(QString hash) const;
std::vector<torrent_handle> getTorrents() const; std::vector<torrent_handle> getTorrents() const;
bool isFilePreviewPossible(QString fileHash) const; bool isFilePreviewPossible(QString fileHash) const;
@ -166,6 +166,10 @@ public slots:
protected: protected:
QString getSavePath(QString hash, bool fromScanDir = false, QString filePath = QString::null, QString root_folder=QString::null); QString getSavePath(QString hash, bool fromScanDir = false, QString filePath = QString::null, QString root_folder=QString::null);
bool initWebUi(QString username, QString password, int port); bool initWebUi(QString username, QString password, int port);
bool loadFastResumeData(QString hash, std::vector<char> &buf);
void loadTorrentSettings(QTorrentHandle h);
void loadTorrentTempData(QTorrentHandle h, QString savePath, bool magnet);
add_torrent_params initializeAddTorrentParams(QString hash);
protected slots: protected slots:
void addTorrentsFromScanFolder(QStringList&); void addTorrentsFromScanFolder(QStringList&);
@ -178,6 +182,7 @@ protected slots:
void autoRunExternalProgram(QTorrentHandle h, bool async=true); void autoRunExternalProgram(QTorrentHandle h, bool async=true);
void cleanUpAutoRunProcess(int); void cleanUpAutoRunProcess(int);
void mergeTorrents(QTorrentHandle h_ex, boost::intrusive_ptr<torrent_info> t); void mergeTorrents(QTorrentHandle h_ex, boost::intrusive_ptr<torrent_info> t);
void exportTorrentFile(QTorrentHandle h);
signals: signals:
void addedTorrent(QTorrentHandle& h); void addedTorrent(QTorrentHandle& h);

2
src/rss/feeddownloader.cpp

@ -30,7 +30,7 @@
#include "feeddownloader.h" #include "feeddownloader.h"
FeedDownloaderDlg::FeedDownloaderDlg(QWidget *parent, QString feed_url, QString feed_name, Bittorrent* BTSession): FeedDownloaderDlg::FeedDownloaderDlg(QWidget *parent, QString feed_url, QString feed_name, QBtSession* BTSession):
QDialog(parent), feed_url(feed_url), feed_name(feed_name), BTSession(BTSession), selected_filter(QString::null) QDialog(parent), feed_url(feed_url), feed_name(feed_name), BTSession(BTSession), selected_filter(QString::null)
{ {
setupUi(this); setupUi(this);

4
src/rss/feeddownloader.h

@ -52,7 +52,7 @@ class FeedDownloaderDlg : public QDialog, private Ui_FeedDownloader{
Q_OBJECT Q_OBJECT
public: public:
FeedDownloaderDlg(QWidget *parent, QString feed_url, QString feed_name, Bittorrent* BTSession); FeedDownloaderDlg(QWidget *parent, QString feed_url, QString feed_name, QBtSession* BTSession);
~FeedDownloaderDlg(); ~FeedDownloaderDlg();
protected slots: protected slots:
@ -78,7 +78,7 @@ private:
QString feed_url; QString feed_url;
QString feed_name; QString feed_name;
RssFilters filters; RssFilters filters;
Bittorrent *BTSession; QBtSession *BTSession;
QString selected_filter; // name QString selected_filter; // name
}; };

2
src/rss/rss_imp.cpp

@ -585,7 +585,7 @@ void RSSImp::updateRefreshInterval(unsigned int val) {
rssmanager->updateRefreshInterval(val); rssmanager->updateRefreshInterval(val);
} }
RSSImp::RSSImp(Bittorrent *BTSession) : QWidget(), BTSession(BTSession){ RSSImp::RSSImp(QBtSession *BTSession) : QWidget(), BTSession(BTSession){
setupUi(this); setupUi(this);
rssmanager = new RssManager(BTSession); rssmanager = new RssManager(BTSession);

6
src/rss/rss_imp.h

@ -36,7 +36,7 @@
#include "ui_rss.h" #include "ui_rss.h"
class Bittorrent; class QBtSession;
class FeedListWidget; class FeedListWidget;
class QTreeWidgetItem; class QTreeWidgetItem;
class RssFolder; class RssFolder;
@ -46,7 +46,7 @@ class RSSImp : public QWidget, public Ui::RSS{
Q_OBJECT Q_OBJECT
public: public:
RSSImp(Bittorrent *BTSession); RSSImp(QBtSession *BTSession);
~RSSImp(); ~RSSImp();
public slots: public slots:
@ -83,7 +83,7 @@ protected slots:
private: private:
RssManager *rssmanager; RssManager *rssmanager;
Bittorrent *BTSession; QBtSession *BTSession;
FeedListWidget *listStreams; FeedListWidget *listStreams;
QTreeWidgetItem* previous_news; QTreeWidgetItem* previous_news;

2
src/rss/rssfeed.cpp

@ -36,7 +36,7 @@
#include "rssarticle.h" #include "rssarticle.h"
#include "feeddownloader.h" #include "feeddownloader.h"
RssFeed::RssFeed(RssFolder* parent, RssManager *rssmanager, Bittorrent *BTSession, QString _url): parent(parent), rssmanager(rssmanager), BTSession(BTSession), alias(""), iconPath(":/Icons/rss16.png"), refreshed(false), downloadFailure(false), currently_loading(false) { RssFeed::RssFeed(RssFolder* parent, RssManager *rssmanager, QBtSession *BTSession, QString _url): parent(parent), rssmanager(rssmanager), BTSession(BTSession), alias(""), iconPath(":/Icons/rss16.png"), refreshed(false), downloadFailure(false), currently_loading(false) {
qDebug("RSSStream constructed"); qDebug("RSSStream constructed");
QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss"); QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss");
url = QUrl(_url).toString(); url = QUrl(_url).toString();

6
src/rss/rssfeed.h

@ -36,7 +36,7 @@
#include "rssfile.h" #include "rssfile.h"
class RssManager; class RssManager;
class Bittorrent; class QBtSession;
class RssFeed: public RssFile, public QHash<QString, RssArticle*> { class RssFeed: public RssFile, public QHash<QString, RssArticle*> {
Q_OBJECT Q_OBJECT
@ -44,7 +44,7 @@ class RssFeed: public RssFile, public QHash<QString, RssArticle*> {
private: private:
RssFolder *parent; RssFolder *parent;
RssManager *rssmanager; RssManager *rssmanager;
Bittorrent *BTSession; QBtSession *BTSession;
QString title; QString title;
QString link; QString link;
QString description; QString description;
@ -63,7 +63,7 @@ public slots:
void setDownloadFailed(); void setDownloadFailed();
public: public:
RssFeed(RssFolder* parent, RssManager *rssmanager, Bittorrent *BTSession, QString _url); RssFeed(RssFolder* parent, RssManager *rssmanager, QBtSession *BTSession, QString _url);
~RssFeed(); ~RssFeed();
RssFolder* getParent() const { return parent; } RssFolder* getParent() const { return parent; }
void setParent(RssFolder* _parent) { parent = _parent; } void setParent(RssFolder* _parent) { parent = _parent; }

2
src/rss/rssfolder.cpp

@ -35,7 +35,7 @@
#include "rssmanager.h" #include "rssmanager.h"
#include "rssfeed.h" #include "rssfeed.h"
RssFolder::RssFolder(RssFolder *parent, RssManager *rssmanager, Bittorrent *BTSession, QString name): parent(parent), rssmanager(rssmanager), BTSession(BTSession), name(name) { RssFolder::RssFolder(RssFolder *parent, RssManager *rssmanager, QBtSession *BTSession, QString name): parent(parent), rssmanager(rssmanager), BTSession(BTSession), name(name) {
downloader = new downloadThread(this); downloader = new downloadThread(this);
connect(downloader, SIGNAL(downloadFinished(QString, QString)), this, SLOT(processFinishedDownload(QString, QString))); connect(downloader, SIGNAL(downloadFinished(QString, QString)), this, SLOT(processFinishedDownload(QString, QString)));
connect(downloader, SIGNAL(downloadFailure(QString, QString)), this, SLOT(handleDownloadFailure(QString, QString))); connect(downloader, SIGNAL(downloadFailure(QString, QString)), this, SLOT(handleDownloadFailure(QString, QString)));

6
src/rss/rssfolder.h

@ -36,7 +36,7 @@
#include "rssfile.h" #include "rssfile.h"
class RssArticle; class RssArticle;
class Bittorrent; class QBtSession;
class downloadThread; class downloadThread;
class RssManager; class RssManager;
class RssFeed; class RssFeed;
@ -45,7 +45,7 @@ class RssFolder: public RssFile, public QHash<QString, RssFile*> {
Q_OBJECT Q_OBJECT
public: public:
RssFolder(RssFolder *parent, RssManager *rssmanager, Bittorrent *BTSession, QString name); RssFolder(RssFolder *parent, RssManager *rssmanager, QBtSession *BTSession, QString name);
~RssFolder(); ~RssFolder();
RssFolder* getParent() const { return parent; } RssFolder* getParent() const { return parent; }
void setParent(RssFolder* _parent) { parent = _parent; } void setParent(RssFolder* _parent) { parent = _parent; }
@ -80,7 +80,7 @@ private:
RssFolder *parent; RssFolder *parent;
RssManager *rssmanager; RssManager *rssmanager;
downloadThread *downloader; downloadThread *downloader;
Bittorrent *BTSession; QBtSession *BTSession;
QString name; QString name;
}; };

2
src/rss/rssmanager.cpp

@ -34,7 +34,7 @@
#include "rssfeed.h" #include "rssfeed.h"
#include "rssarticle.h" #include "rssarticle.h"
RssManager::RssManager(Bittorrent *BTSession): RssFolder(0, this, BTSession, QString::null) { RssManager::RssManager(QBtSession *BTSession): RssFolder(0, this, BTSession, QString::null) {
loadStreamList(); loadStreamList();
connect(&newsRefresher, SIGNAL(timeout()), this, SLOT(refreshAll())); connect(&newsRefresher, SIGNAL(timeout()), this, SLOT(refreshAll()));
refreshInterval = Preferences::getRSSRefreshInterval(); refreshInterval = Preferences::getRSSRefreshInterval();

4
src/rss/rssmanager.h

@ -39,7 +39,7 @@ class RssManager: public RssFolder {
Q_OBJECT Q_OBJECT
public: public:
RssManager(Bittorrent *BTSession); RssManager(QBtSession *BTSession);
~RssManager(); ~RssManager();
static void insertSortElem(QList<RssArticle*> &list, RssArticle *item); static void insertSortElem(QList<RssArticle*> &list, RssArticle *item);
static QList<RssArticle*> sortNewsList(const QList<RssArticle*>& news_list); static QList<RssArticle*> sortNewsList(const QList<RssArticle*>& news_list);
@ -59,7 +59,7 @@ signals:
private: private:
QTimer newsRefresher; QTimer newsRefresher;
unsigned int refreshInterval; unsigned int refreshInterval;
Bittorrent *BTSession; QBtSession *BTSession;
}; };

2
src/searchengine.cpp

@ -59,7 +59,7 @@
#define SEARCHHISTORY_MAXSIZE 50 #define SEARCHHISTORY_MAXSIZE 50
/*SEARCH ENGINE START*/ /*SEARCH ENGINE START*/
SearchEngine::SearchEngine(GUI *parent, Bittorrent *BTSession) : QWidget(parent), BTSession(BTSession), parent(parent) { SearchEngine::SearchEngine(GUI *parent, QBtSession *BTSession) : QWidget(parent), BTSession(BTSession), parent(parent) {
setupUi(this); setupUi(this);
// new qCompleter to the search pattern // new qCompleter to the search pattern
startSearchHistory(); startSearchHistory();

6
src/searchengine.h

@ -41,7 +41,7 @@
#include "searchtab.h" #include "searchtab.h"
#include "supportedengines.h" #include "supportedengines.h"
class Bittorrent; class QBtSession;
class downloadThread; class downloadThread;
class QTimer; class QTimer;
class SearchEngine; class SearchEngine;
@ -60,7 +60,7 @@ private:
unsigned long nb_search_results; unsigned long nb_search_results;
QPointer<QCompleter> searchCompleter; QPointer<QCompleter> searchCompleter;
QStringListModel searchHistory; QStringListModel searchHistory;
Bittorrent *BTSession; QBtSession *BTSession;
SupportedEngines *supported_engines; SupportedEngines *supported_engines;
QTimer *searchTimeout; QTimer *searchTimeout;
QPointer<SearchTab> currentSearchTab; QPointer<SearchTab> currentSearchTab;
@ -75,7 +75,7 @@ private:
#endif #endif
public: public:
SearchEngine(GUI *parent, Bittorrent *BTSession); SearchEngine(GUI *parent, QBtSession *BTSession);
~SearchEngine(); ~SearchEngine();
QString selectedCategory() const; QString selectedCategory() const;

4
src/statusbar.h

@ -60,10 +60,10 @@ private:
QTimer *refreshTimer; QTimer *refreshTimer;
QWidget *container; QWidget *container;
QGridLayout *layout; QGridLayout *layout;
Bittorrent *BTSession; QBtSession *BTSession;
public: public:
StatusBar(QStatusBar *bar, Bittorrent *BTSession): bar(bar), BTSession(BTSession) { StatusBar(QStatusBar *bar, QBtSession *BTSession): bar(bar), BTSession(BTSession) {
connect(BTSession, SIGNAL(alternativeSpeedsModeChanged(bool)), this, SLOT(updateAltSpeedsBtn(bool))); connect(BTSession, SIGNAL(alternativeSpeedsModeChanged(bool)), this, SLOT(updateAltSpeedsBtn(bool)));
container = new QWidget(); container = new QWidget();
layout = new QGridLayout(container); layout = new QGridLayout(container);

2
src/torrentadditiondlg.cpp

@ -30,7 +30,7 @@
#include "torrentadditiondlg.h" #include "torrentadditiondlg.h"
torrentAdditionDialog::torrentAdditionDialog(GUI *parent, Bittorrent* _BTSession) : QDialog((QWidget*)parent), old_label(""), hidden_height(0), cursor_pos(-1) { torrentAdditionDialog::torrentAdditionDialog(GUI *parent, QBtSession* _BTSession) : QDialog((QWidget*)parent), old_label(""), hidden_height(0), cursor_pos(-1) {
setupUi(this); setupUi(this);
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
connect(this, SIGNAL(torrentPaused(QTorrentHandle&)), parent->getTransferList(), SLOT(pauseTorrent(QTorrentHandle&))); connect(this, SIGNAL(torrentPaused(QTorrentHandle&)), parent->getTransferList(), SLOT(pauseTorrent(QTorrentHandle&)));

4
src/torrentadditiondlg.h

@ -62,7 +62,7 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
Q_OBJECT Q_OBJECT
public: public:
torrentAdditionDialog(GUI *parent, Bittorrent* _BTSession); torrentAdditionDialog(GUI *parent, QBtSession* _BTSession);
~torrentAdditionDialog(); ~torrentAdditionDialog();
void readSettings(); void readSettings();
void saveSettings(); void saveSettings();
@ -96,7 +96,7 @@ signals:
void torrentPaused(QTorrentHandle &h); void torrentPaused(QTorrentHandle &h);
private: private:
Bittorrent *BTSession; QBtSession *BTSession;
QString fileName; QString fileName;
QString hash; QString hash;
QString filePath; QString filePath;

220
src/torrentpersistentdata.h

@ -45,13 +45,13 @@ class TorrentTempData {
public: public:
static bool hasTempData(QString hash) { static bool hasTempData(QString hash) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents-tmp", QHash<QString, QVariant>()).toHash(); const QHash<QString, QVariant> all_data = settings.value("torrents-tmp").toHash();
return all_data.contains(hash); return all_data.contains(hash);
} }
static void deleteTempData(QString hash) { static void deleteTempData(QString hash) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents-tmp", QHash<QString, QVariant>()).toHash(); QHash<QString, QVariant> all_data = settings.value("torrents-tmp").toHash();
if(all_data.contains(hash)) { if(all_data.contains(hash)) {
all_data.remove(hash); all_data.remove(hash);
settings.setValue("torrents-tmp", all_data); settings.setValue("torrents-tmp", all_data);
@ -60,8 +60,8 @@ public:
static void setFilesPriority(QString hash, const std::vector<int> &pp) { static void setFilesPriority(QString hash, const std::vector<int> &pp) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents-tmp", QHash<QString, QVariant>()).toHash(); QHash<QString, QVariant> all_data = settings.value("torrents-tmp").toHash();
QHash<QString, QVariant> data = all_data[hash].toHash(); QHash<QString, QVariant> data = all_data.value(hash).toHash();
std::vector<int>::const_iterator pp_it = pp.begin(); std::vector<int>::const_iterator pp_it = pp.begin();
QStringList pieces_priority; QStringList pieces_priority;
while(pp_it != pp.end()) { while(pp_it != pp.end()) {
@ -75,8 +75,8 @@ public:
static void setFilesPath(QString hash, const QStringList &path_list) { static void setFilesPath(QString hash, const QStringList &path_list) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents-tmp", QHash<QString, QVariant>()).toHash(); QHash<QString, QVariant> all_data = settings.value("torrents-tmp").toHash();
QHash<QString, QVariant> data = all_data[hash].toHash(); QHash<QString, QVariant> data = all_data.value(hash).toHash();
data["files_path"] = path_list; data["files_path"] = path_list;
all_data[hash] = data; all_data[hash] = data;
settings.setValue("torrents-tmp", all_data); settings.setValue("torrents-tmp", all_data);
@ -84,8 +84,8 @@ public:
static void setSavePath(QString hash, QString save_path) { static void setSavePath(QString hash, QString save_path) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents-tmp", QHash<QString, QVariant>()).toHash(); QHash<QString, QVariant> all_data = settings.value("torrents-tmp").toHash();
QHash<QString, QVariant> data = all_data[hash].toHash(); QHash<QString, QVariant> data = all_data.value(hash).toHash();
data["save_path"] = save_path; data["save_path"] = save_path;
all_data[hash] = data; all_data[hash] = data;
settings.setValue("torrents-tmp", all_data); settings.setValue("torrents-tmp", all_data);
@ -93,8 +93,8 @@ public:
static void setLabel(QString hash, QString label) { static void setLabel(QString hash, QString label) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents-tmp", QHash<QString, QVariant>()).toHash(); QHash<QString, QVariant> all_data = settings.value("torrents-tmp").toHash();
QHash<QString, QVariant> data = all_data[hash].toHash(); QHash<QString, QVariant> data = all_data.value(hash).toHash();
qDebug("Saving label %s to tmp data", label.toLocal8Bit().data()); qDebug("Saving label %s to tmp data", label.toLocal8Bit().data());
data["label"] = label; data["label"] = label;
all_data[hash] = data; all_data[hash] = data;
@ -103,8 +103,8 @@ public:
static void setSequential(QString hash, bool sequential) { static void setSequential(QString hash, bool sequential) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents-tmp", QHash<QString, QVariant>()).toHash(); QHash<QString, QVariant> all_data = settings.value("torrents-tmp").toHash();
QHash<QString, QVariant> data = all_data[hash].toHash(); QHash<QString, QVariant> data = all_data.value(hash).toHash();
data["sequential"] = sequential; data["sequential"] = sequential;
all_data[hash] = data; all_data[hash] = data;
settings.setValue("torrents-tmp", all_data); settings.setValue("torrents-tmp", all_data);
@ -112,19 +112,16 @@ public:
static bool isSequential(QString hash) { static bool isSequential(QString hash) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents-tmp", QHash<QString, QVariant>()).toHash(); const QHash<QString, QVariant> all_data = settings.value("torrents-tmp").toHash();
QHash<QString, QVariant> data = all_data[hash].toHash(); const QHash<QString, QVariant> data = all_data.value(hash).toHash();
if(data.contains("sequential")) return data.value("sequential", false).toBool();
return data["sequential"].toBool();
return false;
} }
#if LIBTORRENT_VERSION_MINOR > 14 #if LIBTORRENT_VERSION_MINOR > 14
static void setSeedingMode(QString hash,bool seed){ static void setSeedingMode(QString hash,bool seed){
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents-tmp", QHash<QString, QVariant>()).toHash(); QHash<QString, QVariant> all_data = settings.value("torrents-tmp").toHash();
QHash<QString, QVariant> data = all_data[hash].toHash(); QHash<QString, QVariant> data = all_data.value(hash).toHash();
data["seeding"] = seed; data["seeding"] = seed;
all_data[hash] = data; all_data[hash] = data;
settings.setValue("torrents-tmp", all_data); settings.setValue("torrents-tmp", all_data);
@ -132,53 +129,42 @@ public:
static bool isSeedingMode(QString hash){ static bool isSeedingMode(QString hash){
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents-tmp", QHash<QString, QVariant>()).toHash(); const QHash<QString, QVariant> all_data = settings.value("torrents-tmp").toHash();
QHash<QString, QVariant> data = all_data[hash].toHash(); const QHash<QString, QVariant> data = all_data.value(hash).toHash();
if(data.contains("seeding")) return data.value("seeding", false).toBool();
return data["seeding"].toBool();
return false;
} }
#endif #endif
static QString getSavePath(QString hash) { static QString getSavePath(QString hash) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents-tmp", QHash<QString, QVariant>()).toHash(); const QHash<QString, QVariant> all_data = settings.value("torrents-tmp").toHash();
QHash<QString, QVariant> data = all_data[hash].toHash(); const QHash<QString, QVariant> data = all_data.value(hash).toHash();
if(data.contains("save_path")) return data.value("save_path").toString();
return data["save_path"].toString();
qDebug("Warning Temp::getSavePath returns null string!");
return QString::null;
} }
static QStringList getFilesPath(QString hash) { static QStringList getFilesPath(QString hash) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents-tmp", QHash<QString, QVariant>()).toHash(); const QHash<QString, QVariant> all_data = settings.value("torrents-tmp").toHash();
QHash<QString, QVariant> data = all_data[hash].toHash(); const QHash<QString, QVariant> data = all_data.value(hash).toHash();
if(data.contains("files_path")) return data.value("files_path").toStringList();
return data["files_path"].toStringList();
return QStringList();
} }
static QString getLabel(QString hash) { static QString getLabel(QString hash) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents-tmp", QHash<QString, QVariant>()).toHash(); const QHash<QString, QVariant> all_data = settings.value("torrents-tmp").toHash();
QHash<QString, QVariant> data = all_data[hash].toHash(); const QHash<QString, QVariant> data = all_data.value(hash).toHash();
qDebug("Got label %s from tmp data", data.value("label", "").toString().toLocal8Bit().data()); qDebug("Got label %s from tmp data", data.value("label", "").toString().toLocal8Bit().data());
return data.value("label", "").toString(); return data.value("label", "").toString();
} }
static std::vector<int> getFilesPriority(QString hash) { static void getFilesPriority(QString hash, std::vector<int> &fp) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents-tmp", QHash<QString, QVariant>()).toHash(); const QHash<QString, QVariant> all_data = settings.value("torrents-tmp").toHash();
QHash<QString, QVariant> data = all_data[hash].toHash(); const QHash<QString, QVariant> data = all_data.value(hash).toHash();
std::vector<int> fp; const QList<int> list_var = misc::intListfromStringList(data.value("files_priority").toStringList());
if(data.contains("files_priority")) { foreach(const int &var, list_var) {
QList<int> list_var = misc::intListfromStringList(data["files_priority"].toStringList()); fp.push_back(var);
foreach(int var, list_var) {
fp.push_back(var);
}
} }
return fp;
} }
}; };
@ -187,22 +173,22 @@ public:
static bool isKnownTorrent(QString hash) { static bool isKnownTorrent(QString hash) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash(); const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
return all_data.contains(hash); return all_data.contains(hash);
} }
static QStringList knownTorrents() { static QStringList knownTorrents() {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash(); const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
return all_data.keys(); return all_data.keys();
} }
static void setAddedDate(QString hash) { static void setAddedDate(QString hash) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash(); QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
QHash<QString, QVariant> data = all_data[hash].toHash(); QHash<QString, QVariant> data = all_data.value(hash).toHash();
if(!data.contains("add_date")) { if(!data.contains("add_date")) {
data.insert("add_date", QDateTime::currentDateTime()); data["add_date"] = QDateTime::currentDateTime();
all_data[hash] = data; all_data[hash] = data;
settings.setValue("torrents", all_data); settings.setValue("torrents", all_data);
} }
@ -210,9 +196,9 @@ public:
static QDateTime getAddedDate(QString hash) { static QDateTime getAddedDate(QString hash) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash(); const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
QHash<QString, QVariant> data = all_data[hash].toHash(); const QHash<QString, QVariant> data = all_data.value(hash).toHash();
QDateTime dt = data.value("add_date", QDateTime()).toDateTime(); QDateTime dt = data.value("add_date").toDateTime();
if(!dt.isValid()) { if(!dt.isValid()) {
setAddedDate(hash); setAddedDate(hash);
dt = QDateTime::currentDateTime(); dt = QDateTime::currentDateTime();
@ -222,89 +208,86 @@ public:
static void setErrorState(QString hash, bool has_error) { static void setErrorState(QString hash, bool has_error) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash(); QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
QHash<QString, QVariant> data = all_data[hash].toHash(); QHash<QString, QVariant> data = all_data.value(hash).toHash();
data.insert("has_error", has_error); data["has_error"] = has_error;
all_data[hash] = data; all_data[hash] = data;
settings.setValue("torrents", all_data); settings.setValue("torrents", all_data);
} }
static bool hasError(QString hash) { static bool hasError(QString hash) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash(); const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
QHash<QString, QVariant> data = all_data[hash].toHash(); const QHash<QString, QVariant> data = all_data.value(hash).toHash();
return data.value("has_error", false).toBool(); return data.value("has_error", false).toBool();
} }
static void setRootFolder(QString hash, QString root_folder) { static void setRootFolder(QString hash, QString root_folder) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash(); QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
QHash<QString, QVariant> data = all_data[hash].toHash(); QHash<QString, QVariant> data = all_data.value(hash).toHash();
data.insert("root_folder", root_folder); data["root_folder"] = root_folder;
all_data[hash] = data; all_data[hash] = data;
settings.setValue("torrents", all_data); settings.setValue("torrents", all_data);
} }
static QString getRootFolder(QString hash) { static QString getRootFolder(QString hash) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash(); const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
QHash<QString, QVariant> data = all_data[hash].toHash(); const QHash<QString, QVariant> data = all_data.value(hash).toHash();
return data.value("root_folder", QString()).toString(); return data.value("root_folder").toString();
} }
static void setPreviousSavePath(QString hash, QString previous_path) { static void setPreviousSavePath(QString hash, QString previous_path) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash(); QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
QHash<QString, QVariant> data = all_data[hash].toHash(); QHash<QString, QVariant> data = all_data.value(hash).toHash();
data.insert("previous_path", previous_path); data["previous_path"] = previous_path;
all_data[hash] = data; all_data[hash] = data;
settings.setValue("torrents", all_data); settings.setValue("torrents", all_data);
} }
static QString getPreviousPath(QString hash) { static QString getPreviousPath(QString hash) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash(); const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
QHash<QString, QVariant> data = all_data[hash].toHash(); const QHash<QString, QVariant> data = all_data.value(hash).toHash();
return data.value("previous_path", QString()).toString(); return data.value("previous_path").toString();
} }
static void saveSeedDate(const QTorrentHandle &h) { static void saveSeedDate(const QTorrentHandle &h) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash(); QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
QHash<QString, QVariant> data = all_data[h.hash()].toHash(); QHash<QString, QVariant> data = all_data[h.hash()].toHash();
if(h.is_seed()) if(h.is_seed())
data.insert("seed_date", QDateTime::currentDateTime()); data["seed_date"] = QDateTime::currentDateTime();
else else
data.insert("seed_date", QDateTime()); data.remove("seed_date");
all_data[h.hash()] = data; all_data[h.hash()] = data;
settings.setValue("torrents", all_data); settings.setValue("torrents", all_data);
} }
static QDateTime getSeedDate(QString hash) { static QDateTime getSeedDate(QString hash) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash(); const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
QHash<QString, QVariant> data = all_data[hash].toHash(); const QHash<QString, QVariant> data = all_data.value(hash).toHash();
return data.value("seed_date", QDateTime()).toDateTime(); return data.value("seed_date").toDateTime();
} }
static void deletePersistentData(QString hash) { static void deletePersistentData(QString hash) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash(); QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
if(all_data.contains(hash)) { if(all_data.contains(hash)) {
all_data.remove(hash); all_data.remove(hash);
settings.setValue("torrents", all_data); settings.setValue("torrents", all_data);
} }
} }
static void saveTorrentPersistentData(const QTorrentHandle &h, bool is_magnet = false) { static void saveTorrentPersistentData(const QTorrentHandle &h, QString save_path = QString::null, bool is_magnet = false) {
Q_ASSERT(h.is_valid()); Q_ASSERT(h.is_valid());
qDebug("Saving persistent data for %s", h.hash().toLocal8Bit().data()); qDebug("Saving persistent data for %s", qPrintable(h.hash()));
// First, remove temp data
TorrentTempData::deleteTempData(h.hash());
Q_ASSERT(!TorrentTempData::hasTempData(h.hash()));
// Save persistent data // Save persistent data
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash(); QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
QHash<QString, QVariant> data; QHash<QString, QVariant> data;
data["is_magnet"] = is_magnet; data["is_magnet"] = is_magnet;
if(is_magnet) { if(is_magnet) {
@ -312,13 +295,20 @@ public:
} }
data["seed"] = h.is_seed(); data["seed"] = h.is_seed();
data["priority"] = h.queue_position(); data["priority"] = h.queue_position();
data["save_path"] = h.save_path(); if(save_path.isEmpty())
data["save_path"] = h.save_path();
else
data["save_path"] = save_path; // Override torrent save path (e.g. because it is a temp dir)
// Label
data["label"] = TorrentTempData::getLabel(h.hash());
// Save data // Save data
all_data[h.hash()] = data; all_data[h.hash()] = data;
settings.setValue("torrents", all_data); settings.setValue("torrents", all_data);
qDebug("TorrentPersistentData: Saving save_path %s, hash: %s", h.save_path().toLocal8Bit().data(), h.hash().toLocal8Bit().data()); qDebug("TorrentPersistentData: Saving save_path %s, hash: %s", qPrintable(h.save_path()), qPrintable(h.hash()));
// Set Added date // Set Added date
setAddedDate(h.hash()); setAddedDate(h.hash());
// Finally, remove temp data
TorrentTempData::deleteTempData(h.hash());
} }
// Setters // Setters
@ -327,8 +317,8 @@ public:
Q_ASSERT(!hash.isEmpty()); Q_ASSERT(!hash.isEmpty());
qDebug("TorrentPersistentData::saveSavePath(%s)", qPrintable(save_path)); qDebug("TorrentPersistentData::saveSavePath(%s)", qPrintable(save_path));
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash(); QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
QHash<QString, QVariant> data = all_data[hash].toHash(); QHash<QString, QVariant> data = all_data.value(hash).toHash();
data["save_path"] = save_path; data["save_path"] = save_path;
all_data[hash] = data; all_data[hash] = data;
settings.setValue("torrents", all_data); settings.setValue("torrents", all_data);
@ -338,8 +328,8 @@ public:
static void saveLabel(QString hash, QString label) { static void saveLabel(QString hash, QString label) {
Q_ASSERT(!hash.isEmpty()); Q_ASSERT(!hash.isEmpty());
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash(); QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
QHash<QString, QVariant> data = all_data[hash].toHash(); QHash<QString, QVariant> data = all_data.value(hash).toHash();
data["label"] = label; data["label"] = label;
all_data[hash] = data; all_data[hash] = data;
settings.setValue("torrents", all_data); settings.setValue("torrents", all_data);
@ -348,8 +338,8 @@ public:
static void saveName(QString hash, QString name) { static void saveName(QString hash, QString name) {
Q_ASSERT(!hash.isEmpty()); Q_ASSERT(!hash.isEmpty());
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash(); QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
QHash<QString, QVariant> data = all_data[hash].toHash(); QHash<QString, QVariant> data = all_data.value(hash).toHash();
data["name"] = name; data["name"] = name;
all_data[hash] = data; all_data[hash] = data;
settings.setValue("torrents", all_data); settings.setValue("torrents", all_data);
@ -357,7 +347,7 @@ public:
static void savePriority(const QTorrentHandle &h) { static void savePriority(const QTorrentHandle &h) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash(); QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
QHash<QString, QVariant> data = all_data[h.hash()].toHash(); QHash<QString, QVariant> data = all_data[h.hash()].toHash();
data["priority"] = h.queue_position(); data["priority"] = h.queue_position();
all_data[h.hash()] = data; all_data[h.hash()] = data;
@ -366,7 +356,7 @@ public:
static void saveSeedStatus(const QTorrentHandle &h) { static void saveSeedStatus(const QTorrentHandle &h) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash(); QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
QHash<QString, QVariant> data = all_data[h.hash()].toHash(); QHash<QString, QVariant> data = all_data[h.hash()].toHash();
bool was_seed = data.value("seed", false).toBool(); bool was_seed = data.value("seed", false).toBool();
if(was_seed != h.is_seed()) { if(was_seed != h.is_seed()) {
@ -383,53 +373,53 @@ public:
// Getters // Getters
static QString getSavePath(QString hash) { static QString getSavePath(QString hash) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash(); const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
QHash<QString, QVariant> data = all_data[hash].toHash(); const QHash<QString, QVariant> data = all_data.value(hash).toHash();
//qDebug("TorrentPersistentData: getSavePath %s", data["save_path"].toString().toLocal8Bit().data()); //qDebug("TorrentPersistentData: getSavePath %s", data["save_path"].toString().toLocal8Bit().data());
return data["save_path"].toString(); return data.value("save_path").toString();
} }
static QString getLabel(QString hash) { static QString getLabel(QString hash) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash(); const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
QHash<QString, QVariant> data = all_data[hash].toHash(); const QHash<QString, QVariant> data = all_data.value(hash).toHash();
return data.value("label", "").toString(); return data.value("label", "").toString();
} }
static QString getName(QString hash) { static QString getName(QString hash) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash(); const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
QHash<QString, QVariant> data = all_data[hash].toHash(); const QHash<QString, QVariant> data = all_data.value(hash).toHash();
return data.value("name", "").toString(); return data.value("name", "").toString();
} }
static int getPriority(QString hash) { static int getPriority(QString hash) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash(); const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
QHash<QString, QVariant> data = all_data[hash].toHash(); const QHash<QString, QVariant> data = all_data.value(hash).toHash();
return data["priority"].toInt(); return data.value("priority", -1).toInt();
} }
static bool isSeed(QString hash) { static bool isSeed(QString hash) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash(); const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
QHash<QString, QVariant> data = all_data[hash].toHash(); const QHash<QString, QVariant> data = all_data.value(hash).toHash();
return data.value("seed", false).toBool(); return data.value("seed", false).toBool();
} }
static bool isMagnet(QString hash) { static bool isMagnet(QString hash) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash(); const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
QHash<QString, QVariant> data = all_data[hash].toHash(); const QHash<QString, QVariant> data = all_data.value(hash).toHash();
return data["is_magnet"].toBool(); return data.value("is_magnet", false).toBool();
} }
static QString getMagnetUri(QString hash) { static QString getMagnetUri(QString hash) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash(); const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
QHash<QString, QVariant> data = all_data[hash].toHash(); const QHash<QString, QVariant> data = all_data.value(hash).toHash();
Q_ASSERT(data["is_magnet"].toBool()); Q_ASSERT(data.value("is_magnet", false).toBool());
return data["magnet_uri"].toString(); return data.value("magnet_uri").toString();
} }
}; };

2
src/transferlistwidget.cpp

@ -55,7 +55,7 @@
#include "qinisettings.h" #include "qinisettings.h"
TransferListWidget::TransferListWidget(QWidget *parent, GUI *main_window, Bittorrent *_BTSession): TransferListWidget::TransferListWidget(QWidget *parent, GUI *main_window, QBtSession *_BTSession):
QTreeView(parent), BTSession(_BTSession), main_window(main_window) { QTreeView(parent), BTSession(_BTSession), main_window(main_window) {
QIniSettings settings("qBittorrent", "qBittorrent"); QIniSettings settings("qBittorrent", "qBittorrent");
// Create and apply delegate // Create and apply delegate

6
src/transferlistwidget.h

@ -37,7 +37,7 @@
class QStandardItemModel; class QStandardItemModel;
class QSortFilterProxyModel; class QSortFilterProxyModel;
class Bittorrent; class QBtSession;
class QTimer; class QTimer;
class TransferListDelegate; class TransferListDelegate;
class GUI; class GUI;
@ -48,7 +48,7 @@ class TransferListWidget: public QTreeView {
Q_OBJECT Q_OBJECT
public: public:
TransferListWidget(QWidget *parent, GUI *main_window, Bittorrent* BTSession); TransferListWidget(QWidget *parent, GUI *main_window, QBtSession* BTSession);
~TransferListWidget(); ~TransferListWidget();
int getNbTorrents() const; int getNbTorrents() const;
QStandardItemModel* getSourceModel() const; QStandardItemModel* getSourceModel() const;
@ -134,7 +134,7 @@ private:
QSortFilterProxyModel *nameFilterModel; QSortFilterProxyModel *nameFilterModel;
QSortFilterProxyModel *statusFilterModel; QSortFilterProxyModel *statusFilterModel;
QSortFilterProxyModel *labelFilterModel; QSortFilterProxyModel *labelFilterModel;
Bittorrent* BTSession; QBtSession* BTSession;
QTimer *refreshTimer; QTimer *refreshTimer;
GUI *main_window; GUI *main_window;
}; };

2
src/webui/eventmanager.cpp

@ -40,7 +40,7 @@
#include <QDebug> #include <QDebug>
#include <QTranslator> #include <QTranslator>
EventManager::EventManager(QObject *parent, Bittorrent *BTSession) EventManager::EventManager(QObject *parent, QBtSession *BTSession)
: QObject(parent), BTSession(BTSession) : QObject(parent), BTSession(BTSession)
{ {
} }

6
src/webui/eventmanager.h

@ -36,20 +36,20 @@
#include <QHash> #include <QHash>
#include <QVariant> #include <QVariant>
class Bittorrent; class QBtSession;
class EventManager : public QObject class EventManager : public QObject
{ {
Q_OBJECT Q_OBJECT
private: private:
QHash<QString, QVariantMap> event_list; QHash<QString, QVariantMap> event_list;
Bittorrent* BTSession; QBtSession* BTSession;
protected: protected:
void update(QVariantMap event); void update(QVariantMap event);
public: public:
EventManager(QObject *parent, Bittorrent* BTSession); EventManager(QObject *parent, QBtSession* BTSession);
QList<QVariantMap> getEventList() const; QList<QVariantMap> getEventList() const;
QVariantMap getPropGeneralInfo(QString hash) const; QVariantMap getPropGeneralInfo(QString hash) const;
QList<QVariantMap> getPropTrackersInfo(QString hash) const; QList<QVariantMap> getPropTrackersInfo(QString hash) const;

2
src/webui/httpconnection.cpp

@ -46,7 +46,7 @@
#include <QRegExp> #include <QRegExp>
#include <QTemporaryFile> #include <QTemporaryFile>
HttpConnection::HttpConnection(QTcpSocket *socket, Bittorrent *BTSession, HttpServer *parent) HttpConnection::HttpConnection(QTcpSocket *socket, QBtSession *BTSession, HttpServer *parent)
: QObject(parent), socket(socket), parent(parent), BTSession(BTSession) : QObject(parent), socket(socket), parent(parent), BTSession(BTSession)
{ {
socket->setParent(this); socket->setParent(this);

6
src/webui/httpconnection.h

@ -38,7 +38,7 @@
class QTcpSocket; class QTcpSocket;
class HttpServer; class HttpServer;
class Bittorrent; class QBtSession;
class HttpConnection : public QObject class HttpConnection : public QObject
{ {
@ -46,7 +46,7 @@ class HttpConnection : public QObject
private: private:
QTcpSocket *socket; QTcpSocket *socket;
HttpServer *parent; HttpServer *parent;
Bittorrent *BTSession; QBtSession *BTSession;
protected: protected:
HttpRequestParser parser; HttpRequestParser parser;
@ -69,7 +69,7 @@ class HttpConnection : public QObject
void recheckAllTorrents(); void recheckAllTorrents();
public: public:
HttpConnection(QTcpSocket *socket, Bittorrent* BTSession, HttpServer *parent); HttpConnection(QTcpSocket *socket, QBtSession* BTSession, HttpServer *parent);
~HttpConnection(); ~HttpConnection();
QString translateDocument(QString data); QString translateDocument(QString data);

2
src/webui/httpserver.cpp

@ -80,7 +80,7 @@ void HttpServer::resetNbFailedAttemptsForIp(QString ip) {
client_failed_attempts.remove(ip); client_failed_attempts.remove(ip);
} }
HttpServer::HttpServer(Bittorrent *_BTSession, int msec, QObject* parent) : QTcpServer(parent) { HttpServer::HttpServer(QBtSession *_BTSession, int msec, QObject* parent) : QTcpServer(parent) {
username = Preferences::getWebUiUsername().toLocal8Bit(); username = Preferences::getWebUiUsername().toLocal8Bit();
password_ha1 = Preferences::getWebUiPassword().toLocal8Bit(); password_ha1 = Preferences::getWebUiPassword().toLocal8Bit();
connect(this, SIGNAL(newConnection()), this, SLOT(newHttpConnection())); connect(this, SIGNAL(newConnection()), this, SLOT(newHttpConnection()));

6
src/webui/httpserver.h

@ -38,7 +38,7 @@
#include <QHash> #include <QHash>
#include "preferences.h" #include "preferences.h"
class Bittorrent; class QBtSession;
class QTimer; class QTimer;
class EventManager; class EventManager;
@ -48,7 +48,7 @@ class HttpServer : public QTcpServer {
Q_OBJECT Q_OBJECT
public: public:
HttpServer(Bittorrent *BTSession, int msec, QObject* parent = 0); HttpServer(QBtSession *BTSession, int msec, QObject* parent = 0);
~HttpServer(); ~HttpServer();
void setAuthorization(QString username, QString password_ha1); void setAuthorization(QString username, QString password_ha1);
bool isAuthorized(QByteArray auth, QString method) const; bool isAuthorized(QByteArray auth, QString method) const;
@ -66,7 +66,7 @@ private slots:
private: private:
QByteArray username; QByteArray username;
QByteArray password_ha1; QByteArray password_ha1;
Bittorrent *BTSession; QBtSession *BTSession;
EventManager *manager; EventManager *manager;
QTimer *timer; QTimer *timer;
QHash<QString, int> client_failed_attempts; QHash<QString, int> client_failed_attempts;

Loading…
Cancel
Save