Browse Source

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

Free disk space in WebUI status bar
adaptive-webui-19844
Vladimir Golovnev 6 years ago committed by GitHub
parent
commit
4fee16fafb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/webui/CMakeLists.txt
  2. 38
      src/webui/api/freediskspacechecker.cpp
  3. 46
      src/webui/api/freediskspacechecker.h
  4. 44
      src/webui/api/synccontroller.cpp
  5. 20
      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
  9. 2
      src/webui/www/private/scripts/misc.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/searchcontroller.h api/searchcontroller.h
@ -20,6 +21,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/searchcontroller.cpp api/searchcontroller.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);
};

44
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,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. // 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 +396,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 +440,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 +511,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()
{
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;
}

20
src/webui/api/synccontroller.h

@ -28,8 +28,16 @@
#pragma once #pragma once
#include <QElapsedTimer>
#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 +46,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;
FreeDiskSpaceChecker *m_freeDiskSpaceChecker = nullptr;
QThread *m_freeDiskSpaceThread = nullptr;
QElapsedTimer m_freeDiskSpaceElapsedTimer;
}; };

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 \
@ -19,6 +20,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/searchcontroller.cpp \ $$PWD/api/searchcontroller.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

2
src/webui/www/private/scripts/misc.js

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

Loading…
Cancel
Save