Browse Source

Add free disk space to WebUI status bar

Closes #6829.
adaptive-webui-19844
Thomas Piccirello 6 years ago
parent
commit
2aea235e34
  1. 2
      src/webui/CMakeLists.txt
  2. 38
      src/webui/api/freediskspacechecker.cpp
  3. 46
      src/webui/api/freediskspacechecker.h
  4. 42
      src/webui/api/synccontroller.cpp
  5. 18
      src/webui/api/synccontroller.h
  6. 2
      src/webui/webui.pri
  7. 2
      src/webui/www/private/index.html
  8. 1
      src/webui/www/private/scripts/client.js

2
src/webui/CMakeLists.txt

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

38
src/webui/api/freediskspacechecker.cpp

@ -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);
}

46
src/webui/api/freediskspacechecker.h

@ -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);
};

42
src/webui/api/synccontroller.cpp

@ -29,6 +29,8 @@
#include "synccontroller.h" #include "synccontroller.h"
#include <QJsonObject> #include <QJsonObject>
#include <QThread>
#include <QTimer>
#include "base/bittorrent/peerinfo.h" #include "base/bittorrent/peerinfo.h"
#include "base/bittorrent/session.h" #include "base/bittorrent/session.h"
@ -38,6 +40,7 @@
#include "base/utils/fs.h" #include "base/utils/fs.h"
#include "base/utils/string.h" #include "base/utils/string.h"
#include "apierror.h" #include "apierror.h"
#include "freediskspacechecker.h"
#include "isessionmanager.h" #include "isessionmanager.h"
#include "serialize/serialize_torrent.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_UPRATELIMIT[] = "up_rate_limit";
const char KEY_TRANSFER_DHT_NODES[] = "dht_nodes"; const char KEY_TRANSFER_DHT_NODES[] = "dht_nodes";
const char KEY_TRANSFER_CONNECTION_STATUS[] = "connection_status"; const char KEY_TRANSFER_CONNECTION_STATUS[] = "connection_status";
const char KEY_TRANSFER_FREESPACEONDISK[] = "free_space_on_disk";
// Statistics keys // Statistics keys
const char KEY_TRANSFER_ALLTIME_DL[] = "alltime_dl"; 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_RESPONSE_ID[] = "rid";
const char KEY_SUFFIX_REMOVED[] = "_removed"; const char KEY_SUFFIX_REMOVED[] = "_removed";
const int FREEDISKSPACE_CHECK_TIMEOUT = 30000;
namespace namespace
{ {
void processMap(const QVariantMap &prevData, const QVariantMap &data, QVariantMap &syncData); void processMap(const QVariantMap &prevData, const QVariantMap &data, QVariantMap &syncData);
@ -312,6 +318,25 @@ 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();
}
SyncController::~SyncController()
{
m_freeDiskSpaceThread->quit();
m_freeDiskSpaceThread->wait();
}
// The function returns the changed data from the server to synchronize with the web client. // The function returns the changed data from the server to synchronize with the web client.
// Return value is map in JSON format. // Return value is map in JSON format.
// Map contain the key: // Map contain the key:
@ -369,6 +394,7 @@ namespace
// - "up_rate_limit: upload speed limit // - "up_rate_limit: upload speed limit
// - "queueing": priority system usage flag // - "queueing": priority system usage flag
// - "refresh_interval": torrents table refresh interval // - "refresh_interval": torrents table refresh interval
// - "free_space_on_disk": Free space on the default save path
// GET param: // GET param:
// - rid (int): last response id // - rid (int): last response id
void SyncController::maindataAction() void SyncController::maindataAction()
@ -412,6 +438,7 @@ void SyncController::maindataAction()
data["categories"] = categories; data["categories"] = categories;
QVariantMap serverState = getTranserInfo(); QVariantMap serverState = getTranserInfo();
serverState[KEY_TRANSFER_FREESPACEONDISK] = getFreeDiskSpace();
serverState[KEY_SYNC_MAINDATA_QUEUEING] = session->isQueueingSystemEnabled(); serverState[KEY_SYNC_MAINDATA_QUEUEING] = session->isQueueingSystemEnabled();
serverState[KEY_SYNC_MAINDATA_USE_ALT_SPEED_LIMITS] = session->isAltGlobalSpeedLimitEnabled(); serverState[KEY_SYNC_MAINDATA_USE_ALT_SPEED_LIMITS] = session->isAltGlobalSpeedLimitEnabled();
serverState[KEY_SYNC_MAINDATA_REFRESH_INTERVAL] = session->refreshInterval(); serverState[KEY_SYNC_MAINDATA_REFRESH_INTERVAL] = session->refreshInterval();
@ -482,3 +509,18 @@ void SyncController::torrentPeersAction()
sessionManager()->session()->setData(QLatin1String("syncTorrentPeersLastResponse"), lastResponse); sessionManager()->session()->setData(QLatin1String("syncTorrentPeersLastResponse"), lastResponse);
sessionManager()->session()->setData(QLatin1String("syncTorrentPeersLastAcceptedResponse"), lastAcceptedResponse); sessionManager()->session()->setData(QLatin1String("syncTorrentPeersLastAcceptedResponse"), lastAcceptedResponse);
} }
qint64 SyncController::getFreeDiskSpace()
{
const qint64 now = QDateTime::currentMSecsSinceEpoch();
if ((now - m_freeDiskSpaceLastUpdate) >= FREEDISKSPACE_CHECK_TIMEOUT) {
QTimer::singleShot(0, m_freeDiskSpaceChecker, &FreeDiskSpaceChecker::check);
m_freeDiskSpaceLastUpdate = now;
}
return m_freeDiskSpace;
}
void SyncController::freeDiskSpaceSizeUpdated(qint64 freeSpaceSize)
{
m_freeDiskSpace = freeSpaceSize;
}

18
src/webui/api/synccontroller.h

@ -30,6 +30,12 @@
#include "apicontroller.h" #include "apicontroller.h"
struct ISessionManager;
class QThread;
class FreeDiskSpaceChecker;
class SyncController : public APIController class SyncController : public APIController
{ {
Q_OBJECT Q_OBJECT
@ -38,7 +44,19 @@ class SyncController : public APIController
public: public:
using APIController::APIController; using APIController::APIController;
explicit SyncController(ISessionManager *sessionManager, QObject *parent = nullptr);
~SyncController() override;
private slots: private slots:
void maindataAction(); void maindataAction();
void torrentPeersAction(); void torrentPeersAction();
void freeDiskSpaceSizeUpdated(qint64 freeSpaceSize);
private:
qint64 getFreeDiskSpace();
qint64 m_freeDiskSpace = 0;
qint64 m_freeDiskSpaceLastUpdate = 0;
FreeDiskSpaceChecker *m_freeDiskSpaceChecker = nullptr;
QThread *m_freeDiskSpaceThread = nullptr;
}; };

2
src/webui/webui.pri

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

2
src/webui/www/private/index.html

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

1
src/webui/www/private/scripts/client.js

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

Loading…
Cancel
Save