Show free disk space in status bar

PR #22407.
Closes #19607.
This commit is contained in:
Vladimir Golovnev
2025-03-13 14:47:10 +03:00
committed by GitHub
parent 882da47609
commit d174bc75e4
15 changed files with 163 additions and 80 deletions

View File

@@ -13,7 +13,6 @@ add_library(qbt_webui STATIC
api/torrentscontroller.h
api/transfercontroller.h
api/serialize/serialize_torrent.h
freediskspacechecker.h
webapplication.h
webui.h
@@ -30,7 +29,6 @@ add_library(qbt_webui STATIC
api/torrentscontroller.cpp
api/transfercontroller.cpp
api/serialize/serialize_torrent.cpp
freediskspacechecker.cpp
webapplication.cpp
webui.cpp
)

View File

@@ -1,44 +0,0 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2023 Vladimir Golovnev <glassez@yandex.ru>
* 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"
qint64 FreeDiskSpaceChecker::lastResult() const
{
return m_lastResult;
}
void FreeDiskSpaceChecker::check()
{
m_lastResult = Utils::Fs::freeDiskSpaceOnPath(BitTorrent::Session::instance()->savePath());
emit checked(m_lastResult);
}

View File

@@ -1,52 +0,0 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2023 Vladimir Golovnev <glassez@yandex.ru>
* 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 final : public QObject
{
Q_OBJECT
Q_DISABLE_COPY_MOVE(FreeDiskSpaceChecker)
public:
using QObject::QObject;
qint64 lastResult() const;
public slots:
void check();
signals:
void checked(qint64 freeSpaceSize);
private:
qint64 m_lastResult = 0;
};

View File

@@ -1,6 +1,6 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2014-2024 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2014-2025 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2024 Radu Carpa <radu.carpa@cern.ch>
*
* This program is free software; you can redistribute it and/or
@@ -43,10 +43,10 @@
#include <QNetworkCookie>
#include <QRegularExpression>
#include <QThread>
#include <QTimer>
#include <QUrl>
#include "base/algorithm.h"
#include "base/bittorrent/session.h"
#include "base/bittorrent/torrentcreationmanager.h"
#include "base/http/httperror.h"
#include "base/logger.h"
@@ -67,7 +67,6 @@
#include "api/torrentcreatorcontroller.h"
#include "api/torrentscontroller.h"
#include "api/transfercontroller.h"
#include "freediskspacechecker.h"
const int MAX_ALLOWED_FILESIZE = 10 * 1024 * 1024;
const QString DEFAULT_SESSION_COOKIE_NAME = u"SID"_s;
@@ -76,10 +75,6 @@ const QString WWW_FOLDER = u":/www"_s;
const QString PUBLIC_FOLDER = u"/public"_s;
const QString PRIVATE_FOLDER = u"/private"_s;
using namespace std::chrono_literals;
const std::chrono::seconds FREEDISKSPACE_CHECK_TIMEOUT = 30s;
namespace
{
QStringMap parseCookie(const QStringView cookieStr)
@@ -161,9 +156,6 @@ WebApplication::WebApplication(IApplication *app, QObject *parent)
: ApplicationComponent(app, parent)
, m_cacheID {QString::number(Utils::Random::rand(), 36)}
, m_authController {new AuthController(this, app, this)}
, m_workerThread {new QThread}
, m_freeDiskSpaceChecker {new FreeDiskSpaceChecker}
, m_freeDiskSpaceCheckingTimer {new QTimer(this)}
, m_torrentCreationManager {new BitTorrent::TorrentCreationManager(app, this)}
{
declarePublicAPI(u"auth/login"_s);
@@ -181,17 +173,6 @@ WebApplication::WebApplication(IApplication *app, QObject *parent)
}
m_sessionCookieName = DEFAULT_SESSION_COOKIE_NAME;
}
m_freeDiskSpaceChecker->moveToThread(m_workerThread.get());
connect(m_workerThread.get(), &QThread::finished, m_freeDiskSpaceChecker, &QObject::deleteLater);
m_workerThread->setObjectName("WebApplication m_workerThread");
m_workerThread->start();
m_freeDiskSpaceCheckingTimer->setInterval(FREEDISKSPACE_CHECK_TIMEOUT);
m_freeDiskSpaceCheckingTimer->setSingleShot(true);
connect(m_freeDiskSpaceCheckingTimer, &QTimer::timeout, m_freeDiskSpaceChecker, &FreeDiskSpaceChecker::check);
connect(m_freeDiskSpaceChecker, &FreeDiskSpaceChecker::checked, m_freeDiskSpaceCheckingTimer, qOverload<>(&QTimer::start));
QMetaObject::invokeMethod(m_freeDiskSpaceChecker, &FreeDiskSpaceChecker::check);
}
WebApplication::~WebApplication()
@@ -739,9 +720,10 @@ void WebApplication::sessionStart()
m_currentSession->registerAPIController(u"torrents"_s, new TorrentsController(app(), m_currentSession));
m_currentSession->registerAPIController(u"transfer"_s, new TransferController(app(), m_currentSession));
const auto *btSession = BitTorrent::Session::instance();
auto *syncController = new SyncController(app(), m_currentSession);
syncController->updateFreeDiskSpace(m_freeDiskSpaceChecker->lastResult());
connect(m_freeDiskSpaceChecker, &FreeDiskSpaceChecker::checked, syncController, &SyncController::updateFreeDiskSpace);
syncController->updateFreeDiskSpace(btSession->freeDiskSpace());
connect(btSession, &BitTorrent::Session::freeDiskSpaceChecked, syncController, &SyncController::updateFreeDiskSpace);
m_currentSession->registerAPIController(u"sync"_s, syncController);
QNetworkCookie cookie {m_sessionCookieName.toLatin1(), m_currentSession->id().toLatin1()};

View File

@@ -1,6 +1,6 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2014-2024 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2014-2025 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2024 Radu Carpa <radu.carpa@cern.ch>
*
* This program is free software; you can redistribute it and/or
@@ -50,17 +50,13 @@
#include "base/http/types.h"
#include "base/path.h"
#include "base/utils/net.h"
#include "base/utils/thread.h"
#include "base/utils/version.h"
#include "api/isessionmanager.h"
inline const Utils::Version<3, 2> API_VERSION {2, 11, 4};
class QTimer;
class APIController;
class AuthController;
class FreeDiskSpaceChecker;
class WebApplication;
namespace BitTorrent
@@ -259,8 +255,5 @@ private:
QList<Http::Header> m_prebuiltHeaders;
Utils::Thread::UniquePtr m_workerThread;
FreeDiskSpaceChecker *m_freeDiskSpaceChecker = nullptr;
QTimer *m_freeDiskSpaceCheckingTimer = nullptr;
BitTorrent::TorrentCreationManager *m_torrentCreationManager = nullptr;
};