mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-26 03:06:37 +03:00
Speedup persistent data
Conflicts: src/mainwindow.cpp src/mainwindow.h
This commit is contained in:
parent
f2c6981711
commit
70a114eb13
4 changed files with 48 additions and 64 deletions
|
@ -243,6 +243,11 @@ MainWindow::MainWindow(QWidget *parent, const QStringList& torrentCmdLine): QMai
|
|||
preventTimer = new QTimer(this);
|
||||
connect(preventTimer, SIGNAL(timeout()), SLOT(checkForActiveTorrents()));
|
||||
|
||||
// Initialization of persistent data
|
||||
TorrentPersistentData::load();
|
||||
connect(&persistentDataSaver, SIGNAL(timeout()), SLOT(savePersistentData()));
|
||||
persistentDataSaver.start(10000);
|
||||
|
||||
// Configure BT session according to options
|
||||
loadPreferences(false);
|
||||
|
||||
|
@ -459,6 +464,7 @@ void MainWindow::shutdownCleanUp()
|
|||
QBtSession::drop();
|
||||
// Save window size, columns size
|
||||
writeSettings();
|
||||
TorrentPersistentData::save();
|
||||
#ifdef Q_OS_MAC
|
||||
// Workaround to avoid bug http://bugreports.qt.nokia.com/browse/QTBUG-7305
|
||||
setUnifiedTitleAndToolBarOnMac(false);
|
||||
|
@ -1586,6 +1592,11 @@ void MainWindow::handleUpdateCheckFinished(bool update_available, QString new_ve
|
|||
}
|
||||
#endif
|
||||
|
||||
void MainWindow::savePersistentData()
|
||||
{
|
||||
TorrentPersistentData::save();
|
||||
}
|
||||
|
||||
void MainWindow::on_actionDonate_money_triggered()
|
||||
{
|
||||
QDesktopServices::openUrl(QUrl("http://sourceforge.net/donate/index.php?group_id=163414"));
|
||||
|
|
|
@ -143,6 +143,7 @@ protected slots:
|
|||
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
|
||||
void handleUpdateCheckFinished(bool update_available, QString new_version, bool invokedByUser);
|
||||
#endif
|
||||
void savePersistentData();
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *);
|
||||
|
@ -216,6 +217,7 @@ private:
|
|||
bool has_python;
|
||||
#endif
|
||||
QMenu* toolbarMenu;
|
||||
QTimer persistentDataSaver;
|
||||
|
||||
private slots:
|
||||
void on_actionSearch_engine_triggered();
|
||||
|
|
|
@ -44,6 +44,8 @@ QHash<QString, TorrentTempData::TorrentData> TorrentTempData::data = QHash<QStri
|
|||
QHash<QString, TorrentTempData::TorrentMoveState> TorrentTempData::torrentMoveStates = QHash<QString, TorrentTempData::TorrentMoveState>();
|
||||
QHash<QString, bool> HiddenData::data = QHash<QString, bool>();
|
||||
unsigned int HiddenData::metadata_counter = 0;
|
||||
QHash<QString, QVariant> TorrentPersistentData::all_data = QHash<QString, QVariant>();
|
||||
bool TorrentPersistentData::dirty = false;
|
||||
|
||||
bool TorrentTempData::hasTempData(const QString &hash) {
|
||||
return data.contains(hash);
|
||||
|
@ -197,37 +199,41 @@ void HiddenData::gotMetadata(const QString &hash) {
|
|||
metadata_counter++;
|
||||
}
|
||||
|
||||
bool TorrentPersistentData::isKnownTorrent(QString hash) {
|
||||
void TorrentPersistentData::load() {
|
||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||
all_data = settings.value("torrents").toHash();
|
||||
dirty = false;
|
||||
}
|
||||
|
||||
void TorrentPersistentData::save() {
|
||||
if (dirty) {
|
||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||
settings.setValue("torrents", all_data);
|
||||
dirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool TorrentPersistentData::isKnownTorrent(QString hash) {
|
||||
return all_data.contains(hash);
|
||||
}
|
||||
|
||||
QStringList TorrentPersistentData::knownTorrents() {
|
||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||
return all_data.keys();
|
||||
}
|
||||
|
||||
void TorrentPersistentData::setRatioLimit(const QString &hash, const qreal &ratio) {
|
||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||
QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
||||
data["max_ratio"] = ratio;
|
||||
all_data[hash] = data;
|
||||
settings.setValue("torrents", all_data);
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
qreal TorrentPersistentData::getRatioLimit(const QString &hash) {
|
||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
||||
return data.value("max_ratio", USE_GLOBAL_RATIO).toReal();
|
||||
}
|
||||
|
||||
bool TorrentPersistentData::hasPerTorrentRatioLimit() {
|
||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||
QHash<QString, QVariant>::ConstIterator it = all_data.constBegin();
|
||||
QHash<QString, QVariant>::ConstIterator itend = all_data.constEnd();
|
||||
for ( ; it != itend; ++it) {
|
||||
|
@ -239,19 +245,15 @@ bool TorrentPersistentData::hasPerTorrentRatioLimit() {
|
|||
}
|
||||
|
||||
void TorrentPersistentData::setAddedDate(const QString &hash, const QDateTime &time) {
|
||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||
QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
||||
if (!data.contains("add_date")) {
|
||||
data["add_date"] = time;
|
||||
all_data[hash] = data;
|
||||
settings.setValue("torrents", all_data);
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
QDateTime TorrentPersistentData::getAddedDate(const QString &hash) {
|
||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
||||
QDateTime dt = data.value("add_date").toDateTime();
|
||||
if (!dt.isValid()) {
|
||||
|
@ -262,34 +264,26 @@ QDateTime TorrentPersistentData::getAddedDate(const QString &hash) {
|
|||
}
|
||||
|
||||
void TorrentPersistentData::setErrorState(const QString &hash, const bool has_error) {
|
||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||
QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
||||
data["has_error"] = has_error;
|
||||
all_data[hash] = data;
|
||||
settings.setValue("torrents", all_data);
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
bool TorrentPersistentData::hasError(const QString &hash) {
|
||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
||||
return data.value("has_error", false).toBool();
|
||||
}
|
||||
|
||||
QDateTime TorrentPersistentData::getSeedDate(const QString &hash) {
|
||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
||||
return data.value("seed_date").toDateTime();
|
||||
}
|
||||
|
||||
void TorrentPersistentData::deletePersistentData(const QString &hash) {
|
||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||
if (all_data.contains(hash)) {
|
||||
all_data.remove(hash);
|
||||
settings.setValue("torrents", all_data);
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -297,8 +291,6 @@ void TorrentPersistentData::saveTorrentPersistentData(const QTorrentHandle &h, c
|
|||
Q_ASSERT(h.is_valid());
|
||||
qDebug("Saving persistent data for %s", qPrintable(h.hash()));
|
||||
// Save persistent data
|
||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||
QHash<QString, QVariant> data = all_data.value(h.hash()).toHash();
|
||||
data["is_magnet"] = is_magnet;
|
||||
if (is_magnet) {
|
||||
|
@ -317,7 +309,7 @@ void TorrentPersistentData::saveTorrentPersistentData(const QTorrentHandle &h, c
|
|||
data["label"] = TorrentTempData::getLabel(h.hash());
|
||||
// Save data
|
||||
all_data[h.hash()] = data;
|
||||
settings.setValue("torrents", all_data);
|
||||
dirty = true;
|
||||
qDebug("TorrentPersistentData: Saving save_path %s, hash: %s", qPrintable(h.save_path()), qPrintable(h.hash()));
|
||||
// Set Added date
|
||||
setAddedDate(h.hash(), QDateTime::currentDateTime());
|
||||
|
@ -328,120 +320,92 @@ void TorrentPersistentData::saveTorrentPersistentData(const QTorrentHandle &h, c
|
|||
void TorrentPersistentData::saveSavePath(const QString &hash, const QString &save_path) {
|
||||
Q_ASSERT(!hash.isEmpty());
|
||||
qDebug("TorrentPersistentData::saveSavePath(%s)", qPrintable(save_path));
|
||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||
QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
||||
data["save_path"] = save_path;
|
||||
all_data[hash] = data;
|
||||
settings.setValue("torrents", all_data);
|
||||
dirty = true;
|
||||
qDebug("TorrentPersistentData: Saving save_path: %s, hash: %s", qPrintable(save_path), qPrintable(hash));
|
||||
}
|
||||
|
||||
void TorrentPersistentData::saveLabel(const QString &hash, const QString &label) {
|
||||
Q_ASSERT(!hash.isEmpty());
|
||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||
QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
||||
data["label"] = label;
|
||||
all_data[hash] = data;
|
||||
settings.setValue("torrents", all_data);
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
void TorrentPersistentData::saveName(const QString &hash, const QString &name) {
|
||||
Q_ASSERT(!hash.isEmpty());
|
||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||
QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
||||
data["name"] = name;
|
||||
all_data[hash] = data;
|
||||
settings.setValue("torrents", all_data);
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
void TorrentPersistentData::savePriority(const QTorrentHandle &h) {
|
||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||
QHash<QString, QVariant> data = all_data[h.hash()].toHash();
|
||||
data["priority"] = h.queue_position();
|
||||
all_data[h.hash()] = data;
|
||||
settings.setValue("torrents", all_data);
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
void TorrentPersistentData::savePriority(const QString &hash, const int &queue_pos) {
|
||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||
QHash<QString, QVariant> data = all_data[hash].toHash();
|
||||
data["priority"] = queue_pos;
|
||||
all_data[hash] = data;
|
||||
settings.setValue("torrents", all_data);
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
void TorrentPersistentData::saveSeedStatus(const QTorrentHandle &h) {
|
||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||
QHash<QString, QVariant> data = all_data[h.hash()].toHash();
|
||||
bool was_seed = data.value("seed", false).toBool();
|
||||
if (was_seed != h.is_seed()) {
|
||||
data["seed"] = !was_seed;
|
||||
all_data[h.hash()] = data;
|
||||
settings.setValue("torrents", all_data);
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
void TorrentPersistentData::saveSeedStatus(const QString &hash, const bool seedStatus) {
|
||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||
QHash<QString, QVariant> data = all_data[hash].toHash();
|
||||
data["seed"] = seedStatus;
|
||||
all_data[hash] = data;
|
||||
settings.setValue("torrents", all_data);
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
QString TorrentPersistentData::getSavePath(const QString &hash) {
|
||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
||||
//qDebug("TorrentPersistentData: getSavePath %s", data["save_path"].toString().toLocal8Bit().data());
|
||||
return data.value("save_path").toString();
|
||||
}
|
||||
|
||||
QString TorrentPersistentData::getLabel(const QString &hash) {
|
||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
||||
return data.value("label", "").toString();
|
||||
}
|
||||
|
||||
QString TorrentPersistentData::getName(const QString &hash) {
|
||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
||||
return data.value("name", "").toString();
|
||||
}
|
||||
|
||||
int TorrentPersistentData::getPriority(const QString &hash) {
|
||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
||||
return data.value("priority", -1).toInt();
|
||||
}
|
||||
|
||||
bool TorrentPersistentData::isSeed(const QString &hash) {
|
||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
||||
return data.value("seed", false).toBool();
|
||||
}
|
||||
|
||||
bool TorrentPersistentData::isMagnet(const QString &hash) {
|
||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
||||
return data.value("is_magnet", false).toBool();
|
||||
}
|
||||
|
||||
QString TorrentPersistentData::getMagnetUri(const QString &hash) {
|
||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
||||
Q_ASSERT(data.value("is_magnet", false).toBool());
|
||||
return data.value("magnet_uri").toString();
|
||||
|
|
|
@ -121,6 +121,9 @@ public:
|
|||
};
|
||||
|
||||
public:
|
||||
static void load();
|
||||
static void save();
|
||||
|
||||
static bool isKnownTorrent(QString hash);
|
||||
static QStringList knownTorrents();
|
||||
static void setRatioLimit(const QString &hash, const qreal &ratio);
|
||||
|
@ -151,6 +154,10 @@ public:
|
|||
static bool isSeed(const QString &hash);
|
||||
static bool isMagnet(const QString &hash);
|
||||
static QString getMagnetUri(const QString &hash);
|
||||
|
||||
private:
|
||||
static QHash<QString, QVariant> all_data;
|
||||
static bool dirty;
|
||||
};
|
||||
|
||||
#endif // TORRENTPERSISTENTDATA_H
|
||||
|
|
Loading…
Reference in a new issue