Merge pull request #8217 from Piccirello/webui-statusbar-freespace

Free disk space in WebUI status bar
This commit is contained in:
Vladimir Golovnev 2018-10-28 10:02:49 +03:00 committed by GitHub
commit 4fee16fafb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 156 additions and 1 deletions

View file

@ -5,6 +5,7 @@ api/apierror.h
api/appcontroller.h
api/isessionmanager.h
api/authcontroller.h
api/freediskspacechecker.h
api/logcontroller.h
api/rsscontroller.h
api/searchcontroller.h
@ -20,6 +21,7 @@ api/apicontroller.cpp
api/apierror.cpp
api/appcontroller.cpp
api/authcontroller.cpp
api/freediskspacechecker.cpp
api/logcontroller.cpp
api/rsscontroller.cpp
api/searchcontroller.cpp

View file

@ -0,0 +1,38 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2018 Thomas Piccirello <thomas.piccirello@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*/
#include "freediskspacechecker.h"
#include "base/bittorrent/session.h"
#include "base/utils/fs.h"
void FreeDiskSpaceChecker::check()
{
const qint64 freeDiskSpace = Utils::Fs::freeDiskSpaceOnPath(BitTorrent::Session::instance()->defaultSavePath());
emit checked(freeDiskSpace);
}

View file

@ -0,0 +1,46 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2018 Thomas Piccirello <thomas.piccirello@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*/
#pragma once
#include <QObject>
class FreeDiskSpaceChecker : public QObject
{
Q_OBJECT
Q_DISABLE_COPY(FreeDiskSpaceChecker)
public:
FreeDiskSpaceChecker() = default;
public slots:
void check();
signals:
void checked(qint64 freeSpaceSize);
};

View file

@ -29,6 +29,8 @@
#include "synccontroller.h"
#include <QJsonObject>
#include <QThread>
#include <QTimer>
#include "base/bittorrent/peerinfo.h"
#include "base/bittorrent/session.h"
@ -38,6 +40,7 @@
#include "base/utils/fs.h"
#include "base/utils/string.h"
#include "apierror.h"
#include "freediskspacechecker.h"
#include "isessionmanager.h"
#include "serialize/serialize_torrent.h"
@ -75,6 +78,7 @@ const char KEY_TRANSFER_UPDATA[] = "up_info_data";
const char KEY_TRANSFER_UPRATELIMIT[] = "up_rate_limit";
const char KEY_TRANSFER_DHT_NODES[] = "dht_nodes";
const char KEY_TRANSFER_CONNECTION_STATUS[] = "connection_status";
const char KEY_TRANSFER_FREESPACEONDISK[] = "free_space_on_disk";
// Statistics keys
const char KEY_TRANSFER_ALLTIME_DL[] = "alltime_dl";
@ -94,6 +98,8 @@ const char KEY_FULL_UPDATE[] = "full_update";
const char KEY_RESPONSE_ID[] = "rid";
const char KEY_SUFFIX_REMOVED[] = "_removed";
const int FREEDISKSPACE_CHECK_TIMEOUT = 30000;
namespace
{
void processMap(const QVariantMap &prevData, const QVariantMap &data, QVariantMap &syncData);
@ -312,6 +318,27 @@ namespace
}
}
SyncController::SyncController(ISessionManager *sessionManager, QObject *parent)
: APIController(sessionManager, parent)
{
m_freeDiskSpaceThread = new QThread(this);
m_freeDiskSpaceChecker = new FreeDiskSpaceChecker();
m_freeDiskSpaceChecker->moveToThread(m_freeDiskSpaceThread);
connect(m_freeDiskSpaceThread, &QThread::finished, m_freeDiskSpaceChecker, &QObject::deleteLater);
connect(m_freeDiskSpaceChecker, &FreeDiskSpaceChecker::checked, this, &SyncController::freeDiskSpaceSizeUpdated);
m_freeDiskSpaceThread->start();
QTimer::singleShot(0, m_freeDiskSpaceChecker, &FreeDiskSpaceChecker::check);
m_freeDiskSpaceElapsedTimer.start();
}
SyncController::~SyncController()
{
m_freeDiskSpaceThread->quit();
m_freeDiskSpaceThread->wait();
}
// The function returns the changed data from the server to synchronize with the web client.
// Return value is map in JSON format.
// Map contain the key:
@ -369,6 +396,7 @@ namespace
// - "up_rate_limit: upload speed limit
// - "queueing": priority system usage flag
// - "refresh_interval": torrents table refresh interval
// - "free_space_on_disk": Free space on the default save path
// GET param:
// - rid (int): last response id
void SyncController::maindataAction()
@ -412,6 +440,7 @@ void SyncController::maindataAction()
data["categories"] = categories;
QVariantMap serverState = getTranserInfo();
serverState[KEY_TRANSFER_FREESPACEONDISK] = getFreeDiskSpace();
serverState[KEY_SYNC_MAINDATA_QUEUEING] = session->isQueueingSystemEnabled();
serverState[KEY_SYNC_MAINDATA_USE_ALT_SPEED_LIMITS] = session->isAltGlobalSpeedLimitEnabled();
serverState[KEY_SYNC_MAINDATA_REFRESH_INTERVAL] = session->refreshInterval();
@ -482,3 +511,18 @@ void SyncController::torrentPeersAction()
sessionManager()->session()->setData(QLatin1String("syncTorrentPeersLastResponse"), lastResponse);
sessionManager()->session()->setData(QLatin1String("syncTorrentPeersLastAcceptedResponse"), lastAcceptedResponse);
}
qint64 SyncController::getFreeDiskSpace()
{
if (m_freeDiskSpaceElapsedTimer.hasExpired(FREEDISKSPACE_CHECK_TIMEOUT)) {
QTimer::singleShot(0, m_freeDiskSpaceChecker, &FreeDiskSpaceChecker::check);
m_freeDiskSpaceElapsedTimer.restart();
}
return m_freeDiskSpace;
}
void SyncController::freeDiskSpaceSizeUpdated(qint64 freeSpaceSize)
{
m_freeDiskSpace = freeSpaceSize;
}

View file

@ -28,8 +28,16 @@
#pragma once
#include <QElapsedTimer>
#include "apicontroller.h"
struct ISessionManager;
class QThread;
class FreeDiskSpaceChecker;
class SyncController : public APIController
{
Q_OBJECT
@ -38,7 +46,19 @@ class SyncController : public APIController
public:
using APIController::APIController;
explicit SyncController(ISessionManager *sessionManager, QObject *parent = nullptr);
~SyncController() override;
private slots:
void maindataAction();
void torrentPeersAction();
void freeDiskSpaceSizeUpdated(qint64 freeSpaceSize);
private:
qint64 getFreeDiskSpace();
qint64 m_freeDiskSpace = 0;
FreeDiskSpaceChecker *m_freeDiskSpaceChecker = nullptr;
QThread *m_freeDiskSpaceThread = nullptr;
QElapsedTimer m_freeDiskSpaceElapsedTimer;
};

View file

@ -3,6 +3,7 @@ HEADERS += \
$$PWD/api/apierror.h \
$$PWD/api/appcontroller.h \
$$PWD/api/authcontroller.h \
$$PWD/api/freediskspacechecker.h \
$$PWD/api/isessionmanager.h \
$$PWD/api/logcontroller.h \
$$PWD/api/rsscontroller.h \
@ -19,6 +20,7 @@ SOURCES += \
$$PWD/api/apierror.cpp \
$$PWD/api/appcontroller.cpp \
$$PWD/api/authcontroller.cpp \
$$PWD/api/freediskspacechecker.cpp \
$$PWD/api/logcontroller.cpp \
$$PWD/api/rsscontroller.cpp \
$$PWD/api/searchcontroller.cpp \

View file

@ -155,6 +155,8 @@
<span id="error_div"></span>
<table style="position: absolute; right: 5px;">
<tr>
<td id="freeSpaceOnDisk"></td>
<td class="statusBarSeparator"></td>
<td id="DHTNodes"></td>
<td class="statusBarSeparator"></td>
<td><img id="connectionStatus" alt="Connection Status" src="images/skin/firewalled.svg" style="height: 1.5em;" /></td>

View file

@ -421,6 +421,7 @@ window.addEvent('load', function() {
}
else
document.title = "qBittorrent ${VERSION} QBT_TR(Web UI)QBT_TR[CONTEXT=OptionsDialog]";
$('freeSpaceOnDisk').set('html', 'QBT_TR(Free space: %1)QBT_TR[CONTEXT=HttpServer]'.replace("%1", friendlyUnit(serverState.free_space_on_disk)));
$('DHTNodes').set('html', 'QBT_TR(DHT: %1 nodes)QBT_TR[CONTEXT=StatusBar]'.replace("%1", serverState.dht_nodes));
// Statistics dialog

View file

@ -12,7 +12,7 @@ function friendlyUnit(value, isSpeed) {
"QBT_TR(EiB)QBT_TR[CONTEXT=misc]"
];
if (value < 0)
if ((value === undefined) || (value === null) || (value < 0))
return "QBT_TR(Unknown)QBT_TR[CONTEXT=misc]";
var i = 0;